4 * Copyright (C) 2008 The Geeqie Team
8 * This software is released under the GNU General Public License (GNU GPL).
9 * Please read the included file COPYING for more information.
10 * This software comes with no warranty of any kind, use at your own risk!
18 #include "collect-io.h"
23 #include "filefilter.h"
24 #include "fullscreen.h"
25 #include "image-overlay.h"
28 #include "layout_image.h"
30 #include "pixbuf_util.h"
31 #include "preferences.h"
35 #include "slideshow.h"
37 #include "ui_bookmark.h"
39 #include "ui_fileops.h"
40 #include "ui_tabcomp.h"
41 #include "ui_utildlg.h"
44 #include <gdk/gdkkeysyms.h> /* for keyboard values */
50 static RemoteConnection *remote_connection = NULL;
51 static CollectionData *command_collection = NULL;
55 *-----------------------------------------------------------------------------
57 *-----------------------------------------------------------------------------
61 gdouble get_zoom_increment(void)
63 return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 10.0 : 1.0);
66 gchar *utf8_validate_or_convert(gchar *text)
70 if (!text) return NULL;
73 if (!g_utf8_validate(text, len, NULL))
77 conv_text = g_convert(text, len, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
86 *-----------------------------------------------------------------------------
88 *-----------------------------------------------------------------------------
91 void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event)
93 static gint delta = 0;
94 static guint32 time_old = 0;
95 static guint keyval_old = 0;
97 if (event->state & GDK_CONTROL_MASK)
99 if (*x < 0) *x = G_MININT / 2;
100 if (*x > 0) *x = G_MAXINT / 2;
101 if (*y < 0) *y = G_MININT / 2;
102 if (*y > 0) *y = G_MAXINT / 2;
107 if (options->progressive_key_scrolling)
111 time_diff = event->time - time_old;
113 /* key pressed within 125ms ? (1/8 second) */
114 if (time_diff > 125 || event->keyval != keyval_old) delta = 0;
116 time_old = event->time;
117 keyval_old = event->keyval;
132 *-----------------------------------------------------------------------------
134 *-----------------------------------------------------------------------------
137 static void gr_image_next(const gchar *text, gpointer data)
139 layout_image_next(NULL);
142 static void gr_image_prev(const gchar *text, gpointer data)
144 layout_image_prev(NULL);
147 static void gr_image_first(const gchar *text, gpointer data)
149 layout_image_first(NULL);
152 static void gr_image_last(const gchar *text, gpointer data)
154 layout_image_last(NULL);
157 static void gr_fullscreen_toggle(const gchar *text, gpointer data)
159 layout_image_full_screen_toggle(NULL);
162 static void gr_fullscreen_start(const gchar *text, gpointer data)
164 layout_image_full_screen_start(NULL);
167 static void gr_fullscreen_stop(const gchar *text, gpointer data)
169 layout_image_full_screen_stop(NULL);
172 static void gr_slideshow_start_rec(const gchar *text, gpointer data)
176 list = filelist_recursive(text);
178 //printf("length: %d\n", g_list_length(list));
179 layout_image_slideshow_stop(NULL);
180 layout_image_slideshow_start_from_list(NULL, list);
183 static void gr_slideshow_toggle(const gchar *text, gpointer data)
185 layout_image_slideshow_toggle(NULL);
188 static void gr_slideshow_start(const gchar *text, gpointer data)
190 layout_image_slideshow_start(NULL);
193 static void gr_slideshow_stop(const gchar *text, gpointer data)
195 layout_image_slideshow_stop(NULL);
198 static void gr_slideshow_delay(const gchar *text, gpointer data)
202 n = strtod(text, NULL);
203 if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS)
205 printf_term("Remote slideshow delay out of range (%.1f to %.1f)\n",
206 SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
209 options->slideshow.delay = (gint)(n * 10.0 + 0.01);
212 static void gr_tools_show(const gchar *text, gpointer data)
217 if (layout_tools_float_get(NULL, &popped, &hidden) && hidden)
219 layout_tools_float_set(NULL, popped, FALSE);
223 static void gr_tools_hide(const gchar *text, gpointer data)
228 if (layout_tools_float_get(NULL, &popped, &hidden) && !hidden)
230 layout_tools_float_set(NULL, popped, TRUE);
234 static gint gr_quit_idle_cb(gpointer data)
241 static void gr_quit(const gchar *text, gpointer data)
243 /* schedule exit when idle, if done from within a
244 * remote handler remote_close will crash
246 g_idle_add(gr_quit_idle_cb, NULL);
249 static void gr_file_load(const gchar *text, gpointer data)
253 if (file_extension_match(text, ".gqv"))
255 collection_window_new(text);
259 layout_set_path(NULL, text);
262 else if (isdir(text))
264 layout_set_path(NULL, text);
268 printf("remote sent filename that does not exist:\"%s\"\n", text);
272 static void gr_file_view(const gchar *text, gpointer data)
274 view_window_new(file_data_new_simple(text));
277 static void gr_list_clear(const gchar *text, gpointer data)
279 if (command_collection) collection_unref(command_collection);
280 command_collection = NULL;
283 static void gr_list_add(const gchar *text, gpointer data)
287 if (!command_collection)
291 cd = collection_new("");
296 cd->name = g_strdup(_("Command line"));
298 command_collection = cd;
302 new = (!collection_get_first(command_collection));
305 if (collection_add(command_collection, file_data_new_simple(text), FALSE) && new)
307 layout_image_set_collection(NULL, command_collection,
308 collection_get_first(command_collection));
312 static void gr_raise(const gchar *text, gpointer data)
314 LayoutWindow *lw = NULL;
316 if (layout_valid(&lw))
318 gtk_window_present(GTK_WINDOW(lw->window));
322 typedef struct _RemoteCommandEntry RemoteCommandEntry;
323 struct _RemoteCommandEntry {
326 void (*func)(const gchar *text, gpointer data);
328 gint prefer_command_line;
332 static RemoteCommandEntry remote_commands[] = {
333 /* short, long callback, extra, prefer,description */
334 { "-n", "--next", gr_image_next, FALSE, FALSE, N_("next image") },
335 { "-b", "--back", gr_image_prev, FALSE, FALSE, N_("previous image") },
336 { NULL, "--first", gr_image_first, FALSE, FALSE, N_("first image") },
337 { NULL, "--last", gr_image_last, FALSE, FALSE, N_("last image") },
338 { "-f", "--fullscreen", gr_fullscreen_toggle, FALSE, TRUE, N_("toggle full screen") },
339 { "-fs","--fullscreen-start", gr_fullscreen_start, FALSE, FALSE, N_("start full screen") },
340 { "-fS","--fullscreen-stop", gr_fullscreen_stop, FALSE, FALSE, N_("stop full screen") },
341 { "-s", "--slideshow", gr_slideshow_toggle, FALSE, TRUE, N_("toggle slide show") },
342 { "-ss","--slideshow-start", gr_slideshow_start, FALSE, FALSE, N_("start slide show") },
343 { "-sS","--slideshow-stop", gr_slideshow_stop, FALSE, FALSE, N_("stop slide show") },
344 { "-sr","--slideshow-recurse", gr_slideshow_start_rec, TRUE, FALSE, N_("start recursive slide show") },
345 { "-d", "--delay=", gr_slideshow_delay, TRUE, FALSE, N_("set slide show delay in seconds") },
346 { "+t", "--tools-show", gr_tools_show, FALSE, TRUE, N_("show tools") },
347 { "-t", "--tools-hide", gr_tools_hide, FALSE, TRUE, N_("hide tools") },
348 { "-q", "--quit", gr_quit, FALSE, FALSE, N_("quit") },
349 { NULL, "file:", gr_file_load, TRUE, FALSE, N_("open file") },
350 { NULL, "view:", gr_file_view, TRUE, FALSE, N_("open file in new window") },
351 { NULL, "--list-clear", gr_list_clear, FALSE, FALSE, NULL },
352 { NULL, "--list-add:", gr_list_add, TRUE, FALSE, NULL },
353 { NULL, "raise", gr_raise, FALSE, FALSE, NULL },
354 { NULL, NULL, NULL, FALSE, FALSE, NULL }
357 static RemoteCommandEntry *remote_command_find(const gchar *text, const gchar **offset)
363 while (!match && remote_commands[i].func != NULL)
365 if (remote_commands[i].needs_extra)
367 if (remote_commands[i].opt_s &&
368 strncmp(remote_commands[i].opt_s, text, strlen(remote_commands[i].opt_s)) == 0)
370 if (offset) *offset = text + strlen(remote_commands[i].opt_s);
371 return &remote_commands[i];
373 else if (remote_commands[i].opt_l &&
374 strncmp(remote_commands[i].opt_l, text, strlen(remote_commands[i].opt_l)) == 0)
376 if (offset) *offset = text + strlen(remote_commands[i].opt_l);
377 return &remote_commands[i];
382 if ((remote_commands[i].opt_s && strcmp(remote_commands[i].opt_s, text) == 0) ||
383 (remote_commands[i].opt_l && strcmp(remote_commands[i].opt_l, text) == 0))
385 if (offset) *offset = text;
386 return &remote_commands[i];
396 static void remote_cb(RemoteConnection *rc, const gchar *text, gpointer data)
398 RemoteCommandEntry *entry;
401 entry = remote_command_find(text, &offset);
402 if (entry && entry->func)
404 entry->func(offset, data);
408 printf("unknown remote command:%s\n", text);
412 static void remote_help(void)
416 print_term(_("Remote command list:\n"));
419 while (remote_commands[i].func != NULL)
421 if (remote_commands[i].description)
423 printf_term(" %-3s%s %-20s %s\n",
424 (remote_commands[i].opt_s) ? remote_commands[i].opt_s : "",
425 (remote_commands[i].opt_s && remote_commands[i].opt_l) ? "," : " ",
426 (remote_commands[i].opt_l) ? remote_commands[i].opt_l : "",
427 _(remote_commands[i].description));
433 static GList *remote_build_list(GList *list, int argc, char *argv[])
440 RemoteCommandEntry *entry;
442 entry = remote_command_find(argv[i], NULL);
445 list = g_list_append(list, argv[i]);
453 static void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path,
454 GList *cmd_list, GList *collection_list)
456 RemoteConnection *rc;
457 gint started = FALSE;
460 buf = g_strconcat(homedir(), "/", GQ_RC_DIR, "/.command", NULL);
461 rc = remote_client_open(buf);
466 gint retry_count = 12;
469 printf_term(_("Remote %s not running, starting..."), GQ_APPNAME);
471 command = g_string_new(arg_exec);
477 RemoteCommandEntry *entry;
482 entry = remote_command_find(text, NULL);
485 if (entry->prefer_command_line)
487 remote_list = g_list_remove(remote_list, text);
488 g_string_append(command, " ");
489 g_string_append(command, text);
491 if (entry->opt_l && strcmp(entry->opt_l, "file:") == 0)
498 if (blank || cmd_list || path) g_string_append(command, " --blank");
499 if (get_debug_level()) g_string_append(command, " --debug");
501 g_string_append(command, " &");
502 system(command->str);
503 g_string_free(command, TRUE);
505 while (!rc && retry_count > 0)
507 usleep((retry_count > 10) ? 500000 : 1000000);
508 rc = remote_client_open(buf);
509 if (!rc) print_term(".");
523 gint use_path = TRUE;
530 RemoteCommandEntry *entry;
535 entry = remote_command_find(text, NULL);
538 strcmp(entry->opt_l, "file:") == 0) use_path = FALSE;
540 remote_client_send(rc, text);
545 if (cmd_list && cmd_list->next)
547 prefix = "--list-add:";
548 remote_client_send(rc, "--list-clear");
564 text = g_strconcat(prefix, fd->path, NULL);
565 remote_client_send(rc, text);
571 if (path && !cmd_list && use_path)
575 text = g_strdup_printf("file:%s", path);
576 remote_client_send(rc, text);
582 work = collection_list;
591 text = g_strdup_printf("file:%s", name);
592 remote_client_send(rc, text);
598 if (!started && !sent)
600 remote_client_send(rc, "raise");
605 print_term(_("Remote not available\n"));
612 *-----------------------------------------------------------------------------
613 * command line parser (private) hehe, who needs popt anyway?
614 *-----------------------------------------------------------------------------
617 static gint startup_blank = FALSE;
618 static gint startup_full_screen = FALSE;
619 static gint startup_in_slideshow = FALSE;
620 static gint startup_command_line_collection = FALSE;
623 static void parse_command_line_add_file(const gchar *file_path, gchar **path, gchar **file,
624 GList **list, GList **collection_list)
628 path_parsed = g_strdup(file_path);
629 parse_out_relatives(path_parsed);
631 if (file_extension_match(path_parsed, ".gqv"))
633 *collection_list = g_list_append(*collection_list, path_parsed);
637 if (!*path) *path = remove_level_from_path(path_parsed);
638 if (!*file) *file = g_strdup(path_parsed);
639 *list = g_list_prepend(*list, file_data_new_simple(path_parsed));
643 static void parse_command_line_add_dir(const gchar *dir, gchar **path, gchar **file,
649 path_parsed = g_strdup(dir);
650 parse_out_relatives(path_parsed);
652 if (filelist_read(path_parsed, &files, NULL))
656 files = filelist_filter(files, FALSE);
657 files = filelist_sort_path(files);
662 FileData *fd = work->data;
663 if (!*path) *path = remove_level_from_path(fd->path);
664 if (!*file) *file = g_strdup(fd->path);
665 *list = g_list_prepend(*list, fd);
676 static void parse_command_line_process_dir(const gchar *dir, gchar **path, gchar **file,
677 GList **list, gchar **first_dir)
680 if (!*list && !*first_dir)
682 *first_dir = g_strdup(dir);
688 parse_command_line_add_dir(*first_dir, path, file, list);
692 parse_command_line_add_dir(dir, path, file, list);
696 static void parse_command_line_process_file(const gchar *file_path, gchar **path, gchar **file,
697 GList **list, GList **collection_list, gchar **first_dir)
702 parse_command_line_add_dir(*first_dir, path, file, list);
706 parse_command_line_add_file(file_path, path, file, list, collection_list);
709 static void parse_command_line(int argc, char *argv[], gchar **path, gchar **file,
710 GList **cmd_list, GList **collection_list,
714 GList *remote_list = NULL;
715 gint remote_do = FALSE;
716 gchar *first_dir = NULL;
721 gchar *base_dir = get_current_dir();
725 const gchar *cmd_line = argv[i];
726 gchar *cmd_all = concat_dir_and_file(base_dir, cmd_line);
728 if (cmd_line[0] == '/' && isdir(cmd_line))
730 parse_command_line_process_dir(cmd_line, path, file, &list, &first_dir);
732 else if (isdir(cmd_all))
734 parse_command_line_process_dir(cmd_all, path, file, &list, &first_dir);
736 else if (cmd_line[0] == '/' && isfile(cmd_line))
738 parse_command_line_process_file(cmd_line, path, file,
739 &list, collection_list, &first_dir);
741 else if (isfile(cmd_all))
743 parse_command_line_process_file(cmd_all, path, file,
744 &list, collection_list, &first_dir);
746 else if (strncmp(cmd_line, "--debug", 7) == 0 && (cmd_line[7] == '\0' || cmd_line[7] == '='))
748 /* do nothing but do not produce warnings */
750 else if (strcmp(cmd_line, "+t") == 0 ||
751 strcmp(cmd_line, "--with-tools") == 0)
753 options->layout.tools_float = FALSE;
754 options->layout.tools_hidden = FALSE;
756 remote_list = g_list_append(remote_list, "+t");
758 else if (strcmp(cmd_line, "-t") == 0 ||
759 strcmp(cmd_line, "--without-tools") == 0)
761 options->layout.tools_hidden = TRUE;
763 remote_list = g_list_append(remote_list, "-t");
765 else if (strcmp(cmd_line, "-f") == 0 ||
766 strcmp(cmd_line, "--fullscreen") == 0)
768 startup_full_screen = TRUE;
770 else if (strcmp(cmd_line, "-s") == 0 ||
771 strcmp(cmd_line, "--slideshow") == 0)
773 startup_in_slideshow = TRUE;
775 else if (strcmp(cmd_line, "-l") == 0 ||
776 strcmp(cmd_line, "--list") == 0)
778 startup_command_line_collection = TRUE;
780 else if (strncmp(cmd_line, "--geometry=", 11) == 0)
782 if (!*geometry) *geometry = g_strdup(cmd_line + 11);
784 else if (strcmp(cmd_line, "-r") == 0 ||
785 strcmp(cmd_line, "--remote") == 0)
790 remote_list = remote_build_list(remote_list, argc, argv);
793 else if (strcmp(cmd_line, "-rh") == 0 ||
794 strcmp(cmd_line, "--remote-help") == 0)
799 else if (strcmp(cmd_line, "--blank") == 0)
801 startup_blank = TRUE;
803 else if (strcmp(cmd_line, "-v") == 0 ||
804 strcmp(cmd_line, "--version") == 0)
806 printf("%s %s\n", GQ_APPNAME, VERSION);
809 else if (strcmp(cmd_line, "--alternate") == 0)
811 /* enable faster experimental algorithm */
812 printf("Alternate similarity algorithm enabled\n");
813 image_sim_alternate_set(TRUE);
815 else if (strcmp(cmd_line, "-h") == 0 ||
816 strcmp(cmd_line, "--help") == 0)
818 printf("%s %s\n", GQ_APPNAME, VERSION);
819 printf_term(_("Usage: %s [options] [path]\n\n"), GQ_APPNAME_LC);
820 print_term(_("valid options are:\n"));
821 print_term(_(" +t, --with-tools force show of tools\n"));
822 print_term(_(" -t, --without-tools force hide of tools\n"));
823 print_term(_(" -f, --fullscreen start in full screen mode\n"));
824 print_term(_(" -s, --slideshow start in slideshow mode\n"));
825 print_term(_(" -l, --list open collection window for command line\n"));
826 print_term(_(" --geometry=GEOMETRY set main window location\n"));
827 print_term(_(" -r, --remote send following commands to open window\n"));
828 print_term(_(" -rh,--remote-help print remote command list\n"));
830 print_term(_(" --debug[=level] turn on debug output\n"));
832 print_term(_(" -v, --version print version info\n"));
833 print_term(_(" -h, --help show this message\n\n"));
836 /* these options are not officially supported!
837 * only for testing new features, no need to translate them */
838 print_term( " --alternate use alternate similarity algorithm\n");
845 printf_term(_("invalid or ignored: %s\nUse --help for options\n"), cmd_line);
852 parse_out_relatives(*path);
853 parse_out_relatives(*file);
856 list = g_list_reverse(list);
858 if (!*path && first_dir)
863 parse_out_relatives(*path);
869 remote_control(argv[0], remote_list, *path, list, *collection_list);
871 g_list_free(remote_list);
873 if (list && list->next)
884 static void parse_command_line_for_debug_option(int argc, char *argv[])
887 const gchar *debug_option = "--debug";
888 gint len = strlen(debug_option);
894 for (i = 1; i < argc; i++)
896 const gchar *cmd_line = argv[i];
897 if (strncmp(cmd_line, debug_option, len) == 0)
899 gint cmd_line_len = strlen(cmd_line);
901 /* we now increment the debug state for verbosity */
902 if (cmd_line_len == len)
904 else if (cmd_line[len] == '=' && g_ascii_isdigit(cmd_line[len+1]))
906 gint n = atoi(cmd_line + len + 1);
914 DEBUG_1("debugging output enabled (level %d)", get_debug_level());
919 *-----------------------------------------------------------------------------
920 * startup, init, and exit
921 *-----------------------------------------------------------------------------
924 #define RC_HISTORY_NAME "history"
926 static void keys_load(void)
930 path = g_strconcat(homedir(), "/", GQ_RC_DIR, "/", RC_HISTORY_NAME, NULL);
931 history_list_load(path);
935 static void keys_save(void)
939 path = g_strconcat(homedir(), "/", GQ_RC_DIR, "/", RC_HISTORY_NAME, NULL);
940 history_list_save(path);
944 static void check_for_home_path(gchar *path)
948 buf = g_strconcat(homedir(), "/", path, NULL);
951 printf_term(_("Creating %s dir:%s\n"), GQ_APPNAME, buf);
953 if (!mkdir_utf8(buf, 0755))
955 printf_term(_("Could not create dir:%s\n"), buf);
961 static void setup_default_options(void)
966 for (i = 0; i < GQ_EDITOR_SLOTS; i++)
968 options->editor_name[i] = NULL;
969 options->editor_command[i] = NULL;
972 editor_reset_defaults();
974 bookmark_add_default(_("Home"), homedir());
975 path = concat_dir_and_file(homedir(), "Desktop");
976 bookmark_add_default(_("Desktop"), path);
978 path = concat_dir_and_file(homedir(), GQ_RC_DIR_COLLECTIONS);
979 bookmark_add_default(_("Collections"), path);
982 g_free(options->file_ops.safe_delete_path);
983 options->file_ops.safe_delete_path = concat_dir_and_file(homedir(), GQ_RC_DIR_TRASH);
985 for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
987 options->color_profile.input_file[i] = NULL;
988 options->color_profile.input_name[i] = NULL;
991 set_default_image_overlay_template_string(options);
992 sidecar_ext_add_defaults();
993 options->layout.order = g_strdup("123");
996 static void exit_program_final(void)
1000 LayoutWindow *lw = NULL;
1002 remote_close(remote_connection);
1004 collect_manager_flush();
1006 if (layout_valid(&lw))
1008 options->layout.main_window.maximized = window_maximized(lw->window);
1009 if (!options->layout.main_window.maximized)
1011 layout_geometry_get(NULL, &options->layout.main_window.x, &options->layout.main_window.y,
1012 &options->layout.main_window.w, &options->layout.main_window.h);
1015 options->image_overlay.common.state = image_osd_get(lw->image);
1018 layout_geometry_get_dividers(NULL, &options->layout.main_window.hdivider_pos, &options->layout.main_window.vdivider_pos);
1020 layout_views_get(NULL, &options->layout.dir_view_type, &options->layout.file_view_type);
1022 options->layout.show_thumbnails = layout_thumb_get(NULL);
1023 options->layout.show_marks = layout_marks_get(NULL);
1025 layout_sort_get(NULL, &options->file_sort.method, &options->file_sort.ascending);
1027 layout_geometry_get_tools(NULL, &options->layout.float_window.x, &options->layout.float_window.y,
1028 &options->layout.float_window.w, &options->layout.float_window.h, &options->layout.float_window.vdivider_pos);
1029 layout_tools_float_get(NULL, &options->layout.tools_float, &options->layout.tools_hidden);
1030 options->layout.toolbar_hidden = layout_toolbar_hidden(NULL);
1032 options->color_profile.enabled = layout_image_color_profile_get_use(NULL);
1033 layout_image_color_profile_get(NULL,
1034 &options->color_profile.input_type,
1035 &options->color_profile.screen_type,
1036 &options->color_profile.use_image);
1038 if (options->startup.restore_path && options->startup.use_last_path)
1040 g_free(options->startup.path);
1041 options->startup.path = g_strdup(layout_get_path(NULL));
1047 path = g_strconcat(homedir(), "/", GQ_RC_DIR, "/accels", NULL);
1048 pathl = path_from_utf8(path);
1049 gtk_accel_map_save(pathl);
1056 static GenericDialog *exit_dialog = NULL;
1058 static void exit_confirm_cancel_cb(GenericDialog *gd, gpointer data)
1061 generic_dialog_close(gd);
1064 static void exit_confirm_exit_cb(GenericDialog *gd, gpointer data)
1067 generic_dialog_close(gd);
1068 exit_program_final();
1071 static gint exit_confirm_dlg(void)
1079 gtk_window_present(GTK_WINDOW(exit_dialog->dialog));
1083 if (!collection_window_modified_exists()) return FALSE;
1087 if (layout_valid(&lw))
1089 parent = lw->window;
1092 msg = g_strdup_printf("%s - %s", GQ_APPNAME, _("exit"));
1093 exit_dialog = generic_dialog_new(msg,
1094 GQ_WMCLASS, "exit", parent, FALSE,
1095 exit_confirm_cancel_cb, NULL);
1097 msg = g_strdup_printf(_("Quit %s"), GQ_APPNAME);
1098 generic_dialog_add_message(exit_dialog, GTK_STOCK_DIALOG_QUESTION,
1099 msg, _("Collections have been modified. Quit anyway?"));
1101 generic_dialog_add_button(exit_dialog, GTK_STOCK_QUIT, NULL, exit_confirm_exit_cb, TRUE);
1103 gtk_widget_show(exit_dialog->dialog);
1108 void exit_program(void)
1110 layout_image_full_screen_stop(NULL);
1112 if (exit_confirm_dlg()) return;
1114 exit_program_final();
1117 int main(int argc, char *argv[])
1121 gchar *cmd_path = NULL;
1122 gchar *cmd_file = NULL;
1123 GList *cmd_list = NULL;
1124 GList *collection_list = NULL;
1125 CollectionData *first_collection = NULL;
1126 gchar *geometry = NULL;
1130 /* init execution time counter (debug only) */
1133 /* setup locale, i18n */
1135 bindtextdomain(PACKAGE, GQ_LOCALEDIR);
1136 bind_textdomain_codeset(PACKAGE, "UTF-8");
1137 textdomain(PACKAGE);
1139 /* setup random seed for random slideshow */
1143 printf("%s %s, This is an alpha release.\n", GQ_APPNAME, VERSION);
1145 parse_command_line_for_debug_option(argc, argv);
1147 options = init_options(NULL);
1148 setup_default_options();
1151 parse_command_line(argc, argv, &cmd_path, &cmd_file, &cmd_list, &collection_list, &geometry);
1153 gtk_init(&argc, &argv);
1155 if (gtk_major_version < GTK_MAJOR_VERSION ||
1156 (gtk_major_version == GTK_MAJOR_VERSION && gtk_minor_version < GTK_MINOR_VERSION) )
1158 printf_term("!!! This is a friendly warning.\n");
1159 printf_term("!!! The version of GTK+ in use now is older than when %s was compiled.\n", GQ_APPNAME);
1160 printf_term("!!! compiled with GTK+-%d.%d\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION);
1161 printf_term("!!! running with GTK+-%d.%d\n", gtk_major_version, gtk_minor_version);
1162 printf_term("!!! %s may quit unexpectedly with a relocation error.\n", GQ_APPNAME);
1165 check_for_home_path(GQ_RC_DIR);
1166 check_for_home_path(GQ_RC_DIR_COLLECTIONS);
1167 check_for_home_path(GQ_CACHE_RC_THUMB);
1168 check_for_home_path(GQ_CACHE_RC_METADATA);
1171 filter_add_defaults();
1174 buf = g_strconcat(homedir(), "/", GQ_RC_DIR, "/accels", NULL);
1175 bufl = path_from_utf8(buf);
1176 gtk_accel_map_load(bufl);
1186 filelist_free(cmd_list);
1188 string_list_free(collection_list);
1189 collection_list = NULL;
1195 path = g_strdup(cmd_path);
1197 else if (options->startup.restore_path && options->startup.path && isdir(options->startup.path))
1199 path = g_strdup(options->startup.path);
1203 path = get_current_dir();
1206 lw = layout_new_with_geometry(NULL, options->layout.tools_float, options->layout.tools_hidden, geometry);
1207 layout_sort_set(lw, options->file_sort.method, options->file_sort.ascending);
1209 if (collection_list && !startup_command_line_collection)
1213 work = collection_list;
1222 cw = collection_window_new(path);
1223 if (!first_collection && cw) first_collection = cw->cd;
1228 (startup_command_line_collection && collection_list))
1233 if (startup_command_line_collection)
1237 cw = collection_window_new("");
1242 cd = collection_new(""); /* if we pass NULL, untitled counter is falsely increm. */
1243 command_collection = cd;
1249 cd->name = g_strdup(_("Command line"));
1251 collection_path_changed(cd);
1256 collection_add(cd, file_data_new_simple((gchar *)work->data), FALSE);
1260 work = collection_list;
1263 collection_load(cd, (gchar *)work->data, COLLECTION_LOAD_APPEND);
1267 layout_set_path(lw, path);
1268 if (cd->list) layout_image_set_collection(lw, cd, cd->list->data);
1270 /* mem leak, we never unref this collection when !startup_command_line_collection
1271 * (the image view of the main window does not hold a ref to the collection)
1272 * this is sort of unavoidable, for if it did hold a ref, next/back
1273 * may not work as expected when closing collection windows.
1275 * collection_unref(cd);
1281 layout_set_path(lw, cmd_file);
1285 layout_set_path(lw, path);
1286 if (first_collection)
1288 layout_image_set_collection(lw, first_collection,
1289 collection_get_first(first_collection));
1293 image_osd_set(lw->image, options->image_overlay.common.state | (options->image_overlay.common.show_at_startup ? OSD_SHOW_INFO : OSD_SHOW_NOTHING));
1298 filelist_free(cmd_list);
1299 string_list_free(collection_list);
1302 if (startup_full_screen) layout_image_full_screen_start(lw);
1303 if (startup_in_slideshow) layout_image_slideshow_start(lw);
1305 buf = g_strconcat(homedir(), "/", GQ_RC_DIR, "/.command", NULL);
1306 remote_connection = remote_server_open(buf);
1307 remote_server_subscribe(remote_connection, remote_cb, NULL);