[glib/application] sdfsdf
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/application] sdfsdf
- Date: Tue, 10 Aug 2010 19:50:20 +0000 (UTC)
commit 99c64ac40e93151dfd67a1ba03c10049ddd23613
Author: Ryan Lortie <desrt desrt ca>
Date: Tue Aug 10 15:50:00 2010 -0400
sdfsdf
gio/gapplication.c | 1776 ++++++++++++++++++++-----------------------
gio/gapplication.h | 90 ++-
gio/gapplicationimpl-dbus.c | 41 +-
gio/gioenums.h | 2 +-
4 files changed, 894 insertions(+), 1015 deletions(-)
---
diff --git a/gio/gapplication.c b/gio/gapplication.c
index 2309204..ccb466a 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -1,186 +1,15 @@
-/* GIO - GLib Input, Output and Streaming Library
- *
- * Coypright © 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 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: Colin Walters <walters verbum org>
- * Emmanuele Bassi <ebassi linux intel com>
- * Ryan Lortie <desrt desrt ca>
- */
-
-#include "config.h"
-
-#include <string.h>
-#include <stdlib.h>
-
-#include <gobject/gvaluecollector.h>
-
#include "gapplication.h"
-#include "gio-marshal.h"
-#include "glibintl.h"
-
-#include "gioerror.h"
-#include "ginitable.h"
-
-#include "gdbusconnection.h"
-#include "gdbusintrospection.h"
-#include "gdbusmethodinvocation.h"
-#include "gioenumtypes.h"
+#include "string.h"
#include "gapplicationcommandline.h"
-
-/**
- * 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>
- */
-
-G_DEFINE_TYPE (GApplication, g_application, G_TYPE_OBJECT)
+#include "gioenums.h"
+#include "gioenumtypes.h"
+#include "gfile.h"
typedef struct _GApplicationImpl GApplicationImpl;
-static void g_application_impl_init (GApplicationImpl *impl,
- gpointer app);
-
-static void g_application_impl_set_id (GApplicationImpl *impl,
- const gchar *appid);
-
static gboolean g_application_impl_register (GApplicationImpl *impl,
+ const gchar *appid,
+ gpointer app,
gboolean *is_remote,
GCancellable *cancellable,
GError **error);
@@ -211,18 +40,9 @@ void g_application_command_line_setup_remote (GApplicationCommandLine *,
#ifdef G_OS_UNIX
#include "gapplicationimpl-dbus.c"
#else
-#include "gnullapplication.c"
+#include "gapplicationimpl-null.c"
#endif
-enum
-{
- PROP_0,
-
- PROP_APPLICATION_ID,
- PROP_FLAGS,
- PROP_IS_REMOTE
-};
-
typedef struct {
gchar *name;
gchar *description;
@@ -233,70 +53,353 @@ typedef struct {
struct _GApplicationPrivate
{
- gchar *appid;
+ GApplicationFlags flags;
+ gchar *id;
- GHashTable *actions; /* name -> GApplicationAction */
+ GHashTable *actions; /* string -> GApplicationAction */
GMainLoop *mainloop;
- guint is_remote : 1;
- guint registered : 1;
-
- GApplicationFlags flags;
- guint use_count;
guint inactivity_timeout;
+ guint use_count;
- guint actions_changed_id;
+ guint is_registered : 1;
+ guint is_remote : 1;
GApplicationImpl impl;
};
-static GApplication *primary_application = NULL;
-static GHashTable *instances_for_appid = NULL;
+enum
+{
+ PROP_NONE,
+ PROP_APPLICATION_ID,
+ PROP_FLAGS,
+ PROP_IS_REGISTERED,
+ PROP_IS_REMOTE
+};
-static gboolean
-_g_application_validate_id (const char *id)
+G_DEFINE_TYPE (GApplication, g_application, G_TYPE_OBJECT)
+
+static void
+g_application_real_startup (GApplication *application)
{
- gboolean allow_dot;
+}
- if (strlen (id) > 255)
- return FALSE;
+static void
+g_application_real_activate (GApplication *application)
+{
+}
+
+static void
+g_application_real_open (GApplication *application,
+ GFile **files,
+ gint n_files,
+ const gchar *hint)
+{
+ g_warning ("Your application claims to support opening files "
+ "but does not implement g_application_open().");
+}
+
+static void
+g_application_real_action (GApplication *application,
+ const gchar *action_name,
+ GVariant *parameters)
+{
+ g_warning ("Your application claims to support actions "
+ "but does not implement g_application_action().");
+}
+
+static int
+g_application_real_command_line (GApplication *application,
+ GApplicationCommandLine *command_line)
+{
+ g_warning ("Your application claims to support command line invocation "
+ "but does not implement g_application_command_line().");
+
+ return 1;
+}
- if (!g_ascii_isalpha (*id))
+static gboolean
+g_application_real_handle_command_line (GApplication *application,
+ GVariant **arguments,
+ int *exit_status)
+{
+ if (application->priv->flags & G_APPLICATION_FLAGS_CAN_COMMAND_LINE)
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 (n_args <= 1)
+ {
+ g_application_activate (application);
+ *exit_status = 0;
+ }
+
else
- return FALSE;
+ {
+ if (~application->priv->flags & G_APPLICATION_FLAGS_CAN_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, "&s", &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;
+ }
+}
+
+void
+g_application_real_emit_startup (GApplication *application)
+{
+ G_APPLICATION_GET_CLASS (application)
+ ->startup (application);
+}
+
+static void
+g_application_real_emit_activate (GApplication *application,
+ GVariant *platform_data)
+{
+ G_APPLICATION_GET_CLASS (application)
+ ->activate (application);
+}
+
+static void
+g_application_real_emit_open (GApplication *application,
+ GFile **files,
+ gint n_files,
+ const gchar *hint,
+ GVariant *platform_data)
+{
+ G_APPLICATION_GET_CLASS (application)
+ ->open (application, files, n_files, hint);
+}
+
+static void
+g_application_real_emit_action (GApplication *application,
+ const gchar *action_name,
+ GVariant *parameters,
+ GVariant *platform_data)
+{
+ G_APPLICATION_GET_CLASS (application)
+ ->action (application, action_name, parameters);
+}
+
+static GApplicationCommandLine *
+g_application_real_create_command_line (GApplication *application,
+ GVariant *arguments,
+ GVariant *platform_data)
+{
+ return g_object_new (G_TYPE_APPLICATION_COMMAND_LINE,
+ "arguments", arguments,
+ "platform-data", platform_data,
+ NULL);
+}
+
+static int
+g_application_real_emit_command_line (GApplication *application,
+ GApplicationCommandLine *command_line)
+{
+ return G_APPLICATION_GET_CLASS (application)
+ ->command_line (application, command_line);
+}
+
+void
+g_application_real_add_platform_data (GApplication *application,
+ GVariantBuilder *builder)
+{
+}
+
+void
+g_application_real_quit_mainloop (GApplication *application)
+{
+ if (application->priv->mainloop != NULL)
+ g_main_loop_quit (application->priv->mainloop);
+}
+
+void
+g_application_real_run_mainloop (GApplication *application)
+{
+ if (application->priv->mainloop == NULL)
+ application->priv->mainloop = g_main_loop_new (NULL, FALSE);
+
+ g_main_loop_run (application->priv->mainloop);
+}
+
+static void
+g_application_set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ GApplication *application = G_APPLICATION (object);
+
+ 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;
+
+ default:
+ g_assert_not_reached ();
+ }
+}
+
+static void
+g_application_get_property (GObject *object, guint prop_id,
+ GValue *value, GParamSpec *pspec)
+{
+ GApplication *application = G_APPLICATION (object);
+
+ switch (prop_id)
+ {
+ case PROP_APPLICATION_ID:
+ g_value_set_string (value,
+ g_application_get_application_id (application));
+ break;
+
+ case PROP_FLAGS:
+ g_value_set_flags (value,
+ g_application_get_flags (application));
+ break;
+
+ case PROP_IS_REGISTERED:
+ g_value_set_boolean (value,
+ g_application_get_is_registered (application));
+ break;
+
+ case PROP_IS_REMOTE:
+ g_value_set_boolean (value,
+ g_application_get_is_remote (application));
+ break;
+
+ default:
+ g_assert_not_reached ();
}
- return TRUE;
}
-static gpointer
-init_appid_statics (gpointer data)
+static void
+g_application_constructed (GObject *object)
{
- instances_for_appid = g_hash_table_new (g_str_hash, g_str_equal);
- return NULL;
+ GApplication *application = G_APPLICATION (object);
+
+ g_assert (application->priv->id != NULL);
}
-static GApplication *
-application_for_appid (const char *appid)
+static void
+g_application_finalize (GObject *object)
{
- static GOnce appid_once = G_ONCE_INIT;
+ GApplication *application = G_APPLICATION (object);
+
+ g_application_impl_destroy (&application->priv->impl);
+ g_free (application->priv->id);
+
+ if (application->priv->mainloop)
+ g_main_loop_unref (application->priv->mainloop);
- g_once (&appid_once, init_appid_statics, NULL);
+ G_OBJECT_CLASS (g_application_parent_class)
+ ->finalize (object);
+}
- return g_hash_table_lookup (instances_for_appid, appid);
+static void
+g_application_init (GApplication *application)
+{
+ application->priv = G_TYPE_INSTANCE_GET_PRIVATE (application,
+ G_TYPE_APPLICATION,
+ GApplicationPrivate);
+}
+
+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->startup = g_application_real_startup;
+ class->activate = g_application_real_activate;
+ class->open = g_application_real_open;
+ class->action = g_application_real_action;
+ class->command_line = g_application_real_command_line;
+ class->handle_command_line = g_application_real_handle_command_line;
+ class->emit_startup = g_application_real_emit_startup;
+ class->emit_activate = g_application_real_emit_activate;
+ class->emit_open = g_application_real_emit_open;
+ class->emit_action = g_application_real_emit_action;
+ class->create_command_line = g_application_real_create_command_line;
+ class->emit_command_line = g_application_real_emit_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_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_type_class_add_private (class, sizeof (GApplicationPrivate));
}
static GVariant *
-g_application_get_platform_data (GApplication *application)
+get_platform_data (GApplication *application)
{
GVariantBuilder *builder;
GVariant *result;
@@ -319,153 +422,264 @@ g_application_get_platform_data (GApplication *application)
return result;
}
-static gboolean
-timeout_handle_actions_changed (gpointer user_data)
+/**
+ * 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)
{
- GApplication *application = user_data;
+ gboolean allow_dot;
- application->priv->actions_changed_id = 0;
+ if (strlen (application_id) > 255)
+ return FALSE;
- return FALSE;
+ if (!g_ascii_isalpha (*application_id))
+ return FALSE;
+
+ application_id++;
+ allow_dot = FALSE;
+ for (; *application_id; application_id++)
+ {
+ 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 TRUE;
}
-static inline void
-queue_actions_change_notification (GApplication *application)
+/**
+ * g_application_new:
+ * @application_id: the application id
+ * @flags: the application flags
+ * @returns: a new #GApplication instance
+ *
+ * Creates a new #GApplication instance.
+ *
+ * The application id must be valid. See g_application_id_is_valid().
+ **/
+GApplication *
+g_application_new (const gchar *application_id,
+ GApplicationFlags flags)
{
- GApplicationPrivate *priv = application->priv;
+ g_return_val_if_fail (g_application_id_is_valid (application_id), NULL);
- if (priv->actions_changed_id == 0)
- priv->actions_changed_id = g_timeout_add (0, timeout_handle_actions_changed, application);
+ return g_object_new (G_TYPE_APPLICATION,
+ "application-id", application_id,
+ "flags", flags,
+ NULL);
}
-static void
-g_application_action_free (gpointer data)
+/**
+ * g_application_get_application_id:
+ * @application: a #GApplication
+ * @returns: the identifier for @application, owned by @application
+ *
+ * Gets the unique identifier for @application.
+ *
+ * Since: 2.26
+ **/
+const gchar *
+g_application_get_application_id (GApplication *application)
{
- if (G_LIKELY (data != NULL))
+ g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
+
+ return application->priv->id;
+}
+
+/**
+ * g_application_set_application_id:
+ * @application: a #GApplication
+ * @application_id: the identifier for @application
+ *
+ * Sets the unique identifier for @application.
+ *
+ * The application id can only be modified if @application has not yet
+ * been registered.
+ *
+ * The application id must be valid. See g_application_id_is_valid().
+ *
+ * Since: 2.26
+ **/
+void
+g_application_set_application_id (GApplication *application,
+ const gchar *application_id)
+{
+ g_return_if_fail (G_IS_APPLICATION (application));
+
+ if (g_strcmp0 (application->priv->id, application_id))
{
- GApplicationAction *action = data;
+ g_return_if_fail (g_application_id_is_valid (application_id));
+ g_return_if_fail (!application->priv->is_registered);
- g_free (action->name);
- g_free (action->description);
+ g_free (application->priv->id);
+ application->priv->id = g_strdup (application_id);
- g_slice_free (GApplicationAction, action);
+ g_object_notify (G_OBJECT (application), "application-id");
}
}
/**
- * 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
+ * g_application_get_flags:
+ * @application: a #GApplication
+ * @returns: the flags for @application
+ *
+ * Gets the flags for @application.
+ *
+ * See #GApplicationFlags.
*
* Since: 2.26
- */
-GApplication *
-g_application_new (const gchar *appid,
- GApplicationFlags flags)
+ **/
+GApplicationFlags
+g_application_get_flags (GApplication *application)
{
- g_type_init ();
+ g_return_val_if_fail (G_IS_APPLICATION (application), 0);
- return g_object_new (G_TYPE_APPLICATION,
- "application-id", appid,
- "flags", flags,
- NULL);
+ return application->priv->flags;
}
/**
- * 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_set_flags:
+ * @application: a #GApplication
+ * @flags: the flags for @application
*
- * This function is similar to g_application_new(), but allows for
- * more graceful fallback if the environment doesn't support the
- * basic #GApplication functionality.
+ * Sets the flags for @application.
*
- * Returns: (transfer full): An application instance
+ * The flags can only be modified if @application has not yet been
+ * registered.
+ *
+ * See #GApplicationFlags.
*
* Since: 2.26
- */
-GApplication *
-g_application_try_new (const gchar *appid)
+ **/
+void
+g_application_set_flags (GApplication *application,
+ GApplicationFlags flags)
{
- g_type_init ();
+ g_return_if_fail (G_IS_APPLICATION (application));
- /* XXX do the check for required functionality */
+ if (application->priv->flags != flags)
+ {
+ g_return_if_fail (!application->priv->is_registered);
- return g_object_new (G_TYPE_APPLICATION,
- "application-id", appid,
- NULL);
+ application->priv->flags = flags;
+
+ g_object_notify (G_OBJECT (application), "flags");
+ }
+}
+
+/**
+ * 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.26
+ **/
+gboolean
+g_application_get_is_registered (GApplication *application)
+{
+ g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
+
+ return application->priv->is_registered;
+}
+
+/**
+ * g_application_get_is_remote:
+ * @application: a #GApplication
+ * @returns: %TRUE if @application is remote
+ *
+ * Checks if @application is remote.
+ *
+ * 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.
+ *
+ * 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
+ **/
+gboolean
+g_application_get_is_remote (GApplication *application)
+{
+ g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
+ g_return_val_if_fail (application->priv->is_registered, FALSE);
+
+ return application->priv->is_remote;
}
/**
* g_application_register:
* @application: a #GApplication
+ * @cancellable: a #GCancellable, or %NULL
+ * @error: a pointer to a NULL #GError, or %NULL
+ * @returns: %TRUE if registration succeeded
*
- * 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.
+ * Attempts registration of the 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.
+ * 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.
*
- * Returns: %TRUE if registration was successful
- */
+ * If the application has already been registered then %TRUE is
+ * returned with no work performed.
+ *
+ * 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.26
+ **/
gboolean
g_application_register (GApplication *application,
GCancellable *cancellable,
GError **error)
{
- gboolean is_remote;
-
g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
- if (application->priv->registered)
- return TRUE;
+ if (!application->priv->is_registered)
+ {
+ gboolean is_remote;
- if (!g_application_impl_register (&application->priv->impl,
- &is_remote, cancellable, error))
- return FALSE;
+ if (!g_application_impl_register (&application->priv->impl,
+ application->priv->id, application,
+ &is_remote, cancellable, error))
+ return FALSE;
+
+ application->priv->is_remote = is_remote;
+ application->priv->is_registered = TRUE;
- application->priv->is_remote = is_remote;
- application->priv->registered = TRUE;
+ g_object_notify (G_OBJECT (application), "is-registered");
+
+ if (!is_remote)
+ G_APPLICATION_GET_CLASS (application)
+ ->emit_startup (application);
+ }
return TRUE;
}
@@ -473,110 +687,130 @@ g_application_register (GApplication *application,
/**
* g_application_add_action:
* @application: a #GApplication
- * @name: the action name
+ * @action_name: the action name
+ * @parameters_type: a #GVariantType, or %NULL
* @description: the action description; can be a translatable
* string
*
- * Adds an action @name to the list of exported actions of @application.
+ * Adds an action @action_name to the list of actions for @application.
+ *
+ * You can invoke an action using g_application_action().
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * If @parameters_type is %NULL then the action takes no parameters.
+ * Otherwise, @parameters_type specifies the expected type of the
+ * parameters.
*
- * You can invoke an action using g_application_invoke_action().
+ * It is customary for actions that take no parameters to show up in the
+ * user interface. The desktop shell may do this, for example. To
+ * supress this, consider using %G_VARIANT_TYPE_UNIT for
+ * @parameters_type.
*
* The newly added action is enabled by default; you can call
* g_application_set_action_enabled() to disable it.
*
+ * Note that the list of actions is maintained locally. If @application
+ * is remote then this call has no impact other than modifying the
+ * result of future calls to action-related functions on this instance.
+ *
+ * If @application is remote then g_application_action() itself does not
+ * check the local list of actions before transmitting the action to the
+ * primary instance. This means that there is no need to populate the
+ * list of actions in the case of @application being remote, but also no
+ * harm.
+ *
* Since: 2.26
*/
void
-g_application_add_action (GApplication *application,
- const gchar *name,
- const gchar *description)
+g_application_add_action (GApplication *application,
+ const gchar *action_name,
+ const GVariantType *parameters_type,
+ const gchar *description)
{
- 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);
+ g_return_if_fail (action_name != NULL && *action_name != '\0');
- priv = application->priv;
-
- g_return_if_fail (g_hash_table_lookup (priv->actions, name) == NULL);
+ g_return_if_fail (g_hash_table_lookup (application->priv->actions,
+ action_name) == NULL);
action = g_slice_new (GApplicationAction);
- action->name = g_strdup (name);
+ action->name = g_strdup (action_name);
+ if (parameters_type)
+ action->type = g_variant_type_copy (parameters_type);
+ else
+ action->type = NULL;
action->description = g_strdup (description);
action->enabled = TRUE;
- g_hash_table_insert (priv->actions, action->name, action);
- queue_actions_change_notification (application);
+ g_hash_table_insert (application->priv->actions,
+ action->name, action);
+
+ //queue_actions_change_notification (application);
}
/**
* g_application_remove_action:
* @application: a #GApplication
- * @name: the name of the action to remove
+ * @action_name: the name of the action to remove
*
- * Removes the action @name from the list of exported actions of @application.
+ * Removes the action @action_name from the list of actions for
+ * @application.
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * Note that the list of actions is maintained locally. If @application
+ * is remote then this call has no impact other than modifying the
+ * result of future calls to action-related functions on this instance.
*
* Since: 2.26
*/
void
g_application_remove_action (GApplication *application,
- const gchar *name)
+ const gchar *action_name)
{
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);
+ g_return_if_fail (action_name != NULL);
priv = application->priv;
- g_return_if_fail (g_hash_table_lookup (priv->actions, name) != NULL);
+ g_return_if_fail (g_hash_table_lookup (priv->actions, action_name) != NULL);
+
+ g_hash_table_remove (priv->actions, action_name);
- g_hash_table_remove (priv->actions, name);
- queue_actions_change_notification (application);
+ //queue_actions_change_notification (application);
}
/**
* g_application_list_actions:
* @application: a #GApplication
+ * @returns: a newly allocated, %NULL-terminated array of strings
+ * containing action names; use g_strfreev() to free it when
+ * you are done.
*
- * Retrieves the list of action names currently exported by @application.
+ * Gets a list of the actions that have been registered with
+ * @application.
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * Note that the list of actions is maintained locally, so this function
+ * will only query actions that have been registered on this 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
*
* Since: 2.26
*/
gchar **
g_application_list_actions (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);
+ retval = g_new (gchar*, g_hash_table_size (application->priv->actions) + 1);
i = 0;
- g_hash_table_iter_init (&iter, priv->actions);
+ g_hash_table_iter_init (&iter, application->priv->actions);
while (g_hash_table_iter_next (&iter, &key, NULL))
retval[i++] = g_strdup (key);
@@ -588,585 +822,131 @@ g_application_list_actions (GApplication *application)
/**
* g_application_set_action_enabled:
* @application: a #GApplication
- * @name: the name of the application
- * @enabled: whether to enable or disable the action @name
+ * @action_name: the name of an action
+ * @enabled: whether to enable or disable the action @action_name
*
- * Sets whether the action @name inside @application should be enabled
- * or disabled.
+ * Sets whether the action @action_name should be enabled or disabled.
+ * Attempting to invoke a disabled action will have no effect.
*
- * It is an error to call this function if @application is a proxy for
- * a remote application.
+ * @action_name must name an action that is supposed by the application.
*
- * Invoking a disabled action will not result in the #GApplication::action
- * signal being emitted.
+ * Note that the list of actions is maintained locally, so this function
+ * will have no effect if @application is remote, other than to modify
+ * the result of future calls to g_application_get_action_enabled() made
+ * on this instance.
*
* Since: 2.26
*/
void
g_application_set_action_enabled (GApplication *application,
- const gchar *name,
+ const gchar *action_name,
gboolean enabled)
{
GApplicationAction *action;
g_return_if_fail (G_IS_APPLICATION (application));
- g_return_if_fail (name != NULL);
- g_return_if_fail (!application->priv->is_remote);
+ g_return_if_fail (action_name != NULL);
enabled = !!enabled;
- action = g_hash_table_lookup (application->priv->actions, name);
+ action = g_hash_table_lookup (application->priv->actions, action_name);
g_return_if_fail (action != NULL);
+
if (action->enabled == enabled)
return;
action->enabled = enabled;
- queue_actions_change_notification (application);
-}
-
-
-/**
- * g_application_get_action_description:
- * @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.
- *
- * Returns: Description for the given action named @name
- *
- * Since: 2.26
- */
-G_CONST_RETURN gchar *
-g_application_get_action_description (GApplication *application,
- const gchar *name)
-{
- 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);
-
- action = g_hash_table_lookup (application->priv->actions, name);
- g_return_val_if_fail (action != NULL, NULL);
-
- return action->description;
+ //queue_actions_change_notification (application);
}
/**
* g_application_get_action_enabled:
* @application: a #GApplication
- * @name: the name of the action
+ * @action_name: the name of the action
+ * @returns: %TRUE if the action is enabled
*
- * Retrieves whether the action @name is enabled or not.
+ * Retrieves whether the action @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.
- *
- * Return value: %TRUE if the action was enabled, and %FALSE otherwise
+ * Note that the list of actions is maintained locally, so this function
+ * simply returns the value set by the last call made to
+ * to g_application_set_action_enabled() on this instance.
*
* Since: 2.26
*/
gboolean
g_application_get_action_enabled (GApplication *application,
- const gchar *name)
+ const gchar *action_name)
{
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);
+ g_return_val_if_fail (action_name != NULL, FALSE);
- action = g_hash_table_lookup (application->priv->actions, name);
+ action = g_hash_table_lookup (application->priv->actions, action_name);
g_return_val_if_fail (action != NULL, FALSE);
return action->enabled;
}
/**
- * g_application_get_instance:
- *
- * 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.
- *
- * Returns: (transfer none): The primary instance of #GApplication,
- * or %NULL if none is set
- *
- * Since: 2.26
- */
-GApplication *
-g_application_get_instance (void)
-{
- return primary_application;
-}
-
-/**
- * g_application_get_id:
- * @application: a #GApplication
- *
- * Retrieves the platform-specific identifier for the #GApplication.
- *
- * Return value: The platform-specific identifier. The returned string
- * is owned by the #GApplication instance and it should never be
- * modified or freed
- *
- * Since: 2.26
- */
-G_CONST_RETURN gchar *
-g_application_get_id (GApplication *application)
-{
- g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
-
- return application->priv->appid;
-}
-
-/**
- * g_application_is_remote:
- * @application: a #GApplication
- *
- * Returns whether the object represents a proxy for a remote application.
- *
- * Returns: %TRUE if this object represents a proxy for a remote application.
- */
-gboolean
-g_application_is_remote (GApplication *application)
-{
- g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
-
- 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);
- g_application_impl_init (&app->priv->impl, app);
-}
-
-GApplicationFlags
-g_application_get_flags (GApplication *application)
-{
- g_return_val_if_fail (G_IS_APPLICATION (application), 0);
-
- return application->priv->flags;
-}
-
-static void
-g_application_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GApplication *app = G_APPLICATION (object);
-
- switch (prop_id)
- {
- case PROP_APPLICATION_ID:
- g_value_set_string (value, g_application_get_id (app));
- break;
-
- case PROP_FLAGS:
- g_value_set_flags (value, g_application_get_flags (app));
-
- case PROP_IS_REMOTE:
- g_value_set_boolean (value, g_application_is_remote (app));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-g_application_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GApplication *app = G_APPLICATION (object);
-
- switch (prop_id)
- {
- 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);
- g_application_impl_set_id (&app->priv->impl, app->priv->appid);
- break;
-
- case PROP_FLAGS:
- app->priv->flags = g_value_get_flags (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-g_application_finalize (GObject *object)
-{
- GApplication *app = G_APPLICATION (object);
-
- g_application_impl_destroy (&app->priv->impl);
-
- 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);
-
- G_OBJECT_CLASS (g_application_parent_class)
- ->finalize (object);
-}
-
-static gboolean
-g_application_process_cmdline (GApplication *application,
- GVariant **arguments,
- int *exit_status)
-{
- return FALSE;
-}
-
-static void
-g_application_add_platform_data (GApplication *application,
- GVariantBuilder *builder)
-{
-}
-
-static GApplicationCommandLine *
-g_application_create_command_line (GApplication *application,
- GVariant *arguments,
- GVariant *platform_data)
-{
- return g_object_new (G_TYPE_APPLICATION_COMMAND_LINE,
- "arguments", arguments,
- "platform-data", platform_data,
- NULL);
-}
-
-static int
-g_application_emit_cmdline (GApplication *application,
- GApplicationCommandLine *command_line)
-{
- return G_APPLICATION_GET_CLASS (application)
- ->cmdline (application, command_line);
-}
-
-int
-g_application_real_cmdline (GApplication *application,
- GApplicationCommandLine *command_line)
-{
- g_warning ("G_APPLICATION_FLAGS_REMOTE_CMDLINE specified but the "
- "cmdline() virtual function has not been implemented");
-
- return 1;
-}
-
-static void
-g_application_real_run_mainloop (GApplication *application)
-{
- if (application->priv->mainloop == NULL)
- application->priv->mainloop = g_main_loop_new (NULL, TRUE);
-
- g_main_loop_run (application->priv->mainloop);
-}
-
-static void
-g_application_real_quit_mainloop (GApplication *application)
-{
- g_main_loop_quit (application->priv->mainloop);
-}
-
-void
-g_application_startup (GApplication *application)
-{
-}
-
-static void
-g_application_emit_activate (GApplication *application,
- GVariant *platform_data)
-{
- G_APPLICATION_GET_CLASS (application)
- ->activate (application);
-}
-
-static void
-g_application_emit_open (GApplication *application,
- GFile **files,
- gint n_files,
- const gchar *hint,
- GVariant *platform_data)
-{
- G_APPLICATION_GET_CLASS (application)
- ->open (application, files, n_files, hint);
-}
-
-static void
-g_application_class_init (GApplicationClass *klass)
-{
- GObjectClass *gobject_class G_GNUC_UNUSED = G_OBJECT_CLASS (klass);
-
- klass->process_cmdline = g_application_process_cmdline;
- klass->add_platform_data = g_application_add_platform_data;
- klass->create_command_line = g_application_create_command_line;
- klass->emit_cmdline = g_application_emit_cmdline;
- klass->cmdline = g_application_real_cmdline;
- klass->run_mainloop = g_application_real_run_mainloop;
- klass->quit_mainloop = g_application_real_quit_mainloop;
- klass->startup = g_application_startup;
- klass->emit_activate = g_application_emit_activate;
- klass->emit_open = g_application_emit_open;
-
- g_type_class_add_private (klass, sizeof (GApplicationPrivate));
-
- 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: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: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:flags:
- *
- * The flags that define the behaviour of this application.
- **/
- g_object_class_install_property (gobject_class,
- PROP_FLAGS,
- g_param_spec_flags ("flags",
- P_("Application Flags"),
- P_("Application Flags"),
- G_TYPE_APPLICATION_FLAGS,
- G_APPLICATION_FLAGS_NONE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-}
-
-
-/**
- * g_application_open:
+ * g_application_get_action_description:
* @application: a #GApplication
- * @file: a #GFile, the file to open
- * @hint: the hint
- *
- * Request that a file be opened by the application.
+ * @action_name: the name of an action
+ * @returns: the description for @action_name
*
- * The application is registered (if it is not already).
+ * Gets the description of the action @action_name.
*
- * If this process is the first instance of the application that was
- * invoked then the 'open' signal is emitted.
- */
-
-/**
- * g_application_cmdline_with_arguments:
- * @application: a #GApplication
- * @arguments: a bytestring array #GVariant
- * @returns: a status code
+ * @action_name must name an action that is supported by the application.
*
- * Invokes the application with the given commandline arguments.
+ * Note that the list of actions is maintained locally, so this function
+ * will only query actions that have been registered on this instance.
*
- * This is a bindings-friendly version of g_application_cmdline().
+ * Since: 2.26
**/
-int
-g_application_cmdline_with_arguments (GApplication *application,
- GVariant *arguments)
+const gchar *
+g_application_get_action_description (GApplication *application,
+ const gchar *action_name)
{
- GApplicationClass *class = G_APPLICATION_GET_CLASS (application);
- GError *error = NULL;
- int exit_status;
-
- g_variant_ref_sink (arguments);
-
- if (!class->process_cmdline (application, &arguments, &exit_status))
- {
- if (!g_application_register (application, NULL, &error))
- {
- g_critical ("%s", error->message);
- g_error_free (error);
- exit_status = 1;
- }
-
- else if (g_application_is_remote (application))
- {
- GVariant *platform_data;
-
- platform_data = g_application_get_platform_data (application);
- exit_status = g_application_impl_cmdline (&application->priv->impl,
- arguments, platform_data);
- }
- else
- {
- GApplicationCommandLine *command_line;
-
- command_line = G_APPLICATION_GET_CLASS (application)
- ->create_command_line (application, arguments, NULL);
-
- exit_status = class->emit_cmdline (application, command_line);
-
- g_object_unref (command_line);
-
- if (exit_status == 0)
- class->run_mainloop (application);
- }
- }
-
- g_variant_unref (arguments);
-
- if (application->priv->use_count)
- {
- G_APPLICATION_GET_CLASS (application)->run_mainloop (application);
- exit_status = 0;
- }
-
- g_application_impl_flush (&application->priv->impl);
-
- return exit_status;
-}
-
-
- else /* not G_APPLICATION_FLAGS_REMOTE_CMDLINE */
- {
- gint n;
-
- n = g_variant_n_children (arguments);
-
- if (n < 2)
- g_application_activate (application);
-
- else
- {
- if (application->priv->flags & G_APPLICATION_FLAGS_CAN_OPEN)
- {
- GFile **files;
- gint i;
-
- files = g_new (GFile *, (n - 1) + 1);
- for (i = 0; i < n - 1; i++)
- {
- const gchar *arg;
-
- g_variant_get_child (arguments, i + 1, "^&ay", &arg);
- files[i] = g_file_new_for_commandline_arg (arg);
- }
- files[i] = NULL;
-
- g_application_open (application, files, n - 1, "");
- }
-
- else
- {
- g_critical ("This application does not open files.");
- exit_status = 1;
- }
- }
- }
-
- g_variant_unref (arguments);
+ GApplicationAction *action;
- if (application->priv->use_count)
- {
- G_APPLICATION_GET_CLASS (application)->run_mainloop (application);
- exit_status = 0;
- }
+ g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
+ g_return_val_if_fail (action_name != NULL, NULL);
- g_application_impl_flush (&application->priv->impl);
+ action = g_hash_table_lookup (application->priv->actions, action_name);
+ g_return_val_if_fail (action != NULL, NULL);
- return exit_status;
+ return action->description;
}
/**
- * g_application_invoke:
+ * g_application_activate:
* @application: a #GApplication
- * @argc: the argc from the main function
- * @argv: the argv from the main function
- * @returns: a status code
- *
- * Invokes the application with the given commandline arguments.
- *
- * The application is registered (if it is not already).
*
- * If this process is the first instance of the application that was
- * invoked then the 'invoke' signal is emitted.
+ * Activates the application.
*
- * If the use count of the application is zero after 'invoke' then this
- * function immediately returns the same value as was returned by
- * 'invoke'.
+ * In essence, this results in the activate() virtual function being
+ * invoked in the primary instance.
*
- * If the use count of the application is non-zero after 'invoke' then
- * the application continues to run until the use count drops to zero,
- * at which point this function returns 0.
+ * The application must be registered before calling this function.
*
- * If the application is already running then the 'invoke' method will
- * be called in the existing application. If the application is not
- * already running and the disposition of @application is
- * %G_APPLICATION_DISPOSITION_LAUNCHER then the application will be
- * activated. In either case, this function will return when the
- * invocation object is no longer in use (which can be at the end of the
- * 'invoke' call, or later if the object is held). The return value of
- * this function will be the exit status of the invocation.
- *
- * It is an error to use this function if the application has the
- * %G_APPLICATION_DISPOSITION_SERVICE disposition.
- *
- * The return value of this function is intended to be used as the exit
- * status of the process calling it.
+ * Since: 2.26
**/
-int
-g_application_cmdline (GApplication *application,
- int argc, char **argv)
+void
+g_application_activate (GApplication *application)
{
- GVariant *args;
+ g_return_if_fail (G_IS_APPLICATION (application));
+ g_return_if_fail (application->priv->is_registered);
+
+ if (application->priv->is_remote)
+ g_application_impl_activate (&application->priv->impl,
+ get_platform_data (application));
- args = g_variant_new_bytestring_array ((const gchar **) argv, argc);
- return g_application_cmdline_with_arguments (application, args);
+ else
+ G_APPLICATION_GET_CLASS (application)
+ ->emit_activate (application, NULL);
}
/**
@@ -1193,20 +973,6 @@ g_application_hold (GApplication *application)
application->priv->use_count++;
}
-void
-g_application_quit_mainloop (GApplication *app)
-{
- G_APPLICATION_GET_CLASS (app)
- ->quit_mainloop (app);
-}
-
-void
-g_application_run_mainloop (GApplication *app)
-{
- G_APPLICATION_GET_CLASS (app)
- ->run_mainloop (app);
-}
-
/**
* g_application_release:
* @application: a #GApplication
@@ -1224,107 +990,213 @@ g_application_release (GApplication *application)
application->priv->use_count--;
if (application->priv->use_count == 0)
- g_application_quit_mainloop (application);
+ G_APPLICATION_GET_CLASS (application)
+ ->quit_mainloop (application);
}
-static gboolean
-g_application_inactivity_timeout (gpointer data)
+/**
+ * g_application_open:
+ * @application: a #GApplication
+ * @files: an array of #GFile<!-- -->s to open
+ * @n_files: the length of the @files array
+ * @hint: a hint (or ""), but never %NULL
+ *
+ * Opens the given files.
+ *
+ * In essence, this results in the open() virtual function being invoked
+ * in the primary instance.
+ *
+ * @n_files must be greater than zero.
+ *
+ * @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 "".
+ *
+ * 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.26
+ **/
+void
+g_application_open (GApplication *application,
+ GFile **files,
+ gint n_files,
+ const gchar *hint)
{
- GApplication *application = data;
+ g_return_if_fail (G_IS_APPLICATION (application));
+ g_return_if_fail (application->priv->flags & G_APPLICATION_FLAGS_CAN_OPEN);
+ g_return_if_fail (application->priv->is_registered);
- g_message ("exiting application due to inactivity");
- application->priv->inactivity_timeout = 0;
- g_application_quit_mainloop (application);
+ if (application->priv->is_remote)
+ g_application_impl_open (&application->priv->impl,
+ files, n_files, hint,
+ get_platform_data (application));
- return FALSE;
+ else
+ G_APPLICATION_GET_CLASS (application)
+ ->emit_open (application, files, n_files, hint, NULL);
}
+/**
+ * g_application_action:
+ * @application: a #GApplication
+ * @action_name: the name of the action to invoke
+ * @parameters: the parameters to pass to the action, or %NULL
+ *
+ * Invokes the named action with the given parameters.
+ *
+ * In essence, this results in the action() virtual function being
+ * invoked in the primary instance.
+ *
+ * @action_name must name an action that is supported by the
+ * application. Non-existent actions will either generate g_warning()
+ * output (in the case of local invocation) or be silently ignored (in
+ * the case of remote invocation).
+ *
+ * @parameters must either be %NULL or contain parameters of the correct
+ * #GVariantType. The correct thing to do depends on the type given
+ * when calling g_application_add_action(). Actions with incorrect
+ * @parameters will either generate g_warning() output (in the case of
+ * local invocation) or be silently ignored (in case of remote
+ * invocation).
+ *
+ * The application must be registered before calling this function.
+ *
+ * Since: 2.26
+ **/
void
-g_application_activate (GApplication *application)
+g_application_action (GApplication *application,
+ const gchar *action,
+ GVariant *parameters)
{
- g_print ("act\n");
- if (g_application_is_remote (application))
- {
- GVariant *platform_data;
+ g_return_if_fail (G_IS_APPLICATION (application));
+ g_return_if_fail (application->priv->is_registered);
+
+ if (application->priv->is_remote)
+ g_application_impl_action (&application->priv->impl,
+ action, parameters,
+ get_platform_data (application));
- platform_data = g_application_get_platform_data (application);
- g_application_impl_activate (&application->priv->impl, platform_data);
- }
else
G_APPLICATION_GET_CLASS (application)
- ->activate (application);
+ ->emit_action (application, action, parameters, NULL);
}
/**
- * g_application_run_service:
+ * g_application_run:
* @application: a #GApplication
- * @returns: a status code
- *
- * Runs the application as a service.
- *
- * This call will switch the disposition of the application to
- * %G_APPLICATION_DISPOSITION_SERVICE, register the application (if not
- * yet registered), invoke the 'startup' virtual function and run the
- * mainloop.
+ * @argc: the argc from main()
+ * @argv: the argv from main()
+ * @returns: the exit status
+ *
+ * Runs the application.
+ *
+ * This function is intended to be run from main() and its return value
+ * is intended to be returned by main().
+ *
+ * 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).
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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.
*
- * Because it is not possible to change the disposition of an
- * application after it has been registered, the application must either
- * be unregistered or already have had its disposition set to
- * %%G_APPLICATION_DISPOSITION_SERVICE.
- *
- * The initial use count of the application will be zero. The
- * application will exit after 10 seconds if the use count remains at
- * zero.
+ * Since: 2.26
+ **/
+int
+g_application_run (GApplication *application,
+ int argc,
+ char **argv)
+{
+ return g_application_run_with_arguments (application,
+ g_variant_new_bytestring_array ((const gchar **) argv, argc));
+}
+
+/**
+ * g_application_run_with_arguments:
+ * @application: a #GApplication
+ * @arguments: a bytestring array #GVariant
+ * @returns: the exit status
*
- * This call never results in activation of another application process
- * or any communication with an existing application process. If an
- * instance of the application is already running then this call will
- * simply fail, writing a diagnostic to stderr and returning a non-zero
- * value, with no additional side effects.
+ * This is a bindings-friendly version of g_application_run().
*
- * The return value of this function is intended to be used as the exit
- * status of the process calling it.
+ * This function will consume @arguments if it is floating.
**/
int
-g_application_run_service (GApplication *application)
+g_application_run_with_arguments (GApplication *application,
+ GVariant *arguments)
{
- GError *error = NULL;
+ int status;
g_return_val_if_fail (G_IS_APPLICATION (application), 1);
- if (!g_application_register (application, NULL, &error))
+ g_variant_ref_sink (arguments);
+
+ if (!G_APPLICATION_GET_CLASS (application)
+ ->handle_command_line (application, &arguments, &status))
{
- g_critical ("%s", error->message);
- g_error_free (error);
+ GError *error = NULL;
- return 1;
- }
+ if (!g_application_register (application, NULL, &error))
+ {
+ g_critical ("%s\n", error->message);
+ g_error_free (error);
+ status = 1;
+ }
- application->priv->inactivity_timeout =
- g_timeout_add (10000, g_application_inactivity_timeout, application);
+ else if (application->priv->is_remote)
+ status = g_application_impl_cmdline (&application->priv->impl,
+ arguments,
+ get_platform_data (application));
- g_application_run_mainloop (application);
+ else
+ {
+ GApplicationCommandLine *command_line;
- return 0;
-}
+ command_line = G_APPLICATION_GET_CLASS (application)
+ ->create_command_line (application, arguments, NULL);
-void
-g_application_open (GApplication *application,
- GFile **files,
- gint n_files,
- const gchar *hint)
-{
- if (g_application_is_remote (application))
- {
- GVariant *platform_data;
+ status = G_APPLICATION_GET_CLASS (application)
+ ->emit_command_line (application, command_line);
- platform_data = g_application_get_platform_data (application);
- g_application_impl_open (&application->priv->impl,
- files, n_files, hint, platform_data);
+ g_object_unref (command_line);
+ }
}
- else
+
+ g_variant_unref (arguments);
+
+ if (application->priv->use_count)
{
G_APPLICATION_GET_CLASS (application)
- ->open (application, files, n_files, hint);
+ ->run_mainloop (application);
+ status = 0;
}
+
+ g_application_impl_flush (&application->priv->impl);
+
+ return status;
}
diff --git a/gio/gapplication.h b/gio/gapplication.h
index de1648d..4cef9cb 100644
--- a/gio/gapplication.h
+++ b/gio/gapplication.h
@@ -94,45 +94,50 @@ struct _GApplicationClass
/* signals */
void (* startup) (GApplication *application);
+ void (* activate) (GApplication *application);
+
void (* open) (GApplication *application,
GFile **files,
gint n_files,
const gchar *hint);
- void (* activate) (GApplication *application);
-
- int (* cmdline) (GApplication *application,
- GApplicationCommandLine *command_line);
-
- gboolean (* action) (GApplication *application,
+ void (* action) (GApplication *application,
const gchar *action_name,
GVariant *parameters);
+ int (* command_line) (GApplication *application,
+ GApplicationCommandLine *command_line);
/* vfuncs */
- void (* add_platform_data) (GApplication *application,
- GVariantBuilder *builder);
- gboolean (* process_cmdline) (GApplication *application,
+ gboolean (* handle_command_line) (GApplication *application,
GVariant **arguments,
- gint *exit_status);
+ int *exit_status);
- GApplicationCommandLine * (* create_command_line) (GApplication *application,
- GVariant *arguments,
+ void (* emit_startup) (GApplication *application);
+
+ void (* emit_activate) (GApplication *application,
GVariant *platform_data);
- int (* emit_cmdline) (GApplication *application,
- GApplicationCommandLine *command_line);
void (* emit_open) (GApplication *application,
GFile **files,
gint n_files,
const gchar *hint,
GVariant *platform_data);
- void (* emit_activate) (GApplication *application,
- GVariant *platform_data);
+
void (* emit_action) (GApplication *application,
const gchar *action_name,
+ GVariant *parameters,
GVariant *platform_data);
+ GApplicationCommandLine * (* create_command_line) (GApplication *application,
+ GVariant *arguments,
+ GVariant *platform_data);
+
+ int (* emit_command_line) (GApplication *application,
+ GApplicationCommandLine *command_line);
+
+ void (* add_platform_data) (GApplication *application,
+ GVariantBuilder *builder);
void (* quit_mainloop) (GApplication *application);
void (* run_mainloop) (GApplication *application);
@@ -142,44 +147,43 @@ struct _GApplicationClass
GType g_application_get_type (void) G_GNUC_CONST;
-GApplication * g_application_get_instance (void);
-gboolean g_application_is_supported (void);
+gboolean g_application_id_is_valid (const gchar *application_id);
-GApplication * g_application_new (const gchar *appid,
+GApplication * g_application_new (const gchar *application_id,
GApplicationFlags flags);
-gboolean g_application_register (GApplication *application,
- GCancellable *cancellable,
- GError **error);
-gboolean g_application_is_remote (GApplication *application);
+const gchar * g_application_get_application_id (GApplication *application);
+void g_application_set_application_id (GApplication *application,
+ const gchar *application_id);
+
+GApplicationFlags g_application_get_flags (GApplication *application);
void g_application_set_flags (GApplication *application,
GApplicationFlags flags);
-const gchar * g_application_get_id (GApplication *application);
+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_add_action (GApplication *application,
- const gchar *name,
+ const gchar *action_name,
+ const GVariantType *parameters_type,
const gchar *description);
void g_application_remove_action (GApplication *application,
- const gchar *name);
+ const gchar *action_name);
gchar ** g_application_list_actions (GApplication *application);
void g_application_set_action_enabled (GApplication *application,
- const gchar *name,
+ const gchar *action_name,
gboolean enabled);
gboolean g_application_get_action_enabled (GApplication *application,
- const gchar *name);
+ const gchar *action_name);
const gchar * g_application_get_action_description (GApplication *application,
- const gchar *name);
-
-int g_application_cmdline_with_arguments (GApplication *application,
- GVariant *arguments);
-int g_application_cmdline (GApplication *application,
- int argc,
- char **argv);
+ const gchar *action_name);
-void g_application_action (GApplication *application,
- const gchar *action,
- GVariant *parameters);
+void g_application_hold (GApplication *application);
+void g_application_release (GApplication *application);
void g_application_activate (GApplication *application);
@@ -188,7 +192,15 @@ void g_application_open (GApplic
gint n_files,
const gchar *hint);
-int g_application_run_service (GApplication *application);
+void g_application_action (GApplication *application,
+ const gchar *action_name,
+ GVariant *parameters);
+
+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.c b/gio/gapplicationimpl-dbus.c
index 4a77a2c..b2a46e7 100644
--- a/gio/gapplicationimpl-dbus.c
+++ b/gio/gapplicationimpl-dbus.c
@@ -20,7 +20,7 @@
*/
#include "gapplicationimpl-dbus-private.h"
-#include "gfile.h"
+#include "gdbusconnection.h"
#include <stdio.h>
@@ -118,7 +118,7 @@ g_application_impl_method_call (GDBusConnection *connection,
g_object_ref (invocation));
exit_status = G_APPLICATION_GET_CLASS (impl->app)
- ->emit_cmdline (impl->app, command_line);
+ ->emit_command_line (impl->app, command_line);
g_application_command_line_set_exit_status (command_line, exit_status);
g_object_unref (command_line);
@@ -143,21 +143,6 @@ application_path_from_appid (const gchar *appid)
return appid_path;
}
-void
-g_application_impl_init (GApplicationImpl *impl,
- gpointer app)
-{
- impl->app = app;
-}
-
-static void
-g_application_impl_set_id (GApplicationImpl *impl,
- const gchar *appid)
-{
- impl->bus_name = appid;
- impl->object_path = application_path_from_appid (appid);
-}
-
static void
g_application_impl_destroy (GApplicationImpl *impl)
{
@@ -168,15 +153,19 @@ g_application_impl_destroy (GApplicationImpl *impl)
impl->object_id);
g_object_unref (impl->session_bus);
+ g_free (impl->object_path);
}
else
- g_assert (impl->object_id == 0);
-
- g_free (impl->object_path);
+ {
+ g_assert (impl->object_path == NULL);
+ g_assert (impl->object_id == 0);
+ }
}
static gboolean
g_application_impl_register (GApplicationImpl *impl,
+ const gchar *appid,
+ gpointer app,
gboolean *is_remote,
GCancellable *cancellable,
GError **error)
@@ -187,17 +176,17 @@ g_application_impl_register (GApplicationImpl *impl,
GVariant *reply;
guint32 rval;
- g_print ("eh\n");
-
g_assert (impl->session_bus == NULL);
+ impl->bus_name = appid;
+
impl->session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION,
cancellable, error);
if (impl->session_bus == NULL)
return FALSE;
- g_print ("reg %s %s\n", org_gtk_Application.name, impl->object_path);
+ impl->object_path = application_path_from_appid (appid);
impl->object_id = g_dbus_connection_register_object (impl->session_bus,
impl->object_path,
(GDBusInterfaceInfo *)
@@ -209,7 +198,9 @@ g_application_impl_register (GApplicationImpl *impl,
if (impl->object_id == 0)
{
g_object_unref (impl->session_bus);
+ g_free (impl->object_path);
impl->session_bus = NULL;
+ impl->object_path = NULL;
return FALSE;
}
@@ -232,7 +223,9 @@ g_application_impl_register (GApplicationImpl *impl,
impl->object_id = 0;
g_object_unref (impl->session_bus);
+ g_free (impl->object_path);
impl->session_bus = NULL;
+ impl->object_path = NULL;
return FALSE;
}
@@ -245,6 +238,8 @@ g_application_impl_register (GApplicationImpl *impl,
{
g_dbus_connection_unregister_object (impl->session_bus,
impl->object_id);
+ g_free (impl->object_path);
+ impl->object_path = NULL;
impl->object_id = 0;
}
diff --git a/gio/gioenums.h b/gio/gioenums.h
index 8135ee0..1dcbc1e 100644
--- a/gio/gioenums.h
+++ b/gio/gioenums.h
@@ -1215,7 +1215,7 @@ typedef enum
{
G_APPLICATION_FLAGS_NONE,
G_APPLICATION_FLAGS_CAN_OPEN = (1 << 0),
- G_APPLICATION_FLAGS_REMOTE_CMDLINE = (1 << 1)
+ G_APPLICATION_FLAGS_CAN_COMMAND_LINE = (1 << 1)
} GApplicationFlags;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]