Mercurial > geeqie
changeset 768:ff51413f098d
Use functions to set editors name and command and ensure they are
utf8-encoded.
Previously, non-utf8 strings from rc file caused some issues.
author | zas_ |
---|---|
date | Fri, 30 May 2008 08:39:52 +0000 |
parents | e73d30e0c896 |
children | 110462fdf31b |
files | src/editors.c src/editors.h src/options.c src/preferences.c src/rcfile.c |
diffstat | 5 files changed, 38 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/editors.c Fri May 30 08:36:23 2008 +0000 +++ b/src/editors.c Fri May 30 08:39:52 2008 +0000 @@ -93,16 +93,31 @@ *----------------------------------------------------------------------------- */ +void editor_set_name(gint n, gchar *name) +{ + if (n < 0 || n >= GQ_EDITOR_SLOTS) return; + + g_free(options->editor[n].name); + + options->editor[n].name = name ? utf8_validate_or_convert(name) : NULL; +} + +void editor_set_command(gint n, gchar *command) +{ + if (n < 0 || n >= GQ_EDITOR_SLOTS) return; + + g_free(options->editor[n].command); + options->editor[n].command = command ? utf8_validate_or_convert(command) : NULL; +} + void editor_reset_defaults(void) { gint i; for (i = 0; i < GQ_EDITOR_SLOTS; i++) { - g_free(options->editor[i].name); - options->editor[i].name = g_strdup(_(editor_slot_defaults[i].name)); - g_free(options->editor[i].command); - options->editor[i].command = g_strdup(editor_slot_defaults[i].command); + editor_set_name(i, _(editor_slot_defaults[i].name)); + editor_set_command(i, _(editor_slot_defaults[i].command)); } }
--- a/src/editors.h Fri May 30 08:36:23 2008 +0000 +++ b/src/editors.h Fri May 30 08:39:52 2008 +0000 @@ -55,6 +55,8 @@ */ typedef gint (*EditorCallback) (gpointer ed, gint flags, GList *list, gpointer data); +void editor_set_name(gint n, gchar *name); +void editor_set_command(gint n, gchar *command); void editor_resume(gpointer ed);
--- a/src/options.c Fri May 30 08:36:23 2008 +0000 +++ b/src/options.c Fri May 30 08:39:52 2008 +0000 @@ -164,8 +164,8 @@ for (i = 0; i < GQ_EDITOR_SLOTS; i++) { - options->editor[i].name = NULL; - options->editor[i].command = NULL; + editor_set_name(i, NULL); + editor_set_command(i, NULL); } editor_reset_defaults();
--- a/src/preferences.c Fri May 30 08:36:23 2008 +0000 +++ b/src/preferences.c Fri May 30 08:39:52 2008 +0000 @@ -161,16 +161,18 @@ for (i = 0; i < GQ_EDITOR_SLOTS; i++) { + gchar *command = NULL; + if (i < GQ_EDITOR_GENERIC_SLOTS) { - g_free(options->editor[i].name); - options->editor[i].name = NULL; + gchar *name = NULL; + buf = gtk_entry_get_text(GTK_ENTRY(editor_name_entry[i])); - if (buf && strlen(buf) > 0) options->editor[i].name = g_strdup(buf); + if (buf && strlen(buf) > 0) name = g_strdup(buf); + editor_set_name(i, name); + g_free(name); } - g_free(options->editor[i].command); - options->editor[i].command = NULL; buf = gtk_entry_get_text(GTK_ENTRY(editor_command_entry[i])); if (buf && strlen(buf) > 0) { @@ -183,8 +185,11 @@ i+1, options->editor[i].name, buf); } - options->editor[i].command = g_strdup(buf); + command = g_strdup(buf); } + + editor_set_command(i, command); + g_free(command); } if (errmsg->str[0])
--- a/src/rcfile.c Fri May 30 08:36:23 2008 +0000 +++ b/src/rcfile.c Fri May 30 08:39:52 2008 +0000 @@ -17,6 +17,7 @@ #include "rcfile.h" #include "bar_exif.h" +#include "editors.h" #include "filefilter.h" #include "secure_save.h" #include "slideshow.h" @@ -907,12 +908,10 @@ if (i > 0 && i <= GQ_EDITOR_SLOTS) { const gchar *ptr; + i--; - g_free(options->editor[i].name); - g_free(options->editor[i].command); - - options->editor[i].name = quoted_value(value_all, &ptr); - options->editor[i].command = quoted_value(ptr, NULL); + editor_set_name(i, quoted_value(value_all, &ptr)); + editor_set_command(i, quoted_value(ptr, NULL)); } continue; }