[glib/wip/menus-rebase2: 13/64] GApplication: add default application
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/menus-rebase2: 13/64] GApplication: add default application
- Date: Fri, 18 Nov 2011 16:26:31 +0000 (UTC)
commit 3b642c287dc57c664e195251d9cda78ab26d4b3e
Author: Ryan Lortie <desrt desrt ca>
Date: Thu Sep 29 23:52:16 2011 -0400
GApplication: add default application
gio/gapplication.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
gio/gapplication.h | 3 +++
2 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/gio/gapplication.c b/gio/gapplication.c
index b9f735b..9eaba61 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);
}
@@ -1492,5 +1498,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__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]