diff options
Diffstat (limited to 'src/metadata-widget.c')
-rw-r--r-- | src/metadata-widget.c | 75 |
1 files changed, 56 insertions, 19 deletions
diff --git a/src/metadata-widget.c b/src/metadata-widget.c index a451ad7..c4d3b50 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(gchar * property, - GValue * value, - gpointer userdata); -//static void update_content( +static void metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, + GValue* value, gpointer userdata); + +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); @@ -159,11 +158,49 @@ metadata_widget_button_release_event (GtkWidget *menuitem, return TRUE; } -static void metadata_widget_update_state(gchar *property, GValue *value, gpointer userdata) +// TODO: Manage empty/mangled music details <unknown artist> etc. +static void +metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, + GValue* value, gpointer userdata) { - g_debug("metadata_widget_update_state - with property %s", property); + g_return_if_fail (IS_METADATA_WIDGET (userdata)); + + 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)); + } + 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){ + 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); + } + } } +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); + 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. |