From 98538a540ba7a741a68b4cff6d3e192a43d61077 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Sun, 3 Jun 2012 12:59:43 +0200 Subject: Reexport application actions --- src/app-section.c | 21 +++++++++++++++++++++ src/app-section.h | 1 + src/messages-service.c | 21 +++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/src/app-section.c b/src/app-section.c index 6218f37..f23f412 100644 --- a/src/app-section.c +++ b/src/app-section.c @@ -54,6 +54,7 @@ struct _AppSectionPrivate enum { PROP_0, PROP_APPINFO, + PROP_ACTIONS, NUM_PROPERTIES }; @@ -97,6 +98,12 @@ app_section_class_init (AppSectionClass *klass) G_TYPE_APP_INFO, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + properties[PROP_ACTIONS] = g_param_spec_object ("actions", + "Actions", + "The actions exported by this application", + G_TYPE_ACTION_GROUP, + G_PARAM_READABLE); + g_object_class_install_properties (object_class, NUM_PROPERTIES, properties); } @@ -247,6 +254,9 @@ app_section_set_app_info (AppSection *self, g_free(name); } + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_APPINFO]); + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTIONS]); + g_free(label); g_object_unref (launch); } @@ -306,6 +316,13 @@ app_section_get_desktop (AppSection * self) return NULL; } +GActionGroup * +app_section_get_actions (AppSection *self) +{ + AppSectionPrivate * priv = APP_SECTION_GET_PRIVATE(self); + return priv->actions ? priv->actions : G_ACTION_GROUP (priv->static_shortcuts); +} + GMenuModel * app_section_get_menu (AppSection *self) { @@ -381,6 +398,8 @@ app_section_set_object_path (AppSection *self, priv->name_watch_id = g_bus_watch_name_on_connection (bus, bus_name, 0, NULL, application_vanished, self, NULL); + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTIONS]); } /* @@ -402,5 +421,7 @@ app_section_unset_object_path (AppSection *self) } g_clear_object (&priv->actions); g_clear_object (&priv->remote_menu); + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTIONS]); } diff --git a/src/app-section.h b/src/app-section.h index aa6ef75..24074b8 100644 --- a/src/app-section.h +++ b/src/app-section.h @@ -49,6 +49,7 @@ AppSection * app_section_new (GDesktopAppInfo *appinfo); guint app_section_get_count (AppSection * appitem); const gchar * app_section_get_name (AppSection * appitem); const gchar * app_section_get_desktop (AppSection * appitem); +GActionGroup * app_section_get_actions (AppSection *self); GMenuModel * app_section_get_menu (AppSection *appitem); GAppInfo * app_section_get_app_info (AppSection *appitem); GMenuItem * app_section_create_menu_item (AppSection *self); diff --git a/src/messages-service.c b/src/messages-service.c index ec12cbe..e302219 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -64,6 +64,22 @@ g_app_info_get_simple_id (GAppInfo *appinfo) return g_strdup (id); } +static void +actions_changed (GObject *object, + GParamSpec *pspec, + gpointer user_data) +{ + AppSection *section = APP_SECTION (object); + gchar *id; + GActionGroup *actions; + + id = g_app_info_get_simple_id (app_section_get_app_info (section)); + actions = app_section_get_actions (section); + + g_action_muxer_insert (action_muxer, id, actions); + g_free (id); +} + static AppSection * add_application (const gchar *desktop_id) { @@ -86,6 +102,10 @@ add_application (const gchar *desktop_id) section = app_section_new(appinfo); g_hash_table_insert (applications, g_strdup (id), section); + g_action_muxer_insert (action_muxer, id, app_section_get_actions (section)); + g_signal_connect (section, "notify::actions", + G_CALLBACK (actions_changed), NULL); + item = app_section_create_menu_item (section); /* TODO insert it at the right position (alphabetically by application name) */ g_menu_insert_item (menu, 2, item); @@ -137,6 +157,7 @@ remove_application (const char *desktop_id) int pos = g_menu_find_section (menu, app_section_get_menu (section)); if (pos >= 0) g_menu_remove (menu, pos); + g_action_muxer_remove (action_muxer, id); } else { g_warning ("could not remove '%s', it's not registered", desktop_id); -- cgit v1.2.3