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