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