summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2012-01-12 11:45:16 +0100
committerVincent Untz <vuntz@gnome.org>2012-01-12 11:45:16 +0100
commitc5110b3253239f80485d879e7d8a186f3a63e7c4 (patch)
tree28587f2441ef43e8d14cbf6ec17f626a5fb73d89
parente8e510b58c72f314645872f440d1abcffb7bfeb2 (diff)
validate: Handle list of locale strings in fixup too
https://bugs.freedesktop.org/show_bug.cgi?id=44098
-rw-r--r--src/validate.c77
1 files changed, 51 insertions, 26 deletions
diff --git a/src/validate.c b/src/validate.c
index d5eb23c..a1e16f4 100644
--- a/src/validate.c
+++ b/src/validate.c
@@ -2722,13 +2722,44 @@ desktop_file_validate (const char *filename,
return (!kf.fatal_error);
}
+static void
+fixup_list (GKeyFile *keyfile,
+ const gchar *filename,
+ const gchar *key)
+{
+ char *value;
+ int len;
+
+ value = g_key_file_get_value (keyfile, GROUP_DESKTOP_ENTRY, key, NULL);
+ if (!value)
+ return;
+
+ len = strlen (value);
+
+ if (len > 0 && (value[len - 1] != ';' ||
+ (len > 1 && value[len - 2] == '\\' &&
+ (len < 3 || value[len - 3] != '\\')))) {
+ char *str;
+
+ g_printerr ("%s: warning: key \"%s\" is a list and does not have a "
+ "semicolon as trailing character, fixing\n",
+ filename, key);
+
+ str = g_strconcat (value, ";", NULL);
+ g_key_file_set_value (keyfile, GROUP_DESKTOP_ENTRY,
+ key, str);
+ g_free (str);
+ }
+}
+
/* return FALSE if we were unable to fix the file */
gboolean
desktop_file_fixup (GKeyFile *keyfile,
const char *filename)
{
- char *value;
- unsigned int i;
+ gchar **keys;
+ gsize keys_nb;
+ unsigned int i;
if (g_key_file_has_group (keyfile, GROUP_KDE_DESKTOP_ENTRY)) {
g_printerr ("%s: warning: renaming deprecated \"%s\" group to \"%s\"\n",
@@ -2737,35 +2768,29 @@ desktop_file_fixup (GKeyFile *keyfile,
GROUP_KDE_DESKTOP_ENTRY, GROUP_DESKTOP_ENTRY);
}
+ keys = g_key_file_get_keys (keyfile, GROUP_DESKTOP_ENTRY, &keys_nb, NULL);
+
/* Fix lists to have a ';' at the end if they don't */
for (i = 0; i < G_N_ELEMENTS (registered_desktop_keys); i++) {
- if (registered_desktop_keys[i].type != DESKTOP_STRING_LIST_TYPE &&
- registered_desktop_keys[i].type != DESKTOP_REGEXP_LIST_TYPE)
- continue;
-
- value = g_key_file_get_value (keyfile, GROUP_DESKTOP_ENTRY,
- registered_desktop_keys[i].name, NULL);
- if (value) {
- int len;
-
- len = strlen (value);
-
- if (len > 0 && (value[len - 1] != ';' ||
- (len > 1 && value[len - 2] == '\\' &&
- (len < 3 || value[len - 3] != '\\')))) {
- char *str;
-
- g_printerr ("%s: warning: key \"%s\" is a list and does not have a "
- "semicolon as trailing character, fixing\n",
- filename, registered_desktop_keys[i].name);
-
- str = g_strconcat (value, ";", NULL);
- g_key_file_set_value (keyfile, GROUP_DESKTOP_ENTRY,
- registered_desktop_keys[i].name, str);
- g_free (str);
+ if (registered_desktop_keys[i].type == DESKTOP_STRING_LIST_TYPE ||
+ registered_desktop_keys[i].type == DESKTOP_REGEXP_LIST_TYPE)
+ fixup_list (keyfile, filename, registered_desktop_keys[i].name);
+
+ if (registered_desktop_keys[i].type == DESKTOP_LOCALESTRING_LIST_TYPE) {
+ gsize keylen;
+ guint j;
+
+ keylen = strlen (registered_desktop_keys[i].name);
+ for (j = 0; j < keys_nb; j++) {
+ if (g_str_has_prefix (keys[j], registered_desktop_keys[i].name) &&
+ (keys[j][keylen] == '[' || keys[j][keylen] == '\0')) {
+ fixup_list (keyfile, filename, keys[j]);
+ }
}
}
}
+ g_strfreev (keys);
+
return TRUE;
}