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 "slideshow.h"
18 #include "ui_fileops.h"
22 *-----------------------------------------------------------------------------
23 * line write/parse routines (private)
24 *-----------------------------------------------------------------------------
27 gchar *quoted_value(const gchar *text)
31 gint l = strlen(text);
34 if (l == 0) return retval;
36 while (c < l && text[c] !='"') c++;
45 if (text[e-1] != '\\' && text[e] == '"') break;
52 gchar *substring = g_strndup(ptr, e - c);
56 retval = g_strcompress(substring);
63 /* for compatibility with older formats (<0.3.7)
64 * read a line without quotes too */
67 while (c < l && text[c] !=' ' && text[c] !=8 && text[c] != '\n') c++;
70 retval = g_strndup(text, c);
77 gchar *escquote_value(const gchar *text)
82 if (!text) return g_strdup("");
84 e = g_strescape(text, "");
87 gchar *retval = g_strdup_printf("\"%s\"", e);
94 static void write_char_option(FILE *f, gchar *label, gchar *text)
96 gchar *escval = escquote_value(text);
100 fprintf(f,"%s: %s\n", label, escval);
104 fprintf(f,"%s: \n", label);
107 static gchar *read_char_option(FILE *f, gchar *option, gchar *label, gchar *value, gchar *text)
109 if (strcasecmp(option, label) == 0)
112 text = quoted_value(value);
117 static void write_color_option(FILE *f, gchar *label, GdkColor *color)
121 gchar *colorstring = gdk_color_to_string (color);
123 fprintf(f,"%s: \"%s\"\n", label, colorstring);
127 fprintf(f,"%s: \n", label);
130 static GdkColor *read_color_option(FILE *f, gchar *option, gchar *label, gchar *value, GdkColor *color)
132 if (strcasecmp(option, label) == 0)
134 gdk_color_parse(quoted_value(value), color);
140 static void write_int_option(FILE *f, gchar *label, gint n)
142 fprintf(f,"%s: %d\n\n", label, n);
145 static gint read_int_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n)
147 if (strcasecmp(option, label) == 0)
149 n = strtol(value, NULL, 10);
154 static void write_int_unit_option(FILE *f, gchar *label, gint n, gint subunits)
169 fprintf(f,"%s: %d.%d\n\n", label, l, r);
172 static gint read_int_unit_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n, gint subunits)
174 if (strcasecmp(option, label) == 0)
180 while (*ptr != '\0' && *ptr != '.') ptr++;
184 l = strtol(value, NULL, 10);
187 r = strtol(ptr, NULL, 10);
191 l = strtol(value, NULL, 10);
195 n = l * subunits + r;
200 static void write_bool_option(FILE *f, gchar *label, gint n)
202 fprintf(f,"%s: ", label);
203 if (n) fprintf(f,"true\n"); else fprintf(f,"false\n");
207 static gint read_bool_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n)
209 if (strcasecmp(option, label) == 0)
211 if (strcasecmp(value, "true") == 0)
220 *-----------------------------------------------------------------------------
221 * save configuration (public)
222 *-----------------------------------------------------------------------------
225 void save_options(void)
232 rc_path = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/", RC_FILE_NAME, NULL);
234 rc_pathl = path_from_utf8(rc_path);
235 f = fopen(rc_pathl, "w");
241 buf = g_strdup_printf(_("error saving config file: %s\n"), rc_path);
249 fprintf(f,"######################################################################\n");
250 fprintf(f,"# Geeqie config file version %7s #\n", VERSION);
251 fprintf(f,"######################################################################\n");
253 fprintf(f,"# Note: This file is autogenerated. Options can be changed here,\n");
254 fprintf(f,"# but user comments and formatting will be lost.\n");
256 fprintf(f,"##### General Options #####\n\n");
258 write_int_option(f, "layout_style", layout_style);
259 write_char_option(f, "layout_order", layout_order);
261 write_bool_option(f, "layout_view_as_icons", layout_view_icons);
262 write_bool_option(f, "layout_view_as_tree", layout_view_tree);
263 write_bool_option(f, "show_icon_names", show_icon_names);
266 write_bool_option(f, "tree_descend_folders", tree_descend_subdirs);
267 write_bool_option(f, "lazy_image_sync", lazy_image_sync);
268 write_bool_option(f, "update_on_time_change", update_on_time_change);
269 write_bool_option(f, "exif_auto_rotate", exif_rotate_enable);
272 write_bool_option(f, "enable_startup_path", startup_path_enable);
273 write_char_option(f, "startup_path", startup_path);
276 fprintf(f,"zoom_mode: ");
277 if (zoom_mode == ZOOM_RESET_ORIGINAL) fprintf(f,"original\n");
278 if (zoom_mode == ZOOM_RESET_FIT_WINDOW) fprintf(f,"fit\n");
279 if (zoom_mode == ZOOM_RESET_NONE) fprintf(f,"dont_change\n");
281 write_bool_option(f, "two_pass_scaling", two_pass_zoom);
283 write_bool_option(f, "zoom_to_fit_allow_expand", zoom_to_fit_expands);
286 write_bool_option(f, "fit_window_to_image", fit_window);
287 write_bool_option(f, "limit_window_size", limit_window_size);
288 write_int_option(f, "max_window_size", max_window_size);
289 write_bool_option(f, "limit_autofit_size", limit_autofit_size);
290 write_int_option(f, "max_autofit_size", max_autofit_size);
293 write_bool_option(f, "progressive_keyboard_scrolling", progressive_key_scrolling);
294 write_int_option(f, "scroll_reset_method", scroll_reset_method);
297 write_bool_option(f, "enable_thumbnails", thumbnails_enabled);
298 write_int_option(f, "thumbnail_width", thumb_max_width);
299 write_int_option(f, "thumbnail_height", thumb_max_height);
300 write_bool_option(f, "cache_thumbnails", enable_thumb_caching);
301 write_bool_option(f, "cache_thumbnails_into_dirs", enable_thumb_dirs);
302 write_bool_option(f, "thumbnail_fast", thumbnail_fast);
303 write_bool_option(f, "use_xvpics_thumbnails", use_xvpics_thumbnails);
304 write_bool_option(f, "thumbnail_spec_standard", thumbnail_spec_standard);
307 write_bool_option(f, "local_metadata", enable_metadata_dirs);
310 write_int_option(f, "sort_method", (gint)file_sort_method);
311 write_bool_option(f, "sort_ascending", file_sort_ascending);
312 write_bool_option(f, "sort_case_sensitive", file_sort_case_sensitive);
315 write_bool_option(f, "confirm_delete", confirm_delete);
316 write_bool_option(f, "enable_delete_key", enable_delete_key);
317 write_bool_option(f, "safe_delete", safe_delete_enable);
318 write_char_option(f, "safe_delete_path", safe_delete_path);
319 write_int_option(f, "safe_delete_size", safe_delete_size);
321 write_bool_option(f, "tools_float", tools_float);
322 write_bool_option(f, "tools_hidden", tools_hidden);
323 write_bool_option(f, "restore_tool_state", restore_tool);
325 write_bool_option(f, "toolbar_hidden", toolbar_hidden);
327 write_bool_option(f, "mouse_wheel_scrolls", mousewheel_scrolls);
328 write_bool_option(f, "in_place_rename", enable_in_place_rename);
330 write_int_option(f, "open_recent_max", recent_list_max);
332 write_int_option(f, "image_cache_size_max", tile_cache_max);
334 write_int_option(f, "thumbnail_quality", thumbnail_quality);
335 write_int_option(f, "zoom_quality", zoom_quality);
336 write_int_option(f, "dither_quality", dither_quality);
338 write_int_option(f, "zoom_increment", zoom_increment);
340 write_bool_option(f, "enable_read_ahead", enable_read_ahead);
342 write_bool_option(f, "display_dialogs_under_mouse", place_dialogs_under_mouse);
344 write_bool_option(f, "user_specified_window_background", user_specified_window_background);
345 write_color_option(f, "window_background_color", &window_background_color);
347 write_int_option(f, "fullscreen_screen", fullscreen_screen);
348 write_bool_option(f, "fullscreen_clean_flip", fullscreen_clean_flip);
349 write_bool_option(f, "fullscreen_disable_saver", fullscreen_disable_saver);
350 write_bool_option(f, "fullscreen_above", fullscreen_above);
352 write_int_option(f, "custom_similarity_threshold", dupe_custom_threshold);
354 fprintf(f,"\n##### Slideshow Options #####\n\n");
356 write_int_unit_option(f, "slideshow_delay", slideshow_delay, SLIDESHOW_SUBSECOND_PRECISION);
358 write_bool_option(f, "slideshow_random", slideshow_random);
359 write_bool_option(f, "slideshow_repeat", slideshow_repeat);
361 fprintf(f,"\n##### Filtering Options #####\n\n");
363 write_bool_option(f, "show_dotfiles", show_dot_files);
364 write_bool_option(f, "disable_filtering", file_filter_disable);
365 filter_write_list(f);
367 sidecar_ext_write(f);
369 fprintf(f,"\n##### Color Profiles #####\n\n");
372 fprintf(f,"# NOTICE: Geeqie was not built with support for color profiles,\n"
373 "# color profile options will have no effect.\n\n");
376 write_bool_option(f, "color_profile_enabled", color_profile_enabled);
377 write_bool_option(f, "color_profile_use_image", color_profile_use_image);
378 write_int_option(f, "color_profile_input_type", color_profile_input_type);
379 for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
383 buf = g_strdup_printf("color_profile_input_file_%d", i + 1);
384 write_char_option(f, buf, color_profile_input_file[i]);
387 buf = g_strdup_printf("color_profile_input_name_%d", i + 1);
388 write_char_option(f, buf, color_profile_input_name[i]);
392 write_int_option(f, "color_profile_screen_type", color_profile_screen_type);
393 write_char_option(f, "color_profile_screen_file_1", color_profile_screen_file);
395 fprintf(f,"\n##### External Programs #####\n");
396 fprintf(f,"# Maximum of 10 programs (external_1 through external_10)\n");
397 fprintf(f,"# format: external_n: \"menu name\" \"command line\"\n\n");
399 for (i = 0; i < GQVIEW_EDITOR_SLOTS; i++)
401 fprintf(f,"external_%d: \"", i+1);
402 if (editor_name[i]) fprintf(f, "%s", editor_name[i]);
404 if (editor_command[i]) fprintf(f, "%s", editor_command[i]);
408 fprintf(f,"\n##### Collection Options #####\n\n");
410 write_bool_option(f, "rectangular_selections", collection_rectangular_selection);
412 fprintf(f,"\n##### Window Positions #####\n\n");
414 write_bool_option(f, "restore_window_positions", save_window_positions);
416 write_int_option(f, "main_window_x", main_window_x);
417 write_int_option(f, "main_window_y", main_window_y);
418 write_int_option(f, "main_window_width", main_window_w);
419 write_int_option(f, "main_window_height", main_window_h);
420 write_bool_option(f, "main_window_maximized", main_window_maximized);
421 write_int_option(f, "float_window_x", float_window_x);
422 write_int_option(f, "float_window_y", float_window_y);
423 write_int_option(f, "float_window_width", float_window_w);
424 write_int_option(f, "float_window_height", float_window_h);
425 write_int_option(f, "float_window_divider", float_window_divider);
426 write_int_option(f, "divider_position_h", window_hdivider_pos);
427 write_int_option(f, "divider_position_v", window_vdivider_pos);
429 fprintf(f,"######################################################################\n");
430 fprintf(f,"# end of Geeqie config file #\n");
431 fprintf(f,"######################################################################\n");
439 *-----------------------------------------------------------------------------
440 * load configuration (public)
441 *-----------------------------------------------------------------------------
444 void load_options(void)
453 gchar value_all[1024];
456 rc_path = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/", RC_FILE_NAME, NULL);
458 rc_pathl = path_from_utf8(rc_path);
459 f = fopen(rc_pathl,"r");
467 while (fgets(s_buf,1024,f))
469 if (s_buf[0]=='#') continue;
470 if (s_buf[0]=='\n') continue;
473 while (s_buf[c] != ':' && c < l) c++;
474 if (c >= l) continue;
477 while ((s_buf[c] == ' ' || s_buf[c] == 8) && c < l) c++;
478 s_buf_ptr = s_buf + c;
479 strncpy(value_all, s_buf_ptr, sizeof(value_all));
480 while (s_buf[c] != 8 && s_buf[c] != ' ' && s_buf[c] != '\n' && c < l) c++;
482 strncpy(option, s_buf, sizeof(option));
483 strncpy(value, s_buf_ptr, sizeof(value));
485 /* general options */
487 layout_style = read_int_option(f, option,
488 "layout_style", value, layout_style);
489 layout_order = read_char_option(f, option,
490 "layout_order", value, layout_order);
491 layout_view_icons = read_bool_option(f, option,
492 "layout_view_as_icons", value, layout_view_icons);
493 layout_view_tree = read_bool_option(f, option,
494 "layout_view_as_tree", value, layout_view_tree);
495 show_icon_names = read_bool_option(f, option,
496 "show_icon_names", value, show_icon_names);
498 tree_descend_subdirs = read_bool_option(f, option,
499 "tree_descend_folders", value, tree_descend_subdirs);
500 lazy_image_sync = read_bool_option(f, option,
501 "lazy_image_sync", value, lazy_image_sync);
502 update_on_time_change = read_bool_option(f, option,
503 "update_on_time_change", value, update_on_time_change);
504 exif_rotate_enable = read_bool_option(f, option,
505 "exif_auto_rotate", value, exif_rotate_enable);
507 startup_path_enable = read_bool_option(f, option,
508 "enable_startup_path", value, startup_path_enable);
509 startup_path = read_char_option(f, option,
510 "startup_path", value_all, startup_path);
512 if (strcasecmp(option,"zoom_mode") == 0)
514 if (strcasecmp(value, "original") == 0) zoom_mode = ZOOM_RESET_ORIGINAL;
515 if (strcasecmp(value, "fit") == 0) zoom_mode = ZOOM_RESET_FIT_WINDOW;
516 if (strcasecmp(value, "dont_change") == 0) zoom_mode = ZOOM_RESET_NONE;
518 two_pass_zoom = read_bool_option(f, option,
519 "two_pass_scaling", value, two_pass_zoom);
520 zoom_to_fit_expands = read_bool_option(f, option,
521 "zoom_to_fit_allow_expand", value, zoom_to_fit_expands);
523 fit_window = read_bool_option(f, option,
524 "fit_window_to_image", value, fit_window);
525 limit_window_size = read_bool_option(f, option,
526 "limit_window_size", value, limit_window_size);
527 max_window_size = read_int_option(f, option,
528 "max_window_size", value, max_window_size);
529 limit_autofit_size = read_bool_option(f, option,
530 "limit_autofit_size", value, limit_autofit_size);
531 max_autofit_size = read_int_option(f, option,
532 "max_autofit_size", value, max_autofit_size);
533 progressive_key_scrolling = read_bool_option(f, option,
534 "progressive_keyboard_scrolling", value, progressive_key_scrolling);
535 scroll_reset_method = read_int_option(f, option,
536 "scroll_reset_method", value, scroll_reset_method);
538 thumbnails_enabled = read_bool_option(f, option,
539 "enable_thumbnails", value, thumbnails_enabled);
540 thumb_max_width = read_int_option(f, option,
541 "thumbnail_width", value, thumb_max_width);
542 thumb_max_height = read_int_option(f, option,
543 "thumbnail_height", value, thumb_max_height);
544 enable_thumb_caching = read_bool_option(f, option,
545 "cache_thumbnails", value, enable_thumb_caching);
546 enable_thumb_dirs = read_bool_option(f, option,
547 "cache_thumbnails_into_dirs", value, enable_thumb_dirs);
548 thumbnail_fast = read_bool_option(f, option,
549 "thumbnail_fast", value, thumbnail_fast);
550 use_xvpics_thumbnails = read_bool_option(f, option,
551 "use_xvpics_thumbnails", value, use_xvpics_thumbnails);
552 thumbnail_spec_standard = read_bool_option(f, option,
553 "thumbnail_spec_standard", value, thumbnail_spec_standard);
555 enable_metadata_dirs = read_bool_option(f, option,
556 "local_metadata", value, enable_metadata_dirs);
558 file_sort_method = (SortType)read_int_option(f, option,
559 "sort_method", value, (gint)file_sort_method);
560 file_sort_ascending = read_bool_option(f, option,
561 "sort_ascending", value, file_sort_ascending);
562 file_sort_case_sensitive = read_bool_option(f, option,
563 "sort_case_sensitive", value, file_sort_case_sensitive);
565 confirm_delete = read_bool_option(f, option,
566 "confirm_delete", value, confirm_delete);
567 enable_delete_key = read_bool_option(f, option,
568 "enable_delete_key", value, enable_delete_key);
569 safe_delete_enable = read_bool_option(f, option,
570 "safe_delete", value, safe_delete_enable);
571 safe_delete_path = read_char_option(f, option,
572 "safe_delete_path", value, safe_delete_path);
573 safe_delete_size = read_int_option(f, option,
574 "safe_delete_size", value, safe_delete_size);
576 tools_float = read_bool_option(f, option,
577 "tools_float", value, tools_float);
578 tools_hidden = read_bool_option(f, option,
579 "tools_hidden", value, tools_hidden);
580 restore_tool = read_bool_option(f, option,
581 "restore_tool_state", value, restore_tool);
583 toolbar_hidden = read_bool_option(f, option,
584 "toolbar_hidden", value, toolbar_hidden);
586 mousewheel_scrolls = read_bool_option(f, option,
587 "mouse_wheel_scrolls", value, mousewheel_scrolls);
588 enable_in_place_rename = read_bool_option(f, option,
589 "in_place_rename", value, enable_in_place_rename);
591 recent_list_max = read_int_option(f, option,
592 "open_recent_max", value, recent_list_max);
594 tile_cache_max = read_int_option(f, option,
595 "image_cache_size_max", value, tile_cache_max);
597 thumbnail_quality = CLAMP(read_int_option(f, option,
598 "thumbnail_quality", value, thumbnail_quality), GDK_INTERP_NEAREST, GDK_INTERP_HYPER);
599 zoom_quality = CLAMP(read_int_option(f, option,
600 "zoom_quality", value, zoom_quality), GDK_INTERP_NEAREST, GDK_INTERP_HYPER);
601 dither_quality = CLAMP(read_int_option(f, option,
602 "dither_quality", value, dither_quality), GDK_RGB_DITHER_NONE, GDK_RGB_DITHER_MAX);
604 zoom_increment = read_int_option(f, option,
605 "zoom_increment", value, zoom_increment);
607 enable_read_ahead = read_bool_option(f, option,
608 "enable_read_ahead", value, enable_read_ahead);
610 place_dialogs_under_mouse = read_bool_option(f, option,
611 "display_dialogs_under_mouse", value, place_dialogs_under_mouse);
613 user_specified_window_background = read_bool_option(f, option,
614 "user_specified_window_background", value, user_specified_window_background);
615 read_color_option(f, option,
616 "window_background_color", value, &window_background_color);
618 fullscreen_screen = read_int_option(f, option,
619 "fullscreen_screen", value, fullscreen_screen);
620 fullscreen_clean_flip = read_bool_option(f, option,
621 "fullscreen_clean_flip", value, fullscreen_clean_flip);
622 fullscreen_disable_saver = read_bool_option(f, option,
623 "fullscreen_disable_saver", value, fullscreen_disable_saver);
624 fullscreen_above = read_bool_option(f, option,
625 "fullscreen_above", value, fullscreen_above);
627 dupe_custom_threshold = read_int_option(f, option,
628 "custom_similarity_threshold", value, dupe_custom_threshold);
630 /* slideshow options */
632 slideshow_delay = read_int_unit_option(f, option,
633 "slideshow_delay", value, slideshow_delay, SLIDESHOW_SUBSECOND_PRECISION);
634 slideshow_random = read_bool_option(f, option,
635 "slideshow_random", value, slideshow_random);
636 slideshow_repeat = read_bool_option(f, option,
637 "slideshow_repeat", value, slideshow_repeat);
639 /* filtering options */
641 show_dot_files = read_bool_option(f, option,
642 "show_dotfiles", value, show_dot_files);
643 file_filter_disable = read_bool_option(f, option,
644 "disable_filtering", value, file_filter_disable);
646 if (strcasecmp(option, "filter_ext") == 0)
648 filter_parse(value_all);
651 if (strcasecmp(option, "sidecar_ext") == 0)
653 sidecar_ext_parse(value_all, TRUE);
658 color_profile_enabled = read_bool_option(f, option,
659 "color_profile_enabled", value, color_profile_enabled);
660 color_profile_use_image = read_bool_option(f, option,
661 "color_profile_use_image", value, color_profile_use_image);
662 color_profile_input_type = read_int_option(f, option,
663 "color_profile_input_type", value, color_profile_input_type);
665 if (strncasecmp(option, "color_profile_input_file_", 25) == 0)
667 i = strtol(option + 25, NULL, 0) - 1;
668 if (i >= 0 && i < COLOR_PROFILE_INPUTS)
670 color_profile_input_file[i] = read_char_option(f, option,
671 option, value, color_profile_input_file[i]);
674 if (strncasecmp(option, "color_profile_input_name_", 25) == 0)
676 i = strtol(option + 25, NULL, 0) - 1;
677 if (i >= 0 && i < COLOR_PROFILE_INPUTS)
679 color_profile_input_name[i] = read_char_option(f, option,
680 option, value, color_profile_input_name[i]);
684 color_profile_screen_type = read_int_option(f, option,
685 "color_profile_screen_type", value, color_profile_screen_type);
686 color_profile_screen_file = read_char_option(f, option,
687 "color_profile_screen_file_1", value, color_profile_screen_file);
689 /* External Programs */
691 if (strncasecmp(option, "external_", 9) == 0)
693 i = strtol(option + 9, NULL, 0);
694 if (i > 0 && i <= GQVIEW_EDITOR_SLOTS)
699 l = strlen(value_all);
702 g_free(editor_name[i]);
703 editor_name[i] = NULL;
704 g_free(editor_command[i]);
705 editor_command[i] = NULL;
707 while (c<l && value_all[c] !='"') c++;
712 while (c<l && value_all[c] !='"') c++;
716 if (ptr1 + c - 1 != ptr2)
717 editor_name[i] = g_strdup(ptr2);
719 while (c<l && value_all[c] !='"') c++;
724 while (value_all[c] != '\0') c++;
725 while (c > 0 && value_all[c] != '"') c--;
726 if (ptr1[c] == '"' && ptr1 + c > ptr2)
729 editor_command[i] = g_strdup(ptr2);
737 /* colection options */
739 collection_rectangular_selection = read_bool_option(f, option,
740 "rectangular_selections", value, collection_rectangular_selection);
742 /* window positions */
744 save_window_positions = read_bool_option(f, option,
745 "restore_window_positions", value, save_window_positions);
747 main_window_x = read_int_option(f, option,
748 "main_window_x", value, main_window_x);
749 main_window_y = read_int_option(f, option,
750 "main_window_y", value, main_window_y);
751 main_window_w = read_int_option(f, option,
752 "main_window_width", value, main_window_w);
753 main_window_h = read_int_option(f, option,
754 "main_window_height", value, main_window_h);
755 main_window_maximized = read_bool_option(f, option,
756 "main_window_maximized", value, main_window_maximized);
757 float_window_x = read_int_option(f, option,
758 "float_window_x", value, float_window_x);
759 float_window_y = read_int_option(f, option,
760 "float_window_y", value, float_window_y);
761 float_window_w = read_int_option(f, option,
762 "float_window_width", value, float_window_w);
763 float_window_h = read_int_option(f, option,
764 "float_window_height", value, float_window_h);
765 float_window_divider = read_int_option(f, option,
766 "float_window_divider", value, float_window_divider);
767 window_hdivider_pos = read_int_option(f, option,
768 "divider_position_h", value, window_hdivider_pos);
769 window_vdivider_pos = read_int_option(f, option,
770 "divider_position_v", value, window_vdivider_pos);