# HG changeset patch # User zas_ # Date 1212136792 0 # Node ID ff51413f098df04589d4e834d974ca8d7e30bed7 # Parent e73d30e0c8966cf580d52b5e5fefb334c7643941 Use functions to set editors name and command and ensure they are utf8-encoded. Previously, non-utf8 strings from rc file caused some issues. diff -r e73d30e0c896 -r ff51413f098d src/editors.c --- 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)); } } diff -r e73d30e0c896 -r ff51413f098d src/editors.h --- 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); diff -r e73d30e0c896 -r ff51413f098d src/options.c --- 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(); diff -r e73d30e0c896 -r ff51413f098d src/preferences.c --- 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]) diff -r e73d30e0c896 -r ff51413f098d src/rcfile.c --- 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; }