1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright © 2010 Red Hat, Inc
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Authors: Colin Walters <walters@verbum.org>
21 * Emmanuele Bassi <ebassi@linux.intel.com>
29 #include <gobject/gvaluecollector.h>
31 #include "gapplication.h"
32 #include "gio-marshal.h"
36 #include "ginitable.h"
38 #include "gdbusconnection.h"
39 #include "gdbusintrospection.h"
40 #include "gdbusmethodinvocation.h"
45 * SECTION: gapplication
46 * @title: GApplication
47 * @short_description: Core application class
49 * A #GApplication is the foundation of an application, unique for a
50 * given application identifier. The #GApplication wraps some
51 * low-level platform-specific services and is intended to act as the
52 * foundation for higher-level application classes such as
53 * #GtkApplication or #MxApplication. In general, you should not use
54 * this class outside of a higher level framework. By default,
55 * g_application_register_with_data() will invoke g_error() if it is
56 * run in a context where it cannot support its core features. Note
57 * that g_error() is by default fatal.
59 * One of the core features that #GApplication provides is process
60 * uniqueness, in the context of a "session". The session concept is
61 * platform-dependent, but corresponds roughly to a graphical desktop
62 * login. When your application is launched again, its arguments
63 * are passed through platform communication to the already running
66 * In addition, #GApplication provides support for 'actions', which
67 * can be presented to the user in a platform-specific way
68 * (e.g. Windows 7 jump lists). Note that these are just simple
69 * actions without parameters. For more flexible scriptability,
70 * implementing a a separate D-Bus interface is recommended, see e.g.
71 * <xref linkend="gdbus-convenience"/>.
73 * Finally, #GApplication acts as a basic lifecycle root; see the
74 * g_application_run() and g_application_quit_with_data() methods.
76 * Before using #GApplication, you must choose an "application identifier".
77 * The expected form of an application identifier is very close to that of
78 * of a <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface">DBus bus name</ulink>.
79 * Examples include: "com.example.MyApp" "org.example.internal-apps.Calculator"
80 * For convenience, the restrictions on application identifiers are reproduced
83 * <listitem>Application identifiers must contain only the ASCII characters "[A-Z][a-z][0-9]_-" and must not begin with a digit.</listitem>
84 * <listitem>Application identifiers must contain at least one '.' (period) character (and thus at least two elements).</listitem>
85 * <listitem>Application identifiers must not begin with a '.' (period) character.</listitem>
86 * <listitem>Application identifiers must not exceed 255 characters.</listitem>
89 * <refsect2><title>D-Bus implementation</title>
91 * On UNIX systems using D-Bus, #GApplication is implemented by claiming the
92 * application identifier as a bus name on the session bus. The implementation
93 * exports an object at the object path that is created by replacing '.' with
94 * '/' in the application identifier (e.g. the object path for the
95 * application id 'org.gtk.TestApp' is '/org/gtk/TestApp'). The object
96 * implements the org.gtk.Application interface.
98 * <classsynopsis class="interface">
99 * <ooclass><interfacename>org.gtk.Application</interfacename></ooclass>
102 * <methodname>Activate</methodname>
103 * <methodparam><modifier>in</modifier><type>aay</type><parameter>arguments</parameter></methodparam>
104 * <methodparam><modifier>in</modifier><type>a{sv}</type><parameter>data</parameter></methodparam>
108 * <methodname>InvokeAction</methodname>
109 * <methodparam><modifier>in</modifier><type>s</type><parameter>action</parameter></methodparam>
110 * <methodparam><modifier>in</modifier><type>a{sv}</type><parameter>data</parameter></methodparam>
113 * <type>a{s(sb)}</type>
114 * <methodname>ListActions</methodname>
119 * <methodname>Quit</methodname>
120 * <methodparam><modifier>in</modifier><type>a{sv}</type><parameter>data</parameter></methodparam>
123 * <modifier>Signal</modifier>
125 * <methodname>ActionsChanged</methodname>
130 * The <methodname>Activate</methodname> function is called on the existing
131 * application instance when a second instance fails to take the bus name.
132 * @arguments contains the commandline arguments given to the second instance
133 * and @data contains platform-specific additional data.
135 * On all platforms, @data is guaranteed to have a key "cwd" of type
136 * singature "ay" which contains the working directory of the invoked
141 * The <methodname>InvokeAction</methodname> function can be called to
142 * invoke one of the actions exported by the application. On X11
143 * platforms, the platform_data argument should have a "timestamp"
144 * parameter of type "u" with the server time of the initiating event.
147 * The <methodname>ListActions</methodname> function returns a dictionary
148 * with the exported actions of the application. The keys of the dictionary
149 * are the action names, and the values are structs containing the description
150 * for the action and a boolean that represents if the action is enabled or not.
153 * The <methodname>Quit</methodname> function can be called to
154 * terminate the application. The @data parameter contains
155 * platform-specific data. On X11 platforms, the platform_data
156 * argument should have a "timestamp" parameter of type "u" with the
157 * server time of the initiating event.
160 * The <methodname>ActionsChanged</methodname> signal is emitted when the
161 * exported actions change (i.e. an action is added, removed, enabled,
162 * disabled, or otherwise changed).
165 * #GApplication is supported since Gio 2.26.
170 static void initable_iface_init (GInitableIface *initable_iface);
172 G_DEFINE_TYPE_WITH_CODE (GApplication, g_application, G_TYPE_OBJECT,
173 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init));
197 static guint application_signals[LAST_SIGNAL] = { 0 };
203 } GApplicationAction;
205 struct _GApplicationPrivate
208 GHashTable *actions; /* name -> GApplicationAction */
212 GVariant *platform_data;
214 guint do_register : 1;
215 guint default_quit : 1;
218 guint actions_changed_id;
222 GDBusConnection *session_bus;
226 static GApplication *primary_application = NULL;
227 static GHashTable *instances_for_appid = NULL;
229 static gboolean initable_init (GInitable *initable,
230 GCancellable *cancellable,
233 static gboolean _g_application_platform_init (GApplication *app,
234 GCancellable *cancellable,
236 static gboolean _g_application_platform_register (GApplication *app,
238 GCancellable *cancellable,
241 static void _g_application_platform_remote_invoke_action (GApplication *app,
243 GVariant *platform_data);
244 static void _g_application_platform_remote_quit (GApplication *app,
245 GVariant *platform_data);
246 static void _g_application_platform_on_actions_changed (GApplication *app);
249 initable_iface_init (GInitableIface *initable_iface)
251 initable_iface->init = initable_init;
255 #include "gdbusapplication.c"
257 #include "gnullapplication.c"
261 _g_application_validate_id (const char *id)
265 if (strlen (id) > 255)
268 if (!g_ascii_isalpha (*id))
275 if (g_ascii_isalnum (*id) || (*id == '-') || (*id == '_'))
277 else if (allow_dot && *id == '.')
286 init_appid_statics (gpointer data)
288 instances_for_appid = g_hash_table_new (g_str_hash, g_str_equal);
292 static GApplication *
293 application_for_appid (const char *appid)
295 static GOnce appid_once = G_ONCE_INIT;
297 g_once (&appid_once, init_appid_statics, NULL);
299 return g_hash_table_lookup (instances_for_appid, appid);
303 g_application_default_quit_with_data (GApplication *application,
304 GVariant *platform_data)
306 g_return_val_if_fail (application->priv->mainloop != NULL, FALSE);
307 g_main_loop_quit (application->priv->mainloop);
313 g_application_default_run (GApplication *application)
315 if (application->priv->mainloop == NULL)
316 application->priv->mainloop = g_main_loop_new (NULL, TRUE);
318 g_main_loop_run (application->priv->mainloop);
322 variant_from_argv (int argc,
325 GVariantBuilder builder;
328 g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay"));
330 for (i = 1; i < argc; i++)
334 argv_bytes = (guint8*) argv[i];
335 g_variant_builder_add_value (&builder,
336 g_variant_new_byte_array (argv_bytes, -1));
339 return g_variant_builder_end (&builder);
343 timeout_handle_actions_changed (gpointer user_data)
345 GApplication *application = user_data;
347 application->priv->actions_changed_id = 0;
349 _g_application_platform_on_actions_changed (application);
355 queue_actions_change_notification (GApplication *application)
357 GApplicationPrivate *priv = application->priv;
359 if (priv->actions_changed_id == 0)
360 priv->actions_changed_id = g_timeout_add (0, timeout_handle_actions_changed, application);
364 initable_init (GInitable *initable,
365 GCancellable *cancellable,
368 GApplication *app = G_APPLICATION (initable);
371 if (!_g_application_platform_init (app, cancellable, error))
374 if (app->priv->do_register &&
375 !_g_application_platform_register (app, &unique, cancellable ,error))
382 g_application_action_free (gpointer data)
384 if (G_LIKELY (data != NULL))
386 GApplicationAction *action = data;
388 g_free (action->name);
389 g_free (action->description);
391 g_slice_free (GApplicationAction, action);
397 * @appid: System-dependent application identifier
398 * @argc: Number of arguments in @argv
399 * @argv: (allow-none) (array length=argc): Argument vector, usually from the <parameter>argv</parameter> parameter of main()
401 * Create a new #GApplication. This uses a platform-specific
402 * mechanism to ensure the current process is the unique owner of the
403 * application (as defined by the @appid). If successful, the
404 * #GApplication:is-remote property will be %FALSE, and it is safe to
405 * continue creating other resources such as graphics windows.
407 * If the given @appid is already running in another process, the the
408 * GApplication::activate_with_data signal will be emitted in the
409 * remote process, with the data from @argv and other
410 * platform-specific data available. Subsequently the
411 * #GApplication:default-exit property will be evaluated. If it's
412 * %TRUE, then the current process will terminate. If %FALSE, then
413 * the application remains in the #GApplication:is-remote state, and
414 * you can e.g. call g_application_invoke_action().
416 * This function may do synchronous I/O to obtain unique ownership
417 * of the application id, and will block the calling thread in this
420 * If the environment does not support the basic functionality of
421 * #GApplication, this function will invoke g_error(), which by
422 * default is a fatal operation. This may arise for example on
423 * UNIX systems using D-Bus when the session bus is not available.
425 * As a convenience, this function is defined to call g_type_init() as
426 * its very first action.
428 * Returns: (transfer full): An application instance
433 g_application_new (const gchar *appid,
438 GError *error = NULL;
439 GVariant *argv_variant;
443 g_return_val_if_fail (appid != NULL, NULL);
445 argv_variant = variant_from_argv (argc, argv);
447 app = g_initable_new (G_TYPE_APPLICATION,
450 "application-id", appid,
451 "argv", argv_variant,
455 g_error ("%s", error->message);
456 g_clear_error (&error);
459 return G_APPLICATION (app);
463 * g_application_try_new:
464 * @appid: System-dependent application identifier
465 * @argc: Number of arguments in @argv
466 * @argv: (allow-none) (array length=argc): Argument vector, usually from the <parameter>argv</parameter> parameter of main()
469 * This function is similar to g_application_new(), but allows for
470 * more graceful fallback if the environment doesn't support the
471 * basic #GApplication functionality.
473 * Returns: (transfer full): An application instance
478 g_application_try_new (const gchar *appid,
483 GVariant *argv_variant;
487 g_return_val_if_fail (appid != NULL, NULL);
489 argv_variant = variant_from_argv (argc, argv);
491 return G_APPLICATION (g_initable_new (G_TYPE_APPLICATION,
494 "application-id", appid,
495 "argv", argv_variant,
500 * g_application_unregistered_try_new:
501 * @appid: System-dependent application identifier
502 * @argc: Number of arguments in @argv
503 * @argv: (allow-none) (array length=argc): Argument vector, usually from the <parameter>argv</parameter> parameter of main()
506 * This function is similar to g_application_try_new(), but also
507 * sets the GApplication:register property to %FALSE. You can later
508 * call g_application_register() to complete initialization.
510 * Returns: (transfer full): An application instance
515 g_application_unregistered_try_new (const gchar *appid,
520 GVariant *argv_variant;
524 g_return_val_if_fail (appid != NULL, NULL);
526 argv_variant = variant_from_argv (argc, argv);
528 return G_APPLICATION (g_initable_new (G_TYPE_APPLICATION,
531 "application-id", appid,
532 "argv", argv_variant,
538 * g_application_register:
539 * @app: a #GApplication
541 * By default, #GApplication ensures process uniqueness when
542 * initialized, but this behavior is controlled by the
543 * GApplication:register property. If it was given as %FALSE at
544 * construction time, this function allows you to later attempt
545 * to ensure uniqueness.
547 * Returns: %TRUE if registration was successful
550 g_application_register (GApplication *app)
554 g_return_val_if_fail (G_IS_APPLICATION (app), FALSE);
555 g_return_val_if_fail (app->priv->is_remote, FALSE);
557 if (!_g_application_platform_register (app, &unique, NULL, NULL))
563 * g_application_add_action:
564 * @application: a #GApplication
565 * @name: the action name
566 * @description: the action description; can be a translatable
569 * Adds an action @name to the list of exported actions of @application.
571 * It is an error to call this function if @application is a proxy for
572 * a remote application.
574 * You can invoke an action using g_application_invoke_action().
576 * The newly added action is enabled by default; you can call
577 * g_application_set_action_enabled() to disable it.
582 g_application_add_action (GApplication *application,
584 const gchar *description)
586 GApplicationPrivate *priv;
587 GApplicationAction *action;
589 g_return_if_fail (G_IS_APPLICATION (application));
590 g_return_if_fail (name != NULL && *name != '\0');
591 g_return_if_fail (!application->priv->is_remote);
593 priv = application->priv;
595 g_return_if_fail (g_hash_table_lookup (priv->actions, name) == NULL);
597 action = g_slice_new (GApplicationAction);
598 action->name = g_strdup (name);
599 action->description = g_strdup (description);
600 action->enabled = TRUE;
602 g_hash_table_insert (priv->actions, action->name, action);
603 queue_actions_change_notification (application);
607 * g_application_remove_action:
608 * @application: a #GApplication
609 * @name: the name of the action to remove
611 * Removes the action @name from the list of exported actions of @application.
613 * It is an error to call this function if @application is a proxy for
614 * a remote application.
619 g_application_remove_action (GApplication *application,
622 GApplicationPrivate *priv;
624 g_return_if_fail (G_IS_APPLICATION (application));
625 g_return_if_fail (name != NULL && *name != '\0');
626 g_return_if_fail (!application->priv->is_remote);
628 priv = application->priv;
630 g_return_if_fail (g_hash_table_lookup (priv->actions, name) != NULL);
632 g_hash_table_remove (priv->actions, name);
633 queue_actions_change_notification (application);
637 * g_application_invoke_action:
638 * @application: a #GApplication
639 * @name: the name of the action to invoke
640 * @platform_data: (allow-none): platform-specific event data
642 * Invokes the action @name of the passed #GApplication.
644 * This function has different behavior depending on whether @application
645 * is acting as a proxy for another process. In the normal case where
646 * the current process is hosting the application, and the specified
647 * action exists and is enabled, the #GApplication::action signal will
650 * If @application is a proxy, then the specified action will be invoked
651 * in the remote process. It is not necessary to call
652 * g_application_add_action() in the current process in order to invoke
658 g_application_invoke_action (GApplication *application,
660 GVariant *platform_data)
662 GApplicationPrivate *priv;
663 GApplicationAction *action;
665 g_return_if_fail (G_IS_APPLICATION (application));
666 g_return_if_fail (name != NULL);
667 g_return_if_fail (platform_data == NULL
668 || g_variant_is_of_type (platform_data, G_VARIANT_TYPE ("a{sv}")));
670 if (platform_data == NULL)
671 platform_data = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
673 g_variant_ref (platform_data);
675 priv = application->priv;
679 _g_application_platform_remote_invoke_action (application, name, platform_data);
683 action = g_hash_table_lookup (priv->actions, name);
684 g_return_if_fail (action != NULL);
685 if (!action->enabled)
688 g_signal_emit (application, application_signals[ACTION_WITH_DATA],
689 g_quark_from_string (name),
694 g_variant_unref (platform_data);
698 * g_application_list_actions:
699 * @application: a #GApplication
701 * Retrieves the list of action names currently exported by @application.
703 * It is an error to call this function if @application is a proxy for
704 * a remote application.
706 * Return value: (transfer full): a newly allocation, %NULL-terminated array
707 * of strings containing action names; use g_strfreev() to free the
708 * resources used by the returned array
713 g_application_list_actions (GApplication *application)
715 GApplicationPrivate *priv;
721 g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
722 g_return_val_if_fail (!application->priv->is_remote, NULL);
724 priv = application->priv;
726 retval = g_new (gchar*, g_hash_table_size (priv->actions));
729 g_hash_table_iter_init (&iter, priv->actions);
730 while (g_hash_table_iter_next (&iter, &key, NULL))
731 retval[i++] = g_strdup (key);
739 * g_application_set_action_enabled:
740 * @application: a #GApplication
741 * @name: the name of the application
742 * @enabled: whether to enable or disable the action @name
744 * Sets whether the action @name inside @application should be enabled
747 * It is an error to call this function if @application is a proxy for
748 * a remote application.
750 * Invoking a disabled action will not result in the #GApplication::action
751 * signal being emitted.
756 g_application_set_action_enabled (GApplication *application,
760 GApplicationAction *action;
762 g_return_if_fail (G_IS_APPLICATION (application));
763 g_return_if_fail (name != NULL);
764 g_return_if_fail (!application->priv->is_remote);
768 action = g_hash_table_lookup (application->priv->actions, name);
769 g_return_if_fail (action != NULL);
770 if (action->enabled == enabled)
773 action->enabled = enabled;
775 queue_actions_change_notification (application);
780 * g_application_get_action_description:
781 * @application: a #GApplication
784 * Gets the description of the action @name.
786 * It is an error to call this function if @application is a proxy for
787 * a remote application.
789 * Returns: Description for the given action named @name
793 G_CONST_RETURN gchar *
794 g_application_get_action_description (GApplication *application,
797 GApplicationAction *action;
799 g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
800 g_return_val_if_fail (name != NULL, NULL);
801 g_return_val_if_fail (!application->priv->is_remote, NULL);
803 action = g_hash_table_lookup (application->priv->actions, name);
804 g_return_val_if_fail (action != NULL, NULL);
806 return action->description;
811 * g_application_get_action_enabled:
812 * @application: a #GApplication
813 * @name: the name of the action
815 * Retrieves whether the action @name is enabled or not.
817 * See g_application_set_action_enabled().
819 * It is an error to call this function if @application is a proxy for
820 * a remote application.
822 * Return value: %TRUE if the action was enabled, and %FALSE otherwise
827 g_application_get_action_enabled (GApplication *application,
830 GApplicationAction *action;
832 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
833 g_return_val_if_fail (name != NULL, FALSE);
834 g_return_val_if_fail (!application->priv->is_remote, FALSE);
836 action = g_hash_table_lookup (application->priv->actions, name);
837 g_return_val_if_fail (action != NULL, FALSE);
839 return action->enabled;
844 * @application: a #GApplication
846 * Starts the application.
848 * The default implementation of this virtual function will simply run
851 * It is an error to call this function if @application is a proxy for
852 * a remote application.
857 g_application_run (GApplication *application)
859 g_return_if_fail (G_IS_APPLICATION (application));
860 g_return_if_fail (!application->priv->is_remote);
862 G_APPLICATION_GET_CLASS (application)->run (application);
866 * g_application_quit_with_data:
867 * @application: a #GApplication
868 * @platform_data: (allow-none): platform-specific data
870 * Request that the application quits.
872 * This function has different behavior depending on whether @application
873 * is acting as a proxy for another process. In the normal case where
874 * the current process is hosting the application, the default
875 * implementation will quit the main loop created by g_application_run().
877 * If @application is a proxy, then the remote process will be asked
880 * Returns: %TRUE if the application accepted the request, %FALSE otherwise
885 g_application_quit_with_data (GApplication *application,
886 GVariant *platform_data)
888 gboolean retval = FALSE;
890 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
891 g_return_val_if_fail (platform_data == NULL
892 || g_variant_is_of_type (platform_data, G_VARIANT_TYPE ("a{sv}")), FALSE);
894 if (platform_data == NULL)
895 platform_data = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
897 g_variant_ref (platform_data);
899 if (application->priv->is_remote)
901 _g_application_platform_remote_quit (application, platform_data);
905 g_signal_emit (application, application_signals[QUIT_WITH_DATA], 0, platform_data, &retval);
907 g_variant_unref (platform_data);
913 * g_application_get_instance:
915 * In the normal case where there is exactly one #GApplication instance
916 * in this process, return that instance. If there are multiple, the
917 * first one created will be returned. Otherwise, return %NULL.
919 * Returns: (transfer none): The primary instance of #GApplication,
920 * or %NULL if none is set
925 g_application_get_instance (void)
927 return primary_application;
931 * g_application_get_id:
932 * @application: a #GApplication
934 * Retrieves the platform-specific identifier for the #GApplication.
936 * Return value: The platform-specific identifier. The returned string
937 * is owned by the #GApplication instance and it should never be
942 G_CONST_RETURN gchar *
943 g_application_get_id (GApplication *application)
945 g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
947 return application->priv->appid;
951 * g_application_is_remote:
952 * @application: a #GApplication
954 * Returns: %TRUE if this object represents a proxy for a remote application.
957 g_application_is_remote (GApplication *application)
959 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
961 return application->priv->is_remote;
965 g_application_init (GApplication *app)
967 app->priv = G_TYPE_INSTANCE_GET_PRIVATE (app,
969 GApplicationPrivate);
971 app->priv->actions = g_hash_table_new_full (g_str_hash, g_str_equal,
973 g_application_action_free);
974 app->priv->default_quit = TRUE;
975 app->priv->do_register = TRUE;
976 app->priv->is_remote = TRUE;
980 g_application_get_property (GObject *object,
985 GApplication *app = G_APPLICATION (object);
989 case PROP_APPLICATION_ID:
990 g_value_set_string (value, g_application_get_id (app));
993 case PROP_DEFAULT_QUIT:
994 g_value_set_boolean (value, app->priv->default_quit);
998 g_value_set_boolean (value, g_application_is_remote (app));
1002 g_value_set_boolean (value, app->priv->do_register);
1006 g_value_set_boxed (value, app->priv->argv);
1009 case PROP_PLATFORM_DATA:
1010 g_value_set_boxed (value, app->priv->platform_data);
1014 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1019 g_application_set_property (GObject *object,
1021 const GValue *value,
1024 GApplication *app = G_APPLICATION (object);
1028 case PROP_APPLICATION_ID:
1029 g_return_if_fail (_g_application_validate_id (g_value_get_string (value)));
1030 app->priv->appid = g_value_dup_string (value);
1033 case PROP_DEFAULT_QUIT:
1034 app->priv->default_quit = g_value_get_boolean (value);
1038 app->priv->do_register = g_value_get_boolean (value);
1043 GVariant *argv = g_value_get_boxed (value);
1044 g_return_if_fail (argv == NULL ||
1045 g_variant_is_of_type (argv, G_VARIANT_TYPE ("aay")));
1046 app->priv->argv = argv;
1050 case PROP_PLATFORM_DATA:
1052 GVariant *platform_data = g_value_get_boxed (value);
1053 g_return_if_fail (platform_data == NULL ||
1054 g_variant_is_of_type (platform_data, G_VARIANT_TYPE ("a{sv}")));
1055 app->priv->platform_data = platform_data;
1060 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1065 g_application_constructor (GType type,
1066 guint n_construct_properties,
1067 GObjectConstructParam *construct_params)
1071 const char *appid = NULL;
1074 for (i = 0; i < n_construct_properties; i++)
1076 GObjectConstructParam *param = &construct_params[i];
1077 if (strcmp (param->pspec->name, "application-id") == 0)
1078 appid = g_value_get_string (param->value);
1081 g_return_val_if_fail (appid != NULL, NULL);
1083 app = application_for_appid (appid);
1085 return g_object_ref (app);
1087 object = (* G_OBJECT_CLASS (g_application_parent_class)->constructor) (type,
1088 n_construct_properties,
1090 app = G_APPLICATION (object);
1092 if (primary_application == NULL)
1093 primary_application = app;
1094 g_hash_table_insert (instances_for_appid, g_strdup (appid), app);
1100 g_application_finalize (GObject *object)
1102 GApplication *app = G_APPLICATION (object);
1104 g_free (app->priv->appid);
1105 if (app->priv->actions)
1106 g_hash_table_unref (app->priv->actions);
1107 if (app->priv->actions_changed_id)
1108 g_source_remove (app->priv->actions_changed_id);
1109 if (app->priv->mainloop)
1110 g_main_loop_unref (app->priv->mainloop);
1113 g_free (app->priv->dbus_path);
1114 if (app->priv->session_bus)
1115 g_object_unref (app->priv->session_bus);
1118 G_OBJECT_CLASS (g_application_parent_class)->finalize (object);
1122 g_application_class_init (GApplicationClass *klass)
1124 GObjectClass *gobject_class G_GNUC_UNUSED = G_OBJECT_CLASS (klass);
1126 g_type_class_add_private (klass, sizeof (GApplicationPrivate));
1128 gobject_class->constructor = g_application_constructor;
1129 gobject_class->set_property = g_application_set_property;
1130 gobject_class->get_property = g_application_get_property;
1132 gobject_class->finalize = g_application_finalize;
1134 klass->run = g_application_default_run;
1135 klass->quit_with_data = g_application_default_quit_with_data;
1138 * GApplication::quit-with-data:
1139 * @application: the object on which the signal is emitted
1140 * @platform_data: Platform-specific data, or %NULL
1142 * This signal is emitted when the Quit action is invoked on the
1145 * The default handler for this signal exits the mainloop of the
1148 * Returns: %TRUE if the signal has been handled, %FALSE to continue
1151 application_signals[QUIT_WITH_DATA] =
1152 g_signal_new (g_intern_static_string ("quit-with-data"),
1153 G_OBJECT_CLASS_TYPE (klass),
1155 G_STRUCT_OFFSET (GApplicationClass, quit_with_data),
1156 g_signal_accumulator_true_handled, NULL,
1157 _gio_marshal_BOOLEAN__BOXED,
1162 * GApplication::action-with-data:
1163 * @application: the object on which the signal is emitted
1164 * @name: The name of the activated action
1165 * @platform_data: Platform-specific data, or %NULL
1167 * This signal is emitted when an action is activated. The action name
1168 * is passed as the first argument, but also as signal detail, so it
1169 * is possible to connect to this signal for individual actions.
1171 * The signal is never emitted for disabled actions.
1173 application_signals[ACTION_WITH_DATA] =
1174 g_signal_new (g_intern_static_string ("action-with-data"),
1175 G_OBJECT_CLASS_TYPE (klass),
1176 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED,
1177 G_STRUCT_OFFSET (GApplicationClass, action_with_data),
1179 _gio_marshal_VOID__STRING_BOXED,
1185 * GApplication::prepare-activation:
1186 * @application: the object on which the signal is emitted
1187 * @arguments: A #GVariant with the signature "aay"
1188 * @platform_data: A #GVariant with the signature "a{sv}", or %NULL
1190 * This signal is emitted when a non-primary process for a given
1191 * application is invoked while your application is running; for
1192 * example, when a file browser launches your program to open a
1193 * file. The raw operating system arguments are passed in the
1194 * @arguments variant. Additional platform-dependent data is
1195 * stored in @platform_data.
1197 application_signals[PREPARE_ACTIVATION] =
1198 g_signal_new (g_intern_static_string ("prepare-activation"),
1199 G_OBJECT_CLASS_TYPE (klass),
1201 G_STRUCT_OFFSET (GApplicationClass, prepare_activation),
1203 _gio_marshal_VOID__BOXED_BOXED,
1209 * GApplication:application-id:
1211 * The unique identifier for this application. See the documentation for
1212 * #GApplication for more information about this property.
1215 g_object_class_install_property (gobject_class,
1216 PROP_APPLICATION_ID,
1217 g_param_spec_string ("application-id",
1218 P_("Application ID"),
1219 P_("Identifier for this application"),
1222 G_PARAM_CONSTRUCT_ONLY |
1223 G_PARAM_STATIC_STRINGS));
1226 * GApplication:argv:
1228 * The argument vector given to this application. It must be a #GVariant
1229 * with a type signature "aay".
1232 g_object_class_install_property (gobject_class,
1234 g_param_spec_boxed ("argv",
1235 P_("Argument vector"),
1236 P_("System argument vector with type signature aay"),
1239 G_PARAM_CONSTRUCT_ONLY |
1240 G_PARAM_STATIC_STRINGS));
1243 * GApplication:platform-data:
1245 * Platform-specific data retrieved from the operating system
1246 * environment. It must be a #GVariant with type signature "a{sv}".
1249 g_object_class_install_property (gobject_class,
1251 g_param_spec_boxed ("platform-data",
1252 P_("Platform data"),
1253 P_("Environmental data, must have type signature a{sv}"),
1256 G_PARAM_CONSTRUCT_ONLY |
1257 G_PARAM_STATIC_STRINGS));
1260 * GApplication:default-quit:
1262 * By default, if a different process is running this application, the
1263 * process will be exited. Set this property to %FALSE to allow custom
1264 * interaction with the remote process.
1267 g_object_class_install_property (gobject_class,
1269 g_param_spec_boolean ("default-quit",
1271 P_("Exit the process by default"),
1274 G_PARAM_CONSTRUCT_ONLY |
1275 G_PARAM_STATIC_STRINGS));
1279 * GApplication:is-remote:
1281 * This property is %TRUE if this application instance represents a proxy
1282 * to the instance of this application in another process.
1285 g_object_class_install_property (gobject_class,
1287 g_param_spec_boolean ("is-remote",
1289 P_("Whether this application is a proxy for another process"),
1291 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
1294 * GApplication:register:
1296 * If this property is %FALSE, the application construction will not attempt
1297 * to ensure process uniqueness, and the application is guaranteed to be in the
1298 * remote state. See GApplication:is-remote.
1300 g_object_class_install_property (gobject_class,
1302 g_param_spec_boolean ("register",
1304 P_("If false, do not "),
1307 G_PARAM_CONSTRUCT_ONLY |
1308 G_PARAM_STATIC_STRINGS));
1311 #define __G_APPLICATION_C__
1312 #include "gioaliasdef.c"