Add unknown file class to grouping
[geeqie.git] / src / options.c
1 /*
2  * Geeqie
3  * Copyright (C) 2008 - 2010 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.use_image = TRUE;
37         options->color_profile.use_x11_screen_profile = 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->save_window_positions = TRUE;
47         options->tools_restore_state = TRUE;
48
49         options->file_ops.confirm_delete = TRUE;
50         options->file_ops.enable_delete_key = TRUE;
51         options->file_ops.enable_in_place_rename = TRUE;
52         options->file_ops.safe_delete_enable = FALSE;
53         options->file_ops.safe_delete_folder_maxsize = 128;
54         options->file_ops.safe_delete_path = NULL;
55
56         options->file_sort.ascending = TRUE;
57         options->file_sort.case_sensitive = FALSE;
58         options->file_sort.method = SORT_NAME;
59
60         options->fullscreen.above = FALSE;
61         options->fullscreen.clean_flip = FALSE;
62         options->fullscreen.disable_saver = TRUE;
63         options->fullscreen.screen = -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.limit_autofit_size = FALSE;
71         options->image.limit_window_size = TRUE;
72         options->image.max_autofit_size = 100;
73         options->image.max_window_size = 90;
74         options->image.scroll_reset_method = SCROLL_RESET_NOCHANGE;
75         options->image.tile_cache_max = 10;
76         options->image.image_cache_max = 128; /* 4 x 10MPix */
77         options->image.use_custom_border_color = FALSE;
78         options->image.use_custom_border_color_in_fullscreen = TRUE;
79         options->image.zoom_2pass = TRUE;
80         options->image.zoom_increment = 5;
81         options->image.zoom_mode = ZOOM_RESET_NONE;
82         options->image.zoom_quality = GDK_INTERP_BILINEAR;
83         options->image.zoom_to_fit_allow_expand = FALSE;
84
85         options->image_overlay.template_string = NULL;
86         options->image_overlay.x = 10;
87         options->image_overlay.y = -10;
88
89         options->lazy_image_sync = FALSE;
90         options->mousewheel_scrolls = FALSE;
91         options->open_recent_list_maxsize = 10;
92         options->place_dialogs_under_mouse = FALSE;
93
94         options->progressive_key_scrolling = TRUE;
95         
96         options->metadata.enable_metadata_dirs = FALSE;
97         options->metadata.save_in_image_file = FALSE;
98         options->metadata.save_legacy_IPTC = FALSE;
99         options->metadata.warn_on_write_problems = TRUE;
100         options->metadata.save_legacy_format = FALSE;
101         options->metadata.sync_grouped_files = TRUE;
102         options->metadata.confirm_write = TRUE;
103         options->metadata.confirm_after_timeout = FALSE;
104         options->metadata.confirm_timeout = 10;
105         options->metadata.confirm_on_image_change = FALSE;
106         options->metadata.confirm_on_dir_change = TRUE;
107         options->metadata.keywords_case_sensitive = FALSE;
108         options->metadata.write_orientation = TRUE;
109         
110         options->show_icon_names = TRUE;
111
112         options->slideshow.delay = 50;
113         options->slideshow.random = FALSE;
114         options->slideshow.repeat = FALSE;
115
116         options->thumbnails.cache_into_dirs = FALSE;
117         options->thumbnails.enable_caching = TRUE;
118         options->thumbnails.max_height = DEFAULT_THUMB_HEIGHT;
119         options->thumbnails.max_width = DEFAULT_THUMB_WIDTH;
120         options->thumbnails.quality = GDK_INTERP_TILES;
121         options->thumbnails.spec_standard = TRUE;
122         options->thumbnails.use_xvpics = TRUE;
123         options->thumbnails.use_exif = FALSE;
124
125         options->tree_descend_subdirs = FALSE;
126         options->update_on_time_change = TRUE;
127
128         return options;
129 }
130
131 void setup_default_options(ConfOptions *options)
132 {
133         gchar *path;
134         gint i;
135
136         bookmark_add_default(_("Home"), homedir());
137         path = g_build_filename(homedir(), "Desktop", NULL);
138         bookmark_add_default(_("Desktop"), path);
139         g_free(path);
140         bookmark_add_default(_("Collections"), get_collections_dir());
141
142         g_free(options->file_ops.safe_delete_path);
143         options->file_ops.safe_delete_path = g_strdup(get_trash_dir());
144
145         for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
146                 {
147                 options->color_profile.input_file[i] = NULL;
148                 options->color_profile.input_name[i] = NULL;
149                 }
150
151         set_default_image_overlay_template_string(&options->image_overlay.template_string);
152         options->sidecar.ext = g_strdup(".jpg;%raw;.ufraw;.xmp;%unknown");
153
154         options->shell.path = g_strdup(GQ_DEFAULT_SHELL_PATH);
155         options->shell.options = g_strdup(GQ_DEFAULT_SHELL_OPTIONS);
156
157 #if 0   
158         for (i = 0; ExifUIList[i].key; i++)
159                 ExifUIList[i].current = ExifUIList[i].default_value;
160 #endif
161 }
162
163 void copy_layout_options(LayoutOptions *dest, const LayoutOptions *src)
164 {
165         free_layout_options_content(dest);
166         
167         *dest = *src;
168         dest->id = g_strdup(src->id);
169         dest->order = g_strdup(src->order);
170         dest->home_path = g_strdup(src->home_path);
171         dest->last_path = g_strdup(src->last_path);
172 }
173
174 void free_layout_options_content(LayoutOptions *dest)
175 {
176         g_free(dest->id);
177         g_free(dest->order);
178         g_free(dest->home_path);
179         g_free(dest->last_path);
180 }
181
182 LayoutOptions *init_layout_options(LayoutOptions *options)
183 {
184         memset(options, 0, sizeof(LayoutOptions));
185
186         options->dir_view_type = DIRVIEW_LIST;
187         options->file_view_type = FILEVIEW_LIST;
188         options->float_window.h = 450;
189         options->float_window.vdivider_pos = -1;
190         options->float_window.w = 260;
191         options->float_window.x = 0;
192         options->float_window.y = 0;
193         options->home_path = NULL;
194         options->main_window.h = 540;
195         options->main_window.hdivider_pos = -1;
196         options->main_window.maximized = FALSE;
197         options->main_window.vdivider_pos = 200;
198         options->main_window.w = 720;
199         options->main_window.x = 0;
200         options->main_window.y = 0;
201         options->order = g_strdup("123");
202         options->show_directory_date = FALSE;
203         options->show_marks = FALSE;
204         options->show_thumbnails = FALSE;
205         options->style = 0;
206         options->show_info_pixel = FALSE;
207         options->toolbar_hidden = FALSE;
208         options->tools_float = FALSE;
209         options->tools_hidden = FALSE;
210         options->image_overlay.histogram_channel = HCHAN_RGB;
211         options->image_overlay.histogram_mode = 1;
212         options->image_overlay.state = OSD_SHOW_NOTHING;
213         return options;
214 }
215
216 static void sync_options_with_current_state(ConfOptions *options)
217 {
218         LayoutWindow *lw = NULL;
219
220         if (layout_valid(&lw))
221                 {
222                 layout_sync_options_with_current_state(lw);
223                 layout_sort_get(lw, &options->file_sort.method, &options->file_sort.ascending);
224
225                 options->color_profile.enabled = layout_image_color_profile_get_use(lw);
226                 layout_image_color_profile_get(lw,
227                                                &options->color_profile.input_type,
228                                                &options->color_profile.use_image);
229                 }
230
231 }
232
233 void save_options(ConfOptions *options)
234 {
235         gchar *rc_path;
236
237         sync_options_with_current_state(options);
238
239         rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
240         save_config_to_file(rc_path, options);
241         g_free(rc_path);
242 }
243
244 gboolean load_options(ConfOptions *options)
245 {
246         gboolean success;
247         gchar *rc_path;
248
249         if (isdir(GQ_SYSTEM_WIDE_DIR))
250                 {
251                 rc_path = g_build_filename(GQ_SYSTEM_WIDE_DIR, RC_FILE_NAME, NULL);
252                 success = load_config_from_file(rc_path, TRUE);
253                 DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
254                 g_free(rc_path);
255                 }
256         
257         rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
258         success = load_config_from_file(rc_path, TRUE);
259         DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
260         g_free(rc_path);
261         return(success);
262 }
263 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */