From 0d54cdd2276dfd43af9b7849da8e214d76c306f3 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 27 Aug 2013 11:05:40 +0200 Subject: im-application-list: use correct signal marshaller for app-stopped --- src/im-application-list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/im-application-list.c b/src/im-application-list.c index 1493adf..ce88db0 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -539,7 +539,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); -- cgit v1.2.3 From 0eae4379c30b5afe8f21f88b30c7ce5d795556d0 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 27 Aug 2013 11:06:05 +0200 Subject: desktop menu: remove all sources when an application has quit --- src/im-desktop-menu.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c index 834a8c9..f70ff54 100644 --- a/src/im-desktop-menu.c +++ b/src/im-desktop-menu.c @@ -184,6 +184,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) { @@ -263,6 +278,7 @@ im_desktop_menu_constructed (GObject *object) 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, "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); } -- cgit v1.2.3 From e1050a9ceed9cfd0c31ebcaf1d4abb931c5d62ed Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 27 Aug 2013 12:35:02 +0200 Subject: desktop menu: don't show sources with a count of 0 --- src/im-application-list.c | 12 ++++-- src/im-desktop-menu.c | 107 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 90 insertions(+), 29 deletions(-) diff --git a/src/im-application-list.c b/src/im-application-list.c index ce88db0..17fffdc 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, @@ -806,6 +807,7 @@ im_application_list_source_changed (Application *app, const gchar *string; gboolean draws_attention; gboolean old_draw; + gboolean visible; g_variant_get (source, "(&s&s&sux&sb)", &id, &label, &iconstr, &count, &time, &string, &draws_attention); @@ -815,9 +817,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); - if (!old_draw && draws_attention) + if (visible && !old_draw && draws_attention) app->draws_attention = TRUE; im_application_list_update_draws_attention (app->list); 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); -- cgit v1.2.3 From f2b47b88f70990bf76fe83d45b64477b4db4dffc Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 27 Aug 2013 16:26:06 +0200 Subject: test-client.py: flush GDBusConnection before (potentially) freeing it --- test/test-client.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test-client.py b/test/test-client.py index a1d503f..0dbf868 100755 --- a/test/test-client.py +++ b/test/test-client.py @@ -63,6 +63,11 @@ class MessagingMenuTest(dbusmock.DBusTestCase): self.assertMethodCalled('UnregisterApplication', 'test.desktop') # ApplicationStoppedRunning is called when the last ref on mmapp is dropped + # Since mmapp is the only thing holding on to a GDBusConnection, the + # connection might get freed before it sends the StoppedRunning + # message. Flush the connection to make sure it is sent. + bus = Gio.bus_get_sync(Gio.BusType.SESSION, None) + bus.flush_sync(None) del mmapp self.assertMethodCalled('ApplicationStoppedRunning', 'test.desktop') -- cgit v1.2.3