Handle missing speedial.json and missing shortcuts array

This commit is contained in:
Christian Dywan 2011-05-20 21:58:35 +02:00
parent ad229121f0
commit 7f549b89a9

View file

@ -1605,7 +1605,12 @@ speeddial_new_from_file (const gchar* config,
} }
katze_assign (config_file, g_build_filename (config, "speeddial.json", NULL)); katze_assign (config_file, g_build_filename (config, "speeddial.json", NULL));
g_file_get_contents (config_file, &json_content, &json_length, NULL); if (!g_file_get_contents (config_file, &json_content, &json_length, NULL))
{
katze_assign (json_content, g_strdup ("'{}'"));
json_length = strlen ("'{}'");
}
script = g_string_sized_new (json_length); script = g_string_sized_new (json_length);
g_string_append (script, "var json = JSON.parse ("); g_string_append (script, "var json = JSON.parse (");
g_string_append_len (script, json_content, json_length); g_string_append_len (script, json_content, json_length);
@ -1619,7 +1624,7 @@ speeddial_new_from_file (const gchar* config,
" + 'title=' + tile['title'] + '\\n\\n';" " + 'title=' + tile['title'] + '\\n\\n';"
"} " "} "
"var columns = json['width'] ? json['width'] : 3;" "var columns = json['width'] ? json['width'] : 3;"
"var rows = json['shortcuts'].length / columns;" "var rows = json['shortcuts'] ? json['shortcuts'].length / columns : 0;"
"keyfile += '[settings]\\n'" "keyfile += '[settings]\\n'"
" + 'columns=' + columns + '\\n'" " + 'columns=' + columns + '\\n'"
" + 'rows=' + (rows > 3 ? rows : 3) + '\\n\\n';" " + 'rows=' + (rows > 3 ? rows : 3) + '\\n\\n';"