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