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