summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Untz <vuntz@gnome.org>2011-12-14 15:41:57 +0100
committerVincent Untz <vuntz@gnome.org>2011-12-14 15:46:33 +0100
commite6f385182a1735eea36ca1041ed53696a62c89c6 (patch)
tree94331eb5e540e41fc15032ed64b0dda0a9278415
parent9afde296e5ef63c1908b93811f9204a01eeb130e (diff)
downloaddesktop-file-utils-e6f385182a1735eea36ca1041ed53696a62c89c6.tar.gz
keyfileutils: Also copy translations when copying a key
We of course don't do that if we're dealing with keys that are localized keys.
-rw-r--r--src/keyfileutils.c62
1 files changed, 55 insertions, 7 deletions
diff --git a/src/keyfileutils.c b/src/keyfileutils.c
index 598925b..dd67170 100644
--- a/src/keyfileutils.c
+++ b/src/keyfileutils.c
@@ -86,6 +86,29 @@ dfu_key_file_drop_locale_strings (GKeyFile *keyfile,
g_strfreev (keys);
}
+static gboolean
+_dfu_key_file_copy_key_helper (GKeyFile *keyfile,
+ const char *fromgroup,
+ const char *fromkey,
+ const char *togroup,
+ const char *tokey)
+{
+ char *value;
+
+ if (!g_key_file_has_group (keyfile, fromgroup))
+ return FALSE;
+
+ value = g_key_file_get_value (keyfile, fromgroup, fromkey, NULL);
+ if (!value)
+ return FALSE;
+
+ g_key_file_set_value (keyfile, togroup, tokey, value);
+
+ g_free (value);
+
+ return TRUE;
+}
+
gboolean
dfu_key_file_copy_key (GKeyFile *keyfile,
const char *fromgroup,
@@ -93,20 +116,45 @@ dfu_key_file_copy_key (GKeyFile *keyfile,
const char *togroup,
const char *tokey)
{
- char *value;
+ char **fromkeys;
+ gsize len;
+ char *fromprefix;
+ gsize i;
g_return_val_if_fail (keyfile != NULL, FALSE);
+ g_return_val_if_fail (fromgroup != NULL, FALSE);
+ g_return_val_if_fail (fromkey != NULL, FALSE);
+ g_return_val_if_fail (togroup != NULL, FALSE);
+ g_return_val_if_fail (tokey != NULL, FALSE);
- if (!g_key_file_has_group (keyfile, fromgroup))
+ if (!_dfu_key_file_copy_key_helper (keyfile, fromgroup, fromkey,
+ togroup, tokey))
return FALSE;
- value = g_key_file_get_value (keyfile, fromgroup, fromkey, NULL);
- if (!value)
- return FALSE;
+ /* Also copy translations if we're not dealing with localized keys already
+ * (first drop old ones) */
+ if (strchr (fromkey, '[') != NULL || strchr (tokey, '[') != NULL)
+ return TRUE;
- g_key_file_set_value (keyfile, togroup, tokey, value);
+ dfu_key_file_drop_locale_strings (keyfile, togroup, tokey);
- g_free (value);
+ fromkeys = g_key_file_get_keys (keyfile, fromgroup, &len, NULL);
+ fromprefix = g_strdup_printf ("%s[", fromkey);
+
+ for (i = 0; i < len; i++)
+ {
+ if (g_str_has_prefix (fromkeys[i], fromprefix))
+ {
+ const char *locale = fromkeys[i] + strlen (fromkey);
+ char *tolocalekey = g_strdup_printf ("%s%s", tokey, locale);
+ _dfu_key_file_copy_key_helper (keyfile, fromgroup, fromkeys[i],
+ togroup, tolocalekey);
+ g_free (tolocalekey);
+ }
+ }
+
+ g_free (fromprefix);
+ g_strfreev (fromkeys);
return TRUE;
}