aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-11-21 00:02:12 +0100
committerLars Uebernickel <lars.uebernickel@canonical.com>2012-11-21 00:02:12 +0100
commitd22b49e5fee5ae352ec6050e63181850a857fb3a (patch)
treef64a82b8233d0fcc18cdfd3c918b361f22ebd14f /src
parent15f2eef7082f9a68b1511f0868cdd60558b3a4f6 (diff)
downloadayatana-indicator-messages-d22b49e5fee5ae352ec6050e63181850a857fb3a.tar.gz
ayatana-indicator-messages-d22b49e5fee5ae352ec6050e63181850a857fb3a.tar.bz2
ayatana-indicator-messages-d22b49e5fee5ae352ec6050e63181850a857fb3a.zip
Remove applications from the menu when the disappear from the bus
Diffstat (limited to 'src')
-rw-r--r--src/im-application-list.c42
-rw-r--r--src/im-phone-menu.c43
-rw-r--r--src/im-phone-menu.h3
-rw-r--r--src/messages-service.c2
4 files changed, 90 insertions, 0 deletions
diff --git a/src/im-application-list.c b/src/im-application-list.c
index 920626d..6da2950 100644
--- a/src/im-application-list.c
+++ b/src/im-application-list.c
@@ -43,6 +43,7 @@ enum
SOURCE_REMOVED,
MESSAGE_ADDED,
MESSAGE_REMOVED,
+ APP_STOPPED,
N_SIGNALS
};
@@ -179,6 +180,16 @@ im_application_list_class_init (ImApplicationListClass *klass)
2,
G_TYPE_DESKTOP_APP_INFO,
G_TYPE_STRING);
+
+ signals[APP_STOPPED] = g_signal_new ("app-stopped",
+ IM_TYPE_APPLICATION_LIST,
+ G_SIGNAL_RUN_FIRST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_DESKTOP_APP_INFO);
}
static void
@@ -394,6 +405,31 @@ im_application_list_messages_listed (GObject *source_object,
}
static void
+im_application_list_app_vanished (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ Application *app = user_data;
+
+ if (app->cancellable)
+ {
+ g_cancellable_cancel (app->cancellable);
+ g_clear_object (&app->cancellable);
+ }
+ g_clear_object (&app->proxy);
+
+ /* clear actions by creating a new action group and overriding it in
+ * the muxer */
+ g_object_unref (app->actions);
+ app->actions = g_simple_action_group_new ();
+ g_action_muxer_insert (app->list->muxer,
+ g_app_info_get_id (G_APP_INFO (app->info)),
+ G_ACTION_GROUP (app->actions));
+
+ g_signal_emit (app->list, signals[APP_STOPPED], 0, app->info);
+}
+
+static void
im_application_list_proxy_created (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
@@ -419,6 +455,12 @@ im_application_list_proxy_created (GObject *source_object,
g_signal_connect_swapped (app->proxy, "source-removed", G_CALLBACK (im_application_list_source_removed), app);
g_signal_connect_swapped (app->proxy, "message-added", G_CALLBACK (im_application_list_message_added), app);
g_signal_connect_swapped (app->proxy, "message-removed", G_CALLBACK (im_application_list_message_removed), app);
+
+ g_bus_watch_name_on_connection (g_dbus_proxy_get_connection (G_DBUS_PROXY (app->proxy)),
+ g_dbus_proxy_get_name (G_DBUS_PROXY (app->proxy)),
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ NULL, im_application_list_app_vanished,
+ app, NULL);
}
void
diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c
index abb3a11..43b7a6c 100644
--- a/src/im-phone-menu.c
+++ b/src/im-phone-menu.c
@@ -214,3 +214,46 @@ im_phone_menu_remove_source (ImPhoneMenu *menu,
g_free (action_name);
}
+
+static void
+im_phone_menu_remove_all_for_app (GMenu *menu,
+ GDesktopAppInfo *app)
+{
+ gchar *prefix;
+ gint n_items;
+ gint i = 0;
+
+ prefix = g_strconcat (g_app_info_get_id (G_APP_INFO (app)), ".", NULL);
+
+ n_items = g_menu_model_get_n_items (G_MENU_MODEL (menu));
+ while (i < n_items)
+ {
+ gchar *action;
+
+ g_menu_model_get_item_attribute (G_MENU_MODEL (menu), i, G_MENU_ATTRIBUTE_ACTION, "s", &action);
+ if (g_str_has_prefix (action, prefix))
+ {
+ g_menu_remove (menu, i);
+ n_items--;
+ }
+ else
+ {
+ i++;
+ }
+
+ g_free (action);
+ }
+
+ g_free (prefix);
+}
+
+void
+im_phone_menu_remove_application (ImPhoneMenu *menu,
+ GDesktopAppInfo *app)
+{
+ g_return_if_fail (IM_IS_PHONE_MENU (menu));
+ g_return_if_fail (G_IS_DESKTOP_APP_INFO (app));
+
+ im_phone_menu_remove_all_for_app (menu->source_section, app);
+ im_phone_menu_remove_all_for_app (menu->message_section, app);
+}
diff --git a/src/im-phone-menu.h b/src/im-phone-menu.h
index f7cc645..91aae2c 100644
--- a/src/im-phone-menu.h
+++ b/src/im-phone-menu.h
@@ -64,4 +64,7 @@ void im_phone_menu_remove_source (ImPhoneMenu *men
GDesktopAppInfo *app,
const gchar *id);
+void im_phone_menu_remove_application (ImPhoneMenu *menu,
+ GDesktopAppInfo *app);
+
#endif
diff --git a/src/messages-service.c b/src/messages-service.c
index 467224d..18f3d0a 100644
--- a/src/messages-service.c
+++ b/src/messages-service.c
@@ -273,6 +273,8 @@ main (int argc, char ** argv)
G_CALLBACK (im_phone_menu_add_message), menu);
g_signal_connect_swapped (applications, "message-removed",
G_CALLBACK (im_phone_menu_remove_message), menu);
+ g_signal_connect_swapped (applications, "app-stopped",
+ G_CALLBACK (im_phone_menu_remove_application), menu);
g_main_loop_run(mainloop);