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
This commit is contained in:
Ryan Lortie 2012-02-09 12:15:49 -05:00
parent db38923c94
commit 40e9192d72
2 changed files with 29 additions and 12 deletions

View File

@ -1179,18 +1179,15 @@ g_application_register (GApplication *application,
if (!application->priv->is_registered) 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->impl = application->priv->flags,
g_application_impl_register (application, application->priv->id, application->priv->actions,
application->priv->flags, &application->priv->remote_actions,
application->priv->actions, cancellable, error);
&application->priv->remote_actions,
cancellable, error);
if (application->priv->impl == NULL) if (application->priv->impl == NULL)
return FALSE; return FALSE;
}
application->priv->is_remote = application->priv->remote_actions != NULL; application->priv->is_remote = application->priv->remote_actions != NULL;
application->priv->is_registered = TRUE; application->priv->is_registered = TRUE;

View File

@ -218,6 +218,7 @@ application_path_from_appid (const gchar *appid)
*/ */
static gboolean static gboolean
g_application_impl_attempt_primary (GApplicationImpl *impl, g_application_impl_attempt_primary (GApplicationImpl *impl,
gboolean non_unique,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
@ -267,6 +268,21 @@ g_application_impl_attempt_primary (GApplicationImpl *impl,
if (impl->actions_id == 0) if (impl->actions_id == 0)
return FALSE; 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 */ /* DBUS_NAME_FLAG_DO_NOT_QUEUE: 0x4 */
reply = g_dbus_connection_call_sync (impl->session_bus, "org.freedesktop.DBus", "/org/freedesktop/DBus", reply = g_dbus_connection_call_sync (impl->session_bus, "org.freedesktop.DBus", "/org/freedesktop/DBus",
"org.freedesktop.DBus", "RequestName", "org.freedesktop.DBus", "RequestName",
@ -367,7 +383,11 @@ g_application_impl_register (GApplication *application,
*/ */
if (~flags & G_APPLICATION_IS_LAUNCHER) 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); g_application_impl_destroy (impl);
return NULL; return NULL;