Update copyright in all files
[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
47         options->dnd_icon_size = 48;
48         options->duplicates_similarity_threshold = 99;
49         options->rot_invariant_sim = TRUE;
50
51         options->file_filter.disable = FALSE;
52         options->file_filter.show_dot_directory = FALSE;
53         options->file_filter.show_hidden_files = FALSE;
54         options->file_filter.show_parent_directory = TRUE;
55         options->file_filter.disable_file_extension_checks = FALSE;
56
57         options->save_window_positions = TRUE;
58         options->tools_restore_state = TRUE;
59
60         options->file_ops.confirm_delete = TRUE;
61         options->file_ops.enable_delete_key = TRUE;
62         options->file_ops.enable_in_place_rename = TRUE;
63         options->file_ops.safe_delete_enable = FALSE;
64         options->file_ops.safe_delete_folder_maxsize = 128;
65         options->file_ops.safe_delete_path = NULL;
66
67         options->file_sort.ascending = TRUE;
68         options->file_sort.case_sensitive = FALSE;
69         options->file_sort.method = SORT_NAME;
70
71         options->fullscreen.above = FALSE;
72         options->fullscreen.clean_flip = FALSE;
73         options->fullscreen.disable_saver = TRUE;
74         options->fullscreen.screen = -1;
75
76         memset(&options->image.border_color, 0, sizeof(options->image.border_color));
77         options->image.enable_read_ahead = TRUE;
78         options->image.exif_rotate_enable = TRUE;
79         options->image.exif_proof_rotate_enable = TRUE;
80         options->image.fit_window_to_image = FALSE;
81         options->image.limit_autofit_size = FALSE;
82         options->image.limit_window_size = TRUE;
83         options->image.max_autofit_size = 100;
84         options->image.max_window_size = 90;
85         options->image.scroll_reset_method = SCROLL_RESET_NOCHANGE;
86         options->image.tile_cache_max = 10;
87         options->image.image_cache_max = 128; /* 4 x 10MPix */
88         options->image.use_custom_border_color = FALSE;
89         options->image.use_custom_border_color_in_fullscreen = TRUE;
90         options->image.zoom_2pass = TRUE;
91         options->image.zoom_increment = 5;
92         options->image.zoom_mode = ZOOM_RESET_NONE;
93         options->image.zoom_quality = GDK_INTERP_BILINEAR;
94         options->image.zoom_to_fit_allow_expand = FALSE;
95
96         options->image_overlay.template_string = NULL;
97         options->image_overlay.x = 10;
98         options->image_overlay.y = -10;
99         options->image_overlay.font = NULL;
100         options->image_overlay.text_red = 0;
101         options->image_overlay.text_green = 0;
102         options->image_overlay.text_blue = 0;
103         options->image_overlay.text_alpha = 255;
104         options->image_overlay.background_red = 240;
105         options->image_overlay.background_green = 240;
106         options->image_overlay.background_blue = 240;
107         options->image_overlay.background_alpha = 210;
108
109         options->lazy_image_sync = FALSE;
110         options->mousewheel_scrolls = FALSE;
111         options->open_recent_list_maxsize = 10;
112         options->place_dialogs_under_mouse = FALSE;
113
114         options->progressive_key_scrolling = TRUE;
115
116         options->metadata.enable_metadata_dirs = FALSE;
117         options->metadata.save_in_image_file = FALSE;
118         options->metadata.save_legacy_IPTC = FALSE;
119         options->metadata.warn_on_write_problems = TRUE;
120         options->metadata.save_legacy_format = FALSE;
121         options->metadata.sync_grouped_files = TRUE;
122         options->metadata.confirm_write = TRUE;
123         options->metadata.confirm_after_timeout = FALSE;
124         options->metadata.confirm_timeout = 10;
125         options->metadata.confirm_on_image_change = FALSE;
126         options->metadata.confirm_on_dir_change = TRUE;
127         options->metadata.keywords_case_sensitive = FALSE;
128         options->metadata.write_orientation = TRUE;
129
130         options->show_icon_names = TRUE;
131
132         options->slideshow.delay = 50;
133         options->slideshow.random = FALSE;
134         options->slideshow.repeat = FALSE;
135
136         options->thumbnails.cache_into_dirs = FALSE;
137         options->thumbnails.enable_caching = TRUE;
138         options->thumbnails.max_height = DEFAULT_THUMB_HEIGHT;
139         options->thumbnails.max_width = DEFAULT_THUMB_WIDTH;
140         options->thumbnails.quality = GDK_INTERP_TILES;
141         options->thumbnails.spec_standard = TRUE;
142         options->thumbnails.use_xvpics = TRUE;
143         options->thumbnails.use_exif = FALSE;
144
145         options->tree_descend_subdirs = FALSE;
146         options->update_on_time_change = TRUE;
147
148         options->stereo.fixed_w = 1920;
149         options->stereo.fixed_h = 1080;
150         options->stereo.fixed_x1 = 0;
151         options->stereo.fixed_y1 = 0;
152         options->stereo.fixed_x2 = 0;
153         options->stereo.fixed_y2 = 1125;
154
155         return options;
156 }
157
158 void setup_default_options(ConfOptions *options)
159 {
160         gchar *path;
161         gint i;
162
163         bookmark_add_default(".", get_current_dir());
164         bookmark_add_default(_("Home"), homedir());
165         path = g_build_filename(homedir(), "Desktop", NULL);
166         bookmark_add_default(_("Desktop"), path);
167         g_free(path);
168         bookmark_add_default(_("Collections"), get_collections_dir());
169
170         g_free(options->file_ops.safe_delete_path);
171         options->file_ops.safe_delete_path = g_strdup(get_trash_dir());
172
173         for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
174                 {
175                 options->color_profile.input_file[i] = NULL;
176                 options->color_profile.input_name[i] = NULL;
177                 }
178
179         set_default_image_overlay_template_string(&options->image_overlay.template_string);
180         options->sidecar.ext = g_strdup(".jpg;%raw;.ufraw;.xmp;%unknown");
181
182         options->shell.path = g_strdup(GQ_DEFAULT_SHELL_PATH);
183         options->shell.options = g_strdup(GQ_DEFAULT_SHELL_OPTIONS);
184 }
185
186 void copy_layout_options(LayoutOptions *dest, const LayoutOptions *src)
187 {
188         free_layout_options_content(dest);
189
190         *dest = *src;
191         dest->id = g_strdup(src->id);
192         dest->order = g_strdup(src->order);
193         dest->home_path = g_strdup(src->home_path);
194         dest->last_path = g_strdup(src->last_path);
195 }
196
197 void free_layout_options_content(LayoutOptions *dest)
198 {
199         g_free(dest->id);
200         g_free(dest->order);
201         g_free(dest->home_path);
202         g_free(dest->last_path);
203 }
204
205 LayoutOptions *init_layout_options(LayoutOptions *options)
206 {
207         memset(options, 0, sizeof(LayoutOptions));
208
209         options->dir_view_type = DIRVIEW_LIST;
210         options->file_view_type = FILEVIEW_LIST;
211         options->float_window.h = 450;
212         options->float_window.vdivider_pos = -1;
213         options->float_window.w = 260;
214         options->float_window.x = 0;
215         options->float_window.y = 0;
216         options->home_path = NULL;
217         options->main_window.h = 540;
218         options->main_window.hdivider_pos = -1;
219         options->main_window.maximized = FALSE;
220         options->main_window.vdivider_pos = 200;
221         options->main_window.w = 720;
222         options->main_window.x = 0;
223         options->main_window.y = 0;
224         options->order = g_strdup("123");
225         options->show_directory_date = FALSE;
226         options->show_marks = FALSE;
227         options->show_thumbnails = FALSE;
228         options->style = 0;
229         options->show_info_pixel = FALSE;
230         options->toolbar_hidden = FALSE;
231         options->tools_float = FALSE;
232         options->tools_hidden = FALSE;
233         options->image_overlay.histogram_channel = HCHAN_RGB;
234         options->image_overlay.histogram_mode = 1;
235         options->image_overlay.state = OSD_SHOW_NOTHING;
236         return options;
237 }
238
239 static void sync_options_with_current_state(ConfOptions *options)
240 {
241         LayoutWindow *lw = NULL;
242
243         if (layout_valid(&lw))
244                 {
245                 layout_sync_options_with_current_state(lw);
246                 layout_sort_get(lw, &options->file_sort.method, &options->file_sort.ascending);
247
248                 options->color_profile.enabled = layout_image_color_profile_get_use(lw);
249                 layout_image_color_profile_get(lw,
250                                                &options->color_profile.input_type,
251                                                &options->color_profile.use_image);
252                 }
253
254 }
255
256 void save_options(ConfOptions *options)
257 {
258         gchar *rc_path;
259
260         sync_options_with_current_state(options);
261
262         rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
263         save_config_to_file(rc_path, options);
264         g_free(rc_path);
265 }
266
267 gboolean load_options(ConfOptions *options)
268 {
269         gboolean success;
270         gchar *rc_path;
271
272         if (isdir(GQ_SYSTEM_WIDE_DIR))
273                 {
274                 rc_path = g_build_filename(GQ_SYSTEM_WIDE_DIR, RC_FILE_NAME, NULL);
275                 success = load_config_from_file(rc_path, TRUE);
276                 DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
277                 g_free(rc_path);
278                 }
279
280         rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
281         success = load_config_from_file(rc_path, TRUE);
282         DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
283         g_free(rc_path);
284         return(success);
285 }
286 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */