Mercurial > geeqie
comparison src/main.c @ 1313:1ffa5222dc61
enabled commandline again
author | nadvornik |
---|---|
date | Mon, 23 Feb 2009 21:21:15 +0000 |
parents | 55ea4962887a |
children | 50b325a2386e |
comparison
equal
deleted
inserted
replaced
1312:fcf0e7a6143e | 1313:1ffa5222dc61 |
---|---|
100 *----------------------------------------------------------------------------- | 100 *----------------------------------------------------------------------------- |
101 * command line parser (private) hehe, who needs popt anyway? | 101 * command line parser (private) hehe, who needs popt anyway? |
102 *----------------------------------------------------------------------------- | 102 *----------------------------------------------------------------------------- |
103 */ | 103 */ |
104 | 104 |
105 static gint startup_blank = FALSE; | |
106 static gint startup_full_screen = FALSE; | |
107 static gint startup_in_slideshow = FALSE; | |
108 static gint startup_command_line_collection = FALSE; | |
109 | |
110 | |
111 static void parse_command_line_add_file(const gchar *file_path, gchar **path, gchar **file, | 105 static void parse_command_line_add_file(const gchar *file_path, gchar **path, gchar **file, |
112 GList **list, GList **collection_list) | 106 GList **list, GList **collection_list) |
113 { | 107 { |
114 gchar *path_parsed; | 108 gchar *path_parsed; |
115 | 109 |
196 *first_dir = NULL; | 190 *first_dir = NULL; |
197 } | 191 } |
198 parse_command_line_add_file(file_path, path, file, list, collection_list); | 192 parse_command_line_add_file(file_path, path, file, list, collection_list); |
199 } | 193 } |
200 | 194 |
201 static void parse_command_line(gint argc, gchar *argv[], gchar **path, gchar **file, | 195 static void parse_command_line(gint argc, gchar *argv[]) |
202 GList **cmd_list, GList **collection_list, | |
203 gchar **geometry) | |
204 { | 196 { |
205 GList *list = NULL; | 197 GList *list = NULL; |
206 GList *remote_list = NULL; | 198 GList *remote_list = NULL; |
207 GList *remote_errors = NULL; | 199 GList *remote_errors = NULL; |
208 gint remote_do = FALSE; | 200 gint remote_do = FALSE; |
209 gchar *first_dir = NULL; | 201 gchar *first_dir = NULL; |
202 | |
203 command_line = g_new0(CommandLine, 1); | |
204 | |
205 command_line->argc = argc; | |
206 command_line->argv = argv; | |
210 | 207 |
211 if (argc > 1) | 208 if (argc > 1) |
212 { | 209 { |
213 gint i; | 210 gint i; |
214 gchar *base_dir = get_current_dir(); | 211 gchar *base_dir = get_current_dir(); |
218 const gchar *cmd_line = argv[i]; | 215 const gchar *cmd_line = argv[i]; |
219 gchar *cmd_all = g_build_filename(base_dir, cmd_line, NULL); | 216 gchar *cmd_all = g_build_filename(base_dir, cmd_line, NULL); |
220 | 217 |
221 if (cmd_line[0] == G_DIR_SEPARATOR && isdir(cmd_line)) | 218 if (cmd_line[0] == G_DIR_SEPARATOR && isdir(cmd_line)) |
222 { | 219 { |
223 parse_command_line_process_dir(cmd_line, path, file, &list, &first_dir); | 220 parse_command_line_process_dir(cmd_line, &command_line->path, &command_line->file, &list, &first_dir); |
224 } | 221 } |
225 else if (isdir(cmd_all)) | 222 else if (isdir(cmd_all)) |
226 { | 223 { |
227 parse_command_line_process_dir(cmd_all, path, file, &list, &first_dir); | 224 parse_command_line_process_dir(cmd_all, &command_line->path, &command_line->file, &list, &first_dir); |
228 } | 225 } |
229 else if (cmd_line[0] == G_DIR_SEPARATOR && isfile(cmd_line)) | 226 else if (cmd_line[0] == G_DIR_SEPARATOR && isfile(cmd_line)) |
230 { | 227 { |
231 parse_command_line_process_file(cmd_line, path, file, | 228 parse_command_line_process_file(cmd_line, &command_line->path, &command_line->file, |
232 &list, collection_list, &first_dir); | 229 &list, &command_line->collection_list, &first_dir); |
233 } | 230 } |
234 else if (isfile(cmd_all)) | 231 else if (isfile(cmd_all)) |
235 { | 232 { |
236 parse_command_line_process_file(cmd_all, path, file, | 233 parse_command_line_process_file(cmd_all, &command_line->path, &command_line->file, |
237 &list, collection_list, &first_dir); | 234 &list, &command_line->collection_list, &first_dir); |
238 } | 235 } |
239 else if (strncmp(cmd_line, "--debug", 7) == 0 && (cmd_line[7] == '\0' || cmd_line[7] == '=')) | 236 else if (strncmp(cmd_line, "--debug", 7) == 0 && (cmd_line[7] == '\0' || cmd_line[7] == '=')) |
240 { | 237 { |
241 /* do nothing but do not produce warnings */ | 238 /* do nothing but do not produce warnings */ |
242 } | 239 } |
243 else if (strcmp(cmd_line, "+t") == 0 || | 240 else if (strcmp(cmd_line, "+t") == 0 || |
244 strcmp(cmd_line, "--with-tools") == 0) | 241 strcmp(cmd_line, "--with-tools") == 0) |
245 { | 242 { |
246 options->layout.tools_float = FALSE; | 243 command_line->tools_show = TRUE; |
247 options->layout.tools_hidden = FALSE; | |
248 | 244 |
249 remote_list = g_list_append(remote_list, "+t"); | 245 remote_list = g_list_append(remote_list, "+t"); |
250 } | 246 } |
251 else if (strcmp(cmd_line, "-t") == 0 || | 247 else if (strcmp(cmd_line, "-t") == 0 || |
252 strcmp(cmd_line, "--without-tools") == 0) | 248 strcmp(cmd_line, "--without-tools") == 0) |
253 { | 249 { |
254 options->layout.tools_hidden = TRUE; | 250 command_line->tools_hide = TRUE; |
255 | 251 |
256 remote_list = g_list_append(remote_list, "-t"); | 252 remote_list = g_list_append(remote_list, "-t"); |
257 } | 253 } |
258 else if (strcmp(cmd_line, "-f") == 0 || | 254 else if (strcmp(cmd_line, "-f") == 0 || |
259 strcmp(cmd_line, "--fullscreen") == 0) | 255 strcmp(cmd_line, "--fullscreen") == 0) |
260 { | 256 { |
261 startup_full_screen = TRUE; | 257 command_line->startup_full_screen = TRUE; |
262 } | 258 } |
263 else if (strcmp(cmd_line, "-s") == 0 || | 259 else if (strcmp(cmd_line, "-s") == 0 || |
264 strcmp(cmd_line, "--slideshow") == 0) | 260 strcmp(cmd_line, "--slideshow") == 0) |
265 { | 261 { |
266 startup_in_slideshow = TRUE; | 262 command_line->startup_in_slideshow = TRUE; |
267 } | 263 } |
268 else if (strcmp(cmd_line, "-l") == 0 || | 264 else if (strcmp(cmd_line, "-l") == 0 || |
269 strcmp(cmd_line, "--list") == 0) | 265 strcmp(cmd_line, "--list") == 0) |
270 { | 266 { |
271 startup_command_line_collection = TRUE; | 267 command_line->startup_command_line_collection = TRUE; |
272 } | 268 } |
273 else if (strncmp(cmd_line, "--geometry=", 11) == 0) | 269 else if (strncmp(cmd_line, "--geometry=", 11) == 0) |
274 { | 270 { |
275 if (!*geometry) *geometry = g_strdup(cmd_line + 11); | 271 if (!command_line->geometry) command_line->geometry = g_strdup(cmd_line + 11); |
276 } | 272 } |
277 else if (strcmp(cmd_line, "-r") == 0 || | 273 else if (strcmp(cmd_line, "-r") == 0 || |
278 strcmp(cmd_line, "--remote") == 0) | 274 strcmp(cmd_line, "--remote") == 0) |
279 { | 275 { |
280 if (!remote_do) | 276 if (!remote_do) |
289 remote_help(); | 285 remote_help(); |
290 exit(0); | 286 exit(0); |
291 } | 287 } |
292 else if (strcmp(cmd_line, "--blank") == 0) | 288 else if (strcmp(cmd_line, "--blank") == 0) |
293 { | 289 { |
294 startup_blank = TRUE; | 290 command_line->startup_blank = TRUE; |
295 } | 291 } |
296 else if (strcmp(cmd_line, "-v") == 0 || | 292 else if (strcmp(cmd_line, "-v") == 0 || |
297 strcmp(cmd_line, "--version") == 0) | 293 strcmp(cmd_line, "--version") == 0) |
298 { | 294 { |
299 printf_term("%s %s\n", GQ_APPNAME, VERSION); | 295 printf_term("%s %s\n", GQ_APPNAME, VERSION); |
340 | 336 |
341 g_free(cmd_all); | 337 g_free(cmd_all); |
342 i++; | 338 i++; |
343 } | 339 } |
344 g_free(base_dir); | 340 g_free(base_dir); |
345 parse_out_relatives(*path); | 341 parse_out_relatives(command_line->path); |
346 parse_out_relatives(*file); | 342 parse_out_relatives(command_line->file); |
347 } | 343 } |
348 | 344 |
349 list = g_list_reverse(list); | 345 list = g_list_reverse(list); |
350 | 346 |
351 if (!*path && first_dir) | 347 if (!command_line->path && first_dir) |
352 { | 348 { |
353 *path = first_dir; | 349 command_line->path = first_dir; |
354 first_dir = NULL; | 350 first_dir = NULL; |
355 | 351 |
356 parse_out_relatives(*path); | 352 parse_out_relatives(command_line->path); |
357 } | 353 } |
358 g_free(first_dir); | 354 g_free(first_dir); |
359 | 355 |
360 if (remote_do) | 356 if (remote_do) |
361 { | 357 { |
373 } | 369 } |
374 | 370 |
375 printf_term(_("\nUse --remote-help for valid remote options.\n")); | 371 printf_term(_("\nUse --remote-help for valid remote options.\n")); |
376 } | 372 } |
377 | 373 |
378 remote_control(argv[0], remote_list, *path, list, *collection_list); | 374 remote_control(argv[0], remote_list, command_line->path, list, command_line->collection_list); |
379 } | 375 } |
380 g_list_free(remote_list); | 376 g_list_free(remote_list); |
381 | 377 |
382 if (list && list->next) | 378 if (list && list->next) |
383 { | 379 { |
384 *cmd_list = list; | 380 command_line->cmd_list = list; |
385 } | 381 } |
386 else | 382 else |
387 { | 383 { |
388 filelist_free(list); | 384 filelist_free(list); |
389 *cmd_list = NULL; | 385 command_line->cmd_list = NULL; |
386 } | |
387 | |
388 if (command_line->startup_blank) | |
389 { | |
390 g_free(command_line->path); | |
391 command_line->path = NULL; | |
392 g_free(command_line->file); | |
393 command_line->file = NULL; | |
394 filelist_free(command_line->cmd_list); | |
395 command_line->cmd_list = NULL; | |
396 string_list_free(command_line->collection_list); | |
397 command_line->collection_list = NULL; | |
390 } | 398 } |
391 } | 399 } |
392 | 400 |
393 static void parse_command_line_for_debug_option(gint argc, gchar *argv[]) | 401 static void parse_command_line_for_debug_option(gint argc, gchar *argv[]) |
394 { | 402 { |
667 } | 675 } |
668 | 676 |
669 void init_after_global_options(void) | 677 void init_after_global_options(void) |
670 { | 678 { |
671 | 679 |
672 if (gtk_major_version < GTK_MAJOR_VERSION || | |
673 (gtk_major_version == GTK_MAJOR_VERSION && gtk_minor_version < GTK_MINOR_VERSION) ) | |
674 { | |
675 log_printf("!!! This is a friendly warning.\n"); | |
676 log_printf("!!! The version of GTK+ in use now is older than when %s was compiled.\n", GQ_APPNAME); | |
677 log_printf("!!! compiled with GTK+-%d.%d\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION); | |
678 log_printf("!!! running with GTK+-%d.%d\n", gtk_major_version, gtk_minor_version); | |
679 log_printf("!!! %s may quit unexpectedly with a relocation error.\n", GQ_APPNAME); | |
680 } | |
681 | |
682 mkdir_if_not_exists(get_rc_dir()); | 680 mkdir_if_not_exists(get_rc_dir()); |
683 mkdir_if_not_exists(get_collections_dir()); | 681 mkdir_if_not_exists(get_collections_dir()); |
684 mkdir_if_not_exists(get_thumbnails_cache_dir()); | 682 mkdir_if_not_exists(get_thumbnails_cache_dir()); |
685 mkdir_if_not_exists(get_metadata_cache_dir()); | 683 mkdir_if_not_exists(get_metadata_cache_dir()); |
686 | 684 |
723 #endif | 721 #endif |
724 } | 722 } |
725 | 723 |
726 gint main(gint argc, gchar *argv[]) | 724 gint main(gint argc, gchar *argv[]) |
727 { | 725 { |
728 LayoutWindow *lw; | |
729 gchar *path = NULL; | |
730 gchar *cmd_path = NULL; | |
731 gchar *cmd_file = NULL; | |
732 GList *cmd_list = NULL; | |
733 GList *collection_list = NULL; | |
734 CollectionData *first_collection = NULL; | 726 CollectionData *first_collection = NULL; |
735 gchar *geometry = NULL; | |
736 gchar *buf; | 727 gchar *buf; |
737 CollectionData *cd = NULL; | 728 CollectionData *cd = NULL; |
738 | 729 |
739 #ifdef HAVE_GTHREAD | 730 #ifdef HAVE_GTHREAD |
740 g_thread_init (NULL); | 731 g_thread_init (NULL); |
769 file_data_register_notify_func(cache_notify_cb, NULL, NOTIFY_PRIORITY_HIGH); | 760 file_data_register_notify_func(cache_notify_cb, NULL, NOTIFY_PRIORITY_HIGH); |
770 file_data_register_notify_func(thumb_notify_cb, NULL, NOTIFY_PRIORITY_HIGH); | 761 file_data_register_notify_func(thumb_notify_cb, NULL, NOTIFY_PRIORITY_HIGH); |
771 file_data_register_notify_func(histogram_notify_cb, NULL, NOTIFY_PRIORITY_HIGH); | 762 file_data_register_notify_func(histogram_notify_cb, NULL, NOTIFY_PRIORITY_HIGH); |
772 file_data_register_notify_func(collect_manager_notify_cb, NULL, NOTIFY_PRIORITY_LOW); | 763 file_data_register_notify_func(collect_manager_notify_cb, NULL, NOTIFY_PRIORITY_LOW); |
773 | 764 |
765 gtkrc_load(); | |
766 gtk_init(&argc, &argv); | |
767 | |
768 if (gtk_major_version < GTK_MAJOR_VERSION || | |
769 (gtk_major_version == GTK_MAJOR_VERSION && gtk_minor_version < GTK_MINOR_VERSION) ) | |
770 { | |
771 log_printf("!!! This is a friendly warning.\n"); | |
772 log_printf("!!! The version of GTK+ in use now is older than when %s was compiled.\n", GQ_APPNAME); | |
773 log_printf("!!! compiled with GTK+-%d.%d\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION); | |
774 log_printf("!!! running with GTK+-%d.%d\n", gtk_major_version, gtk_minor_version); | |
775 log_printf("!!! %s may quit unexpectedly with a relocation error.\n", GQ_APPNAME); | |
776 } | |
777 | |
774 parse_command_line_for_debug_option(argc, argv); | 778 parse_command_line_for_debug_option(argc, argv); |
779 parse_command_line(argc, argv); | |
775 | 780 |
776 options = init_options(NULL); | 781 options = init_options(NULL); |
777 setup_default_options(options); | 782 setup_default_options(options); |
778 | 783 |
779 gtkrc_load(); //FIXME: move to init_after_global_options() | 784 |
780 gtk_init(&argc, &argv); | 785 |
781 | 786 /* load_options calls init_after_global_options() after it parses global options, we have to call it here if it fails*/ |
782 | 787 if (!load_options(options)) init_after_global_options(); |
783 load_options(options); | |
784 /* ^^^ this calls init_after_global_options(); at the right moment*/ | |
785 | 788 |
786 if (!layout_window_list) | 789 if (!layout_window_list) |
787 { // FIXME: commandline handling does not work at all, this is a quick workaround for missing rc file | 790 { |
788 | 791 /* broken or no config file */ |
789 init_after_global_options(); | 792 layout_new_from_config(NULL, NULL, TRUE); |
790 parse_command_line(argc, argv, &cmd_path, &cmd_file, &cmd_list, &collection_list, &geometry); | 793 } |
791 | 794 |
792 if (startup_blank) | 795 if (command_line->collection_list && !command_line->startup_command_line_collection) |
793 { | |
794 g_free(cmd_path); | |
795 cmd_path = NULL; | |
796 g_free(cmd_file); | |
797 cmd_file = NULL; | |
798 filelist_free(cmd_list); | |
799 cmd_list = NULL; | |
800 string_list_free(collection_list); | |
801 collection_list = NULL; | |
802 | |
803 path = NULL; | |
804 } | |
805 else if (cmd_path) | |
806 { | |
807 path = g_strdup(cmd_path); | |
808 } | |
809 else if (options->startup.restore_path && options->startup.path && isdir(options->startup.path)) | |
810 { | |
811 path = g_strdup(options->startup.path); | |
812 } | |
813 else | |
814 { | |
815 path = get_current_dir(); | |
816 } | |
817 | |
818 lw = layout_new_with_geometry(NULL, NULL, geometry); | |
819 layout_sort_set(lw, options->file_sort.method, options->file_sort.ascending); | |
820 | |
821 if (collection_list && !startup_command_line_collection) | |
822 { | 796 { |
823 GList *work; | 797 GList *work; |
824 | 798 |
825 work = collection_list; | 799 work = command_line->collection_list; |
826 while (work) | 800 while (work) |
827 { | 801 { |
828 CollectWindow *cw; | 802 CollectWindow *cw; |
829 const gchar *path; | 803 const gchar *path; |
830 | 804 |
834 cw = collection_window_new(path); | 808 cw = collection_window_new(path); |
835 if (!first_collection && cw) first_collection = cw->cd; | 809 if (!first_collection && cw) first_collection = cw->cd; |
836 } | 810 } |
837 } | 811 } |
838 | 812 |
839 if (cmd_list || | 813 if (command_line->cmd_list || |
840 (startup_command_line_collection && collection_list)) | 814 (command_line->startup_command_line_collection && command_line->collection_list)) |
841 { | 815 { |
842 GList *work; | 816 GList *work; |
843 | 817 |
844 if (startup_command_line_collection) | 818 if (command_line->startup_command_line_collection) |
845 { | 819 { |
846 CollectWindow *cw; | 820 CollectWindow *cw; |
847 | 821 |
848 cw = collection_window_new(""); | 822 cw = collection_window_new(""); |
849 cd = cw->cd; | 823 cd = cw->cd; |
858 g_free(cd->name); | 832 g_free(cd->name); |
859 cd->name = g_strdup(_("Command line")); | 833 cd->name = g_strdup(_("Command line")); |
860 | 834 |
861 collection_path_changed(cd); | 835 collection_path_changed(cd); |
862 | 836 |
863 work = cmd_list; | 837 work = command_line->cmd_list; |
864 while (work) | 838 while (work) |
865 { | 839 { |
866 collection_add(cd, file_data_new_simple((gchar *)work->data), FALSE); | 840 collection_add(cd, file_data_new_simple((gchar *)work->data), FALSE); |
867 work = work->next; | 841 work = work->next; |
868 } | 842 } |
869 | 843 |
870 work = collection_list; | 844 work = command_line->collection_list; |
871 while (work) | 845 while (work) |
872 { | 846 { |
873 collection_load(cd, (gchar *)work->data, COLLECTION_LOAD_APPEND); | 847 collection_load(cd, (gchar *)work->data, COLLECTION_LOAD_APPEND); |
874 work = work->next; | 848 work = work->next; |
875 } | 849 } |
876 | 850 |
877 layout_set_path(lw, path); | 851 if (cd->list) layout_image_set_collection(NULL, cd, cd->list->data); |
878 if (cd->list) layout_image_set_collection(lw, cd, cd->list->data); | |
879 | 852 |
880 /* mem leak, we never unref this collection when !startup_command_line_collection | 853 /* mem leak, we never unref this collection when !startup_command_line_collection |
881 * (the image view of the main window does not hold a ref to the collection) | 854 * (the image view of the main window does not hold a ref to the collection) |
882 * this is sort of unavoidable, for if it did hold a ref, next/back | 855 * this is sort of unavoidable, for if it did hold a ref, next/back |
883 * may not work as expected when closing collection windows. | 856 * may not work as expected when closing collection windows. |
884 * | 857 * |
885 * collection_unref(cd); | 858 * collection_unref(cd); |
886 */ | 859 */ |
887 | 860 |
888 } | 861 } |
889 else if (cmd_file) | 862 else if (first_collection) |
890 { | 863 { |
891 layout_set_path(lw, cmd_file); | 864 layout_image_set_collection(NULL, first_collection, |
892 } | 865 collection_get_first(first_collection)); |
893 else | 866 } |
894 { | |
895 layout_set_path(lw, path); | |
896 if (first_collection) | |
897 { | |
898 layout_image_set_collection(lw, first_collection, | |
899 collection_get_first(first_collection)); | |
900 } | |
901 } | |
902 | |
903 image_osd_set(lw->image, options->image_overlay.common.state | (options->image_overlay.common.show_at_startup ? OSD_SHOW_INFO : OSD_SHOW_NOTHING)); | |
904 | |
905 } | |
906 | |
907 g_free(geometry); | |
908 g_free(cmd_path); | |
909 g_free(cmd_file); | |
910 filelist_free(cmd_list); | |
911 string_list_free(collection_list); | |
912 g_free(path); | |
913 | |
914 if (startup_full_screen) layout_image_full_screen_start(lw); | |
915 if (startup_in_slideshow) layout_image_slideshow_start(lw); | |
916 | 867 |
917 buf = g_build_filename(get_rc_dir(), ".command", NULL); | 868 buf = g_build_filename(get_rc_dir(), ".command", NULL); |
918 remote_connection = remote_server_init(buf, cd); | 869 remote_connection = remote_server_init(buf, cd); |
919 g_free(buf); | 870 g_free(buf); |
920 | 871 |