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"
21 #include "image-overlay.h"
24 #include "layout_image.h"
26 #include "pixbuf_util.h"
27 #include "preferences.h"
31 #include "slideshow.h"
33 #include "ui_bookmark.h"
35 #include "ui_fileops.h"
36 #include "ui_tabcomp.h"
37 #include "ui_utildlg.h"
39 #include <gdk/gdkkeysyms.h> /* for keyboard values */
45 static RemoteConnection *remote_connection = NULL;
46 static CollectionData *command_collection = NULL;
50 *-----------------------------------------------------------------------------
52 *-----------------------------------------------------------------------------
55 void window_set_icon(GtkWidget *window, const gchar *icon, const gchar *file)
57 if (!icon && !file) icon = PIXBUF_INLINE_ICON;
63 pixbuf = pixbuf_inline(icon);
66 gtk_window_set_icon(GTK_WINDOW(window), pixbuf);
67 g_object_unref(pixbuf);
72 gtk_window_set_icon_from_file(GTK_WINDOW(window), file, NULL);
76 gint window_maximized(GtkWidget *window)
80 if (!window || !window->window) return FALSE;
82 state = gdk_window_get_state(window->window);
83 return (state & GDK_WINDOW_STATE_MAXIMIZED);
86 gdouble get_zoom_increment(void)
88 return ((zoom_increment != 0) ? (gdouble)zoom_increment / 10.0 : 1.0);
92 *-----------------------------------------------------------------------------
93 * Open browser with the help Documentation
94 *-----------------------------------------------------------------------------
97 static gchar *command_result(const gchar *binary, const gchar *command)
104 if (!binary) return NULL;
105 if (!file_in_path(binary)) return NULL;
107 if (!command) return g_strdup(binary);
108 if (command[0] == '!') return g_strdup(command + 1);
110 f = popen(command, "r");
113 while ((l = fread(buf, sizeof(char), sizeof(buf), f)) > 0)
119 while (n < l && buf[n] != '\n' && buf[n] != '\r') n++;
120 if (n > 0) result = g_strndup(buf, n);
129 static void help_browser_command(const gchar *command, const gchar *path)
136 if (!command || !path) return;
138 if (debug) printf("Help command pre \"%s\", \"%s\"\n", command, path);
140 buf = g_strdup(command);
141 begin = strstr(buf, "%s");
148 result = g_strdup_printf("%s%s%s &", begin, path, end);
152 result = g_strdup_printf("%s \"%s\" &", command, path);
156 if (debug) printf("Help command post [%s]\n", result);
164 * each set of 2 strings is one browser:
165 * the 1st is the binary to look for in the path
166 * the 2nd has 3 capabilities:
167 * NULL exec binary with html file path as command line
168 * string exec string and use results for command line
169 * !string use text following ! as command line, replacing optional %s with html file path
171 static gchar *html_browsers[] =
173 /* Redhat has a nifty htmlview script to start the user's preferred browser */
176 "gconftool-2", "gconftool-2 -g /desktop/gnome/url-handlers/http/command",
178 "kfmclient", "!kfmclient exec \"%s\"",
187 static void help_browser_run(void)
189 gchar *result = NULL;
193 while (!result && html_browsers[i])
195 result = command_result(html_browsers[i], html_browsers[i+1]);
201 printf("Unable to detect an installed browser.\n");
205 help_browser_command(result, GQ_HTMLDIR "/index.html");
211 *-----------------------------------------------------------------------------
213 *-----------------------------------------------------------------------------
216 static GtkWidget *help_window = NULL;
218 static void help_window_destroy_cb(GtkWidget *window, gpointer data)
223 void help_window_show(const gchar *key)
225 if (key && strcmp(key, "html_contents") == 0)
233 gtk_window_present(GTK_WINDOW(help_window));
234 if (key) help_window_set_key(help_window, key);
238 help_window = help_window_new(_("Help - Geeqie"), GQ_WMCLASS, "help",
239 GQ_HELPDIR "/README", key);
240 g_signal_connect(G_OBJECT(help_window), "destroy",
241 G_CALLBACK(help_window_destroy_cb), NULL);
246 *-----------------------------------------------------------------------------
248 *-----------------------------------------------------------------------------
251 void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event)
253 static gint delta = 0;
254 static guint32 time_old = 0;
255 static guint keyval_old = 0;
257 if (event->state & GDK_CONTROL_MASK)
259 if (*x < 0) *x = G_MININT / 2;
260 if (*x > 0) *x = G_MAXINT / 2;
261 if (*y < 0) *y = G_MININT / 2;
262 if (*y > 0) *y = G_MAXINT / 2;
267 if (progressive_key_scrolling)
271 time_diff = event->time - time_old;
273 /* key pressed within 125ms ? (1/8 second) */
274 if (time_diff > 125 || event->keyval != keyval_old) delta = 0;
276 time_old = event->time;
277 keyval_old = event->keyval;
292 *-----------------------------------------------------------------------------
294 *-----------------------------------------------------------------------------
297 static void gr_image_next(const gchar *text, gpointer data)
299 layout_image_next(NULL);
302 static void gr_image_prev(const gchar *text, gpointer data)
304 layout_image_prev(NULL);
307 static void gr_image_first(const gchar *text, gpointer data)
309 layout_image_first(NULL);
312 static void gr_image_last(const gchar *text, gpointer data)
314 layout_image_last(NULL);
317 static void gr_fullscreen_toggle(const gchar *text, gpointer data)
319 layout_image_full_screen_toggle(NULL);
322 static void gr_fullscreen_start(const gchar *text, gpointer data)
324 layout_image_full_screen_start(NULL);
327 static void gr_fullscreen_stop(const gchar *text, gpointer data)
329 layout_image_full_screen_stop(NULL);
332 static void gr_slideshow_start_rec(const gchar *text, gpointer data)
336 list = path_list_recursive(text);
338 //printf("length: %d\n", g_list_length(list));
339 layout_image_slideshow_stop(NULL);
340 layout_image_slideshow_start_from_list(NULL, list);
343 static void gr_slideshow_toggle(const gchar *text, gpointer data)
345 layout_image_slideshow_toggle(NULL);
348 static void gr_slideshow_start(const gchar *text, gpointer data)
350 layout_image_slideshow_start(NULL);
353 static void gr_slideshow_stop(const gchar *text, gpointer data)
355 layout_image_slideshow_stop(NULL);
358 static void gr_slideshow_delay(const gchar *text, gpointer data)
362 n = strtod(text, NULL);
363 if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS)
367 buf = g_strdup_printf("Remote slideshow delay out of range (%.1f to %.1f)\n",
368 SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
374 slideshow_delay = (gint)(n * 10.0 + 0.01);
377 static void gr_tools_show(const gchar *text, gpointer data)
382 if (layout_tools_float_get(NULL, &popped, &hidden) && hidden)
384 layout_tools_float_set(NULL, popped, FALSE);
388 static void gr_tools_hide(const gchar *text, gpointer data)
393 if (layout_tools_float_get(NULL, &popped, &hidden) && !hidden)
395 layout_tools_float_set(NULL, popped, TRUE);
399 static gint gr_quit_idle_cb(gpointer data)
406 static void gr_quit(const gchar *text, gpointer data)
408 /* schedule exit when idle, if done from within a
409 * remote handler remote_close will crash
411 g_idle_add(gr_quit_idle_cb, NULL);
414 static void gr_file_load(const gchar *text, gpointer data)
418 if (file_extension_match(text, ".gqv"))
420 collection_window_new(text);
424 layout_set_path(NULL, text);
427 else if (isdir(text))
429 layout_set_path(NULL, text);
433 printf("remote sent filename that does not exist:\"%s\"\n", text);
437 static void gr_file_view(const gchar *text, gpointer data)
439 view_window_new(file_data_new_simple(text));
442 static void gr_list_clear(const gchar *text, gpointer data)
444 if (command_collection) collection_unref(command_collection);
445 command_collection = NULL;
448 static void gr_list_add(const gchar *text, gpointer data)
452 if (!command_collection)
456 cd = collection_new("");
461 cd->name = g_strdup(_("Command line"));
463 command_collection = cd;
467 new = (!collection_get_first(command_collection));
470 if (collection_add(command_collection, file_data_new_simple(text), FALSE) && new)
472 layout_image_set_collection(NULL, command_collection,
473 collection_get_first(command_collection));
477 static void gr_raise(const gchar *text, gpointer data)
479 LayoutWindow *lw = NULL;
481 if (layout_valid(&lw))
483 gtk_window_present(GTK_WINDOW(lw->window));
487 typedef struct _RemoteCommandEntry RemoteCommandEntry;
488 struct _RemoteCommandEntry {
491 void (*func)(const gchar *text, gpointer data);
493 gint prefer_command_line;
497 static RemoteCommandEntry remote_commands[] = {
498 /* short, long callback, extra, prefer,description */
499 { "-n", "--next", gr_image_next, FALSE, FALSE, N_("next image") },
500 { "-b", "--back", gr_image_prev, FALSE, FALSE, N_("previous image") },
501 { NULL, "--first", gr_image_first, FALSE, FALSE, N_("first image") },
502 { NULL, "--last", gr_image_last, FALSE, FALSE, N_("last image") },
503 { "-f", "--fullscreen", gr_fullscreen_toggle, FALSE, TRUE, N_("toggle full screen") },
504 { "-fs","--fullscreen-start", gr_fullscreen_start, FALSE, FALSE, N_("start full screen") },
505 { "-fS","--fullscreen-stop", gr_fullscreen_stop, FALSE, FALSE, N_("stop full screen") },
506 { "-s", "--slideshow", gr_slideshow_toggle, FALSE, TRUE, N_("toggle slide show") },
507 { "-ss","--slideshow-start", gr_slideshow_start, FALSE, FALSE, N_("start slide show") },
508 { "-sS","--slideshow-stop", gr_slideshow_stop, FALSE, FALSE, N_("stop slide show") },
509 { "-sr","--slideshow-recurse", gr_slideshow_start_rec, TRUE, FALSE, N_("start recursive slide show") },
510 { "-d", "--delay=", gr_slideshow_delay, TRUE, FALSE, N_("set slide show delay in seconds") },
511 { "+t", "--tools-show", gr_tools_show, FALSE, TRUE, N_("show tools") },
512 { "-t", "--tools-hide", gr_tools_hide, FALSE, TRUE, N_("hide tools") },
513 { "-q", "--quit", gr_quit, FALSE, FALSE, N_("quit") },
514 { NULL, "file:", gr_file_load, TRUE, FALSE, N_("open file") },
515 { NULL, "view:", gr_file_view, TRUE, FALSE, N_("open file in new window") },
516 { NULL, "--list-clear", gr_list_clear, FALSE, FALSE, NULL },
517 { NULL, "--list-add:", gr_list_add, TRUE, FALSE, NULL },
518 { NULL, "raise", gr_raise, FALSE, FALSE, NULL },
519 { NULL, NULL, NULL, FALSE, FALSE, NULL }
522 static RemoteCommandEntry *remote_command_find(const gchar *text, const gchar **offset)
528 while (!match && remote_commands[i].func != NULL)
530 if (remote_commands[i].needs_extra)
532 if (remote_commands[i].opt_s &&
533 strncmp(remote_commands[i].opt_s, text, strlen(remote_commands[i].opt_s)) == 0)
535 if (offset) *offset = text + strlen(remote_commands[i].opt_s);
536 return &remote_commands[i];
538 else if (remote_commands[i].opt_l &&
539 strncmp(remote_commands[i].opt_l, text, strlen(remote_commands[i].opt_l)) == 0)
541 if (offset) *offset = text + strlen(remote_commands[i].opt_l);
542 return &remote_commands[i];
547 if ((remote_commands[i].opt_s && strcmp(remote_commands[i].opt_s, text) == 0) ||
548 (remote_commands[i].opt_l && strcmp(remote_commands[i].opt_l, text) == 0))
550 if (offset) *offset = text;
551 return &remote_commands[i];
561 static void remote_cb(RemoteConnection *rc, const gchar *text, gpointer data)
563 RemoteCommandEntry *entry;
566 entry = remote_command_find(text, &offset);
567 if (entry && entry->func)
569 entry->func(offset, data);
573 printf("unknown remote command:%s\n", text);
577 static void remote_help(void)
581 print_term(_("Remote command list:\n"));
584 while (remote_commands[i].func != NULL)
586 if (remote_commands[i].description)
590 buf = g_strdup_printf(" %-3s%s %-20s %s\n",
591 (remote_commands[i].opt_s) ? remote_commands[i].opt_s : "",
592 (remote_commands[i].opt_s && remote_commands[i].opt_l) ? "," : " ",
593 (remote_commands[i].opt_l) ? remote_commands[i].opt_l : "",
594 _(remote_commands[i].description));
603 static GList *remote_build_list(GList *list, int argc, char *argv[])
610 RemoteCommandEntry *entry;
612 entry = remote_command_find(argv[i], NULL);
615 list = g_list_append(list, argv[i]);
623 static void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path,
624 GList *cmd_list, GList *collection_list)
626 RemoteConnection *rc;
627 gint started = FALSE;
630 buf = g_strconcat(homedir(), "/", GQ_RC_DIR, "/.command", NULL);
631 rc = remote_client_open(buf);
636 gint retry_count = 12;
639 print_term(_("Remote Geeqie not running, starting..."));
640 command = g_string_new(arg_exec);
646 RemoteCommandEntry *entry;
651 entry = remote_command_find(text, NULL);
654 if (entry->prefer_command_line)
656 remote_list = g_list_remove(remote_list, text);
657 g_string_append(command, " ");
658 g_string_append(command, text);
660 if (entry->opt_l && strcmp(entry->opt_l, "file:") == 0)
667 if (blank || cmd_list || path) g_string_append(command, " --blank");
668 if (debug) g_string_append(command, " --debug");
670 g_string_append(command, " &");
671 system(command->str);
672 g_string_free(command, TRUE);
674 while (!rc && retry_count > 0)
676 usleep((retry_count > 10) ? 500000 : 1000000);
677 rc = remote_client_open(buf);
678 if (!rc) print_term(".");
692 gint use_path = TRUE;
699 RemoteCommandEntry *entry;
704 entry = remote_command_find(text, NULL);
707 strcmp(entry->opt_l, "file:") == 0) use_path = FALSE;
709 remote_client_send(rc, text);
714 if (cmd_list && cmd_list->next)
716 prefix = "--list-add:";
717 remote_client_send(rc, "--list-clear");
733 text = g_strconcat(prefix, name, NULL);
734 remote_client_send(rc, text);
740 if (path && !cmd_list && use_path)
744 text = g_strdup_printf("file:%s", path);
745 remote_client_send(rc, text);
751 work = collection_list;
760 text = g_strdup_printf("file:%s", name);
761 remote_client_send(rc, text);
767 if (!started && !sent)
769 remote_client_send(rc, "raise");
774 print_term(_("Remote not available\n"));
781 *-----------------------------------------------------------------------------
782 * command line parser (private) hehe, who needs popt anyway?
783 *-----------------------------------------------------------------------------
786 static gint startup_blank = FALSE;
787 static gint startup_full_screen = FALSE;
788 static gint startup_in_slideshow = FALSE;
789 static gint startup_command_line_collection = FALSE;
792 static void parse_command_line_add_file(const gchar *file_path, gchar **path, gchar **file,
793 GList **list, GList **collection_list)
797 path_parsed = g_strdup(file_path);
798 parse_out_relatives(path_parsed);
800 if (file_extension_match(path_parsed, ".gqv"))
802 *collection_list = g_list_append(*collection_list, path_parsed);
806 if (!*path) *path = remove_level_from_path(path_parsed);
807 if (!*file) *file = g_strdup(path_parsed);
808 *list = g_list_prepend(*list, path_parsed);
812 static void parse_command_line_add_dir(const gchar *dir, gchar **path, gchar **file,
818 path_parsed = g_strdup(dir);
819 parse_out_relatives(path_parsed);
821 if (path_list(path_parsed, &files, NULL))
825 files = path_list_filter(files, FALSE);
826 files = path_list_sort(files);
834 if (!*path) *path = remove_level_from_path(p);
835 if (!*file) *file = g_strdup(p);
836 *list = g_list_prepend(*list, p);
847 static void parse_command_line_process_dir(const gchar *dir, gchar **path, gchar **file,
848 GList **list, gchar **first_dir)
851 if (!*list && !*first_dir)
853 *first_dir = g_strdup(dir);
859 parse_command_line_add_dir(*first_dir, path, file, list);
863 parse_command_line_add_dir(dir, path, file, list);
867 static void parse_command_line_process_file(const gchar *file_path, gchar **path, gchar **file,
868 GList **list, GList **collection_list, gchar **first_dir)
873 parse_command_line_add_dir(*first_dir, path, file, list);
877 parse_command_line_add_file(file_path, path, file, list, collection_list);
880 static void parse_command_line(int argc, char *argv[], gchar **path, gchar **file,
881 GList **cmd_list, GList **collection_list,
885 GList *remote_list = NULL;
886 gint remote_do = FALSE;
887 gchar *first_dir = NULL;
892 gchar *base_dir = get_current_dir();
896 const gchar *cmd_line = argv[i];
897 gchar *cmd_all = concat_dir_and_file(base_dir, cmd_line);
899 if (cmd_line[0] == '/' && isdir(cmd_line))
901 parse_command_line_process_dir(cmd_line, path, file, &list, &first_dir);
903 else if (isdir(cmd_all))
905 parse_command_line_process_dir(cmd_all, path, file, &list, &first_dir);
907 else if (cmd_line[0] == '/' && isfile(cmd_line))
909 parse_command_line_process_file(cmd_line, path, file,
910 &list, collection_list, &first_dir);
912 else if (isfile(cmd_all))
914 parse_command_line_process_file(cmd_all, path, file,
915 &list, collection_list, &first_dir);
918 else if (strcmp(cmd_line, "--debug") == 0)
920 /* we now increment the debug state for verbosity */
922 printf("debugging output enabled (level %d)\n", debug);
925 else if (strcmp(cmd_line, "+t") == 0 ||
926 strcmp(cmd_line, "--with-tools") == 0)
929 tools_hidden = FALSE;
931 remote_list = g_list_append(remote_list, "+t");
933 else if (strcmp(cmd_line, "-t") == 0 ||
934 strcmp(cmd_line, "--without-tools") == 0)
938 remote_list = g_list_append(remote_list, "-t");
940 else if (strcmp(cmd_line, "-f") == 0 ||
941 strcmp(cmd_line, "--fullscreen") == 0)
943 startup_full_screen = TRUE;
945 else if (strcmp(cmd_line, "-s") == 0 ||
946 strcmp(cmd_line, "--slideshow") == 0)
948 startup_in_slideshow = TRUE;
950 else if (strcmp(cmd_line, "-l") == 0 ||
951 strcmp(cmd_line, "--list") == 0)
953 startup_command_line_collection = TRUE;
955 else if (strncmp(cmd_line, "--geometry=", 11) == 0)
957 if (!*geometry) *geometry = g_strdup(cmd_line + 11);
959 else if (strcmp(cmd_line, "-r") == 0 ||
960 strcmp(cmd_line, "--remote") == 0)
965 remote_list = remote_build_list(remote_list, argc, argv);
968 else if (strcmp(cmd_line, "-rh") == 0 ||
969 strcmp(cmd_line, "--remote-help") == 0)
974 else if (strcmp(cmd_line, "--blank") == 0)
976 startup_blank = TRUE;
978 else if (strcmp(cmd_line, "-v") == 0 ||
979 strcmp(cmd_line, "--version") == 0)
981 printf("Geeqie %s\n", VERSION);
984 else if (strcmp(cmd_line, "--alternate") == 0)
986 /* enable faster experimental algorithm */
987 printf("Alternate similarity algorithm enabled\n");
988 image_sim_alternate_set(TRUE);
990 else if (strcmp(cmd_line, "-h") == 0 ||
991 strcmp(cmd_line, "--help") == 0)
993 printf("Geeqie %s\n", VERSION);
994 print_term(_("Usage: gqview [options] [path]\n\n"));
995 print_term(_("valid options are:\n"));
996 print_term(_(" +t, --with-tools force show of tools\n"));
997 print_term(_(" -t, --without-tools force hide of tools\n"));
998 print_term(_(" -f, --fullscreen start in full screen mode\n"));
999 print_term(_(" -s, --slideshow start in slideshow mode\n"));
1000 print_term(_(" -l, --list open collection window for command line\n"));
1001 print_term(_(" --geometry=GEOMETRY set main window location\n"));
1002 print_term(_(" -r, --remote send following commands to open window\n"));
1003 print_term(_(" -rh,--remote-help print remote command list\n"));
1005 print_term(_(" --debug turn on debug output\n"));
1007 print_term(_(" -v, --version print version info\n"));
1008 print_term(_(" -h, --help show this message\n\n"));
1011 /* these options are not officially supported!
1012 * only for testing new features, no need to translate them */
1013 print_term( " --alternate use alternate similarity algorithm\n");
1018 else if (!remote_do)
1022 buf = g_strdup_printf(_("invalid or ignored: %s\nUse --help for options\n"), cmd_line);
1031 parse_out_relatives(*path);
1032 parse_out_relatives(*file);
1035 list = g_list_reverse(list);
1037 if (!*path && first_dir)
1042 parse_out_relatives(*path);
1048 remote_control(argv[0], remote_list, *path, list, *collection_list);
1050 g_list_free(remote_list);
1052 if (list && list->next)
1058 path_list_free(list);
1064 *-----------------------------------------------------------------------------
1065 * startup, init, and exit
1066 *-----------------------------------------------------------------------------
1069 #define RC_HISTORY_NAME "history"
1071 static void keys_load(void)
1075 path = g_strconcat(homedir(), "/", GQ_RC_DIR, "/", RC_HISTORY_NAME, NULL);
1076 history_list_load(path);
1080 static void keys_save(void)
1084 path = g_strconcat(homedir(), "/", GQ_RC_DIR, "/", RC_HISTORY_NAME, NULL);
1085 history_list_save(path);
1089 static void check_for_home_path(gchar *path)
1093 buf = g_strconcat(homedir(), "/", path, NULL);
1098 tmp = g_strdup_printf(_("Creating Geeqie dir:%s\n"), buf);
1102 if (!mkdir_utf8(buf, 0755))
1104 tmp = g_strdup_printf(_("Could not create dir:%s\n"), buf);
1112 static void setup_default_options(void)
1117 for (i = 0; i < GQ_EDITOR_SLOTS; i++)
1119 editor_name[i] = NULL;
1120 editor_command[i] = NULL;
1123 editor_reset_defaults();
1125 bookmark_add_default(_("Home"), homedir());
1126 path = concat_dir_and_file(homedir(), "Desktop");
1127 bookmark_add_default(_("Desktop"), path);
1129 path = concat_dir_and_file(homedir(), GQ_RC_DIR_COLLECTIONS);
1130 bookmark_add_default(_("Collections"), path);
1133 g_free(safe_delete_path);
1134 safe_delete_path = concat_dir_and_file(homedir(), GQ_RC_DIR_TRASH);
1136 for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
1138 color_profile_input_file[i] = NULL;
1139 color_profile_input_name[i] = NULL;
1142 fullscreen_info = g_strdup("%collection%(%number%/%total%) <b>%name%</b>\n"
1143 "%res%|%date%|%size%\n"
1144 "%fAperture%|%fShutterSpeed%|%fISOSpeedRating%|%fFocalLength%|%fExposureBias%\n"
1145 "%fCamera%|%fFlash%");
1147 sidecar_ext_add_defaults();
1150 static void exit_program_final(void)
1154 LayoutWindow *lw = NULL;
1156 remote_close(remote_connection);
1158 collect_manager_flush();
1160 if (layout_valid(&lw))
1162 main_window_maximized = window_maximized(lw->window);
1163 if (!main_window_maximized)
1165 layout_geometry_get(NULL, &main_window_x, &main_window_y,
1166 &main_window_w, &main_window_h);
1168 show_fullscreen_info = image_osd_get(lw->image, NULL, NULL);
1171 layout_geometry_get_dividers(NULL, &window_hdivider_pos, &window_vdivider_pos);
1173 layout_views_get(NULL, &layout_view_tree, &layout_view_icons);
1175 thumbnails_enabled = layout_thumb_get(NULL);
1176 layout_sort_get(NULL, &file_sort_method, &file_sort_ascending);
1178 layout_geometry_get_tools(NULL, &float_window_x, &float_window_y,
1179 &float_window_w, &float_window_h, &float_window_divider);
1180 layout_tools_float_get(NULL, &tools_float, &tools_hidden);
1181 toolbar_hidden = layout_toolbar_hidden(NULL);
1183 color_profile_enabled = layout_image_color_profile_get_use(NULL);
1184 layout_image_color_profile_get(NULL,
1185 &color_profile_input_type, &color_profile_screen_type,
1186 &color_profile_use_image);
1191 path = g_strconcat(homedir(), "/", GQ_RC_DIR, "/accels", NULL);
1192 pathl = path_from_utf8(path);
1193 gtk_accel_map_save(pathl);
1200 static GenericDialog *exit_dialog = NULL;
1202 static void exit_confirm_cancel_cb(GenericDialog *gd, gpointer data)
1205 generic_dialog_close(gd);
1208 static void exit_confirm_exit_cb(GenericDialog *gd, gpointer data)
1211 generic_dialog_close(gd);
1212 exit_program_final();
1215 static gint exit_confirm_dlg(void)
1222 gtk_window_present(GTK_WINDOW(exit_dialog->dialog));
1226 if (!collection_window_modified_exists()) return FALSE;
1230 if (layout_valid(&lw))
1232 parent = lw->window;
1235 exit_dialog = generic_dialog_new(_("Geeqie - exit"),
1236 GQ_WMCLASS, "exit", parent, FALSE,
1237 exit_confirm_cancel_cb, NULL);
1238 generic_dialog_add_message(exit_dialog, GTK_STOCK_DIALOG_QUESTION,
1239 _("Quit Geeqie"), _("Collections have been modified. Quit anyway?"));
1240 generic_dialog_add_button(exit_dialog, GTK_STOCK_QUIT, NULL, exit_confirm_exit_cb, TRUE);
1242 gtk_widget_show(exit_dialog->dialog);
1247 void exit_program(void)
1249 layout_image_full_screen_stop(NULL);
1251 if (exit_confirm_dlg()) return;
1253 exit_program_final();
1256 int main (int argc, char *argv[])
1260 gchar *cmd_path = NULL;
1261 gchar *cmd_file = NULL;
1262 GList *cmd_list = NULL;
1263 GList *collection_list = NULL;
1264 CollectionData *first_collection = NULL;
1265 gchar *geometry = NULL;
1269 /* setup locale, i18n */
1271 bindtextdomain(PACKAGE, GQ_LOCALEDIR);
1272 bind_textdomain_codeset(PACKAGE, "UTF-8");
1273 textdomain(PACKAGE);
1275 /* setup random seed for random slideshow */
1279 printf("geeqie %s, This is an alpha release.\n", VERSION);
1282 layout_order = g_strdup("123");
1283 setup_default_options();
1286 parse_command_line(argc, argv, &cmd_path, &cmd_file, &cmd_list, &collection_list, &geometry);
1288 gtk_init (&argc, &argv);
1290 if (gtk_major_version < GTK_MAJOR_VERSION ||
1291 (gtk_major_version == GTK_MAJOR_VERSION && gtk_minor_version < GTK_MINOR_VERSION) )
1294 print_term("!!! This is a friendly warning.\n");
1295 print_term("!!! The version of GTK+ in use now is older than when Geeqie was compiled.\n");
1296 msg = g_strdup_printf("!!! compiled with GTK+-%d.%d\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION);
1299 msg = g_strdup_printf("!!! running with GTK+-%d.%d\n", gtk_major_version, gtk_minor_version);
1302 print_term("!!! Geeqie may quit unexpectedly with a relocation error.\n");
1305 check_for_home_path(GQ_RC_DIR);
1306 check_for_home_path(GQ_RC_DIR_COLLECTIONS);
1307 check_for_home_path(GQ_CACHE_RC_THUMB);
1308 check_for_home_path(GQ_CACHE_RC_METADATA);
1311 filter_add_defaults();
1314 buf = g_strconcat(homedir(), "/", GQ_RC_DIR, "/accels", NULL);
1315 bufl = path_from_utf8(buf);
1316 gtk_accel_map_load(bufl);
1326 path_list_free(cmd_list);
1328 path_list_free(collection_list);
1329 collection_list = NULL;
1335 path = g_strdup(cmd_path);
1337 else if (startup_path_enable && startup_path && isdir(startup_path))
1339 path = g_strdup(startup_path);
1343 path = get_current_dir();
1346 lw = layout_new_with_geometry(NULL, tools_float, tools_hidden, geometry);
1347 layout_sort_set(lw, file_sort_method, file_sort_ascending);
1349 if (collection_list && !startup_command_line_collection)
1353 work = collection_list;
1362 cw = collection_window_new(path);
1363 if (!first_collection && cw) first_collection = cw->cd;
1368 (startup_command_line_collection && collection_list))
1373 if (startup_command_line_collection)
1377 cw = collection_window_new("");
1382 cd = collection_new(""); /* if we pass NULL, untitled counter is falsely increm. */
1383 command_collection = cd;
1389 cd->name = g_strdup(_("Command line"));
1391 collection_path_changed(cd);
1396 collection_add(cd, file_data_new_simple((gchar *)work->data), FALSE);
1400 work = collection_list;
1403 collection_load(cd, (gchar *)work->data, TRUE);
1407 layout_set_path(lw, path);
1408 if (cd->list) layout_image_set_collection(lw, cd, cd->list->data);
1410 /* mem leak, we never unref this collection when !startup_command_line_collection
1411 * (the image view of the main window does not hold a ref to the collection)
1412 * this is sort of unavoidable, for if it did hold a ref, next/back
1413 * may not work as expected when closing collection windows.
1415 * collection_unref(cd);
1421 layout_set_path(lw, cmd_file);
1425 layout_set_path(lw, path);
1426 if (first_collection)
1428 layout_image_set_collection(lw, first_collection,
1429 collection_get_first(first_collection));
1432 image_osd_set(lw->image, FALSE, show_fullscreen_info);
1437 path_list_free(cmd_list);
1438 path_list_free(collection_list);
1441 if (startup_full_screen) layout_image_full_screen_start(lw);
1442 if (startup_in_slideshow) layout_image_slideshow_start(lw);
1444 buf = g_strconcat(homedir(), "/", GQ_RC_DIR, "/.command", NULL);
1445 remote_connection = remote_server_open(buf);
1446 remote_server_subscribe(remote_connection, remote_cb, NULL);