diff options
| -rw-r--r-- | unity-shared/CoverArt.cpp | 69 | ||||
| -rw-r--r-- | unity-shared/CoverArt.h | 1 | ||||
| -rw-r--r-- | unity-shared/IconLoader.cpp | 21 |
3 files changed, 46 insertions, 45 deletions
diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index 4b5e21e03..14f4d8e12 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -86,49 +86,20 @@ void CoverArt::SetImage(std::string const& image_hint) GIcon* icon = g_icon_new_for_string(image_hint.c_str(), NULL); - glib::Object<GFile> image_file; - if (g_strrstr(image_hint.c_str(), "://")) + bool bLoadTexture = false; + bLoadTexture |= g_strrstr(image_hint.c_str(), "://") != NULL; + if (!bLoadTexture && !image_hint.empty()) { - /* try to open the source file for reading */ - image_file = g_file_new_for_uri (image_hint.c_str()); + bLoadTexture |= image_hint[0] == '/' && image_hint.size() > 1; } - else - { - image_file = g_file_new_for_path (image_hint.c_str()); - } - - if (g_file_query_exists(image_file, NULL)) - { - // for files on disk, we stretch to maximum aspect ratio. - stretch_image_ = true; - GFileInputStream *stream; - GError *error = NULL; - - stream = g_file_read (image_file, NULL, &error); - - if (error != NULL) - { - g_error_free (error); - - if (icon != NULL) - g_object_unref(icon); - return; - } - - /* stream image into pixel-buffer. */ - glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_stream (G_INPUT_STREAM (stream), NULL, &error)); - g_object_unref (stream); - - texture_screenshot_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true)); - - if (!texture_screenshot_) - { - SetNoImageAvailable(); - } - QueueDraw(); + // texture from file. + if (bLoadTexture) + { + StartWaiting(); + slot_handle_ = IconLoader::GetDefault().LoadFromGIconString(image_hint, ~0, sigc::mem_fun(this, &CoverArt::TextureLoaded)); } - else + else if (!image_hint.empty()) { if (GetLayout()) GetLayout()->RemoveChildObject(overlay_text_); @@ -144,6 +115,10 @@ void CoverArt::SetImage(std::string const& image_hint) slot_handle_ = IconLoader::GetDefault().LoadFromIconName(image_hint, icon_width, sigc::mem_fun(this, &CoverArt::IconLoaded)); } } + else + { + SetNoImageAvailable(); + } if (icon != NULL) g_object_unref(icon); @@ -278,6 +253,22 @@ void CoverArt::IconLoaded(std::string const& texid, unsigned size, glib::Object< } } +void CoverArt::TextureLoaded(std::string const& texid, unsigned size, glib::Object<GdkPixbuf> const& pixbuf) +{ + // Finished waiting + spinner_timeout_.reset(); + frame_timeout_.reset(); + waiting_ = false; + stretch_image_ = false; + + if (!pixbuf) + { + SetNoImageAvailable(); + return; + } + texture_screenshot_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true)); +} + void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) { nux::Geometry const& base = GetGeometry(); diff --git a/unity-shared/CoverArt.h b/unity-shared/CoverArt.h index 13b33cb25..dd5a666fe 100644 --- a/unity-shared/CoverArt.h +++ b/unity-shared/CoverArt.h @@ -69,6 +69,7 @@ protected: bool OnFrameTimeout(); void IconLoaded(std::string const& texid, unsigned size, glib::Object<GdkPixbuf> const& pixbuf); + void TextureLoaded(std::string const& texid, unsigned size, glib::Object<GdkPixbuf> const& pixbuf); void StartWaiting(); void SetNoImageAvailable(); diff --git a/unity-shared/IconLoader.cpp b/unity-shared/IconLoader.cpp index 2627d914c..78c9e9ea9 100644 --- a/unity-shared/IconLoader.cpp +++ b/unity-shared/IconLoader.cpp @@ -268,12 +268,21 @@ private: glib::Object<GInputStream> stream( ::g_memory_input_stream_new_from_data(contents.Value(), length, nullptr)); - task->result = ::gdk_pixbuf_new_from_stream_at_scale(stream, - -1, - task->size, - TRUE, - canc, - &task->error); + if (task->size != static_cast<unsigned int>(~0)) + { + task->result = ::gdk_pixbuf_new_from_stream_at_scale(stream, + -1, + task->size, + TRUE, + canc, + &task->error); + } + else + { + task->result = ::gdk_pixbuf_new_from_stream(stream, + canc, + &task->error); + } ::g_input_stream_close(stream, canc, nullptr); } } |
