-/* GIO - GLib Input, Output and Streaming Library
+/*
+ * Copyright © 2010 Codethink Limited
*
- * Copyright © 2010 Red Hat, Inc
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the licence or (at
+ * your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
- * Authors: Colin Walters <walters@verbum.org>
- * Emmanuele Bassi <ebassi@linux.intel.com>
+ * Authors: Ryan Lortie <desrt@desrt.ca>
*/
+/* Prologue {{{1 */
#include "config.h"
-#include <string.h>
-#include <stdlib.h>
-
-#include <gobject/gvaluecollector.h>
-
#include "gapplication.h"
-#include "gio-marshal.h"
-#include "glibintl.h"
-#include "gioerror.h"
+#include "gapplicationcommandline.h"
+#include "gapplicationimpl.h"
+#include "gactiongroup.h"
+#include "gmenumodel.h"
+#include "gsettings.h"
+
+#include "gioenumtypes.h"
+#include "gioenums.h"
+#include "gfile.h"
-#include "gdbusconnection.h"
-#include "gdbusintrospection.h"
-#include "gdbusmethodinvocation.h"
+#include "glibintl.h"
-#include "gioalias.h"
+#include <string.h>
/**
- * SECTION: gapplication
+ * SECTION:gapplication
* @title: GApplication
* @short_description: Core application class
*
- * A #GApplication is the foundation of an application, unique for
- * a given application identifier. The #GApplication wraps some
- * low-level platform-specific services; it's expected that most
- * software will use a higher-level application class such as
- * #GtkApplication or #MxApplication.
+ * A #GApplication is the foundation of an application, unique for a
+ * given application identifier. The GApplication class wraps some
+ * low-level platform-specific services and is intended to act as the
+ * foundation for higher-level application classes such as
+ * #GtkApplication or #MxApplication. In general, you should not use
+ * this class outside of a higher level framework.
*
- * In addition to single-instance-ness, #GApplication provides support
- * for 'actions', which can be presented to the user in a platform-specific
- * way (e.g. Windows 7 jump lists). Note that these are just simple actions
- * without parameters. For more flexible scriptability, implementing a
- * a separate D-Bus interface is recommended, see e.g.
- * <xref linkend="gdbus-convenience"/>.
+ * One of the core features that GApplication provides is process
+ * uniqueness, in the context of a "session". The session concept is
+ * platform-dependent, but corresponds roughly to a graphical desktop
+ * login. When your application is launched again, its arguments
+ * are passed through platform communication to the already running
+ * program. The already running instance of the program is called the
+ * <firstterm>primary instance</firstterm>.
*
- * Before using #GApplication, you must choose an "application identifier".
+ * Before using GApplication, you must choose an "application identifier".
* The expected form of an application identifier is very close to that of
* of a <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface">DBus bus name</ulink>.
- * Examples include: "com.example.MyApp" "org.example.internal-apps.Calculator"
- * For convenience, the restrictions on application identifiers are reproduced
- * here:
+ * Examples include: "com.example.MyApp", "org.example.internal-apps.Calculator".
+ * For details on valid application identifiers, see
+ * g_application_id_is_valid().
+ *
+ * The application identifier is claimed by the application as a
+ * well-known bus name on the user's session bus. This means that the
+ * uniqueness of your application is scoped to the current session. It
+ * also means that your application may provide additional services
+ * (through registration of other object paths) at that bus name.
+ *
+ * The registration of these object paths should be done with the shared
+ * GDBus session bus. Note that due to the internal architecture of
+ * GDBus, method calls can be dispatched at any time (even if a main
+ * loop is not running). For this reason, you must ensure that any
+ * object paths that you wish to register are registered before
+ * #GApplication attempts to acquire the bus name of your application
+ * (which happens in g_application_register()). Unfortunately, this
+ * means that you cannot use g_application_get_is_remote() to decide if
+ * you want to register object paths.
+ *
+ * GApplication provides convenient life cycle management by maintaining
+ * a <firstterm>use count</firstterm> for the primary application instance.
+ * The use count can be changed using g_application_hold() and
+ * g_application_release(). If it drops to zero, the application exits.
+ *
+ * GApplication also implements the #GActionGroup interface and lets you
+ * easily export actions by adding them with g_application_set_action_group().
+ * When invoking an action by calling g_action_group_activate_action() on
+ * the application, it is always invoked in the primary instance. The actions
+ * are also exported on the session bus, and GIO provides the #GDBusActionGroup
+ * wrapper to conveniently access them remotely. Additionally,
+ * g_application_set_menu() can be used to export representation data
+ * for the actions, in the form of a #GMenuModel.
+ *
+ * There is a number of different entry points into a #GApplication:
* <itemizedlist>
- * <listitem>Application identifiers must contain only the ASCII characters "[A-Z][a-z][0-9]_-" and must not begin with a digit.</listitem>
- * <listitem>Application identifiers must contain at least one '.' (period) character (and thus at least two elements).</listitem>
- * <listitem>Application identifiers must not begin with a '.' (period) character.</listitem>
- * <listitem>Application identifiers must not exceed 255 characters.</listitem>
+ * <listitem>via 'Activate' (i.e. just starting the application)</listitem>
+ * <listitem>via 'Open' (i.e. opening some files)</listitem>
+ * <listitem>by handling a command-line</listitem>
+ * <listitem>via activating an action</listitem>
* </itemizedlist>
+ * The #GApplication::startup signal lets you handle the application
+ * initialization for all of these in a single place.
*
- * <refsect2><title>D-Bus implementation</title>
- * <para>
- * On UNIX systems using D-Bus, #GApplication is implemented by claiming the
- * application identifier as a bus name on the session bus. The implementation
- * exports an object at the object path that is created by replacing '.' with
- * '/' in the application identifier (e.g. the object path for the
- * application id 'org.gtk.TestApp' is '/org/gtk/TestApp'). The object
- * implements the org.gtk.Application interface.
- * </para>
- * <classsynopsis class="interface">
- * <ooclass><interfacename>org.gtk.Application</interfacename></ooclass>
- * <methodsynopsis>
- * <void/>
- * <methodname>Activate</methodname>
- * <methodparam><modifier>in</modifier><type>aay</type><parameter>arguments</parameter></methodparam>
- * <methodparam><modifier>in</modifier><type>a{sv}</type><parameter>data</parameter></methodparam>
- * </methodsynopsis>
- * <methodsynopsis>
- * <void/>
- * <methodname>InvokeAction</methodname>
- * <methodparam><modifier>in</modifier><type>s</type><parameter>action</parameter></methodparam>
- * <methodparam><modifier>in</modifier><type>u</type><parameter>timestamp</parameter></methodparam>
- * </methodsynopsis>
- * <methodsynopsis>
- * <type>a{s(sb)}</type>
- * <methodname>ListActions</methodname>
- * <void/>
- * </methodsynopsis>
- * <methodsynopsis>
- * <void/>
- * <methodname>Quit</methodname>
- * <methodparam><modifier>in</modifier><type>u</type><parameter>timestamp</parameter></methodparam>
- * </methodsynopsis>
- * <methodsynopsis>
- * <modifier>Signal</modifier>
- * <void/>
- * <methodname>ActionsChanged</methodname>
- * <void/>
- * </methodsynopsis>
- * </classsynopsis>
- * <para>
- * The <methodname>Activate</methodname> function is called on the existing
- * application instance when a second instance fails to take the bus name.
- * @arguments contains the commandline arguments given to the second instance
- * and @data contains platform-specific additional data, see
- * g_application_format_activation_data().
- * </para>
- * <para>
- * The <methodname>InvokeAction</methodname> function can be called to invoke
- * one of the actions exported by the application. The @timestamp parameter
- * should be taken from the user event that triggered the method call (e.g.
- * a button press event).
- * </para>
- * <para>
- * The <methodname>ListActions</methodname> function returns a dictionary
- * with the exported actions of the application. The keys of the dictionary
- * are the action names, and the values are structs containing the description
- * for the action and a boolean that represents if the action is enabled or not.
- * </para>
- * <para>
- * The <methodname>Quit</methodname> function can be called to terminate
- * the application. The @timestamp parameter should be taken from the user
- * event that triggered the method call (e.g. a button press event).
- * </para>
- * <para>
- * The <methodname>ActionsChanged</methodname> signal is emitted when the
- * exported actions change (i.e. an action is added, removed, enabled,
- * disabled, or otherwise changed).
- * </para>
- * </refsect2>
- *
- * Since: 2.24
+ * Regardless of which of these entry points is used to start the application,
+ * GApplication passes some <firstterm id="platform-data">platform
+ * data</firstterm> from the launching instance to the primary instance,
+ * in the form of a #GVariant dictionary mapping strings to variants.
+ * To use platform data, override the @before_emit or @after_emit virtual
+ * functions in your #GApplication subclass. When dealing with
+ * #GApplicationCommandline objects, the platform data is directly
+ * available via g_application_command_line_get_cwd(),
+ * g_application_command_line_get_environ() and
+ * g_application_command_line_get_platform_data().
+ *
+ * As the name indicates, the platform data may vary depending on the
+ * operating system, but it always includes the current directory (key
+ * "cwd"), and optionally the environment (ie the set of environment
+ * variables and their values) of the calling process (key "environ").
+ * The environment is only added to the platform data if the
+ * #G_APPLICATION_SEND_ENVIONMENT flag is set. GApplication subclasses
+ * can add their own platform data by overriding the @add_platform_data
+ * virtual function. For instance, #GtkApplication adds startup notification
+ * data in this way.
+ *
+ * To parse commandline arguments you may handle the
+ * #GApplication::command-line signal or override the local_command_line()
+ * vfunc, to parse them in either the primary instance or the local instance,
+ * respectively.
+ *
+ * <example id="gapplication-example-open"><title>Opening files with a GApplication</title>
+ * <programlisting>
+ * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-open.c">
+ * <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
+ * </xi:include>
+ * </programlisting>
+ * </example>
+ *
+ * <example id="gapplication-example-actions"><title>A GApplication with actions</title>
+ * <programlisting>
+ * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-actions.c">
+ * <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
+ * </xi:include>
+ * </programlisting>
+ * </example>
+ *
+ * <example id="gapplication-example-menu"><title>A GApplication with menus</title>
+ * <programlisting>
+ * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-menu.c">
+ * <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
+ * </xi:include>
+ * </programlisting>
+ * </example>
*/
-G_DEFINE_TYPE (GApplication, g_application, G_TYPE_OBJECT);
-
-enum
+struct _GApplicationPrivate
{
- PROP_0,
+ GApplicationFlags flags;
+ gchar *id;
+
+ GActionGroup *actions;
+ GMenuModel *menu;
+
+ guint inactivity_timeout_id;
+ guint inactivity_timeout;
+ guint use_count;
+
+ guint is_registered : 1;
+ guint is_remote : 1;
+ guint did_startup : 1;
+ guint did_shutdown : 1;
- PROP_APPID,
- PROP_DEFAULT_QUIT,
- PROP_IS_REMOTE
+ GActionGroup *remote_actions;
+ GApplicationImpl *impl;
};
enum
{
- QUIT,
- ACTION,
- PREPARE_ACTIVATION,
+ PROP_NONE,
+ PROP_APPLICATION_ID,
+ PROP_FLAGS,
+ PROP_IS_REGISTERED,
+ PROP_IS_REMOTE,
+ PROP_INACTIVITY_TIMEOUT,
+ PROP_ACTION_GROUP,
+ PROP_MENU
+};
- LAST_SIGNAL
+enum
+{
+ SIGNAL_STARTUP,
+ SIGNAL_SHUTDOWN,
+ SIGNAL_ACTIVATE,
+ SIGNAL_OPEN,
+ SIGNAL_ACTION,
+ SIGNAL_COMMAND_LINE,
+ NR_SIGNALS
};
-static guint application_signals[LAST_SIGNAL] = { 0 };
+static guint g_application_signals[NR_SIGNALS];
-typedef struct {
- char *name;
- char *description;
- guint enabled : 1;
-} GApplicationAction;
+static void g_application_action_group_iface_init (GActionGroupInterface *);
+G_DEFINE_TYPE_WITH_CODE (GApplication, g_application, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP,
+ g_application_action_group_iface_init))
-struct _GApplicationPrivate
+/* vfunc defaults {{{1 */
+static void
+g_application_real_before_emit (GApplication *application,
+ GVariant *platform_data)
{
- char *appid;
- GHashTable *actions; /* name -> GApplicationAction */
- GMainLoop *mainloop;
+}
- guint default_quit : 1;
- guint is_remote : 1;
+static void
+g_application_real_after_emit (GApplication *application,
+ GVariant *platform_data)
+{
+}
- guint actions_changed_id;
+static void
+g_application_real_startup (GApplication *application)
+{
+ application->priv->did_startup = TRUE;
+}
-#ifdef G_OS_UNIX
- char *dbus_path;
- GDBusConnection *session_bus;
-#endif
-};
+static void
+g_application_real_shutdown (GApplication *application)
+{
+ application->priv->did_shutdown = TRUE;
+}
-static GApplication *primary_application = NULL;
-static GHashTable *instances_for_appid = NULL;
-
-static void _g_application_platform_init (GApplication *app);
-static gboolean _g_application_platform_acquire_single_instance (GApplication *app,
- GError **error);
-static void _g_application_platform_remote_invoke_action (GApplication *app,
- const char *action,
- guint timestamp);
-static void _g_application_platform_remote_quit (GApplication *app,
- guint timestamp);
-static void _g_application_platform_activate (GApplication *app,
- GVariant *data) G_GNUC_NORETURN;
-static void _g_application_platform_on_actions_changed (GApplication *app);
-
-#ifdef G_OS_UNIX
-#include "gdbusapplication.c"
-#else
-#include "gnullapplication.c"
-#endif
+static void
+g_application_real_activate (GApplication *application)
+{
+ if (!g_signal_has_handler_pending (application,
+ g_application_signals[SIGNAL_ACTIVATE],
+ 0, TRUE) &&
+ G_APPLICATION_GET_CLASS (application)->activate == g_application_real_activate)
+ {
+ static gboolean warned;
-static gboolean
-_g_application_validate_id (const char *id)
+ if (warned)
+ return;
+
+ g_warning ("Your application does not implement "
+ "g_application_activate() and has no handlers connected "
+ "to the 'activate' signal. It should do one of these.");
+ warned = TRUE;
+ }
+}
+
+static void
+g_application_real_open (GApplication *application,
+ GFile **files,
+ gint n_files,
+ const gchar *hint)
{
- gboolean allow_dot;
+ if (!g_signal_has_handler_pending (application,
+ g_application_signals[SIGNAL_OPEN],
+ 0, TRUE) &&
+ G_APPLICATION_GET_CLASS (application)->open == g_application_real_open)
+ {
+ static gboolean warned;
- if (strlen (id) > 255)
- return FALSE;
+ if (warned)
+ return;
- if (!g_ascii_isalpha (*id))
+ g_warning ("Your application claims to support opening files "
+ "but does not implement g_application_open() and has no "
+ "handlers connected to the 'open' signal.");
+ warned = TRUE;
+ }
+}
+
+static int
+g_application_real_command_line (GApplication *application,
+ GApplicationCommandLine *cmdline)
+{
+ if (!g_signal_has_handler_pending (application,
+ g_application_signals[SIGNAL_COMMAND_LINE],
+ 0, TRUE) &&
+ G_APPLICATION_GET_CLASS (application)->command_line == g_application_real_command_line)
+ {
+ static gboolean warned;
+
+ if (warned)
+ return 1;
+
+ g_warning ("Your application claims to support custom command line "
+ "handling but does not implement g_application_command_line() "
+ "and has no handlers connected to the 'command-line' signal.");
+
+ warned = TRUE;
+ }
+
+ return 1;
+}
+
+static gboolean
+g_application_real_local_command_line (GApplication *application,
+ gchar ***arguments,
+ int *exit_status)
+{
+ if (application->priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE)
return FALSE;
- id++;
- allow_dot = FALSE;
- for (; *id; id++)
+ else
{
- if (g_ascii_isalnum (*id) || (*id == '-') || (*id == '_'))
- allow_dot = TRUE;
- else if (allow_dot && *id == '.')
- allow_dot = FALSE;
+ GError *error = NULL;
+ gint n_args;
+
+ if (!g_application_register (application, NULL, &error))
+ {
+ g_critical ("%s", error->message);
+ g_error_free (error);
+ *exit_status = 1;
+ return TRUE;
+ }
+
+ n_args = g_strv_length (*arguments);
+
+ if (application->priv->flags & G_APPLICATION_IS_SERVICE)
+ {
+ if ((*exit_status = n_args > 1))
+ {
+ g_printerr ("GApplication service mode takes no arguments.\n");
+ application->priv->flags &= ~G_APPLICATION_IS_SERVICE;
+ }
+
+ return TRUE;
+ }
+
+ if (n_args <= 1)
+ {
+ g_application_activate (application);
+ *exit_status = 0;
+ }
+
else
- return FALSE;
+ {
+ if (~application->priv->flags & G_APPLICATION_HANDLES_OPEN)
+ {
+ g_critical ("This application can not open files.");
+ *exit_status = 1;
+ }
+ else
+ {
+ GFile **files;
+ gint n_files;
+ gint i;
+
+ n_files = n_args - 1;
+ files = g_new (GFile *, n_files);
+
+ for (i = 0; i < n_files; i++)
+ files[i] = g_file_new_for_commandline_arg ((*arguments)[i + 1]);
+
+ g_application_open (application, files, n_files, "");
+
+ for (i = 0; i < n_files; i++)
+ g_object_unref (files[i]);
+ g_free (files);
+
+ *exit_status = 0;
+ }
+ }
+
+ return TRUE;
}
- return TRUE;
}
-static gpointer
-init_appid_statics (gpointer data)
+static void
+g_application_real_add_platform_data (GApplication *application,
+ GVariantBuilder *builder)
{
- instances_for_appid = g_hash_table_new (g_str_hash, g_str_equal);
- return NULL;
}
-static GApplication *
-application_for_appid (const char *appid)
+/* GObject implementation stuff {{{1 */
+static void
+g_application_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- static GOnce appid_once = G_ONCE_INIT;
+ GApplication *application = G_APPLICATION (object);
+
+ switch (prop_id)
+ {
+ case PROP_APPLICATION_ID:
+ g_application_set_application_id (application,
+ g_value_get_string (value));
+ break;
+
+ case PROP_FLAGS:
+ g_application_set_flags (application, g_value_get_flags (value));
+ break;
+
+ case PROP_INACTIVITY_TIMEOUT:
+ g_application_set_inactivity_timeout (application,
+ g_value_get_uint (value));
+ break;
+
+ case PROP_ACTION_GROUP:
+ g_application_set_action_group (application,
+ g_value_get_object (value));
+ break;
- g_once (&appid_once, init_appid_statics, NULL);
+ case PROP_MENU:
+ g_application_set_menu (application,
+ g_value_get_object (value));
+ break;
- return g_hash_table_lookup (instances_for_appid, appid);
+ default:
+ g_assert_not_reached ();
+ }
}
-static gboolean
-g_application_default_quit (GApplication *application,
- guint timestamp)
+/**
+ * g_application_set_action_group:
+ * @application: a #GApplication
+ * @action_group: (allow-none): a #GActionGroup, or %NULL
+ *
+ * Sets or unsets the group of actions associated with the application.
+ *
+ * These actions can be invoked remotely.
+ *
+ * It is an error to call this function after the application has been
+ * registered.
+ *
+ * Since: 2.28
+ **/
+void
+g_application_set_action_group (GApplication *application,
+ GActionGroup *action_group)
{
- g_return_val_if_fail (application->priv->mainloop != NULL, FALSE);
- g_main_loop_quit (application->priv->mainloop);
+ g_return_if_fail (G_IS_APPLICATION (application));
+ g_return_if_fail (!application->priv->is_registered);
- return TRUE;
+ if (application->priv->actions != NULL)
+ g_object_unref (application->priv->actions);
+
+ application->priv->actions = action_group;
+
+ if (application->priv->actions != NULL)
+ g_object_ref (application->priv->actions);
}
-static void
-g_application_default_run (GApplication *application)
+/**
+ * g_application_set_menu:
+ * @application: a #GApplication
+ * @menu: (allow-none): a #GMenuModel, or %NULL
+ *
+ * Sets or unsets the menu associated with the application. The menu
+ * provides representation data for the exported actions of @application.
+ *
+ * It is an error to call this function after the application has been
+ * registered.
+ *
+ * Since: 2.32
+ */
+void
+g_application_set_menu (GApplication *application,
+ GMenuModel *menu)
{
- if (application->priv->mainloop == NULL)
- application->priv->mainloop = g_main_loop_new (NULL, TRUE);
+ g_return_if_fail (G_IS_APPLICATION (application));
+ g_return_if_fail (!application->priv->is_registered);
- g_main_loop_run (application->priv->mainloop);
+ if (application->priv->menu != NULL)
+ g_object_unref (application->priv->menu);
+
+ application->priv->menu = menu;
+
+ if (application->priv->menu != NULL)
+ g_object_ref (application->priv->menu);
}
-static void
-_g_application_handle_activation (GApplication *app,
- int argc,
- char **argv,
- GVariant *platform_data)
+/**
+ * g_application_get_menu:
+ * @application: a #GApplication
+ *
+ * Returns the menu model that has been set
+ * with g_application_set_menu().
+ *
+ * Returns: the #GMenuModel associated with @application
+ *
+ * Since: 2.32
+ */
+GMenuModel *
+g_application_get_menu (GApplication *application)
{
- GVariantBuilder builder;
- GVariant *message;
- int i;
+ g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("(aaya{sv})"));
- g_variant_builder_open (&builder, G_VARIANT_TYPE ("aay"));
+ return application->priv->menu;
+}
- for (i = 1; i < argc; i++)
+static void
+g_application_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GApplication *application = G_APPLICATION (object);
+
+ switch (prop_id)
{
- int j;
- guint8 *argv_bytes;
+ case PROP_APPLICATION_ID:
+ g_value_set_string (value,
+ g_application_get_application_id (application));
+ break;
- g_variant_builder_open (&builder, G_VARIANT_TYPE ("ay"));
+ case PROP_FLAGS:
+ g_value_set_flags (value,
+ g_application_get_flags (application));
+ break;
- argv_bytes = (guint8*) argv[i];
- for (j = 0; argv_bytes[j]; j++)
- g_variant_builder_add_value (&builder,
- g_variant_new_byte (argv_bytes[j]));
- g_variant_builder_close (&builder);
- }
- g_variant_builder_close (&builder);
+ case PROP_IS_REGISTERED:
+ g_value_set_boolean (value,
+ g_application_get_is_registered (application));
+ break;
- if (platform_data)
- g_variant_builder_add (&builder, "@a{sv}", platform_data);
- else
- {
- g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{sv}"));
- g_variant_builder_close (&builder);
+ case PROP_IS_REMOTE:
+ g_value_set_boolean (value,
+ g_application_get_is_remote (application));
+ break;
+
+ case PROP_INACTIVITY_TIMEOUT:
+ g_value_set_uint (value,
+ g_application_get_inactivity_timeout (application));
+ break;
+
+ default:
+ g_assert_not_reached ();
}
+}
- message = g_variant_builder_end (&builder);
- _g_application_platform_activate (app, message);
- g_variant_unref (message);
+static void
+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 gboolean
-timeout_handle_actions_changed (gpointer user_data)
+static void
+g_application_finalize (GObject *object)
{
- GApplication *application = user_data;
+ GApplication *application = G_APPLICATION (object);
- application->priv->actions_changed_id = 0;
+ if (application->priv->impl)
+ g_application_impl_destroy (application->priv->impl);
+ g_free (application->priv->id);
- _g_application_platform_on_actions_changed (application);
+ if (g_application_get_default () == application)
+ g_application_set_default (NULL);
- return FALSE;
+ G_OBJECT_CLASS (g_application_parent_class)
+ ->finalize (object);
}
-static inline void
-queue_actions_change_notification (GApplication *application)
+static void
+g_application_init (GApplication *application)
{
- GApplicationPrivate *priv = application->priv;
-
- if (priv->actions_changed_id == 0)
- priv->actions_changed_id = g_timeout_add (0, timeout_handle_actions_changed, application);
+ application->priv = G_TYPE_INSTANCE_GET_PRIVATE (application,
+ G_TYPE_APPLICATION,
+ GApplicationPrivate);
}
static void
-g_application_action_free (gpointer data)
+g_application_class_init (GApplicationClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->constructed = g_application_constructed;
+ object_class->finalize = g_application_finalize;
+ object_class->get_property = g_application_get_property;
+ object_class->set_property = g_application_set_property;
+
+ class->before_emit = g_application_real_before_emit;
+ class->after_emit = g_application_real_after_emit;
+ class->startup = g_application_real_startup;
+ class->shutdown = g_application_real_shutdown;
+ class->activate = g_application_real_activate;
+ class->open = g_application_real_open;
+ class->command_line = g_application_real_command_line;
+ class->local_command_line = g_application_real_local_command_line;
+ class->add_platform_data = g_application_real_add_platform_data;
+
+ g_object_class_install_property (object_class, PROP_APPLICATION_ID,
+ g_param_spec_string ("application-id",
+ P_("Application identifier"),
+ P_("The unique identifier for the application"),
+ NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class, PROP_FLAGS,
+ g_param_spec_flags ("flags",
+ P_("Application flags"),
+ P_("Flags specifying the behaviour of the application"),
+ G_TYPE_APPLICATION_FLAGS, G_APPLICATION_FLAGS_NONE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class, PROP_IS_REGISTERED,
+ g_param_spec_boolean ("is-registered",
+ P_("Is registered"),
+ P_("If g_application_register() has been called"),
+ FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class, PROP_IS_REMOTE,
+ g_param_spec_boolean ("is-remote",
+ P_("Is remote"),
+ P_("If this application instance is remote"),
+ FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class, PROP_INACTIVITY_TIMEOUT,
+ g_param_spec_uint ("inactivity-timeout",
+ P_("Inactivity timeout"),
+ P_("Time (ms) to stay alive after becoming idle"),
+ 0, G_MAXUINT, 0,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class, PROP_ACTION_GROUP,
+ g_param_spec_object ("action-group",
+ P_("Action group"),
+ P_("The group of actions that the application exports"),
+ G_TYPE_ACTION_GROUP,
+ G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class, PROP_MENU,
+ g_param_spec_object ("menu",
+ P_("Menu model"),
+ P_("The menu that the application exports"),
+ G_TYPE_MENU_MODEL,
+ G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GApplication::startup:
+ * @application: the application
+ *
+ * The ::startup signal is emitted on the primary instance immediately
+ * after registration. See g_application_register().
+ */
+ g_application_signals[SIGNAL_STARTUP] =
+ g_signal_new ("startup", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GApplicationClass, startup),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+ /**
+ * GApplication::shutdown:
+ * @application: the application
+ *
+ * The ::shutdown signal is emitted only on the registered primary instance
+ * immediately after the main loop terminates.
+ */
+ g_application_signals[SIGNAL_SHUTDOWN] =
+ g_signal_new ("shutdown", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GApplicationClass, shutdown),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+ /**
+ * GApplication::activate:
+ * @application: the application
+ *
+ * The ::activate signal is emitted on the primary instance when an
+ * activation occurs. See g_application_activate().
+ */
+ g_application_signals[SIGNAL_ACTIVATE] =
+ g_signal_new ("activate", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GApplicationClass, activate),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+
+ /**
+ * GApplication::open:
+ * @application: the application
+ * @files: (array length=n_files) (element-type GFile): an array of #GFiles
+ * @n_files: the length of @files
+ * @hint: a hint provided by the calling instance
+ *
+ * The ::open signal is emitted on the primary instance when there are
+ * files to open. See g_application_open() for more information.
+ */
+ g_application_signals[SIGNAL_OPEN] =
+ g_signal_new ("open", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GApplicationClass, open),
+ NULL, NULL, NULL,
+ G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);
+
+ /**
+ * GApplication::command-line:
+ * @application: the application
+ * @command_line: a #GApplicationCommandLine representing the
+ * passed commandline
+ *
+ * The ::command-line signal is emitted on the primary instance when
+ * a commandline is not handled locally. See g_application_run() and
+ * the #GApplicationCommandline documentation for more information.
+ *
+ * Returns: An integer that is set as the exit status for the calling
+ * process. See g_application_command_line_set_exit_status().
+ */
+ g_application_signals[SIGNAL_COMMAND_LINE] =
+ g_signal_new ("command-line", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GApplicationClass, command_line),
+ g_signal_accumulator_first_wins, NULL,
+ NULL,
+ G_TYPE_INT, 1, G_TYPE_APPLICATION_COMMAND_LINE);
+
+ g_type_class_add_private (class, sizeof (GApplicationPrivate));
+}
+
+static GVariant *
+get_platform_data (GApplication *application)
{
- if (G_LIKELY (data != NULL))
+ GVariantBuilder *builder;
+ GVariant *result;
+
+ builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
+
+ {
+ gchar *cwd = g_get_current_dir ();
+ g_variant_builder_add (builder, "{sv}", "cwd",
+ g_variant_new_bytestring (cwd));
+ g_free (cwd);
+ }
+
+ if (application->priv->flags & G_APPLICATION_SEND_ENVIRONMENT)
{
- GApplicationAction *action = data;
+ GVariant *array;
+ gchar **envp;
- g_free (action->name);
- g_free (action->description);
+ envp = g_get_environ ();
+ array = g_variant_new_bytestring_array ((const gchar **) envp, -1);
+ g_strfreev (envp);
- g_slice_free (GApplicationAction, action);
+ g_variant_builder_add (builder, "{sv}", "environ", array);
}
+
+ G_APPLICATION_GET_CLASS (application)->
+ add_platform_data (application, builder);
+
+ result = g_variant_builder_end (builder);
+ g_variant_builder_unref (builder);
+
+ return result;
}
+/* Application ID validity {{{1 */
/**
- * g_application_new:
- * @appid: System-dependent application identifier
+ * g_application_id_is_valid:
+ * @application_id: a potential application identifier
*
- * Create a new #GApplication. The application is initially in
- * "remote" mode. Almost certainly, you want to call
- * g_application_register() immediately after this function, which
- * will finish initialization.
+ * Checks if @application_id is a valid application identifier.
*
- * As a convenience, this function is defined to call g_type_init() as
- * its very first action.
+ * A valid ID is required for calls to g_application_new() and
+ * g_application_set_application_id().
*
- * Returns: (transfer full): An application instance
+ * For convenience, the restrictions on application identifiers are
+ * reproduced here:
+ * <itemizedlist>
+ * <listitem>Application identifiers must contain only the ASCII characters "[A-Z][a-z][0-9]_-." and must not begin with a digit.</listitem>
+ * <listitem>Application identifiers must contain at least one '.' (period) character (and thus at least three elements).</listitem>
+ * <listitem>Application identifiers must not begin or end with a '.' (period) character.</listitem>
+ * <listitem>Application identifiers must not contain consecutive '.' (period) characters.</listitem>
+ * <listitem>Application identifiers must not exceed 255 characters.</listitem>
+ * </itemizedlist>
*
- * Since: 2.26
- */
-GApplication *
-g_application_new (const char *appid)
+ * Returns: %TRUE if @application_id is valid
+ **/
+gboolean
+g_application_id_is_valid (const gchar *application_id)
{
- g_type_init ();
+ gsize len;
+ gboolean allow_dot;
+ gboolean has_dot;
- return G_APPLICATION (g_object_new (G_TYPE_APPLICATION, "appid", appid, NULL));
-}
+ len = strlen (application_id);
-/**
- * g_application_register:
- * @application: A #GApplication
- * @argc: System argument count
- * @argv: (array length=argc): System argument vector
- * @platform_data: (allow-none): Arbitrary platform-specific data, must have signature "a{sv}"
- *
- * Ensure the current process is the unique owner of the application.
- * If successful, the #GApplication:is-remote property will be changed
- * to %FALSE, and it is safe to continue creating other resources
- * such as graphics windows.
- *
- * If the given @appid is already running in another process, the
- * #GApplication:default-exit property will be evaluated. If it's
- * %TRUE, then a platform-specific action such as bringing any
- * graphics windows associated with the application to the foreground
- * may be initiated. After that, the current process will terminate.
- * If %FALSE, then the application remains in the #GApplication:is-remote
- * state, and you can e.g. call g_application_invoke_action().
- */
-void
-g_application_register_with_data (GApplication *application,
- int argc,
- char **argv,
- GVariant *platform_data)
-{
- g_return_if_fail (application->priv->appid != NULL);
- g_return_if_fail (application->priv->is_remote);
- g_return_if_fail (platform_data == NULL
- || strcmp (g_variant_get_type_string (platform_data), "a{sv}") == 0);
+ if (len > 255)
+ return FALSE;
+
+ if (!g_ascii_isalpha (application_id[0]))
+ return FALSE;
- if (!_g_application_platform_acquire_single_instance (application, NULL))
+ if (application_id[len-1] == '.')
+ return FALSE;
+
+ application_id++;
+ allow_dot = TRUE;
+ has_dot = FALSE;
+ for (; *application_id; application_id++)
{
- if (application->priv->default_quit)
- _g_application_handle_activation (application, argc, argv, platform_data);
+ if (g_ascii_isalnum (*application_id) ||
+ (*application_id == '-') ||
+ (*application_id == '_'))
+ {
+ allow_dot = TRUE;
+ }
+ else if (allow_dot && *application_id == '.')
+ {
+ has_dot = TRUE;
+ allow_dot = FALSE;
+ }
else
- return;
+ return FALSE;
}
- application->priv->is_remote = FALSE;
+ if (!has_dot)
+ return FALSE;
- _g_application_platform_init (application);
+ return TRUE;
}
+/* Public Constructor {{{1 */
/**
- * g_application_new_and_register:
- * @appid: An application identifier
- * @argc: System argument count
- * @argv: (array length=argc): System argument vector
+ * g_application_new:
+ * @application_id: the application id
+ * @flags: the application flags
*
- * This is a convenience function which combines g_application_new()
- * with g_application_register_with_data().
- */
+ * Creates a new #GApplication instance.
+ *
+ * This function calls g_type_init() for you.
+ *
+ * The application id must be valid. See g_application_id_is_valid().
+ *
+ * Returns: a new #GApplication instance
+ **/
GApplication *
-g_application_new_and_register (const char *appid,
- int argc,
- char **argv)
+g_application_new (const gchar *application_id,
+ GApplicationFlags flags)
{
- GApplication *app = g_application_new (appid);
- g_application_register_with_data (app, argc, argv, NULL);
- return app;
+ g_return_val_if_fail (g_application_id_is_valid (application_id), NULL);
+
+ g_type_init ();
+
+ return g_object_new (G_TYPE_APPLICATION,
+ "application-id", application_id,
+ "flags", flags,
+ NULL);
}
+/* Simple get/set: application id, flags, inactivity timeout {{{1 */
/**
- * g_application_add_action:
+ * g_application_get_application_id:
* @application: a #GApplication
- * @name: the action name
- * @description: the action description; can be a translatable
- * string
*
- * Adds an action @name to the list of exported actions of @application.
+ * Gets the unique identifier for @application.
+ *
+ * Returns: the identifier for @application, owned by @application
+ *
+ * Since: 2.28
+ **/
+const gchar *
+g_application_get_application_id (GApplication *application)
+{
+ g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
+
+ return application->priv->id;
+}
+
+/**
+ * g_application_set_application_id:
+ * @application: a #GApplication
+ * @application_id: the identifier for @application
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * Sets the unique identifier for @application.
*
- * You can invoke an action using g_application_invoke_action().
+ * The application id can only be modified if @application has not yet
+ * been registered.
*
- * The newly added action is enabled by default; you can call
- * g_application_set_action_enabled() to disable it.
+ * The application id must be valid. See g_application_id_is_valid().
*
- * Since: 2.26
- */
+ * Since: 2.28
+ **/
void
-g_application_add_action (GApplication *application,
- const gchar *name,
- const gchar *description)
+g_application_set_application_id (GApplication *application,
+ const gchar *application_id)
{
- GApplicationPrivate *priv;
- GApplicationAction *action;
-
g_return_if_fail (G_IS_APPLICATION (application));
- g_return_if_fail (name != NULL && *name != '\0');
- g_return_if_fail (!application->priv->is_remote);
-
- priv = application->priv;
- g_return_if_fail (g_hash_table_lookup (priv->actions, name) == NULL);
+ if (g_strcmp0 (application->priv->id, application_id) != 0)
+ {
+ g_return_if_fail (g_application_id_is_valid (application_id));
+ g_return_if_fail (!application->priv->is_registered);
- action = g_slice_new (GApplicationAction);
- action->name = g_strdup (name);
- action->description = g_strdup (description);
- action->enabled = TRUE;
+ g_free (application->priv->id);
+ application->priv->id = g_strdup (application_id);
- g_hash_table_insert (priv->actions, action->name, action);
- queue_actions_change_notification (application);
+ g_object_notify (G_OBJECT (application), "application-id");
+ }
}
/**
- * g_application_remove_action:
+ * g_application_get_flags:
* @application: a #GApplication
- * @name: the name of the action to remove
*
- * Removes the action @name from the list of exported actions of @application.
+ * Gets the flags for @application.
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * See #GApplicationFlags.
*
- * Since: 2.26
- */
-void
-g_application_remove_action (GApplication *application,
- const gchar *name)
+ * Returns: the flags for @application
+ *
+ * Since: 2.28
+ **/
+GApplicationFlags
+g_application_get_flags (GApplication *application)
{
- GApplicationPrivate *priv;
-
- g_return_if_fail (G_IS_APPLICATION (application));
- g_return_if_fail (name != NULL && *name != '\0');
- g_return_if_fail (!application->priv->is_remote);
-
- priv = application->priv;
+ g_return_val_if_fail (G_IS_APPLICATION (application), 0);
- g_return_if_fail (g_hash_table_lookup (priv->actions, name) != NULL);
-
- g_hash_table_remove (priv->actions, name);
- queue_actions_change_notification (application);
+ return application->priv->flags;
}
/**
- * g_application_invoke_action:
+ * g_application_set_flags:
* @application: a #GApplication
- * @name: the name of the action to invoke
- * @timestamp: the timestamp that is going to be passed to
- * the #GApplication::action signal
+ * @flags: the flags for @application
*
- * Invokes the action @name of the passed #GApplication.
+ * Sets the flags for @application.
*
- * This function has different behavior depending on whether @application
- * is acting as a proxy for another process. In the normal case where
- * the current process is hosting the application, and the specified
- * action exists and is enabled, the #GApplication::action signal will
- * be emitted.
+ * The flags can only be modified if @application has not yet been
+ * registered.
*
- * If @application is a proxy, then the specified action will be invoked
- * in the remote process. It is not necessary to call
- * g_application_add_action() in the current process in order to invoke
- * one remotely.
+ * See #GApplicationFlags.
*
- * Since: 2.26
- */
+ * Since: 2.28
+ **/
void
-g_application_invoke_action (GApplication *application,
- const char *name,
- guint timestamp)
+g_application_set_flags (GApplication *application,
+ GApplicationFlags flags)
{
- GApplicationPrivate *priv;
- GApplicationAction *action;
-
g_return_if_fail (G_IS_APPLICATION (application));
- g_return_if_fail (name != NULL);
-
- priv = application->priv;
- if (priv->is_remote)
+ if (application->priv->flags != flags)
{
- _g_application_platform_remote_invoke_action (application, name, timestamp);
- return;
- }
+ g_return_if_fail (!application->priv->is_registered);
- action = g_hash_table_lookup (priv->actions, name);
- g_return_if_fail (action != NULL);
- if (!action->enabled)
- return;
+ application->priv->flags = flags;
- g_signal_emit (application, application_signals[ACTION],
- g_quark_from_string (name),
- name,
- timestamp);
+ g_object_notify (G_OBJECT (application), "flags");
+ }
}
/**
- * g_application_list_actions:
+ * g_application_get_inactivity_timeout:
* @application: a #GApplication
*
- * Retrieves the list of action names currently exported by @application.
+ * Gets the current inactivity timeout for the application.
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * This is the amount of time (in milliseconds) after the last call to
+ * g_application_release() before the application stops running.
*
- * Return value: (transfer full): a newly allocation, %NULL-terminated array
- * of strings containing action names; use g_strfreev() to free the
- * resources used by the returned array
+ * Returns: the timeout, in milliseconds
*
- * Since: 2.26
- */
-gchar **
-g_application_list_actions (GApplication *application)
+ * Since: 2.28
+ **/
+guint
+g_application_get_inactivity_timeout (GApplication *application)
{
- GApplicationPrivate *priv;
- GHashTableIter iter;
- gpointer key;
- gchar **retval;
- gint i;
-
- g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
- g_return_val_if_fail (!application->priv->is_remote, NULL);
-
- priv = application->priv;
-
- retval = g_new (gchar*, g_hash_table_size (priv->actions));
-
- i = 0;
- g_hash_table_iter_init (&iter, priv->actions);
- while (g_hash_table_iter_next (&iter, &key, NULL))
- retval[i++] = g_strdup (key);
-
- retval[i] = NULL;
+ g_return_val_if_fail (G_IS_APPLICATION (application), 0);
- return retval;
+ return application->priv->inactivity_timeout;
}
/**
- * g_application_set_action_enabled:
+ * g_application_set_inactivity_timeout:
* @application: a #GApplication
- * @name: the name of the application
- * @enabled: whether to enable or disable the action @name
+ * @inactivity_timeout: the timeout, in milliseconds
*
- * Sets whether the action @name inside @application should be enabled
- * or disabled.
+ * Sets the current inactivity timeout for the application.
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * This is the amount of time (in milliseconds) after the last call to
+ * g_application_release() before the application stops running.
*
- * Invoking a disabled action will not result in the #GApplication::action
- * signal being emitted.
+ * This call has no side effects of its own. The value set here is only
+ * used for next time g_application_release() drops the use count to
+ * zero. Any timeouts currently in progress are not impacted.
*
- * Since: 2.26
- */
+ * Since: 2.28
+ **/
void
-g_application_set_action_enabled (GApplication *application,
- const gchar *name,
- gboolean enabled)
+g_application_set_inactivity_timeout (GApplication *application,
+ guint inactivity_timeout)
{
- GApplicationAction *action;
-
g_return_if_fail (G_IS_APPLICATION (application));
- g_return_if_fail (name != NULL);
- g_return_if_fail (!application->priv->is_remote);
-
- enabled = !!enabled;
-
- action = g_hash_table_lookup (application->priv->actions, name);
- g_return_if_fail (action != NULL);
- if (action->enabled == enabled)
- return;
- action->enabled = enabled;
+ if (application->priv->inactivity_timeout != inactivity_timeout)
+ {
+ application->priv->inactivity_timeout = inactivity_timeout;
- queue_actions_change_notification (application);
+ g_object_notify (G_OBJECT (application), "inactivity-timeout");
+ }
}
-
-
+/* Read-only property getters (is registered, is remote) {{{1 */
/**
- * g_application_get_action_description:
+ * g_application_get_is_registered:
* @application: a #GApplication
- * @name: Action name
*
- * Gets the description of the action @name.
+ * Checks if @application is registered.
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * An application is registered if g_application_register() has been
+ * successfully called.
*
- * Returns: Description for the given action named @name
+ * Returns: %TRUE if @application is registered
*
- * Since: 2.26
- */
-G_CONST_RETURN gchar *
-g_application_get_action_description (GApplication *application,
- const gchar *name)
+ * Since: 2.28
+ **/
+gboolean
+g_application_get_is_registered (GApplication *application)
{
- GApplicationAction *action;
-
- g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
- g_return_val_if_fail (name != NULL, NULL);
- g_return_val_if_fail (!application->priv->is_remote, NULL);
-
- action = g_hash_table_lookup (application->priv->actions, name);
- g_return_val_if_fail (action != NULL, NULL);
+ g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
- return action->description;
+ return application->priv->is_registered;
}
-
/**
- * g_application_get_action_enabled:
+ * g_application_get_is_remote:
* @application: a #GApplication
- * @name: the name of the action
*
- * Retrieves whether the action @name is enabled or not.
+ * Checks if @application is remote.
*
- * See g_application_set_action_enabled().
+ * If @application is remote then it means that another instance of
+ * application already exists (the 'primary' instance). Calls to
+ * perform actions on @application will result in the actions being
+ * performed by the primary instance.
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * The value of this property cannot be accessed before
+ * g_application_register() has been called. See
+ * g_application_get_is_registered().
*
- * Return value: %TRUE if the action was enabled, and %FALSE otherwise
+ * Returns: %TRUE if @application is remote
*
- * Since: 2.26
- */
+ * Since: 2.28
+ **/
gboolean
-g_application_get_action_enabled (GApplication *application,
- const gchar *name)
+g_application_get_is_remote (GApplication *application)
{
- GApplicationAction *action;
-
g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
- g_return_val_if_fail (name != NULL, FALSE);
- g_return_val_if_fail (!application->priv->is_remote, FALSE);
-
- action = g_hash_table_lookup (application->priv->actions, name);
- g_return_val_if_fail (action != NULL, FALSE);
+ g_return_val_if_fail (application->priv->is_registered, FALSE);
- return action->enabled;
+ return application->priv->is_remote;
}
+/* Register {{{1 */
/**
- * g_application_run:
+ * g_application_register:
* @application: a #GApplication
+ * @cancellable: a #GCancellable, or %NULL
+ * @error: a pointer to a NULL #GError, or %NULL
*
- * Starts the application.
+ * Attempts registration of the application.
*
- * The default implementation of this virtual function will simply run
- * a main loop.
+ * This is the point at which the application discovers if it is the
+ * primary instance or merely acting as a remote for an already-existing
+ * primary instance. This is implemented by attempting to acquire the
+ * application identifier as a unique bus name on the session bus using
+ * GDBus.
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * Due to the internal architecture of GDBus, method calls can be
+ * dispatched at any time (even if a main loop is not running). For
+ * this reason, you must ensure that any object paths that you wish to
+ * register are registered before calling this function.
*
- * Since: 2.26
- */
-void
-g_application_run (GApplication *application)
-{
- g_return_if_fail (G_IS_APPLICATION (application));
- g_return_if_fail (!application->priv->is_remote);
-
- G_APPLICATION_GET_CLASS (application)->run (application);
-}
-
-/**
- * g_application_quit:
- * @application: a #GApplication
- * @timestamp: Platform-specific event timestamp, may be 0 for default
+ * If the application has already been registered then %TRUE is
+ * returned with no work performed.
*
- * Request that the application quits.
+ * The #GApplication::startup signal is emitted if registration succeeds
+ * and @application is the primary instance.
*
- * This function has different behavior depending on whether @application
- * is acting as a proxy for another process. In the normal case where
- * the current process is hosting the application, the default
- * implementation will quit the main loop created by g_application_run().
+ * In the event of an error (such as @cancellable being cancelled, or a
+ * failure to connect to the session bus), %FALSE is returned and @error
+ * is set appropriately.
*
- * If @application is a proxy, then the remote process will be asked
- * to quit.
+ * Note: the return value of this function is not an indicator that this
+ * instance is or is not the primary instance of the application. See
+ * g_application_get_is_remote() for that.
*
- * Returns: %TRUE if the application accepted the request, %FALSE otherwise
+ * Returns: %TRUE if registration succeeded
*
- * Since: 2.26
- */
+ * Since: 2.28
+ **/
gboolean
-g_application_quit (GApplication *application,
- guint timestamp)
+g_application_register (GApplication *application,
+ GCancellable *cancellable,
+ GError **error)
{
- gboolean retval = FALSE;
-
g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
- if (application->priv->is_remote)
+ if (!application->priv->is_registered)
{
- _g_application_platform_remote_quit (application, timestamp);
- retval = TRUE;
+ if (~application->priv->flags & G_APPLICATION_NON_UNIQUE)
+ {
+ application->priv->impl =
+ g_application_impl_register (application, application->priv->id,
+ application->priv->flags,
+ &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;
+
+ g_object_notify (G_OBJECT (application), "is-registered");
+
+ if (!application->priv->is_remote)
+ {
+ g_signal_emit (application, g_application_signals[SIGNAL_STARTUP], 0);
+
+ if (!application->priv->did_startup)
+ g_critical ("GApplication subclass '%s' failed to chain up on"
+ " ::startup (from start of override function)",
+ G_OBJECT_TYPE_NAME (application));
+ }
}
- else
- g_signal_emit (application, application_signals[QUIT], 0, timestamp, &retval);
- return retval;
+ return TRUE;
}
+/* Hold/release {{{1 */
/**
- * g_application_get_instance:
+ * g_application_hold:
+ * @application: a #GApplication
*
- * In the normal case where there is exactly one #GApplication instance
- * in this process, return that instance. If there are multiple, the
- * first one created will be returned. Otherwise, return %NULL.
+ * Increases the use count of @application.
*
- * Returns: (transfer none): The primary instance of #GApplication,
- * or %NULL if none is set
+ * Use this function to indicate that the application has a reason to
+ * continue to run. For example, g_application_hold() is called by GTK+
+ * when a toplevel window is on the screen.
*
- * Since: 2.26
- */
-GApplication *
-g_application_get_instance (void)
+ * To cancel the hold, call g_application_release().
+ **/
+void
+g_application_hold (GApplication *application)
{
- return primary_application;
+ if (application->priv->inactivity_timeout_id)
+ {
+ g_source_remove (application->priv->inactivity_timeout_id);
+ application->priv->inactivity_timeout_id = 0;
+ }
+
+ application->priv->use_count++;
+}
+
+static gboolean
+inactivity_timeout_expired (gpointer data)
+{
+ GApplication *application = G_APPLICATION (data);
+
+ application->priv->inactivity_timeout_id = 0;
+
+ return FALSE;
}
+
/**
- * g_application_get_id:
+ * g_application_release:
+ * @application: a #GApplication
*
- * Retrieves the platform-specific identifier for the #GApplication.
+ * Decrease the use count of @application.
*
- * Return value: The platform-specific identifier. The returned string
- * is owned by the #GApplication instance and it should never be
- * modified or freed
+ * When the use count reaches zero, the application will stop running.
*
- * Since: 2.26
- */
-G_CONST_RETURN char *
-g_application_get_id (GApplication *application)
+ * Never call this function except to cancel the effect of a previous
+ * call to g_application_hold().
+ **/
+void
+g_application_release (GApplication *application)
{
- g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
+ application->priv->use_count--;
- return application->priv->appid;
+ if (application->priv->use_count == 0 && application->priv->inactivity_timeout)
+ application->priv->inactivity_timeout_id = g_timeout_add (application->priv->inactivity_timeout,
+ inactivity_timeout_expired, application);
}
+/* Activate, Open {{{1 */
/**
- * g_application_is_remote:
+ * g_application_activate:
* @application: a #GApplication
*
- * Returns: %TRUE if this object represents a proxy for a remote application.
- */
-gboolean
-g_application_is_remote (GApplication *application)
+ * Activates the application.
+ *
+ * In essence, this results in the #GApplication::activate() signal being
+ * emitted in the primary instance.
+ *
+ * The application must be registered before calling this function.
+ *
+ * Since: 2.28
+ **/
+void
+g_application_activate (GApplication *application)
{
- g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
+ g_return_if_fail (G_IS_APPLICATION (application));
+ g_return_if_fail (application->priv->is_registered);
- return application->priv->is_remote;
+ if (application->priv->is_remote)
+ g_application_impl_activate (application->priv->impl,
+ get_platform_data (application));
+
+ else
+ g_signal_emit (application, g_application_signals[SIGNAL_ACTIVATE], 0);
}
-static void
-g_application_init (GApplication *app)
+/**
+ * g_application_open:
+ * @application: a #GApplication
+ * @files: (array length=n_files): an array of #GFiles to open
+ * @n_files: the length of the @files array
+ * @hint: a hint (or ""), but never %NULL
+ *
+ * Opens the given files.
+ *
+ * In essence, this results in the #GApplication::open signal being emitted
+ * in the primary instance.
+ *
+ * @n_files must be greater than zero.
+ *
+ * @hint is simply passed through to the ::open signal. It is
+ * intended to be used by applications that have multiple modes for
+ * opening files (eg: "view" vs "edit", etc). Unless you have a need
+ * for this functionality, you should use "".
+ *
+ * The application must be registered before calling this function
+ * and it must have the %G_APPLICATION_HANDLES_OPEN flag set.
+ *
+ * Since: 2.28
+ **/
+void
+g_application_open (GApplication *application,
+ GFile **files,
+ gint n_files,
+ const gchar *hint)
{
- app->priv = G_TYPE_INSTANCE_GET_PRIVATE (app,
- G_TYPE_APPLICATION,
- GApplicationPrivate);
-
- app->priv->actions = g_hash_table_new_full (g_str_hash, g_str_equal,
- NULL,
- g_application_action_free);
- app->priv->default_quit = TRUE;
- app->priv->is_remote = TRUE;
+ g_return_if_fail (G_IS_APPLICATION (application));
+ g_return_if_fail (application->priv->flags &
+ G_APPLICATION_HANDLES_OPEN);
+ g_return_if_fail (application->priv->is_registered);
+
+ if (application->priv->is_remote)
+ g_application_impl_open (application->priv->impl,
+ files, n_files, hint,
+ get_platform_data (application));
+
+ else
+ g_signal_emit (application, g_application_signals[SIGNAL_OPEN],
+ 0, files, n_files, hint);
}
-static void
-g_application_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+/* Run {{{1 */
+/**
+ * g_application_run:
+ * @application: a #GApplication
+ * @argc: the argc from main() (or 0 if @argv is %NULL)
+ * @argv: (array length=argc) (allow-none): the argv from main(), or %NULL
+ *
+ * Runs the application.
+ *
+ * This function is intended to be run from main() and its return value
+ * is intended to be returned by main(). Although you are expected to pass
+ * the @argc, @argv parameters from main() to this function, it is possible
+ * to pass %NULL if @argv is not available or commandline handling is not
+ * required.
+ *
+ * First, the local_command_line() virtual function is invoked.
+ * This function always runs on the local instance. It gets passed a pointer
+ * to a %NULL-terminated copy of @argv and is expected to remove the arguments
+ * that it handled (shifting up remaining arguments). See
+ * <xref linkend="gapplication-example-cmdline2"/> for an example of
+ * parsing @argv manually. Alternatively, you may use the #GOptionContext API,
+ * after setting <literal>argc = g_strv_length (argv);</literal>.
+ *
+ * The last argument to local_command_line() is a pointer to the @status
+ * variable which can used to set the exit status that is returned from
+ * g_application_run().
+ *
+ * If local_command_line() returns %TRUE, the command line is expected
+ * to be completely handled, including possibly registering as the primary
+ * instance, calling g_application_activate() or g_application_open(), etc.
+ *
+ * If local_command_line() returns %FALSE then the application is registered
+ * and the #GApplication::command-line signal is emitted in the primary
+ * instance (which may or may not be this instance). The signal handler
+ * gets passed a #GApplicationCommandline object that (among other things)
+ * contains the remaining commandline arguments that have not been handled
+ * by local_command_line().
+ *
+ * If the application has the %G_APPLICATION_HANDLES_COMMAND_LINE
+ * flag set then the default implementation of local_command_line()
+ * always returns %FALSE immediately, resulting in the commandline
+ * always being handled in the primary instance.
+ *
+ * Otherwise, the default implementation of local_command_line() tries
+ * to do a couple of things that are probably reasonable for most
+ * applications. First, g_application_register() is called to attempt
+ * to register the application. If that works, then the command line
+ * arguments are inspected. If no commandline arguments are given, then
+ * g_application_activate() is called. If commandline arguments are
+ * given and the %G_APPLICATION_HANDLES_OPEN flag is set then they
+ * are assumed to be filenames and g_application_open() is called.
+ *
+ * If you need to handle commandline arguments that are not filenames,
+ * and you don't mind commandline handling to happen in the primary
+ * instance, you should set %G_APPLICATION_HANDLED_COMMAND_LINE and
+ * process the commandline arguments in your #GApplication::command-line
+ * signal handler, either manually or using the #GOptionContext API.
+ *
+ * If you are interested in doing more complicated local handling of the
+ * commandline then you should implement your own #GApplication subclass
+ * and override local_command_line(). In this case, you most likely want
+ * to return %TRUE from your local_command_line() implementation to
+ * suppress the default handling. See
+ * <xref linkend="gapplication-example-cmdline2"/> for an example.
+ *
+ * If, after the above is done, the use count of the application is zero
+ * then the exit status is returned immediately. If the use count is
+ * non-zero then the default main context is iterated until the use count
+ * falls to zero, at which point 0 is returned.
+ *
+ * If the %G_APPLICATION_IS_SERVICE flag is set, then the exiting at
+ * use count of zero is delayed for a while (ie: the instance stays
+ * around to provide its <emphasis>service</emphasis> to others).
+ *
+ * Returns: the exit status
+ *
+ * Since: 2.28
+ **/
+int
+g_application_run (GApplication *application,
+ int argc,
+ char **argv)
{
- GApplication *app = G_APPLICATION (object);
+ gchar **arguments;
+ int status;
+ gint i;
- switch (prop_id)
- {
- case PROP_APPID:
- g_value_set_string (value, g_application_get_id (app));
- break;
+ g_return_val_if_fail (G_IS_APPLICATION (application), 1);
+ g_return_val_if_fail (argc == 0 || argv != NULL, 1);
- case PROP_DEFAULT_QUIT:
- g_value_set_boolean (value, app->priv->default_quit);
- break;
+ arguments = g_new (gchar *, argc + 1);
+ for (i = 0; i < argc; i++)
+ arguments[i] = g_strdup (argv[i]);
+ arguments[i] = NULL;
- case PROP_IS_REMOTE:
- g_value_set_boolean (value, g_application_is_remote (app));
- break;
+ if (g_get_prgname () == NULL && argc > 0)
+ {
+ gchar *prgname;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ prgname = g_path_get_basename (argv[0]);
+ g_set_prgname (prgname);
+ g_free (prgname);
}
-}
-static void
-g_application_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GApplication *app = G_APPLICATION (object);
+ if (!G_APPLICATION_GET_CLASS (application)
+ ->local_command_line (application, &arguments, &status))
+ {
+ GError *error = NULL;
+
+ if (!g_application_register (application, NULL, &error))
+ {
+ g_printerr ("%s", error->message);
+ g_error_free (error);
+ return 1;
+ }
+
+ if (application->priv->is_remote)
+ {
+ GVariant *platform_data;
+
+ platform_data = get_platform_data (application);
+ status = g_application_impl_command_line (application->priv->impl,
+ arguments, platform_data);
+ }
+ else
+ {
+ GApplicationCommandLine *cmdline;
+ GVariant *v;
+
+ v = g_variant_new_bytestring_array ((const gchar **) arguments, -1);
+ cmdline = g_object_new (G_TYPE_APPLICATION_COMMAND_LINE,
+ "arguments", v, NULL);
+ g_signal_emit (application,
+ g_application_signals[SIGNAL_COMMAND_LINE],
+ 0, cmdline, &status);
+ g_object_unref (cmdline);
+ }
+ }
- switch (prop_id)
+ g_strfreev (arguments);
+
+ if (application->priv->flags & G_APPLICATION_IS_SERVICE &&
+ application->priv->is_registered &&
+ !application->priv->use_count &&
+ !application->priv->inactivity_timeout_id)
{
- case PROP_APPID:
- g_return_if_fail (_g_application_validate_id (g_value_get_string (value)));
- app->priv->appid = g_value_dup_string (value);
- break;
+ application->priv->inactivity_timeout_id =
+ g_timeout_add (10000, inactivity_timeout_expired, application);
+ }
- case PROP_DEFAULT_QUIT:
- app->priv->default_quit = g_value_get_boolean (value);
- break;
+ while (application->priv->use_count || application->priv->inactivity_timeout_id)
+ {
+ g_main_context_iteration (NULL, TRUE);
+ status = 0;
+ }
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ if (!application->priv->is_remote)
+ {
+ g_signal_emit (application, g_application_signals[SIGNAL_SHUTDOWN], 0);
+
+ if (!application->priv->did_shutdown)
+ g_critical ("GApplication subclass '%s' failed to chain up on"
+ " ::shutdown (from end of override function)",
+ G_OBJECT_TYPE_NAME (application));
}
+
+ if (application->priv->impl)
+ g_application_impl_flush (application->priv->impl);
+
+ g_settings_sync ();
+
+ return status;
}
-static GObject*
-g_application_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_params)
+static gchar **
+g_application_list_actions (GActionGroup *action_group)
{
- GApplication *app;
- GObject *object;
- const char *appid = NULL;
- guint i;
+ GApplication *application = G_APPLICATION (action_group);
- for (i = 0; i < n_construct_properties; i++)
- {
- GObjectConstructParam *param = &construct_params[i];
- if (strcmp (param->pspec->name, "appid") == 0)
- appid = g_value_get_string (param->value);
- }
+ g_return_val_if_fail (application->priv->is_registered, NULL);
- g_return_val_if_fail (appid != NULL, NULL);
+ if (application->priv->remote_actions != NULL)
+ return g_action_group_list_actions (application->priv->remote_actions);
- app = application_for_appid (appid);
- if (app != NULL)
- return g_object_ref (app);
+ else if (application->priv->actions != NULL)
+ return g_action_group_list_actions (application->priv->actions);
- object = (* G_OBJECT_CLASS (g_application_parent_class)->constructor) (type,
- n_construct_properties,
- construct_params);
- app = G_APPLICATION (object);
+ else
+ /* empty string array */
+ return g_new0 (gchar *, 1);
+}
- if (primary_application == NULL)
- primary_application = app;
- g_hash_table_insert (instances_for_appid, g_strdup (appid), app);
+static gboolean
+g_application_query_action (GActionGroup *group,
+ const gchar *action_name,
+ gboolean *enabled,
+ const GVariantType **parameter_type,
+ const GVariantType **state_type,
+ GVariant **state_hint,
+ GVariant **state)
+{
+ GApplication *application = G_APPLICATION (group);
+
+ g_return_val_if_fail (application->priv->is_registered, FALSE);
+
+ if (application->priv->remote_actions != NULL)
+ return g_action_group_query_action (application->priv->remote_actions,
+ action_name,
+ enabled,
+ parameter_type,
+ state_type,
+ state_hint,
+ state);
+
+ if (application->priv->actions != NULL)
+ return g_action_group_query_action (application->priv->actions,
+ action_name,
+ enabled,
+ parameter_type,
+ state_type,
+ state_hint,
+ state);
- return object;
+ return FALSE;
}
static void
-g_application_finalize (GObject *object)
+g_application_change_action_state (GActionGroup *action_group,
+ const gchar *action_name,
+ GVariant *value)
{
- GApplication *app = G_APPLICATION (object);
-
- g_free (app->priv->appid);
- if (app->priv->actions)
- g_hash_table_unref (app->priv->actions);
- if (app->priv->actions_changed_id)
- g_source_remove (app->priv->actions_changed_id);
- if (app->priv->mainloop)
- g_main_loop_unref (app->priv->mainloop);
-
-#ifdef G_OS_UNIX
- g_free (app->priv->dbus_path);
- if (app->priv->session_bus)
- g_object_unref (app->priv->session_bus);
-#endif
-
- G_OBJECT_CLASS (g_application_parent_class)->finalize (object);
+ GApplication *application = G_APPLICATION (action_group);
+
+ g_return_if_fail (application->priv->is_remote ||
+ application->priv->actions != NULL);
+ g_return_if_fail (application->priv->is_registered);
+
+ if (application->priv->remote_actions)
+ return g_action_group_change_action_state (application->priv->remote_actions, action_name, value);
+
+ else
+ g_action_group_change_action_state (application->priv->actions,
+ action_name, value);
}
static void
-g_application_class_init (GApplicationClass *klass)
+g_application_activate_action (GActionGroup *action_group,
+ const gchar *action_name,
+ GVariant *parameter)
{
- GObjectClass *gobject_class G_GNUC_UNUSED = G_OBJECT_CLASS (klass);
-
- g_type_class_add_private (klass, sizeof (GApplicationPrivate));
-
- gobject_class->constructor = g_application_constructor;
- gobject_class->set_property = g_application_set_property;
- gobject_class->get_property = g_application_get_property;
-
- gobject_class->finalize = g_application_finalize;
-
- klass->run = g_application_default_run;
- klass->quit = g_application_default_quit;
-
- application_signals[QUIT] =
- g_signal_new (g_intern_static_string ("quit"),
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GApplicationClass, quit),
- g_signal_accumulator_true_handled, NULL,
- _gio_marshal_BOOLEAN__UINT,
- G_TYPE_BOOLEAN, 1,
- G_TYPE_UINT);
-
- application_signals[ACTION] =
- g_signal_new (g_intern_static_string ("action"),
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED,
- G_STRUCT_OFFSET (GApplicationClass, action),
- NULL, NULL,
- _gio_marshal_VOID__STRING_INT,
- G_TYPE_NONE, 2,
- G_TYPE_STRING,
- G_TYPE_INT);
-
- /**
- * GApplication::prepare-activation:
- * @arguments: A #GVariant with the signature "aay"
- * @platform_data: A #GVariant with the signature "a{sv}"
- *
- * This signal is emitted when a non-primary process for a given
- * application is invoked while your application is running; for
- * example, when a file browser launches your program to open a
- * file. The raw operating system arguments are passed in the
- * @arguments variant. Additional platform-dependent data is
- * stored in @platform_data.
- */
+ GApplication *application = G_APPLICATION (action_group);
- application_signals[PREPARE_ACTIVATION] =
- g_signal_new (g_intern_static_string ("prepare-activation"),
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GApplicationClass, prepare_activation),
- NULL, NULL,
- _gio_marshal_VOID__BOXED_BOXED,
- G_TYPE_NONE, 2,
- G_TYPE_VARIANT,
- G_TYPE_VARIANT);
-
- /**
- * GApplication:appid:
- *
- * The unique identifier for this application. See the documentation for
- * #GApplication for more information about this property.
- *
- */
- g_object_class_install_property (gobject_class,
- PROP_APPID,
- g_param_spec_string ("appid",
- P_("Application ID"),
- P_("Identifier for this application"),
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
+ g_return_if_fail (application->priv->is_remote ||
+ application->priv->actions != NULL);
+ g_return_if_fail (application->priv->is_registered);
- /**
- * GApplication:default-quit:
- *
- * By default, if a different process is running this application, the
- * process will be exited. Set this property to %FALSE to allow custom
- * interaction with the remote process.
- *
- */
- g_object_class_install_property (gobject_class,
- PROP_DEFAULT_QUIT,
- g_param_spec_boolean ("default-quit",
- P_("Default Quit"),
- P_("Exit the process by default"),
- TRUE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
+ if (application->priv->remote_actions)
+ return g_action_group_change_action_state (application->priv->remote_actions, action_name, parameter);
+ else
+ g_action_group_activate_action (application->priv->actions,
+ action_name, parameter);
+}
- /**
- * GApplication:is-remote:
- *
- * This property is %TRUE if this application instance represents a proxy
- * to the instance of this application in another process.
- *
- */
- g_object_class_install_property (gobject_class,
- PROP_IS_REMOTE,
- g_param_spec_boolean ("is-remote",
- P_("Is Remote"),
- P_("Whether this application is a proxy for another process"),
- TRUE,
- G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+static void
+g_application_action_group_iface_init (GActionGroupInterface *iface)
+{
+ iface->list_actions = g_application_list_actions;
+ iface->query_action = g_application_query_action;
+ iface->change_action_state = g_application_change_action_state;
+ 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;
}
-#define __G_APPLICATION_C__
-#include "gioaliasdef.c"
+/* Epilogue {{{1 */
+/* vim:set foldmethod=marker: */