From: Ryan Lortie Date: Fri, 30 Sep 2011 03:52:16 +0000 (-0400) Subject: GApplication: add default application X-Git-Tag: 2.31.4~140 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a81cdf297ca97e375d28463556a7b838f4fb0ac1;p=platform%2Fupstream%2Fglib.git GApplication: add default application --- diff --git a/gio/gapplication.c b/gio/gapplication.c index 8480ed8..b6cdd86 100644 --- a/gio/gapplication.c +++ b/gio/gapplication.c @@ -474,6 +474,9 @@ g_application_constructed (GObject *object) GApplication *application = G_APPLICATION (object); g_assert (application->priv->id != NULL); + + if (g_application_get_default () == NULL) + g_application_set_default (application); } static void @@ -485,6 +488,9 @@ g_application_finalize (GObject *object) g_application_impl_destroy (application->priv->impl); g_free (application->priv->id); + if (g_application_get_default () == application) + g_application_set_default (NULL); + G_OBJECT_CLASS (g_application_parent_class) ->finalize (object); } @@ -1484,5 +1490,48 @@ g_application_action_group_iface_init (GActionGroupInterface *iface) iface->activate_action = g_application_activate_action; } +/* Default Application {{{1 */ + +static GApplication *default_app; + +/** + * g_application_get_default: + * @returns: (transfer none): the default application for this process, or %NULL + * + * Returns the default #GApplication instance for this process. + * + * Normally there is only one #GApplication per process and it becomes + * the default when it is created. You can exercise more control over + * this by using g_application_set_default(). + * + * If there is no default application then %NULL is returned. + * + * Since: 2.32 + **/ +GApplication * +g_application_get_default (void) +{ + return default_app; +} + +/** + * g_application_set_default: + * @application: the application to set as default, or %NULL + * + * Sets or unsets the default application for the process, as returned + * by g_application_get_default(). + * + * This function does not take its own reference on @application. If + * @application is destroyed then the default application will revert + * back to %NULL. + * + * Since: 2.32 + **/ +void +g_application_set_default (GApplication *application) +{ + default_app = application; +} + /* Epilogue {{{1 */ /* vim:set foldmethod=marker: */ diff --git a/gio/gapplication.h b/gio/gapplication.h index 254b841..ce68220 100644 --- a/gio/gapplication.h +++ b/gio/gapplication.h @@ -169,6 +169,9 @@ int g_application_run (GApplic int argc, char **argv); +GApplication * g_application_get_default (void); +void g_application_set_default (GApplication *application); + G_END_DECLS #endif /* __G_APPLICATION_H__ */