34563485aa5a2caedb1acf2ff5e9d0a4955f73aa
[geeqie.git] / src / options.c
1 /*
2  * Copyright (C) 2008, 2016 The Geeqie Team -
3  *
4  * Authors: Vladimir Nadvornik, Laurent Monin
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
19
20 #include "main.h"
21 #include "options.h"
22
23 #include "bar_exif.h"
24 #include "editors.h"
25 #include "filefilter.h"
26 #include "histogram.h" /* HCHAN_RGB */
27 #include "image-overlay.h" /* OSD_SHOW_NOTHING */
28 #include "layout.h"
29 #include "layout_image.h"
30 #include "rcfile.h"
31 #include "ui_bookmark.h"
32 #include "ui_fileops.h"
33 #include "window.h"
34
35 ConfOptions *init_options(ConfOptions *options)
36 {
37         if (!options) options = g_new0(ConfOptions, 1);
38
39         options->collections.rectangular_selection = FALSE;
40
41         options->color_profile.enabled = TRUE;
42         options->color_profile.input_type = 0;
43         options->color_profile.screen_file = NULL;
44         options->color_profile.use_image = TRUE;
45         options->color_profile.use_x11_screen_profile = TRUE;
46         options->color_profile.render_intent = 0;
47
48         options->dnd_icon_size = 48;
49         options->duplicates_similarity_threshold = 99;
50         options->rot_invariant_sim = TRUE;
51
52         options->file_filter.disable = FALSE;
53         options->file_filter.show_dot_directory = FALSE;
54         options->file_filter.show_hidden_files = FALSE;
55         options->file_filter.show_parent_directory = TRUE;
56         options->file_filter.disable_file_extension_checks = FALSE;
57
58         options->save_window_positions = TRUE;
59         options->use_saved_window_positions_for_new_windows = FALSE;
60         options->tools_restore_state = TRUE;
61
62         options->file_ops.confirm_delete = TRUE;
63         options->file_ops.enable_delete_key = TRUE;
64         options->file_ops.enable_in_place_rename = TRUE;
65         options->file_ops.safe_delete_enable = FALSE;
66         options->file_ops.safe_delete_folder_maxsize = 128;
67         options->file_ops.safe_delete_path = NULL;
68
69         options->file_sort.ascending = TRUE;
70         options->file_sort.case_sensitive = FALSE;
71         options->file_sort.method = SORT_NAME;
72         options->file_sort.natural = FALSE;
73
74         options->fullscreen.above = FALSE;
75         options->fullscreen.clean_flip = FALSE;
76         options->fullscreen.disable_saver = TRUE;
77         options->fullscreen.screen = -1;
78
79         memset(&options->image.border_color, 0, sizeof(options->image.border_color));
80         memset(&options->image.alpha_color_1, 0, sizeof(options->image.alpha_color_1));
81         memset(&options->image.alpha_color_2, 0, sizeof(options->image.alpha_color_2));
82 /* alpha channel checkerboard background (same as gimp) */
83         options->image.alpha_color_1.red = 0x009999;
84         options->image.alpha_color_1.green = 0x009999;
85         options->image.alpha_color_1.blue = 0x009999;
86         options->image.alpha_color_2.red = 0x006666;
87         options->image.alpha_color_2.green = 0x006666;
88         options->image.alpha_color_2.blue = 0x006666;
89         options->image.enable_read_ahead = TRUE;
90         options->image.exif_rotate_enable = TRUE;
91         options->image.exif_proof_rotate_enable = TRUE;
92         options->image.fit_window_to_image = FALSE;
93         options->image.limit_autofit_size = FALSE;
94         options->image.limit_window_size = TRUE;
95         options->image.max_autofit_size = 100;
96         options->image.max_window_size = 90;
97         options->image.scroll_reset_method = SCROLL_RESET_NOCHANGE;
98         options->image.tile_cache_max = 10;
99         options->image.image_cache_max = 128; /* 4 x 10MPix */
100         options->image.use_custom_border_color = FALSE;
101         options->image.use_custom_border_color_in_fullscreen = TRUE;
102         options->image.zoom_2pass = TRUE;
103         options->image.zoom_increment = 5;
104         options->image.zoom_mode = ZOOM_RESET_NONE;
105         options->image.zoom_quality = GDK_INTERP_BILINEAR;
106         options->image.zoom_to_fit_allow_expand = FALSE;
107
108         options->image_overlay.template_string = NULL;
109         options->image_overlay.x = 10;
110         options->image_overlay.y = -10;
111         options->image_overlay.font = NULL;
112         options->image_overlay.text_red = 0;
113         options->image_overlay.text_green = 0;
114         options->image_overlay.text_blue = 0;
115         options->image_overlay.text_alpha = 255;
116         options->image_overlay.background_red = 240;
117         options->image_overlay.background_green = 240;
118         options->image_overlay.background_blue = 240;
119         options->image_overlay.background_alpha = 210;
120
121         options->lazy_image_sync = FALSE;
122         options->mousewheel_scrolls = FALSE;
123         options->image_lm_click_nav = TRUE;
124         options->open_recent_list_maxsize = 10;
125         options->place_dialogs_under_mouse = FALSE;
126
127         options->progressive_key_scrolling = TRUE;
128         options->keyboard_scroll_step = 1;
129
130         options->metadata.enable_metadata_dirs = FALSE;
131         options->metadata.save_in_image_file = FALSE;
132         options->metadata.save_legacy_IPTC = FALSE;
133         options->metadata.warn_on_write_problems = TRUE;
134         options->metadata.save_legacy_format = FALSE;
135         options->metadata.sync_grouped_files = TRUE;
136         options->metadata.confirm_write = TRUE;
137         options->metadata.confirm_after_timeout = FALSE;
138         options->metadata.confirm_timeout = 10;
139         options->metadata.confirm_on_image_change = FALSE;
140         options->metadata.confirm_on_dir_change = TRUE;
141         options->metadata.keywords_case_sensitive = FALSE;
142         options->metadata.write_orientation = TRUE;
143         options->metadata.sidecar_extended_name = FALSE;
144
145         options->show_icon_names = TRUE;
146
147         options->slideshow.delay = 50;
148         options->slideshow.random = FALSE;
149         options->slideshow.repeat = FALSE;
150
151         options->thumbnails.cache_into_dirs = FALSE;
152         options->thumbnails.enable_caching = TRUE;
153         options->thumbnails.max_height = DEFAULT_THUMB_HEIGHT;
154         options->thumbnails.max_width = DEFAULT_THUMB_WIDTH;
155         options->thumbnails.quality = GDK_INTERP_TILES;
156         options->thumbnails.spec_standard = TRUE;
157         options->thumbnails.use_xvpics = TRUE;
158         options->thumbnails.use_exif = FALSE;
159
160         options->tree_descend_subdirs = FALSE;
161         options->view_dir_list_single_click_enter = TRUE;
162         options->update_on_time_change = TRUE;
163
164         options->stereo.fixed_w = 1920;
165         options->stereo.fixed_h = 1080;
166         options->stereo.fixed_x1 = 0;
167         options->stereo.fixed_y1 = 0;
168         options->stereo.fixed_x2 = 0;
169         options->stereo.fixed_y2 = 1125;
170
171         return options;
172 }
173
174 void setup_default_options(ConfOptions *options)
175 {
176         gchar *path;
177         gint i;
178
179         bookmark_add_default(".", get_current_dir());
180         bookmark_add_default(_("Home"), homedir());
181         path = g_build_filename(homedir(), "Desktop", NULL);
182         bookmark_add_default(_("Desktop"), path);
183         g_free(path);
184         bookmark_add_default(_("Collections"), get_collections_dir());
185
186         g_free(options->file_ops.safe_delete_path);
187         options->file_ops.safe_delete_path = g_strdup(get_trash_dir());
188
189         for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
190                 {
191                 options->color_profile.input_file[i] = NULL;
192                 options->color_profile.input_name[i] = NULL;
193                 }
194
195         set_default_image_overlay_template_string(&options->image_overlay.template_string);
196         options->sidecar.ext = g_strdup(".jpg;%raw;.ufraw;.xmp;%unknown");
197
198         options->shell.path = g_strdup(GQ_DEFAULT_SHELL_PATH);
199         options->shell.options = g_strdup(GQ_DEFAULT_SHELL_OPTIONS);
200 }
201
202 void copy_layout_options(LayoutOptions *dest, const LayoutOptions *src)
203 {
204         free_layout_options_content(dest);
205
206         *dest = *src;
207         dest->id = g_strdup(src->id);
208         dest->order = g_strdup(src->order);
209         dest->home_path = g_strdup(src->home_path);
210         dest->last_path = g_strdup(src->last_path);
211 }
212
213 void free_layout_options_content(LayoutOptions *dest)
214 {
215         g_free(dest->id);
216         g_free(dest->order);
217         g_free(dest->home_path);
218         g_free(dest->last_path);
219 }
220
221 LayoutOptions *init_layout_options(LayoutOptions *options)
222 {
223         memset(options, 0, sizeof(LayoutOptions));
224
225         options->dir_view_type = DIRVIEW_LIST;
226         options->file_view_type = FILEVIEW_LIST;
227         options->float_window.h = 450;
228         options->float_window.vdivider_pos = -1;
229         options->float_window.w = 260;
230         options->float_window.x = 0;
231         options->float_window.y = 0;
232         options->home_path = NULL;
233         options->main_window.h = 540;
234         options->main_window.hdivider_pos = -1;
235         options->main_window.maximized = FALSE;
236         options->main_window.vdivider_pos = 200;
237         options->main_window.w = 720;
238         options->main_window.x = 0;
239         options->main_window.y = 0;
240         options->folder_window.vdivider_pos = 100;
241         options->order = g_strdup("123");
242         options->show_directory_date = FALSE;
243         options->show_marks = FALSE;
244         options->show_thumbnails = FALSE;
245         options->style = 0;
246         options->show_info_pixel = FALSE;
247         options->toolbar_hidden = FALSE;
248         options->tools_float = FALSE;
249         options->tools_hidden = FALSE;
250         options->image_overlay.histogram_channel = HCHAN_RGB;
251         options->image_overlay.histogram_mode = 1;
252         options->image_overlay.state = OSD_SHOW_NOTHING;
253         options->animate = FALSE;
254         return options;
255 }
256
257 static void sync_options_with_current_state(ConfOptions *options)
258 {
259         LayoutWindow *lw = NULL;
260
261         if (layout_valid(&lw))
262                 {
263                 layout_sync_options_with_current_state(lw);
264                 layout_sort_get(lw, &options->file_sort.method, &options->file_sort.ascending);
265
266                 options->color_profile.enabled = layout_image_color_profile_get_use(lw);
267                 layout_image_color_profile_get(lw,
268                                                &options->color_profile.input_type,
269                                                &options->color_profile.use_image);
270                 }
271
272 }
273
274 void save_options(ConfOptions *options)
275 {
276         gchar *rc_path;
277
278         sync_options_with_current_state(options);
279
280         rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
281         save_config_to_file(rc_path, options);
282         g_free(rc_path);
283 }
284
285 gboolean load_options(ConfOptions *options)
286 {
287         gboolean success;
288         gchar *rc_path;
289
290         if (isdir(GQ_SYSTEM_WIDE_DIR))
291                 {
292                 rc_path = g_build_filename(GQ_SYSTEM_WIDE_DIR, RC_FILE_NAME, NULL);
293                 success = load_config_from_file(rc_path, TRUE);
294                 DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
295                 g_free(rc_path);
296                 }
297
298         rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
299         success = load_config_from_file(rc_path, TRUE);
300         DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
301         g_free(rc_path);
302         return(success);
303 }
304 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */