Use functions to set editors name and command and ensure they are
authorLaurent Monin <geeqie@norz.org>
Fri, 30 May 2008 08:39:52 +0000 (08:39 +0000)
committerLaurent Monin <geeqie@norz.org>
Fri, 30 May 2008 08:39:52 +0000 (08:39 +0000)
utf8-encoded.
Previously, non-utf8 strings from rc file caused some issues.

src/editors.c
src/editors.h
src/options.c
src/preferences.c
src/rcfile.c

index cac2625..5c22eff 100644 (file)
@@ -93,16 +93,31 @@ static gint editor_command_done(EditorData *ed);
  *-----------------------------------------------------------------------------
  */
 
+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));
                }
 }
 
index c35e00d..0b88acf 100644 (file)
@@ -55,6 +55,8 @@ data - generic pointer
 */
 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);
index bfcbd51..2d2604a 100644 (file)
@@ -164,8 +164,8 @@ void setup_default_options(ConfOptions *options)
 
        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();
index ab19d79..54ac521 100644 (file)
@@ -161,16 +161,18 @@ static void config_window_apply(void)
 
        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 @@ static void config_window_apply(void)
                                                       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])
index 4f25dfd..96620fa 100644 (file)
@@ -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 @@ static gboolean load_options_from(const gchar *utf8_path, ConfOptions *options)
                        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);
+                               i--;
+                               editor_set_name(i, quoted_value(value_all, &ptr));
+                               editor_set_command(i, quoted_value(ptr, NULL));
                                }
                        continue;
                        }