Coverage Report

Created: 2025-07-12 06:25

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