From 793c57acf4684b2f7ac04a0529b03461257ef959 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Fri, 17 Aug 2012 15:36:43 +0100 Subject: Check return from thumbnail generator. (bzr r2580.1.1) --- unity-shared/CoverArt.cpp | 38 ++++++++++++++++++++++--------------- unity-shared/CoverArt.h | 4 +++- unity-shared/ThumbnailGenerator.cpp | 3 +++ 3 files changed, 29 insertions(+), 16 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index c6949d499..e7957e58d 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -126,11 +126,18 @@ void CoverArt::SetImage(std::string const& image_hint) void CoverArt::GenerateImage(std::string const& uri) { - StartWaiting(); notifier_ = ThumbnailGenerator::Instance().GetThumbnail(uri, 512); - - notifier_->ready.connect(sigc::mem_fun(this, &CoverArt::OnThumbnailGenerated)); - notifier_->error.connect(sigc::mem_fun(this, &CoverArt::OnThumbnailError)); + if (notifier_) + { + StartWaiting(); + notifier_->ready.connect(sigc::mem_fun(this, &CoverArt::OnThumbnailGenerated)); + notifier_->error.connect(sigc::mem_fun(this, &CoverArt::OnThumbnailError)); + } + else + { + StopWaiting(); + SetNoImageAvailable(); + } } void CoverArt::StartWaiting() @@ -145,9 +152,9 @@ void CoverArt::StartWaiting() spinner_timeout_.reset(new glib::TimeoutSeconds(5, [&] { - texture_screenshot_.Release(); - waiting_ = false; + StopWaiting(); + texture_screenshot_.Release(); SetNoImageAvailable(); return false; })); @@ -155,6 +162,13 @@ void CoverArt::StartWaiting() QueueDraw(); } +void CoverArt::StopWaiting() +{ + spinner_timeout_.reset(); + frame_timeout_.reset(); + waiting_ = false; +} + void CoverArt::SetNoImageAvailable() { if (GetLayout()) @@ -170,9 +184,7 @@ void CoverArt::SetNoImageAvailable() void CoverArt::IconLoaded(std::string const& texid, unsigned size, glib::Object const& pixbuf) { // Finished waiting - spinner_timeout_.reset(); - frame_timeout_.reset(); - waiting_ = false; + StopWaiting(); stretch_image_ = false; if (!pixbuf) @@ -251,9 +263,7 @@ void CoverArt::IconLoaded(std::string const& texid, unsigned size, glib::Object< void CoverArt::TextureLoaded(std::string const& texid, unsigned size, glib::Object const& pixbuf) { // Finished waiting - spinner_timeout_.reset(); - frame_timeout_.reset(); - waiting_ = false; + StopWaiting(); stretch_image_ = true; if (!pixbuf) @@ -425,9 +435,7 @@ void CoverArt::OnThumbnailGenerated(std::string const& uri) void CoverArt::OnThumbnailError(std::string const& error_hint) { LOG_WARNING(logger) << "Failed to generate thumbnail: " << error_hint; - spinner_timeout_.reset(); - frame_timeout_.reset(); - waiting_ = false; + StopWaiting(); texture_screenshot_.Release(); if (GetLayout()) diff --git a/unity-shared/CoverArt.h b/unity-shared/CoverArt.h index dd5a666fe..0fd817aff 100644 --- a/unity-shared/CoverArt.h +++ b/unity-shared/CoverArt.h @@ -52,6 +52,8 @@ public: void SetImage(std::string const& image_hint); // Use for generating an image for a uri which is not necessarily an image. void GenerateImage(std::string const& uri); + + void SetNoImageAvailable(); // From debug::Introspectable std::string GetName() const; @@ -72,7 +74,7 @@ protected: void TextureLoaded(std::string const& texid, unsigned size, glib::Object const& pixbuf); void StartWaiting(); - void SetNoImageAvailable(); + void StopWaiting(); private: nux::ObjectPtr texture_screenshot_; diff --git a/unity-shared/ThumbnailGenerator.cpp b/unity-shared/ThumbnailGenerator.cpp index d13be2b9e..0bbd1dbbf 100644 --- a/unity-shared/ThumbnailGenerator.cpp +++ b/unity-shared/ThumbnailGenerator.cpp @@ -457,6 +457,9 @@ ThumbnailGenerator& ThumbnailGenerator::Instance() ThumbnailNotifier::Ptr ThumbnailGenerator::GetThumbnail(std::string const& uri, int size) { + if (uri.empty()) + return ThumbnailNotifier::Ptr(); + return pimpl->GetThumbnail(uri, size); } -- cgit v1.2.3