~timo-jyrinki/gconf/ubuntu.support-s-to-as-migrations

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
From 24a40aadce621d01ede0d4add76599145778b6f8 Mon Sep 17 00:00:00 2001
From: Timo Jyrinki <timo.jyrinki@iki.fi>
Date: Fri, 14 Sep 2012 09:46:57 +0300
Subject: [PATCH] Support 's' to 'as' migrations v2

If a string's migration target is not a string, try to migrate it as a string array instead. It is a common change in schemas, so this is needed for example when migrating some metacity keys to org.gnome.desktop.wm.keybindings.
---
 gsettings/gsettings-data-convert.c |   22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/gsettings/gsettings-data-convert.c b/gsettings/gsettings-data-convert.c
index a8af942..48dfae9 100644
--- a/gsettings/gsettings-data-convert.c
+++ b/gsettings/gsettings-data-convert.c
@@ -238,8 +238,26 @@ handle_file (const gchar *filename)
                 g_print ("Set key '%s' to string '%s'\n", keys[j],
                          gconf_value_get_string (value));
               else
-                g_settings_set (settings, keys[j], "s",
-                                gconf_value_get_string (value));
+                {
+                  GVariant *range, *type;
+                  range = g_settings_get_range (settings, keys[j]);
+                  g_variant_get (range, "(&sv)", NULL, &type);
+
+                  if (g_variant_is_of_type (type, G_VARIANT_TYPE_STRING_ARRAY))
+                    {
+                      g_settings_set (settings, keys[j], "s",
+                                      gconf_value_get_string (value));
+                    }
+                  else
+                    {
+                      if (verbose)
+                        g_debug ("Setting the target key '%s' as a string not possible, converting the string to a string array.\n", keys[j]);
+                      const gchar *array[2] = { gconf_value_get_string (value), NULL };
+                      g_settings_set_strv (settings, keys[j], array);
+                    }
+                  g_variant_unref (type);
+                  g_variant_unref (range);
+                }
               break;
 
             case GCONF_VALUE_INT:
-- 
1.7.10.4