Drop last uses of @returns:
[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
153   guint              inactivity_timeout_id;
154   guint              inactivity_timeout;
155   guint              use_count;
156
157   guint              is_registered : 1;
158   guint              is_remote : 1;
159   guint              did_startup : 1;
160   guint              did_shutdown : 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_SHUTDOWN,
181   SIGNAL_ACTIVATE,
182   SIGNAL_OPEN,
183   SIGNAL_ACTION,
184   SIGNAL_COMMAND_LINE,
185   NR_SIGNALS
186 };
187
188 static guint g_application_signals[NR_SIGNALS];
189
190 static void g_application_action_group_iface_init (GActionGroupInterface *);
191 G_DEFINE_TYPE_WITH_CODE (GApplication, g_application, G_TYPE_OBJECT,
192  G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP,
193    g_application_action_group_iface_init))
194
195 /* vfunc defaults {{{1 */
196 static void
197 g_application_real_before_emit (GApplication *application,
198                                 GVariant     *platform_data)
199 {
200 }
201
202 static void
203 g_application_real_after_emit (GApplication *application,
204                                GVariant     *platform_data)
205 {
206 }
207
208 static void
209 g_application_real_startup (GApplication *application)
210 {
211   application->priv->did_startup = TRUE;
212 }
213
214 static void
215 g_application_real_shutdown (GApplication *application)
216 {
217   application->priv->did_shutdown = TRUE;
218 }
219
220 static void
221 g_application_real_activate (GApplication *application)
222 {
223   if (!g_signal_has_handler_pending (application,
224                                      g_application_signals[SIGNAL_ACTIVATE],
225                                      0, TRUE) &&
226       G_APPLICATION_GET_CLASS (application)->activate == g_application_real_activate)
227     {
228       static gboolean warned;
229
230       if (warned)
231         return;
232
233       g_warning ("Your application does not implement "
234                  "g_application_activate() and has no handlers connected "
235                  "to the 'activate' signal.  It should do one of these.");
236       warned = TRUE;
237     }
238 }
239
240 static void
241 g_application_real_open (GApplication  *application,
242                          GFile        **files,
243                          gint           n_files,
244                          const gchar   *hint)
245 {
246   if (!g_signal_has_handler_pending (application,
247                                      g_application_signals[SIGNAL_OPEN],
248                                      0, TRUE) &&
249       G_APPLICATION_GET_CLASS (application)->open == g_application_real_open)
250     {
251       static gboolean warned;
252
253       if (warned)
254         return;
255
256       g_warning ("Your application claims to support opening files "
257                  "but does not implement g_application_open() and has no "
258                  "handlers connected to the 'open' signal.");
259       warned = TRUE;
260     }
261 }
262
263 static int
264 g_application_real_command_line (GApplication            *application,
265                                  GApplicationCommandLine *cmdline)
266 {
267   if (!g_signal_has_handler_pending (application,
268                                      g_application_signals[SIGNAL_COMMAND_LINE],
269                                      0, TRUE) &&
270       G_APPLICATION_GET_CLASS (application)->command_line == g_application_real_command_line)
271     {
272       static gboolean warned;
273
274       if (warned)
275         return 1;
276
277       g_warning ("Your application claims to support custom command line "
278                  "handling but does not implement g_application_command_line() "
279                  "and has no handlers connected to the 'command-line' signal.");
280
281       warned = TRUE;
282     }
283
284     return 1;
285 }
286
287 static gboolean
288 g_application_real_local_command_line (GApplication   *application,
289                                        gchar        ***arguments,
290                                        int            *exit_status)
291 {
292   if (application->priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE)
293     return FALSE;
294
295   else
296     {
297       GError *error = NULL;
298       gint n_args;
299
300       if (!g_application_register (application, NULL, &error))
301         {
302           g_critical ("%s", error->message);
303           g_error_free (error);
304           *exit_status = 1;
305           return TRUE;
306         }
307
308       n_args = g_strv_length (*arguments);
309
310       if (application->priv->flags & G_APPLICATION_IS_SERVICE)
311         {
312           if ((*exit_status = n_args > 1))
313             {
314               g_printerr ("GApplication service mode takes no arguments.\n");
315               application->priv->flags &= ~G_APPLICATION_IS_SERVICE;
316             }
317
318           return TRUE;
319         }
320
321       if (n_args <= 1)
322         {
323           g_application_activate (application);
324           *exit_status = 0;
325         }
326
327       else
328         {
329           if (~application->priv->flags & G_APPLICATION_HANDLES_OPEN)
330             {
331               g_critical ("This application can not open files.");
332               *exit_status = 1;
333             }
334           else
335             {
336               GFile **files;
337               gint n_files;
338               gint i;
339
340               n_files = n_args - 1;
341               files = g_new (GFile *, n_files);
342
343               for (i = 0; i < n_files; i++)
344                 files[i] = g_file_new_for_commandline_arg ((*arguments)[i + 1]);
345
346               g_application_open (application, files, n_files, "");
347
348               for (i = 0; i < n_files; i++)
349                 g_object_unref (files[i]);
350               g_free (files);
351
352               *exit_status = 0;
353             }
354         }
355
356       return TRUE;
357     }
358 }
359
360 static void
361 g_application_real_add_platform_data (GApplication    *application,
362                                       GVariantBuilder *builder)
363 {
364 }
365
366 /* GObject implementation stuff {{{1 */
367 static void
368 g_application_set_property (GObject      *object,
369                             guint         prop_id,
370                             const GValue *value,
371                             GParamSpec   *pspec)
372 {
373   GApplication *application = G_APPLICATION (object);
374
375   switch (prop_id)
376     {
377     case PROP_APPLICATION_ID:
378       g_application_set_application_id (application,
379                                         g_value_get_string (value));
380       break;
381
382     case PROP_FLAGS:
383       g_application_set_flags (application, g_value_get_flags (value));
384       break;
385
386     case PROP_INACTIVITY_TIMEOUT:
387       g_application_set_inactivity_timeout (application,
388                                             g_value_get_uint (value));
389       break;
390
391     case PROP_ACTION_GROUP:
392       g_application_set_action_group (application,
393                                       g_value_get_object (value));
394       break;
395
396     default:
397       g_assert_not_reached ();
398     }
399 }
400
401 /**
402  * g_application_set_action_group:
403  * @application: a #GApplication
404  * @action_group: (allow-none): a #GActionGroup, or %NULL
405  *
406  * Sets or unsets the group of actions associated with the application.
407  *
408  * These actions are the actions that can be remotely invoked.
409  *
410  * It is an error to call this function after the application has been
411  * registered.
412  *
413  * Since: 2.28
414  **/
415 void
416 g_application_set_action_group (GApplication *application,
417                                 GActionGroup *action_group)
418 {
419   g_return_if_fail (G_IS_APPLICATION (application));
420   g_return_if_fail (!application->priv->is_registered);
421
422   if (application->priv->actions != NULL)
423     g_object_unref (application->priv->actions);
424
425   application->priv->actions = action_group;
426
427   if (application->priv->actions != NULL)
428     g_object_ref (application->priv->actions);
429 }
430
431 static void
432 g_application_get_property (GObject    *object,
433                             guint       prop_id,
434                             GValue     *value,
435                             GParamSpec *pspec)
436 {
437   GApplication *application = G_APPLICATION (object);
438
439   switch (prop_id)
440     {
441     case PROP_APPLICATION_ID:
442       g_value_set_string (value,
443                           g_application_get_application_id (application));
444       break;
445
446     case PROP_FLAGS:
447       g_value_set_flags (value,
448                          g_application_get_flags (application));
449       break;
450
451     case PROP_IS_REGISTERED:
452       g_value_set_boolean (value,
453                            g_application_get_is_registered (application));
454       break;
455
456     case PROP_IS_REMOTE:
457       g_value_set_boolean (value,
458                            g_application_get_is_remote (application));
459       break;
460
461     case PROP_INACTIVITY_TIMEOUT:
462       g_value_set_uint (value,
463                         g_application_get_inactivity_timeout (application));
464       break;
465
466     default:
467       g_assert_not_reached ();
468     }
469 }
470
471 static void
472 g_application_constructed (GObject *object)
473 {
474   GApplication *application = G_APPLICATION (object);
475
476   g_assert (application->priv->id != NULL);
477 }
478
479 static void
480 g_application_finalize (GObject *object)
481 {
482   GApplication *application = G_APPLICATION (object);
483
484   if (application->priv->impl)
485     g_application_impl_destroy (application->priv->impl);
486   g_free (application->priv->id);
487
488   G_OBJECT_CLASS (g_application_parent_class)
489     ->finalize (object);
490 }
491
492 static void
493 g_application_init (GApplication *application)
494 {
495   application->priv = G_TYPE_INSTANCE_GET_PRIVATE (application,
496                                                    G_TYPE_APPLICATION,
497                                                    GApplicationPrivate);
498 }
499
500 static void
501 g_application_class_init (GApplicationClass *class)
502 {
503   GObjectClass *object_class = G_OBJECT_CLASS (class);
504
505   object_class->constructed = g_application_constructed;
506   object_class->finalize = g_application_finalize;
507   object_class->get_property = g_application_get_property;
508   object_class->set_property = g_application_set_property;
509
510   class->before_emit = g_application_real_before_emit;
511   class->after_emit = g_application_real_after_emit;
512   class->startup = g_application_real_startup;
513   class->shutdown = g_application_real_shutdown;
514   class->activate = g_application_real_activate;
515   class->open = g_application_real_open;
516   class->command_line = g_application_real_command_line;
517   class->local_command_line = g_application_real_local_command_line;
518   class->add_platform_data = g_application_real_add_platform_data;
519
520   g_object_class_install_property (object_class, PROP_APPLICATION_ID,
521     g_param_spec_string ("application-id",
522                          P_("Application identifier"),
523                          P_("The unique identifier for the application"),
524                          NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
525                          G_PARAM_STATIC_STRINGS));
526
527   g_object_class_install_property (object_class, PROP_FLAGS,
528     g_param_spec_flags ("flags",
529                         P_("Application flags"),
530                         P_("Flags specifying the behaviour of the application"),
531                         G_TYPE_APPLICATION_FLAGS, G_APPLICATION_FLAGS_NONE,
532                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
533
534   g_object_class_install_property (object_class, PROP_IS_REGISTERED,
535     g_param_spec_boolean ("is-registered",
536                           P_("Is registered"),
537                           P_("If g_application_register() has been called"),
538                           FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
539
540   g_object_class_install_property (object_class, PROP_IS_REMOTE,
541     g_param_spec_boolean ("is-remote",
542                           P_("Is remote"),
543                           P_("If this application instance is remote"),
544                           FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
545
546   g_object_class_install_property (object_class, PROP_INACTIVITY_TIMEOUT,
547     g_param_spec_uint ("inactivity-timeout",
548                        P_("Inactivity timeout"),
549                        P_("Time (ms) to stay alive after becoming idle"),
550                        0, G_MAXUINT, 0,
551                        G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
552
553   g_object_class_install_property (object_class, PROP_ACTION_GROUP,
554     g_param_spec_object ("action-group",
555                          P_("Action group"),
556                          P_("The group of actions that the application exports"),
557                          G_TYPE_ACTION_GROUP,
558                          G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
559
560   /**
561    * GApplication::startup:
562    * @application: the application
563    *
564    * The ::startup signal is emitted on the primary instance immediately
565    * after registration. See g_application_register().
566    */
567   g_application_signals[SIGNAL_STARTUP] =
568     g_signal_new ("startup", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
569                   G_STRUCT_OFFSET (GApplicationClass, startup),
570                   NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
571
572   /**
573    * GApplication::shutdown:
574    * @application: the application
575    *
576    * The ::shutdown signal is emitted only on the registered primary instance
577    * immediately after the main loop terminates.
578    */
579   g_application_signals[SIGNAL_SHUTDOWN] =
580     g_signal_new ("shutdown", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
581                   G_STRUCT_OFFSET (GApplicationClass, shutdown),
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, NULL,
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                   NULL,
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  *
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  * Returns: %TRUE if @application_id is valid
694  **/
695 gboolean
696 g_application_id_is_valid (const gchar *application_id)
697 {
698   gsize len;
699   gboolean allow_dot;
700   gboolean has_dot;
701
702   len = strlen (application_id);
703
704   if (len > 255)
705     return FALSE;
706
707   if (!g_ascii_isalpha (application_id[0]))
708     return FALSE;
709
710   if (application_id[len-1] == '.')
711     return FALSE;
712
713   application_id++;
714   allow_dot = TRUE;
715   has_dot = FALSE;
716   for (; *application_id; application_id++)
717     {
718       if (g_ascii_isalnum (*application_id) ||
719           (*application_id == '-') ||
720           (*application_id == '_'))
721         {
722           allow_dot = TRUE;
723         }
724       else if (allow_dot && *application_id == '.')
725         {
726           has_dot = TRUE;
727           allow_dot = FALSE;
728         }
729       else
730         return FALSE;
731     }
732
733   if (!has_dot)
734     return FALSE;
735
736   return TRUE;
737 }
738
739 /* Public Constructor {{{1 */
740 /**
741  * g_application_new:
742  * @application_id: the application id
743  * @flags: the application flags
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  * Returns: a new #GApplication instance
752  **/
753 GApplication *
754 g_application_new (const gchar       *application_id,
755                    GApplicationFlags  flags)
756 {
757   g_return_val_if_fail (g_application_id_is_valid (application_id), NULL);
758
759   g_type_init ();
760
761   return g_object_new (G_TYPE_APPLICATION,
762                        "application-id", application_id,
763                        "flags", flags,
764                        NULL);
765 }
766
767 /* Simple get/set: application id, flags, inactivity timeout {{{1 */
768 /**
769  * g_application_get_application_id:
770  * @application: a #GApplication
771  *
772  * Gets the unique identifier for @application.
773  *
774  * Returns: the identifier for @application, owned by @application
775  *
776  * Since: 2.28
777  **/
778 const gchar *
779 g_application_get_application_id (GApplication *application)
780 {
781   g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
782
783   return application->priv->id;
784 }
785
786 /**
787  * g_application_set_application_id:
788  * @application: a #GApplication
789  * @application_id: the identifier for @application
790  *
791  * Sets the unique identifier for @application.
792  *
793  * The application id can only be modified if @application has not yet
794  * been registered.
795  *
796  * The application id must be valid.  See g_application_id_is_valid().
797  *
798  * Since: 2.28
799  **/
800 void
801 g_application_set_application_id (GApplication *application,
802                                   const gchar  *application_id)
803 {
804   g_return_if_fail (G_IS_APPLICATION (application));
805
806   if (g_strcmp0 (application->priv->id, application_id) != 0)
807     {
808       g_return_if_fail (g_application_id_is_valid (application_id));
809       g_return_if_fail (!application->priv->is_registered);
810
811       g_free (application->priv->id);
812       application->priv->id = g_strdup (application_id);
813
814       g_object_notify (G_OBJECT (application), "application-id");
815     }
816 }
817
818 /**
819  * g_application_get_flags:
820  * @application: a #GApplication
821  *
822  * Gets the flags for @application.
823  *
824  * See #GApplicationFlags.
825  *
826  * Returns: the flags for @application
827  *
828  * Since: 2.28
829  **/
830 GApplicationFlags
831 g_application_get_flags (GApplication *application)
832 {
833   g_return_val_if_fail (G_IS_APPLICATION (application), 0);
834
835   return application->priv->flags;
836 }
837
838 /**
839  * g_application_set_flags:
840  * @application: a #GApplication
841  * @flags: the flags for @application
842  *
843  * Sets the flags for @application.
844  *
845  * The flags can only be modified if @application has not yet been
846  * registered.
847  *
848  * See #GApplicationFlags.
849  *
850  * Since: 2.28
851  **/
852 void
853 g_application_set_flags (GApplication      *application,
854                          GApplicationFlags  flags)
855 {
856   g_return_if_fail (G_IS_APPLICATION (application));
857
858   if (application->priv->flags != flags)
859     {
860       g_return_if_fail (!application->priv->is_registered);
861
862       application->priv->flags = flags;
863
864       g_object_notify (G_OBJECT (application), "flags");
865     }
866 }
867
868 /**
869  * g_application_get_inactivity_timeout:
870  * @application: a #GApplication
871  *
872  * Gets the current inactivity timeout for the application.
873  *
874  * This is the amount of time (in milliseconds) after the last call to
875  * g_application_release() before the application stops running.
876  *
877  * Returns: the timeout, in milliseconds
878  *
879  * Since: 2.28
880  **/
881 guint
882 g_application_get_inactivity_timeout (GApplication *application)
883 {
884   g_return_val_if_fail (G_IS_APPLICATION (application), 0);
885
886   return application->priv->inactivity_timeout;
887 }
888
889 /**
890  * g_application_set_inactivity_timeout:
891  * @application: a #GApplication
892  * @inactivity_timeout: the timeout, in milliseconds
893  *
894  * Sets the current inactivity timeout for the application.
895  *
896  * This is the amount of time (in milliseconds) after the last call to
897  * g_application_release() before the application stops running.
898  *
899  * This call has no side effects of its own.  The value set here is only
900  * used for next time g_application_release() drops the use count to
901  * zero.  Any timeouts currently in progress are not impacted.
902  *
903  * Since: 2.28
904  **/
905 void
906 g_application_set_inactivity_timeout (GApplication *application,
907                                       guint         inactivity_timeout)
908 {
909   g_return_if_fail (G_IS_APPLICATION (application));
910
911   if (application->priv->inactivity_timeout != inactivity_timeout)
912     {
913       application->priv->inactivity_timeout = inactivity_timeout;
914
915       g_object_notify (G_OBJECT (application), "inactivity-timeout");
916     }
917 }
918 /* Read-only property getters (is registered, is remote) {{{1 */
919 /**
920  * g_application_get_is_registered:
921  * @application: a #GApplication
922  *
923  * Checks if @application is registered.
924  *
925  * An application is registered if g_application_register() has been
926  * successfully called.
927  *
928  * Returns: %TRUE if @application is registered
929  *
930  * Since: 2.28
931  **/
932 gboolean
933 g_application_get_is_registered (GApplication *application)
934 {
935   g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
936
937   return application->priv->is_registered;
938 }
939
940 /**
941  * g_application_get_is_remote:
942  * @application: a #GApplication
943  *
944  * Checks if @application is remote.
945  *
946  * If @application is remote then it means that another instance of
947  * application already exists (the 'primary' instance).  Calls to
948  * perform actions on @application will result in the actions being
949  * performed by the primary instance.
950  *
951  * The value of this property cannot be accessed before
952  * g_application_register() has been called.  See
953  * g_application_get_is_registered().
954  *
955  * Returns: %TRUE if @application is remote
956  *
957  * Since: 2.28
958  **/
959 gboolean
960 g_application_get_is_remote (GApplication *application)
961 {
962   g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
963   g_return_val_if_fail (application->priv->is_registered, FALSE);
964
965   return application->priv->is_remote;
966 }
967
968 /* Register {{{1 */
969 /**
970  * g_application_register:
971  * @application: a #GApplication
972  * @cancellable: a #GCancellable, or %NULL
973  * @error: a pointer to a NULL #GError, or %NULL
974  *
975  * Attempts registration of the application.
976  *
977  * This is the point at which the application discovers if it is the
978  * primary instance or merely acting as a remote for an already-existing
979  * primary instance.  This is implemented by attempting to acquire the
980  * application identifier as a unique bus name on the session bus using
981  * GDBus.
982  *
983  * Due to the internal architecture of GDBus, method calls can be
984  * dispatched at any time (even if a main loop is not running).  For
985  * this reason, you must ensure that any object paths that you wish to
986  * register are registered before calling this function.
987  *
988  * If the application has already been registered then %TRUE is
989  * returned with no work performed.
990  *
991  * The #GApplication::startup signal is emitted if registration succeeds
992  * and @application is the primary instance.
993  *
994  * In the event of an error (such as @cancellable being cancelled, or a
995  * failure to connect to the session bus), %FALSE is returned and @error
996  * is set appropriately.
997  *
998  * Note: the return value of this function is not an indicator that this
999  * instance is or is not the primary instance of the application.  See
1000  * g_application_get_is_remote() for that.
1001  *
1002  * Returns: %TRUE if registration succeeded
1003  *
1004  * Since: 2.28
1005  **/
1006 gboolean
1007 g_application_register (GApplication  *application,
1008                         GCancellable  *cancellable,
1009                         GError       **error)
1010 {
1011   g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
1012
1013   if (!application->priv->is_registered)
1014     {
1015       if (~application->priv->flags & G_APPLICATION_NON_UNIQUE)
1016         {
1017           application->priv->impl =
1018             g_application_impl_register (application, application->priv->id,
1019                                          application->priv->flags,
1020                                          &application->priv->remote_actions,
1021                                          cancellable, error);
1022
1023           if (application->priv->impl == NULL)
1024             return FALSE;
1025         }
1026
1027       application->priv->is_remote = application->priv->remote_actions != NULL;
1028       application->priv->is_registered = TRUE;
1029
1030       g_object_notify (G_OBJECT (application), "is-registered");
1031
1032       if (!application->priv->is_remote)
1033         {
1034           g_signal_emit (application, g_application_signals[SIGNAL_STARTUP], 0);
1035
1036           if (!application->priv->did_startup)
1037             g_critical ("GApplication subclass '%s' failed to chain up on"
1038                         " ::startup (from start of override function)",
1039                         G_OBJECT_TYPE_NAME (application));
1040         }
1041     }
1042
1043   return TRUE;
1044 }
1045
1046 /* Hold/release {{{1 */
1047 /**
1048  * g_application_hold:
1049  * @application: a #GApplication
1050  *
1051  * Increases the use count of @application.
1052  *
1053  * Use this function to indicate that the application has a reason to
1054  * continue to run.  For example, g_application_hold() is called by GTK+
1055  * when a toplevel window is on the screen.
1056  *
1057  * To cancel the hold, call g_application_release().
1058  **/
1059 void
1060 g_application_hold (GApplication *application)
1061 {
1062   if (application->priv->inactivity_timeout_id)
1063     {
1064       g_source_remove (application->priv->inactivity_timeout_id);
1065       application->priv->inactivity_timeout_id = 0;
1066     }
1067
1068   application->priv->use_count++;
1069 }
1070
1071 static gboolean
1072 inactivity_timeout_expired (gpointer data)
1073 {
1074   GApplication *application = G_APPLICATION (data);
1075
1076   application->priv->inactivity_timeout_id = 0;
1077
1078   return FALSE;
1079 }
1080
1081
1082 /**
1083  * g_application_release:
1084  * @application: a #GApplication
1085  *
1086  * Decrease the use count of @application.
1087  *
1088  * When the use count reaches zero, the application will stop running.
1089  *
1090  * Never call this function except to cancel the effect of a previous
1091  * call to g_application_hold().
1092  **/
1093 void
1094 g_application_release (GApplication *application)
1095 {
1096   application->priv->use_count--;
1097
1098   if (application->priv->use_count == 0 && application->priv->inactivity_timeout)
1099     application->priv->inactivity_timeout_id = g_timeout_add (application->priv->inactivity_timeout,
1100                                                               inactivity_timeout_expired, application);
1101 }
1102
1103 /* Activate, Open {{{1 */
1104 /**
1105  * g_application_activate:
1106  * @application: a #GApplication
1107  *
1108  * Activates the application.
1109  *
1110  * In essence, this results in the #GApplication::activate() signal being
1111  * emitted in the primary instance.
1112  *
1113  * The application must be registered before calling this function.
1114  *
1115  * Since: 2.28
1116  **/
1117 void
1118 g_application_activate (GApplication *application)
1119 {
1120   g_return_if_fail (G_IS_APPLICATION (application));
1121   g_return_if_fail (application->priv->is_registered);
1122
1123   if (application->priv->is_remote)
1124     g_application_impl_activate (application->priv->impl,
1125                                  get_platform_data (application));
1126
1127   else
1128     g_signal_emit (application, g_application_signals[SIGNAL_ACTIVATE], 0);
1129 }
1130
1131 /**
1132  * g_application_open:
1133  * @application: a #GApplication
1134  * @files: (array length=n_files): an array of #GFiles to open
1135  * @n_files: the length of the @files array
1136  * @hint: a hint (or ""), but never %NULL
1137  *
1138  * Opens the given files.
1139  *
1140  * In essence, this results in the #GApplication::open signal being emitted
1141  * in the primary instance.
1142  *
1143  * @n_files must be greater than zero.
1144  *
1145  * @hint is simply passed through to the ::open signal.  It is
1146  * intended to be used by applications that have multiple modes for
1147  * opening files (eg: "view" vs "edit", etc).  Unless you have a need
1148  * for this functionality, you should use "".
1149  *
1150  * The application must be registered before calling this function
1151  * and it must have the %G_APPLICATION_HANDLES_OPEN flag set.
1152  *
1153  * Since: 2.28
1154  **/
1155 void
1156 g_application_open (GApplication  *application,
1157                     GFile        **files,
1158                     gint           n_files,
1159                     const gchar   *hint)
1160 {
1161   g_return_if_fail (G_IS_APPLICATION (application));
1162   g_return_if_fail (application->priv->flags &
1163                     G_APPLICATION_HANDLES_OPEN);
1164   g_return_if_fail (application->priv->is_registered);
1165
1166   if (application->priv->is_remote)
1167     g_application_impl_open (application->priv->impl,
1168                              files, n_files, hint,
1169                              get_platform_data (application));
1170
1171   else
1172     g_signal_emit (application, g_application_signals[SIGNAL_OPEN],
1173                    0, files, n_files, hint);
1174 }
1175
1176 /* Run {{{1 */
1177 /**
1178  * g_application_run:
1179  * @application: a #GApplication
1180  * @argc: the argc from main() (or 0 if @argv is %NULL)
1181  * @argv: (array length=argc) (allow-none): the argv from main(), or %NULL
1182  *
1183  * Runs the application.
1184  *
1185  * This function is intended to be run from main() and its return value
1186  * is intended to be returned by main(). Although you are expected to pass
1187  * the @argc, @argv parameters from main() to this function, it is possible
1188  * to pass %NULL if @argv is not available or commandline handling is not
1189  * required.
1190  *
1191  * First, the local_command_line() virtual function is invoked.
1192  * This function always runs on the local instance. It gets passed a pointer
1193  * to a %NULL-terminated copy of @argv and is expected to remove the arguments
1194  * that it handled (shifting up remaining arguments). See
1195  * <xref linkend="gapplication-example-cmdline2"/> for an example of
1196  * parsing @argv manually. Alternatively, you may use the #GOptionContext API,
1197  * after setting <literal>argc = g_strv_length (argv);</literal>.
1198  *
1199  * The last argument to local_command_line() is a pointer to the @status
1200  * variable which can used to set the exit status that is returned from
1201  * g_application_run().
1202  *
1203  * If local_command_line() returns %TRUE, the command line is expected
1204  * to be completely handled, including possibly registering as the primary
1205  * instance, calling g_application_activate() or g_application_open(), etc.
1206  *
1207  * If local_command_line() returns %FALSE then the application is registered
1208  * and the #GApplication::command-line signal is emitted in the primary
1209  * instance (which may or may not be this instance). The signal handler
1210  * gets passed a #GApplicationCommandline object that (among other things)
1211  * contains the remaining commandline arguments that have not been handled
1212  * by local_command_line().
1213  *
1214  * If the application has the %G_APPLICATION_HANDLES_COMMAND_LINE
1215  * flag set then the default implementation of local_command_line()
1216  * always returns %FALSE immediately, resulting in the commandline
1217  * always being handled in the primary instance.
1218  *
1219  * Otherwise, the default implementation of local_command_line() tries
1220  * to do a couple of things that are probably reasonable for most
1221  * applications.  First, g_application_register() is called to attempt
1222  * to register the application.  If that works, then the command line
1223  * arguments are inspected.  If no commandline arguments are given, then
1224  * g_application_activate() is called.  If commandline arguments are
1225  * given and the %G_APPLICATION_HANDLES_OPEN flag is set then they
1226  * are assumed to be filenames and g_application_open() is called.
1227  *
1228  * If you need to handle commandline arguments that are not filenames,
1229  * and you don't mind commandline handling to happen in the primary
1230  * instance, you should set %G_APPLICATION_HANDLED_COMMAND_LINE and
1231  * process the commandline arguments in your #GApplication::command-line
1232  * signal handler, either manually or using the #GOptionContext API.
1233  *
1234  * If you are interested in doing more complicated local handling of the
1235  * commandline then you should implement your own #GApplication subclass
1236  * and override local_command_line(). In this case, you most likely want
1237  * to return %TRUE from your local_command_line() implementation to
1238  * suppress the default handling. See
1239  * <xref linkend="gapplication-example-cmdline2"/> for an example.
1240  *
1241  * If, after the above is done, the use count of the application is zero
1242  * then the exit status is returned immediately.  If the use count is
1243  * non-zero then the mainloop is run until the use count falls to zero,
1244  * at which point 0 is returned.
1245  *
1246  * If the %G_APPLICATION_IS_SERVICE flag is set, then the exiting at
1247  * use count of zero is delayed for a while (ie: the instance stays
1248  * around to provide its <emphasis>service</emphasis> to others).
1249  *
1250  * Returns: the exit status
1251  *
1252  * Since: 2.28
1253  **/
1254 int
1255 g_application_run (GApplication  *application,
1256                    int            argc,
1257                    char         **argv)
1258 {
1259   gchar **arguments;
1260   int status;
1261   gint i;
1262
1263   g_return_val_if_fail (G_IS_APPLICATION (application), 1);
1264   g_return_val_if_fail (argc == 0 || argv != NULL, 1);
1265
1266   arguments = g_new (gchar *, argc + 1);
1267   for (i = 0; i < argc; i++)
1268     arguments[i] = g_strdup (argv[i]);
1269   arguments[i] = NULL;
1270
1271   if (g_get_prgname () == NULL && argc > 0)
1272     {
1273       gchar *prgname;
1274
1275       prgname = g_path_get_basename (argv[0]);
1276       g_set_prgname (prgname);
1277       g_free (prgname);
1278     }
1279
1280   if (!G_APPLICATION_GET_CLASS (application)
1281         ->local_command_line (application, &arguments, &status))
1282     {
1283       GError *error = NULL;
1284
1285       if (!g_application_register (application, NULL, &error))
1286         {
1287           g_printerr ("%s", error->message);
1288           g_error_free (error);
1289           return 1;
1290         }
1291
1292       if (application->priv->is_remote)
1293         {
1294           GVariant *platform_data;
1295
1296           platform_data = get_platform_data (application);
1297           status = g_application_impl_command_line (application->priv->impl,
1298                                                     arguments, platform_data);
1299         }
1300       else
1301         {
1302           GApplicationCommandLine *cmdline;
1303           GVariant *v;
1304
1305           v = g_variant_new_bytestring_array ((const gchar **) arguments, -1);
1306           cmdline = g_object_new (G_TYPE_APPLICATION_COMMAND_LINE,
1307                                   "arguments", v, NULL);
1308           g_signal_emit (application,
1309                          g_application_signals[SIGNAL_COMMAND_LINE],
1310                          0, cmdline, &status);
1311           g_object_unref (cmdline);
1312         }
1313     }
1314
1315   g_strfreev (arguments);
1316
1317   if (application->priv->flags & G_APPLICATION_IS_SERVICE &&
1318       application->priv->is_registered &&
1319       !application->priv->use_count &&
1320       !application->priv->inactivity_timeout_id)
1321     {
1322       application->priv->inactivity_timeout_id =
1323         g_timeout_add (10000, inactivity_timeout_expired, application);
1324     }
1325
1326   while (application->priv->use_count || application->priv->inactivity_timeout_id)
1327     {
1328       g_main_context_iteration (NULL, TRUE);
1329       status = 0;
1330     }
1331
1332   if (!application->priv->is_remote)
1333     {
1334       g_signal_emit (application, g_application_signals[SIGNAL_SHUTDOWN], 0);
1335
1336       if (!application->priv->did_shutdown)
1337         g_critical ("GApplication subclass '%s' failed to chain up on"
1338                     " ::shutdown (from end of override function)",
1339                     G_OBJECT_TYPE_NAME (application));
1340     }
1341
1342   if (application->priv->impl)
1343     g_application_impl_flush (application->priv->impl);
1344
1345   g_settings_sync ();
1346
1347   return status;
1348 }
1349
1350 static gboolean
1351 g_application_has_action (GActionGroup *action_group,
1352                           const gchar  *action_name)
1353 {
1354   GApplication *application = G_APPLICATION (action_group);
1355
1356   g_return_val_if_fail (application->priv->is_registered, FALSE);
1357
1358   if (application->priv->remote_actions != NULL)
1359     return g_hash_table_lookup (application->priv->remote_actions,
1360                                 action_name) != NULL;
1361
1362   return application->priv->actions &&
1363          g_action_group_has_action (application->priv->actions, action_name);
1364 }
1365
1366 static gchar **
1367 g_application_list_actions (GActionGroup *action_group)
1368 {
1369   GApplication *application = G_APPLICATION (action_group);
1370
1371   g_return_val_if_fail (application->priv->is_registered, NULL);
1372
1373   if (application->priv->remote_actions != NULL)
1374     {
1375       GHashTableIter iter;
1376       gint n, i = 0;
1377       gchar **keys;
1378       gpointer key;
1379
1380       n = g_hash_table_size (application->priv->remote_actions);
1381       keys = g_new (gchar *, n + 1);
1382
1383       g_hash_table_iter_init (&iter, application->priv->remote_actions);
1384       while (g_hash_table_iter_next (&iter, &key, NULL))
1385         keys[i++] = g_strdup (key);
1386       g_assert_cmpint (i, ==, n);
1387       keys[n] = NULL;
1388
1389       return keys;
1390     }
1391
1392   else if (application->priv->actions != NULL)
1393     return g_action_group_list_actions (application->priv->actions);
1394
1395   else
1396     /* empty string array */
1397     return g_new0 (gchar *, 1);
1398 }
1399
1400 static gboolean
1401 g_application_get_action_enabled (GActionGroup *action_group,
1402                                   const gchar  *action_name)
1403 {
1404   GApplication *application = G_APPLICATION (action_group);
1405
1406   g_return_val_if_fail (application->priv->remote_actions != NULL ||
1407                         application->priv->actions != NULL, FALSE);
1408   g_return_val_if_fail (application->priv->is_registered, FALSE);
1409
1410   if (application->priv->remote_actions)
1411     {
1412       RemoteActionInfo *info;
1413
1414       info = g_hash_table_lookup (application->priv->remote_actions,
1415                                   action_name);
1416
1417       return info && info->enabled;
1418     }
1419
1420   return g_action_group_get_action_enabled (application->priv->actions,
1421                                             action_name);
1422 }
1423
1424 static const GVariantType *
1425 g_application_get_action_parameter_type (GActionGroup *action_group,
1426                                          const gchar  *action_name)
1427 {
1428   GApplication *application = G_APPLICATION (action_group);
1429
1430   g_return_val_if_fail (application->priv->remote_actions != NULL ||
1431                         application->priv->actions != NULL, NULL);
1432   g_return_val_if_fail (application->priv->is_registered, NULL);
1433
1434   if (application->priv->remote_actions)
1435     {
1436       RemoteActionInfo *info;
1437
1438       info = g_hash_table_lookup (application->priv->remote_actions,
1439                                   action_name);
1440
1441       if (info)
1442         return info->parameter_type;
1443       else
1444         return NULL;
1445     }
1446
1447   return g_action_group_get_action_parameter_type (application->priv->actions,
1448                                                    action_name);
1449 }
1450
1451 static const GVariantType *
1452 g_application_get_action_state_type (GActionGroup *action_group,
1453                                      const gchar  *action_name)
1454 {
1455   GApplication *application = G_APPLICATION (action_group);
1456
1457   g_return_val_if_fail (application->priv->remote_actions != NULL ||
1458                         application->priv->actions != NULL, NULL);
1459   g_return_val_if_fail (application->priv->is_registered, NULL);
1460
1461   if (application->priv->remote_actions)
1462     {
1463       RemoteActionInfo *info;
1464
1465       info = g_hash_table_lookup (application->priv->remote_actions,
1466                                   action_name);
1467
1468       if (info && info->state)
1469         return g_variant_get_type (info->state);
1470       else
1471         return NULL;
1472     }
1473
1474   return g_action_group_get_action_state_type (application->priv->actions,
1475                                                action_name);
1476 }
1477
1478 static GVariant *
1479 g_application_get_action_state (GActionGroup *action_group,
1480                                 const gchar  *action_name)
1481 {
1482   GApplication *application = G_APPLICATION (action_group);
1483
1484   g_return_val_if_fail (application->priv->remote_actions != NULL ||
1485                         application->priv->actions != NULL, NULL);
1486   g_return_val_if_fail (application->priv->is_registered, NULL);
1487
1488   if (application->priv->remote_actions)
1489     {
1490       RemoteActionInfo *info;
1491
1492       info = g_hash_table_lookup (application->priv->remote_actions,
1493                                   action_name);
1494
1495       if (info && info->state)
1496         return g_variant_ref (info->state);
1497       else
1498         return NULL;
1499     }
1500
1501   return g_action_group_get_action_state (application->priv->actions,
1502                                           action_name);
1503 }
1504
1505 static void
1506 g_application_change_action_state (GActionGroup *action_group,
1507                                    const gchar  *action_name,
1508                                    GVariant     *value)
1509 {
1510   GApplication *application = G_APPLICATION (action_group);
1511
1512   g_return_if_fail (application->priv->is_remote ||
1513                     application->priv->actions != NULL);
1514   g_return_if_fail (application->priv->is_registered);
1515
1516   if (application->priv->is_remote)
1517     g_application_impl_change_action_state (application->priv->impl,
1518                                             action_name, value,
1519                                             get_platform_data (application));
1520
1521   else
1522     g_action_group_change_action_state (application->priv->actions,
1523                                         action_name, value);
1524 }
1525
1526 static void
1527 g_application_activate_action (GActionGroup *action_group,
1528                                const gchar  *action_name,
1529                                GVariant     *parameter)
1530 {
1531   GApplication *application = G_APPLICATION (action_group);
1532
1533   g_return_if_fail (application->priv->is_remote ||
1534                     application->priv->actions != NULL);
1535   g_return_if_fail (application->priv->is_registered);
1536
1537   if (application->priv->is_remote)
1538     g_application_impl_activate_action (application->priv->impl,
1539                                         action_name, parameter,
1540                                         get_platform_data (application));
1541
1542   else
1543     g_action_group_activate_action (application->priv->actions,
1544                                     action_name, parameter);
1545 }
1546
1547 static void
1548 g_application_action_group_iface_init (GActionGroupInterface *iface)
1549 {
1550   iface->has_action = g_application_has_action;
1551   iface->list_actions = g_application_list_actions;
1552
1553   iface->get_action_enabled = g_application_get_action_enabled;
1554   iface->get_action_parameter_type = g_application_get_action_parameter_type;
1555   iface->get_action_state_type = g_application_get_action_state_type;
1556   iface->get_action_state = g_application_get_action_state;
1557   iface->change_action_state = g_application_change_action_state;
1558   iface->activate_action = g_application_activate_action;
1559 }
1560
1561 /* Epilogue {{{1 */
1562 /* vim:set foldmethod=marker: */