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