2 * Copyright (C) 2006 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <gdk/gdkkeysyms.h> /* for keyboard values */
37 #include "collect-io.h"
39 #include "filefilter.h"
40 #include "history_list.h"
41 #include "image-overlay.h"
43 #include "layout_image.h"
44 #include "layout_util.h"
47 #include "secure_save.h"
49 #include "ui_fileops.h"
50 #include "ui_utildlg.h"
51 #include "cache_maint.h"
56 #include "histogram.h"
57 #include "pixbuf_util.h"
61 #include <clutter-gtk/clutter-gtk.h>
65 /* FIXME: see below */
69 gboolean thumb_format_changed = FALSE;
70 static RemoteConnection *remote_connection = NULL;
73 *-----------------------------------------------------------------------------
75 *-----------------------------------------------------------------------------
78 void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event)
80 static gint delta = 0;
81 static guint32 time_old = 0;
82 static guint keyval_old = 0;
84 if (event->state & GDK_CONTROL_MASK)
86 if (*x < 0) *x = G_MININT / 2;
87 if (*x > 0) *x = G_MAXINT / 2;
88 if (*y < 0) *y = G_MININT / 2;
89 if (*y > 0) *y = G_MAXINT / 2;
94 if (options->progressive_key_scrolling)
98 time_diff = event->time - time_old;
100 /* key pressed within 125ms ? (1/8 second) */
101 if (time_diff > 125 || event->keyval != keyval_old) delta = 0;
103 time_old = event->time;
104 keyval_old = event->keyval;
113 *x = *x * delta * options->keyboard_scroll_step;
114 *y = *y * delta * options->keyboard_scroll_step;
120 *-----------------------------------------------------------------------------
121 * command line parser (private) hehe, who needs popt anyway?
122 *-----------------------------------------------------------------------------
125 static void parse_command_line_add_file(const gchar *file_path, gchar **path, gchar **file,
126 GList **list, GList **collection_list)
130 path_parsed = g_strdup(file_path);
131 parse_out_relatives(path_parsed);
133 if (file_extension_match(path_parsed, GQ_COLLECTION_EXT))
135 *collection_list = g_list_append(*collection_list, path_parsed);
139 if (!*path) *path = remove_level_from_path(path_parsed);
140 if (!*file) *file = g_strdup(path_parsed);
141 *list = g_list_prepend(*list, path_parsed);
145 static void parse_command_line_add_dir(const gchar *dir, gchar **path, gchar **file,
149 /* This is broken because file filter is not initialized yet.
155 path_parsed = g_strdup(dir);
156 parse_out_relatives(path_parsed);
157 dir_fd = file_data_new_dir(path_parsed);
160 if (filelist_read(dir_fd, &files, NULL))
164 files = filelist_filter(files, FALSE);
165 files = filelist_sort_path(files);
170 FileData *fd = work->data;
171 if (!*path) *path = remove_level_from_path(fd->path);
172 if (!*file) *file = g_strdup(fd->path);
173 *list = g_list_prepend(*list, fd);
182 file_data_unref(dir_fd);
184 DEBUG_1("multiple directories specified, ignoring: %s", dir);
188 static void parse_command_line_process_dir(const gchar *dir, gchar **path, gchar **file,
189 GList **list, gchar **first_dir)
192 if (!*list && !*first_dir)
194 *first_dir = g_strdup(dir);
200 parse_command_line_add_dir(*first_dir, path, file, list);
204 parse_command_line_add_dir(dir, path, file, list);
208 static void parse_command_line_process_file(const gchar *file_path, gchar **path, gchar **file,
209 GList **list, GList **collection_list, gchar **first_dir)
214 parse_command_line_add_dir(*first_dir, path, file, list);
218 parse_command_line_add_file(file_path, path, file, list, collection_list);
221 static void parse_command_line(gint argc, gchar *argv[])
224 GList *remote_list = NULL;
225 GList *remote_errors = NULL;
226 gboolean remote_do = FALSE;
227 gchar *first_dir = NULL;
231 gchar *geometry = NULL;
233 command_line = g_new0(CommandLine, 1);
235 command_line->argc = argc;
236 command_line->argv = argv;
237 command_line->regexp = NULL;
242 gchar *base_dir = get_current_dir();
246 gchar *cmd_line = path_to_utf8(argv[i]);
247 gchar *cmd_all = g_build_filename(base_dir, cmd_line, NULL);
249 if (cmd_line[0] == G_DIR_SEPARATOR && isdir(cmd_line))
251 parse_command_line_process_dir(cmd_line, &command_line->path, &command_line->file, &list, &first_dir);
253 else if (isdir(cmd_all))
255 parse_command_line_process_dir(cmd_all, &command_line->path, &command_line->file, &list, &first_dir);
257 else if (cmd_line[0] == G_DIR_SEPARATOR && isfile(cmd_line))
259 parse_command_line_process_file(cmd_line, &command_line->path, &command_line->file,
260 &list, &command_line->collection_list, &first_dir);
262 else if (isfile(cmd_all))
264 parse_command_line_process_file(cmd_all, &command_line->path, &command_line->file,
265 &list, &command_line->collection_list, &first_dir);
267 else if (download_web_file(cmd_line, FALSE, NULL))
270 else if (is_collection(cmd_line))
274 path = collection_path(cmd_line);
275 parse_command_line_process_file(path, &command_line->path, &command_line->file,
276 &list, &command_line->collection_list, &first_dir);
279 else if (strncmp(cmd_line, "--debug", 7) == 0 && (cmd_line[7] == '\0' || cmd_line[7] == '='))
281 /* do nothing but do not produce warnings */
283 else if (strncmp(cmd_line, "--disable-clutter", 17) == 0 && (cmd_line[17] == '\0'))
285 /* do nothing but do not produce warnings */
287 else if (strcmp(cmd_line, "+t") == 0 ||
288 strcmp(cmd_line, "--with-tools") == 0)
290 command_line->tools_show = TRUE;
292 remote_list = g_list_append(remote_list, "+t");
294 else if (strcmp(cmd_line, "-t") == 0 ||
295 strcmp(cmd_line, "--without-tools") == 0)
297 command_line->tools_hide = TRUE;
299 remote_list = g_list_append(remote_list, "-t");
301 else if (strcmp(cmd_line, "-f") == 0 ||
302 strcmp(cmd_line, "--fullscreen") == 0)
304 command_line->startup_full_screen = TRUE;
306 else if (strcmp(cmd_line, "-s") == 0 ||
307 strcmp(cmd_line, "--slideshow") == 0)
309 command_line->startup_in_slideshow = TRUE;
311 else if (strcmp(cmd_line, "-l") == 0 ||
312 strcmp(cmd_line, "--list") == 0)
314 command_line->startup_command_line_collection = TRUE;
316 else if (strncmp(cmd_line, "--geometry=", 11) == 0)
318 if (!command_line->geometry) command_line->geometry = g_strdup(cmd_line + 11);
320 else if (strcmp(cmd_line, "-r") == 0 ||
321 strcmp(cmd_line, "--remote") == 0)
326 remote_list = remote_build_list(remote_list, argc - i, &argv[i], &remote_errors);
329 else if ((strcmp(cmd_line, "+w") == 0) ||
330 strcmp(cmd_line, "--show-log-window") == 0)
332 command_line->log_window_show = TRUE;
334 else if (strncmp(cmd_line, "-o:", 3) == 0)
336 command_line->log_file = g_strdup(cmd_line + 3);
338 else if (strncmp(cmd_line, "--log-file:", 11) == 0)
340 command_line->log_file = g_strdup(cmd_line + 11);
342 else if (strncmp(cmd_line, "-g:", 3) == 0)
344 set_regexp(g_strdup(cmd_line+3));
346 else if (strncmp(cmd_line, "-grep:", 6) == 0)
348 set_regexp(g_strdup(cmd_line+3));
350 else if (strncmp(cmd_line, "-n", 2) == 0)
352 command_line->new_instance = TRUE;
354 else if (strncmp(cmd_line, "--new-instance", 14) == 0)
356 command_line->new_instance = TRUE;
358 else if (strcmp(cmd_line, "-rh") == 0 ||
359 strcmp(cmd_line, "--remote-help") == 0)
364 else if (strcmp(cmd_line, "--blank") == 0)
366 command_line->startup_blank = TRUE;
368 else if (strcmp(cmd_line, "-v") == 0 ||
369 strcmp(cmd_line, "--version") == 0)
371 printf_term(FALSE, "%s %s GTK%d\n", GQ_APPNAME, VERSION, gtk_major_version);
374 else if (strcmp(cmd_line, "--alternate") == 0)
376 /* enable faster experimental algorithm */
377 log_printf("Alternate similarity algorithm enabled\n");
378 image_sim_alternate_set(TRUE);
380 else if (strcmp(cmd_line, "-h") == 0 ||
381 strcmp(cmd_line, "--help") == 0)
383 printf_term(FALSE, "%s %s\n", GQ_APPNAME, VERSION);
384 printf_term(FALSE, _("Usage: %s [options] [path]\n\n"), GQ_APPNAME_LC);
385 print_term(FALSE, _("valid options are:\n"));
386 print_term(FALSE, _(" +t, --with-tools force show of tools\n"));
387 print_term(FALSE, _(" -t, --without-tools force hide of tools\n"));
388 print_term(FALSE, _(" -f, --fullscreen start in full screen mode\n"));
389 print_term(FALSE, _(" -s, --slideshow start in slideshow mode\n"));
390 print_term(FALSE, _(" -l, --list [files] [collections] open collection window for command line\n"));
391 print_term(FALSE, _(" --blank start with blank file list\n"));
392 print_term(FALSE, _(" --geometry=XxY+XOFF+YOFF set main window location\n"));
393 print_term(FALSE, _(" -n, --new-instance open a new instance of Geeqie\n"));
394 print_term(FALSE, _(" -r, --remote send following commands to open window\n"));
395 print_term(FALSE, _(" -rh,--remote-help print remote command list\n"));
397 print_term(FALSE, _(" --debug[=level] turn on debug output\n"));
398 print_term(FALSE, _(" -g:<regexp>, --grep:<regexp> filter debug output\n"));
400 print_term(FALSE, _(" +w, --show-log-window show log window\n"));
401 print_term(FALSE, _(" -o:<file>, --log-file:<file> save log data to file\n"));
402 print_term(FALSE, _(" -v, --version print version info\n"));
403 print_term(FALSE, _(" -h, --help show this message\n"));
404 print_term(FALSE, _(" --disable-clutter disable use of Clutter library (i.e. GPU accel.)\n\n"));
407 /* these options are not officially supported!
408 * only for testing new features, no need to translate them */
409 print_term(FALSE, " --alternate use alternate similarity algorithm\n");
417 printf_term(TRUE, _("invalid or ignored: %s\nUse --help for options\n"), cmd_line);
425 parse_out_relatives(command_line->path);
426 parse_out_relatives(command_line->file);
429 list = g_list_reverse(list);
431 if (!command_line->path && first_dir)
433 command_line->path = first_dir;
436 parse_out_relatives(command_line->path);
440 if (!command_line->new_instance)
442 /* If Geeqie is already running, prevent a second instance
443 * from being started. Open a new window instead.
445 app_lock = g_build_filename(get_rc_dir(), ".command", NULL);
446 if (remote_server_exists(app_lock) && !remote_do)
449 if (command_line->geometry)
451 geometry = g_strdup_printf("--geometry=%s", command_line->geometry);
452 remote_list = g_list_prepend(remote_list, geometry);
454 remote_list = g_list_prepend(remote_list, "--new-window");
456 else if (!remote_server_exists(app_lock))
458 /* Geeqie started for first time but with --remote option
469 GList *work = remote_errors;
471 printf_term(TRUE,_("Invalid or ignored remote options: "));
474 gchar *opt = work->data;
476 printf_term(TRUE, "%s%s", (work == remote_errors) ? "" : ", ", opt);
480 printf_term(TRUE, _("\nUse --remote-help for valid remote options.\n"));
483 /* prepend the current dir the remote command was made from,
484 * for use by any remote command that needs it
486 current_dir = g_get_current_dir();
487 pwd = g_strconcat("--PWD:", current_dir, NULL);
488 remote_list = g_list_prepend(remote_list, pwd);
490 remote_control(argv[0], remote_list, command_line->path, list, command_line->collection_list);
491 /* There is no return to this point
497 g_list_free(remote_list);
499 if (list && list->next)
501 command_line->cmd_list = list;
505 string_list_free(list);
506 command_line->cmd_list = NULL;
509 if (command_line->startup_blank)
511 g_free(command_line->path);
512 command_line->path = NULL;
513 g_free(command_line->file);
514 command_line->file = NULL;
515 filelist_free(command_line->cmd_list);
516 command_line->cmd_list = NULL;
517 string_list_free(command_line->collection_list);
518 command_line->collection_list = NULL;
522 static void parse_command_line_for_debug_option(gint argc, gchar *argv[])
525 const gchar *debug_option = "--debug";
526 gint len = strlen(debug_option);
532 for (i = 1; i < argc; i++)
534 const gchar *cmd_line = argv[i];
535 if (strncmp(cmd_line, debug_option, len) == 0)
537 gint cmd_line_len = strlen(cmd_line);
539 /* we now increment the debug state for verbosity */
540 if (cmd_line_len == len)
542 else if (cmd_line[len] == '=' && g_ascii_isdigit(cmd_line[len+1]))
544 gint n = atoi(cmd_line + len + 1);
552 DEBUG_1("debugging output enabled (level %d)", get_debug_level());
557 static gboolean parse_command_line_for_clutter_option(gint argc, gchar *argv[])
559 const gchar *clutter_option = "--disable-clutter";
560 gint len = strlen(clutter_option);
561 gboolean ret = FALSE;
567 for (i = 1; i < argc; i++)
569 const gchar *cmd_line = argv[i];
570 if (strncmp(cmd_line, clutter_option, len) == 0)
582 *-----------------------------------------------------------------------------
583 * startup, init, and exit
584 *-----------------------------------------------------------------------------
587 #define RC_HISTORY_NAME "history"
588 #define RC_MARKS_NAME "marks"
590 static void setup_env_path(void)
592 const gchar *old_path = g_getenv("PATH");
593 gchar *path = g_strconcat(GQ_BIN_DIR, ":", old_path, NULL);
594 g_setenv("PATH", path, TRUE);
598 static void keys_load(void)
602 path = g_build_filename(get_rc_dir(), RC_HISTORY_NAME, NULL);
603 history_list_load(path);
607 static void keys_save(void)
611 path = g_build_filename(get_rc_dir(), RC_HISTORY_NAME, NULL);
612 history_list_save(path);
616 static void marks_load(void)
620 path = g_build_filename(get_rc_dir(), RC_MARKS_NAME, NULL);
621 marks_list_load(path);
625 static void marks_save(gboolean save)
629 path = g_build_filename(get_rc_dir(), RC_MARKS_NAME, NULL);
630 marks_list_save(path, save);
634 static void mkdir_if_not_exists(const gchar *path)
636 if (isdir(path)) return;
638 log_printf(_("Creating %s dir:%s\n"), GQ_APPNAME, path);
640 if (!recursive_mkdir_if_not_exists(path, 0755))
642 log_printf(_("Could not create dir:%s\n"), path);
647 /* We add to duplicate and modify gtk_accel_map_print() and gtk_accel_map_save()
648 * to improve the reliability in special cases (especially when disk is full)
649 * These functions are now using secure saving stuff.
651 static void gq_accel_map_print(
653 const gchar *accel_path,
655 GdkModifierType accel_mods,
658 GString *gstring = g_string_new(changed ? NULL : "; ");
659 SecureSaveInfo *ssi = data;
662 g_string_append(gstring, "(gtk_accel_path \"");
664 tmp = g_strescape(accel_path, NULL);
665 g_string_append(gstring, tmp);
668 g_string_append(gstring, "\" \"");
670 name = gtk_accelerator_name(accel_key, accel_mods);
671 tmp = g_strescape(name, NULL);
673 g_string_append(gstring, tmp);
676 g_string_append(gstring, "\")\n");
678 secure_fwrite(gstring->str, sizeof(*gstring->str), gstring->len, ssi);
680 g_string_free(gstring, TRUE);
683 static gboolean gq_accel_map_save(const gchar *path)
689 pathl = path_from_utf8(path);
690 ssi = secure_open(pathl);
694 log_printf(_("error saving file: %s\n"), path);
698 gstring = g_string_new("; ");
700 g_string_append(gstring, g_get_prgname());
701 g_string_append(gstring, " GtkAccelMap rc-file -*- scheme -*-\n");
702 g_string_append(gstring, "; this file is an automated accelerator map dump\n");
703 g_string_append(gstring, ";\n");
705 secure_fwrite(gstring->str, sizeof(*gstring->str), gstring->len, ssi);
707 g_string_free(gstring, TRUE);
709 gtk_accel_map_foreach((gpointer) ssi, gq_accel_map_print);
711 if (secure_close(ssi))
713 log_printf(_("error saving file: %s\nerror: %s\n"), path,
714 secsave_strerror(secsave_errno));
721 static gchar *accep_map_filename(void)
723 return g_build_filename(get_rc_dir(), "accels", NULL);
726 static void accel_map_save(void)
730 path = accep_map_filename();
731 gq_accel_map_save(path);
735 static void accel_map_load(void)
740 path = accep_map_filename();
741 pathl = path_from_utf8(path);
742 gtk_accel_map_load(pathl);
747 static void gtkrc_load(void)
752 /* If a gtkrc file exists in the rc directory, add it to the
753 * list of files to be parsed at the end of gtk_init() */
754 path = g_build_filename(get_rc_dir(), "gtkrc", NULL);
755 pathl = path_from_utf8(path);
756 if (access(pathl, R_OK) == 0)
757 gtk_rc_add_default_file(pathl);
762 static void exit_program_final(void)
764 LayoutWindow *lw = NULL;
766 LayoutWindow *tmp_lw;
768 /* make sure that external editors are loaded, we would save incomplete configuration otherwise */
769 layout_editors_reload_finish();
771 remote_close(remote_connection);
773 collect_manager_flush();
775 /* Save the named windows */
776 if (layout_window_list && layout_window_list->next)
778 list = layout_window_list;
782 if (!g_str_has_prefix(tmp_lw->options.id, "lw"))
784 save_layout(list->data);
790 save_options(options);
794 if (layout_valid(&lw))
799 secure_close(command_line->ssi);
804 static GenericDialog *exit_dialog = NULL;
806 static void exit_confirm_cancel_cb(GenericDialog *gd, gpointer data)
809 generic_dialog_close(gd);
812 static void exit_confirm_exit_cb(GenericDialog *gd, gpointer data)
815 generic_dialog_close(gd);
816 exit_program_final();
819 static gint exit_confirm_dlg(void)
827 gtk_window_present(GTK_WINDOW(exit_dialog->dialog));
831 if (!collection_window_modified_exists()) return FALSE;
835 if (layout_valid(&lw))
840 msg = g_strdup_printf("%s - %s", GQ_APPNAME, _("exit"));
841 exit_dialog = generic_dialog_new(msg,
842 "exit", parent, FALSE,
843 exit_confirm_cancel_cb, NULL);
845 msg = g_strdup_printf(_("Quit %s"), GQ_APPNAME);
846 generic_dialog_add_message(exit_dialog, GTK_STOCK_DIALOG_QUESTION,
847 msg, _("Collections have been modified. Quit anyway?"), TRUE);
849 generic_dialog_add_button(exit_dialog, GTK_STOCK_QUIT, NULL, exit_confirm_exit_cb, TRUE);
851 gtk_widget_show(exit_dialog->dialog);
856 static void exit_program_write_metadata_cb(gint success, const gchar *dest_path, gpointer data)
858 if (success) exit_program();
861 void exit_program(void)
863 layout_image_full_screen_stop(NULL);
865 if (metadata_write_queue_confirm(FALSE, exit_program_write_metadata_cb, NULL)) return;
867 options->marks_save ? marks_save(TRUE) : marks_save(FALSE);
869 if (exit_confirm_dlg()) return;
871 exit_program_final();
874 /* This code is supposed to handle situation when a file mmaped by image_loader
875 * or by exif loader is truncated by some other process.
876 * This is probably not completely correct according to posix, because
877 * mmap is not in the list of calls that can be used safely in signal handler,
878 * but anyway, the handler is called in situation when the application would
880 * Ideas for improvement are welcome ;)
882 /* FIXME: this probably needs some better ifdefs. Please report any compilation problems */
884 #if defined(SIGBUS) && defined(SA_SIGINFO)
885 static void sigbus_handler_cb(int signum, siginfo_t *info, void *context)
887 unsigned long pagesize = sysconf(_SC_PAGE_SIZE);
888 DEBUG_1("SIGBUS %p", info->si_addr);
889 mmap((void *)(((unsigned long)info->si_addr / pagesize) * pagesize), pagesize, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
893 static void setup_sigbus_handler(void)
895 #if defined(SIGBUS) && defined(SA_SIGINFO)
896 struct sigaction sigbus_action;
897 sigfillset(&sigbus_action.sa_mask);
898 sigbus_action.sa_sigaction = sigbus_handler_cb;
899 sigbus_action.sa_flags = SA_SIGINFO;
901 sigaction(SIGBUS, &sigbus_action, NULL);
905 gint main(gint argc, gchar *argv[])
907 CollectionData *first_collection = NULL;
909 CollectionData *cd = NULL;
910 gboolean disable_clutter = FALSE;
911 gboolean single_dir = TRUE;
915 #if !GLIB_CHECK_VERSION(2,32,0)
923 /* init execution time counter (debug only) */
926 /* setup locale, i18n */
927 setlocale(LC_ALL, "");
930 bindtextdomain(PACKAGE, GQ_LOCALEDIR);
931 bind_textdomain_codeset(PACKAGE, "UTF-8");
941 /* setup random seed for random slideshow */
944 setup_sigbus_handler();
946 /* register global notify functions */
947 file_data_register_notify_func(cache_notify_cb, NULL, NOTIFY_PRIORITY_HIGH);
948 file_data_register_notify_func(thumb_notify_cb, NULL, NOTIFY_PRIORITY_HIGH);
949 file_data_register_notify_func(histogram_notify_cb, NULL, NOTIFY_PRIORITY_HIGH);
950 file_data_register_notify_func(collect_manager_notify_cb, NULL, NOTIFY_PRIORITY_LOW);
951 file_data_register_notify_func(metadata_notify_cb, NULL, NOTIFY_PRIORITY_LOW);
956 parse_command_line_for_debug_option(argc, argv);
957 DEBUG_1("%s main: gtk_init", get_exec_time());
959 if (parse_command_line_for_clutter_option(argc, argv))
961 disable_clutter = TRUE;
962 gtk_init(&argc, &argv);
966 if (gtk_clutter_init(&argc, &argv) != CLUTTER_INIT_SUCCESS)
968 log_printf("Can't initialize clutter-gtk.\nStart Geeqie with the option \"geeqie --disable-clutter\"");
973 gtk_init(&argc, &argv);
976 if (gtk_major_version < GTK_MAJOR_VERSION ||
977 (gtk_major_version == GTK_MAJOR_VERSION && gtk_minor_version < GTK_MINOR_VERSION) )
979 log_printf("!!! This is a friendly warning.\n");
980 log_printf("!!! The version of GTK+ in use now is older than when %s was compiled.\n", GQ_APPNAME);
981 log_printf("!!! compiled with GTK+-%d.%d\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION);
982 log_printf("!!! running with GTK+-%d.%d\n", gtk_major_version, gtk_minor_version);
983 log_printf("!!! %s may quit unexpectedly with a relocation error.\n", GQ_APPNAME);
986 DEBUG_1("%s main: pixbuf_inline_register_stock_icons", get_exec_time());
987 pixbuf_inline_register_stock_icons();
989 DEBUG_1("%s main: setting default options before commandline handling", get_exec_time());
990 options = init_options(NULL);
991 setup_default_options(options);
994 options->disable_gpu = TRUE;
997 DEBUG_1("%s main: parse_command_line", get_exec_time());
998 parse_command_line(argc, argv);
1000 DEBUG_1("%s main: mkdir_if_not_exists", get_exec_time());
1001 /* these functions don't depend on config file */
1002 mkdir_if_not_exists(get_rc_dir());
1003 mkdir_if_not_exists(get_collections_dir());
1004 mkdir_if_not_exists(get_thumbnails_cache_dir());
1005 mkdir_if_not_exists(get_metadata_cache_dir());
1006 mkdir_if_not_exists(get_window_layouts_dir());
1013 /* restore session from the config file */
1016 DEBUG_1("%s main: load_options", get_exec_time());
1017 if (!load_options(options))
1019 /* load_options calls these functions after it parses global options, we have to call it here if it fails */
1020 filter_add_defaults();
1025 /* FIXME: For the background of this see:
1026 * https://github.com/BestImageViewer/geeqie/issues/397
1027 * The feature CLUTTER_FEATURE_SWAP_EVENTS indictates if the
1028 * system is liable to exhibit this problem.
1029 * The user is provided with an override in Preferences/Behavior
1031 if (!options->override_disable_gpu && !options->disable_gpu)
1033 DEBUG_1("CLUTTER_FEATURE_SWAP_EVENTS %d",clutter_feature_available(CLUTTER_FEATURE_SWAP_EVENTS));
1034 if (clutter_feature_available(CLUTTER_FEATURE_SWAP_EVENTS) != 0)
1036 options->disable_gpu = TRUE;
1041 /* handle missing config file and commandline additions*/
1042 if (!layout_window_list)
1044 /* broken or no config file */
1045 layout_new_from_config(NULL, NULL, TRUE);
1048 layout_editors_reload_start();
1050 /* If no --list option, open a separate collection window for each
1051 * .gqv file on the command line
1053 if (command_line->collection_list && !command_line->startup_command_line_collection)
1057 work = command_line->collection_list;
1066 cw = collection_window_new(path);
1067 if (!first_collection && cw) first_collection = cw->cd;
1071 if (command_line->log_file)
1074 gchar *path = g_strdup(command_line->log_file);
1076 pathl = path_from_utf8(path);
1077 command_line->ssi = secure_open(pathl);
1080 /* If there is a files list on the command line and no --list option,
1081 * check if they are all in the same folder
1083 if (command_line->cmd_list && !(command_line->startup_command_line_collection))
1088 work = command_line->cmd_list;
1090 while (work && single_dir)
1094 dirname = g_path_get_dirname(work->data);
1097 path = g_strdup(dirname);
1101 if (g_strcmp0(path, dirname) != 0)
1112 /* Files from multiple folders, or --list option given
1113 * then open an unnamed collection and insert all files
1115 if ((command_line->cmd_list && !single_dir) || (command_line->startup_command_line_collection))
1120 cw = collection_window_new(NULL);
1123 collection_path_changed(cd);
1125 work = command_line->cmd_list;
1130 fd = file_data_new_simple(work->data);
1131 collection_add(cd, fd, FALSE);
1132 file_data_unref(fd);
1136 work = command_line->collection_list;
1139 collection_load(cd, (gchar *)work->data, COLLECTION_LOAD_APPEND);
1143 if (cd->list) layout_image_set_collection(NULL, cd, cd->list->data);
1145 /* mem leak, we never unref this collection when !startup_command_line_collection
1146 * (the image view of the main window does not hold a ref to the collection)
1147 * this is sort of unavoidable, for if it did hold a ref, next/back
1148 * may not work as expected when closing collection windows.
1150 * collection_unref(cd);
1154 else if (first_collection)
1156 layout_image_set_collection(NULL, first_collection,
1157 collection_get_first(first_collection));
1160 /* If the files on the command line are from one folder, select those files
1165 if (single_dir && command_line->cmd_list)
1172 work = command_line->cmd_list;
1175 fd = file_data_new_simple((gchar *)work->data);
1176 selected = g_list_append(selected, fd);
1177 file_data_unref(fd);
1180 layout_select_list(lw, selected);
1183 buf = g_build_filename(get_rc_dir(), ".command", NULL);
1184 remote_connection = remote_server_init(buf, cd);
1189 DEBUG_1("%s main: gtk_main", get_exec_time());
1192 gdk_threads_leave();
1196 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */