[glib] GApplication: receiving end of GRemoteActionGroup



commit 0971d36e4b8338f4f3f96d751f5275517514d3b1
Author: Ryan Lortie <desrt desrt ca>
Date:   Sat Dec 17 00:52:57 2011 -0500

    GApplication: receiving end of GRemoteActionGroup
    
    Use the fact that the action group exporter now speaks to
    GRemoteActionGroup to get the platform data into GApplicion without
    hacks.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=665737

 gio/gapplication.c          |   89 ++++++++++++++++++++++++++++++++++++++++++-
 gio/gapplicationimpl-dbus.c |    6 ++-
 gio/gapplicationimpl.h      |   13 +++---
 3 files changed, 100 insertions(+), 8 deletions(-)
---
diff --git a/gio/gapplication.c b/gio/gapplication.c
index ce14480..a4e6185 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -250,6 +250,92 @@ G_DEFINE_TYPE_WITH_CODE (GApplication, g_application, G_TYPE_OBJECT,
  G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, g_application_action_group_iface_init)
  G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_MAP, g_application_action_map_iface_init))
 
+/* GApplicationExportedActions {{{1 */
+
+/* We create a subclass of GSimpleActionGroup that implements
+ * GRemoteActionGroup and deals with the platform data using
+ * GApplication's before/after_emit vfuncs.  This is the action group we
+ * will be exporting.
+ *
+ * We could implement GRemoteActionGroup on GApplication directly, but
+ * this would be potentially extremely confusing to have exposed as part
+ * of the public API of GApplication.  We certainly don't want anyone in
+ * the same process to be calling these APIs...
+ */
+typedef GSimpleActionGroupClass GApplicationExportedActionsClass;
+typedef struct
+{
+  GSimpleActionGroup parent_instance;
+  GApplication *application;
+} GApplicationExportedActions;
+
+static GType g_application_exported_actions_get_type   (void);
+static void  g_application_exported_actions_iface_init (GRemoteActionGroupInterface *iface);
+G_DEFINE_TYPE_WITH_CODE (GApplicationExportedActions, g_application_exported_actions, G_TYPE_SIMPLE_ACTION_GROUP,
+                         G_IMPLEMENT_INTERFACE (G_TYPE_REMOTE_ACTION_GROUP, g_application_exported_actions_iface_init))
+
+static void
+g_application_exported_actions_activate_action_full (GRemoteActionGroup *remote,
+                                                     const gchar        *action_name,
+                                                     GVariant           *parameter,
+                                                     GVariant           *platform_data)
+{
+  GApplicationExportedActions *exported = (GApplicationExportedActions *) remote;
+
+  G_APPLICATION_GET_CLASS (exported->application)
+    ->before_emit (exported->application, platform_data);
+
+  g_action_group_activate_action (G_ACTION_GROUP (exported), action_name, parameter);
+
+  G_APPLICATION_GET_CLASS (exported->application)
+    ->after_emit (exported->application, platform_data);
+}
+
+static void
+g_application_exported_actions_change_action_state_full (GRemoteActionGroup *remote,
+                                                         const gchar        *action_name,
+                                                         GVariant           *value,
+                                                         GVariant           *platform_data)
+{
+  GApplicationExportedActions *exported = (GApplicationExportedActions *) remote;
+
+  G_APPLICATION_GET_CLASS (exported->application)
+    ->before_emit (exported->application, platform_data);
+
+  g_action_group_change_action_state (G_ACTION_GROUP (exported), action_name, value);
+
+  G_APPLICATION_GET_CLASS (exported->application)
+    ->after_emit (exported->application, platform_data);
+}
+
+static void
+g_application_exported_actions_init (GApplicationExportedActions *actions)
+{
+}
+
+static void
+g_application_exported_actions_iface_init (GRemoteActionGroupInterface *iface)
+{
+  iface->activate_action_full = g_application_exported_actions_activate_action_full;
+  iface->change_action_state_full = g_application_exported_actions_change_action_state_full;
+}
+
+static void
+g_application_exported_actions_class_init (GApplicationExportedActionsClass *class)
+{
+}
+
+static GActionGroup *
+g_application_exported_actions_new (GApplication *application)
+{
+  GApplicationExportedActions *actions;
+
+  actions = g_object_new (g_application_exported_actions_get_type (), NULL);
+  actions->application = application;
+
+  return G_ACTION_GROUP (actions);
+}
+
 /* vfunc defaults {{{1 */
 static void
 g_application_real_before_emit (GApplication *application,
@@ -704,7 +790,7 @@ g_application_init (GApplication *application)
                                                    G_TYPE_APPLICATION,
                                                    GApplicationPrivate);
 
