From 9ab9b175e1f77457157211f5f93c54e8ae87e3dc Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 1 Sep 2010 17:22:55 +0100 Subject: almost bug free --- vapi/common-defs.vapi | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'vapi') diff --git a/vapi/common-defs.vapi b/vapi/common-defs.vapi index c083e2a..54d4ed2 100644 --- a/vapi/common-defs.vapi +++ b/vapi/common-defs.vapi @@ -26,6 +26,11 @@ namespace DbusmenuMetadata{ public const string MENUITEM_ARTURL; } +[CCode (cheader_filename = "common-defs.h")] +namespace DbusmenuPlayer{ + public const string ITEM_REMOTE_FILEPATH; +} + [CCode (cheader_filename = "common-defs.h")] namespace DbusmenuTransport{ public const string MENUITEM_TYPE; -- cgit v1.2.3 From 136b92dbb90bd3c9d1905d0f039b8776aa1a1c73 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 2 Sep 2010 11:27:23 +0100 Subject: album art from remote location working --- src/common-defs.h | 2 +- src/metadata-widget.c | 29 ++++++++++++++++++++--------- src/sound-service.c | 3 +-- vapi/common-defs.vapi | 2 +- 4 files changed, 23 insertions(+), 13 deletions(-) (limited to 'vapi') diff --git a/src/common-defs.h b/src/common-defs.h index 2590692..fc4e323 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -25,7 +25,7 @@ with this program. If not, see . #define SIGNAL_SINK_AVAILABLE_UPDATE "SinkAvailableUpdate" #define DBUSMENU_PROPERTY_EMPTY -1 -#define DBUSMENU_PLAYER_ITEM_REMOTE_FILEPATH "/home/ronoc/Desktop/tempy" +#define DBUSMENU_PLAYER_ITEM_REMOTE_FILEPATH "/tmp/indicator-sound-downloaded-album-art" /* DBUS Custom Items */ #define DBUSMENU_VOLUME_MENUITEM_TYPE "x-canonical-ido-volume-type" diff --git a/src/metadata-widget.c b/src/metadata-widget.c index cfff098..3e01aec 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -70,7 +70,7 @@ static void image_set_from_pixbuf (GtkWidget *widget, MetadataWidget* metadata, GdkPixbuf *source); - +static void draw_album_art_placeholder(GtkWidget *metadata); G_DEFINE_TYPE (MetadataWidget, metadata_widget, GTK_TYPE_MENU_ITEM); @@ -180,7 +180,7 @@ metadata_widget_finalize (GObject *object) /** * We override the expose method to enable primitive drawing of the - * empty album art image (and soon rounded rectangles on the album art) + * empty album art image and rounded rectangles on the album art. */ static gboolean metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user_data) @@ -188,26 +188,37 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user g_return_val_if_fail(IS_METADATA_WIDGET(user_data), FALSE); MetadataWidget* widget = METADATA_WIDGET(user_data); MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widget); - + g_debug("expose"); if(priv->image_path->len > 0){ if(g_string_equal(priv->image_path, priv->old_image_path) == FALSE || (g_string_equal(priv->image_path, priv->remote_image_path) == TRUE && - g_string_equal(priv->old_image_path, priv->remote_image_path) == FALSE)){ + g_string_equal(priv->old_image_path, priv->remote_image_path) == FALSE)){ + g_debug("and we are in"); GdkPixbuf* pixbuf; pixbuf = gdk_pixbuf_new_from_file(priv->image_path->str, NULL); g_debug("metadata_load_new_image -> pixbuf from %s", priv->image_path->str); + if(GDK_IS_PIXBUF(pixbuf) == FALSE){ + g_debug("problem loading the downloaded image just use the placeholder instead"); + draw_album_art_placeholder(metadata); + return TRUE; + } pixbuf = gdk_pixbuf_scale_simple(pixbuf,60, 60, GDK_INTERP_BILINEAR); image_set_from_pixbuf (metadata, widget, pixbuf); g_string_erase(priv->old_image_path, 0, -1); g_string_overwrite(priv->old_image_path, 0, priv->image_path->str); g_object_unref(pixbuf); - } return FALSE; } - + draw_album_art_placeholder(metadata); + return TRUE; +} + +static void draw_album_art_placeholder(GtkWidget *metadata) +{ + cairo_t *cr; cr = gdk_cairo_create (metadata->window); GtkAllocation alloc; @@ -259,8 +270,7 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user g_object_unref(pcontext); g_string_free (string, TRUE); cairo_destroy (cr); - - return TRUE; + } /* Suppress/consume keyevents */ @@ -320,9 +330,10 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, g_string_erase(priv->image_path, 0, -1); g_string_overwrite(priv->image_path, 0, g_value_get_string (value)); // Basically force expose the reload the image because we have an image update - // but we are using remote images i.e. the same file + // but we are using remote images i.e. the same file path but different images if(g_string_equal(priv->image_path, priv->remote_image_path) == TRUE){ g_string_erase(priv->old_image_path, 0, -1); + gtk_widget_queue_draw(GTK_WIDGET(mitem)); } } } diff --git a/src/sound-service.c b/src/sound-service.c index 12f067e..f19379d 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -40,14 +40,13 @@ service_shutdown (IndicatorService *service, gpointer user_data) { if (mainloop != NULL) { g_debug("Service shutdown !"); - // TODO: uncomment for release !! + //TODO: uncomment for release !! close_pulse_activites(); g_main_loop_quit(mainloop); } return; } - /** main: **/ diff --git a/vapi/common-defs.vapi b/vapi/common-defs.vapi index 54d4ed2..93f4795 100644 --- a/vapi/common-defs.vapi +++ b/vapi/common-defs.vapi @@ -1,6 +1,6 @@ /* Copyright 2010 Canonical Ltd. - + Authors: Conor Curran -- cgit v1.2.3 From 779bb004a88acc14c7a505e531731e7d89d65eeb Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 3 Sep 2010 14:06:00 +0100 Subject: reworked album art handling using gio exclusively with mkstemp --- src/common-defs.h | 1 - src/metadata-menu-item.vala | 2 +- src/metadata-widget.c | 15 ++++------- src/player-item.vala | 62 +++++++++++++++++++++++++++------------------ vapi/common-defs.vapi | 5 ---- 5 files changed, 44 insertions(+), 41 deletions(-) (limited to 'vapi') diff --git a/src/common-defs.h b/src/common-defs.h index fc4e323..e554c11 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -25,7 +25,6 @@ with this program. If not, see . #define SIGNAL_SINK_AVAILABLE_UPDATE "SinkAvailableUpdate" #define DBUSMENU_PROPERTY_EMPTY -1 -#define DBUSMENU_PLAYER_ITEM_REMOTE_FILEPATH "/tmp/indicator-sound-downloaded-album-art" /* DBUS Custom Items */ #define DBUSMENU_VOLUME_MENUITEM_TYPE "x-canonical-ido-volume-type" diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index 04284d4..6e7230b 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -38,5 +38,5 @@ public class MetadataMenuitem : PlayerItem attrs.add(MENUITEM_ARTURL); return attrs; } - + } diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 3e01aec..a88d38c 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -36,7 +36,6 @@ struct _MetadataWidgetPrivate GtkWidget* album_art; GString* image_path; GString* old_image_path; - GString* remote_image_path; GtkWidget* artist_label; GtkWidget* piece_label; GtkWidget* container_label; @@ -105,7 +104,6 @@ metadata_widget_init (MetadataWidget *self) priv->album_art = gtk_image_new(); priv->image_path = g_string_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_ARTURL)); priv->old_image_path = g_string_new(""); - priv->remote_image_path = g_string_new(DBUSMENU_PLAYER_ITEM_REMOTE_FILEPATH); g_debug("Metadata::At startup and image path = %s", priv->image_path->str); g_signal_connect(priv->album_art, "expose-event", @@ -190,9 +188,7 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widget); g_debug("expose"); if(priv->image_path->len > 0){ - if(g_string_equal(priv->image_path, priv->old_image_path) == FALSE || - (g_string_equal(priv->image_path, priv->remote_image_path) == TRUE && - g_string_equal(priv->old_image_path, priv->remote_image_path) == FALSE)){ + if(g_string_equal(priv->image_path, priv->old_image_path) == FALSE){ g_debug("and we are in"); GdkPixbuf* pixbuf; pixbuf = gdk_pixbuf_new_from_file(priv->image_path->str, NULL); @@ -328,11 +324,10 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ARTURL, property) == 0){ g_string_erase(priv->image_path, 0, -1); - g_string_overwrite(priv->image_path, 0, g_value_get_string (value)); - // Basically force expose the reload the image because we have an image update - // but we are using remote images i.e. the same file path but different images - if(g_string_equal(priv->image_path, priv->remote_image_path) == TRUE){ - g_string_erase(priv->old_image_path, 0, -1); + g_string_overwrite(priv->image_path, 0, g_value_get_string (value)); + // if its a remote image queue a redraw incase the download took too long + if (g_str_has_prefix(g_value_get_string (value), get_user_special_dir(GUserDirectory.PICTURES))){ + g_debug("the image update is a download so redraw"); gtk_widget_queue_draw(GTK_WIDGET(mitem)); } } diff --git a/src/player-item.vala b/src/player-item.vala index 1e16742..83b19d6 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -20,7 +20,6 @@ with this program. If not, see . using Dbusmenu; using Gee; using Gdk; -using DbusmenuPlayer; public class PlayerItem : Dbusmenu.Menuitem { @@ -28,6 +27,7 @@ public class PlayerItem : Dbusmenu.Menuitem public string item_type { get; construct; } private const int EMPTY = -1; private FetchFile fetcher; + private string previous_temp_album_art_path; public PlayerItem(string type) { @@ -36,6 +36,7 @@ public class PlayerItem : Dbusmenu.Menuitem construct { this.property_set(MENUITEM_PROP_TYPE, item_type); + this.previous_temp_album_art_path = null; } public void reset(HashSet attrs){ @@ -45,6 +46,12 @@ public class PlayerItem : Dbusmenu.Menuitem } } + /** + * update() + * Base update method for playeritems, takes the attributes and the incoming updates + * and attmepts to update the appropriate props on the object. + * Album art is handled separately to deal with remote and local file paths. + */ public void update(HashTable data, HashSet attributes) { debug("PlayerItem::update()"); @@ -62,25 +69,11 @@ public class PlayerItem : Dbusmenu.Menuitem if (v.holds (typeof (string))){ string update = v.get_string().strip(); debug("with value : %s", update); - // Special case for the arturl URI's. if(property.contains("mpris:artUrl")){ - if(update.has_prefix("http://")){ - // This is asyncronous so handle it offline - this.fetch_remote_art(update.strip(), property); + this.fetch_art(update.strip(), property); continue; - } - else{ - // The file is local, just parse the string - try{ - update = Filename.from_uri(update.strip()); - } - catch(ConvertError e){ - warning("Problem converting URI %s to file path", - update); - } - } } - this.property_set(property, update); + this.property_set(property, update); } else if (v.holds (typeof (int))){ debug("with value : %i", v.get_int()); @@ -95,7 +88,6 @@ public class PlayerItem : Dbusmenu.Menuitem this.property_set_bool(property, v.get_boolean()); } } - if(this.property_get_bool(MENUITEM_PROP_VISIBLE) == false){ this.property_set_bool(MENUITEM_PROP_VISIBLE, true); } @@ -114,14 +106,29 @@ public class PlayerItem : Dbusmenu.Menuitem return false; } - public void fetch_remote_art(string uri, string prop) - { + public void fetch_art(string uri, string prop) + { + File art_file = File.new_for_uri(uri); + if(art_file.is_native() == true){ + string path; + try{ + path = Filename.from_uri(uri.strip()); + this.property_set(prop, path); + } + catch(ConvertError e){ + warning("Problem converting URI %s to file path", + uri); + } + // eitherway return, the artwork was local + return; + } + // otherwise go remote this.fetcher = new FetchFile (uri, prop); this.fetcher.failed.connect (() => { this.on_fetcher_failed ();}); this.fetcher.completed.connect (this.on_fetcher_completed); this.fetcher.fetch_data (); } - + private void on_fetcher_failed () { warning("on_fetcher_failed -> could not fetch artwork"); @@ -134,13 +141,20 @@ public class PlayerItem : Dbusmenu.Menuitem loader.write (update.data, update.len); loader.close (); Pixbuf icon = loader.get_pixbuf (); - icon.save (ITEM_REMOTE_FILEPATH, loader.get_format().get_name()); - this.property_set(property, ITEM_REMOTE_FILEPATH); + string path = Environment.get_user_special_dir(UserDirectory.PICTURES).dup().concat("/indicator-sound-XXXXXX"); + int r = FileUtils.mkstemp(path); + icon.save (path, loader.get_format().get_name()); + if(this.previous_temp_album_art_path != null){ + FileUtils.remove(this.previous_temp_album_art_path); + } + this.previous_temp_album_art_path = path; + this.property_set(property, path); } catch(GLib.Error e){ - warning("Problem fetching file from the interweb - error: %s", + warning("Problem creating file from bytearray fetched from the interweb - error: %s", e.message); } } + } diff --git a/vapi/common-defs.vapi b/vapi/common-defs.vapi index 93f4795..84fb924 100644 --- a/vapi/common-defs.vapi +++ b/vapi/common-defs.vapi @@ -26,11 +26,6 @@ namespace DbusmenuMetadata{ public const string MENUITEM_ARTURL; } -[CCode (cheader_filename = "common-defs.h")] -namespace DbusmenuPlayer{ - public const string ITEM_REMOTE_FILEPATH; -} - [CCode (cheader_filename = "common-defs.h")] namespace DbusmenuTransport{ public const string MENUITEM_TYPE; -- cgit v1.2.3