diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2012-09-05 21:39:13 +0000 |
---|---|---|
committer | Tarmac <Unknown> | 2012-09-05 21:39:13 +0000 |
commit | 2e17120b6eefea4710e5a1abf859825f507014bb (patch) | |
tree | 2335637a0f29163b4d51a3c80842251e3e33e447 /src/messages-service.c | |
parent | 824daba1155620df5be05baec1829247dd9788c0 (diff) | |
parent | 014f841f7cd5a1a665da7fc19c775104ea252ab4 (diff) | |
download | ayatana-indicator-messages-2e17120b6eefea4710e5a1abf859825f507014bb.tar.gz ayatana-indicator-messages-2e17120b6eefea4710e5a1abf859825f507014bb.tar.bz2 ayatana-indicator-messages-2e17120b6eefea4710e5a1abf859825f507014bb.zip |
Hide the indicator when no application is configured to use it.. Fixes: https://bugs.launchpad.net/bugs/661059, https://bugs.launchpad.net/bugs/1045039. Approved by jenkins, Charles Kerr.
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); |