-  application->priv->actions = G_ACTION_GROUP (g_simple_action_group_new ());
+  application->priv->actions = g_application_exported_actions_new (application);
 
   /* application->priv->actions is the one and only ref on the group, so when
    * we dispose, the action group will die, disconnecting all signals.
@@ -1253,6 +1339,7 @@ g_application_register (GApplication  *application,
           application->priv->impl =
             g_application_impl_register (application, application->priv->id,
                                          application->priv->flags,
+                                         application->priv->actions,
                                          &application->priv->remote_actions,
                                          cancellable, error);
 
diff --git a/gio/gapplicationimpl-dbus.c b/gio/gapplicationimpl-dbus.c
index ffbb114..d8999d7 100644
--- a/gio/gapplicationimpl-dbus.c
+++ b/gio/gapplicationimpl-dbus.c
@@ -87,6 +87,7 @@ static GDBusInterfaceInfo *org_gtk_private_CommandLine;
 struct _GApplicationImpl
 {
   GDBusConnection *session_bus;
+  GActionGroup    *exported_actions;
   const gchar     *bus_name;
 
   gchar           *object_path;
@@ -377,7 +378,8 @@ g_application_impl_attempt_primary (GApplicationImpl  *impl,
   if (impl->object_id == 0)
     return FALSE;
 
-  impl->actions_id = g_dbus_connection_export_action_group (impl->session_bus, impl->object_path, impl->app, error);
+  impl->actions_id = g_dbus_connection_export_action_group (impl->session_bus, impl->object_path,
+                                                            impl->exported_actions, error);
 
   if (impl->actions_id == 0)
     return FALSE;
@@ -477,6 +479,7 @@ GApplicationImpl *
 g_application_impl_register (GApplication        *application,
                              const gchar         *appid,
                              GApplicationFlags    flags,
+                             GActionGroup        *exported_actions,
                              GRemoteActionGroup **remote_actions,
                              GCancellable        *cancellable,
                              GError             **error)
@@ -487,6 +490,7 @@ g_application_impl_register (GApplication        *application,
   impl = g_slice_new0 (GApplicationImpl);
 
   impl->app = application;
+  impl->exported_actions = exported_actions;
   impl->bus_name = appid;
 
   impl->session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, cancellable, NULL);
diff --git a/gio/gapplicationimpl.h b/gio/gapplicationimpl.h
index 0406700..ef25f2b 100644
--- a/gio/gapplicationimpl.h
+++ b/gio/gapplicationimpl.h
@@ -15,12 +15,13 @@ G_GNUC_INTERNAL
 void                    g_application_impl_destroy                      (GApplicationImpl   *impl);
 
 G_GNUC_INTERNAL
-GApplicationImpl *      g_application_impl_register                     (GApplication       *application,
-                                                                         const gchar        *appid,
-                                                                         GApplicationFlags   flags,
-                                                                         GRemoteActionGroup**remote_actions,
-                                                                         GCancellable       *cancellable,
-                                                                         GError            **error);
+GApplicationImpl *      g_application_impl_register                     (GApplication        *application,
+                                                                         const gchar         *appid,
+                                                                         GApplicationFlags    flags,
+                                                                         GActionGroup        *exported_actions,
+                                                                         GRemoteActionGroup **remote_actions,
+                                                                         GCancellable        *cancellable,
+                                                                         GError             **error);
 
 G_GNUC_INTERNAL
 void                    g_application_impl_activate                     (GApplicationImpl   *impl,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]