aboutsummaryrefslogtreecommitdiff
path: root/src/im-desktop-menu.c
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-08-27 12:35:02 +0200
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-08-27 12:35:02 +0200
commite1050a9ceed9cfd0c31ebcaf1d4abb931c5d62ed (patch)
treea78bf0a5acc3a40fce5e0acdc07b6a9d50ae7a91 /src/im-desktop-menu.c
parent0eae4379c30b5afe8f21f88b30c7ce5d795556d0 (diff)
downloadayatana-indicator-messages-e1050a9ceed9cfd0c31ebcaf1d4abb931c5d62ed.tar.gz
ayatana-indicator-messages-e1050a9ceed9cfd0c31ebcaf1d4abb931c5d62ed.tar.bz2
ayatana-indicator-messages-e1050a9ceed9cfd0c31ebcaf1d4abb931c5d62ed.zip
desktop menu: don't show sources with a count of 0
Diffstat (limited to 'src/im-desktop-menu.c')
-rw-r--r--src/im-desktop-menu.c107
1 files changed, 82 insertions, 25 deletions
diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c
index f70ff54..5707390 100644
--- a/src/im-desktop-menu.c
+++ b/src/im-desktop-menu.c
@@ -106,49 +106,39 @@ im_desktop_menu_app_added (ImApplicationList *applist,
}
static void
-im_desktop_menu_source_added (ImApplicationList *applist,
- const gchar *app_id,
- const gchar *source_id,
- const gchar *label,
- const gchar *icon,
- gpointer user_data)
+im_desktop_menu_source_section_insert_source (GMenu *source_section,
+ const gchar *source_id,
+ const gchar *label,
+ const gchar *icon,
+ gint pos)
{
- ImDesktopMenu *menu = user_data;
- GMenu *source_section;
GMenuItem *item;
gchar *action;
- source_section = g_hash_table_lookup (menu->source_sections, app_id);
- g_return_if_fail (source_section != NULL);
-
action = g_strconcat ("src.", source_id, NULL);
item = g_menu_item_new (label, NULL);
- g_menu_item_set_action_and_target_value(item, action, NULL);
+ g_menu_item_set_action_and_target_value (item, action, NULL);
g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.source");
if (icon && *icon)
g_menu_item_set_attribute (item, "icon", "s", icon);
- g_menu_append_item (source_section, item);
+ if (pos >= 0)
+ g_menu_insert_item (source_section, pos, item);
+ else
+ g_menu_append_item (source_section, item);
g_free (action);
g_object_unref (item);
}
-static void
-im_desktop_menu_source_removed (ImApplicationList *applist,
- const gchar *app_id,
- const gchar *source_id,
- gpointer user_data)
+static gint
+im_desktop_menu_source_section_find_source (GMenu *source_section,
+ const gchar *source_id)
{
- ImDesktopMenu *menu = user_data;
- GMenu *source_section;
gint n_items;
gchar *action;
gint i;
- source_section = g_hash_table_lookup (menu->source_sections, app_id);
- g_return_if_fail (source_section != NULL);
-
n_items = g_menu_model_get_n_items (G_MENU_MODEL (source_section));
action = g_strconcat ("src.", source_id, NULL);
@@ -158,14 +148,80 @@ im_desktop_menu_source_removed (ImApplicationList *applist,
if (g_menu_model_get_item_attribute (G_MENU_MODEL (source_section), i, "action", "s", &item_action))
{
- if (g_str_equal (action, item_action))
- g_menu_remove (source_section, i);
+ gboolean equal;
+ equal = g_str_equal (action, item_action);
g_free (item_action);
+
+ if (equal)
+ break;
}
}
g_free (action);
+
+ return i < n_items ? i : -1;
+}
+
+
+static void
+im_desktop_menu_source_added (ImApplicationList *applist,
+ const gchar *app_id,
+ const gchar *source_id,
+ const gchar *label,
+ const gchar *icon,
+ gpointer user_data)
+{
+ ImDesktopMenu *menu = user_data;
+ GMenu *source_section;
+
+ source_section = g_hash_table_lookup (menu->source_sections, app_id);
+ g_return_if_fail (source_section != NULL);
+
+ im_desktop_menu_source_section_insert_source (source_section, source_id, label, icon, -1);
+}
+
+static void
+im_desktop_menu_source_removed (ImApplicationList *applist,
+ const gchar *app_id,
+ const gchar *source_id,
+ gpointer user_data)
+{
+ ImDesktopMenu *menu = user_data;
+ GMenu *source_section;
+ gint pos;
+
+ source_section = g_hash_table_lookup (menu->source_sections, app_id);
+ g_return_if_fail (source_section != NULL);
+
+ pos = im_desktop_menu_source_section_find_source (source_section, source_id);
+ if (pos >= 0)
+ g_menu_remove (source_section, pos);
+}
+
+static void
+im_desktop_menu_source_changed (ImApplicationList *applist,
+ const gchar *app_id,
+ const gchar *source_id,
+ const gchar *label,
+ const gchar *icon,
+ gboolean visible,
+ gpointer user_data)
+{
+ ImDesktopMenu *menu = user_data;
+ GMenu *section;
+ gint pos;
+
+ section = g_hash_table_lookup (menu->source_sections, app_id);
+ g_return_if_fail (section != NULL);
+
+ pos = im_desktop_menu_source_section_find_source (section, source_id);
+
+ if (pos >= 0)
+ g_menu_remove (section, pos);
+
+ if (visible)
+ im_desktop_menu_source_section_insert_source (section, source_id, label, icon, pos);
}
static void
@@ -277,6 +333,7 @@ im_desktop_menu_constructed (GObject *object)
g_signal_connect (applist, "app-added", G_CALLBACK (im_desktop_menu_app_added), menu);
g_signal_connect (applist, "source-added", G_CALLBACK (im_desktop_menu_source_added), menu);
g_signal_connect (applist, "source-removed", G_CALLBACK (im_desktop_menu_source_removed), menu);
+ g_signal_connect (applist, "source-changed", G_CALLBACK (im_desktop_menu_source_changed), menu);
g_signal_connect (applist, "remove-all", G_CALLBACK (im_desktop_menu_remove_all), menu);
g_signal_connect (applist, "app-stopped", G_CALLBACK (im_desktop_menu_app_stopped), menu);