diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-08-27 16:54:26 +0200 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-08-27 16:54:26 +0200 |
commit | 35c8e4cc25c0012c3d896cc52225874e9049780b (patch) | |
tree | 2475007b5d1313f62fef6dde7d4946b59231791e /src | |
parent | bf3536178c37ee6bf9816a98c92b0de386f551a4 (diff) | |
parent | 6ded3e619d7308b6eda2bf0928b226378b565d1b (diff) | |
download | ayatana-indicator-messages-35c8e4cc25c0012c3d896cc52225874e9049780b.tar.gz ayatana-indicator-messages-35c8e4cc25c0012c3d896cc52225874e9049780b.tar.bz2 ayatana-indicator-messages-35c8e4cc25c0012c3d896cc52225874e9049780b.zip |
Merge trunk
Diffstat (limited to 'src')
-rw-r--r-- | src/im-application-list.c | 14 | ||||
-rw-r--r-- | src/im-desktop-menu.c | 123 |
2 files changed, 107 insertions, 30 deletions
diff --git a/src/im-application-list.c b/src/im-application-list.c index 8b8e4db..950b5bc 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -476,11 +476,12 @@ im_application_list_class_init (ImApplicationListClass *klass) NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, - 4, + 5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_STRING); + G_TYPE_STRING, + G_TYPE_BOOLEAN); signals[SOURCE_REMOVED] = g_signal_new ("source-removed", IM_TYPE_APPLICATION_LIST, @@ -539,7 +540,7 @@ im_application_list_class_init (ImApplicationListClass *klass) G_SIGNAL_RUN_FIRST, 0, NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, + g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); @@ -805,6 +806,7 @@ im_application_list_source_changed (Application *app, gint64 time; const gchar *string; gboolean draws_attention; + gboolean visible; g_variant_get (source, "(&s&s&sux&sb)", &id, &label, &iconstr, &count, &time, &string, &draws_attention); @@ -812,9 +814,11 @@ im_application_list_source_changed (Application *app, g_action_group_change_action_state (G_ACTION_GROUP (app->source_actions), id, g_variant_new ("(uxsb)", count, time, string, draws_attention)); - g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->id, id, label, iconstr); + visible = count > 0; + + g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->id, id, label, iconstr, visible); - app->draws_attention = draws_attention; + app->draws_attention = visible && draws_attention; im_application_list_update_draws_attention (app->list); } diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c index 834a8c9..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 @@ -184,6 +240,21 @@ im_desktop_menu_remove_all (ImApplicationList *applist, } } +static void +im_desktop_menu_app_stopped (ImApplicationList *applist, + const gchar *app_id, + gpointer user_data) +{ + ImDesktopMenu *menu = user_data; + GMenu *section; + + section = g_hash_table_lookup (menu->source_sections, app_id); + g_return_if_fail (section != NULL); + + while (g_menu_model_get_n_items (G_MENU_MODEL (section)) > 0) + g_menu_remove (section, 0); +} + static GMenu * create_status_section (void) { @@ -262,7 +333,9 @@ 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); G_OBJECT_CLASS (im_desktop_menu_parent_class)->constructed (object); } |