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 --- src/common-defs.h | 1 + src/fetch-file.vala | 9 +++++---- src/metadata-menu-item.vala | 1 - src/metadata-widget.c | 22 +++++++++++++++------ src/player-item.vala | 48 +++++++++++++++++++++------------------------ vapi/common-defs.vapi | 5 +++++ 6 files changed, 49 insertions(+), 37 deletions(-) diff --git a/src/common-defs.h b/src/common-defs.h index e554c11..faffcb2 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -25,6 +25,7 @@ with this program. If not, see . #define SIGNAL_SINK_AVAILABLE_UPDATE "SinkAvailableUpdate" #define DBUSMENU_PROPERTY_EMPTY -1 +#define DBUSMENU_PLAYERITEM_REMOTE_FILEPATH "/home/ronoc/Desktop/tempy" /* DBUS Custom Items */ #define DBUSMENU_VOLUME_MENUITEM_TYPE "x-canonical-ido-volume-type" diff --git a/src/fetch-file.vala b/src/fetch-file.vala index 55bfdc3..f172853 100644 --- a/src/fetch-file.vala +++ b/src/fetch-file.vala @@ -2,6 +2,7 @@ public class FetchFile : Object { /* public variables */ public string uri {get; construct;} + public string intended_property {get; construct;} /* private variables */ private DataInputStream stream; @@ -10,11 +11,11 @@ public class FetchFile : Object /* public signals */ public signal void failed (); - public signal void completed (ByteArray data); + public signal void completed (ByteArray data, string property); - public FetchFile (string uri) + public FetchFile (string uri, string prop) { - Object (uri: uri); + Object (uri: uri, intended_property: prop); } construct @@ -60,6 +61,6 @@ public class FetchFile : Object this.failed (); } } while (bufsize > 0); - this.completed (this.data); + this.completed (this.data, this.intended_property); } } diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index 090952b..04284d4 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -19,7 +19,6 @@ with this program. If not, see . using Gee; using DbusmenuMetadata; -using Gdk; public class MetadataMenuitem : PlayerItem { diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 5e75b29..72acc8c 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -36,6 +36,7 @@ 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; @@ -104,6 +105,7 @@ 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_PLAYERITEM_REMOTE_FILEPATH); g_debug("Metadata::At startup and image path = %s", priv->image_path->str); g_signal_connect(priv->album_art, "expose-event", @@ -176,6 +178,10 @@ metadata_widget_finalize (GObject *object) G_OBJECT_CLASS (metadata_widget_parent_class)->finalize (object); } +static void metadata_load_new_image(MetadataWidget* self) +{ +} + /** * We override the expose method to enable primitive drawing of the * empty album art image (and soon rounded rectangles on the album art) @@ -188,19 +194,20 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widget); if(priv->image_path->len > 0){ - - if(g_string_equal(priv->image_path, priv->old_image_path) == FALSE){ - + 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)){ GdkPixbuf* pixbuf; pixbuf = gdk_pixbuf_new_from_file(priv->image_path->str, NULL); - g_debug("metadata_widget_expose, album art update -> pixbuf from %s", - priv->image_path->str); + g_debug("metadata_load_new_image -> pixbuf from %s", + priv->image_path->str); 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); + g_object_unref(pixbuf); + } return FALSE; } @@ -315,7 +322,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); + //gchar* empty = ""; + g_string_erase(priv->old_image_path, 0, -1); g_string_overwrite(priv->image_path, 0, g_value_get_string (value)); + //g_free(empty); } } diff --git a/src/player-item.vala b/src/player-item.vala index 82b9f07..7de6840 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -19,13 +19,15 @@ with this program. If not, see . using Dbusmenu; using Gee; +using Gdk; public class PlayerItem : Dbusmenu.Menuitem { public PlayerController owner {get; construct;} public string item_type { get; construct; } private const int EMPTY = -1; - + private FetchFile fetcher; + public PlayerItem(string type) { Object(item_type: type); @@ -62,6 +64,9 @@ public class PlayerItem : Dbusmenu.Menuitem // 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); + continue; } else{ // The file is local, just parse the string @@ -108,44 +113,35 @@ public class PlayerItem : Dbusmenu.Menuitem return false; } - public fetch_remote_art(uri) + public void fetch_remote_art(string uri, string prop) { - this.fetcher = new FetchFile (uri); + 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 (); } - - public string parse_art_url(string update) - { - if(update == null) - return null; - string temp_path = "/home/ronoc/Desktop/tempy.jpg"; - string local_path = ""; - string temp_name = ""; - debug("MetadataMenuitem: parse art url - result %s", local_path); - return local_path; + private void on_fetcher_failed () + { + warning("on_fetcher_failed -> could not fetch artwork"); } - - public extract_downloaded_file() + + private void on_fetcher_completed(ByteArray update, string property) { + string temp_path = "/home/ronoc/Desktop/tempy"; + //"/tmp/indicator-sound-remote-image"; try{ PixbufLoader loader = new PixbufLoader (); - bool write_result = loader.write (update.data, update.len()); + loader.write (update.data, update.len); loader.close (); - unowned PixbufFormat format = loader.get_format(); - debug("the bloody format name is %s", format.get_name()); - debug("is the format null %s", (format == null).to_string()); Pixbuf icon = loader.get_pixbuf (); - temp_name = loader.get_format().get_name(); - icon.save (temp_path, "jpeg"); - local_path = temp_path; + icon.save (temp_path, loader.get_format().get_name()); + this.property_set(property, temp_path); } catch(GLib.Error e){ - warning("Problem taking file from the interweb - error: %s and name: %s", - e.message, - temp_name); - } + warning("Problem taking file from the interweb - error: %s", + e.message); + } + } } 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