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