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,
161 GVariant **arguments,
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_variant_n_children (*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++)
219 g_variant_get_child (*arguments, i + 1, "^&ay", &arg);
220 files[i] = g_file_new_for_commandline_arg (arg);
223 g_application_open (application, files, n_files, "");
225 for (i = 0; i < n_files; i++)
226 g_object_unref (files[i]);
238 g_application_real_add_platform_data (GApplication *application,
239 GVariantBuilder *builder)
244 g_application_real_quit_mainloop (GApplication *application)
246 if (application->priv->mainloop != NULL)
247 g_main_loop_quit (application->priv->mainloop);
251 g_application_real_run_mainloop (GApplication *application)
253 if (application->priv->mainloop == NULL)
254 application->priv->mainloop = g_main_loop_new (NULL, FALSE);
256 g_main_loop_run (application->priv->mainloop);
259 /* GObject implementation stuff {{{1 */
261 g_application_set_property (GObject *object, guint prop_id,
262 const GValue *value, GParamSpec *pspec)
264 GApplication *application = G_APPLICATION (object);
268 case PROP_APPLICATION_ID:
269 g_application_set_application_id (application,
270 g_value_get_string (value));
274 g_application_set_flags (application, g_value_get_flags (value));
277 case PROP_INACTIVITY_TIMEOUT:
278 g_application_set_inactivity_timeout (application,
279 g_value_get_uint (value));
282 case PROP_ACTION_GROUP:
283 g_application_set_action_group (application,
284 g_value_get_object (value));
288 g_assert_not_reached ();
293 * g_application_set_action_group:
294 * @application: a #GApplication
295 * @action_group: a #GActionGroup, or %NULL
297 * Sets or unsets the group of actions associated with the application.
299 * These actions are the actions that can be remotely invoked.
301 * It is an error to call this function after the application has been
307 g_application_set_action_group (GApplication *application,
308 GActionGroup *action_group)
310 g_return_if_fail (G_IS_APPLICATION (application));
311 g_return_if_fail (application->priv->is_registered);
313 if (application->priv->actions != NULL)
314 g_object_unref (application->priv->actions);
316 application->priv->actions = action_group;
318 if (application->priv->actions != NULL)
319 g_object_ref (application->priv->actions);
323 g_application_get_property (GObject *object, guint prop_id,
324 GValue *value, GParamSpec *pspec)
326 GApplication *application = G_APPLICATION (object);
330 case PROP_APPLICATION_ID:
331 g_value_set_string (value,
332 g_application_get_application_id (application));
336 g_value_set_flags (value,
337 g_application_get_flags (application));
340 case PROP_IS_REGISTERED:
341 g_value_set_boolean (value,
342 g_application_get_is_registered (application));
346 g_value_set_boolean (value,
347 g_application_get_is_remote (application));
350 case PROP_INACTIVITY_TIMEOUT:
351 g_value_set_uint (value,
352 g_application_get_inactivity_timeout (application));
356 g_assert_not_reached ();
361 g_application_constructed (GObject *object)
363 GApplication *application = G_APPLICATION (object);
365 g_assert (application->priv->id != NULL);
369 g_application_finalize (GObject *object)
371 GApplication *application = G_APPLICATION (object);
373 if (application->priv->impl)
374 g_application_impl_destroy (application->priv->impl);
375 g_free (application->priv->id);
377 if (application->priv->mainloop)
378 g_main_loop_unref (application->priv->mainloop);
380 G_OBJECT_CLASS (g_application_parent_class)
385 g_application_init (GApplication *application)
387 application->priv = G_TYPE_INSTANCE_GET_PRIVATE (application,
389 GApplicationPrivate);
393 g_application_class_init (GApplicationClass *class)
395 GObjectClass *object_class = G_OBJECT_CLASS (class);
397 object_class->constructed = g_application_constructed;
398 object_class->finalize = g_application_finalize;
399 object_class->get_property = g_application_get_property;
400 object_class->set_property = g_application_set_property;
402 class->before_emit = g_application_real_before_emit;
403 class->after_emit = g_application_real_after_emit;
404 class->startup = g_application_real_startup;
405 class->activate = g_application_real_activate;
406 class->open = g_application_real_open;
407 class->command_line = g_application_real_command_line;
408 class->local_command_line = g_application_real_local_command_line;
409 class->add_platform_data = g_application_real_add_platform_data;
410 class->quit_mainloop = g_application_real_quit_mainloop;
411 class->run_mainloop = g_application_real_run_mainloop;
413 g_object_class_install_property (object_class, PROP_APPLICATION_ID,
414 g_param_spec_string ("application-id", "application identifier",
415 "Unique identifier for the application",
416 NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
417 G_PARAM_STATIC_STRINGS));
419 g_object_class_install_property (object_class, PROP_FLAGS,
420 g_param_spec_flags ("flags", "application flags",
421 "Flags specifying the behaviour of the application",
422 G_TYPE_APPLICATION_FLAGS, G_APPLICATION_FLAGS_NONE,
423 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
425 g_object_class_install_property (object_class, PROP_IS_REGISTERED,
426 g_param_spec_boolean ("is-registered", "is registered",
427 "If g_application_register() has been called",
428 FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
430 g_object_class_install_property (object_class, PROP_IS_REMOTE,
431 g_param_spec_boolean ("is-remote", "is remote",
432 "If this application instance is remote",
433 FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
435 g_object_class_install_property (object_class, PROP_INACTIVITY_TIMEOUT,
436 g_param_spec_boolean ("inactivity-timeout", "inactivity timeout",
437 "time (ms) to stay alive after becoming idle",
438 FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
440 g_object_class_install_property (object_class, PROP_ACTION_GROUP,
441 g_param_spec_object ("action-group", "action group",
442 "the group of actions that the application exports",
444 G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
446 g_application_signals[SIGNAL_STARTUP] =
447 g_signal_new ("startup", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
448 G_STRUCT_OFFSET (GApplicationClass, startup),
449 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
451 g_application_signals[SIGNAL_ACTIVATE] =
452 g_signal_new ("activate", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
453 G_STRUCT_OFFSET (GApplicationClass, activate),
454 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
456 g_application_signals[SIGNAL_OPEN] =
457 g_signal_new ("open", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
458 G_STRUCT_OFFSET (GApplicationClass, open),
459 NULL, NULL, _gio_marshal_VOID__POINTER_INT_STRING,
460 G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);
462 g_application_signals[SIGNAL_COMMAND_LINE] =
463 g_signal_new ("command-line", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
464 G_STRUCT_OFFSET (GApplicationClass, command_line),
465 g_signal_accumulator_first_wins, NULL,
466 _gio_marshal_INT__OBJECT,
467 G_TYPE_INT, 1, G_TYPE_APPLICATION_COMMAND_LINE);
469 g_type_class_add_private (class, sizeof (GApplicationPrivate));
473 get_platform_data (GApplication *application)
475 GVariantBuilder *builder;
478 builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
481 gchar *cwd = g_get_current_dir ();
482 g_variant_builder_add (builder, "{sv}", "cwd",
483 g_variant_new_bytestring (cwd));
487 G_APPLICATION_GET_CLASS (application)->
488 add_platform_data (application, builder);
490 result = g_variant_builder_end (builder);
491 g_variant_builder_unref (builder);
496 /* Application ID validity {{{1 */
499 * g_application_id_is_valid:
500 * @application_id: a potential application identifier
501 * @returns: %TRUE if @application_id is valid
503 * Checks if @application_id is a valid application ID. A valid ID is
504 * required for calls to g_application_new() and
505 * g_application_set_application_id().
508 g_application_id_is_valid (const gchar *application_id)
512 if (strlen (application_id) > 255)
515 if (!g_ascii_isalpha (*application_id))
520 for (; *application_id; application_id++)
522 if (g_ascii_isalnum (*application_id) ||
523 (*application_id == '-') ||
524 (*application_id == '_'))
526 else if (allow_dot && *application_id == '.')
535 /* Public Constructor {{{1 */
538 * @application_id: the application id
539 * @flags: the application flags
540 * @returns: a new #GApplication instance
542 * Creates a new #GApplication instance.
544 * This function calls g_type_init() for you.
546 * The application id must be valid. See g_application_id_is_valid().
549 g_application_new (const gchar *application_id,
550 GApplicationFlags flags)
552 g_return_val_if_fail (g_application_id_is_valid (application_id), NULL);
556 return g_object_new (G_TYPE_APPLICATION,
557 "application-id", application_id,
562 /* Simple get/set: application id, flags, inactivity timeout {{{1 */
564 * g_application_get_application_id:
565 * @application: a #GApplication
566 * @returns: the identifier for @application, owned by @application
568 * Gets the unique identifier for @application.
573 g_application_get_application_id (GApplication *application)
575 g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
577 return application->priv->id;
581 * g_application_set_application_id:
582 * @application: a #GApplication
583 * @application_id: the identifier for @application
585 * Sets the unique identifier for @application.
587 * The application id can only be modified if @application has not yet
590 * The application id must be valid. See g_application_id_is_valid().
595 g_application_set_application_id (GApplication *application,
596 const gchar *application_id)
598 g_return_if_fail (G_IS_APPLICATION (application));
600 if (g_strcmp0 (application->priv->id, application_id) != 0)
602 g_return_if_fail (g_application_id_is_valid (application_id));
603 g_return_if_fail (!application->priv->is_registered);
605 g_free (application->priv->id);
606 application->priv->id = g_strdup (application_id);
608 g_object_notify (G_OBJECT (application), "application-id");
613 * g_application_get_flags:
614 * @application: a #GApplication
615 * @returns: the flags for @application
617 * Gets the flags for @application.
619 * See #GApplicationFlags.
624 g_application_get_flags (GApplication *application)
626 g_return_val_if_fail (G_IS_APPLICATION (application), 0);
628 return application->priv->flags;
632 * g_application_set_flags:
633 * @application: a #GApplication
634 * @flags: the flags for @application
636 * Sets the flags for @application.
638 * The flags can only be modified if @application has not yet been
641 * See #GApplicationFlags.
646 g_application_set_flags (GApplication *application,
647 GApplicationFlags flags)
649 g_return_if_fail (G_IS_APPLICATION (application));
651 if (application->priv->flags != flags)
653 g_return_if_fail (!application->priv->is_registered);
655 application->priv->flags = flags;
657 g_object_notify (G_OBJECT (application), "flags");
662 * g_application_get_inactivity_timeout:
663 * @application: a #GApplication
665 * Gets the current inactivity timeout for the application.
667 * This is the amount of time (in milliseconds) after the last call to
668 * g_application_release() before the application stops running.
670 * Returns: the timeout, in milliseconds
675 g_application_get_inactivity_timeout (GApplication *application)
677 g_return_val_if_fail (G_IS_APPLICATION (application), 0);
679 return application->priv->inactivity_timeout;
683 * g_application_set_inactivity_timeout:
684 * @application: a #GApplication
685 * @inactivity_timeout: the timeout, in milliseconds
687 * Sets the current inactivity timeout for the application.
689 * This is the amount of time (in milliseconds) after the last call to
690 * g_application_release() before the application stops running.
692 * This call has no side effects of its own. The value set here is only
693 * used for next time g_application_release() drops the use count to
694 * zero. Any timeouts currently in progress are not impacted.
696 * Returns: the timeout, in milliseconds
701 g_application_set_inactivity_timeout (GApplication *application,
702 guint inactivity_timeout)
704 g_return_if_fail (G_IS_APPLICATION (application));
706 if (application->priv->inactivity_timeout != inactivity_timeout)
708 application->priv->inactivity_timeout = inactivity_timeout;
710 g_object_notify (G_OBJECT (application), "inactivity-timeout");
713 /* Read-only property getters (is registered, is remote) {{{1 */
715 * g_application_get_is_registered:
716 * @application: a #GApplication
717 * @returns: %TRUE if @application is registered
719 * Checks if @application is registered.
721 * An application is registered if g_application_register() has been
722 * successfully called.
727 g_application_get_is_registered (GApplication *application)
729 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
731 return application->priv->is_registered;
735 * g_application_get_is_remote:
736 * @application: a #GApplication
737 * @returns: %TRUE if @application is remote
739 * Checks if @application is remote.
741 * If @application is remote then it means that another instance of
742 * application already exists (the 'primary' instance). Calls to
743 * perform actions on @application will result in the actions being
744 * performed by the primary instance.
746 * The value of this property can not be accessed before
747 * g_application_register() has been called. See
748 * g_application_get_is_registered().
753 g_application_get_is_remote (GApplication *application)
755 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
756 g_return_val_if_fail (application->priv->is_registered, FALSE);
758 return application->priv->is_remote;
763 * g_application_register:
764 * @application: a #GApplication
765 * @cancellable: a #GCancellable, or %NULL
766 * @error: a pointer to a NULL #GError, or %NULL
767 * @returns: %TRUE if registration succeeded
769 * Attempts registration of the application.
771 * This is the point at which the application discovers if it is the
772 * primary instance or merely acting as a remote for an already-existing
775 * If the application has already been registered then %TRUE is
776 * returned with no work performed.
778 * The startup() virtual function is invoked if registration succeeds
779 * and @application is the primary instance.
781 * In the event of an error (such as @cancellable being cancelled, or a
782 * failure to connect to the session bus), %FALSE is returned and @error
783 * is set appropriately.
785 * Note: the return value of this function is not an indicator that this
786 * instance is or is not the primary instance of the application. See
787 * g_application_get_is_remote() for that.
792 g_application_register (GApplication *application,
793 GCancellable *cancellable,
796 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
798 if (!application->priv->is_registered)
803 /* don't try to be the primary instance if
804 * G_APPLICATION_IS_LAUNCHER was specified.
806 try = !(application->priv->flags & G_APPLICATION_IS_LAUNCHER);
808 application->priv->impl =
809 g_application_impl_register (application, application->priv->id,
810 application->priv->flags,
811 &is_remote, cancellable, error);
813 if (application->priv->impl == NULL)
816 application->priv->is_remote = is_remote;
817 application->priv->is_registered = TRUE;
819 g_object_notify (G_OBJECT (application), "is-registered");
822 g_signal_emit (application, g_application_signals[SIGNAL_STARTUP], 0);
828 /* Hold/release {{{1 */
830 * g_application_hold:
831 * @application: a #GApplication
833 * Increases the use count of @application.
835 * Use this function to indicate that the application has a reason to
836 * continue to run. For example, g_application_hold() is called by Gtk
837 * when a toplevel window is on the screen.
839 * To cancel the hold, call g_application_release().
842 g_application_hold (GApplication *application)
844 if (application->priv->inactivity_timeout_id)
846 g_source_remove (application->priv->inactivity_timeout_id);
847 application->priv->inactivity_timeout_id = 0;
850 application->priv->use_count++;
854 inactivity_timeout_expired (gpointer data)
856 GApplication *application = G_APPLICATION (data);
858 G_APPLICATION_GET_CLASS (application)
859 ->quit_mainloop (application);
866 * g_application_release:
867 * @application: a #GApplication
869 * Decrease the use count of @application.
871 * When the use count reaches zero, the application will stop running.
873 * Never call this function except to cancel the effect of a previous
874 * call to g_application_hold().
877 g_application_release (GApplication *application)
879 application->priv->use_count--;
881 if (application->priv->use_count == 0)
883 if (application->priv->inactivity_timeout)
884 application->priv->inactivity_timeout_id =
885 g_timeout_add (application->priv->inactivity_timeout,
886 inactivity_timeout_expired, application);
889 G_APPLICATION_GET_CLASS (application)
890 ->quit_mainloop (application);
894 /* Activate, Open {{{1 */
896 * g_application_activate:
897 * @application: a #GApplication
899 * Activates the application.
901 * In essence, this results in the activate() virtual function being
902 * invoked in the primary instance.
904 * The application must be registered before calling this function.
909 g_application_activate (GApplication *application)
911 g_return_if_fail (G_IS_APPLICATION (application));
912 g_return_if_fail (application->priv->is_registered);
914 if (application->priv->is_remote)
915 g_application_impl_activate (application->priv->impl,
916 get_platform_data (application));
919 g_signal_emit (application, g_application_signals[SIGNAL_ACTIVATE], 0);
923 * g_application_open:
924 * @application: a #GApplication
925 * @files: an array of #GFile<!-- -->s to open
926 * @n_files: the length of the @files array
927 * @hint: a hint (or ""), but never %NULL
929 * Opens the given files.
931 * In essence, this results in the open() virtual function being invoked
932 * in the primary instance.
934 * @n_files must be greater than zero.
936 * @hint is simply passed through to the open() virtual function. It is
937 * intended to be used by applications that have multiple modes for
938 * opening files (eg: "view" vs "edit", etc). Unless you have a need
939 * for this functionality, you should use "".
941 * The application must be registered before calling this function and
942 * it must have the %G_APPLICATION_CAN_OPEN flag set. The open()
943 * virtual function should also be implemented in order for anything
944 * meaningful to happen.
949 g_application_open (GApplication *application,
954 g_return_if_fail (G_IS_APPLICATION (application));
955 g_return_if_fail (application->priv->flags &
956 G_APPLICATION_HANDLES_OPEN);
957 g_return_if_fail (application->priv->is_registered);
959 if (application->priv->is_remote)
960 g_application_impl_open (application->priv->impl,
961 files, n_files, hint,
962 get_platform_data (application));
965 g_signal_emit (application, g_application_signals[SIGNAL_OPEN],
966 0, files, n_files, hint);
972 * @application: a #GApplication
973 * @argc: the argc from main()
974 * @argv: the argv from main()
975 * @returns: the exit status
977 * Runs the application.
979 * This function is intended to be run from main() and its return value
980 * is intended to be returned by main().
982 * First, the handle_command_line() virtual function is invoked. This
983 * function always runs on the local instance. If that function returns
984 * %FALSE then the application is registered and the command_line()
985 * virtual function is invoked in the primary instance (which may or may
986 * not be this instance).
988 * If the application has the %G_APPLICATION_REMOTE_COMMAND_LINE
989 * flag set then the default implementation of handle_command_line()
990 * always returns %FALSE immediately, resulting in the commandline
991 * always being handled in the primary instance.
993 * Otherwise, the default implementation of handle_command_line() tries
994 * to do a couple of things that are probably reasoanble for most
995 * applications. First, g_application_register() is called to attempt
996 * to register the application. If that works, then the command line
997 * arguments are inspected. If no commandline arguments are given, then
998 * g_application_activate() is called. If commandline arguments are
999 * given and the %G_APPLICATION_CAN_OPEN flags is set then they
1000 * are assumed to be filenames and g_application_open() is called.
1002 * If you are interested in doing more complicated local handling of the
1003 * commandline then you should override handle_command_line().
1005 * If, after the above is done, the use count of the application is zero
1006 * then the exit status is returned immediately. If the use count is
1007 * non-zero then the mainloop is run until the use count falls to zero,
1008 * at which point 0 is returned.
1013 g_application_run (GApplication *application,
1017 g_return_val_if_fail (G_IS_APPLICATION (application), 1);
1018 g_return_val_if_fail (argc == 0 || argv != NULL, 1);
1020 return g_application_run_with_arguments (application,
1021 g_variant_new_bytestring_array ((const gchar **) argv, argc));
1025 * g_application_run_with_arguments:
1026 * @application: a #GApplication
1027 * @arguments: a bytestring array #GVariant
1028 * @returns: the exit status
1030 * This is a bindings-friendly version of g_application_run().
1032 * This function will consume @arguments if it is floating.
1035 g_application_run_with_arguments (GApplication *application,
1036 GVariant *arguments)
1040 g_return_val_if_fail (G_IS_APPLICATION (application), 1);
1041 g_return_val_if_fail (G_IS_APPLICATION (application), 1);
1043 g_variant_ref_sink (arguments);
1045 if (g_get_prgname () == NULL && g_variant_n_children (arguments))
1050 g_variant_get_child (arguments, 0, "^&ay", &argv0);
1051 prgname = g_path_get_basename (argv0);
1052 g_set_prgname (prgname);
1056 if (!G_APPLICATION_GET_CLASS (application)
1057 ->local_command_line (application, &arguments, &status))
1059 GError *error = NULL;
1061 if (!g_application_register (application, NULL, &error))
1063 g_printerr ("%s", error->message);
1064 g_error_free (error);
1068 if (application->priv->is_remote)
1070 GVariant *platform_data;
1072 platform_data = get_platform_data (application);
1073 status = g_application_impl_command_line (application->priv->impl,
1074 arguments, platform_data);
1078 GApplicationCommandLine *cmdline;
1080 cmdline = g_object_new (G_TYPE_APPLICATION_COMMAND_LINE,
1081 "arguments", arguments, NULL);
1082 g_signal_emit (application,
1083 g_application_signals[SIGNAL_COMMAND_LINE],
1084 0, cmdline, &status);
1085 g_object_unref (cmdline);
1089 g_variant_unref (arguments);
1091 if (application->priv->flags & G_APPLICATION_IS_SERVICE &&
1092 !application->priv->use_count &&
1093 !application->priv->inactivity_timeout_id)
1095 application->priv->inactivity_timeout_id =
1096 g_timeout_add (10000, inactivity_timeout_expired, application);
1099 if (application->priv->use_count ||
1100 application->priv->inactivity_timeout_id)
1102 G_APPLICATION_GET_CLASS (application)
1103 ->run_mainloop (application);
1107 if (application->priv->impl)
1108 g_application_impl_flush (application->priv->impl);
1114 g_application_has_action (GActionGroup *action_group,
1115 const gchar *action_name)
1117 GApplication *application = G_APPLICATION (action_group);
1119 g_return_val_if_fail (application->priv->is_registered, FALSE);
1121 return application->priv->actions &&
1122 g_action_group_has_action (application->priv->actions, action_name);
1126 g_application_list_actions (GActionGroup *action_group)
1128 GApplication *application = G_APPLICATION (action_group);
1130 g_return_val_if_fail (application->priv->is_registered, NULL);
1132 if (application->priv->actions != NULL)
1133 return g_action_group_list_actions (application->priv->actions);
1136 /* empty string array */
1137 return g_new0 (gchar *, 1);
1141 g_application_get_action_enabled (GActionGroup *action_group,
1142 const gchar *action_name)
1144 GApplication *application = G_APPLICATION (action_group);
1146 g_return_val_if_fail (application->priv->actions != NULL, FALSE);
1147 g_return_val_if_fail (application->priv->is_registered, FALSE);
1149 return g_action_group_get_action_enabled (application->priv->actions,
1153 static const GVariantType *
1154 g_application_get_action_parameter_type (GActionGroup *action_group,
1155 const gchar *action_name)
1157 GApplication *application = G_APPLICATION (action_group);
1159 g_return_val_if_fail (application->priv->actions != NULL, NULL);
1160 g_return_val_if_fail (application->priv->is_registered, NULL);
1162 return g_action_group_get_action_parameter_type (application->priv->actions,
1166 static const GVariantType *
1167 g_application_get_action_state_type (GActionGroup *action_group,
1168 const gchar *action_name)
1170 GApplication *application = G_APPLICATION (action_group);
1172 g_return_val_if_fail (application->priv->actions != NULL, NULL);
1173 g_return_val_if_fail (application->priv->is_registered, NULL);
1175 return g_action_group_get_action_state_type (application->priv->actions,
1180 g_application_get_action_state_hint (GActionGroup *action_group,
1181 const gchar *action_name)
1183 GApplication *application = G_APPLICATION (action_group);
1185 g_return_val_if_fail (application->priv->actions != NULL, NULL);
1186 g_return_val_if_fail (application->priv->is_registered, NULL);
1188 return g_action_group_get_action_state_hint (application->priv->actions,
1193 g_application_get_action_state (GActionGroup *action_group,
1194 const gchar *action_name)
1196 GApplication *application = G_APPLICATION (action_group);
1198 g_return_val_if_fail (application->priv->actions != NULL, NULL);
1199 g_return_val_if_fail (application->priv->is_registered, NULL);
1201 return g_action_group_get_action_state (application->priv->actions,
1206 g_application_change_action_state (GActionGroup *action_group,
1207 const gchar *action_name,
1210 GApplication *application = G_APPLICATION (action_group);
1212 g_return_if_fail (application->priv->actions != NULL);
1213 g_return_if_fail (application->priv->is_registered);
1215 g_action_group_change_action_state (application->priv->actions,
1216 action_name, value);
1220 g_application_activate_action (GActionGroup *action_group,
1221 const gchar *action_name,
1222 GVariant *parameter)
1224 GApplication *application = G_APPLICATION (action_group);
1226 g_return_if_fail (application->priv->actions != NULL);
1227 g_return_if_fail (application->priv->is_registered);
1229 g_action_group_activate_action (application->priv->actions,
1230 action_name, parameter);
1234 g_application_action_group_iface_init (GActionGroupInterface *iface)
1236 iface->has_action = g_application_has_action;
1237 iface->list_actions = g_application_list_actions;
1239 iface->get_action_enabled = g_application_get_action_enabled;
1240 iface->get_action_parameter_type = g_application_get_action_parameter_type;
1241 iface->get_action_state_type = g_application_get_action_state_type;
1242 iface->get_action_state_hint = g_application_get_action_state_hint;
1243 iface->get_action_state = g_application_get_action_state;
1244 iface->change_action_state = g_application_change_action_state;
1245 iface->activate_action = g_application_activate_action;
1249 /* vim:set foldmethod=marker: */