Mercurial > geeqie.yaz
annotate src/main.c @ 409:319cd8857399
replace inner loops with memcpy
author | nadvornik |
---|---|
date | Fri, 18 Apr 2008 21:30:12 +0000 |
parents | 2649a28d31b6 |
children | eb5ae19a62f6 |
rev | line source |
---|---|
1 | 1 /* |
196 | 2 * Geeqie |
79
528e3432e0c0
Thu Oct 19 07:23:37 2006 John Ellis <johne@verizon.net>
gqview
parents:
76
diff
changeset
|
3 * (C) 2006 John Ellis |
1 | 4 * |
5 * Author: John Ellis | |
6 * | |
9 | 7 * This software is released under the GNU General Public License (GNU GPL). |
8 * Please read the included file COPYING for more information. | |
9 * This software comes with no warranty of any kind, use at your own risk! | |
1 | 10 */ |
11 | |
9 | 12 |
281 | 13 #include "main.h" |
9 | 14 |
15 #include "cache.h" | |
16 #include "collect.h" | |
17 #include "collect-io.h" | |
18 #include "dnd.h" | |
19 #include "editors.h" | |
20 #include "filelist.h" | |
354
5c82855feba7
Add a button to reset fullscreen info string to default value.
zas_
parents:
341
diff
changeset
|
21 #include "fullscreen.h" |
218
f4a0555794a9
Customizable info overlay in fullscreen, based on the patch posted to gqview-devel list by Timo on 2007-09-10.
zas_
parents:
214
diff
changeset
|
22 #include "image-overlay.h" |
9 | 23 #include "img-view.h" |
24 #include "layout.h" | |
25 #include "layout_image.h" | |
26 #include "menu.h" | |
91
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
27 #include "pixbuf_util.h" |
9 | 28 #include "preferences.h" |
29 #include "rcfile.h" | |
30 #include "remote.h" | |
31 #include "similar.h" | |
32 #include "slideshow.h" | |
33 #include "utilops.h" | |
34 #include "ui_bookmark.h" | |
35 #include "ui_help.h" | |
36 #include "ui_fileops.h" | |
37 #include "ui_tabcomp.h" | |
38 #include "ui_utildlg.h" | |
39 | |
1 | 40 #include <gdk/gdkkeysyms.h> /* for keyboard values */ |
41 | |
9 | 42 |
43 #include <math.h> | |
44 | |
45 | |
279 | 46 static RemoteConnection *remote_connection = NULL; |
47 static CollectionData *command_collection = NULL; | |
9 | 48 |
1 | 49 |
50 /* | |
51 *----------------------------------------------------------------------------- | |
9 | 52 * misc (public) |
1 | 53 *----------------------------------------------------------------------------- |
54 */ | |
55 | |
289
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
56 GtkWidget *window_new(GtkWindowType type, const gchar *name, const gchar *icon, |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
57 const gchar *icon_file, const gchar *subtitle) |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
58 { |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
59 gchar *title; |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
60 GtkWidget *window; |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
61 |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
62 window = gtk_window_new(type); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
63 if (!window) return NULL; |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
64 |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
65 if (subtitle) |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
66 { |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
67 title = g_strdup_printf("%s - %s", subtitle, GQ_APPNAME); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
68 } |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
69 else |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
70 { |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
71 title = g_strdup_printf("%s", GQ_APPNAME); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
72 } |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
73 |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
74 gtk_window_set_title(GTK_WINDOW(window), title); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
75 g_free(title); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
76 |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
77 window_set_icon(window, icon, icon_file); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
78 gtk_window_set_role(GTK_WINDOW(window), name); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
79 gtk_window_set_wmclass(GTK_WINDOW(window), name, GQ_WMCLASS); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
80 |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
81 return window; |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
82 } |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
83 |
91
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
84 void window_set_icon(GtkWidget *window, const gchar *icon, const gchar *file) |
1 | 85 { |
91
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
86 if (!icon && !file) icon = PIXBUF_INLINE_ICON; |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
87 |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
88 if (icon) |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
89 { |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
90 GdkPixbuf *pixbuf; |
1 | 91 |
91
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
92 pixbuf = pixbuf_inline(icon); |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
93 if (pixbuf) |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
94 { |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
95 gtk_window_set_icon(GTK_WINDOW(window), pixbuf); |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
96 g_object_unref(pixbuf); |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
97 } |
9 | 98 } |
99 else | |
100 { | |
91
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
101 gtk_window_set_icon_from_file(GTK_WINDOW(window), file, NULL); |
9 | 102 } |
103 } | |
1 | 104 |
9 | 105 gint window_maximized(GtkWidget *window) |
106 { | |
107 GdkWindowState state; | |
108 | |
109 if (!window || !window->window) return FALSE; | |
110 | |
111 state = gdk_window_get_state(window->window); | |
112 return (state & GDK_WINDOW_STATE_MAXIMIZED); | |
113 } | |
114 | |
115 gdouble get_zoom_increment(void) | |
116 { | |
334 | 117 return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 10.0 : 1.0); |
1 | 118 } |
119 | |
386
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
120 const gchar *get_exec_time() |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
121 { |
387 | 122 static gchar timestr[20]; |
386
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
123 static struct timeval start_tv = {0, 0}; |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
124 |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
125 struct timeval tv = {0, 0}; |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
126 |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
127 gettimeofday(&tv, NULL); |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
128 |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
129 if (start_tv.tv_sec == 0) start_tv = tv; |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
130 |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
131 tv.tv_sec -= start_tv.tv_sec; |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
132 if (tv.tv_usec >= start_tv.tv_usec) |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
133 tv.tv_usec -= start_tv.tv_usec; |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
134 else |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
135 { |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
136 tv.tv_usec += 1000000 - start_tv.tv_usec; |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
137 tv.tv_sec -= 1; |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
138 } |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
139 |
387 | 140 g_snprintf(timestr, sizeof(timestr), "%5d.%06d", (int)tv.tv_sec, (int)tv.tv_usec); |
386
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
141 |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
142 return timestr; |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
143 } |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
144 |
1 | 145 /* |
146 *----------------------------------------------------------------------------- | |
9 | 147 * Open browser with the help Documentation |
148 *----------------------------------------------------------------------------- | |
149 */ | |
150 | |
151 static gchar *command_result(const gchar *binary, const gchar *command) | |
152 { | |
153 gchar *result = NULL; | |
154 FILE *f; | |
155 char buf[2048]; | |
156 int l; | |
157 | |
158 if (!binary) return NULL; | |
159 if (!file_in_path(binary)) return NULL; | |
160 | |
161 if (!command) return g_strdup(binary); | |
162 if (command[0] == '!') return g_strdup(command + 1); | |
163 | |
164 f = popen(command, "r"); | |
165 if (!f) return NULL; | |
166 | |
167 while ((l = fread(buf, sizeof(char), sizeof(buf), f)) > 0) | |
168 { | |
169 if (!result) | |
170 { | |
171 int n = 0; | |
172 | |
173 while (n < l && buf[n] != '\n' && buf[n] != '\r') n++; | |
174 if (n > 0) result = g_strndup(buf, n); | |
175 } | |
176 } | |
177 | |
178 pclose(f); | |
179 | |
180 return result; | |
181 } | |
182 | |
183 static void help_browser_command(const gchar *command, const gchar *path) | |
184 { | |
185 gchar *result; | |
186 gchar *buf; | |
187 gchar *begin; | |
188 gchar *end; | |
189 | |
190 if (!command || !path) return; | |
191 | |
192 if (debug) printf("Help command pre \"%s\", \"%s\"\n", command, path); | |
193 | |
194 buf = g_strdup(command); | |
195 begin = strstr(buf, "%s"); | |
196 if (begin) | |
197 { | |
198 *begin = '\0'; | |
199 end = begin + 2; | |
200 begin = buf; | |
201 | |
202 result = g_strdup_printf("%s%s%s &", begin, path, end); | |
203 } | |
204 else | |
205 { | |
206 result = g_strdup_printf("%s \"%s\" &", command, path); | |
207 } | |
208 g_free(buf); | |
209 | |
210 if (debug) printf("Help command post [%s]\n", result); | |
211 | |
212 system(result); | |
213 | |
214 g_free(result); | |
215 } | |
216 | |
217 /* | |
218 * each set of 2 strings is one browser: | |
219 * the 1st is the binary to look for in the path | |
220 * the 2nd has 3 capabilities: | |
221 * NULL exec binary with html file path as command line | |
222 * string exec string and use results for command line | |
223 * !string use text following ! as command line, replacing optional %s with html file path | |
224 */ | |
225 static gchar *html_browsers[] = | |
226 { | |
227 /* Redhat has a nifty htmlview script to start the user's preferred browser */ | |
228 "htmlview", NULL, | |
229 /* GNOME 2 */ | |
230 "gconftool-2", "gconftool-2 -g /desktop/gnome/url-handlers/http/command", | |
231 /* KDE */ | |
232 "kfmclient", "!kfmclient exec \"%s\"", | |
233 /* use fallbacks */ | |
234 "firefox", NULL, | |
235 "mozilla", NULL, | |
236 "konqueror", NULL, | |
237 "netscape", NULL, | |
238 NULL, NULL | |
239 }; | |
240 | |
241 static void help_browser_run(void) | |
242 { | |
243 gchar *result = NULL; | |
244 gint i; | |
245 | |
246 i = 0; | |
247 while (!result && html_browsers[i]) | |
248 { | |
249 result = command_result(html_browsers[i], html_browsers[i+1]); | |
250 i += 2; | |
251 } | |
252 | |
253 if (!result) | |
254 { | |
255 printf("Unable to detect an installed browser.\n"); | |
256 return; | |
257 } | |
258 | |
283 | 259 help_browser_command(result, GQ_HTMLDIR "/index.html"); |
9 | 260 |
261 g_free(result); | |
262 } | |
263 | |
264 /* | |
265 *----------------------------------------------------------------------------- | |
266 * help window | |
1 | 267 *----------------------------------------------------------------------------- |
268 */ | |
269 | |
9 | 270 static GtkWidget *help_window = NULL; |
271 | |
272 static void help_window_destroy_cb(GtkWidget *window, gpointer data) | |
1 | 273 { |
9 | 274 help_window = NULL; |
1 | 275 } |
276 | |
9 | 277 void help_window_show(const gchar *key) |
1 | 278 { |
9 | 279 if (key && strcmp(key, "html_contents") == 0) |
280 { | |
281 help_browser_run(); | |
282 return; | |
283 } | |
284 | |
285 if (help_window) | |
1 | 286 { |
9 | 287 gtk_window_present(GTK_WINDOW(help_window)); |
288 if (key) help_window_set_key(help_window, key); | |
289 return; | |
1 | 290 } |
9 | 291 |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
292 { |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
293 gchar *title = g_strdup_printf("%s - %s", _("Help"), GQ_APPNAME); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
294 help_window = help_window_new(title, GQ_WMCLASS, "help", |
283 | 295 GQ_HELPDIR "/README", key); |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
296 g_free(title); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
297 } |
9 | 298 g_signal_connect(G_OBJECT(help_window), "destroy", |
299 G_CALLBACK(help_window_destroy_cb), NULL); | |
1 | 300 } |
301 | |
9 | 302 |
1 | 303 /* |
304 *----------------------------------------------------------------------------- | |
305 * keyboard functions | |
306 *----------------------------------------------------------------------------- | |
307 */ | |
308 | |
309 void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event) | |
310 { | |
311 static gint delta = 0; | |
312 static guint32 time_old = 0; | |
313 static guint keyval_old = 0; | |
314 | |
9 | 315 if (event->state & GDK_CONTROL_MASK) |
316 { | |
317 if (*x < 0) *x = G_MININT / 2; | |
318 if (*x > 0) *x = G_MAXINT / 2; | |
319 if (*y < 0) *y = G_MININT / 2; | |
320 if (*y > 0) *y = G_MAXINT / 2; | |
321 | |
322 return; | |
323 } | |
324 | |
318 | 325 if (options->progressive_key_scrolling) |
1 | 326 { |
327 guint32 time_diff; | |
328 | |
329 time_diff = event->time - time_old; | |
330 | |
331 /* key pressed within 125ms ? (1/8 second) */ | |
332 if (time_diff > 125 || event->keyval != keyval_old) delta = 0; | |
333 | |
334 time_old = event->time; | |
335 keyval_old = event->keyval; | |
336 | |
337 delta += 2; | |
338 } | |
339 else | |
340 { | |
341 delta = 8; | |
342 } | |
343 | |
344 *x = *x * delta; | |
345 *y = *y * delta; | |
346 } | |
347 | |
9 | 348 |
349 /* | |
350 *----------------------------------------------------------------------------- | |
351 * remote functions | |
352 *----------------------------------------------------------------------------- | |
353 */ | |
354 | |
355 static void gr_image_next(const gchar *text, gpointer data) | |
356 { | |
357 layout_image_next(NULL); | |
358 } | |
359 | |
360 static void gr_image_prev(const gchar *text, gpointer data) | |
361 { | |
362 layout_image_prev(NULL); | |
363 } | |
364 | |
365 static void gr_image_first(const gchar *text, gpointer data) | |
366 { | |
367 layout_image_first(NULL); | |
368 } | |
369 | |
370 static void gr_image_last(const gchar *text, gpointer data) | |
371 { | |
372 layout_image_last(NULL); | |
373 } | |
374 | |
375 static void gr_fullscreen_toggle(const gchar *text, gpointer data) | |
376 { | |
377 layout_image_full_screen_toggle(NULL); | |
378 } | |
379 | |
380 static void gr_fullscreen_start(const gchar *text, gpointer data) | |
1 | 381 { |
9 | 382 layout_image_full_screen_start(NULL); |
383 } | |
384 | |
385 static void gr_fullscreen_stop(const gchar *text, gpointer data) | |
386 { | |
387 layout_image_full_screen_stop(NULL); | |
388 } | |
389 | |
390 static void gr_slideshow_start_rec(const gchar *text, gpointer data) | |
391 { | |
392 GList *list; | |
393 | |
394 list = path_list_recursive(text); | |
395 if (!list) return; | |
214 | 396 //printf("length: %d\n", g_list_length(list)); |
9 | 397 layout_image_slideshow_stop(NULL); |
398 layout_image_slideshow_start_from_list(NULL, list); | |
399 } | |
1 | 400 |
9 | 401 static void gr_slideshow_toggle(const gchar *text, gpointer data) |
402 { | |
403 layout_image_slideshow_toggle(NULL); | |
404 } | |
405 | |
406 static void gr_slideshow_start(const gchar *text, gpointer data) | |
407 { | |
408 layout_image_slideshow_start(NULL); | |
409 } | |
410 | |
411 static void gr_slideshow_stop(const gchar *text, gpointer data) | |
412 { | |
413 layout_image_slideshow_stop(NULL); | |
414 } | |
415 | |
416 static void gr_slideshow_delay(const gchar *text, gpointer data) | |
417 { | |
418 gdouble n; | |
419 | |
420 n = strtod(text, NULL); | |
421 if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS) | |
1 | 422 { |
403 | 423 printf_term("Remote slideshow delay out of range (%.1f to %.1f)\n", |
424 SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS); | |
9 | 425 return; |
426 } | |
326 | 427 options->slideshow.delay = (gint)(n * 10.0 + 0.01); |
9 | 428 } |
429 | |
430 static void gr_tools_show(const gchar *text, gpointer data) | |
431 { | |
432 gint popped; | |
433 gint hidden; | |
434 | |
435 if (layout_tools_float_get(NULL, &popped, &hidden) && hidden) | |
436 { | |
437 layout_tools_float_set(NULL, popped, FALSE); | |
1 | 438 } |
9 | 439 } |
1 | 440 |
9 | 441 static void gr_tools_hide(const gchar *text, gpointer data) |
442 { | |
443 gint popped; | |
444 gint hidden; | |
445 | |
446 if (layout_tools_float_get(NULL, &popped, &hidden) && !hidden) | |
1 | 447 { |
9 | 448 layout_tools_float_set(NULL, popped, TRUE); |
449 } | |
450 } | |
451 | |
452 static gint gr_quit_idle_cb(gpointer data) | |
453 { | |
278 | 454 exit_program(); |
9 | 455 |
456 return FALSE; | |
457 } | |
458 | |
459 static void gr_quit(const gchar *text, gpointer data) | |
460 { | |
461 /* schedule exit when idle, if done from within a | |
462 * remote handler remote_close will crash | |
463 */ | |
464 g_idle_add(gr_quit_idle_cb, NULL); | |
465 } | |
466 | |
467 static void gr_file_load(const gchar *text, gpointer data) | |
468 { | |
469 if (isfile(text)) | |
470 { | |
471 if (file_extension_match(text, ".gqv")) | |
1 | 472 { |
9 | 473 collection_window_new(text); |
474 } | |
475 else | |
476 { | |
477 layout_set_path(NULL, text); | |
1 | 478 } |
479 } | |
9 | 480 else if (isdir(text)) |
481 { | |
482 layout_set_path(NULL, text); | |
483 } | |
484 else | |
485 { | |
486 printf("remote sent filename that does not exist:\"%s\"\n", text); | |
487 } | |
488 } | |
489 | |
490 static void gr_file_view(const gchar *text, gpointer data) | |
491 { | |
138 | 492 view_window_new(file_data_new_simple(text)); |
9 | 493 } |
494 | |
495 static void gr_list_clear(const gchar *text, gpointer data) | |
496 { | |
279 | 497 if (command_collection) collection_unref(command_collection); |
498 command_collection = NULL; | |
9 | 499 } |
500 | |
501 static void gr_list_add(const gchar *text, gpointer data) | |
502 { | |
503 gint new = TRUE; | |
504 | |
279 | 505 if (!command_collection) |
9 | 506 { |
507 CollectionData *cd; | |
508 | |
509 cd = collection_new(""); | |
510 | |
511 g_free(cd->path); | |
512 cd->path = NULL; | |
513 g_free(cd->name); | |
514 cd->name = g_strdup(_("Command line")); | |
515 | |
279 | 516 command_collection = cd; |
9 | 517 } |
518 else | |
519 { | |
279 | 520 new = (!collection_get_first(command_collection)); |
9 | 521 } |
1 | 522 |
279 | 523 if (collection_add(command_collection, file_data_new_simple(text), FALSE) && new) |
9 | 524 { |
279 | 525 layout_image_set_collection(NULL, command_collection, |
526 collection_get_first(command_collection)); | |
9 | 527 } |
528 } | |
529 | |
530 static void gr_raise(const gchar *text, gpointer data) | |
531 { | |
532 LayoutWindow *lw = NULL; | |
533 | |
534 if (layout_valid(&lw)) | |
535 { | |
536 gtk_window_present(GTK_WINDOW(lw->window)); | |
537 } | |
538 } | |
539 | |
540 typedef struct _RemoteCommandEntry RemoteCommandEntry; | |
541 struct _RemoteCommandEntry { | |
542 gchar *opt_s; | |
543 gchar *opt_l; | |
544 void (*func)(const gchar *text, gpointer data); | |
545 gint needs_extra; | |
546 gint prefer_command_line; | |
547 gchar *description; | |
548 }; | |
549 | |
550 static RemoteCommandEntry remote_commands[] = { | |
551 /* short, long callback, extra, prefer,description */ | |
552 { "-n", "--next", gr_image_next, FALSE, FALSE, N_("next image") }, | |
553 { "-b", "--back", gr_image_prev, FALSE, FALSE, N_("previous image") }, | |
554 { NULL, "--first", gr_image_first, FALSE, FALSE, N_("first image") }, | |
555 { NULL, "--last", gr_image_last, FALSE, FALSE, N_("last image") }, | |
556 { "-f", "--fullscreen", gr_fullscreen_toggle, FALSE, TRUE, N_("toggle full screen") }, | |
557 { "-fs","--fullscreen-start", gr_fullscreen_start, FALSE, FALSE, N_("start full screen") }, | |
558 { "-fS","--fullscreen-stop", gr_fullscreen_stop, FALSE, FALSE, N_("stop full screen") }, | |
559 { "-s", "--slideshow", gr_slideshow_toggle, FALSE, TRUE, N_("toggle slide show") }, | |
560 { "-ss","--slideshow-start", gr_slideshow_start, FALSE, FALSE, N_("start slide show") }, | |
561 { "-sS","--slideshow-stop", gr_slideshow_stop, FALSE, FALSE, N_("stop slide show") }, | |
562 { "-sr","--slideshow-recurse", gr_slideshow_start_rec, TRUE, FALSE, N_("start recursive slide show") }, | |
563 { "-d", "--delay=", gr_slideshow_delay, TRUE, FALSE, N_("set slide show delay in seconds") }, | |
564 { "+t", "--tools-show", gr_tools_show, FALSE, TRUE, N_("show tools") }, | |
565 { "-t", "--tools-hide", gr_tools_hide, FALSE, TRUE, N_("hide tools") }, | |
566 { "-q", "--quit", gr_quit, FALSE, FALSE, N_("quit") }, | |
567 { NULL, "file:", gr_file_load, TRUE, FALSE, N_("open file") }, | |
568 { NULL, "view:", gr_file_view, TRUE, FALSE, N_("open file in new window") }, | |
569 { NULL, "--list-clear", gr_list_clear, FALSE, FALSE, NULL }, | |
570 { NULL, "--list-add:", gr_list_add, TRUE, FALSE, NULL }, | |
571 { NULL, "raise", gr_raise, FALSE, FALSE, NULL }, | |
572 { NULL, NULL, NULL, FALSE, FALSE, NULL } | |
573 }; | |
574 | |
279 | 575 static RemoteCommandEntry *remote_command_find(const gchar *text, const gchar **offset) |
9 | 576 { |
577 gint match = FALSE; | |
578 gint i; | |
579 | |
580 i = 0; | |
581 while (!match && remote_commands[i].func != NULL) | |
1 | 582 { |
9 | 583 if (remote_commands[i].needs_extra) |
584 { | |
585 if (remote_commands[i].opt_s && | |
586 strncmp(remote_commands[i].opt_s, text, strlen(remote_commands[i].opt_s)) == 0) | |
587 { | |
588 if (offset) *offset = text + strlen(remote_commands[i].opt_s); | |
589 return &remote_commands[i]; | |
590 } | |
591 else if (remote_commands[i].opt_l && | |
592 strncmp(remote_commands[i].opt_l, text, strlen(remote_commands[i].opt_l)) == 0) | |
593 { | |
594 if (offset) *offset = text + strlen(remote_commands[i].opt_l); | |
595 return &remote_commands[i]; | |
596 } | |
597 } | |
598 else | |
599 { | |
600 if ((remote_commands[i].opt_s && strcmp(remote_commands[i].opt_s, text) == 0) || | |
601 (remote_commands[i].opt_l && strcmp(remote_commands[i].opt_l, text) == 0)) | |
1 | 602 { |
9 | 603 if (offset) *offset = text; |
604 return &remote_commands[i]; | |
1 | 605 } |
9 | 606 } |
607 | |
608 i++; | |
609 } | |
610 | |
611 return NULL; | |
612 } | |
613 | |
279 | 614 static void remote_cb(RemoteConnection *rc, const gchar *text, gpointer data) |
9 | 615 { |
616 RemoteCommandEntry *entry; | |
617 const gchar *offset; | |
618 | |
279 | 619 entry = remote_command_find(text, &offset); |
9 | 620 if (entry && entry->func) |
621 { | |
622 entry->func(offset, data); | |
623 } | |
624 else | |
625 { | |
626 printf("unknown remote command:%s\n", text); | |
627 } | |
628 } | |
629 | |
279 | 630 static void remote_help(void) |
9 | 631 { |
632 gint i; | |
633 | |
634 print_term(_("Remote command list:\n")); | |
635 | |
636 i = 0; | |
637 while (remote_commands[i].func != NULL) | |
638 { | |
639 if (remote_commands[i].description) | |
640 { | |
403 | 641 printf_term(" %-3s%s %-20s %s\n", |
642 (remote_commands[i].opt_s) ? remote_commands[i].opt_s : "", | |
643 (remote_commands[i].opt_s && remote_commands[i].opt_l) ? "," : " ", | |
644 (remote_commands[i].opt_l) ? remote_commands[i].opt_l : "", | |
645 _(remote_commands[i].description)); | |
9 | 646 } |
647 i++; | |
648 } | |
649 } | |
650 | |
279 | 651 static GList *remote_build_list(GList *list, int argc, char *argv[]) |
9 | 652 { |
653 gint i; | |
654 | |
655 i = 1; | |
656 while (i < argc) | |
657 { | |
658 RemoteCommandEntry *entry; | |
659 | |
279 | 660 entry = remote_command_find(argv[i], NULL); |
9 | 661 if (entry) |
662 { | |
663 list = g_list_append(list, argv[i]); | |
664 } | |
665 i++; | |
1 | 666 } |
667 | |
9 | 668 return list; |
669 } | |
670 | |
279 | 671 static void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path, |
9 | 672 GList *cmd_list, GList *collection_list) |
673 { | |
674 RemoteConnection *rc; | |
675 gint started = FALSE; | |
676 gchar *buf; | |
677 | |
283 | 678 buf = g_strconcat(homedir(), "/", GQ_RC_DIR, "/.command", NULL); |
9 | 679 rc = remote_client_open(buf); |
680 if (!rc) | |
681 { | |
682 GString *command; | |
683 GList *work; | |
684 gint retry_count = 12; | |
685 gint blank = FALSE; | |
686 | |
403 | 687 printf_term(_("Remote %s not running, starting..."), GQ_APPNAME); |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
688 |
9 | 689 command = g_string_new(arg_exec); |
690 | |
691 work = remote_list; | |
692 while (work) | |
693 { | |
694 gchar *text; | |
695 RemoteCommandEntry *entry; | |
696 | |
697 text = work->data; | |
698 work = work->next; | |
699 | |
279 | 700 entry = remote_command_find(text, NULL); |
9 | 701 if (entry) |
702 { | |
703 if (entry->prefer_command_line) | |
704 { | |
705 remote_list = g_list_remove(remote_list, text); | |
706 g_string_append(command, " "); | |
707 g_string_append(command, text); | |
708 } | |
709 if (entry->opt_l && strcmp(entry->opt_l, "file:") == 0) | |
710 { | |
711 blank = TRUE; | |
712 } | |
713 } | |
714 } | |
715 | |
716 if (blank || cmd_list || path) g_string_append(command, " --blank"); | |
717 if (debug) g_string_append(command, " --debug"); | |
718 | |
719 g_string_append(command, " &"); | |
720 system(command->str); | |
721 g_string_free(command, TRUE); | |
722 | |
723 while (!rc && retry_count > 0) | |
724 { | |
725 usleep((retry_count > 10) ? 500000 : 1000000); | |
726 rc = remote_client_open(buf); | |
727 if (!rc) print_term("."); | |
728 retry_count--; | |
729 } | |
730 | |
731 print_term("\n"); | |
732 | |
733 started = TRUE; | |
734 } | |
735 g_free(buf); | |
736 | |
737 if (rc) | |
1 | 738 { |
9 | 739 GList *work; |
740 const gchar *prefix; | |
741 gint use_path = TRUE; | |
742 gint sent = FALSE; | |
743 | |
744 work = remote_list; | |
745 while (work) | |
746 { | |
747 gchar *text; | |
748 RemoteCommandEntry *entry; | |
749 | |
750 text = work->data; | |
751 work = work->next; | |
752 | |
279 | 753 entry = remote_command_find(text, NULL); |
9 | 754 if (entry && |
755 entry->opt_l && | |
756 strcmp(entry->opt_l, "file:") == 0) use_path = FALSE; | |
757 | |
758 remote_client_send(rc, text); | |
759 | |
760 sent = TRUE; | |
761 } | |
762 | |
763 if (cmd_list && cmd_list->next) | |
764 { | |
765 prefix = "--list-add:"; | |
766 remote_client_send(rc, "--list-clear"); | |
767 } | |
768 else | |
769 { | |
770 prefix = "file:"; | |
771 } | |
772 | |
773 work = cmd_list; | |
774 while (work) | |
775 { | |
776 const gchar *name; | |
777 gchar *text; | |
778 | |
779 name = work->data; | |
780 work = work->next; | |
781 | |
782 text = g_strconcat(prefix, name, NULL); | |
783 remote_client_send(rc, text); | |
784 g_free(text); | |
785 | |
786 sent = TRUE; | |
787 } | |
788 | |
789 if (path && !cmd_list && use_path) | |
790 { | |
791 gchar *text; | |
792 | |
793 text = g_strdup_printf("file:%s", path); | |
794 remote_client_send(rc, text); | |
795 g_free(text); | |
796 | |
797 sent = TRUE; | |
798 } | |
799 | |
800 work = collection_list; | |
801 while (work) | |
802 { | |
803 const gchar *name; | |
804 gchar *text; | |
805 | |
806 name = work->data; | |
807 work = work->next; | |
808 | |
809 text = g_strdup_printf("file:%s", name); | |
810 remote_client_send(rc, text); | |
811 g_free(text); | |
812 | |
813 sent = TRUE; | |
814 } | |
815 | |
816 if (!started && !sent) | |
817 { | |
818 remote_client_send(rc, "raise"); | |
819 } | |
820 } | |
821 else | |
822 { | |
823 print_term(_("Remote not available\n")); | |
1 | 824 } |
825 | |
9 | 826 _exit(0); |
1 | 827 } |
828 | |
829 /* | |
830 *----------------------------------------------------------------------------- | |
3 | 831 * command line parser (private) hehe, who needs popt anyway? |
1 | 832 *----------------------------------------------------------------------------- |
833 */ | |
834 | |
9 | 835 static gint startup_blank = FALSE; |
3 | 836 static gint startup_full_screen = FALSE; |
837 static gint startup_in_slideshow = FALSE; | |
9 | 838 static gint startup_command_line_collection = FALSE; |
3 | 839 |
9 | 840 |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
841 static void parse_command_line_add_file(const gchar *file_path, gchar **path, gchar **file, |
9 | 842 GList **list, GList **collection_list) |
1 | 843 { |
9 | 844 gchar *path_parsed; |
845 | |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
846 path_parsed = g_strdup(file_path); |
9 | 847 parse_out_relatives(path_parsed); |
848 | |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
849 if (file_extension_match(path_parsed, ".gqv")) |
9 | 850 { |
851 *collection_list = g_list_append(*collection_list, path_parsed); | |
852 } | |
853 else | |
854 { | |
855 if (!*path) *path = remove_level_from_path(path_parsed); | |
856 if (!*file) *file = g_strdup(path_parsed); | |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
857 *list = g_list_prepend(*list, path_parsed); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
858 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
859 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
860 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
861 static void parse_command_line_add_dir(const gchar *dir, gchar **path, gchar **file, |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
862 GList **list) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
863 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
864 GList *files = NULL; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
865 gchar *path_parsed; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
866 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
867 path_parsed = g_strdup(dir); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
868 parse_out_relatives(path_parsed); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
869 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
870 if (path_list(path_parsed, &files, NULL)) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
871 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
872 GList *work; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
873 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
874 files = path_list_filter(files, FALSE); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
875 files = path_list_sort(files); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
876 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
877 work = files; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
878 while (work) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
879 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
880 gchar *p; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
881 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
882 p = work->data; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
883 if (!*path) *path = remove_level_from_path(p); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
884 if (!*file) *file = g_strdup(p); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
885 *list = g_list_prepend(*list, p); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
886 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
887 work = work->next; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
888 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
889 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
890 g_list_free(files); |
9 | 891 } |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
892 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
893 g_free(path_parsed); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
894 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
895 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
896 static void parse_command_line_process_dir(const gchar *dir, gchar **path, gchar **file, |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
897 GList **list, gchar **first_dir) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
898 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
899 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
900 if (!*list && !*first_dir) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
901 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
902 *first_dir = g_strdup(dir); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
903 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
904 else |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
905 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
906 if (*first_dir) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
907 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
908 parse_command_line_add_dir(*first_dir, path, file, list); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
909 g_free(*first_dir); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
910 *first_dir = NULL; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
911 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
912 parse_command_line_add_dir(dir, path, file, list); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
913 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
914 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
915 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
916 static void parse_command_line_process_file(const gchar *file_path, gchar **path, gchar **file, |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
917 GList **list, GList **collection_list, gchar **first_dir) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
918 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
919 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
920 if (*first_dir) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
921 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
922 parse_command_line_add_dir(*first_dir, path, file, list); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
923 g_free(*first_dir); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
924 *first_dir = NULL; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
925 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
926 parse_command_line_add_file(file_path, path, file, list, collection_list); |
9 | 927 } |
928 | |
929 static void parse_command_line(int argc, char *argv[], gchar **path, gchar **file, | |
81
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
930 GList **cmd_list, GList **collection_list, |
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
931 gchar **geometry) |
9 | 932 { |
933 GList *list = NULL; | |
934 GList *remote_list = NULL; | |
935 gint remote_do = FALSE; | |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
936 gchar *first_dir = NULL; |
9 | 937 |
1 | 938 if (argc > 1) |
939 { | |
940 gint i; | |
941 gchar *base_dir = get_current_dir(); | |
942 i = 1; | |
943 while (i < argc) | |
944 { | |
9 | 945 const gchar *cmd_line = argv[i]; |
946 gchar *cmd_all = concat_dir_and_file(base_dir, cmd_line); | |
1 | 947 |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
948 if (cmd_line[0] == '/' && isdir(cmd_line)) |
1 | 949 { |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
950 parse_command_line_process_dir(cmd_line, path, file, &list, &first_dir); |
1 | 951 } |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
952 else if (isdir(cmd_all)) |
1 | 953 { |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
954 parse_command_line_process_dir(cmd_all, path, file, &list, &first_dir); |
1 | 955 } |
9 | 956 else if (cmd_line[0] == '/' && isfile(cmd_line)) |
1 | 957 { |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
958 parse_command_line_process_file(cmd_line, path, file, |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
959 &list, collection_list, &first_dir); |
1 | 960 } |
9 | 961 else if (isfile(cmd_all)) |
1 | 962 { |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
963 parse_command_line_process_file(cmd_all, path, file, |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
964 &list, collection_list, &first_dir); |
1 | 965 } |
378
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
966 else if (strncmp(cmd_line, "--debug", 7) == 0 && (cmd_line[7] == '\0' || cmd_line[7] == '=')) |
1 | 967 { |
378
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
968 /* do nothing but do not produce warnings */ |
1 | 969 } |
970 else if (strcmp(cmd_line, "+t") == 0 || | |
3 | 971 strcmp(cmd_line, "--with-tools") == 0) |
1 | 972 { |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
973 options->layout.tools_float = FALSE; |
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
974 options->layout.tools_hidden = FALSE; |
9 | 975 |
976 remote_list = g_list_append(remote_list, "+t"); | |
1 | 977 } |
978 else if (strcmp(cmd_line, "-t") == 0 || | |
3 | 979 strcmp(cmd_line, "--without-tools") == 0) |
1 | 980 { |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
981 options->layout.tools_hidden = TRUE; |
9 | 982 |
983 remote_list = g_list_append(remote_list, "-t"); | |
1 | 984 } |
3 | 985 else if (strcmp(cmd_line, "-f") == 0 || |
986 strcmp(cmd_line, "--fullscreen") == 0) | |
987 { | |
988 startup_full_screen = TRUE; | |
989 } | |
990 else if (strcmp(cmd_line, "-s") == 0 || | |
991 strcmp(cmd_line, "--slideshow") == 0) | |
992 { | |
993 startup_in_slideshow = TRUE; | |
994 } | |
9 | 995 else if (strcmp(cmd_line, "-l") == 0 || |
996 strcmp(cmd_line, "--list") == 0) | |
997 { | |
998 startup_command_line_collection = TRUE; | |
999 } | |
81
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
1000 else if (strncmp(cmd_line, "--geometry=", 11) == 0) |
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
1001 { |
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
1002 if (!*geometry) *geometry = g_strdup(cmd_line + 11); |
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
1003 } |
9 | 1004 else if (strcmp(cmd_line, "-r") == 0 || |
1005 strcmp(cmd_line, "--remote") == 0) | |
1006 { | |
1007 if (!remote_do) | |
1008 { | |
1009 remote_do = TRUE; | |
279 | 1010 remote_list = remote_build_list(remote_list, argc, argv); |
9 | 1011 } |
1012 } | |
1013 else if (strcmp(cmd_line, "-rh") == 0 || | |
1014 strcmp(cmd_line, "--remote-help") == 0) | |
1015 { | |
279 | 1016 remote_help(); |
9 | 1017 exit (0); |
1018 } | |
1019 else if (strcmp(cmd_line, "--blank") == 0) | |
1020 { | |
1021 startup_blank = TRUE; | |
1022 } | |
1023 else if (strcmp(cmd_line, "-v") == 0 || | |
1024 strcmp(cmd_line, "--version") == 0) | |
1025 { | |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1026 printf("%s %s\n", GQ_APPNAME, VERSION); |
9 | 1027 exit (0); |
1028 } | |
1029 else if (strcmp(cmd_line, "--alternate") == 0) | |
1030 { | |
1031 /* enable faster experimental algorithm */ | |
1032 printf("Alternate similarity algorithm enabled\n"); | |
1033 image_sim_alternate_set(TRUE); | |
1034 } | |
3 | 1035 else if (strcmp(cmd_line, "-h") == 0 || |
1036 strcmp(cmd_line, "--help") == 0) | |
1 | 1037 { |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1038 printf("%s %s\n", GQ_APPNAME, VERSION); |
403 | 1039 printf_term(_("Usage: %s [options] [path]\n\n"), GQ_APPNAME_LC); |
9 | 1040 print_term(_("valid options are:\n")); |
1041 print_term(_(" +t, --with-tools force show of tools\n")); | |
1042 print_term(_(" -t, --without-tools force hide of tools\n")); | |
1043 print_term(_(" -f, --fullscreen start in full screen mode\n")); | |
1044 print_term(_(" -s, --slideshow start in slideshow mode\n")); | |
1045 print_term(_(" -l, --list open collection window for command line\n")); | |
81
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
1046 print_term(_(" --geometry=GEOMETRY set main window location\n")); |
9 | 1047 print_term(_(" -r, --remote send following commands to open window\n")); |
1048 print_term(_(" -rh,--remote-help print remote command list\n")); | |
227
41fc4bfc8b25
Add a debug level spinner at the end of Preferences > Advanced.
zas_
parents:
218
diff
changeset
|
1049 #ifdef DEBUG |
379 | 1050 print_term(_(" --debug[=level] turn on debug output\n")); |
227
41fc4bfc8b25
Add a debug level spinner at the end of Preferences > Advanced.
zas_
parents:
218
diff
changeset
|
1051 #endif |
9 | 1052 print_term(_(" -v, --version print version info\n")); |
1053 print_term(_(" -h, --help show this message\n\n")); | |
1054 | |
1055 #if 0 | |
1056 /* these options are not officially supported! | |
1057 * only for testing new features, no need to translate them */ | |
1058 print_term( " --alternate use alternate similarity algorithm\n"); | |
1059 #endif | |
1060 | |
1 | 1061 exit (0); |
1062 } | |
9 | 1063 else if (!remote_do) |
1 | 1064 { |
403 | 1065 printf_term(_("invalid or ignored: %s\nUse --help for options\n"), cmd_line); |
1 | 1066 } |
9 | 1067 |
1 | 1068 g_free(cmd_all); |
1069 i++; | |
1070 } | |
1071 g_free(base_dir); | |
1072 parse_out_relatives(*path); | |
1073 parse_out_relatives(*file); | |
1074 } | |
9 | 1075 |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1076 list = g_list_reverse(list); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1077 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1078 if (!*path && first_dir) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1079 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1080 *path = first_dir; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1081 first_dir = NULL; |
79
528e3432e0c0
Thu Oct 19 07:23:37 2006 John Ellis <johne@verizon.net>
gqview
parents:
76
diff
changeset
|
1082 |
528e3432e0c0
Thu Oct 19 07:23:37 2006 John Ellis <johne@verizon.net>
gqview
parents:
76
diff
changeset
|
1083 parse_out_relatives(*path); |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1084 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1085 g_free(first_dir); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1086 |
9 | 1087 if (remote_do) |
1088 { | |
279 | 1089 remote_control(argv[0], remote_list, *path, list, *collection_list); |
9 | 1090 } |
1091 g_list_free(remote_list); | |
1092 | |
1093 if (list && list->next) | |
1094 { | |
1095 *cmd_list = list; | |
1096 } | |
1097 else | |
1098 { | |
1099 path_list_free(list); | |
1100 *cmd_list = NULL; | |
1101 } | |
1 | 1102 } |
1103 | |
378
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1104 static void parse_command_line_for_debug_option(int argc, char *argv[]) |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1105 { |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1106 #ifdef DEBUG |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1107 const gchar *debug_option = "--debug"; |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1108 gint len = strlen(debug_option); |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1109 |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1110 if (argc > 1) |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1111 { |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1112 gint i; |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1113 |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1114 for (i = 1; i < argc; i++) |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1115 { |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1116 const gchar *cmd_line = argv[i]; |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1117 if (strncmp(cmd_line, debug_option, len) == 0) |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1118 { |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1119 gint cmd_line_len = strlen(cmd_line); |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1120 |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1121 /* we now increment the debug state for verbosity */ |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1122 if (cmd_line_len == len) |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1123 debug++; |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1124 else if (cmd_line[len] == '=' && g_ascii_isdigit(cmd_line[len+1])) |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1125 { |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1126 gint n = atoi(cmd_line + len + 1); |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1127 if (n < 0) n = 1; |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1128 debug += n; |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1129 } |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1130 } |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1131 } |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1132 } |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1133 |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1134 if (debug > 0) printf("debugging output enabled (level %d)\n", debug); |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1135 #endif |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1136 } |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1137 |
1 | 1138 /* |
1139 *----------------------------------------------------------------------------- | |
1140 * startup, init, and exit | |
1141 *----------------------------------------------------------------------------- | |
1142 */ | |
1143 | |
9 | 1144 #define RC_HISTORY_NAME "history" |
1145 | |
1146 static void keys_load(void) | |
1147 { | |
1148 gchar *path; | |
1149 | |
283 | 1150 path = g_strconcat(homedir(), "/", GQ_RC_DIR, "/", RC_HISTORY_NAME, NULL); |
9 | 1151 history_list_load(path); |
1152 g_free(path); | |
1153 } | |
1154 | |
1155 static void keys_save(void) | |
1156 { | |
1157 gchar *path; | |
1158 | |
283 | 1159 path = g_strconcat(homedir(), "/", GQ_RC_DIR, "/", RC_HISTORY_NAME, NULL); |
9 | 1160 history_list_save(path); |
1161 g_free(path); | |
1162 } | |
1163 | |
1164 static void check_for_home_path(gchar *path) | |
1 | 1165 { |
9 | 1166 gchar *buf; |
1167 | |
1168 buf = g_strconcat(homedir(), "/", path, NULL); | |
1169 if (!isdir(buf)) | |
1170 { | |
403 | 1171 printf_term(_("Creating %s dir:%s\n"), GQ_APPNAME, buf); |
1172 | |
9 | 1173 if (!mkdir_utf8(buf, 0755)) |
1174 { | |
403 | 1175 printf_term(_("Could not create dir:%s\n"), buf); |
9 | 1176 } |
1177 } | |
1178 g_free(buf); | |
1179 } | |
1180 | |
1181 static void setup_default_options(void) | |
1182 { | |
1183 gchar *path; | |
1 | 1184 gint i; |
1185 | |
283 | 1186 for (i = 0; i < GQ_EDITOR_SLOTS; i++) |
1 | 1187 { |
318 | 1188 options->editor_name[i] = NULL; |
1189 options->editor_command[i] = NULL; | |
1 | 1190 } |
1191 | |
9 | 1192 editor_reset_defaults(); |
1 | 1193 |
9 | 1194 bookmark_add_default(_("Home"), homedir()); |
1195 path = concat_dir_and_file(homedir(), "Desktop"); | |
1196 bookmark_add_default(_("Desktop"), path); | |
1197 g_free(path); | |
283 | 1198 path = concat_dir_and_file(homedir(), GQ_RC_DIR_COLLECTIONS); |
9 | 1199 bookmark_add_default(_("Collections"), path); |
1200 g_free(path); | |
1 | 1201 |
341
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
340
diff
changeset
|
1202 g_free(options->file_ops.safe_delete_path); |
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
340
diff
changeset
|
1203 options->file_ops.safe_delete_path = concat_dir_and_file(homedir(), GQ_RC_DIR_TRASH); |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
1204 |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
1205 for (i = 0; i < COLOR_PROFILE_INPUTS; i++) |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
1206 { |
327 | 1207 options->color_profile.input_file[i] = NULL; |
1208 options->color_profile.input_name[i] = NULL; | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
1209 } |
189
deea9e11f1d4
fixed reading sidecar extensions from config file
nadvornik
parents:
145
diff
changeset
|
1210 |
354
5c82855feba7
Add a button to reset fullscreen info string to default value.
zas_
parents:
341
diff
changeset
|
1211 set_default_fullscreen_info(options); |
189
deea9e11f1d4
fixed reading sidecar extensions from config file
nadvornik
parents:
145
diff
changeset
|
1212 sidecar_ext_add_defaults(); |
367
3556cc825e59
Move layout.order default init to setup_default_options().
zas_
parents:
358
diff
changeset
|
1213 options->layout.order = g_strdup("123"); |
1 | 1214 } |
1215 | |
278 | 1216 static void exit_program_final(void) |
1 | 1217 { |
9 | 1218 gchar *path; |
1219 gchar *pathl; | |
1220 LayoutWindow *lw = NULL; | |
1221 | |
279 | 1222 remote_close(remote_connection); |
9 | 1223 |
1224 collect_manager_flush(); | |
1 | 1225 |
9 | 1226 if (layout_valid(&lw)) |
1227 { | |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1228 options->layout.main_window.maximized = window_maximized(lw->window); |
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1229 if (!options->layout.main_window.maximized) |
9 | 1230 { |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1231 layout_geometry_get(NULL, &options->layout.main_window.x, &options->layout.main_window.y, |
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1232 &options->layout.main_window.w, &options->layout.main_window.h); |
9 | 1233 } |
322 | 1234 options->fullscreen.show_info = image_osd_get(lw->image, NULL, NULL); |
9 | 1235 } |
1 | 1236 |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1237 layout_geometry_get_dividers(NULL, &options->layout.main_window.hdivider_pos, &options->layout.main_window.vdivider_pos); |
9 | 1238 |
380
5afe77bb563a
Introduce a new struct ViewDir to handle directory views common
zas_
parents:
379
diff
changeset
|
1239 layout_views_get(NULL, &options->layout.dir_view_type, &options->layout.view_as_icons); |
9 | 1240 |
340
77103f3f2cb1
Rename option thumbnails.enabled to layout.show_thumbnails as it makes
zas_
parents:
338
diff
changeset
|
1241 options->layout.show_thumbnails = layout_thumb_get(NULL); |
329 | 1242 layout_sort_get(NULL, &options->file_sort.method, &options->file_sort.ascending); |
9 | 1243 |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1244 layout_geometry_get_tools(NULL, &options->layout.float_window.x, &options->layout.float_window.y, |
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1245 &options->layout.float_window.w, &options->layout.float_window.h, &options->layout.float_window.vdivider_pos); |
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1246 layout_tools_float_get(NULL, &options->layout.tools_float, &options->layout.tools_hidden); |
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1247 options->layout.toolbar_hidden = layout_toolbar_hidden(NULL); |
9 | 1248 |
327 | 1249 options->color_profile.enabled = layout_image_color_profile_get_use(NULL); |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
1250 layout_image_color_profile_get(NULL, |
327 | 1251 &options->color_profile.input_type, |
1252 &options->color_profile.screen_type, | |
1253 &options->color_profile.use_image); | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
1254 |
1 | 1255 save_options(); |
9 | 1256 keys_save(); |
1257 | |
283 | 1258 path = g_strconcat(homedir(), "/", GQ_RC_DIR, "/accels", NULL); |
9 | 1259 pathl = path_from_utf8(path); |
1260 gtk_accel_map_save(pathl); | |
1261 g_free(pathl); | |
1262 g_free(path); | |
1 | 1263 |
1264 gtk_main_quit(); | |
1265 } | |
1266 | |
9 | 1267 static GenericDialog *exit_dialog = NULL; |
1268 | |
1269 static void exit_confirm_cancel_cb(GenericDialog *gd, gpointer data) | |
1270 { | |
1271 exit_dialog = NULL; | |
1272 generic_dialog_close(gd); | |
1273 } | |
1274 | |
1275 static void exit_confirm_exit_cb(GenericDialog *gd, gpointer data) | |
1276 { | |
1277 exit_dialog = NULL; | |
1278 generic_dialog_close(gd); | |
278 | 1279 exit_program_final(); |
9 | 1280 } |
1281 | |
1282 static gint exit_confirm_dlg(void) | |
1283 { | |
1284 GtkWidget *parent; | |
1285 LayoutWindow *lw; | |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1286 gchar *msg; |
9 | 1287 |
1288 if (exit_dialog) | |
1289 { | |
1290 gtk_window_present(GTK_WINDOW(exit_dialog->dialog)); | |
1291 return TRUE; | |
1292 } | |
1293 | |
1294 if (!collection_window_modified_exists()) return FALSE; | |
1295 | |
1296 parent = NULL; | |
1297 lw = NULL; | |
1298 if (layout_valid(&lw)) | |
1299 { | |
1300 parent = lw->window; | |
1301 } | |
1302 | |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1303 msg = g_strdup_printf("%s - %s", GQ_APPNAME, _("exit")); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1304 exit_dialog = generic_dialog_new(msg, |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
227
diff
changeset
|
1305 GQ_WMCLASS, "exit", parent, FALSE, |
9 | 1306 exit_confirm_cancel_cb, NULL); |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1307 g_free(msg); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1308 msg = g_strdup_printf(_("Quit %s"), GQ_APPNAME); |
9 | 1309 generic_dialog_add_message(exit_dialog, GTK_STOCK_DIALOG_QUESTION, |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1310 msg, _("Collections have been modified. Quit anyway?")); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1311 g_free(msg); |
9 | 1312 generic_dialog_add_button(exit_dialog, GTK_STOCK_QUIT, NULL, exit_confirm_exit_cb, TRUE); |
1313 | |
1314 gtk_widget_show(exit_dialog->dialog); | |
1315 | |
1316 return TRUE; | |
1317 } | |
1318 | |
278 | 1319 void exit_program(void) |
9 | 1320 { |
1321 layout_image_full_screen_stop(NULL); | |
1322 | |
1323 if (exit_confirm_dlg()) return; | |
1324 | |
278 | 1325 exit_program_final(); |
9 | 1326 } |
1327 | |
1 | 1328 int main (int argc, char *argv[]) |
1329 { | |
9 | 1330 LayoutWindow *lw; |
1331 gchar *path = NULL; | |
1 | 1332 gchar *cmd_path = NULL; |
1333 gchar *cmd_file = NULL; | |
9 | 1334 GList *cmd_list = NULL; |
1335 GList *collection_list = NULL; | |
1336 CollectionData *first_collection = NULL; | |
81
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
1337 gchar *geometry = NULL; |
9 | 1338 gchar *buf; |
1339 gchar *bufl; | |
1 | 1340 |
386
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
1341 /* init execution time counter*/ |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
1342 get_exec_time(); |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
1343 |
1 | 1344 /* setup locale, i18n */ |
1345 gtk_set_locale(); | |
283 | 1346 bindtextdomain(PACKAGE, GQ_LOCALEDIR); |
10 | 1347 bind_textdomain_codeset(PACKAGE, "UTF-8"); |
1348 textdomain(PACKAGE); | |
1 | 1349 |
1350 /* setup random seed for random slideshow */ | |
9 | 1351 srand(time(NULL)); |
1 | 1352 |
21
56866f205a68
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
10
diff
changeset
|
1353 #if 1 |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1354 printf("%s %s, This is an alpha release.\n", GQ_APPNAME, VERSION); |
9 | 1355 #endif |
378
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1356 parse_command_line_for_debug_option(argc, argv); |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1357 |
318 | 1358 options = init_options(NULL); |
1 | 1359 setup_default_options(); |
1360 load_options(); | |
1361 | |
81
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
1362 parse_command_line(argc, argv, &cmd_path, &cmd_file, &cmd_list, &collection_list, &geometry); |
9 | 1363 |
1364 gtk_init (&argc, &argv); | |
1365 | |
1366 if (gtk_major_version < GTK_MAJOR_VERSION || | |
1367 (gtk_major_version == GTK_MAJOR_VERSION && gtk_minor_version < GTK_MINOR_VERSION) ) | |
1368 { | |
403 | 1369 printf_term("!!! This is a friendly warning.\n"); |
1370 printf_term("!!! The version of GTK+ in use now is older than when %s was compiled.\n", GQ_APPNAME); | |
1371 printf_term("!!! compiled with GTK+-%d.%d\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION); | |
1372 printf_term("!!! running with GTK+-%d.%d\n", gtk_major_version, gtk_minor_version); | |
1373 printf_term("!!! %s may quit unexpectedly with a relocation error.\n", GQ_APPNAME); | |
9 | 1374 } |
1375 | |
283 | 1376 check_for_home_path(GQ_RC_DIR); |
1377 check_for_home_path(GQ_RC_DIR_COLLECTIONS); | |
1378 check_for_home_path(GQ_CACHE_RC_THUMB); | |
1379 check_for_home_path(GQ_CACHE_RC_METADATA); | |
9 | 1380 |
1381 keys_load(); | |
1382 filter_add_defaults(); | |
1383 filter_rebuild(); | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
138
diff
changeset
|
1384 |
283 | 1385 buf = g_strconcat(homedir(), "/", GQ_RC_DIR, "/accels", NULL); |
9 | 1386 bufl = path_from_utf8(buf); |
1387 gtk_accel_map_load(bufl); | |
1388 g_free(bufl); | |
1389 g_free(buf); | |
1 | 1390 |
9 | 1391 if (startup_blank) |
1392 { | |
1393 g_free(cmd_path); | |
1394 cmd_path = NULL; | |
1395 g_free(cmd_file); | |
1396 cmd_file = NULL; | |
1397 path_list_free(cmd_list); | |
1398 cmd_list = NULL; | |
1399 path_list_free(collection_list); | |
1400 collection_list = NULL; | |
1401 | |
1402 path = NULL; | |
1403 } | |
1404 else if (cmd_path) | |
1405 { | |
1406 path = g_strdup(cmd_path); | |
1407 } | |
318 | 1408 else if (options->startup_path_enable && options->startup_path && isdir(options->startup_path)) |
9 | 1409 { |
318 | 1410 path = g_strdup(options->startup_path); |
9 | 1411 } |
1 | 1412 else |
9 | 1413 { |
1414 path = get_current_dir(); | |
1415 } | |
1416 | |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1417 lw = layout_new_with_geometry(NULL, options->layout.tools_float, options->layout.tools_hidden, geometry); |
329 | 1418 layout_sort_set(lw, options->file_sort.method, options->file_sort.ascending); |
9 | 1419 |
1420 if (collection_list && !startup_command_line_collection) | |
1421 { | |
1422 GList *work; | |
1423 | |
1424 work = collection_list; | |
1425 while (work) | |
1426 { | |
1427 CollectWindow *cw; | |
1428 const gchar *path; | |
1 | 1429 |
9 | 1430 path = work->data; |
1431 work = work->next; | |
1432 | |
1433 cw = collection_window_new(path); | |
1434 if (!first_collection && cw) first_collection = cw->cd; | |
1435 } | |
1436 } | |
1437 | |
1438 if (cmd_list || | |
1439 (startup_command_line_collection && collection_list)) | |
1440 { | |
1441 CollectionData *cd; | |
1442 GList *work; | |
1443 | |
1444 if (startup_command_line_collection) | |
1445 { | |
1446 CollectWindow *cw; | |
1447 | |
1448 cw = collection_window_new(""); | |
1449 cd = cw->cd; | |
1450 } | |
1451 else | |
1452 { | |
1453 cd = collection_new(""); /* if we pass NULL, untitled counter is falsely increm. */ | |
279 | 1454 command_collection = cd; |
9 | 1455 } |
1456 | |
1457 g_free(cd->path); | |
1458 cd->path = NULL; | |
1459 g_free(cd->name); | |
1460 cd->name = g_strdup(_("Command line")); | |
1461 | |
1462 collection_path_changed(cd); | |
1 | 1463 |
9 | 1464 work = cmd_list; |
1465 while (work) | |
1466 { | |
138 | 1467 collection_add(cd, file_data_new_simple((gchar *)work->data), FALSE); |
9 | 1468 work = work->next; |
1469 } | |
1470 | |
1471 work = collection_list; | |
1472 while (work) | |
1473 { | |
358 | 1474 collection_load(cd, (gchar *)work->data, COLLECTION_LOAD_APPEND); |
9 | 1475 work = work->next; |
1476 } | |
1477 | |
1478 layout_set_path(lw, path); | |
1479 if (cd->list) layout_image_set_collection(lw, cd, cd->list->data); | |
1 | 1480 |
9 | 1481 /* mem leak, we never unref this collection when !startup_command_line_collection |
1482 * (the image view of the main window does not hold a ref to the collection) | |
1483 * this is sort of unavoidable, for if it did hold a ref, next/back | |
1484 * may not work as expected when closing collection windows. | |
1485 * | |
1486 * collection_unref(cd); | |
1487 */ | |
1488 | |
1489 } | |
1490 else if (cmd_file) | |
1491 { | |
1492 layout_set_path(lw, cmd_file); | |
1493 } | |
1494 else | |
1495 { | |
1496 layout_set_path(lw, path); | |
1497 if (first_collection) | |
1498 { | |
1499 layout_image_set_collection(lw, first_collection, | |
1500 collection_get_first(first_collection)); | |
1501 } | |
1502 } | |
322 | 1503 image_osd_set(lw->image, FALSE, options->fullscreen.show_info); |
1 | 1504 |
81
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
1505 g_free(geometry); |
1 | 1506 g_free(cmd_path); |
1507 g_free(cmd_file); | |
9 | 1508 path_list_free(cmd_list); |
1509 path_list_free(collection_list); | |
1510 g_free(path); | |
1 | 1511 |
9 | 1512 if (startup_full_screen) layout_image_full_screen_start(lw); |
1513 if (startup_in_slideshow) layout_image_slideshow_start(lw); | |
1514 | |
283 | 1515 buf = g_strconcat(homedir(), "/", GQ_RC_DIR, "/.command", NULL); |
279 | 1516 remote_connection = remote_server_open(buf); |
1517 remote_server_subscribe(remote_connection, remote_cb, NULL); | |
9 | 1518 g_free(buf); |
3 | 1519 |
1 | 1520 gtk_main (); |
1521 return 0; | |
1522 } | |
1523 |