simplified and improved bar 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         options->histogram.last_channel_mode = HCHAN_RGB;
63         options->histogram.last_log_mode = 1;
64         
65         memset(&options->image.border_color, 0, sizeof(options->image.border_color));
66         options->image.dither_quality = GDK_RGB_DITHER_NORMAL;
67         options->image.enable_read_ahead = TRUE;
68         options->image.exif_rotate_enable = TRUE;
69         options->image.fit_window_to_image = FALSE;
70         options->image.idle_read_loop_count = IMAGE_LOADER_IDLE_READ_LOOP_COUNT_DEFAULT;
71         options->image.limit_autofit_size = FALSE;
72         options->image.limit_window_size = TRUE;
73         options->image.max_autofit_size = 100;
74         options->image.max_window_size = 90;
75         options->image.read_buffer_size = IMAGE_LOADER_READ_BUFFER_SIZE_DEFAULT;
76         options->image.scroll_reset_method = SCROLL_RESET_NOCHANGE;
77         options->image.tile_cache_max = 10;
78         options->image.image_cache_max = 128; /* 4 x 10MPix */
79         options->image.use_custom_border_color = FALSE;
80         options->image.zoom_2pass = TRUE;
81         options->image.zoom_increment = 5;
82         options->image.zoom_mode = ZOOM_RESET_NONE;
83         options->image.zoom_quality = GDK_INTERP_BILINEAR;
84         options->image.zoom_to_fit_allow_expand = FALSE;
85
86         options->image_overlay.common.state = OSD_SHOW_NOTHING;
87         options->image_overlay.common.show_at_startup = FALSE;
88         options->image_overlay.common.template_string = NULL;
89         options->image_overlay.common.x = 10;
90         options->image_overlay.common.y = -10;
91
92         options->layout.dir_view_type = DIRVIEW_LIST;
93         options->layout.file_view_type = FILEVIEW_LIST;
94         options->layout.float_window.h = 450;
95         options->layout.float_window.vdivider_pos = -1;
96         options->layout.float_window.w = 260;
97         options->layout.float_window.x = 0;
98         options->layout.float_window.y = 0;
99         options->layout.home_path = NULL;
100         options->layout.main_window.h = 540;
101         options->layout.main_window.hdivider_pos = -1;
102         options->layout.main_window.maximized = FALSE;
103         options->layout.main_window.vdivider_pos = 200;
104         options->layout.main_window.w = 720;
105         options->layout.main_window.x = 0;
106         options->layout.main_window.y = 0;
107         options->layout.order = NULL;
108         options->layout.save_window_positions = TRUE;
109         options->layout.show_directory_date = FALSE;
110         options->layout.show_marks = FALSE;
111         options->layout.show_thumbnails = FALSE;
112         options->layout.style = 0;
113         options->layout.toolbar_hidden = FALSE;
114         options->layout.tools_float = FALSE;
115         options->layout.tools_hidden = FALSE;
116         options->layout.tools_restore_state = TRUE;
117
118         options->lazy_image_sync = FALSE;
119         options->mousewheel_scrolls = FALSE;
120         options->open_recent_list_maxsize = 10;
121         options->place_dialogs_under_mouse = FALSE;
122
123         options->layout.panels.sort.action_state = 0;
124         options->layout.panels.sort.enabled = FALSE;
125         options->layout.panels.sort.mode_state = 0;
126         options->layout.panels.sort.selection_state = 0;
127         options->layout.panels.sort.action_filter = NULL;
128         
129         options->progressive_key_scrolling = TRUE;
130         
131         options->metadata.enable_metadata_dirs = FALSE;
132         options->metadata.save_in_image_file = FALSE;
133         options->metadata.save_legacy_IPTC = FALSE;
134         options->metadata.warn_on_write_problems = TRUE;
135         options->metadata.save_legacy_format = FALSE;
136         options->metadata.sync_grouped_files = TRUE;
137         options->metadata.confirm_write = TRUE;
138         options->metadata.confirm_after_timeout = FALSE;
139         options->metadata.confirm_timeout = 10;
140         options->metadata.confirm_on_image_change = FALSE;
141         options->metadata.confirm_on_dir_change = TRUE;
142         
143         options->show_copy_path = TRUE;
144         options->show_icon_names = TRUE;
145
146         options->slideshow.delay = 50;
147         options->slideshow.random = FALSE;
148         options->slideshow.repeat = FALSE;
149
150         options->startup.path = NULL;
151         options->startup.restore_path = FALSE;
152         options->startup.use_last_path = FALSE;
153
154         options->thumbnails.cache_into_dirs = FALSE;
155         options->thumbnails.enable_caching = TRUE;
156         options->thumbnails.fast = 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->update_on_time_change = TRUE;
166
167         return options;
168 }
169
170 void setup_default_options(ConfOptions *options)
171 {
172         gchar *path;
173         gint i;
174
175         bookmark_add_default(_("Home"), homedir());
176         path = g_build_filename(homedir(), "Desktop", NULL);
177         bookmark_add_default(_("Desktop"), path);
178         g_free(path);
179         bookmark_add_default(_("Collections"), get_collections_dir());
180
181         g_free(options->file_ops.safe_delete_path);
182         options->file_ops.safe_delete_path = g_strdup(get_trash_dir());
183
184         for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
185                 {
186                 options->color_profile.input_file[i] = NULL;
187                 options->color_profile.input_name[i] = NULL;
188                 }
189
190         set_default_image_overlay_template_string(&options->image_overlay.common.template_string);
191         options->sidecar.ext = g_strdup(".jpg;%raw;.xmp");
192         options->layout.order = g_strdup("123");
193
194         options->shell.path = g_strdup(GQ_DEFAULT_SHELL_PATH);
195         options->shell.options = g_strdup(GQ_DEFAULT_SHELL_OPTIONS);
196         
197         for (i = 0; ExifUIList[i].key; i++)
198                 ExifUIList[i].current = ExifUIList[i].default_value;
199 }
200
201 void copy_layout_options(LayoutOptions *dest, const LayoutOptions *src)
202 {
203         free_layout_options_content(dest);
204         
205         *dest = *src;
206         dest->order = g_strdup(src->order);
207         dest->home_path = g_strdup(src->home_path);
208         dest->panels.sort.action_filter = g_strdup(src->panels.sort.action_filter);
209 }
210
211 void free_layout_options_content(LayoutOptions *dest)
212 {
213         if (dest->order) g_free(dest->order);
214         if (dest->home_path) g_free(dest->home_path);
215         if (dest->panels.sort.action_filter) g_free(dest->panels.sort.action_filter);
216 }
217
218 static void sync_options_with_current_state(ConfOptions *options)
219 {
220         LayoutWindow *lw = NULL;
221
222         if (layout_valid(&lw))
223                 {
224                 layout_sync_options_with_current_state(lw);
225                 copy_layout_options(&options->layout, &lw->options);
226                 options->image_overlay.common.state = image_osd_get(lw->image);
227                 layout_sort_get(lw, &options->file_sort.method, &options->file_sort.ascending);
228
229         
230
231                 options->color_profile.enabled = layout_image_color_profile_get_use(lw);
232                 layout_image_color_profile_get(lw,
233                                                &options->color_profile.input_type,
234                                                &options->color_profile.screen_type,
235                                                &options->color_profile.use_image);
236
237                 if (options->startup.restore_path && options->startup.use_last_path)
238                         {
239                         g_free(options->startup.path);
240                         options->startup.path = g_strdup(layout_get_path(lw));
241                         }
242                 }
243
244 }
245
246 void save_options(ConfOptions *options)
247 {
248         gchar *rc_path;
249
250         sync_options_with_current_state(options);
251
252         rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
253         save_options_to(rc_path, options);
254         g_free(rc_path);
255 }
256
257 gboolean load_options(ConfOptions *options)
258 {
259         gboolean success;
260         gchar *rc_path;
261
262         if (isdir(GQ_SYSTEM_WIDE_DIR))
263                 {
264                 rc_path = g_build_filename(GQ_SYSTEM_WIDE_DIR, RC_FILE_NAME, NULL);
265                 success = load_options_from(rc_path, options, TRUE);
266                 DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
267                 g_free(rc_path);
268                 }
269         
270         rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
271         success = load_options_from(rc_path, options, TRUE);
272         DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
273         g_free(rc_path);
274         return(success);
275 }
276 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */