/src/glib/gio/gapplication.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * Copyright © 2010 Codethink Limited  | 
3  |  |  *  | 
4  |  |  * SPDX-License-Identifier: LGPL-2.1-or-later  | 
5  |  |  *  | 
6  |  |  * This library is free software; you can redistribute it and/or  | 
7  |  |  * modify it under the terms of the GNU Lesser General Public  | 
8  |  |  * License as published by the Free Software Foundation; either  | 
9  |  |  * version 2.1 of the License, or (at your option) any later version.  | 
10  |  |  *  | 
11  |  |  * This library is distributed in the hope that it will be useful,  | 
12  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
13  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  | 
14  |  |  * Lesser General Public License for more details.  | 
15  |  |  *  | 
16  |  |  * You should have received a copy of the GNU Lesser General  | 
17  |  |  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.  | 
18  |  |  *  | 
19  |  |  * Authors: Ryan Lortie <desrt@desrt.ca>  | 
20  |  |  */  | 
21  |  |  | 
22  |  | /* Prologue {{{1 */ | 
23  |  | #include "config.h"  | 
24  |  |  | 
25  |  | #include "gapplication.h"  | 
26  |  |  | 
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 "gsettings.h"  | 
34  |  | #include "gnotification-private.h"  | 
35  |  | #include "gnotificationbackend.h"  | 
36  |  | #include "gdbusutils.h"  | 
37  |  |  | 
38  |  | #include "gioenumtypes.h"  | 
39  |  | #include "gioenums.h"  | 
40  |  | #include "gfile.h"  | 
41  |  |  | 
42  |  | #include "glibintl.h"  | 
43  |  | #include "gmarshal-internal.h"  | 
44  |  |  | 
45  |  | #include <string.h>  | 
46  |  |  | 
47  |  | /**  | 
48  |  |  * SECTION:gapplication  | 
49  |  |  * @title: GApplication  | 
50  |  |  * @short_description: Core application class  | 
51  |  |  * @include: gio/gio.h  | 
52  |  |  *  | 
53  |  |  * A #GApplication is the foundation of an application.  It wraps some  | 
54  |  |  * low-level platform-specific services and is intended to act as the  | 
55  |  |  * foundation for higher-level application classes such as  | 
56  |  |  * #GtkApplication or #MxApplication.  In general, you should not use  | 
57  |  |  * this class outside of a higher level framework.  | 
58  |  |  *  | 
59  |  |  * GApplication provides convenient life cycle management by maintaining  | 
60  |  |  * a "use count" for the primary application instance. The use count can  | 
61  |  |  * be changed using g_application_hold() and g_application_release(). If  | 
62  |  |  * it drops to zero, the application exits. Higher-level classes such as  | 
63  |  |  * #GtkApplication employ the use count to ensure that the application  | 
64  |  |  * stays alive as long as it has any opened windows.  | 
65  |  |  *  | 
66  |  |  * Another feature that GApplication (optionally) provides is process  | 
67  |  |  * uniqueness. Applications can make use of this functionality by  | 
68  |  |  * providing a unique application ID. If given, only one application  | 
69  |  |  * with this ID can be running at a time per session. The session  | 
70  |  |  * concept is platform-dependent, but corresponds roughly to a graphical  | 
71  |  |  * desktop login. When your application is launched again, its  | 
72  |  |  * arguments are passed through platform communication to the already  | 
73  |  |  * running program. The already running instance of the program is  | 
74  |  |  * called the "primary instance"; for non-unique applications this is  | 
75  |  |  * always the current instance. On Linux, the D-Bus session bus  | 
76  |  |  * is used for communication.  | 
77  |  |  *  | 
78  |  |  * The use of #GApplication differs from some other commonly-used  | 
79  |  |  * uniqueness libraries (such as libunique) in important ways. The  | 
80  |  |  * application is not expected to manually register itself and check  | 
81  |  |  * if it is the primary instance. Instead, the main() function of a  | 
82  |  |  * #GApplication should do very little more than instantiating the  | 
83  |  |  * application instance, possibly connecting signal handlers, then  | 
84  |  |  * calling g_application_run(). All checks for uniqueness are done  | 
85  |  |  * internally. If the application is the primary instance then the  | 
86  |  |  * startup signal is emitted and the mainloop runs. If the application  | 
87  |  |  * is not the primary instance then a signal is sent to the primary  | 
88  |  |  * instance and g_application_run() promptly returns. See the code  | 
89  |  |  * examples below.  | 
90  |  |  *  | 
91  |  |  * If used, the expected form of an application identifier is the   | 
92  |  |  * same as that of a  | 
93  |  |  * [D-Bus well-known bus name](https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus).  | 
94  |  |  * Examples include: `com.example.MyApp`, `org.example.internal_apps.Calculator`,  | 
95  |  |  * `org._7_zip.Archiver`.  | 
96  |  |  * For details on valid application identifiers, see g_application_id_is_valid().  | 
97  |  |  *  | 
98  |  |  * On Linux, the application identifier is claimed as a well-known bus name  | 
99  |  |  * on the user's session bus.  This means that the uniqueness of your  | 
100  |  |  * application is scoped to the current session.  It also means that your  | 
101  |  |  * application may provide additional services (through registration of other  | 
102  |  |  * object paths) at that bus name.  The registration of these object paths  | 
103  |  |  * should be done with the shared GDBus session bus.  Note that due to the  | 
104  |  |  * internal architecture of GDBus, method calls can be dispatched at any time  | 
105  |  |  * (even if a main loop is not running).  For this reason, you must ensure that  | 
106  |  |  * any object paths that you wish to register are registered before #GApplication  | 
107  |  |  * attempts to acquire the bus name of your application (which happens in  | 
108  |  |  * g_application_register()).  Unfortunately, this means that you cannot use  | 
109  |  |  * g_application_get_is_remote() to decide if you want to register object paths.  | 
110  |  |  *  | 
111  |  |  * GApplication also implements the #GActionGroup and #GActionMap  | 
112  |  |  * interfaces and lets you easily export actions by adding them with  | 
113  |  |  * g_action_map_add_action(). When invoking an action by calling  | 
114  |  |  * g_action_group_activate_action() on the application, it is always  | 
115  |  |  * invoked in the primary instance. The actions are also exported on  | 
116  |  |  * the session bus, and GIO provides the #GDBusActionGroup wrapper to  | 
117  |  |  * conveniently access them remotely. GIO provides a #GDBusMenuModel wrapper  | 
118  |  |  * for remote access to exported #GMenuModels.  | 
119  |  |  *  | 
120  |  |  * Note: Due to the fact that actions are exported on the session bus,  | 
121  |  |  * using `maybe` parameters is not supported, since D-Bus does not support  | 
122  |  |  * `maybe` types.  | 
123  |  |  *  | 
124  |  |  * There is a number of different entry points into a GApplication:  | 
125  |  |  *  | 
126  |  |  * - via 'Activate' (i.e. just starting the application)  | 
127  |  |  *  | 
128  |  |  * - via 'Open' (i.e. opening some files)  | 
129  |  |  *  | 
130  |  |  * - by handling a command-line  | 
131  |  |  *  | 
132  |  |  * - via activating an action  | 
133  |  |  *  | 
134  |  |  * The #GApplication::startup signal lets you handle the application  | 
135  |  |  * initialization for all of these in a single place.  | 
136  |  |  *  | 
137  |  |  * Regardless of which of these entry points is used to start the  | 
138  |  |  * application, GApplication passes some ‘platform data’ from the  | 
139  |  |  * launching instance to the primary instance, in the form of a  | 
140  |  |  * #GVariant dictionary mapping strings to variants. To use platform  | 
141  |  |  * data, override the @before_emit or @after_emit virtual functions  | 
142  |  |  * in your #GApplication subclass. When dealing with  | 
143  |  |  * #GApplicationCommandLine objects, the platform data is  | 
144  |  |  * directly available via g_application_command_line_get_cwd(),  | 
145  |  |  * g_application_command_line_get_environ() and  | 
146  |  |  * g_application_command_line_get_platform_data().  | 
147  |  |  *  | 
148  |  |  * As the name indicates, the platform data may vary depending on the  | 
149  |  |  * operating system, but it always includes the current directory (key  | 
150  |  |  * "cwd"), and optionally the environment (ie the set of environment  | 
151  |  |  * variables and their values) of the calling process (key "environ").  | 
152  |  |  * The environment is only added to the platform data if the  | 
153  |  |  * %G_APPLICATION_SEND_ENVIRONMENT flag is set. #GApplication subclasses  | 
154  |  |  * can add their own platform data by overriding the @add_platform_data  | 
155  |  |  * virtual function. For instance, #GtkApplication adds startup notification  | 
156  |  |  * data in this way.  | 
157  |  |  *  | 
158  |  |  * To parse commandline arguments you may handle the  | 
159  |  |  * #GApplication::command-line signal or override the local_command_line()  | 
160  |  |  * vfunc, to parse them in either the primary instance or the local instance,  | 
161  |  |  * respectively.  | 
162  |  |  *  | 
163  |  |  * For an example of opening files with a GApplication, see  | 
164  |  |  * [gapplication-example-open.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-open.c).  | 
165  |  |  *  | 
166  |  |  * For an example of using actions with GApplication, see  | 
167  |  |  * [gapplication-example-actions.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-actions.c).  | 
168  |  |  *  | 
169  |  |  * For an example of using extra D-Bus hooks with GApplication, see  | 
170  |  |  * [gapplication-example-dbushooks.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-dbushooks.c).  | 
171  |  |  */  | 
172  |  |  | 
173  |  | /**  | 
174  |  |  * GApplication:  | 
175  |  |  *  | 
176  |  |  * #GApplication is an opaque data structure and can only be accessed  | 
177  |  |  * using the following functions.  | 
178  |  |  * Since: 2.28  | 
179  |  |  */  | 
180  |  |  | 
181  |  | /**  | 
182  |  |  * GApplicationClass:  | 
183  |  |  * @startup: invoked on the primary instance immediately after registration  | 
184  |  |  * @shutdown: invoked only on the registered primary instance immediately  | 
185  |  |  *      after the main loop terminates  | 
186  |  |  * @activate: invoked on the primary instance when an activation occurs  | 
187  |  |  * @open: invoked on the primary instance when there are files to open  | 
188  |  |  * @command_line: invoked on the primary instance when a command-line is  | 
189  |  |  *   not handled locally  | 
190  |  |  * @local_command_line: invoked (locally). The virtual function has the chance  | 
191  |  |  *     to inspect (and possibly replace) command line arguments. See  | 
192  |  |  *     g_application_run() for more information. Also see the  | 
193  |  |  *     #GApplication::handle-local-options signal, which is a simpler  | 
194  |  |  *     alternative to handling some commandline options locally  | 
195  |  |  * @before_emit: invoked on the primary instance before 'activate', 'open',  | 
196  |  |  *     'command-line' or any action invocation, gets the 'platform data' from  | 
197  |  |  *     the calling instance  | 
198  |  |  * @after_emit: invoked on the primary instance after 'activate', 'open',  | 
199  |  |  *     'command-line' or any action invocation, gets the 'platform data' from  | 
200  |  |  *     the calling instance  | 
201  |  |  * @add_platform_data: invoked (locally) to add 'platform data' to be sent to  | 
202  |  |  *     the primary instance when activating, opening or invoking actions  | 
203  |  |  * @quit_mainloop: Used to be invoked on the primary instance when the use  | 
204  |  |  *     count of the application drops to zero (and after any inactivity  | 
205  |  |  *     timeout, if requested). Not used anymore since 2.32  | 
206  |  |  * @run_mainloop: Used to be invoked on the primary instance from  | 
207  |  |  *     g_application_run() if the use-count is non-zero. Since 2.32,  | 
208  |  |  *     GApplication is iterating the main context directly and is not  | 
209  |  |  *     using @run_mainloop anymore  | 
210  |  |  * @dbus_register: invoked locally during registration, if the application is  | 
211  |  |  *     using its D-Bus backend. You can use this to export extra objects on the  | 
212  |  |  *     bus, that need to exist before the application tries to own the bus name.  | 
213  |  |  *     The function is passed the #GDBusConnection to to session bus, and the  | 
214  |  |  *     object path that #GApplication will use to export is D-Bus API.  | 
215  |  |  *     If this function returns %TRUE, registration will proceed; otherwise  | 
216  |  |  *     registration will abort. Since: 2.34  | 
217  |  |  * @dbus_unregister: invoked locally during unregistration, if the application  | 
218  |  |  *     is using its D-Bus backend. Use this to undo anything done by  | 
219  |  |  *     the @dbus_register vfunc. Since: 2.34  | 
220  |  |  * @handle_local_options: invoked locally after the parsing of the commandline  | 
221  |  |  *  options has occurred. Since: 2.40  | 
222  |  |  * @name_lost: invoked when another instance is taking over the name. Since: 2.60  | 
223  |  |  *  | 
224  |  |  * Virtual function table for #GApplication.  | 
225  |  |  *  | 
226  |  |  * Since: 2.28  | 
227  |  |  */  | 
228  |  |  | 
229  |  | struct _GApplicationPrivate  | 
230  |  | { | 
231  |  |   GApplicationFlags  flags;  | 
232  |  |   gchar             *id;  | 
233  |  |   gchar             *resource_path;  | 
234  |  |  | 
235  |  |   GActionGroup      *actions;  | 
236  |  |  | 
237  |  |   guint              inactivity_timeout_id;  | 
238  |  |   guint              inactivity_timeout;  | 
239  |  |   guint              use_count;  | 
240  |  |   guint              busy_count;  | 
241  |  |  | 
242  |  |   guint              is_registered : 1;  | 
243  |  |   guint              is_remote : 1;  | 
244  |  |   guint              did_startup : 1;  | 
245  |  |   guint              did_shutdown : 1;  | 
246  |  |   guint              must_quit_now : 1;  | 
247  |  |  | 
248  |  |   GRemoteActionGroup *remote_actions;  | 
249  |  |   GApplicationImpl   *impl;  | 
250  |  |  | 
251  |  |   GNotificationBackend *notifications;  | 
252  |  |  | 
253  |  |   /* GOptionContext support */  | 
254  |  |   GOptionGroup       *main_options;  | 
255  |  |   GSList             *option_groups;  | 
256  |  |   GHashTable         *packed_options;  | 
257  |  |   gboolean            options_parsed;  | 
258  |  |   gchar              *parameter_string;  | 
259  |  |   gchar              *summary;  | 
260  |  |   gchar              *description;  | 
261  |  |  | 
262  |  |   /* Allocated option strings, from g_application_add_main_option() */  | 
263  |  |   GSList             *option_strings;  | 
264  |  | };  | 
265  |  |  | 
266  |  | enum  | 
267  |  | { | 
268  |  |   PROP_NONE,  | 
269  |  |   PROP_APPLICATION_ID,  | 
270  |  |   PROP_FLAGS,  | 
271  |  |   PROP_RESOURCE_BASE_PATH,  | 
272  |  |   PROP_IS_REGISTERED,  | 
273  |  |   PROP_IS_REMOTE,  | 
274  |  |   PROP_INACTIVITY_TIMEOUT,  | 
275  |  |   PROP_ACTION_GROUP,  | 
276  |  |   PROP_IS_BUSY  | 
277  |  | };  | 
278  |  |  | 
279  |  | enum  | 
280  |  | { | 
281  |  |   SIGNAL_STARTUP,  | 
282  |  |   SIGNAL_SHUTDOWN,  | 
283  |  |   SIGNAL_ACTIVATE,  | 
284  |  |   SIGNAL_OPEN,  | 
285  |  |   SIGNAL_ACTION,  | 
286  |  |   SIGNAL_COMMAND_LINE,  | 
287  |  |   SIGNAL_HANDLE_LOCAL_OPTIONS,  | 
288  |  |   SIGNAL_NAME_LOST,  | 
289  |  |   NR_SIGNALS  | 
290  |  | };  | 
291  |  |  | 
292  |  | static guint g_application_signals[NR_SIGNALS];  | 
293  |  |  | 
294  |  | static void g_application_action_group_iface_init (GActionGroupInterface *);  | 
295  |  | static void g_application_action_map_iface_init (GActionMapInterface *);  | 
296  |  | G_DEFINE_TYPE_WITH_CODE (GApplication, g_application, G_TYPE_OBJECT,  | 
297  |  |  G_ADD_PRIVATE (GApplication)  | 
298  |  |  G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, g_application_action_group_iface_init)  | 
299  |  |  G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_MAP, g_application_action_map_iface_init))  | 
300  |  |  | 
301  |  | /* GApplicationExportedActions {{{1 */ | 
302  |  |  | 
303  |  | /* We create a subclass of GSimpleActionGroup that implements  | 
304  |  |  * GRemoteActionGroup and deals with the platform data using  | 
305  |  |  * GApplication's before/after_emit vfuncs.  This is the action group we  | 
306  |  |  * will be exporting.  | 
307  |  |  *  | 
308  |  |  * We could implement GRemoteActionGroup on GApplication directly, but  | 
309  |  |  * this would be potentially extremely confusing to have exposed as part  | 
310  |  |  * of the public API of GApplication.  We certainly don't want anyone in  | 
311  |  |  * the same process to be calling these APIs...  | 
312  |  |  */  | 
313  |  | typedef GSimpleActionGroupClass GApplicationExportedActionsClass;  | 
314  |  | typedef struct  | 
315  |  | { | 
316  |  |   GSimpleActionGroup parent_instance;  | 
317  |  |   GApplication *application;  | 
318  |  | } GApplicationExportedActions;  | 
319  |  |  | 
320  |  | static GType g_application_exported_actions_get_type   (void);  | 
321  |  | static void  g_application_exported_actions_iface_init (GRemoteActionGroupInterface *iface);  | 
322  |  | G_DEFINE_TYPE_WITH_CODE (GApplicationExportedActions, g_application_exported_actions, G_TYPE_SIMPLE_ACTION_GROUP,  | 
323  |  |                          G_IMPLEMENT_INTERFACE (G_TYPE_REMOTE_ACTION_GROUP, g_application_exported_actions_iface_init))  | 
324  |  |  | 
325  |  | static void  | 
326  |  | g_application_exported_actions_activate_action_full (GRemoteActionGroup *remote,  | 
327  |  |                                                      const gchar        *action_name,  | 
328  |  |                                                      GVariant           *parameter,  | 
329  |  |                                                      GVariant           *platform_data)  | 
330  | 0  | { | 
331  | 0  |   GApplicationExportedActions *exported = (GApplicationExportedActions *) remote;  | 
332  |  | 
  | 
333  | 0  |   G_APPLICATION_GET_CLASS (exported->application)  | 
334  | 0  |     ->before_emit (exported->application, platform_data);  | 
335  |  | 
  | 
336  | 0  |   g_action_group_activate_action (G_ACTION_GROUP (exported), action_name, parameter);  | 
337  |  | 
  | 
338  | 0  |   G_APPLICATION_GET_CLASS (exported->application)  | 
339  | 0  |     ->after_emit (exported->application, platform_data);  | 
340  | 0  | }  | 
341  |  |  | 
342  |  | static void  | 
343  |  | g_application_exported_actions_change_action_state_full (GRemoteActionGroup *remote,  | 
344  |  |                                                          const gchar        *action_name,  | 
345  |  |                                                          GVariant           *value,  | 
346  |  |                                                          GVariant           *platform_data)  | 
347  | 0  | { | 
348  | 0  |   GApplicationExportedActions *exported = (GApplicationExportedActions *) remote;  | 
349  |  | 
  | 
350  | 0  |   G_APPLICATION_GET_CLASS (exported->application)  | 
351  | 0  |     ->before_emit (exported->application, platform_data);  | 
352  |  | 
  | 
353  | 0  |   g_action_group_change_action_state (G_ACTION_GROUP (exported), action_name, value);  | 
354  |  | 
  | 
355  | 0  |   G_APPLICATION_GET_CLASS (exported->application)  | 
356  | 0  |     ->after_emit (exported->application, platform_data);  | 
357  | 0  | }  | 
358  |  |  | 
359  |  | static void  | 
360  |  | g_application_exported_actions_init (GApplicationExportedActions *actions)  | 
361  | 0  | { | 
362  | 0  | }  | 
363  |  |  | 
364  |  | static void  | 
365  |  | g_application_exported_actions_iface_init (GRemoteActionGroupInterface *iface)  | 
366  | 0  | { | 
367  | 0  |   iface->activate_action_full = g_application_exported_actions_activate_action_full;  | 
368  | 0  |   iface->change_action_state_full = g_application_exported_actions_change_action_state_full;  | 
369  | 0  | }  | 
370  |  |  | 
371  |  | static void  | 
372  |  | g_application_exported_actions_class_init (GApplicationExportedActionsClass *class)  | 
373  | 0  | { | 
374  | 0  | }  | 
375  |  |  | 
376  |  | static GActionGroup *  | 
377  |  | g_application_exported_actions_new (GApplication *application)  | 
378  | 0  | { | 
379  | 0  |   GApplicationExportedActions *actions;  | 
380  |  | 
  | 
381  | 0  |   actions = g_object_new (g_application_exported_actions_get_type (), NULL);  | 
382  | 0  |   actions->application = application;  | 
383  |  | 
  | 
384  | 0  |   return G_ACTION_GROUP (actions);  | 
385  | 0  | }  | 
386  |  |  | 
387  |  | /* Command line option handling {{{1 */ | 
388  |  |  | 
389  |  | static void  | 
390  |  | free_option_entry (gpointer data)  | 
391  | 0  | { | 
392  | 0  |   GOptionEntry *entry = data;  | 
393  |  | 
  | 
394  | 0  |   switch (entry->arg)  | 
395  | 0  |     { | 
396  | 0  |     case G_OPTION_ARG_STRING:  | 
397  | 0  |     case G_OPTION_ARG_FILENAME:  | 
398  | 0  |       g_free (*(gchar **) entry->arg_data);  | 
399  | 0  |       break;  | 
400  |  |  | 
401  | 0  |     case G_OPTION_ARG_STRING_ARRAY:  | 
402  | 0  |     case G_OPTION_ARG_FILENAME_ARRAY:  | 
403  | 0  |       g_strfreev (*(gchar ***) entry->arg_data);  | 
404  | 0  |       break;  | 
405  |  |  | 
406  | 0  |     default:  | 
407  |  |       /* most things require no free... */  | 
408  | 0  |       break;  | 
409  | 0  |     }  | 
410  |  |  | 
411  |  |   /* ...except for the space that we allocated for it ourselves */  | 
412  | 0  |   g_free (entry->arg_data);  | 
413  |  | 
  | 
414  | 0  |   g_slice_free (GOptionEntry, entry);  | 
415  | 0  | }  | 
416  |  |  | 
417  |  | static void  | 
418  |  | g_application_pack_option_entries (GApplication *application,  | 
419  |  |                                    GVariantDict *dict)  | 
420  | 0  | { | 
421  | 0  |   GHashTableIter iter;  | 
422  | 0  |   gpointer item;  | 
423  |  | 
  | 
424  | 0  |   g_hash_table_iter_init (&iter, application->priv->packed_options);  | 
425  | 0  |   while (g_hash_table_iter_next (&iter, NULL, &item))  | 
426  | 0  |     { | 
427  | 0  |       GOptionEntry *entry = item;  | 
428  | 0  |       GVariant *value = NULL;  | 
429  |  | 
  | 
430  | 0  |       switch (entry->arg)  | 
431  | 0  |         { | 
432  | 0  |         case G_OPTION_ARG_NONE:  | 
433  | 0  |           if (*(gboolean *) entry->arg_data != 2)  | 
434  | 0  |             value = g_variant_new_boolean (*(gboolean *) entry->arg_data);  | 
435  | 0  |           break;  | 
436  |  |  | 
437  | 0  |         case G_OPTION_ARG_STRING:  | 
438  | 0  |           if (*(gchar **) entry->arg_data)  | 
439  | 0  |             value = g_variant_new_string (*(gchar **) entry->arg_data);  | 
440  | 0  |           break;  | 
441  |  |  | 
442  | 0  |         case G_OPTION_ARG_INT:  | 
443  | 0  |           if (*(gint32 *) entry->arg_data)  | 
444  | 0  |             value = g_variant_new_int32 (*(gint32 *) entry->arg_data);  | 
445  | 0  |           break;  | 
446  |  |  | 
447  | 0  |         case G_OPTION_ARG_FILENAME:  | 
448  | 0  |           if (*(gchar **) entry->arg_data)  | 
449  | 0  |             value = g_variant_new_bytestring (*(gchar **) entry->arg_data);  | 
450  | 0  |           break;  | 
451  |  |  | 
452  | 0  |         case G_OPTION_ARG_STRING_ARRAY:  | 
453  | 0  |           if (*(gchar ***) entry->arg_data)  | 
454  | 0  |             value = g_variant_new_strv (*(const gchar ***) entry->arg_data, -1);  | 
455  | 0  |           break;  | 
456  |  |  | 
457  | 0  |         case G_OPTION_ARG_FILENAME_ARRAY:  | 
458  | 0  |           if (*(gchar ***) entry->arg_data)  | 
459  | 0  |             value = g_variant_new_bytestring_array (*(const gchar ***) entry->arg_data, -1);  | 
460  | 0  |           break;  | 
461  |  |  | 
462  | 0  |         case G_OPTION_ARG_DOUBLE:  | 
463  | 0  |           if (*(gdouble *) entry->arg_data)  | 
464  | 0  |             value = g_variant_new_double (*(gdouble *) entry->arg_data);  | 
465  | 0  |           break;  | 
466  |  |  | 
467  | 0  |         case G_OPTION_ARG_INT64:  | 
468  | 0  |           if (*(gint64 *) entry->arg_data)  | 
469  | 0  |             value = g_variant_new_int64 (*(gint64 *) entry->arg_data);  | 
470  | 0  |           break;  | 
471  |  |  | 
472  | 0  |         default:  | 
473  | 0  |           g_assert_not_reached ();  | 
474  | 0  |         }  | 
475  |  |  | 
476  | 0  |       if (value)  | 
477  | 0  |         g_variant_dict_insert_value (dict, entry->long_name, value);  | 
478  | 0  |     }  | 
479  | 0  | }  | 
480  |  |  | 
481  |  | static GVariantDict *  | 
482  |  | g_application_parse_command_line (GApplication   *application,  | 
483  |  |                                   gchar        ***arguments,  | 
484  |  |                                   GError        **error)  | 
485  | 0  | { | 
486  | 0  |   gboolean become_service = FALSE;  | 
487  | 0  |   gchar *app_id = NULL;  | 
488  | 0  |   gboolean replace = FALSE;  | 
489  | 0  |   GVariantDict *dict = NULL;  | 
490  | 0  |   GOptionContext *context;  | 
491  | 0  |   GOptionGroup *gapplication_group;  | 
492  |  |  | 
493  |  |   /* Due to the memory management of GOptionGroup we can only parse  | 
494  |  |    * options once.  That's because once you add a group to the  | 
495  |  |    * GOptionContext there is no way to get it back again.  This is fine:  | 
496  |  |    * local_command_line() should never get invoked more than once  | 
497  |  |    * anyway.  Add a sanity check just to be sure.  | 
498  |  |    */  | 
499  | 0  |   g_return_val_if_fail (!application->priv->options_parsed, NULL);  | 
500  |  |  | 
501  | 0  |   context = g_option_context_new (application->priv->parameter_string);  | 
502  | 0  |   g_option_context_set_summary (context, application->priv->summary);  | 
503  | 0  |   g_option_context_set_description (context, application->priv->description);  | 
504  |  | 
  | 
505  | 0  |   gapplication_group = g_option_group_new ("gapplication", | 
506  | 0  |                                            _("GApplication Options:"), _("Show GApplication options"), | 
507  | 0  |                                            NULL, NULL);  | 
508  | 0  |   g_option_group_set_translation_domain (gapplication_group, GETTEXT_PACKAGE);  | 
509  | 0  |   g_option_context_add_group (context, gapplication_group);  | 
510  |  |  | 
511  |  |   /* If the application has not registered local options and it has  | 
512  |  |    * G_APPLICATION_HANDLES_COMMAND_LINE then we have to assume that  | 
513  |  |    * their primary instance commandline handler may want to deal with  | 
514  |  |    * the arguments.  We must therefore ignore them.  | 
515  |  |    *  | 
516  |  |    * We must also ignore --help in this case since some applications  | 
517  |  |    * will try to handle this from the remote side.  See #737869.  | 
518  |  |    */  | 
519  | 0  |   if (application->priv->main_options == NULL && (application->priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE))  | 
520  | 0  |     { | 
521  | 0  |       g_option_context_set_ignore_unknown_options (context, TRUE);  | 
522  | 0  |       g_option_context_set_help_enabled (context, FALSE);  | 
523  | 0  |     }  | 
524  |  |  | 
525  |  |   /* Add the main option group, if it exists */  | 
526  | 0  |   if (application->priv->main_options)  | 
527  | 0  |     { | 
528  |  |       /* This consumes the main_options */  | 
529  | 0  |       g_option_context_set_main_group (context, application->priv->main_options);  | 
530  | 0  |       application->priv->main_options = NULL;  | 
531  | 0  |     }  | 
532  |  |  | 
533  |  |   /* Add any other option groups if they exist.  Adding them to the  | 
534  |  |    * context will consume them, so we free the list as we go...  | 
535  |  |    */  | 
536  | 0  |   while (application->priv->option_groups)  | 
537  | 0  |     { | 
538  | 0  |       g_option_context_add_group (context, application->priv->option_groups->data);  | 
539  | 0  |       application->priv->option_groups = g_slist_delete_link (application->priv->option_groups,  | 
540  | 0  |                                                               application->priv->option_groups);  | 
541  | 0  |     }  | 
542  |  |  | 
543  |  |   /* In the case that we are not explicitly marked as a service or a  | 
544  |  |    * launcher then we want to add the "--gapplication-service" option to  | 
545  |  |    * allow the process to be made into a service.  | 
546  |  |    */  | 
547  | 0  |   if ((application->priv->flags & (G_APPLICATION_IS_SERVICE | G_APPLICATION_IS_LAUNCHER)) == 0)  | 
548  | 0  |     { | 
549  | 0  |       GOptionEntry entries[] = { | 
550  | 0  |         { "gapplication-service", '\0', 0, G_OPTION_ARG_NONE, &become_service, | 
551  | 0  |           N_("Enter GApplication service mode (use from D-Bus service files)"), NULL }, | 
552  | 0  |         G_OPTION_ENTRY_NULL  | 
553  | 0  |       };  | 
554  |  | 
  | 
555  | 0  |       g_option_group_add_entries (gapplication_group, entries);  | 
556  | 0  |     }  | 
557  |  |  | 
558  |  |   /* Allow overriding the ID if the application allows it */  | 
559  | 0  |   if (application->priv->flags & G_APPLICATION_CAN_OVERRIDE_APP_ID)  | 
560  | 0  |     { | 
561  | 0  |       GOptionEntry entries[] = { | 
562  | 0  |         { "gapplication-app-id", '\0', 0, G_OPTION_ARG_STRING, &app_id, | 
563  | 0  |           N_("Override the application’s ID"), NULL }, | 
564  | 0  |         G_OPTION_ENTRY_NULL  | 
565  | 0  |       };  | 
566  |  | 
  | 
567  | 0  |       g_option_group_add_entries (gapplication_group, entries);  | 
568  | 0  |     }  | 
569  |  |  | 
570  |  |   /* Allow replacing if the application allows it */  | 
571  | 0  |   if (application->priv->flags & G_APPLICATION_ALLOW_REPLACEMENT)  | 
572  | 0  |     { | 
573  | 0  |       GOptionEntry entries[] = { | 
574  | 0  |         { "gapplication-replace", '\0', 0, G_OPTION_ARG_NONE, &replace, | 
575  | 0  |           N_("Replace the running instance"), NULL }, | 
576  | 0  |         G_OPTION_ENTRY_NULL  | 
577  | 0  |       };  | 
578  |  | 
  | 
579  | 0  |       g_option_group_add_entries (gapplication_group, entries);  | 
580  | 0  |     }  | 
581  |  |  | 
582  |  |   /* Now we parse... */  | 
583  | 0  |   if (!g_option_context_parse_strv (context, arguments, error))  | 
584  | 0  |     goto out;  | 
585  |  |  | 
586  |  |   /* Check for --gapplication-service */  | 
587  | 0  |   if (become_service)  | 
588  | 0  |     application->priv->flags |= G_APPLICATION_IS_SERVICE;  | 
589  |  |  | 
590  |  |   /* Check for --gapplication-app-id */  | 
591  | 0  |   if (app_id)  | 
592  | 0  |     g_application_set_application_id (application, app_id);  | 
593  |  |  | 
594  |  |   /* Check for --gapplication-replace */  | 
595  | 0  |   if (replace)  | 
596  | 0  |     application->priv->flags |= G_APPLICATION_REPLACE;  | 
597  |  | 
  | 
598  | 0  |   dict = g_variant_dict_new (NULL);  | 
599  | 0  |   if (application->priv->packed_options)  | 
600  | 0  |     { | 
601  | 0  |       g_application_pack_option_entries (application, dict);  | 
602  | 0  |       g_hash_table_unref (application->priv->packed_options);  | 
603  | 0  |       application->priv->packed_options = NULL;  | 
604  | 0  |     }  | 
605  |  | 
  | 
606  | 0  | out:  | 
607  |  |   /* Make sure we don't run again */  | 
608  | 0  |   application->priv->options_parsed = TRUE;  | 
609  |  | 
  | 
610  | 0  |   g_option_context_free (context);  | 
611  | 0  |   g_free (app_id);  | 
612  |  | 
  | 
613  | 0  |   return dict;  | 
614  | 0  | }  | 
615  |  |  | 
616  |  | static void  | 
617  |  | add_packed_option (GApplication *application,  | 
618  |  |                    GOptionEntry *entry)  | 
619  | 0  | { | 
620  | 0  |   switch (entry->arg)  | 
621  | 0  |     { | 
622  | 0  |     case G_OPTION_ARG_NONE:  | 
623  | 0  |       entry->arg_data = g_new (gboolean, 1);  | 
624  | 0  |       *(gboolean *) entry->arg_data = 2;  | 
625  | 0  |       break;  | 
626  |  |  | 
627  | 0  |     case G_OPTION_ARG_INT:  | 
628  | 0  |       entry->arg_data = g_new0 (gint, 1);  | 
629  | 0  |       break;  | 
630  |  |  | 
631  | 0  |     case G_OPTION_ARG_STRING:  | 
632  | 0  |     case G_OPTION_ARG_FILENAME:  | 
633  | 0  |     case G_OPTION_ARG_STRING_ARRAY:  | 
634  | 0  |     case G_OPTION_ARG_FILENAME_ARRAY:  | 
635  | 0  |       entry->arg_data = g_new0 (gpointer, 1);  | 
636  | 0  |       break;  | 
637  |  |  | 
638  | 0  |     case G_OPTION_ARG_INT64:  | 
639  | 0  |       entry->arg_data = g_new0 (gint64, 1);  | 
640  | 0  |       break;  | 
641  |  |  | 
642  | 0  |     case G_OPTION_ARG_DOUBLE:  | 
643  | 0  |       entry->arg_data = g_new0 (gdouble, 1);  | 
644  | 0  |       break;  | 
645  |  |  | 
646  | 0  |     default:  | 
647  | 0  |       g_return_if_reached ();  | 
648  | 0  |     }  | 
649  |  |  | 
650  | 0  |   if (!application->priv->packed_options)  | 
651  | 0  |     application->priv->packed_options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_option_entry);  | 
652  |  | 
  | 
653  | 0  |   g_hash_table_insert (application->priv->packed_options,  | 
654  | 0  |                        g_strdup (entry->long_name),  | 
655  | 0  |                        g_slice_dup (GOptionEntry, entry));  | 
656  | 0  | }  | 
657  |  |  | 
658  |  | /**  | 
659  |  |  * g_application_add_main_option_entries:  | 
660  |  |  * @application: a #GApplication  | 
661  |  |  * @entries: (array zero-terminated=1) (element-type GOptionEntry) a  | 
662  |  |  *           %NULL-terminated list of #GOptionEntrys  | 
663  |  |  *  | 
664  |  |  * Adds main option entries to be handled by @application.  | 
665  |  |  *  | 
666  |  |  * This function is comparable to g_option_context_add_main_entries().  | 
667  |  |  *  | 
668  |  |  * After the commandline arguments are parsed, the  | 
669  |  |  * #GApplication::handle-local-options signal will be emitted.  At this  | 
670  |  |  * point, the application can inspect the values pointed to by @arg_data  | 
671  |  |  * in the given #GOptionEntrys.  | 
672  |  |  *  | 
673  |  |  * Unlike #GOptionContext, #GApplication supports giving a %NULL  | 
674  |  |  * @arg_data for a non-callback #GOptionEntry.  This results in the  | 
675  |  |  * argument in question being packed into a #GVariantDict which is also  | 
676  |  |  * passed to #GApplication::handle-local-options, where it can be  | 
677  |  |  * inspected and modified.  If %G_APPLICATION_HANDLES_COMMAND_LINE is  | 
678  |  |  * set, then the resulting dictionary is sent to the primary instance,  | 
679  |  |  * where g_application_command_line_get_options_dict() will return it.  | 
680  |  |  * As it has been passed outside the process at this point, the types of all  | 
681  |  |  * values in the options dict must be checked before being used.  | 
682  |  |  * This "packing" is done according to the type of the argument --  | 
683  |  |  * booleans for normal flags, strings for strings, bytestrings for  | 
684  |  |  * filenames, etc.  The packing only occurs if the flag is given (ie: we  | 
685  |  |  * do not pack a "false" #GVariant in the case that a flag is missing).  | 
686  |  |  *  | 
687  |  |  * In general, it is recommended that all commandline arguments are  | 
688  |  |  * parsed locally.  The options dictionary should then be used to  | 
689  |  |  * transmit the result of the parsing to the primary instance, where  | 
690  |  |  * g_variant_dict_lookup() can be used.  For local options, it is  | 
691  |  |  * possible to either use @arg_data in the usual way, or to consult (and  | 
692  |  |  * potentially remove) the option from the options dictionary.  | 
693  |  |  *  | 
694  |  |  * This function is new in GLib 2.40.  Before then, the only real choice  | 
695  |  |  * was to send all of the commandline arguments (options and all) to the  | 
696  |  |  * primary instance for handling.  #GApplication ignored them completely  | 
697  |  |  * on the local side.  Calling this function "opts in" to the new  | 
698  |  |  * behaviour, and in particular, means that unrecognised options will be  | 
699  |  |  * treated as errors.  Unrecognised options have never been ignored when  | 
700  |  |  * %G_APPLICATION_HANDLES_COMMAND_LINE is unset.  | 
701  |  |  *  | 
702  |  |  * If #GApplication::handle-local-options needs to see the list of  | 
703  |  |  * filenames, then the use of %G_OPTION_REMAINING is recommended.  If  | 
704  |  |  * @arg_data is %NULL then %G_OPTION_REMAINING can be used as a key into  | 
705  |  |  * the options dictionary.  If you do use %G_OPTION_REMAINING then you  | 
706  |  |  * need to handle these arguments for yourself because once they are  | 
707  |  |  * consumed, they will no longer be visible to the default handling  | 
708  |  |  * (which treats them as filenames to be opened).  | 
709  |  |  *  | 
710  |  |  * It is important to use the proper GVariant format when retrieving  | 
711  |  |  * the options with g_variant_dict_lookup():  | 
712  |  |  * - for %G_OPTION_ARG_NONE, use `b`  | 
713  |  |  * - for %G_OPTION_ARG_STRING, use `&s`  | 
714  |  |  * - for %G_OPTION_ARG_INT, use `i`  | 
715  |  |  * - for %G_OPTION_ARG_INT64, use `x`  | 
716  |  |  * - for %G_OPTION_ARG_DOUBLE, use `d`  | 
717  |  |  * - for %G_OPTION_ARG_FILENAME, use `^&ay`  | 
718  |  |  * - for %G_OPTION_ARG_STRING_ARRAY, use `^a&s`  | 
719  |  |  * - for %G_OPTION_ARG_FILENAME_ARRAY, use `^a&ay`  | 
720  |  |  *  | 
721  |  |  * Since: 2.40  | 
722  |  |  */  | 
723  |  | void  | 
724  |  | g_application_add_main_option_entries (GApplication       *application,  | 
725  |  |                                        const GOptionEntry *entries)  | 
726  | 0  | { | 
727  | 0  |   gint i;  | 
728  |  | 
  | 
729  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
730  | 0  |   g_return_if_fail (entries != NULL);  | 
731  |  |  | 
732  | 0  |   if (!application->priv->main_options)  | 
733  | 0  |     { | 
734  | 0  |       application->priv->main_options = g_option_group_new (NULL, NULL, NULL, NULL, NULL);  | 
735  | 0  |       g_option_group_set_translation_domain (application->priv->main_options, NULL);  | 
736  | 0  |     }  | 
737  |  | 
  | 
738  | 0  |   for (i = 0; entries[i].long_name; i++)  | 
739  | 0  |     { | 
740  | 0  |       GOptionEntry my_entries[2] =  | 
741  | 0  |         { | 
742  | 0  |           G_OPTION_ENTRY_NULL,  | 
743  | 0  |           G_OPTION_ENTRY_NULL  | 
744  | 0  |         };  | 
745  | 0  |       my_entries[0] = entries[i];  | 
746  |  | 
  | 
747  | 0  |       if (!my_entries[0].arg_data)  | 
748  | 0  |         add_packed_option (application, &my_entries[0]);  | 
749  |  | 
  | 
750  | 0  |       g_option_group_add_entries (application->priv->main_options, my_entries);  | 
751  | 0  |     }  | 
752  | 0  | }  | 
753  |  |  | 
754  |  | /**  | 
755  |  |  * g_application_add_main_option:  | 
756  |  |  * @application: the #GApplication  | 
757  |  |  * @long_name: the long name of an option used to specify it in a commandline  | 
758  |  |  * @short_name: the short name of an option  | 
759  |  |  * @flags: flags from #GOptionFlags  | 
760  |  |  * @arg: the type of the option, as a #GOptionArg  | 
761  |  |  * @description: the description for the option in `--help` output  | 
762  |  |  * @arg_description: (nullable): the placeholder to use for the extra argument  | 
763  |  |  *    parsed by the option in `--help` output  | 
764  |  |  *  | 
765  |  |  * Add an option to be handled by @application.  | 
766  |  |  *  | 
767  |  |  * Calling this function is the equivalent of calling  | 
768  |  |  * g_application_add_main_option_entries() with a single #GOptionEntry  | 
769  |  |  * that has its arg_data member set to %NULL.  | 
770  |  |  *  | 
771  |  |  * The parsed arguments will be packed into a #GVariantDict which  | 
772  |  |  * is passed to #GApplication::handle-local-options. If  | 
773  |  |  * %G_APPLICATION_HANDLES_COMMAND_LINE is set, then it will also  | 
774  |  |  * be sent to the primary instance. See  | 
775  |  |  * g_application_add_main_option_entries() for more details.  | 
776  |  |  *  | 
777  |  |  * See #GOptionEntry for more documentation of the arguments.  | 
778  |  |  *  | 
779  |  |  * Since: 2.42  | 
780  |  |  **/  | 
781  |  | void  | 
782  |  | g_application_add_main_option (GApplication *application,  | 
783  |  |                                const char   *long_name,  | 
784  |  |                                char          short_name,  | 
785  |  |                                GOptionFlags  flags,  | 
786  |  |                                GOptionArg    arg,  | 
787  |  |                                const char   *description,  | 
788  |  |                                const char   *arg_description)  | 
789  | 0  | { | 
790  | 0  |   gchar *dup_string;  | 
791  | 0  |   GOptionEntry my_entry[2] = { | 
792  | 0  |     { NULL, short_name, flags, arg, NULL, NULL, NULL }, | 
793  | 0  |     G_OPTION_ENTRY_NULL  | 
794  | 0  |   };  | 
795  |  | 
  | 
796  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
797  | 0  |   g_return_if_fail (long_name != NULL);  | 
798  | 0  |   g_return_if_fail (description != NULL);  | 
799  |  |  | 
800  | 0  |   my_entry[0].long_name = dup_string = g_strdup (long_name);  | 
801  | 0  |   application->priv->option_strings = g_slist_prepend (application->priv->option_strings, dup_string);  | 
802  |  | 
  | 
803  | 0  |   my_entry[0].description = dup_string = g_strdup (description);  | 
804  | 0  |   application->priv->option_strings = g_slist_prepend (application->priv->option_strings, dup_string);  | 
805  |  | 
  | 
806  | 0  |   my_entry[0].arg_description = dup_string = g_strdup (arg_description);  | 
807  | 0  |   application->priv->option_strings = g_slist_prepend (application->priv->option_strings, dup_string);  | 
808  |  | 
  | 
809  | 0  |   g_application_add_main_option_entries (application, my_entry);  | 
810  | 0  | }  | 
811  |  |  | 
812  |  | /**  | 
813  |  |  * g_application_add_option_group:  | 
814  |  |  * @application: the #GApplication  | 
815  |  |  * @group: (transfer full): a #GOptionGroup  | 
816  |  |  *  | 
817  |  |  * Adds a #GOptionGroup to the commandline handling of @application.  | 
818  |  |  *  | 
819  |  |  * This function is comparable to g_option_context_add_group().  | 
820  |  |  *  | 
821  |  |  * Unlike g_application_add_main_option_entries(), this function does  | 
822  |  |  * not deal with %NULL @arg_data and never transmits options to the  | 
823  |  |  * primary instance.  | 
824  |  |  *  | 
825  |  |  * The reason for that is because, by the time the options arrive at the  | 
826  |  |  * primary instance, it is typically too late to do anything with them.  | 
827  |  |  * Taking the GTK option group as an example: GTK will already have been  | 
828  |  |  * initialised by the time the #GApplication::command-line handler runs.  | 
829  |  |  * In the case that this is not the first-running instance of the  | 
830  |  |  * application, the existing instance may already have been running for  | 
831  |  |  * a very long time.  | 
832  |  |  *  | 
833  |  |  * This means that the options from #GOptionGroup are only really usable  | 
834  |  |  * in the case that the instance of the application being run is the  | 
835  |  |  * first instance.  Passing options like `--display=` or `--gdk-debug=`  | 
836  |  |  * on future runs will have no effect on the existing primary instance.  | 
837  |  |  *  | 
838  |  |  * Calling this function will cause the options in the supplied option  | 
839  |  |  * group to be parsed, but it does not cause you to be "opted in" to the  | 
840  |  |  * new functionality whereby unrecognised options are rejected even if  | 
841  |  |  * %G_APPLICATION_HANDLES_COMMAND_LINE was given.  | 
842  |  |  *  | 
843  |  |  * Since: 2.40  | 
844  |  |  **/  | 
845  |  | void  | 
846  |  | g_application_add_option_group (GApplication *application,  | 
847  |  |                                 GOptionGroup *group)  | 
848  | 0  | { | 
849  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
850  | 0  |   g_return_if_fail (group != NULL);  | 
851  |  |  | 
852  | 0  |   application->priv->option_groups = g_slist_prepend (application->priv->option_groups, group);  | 
853  | 0  | }  | 
854  |  |  | 
855  |  | /**  | 
856  |  |  * g_application_set_option_context_parameter_string:  | 
857  |  |  * @application: the #GApplication  | 
858  |  |  * @parameter_string: (nullable): a string which is displayed  | 
859  |  |  *   in the first line of `--help` output, after the usage summary `programname [OPTION...]`.  | 
860  |  |  *  | 
861  |  |  * Sets the parameter string to be used by the commandline handling of @application.  | 
862  |  |  *  | 
863  |  |  * This function registers the argument to be passed to g_option_context_new()  | 
864  |  |  * when the internal #GOptionContext of @application is created.  | 
865  |  |  *  | 
866  |  |  * See g_option_context_new() for more information about @parameter_string.  | 
867  |  |  *  | 
868  |  |  * Since: 2.56  | 
869  |  |  */  | 
870  |  | void  | 
871  |  | g_application_set_option_context_parameter_string (GApplication *application,  | 
872  |  |                                                    const gchar  *parameter_string)  | 
873  | 0  | { | 
874  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
875  |  |  | 
876  | 0  |   g_free (application->priv->parameter_string);  | 
877  | 0  |   application->priv->parameter_string = g_strdup (parameter_string);  | 
878  | 0  | }  | 
879  |  |  | 
880  |  | /**  | 
881  |  |  * g_application_set_option_context_summary:  | 
882  |  |  * @application: the #GApplication  | 
883  |  |  * @summary: (nullable): a string to be shown in `--help` output  | 
884  |  |  *  before the list of options, or %NULL  | 
885  |  |  *  | 
886  |  |  * Adds a summary to the @application option context.  | 
887  |  |  *  | 
888  |  |  * See g_option_context_set_summary() for more information.  | 
889  |  |  *  | 
890  |  |  * Since: 2.56  | 
891  |  |  */  | 
892  |  | void  | 
893  |  | g_application_set_option_context_summary (GApplication *application,  | 
894  |  |                                           const gchar  *summary)  | 
895  | 0  | { | 
896  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
897  |  |  | 
898  | 0  |   g_free (application->priv->summary);  | 
899  | 0  |   application->priv->summary = g_strdup (summary);  | 
900  | 0  | }  | 
901  |  |  | 
902  |  | /**  | 
903  |  |  * g_application_set_option_context_description:  | 
904  |  |  * @application: the #GApplication  | 
905  |  |  * @description: (nullable): a string to be shown in `--help` output  | 
906  |  |  *  after the list of options, or %NULL  | 
907  |  |  *  | 
908  |  |  * Adds a description to the @application option context.  | 
909  |  |  *  | 
910  |  |  * See g_option_context_set_description() for more information.  | 
911  |  |  *  | 
912  |  |  * Since: 2.56  | 
913  |  |  */  | 
914  |  | void  | 
915  |  | g_application_set_option_context_description (GApplication *application,  | 
916  |  |                                               const gchar  *description)  | 
917  | 0  | { | 
918  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
919  |  |  | 
920  | 0  |   g_free (application->priv->description);  | 
921  | 0  |   application->priv->description = g_strdup (description);  | 
922  |  | 
  | 
923  | 0  | }  | 
924  |  |  | 
925  |  |  | 
926  |  | /* vfunc defaults {{{1 */ | 
927  |  | static void  | 
928  |  | g_application_real_before_emit (GApplication *application,  | 
929  |  |                                 GVariant     *platform_data)  | 
930  | 0  | { | 
931  | 0  | }  | 
932  |  |  | 
933  |  | static void  | 
934  |  | g_application_real_after_emit (GApplication *application,  | 
935  |  |                                GVariant     *platform_data)  | 
936  | 0  | { | 
937  | 0  | }  | 
938  |  |  | 
939  |  | static void  | 
940  |  | g_application_real_startup (GApplication *application)  | 
941  | 0  | { | 
942  | 0  |   application->priv->did_startup = TRUE;  | 
943  | 0  | }  | 
944  |  |  | 
945  |  | static void  | 
946  |  | g_application_real_shutdown (GApplication *application)  | 
947  | 0  | { | 
948  | 0  |   application->priv->did_shutdown = TRUE;  | 
949  | 0  | }  | 
950  |  |  | 
951  |  | static void  | 
952  |  | g_application_real_activate (GApplication *application)  | 
953  | 0  | { | 
954  | 0  |   if (!g_signal_has_handler_pending (application,  | 
955  | 0  |                                      g_application_signals[SIGNAL_ACTIVATE],  | 
956  | 0  |                                      0, TRUE) &&  | 
957  | 0  |       G_APPLICATION_GET_CLASS (application)->activate == g_application_real_activate)  | 
958  | 0  |     { | 
959  | 0  |       static gboolean warned;  | 
960  |  | 
  | 
961  | 0  |       if (warned)  | 
962  | 0  |         return;  | 
963  |  |  | 
964  | 0  |       g_warning ("Your application does not implement " | 
965  | 0  |                  "g_application_activate() and has no handlers connected "  | 
966  | 0  |                  "to the 'activate' signal.  It should do one of these.");  | 
967  | 0  |       warned = TRUE;  | 
968  | 0  |     }  | 
969  | 0  | }  | 
970  |  |  | 
971  |  | static void  | 
972  |  | g_application_real_open (GApplication  *application,  | 
973  |  |                          GFile        **files,  | 
974  |  |                          gint           n_files,  | 
975  |  |                          const gchar   *hint)  | 
976  | 0  | { | 
977  | 0  |   if (!g_signal_has_handler_pending (application,  | 
978  | 0  |                                      g_application_signals[SIGNAL_OPEN],  | 
979  | 0  |                                      0, TRUE) &&  | 
980  | 0  |       G_APPLICATION_GET_CLASS (application)->open == g_application_real_open)  | 
981  | 0  |     { | 
982  | 0  |       static gboolean warned;  | 
983  |  | 
  | 
984  | 0  |       if (warned)  | 
985  | 0  |         return;  | 
986  |  |  | 
987  | 0  |       g_warning ("Your application claims to support opening files " | 
988  | 0  |                  "but does not implement g_application_open() and has no "  | 
989  | 0  |                  "handlers connected to the 'open' signal.");  | 
990  | 0  |       warned = TRUE;  | 
991  | 0  |     }  | 
992  | 0  | }  | 
993  |  |  | 
994  |  | static int  | 
995  |  | g_application_real_command_line (GApplication            *application,  | 
996  |  |                                  GApplicationCommandLine *cmdline)  | 
997  | 0  | { | 
998  | 0  |   if (!g_signal_has_handler_pending (application,  | 
999  | 0  |                                      g_application_signals[SIGNAL_COMMAND_LINE],  | 
1000  | 0  |                                      0, TRUE) &&  | 
1001  | 0  |       G_APPLICATION_GET_CLASS (application)->command_line == g_application_real_command_line)  | 
1002  | 0  |     { | 
1003  | 0  |       static gboolean warned;  | 
1004  |  | 
  | 
1005  | 0  |       if (warned)  | 
1006  | 0  |         return 1;  | 
1007  |  |  | 
1008  | 0  |       g_warning ("Your application claims to support custom command line " | 
1009  | 0  |                  "handling but does not implement g_application_command_line() "  | 
1010  | 0  |                  "and has no handlers connected to the 'command-line' signal.");  | 
1011  |  | 
  | 
1012  | 0  |       warned = TRUE;  | 
1013  | 0  |     }  | 
1014  |  |  | 
1015  | 0  |     return 1;  | 
1016  | 0  | }  | 
1017  |  |  | 
1018  |  | static gint  | 
1019  |  | g_application_real_handle_local_options (GApplication *application,  | 
1020  |  |                                          GVariantDict *options)  | 
1021  | 0  | { | 
1022  | 0  |   return -1;  | 
1023  | 0  | }  | 
1024  |  |  | 
1025  |  | static GVariant *  | 
1026  |  | get_platform_data (GApplication *application,  | 
1027  |  |                    GVariant     *options)  | 
1028  | 0  | { | 
1029  | 0  |   GVariantBuilder *builder;  | 
1030  | 0  |   GVariant *result;  | 
1031  |  | 
  | 
1032  | 0  |   builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); | 
1033  |  | 
  | 
1034  | 0  |   { | 
1035  | 0  |     gchar *cwd = g_get_current_dir ();  | 
1036  | 0  |     g_variant_builder_add (builder, "{sv}", "cwd", | 
1037  | 0  |                            g_variant_new_bytestring (cwd));  | 
1038  | 0  |     g_free (cwd);  | 
1039  | 0  |   }  | 
1040  |  | 
  | 
1041  | 0  |   if (application->priv->flags & G_APPLICATION_SEND_ENVIRONMENT)  | 
1042  | 0  |     { | 
1043  | 0  |       GVariant *array;  | 
1044  | 0  |       gchar **envp;  | 
1045  |  | 
  | 
1046  | 0  |       envp = g_get_environ ();  | 
1047  | 0  |       array = g_variant_new_bytestring_array ((const gchar **) envp, -1);  | 
1048  | 0  |       g_strfreev (envp);  | 
1049  |  | 
  | 
1050  | 0  |       g_variant_builder_add (builder, "{sv}", "environ", array); | 
1051  | 0  |     }  | 
1052  |  | 
  | 
1053  | 0  |   if (options)  | 
1054  | 0  |     g_variant_builder_add (builder, "{sv}", "options", options); | 
1055  |  | 
  | 
1056  | 0  |   G_APPLICATION_GET_CLASS (application)->  | 
1057  | 0  |     add_platform_data (application, builder);  | 
1058  |  | 
  | 
1059  | 0  |   result = g_variant_builder_end (builder);  | 
1060  | 0  |   g_variant_builder_unref (builder);  | 
1061  |  | 
  | 
1062  | 0  |   return result;  | 
1063  | 0  | }  | 
1064  |  |  | 
1065  |  | static void  | 
1066  |  | g_application_call_command_line (GApplication        *application,  | 
1067  |  |                                  const gchar * const *arguments,  | 
1068  |  |                                  GVariant            *options,  | 
1069  |  |                                  gint                *exit_status)  | 
1070  | 0  | { | 
1071  | 0  |   if (application->priv->is_remote)  | 
1072  | 0  |     { | 
1073  | 0  |       GVariant *platform_data;  | 
1074  |  | 
  | 
1075  | 0  |       platform_data = get_platform_data (application, options);  | 
1076  | 0  |       *exit_status = g_application_impl_command_line (application->priv->impl, arguments, platform_data);  | 
1077  | 0  |     }  | 
1078  | 0  |   else  | 
1079  | 0  |     { | 
1080  | 0  |       GApplicationCommandLine *cmdline;  | 
1081  | 0  |       GVariant *v;  | 
1082  |  | 
  | 
1083  | 0  |       v = g_variant_new_bytestring_array ((const gchar **) arguments, -1);  | 
1084  | 0  |       cmdline = g_object_new (G_TYPE_APPLICATION_COMMAND_LINE,  | 
1085  | 0  |                               "arguments", v,  | 
1086  | 0  |                               "options", options,  | 
1087  | 0  |                               NULL);  | 
1088  | 0  |       g_signal_emit (application, g_application_signals[SIGNAL_COMMAND_LINE], 0, cmdline, exit_status);  | 
1089  | 0  |       g_object_unref (cmdline);  | 
1090  | 0  |     }  | 
1091  | 0  | }  | 
1092  |  |  | 
1093  |  | static gboolean  | 
1094  |  | g_application_real_local_command_line (GApplication   *application,  | 
1095  |  |                                        gchar        ***arguments,  | 
1096  |  |                                        int            *exit_status)  | 
1097  | 0  | { | 
1098  | 0  |   GError *error = NULL;  | 
1099  | 0  |   GVariantDict *options;  | 
1100  | 0  |   gint n_args;  | 
1101  |  | 
  | 
1102  | 0  |   options = g_application_parse_command_line (application, arguments, &error);  | 
1103  | 0  |   if (!options)  | 
1104  | 0  |     { | 
1105  | 0  |       g_printerr ("%s\n", error->message); | 
1106  | 0  |       g_error_free (error);  | 
1107  | 0  |       *exit_status = 1;  | 
1108  | 0  |       return TRUE;  | 
1109  | 0  |     }  | 
1110  |  |  | 
1111  | 0  |   g_signal_emit (application, g_application_signals[SIGNAL_HANDLE_LOCAL_OPTIONS], 0, options, exit_status);  | 
1112  |  | 
  | 
1113  | 0  |   if (*exit_status >= 0)  | 
1114  | 0  |     { | 
1115  | 0  |       g_variant_dict_unref (options);  | 
1116  | 0  |       return TRUE;  | 
1117  | 0  |     }  | 
1118  |  |  | 
1119  | 0  |   if (!g_application_register (application, NULL, &error))  | 
1120  | 0  |     { | 
1121  | 0  |       g_printerr ("Failed to register: %s\n", error->message); | 
1122  | 0  |       g_variant_dict_unref (options);  | 
1123  | 0  |       g_error_free (error);  | 
1124  | 0  |       *exit_status = 1;  | 
1125  | 0  |       return TRUE;  | 
1126  | 0  |     }  | 
1127  |  |  | 
1128  | 0  |   n_args = g_strv_length (*arguments);  | 
1129  |  | 
  | 
1130  | 0  |   if (application->priv->flags & G_APPLICATION_IS_SERVICE)  | 
1131  | 0  |     { | 
1132  | 0  |       if ((*exit_status = n_args > 1))  | 
1133  | 0  |         { | 
1134  | 0  |           g_printerr ("GApplication service mode takes no arguments.\n"); | 
1135  | 0  |           application->priv->flags &= ~G_APPLICATION_IS_SERVICE;  | 
1136  | 0  |           *exit_status = 1;  | 
1137  | 0  |         }  | 
1138  | 0  |       else  | 
1139  | 0  |         *exit_status = 0;  | 
1140  | 0  |     }  | 
1141  | 0  |   else if (application->priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE)  | 
1142  | 0  |     { | 
1143  | 0  |       g_application_call_command_line (application,  | 
1144  | 0  |                                        (const gchar **) *arguments,  | 
1145  | 0  |                                        g_variant_dict_end (options),  | 
1146  | 0  |                                        exit_status);  | 
1147  | 0  |     }  | 
1148  | 0  |   else  | 
1149  | 0  |     { | 
1150  | 0  |       if (n_args <= 1)  | 
1151  | 0  |         { | 
1152  | 0  |           g_application_activate (application);  | 
1153  | 0  |           *exit_status = 0;  | 
1154  | 0  |         }  | 
1155  |  |  | 
1156  | 0  |       else  | 
1157  | 0  |         { | 
1158  | 0  |           if (~application->priv->flags & G_APPLICATION_HANDLES_OPEN)  | 
1159  | 0  |             { | 
1160  | 0  |               g_critical ("This application can not open files."); | 
1161  | 0  |               *exit_status = 1;  | 
1162  | 0  |             }  | 
1163  | 0  |           else  | 
1164  | 0  |             { | 
1165  | 0  |               GFile **files;  | 
1166  | 0  |               gint n_files;  | 
1167  | 0  |               gint i;  | 
1168  |  | 
  | 
1169  | 0  |               n_files = n_args - 1;  | 
1170  | 0  |               files = g_new (GFile *, n_files);  | 
1171  |  | 
  | 
1172  | 0  |               for (i = 0; i < n_files; i++)  | 
1173  | 0  |                 files[i] = g_file_new_for_commandline_arg ((*arguments)[i + 1]);  | 
1174  |  | 
  | 
1175  | 0  |               g_application_open (application, files, n_files, "");  | 
1176  |  | 
  | 
1177  | 0  |               for (i = 0; i < n_files; i++)  | 
1178  | 0  |                 g_object_unref (files[i]);  | 
1179  | 0  |               g_free (files);  | 
1180  |  | 
  | 
1181  | 0  |               *exit_status = 0;  | 
1182  | 0  |             }  | 
1183  | 0  |         }  | 
1184  | 0  |     }  | 
1185  |  | 
  | 
1186  | 0  |   g_variant_dict_unref (options);  | 
1187  |  | 
  | 
1188  | 0  |   return TRUE;  | 
1189  | 0  | }  | 
1190  |  |  | 
1191  |  | static void  | 
1192  |  | g_application_real_add_platform_data (GApplication    *application,  | 
1193  |  |                                       GVariantBuilder *builder)  | 
1194  | 0  | { | 
1195  | 0  | }  | 
1196  |  |  | 
1197  |  | static gboolean  | 
1198  |  | g_application_real_dbus_register (GApplication    *application,  | 
1199  |  |                                   GDBusConnection *connection,  | 
1200  |  |                                   const gchar     *object_path,  | 
1201  |  |                                   GError         **error)  | 
1202  | 0  | { | 
1203  | 0  |   return TRUE;  | 
1204  | 0  | }  | 
1205  |  |  | 
1206  |  | static void  | 
1207  |  | g_application_real_dbus_unregister (GApplication    *application,  | 
1208  |  |                                     GDBusConnection *connection,  | 
1209  |  |                                     const gchar     *object_path)  | 
1210  | 0  | { | 
1211  | 0  | }  | 
1212  |  |  | 
1213  |  | static gboolean  | 
1214  |  | g_application_real_name_lost (GApplication *application)  | 
1215  | 0  | { | 
1216  | 0  |   g_application_quit (application);  | 
1217  | 0  |   return TRUE;  | 
1218  | 0  | }  | 
1219  |  |  | 
1220  |  | /* GObject implementation stuff {{{1 */ | 
1221  |  | static void  | 
1222  |  | g_application_set_property (GObject      *object,  | 
1223  |  |                             guint         prop_id,  | 
1224  |  |                             const GValue *value,  | 
1225  |  |                             GParamSpec   *pspec)  | 
1226  | 0  | { | 
1227  | 0  |   GApplication *application = G_APPLICATION (object);  | 
1228  |  | 
  | 
1229  | 0  |   switch (prop_id)  | 
1230  | 0  |     { | 
1231  | 0  |     case PROP_APPLICATION_ID:  | 
1232  | 0  |       g_application_set_application_id (application,  | 
1233  | 0  |                                         g_value_get_string (value));  | 
1234  | 0  |       break;  | 
1235  |  |  | 
1236  | 0  |     case PROP_FLAGS:  | 
1237  | 0  |       g_application_set_flags (application, g_value_get_flags (value));  | 
1238  | 0  |       break;  | 
1239  |  |  | 
1240  | 0  |     case PROP_RESOURCE_BASE_PATH:  | 
1241  | 0  |       g_application_set_resource_base_path (application, g_value_get_string (value));  | 
1242  | 0  |       break;  | 
1243  |  |  | 
1244  | 0  |     case PROP_INACTIVITY_TIMEOUT:  | 
1245  | 0  |       g_application_set_inactivity_timeout (application,  | 
1246  | 0  |                                             g_value_get_uint (value));  | 
1247  | 0  |       break;  | 
1248  |  |  | 
1249  | 0  |     case PROP_ACTION_GROUP:  | 
1250  | 0  |       g_clear_object (&application->priv->actions);  | 
1251  | 0  |       application->priv->actions = g_value_dup_object (value);  | 
1252  | 0  |       break;  | 
1253  |  |  | 
1254  | 0  |     default:  | 
1255  | 0  |       g_assert_not_reached ();  | 
1256  | 0  |     }  | 
1257  | 0  | }  | 
1258  |  |  | 
1259  |  | /**  | 
1260  |  |  * g_application_set_action_group:  | 
1261  |  |  * @application: a #GApplication  | 
1262  |  |  * @action_group: (nullable): a #GActionGroup, or %NULL  | 
1263  |  |  *  | 
1264  |  |  * This used to be how actions were associated with a #GApplication.  | 
1265  |  |  * Now there is #GActionMap for that.  | 
1266  |  |  *  | 
1267  |  |  * Since: 2.28  | 
1268  |  |  *  | 
1269  |  |  * Deprecated:2.32:Use the #GActionMap interface instead.  Never ever  | 
1270  |  |  * mix use of this API with use of #GActionMap on the same @application  | 
1271  |  |  * or things will go very badly wrong.  This function is known to  | 
1272  |  |  * introduce buggy behaviour (ie: signals not emitted on changes to the  | 
1273  |  |  * action group), so you should really use #GActionMap instead.  | 
1274  |  |  **/  | 
1275  |  | void  | 
1276  |  | g_application_set_action_group (GApplication *application,  | 
1277  |  |                                 GActionGroup *action_group)  | 
1278  | 0  | { | 
1279  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
1280  | 0  |   g_return_if_fail (!application->priv->is_registered);  | 
1281  |  |  | 
1282  | 0  |   if (application->priv->actions != NULL)  | 
1283  | 0  |     g_object_unref (application->priv->actions);  | 
1284  |  | 
  | 
1285  | 0  |   application->priv->actions = action_group;  | 
1286  |  | 
  | 
1287  | 0  |   if (application->priv->actions != NULL)  | 
1288  | 0  |     g_object_ref (application->priv->actions);  | 
1289  | 0  | }  | 
1290  |  |  | 
1291  |  | static void  | 
1292  |  | g_application_get_property (GObject    *object,  | 
1293  |  |                             guint       prop_id,  | 
1294  |  |                             GValue     *value,  | 
1295  |  |                             GParamSpec *pspec)  | 
1296  | 0  | { | 
1297  | 0  |   GApplication *application = G_APPLICATION (object);  | 
1298  |  | 
  | 
1299  | 0  |   switch (prop_id)  | 
1300  | 0  |     { | 
1301  | 0  |     case PROP_APPLICATION_ID:  | 
1302  | 0  |       g_value_set_string (value,  | 
1303  | 0  |                           g_application_get_application_id (application));  | 
1304  | 0  |       break;  | 
1305  |  |  | 
1306  | 0  |     case PROP_FLAGS:  | 
1307  | 0  |       g_value_set_flags (value,  | 
1308  | 0  |                          g_application_get_flags (application));  | 
1309  | 0  |       break;  | 
1310  |  |  | 
1311  | 0  |     case PROP_RESOURCE_BASE_PATH:  | 
1312  | 0  |       g_value_set_string (value, g_application_get_resource_base_path (application));  | 
1313  | 0  |       break;  | 
1314  |  |  | 
1315  | 0  |     case PROP_IS_REGISTERED:  | 
1316  | 0  |       g_value_set_boolean (value,  | 
1317  | 0  |                            g_application_get_is_registered (application));  | 
1318  | 0  |       break;  | 
1319  |  |  | 
1320  | 0  |     case PROP_IS_REMOTE:  | 
1321  | 0  |       g_value_set_boolean (value,  | 
1322  | 0  |                            g_application_get_is_remote (application));  | 
1323  | 0  |       break;  | 
1324  |  |  | 
1325  | 0  |     case PROP_INACTIVITY_TIMEOUT:  | 
1326  | 0  |       g_value_set_uint (value,  | 
1327  | 0  |                         g_application_get_inactivity_timeout (application));  | 
1328  | 0  |       break;  | 
1329  |  |  | 
1330  | 0  |     case PROP_IS_BUSY:  | 
1331  | 0  |       g_value_set_boolean (value, g_application_get_is_busy (application));  | 
1332  | 0  |       break;  | 
1333  |  |  | 
1334  | 0  |     default:  | 
1335  | 0  |       g_assert_not_reached ();  | 
1336  | 0  |     }  | 
1337  | 0  | }  | 
1338  |  |  | 
1339  |  | static void  | 
1340  |  | g_application_constructed (GObject *object)  | 
1341  | 0  | { | 
1342  | 0  |   GApplication *application = G_APPLICATION (object);  | 
1343  |  | 
  | 
1344  | 0  |   if (g_application_get_default () == NULL)  | 
1345  | 0  |     g_application_set_default (application);  | 
1346  |  |  | 
1347  |  |   /* People should not set properties from _init... */  | 
1348  | 0  |   g_assert (application->priv->resource_path == NULL);  | 
1349  |  |  | 
1350  | 0  |   if (application->priv->id != NULL)  | 
1351  | 0  |     { | 
1352  | 0  |       gint i;  | 
1353  |  | 
  | 
1354  | 0  |       application->priv->resource_path = g_strconcat ("/", application->priv->id, NULL); | 
1355  |  | 
  | 
1356  | 0  |       for (i = 1; application->priv->resource_path[i]; i++)  | 
1357  | 0  |         if (application->priv->resource_path[i] == '.')  | 
1358  | 0  |           application->priv->resource_path[i] = '/';  | 
1359  | 0  |     }  | 
1360  | 0  | }  | 
1361  |  |  | 
1362  |  | static void  | 
1363  |  | g_application_dispose (GObject *object)  | 
1364  | 0  | { | 
1365  | 0  |   GApplication *application = G_APPLICATION (object);  | 
1366  |  | 
  | 
1367  | 0  |   if (application->priv->impl != NULL &&  | 
1368  | 0  |       G_APPLICATION_GET_CLASS (application)->dbus_unregister != g_application_real_dbus_unregister)  | 
1369  | 0  |     { | 
1370  | 0  |       static gboolean warned;  | 
1371  |  | 
  | 
1372  | 0  |       if (!warned)  | 
1373  | 0  |         { | 
1374  | 0  |           g_warning ("Your application did not unregister from D-Bus before destruction. " | 
1375  | 0  |                      "Consider using g_application_run().");  | 
1376  | 0  |         }  | 
1377  |  | 
  | 
1378  | 0  |       warned = TRUE;  | 
1379  | 0  |     }  | 
1380  |  | 
  | 
1381  | 0  |   G_OBJECT_CLASS (g_application_parent_class)->dispose (object);  | 
1382  | 0  | }  | 
1383  |  |  | 
1384  |  | static void  | 
1385  |  | g_application_finalize (GObject *object)  | 
1386  | 0  | { | 
1387  | 0  |   GApplication *application = G_APPLICATION (object);  | 
1388  |  | 
  | 
1389  | 0  |   if (application->priv->inactivity_timeout_id)  | 
1390  | 0  |     g_source_remove (application->priv->inactivity_timeout_id);  | 
1391  |  | 
  | 
1392  | 0  |   g_slist_free_full (application->priv->option_groups, (GDestroyNotify) g_option_group_unref);  | 
1393  | 0  |   if (application->priv->main_options)  | 
1394  | 0  |     g_option_group_unref (application->priv->main_options);  | 
1395  | 0  |   if (application->priv->packed_options)  | 
1396  | 0  |     g_hash_table_unref (application->priv->packed_options);  | 
1397  |  | 
  | 
1398  | 0  |   g_free (application->priv->parameter_string);  | 
1399  | 0  |   g_free (application->priv->summary);  | 
1400  | 0  |   g_free (application->priv->description);  | 
1401  |  | 
  | 
1402  | 0  |   g_slist_free_full (application->priv->option_strings, g_free);  | 
1403  |  | 
  | 
1404  | 0  |   if (application->priv->impl)  | 
1405  | 0  |     g_application_impl_destroy (application->priv->impl);  | 
1406  | 0  |   g_free (application->priv->id);  | 
1407  |  | 
  | 
1408  | 0  |   if (g_application_get_default () == application)  | 
1409  | 0  |     g_application_set_default (NULL);  | 
1410  |  | 
  | 
1411  | 0  |   if (application->priv->actions)  | 
1412  | 0  |     g_object_unref (application->priv->actions);  | 
1413  |  | 
  | 
1414  | 0  |   g_clear_object (&application->priv->remote_actions);  | 
1415  |  | 
  | 
1416  | 0  |   if (application->priv->notifications)  | 
1417  | 0  |     g_object_unref (application->priv->notifications);  | 
1418  |  | 
  | 
1419  | 0  |   g_free (application->priv->resource_path);  | 
1420  |  | 
  | 
1421  | 0  |   G_OBJECT_CLASS (g_application_parent_class)  | 
1422  | 0  |     ->finalize (object);  | 
1423  | 0  | }  | 
1424  |  |  | 
1425  |  | static void  | 
1426  |  | g_application_init (GApplication *application)  | 
1427  | 0  | { | 
1428  | 0  |   application->priv = g_application_get_instance_private (application);  | 
1429  |  | 
  | 
1430  | 0  |   application->priv->actions = g_application_exported_actions_new (application);  | 
1431  |  |  | 
1432  |  |   /* application->priv->actions is the one and only ref on the group, so when  | 
1433  |  |    * we dispose, the action group will die, disconnecting all signals.  | 
1434  |  |    */  | 
1435  | 0  |   g_signal_connect_swapped (application->priv->actions, "action-added",  | 
1436  | 0  |                             G_CALLBACK (g_action_group_action_added), application);  | 
1437  | 0  |   g_signal_connect_swapped (application->priv->actions, "action-enabled-changed",  | 
1438  | 0  |                             G_CALLBACK (g_action_group_action_enabled_changed), application);  | 
1439  | 0  |   g_signal_connect_swapped (application->priv->actions, "action-state-changed",  | 
1440  | 0  |                             G_CALLBACK (g_action_group_action_state_changed), application);  | 
1441  | 0  |   g_signal_connect_swapped (application->priv->actions, "action-removed",  | 
1442  | 0  |                             G_CALLBACK (g_action_group_action_removed), application);  | 
1443  | 0  | }  | 
1444  |  |  | 
1445  |  | static gboolean  | 
1446  |  | g_application_handle_local_options_accumulator (GSignalInvocationHint *ihint,  | 
1447  |  |                                                 GValue                *return_accu,  | 
1448  |  |                                                 const GValue          *handler_return,  | 
1449  |  |                                                 gpointer               dummy)  | 
1450  | 0  | { | 
1451  | 0  |   gint value;  | 
1452  |  | 
  | 
1453  | 0  |   value = g_value_get_int (handler_return);  | 
1454  | 0  |   g_value_set_int (return_accu, value);  | 
1455  |  | 
  | 
1456  | 0  |   return value < 0;  | 
1457  | 0  | }  | 
1458  |  |  | 
1459  |  | static void  | 
1460  |  | g_application_class_init (GApplicationClass *class)  | 
1461  | 0  | { | 
1462  | 0  |   GObjectClass *object_class = G_OBJECT_CLASS (class);  | 
1463  |  | 
  | 
1464  | 0  |   object_class->constructed = g_application_constructed;  | 
1465  | 0  |   object_class->dispose = g_application_dispose;  | 
1466  | 0  |   object_class->finalize = g_application_finalize;  | 
1467  | 0  |   object_class->get_property = g_application_get_property;  | 
1468  | 0  |   object_class->set_property = g_application_set_property;  | 
1469  |  | 
  | 
1470  | 0  |   class->before_emit = g_application_real_before_emit;  | 
1471  | 0  |   class->after_emit = g_application_real_after_emit;  | 
1472  | 0  |   class->startup = g_application_real_startup;  | 
1473  | 0  |   class->shutdown = g_application_real_shutdown;  | 
1474  | 0  |   class->activate = g_application_real_activate;  | 
1475  | 0  |   class->open = g_application_real_open;  | 
1476  | 0  |   class->command_line = g_application_real_command_line;  | 
1477  | 0  |   class->local_command_line = g_application_real_local_command_line;  | 
1478  | 0  |   class->handle_local_options = g_application_real_handle_local_options;  | 
1479  | 0  |   class->add_platform_data = g_application_real_add_platform_data;  | 
1480  | 0  |   class->dbus_register = g_application_real_dbus_register;  | 
1481  | 0  |   class->dbus_unregister = g_application_real_dbus_unregister;  | 
1482  | 0  |   class->name_lost = g_application_real_name_lost;  | 
1483  |  | 
  | 
1484  | 0  |   g_object_class_install_property (object_class, PROP_APPLICATION_ID,  | 
1485  | 0  |     g_param_spec_string ("application-id", | 
1486  | 0  |                          P_("Application identifier"), | 
1487  | 0  |                          P_("The unique identifier for the application"), | 
1488  | 0  |                          NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |  | 
1489  | 0  |                          G_PARAM_STATIC_STRINGS));  | 
1490  |  | 
  | 
1491  | 0  |   g_object_class_install_property (object_class, PROP_FLAGS,  | 
1492  | 0  |     g_param_spec_flags ("flags", | 
1493  | 0  |                         P_("Application flags"), | 
1494  | 0  |                         P_("Flags specifying the behaviour of the application"), | 
1495  | 0  |                         G_TYPE_APPLICATION_FLAGS, G_APPLICATION_DEFAULT_FLAGS,  | 
1496  | 0  |                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));  | 
1497  |  | 
  | 
1498  | 0  |   g_object_class_install_property (object_class, PROP_RESOURCE_BASE_PATH,  | 
1499  | 0  |     g_param_spec_string ("resource-base-path", | 
1500  | 0  |                          P_("Resource base path"), | 
1501  | 0  |                          P_("The base resource path for the application"), | 
1502  | 0  |                          NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));  | 
1503  |  | 
  | 
1504  | 0  |   g_object_class_install_property (object_class, PROP_IS_REGISTERED,  | 
1505  | 0  |     g_param_spec_boolean ("is-registered", | 
1506  | 0  |                           P_("Is registered"), | 
1507  | 0  |                           P_("If g_application_register() has been called"), | 
1508  | 0  |                           FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));  | 
1509  |  | 
  | 
1510  | 0  |   g_object_class_install_property (object_class, PROP_IS_REMOTE,  | 
1511  | 0  |     g_param_spec_boolean ("is-remote", | 
1512  | 0  |                           P_("Is remote"), | 
1513  | 0  |                           P_("If this application instance is remote"), | 
1514  | 0  |                           FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));  | 
1515  |  | 
  | 
1516  | 0  |   g_object_class_install_property (object_class, PROP_INACTIVITY_TIMEOUT,  | 
1517  | 0  |     g_param_spec_uint ("inactivity-timeout", | 
1518  | 0  |                        P_("Inactivity timeout"), | 
1519  | 0  |                        P_("Time (ms) to stay alive after becoming idle"), | 
1520  | 0  |                        0, G_MAXUINT, 0,  | 
1521  | 0  |                        G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));  | 
1522  |  | 
  | 
1523  | 0  |   g_object_class_install_property (object_class, PROP_ACTION_GROUP,  | 
1524  | 0  |     g_param_spec_object ("action-group", | 
1525  | 0  |                          P_("Action group"), | 
1526  | 0  |                          P_("The group of actions that the application exports"), | 
1527  | 0  |                          G_TYPE_ACTION_GROUP,  | 
1528  | 0  |                          G_PARAM_DEPRECATED | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));  | 
1529  |  |  | 
1530  |  |   /**  | 
1531  |  |    * GApplication:is-busy:  | 
1532  |  |    *  | 
1533  |  |    * Whether the application is currently marked as busy through  | 
1534  |  |    * g_application_mark_busy() or g_application_bind_busy_property().  | 
1535  |  |    *  | 
1536  |  |    * Since: 2.44  | 
1537  |  |    */  | 
1538  | 0  |   g_object_class_install_property (object_class, PROP_IS_BUSY,  | 
1539  | 0  |     g_param_spec_boolean ("is-busy", | 
1540  | 0  |                           P_("Is busy"), | 
1541  | 0  |                           P_("If this application is currently marked busy"), | 
1542  | 0  |                           FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));  | 
1543  |  |  | 
1544  |  |   /**  | 
1545  |  |    * GApplication::startup:  | 
1546  |  |    * @application: the application  | 
1547  |  |    *  | 
1548  |  |    * The ::startup signal is emitted on the primary instance immediately  | 
1549  |  |    * after registration. See g_application_register().  | 
1550  |  |    */  | 
1551  | 0  |   g_application_signals[SIGNAL_STARTUP] =  | 
1552  | 0  |     g_signal_new (I_("startup"), G_TYPE_APPLICATION, G_SIGNAL_RUN_FIRST, | 
1553  | 0  |                   G_STRUCT_OFFSET (GApplicationClass, startup),  | 
1554  | 0  |                   NULL, NULL, NULL, G_TYPE_NONE, 0);  | 
1555  |  |  | 
1556  |  |   /**  | 
1557  |  |    * GApplication::shutdown:  | 
1558  |  |    * @application: the application  | 
1559  |  |    *  | 
1560  |  |    * The ::shutdown signal is emitted only on the registered primary instance  | 
1561  |  |    * immediately after the main loop terminates.  | 
1562  |  |    */  | 
1563  | 0  |   g_application_signals[SIGNAL_SHUTDOWN] =  | 
1564  | 0  |     g_signal_new (I_("shutdown"), G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST, | 
1565  | 0  |                   G_STRUCT_OFFSET (GApplicationClass, shutdown),  | 
1566  | 0  |                   NULL, NULL, NULL, G_TYPE_NONE, 0);  | 
1567  |  |  | 
1568  |  |   /**  | 
1569  |  |    * GApplication::activate:  | 
1570  |  |    * @application: the application  | 
1571  |  |    *  | 
1572  |  |    * The ::activate signal is emitted on the primary instance when an  | 
1573  |  |    * activation occurs. See g_application_activate().  | 
1574  |  |    */  | 
1575  | 0  |   g_application_signals[SIGNAL_ACTIVATE] =  | 
1576  | 0  |     g_signal_new (I_("activate"), G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST, | 
1577  | 0  |                   G_STRUCT_OFFSET (GApplicationClass, activate),  | 
1578  | 0  |                   NULL, NULL, NULL, G_TYPE_NONE, 0);  | 
1579  |  |  | 
1580  |  |  | 
1581  |  |   /**  | 
1582  |  |    * GApplication::open:  | 
1583  |  |    * @application: the application  | 
1584  |  |    * @files: (array length=n_files) (element-type GFile): an array of #GFiles  | 
1585  |  |    * @n_files: the length of @files  | 
1586  |  |    * @hint: a hint provided by the calling instance  | 
1587  |  |    *  | 
1588  |  |    * The ::open signal is emitted on the primary instance when there are  | 
1589  |  |    * files to open. See g_application_open() for more information.  | 
1590  |  |    */  | 
1591  | 0  |   g_application_signals[SIGNAL_OPEN] =  | 
1592  | 0  |     g_signal_new (I_("open"), G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST, | 
1593  | 0  |                   G_STRUCT_OFFSET (GApplicationClass, open),  | 
1594  | 0  |                   NULL, NULL,  | 
1595  | 0  |                   _g_cclosure_marshal_VOID__POINTER_INT_STRING,  | 
1596  | 0  |                   G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);  | 
1597  | 0  |   g_signal_set_va_marshaller (g_application_signals[SIGNAL_OPEN],  | 
1598  | 0  |                               G_TYPE_FROM_CLASS (class),  | 
1599  | 0  |                               _g_cclosure_marshal_VOID__POINTER_INT_STRINGv);  | 
1600  |  |  | 
1601  |  |   /**  | 
1602  |  |    * GApplication::command-line:  | 
1603  |  |    * @application: the application  | 
1604  |  |    * @command_line: a #GApplicationCommandLine representing the  | 
1605  |  |    *     passed commandline  | 
1606  |  |    *  | 
1607  |  |    * The ::command-line signal is emitted on the primary instance when  | 
1608  |  |    * a commandline is not handled locally. See g_application_run() and  | 
1609  |  |    * the #GApplicationCommandLine documentation for more information.  | 
1610  |  |    *  | 
1611  |  |    * Returns: An integer that is set as the exit status for the calling  | 
1612  |  |    *   process. See g_application_command_line_set_exit_status().  | 
1613  |  |    */  | 
1614  | 0  |   g_application_signals[SIGNAL_COMMAND_LINE] =  | 
1615  | 0  |     g_signal_new (I_("command-line"), G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST, | 
1616  | 0  |                   G_STRUCT_OFFSET (GApplicationClass, command_line),  | 
1617  | 0  |                   g_signal_accumulator_first_wins, NULL,  | 
1618  | 0  |                   _g_cclosure_marshal_INT__OBJECT,  | 
1619  | 0  |                   G_TYPE_INT, 1, G_TYPE_APPLICATION_COMMAND_LINE);  | 
1620  | 0  |   g_signal_set_va_marshaller (g_application_signals[SIGNAL_COMMAND_LINE],  | 
1621  | 0  |                               G_TYPE_FROM_CLASS (class),  | 
1622  | 0  |                               _g_cclosure_marshal_INT__OBJECTv);  | 
1623  |  |  | 
1624  |  |   /**  | 
1625  |  |    * GApplication::handle-local-options:  | 
1626  |  |    * @application: the application  | 
1627  |  |    * @options: the options dictionary  | 
1628  |  |    *  | 
1629  |  |    * The ::handle-local-options signal is emitted on the local instance  | 
1630  |  |    * after the parsing of the commandline options has occurred.  | 
1631  |  |    *  | 
1632  |  |    * You can add options to be recognised during commandline option  | 
1633  |  |    * parsing using g_application_add_main_option_entries() and  | 
1634  |  |    * g_application_add_option_group().  | 
1635  |  |    *  | 
1636  |  |    * Signal handlers can inspect @options (along with values pointed to  | 
1637  |  |    * from the @arg_data of an installed #GOptionEntrys) in order to  | 
1638  |  |    * decide to perform certain actions, including direct local handling  | 
1639  |  |    * (which may be useful for options like --version).  | 
1640  |  |    *  | 
1641  |  |    * In the event that the application is marked  | 
1642  |  |    * %G_APPLICATION_HANDLES_COMMAND_LINE the "normal processing" will  | 
1643  |  |    * send the @options dictionary to the primary instance where it can be  | 
1644  |  |    * read with g_application_command_line_get_options_dict().  The signal  | 
1645  |  |    * handler can modify the dictionary before returning, and the  | 
1646  |  |    * modified dictionary will be sent.  | 
1647  |  |    *  | 
1648  |  |    * In the event that %G_APPLICATION_HANDLES_COMMAND_LINE is not set,  | 
1649  |  |    * "normal processing" will treat the remaining uncollected command  | 
1650  |  |    * line arguments as filenames or URIs.  If there are no arguments,  | 
1651  |  |    * the application is activated by g_application_activate().  One or  | 
1652  |  |    * more arguments results in a call to g_application_open().  | 
1653  |  |    *  | 
1654  |  |    * If you want to handle the local commandline arguments for yourself  | 
1655  |  |    * by converting them to calls to g_application_open() or  | 
1656  |  |    * g_action_group_activate_action() then you must be sure to register  | 
1657  |  |    * the application first.  You should probably not call  | 
1658  |  |    * g_application_activate() for yourself, however: just return -1 and  | 
1659  |  |    * allow the default handler to do it for you.  This will ensure that  | 
1660  |  |    * the `--gapplication-service` switch works properly (i.e. no activation  | 
1661  |  |    * in that case).  | 
1662  |  |    *  | 
1663  |  |    * Note that this signal is emitted from the default implementation of  | 
1664  |  |    * local_command_line().  If you override that function and don't  | 
1665  |  |    * chain up then this signal will never be emitted.  | 
1666  |  |    *  | 
1667  |  |    * You can override local_command_line() if you need more powerful  | 
1668  |  |    * capabilities than what is provided here, but this should not  | 
1669  |  |    * normally be required.  | 
1670  |  |    *  | 
1671  |  |    * Returns: an exit code. If you have handled your options and want  | 
1672  |  |    * to exit the process, return a non-negative option, 0 for success,  | 
1673  |  |    * and a positive value for failure. To continue, return -1 to let  | 
1674  |  |    * the default option processing continue.  | 
1675  |  |    *  | 
1676  |  |    * Since: 2.40  | 
1677  |  |    **/  | 
1678  | 0  |   g_application_signals[SIGNAL_HANDLE_LOCAL_OPTIONS] =  | 
1679  | 0  |     g_signal_new (I_("handle-local-options"), G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST, | 
1680  | 0  |                   G_STRUCT_OFFSET (GApplicationClass, handle_local_options),  | 
1681  | 0  |                   g_application_handle_local_options_accumulator, NULL,  | 
1682  | 0  |                   _g_cclosure_marshal_INT__BOXED,  | 
1683  | 0  |                   G_TYPE_INT, 1, G_TYPE_VARIANT_DICT);  | 
1684  | 0  |   g_signal_set_va_marshaller (g_application_signals[SIGNAL_HANDLE_LOCAL_OPTIONS],  | 
1685  | 0  |                               G_TYPE_FROM_CLASS (class),  | 
1686  | 0  |                               _g_cclosure_marshal_INT__BOXEDv);  | 
1687  |  |  | 
1688  |  |   /**  | 
1689  |  |    * GApplication::name-lost:  | 
1690  |  |    * @application: the application  | 
1691  |  |    *  | 
1692  |  |    * The ::name-lost signal is emitted only on the registered primary instance  | 
1693  |  |    * when a new instance has taken over. This can only happen if the application  | 
1694  |  |    * is using the %G_APPLICATION_ALLOW_REPLACEMENT flag.  | 
1695  |  |    *  | 
1696  |  |    * The default handler for this signal calls g_application_quit().  | 
1697  |  |    *  | 
1698  |  |    * Returns: %TRUE if the signal has been handled  | 
1699  |  |    *  | 
1700  |  |    * Since: 2.60  | 
1701  |  |    */  | 
1702  | 0  |   g_application_signals[SIGNAL_NAME_LOST] =  | 
1703  | 0  |     g_signal_new (I_("name-lost"), G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST, | 
1704  | 0  |                   G_STRUCT_OFFSET (GApplicationClass, name_lost),  | 
1705  | 0  |                   g_signal_accumulator_true_handled, NULL,  | 
1706  | 0  |                   _g_cclosure_marshal_BOOLEAN__VOID,  | 
1707  | 0  |                   G_TYPE_BOOLEAN, 0);  | 
1708  | 0  |   g_signal_set_va_marshaller (g_application_signals[SIGNAL_NAME_LOST],  | 
1709  | 0  |                               G_TYPE_FROM_CLASS (class),  | 
1710  | 0  |                               _g_cclosure_marshal_BOOLEAN__VOIDv);  | 
1711  | 0  | }  | 
1712  |  |  | 
1713  |  | /* Application ID validity {{{1 */ | 
1714  |  |  | 
1715  |  | /**  | 
1716  |  |  * g_application_id_is_valid:  | 
1717  |  |  * @application_id: a potential application identifier  | 
1718  |  |  *  | 
1719  |  |  * Checks if @application_id is a valid application identifier.  | 
1720  |  |  *  | 
1721  |  |  * A valid ID is required for calls to g_application_new() and  | 
1722  |  |  * g_application_set_application_id().  | 
1723  |  |  *  | 
1724  |  |  * Application identifiers follow the same format as  | 
1725  |  |  * [D-Bus well-known bus names](https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus).  | 
1726  |  |  * For convenience, the restrictions on application identifiers are  | 
1727  |  |  * reproduced here:  | 
1728  |  |  *  | 
1729  |  |  * - Application identifiers are composed of 1 or more elements separated by a  | 
1730  |  |  *   period (`.`) character. All elements must contain at least one character.  | 
1731  |  |  *  | 
1732  |  |  * - Each element must only contain the ASCII characters `[A-Z][a-z][0-9]_-`,  | 
1733  |  |  *   with `-` discouraged in new application identifiers. Each element must not  | 
1734  |  |  *   begin with a digit.  | 
1735  |  |  *  | 
1736  |  |  * - Application identifiers must contain at least one `.` (period) character  | 
1737  |  |  *   (and thus at least two elements).  | 
1738  |  |  *  | 
1739  |  |  * - Application identifiers must not begin with a `.` (period) character.  | 
1740  |  |  *  | 
1741  |  |  * - Application identifiers must not exceed 255 characters.  | 
1742  |  |  *  | 
1743  |  |  * Note that the hyphen (`-`) character is allowed in application identifiers,  | 
1744  |  |  * but is problematic or not allowed in various specifications and APIs that  | 
1745  |  |  * refer to D-Bus, such as  | 
1746  |  |  * [Flatpak application IDs](http://docs.flatpak.org/en/latest/introduction.html#identifiers),  | 
1747  |  |  * the  | 
1748  |  |  * [`DBusActivatable` interface in the Desktop Entry Specification](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#dbus),  | 
1749  |  |  * and the convention that an application's "main" interface and object path  | 
1750  |  |  * resemble its application identifier and bus name. To avoid situations that  | 
1751  |  |  * require special-case handling, it is recommended that new application  | 
1752  |  |  * identifiers consistently replace hyphens with underscores.  | 
1753  |  |  *  | 
1754  |  |  * Like D-Bus interface names, application identifiers should start with the  | 
1755  |  |  * reversed DNS domain name of the author of the interface (in lower-case), and  | 
1756  |  |  * it is conventional for the rest of the application identifier to consist of  | 
1757  |  |  * words run together, with initial capital letters.  | 
1758  |  |  *  | 
1759  |  |  * As with D-Bus interface names, if the author's DNS domain name contains  | 
1760  |  |  * hyphen/minus characters they should be replaced by underscores, and if it  | 
1761  |  |  * contains leading digits they should be escaped by prepending an underscore.  | 
1762  |  |  * For example, if the owner of 7-zip.org used an application identifier for an  | 
1763  |  |  * archiving application, it might be named `org._7_zip.Archiver`.  | 
1764  |  |  *  | 
1765  |  |  * Returns: %TRUE if @application_id is valid  | 
1766  |  |  */  | 
1767  |  | gboolean  | 
1768  |  | g_application_id_is_valid (const gchar *application_id)  | 
1769  | 0  | { | 
1770  | 0  |   return g_dbus_is_name (application_id) &&  | 
1771  | 0  |          !g_dbus_is_unique_name (application_id);  | 
1772  | 0  | }  | 
1773  |  |  | 
1774  |  | /* Public Constructor {{{1 */ | 
1775  |  | /**  | 
1776  |  |  * g_application_new:  | 
1777  |  |  * @application_id: (nullable): the application id  | 
1778  |  |  * @flags: the application flags  | 
1779  |  |  *  | 
1780  |  |  * Creates a new #GApplication instance.  | 
1781  |  |  *  | 
1782  |  |  * If non-%NULL, the application id must be valid.  See  | 
1783  |  |  * g_application_id_is_valid().  | 
1784  |  |  *  | 
1785  |  |  * If no application ID is given then some features of #GApplication  | 
1786  |  |  * (most notably application uniqueness) will be disabled.  | 
1787  |  |  *  | 
1788  |  |  * Returns: a new #GApplication instance  | 
1789  |  |  **/  | 
1790  |  | GApplication *  | 
1791  |  | g_application_new (const gchar       *application_id,  | 
1792  |  |                    GApplicationFlags  flags)  | 
1793  | 0  | { | 
1794  | 0  |   g_return_val_if_fail (application_id == NULL || g_application_id_is_valid (application_id), NULL);  | 
1795  |  |  | 
1796  | 0  |   return g_object_new (G_TYPE_APPLICATION,  | 
1797  | 0  |                        "application-id", application_id,  | 
1798  | 0  |                        "flags", flags,  | 
1799  | 0  |                        NULL);  | 
1800  | 0  | }  | 
1801  |  |  | 
1802  |  | /* Simple get/set: application id, flags, inactivity timeout {{{1 */ | 
1803  |  | /**  | 
1804  |  |  * g_application_get_application_id:  | 
1805  |  |  * @application: a #GApplication  | 
1806  |  |  *  | 
1807  |  |  * Gets the unique identifier for @application.  | 
1808  |  |  *  | 
1809  |  |  * Returns: (nullable): the identifier for @application, owned by @application  | 
1810  |  |  *  | 
1811  |  |  * Since: 2.28  | 
1812  |  |  **/  | 
1813  |  | const gchar *  | 
1814  |  | g_application_get_application_id (GApplication *application)  | 
1815  | 0  | { | 
1816  | 0  |   g_return_val_if_fail (G_IS_APPLICATION (application), NULL);  | 
1817  |  |  | 
1818  | 0  |   return application->priv->id;  | 
1819  | 0  | }  | 
1820  |  |  | 
1821  |  | /**  | 
1822  |  |  * g_application_set_application_id:  | 
1823  |  |  * @application: a #GApplication  | 
1824  |  |  * @application_id: (nullable): the identifier for @application  | 
1825  |  |  *  | 
1826  |  |  * Sets the unique identifier for @application.  | 
1827  |  |  *  | 
1828  |  |  * The application id can only be modified if @application has not yet  | 
1829  |  |  * been registered.  | 
1830  |  |  *  | 
1831  |  |  * If non-%NULL, the application id must be valid.  See  | 
1832  |  |  * g_application_id_is_valid().  | 
1833  |  |  *  | 
1834  |  |  * Since: 2.28  | 
1835  |  |  **/  | 
1836  |  | void  | 
1837  |  | g_application_set_application_id (GApplication *application,  | 
1838  |  |                                   const gchar  *application_id)  | 
1839  | 0  | { | 
1840  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
1841  |  |  | 
1842  | 0  |   if (g_strcmp0 (application->priv->id, application_id) != 0)  | 
1843  | 0  |     { | 
1844  | 0  |       g_return_if_fail (application_id == NULL || g_application_id_is_valid (application_id));  | 
1845  | 0  |       g_return_if_fail (!application->priv->is_registered);  | 
1846  |  |  | 
1847  | 0  |       g_free (application->priv->id);  | 
1848  | 0  |       application->priv->id = g_strdup (application_id);  | 
1849  |  | 
  | 
1850  | 0  |       g_object_notify (G_OBJECT (application), "application-id");  | 
1851  | 0  |     }  | 
1852  | 0  | }  | 
1853  |  |  | 
1854  |  | /**  | 
1855  |  |  * g_application_get_flags:  | 
1856  |  |  * @application: a #GApplication  | 
1857  |  |  *  | 
1858  |  |  * Gets the flags for @application.  | 
1859  |  |  *  | 
1860  |  |  * See #GApplicationFlags.  | 
1861  |  |  *  | 
1862  |  |  * Returns: the flags for @application  | 
1863  |  |  *  | 
1864  |  |  * Since: 2.28  | 
1865  |  |  **/  | 
1866  |  | GApplicationFlags  | 
1867  |  | g_application_get_flags (GApplication *application)  | 
1868  | 0  | { | 
1869  | 0  |   g_return_val_if_fail (G_IS_APPLICATION (application), 0);  | 
1870  |  |  | 
1871  | 0  |   return application->priv->flags;  | 
1872  | 0  | }  | 
1873  |  |  | 
1874  |  | /**  | 
1875  |  |  * g_application_set_flags:  | 
1876  |  |  * @application: a #GApplication  | 
1877  |  |  * @flags: the flags for @application  | 
1878  |  |  *  | 
1879  |  |  * Sets the flags for @application.  | 
1880  |  |  *  | 
1881  |  |  * The flags can only be modified if @application has not yet been  | 
1882  |  |  * registered.  | 
1883  |  |  *  | 
1884  |  |  * See #GApplicationFlags.  | 
1885  |  |  *  | 
1886  |  |  * Since: 2.28  | 
1887  |  |  **/  | 
1888  |  | void  | 
1889  |  | g_application_set_flags (GApplication      *application,  | 
1890  |  |                          GApplicationFlags  flags)  | 
1891  | 0  | { | 
1892  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
1893  |  |  | 
1894  | 0  |   if (application->priv->flags != flags)  | 
1895  | 0  |     { | 
1896  | 0  |       g_return_if_fail (!application->priv->is_registered);  | 
1897  |  |  | 
1898  | 0  |       application->priv->flags = flags;  | 
1899  |  | 
  | 
1900  | 0  |       g_object_notify (G_OBJECT (application), "flags");  | 
1901  | 0  |     }  | 
1902  | 0  | }  | 
1903  |  |  | 
1904  |  | /**  | 
1905  |  |  * g_application_get_resource_base_path:  | 
1906  |  |  * @application: a #GApplication  | 
1907  |  |  *  | 
1908  |  |  * Gets the resource base path of @application.  | 
1909  |  |  *  | 
1910  |  |  * See g_application_set_resource_base_path() for more information.  | 
1911  |  |  *  | 
1912  |  |  * Returns: (nullable): the base resource path, if one is set  | 
1913  |  |  *  | 
1914  |  |  * Since: 2.42  | 
1915  |  |  */  | 
1916  |  | const gchar *  | 
1917  |  | g_application_get_resource_base_path (GApplication *application)  | 
1918  | 0  | { | 
1919  | 0  |   g_return_val_if_fail (G_IS_APPLICATION (application), NULL);  | 
1920  |  |  | 
1921  | 0  |   return application->priv->resource_path;  | 
1922  | 0  | }  | 
1923  |  |  | 
1924  |  | /**  | 
1925  |  |  * g_application_set_resource_base_path:  | 
1926  |  |  * @application: a #GApplication  | 
1927  |  |  * @resource_path: (nullable): the resource path to use  | 
1928  |  |  *  | 
1929  |  |  * Sets (or unsets) the base resource path of @application.  | 
1930  |  |  *  | 
1931  |  |  * The path is used to automatically load various [application  | 
1932  |  |  * resources][gresource] such as menu layouts and action descriptions.  | 
1933  |  |  * The various types of resources will be found at fixed names relative  | 
1934  |  |  * to the given base path.  | 
1935  |  |  *  | 
1936  |  |  * By default, the resource base path is determined from the application  | 
1937  |  |  * ID by prefixing '/' and replacing each '.' with '/'.  This is done at  | 
1938  |  |  * the time that the #GApplication object is constructed.  Changes to  | 
1939  |  |  * the application ID after that point will not have an impact on the  | 
1940  |  |  * resource base path.  | 
1941  |  |  *  | 
1942  |  |  * As an example, if the application has an ID of "org.example.app" then  | 
1943  |  |  * the default resource base path will be "/org/example/app".  If this  | 
1944  |  |  * is a #GtkApplication (and you have not manually changed the path)  | 
1945  |  |  * then Gtk will then search for the menus of the application at  | 
1946  |  |  * "/org/example/app/gtk/menus.ui".  | 
1947  |  |  *  | 
1948  |  |  * See #GResource for more information about adding resources to your  | 
1949  |  |  * application.  | 
1950  |  |  *  | 
1951  |  |  * You can disable automatic resource loading functionality by setting  | 
1952  |  |  * the path to %NULL.  | 
1953  |  |  *  | 
1954  |  |  * Changing the resource base path once the application is running is  | 
1955  |  |  * not recommended.  The point at which the resource path is consulted  | 
1956  |  |  * for forming paths for various purposes is unspecified.  When writing  | 
1957  |  |  * a sub-class of #GApplication you should either set the  | 
1958  |  |  * #GApplication:resource-base-path property at construction time, or call  | 
1959  |  |  * this function during the instance initialization. Alternatively, you  | 
1960  |  |  * can call this function in the #GApplicationClass.startup virtual function,  | 
1961  |  |  * before chaining up to the parent implementation.  | 
1962  |  |  *  | 
1963  |  |  * Since: 2.42  | 
1964  |  |  */  | 
1965  |  | void  | 
1966  |  | g_application_set_resource_base_path (GApplication *application,  | 
1967  |  |                                       const gchar  *resource_path)  | 
1968  | 0  | { | 
1969  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
1970  | 0  |   g_return_if_fail (resource_path == NULL || g_str_has_prefix (resource_path, "/"));  | 
1971  |  |  | 
1972  | 0  |   if (g_strcmp0 (application->priv->resource_path, resource_path) != 0)  | 
1973  | 0  |     { | 
1974  | 0  |       g_free (application->priv->resource_path);  | 
1975  |  | 
  | 
1976  | 0  |       application->priv->resource_path = g_strdup (resource_path);  | 
1977  |  | 
  | 
1978  | 0  |       g_object_notify (G_OBJECT (application), "resource-base-path");  | 
1979  | 0  |     }  | 
1980  | 0  | }  | 
1981  |  |  | 
1982  |  | /**  | 
1983  |  |  * g_application_get_inactivity_timeout:  | 
1984  |  |  * @application: a #GApplication  | 
1985  |  |  *  | 
1986  |  |  * Gets the current inactivity timeout for the application.  | 
1987  |  |  *  | 
1988  |  |  * This is the amount of time (in milliseconds) after the last call to  | 
1989  |  |  * g_application_release() before the application stops running.  | 
1990  |  |  *  | 
1991  |  |  * Returns: the timeout, in milliseconds  | 
1992  |  |  *  | 
1993  |  |  * Since: 2.28  | 
1994  |  |  **/  | 
1995  |  | guint  | 
1996  |  | g_application_get_inactivity_timeout (GApplication *application)  | 
1997  | 0  | { | 
1998  | 0  |   g_return_val_if_fail (G_IS_APPLICATION (application), 0);  | 
1999  |  |  | 
2000  | 0  |   return application->priv->inactivity_timeout;  | 
2001  | 0  | }  | 
2002  |  |  | 
2003  |  | /**  | 
2004  |  |  * g_application_set_inactivity_timeout:  | 
2005  |  |  * @application: a #GApplication  | 
2006  |  |  * @inactivity_timeout: the timeout, in milliseconds  | 
2007  |  |  *  | 
2008  |  |  * Sets the current inactivity timeout for the application.  | 
2009  |  |  *  | 
2010  |  |  * This is the amount of time (in milliseconds) after the last call to  | 
2011  |  |  * g_application_release() before the application stops running.  | 
2012  |  |  *  | 
2013  |  |  * This call has no side effects of its own.  The value set here is only  | 
2014  |  |  * used for next time g_application_release() drops the use count to  | 
2015  |  |  * zero.  Any timeouts currently in progress are not impacted.  | 
2016  |  |  *  | 
2017  |  |  * Since: 2.28  | 
2018  |  |  **/  | 
2019  |  | void  | 
2020  |  | g_application_set_inactivity_timeout (GApplication *application,  | 
2021  |  |                                       guint         inactivity_timeout)  | 
2022  | 0  | { | 
2023  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
2024  |  |  | 
2025  | 0  |   if (application->priv->inactivity_timeout != inactivity_timeout)  | 
2026  | 0  |     { | 
2027  | 0  |       application->priv->inactivity_timeout = inactivity_timeout;  | 
2028  |  | 
  | 
2029  | 0  |       g_object_notify (G_OBJECT (application), "inactivity-timeout");  | 
2030  | 0  |     }  | 
2031  | 0  | }  | 
2032  |  | /* Read-only property getters (is registered, is remote, dbus stuff) {{{1 */ | 
2033  |  | /**  | 
2034  |  |  * g_application_get_is_registered:  | 
2035  |  |  * @application: a #GApplication  | 
2036  |  |  *  | 
2037  |  |  * Checks if @application is registered.  | 
2038  |  |  *  | 
2039  |  |  * An application is registered if g_application_register() has been  | 
2040  |  |  * successfully called.  | 
2041  |  |  *  | 
2042  |  |  * Returns: %TRUE if @application is registered  | 
2043  |  |  *  | 
2044  |  |  * Since: 2.28  | 
2045  |  |  **/  | 
2046  |  | gboolean  | 
2047  |  | g_application_get_is_registered (GApplication *application)  | 
2048  | 0  | { | 
2049  | 0  |   g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);  | 
2050  |  |  | 
2051  | 0  |   return application->priv->is_registered;  | 
2052  | 0  | }  | 
2053  |  |  | 
2054  |  | /**  | 
2055  |  |  * g_application_get_is_remote:  | 
2056  |  |  * @application: a #GApplication  | 
2057  |  |  *  | 
2058  |  |  * Checks if @application is remote.  | 
2059  |  |  *  | 
2060  |  |  * If @application is remote then it means that another instance of  | 
2061  |  |  * application already exists (the 'primary' instance).  Calls to  | 
2062  |  |  * perform actions on @application will result in the actions being  | 
2063  |  |  * performed by the primary instance.  | 
2064  |  |  *  | 
2065  |  |  * The value of this property cannot be accessed before  | 
2066  |  |  * g_application_register() has been called.  See  | 
2067  |  |  * g_application_get_is_registered().  | 
2068  |  |  *  | 
2069  |  |  * Returns: %TRUE if @application is remote  | 
2070  |  |  *  | 
2071  |  |  * Since: 2.28  | 
2072  |  |  **/  | 
2073  |  | gboolean  | 
2074  |  | g_application_get_is_remote (GApplication *application)  | 
2075  | 0  | { | 
2076  | 0  |   g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);  | 
2077  | 0  |   g_return_val_if_fail (application->priv->is_registered, FALSE);  | 
2078  |  |  | 
2079  | 0  |   return application->priv->is_remote;  | 
2080  | 0  | }  | 
2081  |  |  | 
2082  |  | /**  | 
2083  |  |  * g_application_get_dbus_connection:  | 
2084  |  |  * @application: a #GApplication  | 
2085  |  |  *  | 
2086  |  |  * Gets the #GDBusConnection being used by the application, or %NULL.  | 
2087  |  |  *  | 
2088  |  |  * If #GApplication is using its D-Bus backend then this function will  | 
2089  |  |  * return the #GDBusConnection being used for uniqueness and  | 
2090  |  |  * communication with the desktop environment and other instances of the  | 
2091  |  |  * application.  | 
2092  |  |  *  | 
2093  |  |  * If #GApplication is not using D-Bus then this function will return  | 
2094  |  |  * %NULL.  This includes the situation where the D-Bus backend would  | 
2095  |  |  * normally be in use but we were unable to connect to the bus.  | 
2096  |  |  *  | 
2097  |  |  * This function must not be called before the application has been  | 
2098  |  |  * registered.  See g_application_get_is_registered().  | 
2099  |  |  *  | 
2100  |  |  * Returns: (nullable) (transfer none): a #GDBusConnection, or %NULL  | 
2101  |  |  *  | 
2102  |  |  * Since: 2.34  | 
2103  |  |  **/  | 
2104  |  | GDBusConnection *  | 
2105  |  | g_application_get_dbus_connection (GApplication *application)  | 
2106  | 0  | { | 
2107  | 0  |   g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);  | 
2108  | 0  |   g_return_val_if_fail (application->priv->is_registered, FALSE);  | 
2109  |  |  | 
2110  | 0  |   return g_application_impl_get_dbus_connection (application->priv->impl);  | 
2111  | 0  | }  | 
2112  |  |  | 
2113  |  | /**  | 
2114  |  |  * g_application_get_dbus_object_path:  | 
2115  |  |  * @application: a #GApplication  | 
2116  |  |  *  | 
2117  |  |  * Gets the D-Bus object path being used by the application, or %NULL.  | 
2118  |  |  *  | 
2119  |  |  * If #GApplication is using its D-Bus backend then this function will  | 
2120  |  |  * return the D-Bus object path that #GApplication is using.  If the  | 
2121  |  |  * application is the primary instance then there is an object published  | 
2122  |  |  * at this path.  If the application is not the primary instance then  | 
2123  |  |  * the result of this function is undefined.  | 
2124  |  |  *  | 
2125  |  |  * If #GApplication is not using D-Bus then this function will return  | 
2126  |  |  * %NULL.  This includes the situation where the D-Bus backend would  | 
2127  |  |  * normally be in use but we were unable to connect to the bus.  | 
2128  |  |  *  | 
2129  |  |  * This function must not be called before the application has been  | 
2130  |  |  * registered.  See g_application_get_is_registered().  | 
2131  |  |  *  | 
2132  |  |  * Returns: (nullable): the object path, or %NULL  | 
2133  |  |  *  | 
2134  |  |  * Since: 2.34  | 
2135  |  |  **/  | 
2136  |  | const gchar *  | 
2137  |  | g_application_get_dbus_object_path (GApplication *application)  | 
2138  | 0  | { | 
2139  | 0  |   g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);  | 
2140  | 0  |   g_return_val_if_fail (application->priv->is_registered, FALSE);  | 
2141  |  |  | 
2142  | 0  |   return g_application_impl_get_dbus_object_path (application->priv->impl);  | 
2143  | 0  | }  | 
2144  |  |  | 
2145  |  |  | 
2146  |  | /* Register {{{1 */ | 
2147  |  | /**  | 
2148  |  |  * g_application_register:  | 
2149  |  |  * @application: a #GApplication  | 
2150  |  |  * @cancellable: (nullable): a #GCancellable, or %NULL  | 
2151  |  |  * @error: a pointer to a NULL #GError, or %NULL  | 
2152  |  |  *  | 
2153  |  |  * Attempts registration of the application.  | 
2154  |  |  *  | 
2155  |  |  * This is the point at which the application discovers if it is the  | 
2156  |  |  * primary instance or merely acting as a remote for an already-existing  | 
2157  |  |  * primary instance.  This is implemented by attempting to acquire the  | 
2158  |  |  * application identifier as a unique bus name on the session bus using  | 
2159  |  |  * GDBus.  | 
2160  |  |  *  | 
2161  |  |  * If there is no application ID or if %G_APPLICATION_NON_UNIQUE was  | 
2162  |  |  * given, then this process will always become the primary instance.  | 
2163  |  |  *  | 
2164  |  |  * Due to the internal architecture of GDBus, method calls can be  | 
2165  |  |  * dispatched at any time (even if a main loop is not running).  For  | 
2166  |  |  * this reason, you must ensure that any object paths that you wish to  | 
2167  |  |  * register are registered before calling this function.  | 
2168  |  |  *  | 
2169  |  |  * If the application has already been registered then %TRUE is  | 
2170  |  |  * returned with no work performed.  | 
2171  |  |  *  | 
2172  |  |  * The #GApplication::startup signal is emitted if registration succeeds  | 
2173  |  |  * and @application is the primary instance (including the non-unique  | 
2174  |  |  * case).  | 
2175  |  |  *  | 
2176  |  |  * In the event of an error (such as @cancellable being cancelled, or a  | 
2177  |  |  * failure to connect to the session bus), %FALSE is returned and @error  | 
2178  |  |  * is set appropriately.  | 
2179  |  |  *  | 
2180  |  |  * Note: the return value of this function is not an indicator that this  | 
2181  |  |  * instance is or is not the primary instance of the application.  See  | 
2182  |  |  * g_application_get_is_remote() for that.  | 
2183  |  |  *  | 
2184  |  |  * Returns: %TRUE if registration succeeded  | 
2185  |  |  *  | 
2186  |  |  * Since: 2.28  | 
2187  |  |  **/  | 
2188  |  | gboolean  | 
2189  |  | g_application_register (GApplication  *application,  | 
2190  |  |                         GCancellable  *cancellable,  | 
2191  |  |                         GError       **error)  | 
2192  | 0  | { | 
2193  | 0  |   g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);  | 
2194  |  |  | 
2195  | 0  |   if (!application->priv->is_registered)  | 
2196  | 0  |     { | 
2197  | 0  |       if (application->priv->id == NULL)  | 
2198  | 0  |         application->priv->flags |= G_APPLICATION_NON_UNIQUE;  | 
2199  |  | 
  | 
2200  | 0  |       application->priv->impl =  | 
2201  | 0  |         g_application_impl_register (application, application->priv->id,  | 
2202  | 0  |                                      application->priv->flags,  | 
2203  | 0  |                                      application->priv->actions,  | 
2204  | 0  |                                      &application->priv->remote_actions,  | 
2205  | 0  |                                      cancellable, error);  | 
2206  |  | 
  | 
2207  | 0  |       if (application->priv->impl == NULL)  | 
2208  | 0  |         return FALSE;  | 
2209  |  |  | 
2210  | 0  |       application->priv->is_remote = application->priv->remote_actions != NULL;  | 
2211  | 0  |       application->priv->is_registered = TRUE;  | 
2212  |  | 
  | 
2213  | 0  |       g_object_notify (G_OBJECT (application), "is-registered");  | 
2214  |  | 
  | 
2215  | 0  |       if (!application->priv->is_remote)  | 
2216  | 0  |         { | 
2217  | 0  |           g_signal_emit (application, g_application_signals[SIGNAL_STARTUP], 0);  | 
2218  |  | 
  | 
2219  | 0  |           if (!application->priv->did_startup)  | 
2220  | 0  |             g_critical ("GApplication subclass '%s' failed to chain up on" | 
2221  | 0  |                         " ::startup (from start of override function)",  | 
2222  | 0  |                         G_OBJECT_TYPE_NAME (application));  | 
2223  | 0  |         }  | 
2224  | 0  |     }  | 
2225  |  |  | 
2226  | 0  |   return TRUE;  | 
2227  | 0  | }  | 
2228  |  |  | 
2229  |  | /* Hold/release {{{1 */ | 
2230  |  | /**  | 
2231  |  |  * g_application_hold:  | 
2232  |  |  * @application: a #GApplication  | 
2233  |  |  *  | 
2234  |  |  * Increases the use count of @application.  | 
2235  |  |  *  | 
2236  |  |  * Use this function to indicate that the application has a reason to  | 
2237  |  |  * continue to run.  For example, g_application_hold() is called by GTK  | 
2238  |  |  * when a toplevel window is on the screen.  | 
2239  |  |  *  | 
2240  |  |  * To cancel the hold, call g_application_release().  | 
2241  |  |  **/  | 
2242  |  | void  | 
2243  |  | g_application_hold (GApplication *application)  | 
2244  | 0  | { | 
2245  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
2246  |  |  | 
2247  | 0  |   if (application->priv->inactivity_timeout_id)  | 
2248  | 0  |     { | 
2249  | 0  |       g_source_remove (application->priv->inactivity_timeout_id);  | 
2250  | 0  |       application->priv->inactivity_timeout_id = 0;  | 
2251  | 0  |     }  | 
2252  |  | 
  | 
2253  | 0  |   application->priv->use_count++;  | 
2254  | 0  | }  | 
2255  |  |  | 
2256  |  | static gboolean  | 
2257  |  | inactivity_timeout_expired (gpointer data)  | 
2258  | 0  | { | 
2259  | 0  |   GApplication *application = G_APPLICATION (data);  | 
2260  |  | 
  | 
2261  | 0  |   application->priv->inactivity_timeout_id = 0;  | 
2262  |  | 
  | 
2263  | 0  |   return G_SOURCE_REMOVE;  | 
2264  | 0  | }  | 
2265  |  |  | 
2266  |  |  | 
2267  |  | /**  | 
2268  |  |  * g_application_release:  | 
2269  |  |  * @application: a #GApplication  | 
2270  |  |  *  | 
2271  |  |  * Decrease the use count of @application.  | 
2272  |  |  *  | 
2273  |  |  * When the use count reaches zero, the application will stop running.  | 
2274  |  |  *  | 
2275  |  |  * Never call this function except to cancel the effect of a previous  | 
2276  |  |  * call to g_application_hold().  | 
2277  |  |  **/  | 
2278  |  | void  | 
2279  |  | g_application_release (GApplication *application)  | 
2280  | 0  | { | 
2281  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
2282  | 0  |   g_return_if_fail (application->priv->use_count > 0);  | 
2283  |  |  | 
2284  | 0  |   application->priv->use_count--;  | 
2285  |  | 
  | 
2286  | 0  |   if (application->priv->use_count == 0 && application->priv->inactivity_timeout)  | 
2287  | 0  |     application->priv->inactivity_timeout_id = g_timeout_add (application->priv->inactivity_timeout,  | 
2288  | 0  |                                                               inactivity_timeout_expired, application);  | 
2289  | 0  | }  | 
2290  |  |  | 
2291  |  | /* Activate, Open {{{1 */ | 
2292  |  | /**  | 
2293  |  |  * g_application_activate:  | 
2294  |  |  * @application: a #GApplication  | 
2295  |  |  *  | 
2296  |  |  * Activates the application.  | 
2297  |  |  *  | 
2298  |  |  * In essence, this results in the #GApplication::activate signal being  | 
2299  |  |  * emitted in the primary instance.  | 
2300  |  |  *  | 
2301  |  |  * The application must be registered before calling this function.  | 
2302  |  |  *  | 
2303  |  |  * Since: 2.28  | 
2304  |  |  **/  | 
2305  |  | void  | 
2306  |  | g_application_activate (GApplication *application)  | 
2307  | 0  | { | 
2308  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
2309  | 0  |   g_return_if_fail (application->priv->is_registered);  | 
2310  |  |  | 
2311  | 0  |   if (application->priv->is_remote)  | 
2312  | 0  |     g_application_impl_activate (application->priv->impl,  | 
2313  | 0  |                                  get_platform_data (application, NULL));  | 
2314  |  |  | 
2315  | 0  |   else  | 
2316  | 0  |     g_signal_emit (application, g_application_signals[SIGNAL_ACTIVATE], 0);  | 
2317  | 0  | }  | 
2318  |  |  | 
2319  |  | /**  | 
2320  |  |  * g_application_open:  | 
2321  |  |  * @application: a #GApplication  | 
2322  |  |  * @files: (array length=n_files): an array of #GFiles to open  | 
2323  |  |  * @n_files: the length of the @files array  | 
2324  |  |  * @hint: a hint (or ""), but never %NULL  | 
2325  |  |  *  | 
2326  |  |  * Opens the given files.  | 
2327  |  |  *  | 
2328  |  |  * In essence, this results in the #GApplication::open signal being emitted  | 
2329  |  |  * in the primary instance.  | 
2330  |  |  *  | 
2331  |  |  * @n_files must be greater than zero.  | 
2332  |  |  *  | 
2333  |  |  * @hint is simply passed through to the ::open signal.  It is  | 
2334  |  |  * intended to be used by applications that have multiple modes for  | 
2335  |  |  * opening files (eg: "view" vs "edit", etc).  Unless you have a need  | 
2336  |  |  * for this functionality, you should use "".  | 
2337  |  |  *  | 
2338  |  |  * The application must be registered before calling this function  | 
2339  |  |  * and it must have the %G_APPLICATION_HANDLES_OPEN flag set.  | 
2340  |  |  *  | 
2341  |  |  * Since: 2.28  | 
2342  |  |  **/  | 
2343  |  | void  | 
2344  |  | g_application_open (GApplication  *application,  | 
2345  |  |                     GFile        **files,  | 
2346  |  |                     gint           n_files,  | 
2347  |  |                     const gchar   *hint)  | 
2348  | 0  | { | 
2349  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
2350  | 0  |   g_return_if_fail (application->priv->flags &  | 
2351  | 0  |                     G_APPLICATION_HANDLES_OPEN);  | 
2352  | 0  |   g_return_if_fail (application->priv->is_registered);  | 
2353  |  |  | 
2354  | 0  |   if (application->priv->is_remote)  | 
2355  | 0  |     g_application_impl_open (application->priv->impl,  | 
2356  | 0  |                              files, n_files, hint,  | 
2357  | 0  |                              get_platform_data (application, NULL));  | 
2358  |  |  | 
2359  | 0  |   else  | 
2360  | 0  |     g_signal_emit (application, g_application_signals[SIGNAL_OPEN],  | 
2361  | 0  |                    0, files, n_files, hint);  | 
2362  | 0  | }  | 
2363  |  |  | 
2364  |  | /* Run {{{1 */ | 
2365  |  | /**  | 
2366  |  |  * g_application_run:  | 
2367  |  |  * @application: a #GApplication  | 
2368  |  |  * @argc: the argc from main() (or 0 if @argv is %NULL)  | 
2369  |  |  * @argv: (array length=argc) (element-type filename) (nullable):  | 
2370  |  |  *     the argv from main(), or %NULL  | 
2371  |  |  *  | 
2372  |  |  * Runs the application.  | 
2373  |  |  *  | 
2374  |  |  * This function is intended to be run from main() and its return value  | 
2375  |  |  * is intended to be returned by main(). Although you are expected to pass  | 
2376  |  |  * the @argc, @argv parameters from main() to this function, it is possible  | 
2377  |  |  * to pass %NULL if @argv is not available or commandline handling is not  | 
2378  |  |  * required.  Note that on Windows, @argc and @argv are ignored, and  | 
2379  |  |  * g_win32_get_command_line() is called internally (for proper support  | 
2380  |  |  * of Unicode commandline arguments).  | 
2381  |  |  *  | 
2382  |  |  * #GApplication will attempt to parse the commandline arguments.  You  | 
2383  |  |  * can add commandline flags to the list of recognised options by way of  | 
2384  |  |  * g_application_add_main_option_entries().  After this, the  | 
2385  |  |  * #GApplication::handle-local-options signal is emitted, from which the  | 
2386  |  |  * application can inspect the values of its #GOptionEntrys.  | 
2387  |  |  *  | 
2388  |  |  * #GApplication::handle-local-options is a good place to handle options  | 
2389  |  |  * such as `--version`, where an immediate reply from the local process is  | 
2390  |  |  * desired (instead of communicating with an already-running instance).  | 
2391  |  |  * A #GApplication::handle-local-options handler can stop further processing  | 
2392  |  |  * by returning a non-negative value, which then becomes the exit status of  | 
2393  |  |  * the process.  | 
2394  |  |  *  | 
2395  |  |  * What happens next depends on the flags: if  | 
2396  |  |  * %G_APPLICATION_HANDLES_COMMAND_LINE was specified then the remaining  | 
2397  |  |  * commandline arguments are sent to the primary instance, where a  | 
2398  |  |  * #GApplication::command-line signal is emitted.  Otherwise, the  | 
2399  |  |  * remaining commandline arguments are assumed to be a list of files.  | 
2400  |  |  * If there are no files listed, the application is activated via the  | 
2401  |  |  * #GApplication::activate signal.  If there are one or more files, and  | 
2402  |  |  * %G_APPLICATION_HANDLES_OPEN was specified then the files are opened  | 
2403  |  |  * via the #GApplication::open signal.  | 
2404  |  |  *  | 
2405  |  |  * If you are interested in doing more complicated local handling of the  | 
2406  |  |  * commandline then you should implement your own #GApplication subclass  | 
2407  |  |  * and override local_command_line(). In this case, you most likely want  | 
2408  |  |  * to return %TRUE from your local_command_line() implementation to  | 
2409  |  |  * suppress the default handling. See  | 
2410  |  |  * [gapplication-example-cmdline2.c][https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-cmdline2.c]  | 
2411  |  |  * for an example.  | 
2412  |  |  *  | 
2413  |  |  * If, after the above is done, the use count of the application is zero  | 
2414  |  |  * then the exit status is returned immediately.  If the use count is  | 
2415  |  |  * non-zero then the default main context is iterated until the use count  | 
2416  |  |  * falls to zero, at which point 0 is returned.  | 
2417  |  |  *  | 
2418  |  |  * If the %G_APPLICATION_IS_SERVICE flag is set, then the service will  | 
2419  |  |  * run for as much as 10 seconds with a use count of zero while waiting  | 
2420  |  |  * for the message that caused the activation to arrive.  After that,  | 
2421  |  |  * if the use count falls to zero the application will exit immediately,  | 
2422  |  |  * except in the case that g_application_set_inactivity_timeout() is in  | 
2423  |  |  * use.  | 
2424  |  |  *  | 
2425  |  |  * This function sets the prgname (g_set_prgname()), if not already set,  | 
2426  |  |  * to the basename of argv[0].  | 
2427  |  |  *  | 
2428  |  |  * Much like g_main_loop_run(), this function will acquire the main context  | 
2429  |  |  * for the duration that the application is running.  | 
2430  |  |  *  | 
2431  |  |  * Since 2.40, applications that are not explicitly flagged as services  | 
2432  |  |  * or launchers (ie: neither %G_APPLICATION_IS_SERVICE or  | 
2433  |  |  * %G_APPLICATION_IS_LAUNCHER are given as flags) will check (from the  | 
2434  |  |  * default handler for local_command_line) if "--gapplication-service"  | 
2435  |  |  * was given in the command line.  If this flag is present then normal  | 
2436  |  |  * commandline processing is interrupted and the  | 
2437  |  |  * %G_APPLICATION_IS_SERVICE flag is set.  This provides a "compromise"  | 
2438  |  |  * solution whereby running an application directly from the commandline  | 
2439  |  |  * will invoke it in the normal way (which can be useful for debugging)  | 
2440  |  |  * while still allowing applications to be D-Bus activated in service  | 
2441  |  |  * mode.  The D-Bus service file should invoke the executable with  | 
2442  |  |  * "--gapplication-service" as the sole commandline argument.  This  | 
2443  |  |  * approach is suitable for use by most graphical applications but  | 
2444  |  |  * should not be used from applications like editors that need precise  | 
2445  |  |  * control over when processes invoked via the commandline will exit and  | 
2446  |  |  * what their exit status will be.  | 
2447  |  |  *  | 
2448  |  |  * Returns: the exit status  | 
2449  |  |  *  | 
2450  |  |  * Since: 2.28  | 
2451  |  |  **/  | 
2452  |  | int  | 
2453  |  | g_application_run (GApplication  *application,  | 
2454  |  |                    int            argc,  | 
2455  |  |                    char         **argv)  | 
2456  | 0  | { | 
2457  | 0  |   gchar **arguments;  | 
2458  | 0  |   int status;  | 
2459  | 0  |   GMainContext *context;  | 
2460  | 0  |   gboolean acquired_context;  | 
2461  |  | 
  | 
2462  | 0  |   g_return_val_if_fail (G_IS_APPLICATION (application), 1);  | 
2463  | 0  |   g_return_val_if_fail (argc == 0 || argv != NULL, 1);  | 
2464  | 0  |   g_return_val_if_fail (!application->priv->must_quit_now, 1);  | 
2465  |  |  | 
2466  |  | #ifdef G_OS_WIN32  | 
2467  |  |   { | 
2468  |  |     gint new_argc = 0;  | 
2469  |  |  | 
2470  |  |     arguments = g_win32_get_command_line ();  | 
2471  |  |  | 
2472  |  |     /*  | 
2473  |  |      * CommandLineToArgvW(), which is called by g_win32_get_command_line(),  | 
2474  |  |      * pulls in the whole command line that is used to call the program.  This is  | 
2475  |  |      * fine in cases where the program is a .exe program, but in the cases where the  | 
2476  |  |      * program is a called via a script, such as PyGObject's gtk-demo.py, which is normally  | 
2477  |  |      * called using 'python gtk-demo.py' on Windows, the program name (argv[0])  | 
2478  |  |      * returned by g_win32_get_command_line() will not be the argv[0] that ->local_command_line()  | 
2479  |  |      * would expect, causing the program to fail with "This application can not open files."  | 
2480  |  |      */  | 
2481  |  |     new_argc = g_strv_length (arguments);  | 
2482  |  |  | 
2483  |  |     if (new_argc > argc)  | 
2484  |  |       { | 
2485  |  |         gint i;  | 
2486  |  |  | 
2487  |  |         for (i = 0; i < new_argc - argc; i++)  | 
2488  |  |           g_free (arguments[i]);  | 
2489  |  |  | 
2490  |  |         memmove (&arguments[0],  | 
2491  |  |                  &arguments[new_argc - argc],  | 
2492  |  |                  sizeof (arguments[0]) * (argc + 1));  | 
2493  |  |       }  | 
2494  |  |   }  | 
2495  |  | #elif defined(__APPLE__)  | 
2496  |  |   { | 
2497  |  |     gint i, j;  | 
2498  |  |  | 
2499  |  |     /*  | 
2500  |  |      * OSX adds an unexpected parameter on the format -psn_X_XXXXXX  | 
2501  |  |      * when opening the application using Launch Services. In order  | 
2502  |  |      * to avoid that GOption fails to parse this parameter we just  | 
2503  |  |      * skip it if it was provided.  | 
2504  |  |      * See: https://gitlab.gnome.org/GNOME/glib/issues/1784  | 
2505  |  |      */  | 
2506  |  |     arguments = g_new (gchar *, argc + 1);  | 
2507  |  |     for (i = 0, j = 0; i < argc; i++)  | 
2508  |  |       { | 
2509  |  |         if (!g_str_has_prefix (argv[i], "-psn_"))  | 
2510  |  |           { | 
2511  |  |             arguments[j] = g_strdup (argv[i]);  | 
2512  |  |             j++;  | 
2513  |  |           }  | 
2514  |  |       }  | 
2515  |  |     arguments[j] = NULL;  | 
2516  |  |   }  | 
2517  |  | #else  | 
2518  | 0  |   { | 
2519  | 0  |     gint i;  | 
2520  |  | 
  | 
2521  | 0  |     arguments = g_new (gchar *, argc + 1);  | 
2522  | 0  |     for (i = 0; i < argc; i++)  | 
2523  | 0  |       arguments[i] = g_strdup (argv[i]);  | 
2524  | 0  |     arguments[i] = NULL;  | 
2525  | 0  |   }  | 
2526  | 0  | #endif  | 
2527  |  | 
  | 
2528  | 0  |   if (g_get_prgname () == NULL && argc > 0)  | 
2529  | 0  |     { | 
2530  | 0  |       gchar *prgname;  | 
2531  |  | 
  | 
2532  | 0  |       prgname = g_path_get_basename (argv[0]);  | 
2533  | 0  |       g_set_prgname (prgname);  | 
2534  | 0  |       g_free (prgname);  | 
2535  | 0  |     }  | 
2536  |  | 
  | 
2537  | 0  |   context = g_main_context_default ();  | 
2538  | 0  |   acquired_context = g_main_context_acquire (context);  | 
2539  | 0  |   if (!acquired_context)  | 
2540  | 0  |     { | 
2541  | 0  |       g_critical ("g_application_run() cannot acquire the default main context because it is already acquired by another thread!"); | 
2542  | 0  |       g_strfreev (arguments);  | 
2543  | 0  |       return 1;  | 
2544  | 0  |     }  | 
2545  |  |  | 
2546  | 0  |   if (!G_APPLICATION_GET_CLASS (application)  | 
2547  | 0  |         ->local_command_line (application, &arguments, &status))  | 
2548  | 0  |     { | 
2549  | 0  |       GError *error = NULL;  | 
2550  |  | 
  | 
2551  | 0  |       if (!g_application_register (application, NULL, &error))  | 
2552  | 0  |         { | 
2553  | 0  |           g_printerr ("Failed to register: %s\n", error->message); | 
2554  | 0  |           g_error_free (error);  | 
2555  | 0  |           return 1;  | 
2556  | 0  |         }  | 
2557  |  |  | 
2558  | 0  |       g_application_call_command_line (application, (const gchar **) arguments, NULL, &status);  | 
2559  | 0  |     }  | 
2560  |  |  | 
2561  | 0  |   g_strfreev (arguments);  | 
2562  |  | 
  | 
2563  | 0  |   if (application->priv->flags & G_APPLICATION_IS_SERVICE &&  | 
2564  | 0  |       application->priv->is_registered &&  | 
2565  | 0  |       !application->priv->use_count &&  | 
2566  | 0  |       !application->priv->inactivity_timeout_id)  | 
2567  | 0  |     { | 
2568  | 0  |       application->priv->inactivity_timeout_id =  | 
2569  | 0  |         g_timeout_add (10000, inactivity_timeout_expired, application);  | 
2570  | 0  |     }  | 
2571  |  | 
  | 
2572  | 0  |   while (application->priv->use_count || application->priv->inactivity_timeout_id)  | 
2573  | 0  |     { | 
2574  | 0  |       if (application->priv->must_quit_now)  | 
2575  | 0  |         break;  | 
2576  |  |  | 
2577  | 0  |       g_main_context_iteration (context, TRUE);  | 
2578  | 0  |       status = 0;  | 
2579  | 0  |     }  | 
2580  |  | 
  | 
2581  | 0  |   if (application->priv->is_registered && !application->priv->is_remote)  | 
2582  | 0  |     { | 
2583  | 0  |       g_signal_emit (application, g_application_signals[SIGNAL_SHUTDOWN], 0);  | 
2584  |  | 
  | 
2585  | 0  |       if (!application->priv->did_shutdown)  | 
2586  | 0  |         g_critical ("GApplication subclass '%s' failed to chain up on" | 
2587  | 0  |                     " ::shutdown (from end of override function)",  | 
2588  | 0  |                     G_OBJECT_TYPE_NAME (application));  | 
2589  | 0  |     }  | 
2590  |  | 
  | 
2591  | 0  |   if (application->priv->impl)  | 
2592  | 0  |     { | 
2593  | 0  |       if (application->priv->is_registered)  | 
2594  | 0  |         { | 
2595  | 0  |           application->priv->is_registered = FALSE;  | 
2596  |  | 
  | 
2597  | 0  |           g_object_notify (G_OBJECT (application), "is-registered");  | 
2598  | 0  |         }  | 
2599  |  | 
  | 
2600  | 0  |       g_application_impl_flush (application->priv->impl);  | 
2601  | 0  |       g_application_impl_destroy (application->priv->impl);  | 
2602  | 0  |       application->priv->impl = NULL;  | 
2603  | 0  |     }  | 
2604  |  | 
  | 
2605  | 0  |   g_settings_sync ();  | 
2606  |  | 
  | 
2607  | 0  |   if (!application->priv->must_quit_now)  | 
2608  | 0  |     while (g_main_context_iteration (context, FALSE))  | 
2609  | 0  |       ;  | 
2610  |  | 
  | 
2611  | 0  |   g_main_context_release (context);  | 
2612  |  | 
  | 
2613  | 0  |   return status;  | 
2614  | 0  | }  | 
2615  |  |  | 
2616  |  | static gchar **  | 
2617  |  | g_application_list_actions (GActionGroup *action_group)  | 
2618  | 0  | { | 
2619  | 0  |   GApplication *application = G_APPLICATION (action_group);  | 
2620  |  | 
  | 
2621  | 0  |   g_return_val_if_fail (application->priv->is_registered, NULL);  | 
2622  |  |  | 
2623  | 0  |   if (application->priv->remote_actions != NULL)  | 
2624  | 0  |     return g_action_group_list_actions (G_ACTION_GROUP (application->priv->remote_actions));  | 
2625  |  |  | 
2626  | 0  |   else if (application->priv->actions != NULL)  | 
2627  | 0  |     return g_action_group_list_actions (application->priv->actions);  | 
2628  |  |  | 
2629  | 0  |   else  | 
2630  |  |     /* empty string array */  | 
2631  | 0  |     return g_new0 (gchar *, 1);  | 
2632  | 0  | }  | 
2633  |  |  | 
2634  |  | static gboolean  | 
2635  |  | g_application_query_action (GActionGroup        *group,  | 
2636  |  |                             const gchar         *action_name,  | 
2637  |  |                             gboolean            *enabled,  | 
2638  |  |                             const GVariantType **parameter_type,  | 
2639  |  |                             const GVariantType **state_type,  | 
2640  |  |                             GVariant           **state_hint,  | 
2641  |  |                             GVariant           **state)  | 
2642  | 0  | { | 
2643  | 0  |   GApplication *application = G_APPLICATION (group);  | 
2644  |  | 
  | 
2645  | 0  |   g_return_val_if_fail (application->priv->is_registered, FALSE);  | 
2646  |  |  | 
2647  | 0  |   if (application->priv->remote_actions != NULL)  | 
2648  | 0  |     return g_action_group_query_action (G_ACTION_GROUP (application->priv->remote_actions),  | 
2649  | 0  |                                         action_name,  | 
2650  | 0  |                                         enabled,  | 
2651  | 0  |                                         parameter_type,  | 
2652  | 0  |                                         state_type,  | 
2653  | 0  |                                         state_hint,  | 
2654  | 0  |                                         state);  | 
2655  |  |  | 
2656  | 0  |   if (application->priv->actions != NULL)  | 
2657  | 0  |     return g_action_group_query_action (application->priv->actions,  | 
2658  | 0  |                                         action_name,  | 
2659  | 0  |                                         enabled,  | 
2660  | 0  |                                         parameter_type,  | 
2661  | 0  |                                         state_type,  | 
2662  | 0  |                                         state_hint,  | 
2663  | 0  |                                         state);  | 
2664  |  |  | 
2665  | 0  |   return FALSE;  | 
2666  | 0  | }  | 
2667  |  |  | 
2668  |  | static void  | 
2669  |  | g_application_change_action_state (GActionGroup *action_group,  | 
2670  |  |                                    const gchar  *action_name,  | 
2671  |  |                                    GVariant     *value)  | 
2672  | 0  | { | 
2673  | 0  |   GApplication *application = G_APPLICATION (action_group);  | 
2674  |  | 
  | 
2675  | 0  |   g_return_if_fail (application->priv->is_remote ||  | 
2676  | 0  |                     application->priv->actions != NULL);  | 
2677  | 0  |   g_return_if_fail (application->priv->is_registered);  | 
2678  |  |  | 
2679  | 0  |   if (application->priv->remote_actions)  | 
2680  | 0  |     g_remote_action_group_change_action_state_full (application->priv->remote_actions,  | 
2681  | 0  |                                                     action_name, value, get_platform_data (application, NULL));  | 
2682  |  |  | 
2683  | 0  |   else  | 
2684  | 0  |     g_action_group_change_action_state (application->priv->actions, action_name, value);  | 
2685  | 0  | }  | 
2686  |  |  | 
2687  |  | static void  | 
2688  |  | g_application_activate_action (GActionGroup *action_group,  | 
2689  |  |                                const gchar  *action_name,  | 
2690  |  |                                GVariant     *parameter)  | 
2691  | 0  | { | 
2692  | 0  |   GApplication *application = G_APPLICATION (action_group);  | 
2693  |  | 
  | 
2694  | 0  |   g_return_if_fail (application->priv->is_remote ||  | 
2695  | 0  |                     application->priv->actions != NULL);  | 
2696  | 0  |   g_return_if_fail (application->priv->is_registered);  | 
2697  |  |  | 
2698  | 0  |   if (application->priv->remote_actions)  | 
2699  | 0  |     g_remote_action_group_activate_action_full (application->priv->remote_actions,  | 
2700  | 0  |                                                 action_name, parameter, get_platform_data (application, NULL));  | 
2701  |  |  | 
2702  | 0  |   else  | 
2703  | 0  |     g_action_group_activate_action (application->priv->actions, action_name, parameter);  | 
2704  | 0  | }  | 
2705  |  |  | 
2706  |  | static GAction *  | 
2707  |  | g_application_lookup_action (GActionMap  *action_map,  | 
2708  |  |                              const gchar *action_name)  | 
2709  | 0  | { | 
2710  | 0  |   GApplication *application = G_APPLICATION (action_map);  | 
2711  |  | 
  | 
2712  | 0  |   g_return_val_if_fail (G_IS_ACTION_MAP (application->priv->actions), NULL);  | 
2713  |  |  | 
2714  | 0  |   return g_action_map_lookup_action (G_ACTION_MAP (application->priv->actions), action_name);  | 
2715  | 0  | }  | 
2716  |  |  | 
2717  |  | static void  | 
2718  |  | g_application_add_action (GActionMap *action_map,  | 
2719  |  |                           GAction    *action)  | 
2720  | 0  | { | 
2721  | 0  |   GApplication *application = G_APPLICATION (action_map);  | 
2722  |  | 
  | 
2723  | 0  |   g_return_if_fail (G_IS_ACTION_MAP (application->priv->actions));  | 
2724  |  |  | 
2725  | 0  |   g_action_map_add_action (G_ACTION_MAP (application->priv->actions), action);  | 
2726  | 0  | }  | 
2727  |  |  | 
2728  |  | static void  | 
2729  |  | g_application_remove_action (GActionMap  *action_map,  | 
2730  |  |                              const gchar *action_name)  | 
2731  | 0  | { | 
2732  | 0  |   GApplication *application = G_APPLICATION (action_map);  | 
2733  |  | 
  | 
2734  | 0  |   g_return_if_fail (G_IS_ACTION_MAP (application->priv->actions));  | 
2735  |  |  | 
2736  | 0  |   g_action_map_remove_action (G_ACTION_MAP (application->priv->actions), action_name);  | 
2737  | 0  | }  | 
2738  |  |  | 
2739  |  | static void  | 
2740  |  | g_application_action_group_iface_init (GActionGroupInterface *iface)  | 
2741  | 0  | { | 
2742  | 0  |   iface->list_actions = g_application_list_actions;  | 
2743  | 0  |   iface->query_action = g_application_query_action;  | 
2744  | 0  |   iface->change_action_state = g_application_change_action_state;  | 
2745  | 0  |   iface->activate_action = g_application_activate_action;  | 
2746  | 0  | }  | 
2747  |  |  | 
2748  |  | static void  | 
2749  |  | g_application_action_map_iface_init (GActionMapInterface *iface)  | 
2750  | 0  | { | 
2751  | 0  |   iface->lookup_action = g_application_lookup_action;  | 
2752  | 0  |   iface->add_action = g_application_add_action;  | 
2753  | 0  |   iface->remove_action = g_application_remove_action;  | 
2754  | 0  | }  | 
2755  |  |  | 
2756  |  | /* Default Application {{{1 */ | 
2757  |  |  | 
2758  |  | static GApplication *default_app;  | 
2759  |  |  | 
2760  |  | /**  | 
2761  |  |  * g_application_get_default:  | 
2762  |  |  *  | 
2763  |  |  * Returns the default #GApplication instance for this process.  | 
2764  |  |  *  | 
2765  |  |  * Normally there is only one #GApplication per process and it becomes  | 
2766  |  |  * the default when it is created.  You can exercise more control over  | 
2767  |  |  * this by using g_application_set_default().  | 
2768  |  |  *  | 
2769  |  |  * If there is no default application then %NULL is returned.  | 
2770  |  |  *  | 
2771  |  |  * Returns: (nullable) (transfer none): the default application for this process, or %NULL  | 
2772  |  |  *  | 
2773  |  |  * Since: 2.32  | 
2774  |  |  **/  | 
2775  |  | GApplication *  | 
2776  |  | g_application_get_default (void)  | 
2777  | 0  | { | 
2778  | 0  |   return default_app;  | 
2779  | 0  | }  | 
2780  |  |  | 
2781  |  | /**  | 
2782  |  |  * g_application_set_default:  | 
2783  |  |  * @application: (nullable): the application to set as default, or %NULL  | 
2784  |  |  *  | 
2785  |  |  * Sets or unsets the default application for the process, as returned  | 
2786  |  |  * by g_application_get_default().  | 
2787  |  |  *  | 
2788  |  |  * This function does not take its own reference on @application.  If  | 
2789  |  |  * @application is destroyed then the default application will revert  | 
2790  |  |  * back to %NULL.  | 
2791  |  |  *  | 
2792  |  |  * Since: 2.32  | 
2793  |  |  **/  | 
2794  |  | void  | 
2795  |  | g_application_set_default (GApplication *application)  | 
2796  | 0  | { | 
2797  | 0  |   default_app = application;  | 
2798  | 0  | }  | 
2799  |  |  | 
2800  |  | /**  | 
2801  |  |  * g_application_quit:  | 
2802  |  |  * @application: a #GApplication  | 
2803  |  |  *  | 
2804  |  |  * Immediately quits the application.  | 
2805  |  |  *  | 
2806  |  |  * Upon return to the mainloop, g_application_run() will return,  | 
2807  |  |  * calling only the 'shutdown' function before doing so.  | 
2808  |  |  *  | 
2809  |  |  * The hold count is ignored.  | 
2810  |  |  * Take care if your code has called g_application_hold() on the application and  | 
2811  |  |  * is therefore still expecting it to exist.  | 
2812  |  |  * (Note that you may have called g_application_hold() indirectly, for example  | 
2813  |  |  * through gtk_application_add_window().)  | 
2814  |  |  *  | 
2815  |  |  * The result of calling g_application_run() again after it returns is  | 
2816  |  |  * unspecified.  | 
2817  |  |  *  | 
2818  |  |  * Since: 2.32  | 
2819  |  |  **/  | 
2820  |  | void  | 
2821  |  | g_application_quit (GApplication *application)  | 
2822  | 0  | { | 
2823  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
2824  |  |  | 
2825  | 0  |   application->priv->must_quit_now = TRUE;  | 
2826  | 0  | }  | 
2827  |  |  | 
2828  |  | /**  | 
2829  |  |  * g_application_mark_busy:  | 
2830  |  |  * @application: a #GApplication  | 
2831  |  |  *  | 
2832  |  |  * Increases the busy count of @application.  | 
2833  |  |  *  | 
2834  |  |  * Use this function to indicate that the application is busy, for instance  | 
2835  |  |  * while a long running operation is pending.  | 
2836  |  |  *  | 
2837  |  |  * The busy state will be exposed to other processes, so a session shell will  | 
2838  |  |  * use that information to indicate the state to the user (e.g. with a  | 
2839  |  |  * spinner).  | 
2840  |  |  *  | 
2841  |  |  * To cancel the busy indication, use g_application_unmark_busy().  | 
2842  |  |  *  | 
2843  |  |  * The application must be registered before calling this function.  | 
2844  |  |  *  | 
2845  |  |  * Since: 2.38  | 
2846  |  |  **/  | 
2847  |  | void  | 
2848  |  | g_application_mark_busy (GApplication *application)  | 
2849  | 0  | { | 
2850  | 0  |   gboolean was_busy;  | 
2851  |  | 
  | 
2852  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
2853  | 0  |   g_return_if_fail (application->priv->is_registered);  | 
2854  |  |  | 
2855  | 0  |   was_busy = (application->priv->busy_count > 0);  | 
2856  | 0  |   application->priv->busy_count++;  | 
2857  |  | 
  | 
2858  | 0  |   if (!was_busy)  | 
2859  | 0  |     { | 
2860  | 0  |       g_application_impl_set_busy_state (application->priv->impl, TRUE);  | 
2861  | 0  |       g_object_notify (G_OBJECT (application), "is-busy");  | 
2862  | 0  |     }  | 
2863  | 0  | }  | 
2864  |  |  | 
2865  |  | /**  | 
2866  |  |  * g_application_unmark_busy:  | 
2867  |  |  * @application: a #GApplication  | 
2868  |  |  *  | 
2869  |  |  * Decreases the busy count of @application.  | 
2870  |  |  *  | 
2871  |  |  * When the busy count reaches zero, the new state will be propagated  | 
2872  |  |  * to other processes.  | 
2873  |  |  *  | 
2874  |  |  * This function must only be called to cancel the effect of a previous  | 
2875  |  |  * call to g_application_mark_busy().  | 
2876  |  |  *  | 
2877  |  |  * Since: 2.38  | 
2878  |  |  **/  | 
2879  |  | void  | 
2880  |  | g_application_unmark_busy (GApplication *application)  | 
2881  | 0  | { | 
2882  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
2883  | 0  |   g_return_if_fail (application->priv->busy_count > 0);  | 
2884  |  |  | 
2885  | 0  |   application->priv->busy_count--;  | 
2886  |  | 
  | 
2887  | 0  |   if (application->priv->busy_count == 0)  | 
2888  | 0  |     { | 
2889  | 0  |       g_application_impl_set_busy_state (application->priv->impl, FALSE);  | 
2890  | 0  |       g_object_notify (G_OBJECT (application), "is-busy");  | 
2891  | 0  |     }  | 
2892  | 0  | }  | 
2893  |  |  | 
2894  |  | /**  | 
2895  |  |  * g_application_get_is_busy:  | 
2896  |  |  * @application: a #GApplication  | 
2897  |  |  *  | 
2898  |  |  * Gets the application's current busy state, as set through  | 
2899  |  |  * g_application_mark_busy() or g_application_bind_busy_property().  | 
2900  |  |  *  | 
2901  |  |  * Returns: %TRUE if @application is currently marked as busy  | 
2902  |  |  *  | 
2903  |  |  * Since: 2.44  | 
2904  |  |  */  | 
2905  |  | gboolean  | 
2906  |  | g_application_get_is_busy (GApplication *application)  | 
2907  | 0  | { | 
2908  | 0  |   g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);  | 
2909  |  |  | 
2910  | 0  |   return application->priv->busy_count > 0;  | 
2911  | 0  | }  | 
2912  |  |  | 
2913  |  | /* Notifications {{{1 */ | 
2914  |  |  | 
2915  |  | /**  | 
2916  |  |  * g_application_send_notification:  | 
2917  |  |  * @application: a #GApplication  | 
2918  |  |  * @id: (nullable): id of the notification, or %NULL  | 
2919  |  |  * @notification: the #GNotification to send  | 
2920  |  |  *  | 
2921  |  |  * Sends a notification on behalf of @application to the desktop shell.  | 
2922  |  |  * There is no guarantee that the notification is displayed immediately,  | 
2923  |  |  * or even at all.  | 
2924  |  |  *  | 
2925  |  |  * Notifications may persist after the application exits. It will be  | 
2926  |  |  * D-Bus-activated when the notification or one of its actions is  | 
2927  |  |  * activated.  | 
2928  |  |  *  | 
2929  |  |  * Modifying @notification after this call has no effect. However, the  | 
2930  |  |  * object can be reused for a later call to this function.  | 
2931  |  |  *  | 
2932  |  |  * @id may be any string that uniquely identifies the event for the  | 
2933  |  |  * application. It does not need to be in any special format. For  | 
2934  |  |  * example, "new-message" might be appropriate for a notification about  | 
2935  |  |  * new messages.  | 
2936  |  |  *  | 
2937  |  |  * If a previous notification was sent with the same @id, it will be  | 
2938  |  |  * replaced with @notification and shown again as if it was a new  | 
2939  |  |  * notification. This works even for notifications sent from a previous  | 
2940  |  |  * execution of the application, as long as @id is the same string.  | 
2941  |  |  *  | 
2942  |  |  * @id may be %NULL, but it is impossible to replace or withdraw  | 
2943  |  |  * notifications without an id.  | 
2944  |  |  *  | 
2945  |  |  * If @notification is no longer relevant, it can be withdrawn with  | 
2946  |  |  * g_application_withdraw_notification().  | 
2947  |  |  *  | 
2948  |  |  * Since: 2.40  | 
2949  |  |  */  | 
2950  |  | void  | 
2951  |  | g_application_send_notification (GApplication  *application,  | 
2952  |  |                                  const gchar   *id,  | 
2953  |  |                                  GNotification *notification)  | 
2954  | 0  | { | 
2955  | 0  |   gchar *generated_id = NULL;  | 
2956  |  | 
  | 
2957  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
2958  | 0  |   g_return_if_fail (G_IS_NOTIFICATION (notification));  | 
2959  | 0  |   g_return_if_fail (g_application_get_is_registered (application));  | 
2960  | 0  |   g_return_if_fail (!g_application_get_is_remote (application));  | 
2961  |  |  | 
2962  | 0  |   if (application->priv->notifications == NULL)  | 
2963  | 0  |     application->priv->notifications = g_notification_backend_new_default (application);  | 
2964  |  | 
  | 
2965  | 0  |   if (id == NULL)  | 
2966  | 0  |     { | 
2967  | 0  |       generated_id = g_dbus_generate_guid ();  | 
2968  | 0  |       id = generated_id;  | 
2969  | 0  |     }  | 
2970  |  | 
  | 
2971  | 0  |   g_notification_backend_send_notification (application->priv->notifications, id, notification);  | 
2972  |  | 
  | 
2973  | 0  |   g_free (generated_id);  | 
2974  | 0  | }  | 
2975  |  |  | 
2976  |  | /**  | 
2977  |  |  * g_application_withdraw_notification:  | 
2978  |  |  * @application: a #GApplication  | 
2979  |  |  * @id: id of a previously sent notification  | 
2980  |  |  *  | 
2981  |  |  * Withdraws a notification that was sent with  | 
2982  |  |  * g_application_send_notification().  | 
2983  |  |  *  | 
2984  |  |  * This call does nothing if a notification with @id doesn't exist or  | 
2985  |  |  * the notification was never sent.  | 
2986  |  |  *  | 
2987  |  |  * This function works even for notifications sent in previous  | 
2988  |  |  * executions of this application, as long @id is the same as it was for  | 
2989  |  |  * the sent notification.  | 
2990  |  |  *  | 
2991  |  |  * Note that notifications are dismissed when the user clicks on one  | 
2992  |  |  * of the buttons in a notification or triggers its default action, so  | 
2993  |  |  * there is no need to explicitly withdraw the notification in that case.  | 
2994  |  |  *  | 
2995  |  |  * Since: 2.40  | 
2996  |  |  */  | 
2997  |  | void  | 
2998  |  | g_application_withdraw_notification (GApplication *application,  | 
2999  |  |                                      const gchar  *id)  | 
3000  | 0  | { | 
3001  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
3002  | 0  |   g_return_if_fail (id != NULL);  | 
3003  |  |  | 
3004  | 0  |   if (application->priv->notifications == NULL)  | 
3005  | 0  |     application->priv->notifications = g_notification_backend_new_default (application);  | 
3006  |  | 
  | 
3007  | 0  |   g_notification_backend_withdraw_notification (application->priv->notifications, id);  | 
3008  | 0  | }  | 
3009  |  |  | 
3010  |  | /* Busy binding {{{1 */ | 
3011  |  |  | 
3012  |  | typedef struct  | 
3013  |  | { | 
3014  |  |   GApplication *app;  | 
3015  |  |   gboolean is_busy;  | 
3016  |  | } GApplicationBusyBinding;  | 
3017  |  |  | 
3018  |  | static void  | 
3019  |  | g_application_busy_binding_destroy (gpointer  data,  | 
3020  |  |                                     GClosure *closure)  | 
3021  | 0  | { | 
3022  | 0  |   GApplicationBusyBinding *binding = data;  | 
3023  |  | 
  | 
3024  | 0  |   if (binding->is_busy)  | 
3025  | 0  |     g_application_unmark_busy (binding->app);  | 
3026  |  | 
  | 
3027  | 0  |   g_object_unref (binding->app);  | 
3028  | 0  |   g_slice_free (GApplicationBusyBinding, binding);  | 
3029  | 0  | }  | 
3030  |  |  | 
3031  |  | static void  | 
3032  |  | g_application_notify_busy_binding (GObject    *object,  | 
3033  |  |                                    GParamSpec *pspec,  | 
3034  |  |                                    gpointer    user_data)  | 
3035  | 0  | { | 
3036  | 0  |   GApplicationBusyBinding *binding = user_data;  | 
3037  | 0  |   gboolean is_busy;  | 
3038  |  | 
  | 
3039  | 0  |   g_object_get (object, pspec->name, &is_busy, NULL);  | 
3040  |  | 
  | 
3041  | 0  |   if (is_busy && !binding->is_busy)  | 
3042  | 0  |     g_application_mark_busy (binding->app);  | 
3043  | 0  |   else if (!is_busy && binding->is_busy)  | 
3044  | 0  |     g_application_unmark_busy (binding->app);  | 
3045  |  | 
  | 
3046  | 0  |   binding->is_busy = is_busy;  | 
3047  | 0  | }  | 
3048  |  |  | 
3049  |  | /**  | 
3050  |  |  * g_application_bind_busy_property:  | 
3051  |  |  * @application: a #GApplication  | 
3052  |  |  * @object: (type GObject.Object): a #GObject  | 
3053  |  |  * @property: the name of a boolean property of @object  | 
3054  |  |  *  | 
3055  |  |  * Marks @application as busy (see g_application_mark_busy()) while  | 
3056  |  |  * @property on @object is %TRUE.  | 
3057  |  |  *  | 
3058  |  |  * The binding holds a reference to @application while it is active, but  | 
3059  |  |  * not to @object. Instead, the binding is destroyed when @object is  | 
3060  |  |  * finalized.  | 
3061  |  |  *  | 
3062  |  |  * Since: 2.44  | 
3063  |  |  */  | 
3064  |  | void  | 
3065  |  | g_application_bind_busy_property (GApplication *application,  | 
3066  |  |                                   gpointer      object,  | 
3067  |  |                                   const gchar  *property)  | 
3068  | 0  | { | 
3069  | 0  |   guint notify_id;  | 
3070  | 0  |   GQuark property_quark;  | 
3071  | 0  |   GParamSpec *pspec;  | 
3072  | 0  |   GApplicationBusyBinding *binding;  | 
3073  | 0  |   GClosure *closure;  | 
3074  |  | 
  | 
3075  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
3076  | 0  |   g_return_if_fail (G_IS_OBJECT (object));  | 
3077  | 0  |   g_return_if_fail (property != NULL);  | 
3078  |  |  | 
3079  | 0  |   notify_id = g_signal_lookup ("notify", G_TYPE_OBJECT); | 
3080  | 0  |   property_quark = g_quark_from_string (property);  | 
3081  | 0  |   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), property);  | 
3082  |  | 
  | 
3083  | 0  |   g_return_if_fail (pspec != NULL && pspec->value_type == G_TYPE_BOOLEAN);  | 
3084  |  |  | 
3085  | 0  |   if (g_signal_handler_find (object, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC,  | 
3086  | 0  |                              notify_id, property_quark, NULL, g_application_notify_busy_binding, NULL) > 0)  | 
3087  | 0  |     { | 
3088  | 0  |       g_critical ("%s: '%s' is already bound to the busy state of the application", G_STRFUNC, property); | 
3089  | 0  |       return;  | 
3090  | 0  |     }  | 
3091  |  |  | 
3092  | 0  |   binding = g_slice_new (GApplicationBusyBinding);  | 
3093  | 0  |   binding->app = g_object_ref (application);  | 
3094  | 0  |   binding->is_busy = FALSE;  | 
3095  |  | 
  | 
3096  | 0  |   closure = g_cclosure_new (G_CALLBACK (g_application_notify_busy_binding), binding,  | 
3097  | 0  |                             g_application_busy_binding_destroy);  | 
3098  | 0  |   g_signal_connect_closure_by_id (object, notify_id, property_quark, closure, FALSE);  | 
3099  |  |  | 
3100  |  |   /* fetch the initial value */  | 
3101  | 0  |   g_application_notify_busy_binding (object, pspec, binding);  | 
3102  | 0  | }  | 
3103  |  |  | 
3104  |  | /**  | 
3105  |  |  * g_application_unbind_busy_property:  | 
3106  |  |  * @application: a #GApplication  | 
3107  |  |  * @object: (type GObject.Object): a #GObject  | 
3108  |  |  * @property: the name of a boolean property of @object  | 
3109  |  |  *  | 
3110  |  |  * Destroys a binding between @property and the busy state of  | 
3111  |  |  * @application that was previously created with  | 
3112  |  |  * g_application_bind_busy_property().  | 
3113  |  |  *  | 
3114  |  |  * Since: 2.44  | 
3115  |  |  */  | 
3116  |  | void  | 
3117  |  | g_application_unbind_busy_property (GApplication *application,  | 
3118  |  |                                     gpointer      object,  | 
3119  |  |                                     const gchar  *property)  | 
3120  | 0  | { | 
3121  | 0  |   guint notify_id;  | 
3122  | 0  |   GQuark property_quark;  | 
3123  | 0  |   gulong handler_id;  | 
3124  |  | 
  | 
3125  | 0  |   g_return_if_fail (G_IS_APPLICATION (application));  | 
3126  | 0  |   g_return_if_fail (G_IS_OBJECT (object));  | 
3127  | 0  |   g_return_if_fail (property != NULL);  | 
3128  |  |  | 
3129  | 0  |   notify_id = g_signal_lookup ("notify", G_TYPE_OBJECT); | 
3130  | 0  |   property_quark = g_quark_from_string (property);  | 
3131  |  | 
  | 
3132  | 0  |   handler_id = g_signal_handler_find (object, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC,  | 
3133  | 0  |                                       notify_id, property_quark, NULL, g_application_notify_busy_binding, NULL);  | 
3134  | 0  |   if (handler_id == 0)  | 
3135  | 0  |     { | 
3136  | 0  |       g_critical ("%s: '%s' is not bound to the busy state of the application", G_STRFUNC, property); | 
3137  | 0  |       return;  | 
3138  | 0  |     }  | 
3139  |  |  | 
3140  | 0  |   g_signal_handler_disconnect (object, handler_id);  | 
3141  | 0  | }  | 
3142  |  |  | 
3143  |  | /* Epilogue {{{1 */ | 
3144  |  | /* vim:set foldmethod=marker: */  |