aboutsummaryrefslogtreecommitdiff
path: root/src/messages-service.c
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-05-31 15:59:02 +0200
committerLars Uebernickel <lars.uebernickel@canonical.com>2012-05-31 15:59:02 +0200
commit0f9764c90a24880a5bda8ff047585ef65958cad4 (patch)
treee002af80496abecd2ccc7650d523a6f495a9feea /src/messages-service.c
parentcb34c1a8d430a21330edc0119a6b74642f77c274 (diff)
downloadayatana-indicator-messages-0f9764c90a24880a5bda8ff047585ef65958cad4.tar.gz
ayatana-indicator-messages-0f9764c90a24880a5bda8ff047585ef65958cad4.tar.bz2
ayatana-indicator-messages-0f9764c90a24880a5bda8ff047585ef65958cad4.zip
Remove an application from the menu after it unregistered
Diffstat (limited to 'src/messages-service.c')
-rw-r--r--src/messages-service.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/src/messages-service.c b/src/messages-service.c
index 7c1a2b5..134c4ee 100644
--- a/src/messages-service.c
+++ b/src/messages-service.c
@@ -56,7 +56,7 @@ add_application (const gchar *desktop_id,
appinfo = g_desktop_app_info_new (desktop_id);
if (!appinfo) {
- g_warning ("could not find a desktop file with id '%s'\n", desktop_id);
+ g_warning ("could not add '%s', there's no desktop file with that id", desktop_id);
return;
}
@@ -76,6 +76,55 @@ add_application (const gchar *desktop_id,
g_object_unref (appinfo);
}
+/* g_menu_model_find_section:
+ *
+ * @Returns the index of the first menu item that is linked to #section, or -1
+ * if there's no such item.
+ */
+static int
+g_menu_find_section (GMenu *menu,
+ GMenuModel *section)
+{
+ int n_items = g_menu_model_get_n_items (G_MENU_MODEL (menu));
+ int i;
+
+ for (i = 0; i < n_items; i++) {
+ if (section == g_menu_model_get_item_link (G_MENU_MODEL (menu), i, G_MENU_LINK_SECTION))
+ return i;
+ }
+
+ return -1;
+}
+
+static void
+remove_application (const char *desktop_id)
+{
+ GDesktopAppInfo *appinfo;
+ const gchar *desktop_file;
+ AppMenuItem *menuitem;
+
+ appinfo = g_desktop_app_info_new (desktop_id);
+ if (!appinfo) {
+ g_warning ("could not remove '%s', there's no desktop file with that id", desktop_id);
+ return;
+ }
+
+ desktop_file = g_desktop_app_info_get_filename (appinfo);
+
+ menuitem = g_hash_table_lookup (applications, desktop_file);
+ if (menuitem) {
+ int pos = g_menu_find_section (menu, app_menu_item_get_menu (menuitem));
+ if (pos >= 0)
+ g_menu_remove (menu, pos);
+ }
+ else {
+ g_warning ("could not remove '%s', it's not registered", desktop_id);
+ }
+
+ g_hash_table_remove (applications, desktop_file);
+ g_object_unref (appinfo);
+}
+
/* This function turns a specific desktop id into a menu
item and registers it appropriately with everyone */
static gboolean
@@ -185,6 +234,8 @@ unregister_application (MessageServiceDbus *msd,
g_settings_set_value (settings, "applications",
g_variant_builder_end (&builder));
+ remove_application (desktop_id);
+
g_strfreev (applications);
}