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 "pixbuf_util.h"
26 #include "preferences.h"
30 #include "slideshow.h"
32 #include "ui_bookmark.h"
34 #include "ui_fileops.h"
35 #include "ui_tabcomp.h"
36 #include "ui_utildlg.h"
38 #include <gdk/gdkkeysyms.h> /* for keyboard values */
44 static RemoteConnection *gqview_remote = NULL;
45 static CollectionData *gqview_command_collection = NULL;
49 *-----------------------------------------------------------------------------
51 *-----------------------------------------------------------------------------
54 void window_set_icon(GtkWidget *window, const gchar *icon, const gchar *file)
56 if (!icon && !file) icon = PIXBUF_INLINE_ICON;
62 pixbuf = pixbuf_inline(icon);
65 gtk_window_set_icon(GTK_WINDOW(window), pixbuf);
66 g_object_unref(pixbuf);
71 gtk_window_set_icon_from_file(GTK_WINDOW(window), file, NULL);
75 gint window_maximized(GtkWidget *window)
79 if (!window || !window->window) return FALSE;
81 state = gdk_window_get_state(window->window);
82 return (state & GDK_WINDOW_STATE_MAXIMIZED);
85 gdouble get_zoom_increment(void)
87 return ((zoom_increment != 0) ? (gdouble)zoom_increment / 10.0 : 1.0);
91 *-----------------------------------------------------------------------------
92 * Open browser with the help Documentation
93 *-----------------------------------------------------------------------------
96 static gchar *command_result(const gchar *binary, const gchar *command)
103 if (!binary) return NULL;
104 if (!file_in_path(binary)) return NULL;
106 if (!command) return g_strdup(binary);
107 if (command[0] == '!') return g_strdup(command + 1);
109 f = popen(command, "r");
112 while ((l = fread(buf, sizeof(char), sizeof(buf), f)) > 0)
118 while (n < l && buf[n] != '\n' && buf[n] != '\r') n++;
119 if (n > 0) result = g_strndup(buf, n);
128 static void help_browser_command(const gchar *command, const gchar *path)
135 if (!command || !path) return;
137 if (debug) printf("Help command pre \"%s\", \"%s\"\n", command, path);
139 buf = g_strdup(command);
140 begin = strstr(buf, "%s");
147 result = g_strdup_printf("%s%s%s &", begin, path, end);
151 result = g_strdup_printf("%s \"%s\" &", command, path);
155 if (debug) printf("Help command post [%s]\n", result);
163 * each set of 2 strings is one browser:
164 * the 1st is the binary to look for in the path
165 * the 2nd has 3 capabilities:
166 * NULL exec binary with html file path as command line
167 * string exec string and use results for command line
168 * !string use text following ! as command line, replacing optional %s with html file path
170 static gchar *html_browsers[] =
172 /* Redhat has a nifty htmlview script to start the user's preferred browser */
175 "gconftool-2", "gconftool-2 -g /desktop/gnome/url-handlers/http/command",
177 "kfmclient", "!kfmclient exec \"%s\"",
186 static void help_browser_run(void)
188 gchar *result = NULL;
192 while (!result && html_browsers[i])
194 result = command_result(html_browsers[i], html_browsers[i+1]);
200 printf("Unable to detect an installed browser.\n");
204 help_browser_command(result, GQVIEW_HTMLDIR "/index.html");
210 *-----------------------------------------------------------------------------
212 *-----------------------------------------------------------------------------
215 static GtkWidget *help_window = NULL;
217 static void help_window_destroy_cb(GtkWidget *window, gpointer data)
222 void help_window_show(const gchar *key)
224 if (key && strcmp(key, "html_contents") == 0)
232 gtk_window_present(GTK_WINDOW(help_window));
233 if (key) help_window_set_key(help_window, key);
237 help_window = help_window_new(_("Help - GQview"), "GQview", "help",
238 GQVIEW_HELPDIR "/README", key);
239 g_signal_connect(G_OBJECT(help_window), "destroy",
240 G_CALLBACK(help_window_destroy_cb), NULL);
245 *-----------------------------------------------------------------------------
247 *-----------------------------------------------------------------------------
250 void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event)
252 static gint delta = 0;
253 static guint32 time_old = 0;
254 static guint keyval_old = 0;
256 if (event->state & GDK_CONTROL_MASK)
258 if (*x < 0) *x = G_MININT / 2;
259 if (*x > 0) *x = G_MAXINT / 2;
260 if (*y < 0) *y = G_MININT / 2;
261 if (*y > 0) *y = G_MAXINT / 2;
266 if (progressive_key_scrolling)
270 time_diff = event->time - time_old;
272 /* key pressed within 125ms ? (1/8 second) */
273 if (time_diff > 125 || event->keyval != keyval_old) delta = 0;
275 time_old = event->time;
276 keyval_old = event->keyval;
291 *-----------------------------------------------------------------------------
293 *-----------------------------------------------------------------------------
296 static void gr_image_next(const gchar *text, gpointer data)
298 layout_image_next(NULL);
301 static void gr_image_prev(const gchar *text, gpointer data)
303 layout_image_prev(NULL);
306 static void gr_image_first(const gchar *text, gpointer data)
308 layout_image_first(NULL);
311 static void gr_image_last(const gchar *text, gpointer data)
313 layout_image_last(NULL);
316 static void gr_fullscreen_toggle(const gchar *text, gpointer data)
318 layout_image_full_screen_toggle(NULL);
321 static void gr_fullscreen_start(const gchar *text, gpointer data)
323 layout_image_full_screen_start(NULL);
326 static void gr_fullscreen_stop(const gchar *text, gpointer data)
328 layout_image_full_screen_stop(NULL);
331 static void gr_slideshow_start_rec(const gchar *text, gpointer data)
335 list = path_list_recursive(text);
337 printf("length: %d\n", g_list_length(list));
338 layout_image_slideshow_stop(NULL);
339 layout_image_slideshow_start_from_list(NULL, list);
342 static void gr_slideshow_toggle(const gchar *text, gpointer data)
344 layout_image_slideshow_toggle(NULL);
347 static void gr_slideshow_start(const gchar *text, gpointer data)
349 layout_image_slideshow_start(NULL);
352 static void gr_slideshow_stop(const gchar *text, gpointer data)
354 layout_image_slideshow_stop(NULL);
357 static void gr_slideshow_delay(const gchar *text, gpointer data)
361 n = strtod(text, NULL);
362 if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS)
366 buf = g_strdup_printf("Remote slideshow delay out of range (%.1f to %.1f)\n",
367 SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
373 slideshow_delay = (gint)(n * 10.0 + 0.01);
376 static void gr_tools_show(const gchar *text, gpointer data)
381 if (layout_tools_float_get(NULL, &popped, &hidden) && hidden)
383 layout_tools_float_set(NULL, popped, FALSE);
387 static void gr_tools_hide(const gchar *text, gpointer data)
392 if (layout_tools_float_get(NULL, &popped, &hidden) && !hidden)
394 layout_tools_float_set(NULL, popped, TRUE);
398 static gint gr_quit_idle_cb(gpointer data)
405 static void gr_quit(const gchar *text, gpointer data)
407 /* schedule exit when idle, if done from within a
408 * remote handler remote_close will crash
410 g_idle_add(gr_quit_idle_cb, NULL);
413 static void gr_file_load(const gchar *text, gpointer data)
417 if (file_extension_match(text, ".gqv"))
419 collection_window_new(text);
423 layout_set_path(NULL, text);
426 else if (isdir(text))
428 layout_set_path(NULL, text);
432 printf("remote sent filename that does not exist:\"%s\"\n", text);
436 static void gr_file_view(const gchar *text, gpointer data)
438 view_window_new(text);
441 static void gr_list_clear(const gchar *text, gpointer data)
443 if (gqview_command_collection) collection_unref(gqview_command_collection);
444 gqview_command_collection = NULL;
447 static void gr_list_add(const gchar *text, gpointer data)
451 if (!gqview_command_collection)
455 cd = collection_new("");
460 cd->name = g_strdup(_("Command line"));
462 gqview_command_collection = cd;
466 new = (!collection_get_first(gqview_command_collection));
469 if (collection_add(gqview_command_collection, text, FALSE) && new)
471 layout_image_set_collection(NULL, gqview_command_collection,
472 collection_get_first(gqview_command_collection));
476 static void gr_raise(const gchar *text, gpointer data)
478 LayoutWindow *lw = NULL;
480 if (layout_valid(&lw))
482 gtk_window_present(GTK_WINDOW(lw->window));
486 typedef struct _RemoteCommandEntry RemoteCommandEntry;
487 struct _RemoteCommandEntry {
490 void (*func)(const gchar *text, gpointer data);
492 gint prefer_command_line;
496 static RemoteCommandEntry remote_commands[] = {
497 /* short, long callback, extra, prefer,description */
498 { "-n", "--next", gr_image_next, FALSE, FALSE, N_("next image") },
499 { "-b", "--back", gr_image_prev, FALSE, FALSE, N_("previous image") },
500 { NULL, "--first", gr_image_first, FALSE, FALSE, N_("first image") },
501 { NULL, "--last", gr_image_last, FALSE, FALSE, N_("last image") },
502 { "-f", "--fullscreen", gr_fullscreen_toggle, FALSE, TRUE, N_("toggle full screen") },
503 { "-fs","--fullscreen-start", gr_fullscreen_start, FALSE, FALSE, N_("start full screen") },
504 { "-fS","--fullscreen-stop", gr_fullscreen_stop, FALSE, FALSE, N_("stop full screen") },
505 { "-s", "--slideshow", gr_slideshow_toggle, FALSE, TRUE, N_("toggle slide show") },
506 { "-ss","--slideshow-start", gr_slideshow_start, FALSE, FALSE, N_("start slide show") },
507 { "-sS","--slideshow-stop", gr_slideshow_stop, FALSE, FALSE, N_("stop slide show") },
508 { "-sr","--slideshow-recurse", gr_slideshow_start_rec, TRUE, FALSE, N_("start recursive slide show") },
509 { "-d", "--delay=", gr_slideshow_delay, TRUE, FALSE, N_("set slide show delay in seconds") },
510 { "+t", "--tools-show", gr_tools_show, FALSE, TRUE, N_("show tools") },
511 { "-t", "--tools-hide", gr_tools_hide, FALSE, TRUE, N_("hide tools") },
512 { "-q", "--quit", gr_quit, FALSE, FALSE, N_("quit") },
513 { NULL, "file:", gr_file_load, TRUE, FALSE, N_("open file") },
514 { NULL, "view:", gr_file_view, TRUE, FALSE, N_("open file in new window") },
515 { NULL, "--list-clear", gr_list_clear, FALSE, FALSE, NULL },
516 { NULL, "--list-add:", gr_list_add, TRUE, FALSE, NULL },
517 { NULL, "raise", gr_raise, FALSE, FALSE, NULL },
518 { NULL, NULL, NULL, FALSE, FALSE, NULL }
521 static RemoteCommandEntry *gqview_remote_command_find(const gchar *text, const gchar **offset)
527 while (!match && remote_commands[i].func != NULL)
529 if (remote_commands[i].needs_extra)
531 if (remote_commands[i].opt_s &&
532 strncmp(remote_commands[i].opt_s, text, strlen(remote_commands[i].opt_s)) == 0)
534 if (offset) *offset = text + strlen(remote_commands[i].opt_s);
535 return &remote_commands[i];
537 else if (remote_commands[i].opt_l &&
538 strncmp(remote_commands[i].opt_l, text, strlen(remote_commands[i].opt_l)) == 0)
540 if (offset) *offset = text + strlen(remote_commands[i].opt_l);
541 return &remote_commands[i];
546 if ((remote_commands[i].opt_s && strcmp(remote_commands[i].opt_s, text) == 0) ||
547 (remote_commands[i].opt_l && strcmp(remote_commands[i].opt_l, text) == 0))
549 if (offset) *offset = text;
550 return &remote_commands[i];
560 static void gqview_remote_cb(RemoteConnection *rc, const gchar *text, gpointer data)
562 RemoteCommandEntry *entry;
565 entry = gqview_remote_command_find(text, &offset);
566 if (entry && entry->func)
568 entry->func(offset, data);
572 printf("unknown remote command:%s\n", text);
576 static void gqview_remote_help(void)
580 print_term(_("Remote command list:\n"));
583 while (remote_commands[i].func != NULL)
585 if (remote_commands[i].description)
589 buf = g_strdup_printf(" %-3s%s %-20s %s\n",
590 (remote_commands[i].opt_s) ? remote_commands[i].opt_s : "",
591 (remote_commands[i].opt_s && remote_commands[i].opt_l) ? "," : " ",
592 (remote_commands[i].opt_l) ? remote_commands[i].opt_l : "",
593 _(remote_commands[i].description));
602 static GList *gqview_remote_build_list(GList *list, int argc, char *argv[])
609 RemoteCommandEntry *entry;
611 entry = gqview_remote_command_find(argv[i], NULL);
614 list = g_list_append(list, argv[i]);
622 static void gqview_remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path,
623 GList *cmd_list, GList *collection_list)
625 RemoteConnection *rc;
626 gint started = FALSE;
629 buf = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/.command", NULL);
630 rc = remote_client_open(buf);
635 gint retry_count = 12;
638 print_term(_("Remote GQview not running, starting..."));
639 command = g_string_new(arg_exec);
645 RemoteCommandEntry *entry;
650 entry = gqview_remote_command_find(text, NULL);
653 if (entry->prefer_command_line)
655 remote_list = g_list_remove(remote_list, text);
656 g_string_append(command, " ");
657 g_string_append(command, text);
659 if (entry->opt_l && strcmp(entry->opt_l, "file:") == 0)
666 if (blank || cmd_list || path) g_string_append(command, " --blank");
667 if (debug) g_string_append(command, " --debug");
669 g_string_append(command, " &");
670 system(command->str);
671 g_string_free(command, TRUE);
673 while (!rc && retry_count > 0)
675 usleep((retry_count > 10) ? 500000 : 1000000);
676 rc = remote_client_open(buf);
677 if (!rc) print_term(".");
691 gint use_path = TRUE;
698 RemoteCommandEntry *entry;
703 entry = gqview_remote_command_find(text, NULL);
706 strcmp(entry->opt_l, "file:") == 0) use_path = FALSE;
708 remote_client_send(rc, text);
713 if (cmd_list && cmd_list->next)
715 prefix = "--list-add:";
716 remote_client_send(rc, "--list-clear");
732 text = g_strconcat(prefix, name, NULL);
733 remote_client_send(rc, text);
739 if (path && !cmd_list && use_path)
743 text = g_strdup_printf("file:%s", path);
744 remote_client_send(rc, text);
750 work = collection_list;
759 text = g_strdup_printf("file:%s", name);
760 remote_client_send(rc, text);
766 if (!started && !sent)
768 remote_client_send(rc, "raise");
773 print_term(_("Remote not available\n"));
780 *-----------------------------------------------------------------------------
781 * command line parser (private) hehe, who needs popt anyway?
782 *-----------------------------------------------------------------------------
785 static gint startup_blank = FALSE;
786 static gint startup_full_screen = FALSE;
787 static gint startup_in_slideshow = FALSE;
788 static gint startup_command_line_collection = FALSE;
791 static void parse_command_line_add_file(const gchar *file_path, gchar **path, gchar **file,
792 GList **list, GList **collection_list)
796 path_parsed = g_strdup(file_path);
797 parse_out_relatives(path_parsed);
799 if (file_extension_match(path_parsed, ".gqv"))
801 *collection_list = g_list_append(*collection_list, path_parsed);
805 if (!*path) *path = remove_level_from_path(path_parsed);
806 if (!*file) *file = g_strdup(path_parsed);
807 *list = g_list_prepend(*list, path_parsed);
811 static void parse_command_line_add_dir(const gchar *dir, gchar **path, gchar **file,
817 path_parsed = g_strdup(dir);
818 parse_out_relatives(path_parsed);
820 if (path_list(path_parsed, &files, NULL))
824 files = path_list_filter(files, FALSE);
825 files = path_list_sort(files);
833 if (!*path) *path = remove_level_from_path(p);
834 if (!*file) *file = g_strdup(p);
835 *list = g_list_prepend(*list, p);
846 static void parse_command_line_process_dir(const gchar *dir, gchar **path, gchar **file,
847 GList **list, gchar **first_dir)
850 if (!*list && !*first_dir)
852 *first_dir = g_strdup(dir);
858 parse_command_line_add_dir(*first_dir, path, file, list);
862 parse_command_line_add_dir(dir, path, file, list);
866 static void parse_command_line_process_file(const gchar *file_path, gchar **path, gchar **file,
867 GList **list, GList **collection_list, gchar **first_dir)
872 parse_command_line_add_dir(*first_dir, path, file, list);
876 parse_command_line_add_file(file_path, path, file, list, collection_list);
879 static void parse_command_line(int argc, char *argv[], gchar **path, gchar **file,
880 GList **cmd_list, GList **collection_list,
884 GList *remote_list = NULL;
885 gint remote_do = FALSE;
886 gchar *first_dir = NULL;
891 gchar *base_dir = get_current_dir();
895 const gchar *cmd_line = argv[i];
896 gchar *cmd_all = concat_dir_and_file(base_dir, cmd_line);
898 if (cmd_line[0] == '/' && isdir(cmd_line))
900 parse_command_line_process_dir(cmd_line, path, file, &list, &first_dir);
902 else if (isdir(cmd_all))
904 parse_command_line_process_dir(cmd_all, path, file, &list, &first_dir);
906 else if (cmd_line[0] == '/' && isfile(cmd_line))
908 parse_command_line_process_file(cmd_line, path, file,
909 &list, collection_list, &first_dir);
911 else if (isfile(cmd_all))
913 parse_command_line_process_file(cmd_all, path, file,
914 &list, collection_list, &first_dir);
916 else if (strcmp(cmd_line, "--debug") == 0)
918 /* we now increment the debug state for verbosity */
920 printf("debugging output enabled (level %d)\n", debug);
922 else if (strcmp(cmd_line, "+t") == 0 ||
923 strcmp(cmd_line, "--with-tools") == 0)
926 tools_hidden = FALSE;
928 remote_list = g_list_append(remote_list, "+t");
930 else if (strcmp(cmd_line, "-t") == 0 ||
931 strcmp(cmd_line, "--without-tools") == 0)
935 remote_list = g_list_append(remote_list, "-t");
937 else if (strcmp(cmd_line, "-f") == 0 ||
938 strcmp(cmd_line, "--fullscreen") == 0)
940 startup_full_screen = TRUE;
942 else if (strcmp(cmd_line, "-s") == 0 ||
943 strcmp(cmd_line, "--slideshow") == 0)
945 startup_in_slideshow = TRUE;
947 else if (strcmp(cmd_line, "-l") == 0 ||
948 strcmp(cmd_line, "--list") == 0)
950 startup_command_line_collection = TRUE;
952 else if (strncmp(cmd_line, "--geometry=", 11) == 0)
954 if (!*geometry) *geometry = g_strdup(cmd_line + 11);
956 else if (strcmp(cmd_line, "-r") == 0 ||
957 strcmp(cmd_line, "--remote") == 0)
962 remote_list = gqview_remote_build_list(remote_list, argc, argv);
965 else if (strcmp(cmd_line, "-rh") == 0 ||
966 strcmp(cmd_line, "--remote-help") == 0)
968 gqview_remote_help();
971 else if (strcmp(cmd_line, "--blank") == 0)
973 startup_blank = TRUE;
975 else if (strcmp(cmd_line, "-v") == 0 ||
976 strcmp(cmd_line, "--version") == 0)
978 printf("GQview %s\n", VERSION);
981 else if (strcmp(cmd_line, "--alternate") == 0)
983 /* enable faster experimental algorithm */
984 printf("Alternate similarity algorithm enabled\n");
985 image_sim_alternate_set(TRUE);
987 else if (strcmp(cmd_line, "-h") == 0 ||
988 strcmp(cmd_line, "--help") == 0)
990 printf("GQview %s\n", VERSION);
991 print_term(_("Usage: gqview [options] [path]\n\n"));
992 print_term(_("valid options are:\n"));
993 print_term(_(" +t, --with-tools force show of tools\n"));
994 print_term(_(" -t, --without-tools force hide of tools\n"));
995 print_term(_(" -f, --fullscreen start in full screen mode\n"));
996 print_term(_(" -s, --slideshow start in slideshow mode\n"));
997 print_term(_(" -l, --list open collection window for command line\n"));
998 print_term(_(" --geometry=GEOMETRY set main window location\n"));
999 print_term(_(" -r, --remote send following commands to open window\n"));
1000 print_term(_(" -rh,--remote-help print remote command list\n"));
1001 print_term(_(" --debug turn on debug output\n"));
1002 print_term(_(" -v, --version print version info\n"));
1003 print_term(_(" -h, --help show this message\n\n"));
1006 /* these options are not officially supported!
1007 * only for testing new features, no need to translate them */
1008 print_term( " --alternate use alternate similarity algorithm\n");
1013 else if (!remote_do)
1017 buf = g_strdup_printf(_("invalid or ignored: %s\nUse --help for options\n"), cmd_line);
1026 parse_out_relatives(*path);
1027 parse_out_relatives(*file);
1030 list = g_list_reverse(list);
1032 if (!*path && first_dir)
1037 parse_out_relatives(*path);
1043 gqview_remote_control(argv[0], remote_list, *path, list, *collection_list);
1045 g_list_free(remote_list);
1047 if (list && list->next)
1053 path_list_free(list);
1059 *-----------------------------------------------------------------------------
1060 * startup, init, and exit
1061 *-----------------------------------------------------------------------------
1064 #define RC_HISTORY_NAME "history"
1066 static void keys_load(void)
1070 path = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/", RC_HISTORY_NAME, NULL);
1071 history_list_load(path);
1075 static void keys_save(void)
1079 path = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/", RC_HISTORY_NAME, NULL);
1080 history_list_save(path);
1084 static void check_for_home_path(gchar *path)
1088 buf = g_strconcat(homedir(), "/", path, NULL);
1093 tmp = g_strdup_printf(_("Creating GQview dir:%s\n"), buf);
1097 if (!mkdir_utf8(buf, 0755))
1099 tmp = g_strdup_printf(_("Could not create dir:%s\n"), buf);
1107 static void setup_default_options(void)
1112 for (i = 0; i < GQVIEW_EDITOR_SLOTS; i++)
1114 editor_name[i] = NULL;
1115 editor_command[i] = NULL;
1118 editor_reset_defaults();
1120 bookmark_add_default(_("Home"), homedir());
1121 path = concat_dir_and_file(homedir(), "Desktop");
1122 bookmark_add_default(_("Desktop"), path);
1124 path = concat_dir_and_file(homedir(), GQVIEW_RC_DIR_COLLECTIONS);
1125 bookmark_add_default(_("Collections"), path);
1128 g_free(safe_delete_path);
1129 safe_delete_path = concat_dir_and_file(homedir(), GQVIEW_RC_DIR_TRASH);
1132 static void exit_gqview_final(void)
1136 LayoutWindow *lw = NULL;
1138 remote_close(gqview_remote);
1140 collect_manager_flush();
1142 if (layout_valid(&lw))
1144 main_window_maximized = window_maximized(lw->window);
1145 if (!main_window_maximized)
1147 layout_geometry_get(NULL, &main_window_x, &main_window_y,
1148 &main_window_w, &main_window_h);
1152 layout_geometry_get_dividers(NULL, &window_hdivider_pos, &window_vdivider_pos);
1154 layout_views_get(NULL, &layout_view_tree, &layout_view_icons);
1156 thumbnails_enabled = layout_thumb_get(NULL);
1157 layout_sort_get(NULL, &file_sort_method, &file_sort_ascending);
1159 layout_geometry_get_tools(NULL, &float_window_x, &float_window_y,
1160 &float_window_w, &float_window_h, &float_window_divider);
1161 layout_tools_float_get(NULL, &tools_float, &tools_hidden);
1162 toolbar_hidden = layout_toolbar_hidden(NULL);
1167 path = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/accels", NULL);
1168 pathl = path_from_utf8(path);
1169 gtk_accel_map_save(pathl);
1176 static GenericDialog *exit_dialog = NULL;
1178 static void exit_confirm_cancel_cb(GenericDialog *gd, gpointer data)
1181 generic_dialog_close(gd);
1184 static void exit_confirm_exit_cb(GenericDialog *gd, gpointer data)
1187 generic_dialog_close(gd);
1188 exit_gqview_final();
1191 static gint exit_confirm_dlg(void)
1198 gtk_window_present(GTK_WINDOW(exit_dialog->dialog));
1202 if (!collection_window_modified_exists()) return FALSE;
1206 if (layout_valid(&lw))
1208 parent = lw->window;
1211 exit_dialog = generic_dialog_new(_("GQview - exit"),
1212 "GQview", "exit", parent, FALSE,
1213 exit_confirm_cancel_cb, NULL);
1214 generic_dialog_add_message(exit_dialog, GTK_STOCK_DIALOG_QUESTION,
1215 _("Quit GQview"), _("Collections have been modified. Quit anyway?"));
1216 generic_dialog_add_button(exit_dialog, GTK_STOCK_QUIT, NULL, exit_confirm_exit_cb, TRUE);
1218 gtk_widget_show(exit_dialog->dialog);
1223 void exit_gqview(void)
1225 layout_image_full_screen_stop(NULL);
1227 if (exit_confirm_dlg()) return;
1229 exit_gqview_final();
1232 int main (int argc, char *argv[])
1236 gchar *cmd_path = NULL;
1237 gchar *cmd_file = NULL;
1238 GList *cmd_list = NULL;
1239 GList *collection_list = NULL;
1240 CollectionData *first_collection = NULL;
1241 gchar *geometry = NULL;
1245 /* setup locale, i18n */
1247 bindtextdomain(PACKAGE, GQVIEW_LOCALEDIR);
1248 bind_textdomain_codeset(PACKAGE, "UTF-8");
1249 textdomain(PACKAGE);
1251 /* setup random seed for random slideshow */
1255 printf("GQview %s, This is a beta release.\n", VERSION);
1258 layout_order = g_strdup("123");
1259 setup_default_options();
1262 parse_command_line(argc, argv, &cmd_path, &cmd_file, &cmd_list, &collection_list, &geometry);
1264 gtk_init (&argc, &argv);
1266 if (gtk_major_version < GTK_MAJOR_VERSION ||
1267 (gtk_major_version == GTK_MAJOR_VERSION && gtk_minor_version < GTK_MINOR_VERSION) )
1270 print_term("!!! This is a friendly warning.\n");
1271 print_term("!!! The version of GTK+ in use now is older than when GQview was compiled.\n");
1272 msg = g_strdup_printf("!!! compiled with GTK+-%d.%d\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION);
1275 msg = g_strdup_printf("!!! running with GTK+-%d.%d\n", gtk_major_version, gtk_minor_version);
1278 print_term("!!! GQview may quit unexpectedly with a relocation error.\n");
1281 check_for_home_path(GQVIEW_RC_DIR);
1282 check_for_home_path(GQVIEW_RC_DIR_COLLECTIONS);
1283 check_for_home_path(GQVIEW_CACHE_RC_THUMB);
1284 check_for_home_path(GQVIEW_CACHE_RC_METADATA);
1287 filter_add_defaults();
1290 buf = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/accels", NULL);
1291 bufl = path_from_utf8(buf);
1292 gtk_accel_map_load(bufl);
1302 path_list_free(cmd_list);
1304 path_list_free(collection_list);
1305 collection_list = NULL;
1311 path = g_strdup(cmd_path);
1313 else if (startup_path_enable && startup_path && isdir(startup_path))
1315 path = g_strdup(startup_path);
1319 path = get_current_dir();
1322 lw = layout_new_with_geometry(NULL, tools_float, tools_hidden, geometry);
1323 layout_sort_set(lw, file_sort_method, file_sort_ascending);
1325 if (collection_list && !startup_command_line_collection)
1329 work = collection_list;
1338 cw = collection_window_new(path);
1339 if (!first_collection && cw) first_collection = cw->cd;
1344 (startup_command_line_collection && collection_list))
1349 if (startup_command_line_collection)
1353 cw = collection_window_new("");
1358 cd = collection_new(""); /* if we pass NULL, untitled counter is falsely increm. */
1359 gqview_command_collection = cd;
1365 cd->name = g_strdup(_("Command line"));
1367 collection_path_changed(cd);
1372 collection_add(cd, (gchar *)work->data, FALSE);
1376 work = collection_list;
1379 collection_load(cd, (gchar *)work->data, TRUE);
1383 layout_set_path(lw, path);
1384 if (cd->list) layout_image_set_collection(lw, cd, cd->list->data);
1386 /* mem leak, we never unref this collection when !startup_command_line_collection
1387 * (the image view of the main window does not hold a ref to the collection)
1388 * this is sort of unavoidable, for if it did hold a ref, next/back
1389 * may not work as expected when closing collection windows.
1391 * collection_unref(cd);
1397 layout_set_path(lw, cmd_file);
1401 layout_set_path(lw, path);
1402 if (first_collection)
1404 layout_image_set_collection(lw, first_collection,
1405 collection_get_first(first_collection));
1412 path_list_free(cmd_list);
1413 path_list_free(collection_list);
1416 if (startup_full_screen) layout_image_full_screen_start(lw);
1417 if (startup_in_slideshow) layout_image_slideshow_start(lw);
1419 buf = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/.command", NULL);
1420 gqview_remote = remote_server_open(buf);
1421 remote_server_subscribe(gqview_remote, gqview_remote_cb, NULL);