[glib/wip/application: 1/11] new GApplication implementation
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/application: 1/11] new GApplication implementation
- Date: Wed, 13 Oct 2010 00:23:41 +0000 (UTC)
commit 207faf83bf0d581939dd364c35244053c9894c62
Author: Ryan Lortie <desrt desrt ca>
Date: Wed Oct 6 13:08:26 2010 -0400
new GApplication implementation
gio/Makefile.am | 9 +-
gio/gapplication.c | 1790 ++++++++++++++-------------------
gio/gapplication.h | 175 ++--
gio/gapplicationimpl-dbus-interface.c | 59 ++
gio/gapplicationimpl-dbus.c | 304 ++++++
gio/gapplicationimpl.h | 28 +
gio/gdbusapplication.c | 424 --------
gio/gio-marshal.list | 3 +-
gio/gio.symbols | 30 +-
gio/gioenums.h | 18 +
gio/giotypes.h | 2 +
gio/tests/.gitignore | 3 -
gio/tests/Makefile.am | 12 -
gio/tests/application.c | 222 ----
gio/tests/testapp.c | 107 --
gio/tests/testapps.c | 604 -----------
16 files changed, 1258 insertions(+), 2532 deletions(-)
---
diff --git a/gio/Makefile.am b/gio/Makefile.am
index 25b6077..50a5aed 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -142,10 +142,11 @@ application_headers = \
gapplication.h
application_sources = \
- gactiongroup.c \
- gsimpleactiongroup.c \
- gaction.c \
- gsimpleaction.c \
+ gactiongroup.c \
+ gsimpleactiongroup.c \
+ gaction.c \
+ gsimpleaction.c \
+ gapplicationimpl-dbus.c \
gapplication.c
local_sources = \
diff --git a/gio/gapplication.c b/gio/gapplication.c
index 9cc59b2..d9beb2d 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -1,11 +1,10 @@
-/* GIO - GLib Input, Output and Streaming Library
+/*
+ * Copyright © 2010 Codethink Limited
*
- * Copyright © 2010 Red Hat, Inc
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the licence or (at
+ * your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,1321 +16,992 @@
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
- * Authors: Colin Walters <walters verbum org>
- * Emmanuele Bassi <ebassi linux intel com>
+ * Authors: Ryan Lortie <desrt desrt ca>
*/
-#include "config.h"
-
-#include <string.h>
-#include <stdlib.h>
+/* Prologue {{{1 */
+#include "gapplication.h"
-#include <gobject/gvaluecollector.h>
+#include "gapplicationimpl.h"
-#include "gapplication.h"
+#include "gioenumtypes.h"
#include "gio-marshal.h"
-#include "glibintl.h"
+#include "gioenums.h"
+#include "gfile.h"
-#include "gioerror.h"
-#include "ginitable.h"
-
-#include "gdbusconnection.h"
-#include "gdbusintrospection.h"
-#include "gdbusmethodinvocation.h"
+#include <string.h>
+struct _GApplicationPrivate
+{
+ GApplicationFlags flags;
+ gchar *id;
-/**
- * SECTION: gapplication
- * @title: GApplication
- * @short_description: Core application class
- *
- * A #GApplication is the foundation of an application, unique for a
- * given application identifier. The #GApplication wraps some
- * low-level platform-specific services and is intended to act as the
- * foundation for higher-level application classes such as
- * #GtkApplication or #MxApplication. In general, you should not use
- * this class outside of a higher level framework. By default,
- * g_application_register_with_data() will invoke g_error() if it is
- * run in a context where it cannot support its core features. Note
- * that g_error() is by default fatal.
- *
- * One of the core features that #GApplication provides is process
- * uniqueness, in the context of a "session". The session concept is
- * platform-dependent, but corresponds roughly to a graphical desktop
- * login. When your application is launched again, its arguments
- * are passed through platform communication to the already running
- * program.
- *
- * In addition, #GApplication provides support for 'actions', which
- * can be presented to the user in a platform-specific way
- * (e.g. Windows 7 jump lists). Note that these are just simple
- * actions without parameters. For more flexible scriptability,
- * implementing a a separate D-Bus interface is recommended, see e.g.
- * <xref linkend="gdbus-convenience"/>.
- *
- * Finally, #GApplication acts as a basic lifecycle root; see the
- * g_application_run() and g_application_quit_with_data() methods.
- *
- * Before using #GApplication, you must choose an "application identifier".
- * The expected form of an application identifier is very close to that of
- * of a <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface">DBus bus name</ulink>.
- * Examples include: "com.example.MyApp" "org.example.internal-apps.Calculator"
- * For convenience, the restrictions on application identifiers are reproduced
- * here:
- * <itemizedlist>
- * <listitem>Application identifiers must contain only the ASCII characters "[A-Z][a-z][0-9]_-" and must not begin with a digit.</listitem>
- * <listitem>Application identifiers must contain at least one '.' (period) character (and thus at least two elements).</listitem>
- * <listitem>Application identifiers must not begin with a '.' (period) character.</listitem>
- * <listitem>Application identifiers must not exceed 255 characters.</listitem>
- * </itemizedlist>
- *
- * <refsect2><title>D-Bus implementation</title>
- * <para>
- * On UNIX systems using D-Bus, #GApplication is implemented by claiming the
- * application identifier as a bus name on the session bus. The implementation
- * exports an object at the object path that is created by replacing '.' with
- * '/' in the application identifier (e.g. the object path for the
- * application id 'org.gtk.TestApp' is '/org/gtk/TestApp'). The object
- * implements the org.gtk.Application interface.
- * </para>
- * <classsynopsis class="interface">
- * <ooclass><interfacename>org.gtk.Application</interfacename></ooclass>
- * <methodsynopsis>
- * <void/>
- * <methodname>Activate</methodname>
- * <methodparam><modifier>in</modifier><type>aay</type><parameter>arguments</parameter></methodparam>
- * <methodparam><modifier>in</modifier><type>a{sv}</type><parameter>data</parameter></methodparam>
- * </methodsynopsis>
- * <methodsynopsis>
- * <void/>
- * <methodname>InvokeAction</methodname>
- * <methodparam><modifier>in</modifier><type>s</type><parameter>action</parameter></methodparam>
- * <methodparam><modifier>in</modifier><type>a{sv}</type><parameter>data</parameter></methodparam>
- * </methodsynopsis>
- * <methodsynopsis>
- * <type>a{s(sb)}</type>
- * <methodname>ListActions</methodname>
- * <void/>
- * </methodsynopsis>
- * <methodsynopsis>
- * <void/>
- * <methodname>Quit</methodname>
- * <methodparam><modifier>in</modifier><type>a{sv}</type><parameter>data</parameter></methodparam>
- * </methodsynopsis>
- * <methodsynopsis>
- * <modifier>Signal</modifier>
- * <void/>
- * <methodname>ActionsChanged</methodname>
- * <void/>
- * </methodsynopsis>
- * </classsynopsis>
- * <para>
- * The <methodname>Activate</methodname> function is called on the existing
- * application instance when a second instance fails to take the bus name.
- * @arguments contains the commandline arguments given to the second instance
- * and @data contains platform-specific additional data.
- *
- * On all platforms, @data will have a key "cwd" of type signature
- * "ay" which contains the working directory of the invoked
- * executable; this data is defined to be in the default GLib
- * filesystem encoding for the platform. See g_filename_to_utf8().
- *
- * </para>
- * <para>
- * The <methodname>InvokeAction</methodname> function can be called to
- * invoke one of the actions exported by the application. On X11
- * platforms, the platform_data argument should have a "timestamp"
- * parameter of type "u" with the server time of the initiating event.
- * </para>
- * <para>
- * The <methodname>ListActions</methodname> function returns a dictionary
- * with the exported actions of the application. The keys of the dictionary
- * are the action names, and the values are structs containing the description
- * for the action and a boolean that represents if the action is enabled or not.
- * </para>
- * <para>
- * The <methodname>Quit</methodname> function can be called to
- * terminate the application. The @data parameter contains
- * platform-specific data. On X11 platforms, the platform_data
- * argument should have a "timestamp" parameter of type "u" with the
- * server time of the initiating event.
- * </para>
- * <para>
- * The <methodname>ActionsChanged</methodname> signal is emitted when the
- * exported actions change (i.e. an action is added, removed, enabled,
- * disabled, or otherwise changed).
- * </para>
- * <para>
- * #GApplication is supported since Gio 2.26.
- * </para>
- * </refsect2>
- */
+ GHashTable *actions; /* string -> GApplicationAction */
+ GMainLoop *mainloop;
-static void initable_iface_init (GInitableIface *initable_iface);
+ guint inactivity_timeout_id;
+ guint inactivity_timeout;
+ guint use_count;
-G_DEFINE_TYPE_WITH_CODE (GApplication, g_application, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init));
+ guint is_registered : 1;
+ guint is_remote : 1;
+ GApplicationImpl *impl;
+};
enum
{
- PROP_0,
-
+ PROP_NONE,
PROP_APPLICATION_ID,
- PROP_REGISTER,
- PROP_DEFAULT_QUIT,
+ PROP_FLAGS,
+ PROP_IS_REGISTERED,
PROP_IS_REMOTE,
- PROP_ARGV,
- PROP_PLATFORM_DATA
+ PROP_INACTIVITY_TIMEOUT
};
enum
{
- QUIT_WITH_DATA,
- ACTION_WITH_DATA,
- PREPARE_ACTIVATION,
-
- LAST_SIGNAL
+ SIGNAL_STARTUP,
+ SIGNAL_ACTIVATE,
+ SIGNAL_OPEN,
+ SIGNAL_ACTION,
+ SIGNAL_COMMAND_LINE,
+ NR_SIGNALS
};
-static guint application_signals[LAST_SIGNAL] = { 0 };
+static guint g_application_signals[NR_SIGNALS];
-typedef struct {
- gchar *name;
- gchar *description;
- guint enabled : 1;
-} GApplicationAction;
+G_DEFINE_TYPE (GApplication, g_application, G_TYPE_OBJECT)
-struct _GApplicationPrivate
+/* vfunc defaults {{{1 */
+static void
+g_application_real_before_emit (GApplication *application,
+ GVariant *platform_data)
{
- gchar *appid;
- GHashTable *actions; /* name -> GApplicationAction */
- GMainLoop *mainloop;
-
- GVariant *argv;
- GVariant *platform_data;
+}
- guint do_register : 1;
- guint default_quit : 1;
- guint is_remote : 1;
- guint registration_tried : 1;
+static void
+g_application_real_after_emit (GApplication *application,
+ GVariant *platform_data)
+{
+}
- guint actions_changed_id;
+static void
+g_application_real_startup (GApplication *application)
+{
+}
-#ifdef G_OS_UNIX
- gchar *dbus_path;
- GDBusConnection *session_bus;
-#endif
-};
+static void
+g_application_real_activate (GApplication *application)
+{
+ if (!g_signal_has_handler_pending (application,
+ g_application_signals[SIGNAL_ACTIVATE],
+ 0, TRUE))
+ {
+ static gboolean warned;
-static GApplication *primary_application = NULL;
-static GHashTable *instances_for_appid = NULL;
+ if (warned)
+ return;
-static gboolean initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error);
+ g_warning ("Your application does not implement "
+ "g_application_activate() and has no handlers connected "
+ "to the 'activate' signal. It should do one of these.");
+ warned = TRUE;
+ }
+}
-static gboolean _g_application_platform_init (GApplication *app,
- GCancellable *cancellable,
- GError **error);
-static gboolean _g_application_platform_register (GApplication *app,
- gboolean *unique,
- GCancellable *cancellable,
- GError **error);
+static void
+g_application_real_open (GApplication *application,
+ GFile **files,
+ gint n_files,
+ const gchar *hint)
+{
+ if (!g_signal_has_handler_pending (application,
+ g_application_signals[SIGNAL_OPEN],
+ 0, TRUE))
+ {
+ static gboolean warned;
-static void _g_application_platform_remote_invoke_action (GApplication *app,
- const gchar *action,
- GVariant *platform_data);
-static void _g_application_platform_remote_quit (GApplication *app,
- GVariant *platform_data);
-static void _g_application_platform_on_actions_changed (GApplication *app);
+ if (warned)
+ return;
-static void
-initable_iface_init (GInitableIface *initable_iface)
-{
- initable_iface->init = initable_init;
+ g_warning ("Your application claims to support opening files "
+ "but does not implement g_application_open() and has no "
+ "handlers connected to the 'open' signal.");
+ warned = TRUE;
+ }
}
-#ifdef G_OS_UNIX
-#include "gdbusapplication.c"
-#else
-#include "gnullapplication.c"
-#endif
-
static gboolean
-_g_application_validate_id (const char *id)
+g_application_real_local_command_line (GApplication *application,
+ GVariant **arguments,
+ int *exit_status)
{
- gboolean allow_dot;
-
- if (strlen (id) > 255)
- return FALSE;
-
- if (!g_ascii_isalpha (*id))
+ if (0)
return FALSE;
- id++;
- allow_dot = FALSE;
- for (; *id; id++)
+ else
{
- if (g_ascii_isalnum (*id) || (*id == '-') || (*id == '_'))
- allow_dot = TRUE;
- else if (allow_dot && *id == '.')
- allow_dot = FALSE;
+ GError *error = NULL;
+ gint n_args;
+
+ if (!g_application_register (application, NULL, &error))
+ {
+ g_critical ("%s", error->message);
+ g_error_free (error);
+ *exit_status = 1;
+ return TRUE;
+ }
+
+ n_args = g_variant_n_children (*arguments);
+
+ if (application->priv->flags & G_APPLICATION_FLAGS_IS_SERVICE)
+ {
+ if (n_args > 1)
+ {
+ g_printerr ("GApplication service mode takes no arguments.\n");
+ application->priv->flags &= ~G_APPLICATION_FLAGS_IS_SERVICE;
+ }
+
+ return TRUE;
+ }
+
+ if (n_args <= 1)
+ {
+ g_application_activate (application);
+ *exit_status = 0;
+ }
+
else
- return FALSE;
+ {
+ if (~application->priv->flags & G_APPLICATION_FLAGS_HANDLES_OPEN)
+ {
+ g_critical ("This application can not open files.");
+ *exit_status = 1;
+ }
+ else
+ {
+ GFile **files;
+ gint n_files;
+ gint i;
+
+ n_files = n_args - 1;
+ files = g_new (GFile *, n_files);
+
+ for (i = 0; i < n_files; i++)
+ {
+ const gchar *arg;
+
+ g_variant_get_child (*arguments, i + 1, "^&ay", &arg);
+ files[i] = g_file_new_for_commandline_arg (arg);
+ }
+
+ g_application_open (application, files, n_files, "");
+
+ for (i = 0; i < n_files; i++)
+ g_object_unref (files[i]);
+ g_free (files);
+
+ *exit_status = 0;
+ }
+ }
+
+ return TRUE;
}
- return TRUE;
-}
-
-static gpointer
-init_appid_statics (gpointer data)
-{
- instances_for_appid = g_hash_table_new (g_str_hash, g_str_equal);
- return NULL;
}
-static GApplication *
-application_for_appid (const char *appid)
+static void
+g_application_real_add_platform_data (GApplication *application,
+ GVariantBuilder *builder)
{
- static GOnce appid_once = G_ONCE_INIT;
-
- g_once (&appid_once, init_appid_statics, NULL);
-
- return g_hash_table_lookup (instances_for_appid, appid);
}
-static gboolean
-g_application_default_quit_with_data (GApplication *application,
- GVariant *platform_data)
+static void
+g_application_real_quit_mainloop (GApplication *application)
{
- g_return_val_if_fail (application->priv->mainloop != NULL, FALSE);
- g_main_loop_quit (application->priv->mainloop);
-
- return TRUE;
+ if (application->priv->mainloop != NULL)
+ g_main_loop_quit (application->priv->mainloop);
}
static void
-g_application_default_run (GApplication *application)
+g_application_real_run_mainloop (GApplication *application)
{
if (application->priv->mainloop == NULL)
- application->priv->mainloop = g_main_loop_new (NULL, TRUE);
+ application->priv->mainloop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (application->priv->mainloop);
}
-static GVariant *
-append_cwd_to_platform_data (GVariant *platform_data)
+/* GObject implementation stuff {{{1 */
+static void
+g_application_set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec)
{
- GVariantBuilder builder;
- gchar *cwd;
- GVariant *result;
+ GApplication *application = G_APPLICATION (object);
- cwd = g_get_current_dir ();
+ switch (prop_id)
+ {
+ case PROP_APPLICATION_ID:
+ g_application_set_application_id (application,
+ g_value_get_string (value));
+ break;
+
+ case PROP_FLAGS:
+ g_application_set_flags (application, g_value_get_flags (value));
+ break;
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
- if (cwd)
- g_variant_builder_add (&builder, "{sv}",
- "cwd",
- g_variant_new_bytestring (cwd));
- g_free (cwd);
+ case PROP_INACTIVITY_TIMEOUT:
+ g_application_set_inactivity_timeout (application,
+ g_value_get_uint (value));
+ break;
- if (platform_data)
- {
- GVariantIter iter;
- GVariant *item;
-
- g_variant_iter_init (&iter, platform_data);
- while (g_variant_iter_next (&iter, "@{sv}", &item))
- {
- g_variant_builder_add_value (&builder, item);
- g_variant_unref (item);
- }
+ default:
+ g_assert_not_reached ();
}
- result = g_variant_builder_end (&builder);
- return result;
}
-static gboolean
-timeout_handle_actions_changed (gpointer user_data)
+static void
+g_application_get_property (GObject *object, guint prop_id,
+ GValue *value, GParamSpec *pspec)
{
- GApplication *application = user_data;
+ GApplication *application = G_APPLICATION (object);
+
+ switch (prop_id)
+ {
+ case PROP_APPLICATION_ID:
+ g_value_set_string (value,
+ g_application_get_application_id (application));
+ break;
- application->priv->actions_changed_id = 0;
+ case PROP_FLAGS:
+ g_value_set_flags (value,
+ g_application_get_flags (application));
+ break;
- _g_application_platform_on_actions_changed (application);
+ case PROP_IS_REGISTERED:
+ g_value_set_boolean (value,
+ g_application_get_is_registered (application));
+ break;
- return FALSE;
+ case PROP_IS_REMOTE:
+ g_value_set_boolean (value,
+ g_application_get_is_remote (application));
+ break;
+
+ case PROP_INACTIVITY_TIMEOUT:
+ g_value_set_uint (value,
+ g_application_get_inactivity_timeout (application));
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
}
-static inline void
-queue_actions_change_notification (GApplication *application)
+static void
+g_application_constructed (GObject *object)
{
- GApplicationPrivate *priv = application->priv;
+ GApplication *application = G_APPLICATION (object);
- if (priv->actions_changed_id == 0)
- priv->actions_changed_id = g_timeout_add (0, timeout_handle_actions_changed, application);
+ g_assert (application->priv->id != NULL);
}
-static gboolean
-initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
+static void
+g_application_finalize (GObject *object)
{
- GApplication *app = G_APPLICATION (initable);
- gboolean unique;
+ GApplication *application = G_APPLICATION (object);
- if (!_g_application_platform_init (app, cancellable, error))
- return FALSE;
+ if (application->priv->impl)
+ g_application_impl_destroy (application->priv->impl);
+ g_free (application->priv->id);
- if (app->priv->do_register
- && !_g_application_platform_register (app, &unique, cancellable ,error))
- return FALSE;
+ if (application->priv->mainloop)
+ g_main_loop_unref (application->priv->mainloop);
- return TRUE;
+ G_OBJECT_CLASS (g_application_parent_class)
+ ->finalize (object);
}
static void
-g_application_action_free (gpointer data)
+g_application_init (GApplication *application)
{
- if (G_LIKELY (data != NULL))
- {
- GApplicationAction *action = data;
+ application->priv = G_TYPE_INSTANCE_GET_PRIVATE (application,
+ G_TYPE_APPLICATION,
+ GApplicationPrivate);
+}
- g_free (action->name);
- g_free (action->description);
+static void
+g_application_class_init (GApplicationClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->constructed = g_application_constructed;
+ object_class->finalize = g_application_finalize;
+ object_class->get_property = g_application_get_property;
+ object_class->set_property = g_application_set_property;
+
+ class->before_emit = g_application_real_before_emit;
+ class->after_emit = g_application_real_after_emit;
+ class->startup = g_application_real_startup;
+ class->activate = g_application_real_activate;
+ class->open = g_application_real_open;
+ class->local_command_line = g_application_real_local_command_line;
+ class->add_platform_data = g_application_real_add_platform_data;
+ class->quit_mainloop = g_application_real_quit_mainloop;
+ class->run_mainloop = g_application_real_run_mainloop;
+
+ g_object_class_install_property (object_class, PROP_APPLICATION_ID,
+ g_param_spec_string ("application-id", "application identifier",
+ "Unique identifier for the application",
+ NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class, PROP_FLAGS,
+ g_param_spec_flags ("flags", "application flags",
+ "Flags specifying the behaviour of the application",
+ G_TYPE_APPLICATION_FLAGS, G_APPLICATION_FLAGS_NONE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class, PROP_IS_REGISTERED,
+ g_param_spec_boolean ("is-registered", "is registered",
+ "If g_application_register() has been called",
+ FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class, PROP_IS_REMOTE,
+ g_param_spec_boolean ("is-remote", "is remote",
+ "If this application instance is remote",
+ FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+
+ g_application_signals[SIGNAL_STARTUP] =
+ g_signal_new ("startup", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GApplicationClass, startup),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+ g_application_signals[SIGNAL_ACTIVATE] =
+ g_signal_new ("activate", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GApplicationClass, activate),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+ g_application_signals[SIGNAL_OPEN] =
+ g_signal_new ("open", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GApplicationClass, open),
+ NULL, NULL, _gio_marshal_VOID__POINTER_INT_STRING,
+ G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);
+
+ g_type_class_add_private (class, sizeof (GApplicationPrivate));
+}
- g_slice_free (GApplicationAction, action);
- }
+static GVariant *
+get_platform_data (GApplication *application)
+{
+ GVariantBuilder *builder;
+ GVariant *result;
+
+ builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
+
+ {
+ gchar *cwd = g_get_current_dir ();
+ g_variant_builder_add (builder, "{sv}", "cwd",
+ g_variant_new_bytestring (cwd));
+ g_free (cwd);
+ }
+
+ G_APPLICATION_GET_CLASS (application)->
+ add_platform_data (application, builder);
+
+ result = g_variant_builder_end (builder);
+ g_variant_builder_unref (builder);
+
+ return result;
}
+/* Application ID validity {{{1 */
+
/**
- * g_application_new:
- * @appid: System-dependent application identifier
- * @argc: Number of arguments in @argv
- * @argv: (allow-none) (array length=argc): Argument vector, usually from the <parameter>argv</parameter> parameter of main()
- *
- * Create a new #GApplication. This uses a platform-specific
- * mechanism to ensure the current process is the unique owner of the
- * application (as defined by the @appid). If successful, the
- * #GApplication:is-remote property will be %FALSE, and it is safe to
- * continue creating other resources such as graphics windows.
- *
- * If the given @appid is already running in another process, the the
- * GApplication::activate_with_data signal will be emitted in the
- * remote process, with the data from @argv and other
- * platform-specific data available. Subsequently the
- * #GApplication:default-quit property will be evaluated. If it's
- * %TRUE, then the current process will terminate. If %FALSE, then
- * the application remains in the #GApplication:is-remote state, and
- * you can e.g. call g_application_invoke_action(). Note that proxy
- * instances should not call g_application_add_action().
- *
- * This function may do synchronous I/O to obtain unique ownership
- * of the application id, and will block the calling thread in this
- * case.
- *
- * If the environment does not support the basic functionality of
- * #GApplication, this function will invoke g_error(), which by
- * default is a fatal operation. This may arise for example on
- * UNIX systems using D-Bus when the session bus is not available.
- *
- * As a convenience, this function is defined to call g_type_init() as
- * its very first action.
- *
- * Returns: (transfer full): An application instance
- *
- * Since: 2.26
- */
-GApplication *
-g_application_new (const gchar *appid,
- int argc,
- char **argv)
+ * g_application_id_is_valid:
+ * @application_id: a potential application identifier
+ * @returns: %TRUE if @application_id is valid
+ *
+ * Checks if @application_id is a valid application ID. A valid ID is
+ * required for calls to g_application_new() and
+ * g_application_set_application_id().
+ **/
+gboolean
+g_application_id_is_valid (const gchar *application_id)
{
- const gchar * const *args = (const gchar **) argv;
- GObject *app;
- GError *error = NULL;
- GVariant *argv_variant;
+ gboolean allow_dot;
- g_type_init ();
+ if (strlen (application_id) > 255)
+ return FALSE;
+
+ if (!g_ascii_isalpha (*application_id))
+ return FALSE;
- g_return_val_if_fail (appid != NULL, NULL);
-
- argv_variant = g_variant_new_bytestring_array (args, argc);
-
- app = g_initable_new (G_TYPE_APPLICATION,
- NULL,
- &error,
- "application-id", appid,
- "argv", argv_variant,
- NULL);
- if (!app)
+ application_id++;
+ allow_dot = FALSE;
+ for (; *application_id; application_id++)
{
- g_error ("%s", error->message);
- g_clear_error (&error);
- return NULL;
+ if (g_ascii_isalnum (*application_id) ||
+ (*application_id == '-') ||
+ (*application_id == '_'))
+ allow_dot = TRUE;
+ else if (allow_dot && *application_id == '.')
+ allow_dot = FALSE;
+ else
+ return FALSE;
}
- return G_APPLICATION (app);
+
+ return TRUE;
}
+/* Public Constructor {{{1 */
/**
- * g_application_try_new:
- * @appid: System-dependent application identifier
- * @argc: Number of arguments in @argv
- * @argv: (allow-none) (array length=argc): Argument vector, usually from the <parameter>argv</parameter> parameter of main()
- * @error: a #GError
+ * g_application_new:
+ * @application_id: the application id
+ * @flags: the application flags
+ * @returns: a new #GApplication instance
*
- * This function is similar to g_application_new(), but allows for
- * more graceful fallback if the environment doesn't support the
- * basic #GApplication functionality.
+ * Creates a new #GApplication instance.
*
- * Returns: (transfer full): An application instance
+ * This function calls g_type_init() for you.
*
- * Since: 2.26
- */
+ * The application id must be valid. See g_application_id_is_valid().
+ **/
GApplication *
-g_application_try_new (const gchar *appid,
- int argc,
- char **argv,
- GError **error)
+g_application_new (const gchar *application_id,
+ GApplicationFlags flags)
{
- const gchar * const *args = (const gchar **) argv;
- GVariant *argv_variant;
+ g_return_val_if_fail (g_application_id_is_valid (application_id), NULL);
g_type_init ();
- g_return_val_if_fail (appid != NULL, NULL);
-
- argv_variant = g_variant_new_bytestring_array (args, argc);
-
- return G_APPLICATION (g_initable_new (G_TYPE_APPLICATION,
- NULL,
- error,
- "application-id", appid,
- "argv", argv_variant,
- NULL));
+ return g_object_new (G_TYPE_APPLICATION,
+ "application-id", application_id,
+ "flags", flags,
+ NULL);
}
+/* Simple get/set: application id, flags, inactivity timeout {{{1 */
/**
- * g_application_unregistered_try_new:
- * @appid: System-dependent application identifier
- * @argc: Number of arguments in @argv
- * @argv: (allow-none) (array length=argc): Argument vector, usually from the <parameter>argv</parameter> parameter of main()
- * @error: a #GError
- *
- * This function is similar to g_application_try_new(), but also
- * sets the GApplication:register property to %FALSE. You can later
- * call g_application_register() to complete initialization.
+ * g_application_get_application_id:
+ * @application: a #GApplication
+ * @returns: the identifier for @application, owned by @application
*
- * Returns: (transfer full): An application instance
+ * Gets the unique identifier for @application.
*
- * Since: 2.26
- */
-GApplication *
-g_application_unregistered_try_new (const gchar *appid,
- int argc,
- char **argv,
- GError **error)
+ * Since: 2.28
+ **/
+const gchar *
+g_application_get_application_id (GApplication *application)
{
- const gchar * const *args = (const gchar **) argv;
- GVariant *argv_variant;
-
- g_type_init ();
+ g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
- g_return_val_if_fail (appid != NULL, NULL);
-
- argv_variant = g_variant_new_bytestring_array (args, argc);
-
- return G_APPLICATION (g_initable_new (G_TYPE_APPLICATION,
- NULL,
- error,
- "application-id", appid,
- "argv", argv_variant,
- "register", FALSE,
- NULL));
+ return application->priv->id;
}
/**
- * g_application_register:
+ * g_application_set_application_id:
* @application: a #GApplication
+ * @application_id: the identifier for @application
*
- * By default, #GApplication ensures process uniqueness when
- * initialized, but this behavior is controlled by the
- * GApplication:register property. If it was given as %FALSE at
- * construction time, this function allows you to later attempt
- * to ensure uniqueness. Note that the GApplication:default-quit
- * property no longer applies at this point; if this function returns
- * %FALSE, platform activation will occur, but the current process
- * will not be terminated.
+ * Sets the unique identifier for @application.
*
- * It is an error to call this function more than once. It is
- * also an error to call this function if the GApplication:register
- * property was %TRUE at construction time.
+ * The application id can only be modified if @application has not yet
+ * been registered.
*
- * Returns: %TRUE if registration was successful
- */
-gboolean
-g_application_register (GApplication *application)
+ * The application id must be valid. See g_application_id_is_valid().
+ *
+ * Since: 2.28
+ **/
+void
+g_application_set_application_id (GApplication *application,
+ const gchar *application_id)
{
- gboolean unique;
+ g_return_if_fail (G_IS_APPLICATION (application));
- g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
- g_return_val_if_fail (application->priv->is_remote, FALSE);
- g_return_val_if_fail (!application->priv->registration_tried, FALSE);
+ if (g_strcmp0 (application->priv->id, application_id) != 0)
+ {
+ g_return_if_fail (g_application_id_is_valid (application_id));
+ g_return_if_fail (!application->priv->is_registered);
- if (!_g_application_platform_register (application, &unique, NULL, NULL))
- return FALSE;
- return unique;
+ g_free (application->priv->id);
+ application->priv->id = g_strdup (application_id);
+
+ g_object_notify (G_OBJECT (application), "application-id");
+ }
}
/**
- * g_application_add_action:
+ * g_application_get_flags:
* @application: a #GApplication
- * @name: the action name
- * @description: the action description; can be a translatable
- * string
+ * @returns: the flags for @application
*
- * Adds an action @name to the list of exported actions of @application.
+ * Gets the flags for @application.
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * See #GApplicationFlags.
*
- * You can invoke an action using g_application_invoke_action().
+ * Since: 2.28
+ **/
+GApplicationFlags
+g_application_get_flags (GApplication *application)
+{
+ g_return_val_if_fail (G_IS_APPLICATION (application), 0);
+
+ return application->priv->flags;
+}
+
+/**
+ * g_application_set_flags:
+ * @application: a #GApplication
+ * @flags: the flags for @application
*
- * The newly added action is enabled by default; you can call
- * g_application_set_action_enabled() to disable it.
+ * Sets the flags for @application.
*
- * Since: 2.26
- */
+ * The flags can only be modified if @application has not yet been
+ * registered.
+ *
+ * See #GApplicationFlags.
+ *
+ * Since: 2.28
+ **/
void
-g_application_add_action (GApplication *application,
- const gchar *name,
- const gchar *description)
+g_application_set_flags (GApplication *application,
+ GApplicationFlags flags)
{
- GApplicationPrivate *priv;
- GApplicationAction *action;
-
g_return_if_fail (G_IS_APPLICATION (application));
- g_return_if_fail (name != NULL && *name != '\0');
- g_return_if_fail (!application->priv->is_remote);
- priv = application->priv;
-
- g_return_if_fail (g_hash_table_lookup (priv->actions, name) == NULL);
+ if (application->priv->flags != flags)
+ {
+ g_return_if_fail (!application->priv->is_registered);
- action = g_slice_new (GApplicationAction);
- action->name = g_strdup (name);
- action->description = g_strdup (description);
- action->enabled = TRUE;
+ application->priv->flags = flags;
- g_hash_table_insert (priv->actions, action->name, action);
- queue_actions_change_notification (application);
+ g_object_notify (G_OBJECT (application), "flags");
+ }
}
/**
- * g_application_remove_action:
+ * g_application_get_inactivity_timeout:
* @application: a #GApplication
- * @name: the name of the action to remove
*
- * Removes the action @name from the list of exported actions of @application.
+ * Gets the current inactivity timeout for the application.
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * This is the amount of time (in milliseconds) after the last call to
+ * g_application_release() before the application stops running.
*
- * Since: 2.26
- */
-void
-g_application_remove_action (GApplication *application,
- const gchar *name)
+ * Returns: the timeout, in milliseconds
+ *
+ * Since: 2.28
+ **/
+guint
+g_application_get_inactivity_timeout (GApplication *application)
{
- GApplicationPrivate *priv;
-
- g_return_if_fail (G_IS_APPLICATION (application));
- g_return_if_fail (name != NULL && *name != '\0');
- g_return_if_fail (!application->priv->is_remote);
-
- priv = application->priv;
+ g_return_val_if_fail (G_IS_APPLICATION (application), 0);
- g_return_if_fail (g_hash_table_lookup (priv->actions, name) != NULL);
-
- g_hash_table_remove (priv->actions, name);
- queue_actions_change_notification (application);
+ return application->priv->inactivity_timeout;
}
/**
- * g_application_invoke_action:
+ * g_application_set_inactivity_timeout:
* @application: a #GApplication
- * @name: the name of the action to invoke
- * @platform_data: (allow-none): platform-specific event data
+ * @inactivity_timeout: the timeout, in milliseconds
*
- * Invokes the action @name of the passed #GApplication.
+ * Sets the current inactivity timeout for the application.
*
- * This function has different behavior depending on whether @application
- * is acting as a proxy for another process. In the normal case where
- * the current process is hosting the application, and the specified
- * action exists and is enabled, the #GApplication::action signal will
- * be emitted.
+ * This is the amount of time (in milliseconds) after the last call to
+ * g_application_release() before the application stops running.
*
- * If @application is a proxy, then the specified action will be invoked
- * in the remote process. It is not necessary to call
- * g_application_add_action() in the current process in order to invoke
- * one remotely.
+ * This call has no side effects of its own. The value set here is only
+ * used for next time g_application_release() drops the use count to
+ * zero. Any timeouts currently in progress are not impacted.
*
- * Since: 2.26
- */
+ * Returns: the timeout, in milliseconds
+ *
+ * Since: 2.28
+ **/
void
-g_application_invoke_action (GApplication *application,
- const gchar *name,
- GVariant *platform_data)
+g_application_set_inactivity_timeout (GApplication *application,
+ guint inactivity_timeout)
{
- GApplicationPrivate *priv;
- GApplicationAction *action;
-
g_return_if_fail (G_IS_APPLICATION (application));
- g_return_if_fail (name != NULL);
- g_return_if_fail (platform_data == NULL
- || g_variant_is_of_type (platform_data, G_VARIANT_TYPE ("a{sv}")));
-
- if (platform_data == NULL)
- platform_data = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
- else
- g_variant_ref (platform_data);
- priv = application->priv;
-
- if (priv->is_remote)
+ if (application->priv->inactivity_timeout != inactivity_timeout)
{
- _g_application_platform_remote_invoke_action (application, name, platform_data);
- goto out;
- }
-
- action = g_hash_table_lookup (priv->actions, name);
- g_return_if_fail (action != NULL);
- if (!action->enabled)
- goto out;
+ application->priv->inactivity_timeout = inactivity_timeout;
- g_signal_emit (application, application_signals[ACTION_WITH_DATA],
- g_quark_from_string (name),
- name,
- platform_data);
+ g_object_notify (G_OBJECT (application), "inactivity-timeout");
+ }
+}
+/* Read-only property getters (is registered, is remote) {{{1 */
+/**
+ * g_application_get_is_registered:
+ * @application: a #GApplication
+ * @returns: %TRUE if @application is registered
+ *
+ * Checks if @application is registered.
+ *
+ * An application is registered if g_application_register() has been
+ * successfully called.
+ *
+ * Since: 2.28
+ **/
+gboolean
+g_application_get_is_registered (GApplication *application)
+{
+ g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
- out:
- g_variant_unref (platform_data);
+ return application->priv->is_registered;
}
/**
- * g_application_list_actions:
+ * g_application_get_is_remote:
* @application: a #GApplication
+ * @returns: %TRUE if @application is remote
*
- * Retrieves the list of action names currently exported by @application.
+ * Checks if @application is remote.
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * If @application is remote then it means that another instance of
+ * application already exists (the 'primary' instance). Calls to
+ * perform actions on @application will result in the actions being
+ * performed by the primary instance.
*
- * Return value: (transfer full): a newly allocation, %NULL-terminated array
- * of strings containing action names; use g_strfreev() to free the
- * resources used by the returned array
+ * The value of this property can not be accessed before
+ * g_application_register() has been called. See
+ * g_application_get_is_registered().
*
- * Since: 2.26
- */
-gchar **
-g_application_list_actions (GApplication *application)
+ * Since: 2.28
+ **/
+gboolean
+g_application_get_is_remote (GApplication *application)
{
- GApplicationPrivate *priv;
- GHashTableIter iter;
- gpointer key;
- gchar **retval;
- gint i;
-
- g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
- g_return_val_if_fail (!application->priv->is_remote, NULL);
-
- priv = application->priv;
-
- retval = g_new (gchar*, g_hash_table_size (priv->actions) + 1);
-
- i = 0;
- g_hash_table_iter_init (&iter, priv->actions);
- while (g_hash_table_iter_next (&iter, &key, NULL))
- retval[i++] = g_strdup (key);
-
- retval[i] = NULL;
+ g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
+ g_return_val_if_fail (application->priv->is_registered, FALSE);
- return retval;
+ return application->priv->is_remote;
}
+/* Register {{{1 */
/**
- * g_application_set_action_enabled:
+ * g_application_register:
* @application: a #GApplication
- * @name: the name of the application
- * @enabled: whether to enable or disable the action @name
+ * @cancellable: a #GCancellable, or %NULL
+ * @error: a pointer to a NULL #GError, or %NULL
+ * @returns: %TRUE if registration succeeded
*
- * Sets whether the action @name inside @application should be enabled
- * or disabled.
+ * Attempts registration of the application.
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * This is the point at which the application discovers if it is the
+ * primary instance or merely acting as a remote for an already-existing
+ * primary instance.
*
- * Invoking a disabled action will not result in the #GApplication::action
- * signal being emitted.
+ * If the application has already been registered then %TRUE is
+ * returned with no work performed.
*
- * Since: 2.26
- */
-void
-g_application_set_action_enabled (GApplication *application,
- const gchar *name,
- gboolean enabled)
+ * The startup() virtual function is invoked if registration succeeds
+ * and @application is the primary instance.
+ *
+ * In the event of an error (such as @cancellable being cancelled, or a
+ * failure to connect to the session bus), %FALSE is returned and @error
+ * is set appropriately.
+ *
+ * Note: the return value of this function is not an indicator that this
+ * instance is or is not the primary instance of the application. See
+ * g_application_get_is_remote() for that.
+ *
+ * Since: 2.28
+ **/
+gboolean
+g_application_register (GApplication *application,
+ GCancellable *cancellable,
+ GError **error)
{
- GApplicationAction *action;
+ g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
- g_return_if_fail (G_IS_APPLICATION (application));
- g_return_if_fail (name != NULL);
- g_return_if_fail (!application->priv->is_remote);
+ if (!application->priv->is_registered)
+ {
+ gboolean is_remote;
+ gboolean try;
- enabled = !!enabled;
+ /* don't try to be the primary instance if
+ * G_APPLICATION_FLAGS_IS_LAUNCHER was specified.
+ */
+ try = !(application->priv->flags & G_APPLICATION_FLAGS_IS_LAUNCHER);
- action = g_hash_table_lookup (application->priv->actions, name);
- g_return_if_fail (action != NULL);
- if (action->enabled == enabled)
- return;
+ application->priv->impl =
+ g_application_impl_register (application, application->priv->id,
+ application->priv->flags,
+ &is_remote, cancellable, error);
- action->enabled = enabled;
+ if (application->priv->impl == NULL)
+ return FALSE;
- queue_actions_change_notification (application);
-}
+ application->priv->is_remote = is_remote;
+ application->priv->is_registered = TRUE;
+
+ g_object_notify (G_OBJECT (application), "is-registered");
+ if (!is_remote)
+ g_signal_emit (application, g_application_signals[SIGNAL_STARTUP], 0);
+ }
+ return TRUE;
+}
+
+/* Hold/release {{{1 */
/**
- * g_application_get_action_description:
+ * g_application_hold:
* @application: a #GApplication
- * @name: Action name
- *
- * Gets the description of the action @name.
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * Increases the use count of @application.
*
- * Returns: Description for the given action named @name
+ * Use this function to indicate that the application has a reason to
+ * continue to run. For example, g_application_hold() is called by Gtk
+ * when a toplevel window is on the screen.
*
- * Since: 2.26
- */
-G_CONST_RETURN gchar *
-g_application_get_action_description (GApplication *application,
- const gchar *name)
+ * To cancel the hold, call g_application_release().
+ **/
+void
+g_application_hold (GApplication *application)
{
- GApplicationAction *action;
-
- g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
- g_return_val_if_fail (name != NULL, NULL);
- g_return_val_if_fail (!application->priv->is_remote, NULL);
+ if (application->priv->inactivity_timeout_id)
+ {
+ g_source_remove (application->priv->inactivity_timeout_id);
+ application->priv->inactivity_timeout_id = 0;
+ }
+
+ application->priv->use_count++;
+}
+
+static gboolean
+inactivity_timeout_expired (gpointer data)
+{
+ GApplication *application = G_APPLICATION (data);
- action = g_hash_table_lookup (application->priv->actions, name);
- g_return_val_if_fail (action != NULL, NULL);
+ G_APPLICATION_GET_CLASS (application)
+ ->quit_mainloop (application);
- return action->description;
+ return FALSE;
}
/**
- * g_application_get_action_enabled:
+ * g_application_release:
* @application: a #GApplication
- * @name: the name of the action
- *
- * Retrieves whether the action @name is enabled or not.
- *
- * See g_application_set_action_enabled().
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * Decrease the use count of @application.
*
- * Return value: %TRUE if the action was enabled, and %FALSE otherwise
+ * When the use count reaches zero, the application will stop running.
*
- * Since: 2.26
- */
-gboolean
-g_application_get_action_enabled (GApplication *application,
- const gchar *name)
+ * Never call this function except to cancel the effect of a previous
+ * call to g_application_hold().
+ **/
+void
+g_application_release (GApplication *application)
{
- GApplicationAction *action;
-
- g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
- g_return_val_if_fail (name != NULL, FALSE);
- g_return_val_if_fail (!application->priv->is_remote, FALSE);
+ application->priv->use_count--;
- action = g_hash_table_lookup (application->priv->actions, name);
- g_return_val_if_fail (action != NULL, FALSE);
+ if (application->priv->use_count == 0)
+ {
+ if (application->priv->inactivity_timeout)
+ application->priv->inactivity_timeout_id =
+ g_timeout_add (application->priv->inactivity_timeout,
+ inactivity_timeout_expired, application);
- return action->enabled;
+ else
+ G_APPLICATION_GET_CLASS (application)
+ ->quit_mainloop (application);
+ }
}
+/* Activate, Open {{{1 */
/**
- * g_application_run:
+ * g_application_activate:
* @application: a #GApplication
*
- * Starts the application.
+ * Activates the application.
*
- * The default implementation of this virtual function will simply run
- * a main loop.
+ * In essence, this results in the activate() virtual function being
+ * invoked in the primary instance.
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * The application must be registered before calling this function.
*
- * Since: 2.26
- */
+ * Since: 2.28
+ **/
void
-g_application_run (GApplication *application)
+g_application_activate (GApplication *application)
{
g_return_if_fail (G_IS_APPLICATION (application));
- g_return_if_fail (!application->priv->is_remote);
+ g_return_if_fail (application->priv->is_registered);
+
+ if (application->priv->is_remote)
+ g_application_impl_activate (application->priv->impl,
+ get_platform_data (application));
- G_APPLICATION_GET_CLASS (application)->run (application);
+ else
+ g_signal_emit (application, g_application_signals[SIGNAL_ACTIVATE], 0);
}
/**
- * g_application_quit_with_data:
+ * g_application_open:
* @application: a #GApplication
- * @platform_data: (allow-none): platform-specific data
+ * @files: an array of #GFile<!-- -->s to open
+ * @n_files: the length of the @files array
+ * @hint: a hint (or ""), but never %NULL
*
- * Request that the application quits.
+ * Opens the given files.
*
- * This function has different behavior depending on whether @application
- * is acting as a proxy for another process. In the normal case where
- * the current process is hosting the application, the default
- * implementation will quit the main loop created by g_application_run().
+ * In essence, this results in the open() virtual function being invoked
+ * in the primary instance.
*
- * If @application is a proxy, then the remote process will be asked
- * to quit.
+ * @n_files must be greater than zero.
*
- * Returns: %TRUE if the application accepted the request, %FALSE otherwise
+ * @hint is simply passed through to the open() virtual function. It is
+ * intended to be used by applications that have multiple modes for
+ * opening files (eg: "view" vs "edit", etc). Unless you have a need
+ * for this functionality, you should use "".
*
- * Since: 2.26
- */
-gboolean
-g_application_quit_with_data (GApplication *application,
- GVariant *platform_data)
+ * The application must be registered before calling this function and
+ * it must have the %G_APPLICATION_FLAGS_CAN_OPEN flag set. The open()
+ * virtual function should also be implemented in order for anything
+ * meaningful to happen.
+ *
+ * Since: 2.28
+ **/
+void
+g_application_open (GApplication *application,
+ GFile **files,
+ gint n_files,
+ const gchar *hint)
{
- gboolean retval = FALSE;
-
- g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
- g_return_val_if_fail (platform_data == NULL
- || g_variant_is_of_type (platform_data, G_VARIANT_TYPE ("a{sv}")), FALSE);
-
- if (platform_data == NULL)
- platform_data = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
- else
- g_variant_ref (platform_data);
+ g_return_if_fail (G_IS_APPLICATION (application));
+ g_return_if_fail (application->priv->flags &
+ G_APPLICATION_FLAGS_HANDLES_OPEN);
+ g_return_if_fail (application->priv->is_registered);
if (application->priv->is_remote)
- {
- _g_application_platform_remote_quit (application, platform_data);
- retval = TRUE;
- }
- else
- g_signal_emit (application, application_signals[QUIT_WITH_DATA], 0, platform_data, &retval);
+ g_application_impl_open (application->priv->impl,
+ files, n_files, hint,
+ get_platform_data (application));
- g_variant_unref (platform_data);
-
- return retval;
+ else
+ g_signal_emit (application, g_application_signals[SIGNAL_OPEN],
+ 0, files, n_files, hint);
}
+/* Run {{{1 */
/**
- * g_application_get_instance:
+ * g_application_run:
+ * @application: a #GApplication
+ * @argc: the argc from main()
+ * @argv: the argv from main()
+ * @returns: the exit status
*
- * In the normal case where there is exactly one #GApplication instance
- * in this process, return that instance. If there are multiple, the
- * first one created will be returned. Otherwise, return %NULL.
+ * Runs the application.
*
- * Returns: (transfer none): The primary instance of #GApplication,
- * or %NULL if none is set
+ * This function is intended to be run from main() and its return value
+ * is intended to be returned by main().
*
- * Since: 2.26
- */
-GApplication *
-g_application_get_instance (void)
-{
- return primary_application;
-}
-
-/**
- * g_application_get_id:
- * @application: a #GApplication
+ * First, the handle_command_line() virtual function is invoked. This
+ * function always runs on the local instance. If that function returns
+ * %FALSE then the application is registered and the command_line()
+ * virtual function is invoked in the primary instance (which may or may
+ * not be this instance).
*
- * Retrieves the platform-specific identifier for the #GApplication.
+ * If the application has the %G_APPLICATION_FLAGS_REMOTE_COMMAND_LINE
+ * flag set then the default implementation of handle_command_line()
+ * always returns %FALSE immediately, resulting in the commandline
+ * always being handled in the primary instance.
*
- * Return value: The platform-specific identifier. The returned string
- * is owned by the #GApplication instance and it should never be
- * modified or freed
+ * Otherwise, the default implementation of handle_command_line() tries
+ * to do a couple of things that are probably reasoanble for most
+ * applications. First, g_application_register() is called to attempt
+ * to register the application. If that works, then the command line
+ * arguments are inspected. If no commandline arguments are given, then
+ * g_application_activate() is called. If commandline arguments are
+ * given and the %G_APPLICATION_FLAGS_CAN_OPEN flags is set then they
+ * are assumed to be filenames and g_application_open() is called.
*
- * Since: 2.26
- */
-G_CONST_RETURN gchar *
-g_application_get_id (GApplication *application)
+ * If you are interested in doing more complicated local handling of the
+ * commandline then you should override handle_command_line().
+ *
+ * If, after the above is done, the use count of the application is zero
+ * then the exit status is returned immediately. If the use count is
+ * non-zero then the mainloop is run until the use count falls to zero,
+ * at which point 0 is returned.
+ *
+ * Since: 2.28
+ **/
+int
+g_application_run (GApplication *application,
+ int argc,
+ char **argv)
{
- g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
+ g_return_val_if_fail (G_IS_APPLICATION (application), 1);
+ g_return_val_if_fail (argc == 0 || argv != NULL, 1);
- return application->priv->appid;
+ return g_application_run_with_arguments (application,
+ g_variant_new_bytestring_array ((const gchar **) argv, argc));
}
/**
- * g_application_is_remote:
+ * g_application_run_with_arguments:
* @application: a #GApplication
+ * @arguments: a bytestring array #GVariant
+ * @returns: the exit status
*
- * Returns whether the object represents a proxy for a remote application.
+ * This is a bindings-friendly version of g_application_run().
*
- * Returns: %TRUE if this object represents a proxy for a remote application.
- */
-gboolean
-g_application_is_remote (GApplication *application)
+ * This function will consume @arguments if it is floating.
+ **/
+int
+g_application_run_with_arguments (GApplication *application,
+ GVariant *arguments)
{
- g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
+ int status;
- return application->priv->is_remote;
-}
-
-static void
-g_application_init (GApplication *app)
-{
- app->priv = G_TYPE_INSTANCE_GET_PRIVATE (app,
- G_TYPE_APPLICATION,
- GApplicationPrivate);
-
- app->priv->actions = g_hash_table_new_full (g_str_hash, g_str_equal,
- NULL,
- g_application_action_free);
- app->priv->default_quit = TRUE;
- app->priv->do_register = TRUE;
- app->priv->is_remote = TRUE;
- app->priv->platform_data = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
-}
+ g_return_val_if_fail (G_IS_APPLICATION (application), 1);
+ g_return_val_if_fail (G_IS_APPLICATION (application), 1);
-static void
-g_application_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GApplication *app = G_APPLICATION (object);
+ g_variant_ref_sink (arguments);
- switch (prop_id)
+ if (g_get_prgname () == NULL && g_variant_n_children (arguments))
{
- case PROP_APPLICATION_ID:
- g_value_set_string (value, g_application_get_id (app));
- break;
+ const gchar *argv0;
+ gchar *prgname;
- case PROP_DEFAULT_QUIT:
- g_value_set_boolean (value, app->priv->default_quit);
- break;
-
- case PROP_IS_REMOTE:
- g_value_set_boolean (value, g_application_is_remote (app));
- break;
-
- case PROP_REGISTER:
- g_value_set_boolean (value, app->priv->do_register);
- break;
-
- case PROP_ARGV:
- g_value_set_variant (value, app->priv->argv);
- break;
-
- case PROP_PLATFORM_DATA:
- g_value_set_variant (value, app->priv->platform_data);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ g_variant_get_child (arguments, 0, "^&ay", &argv0);
+ prgname = g_path_get_basename (argv0);
+ g_set_prgname (prgname);
+ g_free (prgname);
}
-}
-static void
-g_application_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GApplication *app = G_APPLICATION (object);
-
- switch (prop_id)
+ if (!G_APPLICATION_GET_CLASS (application)
+ ->local_command_line (application, &arguments, &status))
{
- case PROP_APPLICATION_ID:
- g_return_if_fail (_g_application_validate_id (g_value_get_string (value)));
- app->priv->appid = g_value_dup_string (value);
- break;
-
- case PROP_DEFAULT_QUIT:
- app->priv->default_quit = g_value_get_boolean (value);
- break;
-
- case PROP_REGISTER:
- app->priv->do_register = g_value_get_boolean (value);
- /* If we're not registering, the default_quit no longer applies */
- if (!app->priv->do_register)
- app->priv->default_quit = FALSE;
- break;
-
- case PROP_ARGV:
- app->priv->argv = g_value_dup_variant (value);
- break;
-
- case PROP_PLATFORM_DATA:
- {
- GVariant *platform_data = g_value_get_variant (value);
- if (app->priv->platform_data)
- g_variant_unref (app->priv->platform_data);
- app->priv->platform_data = g_variant_ref_sink (append_cwd_to_platform_data (platform_data));
- }
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ g_assert_not_reached ();
}
-}
-static GObject*
-g_application_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_params)
-{
- GApplication *app;
- GObject *object;
- const char *appid = NULL;
- guint i;
+ g_variant_unref (arguments);
- for (i = 0; i < n_construct_properties; i++)
+ if (application->priv->use_count ||
+ application->priv->flags & G_APPLICATION_FLAGS_IS_SERVICE)
{
- GObjectConstructParam *param = &construct_params[i];
- if (strcmp (param->pspec->name, "application-id") == 0)
- appid = g_value_get_string (param->value);
- }
-
- g_return_val_if_fail (appid != NULL, NULL);
+ if (!application->priv->use_count)
+ application->priv->inactivity_timeout_id =
+ g_timeout_add (10000, inactivity_timeout_expired, application);
- app = application_for_appid (appid);
- if (app != NULL)
- return g_object_ref (app);
- object = (* G_OBJECT_CLASS (g_application_parent_class)->constructor) (type,
- n_construct_properties,
- construct_params);
- app = G_APPLICATION (object);
+ G_APPLICATION_GET_CLASS (application)
+ ->run_mainloop (application);
+ status = 0;
+ }
- if (primary_application == NULL)
- primary_application = app;
- g_hash_table_insert (instances_for_appid, g_strdup (appid), app);
+ if (application->priv->impl)
+ g_application_impl_flush (application->priv->impl);
- return object;
+ return status;
}
-static void
-g_application_finalize (GObject *object)
-{
- GApplication *app = G_APPLICATION (object);
-
- g_free (app->priv->appid);
- if (app->priv->actions)
- g_hash_table_unref (app->priv->actions);
- if (app->priv->actions_changed_id)
- g_source_remove (app->priv->actions_changed_id);
- if (app->priv->mainloop)
- g_main_loop_unref (app->priv->mainloop);
-
-#ifdef G_OS_UNIX
- g_free (app->priv->dbus_path);
- if (app->priv->session_bus)
- g_object_unref (app->priv->session_bus);
-#endif
-
- G_OBJECT_CLASS (g_application_parent_class)->finalize (object);
-}
-
-static void
-g_application_class_init (GApplicationClass *klass)
-{
- GObjectClass *gobject_class G_GNUC_UNUSED = G_OBJECT_CLASS (klass);
-
- g_type_class_add_private (klass, sizeof (GApplicationPrivate));
-
- gobject_class->constructor = g_application_constructor;
- gobject_class->set_property = g_application_set_property;
- gobject_class->get_property = g_application_get_property;
-
- gobject_class->finalize = g_application_finalize;
-
- klass->run = g_application_default_run;
- klass->quit_with_data = g_application_default_quit_with_data;
-
- /**
- * GApplication::quit-with-data:
- * @application: the object on which the signal is emitted
- * @platform_data: Platform-specific data, or %NULL
- *
- * This signal is emitted when the Quit action is invoked on the
- * application.
- *
- * The default handler for this signal exits the mainloop of the
- * application.
- *
- * Returns: %TRUE if the signal has been handled, %FALSE to continue
- * signal emission
- */
- application_signals[QUIT_WITH_DATA] =
- g_signal_new (g_intern_static_string ("quit-with-data"),
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GApplicationClass, quit_with_data),
- g_signal_accumulator_true_handled, NULL,
- _gio_marshal_BOOLEAN__VARIANT,
- G_TYPE_BOOLEAN, 1,
- G_TYPE_VARIANT);
-
- /**
- * GApplication::action-with-data:
- * @application: the object on which the signal is emitted
- * @name: The name of the activated action
- * @platform_data: Platform-specific data, or %NULL
- *
- * This signal is emitted when an action is activated. The action name
- * is passed as the first argument, but also as signal detail, so it
- * is possible to connect to this signal for individual actions.
- *
- * The signal is never emitted for disabled actions.
- */
- application_signals[ACTION_WITH_DATA] =
- g_signal_new (g_intern_static_string ("action-with-data"),
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED,
- G_STRUCT_OFFSET (GApplicationClass, action_with_data),
- NULL, NULL,
- _gio_marshal_VOID__STRING_VARIANT,
- G_TYPE_NONE, 2,
- G_TYPE_STRING,
- G_TYPE_VARIANT);
-
- /**
- * GApplication::prepare-activation:
- * @application: the object on which the signal is emitted
- * @arguments: A #GVariant with the signature "aay"
- * @platform_data: A #GVariant with the signature "a{sv}", or %NULL
- *
- * This signal is emitted when a non-primary process for a given
- * application is invoked while your application is running; for
- * example, when a file browser launches your program to open a
- * file. The raw operating system arguments are passed in the
- * @arguments variant. Additional platform-dependent data is
- * stored in @platform_data.
- */
- application_signals[PREPARE_ACTIVATION] =
- g_signal_new (g_intern_static_string ("prepare-activation"),
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GApplicationClass, prepare_activation),
- NULL, NULL,
- _gio_marshal_VOID__VARIANT_VARIANT,
- G_TYPE_NONE, 2,
- G_TYPE_VARIANT,
- G_TYPE_VARIANT);
-
- /**
- * GApplication:application-id:
- *
- * The unique identifier for this application. See the documentation for
- * #GApplication for more information about this property.
- *
- */
- g_object_class_install_property (gobject_class,
- PROP_APPLICATION_ID,
- g_param_spec_string ("application-id",
- P_("Application ID"),
- P_("Identifier for this application"),
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * GApplication:argv:
- *
- * The argument vector given to this application. It must be a #GVariant
- * with a type signature "aay".
- *
- */
- g_object_class_install_property (gobject_class,
- PROP_ARGV,
- g_param_spec_variant ("argv",
- P_("Argument vector"),
- P_("System argument vector with type signature aay"),
- G_VARIANT_TYPE ("aay"),
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * GApplication:platform-data:
- *
- * Platform-specific data retrieved from the operating system
- * environment. It must be a #GVariant with type signature "a{sv}".
- *
- */
- g_object_class_install_property (gobject_class,
- PROP_PLATFORM_DATA,
- g_param_spec_variant ("platform-data",
- P_("Platform data"),
- P_("Environmental data, must have type signature a{sv}"),
- G_VARIANT_TYPE ("a{sv}"),
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * GApplication:default-quit:
- *
- * By default, if the GApplication:register property is %TRUE, and a
- * different process is running this application, the process will
- * be exited. Set this property to %FALSE to allow custom
- * interaction with the remote process.
- *
- */
- g_object_class_install_property (gobject_class,
- PROP_DEFAULT_QUIT,
- g_param_spec_boolean ("default-quit",
- P_("Default Quit"),
- P_("Exit the process by default"),
- TRUE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
-
- /**
- * GApplication:is-remote:
- *
- * This property is %TRUE if this application instance represents a proxy
- * to the instance of this application in another process.
- *
- */
- g_object_class_install_property (gobject_class,
- PROP_IS_REMOTE,
- g_param_spec_boolean ("is-remote",
- P_("Is Remote"),
- P_("Whether this application is a proxy for another process"),
- TRUE,
- G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
-
- /**
- * GApplication:register:
- *
- * If this property is %FALSE, the application construction will not attempt
- * to ensure process uniqueness, and the application is guaranteed to be in the
- * remote state. See GApplication:is-remote.
- */
- g_object_class_install_property (gobject_class,
- PROP_REGISTER,
- g_param_spec_boolean ("register",
- P_("Register"),
- P_("If false, do not "),
- TRUE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-}
+/* Epilogue {{{1 */
+/* vim:set foldmethod=marker: */
diff --git a/gio/gapplication.h b/gio/gapplication.h
index 20cc4ea..4e5dc20 100644
--- a/gio/gapplication.h
+++ b/gio/gapplication.h
@@ -1,6 +1,5 @@
-/* GIO - GLib Input, Output and Streaming Library
- *
- * Copyright © 2010 Red Hat, Inc
+/*
+ * Copyright © 2010 Codethink Limited
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
@@ -17,8 +16,7 @@
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
- * Authors: Colin Walters <walters verbum org>
- * Emmanuele Bassi <ebassi linux intel com>
+ * Authors: Ryan Lortie <desrt desrt ca>
*/
#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
@@ -28,21 +26,22 @@
#ifndef __G_APPLICATION_H__
#define __G_APPLICATION_H__
-#include <glib-object.h>
#include <gio/giotypes.h>
G_BEGIN_DECLS
-#define G_TYPE_APPLICATION (g_application_get_type ())
-#define G_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_APPLICATION, GApplication))
-#define G_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), G_TYPE_APPLICATION, GApplicationClass))
-#define G_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_APPLICATION))
-#define G_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), G_TYPE_APPLICATION))
-#define G_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G_TYPE_APPLICATION, GApplicationClass))
+#define G_TYPE_APPLICATION (g_application_get_type ())
+#define G_APPLICATION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
+ G_TYPE_APPLICATION, GApplication))
+#define G_APPLICATION_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
+ G_TYPE_APPLICATION, GApplicationClass))
+#define G_IS_APPLICATION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), G_TYPE_APPLICATION))
+#define G_IS_APPLICATION_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_APPLICATION))
+#define G_APPLICATION_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \
+ G_TYPE_APPLICATION, GApplicationClass))
-typedef struct _GApplication GApplication;
-typedef struct _GApplicationPrivate GApplicationPrivate;
-typedef struct _GApplicationClass GApplicationClass;
+typedef struct _GApplicationPrivate GApplicationPrivate;
+typedef struct _GApplicationClass GApplicationClass;
/**
* GApplication:
@@ -62,13 +61,19 @@ struct _GApplication
/**
* GApplicationClass:
- * @action_with_data: class handler for the #GApplication::action-with-data signal
- * @quit_with_data: class handler for the #GApplication::quit-with-data signal
- * @prepare_activation: class handler for the #GApplication::prepare-activation signal
- * @run: virtual function, called by g_application_run()
- *
- * The <structname>GApplicationClass</structname> structure contains
- * private data only
+ * @startup: invoked on the primary instance immediately after registration
+ * @activate: invoked on the primary instance when an activation occurs
+ * @open: invoked on the primary instance when there are files to open
+ * @local_command_line: invoked (locally) when the process has been invoked via commandline execution. The
+ * virtual function has the chance to inspect (and possibly replace) the list of command line arguments. See
+ * g_application_run() for more information.
+ * @before_emit: invoked on the primary instance before 'activate', 'open' or any action invocation
+ * @after_emit: invoked on the primary instance after 'activate', 'open' or any action invocation
+ * @add_platform_data: invoked (locally) to add 'platform data' to be sent to the primary instance when
+ * activating, opening or invoking actions
+ * @quit_mainloop: invoked on the primary instance when the use count of the application drops to zero (and
+ * after any inactivity timeout, if requested)
+ * @run_mainloop: invoked on the primary instance from g_application_run() if the use-count is non-zero
*
* Since: 2.26
*/
@@ -79,70 +84,78 @@ struct _GApplicationClass
/*< public >*/
/* signals */
- void (* action_with_data) (GApplication *application,
- const gchar *action_name,
- GVariant *platform_data);
- gboolean (* quit_with_data) (GApplication *application,
- GVariant *platform_data);
- void (* prepare_activation) (GApplication *application,
- GVariant *arguments,
- GVariant *platform_data);
+ void (* startup) (GApplication *application);
+
+ void (* activate) (GApplication *application);
+
+ void (* open) (GApplication *application,
+ GFile **files,
+ gint n_files,
+ const gchar *hint);
+
+ gpointer _reserved_1;
/* vfuncs */
- void (* run) (GApplication *application);
+ gboolean (* local_command_line) (GApplication *application,
+ GVariant **arguments,
+ int *exit_status);
+
+ gpointer _reserved_2;
+
+ void (* before_emit) (GApplication *application,
+ GVariant *platform_data);
+ void (* after_emit) (GApplication *application,
+ GVariant *platform_data);
+ void (* add_platform_data) (GApplication *application,
+ GVariantBuilder *builder);
+ void (* quit_mainloop) (GApplication *application);
+ void (* run_mainloop) (GApplication *application);
/*< private >*/
- /* Padding for future expansion */
- void (*_g_reserved1) (void);
- void (*_g_reserved2) (void);
- void (*_g_reserved3) (void);
- void (*_g_reserved4) (void);
- void (*_g_reserved5) (void);
- void (*_g_reserved6) (void);
+ gpointer padding[12];
};
-GType g_application_get_type (void) G_GNUC_CONST;
-
-GApplication * g_application_new (const gchar *appid,
- int argc,
- char **argv);
-
-GApplication * g_application_try_new (const gchar *appid,
- int argc,
- char **argv,
- GError **error);
-
-GApplication * g_application_unregistered_try_new (const gchar *appid,
- int argc,
- char **argv,
- GError **error);
-
-gboolean g_application_register (GApplication *application);
-
-GApplication * g_application_get_instance (void);
-G_CONST_RETURN gchar * g_application_get_id (GApplication *application);
-
-void g_application_add_action (GApplication *application,
- const gchar *name,
- const gchar *description);
-void g_application_remove_action (GApplication *application,
- const gchar *name);
-gchar ** g_application_list_actions (GApplication *application);
-void g_application_set_action_enabled (GApplication *application,
- const gchar *name,
- gboolean enabled);
-gboolean g_application_get_action_enabled (GApplication *application,
- const gchar *name);
-G_CONST_RETURN gchar * g_application_get_action_description (GApplication *application,
- const gchar *name);
-void g_application_invoke_action (GApplication *application,
- const gchar *name,
- GVariant *platform_data);
-
-void g_application_run (GApplication *application);
-gboolean g_application_quit_with_data (GApplication *application,
- GVariant *platform_data);
-
-gboolean g_application_is_remote (GApplication *application);
+
+GType g_application_get_type (void) G_GNUC_CONST;
+
+gboolean g_application_id_is_valid (const gchar *application_id);
+
+GApplication * g_application_new (const gchar *application_id,
+ GApplicationFlags flags);
+
+const gchar * g_application_get_application_id (GApplication *application);
+void g_application_set_application_id (GApplication *application,
+ const gchar *application_id);
+
+guint g_application_get_inactivity_timeout (GApplication *application);
+void g_application_set_inactivity_timeout (GApplication *application,
+ guint inactivity_timeout);
+
+GApplicationFlags g_application_get_flags (GApplication *application);
+void g_application_set_flags (GApplication *application,
+ GApplicationFlags flags);
+
+gboolean g_application_get_is_registered (GApplication *application);
+gboolean g_application_get_is_remote (GApplication *application);
+
+gboolean g_application_register (GApplication *application,
+ GCancellable *cancellable,
+ GError **error);
+
+void g_application_hold (GApplication *application);
+void g_application_release (GApplication *application);
+
+void g_application_activate (GApplication *application);
+
+void g_application_open (GApplication *application,
+ GFile **file,
+ gint n_files,
+ const gchar *hint);
+
+int g_application_run (GApplication *application,
+ int argc,
+ char **argv);
+int g_application_run_with_arguments (GApplication *application,
+ GVariant *arguments);
G_END_DECLS
diff --git a/gio/gapplicationimpl-dbus-interface.c b/gio/gapplicationimpl-dbus-interface.c
new file mode 100644
index 0000000..022fdf7
--- /dev/null
+++ b/gio/gapplicationimpl-dbus-interface.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright © 2010 Codethink Limited
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the licence, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Ryan Lortie <desrt desrt ca>
+ */
+
+static const GDBusArgInfo platform_data_arg = { -1, (gchar *) "platform_data", (gchar *) "a{sv}" };
+
+static const GDBusArgInfo open_uris_arg = { -1, (gchar *) "uris", (gchar *) "as" };
+static const GDBusArgInfo open_hint_arg = { -1, (gchar *) "hint", (gchar *) "s" };
+
+static const GDBusArgInfo invoke_action_name_arg = { -1, (gchar *) "name", (gchar *) "s" };
+static const GDBusArgInfo invoke_action_args_arg = { -1, (gchar *) "args", (gchar *) "v" };
+
+static const GDBusArgInfo cmdline_path_arg = { -1, (gchar *) "path", (gchar *) "o" };
+static const GDBusArgInfo cmdline_arguments_arg = { -1, (gchar *) "arguments", (gchar *) "aay" };
+static const GDBusArgInfo cmdline_exit_status_arg = { -1, (gchar *) "exit_status", (gchar *) "i" };
+
+static const GDBusArgInfo *activate_in[] = { &platform_data_arg, NULL };
+static const GDBusArgInfo *activate_out[] = { NULL };
+
+static const GDBusArgInfo *open_in[] = { &open_uris_arg, &open_hint_arg, &platform_data_arg, NULL };
+static const GDBusArgInfo *open_out[] = { NULL };
+
+static const GDBusMethodInfo activate_method = {
+ -1, (gchar *) "Activate",
+ (GDBusArgInfo **) activate_in,
+ (GDBusArgInfo **) activate_out
+};
+
+static const GDBusMethodInfo open_method = {
+ -1, (gchar *) "Open",
+ (GDBusArgInfo **) open_in,
+ (GDBusArgInfo **) open_out
+};
+
+static const GDBusMethodInfo *application_methods[] = {
+ &activate_method, &open_method, NULL
+};
+
+const GDBusInterfaceInfo org_gtk_Application = {
+ -1, (gchar *) "org.gtk.Application",
+ (GDBusMethodInfo **) application_methods
+};
diff --git a/gio/gapplicationimpl-dbus.c b/gio/gapplicationimpl-dbus.c
new file mode 100644
index 0000000..c271f37
--- /dev/null
+++ b/gio/gapplicationimpl-dbus.c
@@ -0,0 +1,304 @@
+/*
+ * Copyright © 2010 Codethink Limited
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Ryan Lortie <desrt desrt ca>
+ */
+
+#include "gapplicationimpl.h"
+
+#include "gapplication.h"
+#include "gfile.h"
+#include "gdbusconnection.h"
+#include "gdbusintrospection.h"
+#include "gdbuserror.h"
+
+#include <string.h>
+
+
+#include "gapplicationimpl-dbus-interface.c"
+
+struct _GApplicationImpl
+{
+ GDBusConnection *session_bus;
+ const gchar *bus_name;
+ gchar *object_path;
+ guint object_id;
+ gpointer app;
+
+ GMainLoop *cmdline_mainloop;
+};
+
+static void
+g_application_impl_method_call (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ GApplicationImpl *impl = user_data;
+ GApplicationClass *class;
+
+ class = G_APPLICATION_GET_CLASS (impl->app);
+
+ if (strcmp (method_name, "Activate") == 0)
+ {
+ GVariant *platform_data;
+
+ g_variant_get (parameters, "(@a{sv})", &platform_data);
+ class->before_emit (impl->app, platform_data);
+ g_signal_emit_by_name (impl->app, "activate");
+ class->after_emit (impl->app, platform_data);
+ g_variant_unref (platform_data);
+ }
+
+ else if (strcmp (method_name, "Open") == 0)
+ {
+ GVariant *platform_data;
+ const gchar *hint;
+ GVariant *array;
+ GFile **files;
+ gint n, i;
+
+ g_variant_get (parameters, "(@ass a{sv})",
+ &array, &hint, &platform_data);
+
+ n = g_variant_n_children (array);
+ files = g_new (GFile *, n + 1);
+
+ for (i = 0; i < n; i++)
+ {
+ const gchar *uri;
+
+ g_variant_get_child (array, i, "&s", &uri);
+ files[i] = g_file_new_for_uri (uri);
+ }
+ g_variant_unref (array);
+ files[n] = NULL;
+
+ class->before_emit (impl->app, platform_data);
+ g_signal_emit_by_name (impl->app, "open", files, n, hint);
+ class->after_emit (impl->app, platform_data);
+
+ g_variant_unref (platform_data);
+
+ for (i = 0; i < n; i++)
+ g_object_unref (files[i]);
+ g_free (files);
+ }
+
+ else
+ g_assert_not_reached ();
+}
+
+static gchar *
+application_path_from_appid (const gchar *appid)
+{
+ gchar *appid_path, *iter;
+
+ appid_path = g_strconcat ("/", appid, NULL);
+ for (iter = appid_path; *iter; iter++)
+ {
+ if (*iter == '.')
+ *iter = '/';
+ }
+
+ return appid_path;
+}
+
+void
+g_application_impl_destroy (GApplicationImpl *impl)
+{
+ if (impl->session_bus)
+ {
+ if (impl->object_id)
+ g_dbus_connection_unregister_object (impl->session_bus,
+ impl->object_id);
+
+ g_object_unref (impl->session_bus);
+ g_free (impl->object_path);
+ }
+ else
+ {
+ g_assert (impl->object_path == NULL);
+ g_assert (impl->object_id == 0);
+ }
+
+ g_slice_free (GApplicationImpl, impl);
+}
+
+GApplicationImpl *
+g_application_impl_register (GApplication *application,
+ const gchar *appid,
+ GApplicationFlags flags,
+ gboolean *is_remote,
+ GCancellable *cancellable,
+ GError **error)
+{
+ const static GDBusInterfaceVTable vtable = {
+ g_application_impl_method_call
+ };
+ GApplicationImpl *impl;
+ GVariant *reply;
+ guint32 rval;
+
+ impl = g_slice_new (GApplicationImpl);
+
+ impl->app = application;
+ impl->bus_name = appid;
+
+ impl->session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION,
+ cancellable, error);
+
+ if (impl->session_bus == NULL)
+ {
+ g_slice_free (GApplicationImpl, impl);
+ return NULL;
+ }
+
+ impl->object_path = application_path_from_appid (appid);
+
+ if (flags & G_APPLICATION_FLAGS_IS_LAUNCHER)
+ {
+ impl->object_id = 0;
+ *is_remote = TRUE;
+
+ return impl;
+ }
+
+ impl->object_id = g_dbus_connection_register_object (impl->session_bus,
+ impl->object_path,
+ (GDBusInterfaceInfo *)
+ &org_gtk_Application,
+ &vtable,
+ impl, NULL,
+ error);
+
+ if (impl->object_id == 0)
+ {
+ g_object_unref (impl->session_bus);
+ g_free (impl->object_path);
+ impl->session_bus = NULL;
+ impl->object_path = NULL;
+
+ g_slice_free (GApplicationImpl, impl);
+ return NULL;
+ }
+
+ reply = g_dbus_connection_call_sync (impl->session_bus,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ "RequestName",
+ g_variant_new ("(su)",
+ /* DBUS_NAME_FLAG_DO_NOT_QUEUE: 0x4 */
+ impl->bus_name, 0x4),
+ G_VARIANT_TYPE ("(u)"),
+ 0, -1, cancellable, error);
+
+ if (reply == NULL)
+ {
+ g_dbus_connection_unregister_object (impl->session_bus,
+ impl->object_id);
+ impl->object_id = 0;
+
+ g_object_unref (impl->session_bus);
+ g_free (impl->object_path);
+ impl->session_bus = NULL;
+ impl->object_path = NULL;
+
+ g_slice_free (GApplicationImpl, impl);
+ return NULL;
+ }
+
+ g_variant_get (reply, "(u)", &rval);
+ g_variant_unref (reply);
+
+ /* DBUS_REQUEST_NAME_REPLY_EXISTS: 3 */
+ if ((*is_remote = (rval == 3)))
+ {
+ g_dbus_connection_unregister_object (impl->session_bus,
+ impl->object_id);
+ impl->object_id = 0;
+
+ if (flags & G_APPLICATION_FLAGS_IS_SERVICE)
+ {
+ g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
+ "Unable to acquire bus name `%s'", appid);
+ g_object_unref (impl->session_bus);
+ g_free (impl->object_path);
+
+ g_slice_free (GApplicationImpl, impl);
+ impl = NULL;
+ }
+ }
+
+ return impl;
+}
+
+void
+g_application_impl_activate (GApplicationImpl *impl,
+ GVariant *platform_data)
+{
+ g_dbus_connection_call (impl->session_bus,
+ impl->bus_name,
+ impl->object_path,
+ "org.gtk.Application",
+ "Activate",
+ g_variant_new ("(@a{sv})", platform_data),
+ NULL, 0, -1, NULL, NULL, NULL);
+}
+
+void
+g_application_impl_open (GApplicationImpl *impl,
+ GFile **files,
+ gint n_files,
+ const gchar *hint,
+ GVariant *platform_data)
+{
+ GVariantBuilder builder;
+ gint i;
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("(assa{sv})"));
+ g_variant_builder_open (&builder, G_VARIANT_TYPE_STRING_ARRAY);
+ for (i = 0; i < n_files; i++)
+ {
+ gchar *uri = g_file_get_uri (files[i]);
+ g_variant_builder_add (&builder, "s", uri);
+ g_free (uri);
+ }
+ g_variant_builder_close (&builder);
+ g_variant_builder_add (&builder, "s", hint);
+ g_variant_builder_add_value (&builder, platform_data);
+
+ g_dbus_connection_call (impl->session_bus,
+ impl->bus_name,
+ impl->object_path,
+ "org.gtk.Application",
+ "Open",
+ g_variant_builder_end (&builder),
+ NULL, 0, -1, NULL, NULL, NULL);
+}
+
+void
+g_application_impl_flush (GApplicationImpl *impl)
+{
+ g_dbus_connection_flush_sync (impl->session_bus, NULL, NULL);
+}
diff --git a/gio/gapplicationimpl.h b/gio/gapplicationimpl.h
new file mode 100644
index 0000000..1bc5ec9
--- /dev/null
+++ b/gio/gapplicationimpl.h
@@ -0,0 +1,28 @@
+#include "giotypes.h"
+
+typedef struct _GApplicationImpl GApplicationImpl;
+
+G_GNUC_INTERNAL
+void g_application_impl_destroy (GApplicationImpl *impl);
+
+G_GNUC_INTERNAL
+GApplicationImpl * g_application_impl_register (GApplication *application,
+ const gchar *appid,
+ GApplicationFlags flags,
+ gboolean *is_remote,
+ GCancellable *cancellable,
+ GError **error);
+
+G_GNUC_INTERNAL
+void g_application_impl_activate (GApplicationImpl *impl,
+ GVariant *platform_data);
+
+G_GNUC_INTERNAL
+void g_application_impl_open (GApplicationImpl *impl,
+ GFile **files,
+ gint n_files,
+ const gchar *hint,
+ GVariant *platform_data);
+
+G_GNUC_INTERNAL
+void g_application_impl_flush (GApplicationImpl *impl);
diff --git a/gio/gio-marshal.list b/gio/gio-marshal.list
index e85aefc..8b7ce0a 100644
--- a/gio/gio-marshal.list
+++ b/gio/gio-marshal.list
@@ -21,4 +21,5 @@ VOID:STRING,STRING,VARIANT
VOID:STRING
VOID:STRING,STRING
VOID:STRING,BOOLEAN
-BOOL:OBJECT
+VOID:POINTER,INT,STRING
+BOOLEAN:OBJECT
diff --git a/gio/gio.symbols b/gio/gio.symbols
index 15212ec..850d0e7 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -27,22 +27,24 @@ g_vfs_get_local
#if IN_HEADER(__G_APPLICATION_H__)
#if IN_FILE(__G_APPLICATION_C__)
g_application_get_type G_GNUC_CONST
+g_application_activate
+g_application_flags_get_type
+g_application_get_application_id
+g_application_get_flags
+g_application_get_inactivity_timeout
+g_application_get_is_registered
+g_application_get_is_remote
+g_application_hold
+g_application_id_is_valid
g_application_new
-g_application_get_instance
-g_application_get_id
-g_application_set_action_enabled
-g_application_get_action_enabled
-g_application_get_action_description
-g_application_add_action
-g_application_remove_action
-g_application_invoke_action
-g_application_list_actions
-g_application_run
+g_application_open
g_application_register
-g_application_try_new
-g_application_unregistered_try_new
-g_application_quit_with_data
-g_application_is_remote
+g_application_release
+g_application_run
+g_application_run_with_arguments
+g_application_set_application_id
+g_application_set_flags
+g_application_set_inactivity_timeout
#endif
#endif
diff --git a/gio/gioenums.h b/gio/gioenums.h
index 10eedfd..5ebd7f0 100644
--- a/gio/gioenums.h
+++ b/gio/gioenums.h
@@ -1216,6 +1216,24 @@ typedef enum
G_DBUS_MESSAGE_BYTE_ORDER_LITTLE_ENDIAN = 'l'
} GDBusMessageByteOrder;
+/**
+ * GApplicationFlags:
+ * @G_APPLICATION_FLAGS_NONE: Default
+ * @G_APPLICATION_FLAGS_HANDLE_OPEN: This application handles opening files.
+ *
+ * Flags used to define the behaviour of a #GApplication.
+ *
+ * Since: 2.26
+ **/
+typedef enum
+{
+ G_APPLICATION_FLAGS_NONE,
+ G_APPLICATION_FLAGS_IS_SERVICE = (1 << 0),
+ G_APPLICATION_FLAGS_IS_LAUNCHER = (1 << 1),
+
+ G_APPLICATION_FLAGS_HANDLES_OPEN = (1 << 2)
+} GApplicationFlags;
+
G_END_DECLS
#endif /* __GIO_ENUMS_H__ */
diff --git a/gio/giotypes.h b/gio/giotypes.h
index ecd1dc0..ffd38ef 100644
--- a/gio/giotypes.h
+++ b/gio/giotypes.h
@@ -51,6 +51,8 @@ typedef struct _GSimpleActionGroup GSimpleActionGroup;
typedef struct _GActionGroup GActionGroup;
typedef struct _GSimpleAction GSimpleAction;
typedef struct _GAction GAction;
+typedef struct _GApplication GApplication;
+typedef struct _GApplicationCommandLine GApplicationCommandLine;
typedef struct _GSettingsBackend GSettingsBackend;
typedef struct _GSettings GSettings;
typedef struct _GPermission GPermission;
diff --git a/gio/tests/.gitignore b/gio/tests/.gitignore
index f080fbc..15dc9fe 100644
--- a/gio/tests/.gitignore
+++ b/gio/tests/.gitignore
@@ -1,7 +1,6 @@
actions
appinfo
appinfo-test
-application
async-close-output-stream
buffered-input-stream
buffered-output-stream
@@ -65,8 +64,6 @@ sleepy-stream
socket-client
socket-server
srvtarget
-testapp
-testapps
test.mo
unix-fd
unix-streams
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index 4623db9..d1ff433 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -59,8 +59,6 @@ TEST_PROGS += \
gdbus-exit-on-close \
gdbus-non-socket \
gdbus-bz627724 \
- application \
- testapps \
appinfo \
contenttype \
file \
@@ -84,7 +82,6 @@ SAMPLE_PROGS = \
gdbus-example-peer \
gdbus-example-proxy-subclass \
gdbus-connection-flush-helper \
- testapp \
appinfo-test \
proxy \
$(NULL)
@@ -291,21 +288,12 @@ gdbus_example_export_LDADD = $(progs_ldadd)
gdbus_connection_flush_helper_SOURCES = gdbus-connection-flush-helper.c
gdbus_connection_flush_helper_LDADD = $(progs_ldadd)
-application_SOURCES = application.c gdbus-sessionbus.c gdbus-sessionbus.h
-application_LDADD = $(progs_ldadd)
-
appinfo_SOURCES = appinfo.c
appinfo_LDADD = $(progs_ldadd)
appinfo_test_SOURCES = appinfo-test.c
appinfo_test_LDADD = $(progs_ldadd)
-testapp_SOURCES = testapp.c
-testapp_LDADD = $(progs_ldadd)
-
-testapps_SOURCES = testapps.c gdbus-sessionbus.c gdbus-sessionbus.h
-testapps_LDADD = $(progs_ldadd)
-
contenttype_SOURCES = contenttype.c
contenttype_LDADD = $(progs_ldadd)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]