diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2014-04-08 16:24:38 +0000 |
---|---|---|
committer | CI bot <ps-jenkins@lists.canonical.com> | 2014-04-08 16:24:38 +0000 |
commit | ab9d26c0746ac61895522ce62a98150ad0e1f942 (patch) | |
tree | ab839a51dbea3e2d53b2d3f1c6947feb63dea52f /src | |
parent | 8782213594a5d08cb16a964dec3e3232cae18b24 (diff) | |
parent | de9c80835a2facd1957d580f01e81209294406f6 (diff) | |
download | ayatana-indicator-messages-ab9d26c0746ac61895522ce62a98150ad0e1f942.tar.gz ayatana-indicator-messages-ab9d26c0746ac61895522ce62a98150ad0e1f942.tar.bz2 ayatana-indicator-messages-ab9d26c0746ac61895522ce62a98150ad0e1f942.zip |
Don't show the messaging menu and the status section when no app is registered for them Fixes: 1225063
Diffstat (limited to 'src')
-rw-r--r-- | src/im-application-list.c | 33 | ||||
-rw-r--r-- | src/im-desktop-menu.c | 94 | ||||
-rw-r--r-- | src/im-menu.c | 14 | ||||
-rw-r--r-- | src/im-menu.h | 3 |
4 files changed, 79 insertions, 65 deletions
diff --git a/src/im-application-list.c b/src/im-application-list.c index d285fda..4f5903a 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -155,7 +155,7 @@ application_draws_attention (gpointer key, } static void -im_application_list_update_draws_attention (ImApplicationList *list) +im_application_list_update_root_action (ImApplicationList *list) { const gchar *base_icon_name; const gchar *accessible_name; @@ -164,6 +164,7 @@ im_application_list_update_draws_attention (ImApplicationList *list) GVariant *serialized_icon; GVariantBuilder builder; GVariant *state; + guint n_applications; /* Figure out what type of icon we should be drawing */ if (g_hash_table_find (list->applications, application_draws_attention, NULL)) { @@ -202,10 +203,8 @@ im_application_list_update_draws_attention (ImApplicationList *list) g_variant_builder_close(&builder); /* visibility */ - g_variant_builder_open(&builder, G_VARIANT_TYPE_DICT_ENTRY); - g_variant_builder_add_value(&builder, g_variant_new_string("visible")); - g_variant_builder_add_value(&builder, g_variant_new_variant(g_variant_new_boolean(TRUE))); - g_variant_builder_close(&builder); + n_applications = g_hash_table_size (list->applications); + g_variant_builder_add (&builder, "{sv}", "visible", g_variant_new_boolean (n_applications > 0)); /* Set the state */ g_action_group_change_action_state (G_ACTION_GROUP(list->globalactions), "messages", g_variant_builder_end(&builder)); @@ -294,7 +293,7 @@ im_application_list_source_removed (Application *app, g_signal_emit (app->list, signals[SOURCE_REMOVED], 0, app->id, id); if (application_update_draws_attention(app)) - im_application_list_update_draws_attention (app->list); + im_application_list_update_root_action (app->list); } static void @@ -333,7 +332,7 @@ im_application_list_message_removed (Application *app, g_action_muxer_remove (app->message_sub_actions, id); if (application_update_draws_attention(app)) - im_application_list_update_draws_attention (app->list); + im_application_list_update_root_action (app->list); g_signal_emit (app->list, signals[MESSAGE_REMOVED], 0, app->id, id); } @@ -435,7 +434,7 @@ im_application_list_remove_all (GSimpleAction *action, g_strfreev (message_actions); } - im_application_list_update_draws_attention (list); + im_application_list_update_root_action (list); } static void @@ -601,7 +600,7 @@ im_application_list_init (ImApplicationList *list) list->muxer = g_action_muxer_new (); g_action_muxer_insert (list->muxer, NULL, G_ACTION_GROUP (list->globalactions)); - im_application_list_update_draws_attention (list); + im_application_list_update_root_action (list); } ImApplicationList * @@ -744,6 +743,8 @@ im_application_list_add (ImApplicationList *list, g_hash_table_insert (list->applications, (gpointer) app->id, app); g_action_muxer_insert (list->muxer, app->id, G_ACTION_GROUP (app->muxer)); + im_application_list_update_root_action (list); + g_signal_emit (app->list, signals[APP_ADDED], 0, app->id, app->info); g_object_unref (launch_action); @@ -769,7 +770,7 @@ im_application_list_remove (ImApplicationList *list, g_hash_table_remove (list->applications, id); g_action_muxer_remove (list->muxer, id); - im_application_list_update_draws_attention (list); + im_application_list_update_root_action (list); } } @@ -809,7 +810,7 @@ im_application_list_source_added (Application *app, if (visible && draws_attention && app->draws_attention == FALSE) { app->draws_attention = TRUE; - im_application_list_update_draws_attention (app->list); + im_application_list_update_root_action (app->list); } g_object_unref (action); @@ -846,7 +847,7 @@ im_application_list_source_changed (Application *app, g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->id, id, label, serialized_icon, visible); if (application_update_draws_attention (app)) - im_application_list_update_draws_attention (app->list); + im_application_list_update_root_action (app->list); if (serialized_icon) g_variant_unref (serialized_icon); @@ -1010,7 +1011,7 @@ im_application_list_message_added (Application *app, if (draws_attention && !app->draws_attention) { app->draws_attention = TRUE; - im_application_list_update_draws_attention (app->list); + im_application_list_update_root_action (app->list); } app_icon = get_symbolic_app_icon (G_APP_INFO (app->info)); @@ -1084,7 +1085,7 @@ im_application_list_unset_remote (Application *app) g_action_muxer_insert (app->muxer, "msg-actions", G_ACTION_GROUP (app->message_sub_actions)); app->draws_attention = FALSE; - im_application_list_update_draws_attention (app->list); + im_application_list_update_root_action (app->list); g_action_group_change_action_state (G_ACTION_GROUP (app->muxer), "launch", g_variant_new_boolean (FALSE)); @@ -1229,7 +1230,7 @@ status_activated (GSimpleAction * action, GVariant * param, gpointer user_data) g_signal_emit (list, signals[STATUS_SET], 0, status); - im_application_list_update_draws_attention(list); + im_application_list_update_root_action(list); return; } @@ -1276,7 +1277,7 @@ im_application_list_set_status (ImApplicationList * list, const gchar * id, cons g_simple_action_set_state(list->statusaction, g_variant_new_string(status_ids[final_status])); - im_application_list_update_draws_attention(list); + im_application_list_update_root_action(list); return; } diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c index 11e3d41..bfae137 100644 --- a/src/im-desktop-menu.c +++ b/src/im-desktop-menu.c @@ -27,12 +27,54 @@ struct _ImDesktopMenu { ImMenu parent; + gboolean status_section_visible; GHashTable *source_sections; }; G_DEFINE_TYPE (ImDesktopMenu, im_desktop_menu, IM_TYPE_MENU); static void +menu_append_status (GMenu *menu, + const gchar *label, + const gchar *detailed_action, + const gchar *icon_name) +{ + GMenuItem *item; + GIcon *icon; + + icon = g_themed_icon_new (icon_name); + + item = g_menu_item_new (label, detailed_action); + g_menu_item_set_icon (item, icon); + g_menu_append_item (menu, item); + + g_object_unref (icon); + g_object_unref (item); +} + +static void +im_desktop_menu_show_chat_section (ImDesktopMenu *menu) +{ + GMenu *status_section; + + if (menu->status_section_visible) + return; + + status_section = g_menu_new (); + + menu_append_status (status_section, _("Available"), "indicator.status::available", "user-available"); + menu_append_status (status_section, _("Away"), "indicator.status::away", "user-away"); + menu_append_status (status_section, _("Busy"), "indicator.status::busy", "user-busy"); + menu_append_status (status_section, _("Invisible"), "indicator.status::invisible", "user-invisible"); + menu_append_status (status_section, _("Offline"), "indicator.status::offline", "user-offline"); + + im_menu_prepend_section (IM_MENU (menu), G_MENU_MODEL (status_section)); + menu->status_section_visible = TRUE; + + g_object_unref (status_section); +} + +static void im_desktop_menu_app_added (ImApplicationList *applist, const gchar *app_id, GDesktopAppInfo *app_info, @@ -94,6 +136,9 @@ im_desktop_menu_app_added (ImApplicationList *applist, g_clear_object(&shortcuts); } + if (g_desktop_app_info_get_boolean (app_info, "X-MessagingMenu-UsesChatSection")) + im_desktop_menu_show_chat_section (menu); + source_section = g_menu_new (); section = g_menu_new (); @@ -261,46 +306,6 @@ im_desktop_menu_app_stopped (ImApplicationList *applist, g_menu_remove (section, 0); } -static GMenu * -create_status_section (void) -{ - GMenu *menu; - GMenuItem *item; - struct status_item { - gchar *label; - gchar *action; - gchar *icon_name; - } status_items[] = { - { _("Available"), "indicator.status::available", "user-available" }, - { _("Away"), "indicator.status::away", "user-away" }, - { _("Busy"), "indicator.status::busy", "user-busy" }, - { _("Invisible"), "indicator.status::invisible", "user-invisible" }, - { _("Offline"), "indicator.status::offline", "user-offline" } - }; - int i; - - menu = g_menu_new (); - - item = g_menu_item_new (NULL, NULL); - - for (i = 0; i < G_N_ELEMENTS (status_items); i++) { - GIcon *icon; - - g_menu_item_set_label (item, status_items[i].label); - g_menu_item_set_detailed_action (item, status_items[i].action); - - icon = g_themed_icon_new (status_items[i].icon_name); - g_menu_item_set_icon (item, icon); - - g_menu_append_item (menu, item); - - g_object_unref (icon); - } - - g_object_unref (item); - return menu; -} - static void im_desktop_menu_constructed (GObject *object) { @@ -308,15 +313,6 @@ im_desktop_menu_constructed (GObject *object) ImApplicationList *applist; { - GMenu *status_section; - - status_section = create_status_section(); - im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (status_section)); - - g_object_unref (status_section); - } - - { GMenu *clear_section; clear_section = g_menu_new (); diff --git a/src/im-menu.c b/src/im-menu.c index 55ea99c..57cf957 100644 --- a/src/im-menu.c +++ b/src/im-menu.c @@ -149,6 +149,20 @@ im_menu_export (ImMenu *menu, } void +im_menu_prepend_section (ImMenu *menu, + GMenuModel *section) +{ + ImMenuPrivate *priv; + + g_return_if_fail (IM_IS_MENU (menu)); + g_return_if_fail (G_IS_MENU_MODEL (section)); + + priv = im_menu_get_instance_private (menu); + + g_menu_prepend_section (priv->menu, NULL, section); +} + +void im_menu_append_section (ImMenu *menu, GMenuModel *section) { diff --git a/src/im-menu.h b/src/im-menu.h index 7c15eb7..57815b5 100644 --- a/src/im-menu.h +++ b/src/im-menu.h @@ -53,6 +53,9 @@ gboolean im_menu_export (ImMenu const gchar *object_path, GError **error); +void im_menu_prepend_section (ImMenu *menu, + GMenuModel *section); + void im_menu_append_section (ImMenu *menu, GMenuModel *section); |