comparison src/editors.c @ 730:2d8a8e892b5e

Use a struct to handle editor's properties.
author zas_
date Thu, 22 May 2008 08:49:52 +0000
parents 8268cbe682f1
children fa8f7d7396cf
comparison
equal deleted inserted replaced
729:9a6a7e95467a 730:2d8a8e892b5e
54 EditorCallback callback; 54 EditorCallback callback;
55 gpointer data; 55 gpointer data;
56 }; 56 };
57 57
58 58
59 static gchar *editor_slot_defaults[GQ_EDITOR_SLOTS * 2] = { 59 static Editor editor_slot_defaults[GQ_EDITOR_SLOTS] = {
60 N_("The Gimp"), "gimp-remote %{.cr2;.crw;.nef;.raw;*}f", 60 { N_("The Gimp"), "gimp-remote %{.cr2;.crw;.nef;.raw;*}f" },
61 N_("XV"), "xv %f", 61 { N_("XV"), "xv %f" },
62 N_("Xpaint"), "xpaint %f", 62 { N_("Xpaint"), "xpaint %f" },
63 N_("UFraw"), "ufraw %{.cr2;.crw;.nef;.raw}p", 63 { N_("UFraw"), "ufraw %{.cr2;.crw;.nef;.raw}p" },
64 N_("Add XMP sidecar"), "%vFILE=%{.cr2;.crw;.nef;.raw}p;XMP=`echo \"$FILE\"|sed -e 's|\\.[^.]*$|.xmp|'`; exiftool -tagsfromfile \"$FILE\" \"$XMP\"", 64 { N_("Add XMP sidecar"), "%vFILE=%{.cr2;.crw;.nef;.raw}p;XMP=`echo \"$FILE\"|sed -e 's|\\.[^.]*$|.xmp|'`; exiftool -tagsfromfile \"$FILE\" \"$XMP\"" },
65 NULL, NULL, 65 { NULL, NULL },
66 NULL, NULL, 66 { NULL, NULL },
67 NULL, NULL, 67 { NULL, NULL },
68 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", 68 { 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" },
69 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", 69 { 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" },
70 /* special slots */ 70 /* special slots */
71 #if 1 71 #if 1
72 /* for testing */ 72 /* for testing */
73 N_("External Copy command"), "%vset -x;cp %p %d", 73 { N_("External Copy command"), "%vset -x;cp %p %d" },
74 N_("External Move command"), "%vset -x;mv %p %d", 74 { N_("External Move command"), "%vset -x;mv %p %d" },
75 N_("External Rename command"), "%vset -x;mv %p %d", 75 { N_("External Rename command"), "%vset -x;mv %p %d" },
76 N_("External Delete command"), NULL, 76 { N_("External Delete command"), NULL },
77 N_("External New Folder command"), NULL 77 { N_("External New Folder command"), NULL },
78 #else 78 #else
79 N_("External Copy command"), NULL, 79 { N_("External Copy command"), NULL },
80 N_("External Move command"), NULL, 80 { N_("External Move command"), NULL },
81 N_("External Rename command"), NULL, 81 { N_("External Rename command"), NULL },
82 N_("External Delete command"), NULL, 82 { N_("External Delete command"), NULL },
83 N_("External New Folder command"), NULL 83 { N_("External New Folder command"), NULL },
84 #endif 84 #endif
85 }; 85 };
86 86
87 static void editor_verbose_window_progress(EditorData *ed, const gchar *text); 87 static void editor_verbose_window_progress(EditorData *ed, const gchar *text);
88 static gint editor_command_next_start(EditorData *ed); 88 static gint editor_command_next_start(EditorData *ed);
99 { 99 {
100 gint i; 100 gint i;
101 101
102 for (i = 0; i < GQ_EDITOR_SLOTS; i++) 102 for (i = 0; i < GQ_EDITOR_SLOTS; i++)
103 { 103 {
104 g_free(options->editor_name[i]); 104 g_free(options->editor[i].name);
105 options->editor_name[i] = g_strdup(_(editor_slot_defaults[i * 2])); 105 options->editor[i].name = g_strdup(_(editor_slot_defaults[i].name));
106 g_free(options->editor_command[i]); 106 g_free(options->editor[i].command);
107 options->editor_command[i] = g_strdup(editor_slot_defaults[i * 2 + 1]); 107 options->editor[i].command = g_strdup(editor_slot_defaults[i].command);
108 } 108 }
109 } 109 }
110 110
111 static void editor_verbose_data_free(EditorData *ed) 111 static void editor_verbose_data_free(EditorData *ed)
112 { 112 {
795 } 795 }
796 796
797 static gint is_valid_editor_command(gint n) 797 static gint is_valid_editor_command(gint n)
798 { 798 {
799 return (n >= 0 && n < GQ_EDITOR_SLOTS 799 return (n >= 0 && n < GQ_EDITOR_SLOTS
800 && options->editor_command[n] 800 && options->editor[n].command
801 && strlen(options->editor_command[n]) > 0); 801 && strlen(options->editor[n].command) > 0);
802 } 802 }
803 803
804 gint start_editor_from_filelist_full(gint n, GList *list, EditorCallback cb, gpointer data) 804 gint start_editor_from_filelist_full(gint n, GList *list, EditorCallback cb, gpointer data)
805 { 805 {
806 gchar *command; 806 gchar *command;
807 gint error; 807 gint error;
808 808
809 if (!list) return FALSE; 809 if (!list) return FALSE;
810 if (!is_valid_editor_command(n)) return FALSE; 810 if (!is_valid_editor_command(n)) return FALSE;
811 811
812 command = g_locale_from_utf8(options->editor_command[n], -1, NULL, NULL, NULL); 812 command = g_locale_from_utf8(options->editor[n].command, -1, NULL, NULL, NULL);
813 error = editor_command_start(command, options->editor_name[n], list, cb, data); 813 error = editor_command_start(command, options->editor[n].name, list, cb, data);
814 g_free(command); 814 g_free(command);
815 815
816 if (n < GQ_EDITOR_GENERIC_SLOTS && (error & EDITOR_ERROR_MASK)) 816 if (n < GQ_EDITOR_GENERIC_SLOTS && (error & EDITOR_ERROR_MASK))
817 { 817 {
818 gchar *text = g_strdup_printf(_("%s\n#%d \"%s\":\n%s"), editor_get_error_str(error), n+1, 818 gchar *text = g_strdup_printf(_("%s\n#%d \"%s\":\n%s"), editor_get_error_str(error), n+1,
819 options->editor_name[n], options->editor_command[n]); 819 options->editor[n].name, options->editor[n].command);
820 820
821 file_util_warning_dialog(_("Invalid editor command"), text, GTK_STOCK_DIALOG_ERROR, NULL); 821 file_util_warning_dialog(_("Invalid editor command"), text, GTK_STOCK_DIALOG_ERROR, NULL);
822 g_free(text); 822 g_free(text);
823 } 823 }
824 824
850 850
851 gint editor_window_flag_set(gint n) 851 gint editor_window_flag_set(gint n)
852 { 852 {
853 if (!is_valid_editor_command(n)) return TRUE; 853 if (!is_valid_editor_command(n)) return TRUE;
854 854
855 return (editor_command_parse(options->editor_command[n], NULL, NULL) & EDITOR_KEEP_FS); 855 return (editor_command_parse(options->editor[n].command, NULL, NULL) & EDITOR_KEEP_FS);
856 } 856 }
857 857
858 const gchar *editor_get_error_str(gint flags) 858 const gchar *editor_get_error_str(gint flags)
859 { 859 {
860 if (flags & EDITOR_ERROR_EMPTY) return _("Editor template is empty."); 860 if (flags & EDITOR_ERROR_EMPTY) return _("Editor template is empty.");