Use a struct to handle editor's properties.
authorLaurent Monin <geeqie@norz.org>
Thu, 22 May 2008 08:49:52 +0000 (08:49 +0000)
committerLaurent Monin <geeqie@norz.org>
Thu, 22 May 2008 08:49:52 +0000 (08:49 +0000)
src/editors.c
src/layout_util.c
src/main.c
src/menu.c
src/options.h
src/preferences.c
src/rcfile.c
src/trash.c
src/typedefs.h
src/utilops.c

index 020ce12..718eb9d 100644 (file)
@@ -56,31 +56,31 @@ struct _EditorData {
 };
 
 
-static gchar *editor_slot_defaults[GQ_EDITOR_SLOTS * 2] = {
-       N_("The Gimp"), "gimp-remote %{.cr2;.crw;.nef;.raw;*}f",
-       N_("XV"), "xv %f",
-       N_("Xpaint"), "xpaint %f",
-       N_("UFraw"), "ufraw %{.cr2;.crw;.nef;.raw}p",
-       N_("Add XMP sidecar"), "%vFILE=%{.cr2;.crw;.nef;.raw}p;XMP=`echo \"$FILE\"|sed -e 's|\\.[^.]*$|.xmp|'`; exiftool -tagsfromfile \"$FILE\" \"$XMP\"",
-       NULL, NULL,
-       NULL, NULL,
-       NULL, NULL,
-       N_("Rotate jpeg clockwise"), "%vif jpegtran -rotate 90 -copy all -outfile %{.jpg;.jpeg}p_tmp %{.jpg;.jpeg}p; then mv %{.jpg;.jpeg}p_tmp %{.jpg;.jpeg}p;else rm %{.jpg;.jpeg}p_tmp;fi",
-       N_("Rotate jpeg counterclockwise"), "%vif jpegtran -rotate 270 -copy all -outfile %{.jpg;.jpeg}p_tmp %{.jpg;.jpeg}p; then mv %{.jpg;.jpeg}p_tmp %{.jpg;.jpeg}p;else rm %{.jpg;.jpeg}p_tmp;fi",
+static Editor editor_slot_defaults[GQ_EDITOR_SLOTS] = {
+       { N_("The Gimp"), "gimp-remote %{.cr2;.crw;.nef;.raw;*}f" },
+       { N_("XV"), "xv %f" },
+       { N_("Xpaint"), "xpaint %f" },
+       { N_("UFraw"), "ufraw %{.cr2;.crw;.nef;.raw}p" },
+       { N_("Add XMP sidecar"), "%vFILE=%{.cr2;.crw;.nef;.raw}p;XMP=`echo \"$FILE\"|sed -e 's|\\.[^.]*$|.xmp|'`; exiftool -tagsfromfile \"$FILE\" \"$XMP\"" },
+       { NULL, NULL },
+       { NULL, NULL },
+       { NULL, NULL },
+       { N_("Rotate jpeg clockwise"), "%vif jpegtran -rotate 90 -copy all -outfile %{.jpg;.jpeg}p_tmp %{.jpg;.jpeg}p; then mv %{.jpg;.jpeg}p_tmp %{.jpg;.jpeg}p;else rm %{.jpg;.jpeg}p_tmp;fi" },
+       { N_("Rotate jpeg counterclockwise"), "%vif jpegtran -rotate 270 -copy all -outfile %{.jpg;.jpeg}p_tmp %{.jpg;.jpeg}p; then mv %{.jpg;.jpeg}p_tmp %{.jpg;.jpeg}p;else rm %{.jpg;.jpeg}p_tmp;fi" },
        /* special slots */
 #if 1
        /* for testing */
-       N_("External Copy command"), "%vset -x;cp %p %d",
-       N_("External Move command"), "%vset -x;mv %p %d",
-       N_("External Rename command"), "%vset -x;mv %p %d",
-       N_("External Delete command"), NULL,
-       N_("External New Folder command"), NULL
+       { N_("External Copy command"), "%vset -x;cp %p %d" },
+       { N_("External Move command"), "%vset -x;mv %p %d" },
+       { N_("External Rename command"), "%vset -x;mv %p %d" },
+       { N_("External Delete command"), NULL },
+       { N_("External New Folder command"), NULL },
 #else
-       N_("External Copy command"), NULL,
-       N_("External Move command"), NULL,
-       N_("External Rename command"), NULL,
-       N_("External Delete command"), NULL,
-       N_("External New Folder command"), NULL
+       { N_("External Copy command"), NULL },
+       { N_("External Move command"), NULL },
+       { N_("External Rename command"), NULL },
+       { N_("External Delete command"), NULL },
+       { N_("External New Folder command"), NULL },
 #endif
 };
 
@@ -101,10 +101,10 @@ void editor_reset_defaults(void)
 
        for (i = 0; i < GQ_EDITOR_SLOTS; i++)
                {
-               g_free(options->editor_name[i]);
-               options->editor_name[i] = g_strdup(_(editor_slot_defaults[i * 2]));
-               g_free(options->editor_command[i]);
-               options->editor_command[i] = g_strdup(editor_slot_defaults[i * 2 + 1]);
+               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);
                }
 }
 
