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