From 3c93168a4518426fb28f06c3635b7f32fad2f6a1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 13:48:53 -0600 Subject: Adding API for getting items --- src/app-menu-item.c | 8 ++++++++ src/app-menu-item.h | 1 + 2 files changed, 9 insertions(+) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 5fc2a9c..b1b2a02 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -309,3 +309,11 @@ app_menu_item_get_desktop (AppMenuItem * appitem) AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(appitem); return priv->desktop; } + +/* Get the dynamic items added onto the end of + and app entry. */ +GList * +app_menu_item_get_items (AppMenuItem * appitem) +{ + return NULL; +} diff --git a/src/app-menu-item.h b/src/app-menu-item.h index 583d50d..fe16c75 100644 --- a/src/app-menu-item.h +++ b/src/app-menu-item.h @@ -60,6 +60,7 @@ guint app_menu_item_get_count (AppMenuItem * appitem); IndicateListenerServer * app_menu_item_get_server (AppMenuItem * appitem); const gchar * app_menu_item_get_name (AppMenuItem * appitem); const gchar * app_menu_item_get_desktop (AppMenuItem * appitem); +GList * app_menu_item_get_items (AppMenuItem * appitem); G_END_DECLS -- cgit v1.2.3 From d307fee44ed8e2588c23a9461a44b0d86362e53c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 14:17:18 -0600 Subject: Fleshing out menu_cb, lots of avenues for expantion in other directions now. --- src/app-menu-item.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index b1b2a02..ece5a83 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -26,6 +26,7 @@ with this program. If not, see . #include #include +#include #include "app-menu-item.h" #include "dbus-data.h" @@ -48,6 +49,9 @@ struct _AppMenuItemPrivate GAppInfo * appinfo; gchar * desktop; guint unreadcount; + + DbusmenuClient * client; + DbusmenuMenuitem * root; }; #define APP_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), APP_MENU_ITEM_TYPE, AppMenuItemPrivate)) @@ -60,6 +64,7 @@ static void app_menu_item_finalize (GObject *object); static void activate_cb (AppMenuItem * self, guint timestamp, gpointer data); static void count_changed (IndicateListener * listener, IndicateListenerServer * server, guint count, gpointer data); static void count_cb (IndicateListener * listener, IndicateListenerServer * server, guint value, gpointer data); +static void menu_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * menupath, gpointer data); static void desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data); static void update_label (AppMenuItem * self); @@ -168,6 +173,7 @@ app_menu_item_new (IndicateListener * listener, IndicateListenerServer * server) /* Get the values we care about from the server */ indicate_listener_server_get_desktop(listener, server, desktop_cb, self); indicate_listener_server_get_count(listener, server, count_cb, self); + indicate_listener_server_get_menu(listener, server, menu_cb, self); g_signal_connect(G_OBJECT(self), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), NULL); @@ -262,6 +268,27 @@ desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar return; } +static void +root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer user_data) +{ + + +} + +/* Gets the path to menuitems if there are some. Now we need to + make them special. */ +static void +menu_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * menupath, gpointer data) +{ + AppMenuItem * self = APP_MENU_ITEM(data); + AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); + + priv->client = dbusmenu_client_new(indicate_listener_server_get_dbusname(server), menupath); + g_signal_connect(G_OBJECT(priv->client), DBUSMENU_CLIENT_SIGNAL_ROOT_CHANGED, G_CALLBACK(root_changed), self); + + return; +} + static void activate_cb (AppMenuItem * self, guint timestamp, gpointer data) { -- cgit v1.2.3 From 1728c0be0db166c30a2e2b2a5373d135b404d3ed Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 14:22:15 -0600 Subject: Init and cleanup the client and root private properties. --- src/app-menu-item.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index ece5a83..67f616a 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -112,6 +112,9 @@ app_menu_item_init (AppMenuItem *self) priv->desktop = NULL; priv->unreadcount = 0; + priv->client = NULL; + priv->root = NULL; + return; } @@ -122,8 +125,20 @@ app_menu_item_dispose (GObject *object) AppMenuItem * self = APP_MENU_ITEM(object); AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); - g_signal_handlers_disconnect_by_func(G_OBJECT(priv->listener), count_changed, self); - g_object_unref(priv->listener); + if (priv->listener != NULL) { + g_signal_handlers_disconnect_by_func(G_OBJECT(priv->listener), count_changed, self); + g_object_unref(priv->listener); + } + + if (priv->root != NULL) { + g_object_unref(priv->root); + priv->root = NULL; + } + + if (priv->client != NULL) { + g_object_unref(priv->client); + priv->client = NULL; + } G_OBJECT_CLASS (app_menu_item_parent_class)->dispose (object); } -- cgit v1.2.3 From de7363b6804d843f9c8c9a692297570bf1a19cfe Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 14:56:52 -0600 Subject: Handling root item changes. Mostly. --- src/app-menu-item.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 67f616a..5d53053 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -27,6 +27,7 @@ with this program. If not, see . #include #include #include +#include #include "app-menu-item.h" #include "dbus-data.h" @@ -51,7 +52,7 @@ struct _AppMenuItemPrivate guint unreadcount; DbusmenuClient * client; - DbusmenuMenuitem * root; + DbusmenuMenuitemProxy * root; }; #define APP_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), APP_MENU_ITEM_TYPE, AppMenuItemPrivate)) @@ -284,10 +285,63 @@ desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar } static void -root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer user_data) +child_added_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint position, gpointer user_data) { + return; +} + +static void +child_removed_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, gpointer user_data) +{ + + return; +} +static void +child_moved_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint newpos, guint oldpos, gpointer user_data) +{ + + return; +} + +/* We've got a new root. We need to proxy it and handle it's children + if that's a relevant thing to do. */ +static void +root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer data) +{ + AppMenuItem * self = APP_MENU_ITEM(data); + AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); + gboolean change_time = FALSE; + + if (priv->root != NULL) { + if (dbusmenu_menuitem_get_children(DBUSMENU_MENUITEM(priv->root)) != NULL) { + change_time = TRUE; + } + g_object_unref(priv->root); + priv->root = NULL; + } + + /* We need to proxy the new root across to the old + world of indicator land. */ + priv->root = dbusmenu_menuitem_proxy_new(newroot); + g_signal_connect(G_OBJECT(priv->root), DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED, G_CALLBACK(child_added_cb), self); + g_signal_connect(G_OBJECT(priv->root), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(child_removed_cb), self); + g_signal_connect(G_OBJECT(priv->root), DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED, G_CALLBACK(child_moved_cb), self); + + /* See if we have any menuitems to worry about, + otherwise we'll just move along. */ + GList * children = dbusmenu_menuitem_get_children(DBUSMENU_MENUITEM(priv->root)); + if (children != NULL) { + change_time = TRUE; + } + + if (change_time) { + /* Signal that something has changed */ + change_time = FALSE; + } + + return; } /* Gets the path to menuitems if there are some. Now we need to -- cgit v1.2.3 From 958bb92e0346294d34d7628061faf134f1043621 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 15:01:13 -0600 Subject: Adding in a shortcuts changed signal --- src/app-menu-item.c | 8 ++++++++ src/app-menu-item.h | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 5d53053..e9ba0f1 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -34,6 +34,7 @@ with this program. If not, see . enum { COUNT_CHANGED, NAME_CHANGED, + SHORTCUTS_CHANGED, LAST_SIGNAL }; @@ -96,6 +97,13 @@ app_menu_item_class_init (AppMenuItemClass *klass) NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); + signals[SHORTCUTS_CHANGED] = g_signal_new(APP_MENU_ITEM_SIGNAL_SHORTCUTS_CHANGED, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (AppMenuItemClass, shortcuts_changed), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0, G_TYPE_NONE); return; } diff --git a/src/app-menu-item.h b/src/app-menu-item.h index fe16c75..48a7cfa 100644 --- a/src/app-menu-item.h +++ b/src/app-menu-item.h @@ -37,8 +37,9 @@ G_BEGIN_DECLS #define IS_APP_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), APP_MENU_ITEM_TYPE)) #define APP_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), APP_MENU_ITEM_TYPE, AppMenuItemClass)) -#define APP_MENU_ITEM_SIGNAL_COUNT_CHANGED "count-changed" -#define APP_MENU_ITEM_SIGNAL_NAME_CHANGED "name-changed" +#define APP_MENU_ITEM_SIGNAL_COUNT_CHANGED "count-changed" +#define APP_MENU_ITEM_SIGNAL_NAME_CHANGED "name-changed" +#define APP_MENU_ITEM_SIGNAL_SHORTCUTS_CHANGED "shortcuts-changed" typedef struct _AppMenuItem AppMenuItem; typedef struct _AppMenuItemClass AppMenuItemClass; @@ -48,6 +49,7 @@ struct _AppMenuItemClass { void (* count_changed) (guint count); void (* name_changed) (gchar * name); + void (* shortcuts_changed) (void); }; struct _AppMenuItem { -- cgit v1.2.3 From ed9e77cb4d6bf3359138c28153a316ad5418be83 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 15:03:21 -0600 Subject: Emitting the new signal all over the place. --- src/app-menu-item.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index e9ba0f1..59b435a 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -292,24 +292,30 @@ desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar return; } +/* Relay this signal into causing a rebuild of the shortcuts + from those above us. */ static void child_added_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint position, gpointer user_data) { - + g_signal_emit(G_OBJECT(user_data), APP_MENU_ITEM_SIGNAL_SHORTCUTS_CHANGED, 0, TRUE); return; } +/* Relay this signal into causing a rebuild of the shortcuts + from those above us. */ static void child_removed_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, gpointer user_data) { - + g_signal_emit(G_OBJECT(user_data), APP_MENU_ITEM_SIGNAL_SHORTCUTS_CHANGED, 0, TRUE); return; } +/* Relay this signal into causing a rebuild of the shortcuts + from those above us. */ static void child_moved_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint newpos, guint oldpos, gpointer user_data) { - + g_signal_emit(G_OBJECT(user_data), APP_MENU_ITEM_SIGNAL_SHORTCUTS_CHANGED, 0, TRUE); return; } @@ -345,8 +351,7 @@ root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer data } if (change_time) { - /* Signal that something has changed */ - change_time = FALSE; + g_signal_emit(G_OBJECT(self), APP_MENU_ITEM_SIGNAL_SHORTCUTS_CHANGED, 0, TRUE); } return; -- cgit v1.2.3 From 7c08cb9a551c4c9c58bf7ebc1b591471479e9d73 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 15:20:24 -0600 Subject: Oops, wrong signal name for this function. --- src/app-menu-item.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 59b435a..2f96c49 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -297,7 +297,7 @@ desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar static void child_added_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint position, gpointer user_data) { - g_signal_emit(G_OBJECT(user_data), APP_MENU_ITEM_SIGNAL_SHORTCUTS_CHANGED, 0, TRUE); + g_signal_emit(G_OBJECT(user_data), signals[SHORTCUTS_CHANGED], 0, TRUE); return; } @@ -306,7 +306,7 @@ child_added_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint positio static void child_removed_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, gpointer user_data) { - g_signal_emit(G_OBJECT(user_data), APP_MENU_ITEM_SIGNAL_SHORTCUTS_CHANGED, 0, TRUE); + g_signal_emit(G_OBJECT(user_data), signals[SHORTCUTS_CHANGED], 0, TRUE); return; } @@ -315,7 +315,7 @@ child_removed_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, gpointer us static void child_moved_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint newpos, guint oldpos, gpointer user_data) { - g_signal_emit(G_OBJECT(user_data), APP_MENU_ITEM_SIGNAL_SHORTCUTS_CHANGED, 0, TRUE); + g_signal_emit(G_OBJECT(user_data), signals[SHORTCUTS_CHANGED], 0, TRUE); return; } @@ -351,7 +351,7 @@ root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer data } if (change_time) { - g_signal_emit(G_OBJECT(self), APP_MENU_ITEM_SIGNAL_SHORTCUTS_CHANGED, 0, TRUE); + g_signal_emit(G_OBJECT(self), signals[SHORTCUTS_CHANGED], 0, TRUE); } return; -- cgit v1.2.3 From 3bd80ee8e9bfa1c2b50225b67349eaff8bbeafa2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 15:41:38 -0600 Subject: Adding a list to put the shortcuts in --- src/app-menu-item.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 2f96c49..58c8a02 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -54,6 +54,7 @@ struct _AppMenuItemPrivate DbusmenuClient * client; DbusmenuMenuitemProxy * root; + GList * shortcuts; }; #define APP_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), APP_MENU_ITEM_TYPE, AppMenuItemPrivate)) @@ -123,10 +124,19 @@ app_menu_item_init (AppMenuItem *self) priv->client = NULL; priv->root = NULL; + priv->shortcuts = NULL; return; } +/* A wrapper to make the prototypes work for GFunc */ +static void +func_unref (gpointer data, gpointer user_data) +{ + g_object_unref(G_OBJECT(data)); + return; +} + /* Disconnect the count_changed signal and unref the listener */ static void app_menu_item_dispose (GObject *object) @@ -139,6 +149,13 @@ app_menu_item_dispose (GObject *object) g_object_unref(priv->listener); } + if (priv->shortcuts != NULL) { + g_list_foreach(priv->shortcuts, func_unref, NULL); + g_list_free(priv->shortcuts); + priv->shortcuts = NULL; + g_signal_emit(object, signals[SHORTCUTS_CHANGED], 0, TRUE); + } + if (priv->root != NULL) { g_object_unref(priv->root); priv->root = NULL; -- cgit v1.2.3 From 072da6cccd26225f1528bf09917dd38006f9bd7d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 16:10:18 -0600 Subject: Realized that we can't proxy the root as the items can't then have two parents, and they need to exist with a parent in the menu that we're building. So we have to leave the proxy items unparented until they get picked up in the service themselves. --- src/app-menu-item.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 58c8a02..53d4afa 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -53,7 +53,7 @@ struct _AppMenuItemPrivate guint unreadcount; DbusmenuClient * client; - DbusmenuMenuitemProxy * root; + DbusmenuMenuitem * root; GList * shortcuts; }; @@ -312,27 +312,70 @@ desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar /* Relay this signal into causing a rebuild of the shortcuts from those above us. */ static void -child_added_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint position, gpointer user_data) +child_added_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint position, gpointer data) { - g_signal_emit(G_OBJECT(user_data), signals[SHORTCUTS_CHANGED], 0, TRUE); + AppMenuItem * self = APP_MENU_ITEM(data); + AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); + DbusmenuMenuitemProxy * mip = dbusmenu_menuitem_proxy_new(child); + + priv->shortcuts = g_list_insert(priv->shortcuts, mip, position); + + g_signal_emit(G_OBJECT(data), signals[SHORTCUTS_CHANGED], 0, TRUE); return; } /* Relay this signal into causing a rebuild of the shortcuts from those above us. */ static void -child_removed_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, gpointer user_data) +child_removed_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, gpointer data) { - g_signal_emit(G_OBJECT(user_data), signals[SHORTCUTS_CHANGED], 0, TRUE); + AppMenuItem * self = APP_MENU_ITEM(data); + AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); + + GList * pitems = priv->shortcuts; + while (pitems != NULL) { + DbusmenuMenuitemProxy * mip = DBUSMENU_MENUITEM_PROXY(pitems->data); + + if (dbusmenu_menuitem_proxy_get_wrapped(mip) == child) { + break; + } + + pitems = g_list_next(pitems); + } + + if (pitems != NULL) { + DbusmenuMenuitemProxy * mip = DBUSMENU_MENUITEM_PROXY(pitems->data); + g_object_unref(mip); + priv->shortcuts = g_list_remove(priv->shortcuts, mip); + + g_signal_emit(G_OBJECT(data), signals[SHORTCUTS_CHANGED], 0, TRUE); + } + return; } /* Relay this signal into causing a rebuild of the shortcuts from those above us. */ static void -child_moved_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint newpos, guint oldpos, gpointer user_data) +child_moved_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint newpos, guint oldpos, gpointer data) { - g_signal_emit(G_OBJECT(user_data), signals[SHORTCUTS_CHANGED], 0, TRUE); + AppMenuItem * self = APP_MENU_ITEM(data); + AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); + + DbusmenuMenuitemProxy * mip = DBUSMENU_MENUITEM_PROXY(g_list_nth_data(priv->shortcuts, oldpos)); + + if (mip != NULL) { + if (dbusmenu_menuitem_proxy_get_wrapped(mip) != child) { + mip = NULL; + } + } + + if (mip != NULL) { + priv->shortcuts = g_list_remove(priv->shortcuts, mip); + priv->shortcuts = g_list_insert(priv->shortcuts, mip, newpos); + g_signal_emit(G_OBJECT(data), signals[SHORTCUTS_CHANGED], 0, TRUE); + } + return; } @@ -348,6 +391,9 @@ root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer data if (priv->root != NULL) { if (dbusmenu_menuitem_get_children(DBUSMENU_MENUITEM(priv->root)) != NULL) { change_time = TRUE; + g_list_foreach(priv->shortcuts, func_unref, NULL); + g_list_free(priv->shortcuts); + priv->shortcuts = NULL; } g_object_unref(priv->root); priv->root = NULL; @@ -355,7 +401,8 @@ root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer data /* We need to proxy the new root across to the old world of indicator land. */ - priv->root = dbusmenu_menuitem_proxy_new(newroot); + priv->root = newroot; + g_object_ref(priv->root); g_signal_connect(G_OBJECT(priv->root), DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED, G_CALLBACK(child_added_cb), self); g_signal_connect(G_OBJECT(priv->root), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(child_removed_cb), self); g_signal_connect(G_OBJECT(priv->root), DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED, G_CALLBACK(child_moved_cb), self); @@ -365,6 +412,10 @@ root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer data GList * children = dbusmenu_menuitem_get_children(DBUSMENU_MENUITEM(priv->root)); if (children != NULL) { change_time = TRUE; + while (children != NULL) { + DbusmenuMenuitemProxy * mip = dbusmenu_menuitem_proxy_new(DBUSMENU_MENUITEM(children->data)); + priv->shortcuts = g_list_append(priv->shortcuts, mip); + } } if (change_time) { -- cgit v1.2.3 From aa1f03448025d8a0be2a84db6a07430f9b26e941 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 16:40:47 -0600 Subject: Getting the shortcuts in, and handling changes of them. --- src/messages-service.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index 585589a..6b4f7c6 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -31,6 +31,7 @@ with this program. If not, see . #include #include +#include #include "im-menu-item.h" #include "app-menu-item.h" @@ -51,6 +52,7 @@ static MessageServiceDbus * dbus_interface = NULL; #define DESKTOP_FILE_GROUP "Messaging Menu" #define DESKTOP_FILE_KEY_DESKTOP "DesktopFile" +static void server_shortcuts_changed (AppMenuItem * appitem, gpointer data); static void server_count_changed (AppMenuItem * appitem, guint count, gpointer data); static void server_name_changed (AppMenuItem * appitem, gchar * name, gpointer data); static void im_time_changed (ImMenuItem * imitem, glong seconds, gpointer data); @@ -582,11 +584,20 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha /* Connect the signals up to the menu item */ g_signal_connect(G_OBJECT(menuitem), APP_MENU_ITEM_SIGNAL_COUNT_CHANGED, G_CALLBACK(server_count_changed), sl_item); g_signal_connect(G_OBJECT(menuitem), APP_MENU_ITEM_SIGNAL_NAME_CHANGED, G_CALLBACK(server_name_changed), menushell); + g_signal_connect(G_OBJECT(menuitem), APP_MENU_ITEM_SIGNAL_SHORTCUTS_CHANGED, G_CALLBACK(server_shortcuts_changed), menushell); /* Put our new menu item in, with the separator behind it. resort_menu will take care of whether it should be hidden or not. */ dbusmenu_menuitem_child_append(menushell, DBUSMENU_MENUITEM(menuitem)); + + GList * shortcuts = app_menu_item_get_items(sl_item->menuitem); + while (shortcuts != NULL) { + DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(shortcuts->data); + dbusmenu_menuitem_child_append(menushell, mi); + shortcuts = g_list_next(shortcuts); + } + dbusmenu_menuitem_child_append(menushell, DBUSMENU_MENUITEM(sl_item->separator)); resort_menu(menushell); @@ -595,6 +606,46 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha return; } +/* The shortcuts have changed, let's just remove them and put + the back. */ +static void +server_shortcuts_changed (AppMenuItem * appitem, gpointer data) +{ + DbusmenuMenuitem * shell = DBUSMENU_MENUITEM(data); + gboolean appitemfound = FALSE; + GList * children = dbusmenu_menuitem_get_children(shell); + GList * removelist = NULL; + + while (children != NULL) { + if (!appitemfound && children->data != appitem) { + children = g_list_next(children); + continue; + } + appitemfound = TRUE; + + if (!DBUSMENU_IS_MENUITEM_PROXY(children->data)) { + break; + } + + removelist = g_list_prepend(removelist, children->data); + } + + GList * removeitem; + for (removeitem = removelist; removeitem != NULL; removeitem = g_list_next(removeitem)) { + dbusmenu_menuitem_child_delete(shell, DBUSMENU_MENUITEM(removeitem->data)); + } + g_list_free(removeitem); + + GList * shortcuts = app_menu_item_get_items(appitem); + while (shortcuts != NULL) { + DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(shortcuts->data); + dbusmenu_menuitem_child_append(shell, mi); + shortcuts = g_list_next(shortcuts); + } + + return; +} + /* The name of a server has changed, we probably need to reorder the menu to keep it in alphabetical order. This happens often after we read the destkop -- cgit v1.2.3 From 09c3405e449b936d3fce4fd85618dd4e60aaa77c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 16:43:04 -0600 Subject: Moving the shortcuts along with the app item --- src/messages-service.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index 6b4f7c6..c1af270 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -882,6 +882,15 @@ resort_menu (DbusmenuMenuitem * menushell) g_debug("\tMoving app %s to position %d", INDICATE_LISTENER_SERVER_DBUS_NAME(si->server), position); dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(si->menuitem), position); position++; + + /* Inserting the shortcuts from the launcher */ + GList * shortcuts = app_menu_item_get_items(si->menuitem); + while (shortcuts != NULL) { + g_debug("\t\tMoving shortcut to position %d", position); + dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(shortcuts->data), position); + position++; + shortcuts = g_list_next(shortcuts); + } } /* Putting all the indicators that are related to this application -- cgit v1.2.3 From bcc596a2912f66658058d14f8e30b04cb67915e5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 20:31:16 -0600 Subject: Adding some debug messages --- src/app-menu-item.c | 2 ++ src/messages-service.c | 3 +++ 2 files changed, 5 insertions(+) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 53d4afa..57a4e6a 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -384,6 +384,7 @@ child_moved_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint newpos, static void root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer data) { + g_debug("Root Changed"); AppMenuItem * self = APP_MENU_ITEM(data); AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); gboolean change_time = FALSE; @@ -412,6 +413,7 @@ root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer data GList * children = dbusmenu_menuitem_get_children(DBUSMENU_MENUITEM(priv->root)); if (children != NULL) { change_time = TRUE; + g_debug("\tProcessing %d children", g_list_length(children)); while (children != NULL) { DbusmenuMenuitemProxy * mip = dbusmenu_menuitem_proxy_new(DBUSMENU_MENUITEM(children->data)); priv->shortcuts = g_list_append(priv->shortcuts, mip); diff --git a/src/messages-service.c b/src/messages-service.c index c1af270..0cbb91a 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -594,6 +594,7 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha GList * shortcuts = app_menu_item_get_items(sl_item->menuitem); while (shortcuts != NULL) { DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(shortcuts->data); + g_debug("\tAdding shortcut: %s", dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_LABEL)); dbusmenu_menuitem_child_append(menushell, mi); shortcuts = g_list_next(shortcuts); } @@ -611,6 +612,7 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha static void server_shortcuts_changed (AppMenuItem * appitem, gpointer data) { + g_debug("Application Shortcuts changed"); DbusmenuMenuitem * shell = DBUSMENU_MENUITEM(data); gboolean appitemfound = FALSE; GList * children = dbusmenu_menuitem_get_children(shell); @@ -639,6 +641,7 @@ server_shortcuts_changed (AppMenuItem * appitem, gpointer data) GList * shortcuts = app_menu_item_get_items(appitem); while (shortcuts != NULL) { DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(shortcuts->data); + g_debug("\tAdding shortcut: %s", dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_LABEL)); dbusmenu_menuitem_child_append(shell, mi); shortcuts = g_list_next(shortcuts); } -- cgit v1.2.3 From 0d8b02c5c23e4e66d99481888e8e82baa937ce8f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 20:31:48 -0600 Subject: If we already have children, make sure to process them right away. --- src/app-menu-item.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 57a4e6a..19179c8 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -432,12 +432,18 @@ root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer data static void menu_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * menupath, gpointer data) { + g_debug("Got Menu: %s", menupath); AppMenuItem * self = APP_MENU_ITEM(data); AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); priv->client = dbusmenu_client_new(indicate_listener_server_get_dbusname(server), menupath); g_signal_connect(G_OBJECT(priv->client), DBUSMENU_CLIENT_SIGNAL_ROOT_CHANGED, G_CALLBACK(root_changed), self); + DbusmenuMenuitem * root = dbusmenu_client_get_root(priv->client); + if (root != NULL) { + root_changed(priv->client, root, self); + } + return; } -- cgit v1.2.3 From 1df34439fe9a32a2f9f3288d500fdb8a53046185 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 20:41:56 -0600 Subject: Eh, forgot to flesh out the lists --- src/app-menu-item.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 19179c8..e24d43b 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -500,5 +500,7 @@ app_menu_item_get_desktop (AppMenuItem * appitem) GList * app_menu_item_get_items (AppMenuItem * appitem) { - return NULL; + g_return_val_if_fail(IS_APP_MENU_ITEM(appitem), NULL); + AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(appitem); + return priv->shortcuts; } -- cgit v1.2.3 From 88f7d844a5bfbbd3797fef798086d0cd3ea1a59c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 20:47:52 -0600 Subject: Did I ever talk to you about why I hate while loops? I have to stop using them. They just lead to bugs. --- src/app-menu-item.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index e24d43b..b55de2f 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -417,6 +417,7 @@ root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer data while (children != NULL) { DbusmenuMenuitemProxy * mip = dbusmenu_menuitem_proxy_new(DBUSMENU_MENUITEM(children->data)); priv->shortcuts = g_list_append(priv->shortcuts, mip); + children = g_list_next(children); } } -- cgit v1.2.3 From 17b4a50fb7468506c371ae6429238afc9fdcfb2c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 20:59:29 -0600 Subject: Do a resort after adding new items. --- src/messages-service.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index 0cbb91a..1a5a196 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -646,6 +646,8 @@ server_shortcuts_changed (AppMenuItem * appitem, gpointer data) shortcuts = g_list_next(shortcuts); } + resort_menu(shell); + return; } -- cgit v1.2.3 From 536034bb020f39dcf45d9a0d636f3f5dbd55deb7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 18 Feb 2010 08:38:39 -0600 Subject: Setting the listener to NULL after unrefing it. --- src/app-menu-item.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index b55de2f..8e1c50f 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -147,6 +147,7 @@ app_menu_item_dispose (GObject *object) if (priv->listener != NULL) { g_signal_handlers_disconnect_by_func(G_OBJECT(priv->listener), count_changed, self); g_object_unref(priv->listener); + priv->listener = NULL; } if (priv->shortcuts != NULL) { -- cgit v1.2.3 From 06a4fba68ccbdc5b490cd8a9709e4426ec80a0ff Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 18 Feb 2010 08:41:56 -0600 Subject: Adding protection from data fields by checking to ensure they're AppMenuItems --- src/app-menu-item.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 8e1c50f..2fb24f6 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -254,6 +254,7 @@ update_label (AppMenuItem * self) static void count_changed (IndicateListener * listener, IndicateListenerServer * server, guint count, gpointer data) { + g_return_if_fail(IS_APP_MENU_ITEM(data)); AppMenuItem * self = APP_MENU_ITEM(data); AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); @@ -282,6 +283,7 @@ count_cb (IndicateListener * listener, IndicateListenerServer * server, guint va static void desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data) { + g_return_if_fail(IS_APP_MENU_ITEM(data)); AppMenuItem * self = APP_MENU_ITEM(data); AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); @@ -315,6 +317,7 @@ desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar static void child_added_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint position, gpointer data) { + g_return_if_fail(IS_APP_MENU_ITEM(data)); AppMenuItem * self = APP_MENU_ITEM(data); AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); DbusmenuMenuitemProxy * mip = dbusmenu_menuitem_proxy_new(child); @@ -330,6 +333,7 @@ child_added_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint positio static void child_removed_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, gpointer data) { + g_return_if_fail(IS_APP_MENU_ITEM(data)); AppMenuItem * self = APP_MENU_ITEM(data); AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); @@ -360,6 +364,7 @@ child_removed_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, gpointer da static void child_moved_cb (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint newpos, guint oldpos, gpointer data) { + g_return_if_fail(IS_APP_MENU_ITEM(data)); AppMenuItem * self = APP_MENU_ITEM(data); AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); @@ -435,6 +440,7 @@ static void menu_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * menupath, gpointer data) { g_debug("Got Menu: %s", menupath); + g_return_if_fail(IS_APP_MENU_ITEM(data)); AppMenuItem * self = APP_MENU_ITEM(data); AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); -- cgit v1.2.3