mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-11 15:06:14 +01:00
GApplication: add default application
This commit is contained in:
parent
95c3796d6a
commit
a81cdf297c
@ -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: */
|
||||
|
@ -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__ */
|
||||
|
Loading…
Reference in New Issue
Block a user