[glib] GApplication: put non-unique apps on D-Bus



commit 40e9192d7261ff9eec9e6ec4bd7029c08df80004
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Feb 9 12:15:49 2012 -0500

    GApplication: put non-unique apps on D-Bus
    
    For a number of reasons it might be useful to register the object paths
    associated with a non-unique application so that the application can at
    least field requests to its unique D-Bus name.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=647986

 gio/gapplication.c          |   21 +++++++++------------
 gio/gapplicationimpl-dbus.c |   22 +++++++++++++++++++++-
 2 files changed, 30 insertions(+), 13 deletions(-)
---
diff --git a/gio/gapplication.c b/gio/gapplication.c
index 1aab950..0d523d3 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -1179,18 +1179,15 @@ g_application_register (GApplication  *application,
 
   if (!application->priv->is_registered)
     {
-      if (~application->priv->flags & G_APPLICATION_NON_UNIQUE)
-        {
-          application->priv->impl =
-            g_application_impl_register (application, application->priv->id,
-                                         application->priv->flags,
-                                         application->priv->actions,
-                                         &application->priv->remote_actions,
-                                         cancellable, error);
-
-          if (application->priv->impl == NULL)
-            return FALSE;
-        }
+      application->priv->impl =
+        g_application_impl_register (application, application->priv->id,
+                                     application->priv->flags,
+                                     application->priv->actions,
+                                     &application->priv->remote_actions,
+                                     cancellable, error);
+
+      if (application->priv->impl == NULL)
+        return FALSE;
 
       application->priv->is_remote = application->priv->remote_actions != NULL;
       application->priv->is_registered = TRUE;
diff --git a/gio/gapplicationimpl-dbus.c b/gio/gapplicationimpl-dbus.c
index 2dfc153..5a512f8 100644
--- a/gio/gapplicationimpl-dbus.c
+++ b/gio/gapplicationimpl-dbus.c
@@ -218,6 +218,7 @@ application_path_from_appid (const gchar *appid)
  */
 static gboolean
 g_application_impl_attempt_primary (GApplicationImpl  *impl,
+                                    gboolean           non_unique,
                                     GCancellable      *cancellable,
                                     GError           **error)
 {
@@ -267,6 +268,21 @@ g_application_impl_attempt_primary (GApplicationImpl  *impl,
   if (impl->actions_id == 0)
     return FALSE;
 
+  if (non_unique)
+    {
+      /* If this is a non-unique application then it is sufficient to
+       * have our object paths registered. We can return now.
+       *
+       * Note: non-unique applications always act as primary-instance.
+       */
+      impl->primary = TRUE;
+      return TRUE;
+    }
+
+  /* If this is a unique application then we need to attempt to own
+   * the well-known name and fall back to remote mode (!is_primary)
+   * in the case that we can't do that.
+   */
   /* DBUS_NAME_FLAG_DO_NOT_QUEUE: 0x4 */
   reply = g_dbus_connection_call_sync (impl->session_bus, "org.freedesktop.DBus", "/org/freedesktop/DBus",
                                        "org.freedesktop.DBus", "RequestName",
@@ -367,7 +383,11 @@ g_application_impl_register (GApplication        *application,
    */
   if (~flags & G_APPLICATION_IS_LAUNCHER)
     {
-      if (!g_application_impl_attempt_primary (impl, cancellable, error))
+      gboolean non_unique;
+
+      non_unique = (flags & G_APPLICATION_NON_UNIQUE) != 0;
+
+      if (!g_application_impl_attempt_primary (impl, non_unique, cancellable, error))
         {
           g_application_impl_destroy (impl);
           return NULL;



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