Add a quick utility to test datetime formatting
[platform/upstream/glib.git] / gio / gapplication.c
1 /*
2  * Copyright © 2010 Codethink Limited
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; either version 2 of the licence or (at
7  * your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General
15  * Public License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17  * Boston, MA 02111-1307, USA.
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 "gapplicationimpl.h"
29 #include "gactiongroup.h"
30 #include "gsettings.h"
31
32 #include "gioenumtypes.h"
33 #include "gioenums.h"
34 #include "gfile.h"
35
36 #include "glibintl.h"
37
38 #include <string.h>
39
40 /**
41  * SECTION:gapplication
42  * @title: GApplication
43  * @short_description: Core application class
44  *
45  * A #GApplication is the foundation of an application, unique for a
46  * given application identifier.  The GApplication class wraps some
47  * low-level platform-specific services and is intended to act as the
48  * foundation for higher-level application classes such as
49  * #GtkApplication or #MxApplication.  In general, you should not use
50  * this class outside of a higher level framework.
51  *
52  * One of the core features that GApplication provides is process
53  * uniqueness, in the context of a "session".  The session concept is
54  * platform-dependent, but corresponds roughly to a graphical desktop
55  * login.  When your application is launched again, its arguments
56  * are passed through platform communication to the already running
57  * program. The already running instance of the program is called the
58  * <firstterm>primary instance</firstterm>.
59  *
60  * Before using GApplication, you must choose an "application identifier".
61  * The expected form of an application identifier is very close to that of
62  * of a <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface">DBus bus name</ulink>.
63  * Examples include: "com.example.MyApp", "org.example.internal-apps.Calculator".
64  * For details on valid application identifiers, see
65  * g_application_id_is_valid().
66  *
67  * The application identifier is claimed by the application as a
68  * well-known bus name on the user's session bus.  This means that the
69  * uniqueness of your application is scoped to the current session.  It
70  * also means that your application may provide additional services
71  * (through registration of other object paths) at that bus name.
72  *
73  * The registration of these object paths should be done with the shared
74  * GDBus session bus.  Note that due to the internal architecture of
75  * GDBus, method calls can be dispatched at any time (even if a main
76  * loop is not running).  For this reason, you must ensure that any
77  * object paths that you wish to register are registered before
78  * #GApplication attempts to acquire the bus name of your application
79  * (which happens in g_application_register()).  Unfortunately, this
80  * means that you cannot use g_application_get_is_remote() to decide if
81  * you want to register object paths.
82  *
83  * GApplication provides convenient life cycle management by maintaining
84  * a <firstterm>use count</firstterm> for the primary application instance.
85  * The use count can be changed using g_application_hold() and
86  * g_application_release(). If it drops to zero, the application exits.
87  *
88  * GApplication also implements the #GActionGroup interface and lets you
89  * easily export actions by adding them with g_application_set_action_group().
90  * When invoking an action by calling g_action_group_activate_action() on
91  * the application, it is always invoked in the primary instance.
92  *
93  * There is a number of different entry points into a #GApplication:
94  * <itemizedlist>
95  * <listitem>via 'Activate' (i.e. just starting the application)</listitem>
96  * <listitem>via 'Open' (i.e. opening some files)</listitem>
97  * <listitem>by handling a command-line</listitem>
98  * <listitem>via activating an action</listitem>
99  * </itemizedlist>
100  * The #GApplication::startup signal lets you handle the application
101  * initialization for all of these in a single place.
102  *
103  * Regardless of which of these entry points is used to start the application,
104  * GApplication passes some <firstterm id="platform-data">platform
105  * data</firstterm> from the launching instance to the primary instance,
106  * in the form of a #GVariant dictionary mapping strings to variants.
107  * To use platform data, override the @before_emit or @after_emit virtual
108  * functions in your #GApplication subclass. When dealing with
109  * #GApplicationCommandline objects, the platform data is directly
110  * available via g_application_command_line_get_cwd(),
111  * g_application_command_line_get_environ() and
112  * g_application_command_line_get_platform_data().
113  *
114  * As the name indicates, the platform data may vary depending on the
115  * operating system, but it always includes the current directory (key
116  * "cwd"), and optionally the environment (ie the set of environment
117  * variables and their values) of the calling process (key "environ").
118  * The environment is only added to the platform data if the
119  * #G_APPLICATION_SEND_ENVIONMENT flag is set. GApplication subclasses
120  * can add their own platform data by overriding the @add_platform_data
121  * virtual function. For instance, #GtkApplication adds startup notification
122  * data in this way.
123  *
124  * To parse commandline arguments you may handle the
125  * #GApplication::command-line signal or override the local_command_line()
126  * vfunc, to parse them in either the primary instance or the local instance,
127  * respectively.
128  *
129  * <example id="gapplication-example-open"><title>Opening files with a GApplication</title>
130  * <programlisting>
131  * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-open.c">
132  *   <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
133  * </xi:include>
134  * </programlisting>
135  * </example>
136  *
137  * <example id="gapplication-example-actions"><title>A GApplication with actions</title>
138  * <programlisting>
139  * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-actions.c">
140  *   <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
141  * </xi:include>
142  * </programlisting>
143  * </example>
144  */
145
146 struct _GApplicationPrivate
147 {
148   GApplicationFlags  flags;
149   gchar             *id;
150
151   GActionGroup      *actions;
152   GMainLoop         *mainloop;
153
154   guint              inactivity_timeout_id;
155   guint              inactivity_timeout;
156   guint              use_count;
157
158   guint              is_registered : 1;
159   guint              is_remote : 1;
160
161   GHashTable        *remote_actions;  /* string -> RemoteActionInfo */
162   GApplicationImpl  *impl;
163 };
164
165 enum
166 {
167   PROP_NONE,
168   PROP_APPLICATION_ID,
169   PROP_FLAGS,
170   PROP_IS_REGISTERED,
171   PROP_IS_REMOTE,
172   PROP_INACTIVITY_TIMEOUT,
173   PROP_ACTION_GROUP
174 };
175
176 enum
177 {
178   SIGNAL_STARTUP,
179   SIGNAL_ACTIVATE,
180   SIGNAL_OPEN,
181   SIGNAL_ACTION,
182   SIGNAL_COMMAND_LINE,
183   NR_SIGNALS
184 };
185
186 static guint g_application_signals[NR_SIGNALS];
187
188 static void g_application_action_group_iface_init (GActionGroupInterface *);
189 G_DEFINE_TYPE_WITH_CODE (GApplication, g_application, G_TYPE_OBJECT,
190  G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP,
191    g_application_action_group_iface_init))
192
193 /* vfunc defaults {{{1 */
194 static void
195 g_application_real_before_emit (GApplication *application,
196                                 GVariant     *platform_data)
197 {
198 }
199
200 static void
201 g_application_real_after_emit (GApplication *application,
202                                GVariant     *platform_data)
203 {
204 }
205
206 static void
207 g_application_real_startup (GApplication *application)
208 {
209 }
210
211 static void
212 g_application_real_activate (GApplication *application)
213 {
214   if (!g_signal_has_handler_pending (application,
215                                      g_application_signals[SIGNAL_ACTIVATE],
216                                      0, TRUE) &&
217       G_APPLICATION_GET_CLASS (application)->activate == g_application_real_activate)
218     {
219       static gboolean warned;
220
221       if (warned)
222         return;
223
224       g_warning ("Your application does not implement "
225                  "g_application_activate() and has no handlers connected "
226                  "to the 'activate' signal.  It should do one of these.");
227       warned = TRUE;
228     }
229 }
230
231 static void
232 g_application_real_open (GApplication  *application,
233                          GFile        **files,
234                          gint           n_files,
235                          const gchar   *hint)
236 {
237   if (!g_signal_has_handler_pending (application,
238                                      g_application_signals[SIGNAL_OPEN],
239                                      0, TRUE) &&
240       G_APPLICATION_GET_CLASS (application)->open == g_application_real_open)
241     {
242       static gboolean warned;
243
244       if (warned)
245         return;
246
247       g_warning ("Your application claims to support opening files "
248                  "but does not implement g_application_open() and has no "
249                  "handlers connected to the 'open' signal.");
250       warned = TRUE;
251     }
252 }
253
254 static int
255 g_application_real_command_line (GApplication            *application,
256                                  GApplicationCommandLine *cmdline)
257 {
258   if (!g_signal_has_handler_pending (application,
259                                      g_application_signals[SIGNAL_COMMAND_LINE],
260                                      0, TRUE) &&
261       G_APPLICATION_GET_CLASS (application)->command_line == g_application_real_command_line)
262     {
263       static gboolean warned;
264
265       if (warned)
266         return 1;
267
268       g_warning ("Your application claims to support custom command line "
269                  "handling but does not implement g_application_command_line() "
270                  "and has no handlers connected to the 'command-line' signal.");
271
272       warned = TRUE;
273     }
274
275     return 1;
276 }
277
278 static gboolean
279 g_application_real_local_command_line (GApplication   *application,
280                                        gchar        ***arguments,
281                                        int            *exit_status)
282 {
283   if (application->priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE)
284     return FALSE;
285
286   else
287     {
288       GError *error = NULL;
289       gint n_args;
290
291       if (!g_application_register (application, NULL, &error))
292         {
293           g_critical ("%s", error->message);
294           g_error_free (error);
295           *exit_status = 1;
296           return TRUE;
297         }
298
299       n_args = g_strv_length (*arguments);
300
301       if (application->priv->flags & G_APPLICATION_IS_SERVICE)
302         {
303           if ((*exit_status = n_args > 1))
304             {
305               g_printerr ("GApplication service mode takes no arguments.\n");
306               application->priv->flags &= ~G_APPLICATION_IS_SERVICE;
307             }
308
309           return TRUE;
310         }
311
312       if (n_args <= 1)
313         {
314           g_application_activate (application);
315           *exit_status = 0;
316         }
317
318       else
319         {
320           if (~application->priv->flags & G_APPLICATION_HANDLES_OPEN)
321             {
322               g_critical ("This application can not open files.");
323               *exit_status = 1;
324             }
325           else
326             {
327               GFile **files;
328               gint n_files;
329               gint i;
330
331               n_files = n_args - 1;
332               files = g_new (GFile *, n_files);
333
334               for (i = 0; i < n_files; i++)
335                 files[i] = g_file_new_for_commandline_arg ((*arguments)[i + 1]);
336
337               g_application_open (application, files, n_files, "");
338
339               for (i = 0; i < n_files; i++)
340                 g_object_unref (files[i]);
341               g_free (files);
342
343               *exit_status = 0;
344             }
345         }
346
347       return TRUE;
348     }
349 }
350
351 static void
352 g_application_real_add_platform_data (GApplication    *application,
353                                       GVariantBuilder *builder)
354 {
355 }
356
357 static void
358 g_application_real_quit_mainloop (GApplication *application)
359 {
360   if (application->priv->mainloop != NULL)
361     g_main_loop_quit (application->priv->mainloop);
362 }
363
364 static void
365 g_application_real_run_mainloop (GApplication *application)
366 {
367   if (application->priv->mainloop == NULL)
368     application->priv->mainloop = g_main_loop_new (NULL, FALSE);
369
370   g_main_loop_run (application->priv->mainloop);
371 }
372
373 /* GObject implementation stuff {{{1 */
374 static void
375 g_application_set_property (GObject      *object,
376                             guint         prop_id,
377                             const GValue *value,
378                             GParamSpec   *pspec)
379 {
380   GApplication *application = G_APPLICATION (object);
381
382   switch (prop_id)
383     {
384     case PROP_APPLICATION_ID:
385       g_application_set_application_id (application,
386                                         g_value_get_string (value));
387       break;
388
389     case PROP_FLAGS:
390       g_application_set_flags (application, g_value_get_flags (value));
391       break;
392
393     case PROP_INACTIVITY_TIMEOUT:
394       g_application_set_inactivity_timeout (application,
395                                             g_value_get_uint (value));
396       break;
397
398     case PROP_ACTION_GROUP:
399       g_application_set_action_group (application,
400                                       g_value_get_object (value));
401       break;
402
403     default:
404       g_assert_not_reached ();
405     }
406 }
407
408 /**
409  * g_application_set_action_group:
410  * @application: a #GApplication
411  * @action_group: (allow-none): a #GActionGroup, or %NULL
412  *
413  * Sets or unsets the group of actions associated with the application.
414  *
415  * These actions are the actions that can be remotely invoked.
416  *
417  * It is an error to call this function after the application has been
418  * registered.
419  *
420  * Since: 2.28
421  **/
422 void
423 g_application_set_action_group (GApplication *application,
424                                 GActionGroup *action_group)
425 {
426   g_return_if_fail (G_IS_APPLICATION (application));
427   g_return_if_fail (!application->priv->is_registered);
428
429   if (application->priv->actions != NULL)
430     g_object_unref (application->priv->actions);
431
432   application->priv->actions = action_group;
433
434   if (application->priv->actions != NULL)
435     g_object_ref (application->priv->actions);
436 }
437
438 static void
439 g_application_get_property (GObject    *object,
440                             guint       prop_id,
441                             GValue     *value,
442                             GParamSpec *pspec)
443 {
444   GApplication *application = G_APPLICATION (object);
445
446   switch (prop_id)
447     {
448     case PROP_APPLICATION_ID:
449       g_value_set_string (value,
450                           g_application_get_application_id (application));
451       break;
452
453     case PROP_FLAGS:
454       g_value_set_flags (value,
455                          g_application_get_flags (application));
456       break;
457
458     case PROP_IS_REGISTERED:
459       g_value_set_boolean (value,
460                            g_application_get_is_registered (application));
461       break;
462
463     case PROP_IS_REMOTE:
464       g_value_set_boolean (value,
465                            g_application_get_is_remote (application));
466       break;
467
468     case PROP_INACTIVITY_TIMEOUT:
469       g_value_set_uint (value,
470                         g_application_get_inactivity_timeout (application));
471       break;
472
473     default:
474       g_assert_not_reached ();
475     }
476 }
477
478 static void
479 g_application_constructed (GObject *object)
480 {
481   GApplication *application = G_APPLICATION (object);
482
483   g_assert (application->priv->id != NULL);
484 }
485
486 static void
487 g_application_finalize (GObject *object)
488 {
489   GApplication *application = G_APPLICATION (object);
490
491   if (application->priv->impl)
492     g_application_impl_destroy (application->priv->impl);
493   g_free (application->priv->id);
494
495   if (application->priv->mainloop)
496     g_main_loop_unref (application->priv->mainloop);
497
498   G_OBJECT_CLASS (g_application_parent_class)
499     ->finalize (object);
500 }
501
502 static void
503 g_application_init (GApplication *application)
504 {
505   application->priv = G_TYPE_INSTANCE_GET_PRIVATE (application,
506                                                    G_TYPE_APPLICATION,
507                                                    GApplicationPrivate);
508 }
509
510 static void
511 g_application_class_init (GApplicationClass *class)
512 {
513   GObjectClass *object_class = G_OBJECT_CLASS (class);
514
515   object_class->constructed = g_application_constructed;
516   object_class->finalize = g_application_finalize;
517   object_class->get_property = g_application_get_property;
518   object_class->set_property = g_application_set_property;
519
520   class->before_emit = g_application_real_before_emit;
521   class->after_emit = g_application_real_after_emit;
522   class->startup = g_application_real_startup;
523   class->activate = g_application_real_activate;
524   class->open = g_application_real_open;
525   class->command_line = g_application_real_command_line;
526   class->local_command_line = g_application_real_local_command_line;
527   class->add_platform_data = g_application_real_add_platform_data;
528   class->quit_mainloop = g_application_real_quit_mainloop;
529   class->run_mainloop = g_application_real_run_mainloop;
530
531   g_object_class_install_property (object_class, PROP_APPLICATION_ID,
532     g_param_spec_string ("application-id",
533                          P_("Application identifier"),
534                          P_("The unique identifier for the application"),
535                          NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
536                          G_PARAM_STATIC_STRINGS));
537
538   g_object_class_install_property (object_class, PROP_FLAGS,
539     g_param_spec_flags ("flags",
540                         P_("Application flags"),
541                         P_("Flags specifying the behaviour of the application"),
542                         G_TYPE_APPLICATION_FLAGS, G_APPLICATION_FLAGS_NONE,
543                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
544
545   g_object_class_install_property (object_class, PROP_IS_REGISTERED,
546     g_param_spec_boolean ("is-registered",
547                           P_("Is registered"),
548                           P_("If g_application_register() has been called"),
549                           FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
550
551   g_object_class_install_property (object_class, PROP_IS_REMOTE,
552     g_param_spec_boolean ("is-remote",
553                           P_("Is remote"),
554                           P_("If this application instance is remote"),
555                           FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
556
557   g_object_class_install_property (object_class, PROP_INACTIVITY_TIMEOUT,
558     g_param_spec_uint ("inactivity-timeout",
559                        P_("Inactivity timeout"),
560                        P_("Time (ms) to stay alive after becoming idle"),
561                        0, G_MAXUINT, 0,
562                        G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
563
564   g_object_class_install_property (object_class, PROP_ACTION_GROUP,
565     g_param_spec_object ("action-group",
566                          P_("Action group"),
567                          P_("The group of actions that the application exports"),
568                          G_TYPE_ACTION_GROUP,
569                          G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
570
571   /**
572    * GApplication::startup:
573    * @application: the application
574    *
575    * The ::startup signal is emitted on the primary instance immediately
576    * after registration. See g_application_register().
577    */
578   g_application_signals[SIGNAL_STARTUP] =
579     g_signal_new ("startup", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
580                   G_STRUCT_OFFSET (GApplicationClass, startup),
581                   NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
582
583   /**
584    * GApplication::activate:
585    * @application: the application
586    *
587    * The ::activate signal is emitted on the primary instance when an
588    * activation occurs. See g_application_activate().
589    */
590   g_application_signals[SIGNAL_ACTIVATE] =
591     g_signal_new ("activate", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
592                   G_STRUCT_OFFSET (GApplicationClass, activate),
593                   NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
594
595
596   /**
597    * GApplication::open:
598    * @application: the application
599    * @files: (array length=n_files) (element-type GFile): an array of #GFiles
600    * @n_files: the length of @files
601    * @hint: a hint provided by the calling instance
602    *
603    * The ::open signal is emitted on the primary instance when there are
604    * files to open. See g_application_open() for more information.
605    */
606   g_application_signals[SIGNAL_OPEN] =
607     g_signal_new ("open", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
608                   G_STRUCT_OFFSET (GApplicationClass, open),
609                   NULL, NULL, NULL,
610                   G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);
611
612   /**
613    * GApplication::command-line:
614    * @application: the application
615    * @command_line: a #GApplicationCommandLine representing the
616    *     passed commandline
617    *
618    * The ::command-line signal is emitted on the primary instance when
619    * a commandline is not handled locally. See g_application_run() and
620    * the #GApplicationCommandline documentation for more information.
621    *
622    * Returns: An integer that is set as the exit status for the calling
623    *   process. See g_application_command_line_set_exit_status().
624    */
625   g_application_signals[SIGNAL_COMMAND_LINE] =
626     g_signal_new ("command-line", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
627                   G_STRUCT_OFFSET (GApplicationClass, command_line),
628                   g_signal_accumulator_first_wins, NULL,
629                   NULL,
630                   G_TYPE_INT, 1, G_TYPE_APPLICATION_COMMAND_LINE);
631
632   g_type_class_add_private (class, sizeof (GApplicationPrivate));
633 }
634
635 static GVariant *
636 get_platform_data (GApplication *application)
637 {
638   GVariantBuilder *builder;
639   GVariant *result;
640
641   builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
642
643   {
644     gchar *cwd = g_get_current_dir ();
645     g_variant_builder_add (builder, "{sv}", "cwd",
646                            g_variant_new_bytestring (cwd));
647     g_free (cwd);
648   }
649
650   if (application->priv->flags & G_APPLICATION_SEND_ENVIRONMENT)
651     {
652       GVariant *array;
653       gchar **envp;
654
655       envp = g_get_environ ();
656       array = g_variant_new_bytestring_array ((const gchar **) envp, -1);
657       g_strfreev (envp);
658
659       g_variant_builder_add (builder, "{sv}", "environ", array);
660     }
661
662   G_APPLICATION_GET_CLASS (application)->
663     add_platform_data (application, builder);
664
665   result = g_variant_builder_end (builder);
666   g_variant_builder_unref (builder);
667
668   return result;
669 }
670
671 /* Application ID validity {{{1 */
672
673 /**
674  * g_application_id_is_valid:
675  * @application_id: a potential application identifier
676  * @returns: %TRUE if @application_id is valid
677  *
678  * Checks if @application_id is a valid application identifier.
679  *
680  * A valid ID is required for calls to g_application_new() and
681  * g_application_set_application_id().
682  *
683  * For convenience, the restrictions on application identifiers are
684  * reproduced here:
685  * <itemizedlist>
686  *   <listitem>Application identifiers must contain only the ASCII characters "[A-Z][a-z][0-9]_-." and must not begin with a digit.</listitem>
687  *   <listitem>Application identifiers must contain at least one '.' (period) character (and thus at least three elements).</listitem>
688  *   <listitem>Application identifiers must not begin or end with a '.' (period) character.</listitem>
689  *   <listitem>Application identifiers must not contain consecutive '.' (period) characters.</listitem>
690  *   <listitem>Application identifiers must not exceed 255 characters.</listitem>
691  * </itemizedlist>
692  **/
693 gboolean
694 g_application_id_is_valid (const gchar *application_id)
695 {
696   gsize len;
697   gboolean allow_dot;
698   gboolean has_dot;
699
700   len = strlen (application_id);
701
702   if (len > 255)
703     return FALSE;
704
705   if (!g_ascii_isalpha (application_id[0]))
706     return FALSE;
707
708   if (application_id[len-1] == '.')
709     return FALSE;
710
711   application_id++;
712   allow_dot = TRUE;
713   has_dot = FALSE;
714   for (; *application_id; application_id++)
715     {
716       if (g_ascii_isalnum (*application_id) ||
717           (*application_id == '-') ||
718           (*application_id == '_'))
719         {
720           allow_dot = TRUE;
721         }
722       else if (allow_dot && *application_id == '.')
723         {
724           has_dot = TRUE;
725           allow_dot = FALSE;
726         }
727       else
728         return FALSE;
729     }
730
731   if (!has_dot)
732     return FALSE;
733
734   return TRUE;
735 }
736
737 /* Public Constructor {{{1 */
738 /**
739  * g_application_new:
740  * @application_id: the application id
741  * @flags: the application flags
742  * @returns: a new #GApplication instance
743  *
744  * Creates a new #GApplication instance.
745  *
746  * This function calls g_type_init() for you.
747  *
748  * The application id must be valid.  See g_application_id_is_valid().
749  **/
750 GApplication *
751 g_application_new (const gchar       *application_id,
752                    GApplicationFlags  flags)
753 {
754   g_return_val_if_fail (g_application_id_is_valid (application_id), NULL);
755
756   g_type_init ();
757
758   return g_object_new (G_TYPE_APPLICATION,
759                        "application-id", application_id,
760                        "flags", flags,
761                        NULL);
762 }
763
764 /* Simple get/set: application id, flags, inactivity timeout {{{1 */
765 /**
766  * g_application_get_application_id:
767  * @application: a #GApplication
768  * @returns: the identifier for @application, owned by @application
769  *
770  * Gets the unique identifier for @application.
771  *
772  * Since: 2.28
773  **/
774 const gchar *
775 g_application_get_application_id (GApplication *application)
776 {
777   g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
778
779   return application->priv->id;
780 }
781
782 /**
783  * g_application_set_application_id:
784  * @application: a #GApplication
785  * @application_id: the identifier for @application
786  *
787  * Sets the unique identifier for @application.
788  *
789  * The application id can only be modified if @application has not yet
790  * been registered.
791  *
792  * The application id must be valid.  See g_application_id_is_valid().
793  *
794  * Since: 2.28
795  **/
796 void
797 g_application_set_application_id (GApplication *application,
798                                   const gchar  *application_id)
799 {
800   g_return_if_fail (G_IS_APPLICATION (application));
801
802   if (g_strcmp0 (application->priv->id, application_id) != 0)
803     {
804       g_return_if_fail (g_application_id_is_valid (application_id));
805       g_return_if_fail (!application->priv->is_registered);
806
807       g_free (application->priv->id);
808       application->priv->id = g_strdup (application_id);
809
810       g_object_notify (G_OBJECT (application), "application-id");
811     }
812 }
813
814 /**
815  * g_application_get_flags:
816  * @application: a #GApplication
817  * @returns: the flags for @application
818  *
819  * Gets the flags for @application.
820  *
821  * See #GApplicationFlags.
822  *
823  * Since: 2.28
824  **/
825 GApplicationFlags
826 g_application_get_flags (GApplication *application)
827 {
828   g_return_val_if_fail (G_IS_APPLICATION (application), 0);
829
830   return application->priv->flags;
831 }
832
833 /**
834  * g_application_set_flags:
835  * @application: a #GApplication
836  * @flags: the flags for @application
837  *
838  * Sets the flags for @application.
839  *
840  * The flags can only be modified if @application has not yet been
841  * registered.
842  *
843  * See #GApplicationFlags.
844  *
845  * Since: 2.28
846  **/
847 void
848 g_application_set_flags (GApplication      *application,
849                          GApplicationFlags  flags)
850 {
851   g_return_if_fail (G_IS_APPLICATION (application));
852
853   if (application->priv->flags != flags)
854     {
855       g_return_if_fail (!application->priv->is_registered);
856
857       application->priv->flags = flags;
858
859       g_object_notify (G_OBJECT (application), "flags");
860     }
861 }
862
863 /**
864  * g_application_get_inactivity_timeout:
865  * @application: a #GApplication
866  *
867  * Gets the current inactivity timeout for the application.
868  *
869  * This is the amount of time (in milliseconds) after the last call to
870  * g_application_release() before the application stops running.
871  *
872  * Returns: the timeout, in milliseconds
873  *
874  * Since: 2.28
875  **/
876 guint
877 g_application_get_inactivity_timeout (GApplication *application)
878 {
879   g_return_val_if_fail (G_IS_APPLICATION (application), 0);
880
881   return application->priv->inactivity_timeout;
882 }
883
884 /**
885  * g_application_set_inactivity_timeout:
886  * @application: a #GApplication
887  * @inactivity_timeout: the timeout, in milliseconds
888  *
889  * Sets the current inactivity timeout for the application.
890  *
891  * This is the amount of time (in milliseconds) after the last call to
892  * g_application_release() before the application stops running.
893  *
894  * This call has no side effects of its own.  The value set here is only
895  * used for next time g_application_release() drops the use count to
896  * zero.  Any timeouts currently in progress are not impacted.
897  *
898  * Returns: the timeout, in milliseconds
899  *
900  * Since: 2.28
901  **/
902 void
903 g_application_set_inactivity_timeout (GApplication *application,
904                                       guint         inactivity_timeout)
905 {
906   g_return_if_fail (G_IS_APPLICATION (application));
907
908   if (application->priv->inactivity_timeout != inactivity_timeout)
909     {
910       application->priv->inactivity_timeout = inactivity_timeout;
911
912       g_object_notify (G_OBJECT (application), "inactivity-timeout");
913     }
914 }
915 /* Read-only property getters (is registered, is remote) {{{1 */
916 /**
917  * g_application_get_is_registered:
918  * @application: a #GApplication
919  * @returns: %TRUE if @application is registered
920  *
921  * Checks if @application is registered.
922  *
923  * An application is registered if g_application_register() has been
924  * successfully called.
925  *
926  * Since: 2.28
927  **/
928 gboolean
929 g_application_get_is_registered (GApplication *application)
930 {
931   g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
932
933   return application->priv->is_registered;
934 }
935
936 /**
937  * g_application_get_is_remote:
938  * @application: a #GApplication
939  * @returns: %TRUE if @application is remote
940  *
941  * Checks if @application is remote.
942  *
943  * If @application is remote then it means that another instance of
944  * application already exists (the 'primary' instance).  Calls to
945  * perform actions on @application will result in the actions being
946  * performed by the primary instance.
947  *
948  * The value of this property cannot be accessed before
949  * g_application_register() has been called.  See
950  * g_application_get_is_registered().
951  *
952  * Since: 2.28
953  **/
954 gboolean
955 g_application_get_is_remote (GApplication *application)
956 {
957   g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
958   g_return_val_if_fail (application->priv->is_registered, FALSE);
959
960   return application->priv->is_remote;
961 }
962
963 /* Register {{{1 */
964 /**
965  * g_application_register:
966  * @application: a #GApplication
967  * @cancellable: a #GCancellable, or %NULL
968  * @error: a pointer to a NULL #GError, or %NULL
969  * @returns: %TRUE if registration succeeded
970  *
971  * Attempts registration of the application.
972  *
973  * This is the point at which the application discovers if it is the
974  * primary instance or merely acting as a remote for an already-existing
975  * primary instance.  This is implemented by attempting to acquire the
976  * application identifier as a unique bus name on the session bus using
977  * GDBus.
978  *
979  * Due to the internal architecture of GDBus, method calls can be
980  * dispatched at any time (even if a main loop is not running).  For
981  * this reason, you must ensure that any object paths that you wish to
982  * register are registered before calling this function.
983  *
984  * If the application has already been registered then %TRUE is
985  * returned with no work performed.
986  *
987  * The #GApplication::startup signal is emitted if registration succeeds
988  * and @application is the primary instance.
989  *
990  * In the event of an error (such as @cancellable being cancelled, or a
991  * failure to connect to the session bus), %FALSE is returned and @error
992  * is set appropriately.
993  *
994  * Note: the return value of this function is not an indicator that this
995  * instance is or is not the primary instance of the application.  See
996  * g_application_get_is_remote() for that.
997  *
998  * Since: 2.28
999  **/
1000 gboolean
1001 g_application_register (GApplication  *application,
1002                         GCancellable  *cancellable,
1003                         GError       **error)
1004 {
1005   g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
1006
1007   if (!application->priv->is_registered)
1008     {
1009       if (~application->priv->flags & G_APPLICATION_NON_UNIQUE)
1010         {
1011           application->priv->impl =
1012             g_application_impl_register (application, application->priv->id,
1013                                          application->priv->flags,
1014                                          &application->priv->remote_actions,
1015                                          cancellable, error);
1016
1017           if (application->priv->impl == NULL)
1018             return FALSE;
1019         }
1020
1021       application->priv->is_remote = application->priv->remote_actions != NULL;
1022       application->priv->is_registered = TRUE;
1023
1024       g_object_notify (G_OBJECT (application), "is-registered");
1025
1026       if (!application->priv->is_remote)
1027         g_signal_emit (application, g_application_signals[SIGNAL_STARTUP], 0);
1028     }
1029
1030   return TRUE;
1031 }
1032
1033 /* Hold/release {{{1 */
1034 /**
1035  * g_application_hold:
1036  * @application: a #GApplication
1037  *
1038  * Increases the use count of @application.
1039  *
1040  * Use this function to indicate that the application has a reason to
1041  * continue to run.  For example, g_application_hold() is called by GTK+
1042  * when a toplevel window is on the screen.
1043  *
1044  * To cancel the hold, call g_application_release().
1045  **/
1046 void
1047 g_application_hold (GApplication *application)
1048 {
1049   if (application->priv->inactivity_timeout_id)
1050     {
1051       g_source_remove (application->priv->inactivity_timeout_id);
1052       application->priv->inactivity_timeout_id = 0;
1053     }
1054
1055   application->priv->use_count++;
1056 }
1057
1058 static gboolean
1059 inactivity_timeout_expired (gpointer data)
1060 {
1061   GApplication *application = G_APPLICATION (data);
1062
1063   G_APPLICATION_GET_CLASS (application)
1064     ->quit_mainloop (application);
1065
1066   return FALSE;
1067 }
1068
1069
1070 /**
1071  * g_application_release:
1072  * @application: a #GApplication
1073  *
1074  * Decrease the use count of @application.
1075  *
1076  * When the use count reaches zero, the application will stop running.
1077  *
1078  * Never call this function except to cancel the effect of a previous
1079  * call to g_application_hold().
1080  **/
1081 void
1082 g_application_release (GApplication *application)
1083 {
1084   application->priv->use_count--;
1085
1086   if (application->priv->use_count == 0)
1087     {
1088       if (application->priv->inactivity_timeout)
1089         application->priv->inactivity_timeout_id =
1090           g_timeout_add (application->priv->inactivity_timeout,
1091                          inactivity_timeout_expired, application);
1092
1093       else
1094         G_APPLICATION_GET_CLASS (application)
1095           ->quit_mainloop (application);
1096     }
1097 }
1098
1099 /* Activate, Open {{{1 */
1100 /**
1101  * g_application_activate:
1102  * @application: a #GApplication
1103  *
1104  * Activates the application.
1105  *
1106  * In essence, this results in the #GApplication::activate() signal being
1107  * emitted in the primary instance.
1108  *
1109  * The application must be registered before calling this function.
1110  *
1111  * Since: 2.28
1112  **/
1113 void
1114 g_application_activate (GApplication *application)
1115 {
1116   g_return_if_fail (G_IS_APPLICATION (application));
1117   g_return_if_fail (application->priv->is_registered);
1118
1119   if (application->priv->is_remote)
1120     g_application_impl_activate (application->priv->impl,
1121                                  get_platform_data (application));
1122
1123   else
1124     g_signal_emit (application, g_application_signals[SIGNAL_ACTIVATE], 0);
1125 }
1126
1127 /**
1128  * g_application_open:
1129  * @application: a #GApplication
1130  * @files: (array length=n_files): an array of #GFiles to open
1131  * @n_files: the length of the @files array
1132  * @hint: a hint (or ""), but never %NULL
1133  *
1134  * Opens the given files.
1135  *
1136  * In essence, this results in the #GApplication::open signal being emitted
1137  * in the primary instance.
1138  *
1139  * @n_files must be greater than zero.
1140  *
1141  * @hint is simply passed through to the ::open signal.  It is
1142  * intended to be used by applications that have multiple modes for
1143  * opening files (eg: "view" vs "edit", etc).  Unless you have a need
1144  * for this functionality, you should use "".
1145  *
1146  * The application must be registered before calling this function
1147  * and it must have the %G_APPLICATION_HANDLES_OPEN flag set.
1148  *
1149  * Since: 2.28
1150  **/
1151 void
1152 g_application_open (GApplication  *application,
1153                     GFile        **files,
1154                     gint           n_files,
1155                     const gchar   *hint)
1156 {
1157   g_return_if_fail (G_IS_APPLICATION (application));
1158   g_return_if_fail (application->priv->flags &
1159                     G_APPLICATION_HANDLES_OPEN);
1160   g_return_if_fail (application->priv->is_registered);
1161
1162   if (application->priv->is_remote)
1163     g_application_impl_open (application->priv->impl,
1164                              files, n_files, hint,
1165                              get_platform_data (application));
1166
1167   else
1168     g_signal_emit (application, g_application_signals[SIGNAL_OPEN],
1169                    0, files, n_files, hint);
1170 }
1171
1172 /* Run {{{1 */
1173 /**
1174  * g_application_run:
1175  * @application: a #GApplication
1176  * @argc: the argc from main() (or 0 if @argv is %NULL)
1177  * @argv: (array length=argc) (allow-none): the argv from main(), or %NULL
1178  * @returns: the exit status
1179  *
1180  * Runs the application.
1181  *
1182  * This function is intended to be run from main() and its return value
1183  * is intended to be returned by main(). Although you are expected to pass
1184  * the @argc, @argv parameters from main() to this function, it is possible
1185  * to pass %NULL if @argv is not available or commandline handling is not
1186  * required.
1187  *
1188  * First, the local_command_line() virtual function is invoked.
1189  * This function always runs on the local instance. It gets passed a pointer
1190  * to a %NULL-terminated copy of @argv and is expected to remove the arguments
1191  * that it handled (shifting up remaining arguments). See
1192  * <xref linkend="gapplication-example-cmdline2"/> for an example of
1193  * parsing @argv manually. Alternatively, you may use the #GOptionContext API,
1194  * after setting <literal>argc = g_strv_length (argv);</literal>.
1195  *
1196  * The last argument to local_command_line() is a pointer to the @status
1197  * variable which can used to set the exit status that is returned from
1198  * g_application_run().
1199  *
1200  * If local_command_line() returns %TRUE, the command line is expected
1201  * to be completely handled, including possibly registering as the primary
1202  * instance, calling g_application_activate() or g_application_open(), etc.
1203  *
1204  * If local_command_line() returns %FALSE then the application is registered
1205  * and the #GApplication::command-line signal is emitted in the primary
1206  * instance (which may or may not be this instance). The signal handler
1207  * gets passed a #GApplicationCommandline object that (among other things)
1208  * contains the remaining commandline arguments that have not been handled
1209  * by local_command_line().
1210  *
1211  * If the application has the %G_APPLICATION_HANDLES_COMMAND_LINE
1212  * flag set then the default implementation of local_command_line()
1213  * always returns %FALSE immediately, resulting in the commandline
1214  * always being handled in the primary instance.
1215  *
1216  * Otherwise, the default implementation of local_command_line() tries
1217  * to do a couple of things that are probably reasonable for most
1218  * applications.  First, g_application_register() is called to attempt
1219  * to register the application.  If that works, then the command line
1220  * arguments are inspected.  If no commandline arguments are given, then
1221  * g_application_activate() is called.  If commandline arguments are
1222  * given and the %G_APPLICATION_HANDLES_OPEN flag is set then they
1223  * are assumed to be filenames and g_application_open() is called.
1224  *
1225  * If you need to handle commandline arguments that are not filenames,
1226  * and you don't mind commandline handling to happen in the primary
1227  * instance, you should set %G_APPLICATION_HANDLED_COMMAND_LINE and
1228  * process the commandline arguments in your #GApplication::command-line
1229  * signal handler, either manually or using the #GOptionContext API.
1230  *
1231  * If you are interested in doing more complicated local handling of the
1232  * commandline then you should implement your own #GApplication subclass
1233  * and override local_command_line(). In this case, you most likely want
1234  * to return %TRUE from your local_command_line() implementation to
1235  * suppress the default handling. See
1236  * <xref linkend="gapplication-example-cmdline2"/> for an example.
1237  *
1238  * If, after the above is done, the use count of the application is zero
1239  * then the exit status is returned immediately.  If the use count is
1240  * non-zero then the mainloop is run until the use count falls to zero,
1241  * at which point 0 is returned.
1242  *
1243  * If the %G_APPLICATION_IS_SERVICE flag is set, then the exiting at
1244  * use count of zero is delayed for a while (ie: the instance stays
1245  * around to provide its <emphasis>service</emphasis> to others).
1246  *
1247  * Since: 2.28
1248  **/
1249 int
1250 g_application_run (GApplication  *application,
1251                    int            argc,
1252                    char         **argv)
1253 {
1254   gchar **arguments;
1255   int status;
1256   gint i;
1257
1258   g_return_val_if_fail (G_IS_APPLICATION (application), 1);
1259   g_return_val_if_fail (argc == 0 || argv != NULL, 1);
1260
1261   arguments = g_new (gchar *, argc + 1);
1262   for (i = 0; i < argc; i++)
1263     arguments[i] = g_strdup (argv[i]);
1264   arguments[i] = NULL;
1265
1266   if (g_get_prgname () == NULL && argc > 0)
1267     {
1268       gchar *prgname;
1269
1270       prgname = g_path_get_basename (argv[0]);
1271       g_set_prgname (prgname);
1272       g_free (prgname);
1273     }
1274
1275   if (!G_APPLICATION_GET_CLASS (application)
1276         ->local_command_line (application, &arguments, &status))
1277     {
1278       GError *error = NULL;
1279
1280       if (!g_application_register (application, NULL, &error))
1281         {
1282           g_printerr ("%s", error->message);
1283           g_error_free (error);
1284           return 1;
1285         }
1286
1287       if (application->priv->is_remote)
1288         {
1289           GVariant *platform_data;
1290
1291           platform_data = get_platform_data (application);
1292           status = g_application_impl_command_line (application->priv->impl,
1293                                                     arguments, platform_data);
1294         }
1295       else
1296         {
1297           GApplicationCommandLine *cmdline;
1298           GVariant *v;
1299
1300           v = g_variant_new_bytestring_array ((const gchar **) arguments, -1);
1301           cmdline = g_object_new (G_TYPE_APPLICATION_COMMAND_LINE,
1302                                   "arguments", v, NULL);
1303           g_signal_emit (application,
1304                          g_application_signals[SIGNAL_COMMAND_LINE],
1305                          0, cmdline, &status);
1306           g_object_unref (cmdline);
1307         }
1308     }
1309
1310   g_strfreev (arguments);
1311
1312   if (application->priv->flags & G_APPLICATION_IS_SERVICE &&
1313       application->priv->is_registered &&
1314       !application->priv->use_count &&
1315       !application->priv->inactivity_timeout_id)
1316     {
1317       application->priv->inactivity_timeout_id =
1318         g_timeout_add (10000, inactivity_timeout_expired, application);
1319     }
1320
1321   if (application->priv->use_count ||
1322       application->priv->inactivity_timeout_id)
1323     {
1324       G_APPLICATION_GET_CLASS (application)
1325         ->run_mainloop (application);
1326       status = 0;
1327     }
1328
1329   if (application->priv->impl)
1330     g_application_impl_flush (application->priv->impl);
1331
1332   g_settings_sync ();
1333
1334   return status;
1335 }
1336
1337 static gboolean
1338 g_application_has_action (GActionGroup *action_group,
1339                           const gchar  *action_name)
1340 {
1341   GApplication *application = G_APPLICATION (action_group);
1342
1343   g_return_val_if_fail (application->priv->is_registered, FALSE);
1344
1345   if (application->priv->remote_actions != NULL)
1346     return g_hash_table_lookup (application->priv->remote_actions,
1347                                 action_name) != NULL;
1348
1349   return application->priv->actions &&
1350          g_action_group_has_action (application->priv->actions, action_name);
1351 }
1352
1353 static gchar **
1354 g_application_list_actions (GActionGroup *action_group)
1355 {
1356   GApplication *application = G_APPLICATION (action_group);
1357
1358   g_return_val_if_fail (application->priv->is_registered, NULL);
1359
1360   if (application->priv->remote_actions != NULL)
1361     {
1362       GHashTableIter iter;
1363       gint n, i = 0;
1364       gchar **keys;
1365       gpointer key;
1366
1367       n = g_hash_table_size (application->priv->remote_actions);
1368       keys = g_new (gchar *, n + 1);
1369
1370       g_hash_table_iter_init (&iter, application->priv->remote_actions);
1371       while (g_hash_table_iter_next (&iter, &key, NULL))
1372         keys[i++] = g_strdup (key);
1373       g_assert_cmpint (i, ==, n);
1374       keys[n] = NULL;
1375
1376       return keys;
1377     }
1378
1379   else if (application->priv->actions != NULL)
1380     return g_action_group_list_actions (application->priv->actions);
1381
1382   else
1383     /* empty string array */
1384     return g_new0 (gchar *, 1);
1385 }
1386
1387 static gboolean
1388 g_application_get_action_enabled (GActionGroup *action_group,
1389                                   const gchar  *action_name)
1390 {
1391   GApplication *application = G_APPLICATION (action_group);
1392
1393   g_return_val_if_fail (application->priv->remote_actions != NULL ||
1394                         application->priv->actions != NULL, FALSE);
1395   g_return_val_if_fail (application->priv->is_registered, FALSE);
1396
1397   if (application->priv->remote_actions)
1398     {
1399       RemoteActionInfo *info;
1400
1401       info = g_hash_table_lookup (application->priv->remote_actions,
1402                                   action_name);
1403
1404       return info && info->enabled;
1405     }
1406
1407   return g_action_group_get_action_enabled (application->priv->actions,
1408                                             action_name);
1409 }
1410
1411 static const GVariantType *
1412 g_application_get_action_parameter_type (GActionGroup *action_group,
1413                                          const gchar  *action_name)
1414 {
1415   GApplication *application = G_APPLICATION (action_group);
1416
1417   g_return_val_if_fail (application->priv->remote_actions != NULL ||
1418                         application->priv->actions != NULL, NULL);
1419   g_return_val_if_fail (application->priv->is_registered, NULL);
1420
1421   if (application->priv->remote_actions)
1422     {
1423       RemoteActionInfo *info;
1424
1425       info = g_hash_table_lookup (application->priv->remote_actions,
1426                                   action_name);
1427
1428       if (info)
1429         return info->parameter_type;
1430       else
1431         return NULL;
1432     }
1433
1434   return g_action_group_get_action_parameter_type (application->priv->actions,
1435                                                    action_name);
1436 }
1437
1438 static const GVariantType *
1439 g_application_get_action_state_type (GActionGroup *action_group,
1440                                      const gchar  *action_name)
1441 {
1442   GApplication *application = G_APPLICATION (action_group);
1443
1444   g_return_val_if_fail (application->priv->remote_actions != NULL ||
1445                         application->priv->actions != NULL, NULL);
1446   g_return_val_if_fail (application->priv->is_registered, NULL);
1447
1448   if (application->priv->remote_actions)
1449     {
1450       RemoteActionInfo *info;
1451
1452       info = g_hash_table_lookup (application->priv->remote_actions,
1453                                   action_name);
1454
1455       if (info && info->state)
1456         return g_variant_get_type (info->state);
1457       else
1458         return NULL;
1459     }
1460
1461   return g_action_group_get_action_state_type (application->priv->actions,
1462                                                action_name);
1463 }
1464
1465 static GVariant *
1466 g_application_get_action_state (GActionGroup *action_group,
1467                                 const gchar  *action_name)
1468 {
1469   GApplication *application = G_APPLICATION (action_group);
1470
1471   g_return_val_if_fail (application->priv->remote_actions != NULL ||
1472                         application->priv->actions != NULL, NULL);
1473   g_return_val_if_fail (application->priv->is_registered, NULL);
1474
1475   if (application->priv->remote_actions)
1476     {
1477       RemoteActionInfo *info;
1478
1479       info = g_hash_table_lookup (application->priv->remote_actions,
1480                                   action_name);
1481
1482       if (info && info->state)
1483         return g_variant_ref (info->state);
1484       else
1485         return NULL;
1486     }
1487
1488   return g_action_group_get_action_state (application->priv->actions,
1489                                           action_name);
1490 }
1491
1492 static void
1493 g_application_change_action_state (GActionGroup *action_group,
1494                                    const gchar  *action_name,
1495                                    GVariant     *value)
1496 {
1497   GApplication *application = G_APPLICATION (action_group);
1498
1499   g_return_if_fail (application->priv->is_remote ||
1500                     application->priv->actions != NULL);
1501   g_return_if_fail (application->priv->is_registered);
1502
1503   if (application->priv->is_remote)
1504     g_application_impl_change_action_state (application->priv->impl,
1505                                             action_name, value,
1506                                             get_platform_data (application));
1507
1508   else
1509     g_action_group_change_action_state (application->priv->actions,
1510                                         action_name, value);
1511 }
1512
1513 static void
1514 g_application_activate_action (GActionGroup *action_group,
1515                                const gchar  *action_name,
1516                                GVariant     *parameter)
1517 {
1518   GApplication *application = G_APPLICATION (action_group);
1519
1520   g_return_if_fail (application->priv->is_remote ||
1521                     application->priv->actions != NULL);
1522   g_return_if_fail (application->priv->is_registered);
1523
1524   if (application->priv->is_remote)
1525     g_application_impl_activate_action (application->priv->impl,
1526                                         action_name, parameter,
1527                                         get_platform_data (application));
1528
1529   else
1530     g_action_group_activate_action (application->priv->actions,
1531                                     action_name, parameter);
1532 }
1533
1534 static void
1535 g_application_action_group_iface_init (GActionGroupInterface *iface)
1536 {
1537   iface->has_action = g_application_has_action;
1538   iface->list_actions = g_application_list_actions;
1539
1540   iface->get_action_enabled = g_application_get_action_enabled;
1541   iface->get_action_parameter_type = g_application_get_action_parameter_type;
1542   iface->get_action_state_type = g_application_get_action_state_type;
1543   iface->get_action_state = g_application_get_action_state;
1544   iface->change_action_state = g_application_change_action_state;
1545   iface->activate_action = g_application_activate_action;
1546 }
1547
1548 /* Epilogue {{{1 */
1549 /* vim:set foldmethod=marker: */