clang-tidy: misc-redundant-expression
[geeqie.git] / src / options.cc
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 "histogram.h" /* HCHAN_RGB */
24 #include "image-overlay.h" /* OSD_SHOW_NOTHING */
25 #include "layout.h"
26 #include "layout-image.h"
27 #include "misc.h"
28 #include "rcfile.h"
29 #include "ui-bookmark.h"
30 #include "ui-fileops.h"
31
32 ConfOptions *options;
33 CommandLine *command_line;
34
35 ConfOptions *init_options(ConfOptions *options)
36 {
37         gint i;
38
39         if (!options) options = g_new0(ConfOptions, 1);
40
41         options->collections.rectangular_selection = FALSE;
42
43         options->color_profile.enabled = TRUE;
44         options->color_profile.input_type = 0;
45         options->color_profile.screen_file = nullptr;
46         options->color_profile.use_image = TRUE;
47         options->color_profile.use_x11_screen_profile = TRUE;
48         options->color_profile.render_intent = 0;
49
50         options->dnd_icon_size = 48;
51         options->dnd_default_action = DND_ACTION_ASK;
52         options->duplicates_similarity_threshold = 99;
53         options->rot_invariant_sim = TRUE;
54         options->sort_totals = FALSE;
55
56         options->file_filter.disable = FALSE;
57         options->file_filter.show_dot_directory = FALSE;
58         options->file_filter.show_hidden_files = FALSE;
59         options->file_filter.show_parent_directory = TRUE;
60         options->file_filter.disable_file_extension_checks = FALSE;
61
62         options->save_window_positions = TRUE;
63         options->use_saved_window_positions_for_new_windows = FALSE;
64         options->save_window_workspace = FALSE;
65         options->tools_restore_state = TRUE;
66         options->save_dialog_window_positions = FALSE;
67         options->show_window_ids = FALSE;
68
69         options->file_ops.confirm_delete = TRUE;
70         options->file_ops.confirm_move_to_trash = TRUE;
71         options->file_ops.enable_delete_key = TRUE;
72         options->file_ops.use_system_trash = TRUE;
73         options->file_ops.enable_in_place_rename = TRUE;
74         options->file_ops.safe_delete_enable = TRUE;
75         options->file_ops.safe_delete_folder_maxsize = 128;
76         options->file_ops.safe_delete_path = nullptr;
77         options->file_ops.no_trash = FALSE;
78
79         options->file_sort.case_sensitive = FALSE;
80
81         options->fullscreen.above = FALSE;
82         options->fullscreen.clean_flip = FALSE;
83         options->fullscreen.disable_saver = TRUE;
84         options->fullscreen.screen = -1;
85
86         options->appimage_notifications = TRUE;
87         options->marks_save = TRUE;
88         options->with_rename = FALSE;
89         options->collections_duplicates = FALSE;
90         options->collections_on_top = FALSE;
91         options->hide_window_in_fullscreen = TRUE;
92
93         memset(&options->image.border_color, 0, sizeof(options->image.border_color));
94         memset(&options->image.alpha_color_1, 0, sizeof(options->image.alpha_color_1));
95         memset(&options->image.alpha_color_2, 0, sizeof(options->image.alpha_color_2));
96         options->image.border_color.red = static_cast<gdouble>(0x009999) / 65535;
97         options->image.border_color.green = static_cast<gdouble>(0x009999) / 65535;
98         options->image.border_color.blue = static_cast<gdouble>(0x009999) / 65535;
99 /* alpha channel checkerboard background (same as gimp) */
100         options->image.alpha_color_1.red = static_cast<gdouble>(0x009999) / 65535;
101         options->image.alpha_color_1.green = static_cast<gdouble>(0x009999) / 65535;
102         options->image.alpha_color_1.blue = static_cast<gdouble>(0x009999) / 65535;
103         options->image.alpha_color_2.red = static_cast<gdouble>(0x006666) / 65535;
104         options->image.alpha_color_2.green = static_cast<gdouble>(0x006666) / 65535;
105         options->image.alpha_color_2.blue = static_cast<gdouble>(0x006666) / 65535;
106         options->image.enable_read_ahead = TRUE;
107         options->image.exif_rotate_enable = TRUE;
108         options->image.fit_window_to_image = FALSE;
109         options->image.limit_autofit_size = FALSE;
110         options->image.limit_window_size = TRUE;
111         options->image.max_autofit_size = 100;
112         options->image.max_enlargement_size = 900;
113         options->image.max_window_size = 90;
114         options->image.scroll_reset_method = SCROLL_RESET_NOCHANGE;
115         options->image.tile_cache_max = 10;
116         options->image.image_cache_max = 128; /* 4 x 10MPix */
117         options->image.use_custom_border_color = FALSE;
118         options->image.use_custom_border_color_in_fullscreen = TRUE;
119         options->image.zoom_2pass = TRUE;
120         options->image.zoom_increment = 5;
121         options->image.zoom_mode = ZOOM_RESET_NONE;
122         options->image.zoom_quality = GDK_INTERP_BILINEAR;
123         options->image.zoom_to_fit_allow_expand = FALSE;
124         options->image.zoom_style = ZOOM_GEOMETRIC;
125         options->image.tile_size = 128;
126
127         options->image_overlay.template_string = nullptr;
128         options->image_overlay.x = 10;
129         options->image_overlay.y = -10;
130         options->image_overlay.font = g_strdup("Sans 10");
131         options->image_overlay.text_red = 0;
132         options->image_overlay.text_green = 0;
133         options->image_overlay.text_blue = 0;
134         options->image_overlay.text_alpha = 255;
135         options->image_overlay.background_red = 240;
136         options->image_overlay.background_green = 240;
137         options->image_overlay.background_blue = 240;
138         options->image_overlay.background_alpha = 210;
139
140         options->lazy_image_sync = FALSE;
141         options->mousewheel_scrolls = FALSE;
142         options->image_lm_click_nav = TRUE;
143         options->image_l_click_archive = FALSE;
144         options->image_l_click_video = TRUE;
145         options->image_l_click_video_editor = g_strdup("video-player.desktop");
146         options->open_recent_list_maxsize = 10;
147         options->recent_folder_image_list_maxsize = 10;
148         options->place_dialogs_under_mouse = FALSE;
149
150         options->progressive_key_scrolling = TRUE;
151         options->keyboard_scroll_step = 1;
152
153         options->metadata.enable_metadata_dirs = FALSE;
154         options->metadata.save_in_image_file = FALSE;
155         options->metadata.save_legacy_IPTC = FALSE;
156         options->metadata.warn_on_write_problems = TRUE;
157         options->metadata.save_legacy_format = FALSE;
158         options->metadata.sync_grouped_files = TRUE;
159         options->metadata.confirm_write = TRUE;
160         options->metadata.confirm_after_timeout = FALSE;
161         options->metadata.confirm_timeout = 10;
162         options->metadata.confirm_on_image_change = FALSE;
163         options->metadata.confirm_on_dir_change = TRUE;
164         options->metadata.keywords_case_sensitive = FALSE;
165         options->metadata.write_orientation = TRUE;
166         options->metadata.sidecar_extended_name = FALSE;
167         options->metadata.check_spelling = TRUE;
168
169         options->show_icon_names = TRUE;
170         options->show_star_rating = FALSE;
171         options->show_predefined_keyword_tree = TRUE;
172         options->expand_menu_toolbar = FALSE;
173         options->hamburger_menu = FALSE;
174
175         options->slideshow.delay = 50;
176         options->slideshow.random = FALSE;
177         options->slideshow.repeat = FALSE;
178
179         options->thumbnails.cache_into_dirs = FALSE;
180         options->thumbnails.enable_caching = TRUE;
181         options->thumbnails.max_height = DEFAULT_THUMB_HEIGHT;
182         options->thumbnails.max_width = DEFAULT_THUMB_WIDTH;
183         options->thumbnails.quality = GDK_INTERP_TILES;
184         options->thumbnails.spec_standard = TRUE;
185         options->thumbnails.use_xvpics = TRUE;
186         options->thumbnails.use_exif = FALSE;
187         options->thumbnails.use_color_management = FALSE;
188         options->thumbnails.use_ft_metadata = TRUE;
189         options->thumbnails.collection_preview = 20;
190
191         options->tree_descend_subdirs = FALSE;
192         options->view_dir_list_single_click_enter = TRUE;
193         options->circular_selection_lists = TRUE;
194         options->update_on_time_change = TRUE;
195         options->clipboard_selection = CLIPBOARD_BOTH;
196
197         options->stereo.fixed_w = 1920;
198         options->stereo.fixed_h = 1080;
199         options->stereo.fixed_x1 = 0;
200         options->stereo.fixed_y1 = 0;
201         options->stereo.fixed_x2 = 0;
202         options->stereo.fixed_y2 = 1125;
203
204         options->log_window_lines = 1000;
205         options->log_window.line_wrap = FALSE;
206         options->log_window.paused = FALSE;
207         options->log_window.timer_data = FALSE;
208         options->log_window.action = g_strdup("echo");
209
210         options->read_metadata_in_idle = FALSE;
211         options->star_rating.star = STAR_RATING_STAR;
212         options->star_rating.rejected = STAR_RATING_REJECTED;
213
214         options->printer.template_string = nullptr;
215         options->printer.image_font = g_strdup("Serif 10");
216         options->printer.page_font = g_strdup("Serif 10");
217         options->printer.page_text = nullptr;
218         options->printer.image_text_position = 1;
219         options->printer.page_text_position = 3;
220
221         options->threads.duplicates = get_cpu_cores() - 1;
222
223         options->disabled_plugins = nullptr;
224
225         options->mouse_button_8 = g_strdup("Back");
226         options->mouse_button_9 = g_strdup("Forward");
227
228         options->disable_gpu = FALSE;
229         options->override_disable_gpu = FALSE;
230
231         for (i = 0; i < FILE_FORMAT_CLASSES; i++)
232                 {
233                 options->class_filter[i] = TRUE;
234                 }
235         return options;
236 }
237
238 void setup_default_options(ConfOptions *options)
239 {
240         gchar *path;
241         gint i;
242
243         bookmark_add_default(".", get_current_dir());
244         bookmark_add_default(_("Home"), homedir());
245         path = g_build_filename(homedir(), "Desktop", NULL);
246         bookmark_add_default(_("Desktop"), path);
247         g_free(path);
248         bookmark_add_default(_("Collections"), get_collections_dir());
249
250         g_free(options->file_ops.safe_delete_path);
251         options->file_ops.safe_delete_path = g_strdup(get_trash_dir());
252
253         for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
254                 {
255                 options->color_profile.input_file[i] = nullptr;
256                 options->color_profile.input_name[i] = nullptr;
257                 }
258
259         set_default_image_overlay_template_string(&options->image_overlay.template_string);
260         options->sidecar.ext = g_strdup(".jpg;%raw;.gqv;.xmp;%unknown");
261
262         options->shell.path = g_strdup(GQ_DEFAULT_SHELL_PATH);
263         options->shell.options = g_strdup(GQ_DEFAULT_SHELL_OPTIONS);
264
265         for (i = 0; i < FILEDATA_MARKS_SIZE; i++)
266                 {
267                 options->marks_tooltips[i] = g_strdup_printf("%s%d", _("Mark "), i + 1);
268                 }
269
270         options->help_search_engine = g_strdup(HELP_SEARCH_ENGINE);
271 }
272
273 void copy_layout_options(LayoutOptions *dest, const LayoutOptions *src)
274 {
275         free_layout_options_content(dest);
276
277         *dest = *src;
278         dest->id = g_strdup(src->id);
279         dest->order = g_strdup(src->order);
280         dest->home_path = g_strdup(src->home_path);
281         dest->last_path = g_strdup(src->last_path);
282 }
283
284 void free_layout_options_content(LayoutOptions *dest)
285 {
286         g_free(dest->id);
287         g_free(dest->order);
288         g_free(dest->home_path);
289         g_free(dest->last_path);
290 }
291
292 LayoutOptions *init_layout_options(LayoutOptions *options)
293 {
294         memset(options, 0, sizeof(LayoutOptions));
295
296         options->dir_view_type = DIRVIEW_LIST;
297         options->dir_view_list_sort.ascend = TRUE;
298         options->dir_view_list_sort.case_sensitive = TRUE;
299         options->dir_view_list_sort.method = SORT_NAME;
300         options->file_view_list_sort.ascend = TRUE;
301         options->file_view_list_sort.case_sensitive = TRUE;
302         options->file_view_list_sort.method = SORT_NAME;
303         options->file_view_type = FILEVIEW_LIST;
304         options->float_window.h = 450;
305         options->float_window.vdivider_pos = -1;
306         options->float_window.w = 260;
307         options->float_window.x = 0;
308         options->float_window.y = 0;
309         options->home_path = nullptr;
310         options->id = g_strdup("lw1");
311         options->main_window.h = 540;
312         options->main_window.hdivider_pos = -1;
313         options->main_window.maximized = FALSE;
314         options->main_window.vdivider_pos = 200;
315         options->main_window.w = 720;
316         options->main_window.x = 0;
317         options->main_window.y = 0;
318         options->dupe_window.w = 800;
319         options->dupe_window.h = 400;
320         options->dupe_window.x = 100;
321         options->dupe_window.y = 100;
322         options->search_window.w = 700;
323         options->search_window.h = 650;
324         options->search_window.x = 100;
325         options->search_window.y = 100;
326         options->advanced_exif_window.w = 900;
327         options->advanced_exif_window.h = 600;
328         options->advanced_exif_window.x = 0;
329         options->advanced_exif_window.y = 0;
330         options->folder_window.vdivider_pos = 100;
331         options->order = g_strdup("123");
332         options->show_directory_date = FALSE;
333         options->show_marks = FALSE;
334         options->show_file_filter = FALSE;
335         options->show_thumbnails = FALSE;
336         options->style = 0;
337         options->show_info_pixel = FALSE;
338         options->selectable_toolbars_hidden = FALSE;
339         options->tools_float = FALSE;
340         options->tools_hidden = FALSE;
341         options->image_overlay.histogram_channel = HCHAN_RGB;
342         options->image_overlay.histogram_mode = 1;
343         options->image_overlay.state = OSD_SHOW_NOTHING;
344         options->animate = TRUE;
345         options->bars_state.hidden = FALSE;
346         options->log_window.width = 520;
347         options->log_window.height = 400;
348         options->preferences_window.w = 700;
349         options->preferences_window.h = 600;
350         options->split_pane_sync = FALSE;
351         options->workspace = -1;
352         return options;
353 }
354
355 static void sync_options_with_current_state(ConfOptions *options)
356 {
357         LayoutWindow *lw = nullptr;
358
359         if (layout_valid(&lw))
360                 {
361                 layout_sync_options_with_current_state(lw);
362
363                 options->color_profile.enabled = layout_image_color_profile_get_use(lw);
364                 layout_image_color_profile_get(lw,
365                                                &options->color_profile.input_type,
366                                                &options->color_profile.use_image);
367                 }
368
369 }
370
371 void save_options(ConfOptions *options)
372 {
373         gchar *rc_path;
374
375         sync_options_with_current_state(options);
376
377         rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
378         save_config_to_file(rc_path, options, nullptr);
379         g_free(rc_path);
380 }
381
382 gboolean load_options(ConfOptions *)
383 {
384         gboolean success;
385         gchar *rc_path;
386
387         if (isdir(GQ_SYSTEM_WIDE_DIR))
388                 {
389                 rc_path = g_build_filename(GQ_SYSTEM_WIDE_DIR, RC_FILE_NAME, NULL);
390                 success = load_config_from_file(rc_path, TRUE);
391                 DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
392                 g_free(rc_path);
393                 }
394
395         rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
396         success = load_config_from_file(rc_path, TRUE);
397         DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
398         g_free(rc_path);
399         return(success);
400 }
401 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */