diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2012-09-04 10:25:27 +0200 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2012-09-04 10:25:27 +0200 |
commit | b05f7b89e3fd4b61787214742dd7c8597718dc9a (patch) | |
tree | 2c18dec6b625fbab1ac333ff5519f744c78c2cfe /src/messages-service.c | |
parent | 67eb5bea332a35aa1c02984d5a719c696a3e2309 (diff) | |
download | ayatana-indicator-messages-b05f7b89e3fd4b61787214742dd7c8597718dc9a.tar.gz ayatana-indicator-messages-b05f7b89e3fd4b61787214742dd7c8597718dc9a.tar.bz2 ayatana-indicator-messages-b05f7b89e3fd4b61787214742dd7c8597718dc9a.zip |
Hide indicator when no applications are configured to use it
This is done by removing the header item from the menu model in the service.
On the panel side, call indicator_object_hide() if the recevied menu is empty.
Diffstat (limited to 'src/messages-service.c')
-rw-r--r-- | src/messages-service.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/messages-service.c b/src/messages-service.c index 15c5123..d016ff1 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -175,6 +175,25 @@ add_application (const gchar *desktop_id) g_object_unref (menuitem); } + if (g_menu_model_get_n_items (G_MENU_MODEL (toplevel_menu)) == 0) { + GMenuItem *header; + GIcon *icon; + gchar *iconstr; + + icon = g_themed_icon_new ("indicator-messages"); + iconstr = g_icon_to_string (icon); + + header = g_menu_item_new (NULL, "messages"); + g_menu_item_set_submenu (header, G_MENU_MODEL (menu)); + g_menu_item_set_attribute (header, "x-canonical-icon", "s", iconstr); + g_menu_item_set_attribute (header, "x-canonical-accessible-description", "s", _("Messages")); + g_menu_append_item (toplevel_menu, header); + + g_object_unref (header); + g_free (iconstr); + g_object_unref (icon); + } + g_free (id); g_object_unref (appinfo); return section; @@ -211,6 +230,12 @@ remove_application (const char *desktop_id) } g_hash_table_remove (applications, id); + + if (g_hash_table_size (applications) == 0 && + g_menu_model_get_n_items (G_MENU_MODEL (toplevel_menu)) == 1) { + g_menu_remove (toplevel_menu, 0); + } + g_free (id); g_object_unref (appinfo); } @@ -484,9 +509,6 @@ main (int argc, char ** argv) { GMainLoop * mainloop = NULL; IndicatorService * service = NULL; - GMenuItem *header; - GIcon *icon; - gchar *iconstr; /* Glib init */ g_type_init(); @@ -524,16 +546,7 @@ main (int argc, char ** argv) chat_section = create_status_section (); g_menu_append (menu, _("Clear"), "clear"); - icon = g_themed_icon_new ("indicator-messages"); - iconstr = g_icon_to_string (icon); - toplevel_menu = g_menu_new (); - header = g_menu_item_new (NULL, "messages"); - g_menu_item_set_submenu (header, G_MENU_MODEL (menu)); - g_menu_item_set_attribute (header, "x-canonical-icon", "s", iconstr); - g_menu_item_set_attribute (header, "x-canonical-accessible-description", "s", _("Messages")); - g_menu_append_item (toplevel_menu, header); - g_object_unref (header); settings = g_settings_new ("com.canonical.indicator.messages"); @@ -544,8 +557,6 @@ main (int argc, char ** argv) g_main_loop_run(mainloop); /* Clean up */ - g_free (iconstr); - g_object_unref (icon); g_object_unref (messages_service); g_object_unref (chat_section); g_object_unref (settings); |