2 * Copyright © 2010 Codethink Limited
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; either version 2 of the licence or (at
7 * your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
19 * Authors: Ryan Lortie <desrt@desrt.ca>
25 #include "gapplication.h"
27 #include "gapplicationcommandline.h"
28 #include "gsimpleactiongroup.h"
29 #include "gremoteactiongroup.h"
30 #include "gapplicationimpl.h"
31 #include "gactiongroup.h"
32 #include "gactionmap.h"
33 #include "gmenumodel.h"
34 #include "gsettings.h"
36 #include "gioenumtypes.h"
45 * SECTION:gapplication
46 * @title: GApplication
47 * @short_description: Core application class
49 * A #GApplication is the foundation of an application. It wraps some
50 * low-level platform-specific services and is intended to act as the
51 * foundation for higher-level application classes such as
52 * #GtkApplication or #MxApplication. In general, you should not use
53 * this class outside of a higher level framework.
55 * GApplication provides convenient life cycle management by maintaining
56 * a <firstterm>use count</firstterm> for the primary application instance.
57 * The use count can be changed using g_application_hold() and
58 * g_application_release(). If it drops to zero, the application exits.
59 * Higher-level classes such as #GtkApplication employ the use count to
60 * ensure that the application stays alive as long as it has any opened
63 * Another feature that GApplication (optionally) provides is process
64 * uniqueness. Applications can make use of this functionality by
65 * providing a unique application ID. If given, only one application
66 * with this ID can be running at a time per session. The session
67 * concept is platform-dependent, but corresponds roughly to a graphical
68 * desktop login. When your application is launched again, its
69 * arguments are passed through platform communication to the already
70 * running program. The already running instance of the program is
71 * called the <firstterm>primary instance</firstterm>; for non-unique
72 * applications this is the always the current instance.
73 * On Linux, the D-Bus session bus is used for communication.
75 * The use of #GApplication differs from some other commonly-used
76 * uniqueness libraries (such as libunique) in important ways. The
77 * application is not expected to manually register itself and check if
78 * it is the primary instance. Instead, the <code>main()</code>
79 * function of a #GApplication should do very little more than
80 * instantiating the application instance, possibly connecting signal
81 * handlers, then calling g_application_run(). All checks for
82 * uniqueness are done internally. If the application is the primary
83 * instance then the startup signal is emitted and the mainloop runs.
84 * If the application is not the primary instance then a signal is sent
85 * to the primary instance and g_application_run() promptly returns.
86 * See the code examples below.
88 * If used, the expected form of an application identifier is very close
90 * <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface">DBus bus name</ulink>.
91 * Examples include: "com.example.MyApp", "org.example.internal-apps.Calculator".
92 * For details on valid application identifiers, see g_application_id_is_valid().
94 * On Linux, the application identifier is claimed as a well-known bus name
95 * on the user's session bus. This means that the uniqueness of your
96 * application is scoped to the current session. It also means that your
97 * application may provide additional services (through registration of other
98 * object paths) at that bus name. The registration of these object paths
99 * should be done with the shared GDBus session bus. Note that due to the
100 * internal architecture of GDBus, method calls can be dispatched at any time
101 * (even if a main loop is not running). For this reason, you must ensure that
102 * any object paths that you wish to register are registered before #GApplication
103 * attempts to acquire the bus name of your application (which happens in
104 * g_application_register()). Unfortunately, this means that you cannot use
105 * g_application_get_is_remote() to decide if you want to register object paths.
107 * GApplication also implements the #GActionGroup and #GActionMap
108 * interfaces and lets you easily export actions by adding them with
109 * g_action_map_add_action(). When invoking an action by calling
110 * g_action_group_activate_action() on the application, it is always
111 * invoked in the primary instance. The actions are also exported on
112 * the session bus, and GIO provides the #GDBusActionGroup wrapper to
113 * conveniently access them remotely. GIO provides a #GDBusMenuModel wrapper
114 * for remote access to exported #GMenuModels.
116 * There is a number of different entry points into a GApplication:
118 * <listitem>via 'Activate' (i.e. just starting the application)</listitem>
119 * <listitem>via 'Open' (i.e. opening some files)</listitem>
120 * <listitem>by handling a command-line</listitem>
121 * <listitem>via activating an action</listitem>
123 * The #GApplication::startup signal lets you handle the application
124 * initialization for all of these in a single place.
126 * Regardless of which of these entry points is used to start the application,
127 * GApplication passes some <firstterm id="platform-data">platform
128 * data</firstterm> from the launching instance to the primary instance,
129 * in the form of a #GVariant dictionary mapping strings to variants.
130 * To use platform data, override the @before_emit or @after_emit virtual
131 * functions in your #GApplication subclass. When dealing with
132 * #GApplicationCommandLine objects, the platform data is directly
133 * available via g_application_command_line_get_cwd(),
134 * g_application_command_line_get_environ() and
135 * g_application_command_line_get_platform_data().
137 * As the name indicates, the platform data may vary depending on the
138 * operating system, but it always includes the current directory (key
139 * "cwd"), and optionally the environment (ie the set of environment
140 * variables and their values) of the calling process (key "environ").
141 * The environment is only added to the platform data if the
142 * %G_APPLICATION_SEND_ENVIRONMENT flag is set. #GApplication subclasses
143 * can add their own platform data by overriding the @add_platform_data
144 * virtual function. For instance, #GtkApplication adds startup notification
147 * To parse commandline arguments you may handle the
148 * #GApplication::command-line signal or override the local_command_line()
149 * vfunc, to parse them in either the primary instance or the local instance,
152 * <example id="gapplication-example-open"><title>Opening files with a GApplication</title>
154 * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-open.c">
155 * <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
160 * <example id="gapplication-example-actions"><title>A GApplication with actions</title>
162 * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-actions.c">
163 * <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
168 * <example id="gapplication-example-menu"><title>A GApplication with menus</title>
170 * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-menu.c">
171 * <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
176 * <example id="gapplication-example-dbushooks"><title>Using extra D-Bus hooks with a GApplication</title>
178 * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-dbushooks.c">
179 * <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
187 * @startup: invoked on the primary instance immediately after registration
188 * @shutdown: invoked only on the registered primary instance immediately
189 * after the main loop terminates
190 * @activate: invoked on the primary instance when an activation occurs
191 * @open: invoked on the primary instance when there are files to open
192 * @command_line: invoked on the primary instance when a command-line is
193 * not handled locally
194 * @local_command_line: invoked (locally) when the process has been invoked
195 * via commandline execution (as opposed to, say, D-Bus activation - which
196 * is not currently supported by GApplication). The virtual function has
197 * the chance to inspect (and possibly replace) the list of command line
198 * arguments. See g_application_run() for more information.
199 * @before_emit: invoked on the primary instance before 'activate', 'open',
200 * 'command-line' or any action invocation, gets the 'platform data' from
201 * the calling instance
202 * @after_emit: invoked on the primary instance after 'activate', 'open',
203 * 'command-line' or any action invocation, gets the 'platform data' from
204 * the calling instance
205 * @add_platform_data: invoked (locally) to add 'platform data' to be sent to
206 * the primary instance when activating, opening or invoking actions
207 * @quit_mainloop: Used to be invoked on the primary instance when the use
208 * count of the application drops to zero (and after any inactivity
209 * timeout, if requested). Not used anymore since 2.32
210 * @run_mainloop: Used to be invoked on the primary instance from
211 * g_application_run() if the use-count is non-zero. Since 2.32,
212 * GApplication is iterating the main context directly and is not
213 * using @run_mainloop anymore
214 * @dbus_register: invoked locally during registration, if the application is
215 * using its D-Bus backend. You can use this to export extra objects on the
216 * bus, that need to exist before the application tries to own the bus name.
217 * The function is passed the #GDBusConnection to to session bus, and the
218 * object path that #GApplication will use to export is D-Bus API.
219 * If this function returns %TRUE, registration will proceed; otherwise
220 * registration will abort. Since: 2.34
221 * @dbus_unregister: invoked locally during unregistration, if the application
222 * is using its D-Bus backend. Use this to undo anything done by the
223 * @dbus_register vfunc. Since: 2.34
225 * Virtual function table for #GApplication.
230 struct _GApplicationPrivate
232 GApplicationFlags flags;
235 GActionGroup *actions;
236 GMenuModel *app_menu;
239 guint inactivity_timeout_id;
240 guint inactivity_timeout;
244 guint is_registered : 1;
246 guint did_startup : 1;
247 guint did_shutdown : 1;
248 guint must_quit_now : 1;
250 GRemoteActionGroup *remote_actions;
251 GApplicationImpl *impl;
261 PROP_INACTIVITY_TIMEOUT,
276 static guint g_application_signals[NR_SIGNALS];
278 static void g_application_action_group_iface_init (GActionGroupInterface *);
279 static void g_application_action_map_iface_init (GActionMapInterface *);
280 G_DEFINE_TYPE_WITH_CODE (GApplication, g_application, G_TYPE_OBJECT,
281 G_ADD_PRIVATE (GApplication)
282 G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, g_application_action_group_iface_init)
283 G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_MAP, g_application_action_map_iface_init))
285 /* GApplicationExportedActions {{{1 */
287 /* We create a subclass of GSimpleActionGroup that implements
288 * GRemoteActionGroup and deals with the platform data using
289 * GApplication's before/after_emit vfuncs. This is the action group we
292 * We could implement GRemoteActionGroup on GApplication directly, but
293 * this would be potentially extremely confusing to have exposed as part
294 * of the public API of GApplication. We certainly don't want anyone in
295 * the same process to be calling these APIs...
297 typedef GSimpleActionGroupClass GApplicationExportedActionsClass;
300 GSimpleActionGroup parent_instance;
301 GApplication *application;
302 } GApplicationExportedActions;
304 static GType g_application_exported_actions_get_type (void);
305 static void g_application_exported_actions_iface_init (GRemoteActionGroupInterface *iface);
306 G_DEFINE_TYPE_WITH_CODE (GApplicationExportedActions, g_application_exported_actions, G_TYPE_SIMPLE_ACTION_GROUP,
307 G_IMPLEMENT_INTERFACE (G_TYPE_REMOTE_ACTION_GROUP, g_application_exported_actions_iface_init))
310 g_application_exported_actions_activate_action_full (GRemoteActionGroup *remote,
311 const gchar *action_name,
313 GVariant *platform_data)
315 GApplicationExportedActions *exported = (GApplicationExportedActions *) remote;
317 G_APPLICATION_GET_CLASS (exported->application)
318 ->before_emit (exported->application, platform_data);
320 g_action_group_activate_action (G_ACTION_GROUP (exported), action_name, parameter);
322 G_APPLICATION_GET_CLASS (exported->application)
323 ->after_emit (exported->application, platform_data);
327 g_application_exported_actions_change_action_state_full (GRemoteActionGroup *remote,
328 const gchar *action_name,
330 GVariant *platform_data)
332 GApplicationExportedActions *exported = (GApplicationExportedActions *) remote;
334 G_APPLICATION_GET_CLASS (exported->application)
335 ->before_emit (exported->application, platform_data);
337 g_action_group_change_action_state (G_ACTION_GROUP (exported), action_name, value);
339 G_APPLICATION_GET_CLASS (exported->application)
340 ->after_emit (exported->application, platform_data);
344 g_application_exported_actions_init (GApplicationExportedActions *actions)
349 g_application_exported_actions_iface_init (GRemoteActionGroupInterface *iface)
351 iface->activate_action_full = g_application_exported_actions_activate_action_full;
352 iface->change_action_state_full = g_application_exported_actions_change_action_state_full;
356 g_application_exported_actions_class_init (GApplicationExportedActionsClass *class)
360 static GActionGroup *
361 g_application_exported_actions_new (GApplication *application)
363 GApplicationExportedActions *actions;
365 actions = g_object_new (g_application_exported_actions_get_type (), NULL);
366 actions->application = application;
368 return G_ACTION_GROUP (actions);
371 /* vfunc defaults {{{1 */
373 g_application_real_before_emit (GApplication *application,
374 GVariant *platform_data)
379 g_application_real_after_emit (GApplication *application,
380 GVariant *platform_data)
385 g_application_real_startup (GApplication *application)
387 application->priv->did_startup = TRUE;
391 g_application_real_shutdown (GApplication *application)
393 application->priv->did_shutdown = TRUE;
397 g_application_real_activate (GApplication *application)
399 if (!g_signal_has_handler_pending (application,
400 g_application_signals[SIGNAL_ACTIVATE],
402 G_APPLICATION_GET_CLASS (application)->activate == g_application_real_activate)
404 static gboolean warned;
409 g_warning ("Your application does not implement "
410 "g_application_activate() and has no handlers connected "
411 "to the 'activate' signal. It should do one of these.");
417 g_application_real_open (GApplication *application,
422 if (!g_signal_has_handler_pending (application,
423 g_application_signals[SIGNAL_OPEN],
425 G_APPLICATION_GET_CLASS (application)->open == g_application_real_open)
427 static gboolean warned;
432 g_warning ("Your application claims to support opening files "
433 "but does not implement g_application_open() and has no "
434 "handlers connected to the 'open' signal.");
440 g_application_real_command_line (GApplication *application,
441 GApplicationCommandLine *cmdline)
443 if (!g_signal_has_handler_pending (application,
444 g_application_signals[SIGNAL_COMMAND_LINE],
446 G_APPLICATION_GET_CLASS (application)->command_line == g_application_real_command_line)
448 static gboolean warned;
453 g_warning ("Your application claims to support custom command line "
454 "handling but does not implement g_application_command_line() "
455 "and has no handlers connected to the 'command-line' signal.");
464 g_application_real_local_command_line (GApplication *application,
468 if (application->priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE)
473 GError *error = NULL;
476 if (!g_application_register (application, NULL, &error))
478 g_critical ("%s", error->message);
479 g_error_free (error);
484 n_args = g_strv_length (*arguments);
486 if (application->priv->flags & G_APPLICATION_IS_SERVICE)
488 if ((*exit_status = n_args > 1))
490 g_printerr ("GApplication service mode takes no arguments.\n");
491 application->priv->flags &= ~G_APPLICATION_IS_SERVICE;
499 g_application_activate (application);
505 if (~application->priv->flags & G_APPLICATION_HANDLES_OPEN)
507 g_critical ("This application can not open files.");
516 n_files = n_args - 1;
517 files = g_new (GFile *, n_files);
519 for (i = 0; i < n_files; i++)
520 files[i] = g_file_new_for_commandline_arg ((*arguments)[i + 1]);
522 g_application_open (application, files, n_files, "");
524 for (i = 0; i < n_files; i++)
525 g_object_unref (files[i]);
537 g_application_real_add_platform_data (GApplication *application,
538 GVariantBuilder *builder)
543 g_application_real_dbus_register (GApplication *application,
544 GDBusConnection *connection,
545 const gchar *object_path,
552 g_application_real_dbus_unregister (GApplication *application,
553 GDBusConnection *connection,
554 const gchar *object_path)
558 /* GObject implementation stuff {{{1 */
560 g_application_set_property (GObject *object,
565 GApplication *application = G_APPLICATION (object);
569 case PROP_APPLICATION_ID:
570 g_application_set_application_id (application,
571 g_value_get_string (value));
575 g_application_set_flags (application, g_value_get_flags (value));
578 case PROP_INACTIVITY_TIMEOUT:
579 g_application_set_inactivity_timeout (application,
580 g_value_get_uint (value));
583 case PROP_ACTION_GROUP:
584 g_clear_object (&application->priv->actions);
585 application->priv->actions = g_value_dup_object (value);
589 g_assert_not_reached ();
594 * g_application_set_action_group:
595 * @application: a #GApplication
596 * @action_group: (allow-none): a #GActionGroup, or %NULL
598 * This used to be how actions were associated with a #GApplication.
599 * Now there is #GActionMap for that.
603 * Deprecated:2.32:Use the #GActionMap interface instead. Never ever
604 * mix use of this API with use of #GActionMap on the same @application
605 * or things will go very badly wrong. This function is known to
606 * introduce buggy behaviour (ie: signals not emitted on changes to the
607 * action group), so you should really use #GActionMap instead.
610 g_application_set_action_group (GApplication *application,
611 GActionGroup *action_group)
613 g_return_if_fail (G_IS_APPLICATION (application));
614 g_return_if_fail (!application->priv->is_registered);
616 if (application->priv->actions != NULL)
617 g_object_unref (application->priv->actions);
619 application->priv->actions = action_group;
621 if (application->priv->actions != NULL)
622 g_object_ref (application->priv->actions);
626 g_application_get_property (GObject *object,
631 GApplication *application = G_APPLICATION (object);
635 case PROP_APPLICATION_ID:
636 g_value_set_string (value,
637 g_application_get_application_id (application));
641 g_value_set_flags (value,
642 g_application_get_flags (application));
645 case PROP_IS_REGISTERED:
646 g_value_set_boolean (value,
647 g_application_get_is_registered (application));
651 g_value_set_boolean (value,
652 g_application_get_is_remote (application));
655 case PROP_INACTIVITY_TIMEOUT:
656 g_value_set_uint (value,
657 g_application_get_inactivity_timeout (application));
661 g_assert_not_reached ();
666 g_application_constructed (GObject *object)
668 GApplication *application = G_APPLICATION (object);
670 if (g_application_get_default () == NULL)
671 g_application_set_default (application);
675 g_application_finalize (GObject *object)
677 GApplication *application = G_APPLICATION (object);
679 if (application->priv->impl)
680 g_application_impl_destroy (application->priv->impl);
681 g_free (application->priv->id);
683 if (g_application_get_default () == application)
684 g_application_set_default (NULL);
686 if (application->priv->actions)
687 g_object_unref (application->priv->actions);
689 G_OBJECT_CLASS (g_application_parent_class)
694 g_application_init (GApplication *application)
696 application->priv = g_application_get_instance_private (application);
698 application->priv->actions = g_application_exported_actions_new (application);
700 /* application->priv->actions is the one and only ref on the group, so when
701 * we dispose, the action group will die, disconnecting all signals.
703 g_signal_connect_swapped (application->priv->actions, "action-added",
704 G_CALLBACK (g_action_group_action_added), application);
705 g_signal_connect_swapped (application->priv->actions, "action-enabled-changed",
706 G_CALLBACK (g_action_group_action_enabled_changed), application);
707 g_signal_connect_swapped (application->priv->actions, "action-state-changed",
708 G_CALLBACK (g_action_group_action_state_changed), application);
709 g_signal_connect_swapped (application->priv->actions, "action-removed",
710 G_CALLBACK (g_action_group_action_removed), application);
714 g_application_class_init (GApplicationClass *class)
716 GObjectClass *object_class = G_OBJECT_CLASS (class);
718 object_class->constructed = g_application_constructed;
719 object_class->finalize = g_application_finalize;
720 object_class->get_property = g_application_get_property;
721 object_class->set_property = g_application_set_property;
723 class->before_emit = g_application_real_before_emit;
724 class->after_emit = g_application_real_after_emit;
725 class->startup = g_application_real_startup;
726 class->shutdown = g_application_real_shutdown;
727 class->activate = g_application_real_activate;
728 class->open = g_application_real_open;
729 class->command_line = g_application_real_command_line;
730 class->local_command_line = g_application_real_local_command_line;
731 class->add_platform_data = g_application_real_add_platform_data;
732 class->dbus_register = g_application_real_dbus_register;
733 class->dbus_unregister = g_application_real_dbus_unregister;
735 g_object_class_install_property (object_class, PROP_APPLICATION_ID,
736 g_param_spec_string ("application-id",
737 P_("Application identifier"),
738 P_("The unique identifier for the application"),
739 NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
740 G_PARAM_STATIC_STRINGS));
742 g_object_class_install_property (object_class, PROP_FLAGS,
743 g_param_spec_flags ("flags",
744 P_("Application flags"),
745 P_("Flags specifying the behaviour of the application"),
746 G_TYPE_APPLICATION_FLAGS, G_APPLICATION_FLAGS_NONE,
747 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
749 g_object_class_install_property (object_class, PROP_IS_REGISTERED,
750 g_param_spec_boolean ("is-registered",
752 P_("If g_application_register() has been called"),
753 FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
755 g_object_class_install_property (object_class, PROP_IS_REMOTE,
756 g_param_spec_boolean ("is-remote",
758 P_("If this application instance is remote"),
759 FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
761 g_object_class_install_property (object_class, PROP_INACTIVITY_TIMEOUT,
762 g_param_spec_uint ("inactivity-timeout",
763 P_("Inactivity timeout"),
764 P_("Time (ms) to stay alive after becoming idle"),
766 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
768 g_object_class_install_property (object_class, PROP_ACTION_GROUP,
769 g_param_spec_object ("action-group",
771 P_("The group of actions that the application exports"),
773 G_PARAM_DEPRECATED | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
776 * GApplication::startup:
777 * @application: the application
779 * The ::startup signal is emitted on the primary instance immediately
780 * after registration. See g_application_register().
782 g_application_signals[SIGNAL_STARTUP] =
783 g_signal_new ("startup", G_TYPE_APPLICATION, G_SIGNAL_RUN_FIRST,
784 G_STRUCT_OFFSET (GApplicationClass, startup),
785 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
788 * GApplication::shutdown:
789 * @application: the application
791 * The ::shutdown signal is emitted only on the registered primary instance
792 * immediately after the main loop terminates.
794 g_application_signals[SIGNAL_SHUTDOWN] =
795 g_signal_new ("shutdown", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
796 G_STRUCT_OFFSET (GApplicationClass, shutdown),
797 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
800 * GApplication::activate:
801 * @application: the application
803 * The ::activate signal is emitted on the primary instance when an
804 * activation occurs. See g_application_activate().
806 g_application_signals[SIGNAL_ACTIVATE] =
807 g_signal_new ("activate", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
808 G_STRUCT_OFFSET (GApplicationClass, activate),
809 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
813 * GApplication::open:
814 * @application: the application
815 * @files: (array length=n_files) (element-type GFile): an array of #GFiles
816 * @n_files: the length of @files
817 * @hint: a hint provided by the calling instance
819 * The ::open signal is emitted on the primary instance when there are
820 * files to open. See g_application_open() for more information.
822 g_application_signals[SIGNAL_OPEN] =
823 g_signal_new ("open", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
824 G_STRUCT_OFFSET (GApplicationClass, open),
826 G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);
829 * GApplication::command-line:
830 * @application: the application
831 * @command_line: a #GApplicationCommandLine representing the
834 * The ::command-line signal is emitted on the primary instance when
835 * a commandline is not handled locally. See g_application_run() and
836 * the #GApplicationCommandLine documentation for more information.
838 * Returns: An integer that is set as the exit status for the calling
839 * process. See g_application_command_line_set_exit_status().
841 g_application_signals[SIGNAL_COMMAND_LINE] =
842 g_signal_new ("command-line", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
843 G_STRUCT_OFFSET (GApplicationClass, command_line),
844 g_signal_accumulator_first_wins, NULL,
846 G_TYPE_INT, 1, G_TYPE_APPLICATION_COMMAND_LINE);
850 get_platform_data (GApplication *application)
852 GVariantBuilder *builder;
855 builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
858 gchar *cwd = g_get_current_dir ();
859 g_variant_builder_add (builder, "{sv}", "cwd",
860 g_variant_new_bytestring (cwd));
864 if (application->priv->flags & G_APPLICATION_SEND_ENVIRONMENT)
869 envp = g_get_environ ();
870 array = g_variant_new_bytestring_array ((const gchar **) envp, -1);
873 g_variant_builder_add (builder, "{sv}", "environ", array);
876 G_APPLICATION_GET_CLASS (application)->
877 add_platform_data (application, builder);
879 result = g_variant_builder_end (builder);
880 g_variant_builder_unref (builder);
885 /* Application ID validity {{{1 */
888 * g_application_id_is_valid:
889 * @application_id: a potential application identifier
891 * Checks if @application_id is a valid application identifier.
893 * A valid ID is required for calls to g_application_new() and
894 * g_application_set_application_id().
896 * For convenience, the restrictions on application identifiers are
899 * <listitem>Application identifiers must contain only the ASCII characters "[A-Z][a-z][0-9]_-." and must not begin with a digit.</listitem>
900 * <listitem>Application identifiers must contain at least one '.' (period) character (and thus at least three elements).</listitem>
901 * <listitem>Application identifiers must not begin or end with a '.' (period) character.</listitem>
902 * <listitem>Application identifiers must not contain consecutive '.' (period) characters.</listitem>
903 * <listitem>Application identifiers must not exceed 255 characters.</listitem>
906 * Returns: %TRUE if @application_id is valid
909 g_application_id_is_valid (const gchar *application_id)
915 len = strlen (application_id);
920 if (!g_ascii_isalpha (application_id[0]))
923 if (application_id[len-1] == '.')
929 for (; *application_id; application_id++)
931 if (g_ascii_isalnum (*application_id) ||
932 (*application_id == '-') ||
933 (*application_id == '_'))
937 else if (allow_dot && *application_id == '.')
952 /* Public Constructor {{{1 */
955 * @application_id: (allow-none): the application id
956 * @flags: the application flags
958 * Creates a new #GApplication instance.
960 * If non-%NULL, the application id must be valid. See
961 * g_application_id_is_valid().
963 * If no application ID is given then some features of #GApplication
964 * (most notably application uniqueness) will be disabled.
966 * Returns: a new #GApplication instance
969 g_application_new (const gchar *application_id,
970 GApplicationFlags flags)
972 g_return_val_if_fail (application_id == NULL || g_application_id_is_valid (application_id), NULL);
974 return g_object_new (G_TYPE_APPLICATION,
975 "application-id", application_id,
980 /* Simple get/set: application id, flags, inactivity timeout {{{1 */
982 * g_application_get_application_id:
983 * @application: a #GApplication
985 * Gets the unique identifier for @application.
987 * Returns: the identifier for @application, owned by @application
992 g_application_get_application_id (GApplication *application)
994 g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
996 return application->priv->id;
1000 * g_application_set_application_id:
1001 * @application: a #GApplication
1002 * @application_id: (allow-none): the identifier for @application
1004 * Sets the unique identifier for @application.
1006 * The application id can only be modified if @application has not yet
1009 * If non-%NULL, the application id must be valid. See
1010 * g_application_id_is_valid().
1015 g_application_set_application_id (GApplication *application,
1016 const gchar *application_id)
1018 g_return_if_fail (G_IS_APPLICATION (application));
1020 if (g_strcmp0 (application->priv->id, application_id) != 0)
1022 g_return_if_fail (application_id == NULL || g_application_id_is_valid (application_id));
1023 g_return_if_fail (!application->priv->is_registered);
1025 g_free (application->priv->id);
1026 application->priv->id = g_strdup (application_id);
1028 g_object_notify (G_OBJECT (application), "application-id");
1033 * g_application_get_flags:
1034 * @application: a #GApplication
1036 * Gets the flags for @application.
1038 * See #GApplicationFlags.
1040 * Returns: the flags for @application
1045 g_application_get_flags (GApplication *application)
1047 g_return_val_if_fail (G_IS_APPLICATION (application), 0);
1049 return application->priv->flags;
1053 * g_application_set_flags:
1054 * @application: a #GApplication
1055 * @flags: the flags for @application
1057 * Sets the flags for @application.
1059 * The flags can only be modified if @application has not yet been
1062 * See #GApplicationFlags.
1067 g_application_set_flags (GApplication *application,
1068 GApplicationFlags flags)
1070 g_return_if_fail (G_IS_APPLICATION (application));
1072 if (application->priv->flags != flags)
1074 g_return_if_fail (!application->priv->is_registered);
1076 application->priv->flags = flags;
1078 g_object_notify (G_OBJECT (application), "flags");
1083 * g_application_get_inactivity_timeout:
1084 * @application: a #GApplication
1086 * Gets the current inactivity timeout for the application.
1088 * This is the amount of time (in milliseconds) after the last call to
1089 * g_application_release() before the application stops running.
1091 * Returns: the timeout, in milliseconds
1096 g_application_get_inactivity_timeout (GApplication *application)
1098 g_return_val_if_fail (G_IS_APPLICATION (application), 0);
1100 return application->priv->inactivity_timeout;
1104 * g_application_set_inactivity_timeout:
1105 * @application: a #GApplication
1106 * @inactivity_timeout: the timeout, in milliseconds
1108 * Sets the current inactivity timeout for the application.
1110 * This is the amount of time (in milliseconds) after the last call to
1111 * g_application_release() before the application stops running.
1113 * This call has no side effects of its own. The value set here is only
1114 * used for next time g_application_release() drops the use count to
1115 * zero. Any timeouts currently in progress are not impacted.
1120 g_application_set_inactivity_timeout (GApplication *application,
1121 guint inactivity_timeout)
1123 g_return_if_fail (G_IS_APPLICATION (application));
1125 if (application->priv->inactivity_timeout != inactivity_timeout)
1127 application->priv->inactivity_timeout = inactivity_timeout;
1129 g_object_notify (G_OBJECT (application), "inactivity-timeout");
1132 /* Read-only property getters (is registered, is remote, dbus stuff) {{{1 */
1134 * g_application_get_is_registered:
1135 * @application: a #GApplication
1137 * Checks if @application is registered.
1139 * An application is registered if g_application_register() has been
1140 * successfully called.
1142 * Returns: %TRUE if @application is registered
1147 g_application_get_is_registered (GApplication *application)
1149 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
1151 return application->priv->is_registered;
1155 * g_application_get_is_remote:
1156 * @application: a #GApplication
1158 * Checks if @application is remote.
1160 * If @application is remote then it means that another instance of
1161 * application already exists (the 'primary' instance). Calls to
1162 * perform actions on @application will result in the actions being
1163 * performed by the primary instance.
1165 * The value of this property cannot be accessed before
1166 * g_application_register() has been called. See
1167 * g_application_get_is_registered().
1169 * Returns: %TRUE if @application is remote
1174 g_application_get_is_remote (GApplication *application)
1176 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
1177 g_return_val_if_fail (application->priv->is_registered, FALSE);
1179 return application->priv->is_remote;
1183 * g_application_get_dbus_connection:
1184 * @application: a #GApplication
1186 * Gets the #GDBusConnection being used by the application, or %NULL.
1188 * If #GApplication is using its D-Bus backend then this function will
1189 * return the #GDBusConnection being used for uniqueness and
1190 * communication with the desktop environment and other instances of the
1193 * If #GApplication is not using D-Bus then this function will return
1194 * %NULL. This includes the situation where the D-Bus backend would
1195 * normally be in use but we were unable to connect to the bus.
1197 * This function must not be called before the application has been
1198 * registered. See g_application_get_is_registered().
1200 * Returns: (transfer none): a #GDBusConnection, or %NULL
1205 g_application_get_dbus_connection (GApplication *application)
1207 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
1208 g_return_val_if_fail (application->priv->is_registered, FALSE);
1210 return g_application_impl_get_dbus_connection (application->priv->impl);
1214 * g_application_get_dbus_object_path:
1215 * @application: a #GApplication
1217 * Gets the D-Bus object path being used by the application, or %NULL.
1219 * If #GApplication is using its D-Bus backend then this function will
1220 * return the D-Bus object path that #GApplication is using. If the
1221 * application is the primary instance then there is an object published
1222 * at this path. If the application is not the primary instance then
1223 * the result of this function is undefined.
1225 * If #GApplication is not using D-Bus then this function will return
1226 * %NULL. This includes the situation where the D-Bus backend would
1227 * normally be in use but we were unable to connect to the bus.
1229 * This function must not be called before the application has been
1230 * registered. See g_application_get_is_registered().
1232 * Returns: the object path, or %NULL
1237 g_application_get_dbus_object_path (GApplication *application)
1239 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
1240 g_return_val_if_fail (application->priv->is_registered, FALSE);
1242 return g_application_impl_get_dbus_object_path (application->priv->impl);
1247 * g_application_register:
1248 * @application: a #GApplication
1249 * @cancellable: (allow-none): a #GCancellable, or %NULL
1250 * @error: a pointer to a NULL #GError, or %NULL
1252 * Attempts registration of the application.
1254 * This is the point at which the application discovers if it is the
1255 * primary instance or merely acting as a remote for an already-existing
1256 * primary instance. This is implemented by attempting to acquire the
1257 * application identifier as a unique bus name on the session bus using
1260 * If there is no application ID or if %G_APPLICATION_NON_UNIQUE was
1261 * given, then this process will always become the primary instance.
1263 * Due to the internal architecture of GDBus, method calls can be
1264 * dispatched at any time (even if a main loop is not running). For
1265 * this reason, you must ensure that any object paths that you wish to
1266 * register are registered before calling this function.
1268 * If the application has already been registered then %TRUE is
1269 * returned with no work performed.
1271 * The #GApplication::startup signal is emitted if registration succeeds
1272 * and @application is the primary instance (including the non-unique
1275 * In the event of an error (such as @cancellable being cancelled, or a
1276 * failure to connect to the session bus), %FALSE is returned and @error
1277 * is set appropriately.
1279 * Note: the return value of this function is not an indicator that this
1280 * instance is or is not the primary instance of the application. See
1281 * g_application_get_is_remote() for that.
1283 * Returns: %TRUE if registration succeeded
1288 g_application_register (GApplication *application,
1289 GCancellable *cancellable,
1292 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
1294 if (!application->priv->is_registered)
1296 if (application->priv->id == NULL)
1297 application->priv->flags |= G_APPLICATION_NON_UNIQUE;
1299 application->priv->impl =
1300 g_application_impl_register (application, application->priv->id,
1301 application->priv->flags,
1302 application->priv->actions,
1303 &application->priv->remote_actions,
1304 cancellable, error);
1306 if (application->priv->impl == NULL)
1309 application->priv->is_remote = application->priv->remote_actions != NULL;
1310 application->priv->is_registered = TRUE;
1312 g_object_notify (G_OBJECT (application), "is-registered");
1314 if (!application->priv->is_remote)
1316 g_signal_emit (application, g_application_signals[SIGNAL_STARTUP], 0);
1318 if (!application->priv->did_startup)
1319 g_critical ("GApplication subclass '%s' failed to chain up on"
1320 " ::startup (from start of override function)",
1321 G_OBJECT_TYPE_NAME (application));
1328 /* Hold/release {{{1 */
1330 * g_application_hold:
1331 * @application: a #GApplication
1333 * Increases the use count of @application.
1335 * Use this function to indicate that the application has a reason to
1336 * continue to run. For example, g_application_hold() is called by GTK+
1337 * when a toplevel window is on the screen.
1339 * To cancel the hold, call g_application_release().
1342 g_application_hold (GApplication *application)
1344 g_return_if_fail (G_IS_APPLICATION (application));
1346 if (application->priv->inactivity_timeout_id)
1348 g_source_remove (application->priv->inactivity_timeout_id);
1349 application->priv->inactivity_timeout_id = 0;
1352 application->priv->use_count++;
1356 inactivity_timeout_expired (gpointer data)
1358 GApplication *application = G_APPLICATION (data);
1360 application->priv->inactivity_timeout_id = 0;
1362 return G_SOURCE_REMOVE;
1367 * g_application_release:
1368 * @application: a #GApplication
1370 * Decrease the use count of @application.
1372 * When the use count reaches zero, the application will stop running.
1374 * Never call this function except to cancel the effect of a previous
1375 * call to g_application_hold().
1378 g_application_release (GApplication *application)
1380 g_return_if_fail (G_IS_APPLICATION (application));
1382 application->priv->use_count--;
1384 if (application->priv->use_count == 0 && application->priv->inactivity_timeout)
1385 application->priv->inactivity_timeout_id = g_timeout_add (application->priv->inactivity_timeout,
1386 inactivity_timeout_expired, application);
1389 /* Activate, Open {{{1 */
1391 * g_application_activate:
1392 * @application: a #GApplication
1394 * Activates the application.
1396 * In essence, this results in the #GApplication::activate signal being
1397 * emitted in the primary instance.
1399 * The application must be registered before calling this function.
1404 g_application_activate (GApplication *application)
1406 g_return_if_fail (G_IS_APPLICATION (application));
1407 g_return_if_fail (application->priv->is_registered);
1409 if (application->priv->is_remote)
1410 g_application_impl_activate (application->priv->impl,
1411 get_platform_data (application));
1414 g_signal_emit (application, g_application_signals[SIGNAL_ACTIVATE], 0);
1418 * g_application_open:
1419 * @application: a #GApplication
1420 * @files: (array length=n_files): an array of #GFiles to open
1421 * @n_files: the length of the @files array
1422 * @hint: a hint (or ""), but never %NULL
1424 * Opens the given files.
1426 * In essence, this results in the #GApplication::open signal being emitted
1427 * in the primary instance.
1429 * @n_files must be greater than zero.
1431 * @hint is simply passed through to the ::open signal. It is
1432 * intended to be used by applications that have multiple modes for
1433 * opening files (eg: "view" vs "edit", etc). Unless you have a need
1434 * for this functionality, you should use "".
1436 * The application must be registered before calling this function
1437 * and it must have the %G_APPLICATION_HANDLES_OPEN flag set.
1442 g_application_open (GApplication *application,
1447 g_return_if_fail (G_IS_APPLICATION (application));
1448 g_return_if_fail (application->priv->flags &
1449 G_APPLICATION_HANDLES_OPEN);
1450 g_return_if_fail (application->priv->is_registered);
1452 if (application->priv->is_remote)
1453 g_application_impl_open (application->priv->impl,
1454 files, n_files, hint,
1455 get_platform_data (application));
1458 g_signal_emit (application, g_application_signals[SIGNAL_OPEN],
1459 0, files, n_files, hint);
1464 * g_application_run:
1465 * @application: a #GApplication
1466 * @argc: the argc from main() (or 0 if @argv is %NULL)
1467 * @argv: (array length=argc) (allow-none): the argv from main(), or %NULL
1469 * Runs the application.
1471 * This function is intended to be run from main() and its return value
1472 * is intended to be returned by main(). Although you are expected to pass
1473 * the @argc, @argv parameters from main() to this function, it is possible
1474 * to pass %NULL if @argv is not available or commandline handling is not
1477 * First, the local_command_line() virtual function is invoked.
1478 * This function always runs on the local instance. It gets passed a pointer
1479 * to a %NULL-terminated copy of @argv and is expected to remove the arguments
1480 * that it handled (shifting up remaining arguments). See
1481 * <xref linkend="gapplication-example-cmdline2"/> for an example of
1482 * parsing @argv manually. Alternatively, you may use the #GOptionContext API,
1483 * after setting <literal>argc = g_strv_length (argv);</literal>.
1485 * The last argument to local_command_line() is a pointer to the @status
1486 * variable which can used to set the exit status that is returned from
1487 * g_application_run().
1489 * If local_command_line() returns %TRUE, the command line is expected
1490 * to be completely handled, including possibly registering as the primary
1491 * instance, calling g_application_activate() or g_application_open(), etc.
1493 * If local_command_line() returns %FALSE then the application is registered
1494 * and the #GApplication::command-line signal is emitted in the primary
1495 * instance (which may or may not be this instance). The signal handler
1496 * gets passed a #GApplicationCommandLine object that (among other things)
1497 * contains the remaining commandline arguments that have not been handled
1498 * by local_command_line().
1500 * If the application has the %G_APPLICATION_HANDLES_COMMAND_LINE
1501 * flag set then the default implementation of local_command_line()
1502 * always returns %FALSE immediately, resulting in the commandline
1503 * always being handled in the primary instance.
1505 * Otherwise, the default implementation of local_command_line() tries
1506 * to do a couple of things that are probably reasonable for most
1507 * applications. First, g_application_register() is called to attempt
1508 * to register the application. If that works, then the command line
1509 * arguments are inspected. If no commandline arguments are given, then
1510 * g_application_activate() is called. If commandline arguments are
1511 * given and the %G_APPLICATION_HANDLES_OPEN flag is set then they
1512 * are assumed to be filenames and g_application_open() is called.
1514 * If you need to handle commandline arguments that are not filenames,
1515 * and you don't mind commandline handling to happen in the primary
1516 * instance, you should set %G_APPLICATION_HANDLES_COMMAND_LINE and
1517 * process the commandline arguments in your #GApplication::command-line
1518 * signal handler, either manually or using the #GOptionContext API.
1520 * If you are interested in doing more complicated local handling of the
1521 * commandline then you should implement your own #GApplication subclass
1522 * and override local_command_line(). In this case, you most likely want
1523 * to return %TRUE from your local_command_line() implementation to
1524 * suppress the default handling. See
1525 * <xref linkend="gapplication-example-cmdline2"/> for an example.
1527 * If, after the above is done, the use count of the application is zero
1528 * then the exit status is returned immediately. If the use count is
1529 * non-zero then the default main context is iterated until the use count
1530 * falls to zero, at which point 0 is returned.
1532 * If the %G_APPLICATION_IS_SERVICE flag is set, then the service will
1533 * run for as much as 10 seconds with a use count of zero while waiting
1534 * for the message that caused the activation to arrive. After that,
1535 * if the use count falls to zero the application will exit immediately,
1536 * except in the case that g_application_set_inactivity_timeout() is in
1539 * This function sets the prgname (g_set_prgname()), if not already set,
1540 * to the basename of argv[0]. Since 2.38, if %G_APPLICATION_IS_SERVICE
1541 * is specified, the prgname is set to the application ID. The main
1542 * impact of this is is that the wmclass of windows created by Gtk+ will
1543 * be set accordingly, which helps the window manager determine which
1544 * application is showing the window.
1546 * Returns: the exit status
1551 g_application_run (GApplication *application,
1559 g_return_val_if_fail (G_IS_APPLICATION (application), 1);
1560 g_return_val_if_fail (argc == 0 || argv != NULL, 1);
1561 g_return_val_if_fail (!application->priv->must_quit_now, 1);
1563 arguments = g_new (gchar *, argc + 1);
1564 for (i = 0; i < argc; i++)
1565 arguments[i] = g_strdup (argv[i]);
1566 arguments[i] = NULL;
1568 if (g_get_prgname () == NULL)
1570 if (application->priv->flags & G_APPLICATION_IS_SERVICE)
1572 g_set_prgname (application->priv->id);
1578 prgname = g_path_get_basename (argv[0]);
1579 g_set_prgname (prgname);
1584 if (!G_APPLICATION_GET_CLASS (application)
1585 ->local_command_line (application, &arguments, &status))
1587 GError *error = NULL;
1589 if (!g_application_register (application, NULL, &error))
1591 g_printerr ("%s", error->message);
1592 g_error_free (error);
1596 if (application->priv->is_remote)
1598 GVariant *platform_data;
1600 platform_data = get_platform_data (application);
1601 status = g_application_impl_command_line (application->priv->impl,
1602 arguments, platform_data);
1606 GApplicationCommandLine *cmdline;
1609 v = g_variant_new_bytestring_array ((const gchar **) arguments, -1);
1610 cmdline = g_object_new (G_TYPE_APPLICATION_COMMAND_LINE,
1611 "arguments", v, NULL);
1612 g_signal_emit (application,
1613 g_application_signals[SIGNAL_COMMAND_LINE],
1614 0, cmdline, &status);
1615 g_object_unref (cmdline);
1619 g_strfreev (arguments);
1621 if (application->priv->flags & G_APPLICATION_IS_SERVICE &&
1622 application->priv->is_registered &&
1623 !application->priv->use_count &&
1624 !application->priv->inactivity_timeout_id)
1626 application->priv->inactivity_timeout_id =
1627 g_timeout_add (10000, inactivity_timeout_expired, application);
1630 while (application->priv->use_count || application->priv->inactivity_timeout_id)
1632 if (application->priv->must_quit_now)
1635 g_main_context_iteration (NULL, TRUE);
1639 if (application->priv->is_registered && !application->priv->is_remote)
1641 g_signal_emit (application, g_application_signals[SIGNAL_SHUTDOWN], 0);
1643 if (!application->priv->did_shutdown)
1644 g_critical ("GApplication subclass '%s' failed to chain up on"
1645 " ::shutdown (from end of override function)",
1646 G_OBJECT_TYPE_NAME (application));
1649 if (application->priv->impl)
1650 g_application_impl_flush (application->priv->impl);
1658 g_application_list_actions (GActionGroup *action_group)
1660 GApplication *application = G_APPLICATION (action_group);
1662 g_return_val_if_fail (application->priv->is_registered, NULL);
1664 if (application->priv->remote_actions != NULL)
1665 return g_action_group_list_actions (G_ACTION_GROUP (application->priv->remote_actions));
1667 else if (application->priv->actions != NULL)
1668 return g_action_group_list_actions (application->priv->actions);
1671 /* empty string array */
1672 return g_new0 (gchar *, 1);
1676 g_application_query_action (GActionGroup *group,
1677 const gchar *action_name,
1679 const GVariantType **parameter_type,
1680 const GVariantType **state_type,
1681 GVariant **state_hint,
1684 GApplication *application = G_APPLICATION (group);
1686 g_return_val_if_fail (application->priv->is_registered, FALSE);
1688 if (application->priv->remote_actions != NULL)
1689 return g_action_group_query_action (G_ACTION_GROUP (application->priv->remote_actions),
1697 if (application->priv->actions != NULL)
1698 return g_action_group_query_action (application->priv->actions,
1710 g_application_change_action_state (GActionGroup *action_group,
1711 const gchar *action_name,
1714 GApplication *application = G_APPLICATION (action_group);
1716 g_return_if_fail (application->priv->is_remote ||
1717 application->priv->actions != NULL);
1718 g_return_if_fail (application->priv->is_registered);
1720 if (application->priv->remote_actions)
1721 g_remote_action_group_change_action_state_full (application->priv->remote_actions,
1722 action_name, value, get_platform_data (application));
1725 g_action_group_change_action_state (application->priv->actions, action_name, value);
1729 g_application_activate_action (GActionGroup *action_group,
1730 const gchar *action_name,
1731 GVariant *parameter)
1733 GApplication *application = G_APPLICATION (action_group);
1735 g_return_if_fail (application->priv->is_remote ||
1736 application->priv->actions != NULL);
1737 g_return_if_fail (application->priv->is_registered);
1739 if (application->priv->remote_actions)
1740 g_remote_action_group_activate_action_full (application->priv->remote_actions,
1741 action_name, parameter, get_platform_data (application));
1744 g_action_group_activate_action (application->priv->actions, action_name, parameter);
1748 g_application_lookup_action (GActionMap *action_map,
1749 const gchar *action_name)
1751 GApplication *application = G_APPLICATION (action_map);
1753 g_return_val_if_fail (G_IS_SIMPLE_ACTION_GROUP (application->priv->actions), NULL);
1755 return g_simple_action_group_lookup (G_SIMPLE_ACTION_GROUP (application->priv->actions), action_name);
1759 g_application_add_action (GActionMap *action_map,
1762 GApplication *application = G_APPLICATION (action_map);
1764 g_return_if_fail (G_IS_SIMPLE_ACTION_GROUP (application->priv->actions));
1766 g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (application->priv->actions), action);
1770 g_application_remove_action (GActionMap *action_map,
1771 const gchar *action_name)
1773 GApplication *application = G_APPLICATION (action_map);
1775 g_return_if_fail (G_IS_SIMPLE_ACTION_GROUP (application->priv->actions));
1777 g_simple_action_group_remove (G_SIMPLE_ACTION_GROUP (application->priv->actions), action_name);
1781 g_application_action_group_iface_init (GActionGroupInterface *iface)
1783 iface->list_actions = g_application_list_actions;
1784 iface->query_action = g_application_query_action;
1785 iface->change_action_state = g_application_change_action_state;
1786 iface->activate_action = g_application_activate_action;
1790 g_application_action_map_iface_init (GActionMapInterface *iface)
1792 iface->lookup_action = g_application_lookup_action;
1793 iface->add_action = g_application_add_action;
1794 iface->remove_action = g_application_remove_action;
1797 /* Default Application {{{1 */
1799 static GApplication *default_app;
1802 * g_application_get_default:
1804 * Returns the default #GApplication instance for this process.
1806 * Normally there is only one #GApplication per process and it becomes
1807 * the default when it is created. You can exercise more control over
1808 * this by using g_application_set_default().
1810 * If there is no default application then %NULL is returned.
1812 * Returns: (transfer none): the default application for this process, or %NULL
1817 g_application_get_default (void)
1823 * g_application_set_default:
1824 * @application: (allow-none): the application to set as default, or %NULL
1826 * Sets or unsets the default application for the process, as returned
1827 * by g_application_get_default().
1829 * This function does not take its own reference on @application. If
1830 * @application is destroyed then the default application will revert
1836 g_application_set_default (GApplication *application)
1838 default_app = application;
1842 * g_application_quit:
1843 * @application: a #GApplication
1845 * Immediately quits the application.
1847 * Upon return to the mainloop, g_application_run() will return,
1848 * calling only the 'shutdown' function before doing so.
1850 * The hold count is ignored.
1852 * The result of calling g_application_run() again after it returns is
1858 g_application_quit (GApplication *application)
1860 g_return_if_fail (G_IS_APPLICATION (application));
1862 application->priv->must_quit_now = TRUE;
1866 * g_application_mark_busy:
1867 * @application: a #GApplication
1869 * Increases the busy count of @application.
1871 * Use this function to indicate that the application is busy, for instance
1872 * while a long running operation is pending.
1874 * The busy state will be exposed to other processes, so a session shell will
1875 * use that information to indicate the state to the user (e.g. with a
1878 * To cancel the busy indication, use g_application_unmark_busy().
1883 g_application_mark_busy (GApplication *application)
1887 g_return_if_fail (G_IS_APPLICATION (application));
1889 was_busy = (application->priv->busy_count > 0);
1890 application->priv->busy_count++;
1893 g_application_impl_set_busy_state (application->priv->impl, TRUE);
1897 * g_application_unmark_busy:
1898 * @application: a #GApplication
1900 * Decreases the busy count of @application.
1902 * When the busy count reaches zero, the new state will be propagated
1903 * to other processes.
1905 * This function must only be called to cancel the effect of a previous
1906 * call to g_application_mark_busy().
1911 g_application_unmark_busy (GApplication *application)
1913 g_return_if_fail (G_IS_APPLICATION (application));
1914 g_return_if_fail (application->priv->busy_count > 0);
1916 application->priv->busy_count--;
1918 if (application->priv->busy_count == 0)
1919 g_application_impl_set_busy_state (application->priv->impl, FALSE);
1923 /* vim:set foldmethod=marker: */