@@ -797,8 +797,8 @@ static gint editor_command_start(const gchar *template, const gchar *text, GList
 static gint is_valid_editor_command(gint n)
 {
        return (n >= 0 && n < GQ_EDITOR_SLOTS
-               && options->editor_command[n]
-               && strlen(options->editor_command[n]) > 0); 
+               && options->editor[n].command
+               && strlen(options->editor[n].command) > 0); 
 }
 
 gint start_editor_from_filelist_full(gint n, GList *list, EditorCallback cb, gpointer data)
@@ -809,14 +809,14 @@ gint start_editor_from_filelist_full(gint n, GList *list, EditorCallback cb, gpo
        if (!list) return FALSE;
        if (!is_valid_editor_command(n)) return FALSE;
 
-       command = g_locale_from_utf8(options->editor_command[n], -1, NULL, NULL, NULL);
-       error = editor_command_start(command, options->editor_name[n], list, cb, data);
+       command = g_locale_from_utf8(options->editor[n].command, -1, NULL, NULL, NULL);
+       error = editor_command_start(command, options->editor[n].name, list, cb, data);
        g_free(command);
 
        if (n < GQ_EDITOR_GENERIC_SLOTS && (error & EDITOR_ERROR_MASK))
                {
                gchar *text = g_strdup_printf(_("%s\n#%d \"%s\":\n%s"), editor_get_error_str(error), n+1,
-                                             options->editor_name[n], options->editor_command[n]);
+                                             options->editor[n].name, options->editor[n].command);
                
                file_util_warning_dialog(_("Invalid editor command"), text, GTK_STOCK_DIALOG_ERROR, NULL);
                g_free(text);
@@ -852,7 +852,7 @@ gint editor_window_flag_set(gint n)
 {
        if (!is_valid_editor_command(n)) return TRUE;
 
-       return (editor_command_parse(options->editor_command[n], NULL, NULL) & EDITOR_KEEP_FS);
+       return (editor_command_parse(options->editor[n].command, NULL, NULL) & EDITOR_KEEP_FS);
 }
 
 const gchar *editor_get_error_str(gint flags)
index b64efc6..191391c 100644 (file)
@@ -879,13 +879,13 @@ static void layout_menu_edit_update(LayoutWindow *lw)
                action = gtk_action_group_get_action(lw->action_group, key);
                g_object_set_data(G_OBJECT(action), "edit_index", GINT_TO_POINTER(i));
 
-               if (options->editor_command[i] && strlen(options->editor_command[i]) > 0)
+               if (options->editor[i].command && strlen(options->editor[i].command) > 0)
                        {
                        gchar *text;
 
-                       if (options->editor_name[i] && strlen(options->editor_name[i]) > 0)
+                       if (options->editor[i].name && strlen(options->editor[i].name) > 0)
                                {
-                               text = g_strdup_printf(_("_%d %s..."), i, options->editor_name[i]);
+                               text = g_strdup_printf(_("_%d %s..."), i, options->editor[i].name);
                                }
                        else
                                {
index 6869afd..381cdff 100644 (file)
@@ -553,8 +553,8 @@ static void setup_default_options(void)
 
        for (i = 0; i < GQ_EDITOR_SLOTS; i++)
                {
-               options->editor_name[i] = NULL;
-               options->editor_command[i] = NULL;
+               options->editor[i].name = NULL;
+               options->editor[i].command = NULL;
                }
 
        editor_reset_defaults();
index c7dafe8..15d748a 100644 (file)
@@ -69,11 +69,11 @@ static void add_edit_items(GtkWidget *menu, GCallback func, GtkAccelGroup *accel
 
        for (i = 0; i < GQ_EDITOR_GENERIC_SLOTS; i++)
                {
-               if (options->editor_command[i] && strlen(options->editor_command[i]) > 0)
+               if (options->editor[i].command && strlen(options->editor[i].command) > 0)
                        {
                        gchar *text;
-                       if (options->editor_name[i] && strlen(options->editor_name[i]) > 0)
-                               text = g_strdup_printf(_("_%d %s..."), i, options->editor_name[i]);
+                       if (options->editor[i].name && strlen(options->editor[i].name) > 0)
+                               text = g_strdup_printf(_("_%d %s..."), i, options->editor[i].name);
                        else
                                text = g_strdup_printf(_("_%d (unknown)..."), i);
                        if (accel_grp)
index 571a545..f7b8fa6 100644 (file)
@@ -108,8 +108,7 @@ struct _ConfOptions
        } collections;
 
        /* editors */
-       gchar *editor_name[GQ_EDITOR_SLOTS];
-       gchar *editor_command[GQ_EDITOR_SLOTS];
+       Editor editor[GQ_EDITOR_SLOTS];
 
        /* file sorting */
        struct {
index f8e8a0a..fcaf13c 100644 (file)
@@ -163,14 +163,14 @@ static void config_window_apply(void)
                {
                if (i < GQ_EDITOR_GENERIC_SLOTS)
                        {
-                       g_free(options->editor_name[i]);
-                       options->editor_name[i] = NULL;
+                       g_free(options->editor[i].name);
+                       options->editor[i].name = NULL;
                        buf = gtk_entry_get_text(GTK_ENTRY(editor_name_entry[i]));
-                       if (buf && strlen(buf) > 0) options->editor_name[i] = g_strdup(buf);
+                       if (buf && strlen(buf) > 0) options->editor[i].name = g_strdup(buf);
                        }
 
-               g_free(options->editor_command[i]);
-               options->editor_command[i] = NULL;
+               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)
                        {
@@ -180,10 +180,10 @@ static void config_window_apply(void)
                                {
                                if (errmsg->str[0]) g_string_append(errmsg, "\n\n");
                                g_string_append_printf(errmsg, _("%s\n#%d \"%s\":\n%s"), editor_get_error_str(flags),
-                                                      i+1, options->editor_name[i], buf);
+                                                      i+1, options->editor[i].name, buf);
 
                                }
-                       options->editor_command[i] = g_strdup(buf);
+                       options->editor[i].command = g_strdup(buf);
                        }
                }
        
@@ -759,9 +759,9 @@ static void editor_default_ok_cb(GenericDialog *gd, gpointer data)
                {
                if (i < GQ_EDITOR_GENERIC_SLOTS)
                        gtk_entry_set_text(GTK_ENTRY(editor_name_entry[i]),
-                                  (options->editor_name[i]) ? options->editor_name[i] : "");
+                                  (options->editor[i].name) ? options->editor[i].name : "");
                gtk_entry_set_text(GTK_ENTRY(editor_command_entry[i]),
-                                  (options->editor_command[i]) ? options->editor_command[i] : "");
+                                  (options->editor[i].command) ? options->editor[i].command : "");
                }
 }
 
@@ -1225,12 +1225,12 @@ static void config_tab_editors(GtkWidget *notebook)
                        entry = gtk_entry_new();
                        gtk_entry_set_max_length(GTK_ENTRY(entry), EDITOR_NAME_MAX_LENGTH);
                        gtk_widget_set_size_request(entry, 80, -1);
-                       if (options->editor_name[i])
-                               gtk_entry_set_text(GTK_ENTRY(entry), options->editor_name[i]);
+                       if (options->editor[i].name)
+                               gtk_entry_set_text(GTK_ENTRY(entry), options->editor[i].name);
                        }
                else
                        {
-                       entry = gtk_label_new(options->editor_name[i]);
+                       entry = gtk_label_new(options->editor[i].name);
                        gtk_misc_set_alignment(GTK_MISC(entry), 0.0, 0.5);
                        }
 
@@ -1243,8 +1243,8 @@ static void config_tab_editors(GtkWidget *notebook)
                gtk_entry_set_max_length(GTK_ENTRY(entry), EDITOR_COMMAND_MAX_LENGTH);
                gtk_widget_set_size_request(entry, 160, -1);
                tab_completion_add_to_entry(entry, NULL, NULL);
-               if (options->editor_command[i])
-                       gtk_entry_set_text(GTK_ENTRY(entry), options->editor_command[i]);
+               if (options->editor[i].command)
+                       gtk_entry_set_text(GTK_ENTRY(entry), options->editor[i].command);
                gtk_table_attach(GTK_TABLE(table), entry, 2, 3, i+1, i+2,
                                 GTK_FILL | GTK_EXPAND, 0, 0, 0);
                gtk_widget_show(entry);
index a5a11b9..9070871 100644 (file)
@@ -556,8 +556,8 @@ void save_options(void)
        for (i = 0; i < GQ_EDITOR_SLOTS; i++)
                {
                if (i == GQ_EDITOR_GENERIC_SLOTS) secure_fputc(ssi, '\n');
-               gchar *qname = escquote_value(options->editor_name[i]);
-               gchar *qcommand = escquote_value(options->editor_command[i]);
+               gchar *qname = escquote_value(options->editor[i].name);
+               gchar *qcommand = escquote_value(options->editor[i].command);
                secure_fprintf(ssi, "external_%d: %s %s\n", i+1, qname, qcommand);
                g_free(qname);
                g_free(qcommand);
@@ -887,11 +887,11 @@ void load_options(void)
                                {
                                const gchar *ptr;
                                i--;
-                               g_free(options->editor_name[i]);
-                               g_free(options->editor_command[i]);
+                               g_free(options->editor[i].name);
+                               g_free(options->editor[i].command);
 
-                               options->editor_name[i] = quoted_value(value_all, &ptr);
-                               options->editor_command[i] = quoted_value(ptr, NULL);
+                               options->editor[i].name = quoted_value(value_all, &ptr);
+                               options->editor[i].command = quoted_value(ptr, NULL);
                                }
                        continue;
                        }
index 1a1583d..f9a3e62 100644 (file)
@@ -181,7 +181,7 @@ gchar *file_util_safe_delete_status(void)
 {
        gchar *buf;
 
-       if (options->editor_command[CMD_DELETE])
+       if (options->editor[CMD_DELETE].command)
                {
                buf = g_strdup(_("Deletion by external command"));
                }
index e8e3509..b030c19 100644 (file)
@@ -165,6 +165,11 @@ typedef struct _Histogram Histogram;
 
 typedef struct _SecureSaveInfo SecureSaveInfo;
 
+typedef struct _Editor Editor;
+struct _Editor {
+       gchar *name;
+       gchar *command;
+};
 
 struct _ImageLoader
 {
index 11747ce..640d724 100644 (file)
@@ -363,7 +363,7 @@ gint copy_file_ext(FileData *fd)
 {
        gint ok;
        g_assert(fd->change);
-       if (options->editor_command[CMD_COPY])
+       if (options->editor[CMD_COPY].command)
                {
                ok = !start_editor_from_file_full(CMD_COPY, fd, copy_file_ext_cb, NULL);
                if (ok) return ok; /* that's all for now, let's continue in callback */
@@ -411,7 +411,7 @@ gint move_file_ext(FileData *fd)
 {
        gint ok;
        g_assert(fd->change);
-       if (options->editor_command[CMD_MOVE])
+       if (options->editor[CMD_MOVE].command)
                {
                ok = !start_editor_from_file_full(CMD_MOVE, fd, move_file_ext_cb, NULL);
                if (ok) return ok; /* that's all for now, let's continue in callback */
@@ -458,7 +458,7 @@ gint rename_file_ext(FileData *fd)
 {
        gint ok;
        g_assert(fd->change);
-       if (options->editor_command[CMD_RENAME])
+       if (options->editor[CMD_RENAME].command)
                {
                ok = !start_editor_from_file_full(CMD_RENAME, fd, rename_file_ext_cb, NULL);
                if (ok) return ok; /* that's all for now, let's continue in callback */
@@ -1453,7 +1453,7 @@ static void file_util_delete_multiple_ok_cb(GenericDialog *gd, gpointer data)
                }
 
 
-       if (options->editor_command[CMD_DELETE])
+       if (options->editor[CMD_DELETE].command)
                {
                gint flags;
                work = source_list;
@@ -1683,7 +1683,7 @@ static void file_util_delete_ok_cb(GenericDialog *gd, gpointer data)
                }
 
 
-       if (options->editor_command[CMD_DELETE])
+       if (options->editor[CMD_DELETE].command)
                {
                gint flags;
                if ((flags = start_editor_from_file_full(CMD_DELETE, fd, file_util_delete_ext_cb, NULL)))