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 will have a key "cwd" of type signature
136 * "ay" which contains the working directory of the invoked
137 * executable; this data is defined to be in the default GLib
138 * filesystem encoding for the platform. See g_filename_to_utf8().
142 * The <methodname>InvokeAction</methodname> function can be called to
143 * invoke one of the actions exported by the application. On X11
144 * platforms, the platform_data argument should have a "timestamp"
145 * parameter of type "u" with the server time of the initiating event.
148 * The <methodname>ListActions</methodname> function returns a dictionary
149 * with the exported actions of the application. The keys of the dictionary
150 * are the action names, and the values are structs containing the description
151 * for the action and a boolean that represents if the action is enabled or not.
154 * The <methodname>Quit</methodname> function can be called to
155 * terminate the application. The @data parameter contains
156 * platform-specific data. On X11 platforms, the platform_data
157 * argument should have a "timestamp" parameter of type "u" with the
158 * server time of the initiating event.
161 * The <methodname>ActionsChanged</methodname> signal is emitted when the
162 * exported actions change (i.e. an action is added, removed, enabled,
163 * disabled, or otherwise changed).
166 * #GApplication is supported since Gio 2.26.
171 static void initable_iface_init (GInitableIface *initable_iface);
173 G_DEFINE_TYPE_WITH_CODE (GApplication, g_application, G_TYPE_OBJECT,
174 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init));
198 static guint application_signals[LAST_SIGNAL] = { 0 };
204 } GApplicationAction;
206 struct _GApplicationPrivate
209 GHashTable *actions; /* name -> GApplicationAction */
213 GVariant *platform_data;
215 guint do_register : 1;
216 guint default_quit : 1;
219 guint actions_changed_id;
223 GDBusConnection *session_bus;
227 static GApplication *primary_application = NULL;
228 static GHashTable *instances_for_appid = NULL;
230 static gboolean initable_init (GInitable *initable,
231 GCancellable *cancellable,
234 static gboolean _g_application_platform_init (GApplication *app,
235 GCancellable *cancellable,
237 static gboolean _g_application_platform_register (GApplication *app,
239 GCancellable *cancellable,
242 static void _g_application_platform_remote_invoke_action (GApplication *app,
244 GVariant *platform_data);
245 static void _g_application_platform_remote_quit (GApplication *app,
246 GVariant *platform_data);
247 static void _g_application_platform_on_actions_changed (GApplication *app);
250 initable_iface_init (GInitableIface *initable_iface)
252 initable_iface->init = initable_init;
256 #include "gdbusapplication.c"
258 #include "gnullapplication.c"
262 _g_application_validate_id (const char *id)
266 if (strlen (id) > 255)
269 if (!g_ascii_isalpha (*id))
276 if (g_ascii_isalnum (*id) || (*id == '-') || (*id == '_'))
278 else if (allow_dot && *id == '.')
287 init_appid_statics (gpointer data)
289 instances_for_appid = g_hash_table_new (g_str_hash, g_str_equal);
293 static GApplication *
294 application_for_appid (const char *appid)
296 static GOnce appid_once = G_ONCE_INIT;
298 g_once (&appid_once, init_appid_statics, NULL);
300 return g_hash_table_lookup (instances_for_appid, appid);
304 g_application_default_quit_with_data (GApplication *application,
305 GVariant *platform_data)
307 g_return_val_if_fail (application->priv->mainloop != NULL, FALSE);
308 g_main_loop_quit (application->priv->mainloop);
314 g_application_default_run (GApplication *application)
316 if (application->priv->mainloop == NULL)
317 application->priv->mainloop = g_main_loop_new (NULL, TRUE);
319 g_main_loop_run (application->priv->mainloop);
323 append_cwd_to_platform_data (GVariant *platform_data)
325 GVariantBuilder builder;
329 cwd = g_get_current_dir ();
331 g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
333 g_variant_builder_add (&builder, "{sv}",
335 g_variant_new_byte_array (cwd, -1));
343 g_variant_iter_init (&iter, platform_data);
344 while (g_variant_iter_next (&iter, "@{sv}", &item))
346 g_variant_builder_add_value (&builder, item);
347 g_variant_unref (item);
350 result = g_variant_builder_end (&builder);
355 variant_from_argv (int argc,
358 GVariantBuilder builder;
361 g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay"));
363 for (i = 1; i < argc; i++)
367 argv_bytes = (guint8*) argv[i];
368 g_variant_builder_add_value (&builder,
369 g_variant_new_byte_array (argv_bytes, -1));
372 return g_variant_builder_end (&builder);
376 timeout_handle_actions_changed (gpointer user_data)
378 GApplication *application = user_data;
380 application->priv->actions_changed_id = 0;
382 _g_application_platform_on_actions_changed (application);
388 queue_actions_change_notification (GApplication *application)
390 GApplicationPrivate *priv = application->priv;
392 if (priv->actions_changed_id == 0)
393 priv->actions_changed_id = g_timeout_add (0, timeout_handle_actions_changed, application);
397 initable_init (GInitable *initable,
398 GCancellable *cancellable,
401 GApplication *app = G_APPLICATION (initable);
404 if (!_g_application_platform_init (app, cancellable, error))
407 if (app->priv->do_register &&
408 !_g_application_platform_register (app, &unique, cancellable ,error))
415 g_application_action_free (gpointer data)
417 if (G_LIKELY (data != NULL))
419 GApplicationAction *action = data;
421 g_free (action->name);
422 g_free (action->description);
424 g_slice_free (GApplicationAction, action);
430 * @appid: System-dependent application identifier
431 * @argc: Number of arguments in @argv
432 * @argv: (allow-none) (array length=argc): Argument vector, usually from the <parameter>argv</parameter> parameter of main()
434 * Create a new #GApplication. This uses a platform-specific
435 * mechanism to ensure the current process is the unique owner of the
436 * application (as defined by the @appid). If successful, the
437 * #GApplication:is-remote property will be %FALSE, and it is safe to
438 * continue creating other resources such as graphics windows.
440 * If the given @appid is already running in another process, the the
441 * GApplication::activate_with_data signal will be emitted in the
442 * remote process, with the data from @argv and other
443 * platform-specific data available. Subsequently the
444 * #GApplication:default-exit property will be evaluated. If it's
445 * %TRUE, then the current process will terminate. If %FALSE, then
446 * the application remains in the #GApplication:is-remote state, and
447 * you can e.g. call g_application_invoke_action().
449 * This function may do synchronous I/O to obtain unique ownership
450 * of the application id, and will block the calling thread in this
453 * If the environment does not support the basic functionality of
454 * #GApplication, this function will invoke g_error(), which by
455 * default is a fatal operation. This may arise for example on
456 * UNIX systems using D-Bus when the session bus is not available.
458 * As a convenience, this function is defined to call g_type_init() as
459 * its very first action.
461 * Returns: (transfer full): An application instance
466 g_application_new (const gchar *appid,
471 GError *error = NULL;
472 GVariant *argv_variant;
476 g_return_val_if_fail (appid != NULL, NULL);
478 argv_variant = variant_from_argv (argc, argv);
480 app = g_initable_new (G_TYPE_APPLICATION,
483 "application-id", appid,
484 "argv", argv_variant,
488 g_error ("%s", error->message);
489 g_clear_error (&error);
492 return G_APPLICATION (app);
496 * g_application_try_new:
497 * @appid: System-dependent application identifier
498 * @argc: Number of arguments in @argv
499 * @argv: (allow-none) (array length=argc): Argument vector, usually from the <parameter>argv</parameter> parameter of main()
502 * This function is similar to g_application_new(), but allows for
503 * more graceful fallback if the environment doesn't support the
504 * basic #GApplication functionality.
506 * Returns: (transfer full): An application instance
511 g_application_try_new (const gchar *appid,
516 GVariant *argv_variant;
520 g_return_val_if_fail (appid != NULL, NULL);
522 argv_variant = variant_from_argv (argc, argv);
524 return G_APPLICATION (g_initable_new (G_TYPE_APPLICATION,
527 "application-id", appid,
528 "argv", argv_variant,
533 * g_application_unregistered_try_new:
534 * @appid: System-dependent application identifier
535 * @argc: Number of arguments in @argv
536 * @argv: (allow-none) (array length=argc): Argument vector, usually from the <parameter>argv</parameter> parameter of main()
539 * This function is similar to g_application_try_new(), but also
540 * sets the GApplication:register property to %FALSE. You can later
541 * call g_application_register() to complete initialization.
543 * Returns: (transfer full): An application instance
548 g_application_unregistered_try_new (const gchar *appid,
553 GVariant *argv_variant;
557 g_return_val_if_fail (appid != NULL, NULL);
559 argv_variant = variant_from_argv (argc, argv);
561 return G_APPLICATION (g_initable_new (G_TYPE_APPLICATION,
564 "application-id", appid,
565 "argv", argv_variant,
571 * g_application_register:
572 * @application: a #GApplication
574 * By default, #GApplication ensures process uniqueness when
575 * initialized, but this behavior is controlled by the
576 * GApplication:register property. If it was given as %FALSE at
577 * construction time, this function allows you to later attempt
578 * to ensure uniqueness.
580 * Returns: %TRUE if registration was successful
583 g_application_register (GApplication *application)
587 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
588 g_return_val_if_fail (application->priv->is_remote, FALSE);
590 if (!_g_application_platform_register (application, &unique, NULL, NULL))
596 * g_application_add_action:
597 * @application: a #GApplication
598 * @name: the action name
599 * @description: the action description; can be a translatable
602 * Adds an action @name to the list of exported actions of @application.
604 * It is an error to call this function if @application is a proxy for
605 * a remote application.
607 * You can invoke an action using g_application_invoke_action().
609 * The newly added action is enabled by default; you can call
610 * g_application_set_action_enabled() to disable it.
615 g_application_add_action (GApplication *application,
617 const gchar *description)
619 GApplicationPrivate *priv;
620 GApplicationAction *action;
622 g_return_if_fail (G_IS_APPLICATION (application));
623 g_return_if_fail (name != NULL && *name != '\0');
624 g_return_if_fail (!application->priv->is_remote);
626 priv = application->priv;
628 g_return_if_fail (g_hash_table_lookup (priv->actions, name) == NULL);
630 action = g_slice_new (GApplicationAction);
631 action->name = g_strdup (name);
632 action->description = g_strdup (description);
633 action->enabled = TRUE;
635 g_hash_table_insert (priv->actions, action->name, action);
636 queue_actions_change_notification (application);
640 * g_application_remove_action:
641 * @application: a #GApplication
642 * @name: the name of the action to remove
644 * Removes the action @name from the list of exported actions of @application.
646 * It is an error to call this function if @application is a proxy for
647 * a remote application.
652 g_application_remove_action (GApplication *application,
655 GApplicationPrivate *priv;
657 g_return_if_fail (G_IS_APPLICATION (application));
658 g_return_if_fail (name != NULL && *name != '\0');
659 g_return_if_fail (!application->priv->is_remote);
661 priv = application->priv;
663 g_return_if_fail (g_hash_table_lookup (priv->actions, name) != NULL);
665 g_hash_table_remove (priv->actions, name);
666 queue_actions_change_notification (application);
670 * g_application_invoke_action:
671 * @application: a #GApplication
672 * @name: the name of the action to invoke
673 * @platform_data: (allow-none): platform-specific event data
675 * Invokes the action @name of the passed #GApplication.
677 * This function has different behavior depending on whether @application
678 * is acting as a proxy for another process. In the normal case where
679 * the current process is hosting the application, and the specified
680 * action exists and is enabled, the #GApplication::action signal will
683 * If @application is a proxy, then the specified action will be invoked
684 * in the remote process. It is not necessary to call
685 * g_application_add_action() in the current process in order to invoke
691 g_application_invoke_action (GApplication *application,
693 GVariant *platform_data)
695 GApplicationPrivate *priv;
696 GApplicationAction *action;
698 g_return_if_fail (G_IS_APPLICATION (application));
699 g_return_if_fail (name != NULL);
700 g_return_if_fail (platform_data == NULL
701 || g_variant_is_of_type (platform_data, G_VARIANT_TYPE ("a{sv}")));
703 if (platform_data == NULL)
704 platform_data = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
706 g_variant_ref (platform_data);
708 priv = application->priv;
712 _g_application_platform_remote_invoke_action (application, name, platform_data);
716 action = g_hash_table_lookup (priv->actions, name);
717 g_return_if_fail (action != NULL);
718 if (!action->enabled)
721 g_signal_emit (application, application_signals[ACTION_WITH_DATA],
722 g_quark_from_string (name),
727 g_variant_unref (platform_data);
731 * g_application_list_actions:
732 * @application: a #GApplication
734 * Retrieves the list of action names currently exported by @application.
736 * It is an error to call this function if @application is a proxy for
737 * a remote application.
739 * Return value: (transfer full): a newly allocation, %NULL-terminated array
740 * of strings containing action names; use g_strfreev() to free the
741 * resources used by the returned array
746 g_application_list_actions (GApplication *application)
748 GApplicationPrivate *priv;
754 g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
755 g_return_val_if_fail (!application->priv->is_remote, NULL);
757 priv = application->priv;
759 retval = g_new (gchar*, g_hash_table_size (priv->actions));
762 g_hash_table_iter_init (&iter, priv->actions);
763 while (g_hash_table_iter_next (&iter, &key, NULL))
764 retval[i++] = g_strdup (key);
772 * g_application_set_action_enabled:
773 * @application: a #GApplication
774 * @name: the name of the application
775 * @enabled: whether to enable or disable the action @name
777 * Sets whether the action @name inside @application should be enabled
780 * It is an error to call this function if @application is a proxy for
781 * a remote application.
783 * Invoking a disabled action will not result in the #GApplication::action
784 * signal being emitted.
789 g_application_set_action_enabled (GApplication *application,
793 GApplicationAction *action;
795 g_return_if_fail (G_IS_APPLICATION (application));
796 g_return_if_fail (name != NULL);
797 g_return_if_fail (!application->priv->is_remote);
801 action = g_hash_table_lookup (application->priv->actions, name);
802 g_return_if_fail (action != NULL);
803 if (action->enabled == enabled)
806 action->enabled = enabled;
808 queue_actions_change_notification (application);
813 * g_application_get_action_description:
814 * @application: a #GApplication
817 * Gets the description of the action @name.
819 * It is an error to call this function if @application is a proxy for
820 * a remote application.
822 * Returns: Description for the given action named @name
826 G_CONST_RETURN gchar *
827 g_application_get_action_description (GApplication *application,
830 GApplicationAction *action;
832 g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
833 g_return_val_if_fail (name != NULL, NULL);
834 g_return_val_if_fail (!application->priv->is_remote, NULL);
836 action = g_hash_table_lookup (application->priv->actions, name);
837 g_return_val_if_fail (action != NULL, NULL);
839 return action->description;
844 * g_application_get_action_enabled:
845 * @application: a #GApplication
846 * @name: the name of the action
848 * Retrieves whether the action @name is enabled or not.
850 * See g_application_set_action_enabled().
852 * It is an error to call this function if @application is a proxy for
853 * a remote application.
855 * Return value: %TRUE if the action was enabled, and %FALSE otherwise
860 g_application_get_action_enabled (GApplication *application,
863 GApplicationAction *action;
865 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
866 g_return_val_if_fail (name != NULL, FALSE);
867 g_return_val_if_fail (!application->priv->is_remote, FALSE);
869 action = g_hash_table_lookup (application->priv->actions, name);
870 g_return_val_if_fail (action != NULL, FALSE);
872 return action->enabled;
877 * @application: a #GApplication
879 * Starts the application.
881 * The default implementation of this virtual function will simply run
884 * It is an error to call this function if @application is a proxy for
885 * a remote application.
890 g_application_run (GApplication *application)
892 g_return_if_fail (G_IS_APPLICATION (application));
893 g_return_if_fail (!application->priv->is_remote);
895 G_APPLICATION_GET_CLASS (application)->run (application);
899 * g_application_quit_with_data:
900 * @application: a #GApplication
901 * @platform_data: (allow-none): platform-specific data
903 * Request that the application quits.
905 * This function has different behavior depending on whether @application
906 * is acting as a proxy for another process. In the normal case where
907 * the current process is hosting the application, the default
908 * implementation will quit the main loop created by g_application_run().
910 * If @application is a proxy, then the remote process will be asked
913 * Returns: %TRUE if the application accepted the request, %FALSE otherwise
918 g_application_quit_with_data (GApplication *application,
919 GVariant *platform_data)
921 gboolean retval = FALSE;
923 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
924 g_return_val_if_fail (platform_data == NULL
925 || g_variant_is_of_type (platform_data, G_VARIANT_TYPE ("a{sv}")), FALSE);
927 if (platform_data == NULL)
928 platform_data = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
930 g_variant_ref (platform_data);
932 if (application->priv->is_remote)
934 _g_application_platform_remote_quit (application, platform_data);
938 g_signal_emit (application, application_signals[QUIT_WITH_DATA], 0, platform_data, &retval);
940 g_variant_unref (platform_data);
946 * g_application_get_instance:
948 * In the normal case where there is exactly one #GApplication instance
949 * in this process, return that instance. If there are multiple, the
950 * first one created will be returned. Otherwise, return %NULL.
952 * Returns: (transfer none): The primary instance of #GApplication,
953 * or %NULL if none is set
958 g_application_get_instance (void)
960 return primary_application;
964 * g_application_get_id:
965 * @application: a #GApplication
967 * Retrieves the platform-specific identifier for the #GApplication.
969 * Return value: The platform-specific identifier. The returned string
970 * is owned by the #GApplication instance and it should never be
975 G_CONST_RETURN gchar *
976 g_application_get_id (GApplication *application)
978 g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
980 return application->priv->appid;
984 * g_application_is_remote:
985 * @application: a #GApplication
987 * Returns whether the object represents a proxy for a remote application.
989 * Returns: %TRUE if this object represents a proxy for a remote application.
992 g_application_is_remote (GApplication *application)
994 g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
996 return application->priv->is_remote;
1000 g_application_init (GApplication *app)
1002 app->priv = G_TYPE_INSTANCE_GET_PRIVATE (app,
1004 GApplicationPrivate);
1006 app->priv->actions = g_hash_table_new_full (g_str_hash, g_str_equal,
1008 g_application_action_free);
1009 app->priv->default_quit = TRUE;
1010 app->priv->do_register = TRUE;
1011 app->priv->is_remote = TRUE;
1012 app->priv->platform_data = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
1016 g_application_get_property (GObject *object,
1021 GApplication *app = G_APPLICATION (object);
1025 case PROP_APPLICATION_ID:
1026 g_value_set_string (value, g_application_get_id (app));
1029 case PROP_DEFAULT_QUIT:
1030 g_value_set_boolean (value, app->priv->default_quit);
1033 case PROP_IS_REMOTE:
1034 g_value_set_boolean (value, g_application_is_remote (app));
1038 g_value_set_boolean (value, app->priv->do_register);
1042 g_value_set_variant (value, app->priv->argv);
1045 case PROP_PLATFORM_DATA:
1046 g_value_set_variant (value, app->priv->platform_data);
1050 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1055 g_application_set_property (GObject *object,
1057 const GValue *value,
1060 GApplication *app = G_APPLICATION (object);
1064 case PROP_APPLICATION_ID:
1065 g_return_if_fail (_g_application_validate_id (g_value_get_string (value)));
1066 app->priv->appid = g_value_dup_string (value);
1069 case PROP_DEFAULT_QUIT:
1070 app->priv->default_quit = g_value_get_boolean (value);
1074 app->priv->do_register = g_value_get_boolean (value);
1078 app->priv->argv = g_value_dup_variant (value);
1081 case PROP_PLATFORM_DATA:
1083 GVariant *platform_data = g_value_get_variant (value);
1084 if (app->priv->platform_data)
1085 g_variant_unref (app->priv->platform_data);
1086 app->priv->platform_data = g_variant_ref_sink (append_cwd_to_platform_data (platform_data));
1091 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1096 g_application_constructor (GType type,
1097 guint n_construct_properties,
1098 GObjectConstructParam *construct_params)
1102 const char *appid = NULL;
1105 for (i = 0; i < n_construct_properties; i++)
1107 GObjectConstructParam *param = &construct_params[i];
1108 if (strcmp (param->pspec->name, "application-id") == 0)
1109 appid = g_value_get_string (param->value);
1112 g_return_val_if_fail (appid != NULL, NULL);
1114 app = application_for_appid (appid);
1116 return g_object_ref (app);
1118 object = (* G_OBJECT_CLASS (g_application_parent_class)->constructor) (type,
1119 n_construct_properties,
1121 app = G_APPLICATION (object);
1123 if (primary_application == NULL)
1124 primary_application = app;
1125 g_hash_table_insert (instances_for_appid, g_strdup (appid), app);
1131 g_application_finalize (GObject *object)
1133 GApplication *app = G_APPLICATION (object);
1135 g_free (app->priv->appid);
1136 if (app->priv->actions)
1137 g_hash_table_unref (app->priv->actions);
1138 if (app->priv->actions_changed_id)
1139 g_source_remove (app->priv->actions_changed_id);
1140 if (app->priv->mainloop)
1141 g_main_loop_unref (app->priv->mainloop);
1144 g_free (app->priv->dbus_path);
1145 if (app->priv->session_bus)
1146 g_object_unref (app->priv->session_bus);
1149 G_OBJECT_CLASS (g_application_parent_class)->finalize (object);
1153 g_application_class_init (GApplicationClass *klass)
1155 GObjectClass *gobject_class G_GNUC_UNUSED = G_OBJECT_CLASS (klass);
1157 g_type_class_add_private (klass, sizeof (GApplicationPrivate));
1159 gobject_class->constructor = g_application_constructor;
1160 gobject_class->set_property = g_application_set_property;
1161 gobject_class->get_property = g_application_get_property;
1163 gobject_class->finalize = g_application_finalize;
1165 klass->run = g_application_default_run;
1166 klass->quit_with_data = g_application_default_quit_with_data;
1169 * GApplication::quit-with-data:
1170 * @application: the object on which the signal is emitted
1171 * @platform_data: Platform-specific data, or %NULL
1173 * This signal is emitted when the Quit action is invoked on the
1176 * The default handler for this signal exits the mainloop of the
1179 * Returns: %TRUE if the signal has been handled, %FALSE to continue
1182 application_signals[QUIT_WITH_DATA] =
1183 g_signal_new (g_intern_static_string ("quit-with-data"),
1184 G_OBJECT_CLASS_TYPE (klass),
1186 G_STRUCT_OFFSET (GApplicationClass, quit_with_data),
1187 g_signal_accumulator_true_handled, NULL,
1188 _gio_marshal_BOOLEAN__VARIANT,
1193 * GApplication::action-with-data:
1194 * @application: the object on which the signal is emitted
1195 * @name: The name of the activated action
1196 * @platform_data: Platform-specific data, or %NULL
1198 * This signal is emitted when an action is activated. The action name
1199 * is passed as the first argument, but also as signal detail, so it
1200 * is possible to connect to this signal for individual actions.
1202 * The signal is never emitted for disabled actions.
1204 application_signals[ACTION_WITH_DATA] =
1205 g_signal_new (g_intern_static_string ("action-with-data"),
1206 G_OBJECT_CLASS_TYPE (klass),
1207 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED,
1208 G_STRUCT_OFFSET (GApplicationClass, action_with_data),
1210 _gio_marshal_VOID__STRING_VARIANT,
1216 * GApplication::prepare-activation:
1217 * @application: the object on which the signal is emitted
1218 * @arguments: A #GVariant with the signature "aay"
1219 * @platform_data: A #GVariant with the signature "a{sv}", or %NULL
1221 * This signal is emitted when a non-primary process for a given
1222 * application is invoked while your application is running; for
1223 * example, when a file browser launches your program to open a
1224 * file. The raw operating system arguments are passed in the
1225 * @arguments variant. Additional platform-dependent data is
1226 * stored in @platform_data.
1228 application_signals[PREPARE_ACTIVATION] =
1229 g_signal_new (g_intern_static_string ("prepare-activation"),
1230 G_OBJECT_CLASS_TYPE (klass),
1232 G_STRUCT_OFFSET (GApplicationClass, prepare_activation),
1234 _gio_marshal_VOID__VARIANT_VARIANT,
1240 * GApplication:application-id:
1242 * The unique identifier for this application. See the documentation for
1243 * #GApplication for more information about this property.
1246 g_object_class_install_property (gobject_class,
1247 PROP_APPLICATION_ID,
1248 g_param_spec_string ("application-id",
1249 P_("Application ID"),
1250 P_("Identifier for this application"),
1253 G_PARAM_CONSTRUCT_ONLY |
1254 G_PARAM_STATIC_STRINGS));
1257 * GApplication:argv:
1259 * The argument vector given to this application. It must be a #GVariant
1260 * with a type signature "aay".
1263 g_object_class_install_property (gobject_class,
1265 g_param_spec_variant ("argv",
1266 P_("Argument vector"),
1267 P_("System argument vector with type signature aay"),
1268 G_VARIANT_TYPE ("aay"),
1271 G_PARAM_CONSTRUCT_ONLY |
1272 G_PARAM_STATIC_STRINGS));
1275 * GApplication:platform-data:
1277 * Platform-specific data retrieved from the operating system
1278 * environment. It must be a #GVariant with type signature "a{sv}".
1281 g_object_class_install_property (gobject_class,
1283 g_param_spec_variant ("platform-data",
1284 P_("Platform data"),
1285 P_("Environmental data, must have type signature a{sv}"),
1286 G_VARIANT_TYPE ("a{sv}"),
1289 G_PARAM_CONSTRUCT_ONLY |
1290 G_PARAM_STATIC_STRINGS));
1293 * GApplication:default-quit:
1295 * By default, if a different process is running this application, the
1296 * process will be exited. Set this property to %FALSE to allow custom
1297 * interaction with the remote process.
1300 g_object_class_install_property (gobject_class,
1302 g_param_spec_boolean ("default-quit",
1304 P_("Exit the process by default"),
1307 G_PARAM_CONSTRUCT_ONLY |
1308 G_PARAM_STATIC_STRINGS));
1312 * GApplication:is-remote:
1314 * This property is %TRUE if this application instance represents a proxy
1315 * to the instance of this application in another process.
1318 g_object_class_install_property (gobject_class,
1320 g_param_spec_boolean ("is-remote",
1322 P_("Whether this application is a proxy for another process"),
1324 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
1327 * GApplication:register:
1329 * If this property is %FALSE, the application construction will not attempt
1330 * to ensure process uniqueness, and the application is guaranteed to be in the
1331 * remote state. See GApplication:is-remote.
1333 g_object_class_install_property (gobject_class,
1335 g_param_spec_boolean ("register",
1337 P_("If false, do not "),
1340 G_PARAM_CONSTRUCT_ONLY |
1341 G_PARAM_STATIC_STRINGS));
1344 #define __G_APPLICATION_C__
1345 #include "gioaliasdef.c"