GApplication: put non-unique apps on D-Bus
authorRyan Lortie <desrt@desrt.ca>
Thu, 9 Feb 2012 17:15:49 +0000 (12:15 -0500)
committerRyan Lortie <desrt@desrt.ca>
Thu, 9 Feb 2012 17:15:49 +0000 (12:15 -0500)
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
gio/gapplicationimpl-dbus.c

index 1aab950..0d523d3 100644 (file)
@@ -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;
index 2dfc153..5a512f8 100644 (file)
@@ -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;