annotate src/main.c @ 1:b3e0e515fabf

Initial revision
author gqview
date Mon, 03 Apr 2000 18:24:05 +0000
parents
children c0e337a01cb7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1 /*
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
2 * GQview image viewer
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
3 * (C)1999 John Ellis
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
4 *
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
5 * Author: John Ellis
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
6 *
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
7 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
8
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
9 #include "gqview.h"
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
10 #include <gdk/gdkkeysyms.h> /* for keyboard values */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
11
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
12 static void parse_command_line(int argc, char *argv[], gchar **path, gchar **file);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
13 static void setup_default_options();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
14
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
15 /*
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
16 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
17 * path manipulation routines (public)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
18 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
19 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
20
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
21 gchar *filename_from_path(char *t)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
22 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
23 char *p;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
24
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
25 p = t + strlen(t);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
26 while(p > t && p[0] != '/') p--;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
27 if (p[0] == '/') p++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
28 return p;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
29 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
30
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
31 gchar *remove_level_from_path(gchar *path)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
32 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
33 gchar *new_path;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
34 gchar *ptr = path;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
35 gint p;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
36
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
37 if (!path) return NULL;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
38
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
39 p = strlen(path) - 1;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
40 if (p < 0) return NULL;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
41 while(ptr[p] != '/' && p > 0) p--;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
42 if (p == 0 && ptr[p] == '/') p++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
43 new_path = g_strndup(path, (guint)p);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
44 return new_path;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
45 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
46
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
47 void parse_out_relatives(gchar *path)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
48 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
49 gint s, t;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
50
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
51 if (!path) return;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
52
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
53 s = t = 0;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
54
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
55 while (path[s] != '\0')
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
56 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
57 if (path[s] == '/' && path[s+1] == '.' && (path[s+2] == '/' || path[s+2] == '\0') )
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
58 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
59 s += 2;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
60 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
61 else if (path[s] == '/' && path[s+1] == '.' && path[s+2] == '.' && (path[s+3] == '/' || path[s+3] == '\0') )
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
62 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
63 s += 3;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
64 if (t > 0) t--;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
65 while (path[t] != '/' && t > 0) t--;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
66 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
67 else
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
68 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
69 if (s != t) path[t] = path[s];
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
70 t++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
71 s++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
72 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
73 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
74 if (t == 0 && path[t] == '/') t++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
75 if (t > 1 && path[t-1] == '/') t--;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
76 path[t] = '\0';
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
77 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
78
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
79 /*
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
80 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
81 * external editor start routines (public)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
82 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
83 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
84
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
85 void start_editor_from_file(gint n, gchar *path)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
86 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
87 gchar *cmd;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
88 if (!path) return;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
89 cmd = g_strdup_printf("%s \"%s\" &", editor_command[n], path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
90 printf(_("GQview running: %s\n"),cmd);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
91 system(cmd);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
92 g_free(cmd);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
93 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
94
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
95 void start_editor_from_image(gint n)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
96 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
97 start_editor_from_file(n, image_get_path());
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
98 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
99
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
100 void start_editor_from_list(gint n)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
101 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
102 gchar *cmd;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
103 gchar *buf;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
104 GList *list = file_get_selected_list();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
105 GList *work;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
106 if (!list) return;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
107 work = list;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
108 cmd = g_strconcat(editor_command[n], " ", NULL);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
109 while(work)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
110 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
111 buf = cmd;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
112 cmd = g_strconcat(buf, "\"", work->data, "\" ", NULL);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
113 g_free(buf);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
114 work = work->next;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
115 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
116 buf = cmd;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
117 cmd = g_strconcat(buf, "&", NULL);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
118 g_free(buf);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
119 printf(_("GQview running: %s\n"),cmd);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
120 system(cmd);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
121 g_free(cmd);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
122 free_selected_list(list);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
123 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
124
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
125 /*
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
126 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
127 * keyboard functions
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
128 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
129 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
130
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
131 void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
132 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
133 static gint delta = 0;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
134 static guint32 time_old = 0;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
135 static guint keyval_old = 0;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
136
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
137 if (progressive_key_scrolling)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
138 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
139 guint32 time_diff;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
140
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
141 time_diff = event->time - time_old;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
142
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
143 /* key pressed within 125ms ? (1/8 second) */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
144 if (time_diff > 125 || event->keyval != keyval_old) delta = 0;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
145
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
146 time_old = event->time;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
147 keyval_old = event->keyval;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
148
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
149 delta += 2;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
150 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
151 else
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
152 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
153 delta = 8;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
154 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
155
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
156 *x = *x * delta;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
157 *y = *y * delta;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
158 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
159
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
160 gint key_press_cb(GtkWidget *widget, GdkEventKey *event)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
161 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
162 gint stop_signal = FALSE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
163 gint x = 0;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
164 gint y = 0;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
165
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
166 if (GTK_WIDGET_HAS_FOCUS(path_entry))
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
167 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
168 if (event->keyval == GDK_Escape)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
169 gtk_entry_set_text(GTK_ENTRY(path_entry), current_path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
170 return stop_signal;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
171 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
172
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
173 if (full_screen_window || GTK_WIDGET_HAS_FOCUS(main_image->viewport))
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
174 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
175 switch (event->keyval)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
176 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
177 case GDK_Left:
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
178 x -= 1;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
179 stop_signal = TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
180 break;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
181 case GDK_Right:
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
182 x += 1;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
183 stop_signal = TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
184 break;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
185 case GDK_Up:
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
186 y -= 1;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
187 stop_signal = TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
188 break;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
189 case GDK_Down:
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
190 y += 1;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
191 stop_signal = TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
192 break;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
193 case GDK_BackSpace:
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
194 file_prev_image();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
195 stop_signal = TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
196 break;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
197 case GDK_space:
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
198 file_next_image();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
199 stop_signal = TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
200 break;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
201 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
202 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
203
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
204 switch (event->keyval)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
205 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
206 case '+':
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
207 image_adjust_zoom(1);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
208 break;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
209 case GDK_Page_Up:
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
210 file_prev_image();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
211 stop_signal = TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
212 break;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
213 case GDK_Page_Down:
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
214 file_next_image();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
215 stop_signal = TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
216 break;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
217 case GDK_Home:
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
218 file_first_image();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
219 stop_signal = TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
220 break;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
221 case GDK_End:
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
222 file_last_image();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
223 stop_signal = TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
224 break;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
225 case GDK_Delete:
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
226 file_util_delete(image_get_path(), NULL);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
227 stop_signal = TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
228 break;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
229 case GDK_Escape:
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
230 interrupt_thumbs();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
231 stop_signal = TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
232 break;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
233 case 'Q': case 'q':
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
234 if (event->state == 0 || (event->state & GDK_MODIFIER_MASK) == GDK_LOCK_MASK)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
235 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
236 exit_gqview();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
237 return FALSE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
238 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
239 break;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
240 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
241
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
242 if (event->state & GDK_SHIFT_MASK)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
243 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
244 x *= 3;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
245 y *= 3;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
246 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
247
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
248 if (x != 0 || y!= 0)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
249 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
250 keyboard_scroll_calc(&x, &y, event);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
251 image_scroll(x, y);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
252 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
253
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
254 if (stop_signal) gtk_signal_emit_stop_by_name(GTK_OBJECT(widget), "key_press_event");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
255
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
256 return stop_signal;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
257 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
258
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
259 /*
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
260 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
261 * command line parser (private)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
262 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
263 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
264
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
265 static void parse_command_line(int argc, char *argv[], gchar **path, gchar **file)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
266 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
267 if (argc > 1)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
268 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
269 gint i;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
270 gchar *base_dir = get_current_dir();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
271 i = 1;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
272 while (i < argc)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
273 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
274 gchar *cmd_line = argv[i];
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
275 gchar *cmd_all = g_strconcat(base_dir, "/", cmd_line, NULL);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
276
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
277 if (!*path && cmd_line[0] == '/' && isdir(cmd_line))
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
278 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
279 *path = g_strdup(cmd_line);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
280 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
281 else if (!*path && isdir(cmd_all))
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
282 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
283 *path = g_strdup(cmd_all);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
284 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
285 else if (!*file && cmd_line[0] == '/' && isfile(cmd_line))
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
286 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
287 g_free(*path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
288 *path = remove_level_from_path(cmd_line);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
289 *file = g_strdup(cmd_line);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
290 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
291 else if (!*file && isfile(cmd_all))
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
292 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
293 g_free(*path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
294 *path = remove_level_from_path(cmd_all);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
295 *file = g_strdup(cmd_all);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
296 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
297 else if (strcmp(cmd_line, "-debug") == 0)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
298 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
299 debug = TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
300 printf("debugging output enabled\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
301 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
302 else if (strcmp(cmd_line, "+t") == 0 ||
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
303 strcmp(cmd_line, "+tools") == 0)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
304 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
305 tools_float = FALSE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
306 tools_hidden = FALSE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
307 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
308 else if (strcmp(cmd_line, "-t") == 0 ||
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
309 strcmp(cmd_line, "-tools") == 0)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
310 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
311 tools_hidden = TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
312 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
313 else if (strcmp(cmd_line, "-help") == 0)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
314 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
315 printf("GQview version %s\n", VERSION);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
316 printf(_("Usage: gqview [options] [path]\n\n"));
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
317 printf(_("valid options are:\n"));
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
318 printf(_(" +t, +tools force show of tools\n"));
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
319 printf(_(" -t, -tools force hide of tools\n"));
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
320 printf(_(" -debug turn on debug output\n"));
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
321 printf(_(" -help this message\n\n"));
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
322 exit (0);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
323 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
324 else
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
325 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
326 printf(_("invalid or ignored: %s\nUse -help for options\n"), cmd_line);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
327 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
328 g_free(cmd_all);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
329 i++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
330 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
331 g_free(base_dir);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
332 parse_out_relatives(*path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
333 parse_out_relatives(*file);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
334 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
335 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
336
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
337 /*
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
338 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
339 * startup, init, and exit
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
340 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
341 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
342
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
343 static void setup_default_options()
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
344 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
345 gint i;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
346
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
347 for(i=0; i<8; i++)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
348 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
349 editor_name[i] = NULL;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
350 editor_command[i] = NULL;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
351 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
352
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
353 editor_name[0] = g_strdup(_("The Gimp"));
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
354 editor_command[0] = g_strdup("gimp");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
355
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
356 editor_name[1] = g_strdup(_("Electric Eyes"));
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
357 editor_command[1] = g_strdup("ee");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
358
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
359 editor_name[2] = g_strdup(_("XV"));
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
360 editor_command[2] = g_strdup("xv");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
361
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
362 editor_name[3] = g_strdup(_("Xpaint"));
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
363 editor_command[3] = g_strdup("xpaint");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
364
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
365 custom_filter = g_strdup(".eim;");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
366 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
367
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
368 void exit_gqview()
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
369 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
370 full_screen_stop();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
371
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
372 gdk_window_get_position (mainwindow->window, &main_window_x, &main_window_y);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
373 gdk_window_get_size(mainwindow->window, &main_window_w, &main_window_h);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
374
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
375 if (toolwindow)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
376 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
377 gdk_window_get_position (toolwindow->window, &float_window_x, &float_window_y);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
378 gdk_window_get_size(toolwindow->window, &float_window_w, &float_window_h);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
379 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
380 save_options();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
381
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
382 gtk_main_quit();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
383 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
384
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
385 int main (int argc, char *argv[])
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
386 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
387 gchar *cmd_path = NULL;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
388 gchar *cmd_file = NULL;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
389
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
390 /* setup locale, i18n */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
391 gtk_set_locale();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
392 bindtextdomain (PACKAGE, LOCALEDIR);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
393 textdomain (PACKAGE);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
394
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
395 /* setup random seed for random slideshow */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
396 srand (time (0));
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
397
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
398 gtk_init (&argc, &argv);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
399 gdk_imlib_init();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
400
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
401 /* push the correct color depths to gtk, (for 8-bit psuedo color displays)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
402 * they should be popped, too, I guess...
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
403 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
404 gtk_widget_push_visual(gdk_imlib_get_visual());
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
405 gtk_widget_push_colormap(gdk_imlib_get_colormap());
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
406
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
407 setup_default_options();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
408 load_options();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
409
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
410 parse_command_line(argc, argv, &cmd_path, &cmd_file);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
411
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
412 if (cmd_path)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
413 current_path = g_strdup(cmd_path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
414 else if (startup_path_enable && startup_path && isdir(startup_path))
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
415 current_path = g_strdup(startup_path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
416 else
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
417 current_path = get_current_dir();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
418
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
419 create_main_window();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
420 update_edit_menus(mainwindow_accel_grp);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
421 rebuild_file_filter();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
422 filelist_refresh();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
423
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
424 init_dnd();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
425
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
426 while(gtk_events_pending()) gtk_main_iteration();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
427 image_change_to(cmd_file);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
428
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
429 g_free(cmd_path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
430 g_free(cmd_file);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
431
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
432 gtk_main ();
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
433 return 0;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
434 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
435
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
436