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, unique for a
50 * given application identifier. The GApplication class wraps some
51 * low-level platform-specific services and is intended to act as the
52 * foundation for higher-level application classes such as
53 * #GtkApplication or #MxApplication. In general, you should not use
54 * this class outside of a higher level framework.
56 * One of the core features that GApplication provides is process
57 * uniqueness, in the context of a "session". The session concept is
58 * platform-dependent, but corresponds roughly to a graphical desktop
59 * login. When your application is launched again, its arguments
60 * are passed through platform communication to the already running
61 * program. The already running instance of the program is called the
62 * <firstterm>primary instance</firstterm>. On Linux, the D-Bus session
63 * bus is used for communication.
65 * GApplication provides convenient life cycle management by maintaining
66 * a <firstterm>use count</firstterm> for the primary application instance.
67 * The use count can be changed using g_application_hold() and
68 * g_application_release(). If it drops to zero, the application exits.
69 * Higher-level classes such as #GtkApplication employ the use count to
70 * ensure that the application stays alive as long as it has any opened
73 * Before using GApplication, you must choose an "application identifier".
74 * The expected form of an application identifier is very close to that of
75 * of a <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface">DBus bus name</ulink>.
76 * Examples include: "com.example.MyApp", "org.example.internal-apps.Calculator".
77 * For details on valid application identifiers, see g_application_id_is_valid().
79 * On Linux, the application identifier is claimed as a well-known bus name
80 * on the user's session bus. This means that the uniqueness of your
81 * application is scoped to the current session. It also means that your
82 * application may provide additional services (through registration of other
83 * object paths) at that bus name. The registration of these object paths
84 * should be done with the shared GDBus session bus. Note that due to the
85 * internal architecture of GDBus, method calls can be dispatched at any time
86 * (even if a main loop is not running). For this reason, you must ensure that
87 * any object paths that you wish to register are registered before #GApplication
88 * attempts to acquire the bus name of your application (which happens in
89 * g_application_register()). Unfortunately, this means that you cannot use
90 * g_application_get_is_remote() to decide if you want to register object paths.
92 * GApplication also implements the #GActionGroup and #GActionMap
93 * interfaces and lets you easily export actions by adding them with
94 * g_action_map_add_action(). When invoking an action by calling
95 * g_action_group_activate_action() on the application, it is always
96 * invoked in the primary instance. The actions are also exported on
97 * the session bus, and GIO provides the #GDBusActionGroup wrapper to
98 * conveniently access them remotely. Additionally, g_application_set_app_menu()
99 * and g_application_set_menubar() can be used to export representation
100 * data for the actions, in the form of #GMenuModels. GIO provides
101 * a #GDBusMenuModel wrapper for remote access to exported #GMenuModels.
103 * There is a number of different entry points into a GApplication:
105 * <listitem>via 'Activate' (i.e. just starting the application)</listitem>
106 * <listitem>via 'Open' (i.e. opening some files)</listitem>
107 * <listitem>by handling a command-line</listitem>
108 * <listitem>via activating an action</listitem>
110 * The #GApplication::startup signal lets you handle the application
111 * initialization for all of these in a single place.
113 * Regardless of which of these entry points is used to start the application,
114 * GApplication passes some <firstterm id="platform-data">platform
115 * data</firstterm> from the launching instance to the primary instance,
116 * in the form of a #GVariant dictionary mapping strings to variants.
117 * To use platform data, override the @before_emit or @after_emit virtual
118 * functions in your #GApplication subclass. When dealing with
119 * #GApplicationCommandline objects, the platform data is directly
120 * available via g_application_command_line_get_cwd(),
121 * g_application_command_line_get_environ() and
122 * g_application_command_line_get_platform_data().
124 * As the name indicates, the platform data may vary depending on the
125 * operating system, but it always includes the current directory (key
126 * "cwd"), and optionally the environment (ie the set of environment
127 * variables and their values) of the calling process (key "environ").
128 * The environment is only added to the platform data if the
129 * #G_APPLICATION_SEND_ENVIONMENT flag is set. GApplication subclasses
130 * can add their own platform data by overriding the @add_platform_data
131 * virtual function. For instance, #GtkApplication adds startup notification
134 * To parse commandline arguments you may handle the
135 * #GApplication::command-line signal or override the local_command_line()
136 * vfunc, to parse them in either the primary instance or the local instance,
139 * <example id="gapplication-example-open"><title>Opening files with a GApplication</title>
141 * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-open.c">
142 * <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
147 * <example id="gapplication-example-actions"><title>A GApplication with actions</title>
149 * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-actions.c">
150 * <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
155 * <example id="gapplication-example-menu"><title>A GApplication with menus</title>
157 * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-menu.c">
158 * <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
166 * @startup: invoked on the primary instance immediately after registration
167 * @shutdown: invoked only on the registered primary instance immediately
168 * after the main loop terminates
169 * @activate: invoked on the primary instance when an activation occurs
170 * @open: invoked on the primary instance when there are files to open
171 * @command_line: invoked on the primary instance when a command-line is
172 * not handled locally
173 * @local_command_line: invoked (locally) when the process has been invoked
174 * via commandline execution (as opposed to, say, D-Bus activation - which
175 * is not currently supported by GApplication). The virtual function has
176 * the chance to inspect (and possibly replace) the list of command line
177 * arguments. See g_application_run() for more information.
178 * @before_emit: invoked on the primary instance before 'activate', 'open',
179 * 'command-line' or any action invocation, gets the 'platform data' from
180 * the calling instance
181 * @after_emit: invoked on the primary instance after 'activate', 'open',
182 * 'command-line' or any action invocation, gets the 'platform data' from
183 * the calling instance
184 * @add_platform_data: invoked (locally) to add 'platform data' to be sent to
185 * the primary instance when activating, opening or invoking actions
186 * @quit_mainloop: Used to be invoked on the primary instance when the use
187 * count of the application drops to zero (and after any inactivity
188 * timeout, if requested). Not used anymore since 2.32
189 * @run_mainloop: Used to be invoked on the primary instance from
190 * g_application_run() if the use-count is non-zero. Since 2.32,
191 * GApplication is iterating the main context directly and is not
192 * using @run_mainloop anymore
194 * Virtual function table for #GApplication.
199 struct _GApplicationPrivate
201 GApplicationFlags flags;
204 GActionGroup *actions;
205 GMenuModel *app_menu;
208 guint inactivity_timeout_id;
209 guint inactivity_timeout;
212 guint is_registered : 1;
214 guint did_startup : 1;
215 guint did_shutdown : 1;
217 GRemoteActionGroup *remote_actions;
218 GApplicationImpl *impl;
228 PROP_INACTIVITY_TIMEOUT,
245 static guint g_application_signals[NR_SIGNALS];
247 static void g_application_action_group_iface_init (GActionGroupInterface *);
248 static void g_application_action_map_iface_init (GActionMapInterface *);
249 G_DEFINE_TYPE_WITH_CODE (GApplication, g_application, G_TYPE_OBJECT,
250 G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, g_application_action_group_iface_init)
251 G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_MAP, g_application_action_map_iface_init))
253 /* GApplicationExportedActions {{{1 */
255 /* We create a subclass of GSimpleActionGroup that implements
256 * GRemoteActionGroup and deals with the platform data using
257 * GApplication's before/after_emit vfuncs. This is the action group we
260 * We could implement GRemoteActionGroup on GApplication directly, but
261 * this would be potentially extremely confusing to have exposed as part
262 * of the public API of GApplication. We certainly don't want anyone in
263 * the same process to be calling these APIs...
265 typedef GSimpleActionGroupClass GApplicationExportedActionsClass;
268 GSimpleActionGroup parent_instance;
269 GApplication *application;
270 } GApplicationExportedActions;
272 static GType g_application_exported_actions_get_type (void);
273 static void g_application_exported_actions_iface_init (GRemoteActionGroupInterface *iface);
274 G_DEFINE_TYPE_WITH_CODE (GApplicationExportedActions, g_application_exported_actions, G_TYPE_SIMPLE_ACTION_GROUP,
275 G_IMPLEMENT_INTERFACE (G_TYPE_REMOTE_ACTION_GROUP, g_application_exported_actions_iface_init))
278 g_application_exported_actions_activate_action_full (GRemoteActionGroup *remote,
279 const gchar *action_name,
281 GVariant *platform_data)
283 GApplicationExportedActions *exported = (GApplicationExportedActions *) remote;
285 G_APPLICATION_GET_CLASS (exported->application)
286 ->before_emit (exported->application, platform_data);
288 g_action_group_activate_action (G_ACTION_GROUP (exported), action_name, parameter);
290 G_APPLICATION_GET_CLASS (exported->application)
291 ->after_emit (exported->application, platform_data);
295 g_application_exported_actions_change_action_state_full (GRemoteActionGroup *remote,
296 const gchar *action_name,
298 GVariant *platform_data)
300 GApplicationExportedActions *exported = (GApplicationExportedActions *) remote;
302 G_APPLICATION_GET_CLASS (exported->application)
303 ->before_emit (exported->application, platform_data);
305 g_action_group_change_action_state (G_ACTION_GROUP (exported), action_name, value);
307 G_APPLICATION_GET_CLASS (exported->application)
308 ->after_emit (exported->application, platform_data);
312 g_application_exported_actions_init (GApplicationExportedActions *actions)
317 g_application_exported_actions_iface_init (GRemoteActionGroupInterface *iface)
319 iface->activate_action_full = g_application_exported_actions_activate_action_full;
320 iface->change_action_state_full = g_application_exported_actions_change_action_state_full;
324 g_application_exported_actions_class_init (GApplicationExportedActionsClass *class)
328 static GActionGroup *
329 g_application_exported_actions_new (GApplication *application)
331 GApplicationExportedActions *actions;
333 actions = g_object_new (g_application_exported_actions_get_type (), NULL);
334 actions->application = application;
336 return G_ACTION_GROUP (actions);
339 /* vfunc defaults {{{1 */
341 g_application_real_before_emit (GApplication *application,
342 GVariant *platform_data)
347 g_application_real_after_emit (GApplication *application,
348 GVariant *platform_data)
353 g_application_real_startup (GApplication *application)
355 application->priv->did_startup = TRUE;
359 g_application_real_shutdown (GApplication *application)
361 application->priv->did_shutdown = TRUE;
365 g_application_real_activate (GApplication *application)
367 if (!g_signal_has_handler_pending (application,
368 g_application_signals[SIGNAL_ACTIVATE],
370 G_APPLICATION_GET_CLASS (application)->activate == g_application_real_activate)
372 static gboolean warned;
377 g_warning ("Your application does not implement "
378 "g_application_activate() and has no handlers connected "
379 "to the 'activate' signal. It should do one of these.");
385 g_application_real_open (GApplication *application,
390 if (!g_signal_has_handler_pending (application,
391 g_application_signals[SIGNAL_OPEN],
393 G_APPLICATION_GET_CLASS (application)->open == g_application_real_open)
395 static gboolean warned;
400 g_warning ("Your application claims to support opening files "
401 "but does not implement g_application_open() and has no "
402 "handlers connected to the 'open' signal.");
408 g_application_real_command_line (GApplication *application,
409 GApplicationCommandLine *cmdline)
411 if (!g_signal_has_handler_pending (application,
412 g_application_signals[SIGNAL_COMMAND_LINE],
414 G_APPLICATION_GET_CLASS (application)->command_line == g_application_real_command_line)
416 static gboolean warned;
421 g_warning ("Your application claims to support custom command line "
422 "handling but does not implement g_application_command_line() "
423 "and has no handlers connected to the 'command-line' signal.");
432 g_application_real_local_command_line (GApplication *application,
436 if (application->priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE)
441 GError *error = NULL;
444 if (!g_application_register (application, NULL, &error))
446 g_critical ("%s", error->message);
447 g_error_free (error);
452 n_args = g_strv_length (*arguments);
454 if (application->priv->flags & G_APPLICATION_IS_SERVICE)
456 if ((*exit_status = n_args > 1))
458 g_printerr ("GApplication service mode takes no arguments.\n");
459 application->priv->flags &= ~G_APPLICATION_IS_SERVICE;
467 g_application_activate (application);
473 if (~application->priv->flags & G_APPLICATION_HANDLES_OPEN)
475 g_critical ("This application can not open files.");
484 n_files = n_args - 1;
485 files = g_new (GFile *, n_files);
487 for (i = 0; i < n_files; i++)
488 files[i] = g_file_new_for_commandline_arg ((*arguments)[i + 1]);
490 g_application_open (application, files, n_files, "");
492 for (i = 0; i < n_files; i++)
493 g_object_unref (files[i]);
505 g_application_real_add_platform_data (GApplication *application,
506 GVariantBuilder *builder)
510 /* GObject implementation stuff {{{1 */
512 g_application_set_property (GObject *object,
517 GApplication *application = G_APPLICATION (object);
521 case PROP_APPLICATION_ID:
522 g_application_set_application_id (application,
523 g_value_get_string (value));
527 g_application_set_flags (application, g_value_get_flags (value));
530 case PROP_INACTIVITY_TIMEOUT:
531 g_application_set_inactivity_timeout (application,
532 g_value_get_uint (value));
535 case PROP_ACTION_GROUP:
536 g_clear_object (&application->priv->actions);
537 application->priv->actions = g_value_dup_object (value);
541 g_application_set_app_menu (application, g_value_get_object (value));
545 g_application_set_menubar (application, g_value_get_object (value));
549 g_assert_not_reached ();
554 * g_application_set_action_group:
555 * @application: a #GApplication
556 * @action_group: (allow-none): a #GActionGroup, or %NULL
558 * This used to be how actions were associated with a #GApplication.
559 * Now there is #GActionMap for that.
563 * Deprecated:2.32:Use the #GActionMap interface instead. Never ever
564 * mix use of this API with use of #GActionMap on the same @application
565 * or things will go very badly wrong. This function is known to
566 * introduce buggy behaviour (ie: signals not emitted on changes to the
567 * action group), so you should really use #GActionMap instead.
570 g_application_set_action_group (GApplication *application,
571 GActionGroup *action_group)
573 g_return_if_fail (G_IS_APPLICATION (application));
574 g_return_if_fail (!application->priv->is_registered);
576 if (application->priv->actions != NULL)
577 g_object_unref (application->priv->actions);
579 application->priv->actions = action_group;
581 if (application->priv->actions != NULL)
582 g_object_ref (application->priv->actions);
586 * g_application_set_app_menu:
587 * @application: a #GApplication
588 * @app_menu: (allow-none): a #GMenuModel, or %NULL
590 * Sets or unsets the application menu for @application.
592 * The application menu is a single menu containing items that typically
593 * impact the application as a whole, rather than acting on a specific
594 * window or document. For example, you would expect to see
595 * "Preferences" or "Quit" in an application menu, but not "Save" or
598 * If supported, the application menu will be rendered by the desktop
604 g_application_set_app_menu (GApplication *application,
605 GMenuModel *app_menu)
607 g_return_if_fail (G_IS_APPLICATION (application));
609 if (app_menu != application->priv->app_menu)
611 if (application->priv->app_menu != NULL)
612 g_object_unref (application->priv->app_menu);
614 application->priv->app_menu = app_menu;
616 if (application->priv->app_menu != NULL)
617 g_object_ref (application->priv->app_menu);
619 g_object_notify (G_OBJECT (application), "app-menu");
624 * g_application_get_app_menu:
625 * @application: a #GApplication
627 * Returns the menu model that has been set with
628 * g_application_set_app_menu().
630 * Returns: the application menu of @application
635 g_application_get_app_menu (GApplication *application)
637 g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
639 return application->priv->app_menu;
643 * g_application_set_menubar:
644 * @application: a #GApplication
645 * @menubar: (allow-none): a #GMenuModel, or %NULL
647 * Sets or unsets the menubar for windows of @application.
649 * This is a menubar in the traditional sense.
651 * Depending on the desktop environment, this may appear at the top of
652 * each window, or at the top of the screen. In some environments, if
653 * both the application menu and the menubar are set, the application
654 * menu will be presented as if it were the first item of the menubar.
655 * Other environments treat the two as completely separate -- for
656 * example, the application menu may be rendered by the desktop shell
657 * while the menubar (if set) remains in each individual window.
662 g_application_set_menubar (GApplication *application,
665 g_return_if_fail (G_IS_APPLICATION (application));
667 if (menubar != application->priv->menubar)
669 if (application->priv->menubar != NULL)
670 g_object_unref (application->priv->menubar);
672 application->priv->menubar = menubar;
674 if (application->priv->menubar != NULL)
675 g_object_ref (application->priv->menubar);
677 g_object_notify (G_OBJECT (application), "menubar");
682 * g_application_get_menubar:
683 * @application: a #GApplication
685 * Returns the menu model that has been set with
686 * g_application_set_menubar().
688 * Returns: the menubar for windows of @application
693 g_application_get_menubar (GApplication *application)
695 g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
697 return application->priv->menubar;
701 g_application_get_property (GObject *object,
706 GApplication *application = G_APPLICATION (object);
710 case PROP_APPLICATION_ID:
711 g_value_set_string (value,
712 g_application_get_application_id (application));
716 g_value_set_flags (value,
717 g_application_get_flags (application));
720 case PROP_IS_REGISTERED:
721 g_value_set_boolean (value,
722 g_application_get_is_registered (application));
726 g_value_set_boolean (value,
727 g_application_get_is_remote (application));
730 case PROP_INACTIVITY_TIMEOUT:
731 g_value_set_uint (value,
732 g_application_get_inactivity_timeout (application));
736 g_value_set_object (value,
737 g_application_get_app_menu (application));
741 g_value_set_object (value,
742 g_application_get_menubar (application));
746 g_assert_not_reached ();
751 g_application_constructed (GObject *object)
753 GApplication *application = G_APPLICATION (object);
755 g_assert (application->priv->id != NULL);
757 if (g_application_get_default () == NULL)
758 g_application_set_default (application);
762 g_application_finalize (GObject *object)
764 GApplication *application = G_APPLICATION (object);
766 if (application->priv->impl)
767 g_application_impl_destroy (application->priv->impl);
768 g_free (application->priv->id);
770 if (g_application_get_default () == application)
771 g_application_set_default (NULL);
773 if (application->priv->app_menu)
774 g_object_unref (application->priv->app_menu);
776 if (application->priv->menubar)
777 g_object_unref (application->priv->menubar);
779 if (application->priv->actions)
780 g_object_unref (application->priv->actions);
782 G_OBJECT_CLASS (g_application_parent_class)
787 g_application_init (GApplication *application)
789 application->priv = G_TYPE_INSTANCE_GET_PRIVATE (application,
791 GApplicationPrivate);
793 application->priv->actions = g_application_exported_actions_new (application);
795 /* application->priv->actions is the one and only ref on the group, so when
796 * we dispose, the action group will die, disconnecting all signals.
798 g_signal_connect_swapped (application->priv->actions, "action-added",
799 G_CALLBACK (g_action_group_action_added), application);
800 g_signal_connect_swapped (application->priv->actions, "action-enabled-changed",
801 G_CALLBACK (g_action_group_action_enabled_changed), application);
802 g_signal_connect_swapped (application->priv->actions, "action-state-changed",
803 G_CALLBACK (g_action_group_action_state_changed), application);
804 g_signal_connect_swapped (application->priv->actions, "action-removed",
805 G_CALLBACK (g_action_group_action_removed), application);
809 g_application_class_init (GApplicationClass *class)
811 GObjectClass *object_class = G_OBJECT_CLASS (class);
813 object_class->constructed = g_application_constructed;
814 object_class->finalize = g_application_finalize;
815 object_class->get_property = g_application_get_property;
816 object_class->set_property = g_application_set_property;
818 class->before_emit = g_application_real_before_emit;
819 class->after_emit = g_application_real_after_emit;
820 class->startup = g_application_real_startup;
821 class->shutdown = g_application_real_shutdown;
822 class->activate = g_application_real_activate;
823 class->open = g_application_real_open;
824 class->command_line = g_application_real_command_line;
825 class->local_command_line = g_application_real_local_command_line;
826 class->add_platform_data = g_application_real_add_platform_data;
828 g_object_class_install_property (object_class, PROP_APPLICATION_ID,
829 g_param_spec_string ("application-id",
830 P_("Application identifier"),
831 P_("The unique identifier for the application"),
832 NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
833 G_PARAM_STATIC_STRINGS));
835 g_object_class_install_property (object_class, PROP_FLAGS,
836 g_param_spec_flags ("flags",
837 P_("Application flags"),
838 P_("Flags specifying the behaviour of the application"),
839 G_TYPE_APPLICATION_FLAGS, G_APPLICATION_FLAGS_NONE,
840 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
842 g_object_class_install_property (object_class, PROP_IS_REGISTERED,
843 g_param_spec_boolean ("is-registered",
845 P_("If g_application_register() has been called"),
846 FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
848 g_object_class_install_property (object_class, PROP_IS_REMOTE,
849 g_param_spec_boolean ("is-remote",
851 P_("If this application instance is remote"),
852 FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
854 g_object_class_install_property (object_class, PROP_INACTIVITY_TIMEOUT,
855 g_param_spec_uint ("inactivity-timeout",
856 P_("Inactivity timeout"),
857 P_("Time (ms) to stay alive after becoming idle"),
859 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
861 g_object_class_install_property (object_class, PROP_ACTION_GROUP,
862 g_param_spec_object ("action-group",
864 P_("The group of actions that the application exports"),
866 G_PARAM_DEPRECATED | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
868 g_object_class_install_property (object_class, PROP_APP_MENU,
869 g_param_spec_object ("app-menu",
870 P_("Application menu"),
871 P_("The GMenuModel for the application menu"),
873 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
875 g_object_class_install_property (object_class, PROP_MENUBAR,
876 g_param_spec_object ("menubar",
878 P_("The GMenuModel for the menubar"),
880 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
883 * GApplication::startup:
884 * @application: the application
886 * The ::startup signal is emitted on the primary instance immediately
887 * after registration. See g_application_register().
889 g_application_signals[SIGNAL_STARTUP] =
890 g_signal_new ("startup", G_TYPE_APPLICATION, G_SIGNAL_RUN_FIRST,
891 G_STRUCT_OFFSET (GApplicationClass, startup),
892 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
895 * GApplication::shutdown:
896 * @application: the application
898 * The ::shutdown signal is emitted only on the registered primary instance
899 * immediately after the main loop terminates.
901 g_application_signals[SIGNAL_SHUTDOWN] =
902 g_signal_new ("shutdown", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
903 G_STRUCT_OFFSET (GApplicationClass, shutdown),
904 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
907 * GApplication::activate:
908 * @application: the application
910 * The ::activate signal is emitted on the primary instance when an
911 * activation occurs. See g_application_activate().
913 g_application_signals[SIGNAL_ACTIVATE] =
914 g_signal_new ("activate", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
915 G_STRUCT_OFFSET (GApplicationClass, activate),
916 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
920 * GApplication::open:
921 * @application: the application
922 * @files: (array length=n_files) (element-type GFile): an array of #GFiles
923 * @n_files: the length of @files
924 * @hint: a hint provided by the calling instance
926 * The ::open signal is emitted on the primary instance when there are
927 * files to open. See g_application_open() for more information.
929 g_application_signals[SIGNAL_OPEN] =
930 g_signal_new ("open", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
931 G_STRUCT_OFFSET (GApplicationClass, open),
933 G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);
936 * GApplication::command-line:
937 * @application: the application
938 * @command_line: a #GApplicationCommandLine representing the
941 * The ::command-line signal is emitted on the primary instance when
942 * a commandline is not handled locally. See g_application_run() and
943 * the #GApplicationCommandline documentation for more information.
945 * Returns: An integer that is set as the exit status for the calling
946 * process. See g_application_command_line_set_exit_status().
948 g_application_signals[SIGNAL_COMMAND_LINE] =
949 g_signal_new ("command-line", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
950 G_STRUCT_OFFSET (GApplicationClass, command_line),
951 g_signal_accumulator_first_wins, NULL,
953 G_TYPE_INT, 1, G_TYPE_APPLICATION_COMMAND_LINE);
955 g_type_class_add_private (class, sizeof (GApplicationPrivate));
959 get_platform_data (GApplication *application)
961 GVariantBuilder *builder;
964 builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
967 gchar *cwd = g_get_current_dir ();
968 g_variant_builder_add (builder, "{sv}", "cwd",
969 g_variant_new_bytestring (cwd));
973 if (application->priv->flags & G_APPLICATION_SEND_ENVIRONMENT)
978 envp = g_get_environ ();
979 array = g_variant_new_bytestring_array ((const gchar **) envp, -1);
982 g_variant_builder_add (builder, "{sv}", "environ", array);
985 G_APPLICATION_GET_CLASS (application)->
986 add_platform_data (application, builder);
988 result = g_variant_builder_end (builder);
989 g_variant_builder_unref (builder);
994 /* Application ID validity {{{1 */
997 * g_application_id_is_valid:
998 * @application_id: a potential application identifier
1000 * Checks if @application_id is a valid application identifier.
1002 * A valid ID is required for calls to g_application_new() and
1003 * g_application_set_application_id().
1005 * For convenience, the restrictions on application identifiers are
1008 * <listitem>Application identifiers must contain only the ASCII characters "[A-Z][a-z][0-9]_-." and must not begin with a digit.</listitem>
1009 * <listitem>Application identifiers must contain at least one '.' (period) character (and thus at least three elements).</listitem>
1010 * <listitem>Application identifiers must not begin or end with a '.' (period) character.</listitem>
1011 * <listitem>Application identifiers must not contain consecutive '.' (period) characters.</listitem>
1012 * <listitem>Application identifiers must not exceed 255 characters.</listitem>
1015 * Returns: %TRUE if @application_id is valid
1018 g_application_id_is_valid (const gchar *application_id)
1024 len = strlen (application_id);
1029 if (!g_ascii_isalpha (application_id[0]))
1032 if (application_id[len-1] == '.')
1038 for (; *application_id; application_id++)
1040 if (g_ascii_isalnum (*application_id) ||
1041 (*application_id == '-') ||
1042 (*application_id == '_'))
1046 else if (allow_dot && *application_id == '.')
1061 /* Public Constructor {{{1 */
1063 * g_application_new:
1064 * @application_id: the application id
1065 * @flags: the application flags
1067 * Creates a new #GApplication instance.
1069 * This function calls g_type_init() for you.
1071 * The application id must be valid. See g_application_id_is_valid().
1073 * Returns: a new #GApplication instance
1076 g_application_new (const gchar *application_id,
1077 GApplicationFlags flags)
1079 g_return_val_if_fail (g_application_id_is_valid (application_id), NULL);
1083 return g_object_new (G_TYPE_APPLICATION,
1084 "application-id", application_id,
1089 /* Simple get/set: application id, flags, inactivity timeout {{{1 */
1091 * g_application_get_application_id:
1092 * @application: a #GApplication
1094 * Gets the unique identifier for @application.
1096 * Returns: the identifier for @application, owned by @application
1101 g_application_get_application_id (GApplication *application)
1103 g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
1105 return application->priv->id;
1109 * g_application_set_application_id:
1110 * @application: a #GApplication
1111 * @application_id: the identifier for @application
1113 * Sets the unique identifier for @application.
1115 * The application id can only be modified if @application has not yet
1118 * The application id must be valid. See g_application_id_is_valid().
1123 g_application_set_application_id (GApplication *application,
1124 const gchar *application_id)
1126 g_return_if_fail (G_IS_APPLICATION (application));
1128 if (g_strcmp0 (application->priv->id, application_id) != 0)
1130 g_return_if_fail (g_application_id_is_valid (application_id));
1131 g_return_if_fail (!application->priv->is_registered);
1133 g_free (application->priv->id);
1134 application->priv->id = g_strdup (application_id);
1136 g_object_notify (G_OBJECT (application), "application-id");
1141 * g_application_get_flags:
1142 * @application: a #GApplication
1144 * Gets the flags for @application.
1146 * See #GApplicationFlags.
1148 * Returns: the flags for @application
1153 g_application_get_flags (GApplication *application)
1155 g_return_val_if_fail (G_IS_APPLICATION (application), 0);
1157 return application->priv->flags;
1161 * g_application_set_flags:
1162 * @application: a #GApplication
1163 * @flags: the flags for @application
1165 * Sets the flags for @application.
1167 * The flags can only be modified if @application has not yet been
1170 * See #GApplicationFlags.
1175 g_application_set_flags (GApplication *application,
1176 GApplicationFlags flags)
1178 g_return_if_fail (G_IS_APPLICATION (application));
1180 if (application->priv->flags != flags)
1182 g_return_if_fail (!application->priv->is_registered);
1184 application->priv->flags = flags;
1186 g_object_notify (G_OBJECT (application), "flags");
1191 * g_application_get_inactivity_timeout:
1192 * @application: a #GApplication
1194 * Gets the current inactivity timeout for the application.
1196 * This is the amount of time (in milliseconds) after the last call to
1197 * g_application_release() before the application stops running.
1199 * Returns: the timeout, in milliseconds
1204 g_application_get_inactivity_timeout (GApplication *application)
1206 g_return_val_if_fail (G_IS_APPLICATION (application), 0);
1208 return application->priv->inactivity_timeout;
1212 * g_application_set_inactivity_timeout:
1213 * @application: a #GApplication
1214 * @inactivity_timeout: the timeout, in milliseconds
1216 * Sets the current inactivity timeout for the application.
1218 * This is the amount of time (in milliseconds) after the last call to
1219 * g_application_release() before the application stops running.
1221 * This call has no side effects of its own. The value set here is only
1222 * used for next time g_application_release() drops the use count to
1223 * zero. Any timeouts currently in progress are not impacted.
1228 g_application_set_inactivity_timeout (GApplication *application,
1229 guint inactivity_timeout)
1231 g_return_if_fail (G_IS_APPLICATION (application));
1233 if (application->priv->inactivity_timeout != inactivity_timeout)
1235 application->priv->inactivity_timeout = inactivity_timeout;
1237 g_object_notify (G_OBJECT (application), "inactivity-timeout");
1240 /* Read-only property getters (is registered, is remote) {{{1 */
1242 * g_application_get_is_registered:
1243 * @application: a #GApplication
1245 * Checks if @application is registered.
1247 * An application is registered if g_application_register() has been
1248 * successfully called.
1250 * Returns: %TRUE if @application is registered
1255 g_application_get_is_registered (GApplication *application)
1257 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
1259 return application->priv->is_registered;
1263 * g_application_get_is_remote:
1264 * @application: a #GApplication
1266 * Checks if @application is remote.
1268 * If @application is remote then it means that another instance of
1269 * application already exists (the 'primary' instance). Calls to
1270 * perform actions on @application will result in the actions being
1271 * performed by the primary instance.
1273 * The value of this property cannot be accessed before
1274 * g_application_register() has been called. See
1275 * g_application_get_is_registered().
1277 * Returns: %TRUE if @application is remote
1282 g_application_get_is_remote (GApplication *application)
1284 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
1285 g_return_val_if_fail (application->priv->is_registered, FALSE);
1287 return application->priv->is_remote;
1292 * g_application_register:
1293 * @application: a #GApplication
1294 * @cancellable: a #GCancellable, or %NULL
1295 * @error: a pointer to a NULL #GError, or %NULL
1297 * Attempts registration of the application.
1299 * This is the point at which the application discovers if it is the
1300 * primary instance or merely acting as a remote for an already-existing
1301 * primary instance. This is implemented by attempting to acquire the
1302 * application identifier as a unique bus name on the session bus using
1305 * Due to the internal architecture of GDBus, method calls can be
1306 * dispatched at any time (even if a main loop is not running). For
1307 * this reason, you must ensure that any object paths that you wish to
1308 * register are registered before calling this function.
1310 * If the application has already been registered then %TRUE is
1311 * returned with no work performed.
1313 * The #GApplication::startup signal is emitted if registration succeeds
1314 * and @application is the primary instance.
1316 * In the event of an error (such as @cancellable being cancelled, or a
1317 * failure to connect to the session bus), %FALSE is returned and @error
1318 * is set appropriately.
1320 * Note: the return value of this function is not an indicator that this
1321 * instance is or is not the primary instance of the application. See
1322 * g_application_get_is_remote() for that.
1324 * Returns: %TRUE if registration succeeded
1329 g_application_register (GApplication *application,
1330 GCancellable *cancellable,
1333 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
1335 if (!application->priv->is_registered)
1337 if (~application->priv->flags & G_APPLICATION_NON_UNIQUE)
1339 application->priv->impl =
1340 g_application_impl_register (application, application->priv->id,
1341 application->priv->flags,
1342 application->priv->actions,
1343 &application->priv->remote_actions,
1344 cancellable, error);
1346 if (application->priv->impl == NULL)
1350 application->priv->is_remote = application->priv->remote_actions != NULL;
1351 application->priv->is_registered = TRUE;
1353 g_object_notify (G_OBJECT (application), "is-registered");
1355 if (!application->priv->is_remote)
1357 g_signal_emit (application, g_application_signals[SIGNAL_STARTUP], 0);
1359 if (!application->priv->did_startup)
1360 g_critical ("GApplication subclass '%s' failed to chain up on"
1361 " ::startup (from start of override function)",
1362 G_OBJECT_TYPE_NAME (application));
1369 /* Hold/release {{{1 */
1371 * g_application_hold:
1372 * @application: a #GApplication
1374 * Increases the use count of @application.
1376 * Use this function to indicate that the application has a reason to
1377 * continue to run. For example, g_application_hold() is called by GTK+
1378 * when a toplevel window is on the screen.
1380 * To cancel the hold, call g_application_release().
1383 g_application_hold (GApplication *application)
1385 if (application->priv->inactivity_timeout_id)
1387 g_source_remove (application->priv->inactivity_timeout_id);
1388 application->priv->inactivity_timeout_id = 0;
1391 application->priv->use_count++;
1395 inactivity_timeout_expired (gpointer data)
1397 GApplication *application = G_APPLICATION (data);
1399 application->priv->inactivity_timeout_id = 0;
1406 * g_application_release:
1407 * @application: a #GApplication
1409 * Decrease the use count of @application.
1411 * When the use count reaches zero, the application will stop running.
1413 * Never call this function except to cancel the effect of a previous
1414 * call to g_application_hold().
1417 g_application_release (GApplication *application)
1419 application->priv->use_count--;
1421 if (application->priv->use_count == 0 && application->priv->inactivity_timeout)
1422 application->priv->inactivity_timeout_id = g_timeout_add (application->priv->inactivity_timeout,
1423 inactivity_timeout_expired, application);
1426 /* Activate, Open {{{1 */
1428 * g_application_activate:
1429 * @application: a #GApplication
1431 * Activates the application.
1433 * In essence, this results in the #GApplication::activate() signal being
1434 * emitted in the primary instance.
1436 * The application must be registered before calling this function.
1441 g_application_activate (GApplication *application)
1443 g_return_if_fail (G_IS_APPLICATION (application));
1444 g_return_if_fail (application->priv->is_registered);
1446 if (application->priv->is_remote)
1447 g_application_impl_activate (application->priv->impl,
1448 get_platform_data (application));
1451 g_signal_emit (application, g_application_signals[SIGNAL_ACTIVATE], 0);
1455 * g_application_open:
1456 * @application: a #GApplication
1457 * @files: (array length=n_files): an array of #GFiles to open
1458 * @n_files: the length of the @files array
1459 * @hint: a hint (or ""), but never %NULL
1461 * Opens the given files.
1463 * In essence, this results in the #GApplication::open signal being emitted
1464 * in the primary instance.
1466 * @n_files must be greater than zero.
1468 * @hint is simply passed through to the ::open signal. It is
1469 * intended to be used by applications that have multiple modes for
1470 * opening files (eg: "view" vs "edit", etc). Unless you have a need
1471 * for this functionality, you should use "".
1473 * The application must be registered before calling this function
1474 * and it must have the %G_APPLICATION_HANDLES_OPEN flag set.
1479 g_application_open (GApplication *application,
1484 g_return_if_fail (G_IS_APPLICATION (application));
1485 g_return_if_fail (application->priv->flags &
1486 G_APPLICATION_HANDLES_OPEN);
1487 g_return_if_fail (application->priv->is_registered);
1489 if (application->priv->is_remote)
1490 g_application_impl_open (application->priv->impl,
1491 files, n_files, hint,
1492 get_platform_data (application));
1495 g_signal_emit (application, g_application_signals[SIGNAL_OPEN],
1496 0, files, n_files, hint);
1501 * g_application_run:
1502 * @application: a #GApplication
1503 * @argc: the argc from main() (or 0 if @argv is %NULL)
1504 * @argv: (array length=argc) (allow-none): the argv from main(), or %NULL
1506 * Runs the application.
1508 * This function is intended to be run from main() and its return value
1509 * is intended to be returned by main(). Although you are expected to pass
1510 * the @argc, @argv parameters from main() to this function, it is possible
1511 * to pass %NULL if @argv is not available or commandline handling is not
1514 * First, the local_command_line() virtual function is invoked.
1515 * This function always runs on the local instance. It gets passed a pointer
1516 * to a %NULL-terminated copy of @argv and is expected to remove the arguments
1517 * that it handled (shifting up remaining arguments). See
1518 * <xref linkend="gapplication-example-cmdline2"/> for an example of
1519 * parsing @argv manually. Alternatively, you may use the #GOptionContext API,
1520 * after setting <literal>argc = g_strv_length (argv);</literal>.
1522 * The last argument to local_command_line() is a pointer to the @status
1523 * variable which can used to set the exit status that is returned from
1524 * g_application_run().
1526 * If local_command_line() returns %TRUE, the command line is expected
1527 * to be completely handled, including possibly registering as the primary
1528 * instance, calling g_application_activate() or g_application_open(), etc.
1530 * If local_command_line() returns %FALSE then the application is registered
1531 * and the #GApplication::command-line signal is emitted in the primary
1532 * instance (which may or may not be this instance). The signal handler
1533 * gets passed a #GApplicationCommandline object that (among other things)
1534 * contains the remaining commandline arguments that have not been handled
1535 * by local_command_line().
1537 * If the application has the %G_APPLICATION_HANDLES_COMMAND_LINE
1538 * flag set then the default implementation of local_command_line()
1539 * always returns %FALSE immediately, resulting in the commandline
1540 * always being handled in the primary instance.
1542 * Otherwise, the default implementation of local_command_line() tries
1543 * to do a couple of things that are probably reasonable for most
1544 * applications. First, g_application_register() is called to attempt
1545 * to register the application. If that works, then the command line
1546 * arguments are inspected. If no commandline arguments are given, then
1547 * g_application_activate() is called. If commandline arguments are
1548 * given and the %G_APPLICATION_HANDLES_OPEN flag is set then they
1549 * are assumed to be filenames and g_application_open() is called.
1551 * If you need to handle commandline arguments that are not filenames,
1552 * and you don't mind commandline handling to happen in the primary
1553 * instance, you should set %G_APPLICATION_HANDLED_COMMAND_LINE and
1554 * process the commandline arguments in your #GApplication::command-line
1555 * signal handler, either manually or using the #GOptionContext API.
1557 * If you are interested in doing more complicated local handling of the
1558 * commandline then you should implement your own #GApplication subclass
1559 * and override local_command_line(). In this case, you most likely want
1560 * to return %TRUE from your local_command_line() implementation to
1561 * suppress the default handling. See
1562 * <xref linkend="gapplication-example-cmdline2"/> for an example.
1564 * If, after the above is done, the use count of the application is zero
1565 * then the exit status is returned immediately. If the use count is
1566 * non-zero then the default main context is iterated until the use count
1567 * falls to zero, at which point 0 is returned.
1569 * If the %G_APPLICATION_IS_SERVICE flag is set, then the exiting at
1570 * use count of zero is delayed for a while (ie: the instance stays
1571 * around to provide its <emphasis>service</emphasis> to others).
1573 * Returns: the exit status
1578 g_application_run (GApplication *application,
1586 g_return_val_if_fail (G_IS_APPLICATION (application), 1);
1587 g_return_val_if_fail (argc == 0 || argv != NULL, 1);
1589 arguments = g_new (gchar *, argc + 1);
1590 for (i = 0; i < argc; i++)
1591 arguments[i] = g_strdup (argv[i]);
1592 arguments[i] = NULL;
1594 if (g_get_prgname () == NULL && argc > 0)
1598 prgname = g_path_get_basename (argv[0]);
1599 g_set_prgname (prgname);
1603 if (!G_APPLICATION_GET_CLASS (application)
1604 ->local_command_line (application, &arguments, &status))
1606 GError *error = NULL;
1608 if (!g_application_register (application, NULL, &error))
1610 g_printerr ("%s", error->message);
1611 g_error_free (error);
1615 if (application->priv->is_remote)
1617 GVariant *platform_data;
1619 platform_data = get_platform_data (application);
1620 status = g_application_impl_command_line (application->priv->impl,
1621 arguments, platform_data);
1625 GApplicationCommandLine *cmdline;
1628 v = g_variant_new_bytestring_array ((const gchar **) arguments, -1);
1629 cmdline = g_object_new (G_TYPE_APPLICATION_COMMAND_LINE,
1630 "arguments", v, NULL);
1631 g_signal_emit (application,
1632 g_application_signals[SIGNAL_COMMAND_LINE],
1633 0, cmdline, &status);
1634 g_object_unref (cmdline);
1638 g_strfreev (arguments);
1640 if (application->priv->flags & G_APPLICATION_IS_SERVICE &&
1641 application->priv->is_registered &&
1642 !application->priv->use_count &&
1643 !application->priv->inactivity_timeout_id)
1645 application->priv->inactivity_timeout_id =
1646 g_timeout_add (10000, inactivity_timeout_expired, application);
1649 while (application->priv->use_count || application->priv->inactivity_timeout_id)
1651 g_main_context_iteration (NULL, TRUE);
1655 if (!application->priv->is_remote)
1657 g_signal_emit (application, g_application_signals[SIGNAL_SHUTDOWN], 0);
1659 if (!application->priv->did_shutdown)
1660 g_critical ("GApplication subclass '%s' failed to chain up on"
1661 " ::shutdown (from end of override function)",
1662 G_OBJECT_TYPE_NAME (application));
1665 if (application->priv->impl)
1666 g_application_impl_flush (application->priv->impl);
1674 g_application_list_actions (GActionGroup *action_group)
1676 GApplication *application = G_APPLICATION (action_group);
1678 g_return_val_if_fail (application->priv->is_registered, NULL);
1680 if (application->priv->remote_actions != NULL)
1681 return g_action_group_list_actions (G_ACTION_GROUP (application->priv->remote_actions));
1683 else if (application->priv->actions != NULL)
1684 return g_action_group_list_actions (application->priv->actions);
1687 /* empty string array */
1688 return g_new0 (gchar *, 1);
1692 g_application_query_action (GActionGroup *group,
1693 const gchar *action_name,
1695 const GVariantType **parameter_type,
1696 const GVariantType **state_type,
1697 GVariant **state_hint,
1700 GApplication *application = G_APPLICATION (group);
1702 g_return_val_if_fail (application->priv->is_registered, FALSE);
1704 if (application->priv->remote_actions != NULL)
1705 return g_action_group_query_action (G_ACTION_GROUP (application->priv->remote_actions),
1713 if (application->priv->actions != NULL)
1714 return g_action_group_query_action (application->priv->actions,
1726 g_application_change_action_state (GActionGroup *action_group,
1727 const gchar *action_name,
1730 GApplication *application = G_APPLICATION (action_group);
1732 g_return_if_fail (application->priv->is_remote ||
1733 application->priv->actions != NULL);
1734 g_return_if_fail (application->priv->is_registered);
1736 if (application->priv->remote_actions)
1737 g_remote_action_group_change_action_state_full (application->priv->remote_actions,
1738 action_name, value, get_platform_data (application));
1741 g_action_group_change_action_state (application->priv->actions, action_name, value);
1745 g_application_activate_action (GActionGroup *action_group,
1746 const gchar *action_name,
1747 GVariant *parameter)
1749 GApplication *application = G_APPLICATION (action_group);
1751 g_return_if_fail (application->priv->is_remote ||
1752 application->priv->actions != NULL);
1753 g_return_if_fail (application->priv->is_registered);
1755 if (application->priv->remote_actions)
1756 g_remote_action_group_activate_action_full (application->priv->remote_actions,
1757 action_name, parameter, get_platform_data (application));
1760 g_action_group_activate_action (application->priv->actions, action_name, parameter);
1764 g_application_lookup_action (GActionMap *action_map,
1765 const gchar *action_name)
1767 GApplication *application = G_APPLICATION (action_map);
1769 g_return_val_if_fail (G_IS_SIMPLE_ACTION_GROUP (application->priv->actions), NULL);
1771 return g_simple_action_group_lookup (G_SIMPLE_ACTION_GROUP (application->priv->actions), action_name);
1775 g_application_add_action (GActionMap *action_map,
1778 GApplication *application = G_APPLICATION (action_map);
1780 g_return_if_fail (G_IS_SIMPLE_ACTION_GROUP (application->priv->actions));
1782 g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (application->priv->actions), action);
1786 g_application_remove_action (GActionMap *action_map,
1787 const gchar *action_name)
1789 GApplication *application = G_APPLICATION (action_map);
1791 g_return_if_fail (G_IS_SIMPLE_ACTION_GROUP (application->priv->actions));
1793 g_simple_action_group_remove (G_SIMPLE_ACTION_GROUP (application->priv->actions), action_name);
1797 g_application_action_group_iface_init (GActionGroupInterface *iface)
1799 iface->list_actions = g_application_list_actions;
1800 iface->query_action = g_application_query_action;
1801 iface->change_action_state = g_application_change_action_state;
1802 iface->activate_action = g_application_activate_action;
1806 g_application_action_map_iface_init (GActionMapInterface *iface)
1808 iface->lookup_action = g_application_lookup_action;
1809 iface->add_action = g_application_add_action;
1810 iface->remove_action = g_application_remove_action;
1813 /* Default Application {{{1 */
1815 static GApplication *default_app;
1818 * g_application_get_default:
1819 * @returns: (transfer none): the default application for this process, or %NULL
1821 * Returns the default #GApplication instance for this process.
1823 * Normally there is only one #GApplication per process and it becomes
1824 * the default when it is created. You can exercise more control over
1825 * this by using g_application_set_default().
1827 * If there is no default application then %NULL is returned.
1832 g_application_get_default (void)
1838 * g_application_set_default:
1839 * @application: the application to set as default, or %NULL
1841 * Sets or unsets the default application for the process, as returned
1842 * by g_application_get_default().
1844 * This function does not take its own reference on @application. If
1845 * @application is destroyed then the default application will revert
1851 g_application_set_default (GApplication *application)
1853 default_app = application;
1857 /* vim:set foldmethod=marker: */