annotate src/editors.c @ 9:d907d608745f

Sync to GQview 1.5.9 release. ######## DO NOT BASE ENHANCEMENTS OR TRANSLATION UPDATES ON CODE IN THIS CVS! This CVS is never up to date with current development and is provided solely for reference purposes, please use the latest official release package when making any changes or translation updates. ########
author gqview
date Sat, 26 Feb 2005 00:13:35 +0000
parents
children 9c0c402b0ef3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
1 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
2 * GQview
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
3 * (C) 2004 John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
4 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * This software comes with no warranty of any kind, use at your own risk!
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
11
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
13 #include "gqview.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
14 #include "editors.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
16 #include "utilops.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
17 #include "ui_fileops.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
18 #include "ui_spinner.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
19 #include "ui_utildlg.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
20
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
21 #include <errno.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
22
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
24 #define EDITOR_WINDOW_WIDTH 500
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
25 #define EDITOR_WINDOW_HEIGHT 300
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
26
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
27 #define COMMAND_SHELL "sh"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
28 #define COMMAND_OPT "-c"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
29
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
30
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
31 typedef struct _EditorVerboseData EditorVerboseData;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
32 struct _EditorVerboseData {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33 int fd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
35 GenericDialog *gd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
36 GtkWidget *button_close;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
37 GtkWidget *button_stop;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
38 GtkWidget *text;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39 GtkWidget *progress;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
40 GtkWidget *spinner;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41 gint count;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42 gint total;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
43
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
44 gchar *command_template;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
45 GList *list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
46 };
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
47
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49 static gchar *editor_slot_defaults[] = {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
50 N_("The Gimp"), "gimp-remote -n %f",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
51 N_("XV"), "xv %f",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52 N_("Xpaint"), "xpaint %f",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
53 NULL, NULL,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
54 NULL, NULL,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
55 NULL, NULL,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
56 NULL, NULL,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
57 NULL, NULL,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
58 N_("Rotate jpeg clockwise"), "%vif jpegtran -rotate 90 -copy all -outfile %p_tmp %p; then mv %p_tmp %p;else rm %p_tmp;fi",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59 N_("Rotate jpeg counterclockwise"), "%vif jpegtran -rotate 270 -copy all -outfile %p_tmp %p; then mv %p_tmp %p;else rm %p_tmp;fi",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
60 NULL, NULL
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
61 };
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
62
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
63
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
64 static void editor_verbose_window_progress(EditorVerboseData *vd, const gchar *text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
65 static gint editor_command_next(EditorVerboseData *vd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
66
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
67
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
68 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
69 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
70 * external editor routines
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
71 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
72 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
73
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
74 void editor_reset_defaults(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
75 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
76 gint i;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
77
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
78 for (i = 0; i < GQVIEW_EDITOR_SLOTS; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
79 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
80 g_free(editor_name[i]);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
81 editor_name[i] = g_strdup(_(editor_slot_defaults[i * 2]));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
82 g_free(editor_command[i]);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
83 editor_command[i] = g_strdup(editor_slot_defaults[i * 2 + 1]);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
84 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
85 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
86
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
87 static void editor_verbose_window_close(GenericDialog *gd, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
88 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
89 EditorVerboseData *vd = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
90
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
91 generic_dialog_close(gd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
92 g_free(vd->command_template);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
93 g_free(vd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
95
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
96 static void editor_verbose_window_stop(GenericDialog *gd, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
97 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98 EditorVerboseData *vd = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
99
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
100 path_list_free(vd->list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101 vd->list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
102
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103 vd->count = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
104 editor_verbose_window_progress(vd, _("stopping..."));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
106
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
107 static void editor_verbose_window_enable_close(EditorVerboseData *vd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
108 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
109 vd->gd->cancel_cb = editor_verbose_window_close;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
110
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
111 spinner_set_interval(vd->spinner, -1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
112 gtk_widget_set_sensitive(vd->button_stop, FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
113 gtk_widget_set_sensitive(vd->button_close, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
114 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
115
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116 static EditorVerboseData *editor_verbose_window(const gchar *template, const gchar *text)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
117 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
118 EditorVerboseData *vd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
119 GtkWidget *scrolled;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
120 GtkWidget *hbox;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
121 gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
122
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
123 vd = g_new0(EditorVerboseData, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
124
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
125 vd->list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126 vd->command_template = g_strdup(template);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
127 vd->total = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
128 vd->count = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
129 vd->fd = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
130
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
131 vd->gd = file_util_gen_dlg(_("Edit command results"), "GQview", "editor_results",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
132 NULL, FALSE,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
133 NULL, vd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
134 buf = g_strdup_printf(_("Output of %s"), text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
135 generic_dialog_add_message(vd->gd, NULL, buf, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
136 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
137 vd->button_stop = generic_dialog_add_button(vd->gd, GTK_STOCK_STOP, NULL,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
138 editor_verbose_window_stop, FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
139 gtk_widget_set_sensitive(vd->button_stop, FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
140 vd->button_close = generic_dialog_add_button(vd->gd, GTK_STOCK_CLOSE, NULL,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141 editor_verbose_window_close, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
142 gtk_widget_set_sensitive(vd->button_close, FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
143
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
144 scrolled = gtk_scrolled_window_new(NULL, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
145 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
146 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
147 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
148 gtk_box_pack_start(GTK_BOX(vd->gd->vbox), scrolled, TRUE, TRUE, 5);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
149 gtk_widget_show(scrolled);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
150
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
151 vd->text = gtk_text_view_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
152 gtk_text_view_set_editable(GTK_TEXT_VIEW(vd->text), FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
153 gtk_widget_set_size_request(vd->text, EDITOR_WINDOW_WIDTH, EDITOR_WINDOW_HEIGHT);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154 gtk_container_add(GTK_CONTAINER(scrolled), vd->text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
155 gtk_widget_show(vd->text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
156
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
157 hbox = gtk_hbox_new(FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
158 gtk_box_pack_start(GTK_BOX(vd->gd->vbox), hbox, FALSE, FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
159 gtk_widget_show(hbox);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
160
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
161 vd->progress = gtk_progress_bar_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
162 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(vd->progress), 0.0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
163 gtk_box_pack_start(GTK_BOX(hbox), vd->progress, TRUE, TRUE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
164 gtk_widget_show(vd->progress);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
165
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
166 vd->spinner = spinner_new(NULL, SPINNER_SPEED);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
167 gtk_box_pack_start(GTK_BOX(hbox), vd->spinner, FALSE, FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
168 gtk_widget_show(vd->spinner);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
169
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
170 gtk_widget_show(vd->gd->dialog);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
171
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
172 return vd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
173 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
174
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
175 static void editor_verbose_window_fill(EditorVerboseData *vd, gchar *text, gint len)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
176 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
177 GtkTextBuffer *buffer;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
178 GtkTextIter iter;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
179
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
180 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(vd->text));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
181 gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
182 gtk_text_buffer_insert(buffer, &iter, text, len);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
183 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
185 static void editor_verbose_window_progress(EditorVerboseData *vd, const gchar *text)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
186 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187 if (vd->total)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
188 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
189 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(vd->progress), (double)vd->count / vd->total);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
190 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
192 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(vd->progress), (text) ? text : "");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
194
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195 static gboolean editor_verbose_io_cb(GIOChannel *source, GIOCondition condition, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 EditorVerboseData *vd = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
198 gchar buf[512];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199 gsize count;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
200
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
201 switch (condition)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
202 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
203 case G_IO_IN:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
204 while (g_io_channel_read_chars(source, buf, sizeof(buf), &count, NULL) == G_IO_STATUS_NORMAL)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
205 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
206 if (!g_utf8_validate(buf, count, NULL))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
207 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
208 gchar *utf8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
209 utf8 = g_locale_to_utf8(buf, count, NULL, NULL, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
210 if (utf8)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
211 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
212 editor_verbose_window_fill(vd, utf8, -1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
213 g_free(utf8);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
214 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217 editor_verbose_window_fill(vd, "GQview: Error converting text to valid utf8\n", -1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222 editor_verbose_window_fill(vd, buf, count);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
223 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
224 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
225 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
226 case G_IO_ERR:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
227 printf("Error reading from command\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228 case G_IO_HUP:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 if (debug) printf("Editor command HUP\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230 default:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231 while (g_source_remove_by_user_data(vd));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232 close(vd->fd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 vd->fd = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234 editor_command_next(vd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
237 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
238
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
239 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
241
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
242 static int command_pipe(char *command)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
243 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
244 char *args[4];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
245 int fpipe[2];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
246 pid_t fpid;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
248 args[0] = COMMAND_SHELL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
249 args[1] = COMMAND_OPT;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
250 args[2] = command;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
251 args[3] = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
252
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
253 if (pipe(fpipe) < 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
255 printf("pipe setup failed: %s\n", strerror(errno));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
256 return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
257 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
259 fpid = fork();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
260 if (fpid < 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
261 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
262 /* fork failed */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
263 printf("fork failed: %s\n", strerror(errno));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
264 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
265 else if (fpid == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
266 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
267 /* child */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
268 gchar *msg;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
269
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
270 dup2(fpipe[1], 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
271 dup2(fpipe[1], 2);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
272 close(fpipe[0]);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
273
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
274 execvp(args[0], args);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
275
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
276 msg = g_strdup_printf("Unable to exec command:\n%s\n\n%s\n", command, strerror(errno));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
277 write(1, msg, strlen(msg));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
278
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
279 _exit(1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
280 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
281 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
282 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
283 /* parent */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
284 fcntl(fpipe[0], F_SETFL, O_NONBLOCK);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
285 close(fpipe[1]);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
286
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
287 return fpipe[0];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
288 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
289
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
290 return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
291 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
292
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
293 static gint editor_verbose_start(EditorVerboseData *vd, gchar *command)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
295 GIOChannel *channel;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
296 int fd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
297
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
298 fd = command_pipe(command);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299 if (fd < 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
300 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301 gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
302
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
303 buf = g_strdup_printf(_("Failed to run command:\n%s\n"), command);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
304 editor_verbose_window_fill(vd, buf, strlen(buf));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
305 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
306
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310 vd->fd = fd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
311 channel = g_io_channel_unix_new(fd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
313 g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, G_IO_IN,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
314 editor_verbose_io_cb, vd, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
315 g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, G_IO_ERR,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
316 editor_verbose_io_cb, vd, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
317 g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, G_IO_HUP,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318 editor_verbose_io_cb, vd, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319 g_io_channel_unref(channel);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
320
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
321 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
322 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
323
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
324 static gint editor_command_one(const gchar *template, const gchar *path, EditorVerboseData *vd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
325 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
326 GString *result = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
328 gchar *found;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
329 const gchar *ptr;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330 gchar path_buffer[512];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
331 gchar *current_path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
332 gint path_change = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
333 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
334
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
335 current_path = getcwd(path_buffer, sizeof(path_buffer));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
336
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
337 result = g_string_new("");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338 pathl = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
339
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
340 ptr = template;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
341 while ( (found = strstr(ptr, "%p")) )
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
342 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343 result = g_string_append_len(result, ptr, found - ptr);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
344 ptr = found + 2;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
345 result = g_string_append_c(result, '"');
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
346 result = g_string_append(result, pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
347 result = g_string_append_c(result, '"');
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
348 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
349 result = g_string_append(result, ptr);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
350
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
351 if (debug) printf("system command: %s\n", result->str);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
352
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 if (current_path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
354 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
355 gchar *base;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
356 base = remove_level_from_path(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
357 if (chdir(base) == 0) path_change = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
358 g_free(base);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
360
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
361 if (vd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
362 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
363 result = g_string_append(result, " 2>&1");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
364 ret = editor_verbose_start(vd, result->str);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
365 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
366 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
367 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
368 ret = system(result->str);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
369 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
370
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
371 if (path_change) chdir(current_path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
372
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
373 g_string_free(result, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
374 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379 static gint editor_command_next(EditorVerboseData *vd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
381 const gchar *text;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
383 editor_verbose_window_fill(vd, "\n", 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
384
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385 while (vd->list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
386 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
387 gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
388 gint success;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
389
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
390 path = vd->list->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
391 vd->list = g_list_remove(vd->list, path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
392
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 editor_verbose_window_progress(vd, path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395 vd->count++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
396 success = editor_command_one(vd->command_template, path, vd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 if (success)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
398 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
399 gtk_widget_set_sensitive(vd->button_stop, (vd->list != NULL) );
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400 editor_verbose_window_fill(vd, path, strlen(path));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401 editor_verbose_window_fill(vd, "\n", 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
402 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
403
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404 g_free(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
405 if (success) return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
406 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
408 if (vd->count == vd->total)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
409 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410 text = _("done");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
412 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
413 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414 text = _("stopped by user");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416 vd->count = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417 editor_verbose_window_progress(vd, text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418 editor_verbose_window_enable_close(vd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
421
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
422 static void editor_command_start(const gchar *template, const gchar *text, GList *list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
424 EditorVerboseData *vd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426 vd = editor_verbose_window(template, text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427 vd->list = path_list_copy(list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428 vd->total = g_list_length(list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430 editor_command_next(vd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
432
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
433 static gint editor_line_break(const gchar *template, gchar **front, const gchar **end)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
435 gchar *found;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
436
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437 *front = g_strdup(template);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
438 found = strstr(*front, "%f");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
439
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
440 if (found)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
441 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
442 *found = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
443 *end = found + 2;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
444 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
445 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447 *end = "";
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452 * The supported macros for editor commands:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
454 * %f first occurence replaced by quoted sequence of filenames, command is run once.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
455 * only one occurence of this macro is supported.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
456 * ([ls %f] results in [ls "file1" "file2" ... "lastfile"])
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457 * %p command is run for each filename in turn, each instance replaced with single filename.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458 * multiple occurences of this macro is supported for complex shell commands.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
459 * This macro will BLOCK THE APPLICATION until it completes, since command is run once
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
460 * for every file in syncronous order. To avoid blocking add the %v macro, below.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
461 * ([ls %p] results in [ls "file1"], [ls "file2"] ... [ls "lastfile"])
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462 * none if no macro is supplied, the result is equivalent to "command %f"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
463 * ([ls] results in [ls "file1" "file2" ... "lastfile"])
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
464 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465 * Only one of the macros %f or %p may be used in a given commmand.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
467 * %v must be the first two characters in a command, causes a window to display
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
468 * showing the output of the command(s).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
469 * %V same as %v except in the case of %p only displays a window for multiple files,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
470 * operating on a single file is suppresses the output dialog.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
471 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472 static void editor_command_run(const gchar *template, const gchar *text, GList *list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
473 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474 gint verbose = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475 gint for_each = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
476
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
477 if (!template || template[0] == '\0') return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
478
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479 for_each = (strstr(template, "%p") != NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
481 if (strncmp(template, "%v", 2) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
482 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
483 template += 2;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
484 verbose = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
486 else if (strncmp(template, "%V", 2) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
487 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
488 template += 2;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
489 if (!for_each || list->next) verbose = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
491
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
492 if (for_each)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
494 if (verbose)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
495 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
496 editor_command_start(template, text, list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
497 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
499 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
500 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
501
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
502 work = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
503 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
504 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
505 gchar *path = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
506 editor_command_one(template, path, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
507 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
508 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
509 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
510 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
511 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
512 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
513 gchar *front;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
514 const gchar *end;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
515 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
516 GString *result = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
517 gint parser_match;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
518
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
519 parser_match = editor_line_break(template, &front, &end);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
520 result = g_string_new((parser_match) ? "" : " ");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
521
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522 work = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
523 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
524 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
525 gchar *path = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
526 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
527
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
528 if (work != list) g_string_append_c(result, ' ');
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
529 result = g_string_append_c(result, '"');
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
530 pathl = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
531 result = g_string_append(result, pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
532 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
533 result = g_string_append_c(result, '"');
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
534 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
535 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
536
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
537 result = g_string_prepend(result, front);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
538 result = g_string_append(result, end);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
539 if (verbose) result = g_string_append(result, " 2>&1 ");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
540 result = g_string_append(result, "&");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
541
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
542 if (debug) printf("system command: %s\n", result->str);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
544 if (verbose)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
545 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
546 EditorVerboseData *vd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
547
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
548 vd = editor_verbose_window(template, text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
549 editor_verbose_window_progress(vd, _("running..."));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
550 editor_verbose_start(vd, result->str);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
551 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
552 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554 system(result->str);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
556
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
557 g_free(front);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
558 g_string_free(result, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
559 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
560 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
561
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
562 void start_editor_from_path_list(gint n, GList *list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
563 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
564 gchar *command;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
565
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
566 if (n < 0 || n >= GQVIEW_EDITOR_SLOTS || !list ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
567 !editor_command[n] ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
568 strlen(editor_command[n]) == 0) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
569
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
570 command = g_locale_from_utf8(editor_command[n], -1, NULL, NULL, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
571 editor_command_run(command, editor_name[n], list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
572 g_free(command);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
573 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
574
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
575 void start_editor_from_file(gint n, const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
576 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
577 GList *list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
578
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
579 if (!path) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
580
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
581 list = g_list_append(NULL, (gchar *)path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
582 start_editor_from_path_list(n, list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
583 g_list_free(list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
584 }