Allow to choose to show parent folder
[geeqie.git] / src / options.c
1 /*
2  * Geeqie
3  * Copyright (C) 2008 - 2012 The Geeqie Team
4  *
5  * Authors: Vladimir Nadvornik, Laurent Monin
6  *
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!
10  */
11
12 #include "main.h"
13 #include "options.h"
14
15 #include "bar_exif.h"
16 #include "editors.h"
17 #include "filefilter.h"
18 #include "histogram.h" /* HCHAN_RGB */
19 #include "image-overlay.h" /* OSD_SHOW_NOTHING */
20 #include "layout.h"
21 #include "layout_image.h"
22 #include "rcfile.h"
23 #include "ui_bookmark.h"
24 #include "ui_fileops.h"
25 #include "window.h"
26
27 ConfOptions *init_options(ConfOptions *options)
28 {
29         if (!options) options = g_new0(ConfOptions, 1);
30
31         options->collections.rectangular_selection = FALSE;
32
33         options->color_profile.enabled = TRUE;
34         options->color_profile.input_type = 0;
35         options->color_profile.screen_file = NULL;
36         options->color_profile.use_image = TRUE;
37         options->color_profile.use_x11_screen_profile = TRUE;
38
39         options->dnd_icon_size = 48;
40         options->duplicates_similarity_threshold = 99;
41
42         options->file_filter.disable = FALSE;
43         options->file_filter.show_dot_directory = FALSE;
44         options->file_filter.show_hidden_files = FALSE;
45         options->file_filter.show_parent_directory = TRUE;
46
47         options->save_window_positions = TRUE;
48         options->tools_restore_state = TRUE;
49
50         options->file_ops.confirm_delete = TRUE;
51         options->file_ops.enable_delete_key = TRUE;
52         options->file_ops.enable_in_place_rename = TRUE;
53         options->file_ops.safe_delete_enable = FALSE;
54         options->file_ops.safe_delete_folder_maxsize = 128;
55         options->file_ops.safe_delete_path = NULL;
56
57         options->file_sort.ascending = TRUE;
58         options->file_sort.case_sensitive = FALSE;
59         options->file_sort.method = SORT_NAME;
60
61         options->fullscreen.above = FALSE;
62         options->fullscreen.clean_flip = FALSE;
63         options->fullscreen.disable_saver = TRUE;
64         options->fullscreen.screen = -1;
65
66         memset(&options->image.border_color, 0, sizeof(options->image.border_color));
67         options->image.enable_read_ahead = TRUE;
68         options->image.exif_rotate_enable = TRUE;
69         options->image.exif_proof_rotate_enable = TRUE;
70         options->image.fit_window_to_image = FALSE;
71         options->image.limit_autofit_size = FALSE;
72         options->image.limit_window_size = TRUE;
73         options->image.max_autofit_size = 100;
74         options->image.max_window_size = 90;
75         options->image.scroll_reset_method = SCROLL_RESET_NOCHANGE;
76         options->image.tile_cache_max = 10;
77         options->image.image_cache_max = 128; /* 4 x 10MPix */
78         options->image.use_custom_border_color = FALSE;
79         options->image.use_custom_border_color_in_fullscreen = TRUE;
80         options->image.zoom_2pass = TRUE;
81         options->image.zoom_increment = 5;
82         options->image.zoom_mode = ZOOM_RESET_NONE;
83         options->image.zoom_quality = GDK_INTERP_BILINEAR;
84         options->image.zoom_to_fit_allow_expand = FALSE;
85
86         options->image_overlay.template_string = NULL;
87         options->image_overlay.x = 10;
88         options->image_overlay.y = -10;
89
90         options->lazy_image_sync = FALSE;
91         options->mousewheel_scrolls = FALSE;
92         options->open_recent_list_maxsize = 10;
93         options->place_dialogs_under_mouse = FALSE;
94
95         options->progressive_key_scrolling = TRUE;
96
97         options->metadata.enable_metadata_dirs = FALSE;
98         options->metadata.save_in_image_file = FALSE;
99         options->metadata.save_legacy_IPTC = FALSE;
100         options->metadata.warn_on_write_problems = TRUE;
101         options->metadata.save_legacy_format = FALSE;
102         options->metadata.sync_grouped_files = TRUE;
103         options->metadata.confirm_write = TRUE;
104         options->metadata.confirm_after_timeout = FALSE;
105         options->metadata.confirm_timeout = 10;
106         options->metadata.confirm_on_image_change = FALSE;
107         options->metadata.confirm_on_dir_change = TRUE;
108         options->metadata.keywords_case_sensitive = FALSE;
109         options->metadata.write_orientation = TRUE;
110
111         options->show_icon_names = TRUE;
112
113         options->slideshow.delay = 50;
114         options->slideshow.random = FALSE;
115         options->slideshow.repeat = FALSE;
116
117         options->thumbnails.cache_into_dirs = FALSE;
118         options->thumbnails.enable_caching = TRUE;
119         options->thumbnails.max_height = DEFAULT_THUMB_HEIGHT;
120         options->thumbnails.max_width = DEFAULT_THUMB_WIDTH;
121         options->thumbnails.quality = GDK_INTERP_TILES;
122         options->thumbnails.spec_standard = TRUE;
123         options->thumbnails.use_xvpics = TRUE;
124         options->thumbnails.use_exif = FALSE;
125
126         options->tree_descend_subdirs = FALSE;
127         options->update_on_time_change = TRUE;
128
129         options->stereo.fixed_w = 1920;
130         options->stereo.fixed_h = 1080;
131         options->stereo.fixed_x1 = 0;
132         options->stereo.fixed_y1 = 0;
133         options->stereo.fixed_x2 = 0;
134         options->stereo.fixed_y2 = 1125;
135
136         return options;
137 }
138
139 void setup_default_options(ConfOptions *options)
140 {
141         gchar *path;
142         gint i;
143
144         bookmark_add_default(_("Home"), homedir());
145         path = g_build_filename(homedir(), "Desktop", NULL);
146         bookmark_add_default(_("Desktop"), path);
147         g_free(path);
148         bookmark_add_default(_("Collections"), get_collections_dir());
149
150         g_free(options->file_ops.safe_delete_path);
151         options->file_ops.safe_delete_path = g_strdup(get_trash_dir());
152
153         for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
154                 {
155                 options->color_profile.input_file[i] = NULL;
156                 options->color_profile.input_name[i] = NULL;
157                 }
158
159         set_default_image_overlay_template_string(&options->image_overlay.template_string);
160         options->sidecar.ext = g_strdup(".jpg;%raw;.ufraw;.xmp;%unknown");
161
162         options->shell.path = g_strdup(GQ_DEFAULT_SHELL_PATH);
163         options->shell.options = g_strdup(GQ_DEFAULT_SHELL_OPTIONS);
164 }
165
166 void copy_layout_options(LayoutOptions *dest, const LayoutOptions *src)
167 {
168         free_layout_options_content(dest);
169
170         *dest = *src;
171         dest->id = g_strdup(src->id);
172         dest->order = g_strdup(src->order);
173         dest->home_path = g_strdup(src->home_path);
174         dest->last_path = g_strdup(src->last_path);
175 }
176
177 void free_layout_options_content(LayoutOptions *dest)
178 {
179         g_free(dest->id);
180         g_free(dest->order);
181         g_free(dest->home_path);
182         g_free(dest->last_path);
183 }
184
185 LayoutOptions *init_layout_options(LayoutOptions *options)
186 {
187         memset(options, 0, sizeof(LayoutOptions));
188
189         options->dir_view_type = DIRVIEW_LIST;
190         options->file_view_type = FILEVIEW_LIST;
191         options->float_window.h = 450;
192         options->float_window.vdivider_pos = -1;
193         options->float_window.w = 260;
194         options->float_window.x = 0;
195         options->float_window.y = 0;
196         options->home_path = NULL;
197         options->main_window.h = 540;
198         options->main_window.hdivider_pos = -1;
199         options->main_window.maximized = FALSE;
200         options->main_window.vdivider_pos = 200;
201         options->main_window.w = 720;
202         options->main_window.x = 0;
203         options->main_window.y = 0;
204         options->order = g_strdup("123");
205         options->show_directory_date = FALSE;
206         options->show_marks = FALSE;
207         options->show_thumbnails = FALSE;
208         options->style = 0;
209         options->show_info_pixel = FALSE;
210         options->toolbar_hidden = FALSE;
211         options->tools_float = FALSE;
212         options->tools_hidden = FALSE;
213         options->image_overlay.histogram_channel = HCHAN_RGB;
214         options->image_overlay.histogram_mode = 1;
215         options->image_overlay.state = OSD_SHOW_NOTHING;
216         return options;
217 }
218
219 static void sync_options_with_current_state(ConfOptions *options)
220 {
221         LayoutWindow *lw = NULL;
222
223         if (layout_valid(&lw))
224                 {
225                 layout_sync_options_with_current_state(lw);
226                 layout_sort_get(lw, &options->file_sort.method, &options->file_sort.ascending);
227
228                 options->color_profile.enabled = layout_image_color_profile_get_use(lw);
229                 layout_image_color_profile_get(lw,
230                                                &options->color_profile.input_type,
231                                                &options->color_profile.use_image);
232                 }
233
234 }
235
236 void save_options(ConfOptions *options)
237 {
238         gchar *rc_path;
239
240         sync_options_with_current_state(options);
241
242         rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
243         save_config_to_file(rc_path, options);
244         g_free(rc_path);
245 }
246
247 gboolean load_options(ConfOptions *options)
248 {
249         gboolean success;
250         gchar *rc_path;
251
252         if (isdir(GQ_SYSTEM_WIDE_DIR))
253                 {
254                 rc_path = g_build_filename(GQ_SYSTEM_WIDE_DIR, RC_FILE_NAME, NULL);
255                 success = load_config_from_file(rc_path, TRUE);
256                 DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
257                 g_free(rc_path);
258                 }
259
260         rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
261         success = load_config_from_file(rc_path, TRUE);
262         DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
263         g_free(rc_path);
264         return(success);
265 }
266 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */