fixed overlay configuration
[geeqie.git] / src / options.c
1 /*
2  * Geeqie
3  * Copyright (C) 2008 - 2009 The Geeqie Team
4  *
5  * Authors: Vladimir Nadvornik, Laurent Monin
6  *
7  * This software is released under the GNU General Public License (GNU GPL).
8  * Please read the included file COPYING for more information.
9  * This software comes with no warranty of any kind, use at your own risk!
10  */
11
12 #include "main.h"
13 #include "options.h"
14
15 #include "bar_exif.h"
16 #include "editors.h"
17 #include "filefilter.h"
18 #include "histogram.h" /* HCHAN_RGB */
19 #include "image-overlay.h" /* OSD_SHOW_NOTHING */
20 #include "layout.h"
21 #include "layout_image.h"
22 #include "rcfile.h"
23 #include "ui_bookmark.h"
24 #include "ui_fileops.h"
25 #include "window.h"
26
27 ConfOptions *init_options(ConfOptions *options)
28 {
29         if (!options) options = g_new0(ConfOptions, 1);
30
31         options->collections.rectangular_selection = FALSE;
32
33         options->color_profile.enabled = TRUE;
34         options->color_profile.input_type = 0;
35         options->color_profile.screen_file = NULL;
36         options->color_profile.screen_type = 0;
37         options->color_profile.use_image = TRUE;
38
39         options->dnd_icon_size = 48;
40         options->duplicates_similarity_threshold = 99;
41         
42         options->file_filter.disable = FALSE;
43         options->file_filter.show_dot_directory = FALSE;
44         options->file_filter.show_hidden_files = FALSE;
45
46         options->file_ops.confirm_delete = TRUE;
47         options->file_ops.enable_delete_key = TRUE;
48         options->file_ops.enable_in_place_rename = TRUE;
49         options->file_ops.safe_delete_enable = FALSE;
50         options->file_ops.safe_delete_folder_maxsize = 128;
51         options->file_ops.safe_delete_path = NULL;
52
53         options->file_sort.ascending = TRUE;
54         options->file_sort.case_sensitive = FALSE;
55         options->file_sort.method = SORT_NAME;
56
57         options->fullscreen.above = FALSE;
58         options->fullscreen.clean_flip = FALSE;
59         options->fullscreen.disable_saver = TRUE;
60         options->fullscreen.screen = -1;
61
62         memset(&options->image.border_color, 0, sizeof(options->image.border_color));
63         options->image.dither_quality = GDK_RGB_DITHER_NORMAL;
64         options->image.enable_read_ahead = TRUE;
65         options->image.exif_rotate_enable = TRUE;
66         options->image.fit_window_to_image = FALSE;
67         options->image.idle_read_loop_count = IMAGE_LOADER_IDLE_READ_LOOP_COUNT_DEFAULT;
68         options->image.limit_autofit_size = FALSE;
69         options->image.limit_window_size = TRUE;
70         options->image.max_autofit_size = 100;
71         options->image.max_window_size = 90;
72         options->image.read_buffer_size = IMAGE_LOADER_READ_BUFFER_SIZE_DEFAULT;
73         options->image.scroll_reset_method = SCROLL_RESET_NOCHANGE;
74         options->image.tile_cache_max = 10;
75         options->image.image_cache_max = 128; /* 4 x 10MPix */
76         options->image.use_custom_border_color = FALSE;
77         options->image.zoom_2pass = TRUE;
78         options->image.zoom_increment = 5;
79         options->image.zoom_mode = ZOOM_RESET_NONE;
80         options->image.zoom_quality = GDK_INTERP_BILINEAR;
81         options->image.zoom_to_fit_allow_expand = FALSE;
82
83         options->image_overlay.template_string = NULL;
84         options->image_overlay.x = 10;
85         options->image_overlay.y = -10;
86
87         options->layout.dir_view_type = DIRVIEW_LIST;
88         options->layout.file_view_type = FILEVIEW_LIST;
89         options->layout.float_window.h = 450;
90         options->layout.float_window.vdivider_pos = -1;
91         options->layout.float_window.w = 260;
92         options->layout.float_window.x = 0;
93         options->layout.float_window.y = 0;
94         options->layout.home_path = NULL;
95         options->layout.main_window.h = 540;
96         options->layout.main_window.hdivider_pos = -1;
97         options->layout.main_window.maximized = FALSE;
98         options->layout.main_window.vdivider_pos = 200;
99         options->layout.main_window.w = 720;
100         options->layout.main_window.x = 0;
101         options->layout.main_window.y = 0;
102         options->layout.order = NULL;
103         options->layout.save_window_positions = TRUE;
104         options->layout.show_directory_date = FALSE;
105         options->layout.show_marks = FALSE;
106         options->layout.show_thumbnails = FALSE;
107         options->layout.style = 0;
108         options->layout.toolbar_hidden = FALSE;
109         options->layout.tools_float = FALSE;
110         options->layout.tools_hidden = FALSE;
111         options->layout.tools_restore_state = TRUE;
112         options->layout.image_overlay.histogram_channel = HCHAN_RGB;
113         options->layout.image_overlay.histogram_mode = 1;
114         options->layout.image_overlay.state = OSD_SHOW_NOTHING;
115         
116         options->lazy_image_sync = FALSE;
117         options->mousewheel_scrolls = FALSE;
118         options->open_recent_list_maxsize = 10;
119         options->place_dialogs_under_mouse = FALSE;
120
121         options->progressive_key_scrolling = TRUE;
122         
123         options->metadata.enable_metadata_dirs = FALSE;
124         options->metadata.save_in_image_file = FALSE;
125         options->metadata.save_legacy_IPTC = FALSE;
126         options->metadata.warn_on_write_problems = TRUE;
127         options->metadata.save_legacy_format = FALSE;
128         options->metadata.sync_grouped_files = TRUE;
129         options->metadata.confirm_write = TRUE;
130         options->metadata.confirm_after_timeout = FALSE;
131         options->metadata.confirm_timeout = 10;
132         options->metadata.confirm_on_image_change = FALSE;
133         options->metadata.confirm_on_dir_change = TRUE;
134         
135         options->show_copy_path = TRUE;
136         options->show_icon_names = TRUE;
137
138         options->slideshow.delay = 50;
139         options->slideshow.random = FALSE;
140         options->slideshow.repeat = FALSE;
141
142         options->startup.path = NULL;
143         options->startup.restore_path = FALSE;
144         options->startup.use_last_path = FALSE;
145
146         options->thumbnails.cache_into_dirs = FALSE;
147         options->thumbnails.enable_caching = TRUE;
148         options->thumbnails.fast = TRUE;
149         options->thumbnails.max_height = DEFAULT_THUMB_HEIGHT;
150         options->thumbnails.max_width = DEFAULT_THUMB_WIDTH;
151         options->thumbnails.quality = GDK_INTERP_TILES;
152         options->thumbnails.spec_standard = TRUE;
153         options->thumbnails.use_xvpics = TRUE;
154         options->thumbnails.use_exif = FALSE;
155
156         options->tree_descend_subdirs = FALSE;
157         options->update_on_time_change = TRUE;
158
159         return options;
160 }
161
162 void setup_default_options(ConfOptions *options)
163 {
164         gchar *path;
165         gint i;
166
167         bookmark_add_default(_("Home"), homedir());
168         path = g_build_filename(homedir(), "Desktop", NULL);
169         bookmark_add_default(_("Desktop"), path);
170         g_free(path);
171         bookmark_add_default(_("Collections"), get_collections_dir());
172
173         g_free(options->file_ops.safe_delete_path);
174         options->file_ops.safe_delete_path = g_strdup(get_trash_dir());
175
176         for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
177                 {
178                 options->color_profile.input_file[i] = NULL;
179                 options->color_profile.input_name[i] = NULL;
180                 }
181
182         set_default_image_overlay_template_string(&options->image_overlay.template_string);
183         options->sidecar.ext = g_strdup(".jpg;%raw;.xmp");
184         options->layout.order = g_strdup("123");
185
186         options->shell.path = g_strdup(GQ_DEFAULT_SHELL_PATH);
187         options->shell.options = g_strdup(GQ_DEFAULT_SHELL_OPTIONS);
188         
189         for (i = 0; ExifUIList[i].key; i++)
190                 ExifUIList[i].current = ExifUIList[i].default_value;
191 }
192
193 void copy_layout_options(LayoutOptions *dest, const LayoutOptions *src)
194 {
195         free_layout_options_content(dest);
196         
197         *dest = *src;
198         dest->order = g_strdup(src->order);
199         dest->home_path = g_strdup(src->home_path);
200 }
201
202 void free_layout_options_content(LayoutOptions *dest)
203 {
204         if (dest->order) g_free(dest->order);
205         if (dest->home_path) g_free(dest->home_path);
206 }
207
208 static void sync_options_with_current_state(ConfOptions *options)
209 {
210         LayoutWindow *lw = NULL;
211
212         if (layout_valid(&lw))
213                 {
214                 layout_sync_options_with_current_state(lw);
215                 copy_layout_options(&options->layout, &lw->options);
216                 layout_sort_get(lw, &options->file_sort.method, &options->file_sort.ascending);
217
218         
219
220                 options->color_profile.enabled = layout_image_color_profile_get_use(lw);
221                 layout_image_color_profile_get(lw,
222                                                &options->color_profile.input_type,
223                                                &options->color_profile.screen_type,
224                                                &options->color_profile.use_image);
225
226                 if (options->startup.restore_path && options->startup.use_last_path)
227                         {
228                         g_free(options->startup.path);
229                         options->startup.path = g_strdup(layout_get_path(lw));
230                         }
231                 }
232
233 }
234
235 void save_options(ConfOptions *options)
236 {
237         gchar *rc_path;
238
239         sync_options_with_current_state(options);
240
241         rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
242         save_options_to(rc_path, options);
243         g_free(rc_path);
244 }
245
246 gboolean load_options(ConfOptions *options)
247 {
248         gboolean success;
249         gchar *rc_path;
250
251         if (isdir(GQ_SYSTEM_WIDE_DIR))
252                 {
253                 rc_path = g_build_filename(GQ_SYSTEM_WIDE_DIR, RC_FILE_NAME, NULL);
254                 success = load_options_from(rc_path, options, TRUE);
255                 DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
256                 g_free(rc_path);
257                 }
258         
259         rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
260         success = load_options_from(rc_path, options, TRUE);
261         DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
262         g_free(rc_path);
263         return(success);
264 }
265 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */