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