From 2d40c713f6d5fab70c952e757d0690c7dad63d2d Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 15 Oct 2010 13:59:45 +0100 Subject: updates done for now --- src/familiar-players-db.vala | 22 +++++++++++++++++++++- src/music-player-bridge.vala | 36 +++++------------------------------- src/player-controller.vala | 39 +++++++++++++++++++++------------------ src/title-menu-item.vala | 8 ++++++-- src/title-widget.c | 30 ++++++++++++++++++++++-------- src/title-widget.h | 1 - vapi/common-defs.vapi | 1 + 7 files changed, 76 insertions(+), 61 deletions(-) diff --git a/src/familiar-players-db.vala b/src/familiar-players-db.vala index 894447c..76cc2f1 100644 --- a/src/familiar-players-db.vala +++ b/src/familiar-players-db.vala @@ -153,5 +153,25 @@ public class FamiliarPlayersDB : GLib.Object { return this.players_DB.keys; } - + + public static string? fetch_icon_name(string desktop_path) + { + KeyFile desktop_keyfile = new KeyFile (); + try{ + desktop_keyfile.load_from_file (desktop_path, KeyFileFlags.NONE); + } + catch(GLib.FileError error){ + warning("Error loading keyfile"); + return null; + } + try{ + return desktop_keyfile.get_string (KeyFileDesktop.GROUP, + KeyFileDesktop.KEY_ICON); + } + catch(GLib.KeyFileError error){ + warning("Error trying to fetch the icon name from the keyfile"); + return null; + } + } + } \ No newline at end of file diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index e109dec..9ab1b3c 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -56,17 +56,12 @@ public class MusicPlayerBridge : GLib.Object GLib.AppInfo app_info = info as GLib.AppInfo; PlayerController ctrl = new PlayerController(this.root_menu, - truncate_player_name(app_info.get_name()), + app_info, + playersDB.fetch_icon_name(app), calculate_menu_position(), PlayerController.state.OFFLINE); ctrl.app_info = app_info; - if(ctrl.app_info == null){ - warning("for some reason the app info is null"); - } - else{ - ctrl.set_icon_path(); - } - this.registered_clients.set(determine_key(app), ctrl); + this.registered_clients.set(determine_key(app), ctrl); } } @@ -96,22 +91,14 @@ public class MusicPlayerBridge : GLib.Object { MusicPlayerBridge bridge = data as MusicPlayerBridge; AppInfo? app_info = create_app_info(path); - var name = truncate_player_name(app_info.get_name()); if(path.contains("/") && bridge.playersDB.already_familiar(path) == false){ debug("About to store desktop file path: %s", path); bridge.playersDB.insert(path); PlayerController ctrl = new PlayerController(bridge.root_menu, - name, + app_info, + playersDB.fetch_icon_name(path), bridge.calculate_menu_position(), PlayerController.state.READY); - ctrl.set("app_info", app_info); - if(ctrl.app_info == null){ - warning("for some reason the app info is null"); - } - else{ - ctrl.set_icon_path(); - } - bridge.registered_clients.set(determine_key(path), ctrl); debug("successfully created appinfo and instance from path and set it on the respective instance"); } @@ -163,19 +150,6 @@ public class MusicPlayerBridge : GLib.Object return app_info; } - private static string truncate_player_name(owned string app_info_name) - { - string result = app_info_name.down().strip(); - - var tokens = result.split(" "); - - if(tokens.length > 1){ - result = tokens[0]; - } - debug("truncate player name %s", result); - return result; - } - private static string? determine_key(owned string path) { var tokens = path.split("/"); diff --git a/src/player-controller.vala b/src/player-controller.vala index 4b5144a..06a5b4e 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -49,21 +49,24 @@ public class PlayerController : GLib.Object public Mpris2Controller mpris_bridge; public AppInfo? app_info { get; set;} public int menu_offset { get; set;} + public string icon_name { get; set; } public PlayerController(Dbusmenu.Menuitem root, - string client_name, + AppInfo app_info, + string icon_name, int offset, state initial_state) { this.root_menu = root; - this.name = format_client_name(client_name.strip()); + this.app_info = app_info; + this.icon_name = icon_name; + this.name = format_client_name(truncate_player_name(app_info.get_name())); this.custom_items = new ArrayList(); this.current_state = initial_state; this.menu_offset = offset; construct_widgets(); establish_mpris_connection(); - this.update_layout(); - + this.update_layout(); } public void update_state(state new_state) @@ -168,20 +171,6 @@ public class PlayerController : GLib.Object } return formatted; } - - public void set_icon_path() - { - if(this.app_info != null){ - /*Gtk.IconTheme icon_t = Gtk.IconTheme.get_default(); - Gtk.IconInfo iconInfo = icon_t.lookup_icon(app_info.get_icon(), - getIconSize(), - Gtk.ICON_LOOKUP_USE_BUILTIN);*/ - //return iconInfo.load_icon(); - dbusmenu_menuitem_property_set_image(this.custom_items[widget_order.TITLE], - MENUITEM_PROP_ICON_DATA, - app_info.get_icon()); - } - } // Temporarily we will need to handle to different mpris implemenations // Do it for now - a couple of weeks should see this messy carry on out of @@ -199,4 +188,18 @@ public class PlayerController : GLib.Object this.update_state(state.DISCONNECTED); } } + + private static string truncate_player_name(owned string app_info_name) + { + string result = app_info_name.down().strip(); + + var tokens = result.split(" "); + + if(tokens.length > 1){ + result = tokens[0]; + } + debug("truncate player name %s", result); + return result; + } + } \ No newline at end of file diff --git a/src/title-menu-item.vala b/src/title-menu-item.vala index bb3d103..64ddebf 100644 --- a/src/title-menu-item.vala +++ b/src/title-menu-item.vala @@ -27,7 +27,9 @@ public class TitleMenuitem : PlayerItem { Object(item_type: MENUITEM_TYPE, owner: parent); this.property_set(MENUITEM_NAME, parent.name); - this.property_set_bool(MENUITEM_RUNNING, false); + debug("title init - icon name = %s", parent.icon_name); + this.property_set(MENUITEM_ICON, parent.icon_name); + this.property_set_bool(MENUITEM_RUNNING, false); } public override void handle_event(string name, GLib.Value input_value, uint timestamp) @@ -50,6 +52,8 @@ public class TitleMenuitem : PlayerItem { HashSet attrs = new HashSet(); attrs.add(MENUITEM_NAME); - return attrs; + attrs.add(MENUITEM_RUNNING); + attrs.add(MENUITEM_ICON); + return attrs; } } \ No newline at end of file diff --git a/src/title-widget.c b/src/title-widget.c index d9faa57..344d0a7 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -76,14 +76,23 @@ static void title_widget_init (TitleWidget *self) { //g_debug("TitleWidget::title_widget_init"); +} + +static void +title_widget_set_icon(TitleWidget *self) +{ + TitleWidgetPrivate *priv = TITLE_WIDGET_GET_PRIVATE(self); - gint padding = 0; + gchar* icon_name = dbusmenu_menuitem_property_get(priv->twin_item, + DBUSMENU_TITLE_MENUITEM_ICON); + 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); - GtkWidget * icon = gtk_image_new_from_icon_name("sound-icon", GTK_ICON_SIZE_MENU); + GtkWidget * icon = gtk_image_new_from_icon_name(icon_name, + GTK_ICON_SIZE_MENU); gtk_widget_set_size_request(icon, width + 5 /* ref triangle is 5x9 pixels */ @@ -91,8 +100,7 @@ title_widget_init (TitleWidget *self) 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); - + gtk_widget_show(icon); } static void @@ -130,14 +138,19 @@ title_widget_property_update(DbusmenuMenuitem* item, gchar* property, { g_return_if_fail (IS_TITLE_WIDGET (userdata)); TitleWidget* mitem = TITLE_WIDGET(userdata); - + g_debug("PROPERTY UPDATE FOR THE TITLE"); if(g_ascii_strcasecmp(DBUSMENU_TITLE_MENUITEM_NAME, property) == 0){ gtk_menu_item_set_label (GTK_MENU_ITEM(mitem), g_value_get_string(value)); } - /*else(g_ascii_strcasecmp(DBUSMENU_MENUITEM_PROP_ICON_DATA, property) == 0){ - g_debug("changing the icon data on the title"); - }*/ + else if(g_ascii_strcasecmp(DBUSMENU_TITLE_MENUITEM_ICON, property) == 0){ + g_debug("changing the icon data on the title - %s", + g_value_get_string(value)); + GtkWidget * icon = gtk_image_new_from_icon_name(g_value_get_string(value), + GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mitem), GTK_WIDGET(icon)); + + } } static void @@ -160,6 +173,7 @@ title_widget_set_twin_item(TitleWidget* self, gtk_menu_item_set_label (GTK_MENU_ITEM(self), dbusmenu_menuitem_property_get(priv->twin_item, DBUSMENU_TITLE_MENUITEM_NAME)); + title_widget_set_icon(self); } static gboolean diff --git a/src/title-widget.h b/src/title-widget.h index 1e25775..029aba4 100644 --- a/src/title-widget.h +++ b/src/title-widget.h @@ -20,7 +20,6 @@ with this program. If not, see . #define __TITLE_WIDGET_H__ #include -#include #include diff --git a/vapi/common-defs.vapi b/vapi/common-defs.vapi index 9d49a92..6938420 100644 --- a/vapi/common-defs.vapi +++ b/vapi/common-defs.vapi @@ -36,6 +36,7 @@ namespace DbusmenuTransport{ namespace DbusmenuTitle{ public const string MENUITEM_TYPE; public const string MENUITEM_NAME; + public const string MENUITEM_ICON; public const string MENUITEM_RUNNING; } -- cgit v1.2.3