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);
33 if (l == 0) return NULL;
35 while (c < l && text[c] !='"') c++;
42 while (e < l && text[e] !='"') e++;
47 return g_strndup(ptr, e - c);
52 /* for compatibility with older formats (<0.3.7)
53 * read a line without quotes too */
56 while (c < l && text[c] !=' ' && text[c] !=8 && text[c] != '\n') c++;
59 return g_strndup(text, c);
66 static void write_char_option(FILE *f, gchar *label, gchar *text)
69 fprintf(f,"%s: \"%s\"\n", label, text);
71 fprintf(f,"%s: \n", label);
74 static gchar *read_char_option(FILE *f, gchar *option, gchar *label, gchar *value, gchar *text)
76 if (strcasecmp(option, label) == 0)
79 text = quoted_value(value);
84 static void write_int_option(FILE *f, gchar *label, gint n)
86 fprintf(f,"%s: %d\n\n", label, n);
89 static gint read_int_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n)
91 if (strcasecmp(option, label) == 0)
93 n = strtol(value, NULL, 10);
98 static void write_int_unit_option(FILE *f, gchar *label, gint n, gint subunits)
113 fprintf(f,"%s: %d.%d\n\n", label, l, r);
116 static gint read_int_unit_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n, gint subunits)
118 if (strcasecmp(option, label) == 0)
124 while (*ptr != '\0' && *ptr != '.') ptr++;
128 l = strtol(value, NULL, 10);
131 r = strtol(ptr, NULL, 10);
135 l = strtol(value, NULL, 10);
139 n = l * subunits + r;
144 static void write_bool_option(FILE *f, gchar *label, gint n)
146 fprintf(f,"%s: ", label);
147 if (n) fprintf(f,"true\n"); else fprintf(f,"false\n");
151 static gint read_bool_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n)
153 if (strcasecmp(option, label) == 0)
155 if (strcasecmp(value, "true") == 0)
164 *-----------------------------------------------------------------------------
165 * save configuration (public)
166 *-----------------------------------------------------------------------------
169 void save_options(void)
176 rc_path = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/", RC_FILE_NAME, NULL);
178 rc_pathl = path_from_utf8(rc_path);
179 f = fopen(rc_pathl, "w");
185 buf = g_strdup_printf(_("error saving config file: %s\n"), rc_path);
193 fprintf(f,"######################################################################\n");
194 fprintf(f,"# GQview config file version %7s #\n", VERSION);
195 fprintf(f,"######################################################################\n");
197 fprintf(f,"# Note: This file is autogenerated. Options can be changed here,\n");
198 fprintf(f,"# but user comments and formatting will be lost.\n");
200 fprintf(f,"##### General Options #####\n\n");
202 write_int_option(f, "layout_style", layout_style);
203 write_char_option(f, "layout_order", layout_order);
205 write_bool_option(f, "layout_view_as_icons", layout_view_icons);
206 write_bool_option(f, "layout_view_as_tree", layout_view_tree);
207 write_bool_option(f, "show_icon_names", show_icon_names);
210 write_bool_option(f, "tree_descend_folders", tree_descend_subdirs);
211 write_bool_option(f, "lazy_image_sync", lazy_image_sync);
212 write_bool_option(f, "update_on_time_change", update_on_time_change);
213 write_bool_option(f, "exif_auto_rotate", exif_rotate_enable);
216 write_bool_option(f, "enable_startup_path", startup_path_enable);
217 write_char_option(f, "startup_path", startup_path);
220 fprintf(f,"zoom_mode: ");
221 if (zoom_mode == ZOOM_RESET_ORIGINAL) fprintf(f,"original\n");
222 if (zoom_mode == ZOOM_RESET_FIT_WINDOW) fprintf(f,"fit\n");
223 if (zoom_mode == ZOOM_RESET_NONE) fprintf(f,"dont_change\n");
225 write_bool_option(f, "two_pass_scaling", two_pass_zoom);
227 write_bool_option(f, "zoom_to_fit_allow_expand", zoom_to_fit_expands);
230 write_bool_option(f, "fit_window_to_image", fit_window);
231 write_bool_option(f, "limit_window_size", limit_window_size);
232 write_int_option(f, "max_window_size", max_window_size);
235 write_bool_option(f, "progressive_keyboard_scrolling", progressive_key_scrolling);
236 write_int_option(f, "scroll_reset_method", scroll_reset_method);
239 write_bool_option(f, "enable_thumbnails", thumbnails_enabled);
240 write_int_option(f, "thumbnail_width", thumb_max_width);
241 write_int_option(f, "thumbnail_height", thumb_max_height);
242 write_bool_option(f, "cache_thumbnails", enable_thumb_caching);
243 write_bool_option(f, "cache_thumbnails_into_dirs", enable_thumb_dirs);
244 write_bool_option(f, "thumbnail_fast", thumbnail_fast);
245 write_bool_option(f, "use_xvpics_thumbnails", use_xvpics_thumbnails);
246 write_bool_option(f, "thumbnail_spec_standard", thumbnail_spec_standard);
249 write_bool_option(f, "local_metadata", enable_metadata_dirs);
252 write_int_option(f, "sort_method", (gint)file_sort_method);
253 write_bool_option(f, "sort_ascending", file_sort_ascending);
254 write_bool_option(f, "sort_case_sensitive", file_sort_case_sensitive);
257 write_bool_option(f, "confirm_delete", confirm_delete);
258 write_bool_option(f, "enable_delete_key", enable_delete_key);
259 write_bool_option(f, "safe_delete", safe_delete_enable);
260 write_char_option(f, "safe_delete_path", safe_delete_path);
261 write_int_option(f, "safe_delete_size", safe_delete_size);
263 write_bool_option(f, "tools_float", tools_float);
264 write_bool_option(f, "tools_hidden", tools_hidden);
265 write_bool_option(f, "restore_tool_state", restore_tool);
267 write_bool_option(f, "toolbar_hidden", toolbar_hidden);
269 write_bool_option(f, "mouse_wheel_scrolls", mousewheel_scrolls);
270 write_bool_option(f, "in_place_rename", enable_in_place_rename);
272 write_int_option(f, "open_recent_max", recent_list_max);
274 write_int_option(f, "image_cache_size_max", tile_cache_max);
276 write_int_option(f, "thumbnail_quality", thumbnail_quality);
277 write_int_option(f, "zoom_quality", zoom_quality);
278 write_int_option(f, "dither_quality", dither_quality);
280 write_int_option(f, "zoom_increment", zoom_increment);
282 write_bool_option(f, "enable_read_ahead", enable_read_ahead);
284 write_bool_option(f, "display_dialogs_under_mouse", place_dialogs_under_mouse);
286 write_bool_option(f, "black_window_background", black_window_background);
288 write_int_option(f, "fullscreen_screen", fullscreen_screen);
289 write_bool_option(f, "fullscreen_clean_flip", fullscreen_clean_flip);
290 write_bool_option(f, "fullscreen_disable_saver", fullscreen_disable_saver);
291 write_bool_option(f, "fullscreen_above", fullscreen_above);
293 write_int_option(f, "custom_similarity_threshold", dupe_custom_threshold);
295 fprintf(f,"\n##### Slideshow Options #####\n\n");
297 write_int_unit_option(f, "slideshow_delay", slideshow_delay, SLIDESHOW_SUBSECOND_PRECISION);
299 write_bool_option(f, "slideshow_random", slideshow_random);
300 write_bool_option(f, "slideshow_repeat", slideshow_repeat);
302 fprintf(f,"\n##### Filtering Options #####\n\n");
304 write_bool_option(f, "show_dotfiles", show_dot_files);
305 write_bool_option(f, "disable_filtering", file_filter_disable);
306 filter_write_list(f);
308 fprintf(f,"\n##### External Programs #####\n");
309 fprintf(f,"# Maximum of 10 programs (external_1 through external_10)\n");
310 fprintf(f,"# format: external_n: \"menu name\" \"command line\"\n\n");
312 for (i = 0; i < GQVIEW_EDITOR_SLOTS; i++)
314 fprintf(f,"external_%d: \"", i+1);
315 if (editor_name[i]) fprintf(f, "%s", editor_name[i]);
317 if (editor_command[i]) fprintf(f, "%s", editor_command[i]);
321 fprintf(f,"\n##### Collection Options #####\n\n");
323 write_bool_option(f, "rectangular_selections", collection_rectangular_selection);
325 fprintf(f,"\n##### Window Positions #####\n\n");
327 write_bool_option(f, "restore_window_positions", save_window_positions);
329 write_int_option(f, "main_window_x", main_window_x);
330 write_int_option(f, "main_window_y", main_window_y);
331 write_int_option(f, "main_window_width", main_window_w);
332 write_int_option(f, "main_window_height", main_window_h);
333 write_bool_option(f, "main_window_maximized", main_window_maximized);
334 write_int_option(f, "float_window_x", float_window_x);
335 write_int_option(f, "float_window_y", float_window_y);
336 write_int_option(f, "float_window_width", float_window_w);
337 write_int_option(f, "float_window_height", float_window_h);
338 write_int_option(f, "float_window_divider", float_window_divider);
339 write_int_option(f, "divider_position_h", window_hdivider_pos);
340 write_int_option(f, "divider_position_v", window_vdivider_pos);
342 fprintf(f,"######################################################################\n");
343 fprintf(f,"# end of GQview config file #\n");
344 fprintf(f,"######################################################################\n");
352 *-----------------------------------------------------------------------------
353 * load configuration (public)
354 *-----------------------------------------------------------------------------
357 void load_options(void)
366 gchar value_all[1024];
369 rc_path = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/", RC_FILE_NAME, NULL);
371 rc_pathl = path_from_utf8(rc_path);
372 f = fopen(rc_pathl,"r");
380 while (fgets(s_buf,1024,f))
382 if (s_buf[0]=='#') continue;
383 if (s_buf[0]=='\n') continue;
386 while (s_buf[c] != ':' && c < l) c++;
387 if (c >= l) continue;
390 while ((s_buf[c] == ' ' || s_buf[c] == 8) && c < l) c++;
391 s_buf_ptr = s_buf + c;
392 strncpy(value_all, s_buf_ptr, sizeof(value_all));
393 while (s_buf[c] != 8 && s_buf[c] != ' ' && s_buf[c] != '\n' && c < l) c++;
395 strncpy(option, s_buf, sizeof(option));
396 strncpy(value, s_buf_ptr, sizeof(value));
398 /* general options */
400 layout_style = read_int_option(f, option,
401 "layout_style", value, layout_style);
402 layout_order = read_char_option(f, option,
403 "layout_order", value, layout_order);
404 layout_view_icons = read_bool_option(f, option,
405 "layout_view_as_icons", value, layout_view_icons);
406 layout_view_tree = read_bool_option(f, option,
407 "layout_view_as_tree", value, layout_view_tree);
408 show_icon_names = read_bool_option(f, option,
409 "show_icon_names", value, show_icon_names);
411 tree_descend_subdirs = read_bool_option(f, option,
412 "tree_descend_folders", value, tree_descend_subdirs);
413 lazy_image_sync = read_bool_option(f, option,
414 "lazy_image_sync", value, lazy_image_sync);
415 update_on_time_change = read_bool_option(f, option,
416 "update_on_time_change", value, update_on_time_change);
417 exif_rotate_enable = read_bool_option(f, option,
418 "exif_auto_rotate", value, exif_rotate_enable);
420 startup_path_enable = read_bool_option(f, option,
421 "enable_startup_path", value, startup_path_enable);
422 startup_path = read_char_option(f, option,
423 "startup_path", value_all, startup_path);
425 if (strcasecmp(option,"zoom_mode") == 0)
427 if (strcasecmp(value, "original") == 0) zoom_mode = ZOOM_RESET_ORIGINAL;
428 if (strcasecmp(value, "fit") == 0) zoom_mode = ZOOM_RESET_FIT_WINDOW;
429 if (strcasecmp(value, "dont_change") == 0) zoom_mode = ZOOM_RESET_NONE;
431 two_pass_zoom = read_bool_option(f, option,
432 "two_pass_scaling", value, two_pass_zoom);
433 zoom_to_fit_expands = read_bool_option(f, option,
434 "zoom_to_fit_allow_expand", value, zoom_to_fit_expands);
436 fit_window = read_bool_option(f, option,
437 "fit_window_to_image", value, fit_window);
438 limit_window_size = read_bool_option(f, option,
439 "limit_window_size", value, limit_window_size);
440 max_window_size = read_int_option(f, option,
441 "max_window_size", value, max_window_size);
442 progressive_key_scrolling = read_bool_option(f, option,
443 "progressive_keyboard_scrolling", value, progressive_key_scrolling);
444 scroll_reset_method = read_int_option(f, option,
445 "scroll_reset_method", value, scroll_reset_method);
447 thumbnails_enabled = read_bool_option(f, option,
448 "enable_thumbnails", value, thumbnails_enabled);
449 thumb_max_width = read_int_option(f, option,
450 "thumbnail_width", value, thumb_max_width);
451 thumb_max_height = read_int_option(f, option,
452 "thumbnail_height", value, thumb_max_height);
453 enable_thumb_caching = read_bool_option(f, option,
454 "cache_thumbnails", value, enable_thumb_caching);
455 enable_thumb_dirs = read_bool_option(f, option,
456 "cache_thumbnails_into_dirs", value, enable_thumb_dirs);
457 thumbnail_fast = read_bool_option(f, option,
458 "thumbnail_fast", value, thumbnail_fast);
459 use_xvpics_thumbnails = read_bool_option(f, option,
460 "use_xvpics_thumbnails", value, use_xvpics_thumbnails);
461 thumbnail_spec_standard = read_bool_option(f, option,
462 "thumbnail_spec_standard", value, thumbnail_spec_standard);
464 enable_metadata_dirs = read_bool_option(f, option,
465 "local_metadata", value, enable_metadata_dirs);
467 file_sort_method = (SortType)read_int_option(f, option,
468 "sort_method", value, (gint)file_sort_method);
469 file_sort_ascending = read_bool_option(f, option,
470 "sort_ascending", value, file_sort_ascending);
471 file_sort_case_sensitive = read_bool_option(f, option,
472 "sort_case_sensitive", value, file_sort_case_sensitive);
474 confirm_delete = read_bool_option(f, option,
475 "confirm_delete", value, confirm_delete);
476 enable_delete_key = read_bool_option(f, option,
477 "enable_delete_key", value, enable_delete_key);
478 safe_delete_enable = read_bool_option(f, option,
479 "safe_delete", value, safe_delete_enable);
480 safe_delete_path = read_char_option(f, option,
481 "safe_delete_path", value, safe_delete_path);
482 safe_delete_size = read_int_option(f, option,
483 "safe_delete_size", value, safe_delete_size);
485 tools_float = read_bool_option(f, option,
486 "tools_float", value, tools_float);
487 tools_hidden = read_bool_option(f, option,
488 "tools_hidden", value, tools_hidden);
489 restore_tool = read_bool_option(f, option,
490 "restore_tool_state", value, restore_tool);
492 toolbar_hidden = read_bool_option(f, option,
493 "toolbar_hidden", value, toolbar_hidden);
495 mousewheel_scrolls = read_bool_option(f, option,
496 "mouse_wheel_scrolls", value, mousewheel_scrolls);
497 enable_in_place_rename = read_bool_option(f, option,
498 "in_place_rename", value, enable_in_place_rename);
500 recent_list_max = read_int_option(f, option,
501 "open_recent_max", value, recent_list_max);
503 tile_cache_max = read_int_option(f, option,
504 "image_cache_size_max", value, tile_cache_max);
506 thumbnail_quality = CLAMP(read_int_option(f, option,
507 "thumbnail_quality", value, thumbnail_quality), GDK_INTERP_NEAREST, GDK_INTERP_HYPER);
508 zoom_quality = CLAMP(read_int_option(f, option,
509 "zoom_quality", value, zoom_quality), GDK_INTERP_NEAREST, GDK_INTERP_HYPER);
510 dither_quality = CLAMP(read_int_option(f, option,
511 "dither_quality", value, dither_quality), GDK_RGB_DITHER_NONE, GDK_RGB_DITHER_MAX);
513 zoom_increment = read_int_option(f, option,
514 "zoom_increment", value, zoom_increment);
516 enable_read_ahead = read_bool_option(f, option,
517 "enable_read_ahead", value, enable_read_ahead);
519 place_dialogs_under_mouse = read_bool_option(f, option,
520 "display_dialogs_under_mouse", value, place_dialogs_under_mouse);
522 black_window_background = read_bool_option(f, option,
523 "black_window_background", value, black_window_background);
525 fullscreen_screen = read_int_option(f, option,
526 "fullscreen_screen", value, fullscreen_screen);
527 fullscreen_clean_flip = read_bool_option(f, option,
528 "fullscreen_clean_flip", value, fullscreen_clean_flip);
529 fullscreen_disable_saver = read_bool_option(f, option,
530 "fullscreen_disable_saver", value, fullscreen_disable_saver);
531 fullscreen_above = read_bool_option(f, option,
532 "fullscreen_above", value, fullscreen_above);
534 dupe_custom_threshold = read_int_option(f, option,
535 "custom_similarity_threshold", value, dupe_custom_threshold);
537 /* slideshow options */
539 slideshow_delay = read_int_unit_option(f, option,
540 "slideshow_delay", value, slideshow_delay, SLIDESHOW_SUBSECOND_PRECISION);
541 slideshow_random = read_bool_option(f, option,
542 "slideshow_random", value, slideshow_random);
543 slideshow_repeat = read_bool_option(f, option,
544 "slideshow_repeat", value, slideshow_repeat);
546 /* filtering options */
548 show_dot_files = read_bool_option(f, option,
549 "show_dotfiles", value, show_dot_files);
550 file_filter_disable = read_bool_option(f, option,
551 "disable_filtering", value, file_filter_disable);
553 if (strcasecmp(option, "filter_ext") == 0)
555 filter_parse(value_all);
558 /* External Programs */
560 if (strncasecmp(option, "external_", 9) == 0)
562 i = strtol(option + 9, NULL, 0);
563 if (i > 0 && i <= GQVIEW_EDITOR_SLOTS)
568 l = strlen(value_all);
571 g_free(editor_name[i]);
572 editor_name[i] = NULL;
573 g_free(editor_command[i]);
574 editor_command[i] = NULL;
576 while (c<l && value_all[c] !='"') c++;
581 while (c<l && value_all[c] !='"') c++;
585 if (ptr1 + c - 1 != ptr2)
586 editor_name[i] = g_strdup(ptr2);
588 while (c<l && value_all[c] !='"') c++;
593 while (value_all[c] != '\0') c++;
594 while (c > 0 && value_all[c] != '"') c--;
595 if (ptr1[c] == '"' && ptr1 + c > ptr2)
598 editor_command[i] = g_strdup(ptr2);
606 /* colection options */
608 collection_rectangular_selection = read_bool_option(f, option,
609 "rectangular_selections", value, collection_rectangular_selection);
611 /* window positions */
613 save_window_positions = read_bool_option(f, option,
614 "restore_window_positions", value, save_window_positions);
616 main_window_x = read_int_option(f, option,
617 "main_window_x", value, main_window_x);
618 main_window_y = read_int_option(f, option,
619 "main_window_y", value, main_window_y);
620 main_window_w = read_int_option(f, option,
621 "main_window_width", value, main_window_w);
622 main_window_h = read_int_option(f, option,
623 "main_window_height", value, main_window_h);
624 main_window_maximized = read_bool_option(f, option,
625 "main_window_maximized", value, main_window_maximized);
626 float_window_x = read_int_option(f, option,
627 "float_window_x", value, float_window_x);
628 float_window_y = read_int_option(f, option,
629 "float_window_y", value, float_window_y);
630 float_window_w = read_int_option(f, option,
631 "float_window_width", value, float_window_w);
632 float_window_h = read_int_option(f, option,
633 "float_window_height", value, float_window_h);
634 float_window_divider = read_int_option(f, option,
635 "float_window_divider", value, float_window_divider);
636 window_hdivider_pos = read_int_option(f, option,
637 "divider_position_h", value, window_hdivider_pos);
638 window_vdivider_pos = read_int_option(f, option,
639 "divider_position_v", value, window_vdivider_pos);