From 21f3cac4cb191430abf89b7cebd0093952c827b0 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Sat, 2 Jun 2012 16:44:47 +0200 Subject: Listen to actions exported by applications --- src/app-section.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'src/app-section.c') diff --git a/src/app-section.c b/src/app-section.c index 6990611..6d00cf1 100644 --- a/src/app-section.c +++ b/src/app-section.c @@ -42,6 +42,9 @@ struct _AppSectionPrivate GMenu *menu; GSimpleActionGroup *static_shortcuts; + GActionGroup *actions; + + guint name_watch_id; }; #define APP_SECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), APP_SECTION_TYPE, AppSectionPrivate)) @@ -155,6 +158,12 @@ app_section_dispose (GObject *object) g_clear_object (&priv->menu); g_clear_object (&priv->static_shortcuts); + if (priv->actions) { + g_clear_object (&priv->actions); + g_bus_unwatch_name (priv->name_watch_id); + priv->name_watch_id = 0; + } + if (priv->ids != NULL) { g_object_unref(priv->ids); priv->ids = NULL; @@ -328,3 +337,62 @@ app_section_create_menu_item (AppSection *self) return item; } +static void +application_vanished (GDBusConnection *bus, + const gchar *name, + gpointer user_data) +{ + AppSection *self = user_data; + + app_section_unset_object_path (self); +} + +/* + * app_section_set_object_path: + * @self: an #AppSection + * @bus: a #GDBusConnection + * @bus_name: the bus name of the application + * @object_path: the object path on which the app exports its actions and menus + * + * Sets the D-Bus object path exported by an instance of the application + * associated with @self. Actions and menus exported on that path will be + * shown in the section. + */ +void +app_section_set_object_path (AppSection *self, + GDBusConnection *bus, + const gchar *bus_name, + const gchar *object_path) +{ + AppSectionPrivate *priv = APP_SECTION_GET_PRIVATE (self); + + if (priv->actions) { + g_clear_object (&priv->actions); + g_bus_unwatch_name (priv->name_watch_id); + } + + priv->actions = G_ACTION_GROUP (g_dbus_action_group_get (bus, bus_name, object_path)); + priv->name_watch_id = g_bus_watch_name_on_connection (bus, bus_name, 0, + NULL, application_vanished, + self, NULL); +} + +/* + * app_section_unset_object_path: + * @self: an #AppSection + * + * Unsets the object path set with app_section_set_object_path(). The section + * will return to only showing application name and static shortcuts in the + * menu. + */ +void +app_section_unset_object_path (AppSection *self) +{ + AppSectionPrivate *priv = APP_SECTION_GET_PRIVATE (self); + + if (priv->actions) { + g_clear_object (&priv->actions); + g_bus_unwatch_name (priv->name_watch_id); + } +} + -- cgit v1.2.3