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