[glib/wip/gapplication] Switch activation arguments to "aay"
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/gapplication] Switch activation arguments to "aay"
- Date: Wed, 2 Jun 2010 20:56:28 +0000 (UTC)
commit e9423e752073b802d834e6f6c0e455faced3e5d5
Author: Colin Walters <walters verbum org>
Date: Wed Jun 2 16:45:00 2010 -0400
Switch activation arguments to "aay"
In Unix, argv is an array of byte arrays. The typical way we
work around this is that GOption allows to say "I expect this argument
to be a string" or "I expect this argument to be a filename".
Since in GApplication we're processing arguments before GOption
comes into play, we need to pass them over as bytes.
The problem this introduces is we can no longer use G_TYPE_STRV
in our signal, because that's defined to be UTF-8. Switch
to GVariant instead, which is the least-bad option I see here.
gio/gapplication.c | 25 ++++++++++++++++++-------
gio/gapplication.h | 3 ++-
gio/gunixapplication.c | 10 +++++-----
gio/tests/testapp.c | 24 +++++++++++++++++++-----
4 files changed, 44 insertions(+), 18 deletions(-)
---
diff --git a/gio/gapplication.c b/gio/gapplication.c
index cec3252..10094b4 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -201,15 +201,25 @@ _g_application_handle_activation (const char *appid)
int i;
GApplicationConstructionData *construct_data;
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("(asa{sv})"));
- g_variant_builder_open (&builder, G_VARIANT_TYPE ("as"));
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("(aaya{sv})"));
+ g_variant_builder_open (&builder, G_VARIANT_TYPE ("aay"));
construct_data = g_static_private_get (&construction_data);
if (construct_data)
{
for (i = 1; i < construct_data->argc; i++)
- g_variant_builder_add_value (&builder,
- g_variant_new_string (construct_data->argv[i]));
+ {
+ int j;
+ guint8 *argv_bytes;
+
+ g_variant_builder_open (&builder, G_VARIANT_TYPE ("ay"));
+
+ argv_bytes = (guint8*) construct_data->argv[i];
+ for (j = 0; argv_bytes[j]; j++)
+ g_variant_builder_add_value (&builder,
+ g_variant_new_byte (argv_bytes[j]));
+ g_variant_builder_close (&builder);
+ }
}
g_variant_builder_close (&builder);
@@ -850,12 +860,13 @@ g_application_class_init (GApplicationClass *klass)
/**
* GApplication::activated:
- * @args: Arguments given to non-primary process
+ * @arguments: A #GVariant with the signature "aay"
*
* 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 given arguments are defined to be in UTF-8 encoding.
+ * file. The raw operating system arguments are passed in the
+ * @arguments variant.
*/
application_signals[ACTIVATED] =
@@ -866,7 +877,7 @@ g_application_class_init (GApplicationClass *klass)
NULL, NULL,
g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE, 1,
- G_TYPE_STRV);
+ G_TYPE_VARIANT);
/**
* GApplication:appid:
diff --git a/gio/gapplication.h b/gio/gapplication.h
index b8f6243..4a956f9 100644
--- a/gio/gapplication.h
+++ b/gio/gapplication.h
@@ -44,6 +44,7 @@ typedef struct _GApplication GApplication;
typedef struct _GApplicationPrivate GApplicationPrivate;
typedef struct _GApplicationClass GApplicationClass;
typedef struct _GApplicationPlugin GApplicationPlugin;
+typedef struct _GApplicationArguments GApplicationArguments;
/**
* GApplication:
@@ -85,7 +86,7 @@ struct _GApplicationClass
gboolean (* quit) (GApplication *application,
guint timestamp);
void (* activated) (GApplication *application,
- const gchar **arguments);
+ GVariant *arguments);
/* vfuncs */
void (* run) (GApplication *application);
diff --git a/gio/gunixapplication.c b/gio/gunixapplication.c
index 6c3d865..1dfdfc1 100644
--- a/gio/gunixapplication.c
+++ b/gio/gunixapplication.c
@@ -101,18 +101,18 @@ application_dbus_method_call (GDBusConnection *connection,
}
else if (strcmp (method_name, "Activate") == 0)
{
+ GVariant *args;
GVariant *platform_data;
- char **args;
- g_variant_get (parameters, "(^a&s a{sv})", &args, &platform_data);
+ g_variant_get (parameters, "(@aay a{sv})", &args, &platform_data);
if (app->priv->plugin && app->priv->plugin->receive_activation_data)
{
app->priv->plugin->receive_activation_data (platform_data);
}
-
g_signal_emit (app, application_signals[ACTIVATED], 0, args);
- g_free (args);
+
+ g_variant_unref (args);
g_variant_unref (platform_data);
g_dbus_method_invocation_return_value (invocation, NULL);
@@ -203,7 +203,7 @@ static const GDBusArgInfo application_activate_in_args[] =
{
-1,
"arguments",
- "as",
+ "aay",
NULL
},
{
diff --git a/gio/tests/testapp.c b/gio/tests/testapp.c
index 5534268..b42543a 100644
--- a/gio/tests/testapp.c
+++ b/gio/tests/testapp.c
@@ -34,13 +34,27 @@ invoke_action1 (gpointer data)
static void
on_app_activated (GApplication *application,
- char **args,
- GVariant *platform_data)
+ GVariant *args)
{
- char **iter;
+ GVariantIter iter;
+ GVariant *arg;
g_print ("got args: ");
- for (iter = args; *iter; iter++)
- g_print ("%s ", *iter);
+
+ g_variant_iter_init (&iter, args);
+ while (g_variant_iter_next (&iter, "@ay", &arg))
+ {
+ const guint8 *bytes;
+ gsize len;
+ char *utf;
+
+ bytes = g_variant_get_byte_array (arg, &len);
+ utf = g_locale_to_utf8 ((char*) bytes, len, NULL, NULL, NULL);
+
+ if (utf)
+ g_print ("%s ", utf);
+ g_free (utf);
+ g_variant_unref (arg);
+ }
g_print ("\n");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]