[glib] [GApplication] Add working directory to platform data
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] [GApplication] Add working directory to platform data
- Date: Fri, 18 Jun 2010 17:05:19 +0000 (UTC)
commit 8f5bde679e7cf5b519988b0fa36c300ecce3f19f
Author: Colin Walters <walters verbum org>
Date: Wed Jun 16 14:17:26 2010 -0400
[GApplication] Add working directory to platform data
https://bugzilla.gnome.org/show_bug.cgi?id=621838
gio/gapplication.c | 51 ++++++++++++++++++++++++++++++++++++++++++-----
gio/gdbusapplication.c | 12 +---------
gio/tests/testapp.c | 20 ++++++++++++++++++
3 files changed, 67 insertions(+), 16 deletions(-)
---
diff --git a/gio/gapplication.c b/gio/gapplication.c
index 31964ec..25a2cc4 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -131,11 +131,12 @@
* 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 is guaranteed to have a key "cwd" of type
- * signature "ay" which contains the working directory of the invoked
- * executable.
- *
+ *
+ * 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
@@ -319,6 +320,38 @@ g_application_default_run (GApplication *application)
}
static GVariant *
+append_cwd_to_platform_data (GVariant *platform_data)
+{
+ GVariantBuilder builder;
+ gchar *cwd;
+ GVariant *result;
+
+ cwd = g_get_current_dir ();
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+ if (cwd)
+ g_variant_builder_add (&builder, "{sv}",
+ "cwd",
+ g_variant_new_byte_array (cwd, -1));
+ g_free (cwd);
+
+ 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);
+ }
+ }
+ result = g_variant_builder_end (&builder);
+ return result;
+}
+
+static GVariant *
variant_from_argv (int argc,
char **argv)
{
@@ -976,6 +1009,7 @@ g_application_init (GApplication *app)
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);
}
static void
@@ -1045,7 +1079,12 @@ g_application_set_property (GObject *object,
break;
case PROP_PLATFORM_DATA:
- app->priv->platform_data = g_value_dup_variant (value);
+ {
+ 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:
diff --git a/gio/gdbusapplication.c b/gio/gdbusapplication.c
index 39f46ed..e376c04 100644
--- a/gio/gdbusapplication.c
+++ b/gio/gdbusapplication.c
@@ -346,16 +346,8 @@ _g_application_platform_register (GApplication *app,
GVariant *result;
g_variant_builder_init (&builder, G_VARIANT_TYPE ("(aaya{sv})"));
- g_variant_builder_add (&builder, "@aay", app->priv->argv);
-
- if (app->priv->platform_data)
- g_variant_builder_add (&builder, "@a{sv}", app->priv->platform_data);
- else
- {
- g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{sv}"));
- g_variant_builder_close (&builder);
- }
-
+ g_variant_builder_add_value (&builder, app->priv->argv);
+ g_variant_builder_add_value (&builder, app->priv->platform_data);
message = g_variant_builder_end (&builder);
result = g_dbus_connection_call_sync (app->priv->session_bus,
diff --git a/gio/tests/testapp.c b/gio/tests/testapp.c
index 1985698..caed830 100644
--- a/gio/tests/testapp.c
+++ b/gio/tests/testapp.c
@@ -31,6 +31,26 @@ on_app_activated (GApplication *application,
GVariant *args,
GVariant *platform_data)
{
+ GVariantIter iter;
+ const char *key;
+ GVariant *value;
+ char *cwd;
+
+ cwd = g_get_current_dir ();
+ g_variant_iter_init (&iter, platform_data);
+ while (g_variant_iter_next (&iter, "{&sv}", &key, &value))
+ {
+ const char *activate_cwd;
+ gsize *len;
+ if (strcmp (key, "cwd") != 0)
+ continue;
+
+ activate_cwd = g_variant_get_byte_array (value, &len);
+ g_assert_cmpstr (cwd, ==, activate_cwd);
+ g_variant_unref (value);
+ }
+
+ g_free (cwd);
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]