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!
17 #include "collect-io.h"
23 #include "layout_image.h"
25 #include "preferences.h"
29 #include "slideshow.h"
31 #include "ui_bookmark.h"
33 #include "ui_fileops.h"
34 #include "ui_tabcomp.h"
35 #include "ui_utildlg.h"
37 #include <gdk/gdkkeysyms.h> /* for keyboard values */
39 #include "icons/icon.xpm"
45 static RemoteConnection *gqview_remote = NULL;
46 static CollectionData *gqview_command_collection = NULL;
50 *-----------------------------------------------------------------------------
52 *-----------------------------------------------------------------------------
55 typedef struct _WindowIconData WindowIconData;
56 struct _WindowIconData
62 static void window_set_icon_cb(GtkWidget *widget, gpointer data)
64 WindowIconData *wid = data;
71 pb = gdk_pixbuf_new_from_xpm_data(wid->icon);
75 pb = gdk_pixbuf_new_from_file(wid->path, NULL);
83 gdk_pixbuf_render_pixmap_and_mask(pb, &pixmap, &mask, 128);
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?) */
90 void window_set_icon(GtkWidget *window, const char **icon, const gchar *file)
94 if (!icon && !file) icon = (const char **)icon_xpm;
96 wid = g_new0(WindowIconData, 1);
98 wid->path = g_strdup(file);
100 g_signal_connect(G_OBJECT(window), "realize",
101 G_CALLBACK(window_set_icon_cb), wid);
104 gint window_maximized(GtkWidget *window)
106 GdkWindowState state;
108 if (!window || !window->window) return FALSE;
110 state = gdk_window_get_state(window->window);
111 return (state & GDK_WINDOW_STATE_MAXIMIZED);
114 gdouble get_zoom_increment(void)
116 return ((zoom_increment != 0) ? (gdouble)zoom_increment / 10.0 : 1.0);
120 *-----------------------------------------------------------------------------
121 * Open browser with the help Documentation
122 *-----------------------------------------------------------------------------
125 static gchar *command_result(const gchar *binary, const gchar *command)
127 gchar *result = NULL;
132 if (!binary) return NULL;
133 if (!file_in_path(binary)) return NULL;
135 if (!command) return g_strdup(binary);
136 if (command[0] == '!') return g_strdup(command + 1);
138 f = popen(command, "r");
141 while ((l = fread(buf, sizeof(char), sizeof(buf), f)) > 0)
147 while (n < l && buf[n] != '\n' && buf[n] != '\r') n++;
148 if (n > 0) result = g_strndup(buf, n);
157 static void help_browser_command(const gchar *command, const gchar *path)
164 if (!command || !path) return;
166 if (debug) printf("Help command pre \"%s\", \"%s\"\n", command, path);
168 buf = g_strdup(command);
169 begin = strstr(buf, "%s");
176 result = g_strdup_printf("%s%s%s &", begin, path, end);
180 result = g_strdup_printf("%s \"%s\" &", command, path);
184 if (debug) printf("Help command post [%s]\n", result);
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
199 static gchar *html_browsers[] =
201 /* Redhat has a nifty htmlview script to start the user's preferred browser */
204 "gconftool-2", "gconftool-2 -g /desktop/gnome/url-handlers/http/command",
206 "kfmclient", "!kfmclient exec \"%s\"",
215 static void help_browser_run(void)
217 gchar *result = NULL;
221 while (!result && html_browsers[i])
223 result = command_result(html_browsers[i], html_browsers[i+1]);
229 printf("Unable to detect an installed browser.\n");
233 help_browser_command(result, GQVIEW_HTMLDIR "/index.html");
239 *-----------------------------------------------------------------------------
241 *-----------------------------------------------------------------------------
244 static GtkWidget *help_window = NULL;
246 static void help_window_destroy_cb(GtkWidget *window, gpointer data)
251 void help_window_show(const gchar *key)
253 if (key && strcmp(key, "html_contents") == 0)
261 gtk_window_present(GTK_WINDOW(help_window));
262 if (key) help_window_set_key(help_window, key);
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);
274 *-----------------------------------------------------------------------------
276 *-----------------------------------------------------------------------------
279 void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event)
281 static gint delta = 0;
282 static guint32 time_old = 0;
283 static guint keyval_old = 0;
285 if (event->state & GDK_CONTROL_MASK)
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;
295 if (progressive_key_scrolling)
299 time_diff = event->time - time_old;
301 /* key pressed within 125ms ? (1/8 second) */
302 if (time_diff > 125 || event->keyval != keyval_old) delta = 0;
304 time_old = event->time;
305 keyval_old = event->keyval;
320 *-----------------------------------------------------------------------------
322 *-----------------------------------------------------------------------------
325 static void gr_image_next(const gchar *text, gpointer data)
327 layout_image_next(NULL);
330 static void gr_image_prev(const gchar *text, gpointer data)
332 layout_image_prev(NULL);
335 static void gr_image_first(const gchar *text, gpointer data)
337 layout_image_first(NULL);
340 static void gr_image_last(const gchar *text, gpointer data)
342 layout_image_last(NULL);
345 static void gr_fullscreen_toggle(const gchar *text, gpointer data)
347 layout_image_full_screen_toggle(NULL);
350 static void gr_fullscreen_start(const gchar *text, gpointer data)
352 layout_image_full_screen_start(NULL);
355 static void gr_fullscreen_stop(const gchar *text, gpointer data)
357 layout_image_full_screen_stop(NULL);
360 static void gr_slideshow_start_rec(const gchar *text, gpointer data)
364 list = path_list_recursive(text);
366 printf("length: %d\n", g_list_length(list));
367 layout_image_slideshow_stop(NULL);
368 layout_image_slideshow_start_from_list(NULL, list);
371 static void gr_slideshow_toggle(const gchar *text, gpointer data)
373 layout_image_slideshow_toggle(NULL);
376 static void gr_slideshow_start(const gchar *text, gpointer data)
378 layout_image_slideshow_start(NULL);
381 static void gr_slideshow_stop(const gchar *text, gpointer data)
383 layout_image_slideshow_stop(NULL);
386 static void gr_slideshow_delay(const gchar *text, gpointer data)
390 n = strtod(text, NULL);
391 if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS)
395 buf = g_strdup_printf("Remote slideshow delay out of range (%.1f to %.1f)\n",
396 SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
402 slideshow_delay = (gint)(n * 10.0 + 0.01);
405 static void gr_tools_show(const gchar *text, gpointer data)
410 if (layout_tools_float_get(NULL, &popped, &hidden) && hidden)
412 layout_tools_float_set(NULL, popped, FALSE);
416 static void gr_tools_hide(const gchar *text, gpointer data)
421 if (layout_tools_float_get(NULL, &popped, &hidden) && !hidden)
423 layout_tools_float_set(NULL, popped, TRUE);
427 static gint gr_quit_idle_cb(gpointer data)
434 static void gr_quit(const gchar *text, gpointer data)
436 /* schedule exit when idle, if done from within a
437 * remote handler remote_close will crash
439 g_idle_add(gr_quit_idle_cb, NULL);
442 static void gr_file_load(const gchar *text, gpointer data)
446 if (file_extension_match(text, ".gqv"))
448 collection_window_new(text);
452 layout_set_path(NULL, text);
455 else if (isdir(text))
457 layout_set_path(NULL, text);
461 printf("remote sent filename that does not exist:\"%s\"\n", text);
465 static void gr_file_view(const gchar *text, gpointer data)
467 view_window_new(text);
470 static void gr_list_clear(const gchar *text, gpointer data)
472 if (gqview_command_collection) collection_unref(gqview_command_collection);
473 gqview_command_collection = NULL;
476 static void gr_list_add(const gchar *text, gpointer data)
480 if (!gqview_command_collection)
484 cd = collection_new("");
489 cd->name = g_strdup(_("Command line"));
491 gqview_command_collection = cd;
495 new = (!collection_get_first(gqview_command_collection));
498 if (collection_add(gqview_command_collection, text, FALSE) && new)
500 layout_image_set_collection(NULL, gqview_command_collection,
501 collection_get_first(gqview_command_collection));
505 static void gr_raise(const gchar *text, gpointer data)
507 LayoutWindow *lw = NULL;
509 if (layout_valid(&lw))
511 gtk_window_present(GTK_WINDOW(lw->window));
515 typedef struct _RemoteCommandEntry RemoteCommandEntry;
516 struct _RemoteCommandEntry {
519 void (*func)(const gchar *text, gpointer data);
521 gint prefer_command_line;
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 }
550 static RemoteCommandEntry *gqview_remote_command_find(const gchar *text, const gchar **offset)
556 while (!match && remote_commands[i].func != NULL)
558 if (remote_commands[i].needs_extra)
560 if (remote_commands[i].opt_s &&
561 strncmp(remote_commands[i].opt_s, text, strlen(remote_commands[i].opt_s)) == 0)
563 if (offset) *offset = text + strlen(remote_commands[i].opt_s);
564 return &remote_commands[i];
566 else if (remote_commands[i].opt_l &&
567 strncmp(remote_commands[i].opt_l, text, strlen(remote_commands[i].opt_l)) == 0)
569 if (offset) *offset = text + strlen(remote_commands[i].opt_l);
570 return &remote_commands[i];
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))
578 if (offset) *offset = text;
579 return &remote_commands[i];
589 static void gqview_remote_cb(RemoteConnection *rc, const gchar *text, gpointer data)
591 RemoteCommandEntry *entry;
594 entry = gqview_remote_command_find(text, &offset);
595 if (entry && entry->func)
597 entry->func(offset, data);
601 printf("unknown remote command:%s\n", text);
605 static void gqview_remote_help(void)
609 print_term(_("Remote command list:\n"));
612 while (remote_commands[i].func != NULL)
614 if (remote_commands[i].description)
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));
631 static GList *gqview_remote_build_list(GList *list, int argc, char *argv[])
638 RemoteCommandEntry *entry;
640 entry = gqview_remote_command_find(argv[i], NULL);
643 list = g_list_append(list, argv[i]);
651 static void gqview_remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path,
652 GList *cmd_list, GList *collection_list)
654 RemoteConnection *rc;
655 gint started = FALSE;
658 buf = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/.command", NULL);
659 rc = remote_client_open(buf);
664 gint retry_count = 12;
667 print_term(_("Remote GQview not running, starting..."));
668 command = g_string_new(arg_exec);
674 RemoteCommandEntry *entry;
679 entry = gqview_remote_command_find(text, NULL);
682 if (entry->prefer_command_line)
684 remote_list = g_list_remove(remote_list, text);
685 g_string_append(command, " ");
686 g_string_append(command, text);
688 if (entry->opt_l && strcmp(entry->opt_l, "file:") == 0)
695 if (blank || cmd_list || path) g_string_append(command, " --blank");
696 if (debug) g_string_append(command, " --debug");
698 g_string_append(command, " &");
699 system(command->str);
700 g_string_free(command, TRUE);
702 while (!rc && retry_count > 0)
704 usleep((retry_count > 10) ? 500000 : 1000000);
705 rc = remote_client_open(buf);
706 if (!rc) print_term(".");
720 gint use_path = TRUE;
727 RemoteCommandEntry *entry;
732 entry = gqview_remote_command_find(text, NULL);
735 strcmp(entry->opt_l, "file:") == 0) use_path = FALSE;
737 remote_client_send(rc, text);
742 if (cmd_list && cmd_list->next)
744 prefix = "--list-add:";
745 remote_client_send(rc, "--list-clear");
761 text = g_strconcat(prefix, name, NULL);
762 remote_client_send(rc, text);
768 if (path && !cmd_list && use_path)
772 text = g_strdup_printf("file:%s", path);
773 remote_client_send(rc, text);
779 work = collection_list;
788 text = g_strdup_printf("file:%s", name);
789 remote_client_send(rc, text);
795 if (!started && !sent)
797 remote_client_send(rc, "raise");
802 print_term(_("Remote not available\n"));
809 *-----------------------------------------------------------------------------
810 * command line parser (private) hehe, who needs popt anyway?
811 *-----------------------------------------------------------------------------
814 static gint startup_blank = FALSE;
815 static gint startup_full_screen = FALSE;
816 static gint startup_in_slideshow = FALSE;
817 static gint startup_command_line_collection = FALSE;
820 static void parse_command_line_add_file(const gchar *file_path, gchar **path, gchar **file,
821 GList **list, GList **collection_list)
825 path_parsed = g_strdup(file_path);
826 parse_out_relatives(path_parsed);
828 if (file_extension_match(path_parsed, ".gqv"))
830 *collection_list = g_list_append(*collection_list, path_parsed);
834 if (!*path) *path = remove_level_from_path(path_parsed);
835 if (!*file) *file = g_strdup(path_parsed);
836 *list = g_list_prepend(*list, path_parsed);
840 static void parse_command_line_add_dir(const gchar *dir, gchar **path, gchar **file,
846 path_parsed = g_strdup(dir);
847 parse_out_relatives(path_parsed);
849 if (path_list(path_parsed, &files, NULL))
853 files = path_list_filter(files, FALSE);
854 files = path_list_sort(files);
862 if (!*path) *path = remove_level_from_path(p);
863 if (!*file) *file = g_strdup(p);
864 *list = g_list_prepend(*list, p);
875 static void parse_command_line_process_dir(const gchar *dir, gchar **path, gchar **file,
876 GList **list, gchar **first_dir)
879 if (!*list && !*first_dir)
881 *first_dir = g_strdup(dir);
887 parse_command_line_add_dir(*first_dir, path, file, list);
891 parse_command_line_add_dir(dir, path, file, list);
895 static void parse_command_line_process_file(const gchar *file_path, gchar **path, gchar **file,
896 GList **list, GList **collection_list, gchar **first_dir)
901 parse_command_line_add_dir(*first_dir, path, file, list);
905 parse_command_line_add_file(file_path, path, file, list, collection_list);
908 static void parse_command_line(int argc, char *argv[], gchar **path, gchar **file,
909 GList **cmd_list, GList **collection_list,
913 GList *remote_list = NULL;
914 gint remote_do = FALSE;
915 gchar *first_dir = NULL;
920 gchar *base_dir = get_current_dir();
924 const gchar *cmd_line = argv[i];
925 gchar *cmd_all = concat_dir_and_file(base_dir, cmd_line);
927 if (cmd_line[0] == '/' && isdir(cmd_line))
929 parse_command_line_process_dir(cmd_line, path, file, &list, &first_dir);
931 else if (isdir(cmd_all))
933 parse_command_line_process_dir(cmd_all, path, file, &list, &first_dir);
935 else if (cmd_line[0] == '/' && isfile(cmd_line))
937 parse_command_line_process_file(cmd_line, path, file,
938 &list, collection_list, &first_dir);
940 else if (isfile(cmd_all))
942 parse_command_line_process_file(cmd_all, path, file,
943 &list, collection_list, &first_dir);
945 else if (strcmp(cmd_line, "--debug") == 0)
947 /* we now increment the debug state for verbosity */
949 printf("debugging output enabled (level %d)\n", debug);
951 else if (strcmp(cmd_line, "+t") == 0 ||
952 strcmp(cmd_line, "--with-tools") == 0)
955 tools_hidden = FALSE;
957 remote_list = g_list_append(remote_list, "+t");
959 else if (strcmp(cmd_line, "-t") == 0 ||
960 strcmp(cmd_line, "--without-tools") == 0)
964 remote_list = g_list_append(remote_list, "-t");
966 else if (strcmp(cmd_line, "-f") == 0 ||
967 strcmp(cmd_line, "--fullscreen") == 0)
969 startup_full_screen = TRUE;
971 else if (strcmp(cmd_line, "-s") == 0 ||
972 strcmp(cmd_line, "--slideshow") == 0)
974 startup_in_slideshow = TRUE;
976 else if (strcmp(cmd_line, "-l") == 0 ||
977 strcmp(cmd_line, "--list") == 0)
979 startup_command_line_collection = TRUE;
981 else if (strncmp(cmd_line, "--geometry=", 11) == 0)
983 if (!*geometry) *geometry = g_strdup(cmd_line + 11);
985 else if (strcmp(cmd_line, "-r") == 0 ||
986 strcmp(cmd_line, "--remote") == 0)
991 remote_list = gqview_remote_build_list(remote_list, argc, argv);
994 else if (strcmp(cmd_line, "-rh") == 0 ||
995 strcmp(cmd_line, "--remote-help") == 0)
997 gqview_remote_help();
1000 else if (strcmp(cmd_line, "--blank") == 0)
1002 startup_blank = TRUE;
1004 else if (strcmp(cmd_line, "-v") == 0 ||
1005 strcmp(cmd_line, "--version") == 0)
1007 printf("GQview %s\n", VERSION);
1010 else if (strcmp(cmd_line, "--alternate") == 0)
1012 /* enable faster experimental algorithm */
1013 printf("Alternate similarity algorithm enabled\n");
1014 image_sim_alternate_set(TRUE);
1016 else if (strcmp(cmd_line, "-h") == 0 ||
1017 strcmp(cmd_line, "--help") == 0)
1019 printf("GQview %s\n", VERSION);
1020 print_term(_("Usage: gqview [options] [path]\n\n"));
1021 print_term(_("valid options are:\n"));
1022 print_term(_(" +t, --with-tools force show of tools\n"));
1023 print_term(_(" -t, --without-tools force hide of tools\n"));
1024 print_term(_(" -f, --fullscreen start in full screen mode\n"));
1025 print_term(_(" -s, --slideshow start in slideshow mode\n"));
1026 print_term(_(" -l, --list open collection window for command line\n"));
1027 print_term(_(" --geometry=GEOMETRY set main window location\n"));
1028 print_term(_(" -r, --remote send following commands to open window\n"));
1029 print_term(_(" -rh,--remote-help print remote command list\n"));
1030 print_term(_(" --debug turn on debug output\n"));
1031 print_term(_(" -v, --version print version info\n"));
1032 print_term(_(" -h, --help show this message\n\n"));
1035 /* these options are not officially supported!
1036 * only for testing new features, no need to translate them */
1037 print_term( " --alternate use alternate similarity algorithm\n");
1042 else if (!remote_do)
1046 buf = g_strdup_printf(_("invalid or ignored: %s\nUse --help for options\n"), cmd_line);
1055 parse_out_relatives(*path);
1056 parse_out_relatives(*file);
1059 list = g_list_reverse(list);
1061 if (!*path && first_dir)
1066 parse_out_relatives(*path);
1072 gqview_remote_control(argv[0], remote_list, *path, list, *collection_list);
1074 g_list_free(remote_list);
1076 if (list && list->next)
1082 path_list_free(list);
1088 *-----------------------------------------------------------------------------
1089 * startup, init, and exit
1090 *-----------------------------------------------------------------------------
1093 #define RC_HISTORY_NAME "history"
1095 static void keys_load(void)
1099 path = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/", RC_HISTORY_NAME, NULL);
1100 history_list_load(path);
1104 static void keys_save(void)
1108 path = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/", RC_HISTORY_NAME, NULL);
1109 history_list_save(path);
1113 static void check_for_home_path(gchar *path)
1117 buf = g_strconcat(homedir(), "/", path, NULL);
1122 tmp = g_strdup_printf(_("Creating GQview dir:%s\n"), buf);
1126 if (!mkdir_utf8(buf, 0755))
1128 tmp = g_strdup_printf(_("Could not create dir:%s\n"), buf);
1136 static void setup_default_options(void)
1141 for (i = 0; i < GQVIEW_EDITOR_SLOTS; i++)
1143 editor_name[i] = NULL;
1144 editor_command[i] = NULL;
1147 editor_reset_defaults();
1149 bookmark_add_default(_("Home"), homedir());
1150 path = concat_dir_and_file(homedir(), "Desktop");
1151 bookmark_add_default(_("Desktop"), path);
1153 path = concat_dir_and_file(homedir(), GQVIEW_RC_DIR_COLLECTIONS);
1154 bookmark_add_default(_("Collections"), path);
1157 g_free(safe_delete_path);
1158 safe_delete_path = concat_dir_and_file(homedir(), GQVIEW_RC_DIR_TRASH);
1161 static void exit_gqview_final(void)
1165 LayoutWindow *lw = NULL;
1167 remote_close(gqview_remote);
1169 collect_manager_flush();
1171 if (layout_valid(&lw))
1173 main_window_maximized = window_maximized(lw->window);
1174 if (!main_window_maximized)
1176 layout_geometry_get(NULL, &main_window_x, &main_window_y,
1177 &main_window_w, &main_window_h);
1181 layout_geometry_get_dividers(NULL, &window_hdivider_pos, &window_vdivider_pos);
1183 layout_views_get(NULL, &layout_view_tree, &layout_view_icons);
1185 thumbnails_enabled = layout_thumb_get(NULL);
1186 layout_sort_get(NULL, &file_sort_method, &file_sort_ascending);
1188 layout_geometry_get_tools(NULL, &float_window_x, &float_window_y,
1189 &float_window_w, &float_window_h, &float_window_divider);
1190 layout_tools_float_get(NULL, &tools_float, &tools_hidden);
1191 toolbar_hidden = layout_toolbar_hidden(NULL);
1196 path = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/accels", NULL);
1197 pathl = path_from_utf8(path);
1198 gtk_accel_map_save(pathl);
1205 static GenericDialog *exit_dialog = NULL;
1207 static void exit_confirm_cancel_cb(GenericDialog *gd, gpointer data)
1210 generic_dialog_close(gd);
1213 static void exit_confirm_exit_cb(GenericDialog *gd, gpointer data)
1216 generic_dialog_close(gd);
1217 exit_gqview_final();
1220 static gint exit_confirm_dlg(void)
1227 gtk_window_present(GTK_WINDOW(exit_dialog->dialog));
1231 if (!collection_window_modified_exists()) return FALSE;
1235 if (layout_valid(&lw))
1237 parent = lw->window;
1240 exit_dialog = generic_dialog_new(_("GQview - exit"),
1241 "GQview", "exit", parent, FALSE,
1242 exit_confirm_cancel_cb, NULL);
1243 generic_dialog_add_message(exit_dialog, GTK_STOCK_DIALOG_QUESTION,
1244 _("Quit GQview"), _("Collections have been modified. Quit anyway?"));
1245 generic_dialog_add_button(exit_dialog, GTK_STOCK_QUIT, NULL, exit_confirm_exit_cb, TRUE);
1247 gtk_widget_show(exit_dialog->dialog);
1252 void exit_gqview(void)
1254 layout_image_full_screen_stop(NULL);
1256 if (exit_confirm_dlg()) return;
1258 exit_gqview_final();
1261 int main (int argc, char *argv[])
1265 gchar *cmd_path = NULL;
1266 gchar *cmd_file = NULL;
1267 GList *cmd_list = NULL;
1268 GList *collection_list = NULL;
1269 CollectionData *first_collection = NULL;
1270 gchar *geometry = NULL;
1274 /* setup locale, i18n */
1276 bindtextdomain(PACKAGE, GQVIEW_LOCALEDIR);
1277 bind_textdomain_codeset(PACKAGE, "UTF-8");
1278 textdomain(PACKAGE);
1280 /* setup random seed for random slideshow */
1284 printf("GQview %s, This is a beta release.\n", VERSION);
1287 layout_order = g_strdup("123");
1288 setup_default_options();
1291 parse_command_line(argc, argv, &cmd_path, &cmd_file, &cmd_list, &collection_list, &geometry);
1293 gtk_init (&argc, &argv);
1295 if (gtk_major_version < GTK_MAJOR_VERSION ||
1296 (gtk_major_version == GTK_MAJOR_VERSION && gtk_minor_version < GTK_MINOR_VERSION) )
1299 print_term("!!! This is a friendly warning.\n");
1300 print_term("!!! The version of GTK+ in use now is older than when GQview was compiled.\n");
1301 msg = g_strdup_printf("!!! compiled with GTK+-%d.%d\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION);
1304 msg = g_strdup_printf("!!! running with GTK+-%d.%d\n", gtk_major_version, gtk_minor_version);
1307 print_term("!!! GQview may quit unexpectedly with a relocation error.\n");
1310 check_for_home_path(GQVIEW_RC_DIR);
1311 check_for_home_path(GQVIEW_RC_DIR_COLLECTIONS);
1312 check_for_home_path(GQVIEW_CACHE_RC_THUMB);
1313 check_for_home_path(GQVIEW_CACHE_RC_METADATA);
1316 filter_add_defaults();
1319 buf = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/accels", NULL);
1320 bufl = path_from_utf8(buf);
1321 gtk_accel_map_load(bufl);
1331 path_list_free(cmd_list);
1333 path_list_free(collection_list);
1334 collection_list = NULL;
1340 path = g_strdup(cmd_path);
1342 else if (startup_path_enable && startup_path && isdir(startup_path))
1344 path = g_strdup(startup_path);
1348 path = get_current_dir();
1351 lw = layout_new_with_geometry(NULL, tools_float, tools_hidden, geometry);
1352 layout_sort_set(lw, file_sort_method, file_sort_ascending);
1354 if (collection_list && !startup_command_line_collection)
1358 work = collection_list;
1367 cw = collection_window_new(path);
1368 if (!first_collection && cw) first_collection = cw->cd;
1373 (startup_command_line_collection && collection_list))
1378 if (startup_command_line_collection)
1382 cw = collection_window_new("");
1387 cd = collection_new(""); /* if we pass NULL, untitled counter is falsely increm. */
1388 gqview_command_collection = cd;
1394 cd->name = g_strdup(_("Command line"));
1396 collection_path_changed(cd);
1401 collection_add(cd, (gchar *)work->data, FALSE);
1405 work = collection_list;
1408 collection_load(cd, (gchar *)work->data, TRUE);
1412 layout_set_path(lw, path);
1413 if (cd->list) layout_image_set_collection(lw, cd, cd->list->data);
1415 /* mem leak, we never unref this collection when !startup_command_line_collection
1416 * (the image view of the main window does not hold a ref to the collection)
1417 * this is sort of unavoidable, for if it did hold a ref, next/back
1418 * may not work as expected when closing collection windows.
1420 * collection_unref(cd);
1426 layout_set_path(lw, cmd_file);
1430 layout_set_path(lw, path);
1431 if (first_collection)
1433 layout_image_set_collection(lw, first_collection,
1434 collection_get_first(first_collection));
1441 path_list_free(cmd_list);
1442 path_list_free(collection_list);
1445 if (startup_full_screen) layout_image_full_screen_start(lw);
1446 if (startup_in_slideshow) layout_image_slideshow_start(lw);
1448 buf = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/.command", NULL);
1449 gqview_remote = remote_server_open(buf);
1450 remote_server_subscribe(gqview_remote, gqview_remote_cb, NULL);