diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common-defs.h | 2 | ||||
-rw-r--r-- | src/indicator-sound.c | 9 | ||||
-rw-r--r-- | src/metadata-menu-item.vala | 10 | ||||
-rw-r--r-- | src/metadata-widget.c | 126 | ||||
-rw-r--r-- | src/metadata-widget.h | 7 | ||||
-rw-r--r-- | src/player-controller.vala | 5 | ||||
-rw-r--r-- | src/player-item.vala | 2 | ||||
-rw-r--r-- | src/title-widget.c | 3 |
8 files changed, 140 insertions, 24 deletions
diff --git a/src/common-defs.h b/src/common-defs.h index 5f44296..b6799e8 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -67,8 +67,6 @@ typedef enum { #define DBUSMENU_TRANSPORT_MENUITEM_TYPE "x-canonical-sound-menu-player-transport-type" #define DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE "x-canonical-sound-menu-player-transport-state" -#define DBUSMENU_TRACK_SPECIFIC_MENUITEM_TYPE "x-canonical-sound-menu-player-track-specific-type" - #define DBUSMENU_METADATA_MENUITEM_TYPE "x-canonical-sound-menu-player-metadata-type" #define DBUSMENU_METADATA_MENUITEM_ARTIST "x-canonical-sound-menu-player-metadata-xesam:artist" #define DBUSMENU_METADATA_MENUITEM_TITLE "x-canonical-sound-menu-player-metadata-xesam:title" diff --git a/src/indicator-sound.c b/src/indicator-sound.c index da5218f..8daf06c 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -353,12 +353,19 @@ new_metadata_widget (DbusmenuMenuitem * newitem, g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + metadata = metadata_widget_new (newitem); + + g_debug ("%s (\"%s\")", __func__, + dbusmenu_menuitem_property_get(newitem, DBUSMENU_METADATA_MENUITEM_PLAYER_NAME)); + GtkMenuItem *menu_metadata_widget = GTK_MENU_ITEM(metadata); gtk_widget_show_all(metadata); dbusmenu_gtkclient_newitem_base (DBUSMENU_GTKCLIENT(client), - newitem, menu_metadata_widget, parent); + newitem, + menu_metadata_widget, + parent); return TRUE; } diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index 599a9c6..1d50d38 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -18,6 +18,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. */ using Gee; +using Dbusmenu; using DbusmenuMetadata; using Gdk; @@ -32,16 +33,17 @@ public class MetadataMenuitem : PlayerItem public MetadataMenuitem (PlayerController parent) { Object(item_type: MENUITEM_TYPE, owner: parent); - reset(attributes_format()); + //reset(attributes_format()); } construct{ MetadataMenuitem.clean_album_art_temp_dir(); this.previous_temp_album_art_path = null; this.album_art_cache_dir = MetadataMenuitem.create_album_art_temp_dir(); - this.property_set(MENUITEM_PLAYER_NAME, this.owner.app_info.get_name()); - this.property_set(MENUITEM_PLAYER_ICON, this.owner.icon_name); - this.property_set_bool(MENUITEM_PLAYER_RUNNING, false); + debug ("JUST ABOUT TO ATTEMPT PLAYER NAME SETTING %s", this.owner.app_info.get_name()); + this.property_set (MENUITEM_PLAYER_NAME, this.owner.app_info.get_name()); + this.property_set (MENUITEM_PLAYER_ICON, this.owner.icon_name); + this.property_set_bool (MENUITEM_PLAYER_RUNNING, false); } private static void clean_album_art_temp_dir() diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 38ed529..5937eb8 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -28,6 +28,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <gtk/gtk.h> #include <glib.h> #include "transport-widget.h" +#include <libindicator/indicator-image-helper.h> typedef struct _MetadataWidgetPrivate MetadataWidgetPrivate; @@ -41,6 +42,7 @@ struct _MetadataWidgetPrivate GtkWidget* artist_label; GtkWidget* piece_label; GtkWidget* container_label; + GtkWidget* player_label; DbusmenuMenuitem* twin_item; }; @@ -56,7 +58,7 @@ static void metadata_widget_set_style (GtkWidget* button, GtkStyle* style); static void metadata_widget_set_twin_item (MetadataWidget* self, DbusmenuMenuitem* twin_item); // keyevent consumers -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_property_update (DbusmenuMenuitem* item, @@ -71,8 +73,12 @@ static void metadata_widget_selection_received_event_callback( GtkWidget GtkSelectionData *data, guint time, gpointer user_data); -G_DEFINE_TYPE (MetadataWidget, metadata_widget, GTK_TYPE_MENU_ITEM); +static gboolean metadata_widget_triangle_draw_cb (GtkWidget *widget, + GdkEventExpose *event, + gpointer data); +static void metadata_widget_set_icon (MetadataWidget *self); +G_DEFINE_TYPE (MetadataWidget, metadata_widget, GTK_TYPE_IMAGE_MENU_ITEM); static void metadata_widget_class_init (MetadataWidgetClass *klass) @@ -80,7 +86,7 @@ metadata_widget_class_init (MetadataWidgetClass *klass) GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - widget_class->button_press_event = metadata_widget_button_press_event; + widget_class->button_release_event = metadata_widget_button_release_event; g_type_class_add_private (klass, sizeof (MetadataWidgetPrivate)); @@ -91,8 +97,6 @@ metadata_widget_class_init (MetadataWidgetClass *klass) static void metadata_widget_init (MetadataWidget *self) { - //g_debug("MetadataWidget::metadata_widget_init"); - MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); GtkWidget *hbox; @@ -375,8 +379,8 @@ metadata_widget_selection_received_event_callback ( GtkWidget *widget, /* Suppress/consume keyevents */ static gboolean -metadata_widget_button_press_event (GtkWidget *menuitem, - GdkEventButton *event) +metadata_widget_button_release_event (GtkWidget *menuitem, + GdkEventButton *event) { GtkClipboard* board = gtk_clipboard_get (GDK_NONE); @@ -454,9 +458,48 @@ metadata_widget_set_style(GtkWidget* metadata, GtkStyle* style) gtk_widget_queue_draw(GTK_WIDGET(metadata)); } +static void +metadata_widget_set_icon (MetadataWidget *self) +{ + MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); + + gint padding = 0; + gtk_widget_style_get(GTK_WIDGET(self), "horizontal-padding", &padding, NULL); + gint width, height; + gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); + + GString* banshee_string = g_string_new ( "banshee" ); + GString* app_panel = g_string_new ( g_utf8_strdown ( dbusmenu_menuitem_property_get(priv->twin_item, DBUSMENU_METADATA_MENUITEM_PLAYER_NAME), + -1 )); + GtkWidget * icon = NULL; + + // Not ideal but apparently we want the banshee icon to be the greyscale one + // and any others to be the icon from the desktop file => colour. + if ( g_string_equal ( banshee_string, app_panel ) == TRUE && + gtk_icon_theme_has_icon ( gtk_icon_theme_get_default(), app_panel->str ) ){ + g_string_append ( app_panel, "-panel" ); + icon = gtk_image_new_from_icon_name ( app_panel->str, + GTK_ICON_SIZE_MENU ); + } + else{ + icon = gtk_image_new_from_icon_name ( g_strdup (dbusmenu_menuitem_property_get ( priv->twin_item, DBUSMENU_METADATA_MENUITEM_PLAYER_ICON )), + GTK_ICON_SIZE_MENU ); + } + g_string_free ( app_panel, FALSE) ; + g_string_free ( banshee_string, FALSE) ; + + gtk_widget_set_size_request(icon, width + + 5 /* ref triangle is 5x9 pixels */ + + 1 /* padding */, + height); + gtk_misc_set_alignment(GTK_MISC(icon), 0.5 /* right aligned */, 0); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), GTK_WIDGET(icon)); + gtk_widget_show(icon); +} + static void -metadata_widget_set_twin_item(MetadataWidget* self, - DbusmenuMenuitem* twin_item) +metadata_widget_set_twin_item (MetadataWidget* self, + DbusmenuMenuitem* twin_item) { MetadataWidgetPrivate* priv = METADATA_WIDGET_GET_PRIVATE(self); priv->twin_item = twin_item; @@ -479,11 +522,22 @@ metadata_widget_set_twin_item(MetadataWidget* self, g_string_erase(priv->image_path, 0, -1); const gchar *arturl = dbusmenu_menuitem_property_get( priv->twin_item, DBUSMENU_METADATA_MENUITEM_ARTURL ); + + g_signal_connect_after (G_OBJECT (self), + "expose_event", + G_CALLBACK (metadata_widget_triangle_draw_cb), + priv->twin_item); + + gtk_menu_item_set_label (GTK_MENU_ITEM(self), + dbusmenu_menuitem_property_get(priv->twin_item, + DBUSMENU_METADATA_MENUITEM_PLAYER_NAME)); + + metadata_widget_set_icon(self); + if (arturl != NULL){ g_string_overwrite( priv->image_path, 0, arturl); - // if its a remote image queue a redraw incase the download took too long if (g_str_has_prefix (arturl, g_get_user_cache_dir())){ gtk_widget_queue_draw(GTK_WIDGET(self)); @@ -491,6 +545,56 @@ metadata_widget_set_twin_item(MetadataWidget* self, } } + +// Title related ... +static gboolean +metadata_widget_triangle_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) +{ + GtkStyle *style; + cairo_t *cr; + int x, y, arrow_width, arrow_height; + + if (!GTK_IS_WIDGET (widget)) return FALSE; + if (!DBUSMENU_IS_MENUITEM (data)) return FALSE; + + /* render the triangle indicator only if the application is running */ + if (! dbusmenu_menuitem_property_get_bool (DBUSMENU_MENUITEM(data), + DBUSMENU_METADATA_MENUITEM_PLAYER_RUNNING)){ + return FALSE; + } + + /* get style */ + style = gtk_widget_get_style (widget); + + /* set arrow position / dimensions */ + arrow_width = 5; /* the pixel-based reference triangle is 5x9 */ + arrow_height = 9; + x = widget->allocation.x; + y = widget->allocation.y + widget->allocation.height/2.0 - (double)arrow_height/2.0; + + /* initialize cairo drawing area */ + cr = (cairo_t*) gdk_cairo_create (widget->window); + + /* set line width */ + cairo_set_line_width (cr, 1.0); + + /* cairo drawing code */ + cairo_move_to (cr, x, y); + cairo_line_to (cr, x, y + arrow_height); + cairo_line_to (cr, x + arrow_width, y + (double)arrow_height/2.0); + cairo_close_path (cr); + cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0, + style->fg[gtk_widget_get_state(widget)].green/65535.0, + style->fg[gtk_widget_get_state(widget)].blue/65535.0); + cairo_fill (cr); + + /* remember to destroy cairo context to avoid leaks */ + cairo_destroy (cr); + + return FALSE; +} + + /** * transport_new: * @returns: a new #MetadataWidget. @@ -500,6 +604,8 @@ metadata_widget_new(DbusmenuMenuitem *item) { GtkWidget* widget = g_object_new(METADATA_WIDGET_TYPE, NULL); + gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (widget), + TRUE); metadata_widget_set_twin_item ( METADATA_WIDGET(widget), item ); return widget; diff --git a/src/metadata-widget.h b/src/metadata-widget.h index 6021af5..48dc61e 100644 --- a/src/metadata-widget.h +++ b/src/metadata-widget.h @@ -19,7 +19,8 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #ifndef __METADATA_WIDGET_H__ #define __METADATA_WIDGET_H__ -#include <gtk/gtkmenuitem.h> +//#include <gtk/gtkmenuitem.h> +#include <gtk/gtkimagemenuitem.h> #include <libdbusmenu-gtk/menuitem.h> G_BEGIN_DECLS @@ -35,11 +36,11 @@ typedef struct _MetadataWidget MetadataWidget; typedef struct _MetadataWidgetClass MetadataWidgetClass; struct _MetadataWidgetClass { - GtkMenuItemClass parent_class; + GtkImageMenuItemClass parent_class; }; struct _MetadataWidget { - GtkMenuItem parent; + GtkImageMenuItem parent; }; GType metadata_widget_get_type (void); diff --git a/src/player-controller.vala b/src/player-controller.vala index 1ff8b08..a7c1424 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -70,6 +70,7 @@ public class PlayerController : GLib.Object this.construct_widgets(); this.establish_mpris_connection(); this.update_layout(); + debug ("New player controller for %s with icon name %s", this.app_info.get_name(), this.icon_name); } public void update_state(state new_state) @@ -144,8 +145,10 @@ public class PlayerController : GLib.Object { PlaylistsMenuitem playlists_menuitem = this.custom_items[widget_order.PLAYLISTS] as PlaylistsMenuitem; if(this.current_state != state.CONNECTED){ + // TODO + // For now just set the visibility to true so that I can figure out what todo here. this.custom_items[widget_order.METADATA].property_set_bool (MENUITEM_PROP_VISIBLE, - false); + true); playlists_menuitem.root_item.property_set_bool (MENUITEM_PROP_VISIBLE, false ); this.custom_items[widget_order.TRANSPORT].property_set_bool (MENUITEM_PROP_VISIBLE, diff --git a/src/player-item.vala b/src/player-item.vala index f71b166..cb21115 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -87,7 +87,7 @@ public class PlayerItem : Dbusmenu.Menuitem this.property_set_bool(property, v.get_boolean()); } } - this.property_set_bool(MENUITEM_PROP_VISIBLE, populated(attributes)); + //this.property_set_bool(MENUITEM_PROP_VISIBLE, populated(attributes)); } public bool populated(HashSet<string> attrs) diff --git a/src/title-widget.c b/src/title-widget.c index b8058b8..e463582 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -116,8 +116,7 @@ title_widget_set_icon(TitleWidget *self) gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), GTK_WIDGET(icon)); gtk_widget_show(icon); } - - + static void title_widget_dispose (GObject *object) { |