From 71d315d3abec5b62e43b821232d70262bec92bd1 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 16 Jun 2010 18:19:35 +0100 Subject: metadata being updated dynamically --- src/metadata-widget.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/metadata-widget.c') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index a451ad7..e69a9dd 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -53,9 +53,9 @@ static gboolean metadata_widget_button_press_event (GtkWidget *menuitem, static gboolean metadata_widget_button_release_event (GtkWidget *menuitem, GdkEventButton *event); // Dbusmenuitem properties update callback -static void metadata_widget_update_state(gchar * property, - GValue * value, - gpointer userdata); +static void metadata_widget_update_state(DbusmenuMenuitem* item, gchar* property, + GValue* value, gpointer userdata); + //static void update_content( @@ -159,9 +159,20 @@ metadata_widget_button_release_event (GtkWidget *menuitem, return TRUE; } -static void metadata_widget_update_state(gchar *property, GValue *value, gpointer userdata) +static void +metadata_widget_update_state(DbusmenuMenuitem* item, gchar* property, + GValue* value, gpointer userdata) { - g_debug("metadata_widget_update_state - with property %s", property); + //g_debug("metadata_widget_update_state - with property %s", property); + MetadataWidget* mitem = METADATA_WIDGET(userdata); + MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(mitem); + + if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_TEXT_ARTIST, property) == 0){ + gtk_label_set_text(GTK_LABEL(priv->artist_label), g_value_get_string(value)); + } + else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_TEXT_PIECE, property) == 0){ + gtk_label_set_text(GTK_LABEL(priv->piece_label), g_value_get_string(value)); + } } /** -- cgit v1.2.3 From 4125fd9e2eb0de55d04482b3c035aa91fe7d547a Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 16 Jun 2010 19:40:15 +0100 Subject: album art updates working just fine --- src/metadata-widget.c | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'src/metadata-widget.c') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index e69a9dd..e0dca6e 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -34,7 +34,7 @@ struct _MetadataWidgetPrivate { GtkWidget* hbox; GtkWidget* album_art; - gchar* our_path; + gchar* image_path; GtkWidget* artist_label; GtkWidget* piece_label; GtkWidget* container_label; @@ -53,10 +53,10 @@ static gboolean metadata_widget_button_press_event (GtkWidget *menuitem, static gboolean metadata_widget_button_release_event (GtkWidget *menuitem, GdkEventButton *event); // Dbusmenuitem properties update callback -static void metadata_widget_update_state(DbusmenuMenuitem* item, gchar* property, +static void metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata); -//static void update_content( +static void update_album_art(MetadataWidget* self); G_DEFINE_TYPE (MetadataWidget, metadata_widget, GTK_TYPE_MENU_ITEM); @@ -92,14 +92,9 @@ metadata_widget_init (MetadataWidget *self) priv->hbox = hbox; // image - const gchar* path = dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_IMAGE_PATH); - g_debug("MetadataWidget:init - path = %s", path); - priv->our_path = g_strdup(path); - GdkPixbuf* pixbuf; - pixbuf=gdk_pixbuf_new_from_file(path, NULL); - pixbuf=gdk_pixbuf_scale_simple(pixbuf,60,60,GDK_INTERP_BILINEAR); - priv->album_art = gtk_image_new_from_pixbuf(pixbuf); - g_object_unref(pixbuf); + priv->album_art = gtk_image_new(); + priv->image_path = g_strdup(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_IMAGE_PATH)); + update_album_art(self); gtk_box_pack_start (GTK_BOX (priv->hbox), priv->album_art, FALSE, FALSE, 0); GtkWidget* vbox = gtk_vbox_new(TRUE, 0); @@ -107,24 +102,28 @@ metadata_widget_init (MetadataWidget *self) GtkWidget* artist; artist = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_TEXT_ARTIST)); priv->artist_label = artist; - gtk_box_pack_start (GTK_BOX (vbox), priv->artist_label, FALSE, FALSE, 0); + // piece GtkWidget* piece; piece = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_TEXT_PIECE)); priv->piece_label = piece; - gtk_box_pack_start (GTK_BOX (vbox), priv->piece_label, FALSE, FALSE, 0); - + + // container GtkWidget* container; container = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_TEXT_CONTAINER)); priv->container_label = container; + + // Pack in the right order + gtk_box_pack_start (GTK_BOX (vbox), priv->piece_label, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox), priv->artist_label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), priv->container_label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (priv->hbox), vbox, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(twin_item), "property-changed", - G_CALLBACK(metadata_widget_update_state), self); + G_CALLBACK(metadata_widget_property_update), self); gtk_widget_show_all (priv->hbox); gtk_container_add (GTK_CONTAINER (self), hbox); @@ -160,10 +159,9 @@ metadata_widget_button_release_event (GtkWidget *menuitem, } static void -metadata_widget_update_state(DbusmenuMenuitem* item, gchar* property, +metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata) { - //g_debug("metadata_widget_update_state - with property %s", property); MetadataWidget* mitem = METADATA_WIDGET(userdata); MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(mitem); @@ -173,6 +171,22 @@ metadata_widget_update_state(DbusmenuMenuitem* item, gchar* property, else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_TEXT_PIECE, property) == 0){ gtk_label_set_text(GTK_LABEL(priv->piece_label), g_value_get_string(value)); } + else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_TEXT_CONTAINER, property) == 0){ + gtk_label_set_text(GTK_LABEL(priv->container_label), g_value_get_string(value)); + } + else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_IMAGE_PATH, property) == 0){ + priv->image_path = g_strdup(g_value_get_string(value)); + update_album_art(mitem); + } +} + +static void update_album_art(MetadataWidget* self){ + MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); + GdkPixbuf* pixbuf; + pixbuf = gdk_pixbuf_new_from_file(priv->image_path, NULL); + pixbuf = gdk_pixbuf_scale_simple(pixbuf,60,60,GDK_INTERP_BILINEAR); + gtk_image_set_from_pixbuf(GTK_IMAGE(priv->album_art), pixbuf); + g_object_unref(pixbuf); } /** -- cgit v1.2.3 From 05e82f2c6a8a72aeb3a589b702e5a9f1d68251d9 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 17 Jun 2010 16:41:54 +0100 Subject: transport plugged in --- src/metadata-widget.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/metadata-widget.c') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index e0dca6e..357c31a 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -176,7 +176,9 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_IMAGE_PATH, property) == 0){ priv->image_path = g_strdup(g_value_get_string(value)); - update_album_art(mitem); + if(priv->image_path != NULL){ + update_album_art(mitem); + } } } @@ -184,11 +186,13 @@ static void update_album_art(MetadataWidget* self){ MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); GdkPixbuf* pixbuf; pixbuf = gdk_pixbuf_new_from_file(priv->image_path, NULL); - pixbuf = gdk_pixbuf_scale_simple(pixbuf,60,60,GDK_INTERP_BILINEAR); + pixbuf = gdk_pixbuf_scale_simple(pixbuf,60, 60,GDK_INTERP_BILINEAR); + g_debug("attempting to set the image with path %s", priv->image_path); gtk_image_set_from_pixbuf(GTK_IMAGE(priv->album_art), pixbuf); g_object_unref(pixbuf); } + /** * transport_new: * @returns: a new #MetadataWidget. -- cgit v1.2.3 From 5f7e8583de28afb9424666bbf9652b9774cf9499 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 17 Jun 2010 18:02:38 +0100 Subject: merge request comments applied --- src/metadata-widget.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/metadata-widget.c') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 357c31a..c4d3b50 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -158,10 +158,13 @@ metadata_widget_button_release_event (GtkWidget *menuitem, return TRUE; } +// TODO: Manage empty/mangled music details etc. static void metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata) { + g_return_if_fail (IS_METADATA_WIDGET (userdata)); + MetadataWidget* mitem = METADATA_WIDGET(userdata); MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(mitem); @@ -175,8 +178,13 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, gtk_label_set_text(GTK_LABEL(priv->container_label), g_value_get_string(value)); } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_IMAGE_PATH, property) == 0){ - priv->image_path = g_strdup(g_value_get_string(value)); - if(priv->image_path != NULL){ + if(priv->image_path != NULL){ + g_free(priv->image_path); + } + + priv->image_path = g_value_dup_string(value); + + if(priv->image_path != NULL){ update_album_art(mitem); } } -- cgit v1.2.3