aboutsummaryrefslogtreecommitdiff
path: root/src/app-section.c
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-06-02 16:44:47 +0200
committerLars Uebernickel <lars.uebernickel@canonical.com>2012-06-02 16:44:47 +0200
commit21f3cac4cb191430abf89b7cebd0093952c827b0 (patch)
tree5aee144e7dac57d0c4cd764614b9dab7ebc9fa92 /src/app-section.c
parentb4062c831c830df78baeecf092e7c5e7198afada (diff)
downloadayatana-indicator-messages-21f3cac4cb191430abf89b7cebd0093952c827b0.tar.gz
ayatana-indicator-messages-21f3cac4cb191430abf89b7cebd0093952c827b0.tar.bz2
ayatana-indicator-messages-21f3cac4cb191430abf89b7cebd0093952c827b0.zip
Listen to actions exported by applications
Diffstat (limited to 'src/app-section.c')
-rw-r--r--src/app-section.c68
1 files changed, 68 insertions, 0 deletions
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);
+ }
+}
+