[Pkg-telepathy-commits] [telepathy-mission-control-6] 98/280: mcd_keyfile_escape_value: implement in terms of mcd_keyfile_escape_variant

Simon McVittie smcv at debian.org
Thu Mar 27 20:07:10 UTC 2014


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch debian
in repository telepathy-mission-control-6.

commit 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 file 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);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-telepathy/telepathy-mission-control-6.git



More information about the Pkg-telepathy-commits mailing list