[next] telepathy-mission-control: mcd_keyfile_escape_value: implement in terms of mcd_keyfile_escape_variant
Simon McVittie
smcv at kemper.freedesktop.org
Tue Nov 5 14:25:08 CET 2013
Module: telepathy-mission-control
Branch: next
Commit: 84c7a221cc0213751a065d15e0c54798c86ada6b
URL: http://cgit.freedesktop.org/telepathy/telepathy-mission-control/commit/?id=84c7a221cc0213751a065d15e0c54798c86ada6b
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Wed Sep 12 14:56:07 2012 +0100
mcd_keyfile_escape_value: implement in terms of mcd_keyfile_escape_variant
It was previously the other way round.
Similarly, implement mcd_storage_coerce_variant_to_value in terms of
mcd_keyfile_escape_variant.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=54874
Reviewed-by: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
---
src/mcd-storage.c | 55 +++++++++++++++++++++++++++++-----------------------
1 files changed, 31 insertions(+), 24 deletions(-)
diff --git a/src/mcd-storage.c b/src/mcd-storage.c
index 337d946..323a287 100644
--- a/src/mcd-storage.c
+++ b/src/mcd-storage.c
@@ -192,25 +192,15 @@ mcd_storage_new (TpDBusDaemon *dbus_daemon)
static gchar *
mcd_keyfile_escape_variant (GVariant *variant)
{
- GValue value = G_VALUE_INIT;
+ GKeyFile *keyfile;
gchar *ret;
- dbus_g_value_parse_g_variant (variant, &value);
-
- if (G_IS_VALUE (&value))
- {
- ret = mcd_keyfile_escape_value (&value);
- g_value_unset (&value);
- }
- else
- {
- gchar *printed = g_variant_print (variant, TRUE);
-
- ret = NULL;
- g_warning ("Unable to translate variant %s", printed);
- g_free (printed);
- }
+ g_return_val_if_fail (variant != NULL, NULL);
+ keyfile = g_key_file_new ();
+ mcd_keyfile_set_variant (keyfile, "g", "k", variant);
+ ret = g_key_file_get_value (keyfile, "g", "k", NULL);
+ g_key_file_free (keyfile);
return ret;
}
@@ -967,10 +957,10 @@ mcd_storage_coerce_variant_to_value (GVariant *variant,
/* This is really pretty stupid but it'll do for now.
* FIXME: implement a better similar-type-coercion mechanism than
* round-tripping through a GKeyFile. */
- escaped = mcd_keyfile_escape_value (&tmp);
+ g_value_unset (&tmp);
+ escaped = mcd_keyfile_escape_variant (variant);
ret = mcd_keyfile_unescape_value (escaped, value, error);
g_free (escaped);
- g_value_unset (&tmp);
return ret;
}
@@ -1826,15 +1816,23 @@ mcpa_escape_value_for_keyfile (const McpAccountManager *unused G_GNUC_UNUSED,
gchar *
mcd_keyfile_escape_value (const GValue *value)
{
- GKeyFile *keyfile;
+ GVariant *variant;
gchar *ret;
g_return_val_if_fail (G_IS_VALUE (value), NULL);
- keyfile = g_key_file_new ();
- mcd_keyfile_set_value (keyfile, "g", "k", value);
- ret = g_key_file_get_value (keyfile, "g", "k", NULL);
- g_key_file_free (keyfile);
+ variant = dbus_g_value_build_g_variant (value);
+
+ if (variant == NULL)
+ {
+ g_warning ("Unable to convert %s to GVariant",
+ G_VALUE_TYPE_NAME (value));
+ return NULL;
+ }
+
+ g_variant_ref_sink (variant);
+ ret = mcd_keyfile_escape_variant (variant);
+ g_variant_unref (variant);
return ret;
}
@@ -1876,9 +1874,18 @@ mcd_keyfile_set_value (GKeyFile *keyfile,
}
else
{
- GVariant *variant = dbus_g_value_build_g_variant (value);
+ GVariant *variant;
gboolean ret;
+ variant = dbus_g_value_build_g_variant (value);
+
+ if (variant == NULL)
+ {
+ g_warning ("Unable to convert %s to GVariant",
+ G_VALUE_TYPE_NAME (value));
+ return FALSE;
+ }
+
g_variant_ref_sink (variant);
ret = mcd_keyfile_set_variant (keyfile, name, key, variant);
g_variant_unref (variant);
More information about the telepathy-commits
mailing list