read external editors from .desktop files
[geeqie.git] / src / options.c
1 /*
2  * Geeqie
3  * Copyright (C) 2008 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 "info.h"
21 #include "layout.h"
22 #include "layout_image.h"
23 #include "rcfile.h"
24 #include "ui_bookmark.h"
25 #include "ui_fileops.h"
26 #include "window.h"
27
28 ConfOptions *init_options(ConfOptions *options)
29 {
30         if (!options) options = g_new0(ConfOptions, 1);
31
32         options->collections.rectangular_selection = FALSE;
33
34         options->color_profile.enabled = TRUE;
35         options->color_profile.input_type = 0;
36         options->color_profile.screen_file = NULL;
37         options->color_profile.screen_type = 0;
38         options->color_profile.use_image = TRUE;
39
40         options->dnd_icon_size = 48;
41         options->duplicates_similarity_threshold = 99;
42         
43         options->file_filter.disable = FALSE;
44         options->file_filter.show_dot_directory = FALSE;
45         options->file_filter.show_hidden_files = FALSE;
46
47         options->file_ops.confirm_delete = TRUE;
48         options->file_ops.enable_delete_key = TRUE;
49         options->file_ops.enable_in_place_rename = TRUE;
50         options->file_ops.safe_delete_enable = FALSE;
51         options->file_ops.safe_delete_folder_maxsize = 128;
52         options->file_ops.safe_delete_path = NULL;
53
54         options->file_sort.ascending = TRUE;
55         options->file_sort.case_sensitive = FALSE;
56         options->file_sort.method = SORT_NAME;
57
58         options->fullscreen.above = FALSE;
59         options->fullscreen.clean_flip = FALSE;
60         options->fullscreen.disable_saver = TRUE;
61         options->fullscreen.screen = -1;
62
63         options->histogram.last_channel_mode = HCHAN_RGB;
64         options->histogram.last_log_mode = 1;
65         
66         memset(&options->image.border_color, 0, sizeof(options->image.border_color));
67         options->image.dither_quality = GDK_RGB_DITHER_NORMAL;
68         options->image.enable_read_ahead = TRUE;
69         options->image.exif_rotate_enable = TRUE;
70         options->image.fit_window_to_image = FALSE;
71         options->image.idle_read_loop_count = IMAGE_LOADER_IDLE_READ_LOOP_COUNT_DEFAULT;
72         options->image.limit_autofit_size = FALSE;
73         options->image.limit_window_size = TRUE;
74         options->image.max_autofit_size = 100;
75         options->image.max_window_size = 90;
76         options->image.read_buffer_size = IMAGE_LOADER_READ_BUFFER_SIZE_DEFAULT;
77         options->image.scroll_reset_method = SCROLL_RESET_NOCHANGE;
78         options->image.tile_cache_max = 10;
79         options->image.image_cache_max = 128; /* 4 x 10MPix */
80         options->image.use_custom_border_color = FALSE;
81         options->image.zoom_2pass = TRUE;
82         options->image.zoom_increment = 5;
83         options->image.zoom_mode = ZOOM_RESET_NONE;
84         options->image.zoom_quality = GDK_INTERP_BILINEAR;
85         options->image.zoom_to_fit_allow_expand = FALSE;
86
87         options->image_overlay.common.state = OSD_SHOW_NOTHING;
88         options->image_overlay.common.show_at_startup = FALSE;
89         options->image_overlay.common.template_string = NULL;
90         options->image_overlay.common.x = 10;
91         options->image_overlay.common.y = -10;
92
93         options->layout.dir_view_type = DIRVIEW_LIST;
94         options->layout.file_view_type = FILEVIEW_LIST;
95         options->layout.float_window.h = 450;
96         options->layout.float_window.vdivider_pos = -1;
97         options->layout.float_window.w = 260;
98         options->layout.float_window.x = 0;
99         options->layout.float_window.y = 0;
100         options->layout.home_path = NULL;
101         options->layout.main_window.h = 540;
102         options->layout.main_window.hdivider_pos = -1;
103         options->layout.main_window.maximized = FALSE;
104         options->layout.main_window.vdivider_pos = 200;
105         options->layout.main_window.w = 720;
106         options->layout.main_window.x = 0;
107         options->layout.main_window.y = 0;
108         options->layout.order = NULL;
109         options->layout.properties_window.w = DEF_PROPERTY_WIDTH;
110         options->layout.properties_window.h = DEF_PROPERTY_HEIGHT;
111         options->layout.save_window_positions = TRUE;
112         options->layout.show_directory_date = FALSE;
113         options->layout.show_marks = FALSE;
114         options->layout.show_thumbnails = FALSE;
115         options->layout.style = 0;
116         options->layout.toolbar_hidden = FALSE;
117         options->layout.tools_float = FALSE;
118         options->layout.tools_hidden = FALSE;
119         options->layout.tools_restore_state = TRUE;
120
121         options->lazy_image_sync = FALSE;
122         options->mousewheel_scrolls = FALSE;
123         options->open_recent_list_maxsize = 10;
124         options->place_dialogs_under_mouse = FALSE;
125
126         options->panels.exif.enabled = FALSE;
127         options->panels.exif.width = PANEL_DEFAULT_WIDTH;
128         options->panels.info.enabled = FALSE;
129         options->panels.info.width = PANEL_DEFAULT_WIDTH;
130         options->panels.sort.action_state = 0;
131         options->panels.sort.enabled = FALSE;
132         options->panels.sort.mode_state = 0;
133         options->panels.sort.selection_state = 0;
134         options->panels.sort.action_filter = NULL;
135         
136         options->progressive_key_scrolling = TRUE;
137         
138         options->metadata.enable_metadata_dirs = FALSE;
139         options->metadata.save_in_image_file = FALSE;
140         options->metadata.save_legacy_IPTC = FALSE;
141         options->metadata.warn_on_write_problems = TRUE;
142         options->metadata.save_legacy_format = FALSE;
143         options->metadata.sync_grouped_files = TRUE;
144         options->metadata.confirm_write = TRUE;
145         options->metadata.confirm_after_timeout = FALSE;
146         options->metadata.confirm_timeout = 10;
147         options->metadata.confirm_on_image_change = FALSE;
148         options->metadata.confirm_on_dir_change = TRUE;
149         
150         options->show_copy_path = TRUE;
151         options->show_icon_names = TRUE;
152
153         options->slideshow.delay = 50;
154         options->slideshow.random = FALSE;
155         options->slideshow.repeat = FALSE;
156
157         options->startup.path = NULL;
158         options->startup.restore_path = FALSE;
159         options->startup.use_last_path = FALSE;
160
161         options->thumbnails.cache_into_dirs = FALSE;
162         options->thumbnails.enable_caching = TRUE;
163         options->thumbnails.fast = 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
171         options->tree_descend_subdirs = FALSE;
172         options->update_on_time_change = TRUE;
173
174         return options;
175 }
176
177 void setup_default_options(ConfOptions *options)
178 {
179         gchar *path;
180         gint i;
181
182         bookmark_add_default(_("Home"), homedir());
183         path = g_build_filename(homedir(), "Desktop", NULL);
184         bookmark_add_default(_("Desktop"), path);
185         g_free(path);
186         bookmark_add_default(_("Collections"), get_collections_dir());
187
188         g_free(options->file_ops.safe_delete_path);
189         options->file_ops.safe_delete_path = g_strdup(get_trash_dir());
190
191         for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
192                 {
193                 options->color_profile.input_file[i] = NULL;
194                 options->color_profile.input_name[i] = NULL;
195                 }
196
197         set_default_image_overlay_template_string(&options->image_overlay.common.template_string);
198         options->sidecar.ext = g_strdup(".jpg;%raw;.xmp");
199         options->layout.order = g_strdup("123");
200         options->properties.tabs_order = g_strdup(info_tab_default_order());
201
202         options->shell.path = g_strdup(GQ_DEFAULT_SHELL_PATH);
203         options->shell.options = g_strdup(GQ_DEFAULT_SHELL_OPTIONS);
204         
205         for (i = 0; ExifUIList[i].key; i++)
206                 ExifUIList[i].current = ExifUIList[i].default_value;
207 }
208
209 static void sync_options_with_current_state(ConfOptions *options)
210 {
211         LayoutWindow *lw = NULL;
212
213         if (layout_valid(&lw))
214                 {
215                 options->layout.main_window.maximized =  window_maximized(lw->window);
216                 if (!options->layout.main_window.maximized)
217                         {
218                         layout_geometry_get(NULL, &options->layout.main_window.x, &options->layout.main_window.y,
219                                             &options->layout.main_window.w, &options->layout.main_window.h);
220                         }
221
222                 options->image_overlay.common.state = image_osd_get(lw->image);
223                 }
224
225         layout_geometry_get_dividers(NULL, &options->layout.main_window.hdivider_pos, &options->layout.main_window.vdivider_pos);
226
227         layout_views_get(NULL, &options->layout.dir_view_type, &options->layout.file_view_type);
228
229         options->layout.show_thumbnails = layout_thumb_get(NULL);
230         options->layout.show_marks = layout_marks_get(NULL);
231
232         layout_sort_get(NULL, &options->file_sort.method, &options->file_sort.ascending);
233
234         layout_geometry_get_tools(NULL, &options->layout.float_window.x, &options->layout.float_window.y,
235                                   &options->layout.float_window.w, &options->layout.float_window.h, &options->layout.float_window.vdivider_pos);
236         layout_tools_float_get(NULL, &options->layout.tools_float, &options->layout.tools_hidden);
237         options->layout.toolbar_hidden = layout_toolbar_hidden(NULL);
238
239         options->color_profile.enabled = layout_image_color_profile_get_use(NULL);
240         layout_image_color_profile_get(NULL,
241                                        &options->color_profile.input_type,
242                                        &options->color_profile.screen_type,
243                                        &options->color_profile.use_image);
244
245         if (options->startup.restore_path && options->startup.use_last_path)
246                 {
247                 g_free(options->startup.path);
248                 options->startup.path = g_strdup(layout_get_path(NULL));
249                 }
250 }
251
252 void save_options(ConfOptions *options)
253 {
254         gchar *rc_path;
255
256         sync_options_with_current_state(options);
257
258         rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
259         save_options_to(rc_path, options);
260         g_free(rc_path);
261 }
262
263 void load_options(ConfOptions *options)
264 {
265         gboolean success;
266         gchar *rc_path;
267
268         if (isdir(GQ_SYSTEM_WIDE_DIR))
269                 {
270                 rc_path = g_build_filename(GQ_SYSTEM_WIDE_DIR, RC_FILE_NAME, NULL);
271                 success = load_options_from(rc_path, options);
272                 DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
273                 g_free(rc_path);
274                 }
275         
276         rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
277         success = load_options_from(rc_path, options);
278         DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
279         g_free(rc_path);
280 }
281 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */