2 * Copyright © 2010 Codethink Limited
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.
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.
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.
19 * Authors: Ryan Lortie <desrt@desrt.ca>
23 #include "gapplication.h"
25 #include "gapplicationcommandline.h"
26 #include "gapplicationimpl.h"
27 #include "gactiongroup.h"
29 #include "gioenumtypes.h"
30 #include "gio-marshal.h"
36 struct _GApplicationPrivate
38 GApplicationFlags flags;
41 GActionGroup *actions;
44 guint inactivity_timeout_id;
45 guint inactivity_timeout;
48 guint is_registered : 1;
51 GApplicationImpl *impl;
61 PROP_INACTIVITY_TIMEOUT,
75 static guint g_application_signals[NR_SIGNALS];
77 static void g_application_action_group_iface_init (GActionGroupInterface *);
78 G_DEFINE_TYPE_WITH_CODE (GApplication, g_application, G_TYPE_OBJECT,
79 G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP,
80 g_application_action_group_iface_init))
82 /* vfunc defaults {{{1 */
84 g_application_real_before_emit (GApplication *application,
85 GVariant *platform_data)
90 g_application_real_after_emit (GApplication *application,
91 GVariant *platform_data)
96 g_application_real_startup (GApplication *application)
101 g_application_real_activate (GApplication *application)
103 if (!g_signal_has_handler_pending (application,
104 g_application_signals[SIGNAL_ACTIVATE],
107 static gboolean warned;
112 g_warning ("Your application does not implement "
113 "g_application_activate() and has no handlers connected "
114 "to the 'activate' signal. It should do one of these.");
120 g_application_real_open (GApplication *application,
125 if (!g_signal_has_handler_pending (application,
126 g_application_signals[SIGNAL_OPEN],
129 static gboolean warned;
134 g_warning ("Your application claims to support opening files "
135 "but does not implement g_application_open() and has no "
136 "handlers connected to the 'open' signal.");
142 g_application_real_command_line (GApplication *application,
143 GApplicationCommandLine *cmdline)
145 static gboolean warned;
150 g_warning ("Your application claims to support custom command line "
151 "handling but does not implement g_application_command_line() "
152 "and has no handlers connected to the 'command-line' signal.");
160 g_application_real_local_command_line (GApplication *application,
164 if (application->priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE)
169 GError *error = NULL;
172 if (!g_application_register (application, NULL, &error))
174 g_critical ("%s", error->message);
175 g_error_free (error);
180 n_args = g_strv_length (*arguments);
182 if (application->priv->flags & G_APPLICATION_IS_SERVICE)
186 g_printerr ("GApplication service mode takes no arguments.\n");
187 application->priv->flags &= ~G_APPLICATION_IS_SERVICE;
195 g_application_activate (application);
201 if (~application->priv->flags & G_APPLICATION_HANDLES_OPEN)
203 g_critical ("This application can not open files.");
212 n_files = n_args - 1;
213 files = g_new (GFile *, n_files);
215 for (i = 0; i < n_files; i++)
216 files[i] = g_file_new_for_commandline_arg ((*arguments)[i + 1]);
218 g_application_open (application, files, n_files, "");
220 for (i = 0; i < n_files; i++)
221 g_object_unref (files[i]);
233 g_application_real_add_platform_data (GApplication *application,
234 GVariantBuilder *builder)
239 g_application_real_quit_mainloop (GApplication *application)
241 if (application->priv->mainloop != NULL)
242 g_main_loop_quit (application->priv->mainloop);
246 g_application_real_run_mainloop (GApplication *application)
248 if (application->priv->mainloop == NULL)
249 application->priv->mainloop = g_main_loop_new (NULL, FALSE);
251 g_main_loop_run (application->priv->mainloop);
254 /* GObject implementation stuff {{{1 */
256 g_application_set_property (GObject *object, guint prop_id,
257 const GValue *value, GParamSpec *pspec)
259 GApplication *application = G_APPLICATION (object);
263 case PROP_APPLICATION_ID:
264 g_application_set_application_id (application,
265 g_value_get_string (value));
269 g_application_set_flags (application, g_value_get_flags (value));
272 case PROP_INACTIVITY_TIMEOUT:
273 g_application_set_inactivity_timeout (application,
274 g_value_get_uint (value));
277 case PROP_ACTION_GROUP:
278 g_application_set_action_group (application,
279 g_value_get_object (value));
283 g_assert_not_reached ();
288 * g_application_set_action_group:
289 * @application: a #GApplication
290 * @action_group: a #GActionGroup, or %NULL
292 * Sets or unsets the group of actions associated with the application.
294 * These actions are the actions that can be remotely invoked.
296 * It is an error to call this function after the application has been
302 g_application_set_action_group (GApplication *application,
303 GActionGroup *action_group)
305 g_return_if_fail (G_IS_APPLICATION (application));
306 g_return_if_fail (application->priv->is_registered);
308 if (application->priv->actions != NULL)
309 g_object_unref (application->priv->actions);
311 application->priv->actions = action_group;
313 if (application->priv->actions != NULL)
314 g_object_ref (application->priv->actions);
318 g_application_get_property (GObject *object, guint prop_id,
319 GValue *value, GParamSpec *pspec)
321 GApplication *application = G_APPLICATION (object);
325 case PROP_APPLICATION_ID:
326 g_value_set_string (value,
327 g_application_get_application_id (application));
331 g_value_set_flags (value,
332 g_application_get_flags (application));
335 case PROP_IS_REGISTERED:
336 g_value_set_boolean (value,
337 g_application_get_is_registered (application));
341 g_value_set_boolean (value,
342 g_application_get_is_remote (application));
345 case PROP_INACTIVITY_TIMEOUT:
346 g_value_set_uint (value,
347 g_application_get_inactivity_timeout (application));
351 g_assert_not_reached ();
356 g_application_constructed (GObject *object)
358 GApplication *application = G_APPLICATION (object);
360 g_assert (application->priv->id != NULL);
364 g_application_finalize (GObject *object)
366 GApplication *application = G_APPLICATION (object);
368 if (application->priv->impl)
369 g_application_impl_destroy (application->priv->impl);
370 g_free (application->priv->id);
372 if (application->priv->mainloop)
373 g_main_loop_unref (application->priv->mainloop);
375 G_OBJECT_CLASS (g_application_parent_class)
380 g_application_init (GApplication *application)
382 application->priv = G_TYPE_INSTANCE_GET_PRIVATE (application,
384 GApplicationPrivate);
388 g_application_class_init (GApplicationClass *class)
390 GObjectClass *object_class = G_OBJECT_CLASS (class);
392 object_class->constructed = g_application_constructed;
393 object_class->finalize = g_application_finalize;
394 object_class->get_property = g_application_get_property;
395 object_class->set_property = g_application_set_property;
397 class->before_emit = g_application_real_before_emit;
398 class->after_emit = g_application_real_after_emit;
399 class->startup = g_application_real_startup;
400 class->activate = g_application_real_activate;
401 class->open = g_application_real_open;
402 class->command_line = g_application_real_command_line;
403 class->local_command_line = g_application_real_local_command_line;
404 class->add_platform_data = g_application_real_add_platform_data;
405 class->quit_mainloop = g_application_real_quit_mainloop;
406 class->run_mainloop = g_application_real_run_mainloop;
408 g_object_class_install_property (object_class, PROP_APPLICATION_ID,
409 g_param_spec_string ("application-id", "application identifier",
410 "Unique identifier for the application",
411 NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
412 G_PARAM_STATIC_STRINGS));
414 g_object_class_install_property (object_class, PROP_FLAGS,
415 g_param_spec_flags ("flags", "application flags",
416 "Flags specifying the behaviour of the application",
417 G_TYPE_APPLICATION_FLAGS, G_APPLICATION_FLAGS_NONE,
418 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
420 g_object_class_install_property (object_class, PROP_IS_REGISTERED,
421 g_param_spec_boolean ("is-registered", "is registered",
422 "If g_application_register() has been called",
423 FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
425 g_object_class_install_property (object_class, PROP_IS_REMOTE,
426 g_param_spec_boolean ("is-remote", "is remote",
427 "If this application instance is remote",
428 FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
430 g_object_class_install_property (object_class, PROP_INACTIVITY_TIMEOUT,
431 g_param_spec_boolean ("inactivity-timeout", "inactivity timeout",
432 "time (ms) to stay alive after becoming idle",
433 FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
435 g_object_class_install_property (object_class, PROP_ACTION_GROUP,
436 g_param_spec_object ("action-group", "action group",
437 "the group of actions that the application exports",
439 G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
441 g_application_signals[SIGNAL_STARTUP] =
442 g_signal_new ("startup", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
443 G_STRUCT_OFFSET (GApplicationClass, startup),
444 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
446 g_application_signals[SIGNAL_ACTIVATE] =
447 g_signal_new ("activate", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
448 G_STRUCT_OFFSET (GApplicationClass, activate),
449 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
451 g_application_signals[SIGNAL_OPEN] =
452 g_signal_new ("open", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
453 G_STRUCT_OFFSET (GApplicationClass, open),
454 NULL, NULL, _gio_marshal_VOID__POINTER_INT_STRING,
455 G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);
457 g_application_signals[SIGNAL_COMMAND_LINE] =
458 g_signal_new ("command-line", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
459 G_STRUCT_OFFSET (GApplicationClass, command_line),
460 g_signal_accumulator_first_wins, NULL,
461 _gio_marshal_INT__OBJECT,
462 G_TYPE_INT, 1, G_TYPE_APPLICATION_COMMAND_LINE);
464 g_type_class_add_private (class, sizeof (GApplicationPrivate));
468 get_platform_data (GApplication *application)
470 GVariantBuilder *builder;
473 builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
476 gchar *cwd = g_get_current_dir ();
477 g_variant_builder_add (builder, "{sv}", "cwd",
478 g_variant_new_bytestring (cwd));
482 G_APPLICATION_GET_CLASS (application)->
483 add_platform_data (application, builder);
485 result = g_variant_builder_end (builder);
486 g_variant_builder_unref (builder);
491 /* Application ID validity {{{1 */
494 * g_application_id_is_valid:
495 * @application_id: a potential application identifier
496 * @returns: %TRUE if @application_id is valid
498 * Checks if @application_id is a valid application ID. A valid ID is
499 * required for calls to g_application_new() and
500 * g_application_set_application_id().
503 g_application_id_is_valid (const gchar *application_id)
507 if (strlen (application_id) > 255)
510 if (!g_ascii_isalpha (*application_id))
515 for (; *application_id; application_id++)
517 if (g_ascii_isalnum (*application_id) ||
518 (*application_id == '-') ||
519 (*application_id == '_'))
521 else if (allow_dot && *application_id == '.')
530 /* Public Constructor {{{1 */
533 * @application_id: the application id
534 * @flags: the application flags
535 * @returns: a new #GApplication instance
537 * Creates a new #GApplication instance.
539 * This function calls g_type_init() for you.
541 * The application id must be valid. See g_application_id_is_valid().
544 g_application_new (const gchar *application_id,
545 GApplicationFlags flags)
547 g_return_val_if_fail (g_application_id_is_valid (application_id), NULL);
551 return g_object_new (G_TYPE_APPLICATION,
552 "application-id", application_id,
557 /* Simple get/set: application id, flags, inactivity timeout {{{1 */
559 * g_application_get_application_id:
560 * @application: a #GApplication
561 * @returns: the identifier for @application, owned by @application
563 * Gets the unique identifier for @application.
568 g_application_get_application_id (GApplication *application)
570 g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
572 return application->priv->id;
576 * g_application_set_application_id:
577 * @application: a #GApplication
578 * @application_id: the identifier for @application
580 * Sets the unique identifier for @application.
582 * The application id can only be modified if @application has not yet
585 * The application id must be valid. See g_application_id_is_valid().
590 g_application_set_application_id (GApplication *application,
591 const gchar *application_id)
593 g_return_if_fail (G_IS_APPLICATION (application));
595 if (g_strcmp0 (application->priv->id, application_id) != 0)
597 g_return_if_fail (g_application_id_is_valid (application_id));
598 g_return_if_fail (!application->priv->is_registered);
600 g_free (application->priv->id);
601 application->priv->id = g_strdup (application_id);
603 g_object_notify (G_OBJECT (application), "application-id");
608 * g_application_get_flags:
609 * @application: a #GApplication
610 * @returns: the flags for @application
612 * Gets the flags for @application.
614 * See #GApplicationFlags.
619 g_application_get_flags (GApplication *application)
621 g_return_val_if_fail (G_IS_APPLICATION (application), 0);
623 return application->priv->flags;
627 * g_application_set_flags:
628 * @application: a #GApplication
629 * @flags: the flags for @application
631 * Sets the flags for @application.
633 * The flags can only be modified if @application has not yet been
636 * See #GApplicationFlags.
641 g_application_set_flags (GApplication *application,
642 GApplicationFlags flags)
644 g_return_if_fail (G_IS_APPLICATION (application));
646 if (application->priv->flags != flags)
648 g_return_if_fail (!application->priv->is_registered);
650 application->priv->flags = flags;
652 g_object_notify (G_OBJECT (application), "flags");
657 * g_application_get_inactivity_timeout:
658 * @application: a #GApplication
660 * Gets the current inactivity timeout for the application.
662 * This is the amount of time (in milliseconds) after the last call to
663 * g_application_release() before the application stops running.
665 * Returns: the timeout, in milliseconds
670 g_application_get_inactivity_timeout (GApplication *application)
672 g_return_val_if_fail (G_IS_APPLICATION (application), 0);
674 return application->priv->inactivity_timeout;
678 * g_application_set_inactivity_timeout:
679 * @application: a #GApplication
680 * @inactivity_timeout: the timeout, in milliseconds
682 * Sets the current inactivity timeout for the application.
684 * This is the amount of time (in milliseconds) after the last call to
685 * g_application_release() before the application stops running.
687 * This call has no side effects of its own. The value set here is only
688 * used for next time g_application_release() drops the use count to
689 * zero. Any timeouts currently in progress are not impacted.
691 * Returns: the timeout, in milliseconds
696 g_application_set_inactivity_timeout (GApplication *application,
697 guint inactivity_timeout)
699 g_return_if_fail (G_IS_APPLICATION (application));
701 if (application->priv->inactivity_timeout != inactivity_timeout)
703 application->priv->inactivity_timeout = inactivity_timeout;
705 g_object_notify (G_OBJECT (application), "inactivity-timeout");
708 /* Read-only property getters (is registered, is remote) {{{1 */
710 * g_application_get_is_registered:
711 * @application: a #GApplication
712 * @returns: %TRUE if @application is registered
714 * Checks if @application is registered.
716 * An application is registered if g_application_register() has been
717 * successfully called.
722 g_application_get_is_registered (GApplication *application)
724 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
726 return application->priv->is_registered;
730 * g_application_get_is_remote:
731 * @application: a #GApplication
732 * @returns: %TRUE if @application is remote
734 * Checks if @application is remote.
736 * If @application is remote then it means that another instance of
737 * application already exists (the 'primary' instance). Calls to
738 * perform actions on @application will result in the actions being
739 * performed by the primary instance.
741 * The value of this property can not be accessed before
742 * g_application_register() has been called. See
743 * g_application_get_is_registered().
748 g_application_get_is_remote (GApplication *application)
750 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
751 g_return_val_if_fail (application->priv->is_registered, FALSE);
753 return application->priv->is_remote;
758 * g_application_register:
759 * @application: a #GApplication
760 * @cancellable: a #GCancellable, or %NULL
761 * @error: a pointer to a NULL #GError, or %NULL
762 * @returns: %TRUE if registration succeeded
764 * Attempts registration of the application.
766 * This is the point at which the application discovers if it is the
767 * primary instance or merely acting as a remote for an already-existing
770 * If the application has already been registered then %TRUE is
771 * returned with no work performed.
773 * The startup() virtual function is invoked if registration succeeds
774 * and @application is the primary instance.
776 * In the event of an error (such as @cancellable being cancelled, or a
777 * failure to connect to the session bus), %FALSE is returned and @error
778 * is set appropriately.
780 * Note: the return value of this function is not an indicator that this
781 * instance is or is not the primary instance of the application. See
782 * g_application_get_is_remote() for that.
787 g_application_register (GApplication *application,
788 GCancellable *cancellable,
791 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
793 if (!application->priv->is_registered)
798 /* don't try to be the primary instance if
799 * G_APPLICATION_IS_LAUNCHER was specified.
801 try = !(application->priv->flags & G_APPLICATION_IS_LAUNCHER);
803 application->priv->impl =
804 g_application_impl_register (application, application->priv->id,
805 application->priv->flags,
806 &is_remote, cancellable, error);
808 if (application->priv->impl == NULL)
811 application->priv->is_remote = is_remote;
812 application->priv->is_registered = TRUE;
814 g_object_notify (G_OBJECT (application), "is-registered");
817 g_signal_emit (application, g_application_signals[SIGNAL_STARTUP], 0);
823 /* Hold/release {{{1 */
825 * g_application_hold:
826 * @application: a #GApplication
828 * Increases the use count of @application.
830 * Use this function to indicate that the application has a reason to
831 * continue to run. For example, g_application_hold() is called by Gtk
832 * when a toplevel window is on the screen.
834 * To cancel the hold, call g_application_release().
837 g_application_hold (GApplication *application)
839 if (application->priv->inactivity_timeout_id)
841 g_source_remove (application->priv->inactivity_timeout_id);
842 application->priv->inactivity_timeout_id = 0;
845 application->priv->use_count++;
849 inactivity_timeout_expired (gpointer data)
851 GApplication *application = G_APPLICATION (data);
853 G_APPLICATION_GET_CLASS (application)
854 ->quit_mainloop (application);
861 * g_application_release:
862 * @application: a #GApplication
864 * Decrease the use count of @application.
866 * When the use count reaches zero, the application will stop running.
868 * Never call this function except to cancel the effect of a previous
869 * call to g_application_hold().
872 g_application_release (GApplication *application)
874 application->priv->use_count--;
876 if (application->priv->use_count == 0)
878 if (application->priv->inactivity_timeout)
879 application->priv->inactivity_timeout_id =
880 g_timeout_add (application->priv->inactivity_timeout,
881 inactivity_timeout_expired, application);
884 G_APPLICATION_GET_CLASS (application)
885 ->quit_mainloop (application);
889 /* Activate, Open {{{1 */
891 * g_application_activate:
892 * @application: a #GApplication
894 * Activates the application.
896 * In essence, this results in the activate() virtual function being
897 * invoked in the primary instance.
899 * The application must be registered before calling this function.
904 g_application_activate (GApplication *application)
906 g_return_if_fail (G_IS_APPLICATION (application));
907 g_return_if_fail (application->priv->is_registered);
909 if (application->priv->is_remote)
910 g_application_impl_activate (application->priv->impl,
911 get_platform_data (application));
914 g_signal_emit (application, g_application_signals[SIGNAL_ACTIVATE], 0);
918 * g_application_open:
919 * @application: a #GApplication
920 * @files: an array of #GFile<!-- -->s to open
921 * @n_files: the length of the @files array
922 * @hint: a hint (or ""), but never %NULL
924 * Opens the given files.
926 * In essence, this results in the open() virtual function being invoked
927 * in the primary instance.
929 * @n_files must be greater than zero.
931 * @hint is simply passed through to the open() virtual function. It is
932 * intended to be used by applications that have multiple modes for
933 * opening files (eg: "view" vs "edit", etc). Unless you have a need
934 * for this functionality, you should use "".
936 * The application must be registered before calling this function and
937 * it must have the %G_APPLICATION_CAN_OPEN flag set. The open()
938 * virtual function should also be implemented in order for anything
939 * meaningful to happen.
944 g_application_open (GApplication *application,
949 g_return_if_fail (G_IS_APPLICATION (application));
950 g_return_if_fail (application->priv->flags &
951 G_APPLICATION_HANDLES_OPEN);
952 g_return_if_fail (application->priv->is_registered);
954 if (application->priv->is_remote)
955 g_application_impl_open (application->priv->impl,
956 files, n_files, hint,
957 get_platform_data (application));
960 g_signal_emit (application, g_application_signals[SIGNAL_OPEN],
961 0, files, n_files, hint);
967 * @application: a #GApplication
968 * @argc: the argc from main()
969 * @argv: the argv from main()
970 * @returns: the exit status
972 * Runs the application.
974 * This function is intended to be run from main() and its return value
975 * is intended to be returned by main().
977 * First, the handle_command_line() virtual function is invoked. This
978 * function always runs on the local instance. If that function returns
979 * %FALSE then the application is registered and the command_line()
980 * virtual function is invoked in the primary instance (which may or may
981 * not be this instance).
983 * If the application has the %G_APPLICATION_REMOTE_COMMAND_LINE
984 * flag set then the default implementation of handle_command_line()
985 * always returns %FALSE immediately, resulting in the commandline
986 * always being handled in the primary instance.
988 * Otherwise, the default implementation of handle_command_line() tries
989 * to do a couple of things that are probably reasoanble for most
990 * applications. First, g_application_register() is called to attempt
991 * to register the application. If that works, then the command line
992 * arguments are inspected. If no commandline arguments are given, then
993 * g_application_activate() is called. If commandline arguments are
994 * given and the %G_APPLICATION_CAN_OPEN flags is set then they
995 * are assumed to be filenames and g_application_open() is called.
997 * If you are interested in doing more complicated local handling of the
998 * commandline then you should override handle_command_line().
1000 * If, after the above is done, the use count of the application is zero
1001 * then the exit status is returned immediately. If the use count is
1002 * non-zero then the mainloop is run until the use count falls to zero,
1003 * at which point 0 is returned.
1008 g_application_run (GApplication *application,
1016 g_return_val_if_fail (G_IS_APPLICATION (application), 1);
1017 g_return_val_if_fail (argc == 0 || argv != NULL, 1);
1019 arguments = g_new (gchar *, argc + 1);
1020 for (i = 0; i < argc; i++)
1021 arguments[i] = g_strdup (argv[i]);
1022 arguments[i] = NULL;
1024 if (g_get_prgname () == NULL && argc > 0)
1028 prgname = g_path_get_basename (argv[0]);
1029 g_set_prgname (prgname);
1033 if (!G_APPLICATION_GET_CLASS (application)
1034 ->local_command_line (application, &arguments, &status))
1036 GError *error = NULL;
1038 if (!g_application_register (application, NULL, &error))
1040 g_printerr ("%s", error->message);
1041 g_error_free (error);
1045 if (application->priv->is_remote)
1047 GVariant *platform_data;
1049 platform_data = get_platform_data (application);
1050 status = g_application_impl_command_line (application->priv->impl,
1051 arguments, platform_data);
1055 GApplicationCommandLine *cmdline;
1058 v = g_variant_new_bytestring_array ((const gchar **) arguments, -1);
1059 cmdline = g_object_new (G_TYPE_APPLICATION_COMMAND_LINE,
1060 "arguments", v, NULL);
1061 g_signal_emit (application,
1062 g_application_signals[SIGNAL_COMMAND_LINE],
1063 0, cmdline, &status);
1064 g_object_unref (cmdline);
1068 g_strfreev (arguments);
1070 if (application->priv->flags & G_APPLICATION_IS_SERVICE &&
1071 !application->priv->use_count &&
1072 !application->priv->inactivity_timeout_id)
1074 application->priv->inactivity_timeout_id =
1075 g_timeout_add (10000, inactivity_timeout_expired, application);
1078 if (application->priv->use_count ||
1079 application->priv->inactivity_timeout_id)
1081 G_APPLICATION_GET_CLASS (application)
1082 ->run_mainloop (application);
1086 if (application->priv->impl)
1087 g_application_impl_flush (application->priv->impl);
1093 g_application_has_action (GActionGroup *action_group,
1094 const gchar *action_name)
1096 GApplication *application = G_APPLICATION (action_group);
1098 g_return_val_if_fail (application->priv->is_registered, FALSE);
1100 return application->priv->actions &&
1101 g_action_group_has_action (application->priv->actions, action_name);
1105 g_application_list_actions (GActionGroup *action_group)
1107 GApplication *application = G_APPLICATION (action_group);
1109 g_return_val_if_fail (application->priv->is_registered, NULL);
1111 if (application->priv->actions != NULL)
1112 return g_action_group_list_actions (application->priv->actions);
1115 /* empty string array */
1116 return g_new0 (gchar *, 1);
1120 g_application_get_action_enabled (GActionGroup *action_group,
1121 const gchar *action_name)
1123 GApplication *application = G_APPLICATION (action_group);
1125 g_return_val_if_fail (application->priv->actions != NULL, FALSE);
1126 g_return_val_if_fail (application->priv->is_registered, FALSE);
1128 return g_action_group_get_action_enabled (application->priv->actions,
1132 static const GVariantType *
1133 g_application_get_action_parameter_type (GActionGroup *action_group,
1134 const gchar *action_name)
1136 GApplication *application = G_APPLICATION (action_group);
1138 g_return_val_if_fail (application->priv->actions != NULL, NULL);
1139 g_return_val_if_fail (application->priv->is_registered, NULL);
1141 return g_action_group_get_action_parameter_type (application->priv->actions,
1145 static const GVariantType *
1146 g_application_get_action_state_type (GActionGroup *action_group,
1147 const gchar *action_name)
1149 GApplication *application = G_APPLICATION (action_group);
1151 g_return_val_if_fail (application->priv->actions != NULL, NULL);
1152 g_return_val_if_fail (application->priv->is_registered, NULL);
1154 return g_action_group_get_action_state_type (application->priv->actions,
1159 g_application_get_action_state_hint (GActionGroup *action_group,
1160 const gchar *action_name)
1162 GApplication *application = G_APPLICATION (action_group);
1164 g_return_val_if_fail (application->priv->actions != NULL, NULL);
1165 g_return_val_if_fail (application->priv->is_registered, NULL);
1167 return g_action_group_get_action_state_hint (application->priv->actions,
1172 g_application_get_action_state (GActionGroup *action_group,
1173 const gchar *action_name)
1175 GApplication *application = G_APPLICATION (action_group);
1177 g_return_val_if_fail (application->priv->actions != NULL, NULL);
1178 g_return_val_if_fail (application->priv->is_registered, NULL);
1180 return g_action_group_get_action_state (application->priv->actions,
1185 g_application_change_action_state (GActionGroup *action_group,
1186 const gchar *action_name,
1189 GApplication *application = G_APPLICATION (action_group);
1191 g_return_if_fail (application->priv->actions != NULL);
1192 g_return_if_fail (application->priv->is_registered);
1194 g_action_group_change_action_state (application->priv->actions,
1195 action_name, value);
1199 g_application_activate_action (GActionGroup *action_group,
1200 const gchar *action_name,
1201 GVariant *parameter)
1203 GApplication *application = G_APPLICATION (action_group);
1205 g_return_if_fail (application->priv->actions != NULL);
1206 g_return_if_fail (application->priv->is_registered);
1208 g_action_group_activate_action (application->priv->actions,
1209 action_name, parameter);
1213 g_application_action_group_iface_init (GActionGroupInterface *iface)
1215 iface->has_action = g_application_has_action;
1216 iface->list_actions = g_application_list_actions;
1218 iface->get_action_enabled = g_application_get_action_enabled;
1219 iface->get_action_parameter_type = g_application_get_action_parameter_type;
1220 iface->get_action_state_type = g_application_get_action_state_type;
1221 iface->get_action_state_hint = g_application_get_action_state_hint;
1222 iface->get_action_state = g_application_get_action_state;
1223 iface->change_action_state = g_application_change_action_state;
1224 iface->activate_action = g_application_activate_action;
1228 /* vim:set foldmethod=marker: */