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