Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the...
[geeqie.git] / src / preferences.c
1 /*
2  * Geeqie
3  * (C) 2006 John Ellis
4  * Copyright (C) 2008 - 2009 The Geeqie Team
5  *
6  * Author: John Ellis
7  *
8  * This software is released under the GNU General Public License (GNU GPL).
9  * Please read the included file COPYING for more information.
10  * This software comes with no warranty of any kind, use at your own risk!
11  */
12
13
14 #include "main.h"
15 #include "preferences.h"
16
17 #include "bar_exif.h"
18 #include "cache_maint.h"
19 #include "editors.h"
20 #include "exif.h"
21 #include "filedata.h"
22 #include "filefilter.h"
23 #include "fullscreen.h"
24 #include "image.h"
25 #include "image-overlay.h"
26 #include "color-man.h"
27 #include "img-view.h"
28 #include "layout_config.h"
29 #include "layout_util.h"
30 #include "pixbuf_util.h"
31 #include "slideshow.h"
32 #include "trash.h"
33 #include "utilops.h"
34 #include "ui_fileops.h"
35 #include "ui_misc.h"
36 #include "ui_tabcomp.h"
37 #include "ui_utildlg.h"
38 #include "window.h"
39
40 #include <math.h>
41
42
43 #define EDITOR_NAME_MAX_LENGTH 32
44 #define EDITOR_COMMAND_MAX_LENGTH 1024
45
46
47 typedef struct _ThumbSize ThumbSize;
48 struct _ThumbSize
49 {
50         gint w;
51         gint h;
52 };
53
54 static ThumbSize thumb_size_list[] =
55 {
56         { 24, 24 },
57         { 32, 32 },
58         { 48, 48 },
59         { 64, 64 },
60         { 96, 72 },
61         { 96, 96 },
62         { 128, 96 },
63         { 128, 128 },
64         { 160, 120 },
65         { 160, 160 },
66         { 192, 144 },
67         { 192, 192 },
68         { 256, 192 },
69         { 256, 256 }
70 };
71
72 enum {
73         FE_ENABLE,
74         FE_EXTENSION,
75         FE_DESCRIPTION,
76         FE_CLASS,
77         FE_WRITABLE,
78         FE_ALLOW_SIDECAR
79 };
80
81
82 static gchar *format_class_list[] = {
83         N_("Unknown"),
84         N_("Image"),
85         N_("RAW Image"),
86         N_("Metadata")
87         };
88
89
90 /* config memory values */
91 static ConfOptions *c_options = NULL;
92
93
94 #ifdef DEBUG
95 static gint debug_c;
96 #endif
97
98 static GtkWidget *configwindow = NULL;
99 static GtkWidget *startup_path_entry;
100 static GtkWidget *home_path_entry;
101 static GtkListStore *filter_store = NULL;
102
103 static GtkWidget *layout_widget;
104
105 static GtkWidget *safe_delete_path_entry;
106
107 static GtkWidget *color_profile_input_file_entry[COLOR_PROFILE_INPUTS];
108 static GtkWidget *color_profile_input_name_entry[COLOR_PROFILE_INPUTS];
109 static GtkWidget *color_profile_screen_file_entry;
110
111 static GtkWidget *sidecar_ext_entry;
112
113
114 #define CONFIG_WINDOW_DEF_WIDTH         700
115 #define CONFIG_WINDOW_DEF_HEIGHT        600
116
117 /*
118  *-----------------------------------------------------------------------------
119  * option widget callbacks (private)
120  *-----------------------------------------------------------------------------
121  */
122
123 static void startup_path_set_current(GtkWidget *widget, gpointer data)
124 {
125         gtk_entry_set_text(GTK_ENTRY(startup_path_entry), layout_get_path(NULL));
126 }
127
128 static void home_path_set_current(GtkWidget *widget, gpointer data)
129 {
130         gtk_entry_set_text(GTK_ENTRY(home_path_entry), layout_get_path(NULL));
131 }
132
133 static void zoom_mode_cb(GtkWidget *widget, gpointer data)
134 {
135         if (GTK_TOGGLE_BUTTON (widget)->active)
136                 c_options->image.zoom_mode = GPOINTER_TO_INT(data);
137 }
138
139 static void scroll_reset_cb(GtkWidget *widget, gpointer data)
140 {
141         if (GTK_TOGGLE_BUTTON (widget)->active)
142                 c_options->image.scroll_reset_method = GPOINTER_TO_INT(data);
143 }
144
145 static void zoom_increment_cb(GtkWidget *spin, gpointer data)
146 {
147         c_options->image.zoom_increment = (gint)(gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin)) * 10.0 + 0.01);
148 }
149
150 static void slideshow_delay_cb(GtkWidget *spin, gpointer data)
151 {
152         c_options->slideshow.delay = (gint)(gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin)) *
153                                    (gdouble)SLIDESHOW_SUBSECOND_PRECISION + 0.01);
154 }
155
156 /*
157  *-----------------------------------------------------------------------------
158  * sync progam to config window routine (private)
159  *-----------------------------------------------------------------------------
160  */
161
162 static void config_entry_to_option(GtkWidget *entry, gchar **option, gchar *(*func)(const gchar *))
163 {
164         const gchar *buf;
165
166         g_free(*option);
167         *option = NULL;
168         buf = gtk_entry_get_text(GTK_ENTRY(entry));
169         if (buf && strlen(buf) > 0)
170                 {
171                 if (func)
172                         *option = func(buf);
173                 else
174                         *option = g_strdup(buf);
175                 }
176 }
177
178 #if 0
179 static void config_parse_editor_entries(GtkWidget **editor_name_entry, GtkWidget **editor_command_entry)
180 {
181         gint i;
182         const gchar *buf;
183         GString *errmsg = g_string_new("");
184
185         for (i = 0; i < GQ_EDITOR_SLOTS; i++)
186                 {
187                 gchar *command = NULL;
188
189                 if (i < GQ_EDITOR_GENERIC_SLOTS)
190                         {
191                         gchar *name = NULL;
192
193                         buf = gtk_entry_get_text(GTK_ENTRY(editor_name_entry[i]));
194                         if (buf && strlen(buf) > 0) name = g_strdup(buf);
195                         editor_set_name(i, name);
196                         g_free(name);
197                         }
198
199                 buf = gtk_entry_get_text(GTK_ENTRY(editor_command_entry[i]));
200                 if (buf && strlen(buf) > 0)
201                         {
202                         gint flags = editor_command_parse(buf, NULL, NULL);
203                 
204                         if (EDITOR_ERRORS(flags))
205                                 {
206                                 if (errmsg->str[0]) g_string_append(errmsg, "\n\n");
207                                 g_string_append_printf(errmsg, _("%s\n#%d \"%s\":\n%s"), editor_get_error_str(flags),
208                                                        i+1, options->editor[i].name, buf);
209
210                                 }
211                         command = g_strdup(buf);
212                         }
213
214                 editor_set_command(i, command);
215                 g_free(command);
216                 }
217         
218         if (errmsg->str[0])
219                 {
220                 file_util_warning_dialog(_("Invalid editor command"), errmsg->str, GTK_STOCK_DIALOG_ERROR, NULL);
221                 }
222
223         g_string_free(errmsg, TRUE);
224 }
225 #endif
226
227 static void config_window_apply(void)
228 {
229         gint new_style;
230         gint i;
231         gint refresh = FALSE;
232
233 //      config_parse_editor_entries(editor_name_entry, editor_command_entry); 
234 //      layout_edit_update_all();
235
236         config_entry_to_option(safe_delete_path_entry, &options->file_ops.safe_delete_path, remove_trailing_slash);
237         
238         if (options->file_filter.show_hidden_files != c_options->file_filter.show_hidden_files) refresh = TRUE;
239         if (options->file_filter.show_dot_directory != c_options->file_filter.show_dot_directory) refresh = TRUE;
240         if (options->file_sort.case_sensitive != c_options->file_sort.case_sensitive) refresh = TRUE;
241         if (options->file_filter.disable != c_options->file_filter.disable) refresh = TRUE;
242
243         options->startup.restore_path = c_options->startup.restore_path;
244         options->startup.use_last_path = c_options->startup.use_last_path;
245         config_entry_to_option(startup_path_entry, &options->startup.path, remove_trailing_slash);
246         config_entry_to_option(home_path_entry, &options->layout.home_path, remove_trailing_slash);
247
248         options->file_ops.confirm_delete = c_options->file_ops.confirm_delete;
249         options->file_ops.enable_delete_key = c_options->file_ops.enable_delete_key;
250         options->file_ops.safe_delete_enable = c_options->file_ops.safe_delete_enable;
251         options->file_ops.safe_delete_folder_maxsize = c_options->file_ops.safe_delete_folder_maxsize;
252         options->layout.tools_restore_state = c_options->layout.tools_restore_state;
253         options->layout.save_window_positions = c_options->layout.save_window_positions;
254         options->image.zoom_mode = c_options->image.zoom_mode;
255         options->image.scroll_reset_method = c_options->image.scroll_reset_method;
256         options->image.zoom_2pass = c_options->image.zoom_2pass;
257         options->image.fit_window_to_image = c_options->image.fit_window_to_image;
258         options->image.limit_window_size = c_options->image.limit_window_size;
259         options->image.zoom_to_fit_allow_expand = c_options->image.zoom_to_fit_allow_expand;
260         options->image.max_window_size = c_options->image.max_window_size;
261         options->image.limit_autofit_size = c_options->image.limit_autofit_size;
262         options->image.max_autofit_size = c_options->image.max_autofit_size;
263         options->progressive_key_scrolling = c_options->progressive_key_scrolling;
264         options->thumbnails.max_width = c_options->thumbnails.max_width;
265         options->thumbnails.max_height = c_options->thumbnails.max_height;
266         options->thumbnails.enable_caching = c_options->thumbnails.enable_caching;
267         options->thumbnails.cache_into_dirs = c_options->thumbnails.cache_into_dirs;
268         options->thumbnails.fast = c_options->thumbnails.fast;
269         options->thumbnails.use_exif = c_options->thumbnails.use_exif;
270 #if 0
271         options->thumbnails.use_xvpics = c_options->thumbnails.use_xvpics;
272 #endif
273         options->thumbnails.spec_standard = c_options->thumbnails.spec_standard;
274         options->metadata.enable_metadata_dirs = c_options->metadata.enable_metadata_dirs;
275         options->file_filter.show_hidden_files = c_options->file_filter.show_hidden_files;
276         options->file_filter.show_dot_directory = c_options->file_filter.show_dot_directory;
277
278         options->file_sort.case_sensitive = c_options->file_sort.case_sensitive;
279         options->file_filter.disable = c_options->file_filter.disable;
280
281         config_entry_to_option(sidecar_ext_entry, &options->sidecar.ext, NULL);
282         sidecar_ext_parse(options->sidecar.ext);
283
284         options->slideshow.random = c_options->slideshow.random;
285         options->slideshow.repeat = c_options->slideshow.repeat;
286         options->slideshow.delay = c_options->slideshow.delay;
287
288         options->mousewheel_scrolls = c_options->mousewheel_scrolls;
289
290         options->file_ops.enable_in_place_rename = c_options->file_ops.enable_in_place_rename;
291
292         options->collections.rectangular_selection = c_options->collections.rectangular_selection;
293
294         options->image.tile_cache_max = c_options->image.tile_cache_max;
295         options->image.image_cache_max = c_options->image.image_cache_max;
296
297         options->image.read_buffer_size = c_options->image.read_buffer_size;
298         options->image.idle_read_loop_count = c_options->image.idle_read_loop_count;
299
300         options->thumbnails.quality = c_options->thumbnails.quality;
301         options->image.zoom_quality = c_options->image.zoom_quality;
302
303         options->image.zoom_increment = c_options->image.zoom_increment;
304
305         options->image.enable_read_ahead = c_options->image.enable_read_ahead;
306
307         if (options->image.use_custom_border_color != c_options->image.use_custom_border_color
308             || !gdk_color_equal(&options->image.border_color, &c_options->image.border_color))
309                 {
310                 options->image.use_custom_border_color = c_options->image.use_custom_border_color;
311                 options->image.border_color = c_options->image.border_color;
312                 layout_colors_update();
313                 view_window_colors_update();
314                 }
315
316         options->fullscreen.screen = c_options->fullscreen.screen;
317         options->fullscreen.clean_flip = c_options->fullscreen.clean_flip;
318         options->fullscreen.disable_saver = c_options->fullscreen.disable_saver;
319         options->fullscreen.above = c_options->fullscreen.above;
320         if (c_options->image_overlay.template_string)
321                 set_image_overlay_template_string(&options->image_overlay.template_string,
322                                                   c_options->image_overlay.template_string);
323                 
324         options->update_on_time_change = c_options->update_on_time_change;
325         options->image.exif_rotate_enable = c_options->image.exif_rotate_enable;
326
327         options->duplicates_similarity_threshold = c_options->duplicates_similarity_threshold;
328
329         options->tree_descend_subdirs = c_options->tree_descend_subdirs;
330
331         options->open_recent_list_maxsize = c_options->open_recent_list_maxsize;
332         options->dnd_icon_size = c_options->dnd_icon_size;
333         
334         if (options->show_copy_path != c_options->show_copy_path)
335                 {
336                 options->show_copy_path = c_options->show_copy_path;
337                 layout_copy_path_update_all();
338                 }
339
340         options->metadata.save_in_image_file = c_options->metadata.save_in_image_file;
341         options->metadata.save_legacy_IPTC = c_options->metadata.save_legacy_IPTC;
342         options->metadata.warn_on_write_problems = c_options->metadata.warn_on_write_problems;
343         options->metadata.save_legacy_format = c_options->metadata.save_legacy_format;
344         options->metadata.sync_grouped_files = c_options->metadata.sync_grouped_files;
345         options->metadata.confirm_write = c_options->metadata.confirm_write;
346         options->metadata.confirm_timeout = c_options->metadata.confirm_timeout;
347         options->metadata.confirm_after_timeout = c_options->metadata.confirm_after_timeout;
348         options->metadata.confirm_on_image_change = c_options->metadata.confirm_on_image_change;
349         options->metadata.confirm_on_dir_change = c_options->metadata.confirm_on_dir_change;
350
351 #ifdef DEBUG
352         set_debug_level(debug_c);
353 #endif
354
355 #ifdef HAVE_LCMS
356         for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
357                 {
358                 config_entry_to_option(color_profile_input_name_entry[i], &options->color_profile.input_name[i], NULL);
359                 config_entry_to_option(color_profile_input_file_entry[i], &options->color_profile.input_file[i], NULL);
360                 }
361         config_entry_to_option(color_profile_screen_file_entry, &options->color_profile.screen_file, NULL);
362 #endif
363
364 #if 0
365         for (i = 0; ExifUIList[i].key; i++)
366                 {
367                 ExifUIList[i].current = ExifUIList[i].temp;
368                 }
369
370 #endif
371         {
372         gchar *layout_order = layout_config_get(layout_widget, &new_style);
373
374         if (new_style != options->layout.style ||
375             (layout_order == NULL) != (options->layout.order == NULL) ||
376             !options->layout.order ||
377             strcmp(layout_order, options->layout.order) != 0)
378                 {
379                 if (refresh) filter_rebuild();
380                 refresh = FALSE;
381
382                 g_free(options->layout.order);
383                 options->layout.order = layout_order;
384                 layout_order = NULL; /* g_free() later */
385
386                 options->layout.style = new_style;
387
388                 layout_styles_update();
389                 }
390
391         g_free(layout_order);
392         }
393
394         if (options->layout.show_directory_date != c_options->layout.show_directory_date)
395                 {
396                 options->layout.show_directory_date = c_options->layout.show_directory_date;
397                 refresh = TRUE;
398                 }
399
400         image_options_sync();
401
402         if (refresh)
403                 {
404                 filter_rebuild();
405                 layout_refresh(NULL);
406                 }
407 }
408
409 /*
410  *-----------------------------------------------------------------------------
411  * config window main button callbacks (private)
412  *-----------------------------------------------------------------------------
413  */
414
415 static void config_window_close_cb(GtkWidget *widget, gpointer data)
416 {
417         gtk_widget_destroy(configwindow);
418         configwindow = NULL;
419         filter_store = NULL;
420 }
421
422 static gint config_window_delete(GtkWidget *w, GdkEventAny *event, gpointer data)
423 {
424         config_window_close_cb(NULL, NULL);
425         return TRUE;
426 }
427
428 static void config_window_ok_cb(GtkWidget *widget, gpointer data)
429 {
430         config_window_apply();
431         config_window_close_cb(NULL, NULL);
432 }
433
434 static void config_window_apply_cb(GtkWidget *widget, gpointer data)
435 {
436         config_window_apply();
437 }
438
439 static void config_window_save_cb(GtkWidget *widget, gpointer data)
440 {
441         config_window_apply();
442         save_options(options);
443 }
444
445 /*
446  *-----------------------------------------------------------------------------
447  * config window setup (private)
448  *-----------------------------------------------------------------------------
449  */
450
451 static void exif_item_cb(GtkWidget *combo, gpointer data)
452 {
453         gint *option = data;
454         *option = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
455 }
456
457 static void exif_item(GtkWidget *table, gint column, gint row,
458                       const gchar *text, gint option, gint *option_c)
459 {
460         GtkWidget *combo;
461
462         *option_c = option;
463
464         pref_table_label(table, column, row, text, 0.0);
465
466         combo = gtk_combo_box_new_text();
467
468         /* note: the order is important, it must match the values of
469          * EXIF_UI_OFF, _IFSET, _ON */
470         gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Never"));
471         gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("If set"));
472         gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Always"));
473
474         gtk_combo_box_set_active(GTK_COMBO_BOX(combo), option);
475
476         g_signal_connect(G_OBJECT(combo), "changed",
477                          G_CALLBACK(exif_item_cb), option_c);
478
479         gtk_table_attach(GTK_TABLE(table), combo,
480                          column + 1, column + 2, row, row + 1,
481                          GTK_EXPAND | GTK_FILL, 0, 0, 0);
482         gtk_widget_show(combo);
483 }
484
485 static void quality_menu_cb(GtkWidget *combo, gpointer data)
486 {
487         gint *option = data;
488
489         switch (gtk_combo_box_get_active(GTK_COMBO_BOX(combo)))
490                 {
491                 case 0:
492                 default:
493                         *option = GDK_INTERP_NEAREST;
494                         break;
495                 case 1:
496                         *option = GDK_INTERP_TILES;
497                         break;
498                 case 2:
499                         *option = GDK_INTERP_BILINEAR;
500                         break;
501                 case 3:
502                         *option = GDK_INTERP_HYPER;
503                         break;
504                 }
505 }
506
507 static void add_quality_menu(GtkWidget *table, gint column, gint row, const gchar *text,
508                              guint option, guint *option_c)
509 {
510         GtkWidget *combo;
511         gint current = 0;
512
513         *option_c = option;
514
515         pref_table_label(table, column, row, text, 0.0);
516
517         combo = gtk_combo_box_new_text();
518
519         gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Nearest (worst, but fastest)"));
520         if (option == GDK_INTERP_NEAREST) current = 0;
521         gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Tiles"));
522         if (option == GDK_INTERP_TILES) current = 1;
523         gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Bilinear"));
524         if (option == GDK_INTERP_BILINEAR) current = 2;
525         gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Hyper (best, but slowest)"));
526         if (option == GDK_INTERP_HYPER) current = 3;
527
528         gtk_combo_box_set_active(GTK_COMBO_BOX(combo), current);
529
530         g_signal_connect(G_OBJECT(combo), "changed",
531                          G_CALLBACK(quality_menu_cb), option_c);
532
533         gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1,
534                          GTK_EXPAND | GTK_FILL, 0, 0, 0);
535         gtk_widget_show(combo);
536 }
537
538 #if 0
539 static void add_dither_menu(gint option, gint *option_c, gchar *text, GtkWidget *box)
540 {
541         GtkWidget *hbox;
542         GtkWidget *omenu;
543         GtkWidget *menu;
544
545         *option_c = option;
546
547         hbox = pref_box_new(box, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
548         pref_label_new(hbox, text);
549
550         omenu = gtk_option_menu_new();
551         menu = gtk_menu_new();
552
553         add_menu_item(menu, _("None"), option_c, (gint)GDK_RGB_DITHER_NONE);
554         add_menu_item(menu, _("Normal"), option_c, (gint)GDK_RGB_DITHER_NORMAL);
555         add_menu_item(menu, _("Best"), option_c, (gint)GDK_RGB_DITHER_MAX);
556
557         gtk_option_menu_set_menu(GTK_OPTION_MENU(omenu), menu);
558         gtk_option_menu_set_history(GTK_OPTION_MENU(omenu), *option_c);
559
560         gtk_box_pack_start(GTK_BOX(hbox), omenu, FALSE, FALSE, 0);
561         gtk_widget_show(omenu);
562 }
563 #endif
564
565 static void thumb_size_menu_cb(GtkWidget *combo, gpointer data)
566 {
567         gint n;
568
569         n = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
570         if (n < 0) return;
571
572         if ((guint) n < sizeof(thumb_size_list) / sizeof(ThumbSize))
573                 {
574                 c_options->thumbnails.max_width = thumb_size_list[n].w;
575                 c_options->thumbnails.max_height = thumb_size_list[n].h;
576                 }
577         else
578                 {
579                 c_options->thumbnails.max_width = options->thumbnails.max_width;
580                 c_options->thumbnails.max_height = options->thumbnails.max_height;
581                 }
582 }
583
584 static void add_thumb_size_menu(GtkWidget *table, gint column, gint row, gchar *text)
585 {
586         GtkWidget *combo;
587         gint current;
588         gint i;
589
590         c_options->thumbnails.max_width = options->thumbnails.max_width;
591         c_options->thumbnails.max_height = options->thumbnails.max_height;
592
593         pref_table_label(table, column, row, text, 0.0);
594
595         combo = gtk_combo_box_new_text();
596
597         current = -1;
598         for (i = 0; (guint) i < sizeof(thumb_size_list) / sizeof(ThumbSize); i++)
599                 {
600                 gint w, h;
601                 gchar *buf;
602
603                 w = thumb_size_list[i].w;
604                 h = thumb_size_list[i].h;
605
606                 buf = g_strdup_printf("%d x %d", w, h);
607                 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), buf);
608                 g_free(buf);
609
610                 if (w == options->thumbnails.max_width && h == options->thumbnails.max_height) current = i;
611                 }
612
613         if (current == -1)
614                 {
615                 gchar *buf;
616
617                 buf = g_strdup_printf("%s %d x %d", _("Custom"), options->thumbnails.max_width, options->thumbnails.max_height);
618                 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), buf);
619                 g_free(buf);
620
621                 current = i;
622                 }
623
624         gtk_combo_box_set_active(GTK_COMBO_BOX(combo), current);
625         g_signal_connect(G_OBJECT(combo), "changed",
626                          G_CALLBACK(thumb_size_menu_cb), NULL);
627
628         gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1,
629                          GTK_EXPAND | GTK_FILL, 0, 0, 0);
630         gtk_widget_show(combo);
631 }
632
633 static void filter_store_populate(void)
634 {
635         GList *work;
636
637         if (!filter_store) return;
638
639         gtk_list_store_clear(filter_store);
640
641         work = filter_get_list();
642         while (work)
643                 {
644                 FilterEntry *fe;
645                 GtkTreeIter iter;
646
647                 fe = work->data;
648                 work = work->next;
649
650                 gtk_list_store_append(filter_store, &iter);
651                 gtk_list_store_set(filter_store, &iter, 0, fe, -1);
652                 }
653 }
654
655 static void filter_store_ext_edit_cb(GtkCellRendererText *cell, gchar *path_str,
656                                      gchar *new_text, gpointer data)
657 {
658         GtkWidget *model = data;
659         FilterEntry *fe = data;
660         GtkTreePath *tpath;
661         GtkTreeIter iter;
662
663         if (!new_text || strlen(new_text) < 1) return;
664
665         tpath = gtk_tree_path_new_from_string(path_str);
666         gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, tpath);
667         gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &fe, -1);
668
669         g_free(fe->extensions);
670         fe->extensions = g_strdup(new_text);
671
672         gtk_tree_path_free(tpath);
673         filter_rebuild();
674 }
675
676 static void filter_store_class_edit_cb(GtkCellRendererText *cell, gchar *path_str,
677                                      gchar *new_text, gpointer data)
678 {
679
680         GtkWidget *model = data;
681         FilterEntry *fe = data;
682         GtkTreePath *tpath;
683         GtkTreeIter iter;
684         gint i;
685
686         if (!new_text || strlen(new_text) < 1) return;
687
688         tpath = gtk_tree_path_new_from_string(path_str);
689         gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, tpath);
690         gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &fe, -1);
691
692         for (i = 0; i < FILE_FORMAT_CLASSES; i++)
693                 {
694                 if (strcmp(new_text, _(format_class_list[i])) == 0)
695                         {
696                         fe->file_class = i;
697                         break;
698                         }
699                 }
700
701         gtk_tree_path_free(tpath);
702         filter_rebuild();
703 }
704
705 static void filter_store_desc_edit_cb(GtkCellRendererText *cell, gchar *path_str,
706                                       gchar *new_text, gpointer data)
707 {
708         GtkWidget *model = data;
709         FilterEntry *fe;
710         GtkTreePath *tpath;
711         GtkTreeIter iter;
712
713         if (!new_text || strlen(new_text) < 1) return;
714
715         tpath = gtk_tree_path_new_from_string(path_str);
716         gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, tpath);
717         gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &fe, -1);
718
719         g_free(fe->description);
720         fe->description = g_strdup(new_text);
721
722         gtk_tree_path_free(tpath);
723 }
724
725 static void filter_store_enable_cb(GtkCellRendererToggle *renderer,
726                                    gchar *path_str, gpointer data)
727 {
728         GtkWidget *model = data;
729         FilterEntry *fe;
730         GtkTreePath *tpath;
731         GtkTreeIter iter;
732
733         tpath = gtk_tree_path_new_from_string(path_str);
734         gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, tpath);
735         gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &fe, -1);
736
737         fe->enabled = !fe->enabled;
738
739         gtk_tree_path_free(tpath);
740         filter_rebuild();
741 }
742
743 static void filter_store_writable_cb(GtkCellRendererToggle *renderer,
744                                    gchar *path_str, gpointer data)
745 {
746         GtkWidget *model = data;
747         FilterEntry *fe;
748         GtkTreePath *tpath;
749         GtkTreeIter iter;
750
751         tpath = gtk_tree_path_new_from_string(path_str);
752         gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, tpath);
753         gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &fe, -1);
754
755         fe->writable = !fe->writable;
756         if (fe->writable) fe->allow_sidecar = FALSE;
757
758         gtk_tree_path_free(tpath);
759         filter_rebuild();
760 }
761
762 static void filter_store_sidecar_cb(GtkCellRendererToggle *renderer,
763                                    gchar *path_str, gpointer data)
764 {
765         GtkWidget *model = data;
766         FilterEntry *fe;
767         GtkTreePath *tpath;
768         GtkTreeIter iter;
769
770         tpath = gtk_tree_path_new_from_string(path_str);
771         gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, tpath);
772         gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &fe, -1);
773
774         fe->allow_sidecar = !fe->allow_sidecar;
775         if (fe->allow_sidecar) fe->writable = FALSE;
776
777         gtk_tree_path_free(tpath);
778         filter_rebuild();
779 }
780
781 static void filter_set_func(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
782                             GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
783 {
784         FilterEntry *fe;
785
786         gtk_tree_model_get(tree_model, iter, 0, &fe, -1);
787
788         switch (GPOINTER_TO_INT(data))
789                 {
790                 case FE_ENABLE:
791                         g_object_set(GTK_CELL_RENDERER(cell),
792                                      "active", fe->enabled, NULL);
793                         break;
794                 case FE_EXTENSION:
795                         g_object_set(GTK_CELL_RENDERER(cell),
796                                      "text", fe->extensions, NULL);
797                         break;
798                 case FE_DESCRIPTION:
799                         g_object_set(GTK_CELL_RENDERER(cell),
800                                      "text", fe->description, NULL);
801                         break;
802                 case FE_CLASS:
803                         g_object_set(GTK_CELL_RENDERER(cell),
804                                      "text", _(format_class_list[fe->file_class]), NULL);
805                         break;
806                 case FE_WRITABLE:
807                         g_object_set(GTK_CELL_RENDERER(cell),
808                                      "active", fe->writable, NULL);
809                         break;
810                 case FE_ALLOW_SIDECAR:
811                         g_object_set(GTK_CELL_RENDERER(cell),
812                                      "active", fe->allow_sidecar, NULL);
813                         break;
814                 }
815 }
816
817 static void filter_add_cb(GtkWidget *widget, gpointer data)
818 {
819         filter_add_unique("description", ".new", FORMAT_CLASS_IMAGE, TRUE, FALSE, TRUE);
820         filter_store_populate();
821
822         /* FIXME: implement the scroll to/select row stuff for tree view */
823 }
824
825 static void filter_remove_cb(GtkWidget *widget, gpointer data)
826 {
827         GtkWidget *filter_view = data;
828         GtkTreeSelection *selection;
829         GtkTreeIter iter;
830         FilterEntry *fe;
831
832         if (!filter_store) return;
833         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(filter_view));
834         if (!gtk_tree_selection_get_selected(selection, NULL, &iter)) return;
835         gtk_tree_model_get(GTK_TREE_MODEL(filter_store), &iter, 0, &fe, -1);
836         if (!fe) return;
837
838         filter_remove_entry(fe);
839         filter_rebuild();
840         filter_store_populate();
841 }
842
843 static void filter_default_ok_cb(GenericDialog *gd, gpointer data)
844 {
845         filter_reset();
846         filter_add_defaults();
847         filter_rebuild();
848         filter_store_populate();
849 }
850
851 static void dummy_cancel_cb(GenericDialog *gd, gpointer data)
852 {
853         /* no op, only so cancel button appears */
854 }
855
856 static void filter_default_cb(GtkWidget *widget, gpointer data)
857 {
858         GenericDialog *gd;
859
860         gd = generic_dialog_new(_("Reset filters"),
861                                 "reset_filter", widget, TRUE,
862                                 dummy_cancel_cb, NULL);
863         generic_dialog_add_message(gd, GTK_STOCK_DIALOG_QUESTION, _("Reset filters"),
864                                    _("This will reset the file filters to the defaults.\nContinue?"));
865         generic_dialog_add_button(gd, GTK_STOCK_OK, NULL, filter_default_ok_cb, TRUE);
866         gtk_widget_show(gd->dialog);
867 }
868
869 static void filter_disable_cb(GtkWidget *widget, gpointer data)
870 {
871         GtkWidget *frame = data;
872
873         gtk_widget_set_sensitive(frame,
874                                  !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)));
875 }
876
877 #if 0
878 static void editor_default_ok_cb(GenericDialog *gd, gpointer data)
879 {
880         gint i;
881
882         editor_reset_defaults();
883         if (!configwindow) return;
884
885         for (i = 0; i < GQ_EDITOR_SLOTS; i++)
886                 {
887                 if (i < GQ_EDITOR_GENERIC_SLOTS)
888                         gtk_entry_set_text(GTK_ENTRY(editor_name_entry[i]),
889                                    (options->editor[i].name) ? options->editor[i].name : "");
890                 gtk_entry_set_text(GTK_ENTRY(editor_command_entry[i]),
891                                    (options->editor[i].command) ? options->editor[i].command : "");
892                 }
893 }
894
895 static void editor_default_cb(GtkWidget *widget, gpointer data)
896 {
897         GenericDialog *gd;
898
899         gd = generic_dialog_new(_("Reset editors"),
900                                 "reset_filter", widget, TRUE,
901                                 dummy_cancel_cb, NULL);
902         generic_dialog_add_message(gd, GTK_STOCK_DIALOG_QUESTION, _("Reset editors"),
903                                    _("This will reset the edit commands to the defaults.\nContinue?"));
904         generic_dialog_add_button(gd, GTK_STOCK_OK, NULL, editor_default_ok_cb, TRUE);
905         gtk_widget_show(gd->dialog);
906 }
907
908 static void editor_help_cb(GtkWidget *widget, gpointer data)
909 {
910         help_window_show("editors");
911 }
912 #endif
913
914 static void safe_delete_view_cb(GtkWidget *widget, gpointer data)
915 {
916         layout_set_path(NULL, gtk_entry_get_text(GTK_ENTRY(safe_delete_path_entry)));
917 }
918
919 static void safe_delete_clear_ok_cb(GenericDialog *gd, gpointer data)
920 {
921         file_util_trash_clear();
922 }
923
924 static void safe_delete_clear_cb(GtkWidget *widget, gpointer data)
925 {
926         GenericDialog *gd;
927         GtkWidget *entry;
928         gd = generic_dialog_new(_("Clear trash"),
929                                 "clear_trash", widget, TRUE,
930                                 dummy_cancel_cb, NULL);
931         generic_dialog_add_message(gd, GTK_STOCK_DIALOG_QUESTION, _("Clear trash"),
932                                     _("This will remove the trash contents."));
933         generic_dialog_add_button(gd, GTK_STOCK_OK, NULL, safe_delete_clear_ok_cb, TRUE);
934         entry = gtk_entry_new();
935         GTK_WIDGET_UNSET_FLAGS(entry, GTK_CAN_FOCUS);
936         gtk_editable_set_editable(GTK_EDITABLE(entry), FALSE);
937         if (options->file_ops.safe_delete_path) gtk_entry_set_text(GTK_ENTRY(entry), options->file_ops.safe_delete_path);
938         gtk_box_pack_start(GTK_BOX(gd->vbox), entry, FALSE, FALSE, 0);
939         gtk_widget_show(entry);
940         gtk_widget_show(gd->dialog);
941 }
942
943 static void image_overlay_template_view_changed_cb(GtkWidget *widget, gpointer data)
944 {
945         GtkWidget *pTextView;
946         GtkTextBuffer *pTextBuffer;
947         GtkTextIter iStart;
948         GtkTextIter iEnd;
949
950         pTextView = GTK_WIDGET(data);
951
952         pTextBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pTextView));
953         gtk_text_buffer_get_start_iter(pTextBuffer, &iStart);
954         gtk_text_buffer_get_end_iter(pTextBuffer, &iEnd);
955
956         set_image_overlay_template_string(&c_options->image_overlay.template_string,
957                                           gtk_text_buffer_get_text(pTextBuffer, &iStart, &iEnd, TRUE));
958 }
959
960 static void image_overlay_default_template_ok_cb(GenericDialog *gd, gpointer data)
961 {
962         GtkTextView *text_view = data;
963         GtkTextBuffer *buffer;
964
965         set_default_image_overlay_template_string(&options->image_overlay.template_string);
966         if (!configwindow) return;
967
968         buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
969         gtk_text_buffer_set_text(buffer, options->image_overlay.template_string, -1);
970 }
971
972 static void image_overlay_default_template_cb(GtkWidget *widget, gpointer data)
973 {
974         GenericDialog *gd;
975
976         gd = generic_dialog_new(_("Reset image overlay template string"),
977                                 "reset_image_overlay_template_string", widget, TRUE,
978                                 dummy_cancel_cb, data);
979         generic_dialog_add_message(gd, GTK_STOCK_DIALOG_QUESTION, _("Reset image overlay template string"),
980                                    _("This will reset the image overlay template string to the default.\nContinue?"));
981         generic_dialog_add_button(gd, GTK_STOCK_OK, NULL, image_overlay_default_template_ok_cb, TRUE);
982         gtk_widget_show(gd->dialog);
983 }
984
985 static void image_overlay_help_cb(GtkWidget *widget, gpointer data)
986 {
987         help_window_show("overlay");
988 }
989
990 static GtkWidget *scrolled_notebook_page(GtkWidget *notebook, const gchar *title)
991 {
992         GtkWidget *label;
993         GtkWidget *vbox;
994         GtkWidget *scrolled;
995         GtkWidget *viewport;
996
997         scrolled = gtk_scrolled_window_new(NULL, NULL);
998         gtk_container_set_border_width(GTK_CONTAINER(scrolled), PREF_PAD_BORDER);
999         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
1000                                        GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1001         label = gtk_label_new(title);
1002         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scrolled, label);
1003         gtk_widget_show(scrolled);
1004
1005         viewport = gtk_viewport_new(NULL, NULL);
1006         gtk_viewport_set_shadow_type(GTK_VIEWPORT(viewport), GTK_SHADOW_NONE);
1007         gtk_container_add(GTK_CONTAINER(scrolled), viewport);
1008         gtk_widget_show(viewport);
1009
1010         vbox = gtk_vbox_new(FALSE, 0);
1011         gtk_container_add(GTK_CONTAINER(viewport), vbox);
1012         gtk_widget_show(vbox);
1013
1014         return vbox;
1015 }
1016
1017 /* general options tab */
1018 static void config_tab_general(GtkWidget *notebook)
1019 {
1020         GtkWidget *hbox;
1021         GtkWidget *vbox;
1022         GtkWidget *subvbox;
1023         GtkWidget *group;
1024         GtkWidget *subgroup;
1025         GtkWidget *button;
1026         GtkWidget *tabcomp;
1027         GtkWidget *ct_button;
1028         GtkWidget *table;
1029         GtkWidget *spin;
1030
1031         vbox = scrolled_notebook_page(notebook, _("General"));
1032
1033         group = pref_group_new(vbox, FALSE, _("Startup"), GTK_ORIENTATION_VERTICAL);
1034
1035         button = pref_checkbox_new_int(group, _("Restore folder on startup"),
1036                                        options->startup.restore_path, &c_options->startup.restore_path);
1037
1038         subvbox = pref_box_new(group, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_SPACE);
1039         pref_checkbox_link_sensitivity(button, subvbox);
1040
1041         hbox = pref_box_new(subvbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
1042
1043         tabcomp = tab_completion_new(&startup_path_entry, options->startup.path, NULL, NULL);
1044         tab_completion_add_select_button(startup_path_entry, NULL, TRUE);
1045         gtk_box_pack_start(GTK_BOX(hbox), tabcomp, TRUE, TRUE, 0);
1046         gtk_widget_show(tabcomp);
1047
1048         button = pref_button_new(hbox, NULL, _("Use current"), FALSE,
1049                                  G_CALLBACK(startup_path_set_current), NULL);
1050
1051         button = pref_checkbox_new_int(subvbox, _("Use last path"),
1052                                        options->startup.use_last_path, &c_options->startup.use_last_path);
1053         pref_checkbox_link_sensitivity_swap(button, hbox);
1054
1055
1056         group = pref_group_new(vbox, FALSE, _("Thumbnails"), GTK_ORIENTATION_VERTICAL);
1057
1058         table = pref_table_new(group, 2, 2, FALSE, FALSE);
1059         add_thumb_size_menu(table, 0, 0, _("Size:"));
1060         add_quality_menu(table, 0, 1, _("Quality:"), options->thumbnails.quality, &c_options->thumbnails.quality);
1061
1062         ct_button = pref_checkbox_new_int(group, _("Cache thumbnails"),
1063                                           options->thumbnails.enable_caching, &c_options->thumbnails.enable_caching);
1064
1065         subgroup = pref_box_new(group, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
1066         pref_checkbox_link_sensitivity(ct_button, subgroup);
1067
1068         button = pref_checkbox_new_int(subgroup, _("Use shared thumbnail cache"),
1069                                        options->thumbnails.spec_standard, &c_options->thumbnails.spec_standard);
1070
1071         subgroup = pref_box_new(subgroup, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
1072         pref_checkbox_link_sensitivity_swap(button, subgroup);
1073
1074         pref_checkbox_new_int(subgroup, _("Cache thumbnails into .thumbnails"),
1075                               options->thumbnails.cache_into_dirs, &c_options->thumbnails.cache_into_dirs);
1076
1077 #if 0
1078         pref_checkbox_new_int(subgroup, _("Use xvpics thumbnails when found (read only)"),
1079                               options->thumbnails.use_xvpics, &c_options->thumbnails.use_xvpics);
1080 #endif
1081
1082         pref_checkbox_new_int(group, _("Faster jpeg thumbnailing (may reduce quality)"),
1083                               options->thumbnails.fast, &c_options->thumbnails.fast);
1084
1085         pref_checkbox_new_int(group, _("Use EXIF thumbnails when available"),
1086                               options->thumbnails.use_exif, &c_options->thumbnails.use_exif);
1087
1088         group = pref_group_new(vbox, FALSE, _("Slide show"), GTK_ORIENTATION_VERTICAL);
1089
1090         c_options->slideshow.delay = options->slideshow.delay;
1091         spin = pref_spin_new(group, _("Delay between image change:"), _("seconds"),
1092                              SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS, 1.0, 1,
1093                              options->slideshow.delay ? (gdouble)options->slideshow.delay / SLIDESHOW_SUBSECOND_PRECISION : 10.0,
1094                              G_CALLBACK(slideshow_delay_cb), NULL);
1095         gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(spin), GTK_UPDATE_ALWAYS);
1096
1097         pref_checkbox_new_int(group, _("Random"), options->slideshow.random, &c_options->slideshow.random);
1098         pref_checkbox_new_int(group, _("Repeat"), options->slideshow.repeat, &c_options->slideshow.repeat);
1099 }
1100
1101 /* image tab */
1102 static void config_tab_image(GtkWidget *notebook)
1103 {
1104         GtkWidget *hbox;
1105         GtkWidget *vbox;
1106         GtkWidget *group;
1107         GtkWidget *button;
1108         GtkWidget *ct_button;
1109         GtkWidget *table;
1110         GtkWidget *spin;
1111
1112         vbox = scrolled_notebook_page(notebook, _("Image"));
1113
1114         group = pref_group_new(vbox, FALSE, _("Zoom"), GTK_ORIENTATION_VERTICAL);
1115
1116 #if 0
1117         add_dither_menu(dither_quality, &c_options->image.dither_quality, _("Dithering method:"), group);
1118 #endif
1119         table = pref_table_new(group, 2, 1, FALSE, FALSE);
1120         add_quality_menu(table, 0, 0, _("Quality:"), options->image.zoom_quality, &c_options->image.zoom_quality);
1121
1122         pref_checkbox_new_int(group, _("Two pass zooming"),
1123                               options->image.zoom_2pass, &c_options->image.zoom_2pass);
1124
1125         pref_checkbox_new_int(group, _("Allow enlargement of image for zoom to fit"),
1126                               options->image.zoom_to_fit_allow_expand, &c_options->image.zoom_to_fit_allow_expand);
1127
1128         hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
1129         ct_button = pref_checkbox_new_int(hbox, _("Limit image size when autofitting (%):"),
1130                                           options->image.limit_autofit_size, &c_options->image.limit_autofit_size);
1131         spin = pref_spin_new_int(hbox, NULL, NULL,
1132                                  10, 150, 1,
1133                                  options->image.max_autofit_size, &c_options->image.max_autofit_size);
1134         pref_checkbox_link_sensitivity(ct_button, spin);
1135
1136         c_options->image.zoom_increment = options->image.zoom_increment;
1137         spin = pref_spin_new(group, _("Zoom increment:"), NULL,
1138                              0.1, 4.0, 0.1, 1, (gdouble)options->image.zoom_increment / 10.0,
1139                              G_CALLBACK(zoom_increment_cb), NULL);
1140         gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(spin), GTK_UPDATE_ALWAYS);
1141
1142         group = pref_group_new(vbox, FALSE, _("When new image is selected:"), GTK_ORIENTATION_VERTICAL);
1143
1144         c_options->image.zoom_mode = options->image.zoom_mode;
1145         button = pref_radiobutton_new(group, NULL, _("Zoom to original size"),
1146                                       (options->image.zoom_mode == ZOOM_RESET_ORIGINAL),
1147                                       G_CALLBACK(zoom_mode_cb), GINT_TO_POINTER(ZOOM_RESET_ORIGINAL));
1148         button = pref_radiobutton_new(group, button, _("Fit image to window"),
1149                                       (options->image.zoom_mode == ZOOM_RESET_FIT_WINDOW),
1150                                       G_CALLBACK(zoom_mode_cb), GINT_TO_POINTER(ZOOM_RESET_FIT_WINDOW));
1151         button = pref_radiobutton_new(group, button, _("Leave Zoom at previous setting"),
1152                                       (options->image.zoom_mode == ZOOM_RESET_NONE),
1153                                       G_CALLBACK(zoom_mode_cb), GINT_TO_POINTER(ZOOM_RESET_NONE));
1154
1155         group = pref_group_new(vbox, FALSE, _("Scroll reset method:"), GTK_ORIENTATION_VERTICAL);
1156
1157         c_options->image.scroll_reset_method = options->image.scroll_reset_method;
1158         button = pref_radiobutton_new(group, NULL, _("Top left"),
1159                                       (options->image.scroll_reset_method == SCROLL_RESET_TOPLEFT),
1160                                       G_CALLBACK(scroll_reset_cb), GINT_TO_POINTER(SCROLL_RESET_TOPLEFT));
1161         button = pref_radiobutton_new(group, button, _("Center"),
1162                                       (options->image.scroll_reset_method == SCROLL_RESET_CENTER),
1163                                       G_CALLBACK(scroll_reset_cb), GINT_TO_POINTER(SCROLL_RESET_CENTER));
1164         button = pref_radiobutton_new(group, button, _("No change"),
1165                                       (options->image.scroll_reset_method == SCROLL_RESET_NOCHANGE),
1166                                       G_CALLBACK(scroll_reset_cb), GINT_TO_POINTER(SCROLL_RESET_NOCHANGE));
1167
1168
1169         group = pref_group_new(vbox, FALSE, _("Appearance"), GTK_ORIENTATION_VERTICAL);
1170
1171         pref_checkbox_new_int(group, _("Custom border color"),
1172                               options->image.use_custom_border_color, &c_options->image.use_custom_border_color);
1173
1174         pref_color_button_new(group, _("Border color"), &options->image.border_color,
1175                               G_CALLBACK(pref_color_button_set_cb), &c_options->image.border_color);
1176
1177         group = pref_group_new(vbox, FALSE, _("Convenience"), GTK_ORIENTATION_VERTICAL);
1178
1179         pref_checkbox_new_int(group, _("Refresh on file change"),
1180                               options->update_on_time_change, &c_options->update_on_time_change);
1181         pref_checkbox_new_int(group, _("Preload next image"),
1182                               options->image.enable_read_ahead, &c_options->image.enable_read_ahead);
1183         pref_checkbox_new_int(group, _("Auto rotate image using Exif information"),
1184                               options->image.exif_rotate_enable, &c_options->image.exif_rotate_enable);
1185 }
1186
1187 /* windows tab */
1188 static void config_tab_windows(GtkWidget *notebook)
1189 {
1190         GtkWidget *hbox;
1191         GtkWidget *vbox;
1192         GtkWidget *group;
1193         GtkWidget *ct_button;
1194         GtkWidget *spin;
1195
1196         vbox = scrolled_notebook_page(notebook, _("Windows"));
1197
1198         group = pref_group_new(vbox, FALSE, _("State"), GTK_ORIENTATION_VERTICAL);
1199
1200         pref_checkbox_new_int(group, _("Remember window positions"),
1201                               options->layout.save_window_positions, &c_options->layout.save_window_positions);
1202         pref_checkbox_new_int(group, _("Remember tool state (float/hidden)"),
1203                               options->layout.tools_restore_state, &c_options->layout.tools_restore_state);
1204
1205         group = pref_group_new(vbox, FALSE, _("Size"), GTK_ORIENTATION_VERTICAL);
1206
1207         pref_checkbox_new_int(group, _("Fit window to image when tools are hidden/floating"),
1208                               options->image.fit_window_to_image, &c_options->image.fit_window_to_image);
1209
1210         hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
1211         ct_button = pref_checkbox_new_int(hbox, _("Limit size when auto-sizing window (%):"),
1212                                           options->image.limit_window_size, &c_options->image.limit_window_size);
1213         spin = pref_spin_new_int(hbox, NULL, NULL,
1214                                  10, 150, 1,
1215                                  options->image.max_window_size, &c_options->image.max_window_size);
1216         pref_checkbox_link_sensitivity(ct_button, spin);
1217
1218         group = pref_group_new(vbox, FALSE, _("Layout"), GTK_ORIENTATION_VERTICAL);
1219
1220         layout_widget = layout_config_new();
1221         layout_config_set(layout_widget, options->layout.style, options->layout.order);
1222         gtk_box_pack_start(GTK_BOX(group), layout_widget, FALSE, FALSE, 0);
1223         gtk_widget_show(layout_widget);
1224 }
1225
1226 static GtkTreeModel *create_class_model(void)
1227 {
1228         GtkListStore *model;
1229         GtkTreeIter iter;
1230         gint i;
1231
1232         /* create list store */
1233         model = gtk_list_store_new(1, G_TYPE_STRING);
1234         for (i = 0; i < FILE_FORMAT_CLASSES; i++)
1235                 {
1236                 gtk_list_store_append(model, &iter);
1237                 gtk_list_store_set(model, &iter, 0, _(format_class_list[i]), -1);
1238                 }
1239         return GTK_TREE_MODEL (model);
1240 }
1241
1242
1243 /* filtering tab */
1244 static void config_tab_filtering(GtkWidget *notebook)
1245 {
1246         GtkWidget *hbox;
1247         GtkWidget *frame;
1248         GtkWidget *vbox;
1249         GtkWidget *group;
1250         GtkWidget *button;
1251         GtkWidget *ct_button;
1252         GtkWidget *scrolled;
1253         GtkWidget *filter_view;
1254         GtkCellRenderer *renderer;
1255         GtkTreeSelection *selection;
1256         GtkTreeViewColumn *column;
1257
1258         vbox = scrolled_notebook_page(notebook, _("Filtering"));
1259
1260         group = pref_box_new(vbox, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
1261
1262         pref_checkbox_new_int(group, _("Show hidden files or folders"),
1263                               options->file_filter.show_hidden_files, &c_options->file_filter.show_hidden_files);
1264         pref_checkbox_new_int(group, _("Show dot directory"),
1265                               options->file_filter.show_dot_directory, &c_options->file_filter.show_dot_directory);
1266         pref_checkbox_new_int(group, _("Case sensitive sort"),
1267                               options->file_sort.case_sensitive, &c_options->file_sort.case_sensitive);
1268
1269         ct_button = pref_checkbox_new_int(group, _("Disable File Filtering"),
1270                                           options->file_filter.disable, &c_options->file_filter.disable);
1271
1272
1273         group = pref_group_new(vbox, FALSE, _("Grouping sidecar extensions"), GTK_ORIENTATION_VERTICAL);
1274
1275         sidecar_ext_entry = gtk_entry_new();
1276         gtk_entry_set_text(GTK_ENTRY(sidecar_ext_entry), options->sidecar.ext);
1277         gtk_box_pack_start(GTK_BOX(group), sidecar_ext_entry, FALSE, FALSE, 0);
1278         gtk_widget_show(sidecar_ext_entry);
1279
1280         group = pref_group_new(vbox, TRUE, _("File types"), GTK_ORIENTATION_VERTICAL);
1281
1282         frame = pref_group_parent(group);
1283         g_signal_connect(G_OBJECT(ct_button), "toggled",
1284                          G_CALLBACK(filter_disable_cb), frame);
1285         gtk_widget_set_sensitive(frame, !options->file_filter.disable);
1286
1287         scrolled = gtk_scrolled_window_new(NULL, NULL);
1288         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
1289         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
1290         gtk_box_pack_start(GTK_BOX(group), scrolled, TRUE, TRUE, 0);
1291         gtk_widget_show(scrolled);
1292
1293         filter_store = gtk_list_store_new(1, G_TYPE_POINTER);
1294         filter_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(filter_store));
1295         g_object_unref(filter_store);
1296         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(filter_view));
1297         gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_SINGLE);
1298
1299         gtk_tree_view_set_enable_search(GTK_TREE_VIEW(filter_view), FALSE);
1300
1301         column = gtk_tree_view_column_new();
1302         gtk_tree_view_column_set_title(column, _("Filter"));
1303         gtk_tree_view_column_set_resizable(column, TRUE);
1304
1305         renderer = gtk_cell_renderer_toggle_new();
1306         g_signal_connect(G_OBJECT(renderer), "toggled",
1307                          G_CALLBACK(filter_store_enable_cb), filter_store);
1308         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1309         gtk_tree_view_column_set_cell_data_func(column, renderer, filter_set_func,
1310                                                 GINT_TO_POINTER(FE_ENABLE), NULL);
1311
1312         renderer = gtk_cell_renderer_text_new();
1313         g_signal_connect(G_OBJECT(renderer), "edited",
1314                          G_CALLBACK(filter_store_ext_edit_cb), filter_store);
1315         gtk_tree_view_column_pack_start(column, renderer, TRUE);
1316         g_object_set(G_OBJECT(renderer), "editable", (gboolean)TRUE, NULL);
1317         gtk_tree_view_column_set_cell_data_func(column, renderer, filter_set_func,
1318                                                 GINT_TO_POINTER(FE_EXTENSION), NULL);
1319         gtk_tree_view_append_column(GTK_TREE_VIEW(filter_view), column);
1320
1321         column = gtk_tree_view_column_new();
1322         gtk_tree_view_column_set_title(column, _("Description"));
1323         gtk_tree_view_column_set_resizable(column, TRUE);
1324         renderer = gtk_cell_renderer_text_new();
1325         g_signal_connect(G_OBJECT(renderer), "edited",
1326                          G_CALLBACK(filter_store_desc_edit_cb), filter_store);
1327         g_object_set(G_OBJECT(renderer), "editable", (gboolean)TRUE, NULL);
1328         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1329         gtk_tree_view_column_set_cell_data_func(column, renderer, filter_set_func,
1330                                                 GINT_TO_POINTER(FE_DESCRIPTION), NULL);
1331         gtk_tree_view_append_column(GTK_TREE_VIEW(filter_view), column);
1332
1333         column = gtk_tree_view_column_new();
1334         gtk_tree_view_column_set_title(column, _("Class"));
1335         gtk_tree_view_column_set_resizable(column, TRUE);
1336         renderer = gtk_cell_renderer_combo_new();
1337         g_object_set(G_OBJECT(renderer), "editable", (gboolean)TRUE,
1338                                          "model", create_class_model(),
1339                                          "text-column", 0,
1340                                          "has-entry", FALSE,
1341                                          NULL);
1342
1343         g_signal_connect(G_OBJECT(renderer), "edited",
1344                          G_CALLBACK(filter_store_class_edit_cb), filter_store);
1345         gtk_tree_view_column_pack_start(column, renderer, TRUE);
1346         gtk_tree_view_column_set_cell_data_func(column, renderer, filter_set_func,
1347                                                 GINT_TO_POINTER(FE_CLASS), NULL);
1348         gtk_tree_view_append_column(GTK_TREE_VIEW(filter_view), column);
1349
1350         column = gtk_tree_view_column_new();
1351         gtk_tree_view_column_set_title(column, _("Writable"));
1352         gtk_tree_view_column_set_resizable(column, FALSE);
1353         renderer = gtk_cell_renderer_toggle_new();
1354         g_signal_connect(G_OBJECT(renderer), "toggled",
1355                          G_CALLBACK(filter_store_writable_cb), filter_store);
1356         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1357         gtk_tree_view_column_set_cell_data_func(column, renderer, filter_set_func,
1358                                                 GINT_TO_POINTER(FE_WRITABLE), NULL);
1359         gtk_tree_view_append_column(GTK_TREE_VIEW(filter_view), column);
1360
1361         column = gtk_tree_view_column_new();
1362         gtk_tree_view_column_set_title(column, _("Sidecar is allowed"));
1363         gtk_tree_view_column_set_resizable(column, FALSE);
1364         renderer = gtk_cell_renderer_toggle_new();
1365         g_signal_connect(G_OBJECT(renderer), "toggled",
1366                          G_CALLBACK(filter_store_sidecar_cb), filter_store);
1367         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1368         gtk_tree_view_column_set_cell_data_func(column, renderer, filter_set_func,
1369                                                 GINT_TO_POINTER(FE_ALLOW_SIDECAR), NULL);
1370         gtk_tree_view_append_column(GTK_TREE_VIEW(filter_view), column);
1371
1372
1373         filter_store_populate();
1374         gtk_container_add(GTK_CONTAINER(scrolled), filter_view);
1375         gtk_widget_show(filter_view);
1376
1377         hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_BUTTON_GAP);
1378
1379         button = pref_button_new(NULL, NULL, _("Defaults"), FALSE,
1380                                  G_CALLBACK(filter_default_cb), NULL);
1381         gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1382         gtk_widget_show(button);
1383
1384         button = pref_button_new(NULL, GTK_STOCK_REMOVE, NULL, FALSE,
1385                                  G_CALLBACK(filter_remove_cb), filter_view);
1386         gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1387         gtk_widget_show(button);
1388
1389         button = pref_button_new(NULL, GTK_STOCK_ADD, NULL, FALSE,
1390                                  G_CALLBACK(filter_add_cb), NULL);
1391         gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1392         gtk_widget_show(button);
1393 }
1394 #if 0
1395 /* editors tab */
1396 static void config_tab_editors(GtkWidget *notebook)
1397 {
1398         GtkWidget *hbox;
1399         GtkWidget *label;
1400         GtkWidget *vbox;
1401         GtkWidget *button;
1402         GtkWidget *table;
1403         gint i;
1404
1405         vbox = scrolled_notebook_page(notebook, _("Editors"));
1406
1407         table = pref_table_new(vbox, 3, 9, FALSE, FALSE);
1408         gtk_table_set_col_spacings(GTK_TABLE(table), PREF_PAD_GAP);
1409
1410         label = pref_table_label(table, 0, 0, _("#"), 1.0);
1411         pref_label_bold(label, TRUE, FALSE);
1412
1413         label = pref_table_label(table, 1, 0, _("Menu name"), 0.0);
1414         pref_label_bold(label, TRUE, FALSE);
1415
1416         label = pref_table_label(table, 2, 0, _("Command Line"), 0.0);
1417         pref_label_bold(label, TRUE, FALSE);
1418
1419         for (i = 0; i < GQ_EDITOR_SLOTS; i++)
1420                 {
1421                 GtkWidget *entry;
1422
1423                 if (i < GQ_EDITOR_GENERIC_SLOTS)
1424                         {
1425                         gchar *buf;
1426
1427                         buf = g_strdup_printf("%d", i+1);
1428                         pref_table_label(table, 0, i+1, buf, 1.0);
1429                         g_free(buf);
1430                         entry = gtk_entry_new();
1431                         gtk_entry_set_max_length(GTK_ENTRY(entry), EDITOR_NAME_MAX_LENGTH);
1432                         gtk_widget_set_size_request(entry, 80, -1);
1433                         if (options->editor[i].name)
1434                                 gtk_entry_set_text(GTK_ENTRY(entry), options->editor[i].name);
1435                         }
1436                 else
1437                         {
1438                         entry = gtk_label_new(options->editor[i].name);
1439                         gtk_misc_set_alignment(GTK_MISC(entry), 0.0, 0.5);
1440                         }
1441
1442                 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, i+1, i+2,
1443                                  GTK_FILL | GTK_SHRINK, 0, 0, 0);
1444                 gtk_widget_show(entry);
1445                 editor_name_entry[i] = entry;
1446
1447                 entry = gtk_entry_new();
1448                 gtk_entry_set_max_length(GTK_ENTRY(entry), EDITOR_COMMAND_MAX_LENGTH);
1449                 gtk_widget_set_size_request(entry, 160, -1);
1450                 tab_completion_add_to_entry(entry, NULL, NULL);
1451                 if (options->editor[i].command)
1452                         gtk_entry_set_text(GTK_ENTRY(entry), options->editor[i].command);
1453                 gtk_table_attach(GTK_TABLE(table), entry, 2, 3, i+1, i+2,
1454                                  GTK_FILL | GTK_EXPAND, 0, 0, 0);
1455                 gtk_widget_show(entry);
1456                 editor_command_entry[i] = entry;
1457                 }
1458
1459         hbox = pref_box_new(vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_BUTTON_GAP);
1460
1461         button = pref_button_new(NULL, NULL, _("Defaults"), FALSE,
1462                                  G_CALLBACK(editor_default_cb), NULL);
1463         gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1464         gtk_widget_show(button);
1465
1466         button = pref_button_new(NULL, GTK_STOCK_HELP, NULL, FALSE,
1467                                  G_CALLBACK(editor_help_cb), NULL);
1468         gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1469         gtk_widget_show(button);
1470 }
1471 #endif
1472
1473 /* properties tab */
1474 static void config_tab_properties(GtkWidget *notebook)
1475 {
1476         GtkWidget *label;
1477         GtkWidget *vbox;
1478         GtkWidget *group;
1479         GtkWidget *table;
1480         gint i;
1481
1482         vbox = scrolled_notebook_page(notebook, _("Properties"));
1483
1484         group = pref_group_new(vbox, FALSE, _("Exif"),
1485                                GTK_ORIENTATION_VERTICAL);
1486
1487
1488         pref_spacer(group, PREF_PAD_INDENT - PREF_PAD_SPACE);
1489         label = pref_label_new(group, _("What to show in properties dialog:"));
1490         gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
1491
1492         table = pref_table_new(group, 2, 2, FALSE, FALSE);
1493
1494 #if 0
1495         for (i = 0; ExifUIList[i].key; i++)
1496                 {
1497                 gchar *title;
1498
1499                 title = exif_get_description_by_key(ExifUIList[i].key);
1500                 exif_item(table, 0, i, title, ExifUIList[i].current,
1501                           &ExifUIList[i].temp);
1502                 g_free(title);
1503                 }
1504 #endif
1505 }
1506
1507 /* advanced entry tab */
1508 static void config_tab_advanced(GtkWidget *notebook)
1509 {
1510         GtkWidget *label;
1511         GtkWidget *hbox;
1512         GtkWidget *vbox;
1513         GtkWidget *group;
1514         GtkWidget *button;
1515         GtkWidget *tabcomp;
1516         GtkWidget *ct_button;
1517         GtkWidget *table;
1518         GtkWidget *spin;
1519         GtkWidget *image_overlay_template_view;
1520         GtkWidget *scrolled;
1521         GtkTextBuffer *buffer;
1522         gint i;
1523
1524         vbox = scrolled_notebook_page(notebook, _("Advanced"));
1525
1526         group = pref_group_new(vbox, FALSE, _("Full screen"), GTK_ORIENTATION_VERTICAL);
1527
1528         c_options->fullscreen.screen = options->fullscreen.screen;
1529         c_options->fullscreen.above = options->fullscreen.above;
1530         hbox = fullscreen_prefs_selection_new(_("Location:"), &c_options->fullscreen.screen, &c_options->fullscreen.above);
1531         gtk_box_pack_start(GTK_BOX(group), hbox, FALSE, FALSE, 0);
1532         gtk_widget_show(hbox);
1533
1534         pref_checkbox_new_int(group, _("Smooth image flip"),
1535                               options->fullscreen.clean_flip, &c_options->fullscreen.clean_flip);
1536         pref_checkbox_new_int(group, _("Disable screen saver"),
1537                               options->fullscreen.disable_saver, &c_options->fullscreen.disable_saver);
1538
1539
1540         group = pref_group_new(vbox, FALSE, _("Overlay Screen Display"), GTK_ORIENTATION_VERTICAL);
1541
1542         pref_label_new(group, _("Image overlay template"));
1543
1544         scrolled = gtk_scrolled_window_new(NULL, NULL);
1545         gtk_widget_set_size_request(scrolled, 200, 150);
1546         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
1547         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
1548                                        GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1549         gtk_box_pack_start(GTK_BOX(group), scrolled, TRUE, TRUE, 5);
1550         gtk_widget_show(scrolled);
1551
1552         image_overlay_template_view = gtk_text_view_new();
1553
1554 #if GTK_CHECK_VERSION(2,12,0)
1555         gtk_widget_set_tooltip_markup(image_overlay_template_view,
1556         _("<i>%name%</i> results in the filename of the picture.\n"
1557           "Also available: <i>%collection%</i>, <i>%number%</i>, <i>%total%</i>, <i>%date%</i>,\n"
1558           "<i>%size%</i> (filesize), <i>%width%</i>, <i>%height%</i>, <i>%res%</i> (resolution)\n"
1559           "To access exif data use the exif name, e. g. <i>%formatted.Camera%</i> is the formatted camera name,\n"
1560           "<i>%Exif.Photo.DateTimeOriginal%</i> the date of the original shot.\n"
1561           "<i>%formatted.Camera:20</i> notation will truncate the displayed data to 20 characters and will add 3 dots at the end to denote the truncation.\n"
1562           "If two or more variables are connected with the |-sign, it prints available variables with a separator.\n"
1563           "<i>%formatted.ShutterSpeed%</i>|<i>%formatted.ISOSpeedRating%</i>|<i>%formatted.FocalLength%</i> could show \"1/20s - 400 - 80 mm\" or \"1/200 - 80 mm\",\n"
1564           "if there's no ISO information in the Exif data.\n"
1565           "If a line is empty, it is removed. This allows to add lines that totally disappear when no data is available.\n"
1566 ));
1567 #endif
1568         gtk_container_add(GTK_CONTAINER(scrolled), image_overlay_template_view);
1569         gtk_widget_show(image_overlay_template_view);
1570
1571         hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_BUTTON_GAP);
1572
1573         button = pref_button_new(NULL, NULL, _("Defaults"), FALSE,
1574                                  G_CALLBACK(image_overlay_default_template_cb), image_overlay_template_view);
1575         gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1576         gtk_widget_show(button);
1577
1578         button = pref_button_new(NULL, GTK_STOCK_HELP, NULL, FALSE,
1579                                  G_CALLBACK(image_overlay_help_cb), NULL);
1580         gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1581         gtk_widget_show(button);
1582
1583         buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(image_overlay_template_view));
1584         if (options->image_overlay.template_string) gtk_text_buffer_set_text(buffer, options->image_overlay.template_string, -1);
1585         g_signal_connect(G_OBJECT(buffer), "changed",
1586                          G_CALLBACK(image_overlay_template_view_changed_cb), image_overlay_template_view);
1587
1588         group = pref_group_new(vbox, FALSE, _("Delete"), GTK_ORIENTATION_VERTICAL);
1589
1590         pref_checkbox_new_int(group, _("Confirm file delete"),
1591                               options->file_ops.confirm_delete, &c_options->file_ops.confirm_delete);
1592         pref_checkbox_new_int(group, _("Enable Delete key"),
1593                               options->file_ops.enable_delete_key, &c_options->file_ops.enable_delete_key);
1594
1595         ct_button = pref_checkbox_new_int(group, _("Safe delete"),
1596                                           options->file_ops.safe_delete_enable, &c_options->file_ops.safe_delete_enable);
1597
1598         hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
1599         pref_checkbox_link_sensitivity(ct_button, hbox);
1600
1601         pref_spacer(hbox, PREF_PAD_INDENT - PREF_PAD_SPACE);
1602         pref_label_new(hbox, _("Folder:"));
1603
1604         tabcomp = tab_completion_new(&safe_delete_path_entry, options->file_ops.safe_delete_path, NULL, NULL);
1605         tab_completion_add_select_button(safe_delete_path_entry, NULL, TRUE);
1606         gtk_box_pack_start(GTK_BOX(hbox), tabcomp, TRUE, TRUE, 0);
1607         gtk_widget_show(tabcomp);
1608
1609         hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_BUTTON_GAP);
1610         pref_checkbox_link_sensitivity(ct_button, hbox);
1611
1612         pref_spacer(hbox, PREF_PAD_INDENT - PREF_PAD_GAP);
1613         spin = pref_spin_new_int(hbox, _("Maximum size:"), _("MB"),
1614                                  0, 2048, 1, options->file_ops.safe_delete_folder_maxsize, &c_options->file_ops.safe_delete_folder_maxsize);
1615 #if GTK_CHECK_VERSION(2,12,0)
1616         gtk_widget_set_tooltip_markup(spin, _("Set to 0 for unlimited size"));
1617 #endif
1618         button = pref_button_new(NULL, NULL, _("View"), FALSE,
1619                                  G_CALLBACK(safe_delete_view_cb), NULL);
1620         gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1621         gtk_widget_show(button);
1622
1623         button = pref_button_new(NULL, GTK_STOCK_CLEAR, NULL, FALSE,
1624                                  G_CALLBACK(safe_delete_clear_cb), NULL);
1625         gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1626         gtk_widget_show(button);
1627
1628
1629         group = pref_group_new(vbox, FALSE, _("Behavior"), GTK_ORIENTATION_VERTICAL);
1630
1631         pref_checkbox_new_int(group, _("Rectangular selection in icon view"),
1632                               options->collections.rectangular_selection, &c_options->collections.rectangular_selection);
1633
1634         pref_checkbox_new_int(group, _("Descend folders in tree view"),
1635                               options->tree_descend_subdirs, &c_options->tree_descend_subdirs);
1636
1637         pref_checkbox_new_int(group, _("Show date in directories list view"),
1638                               options->layout.show_directory_date, &c_options->layout.show_directory_date);
1639
1640         pref_checkbox_new_int(group, _("In place renaming"),
1641                               options->file_ops.enable_in_place_rename, &c_options->file_ops.enable_in_place_rename);
1642
1643         pref_checkbox_new_int(group, _("Show \"Copy path\" menu item which write the path of selected files to clipboard"),
1644                               options->show_copy_path, &c_options->show_copy_path);
1645
1646         pref_spin_new_int(group, _("Open recent list maximum size"), NULL,
1647                           1, 50, 1, options->open_recent_list_maxsize, &c_options->open_recent_list_maxsize);
1648         
1649         pref_spin_new_int(group, _("Drag'n drop icon size"), NULL,
1650                           16, 256, 16, options->dnd_icon_size, &c_options->dnd_icon_size);
1651
1652         group = pref_group_new(vbox, FALSE, _("Navigation"), GTK_ORIENTATION_VERTICAL);
1653
1654         pref_checkbox_new_int(group, _("Progressive keyboard scrolling"),
1655                               options->progressive_key_scrolling, &c_options->progressive_key_scrolling);
1656         pref_checkbox_new_int(group, _("Mouse wheel scrolls image"),
1657                               options->mousewheel_scrolls, &c_options->mousewheel_scrolls);
1658
1659         pref_label_new(group, _("Home button path (empty to use your home directory)"));
1660         hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
1661
1662         tabcomp = tab_completion_new(&home_path_entry, options->layout.home_path, NULL, NULL);
1663         tab_completion_add_select_button(home_path_entry, NULL, TRUE);
1664         gtk_box_pack_start(GTK_BOX(hbox), tabcomp, TRUE, TRUE, 0);
1665         gtk_widget_show(tabcomp);
1666
1667         button = pref_button_new(hbox, NULL, _("Use current"), FALSE,
1668                                  G_CALLBACK(home_path_set_current), NULL);
1669
1670
1671         group = pref_group_new(vbox, FALSE, _("Metadata"), GTK_ORIENTATION_VERTICAL);
1672
1673         pref_checkbox_new_int(group, _("Store metadata and cache files in source image's directory"),
1674                               options->metadata.enable_metadata_dirs, &c_options->metadata.enable_metadata_dirs);
1675
1676         ct_button = pref_checkbox_new_int(group, _("Store keywords and comments as XMP tags in image files"),
1677                               options->metadata.save_in_image_file, &c_options->metadata.save_in_image_file);
1678
1679         hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_SPACE);
1680         pref_checkbox_link_sensitivity(ct_button, hbox);
1681
1682         pref_checkbox_new_int(hbox, _("Store keywords and comments also in legacy IPTC tags"),
1683                               options->metadata.save_legacy_IPTC, &c_options->metadata.save_legacy_IPTC);
1684
1685         pref_checkbox_new_int(hbox, _("Warn if the image files are unwritable"),
1686                               options->metadata.warn_on_write_problems, &c_options->metadata.warn_on_write_problems);
1687
1688         pref_checkbox_new_int(hbox, _("Ask before writing to image files"),
1689                               options->metadata.confirm_write, &c_options->metadata.confirm_write);
1690
1691         pref_checkbox_new_int(group, _("Save metadata in GQview legacy metadata format"),
1692                               options->metadata.save_legacy_format, &c_options->metadata.save_legacy_format);
1693
1694         pref_checkbox_new_int(group, _("Write the same keywords and comment to all files in a group"),
1695                               options->metadata.sync_grouped_files, &c_options->metadata.sync_grouped_files);
1696
1697         ct_button = pref_checkbox_new_int(group, _("Write metadata after timeout"),
1698                               options->metadata.confirm_after_timeout, &c_options->metadata.confirm_after_timeout);
1699
1700         hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
1701         pref_checkbox_link_sensitivity(ct_button, hbox);
1702
1703         pref_spin_new_int(hbox, _("Timeout (seconds):"), NULL, 0, 900, 1,
1704                               options->metadata.confirm_timeout, &c_options->metadata.confirm_timeout);
1705                               
1706         pref_checkbox_new_int(group, _("Write metadata on image change"),
1707                               options->metadata.confirm_on_image_change, &c_options->metadata.confirm_on_image_change);
1708
1709         pref_checkbox_new_int(group, _("Write metadata on directory change"),
1710                               options->metadata.confirm_on_dir_change, &c_options->metadata.confirm_on_dir_change);
1711
1712         group = pref_group_new(vbox, FALSE, _("Miscellaneous"), GTK_ORIENTATION_VERTICAL);
1713
1714         pref_spin_new_int(group, _("Custom similarity threshold:"), NULL,
1715                           0, 100, 1, options->duplicates_similarity_threshold, (int *)&c_options->duplicates_similarity_threshold);
1716
1717         group = pref_group_new(vbox, FALSE, _("Image loading and caching"), GTK_ORIENTATION_VERTICAL);
1718
1719         pref_spin_new_int(group, _("Offscreen cache size (Mb per image):"), NULL,
1720                           0, 128, 1, options->image.tile_cache_max, &c_options->image.tile_cache_max);
1721
1722         pref_spin_new_int(group, _("Decoded image cache size (Mb):"), NULL,
1723                           0, 1024, 1, options->image.image_cache_max, &c_options->image.image_cache_max);
1724
1725         pref_spin_new_int(group, _("Image read buffer size (bytes):"), NULL,
1726                           IMAGE_LOADER_READ_BUFFER_SIZE_MIN, IMAGE_LOADER_READ_BUFFER_SIZE_MAX, 512,
1727                           options->image.read_buffer_size, &c_options->image.read_buffer_size);
1728
1729         pref_spin_new_int(group, _("Image idle loop read count:"), NULL,
1730                           IMAGE_LOADER_IDLE_READ_LOOP_COUNT_MIN, IMAGE_LOADER_IDLE_READ_LOOP_COUNT_MAX, 1,
1731                           options->image.idle_read_loop_count, &c_options->image.idle_read_loop_count);
1732
1733
1734         group =  pref_group_new(vbox, FALSE, _("Color profiles"), GTK_ORIENTATION_VERTICAL);
1735 #ifndef HAVE_LCMS
1736         gtk_widget_set_sensitive(pref_group_parent(group), FALSE);
1737 #endif
1738
1739         table = pref_table_new(group, 3, COLOR_PROFILE_INPUTS + 2, FALSE, FALSE);
1740         gtk_table_set_col_spacings(GTK_TABLE(table), PREF_PAD_GAP);
1741
1742         label = pref_table_label(table, 0, 0, _("Type"), 0.0);
1743         pref_label_bold(label, TRUE, FALSE);
1744
1745         label = pref_table_label(table, 1, 0, _("Menu name"), 0.0);
1746         pref_label_bold(label, TRUE, FALSE);
1747
1748         label = pref_table_label(table, 2, 0, _("File"), 0.0);
1749         pref_label_bold(label, TRUE, FALSE);
1750
1751         for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
1752                 {
1753                 GtkWidget *entry;
1754                 gchar *buf;
1755
1756                 buf = g_strdup_printf("Input %d:", i + COLOR_PROFILE_FILE);
1757                 pref_table_label(table, 0, i + 1, buf, 1.0);
1758                 g_free(buf);
1759
1760                 entry = gtk_entry_new();
1761                 gtk_entry_set_max_length(GTK_ENTRY(entry), EDITOR_NAME_MAX_LENGTH);
1762 //              gtk_widget_set_size_request(editor_name_entry[i], 30, -1);
1763                 if (options->color_profile.input_name[i])
1764                         {
1765                         gtk_entry_set_text(GTK_ENTRY(entry), options->color_profile.input_name[i]);
1766                         }
1767                 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, i + 1, i + 2,
1768                                  GTK_FILL | GTK_EXPAND, 0, 0, 0);
1769                 gtk_widget_show(entry);
1770                 color_profile_input_name_entry[i] = entry;
1771
1772                 tabcomp = tab_completion_new(&entry, options->color_profile.input_file[i], NULL, NULL);
1773                 tab_completion_add_select_button(entry, _("Select color profile"), FALSE);
1774                 gtk_widget_set_size_request(entry, 160, -1);
1775                 gtk_table_attach(GTK_TABLE(table), tabcomp, 2, 3, i + 1, i + 2,
1776                                  GTK_FILL | GTK_EXPAND, 0, 0, 0);
1777                 gtk_widget_show(tabcomp);
1778                 color_profile_input_file_entry[i] = entry;
1779                 }
1780
1781         pref_table_label(table, 0, COLOR_PROFILE_INPUTS + 1, _("Screen:"), 1.0);
1782         tabcomp = tab_completion_new(&color_profile_screen_file_entry,
1783                                      options->color_profile.screen_file, NULL, NULL);
1784         tab_completion_add_select_button(color_profile_screen_file_entry, _("Select color profile"), FALSE);
1785         gtk_widget_set_size_request(color_profile_screen_file_entry, 160, -1);
1786         gtk_table_attach(GTK_TABLE(table), tabcomp, 2, 3,
1787                          COLOR_PROFILE_INPUTS + 1, COLOR_PROFILE_INPUTS + 2,
1788                          GTK_FILL | GTK_EXPAND, 0, 0, 0);
1789         gtk_widget_show(tabcomp);
1790
1791 #ifdef DEBUG
1792         group = pref_group_new(vbox, FALSE, _("Debugging"), GTK_ORIENTATION_VERTICAL);
1793
1794         pref_spin_new_int(group, _("Debug level:"), NULL,
1795                           DEBUG_LEVEL_MIN, DEBUG_LEVEL_MAX, 1, get_debug_level(), &debug_c);
1796 #endif
1797 }
1798
1799 /* Main preferences window */
1800 static void config_window_create(void)
1801 {
1802         GtkWidget *win_vbox;
1803         GtkWidget *hbox;
1804         GtkWidget *notebook;
1805         GtkWidget *button;
1806         GtkWidget *ct_button;
1807
1808         if (!c_options) c_options = init_options(NULL);
1809
1810         configwindow = window_new(GTK_WINDOW_TOPLEVEL, "preferences", PIXBUF_INLINE_ICON_CONFIG, NULL, _("Preferences"));
1811         gtk_window_set_type_hint(GTK_WINDOW(configwindow), GDK_WINDOW_TYPE_HINT_DIALOG);
1812         g_signal_connect(G_OBJECT(configwindow), "delete_event",
1813                          G_CALLBACK(config_window_delete), NULL);
1814         gtk_window_set_default_size(GTK_WINDOW(configwindow), CONFIG_WINDOW_DEF_WIDTH, CONFIG_WINDOW_DEF_HEIGHT);
1815         gtk_window_set_resizable(GTK_WINDOW(configwindow), TRUE);
1816         gtk_container_set_border_width(GTK_CONTAINER(configwindow), PREF_PAD_BORDER);
1817
1818         win_vbox = gtk_vbox_new(FALSE, PREF_PAD_SPACE);
1819         gtk_container_add(GTK_CONTAINER(configwindow), win_vbox);
1820         gtk_widget_show(win_vbox);
1821
1822         hbox = gtk_hbutton_box_new();
1823         gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END);
1824         gtk_box_set_spacing(GTK_BOX(hbox), PREF_PAD_BUTTON_GAP);
1825         gtk_box_pack_end(GTK_BOX(win_vbox), hbox, FALSE, FALSE, 0);
1826         gtk_widget_show(hbox);
1827
1828         button = pref_button_new(NULL, GTK_STOCK_OK, NULL, FALSE,
1829                                  G_CALLBACK(config_window_ok_cb), NULL);
1830         gtk_container_add(GTK_CONTAINER(hbox), button);
1831         GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1832         gtk_widget_grab_default(button);
1833         gtk_widget_show(button);
1834
1835         ct_button = button;
1836
1837         button = pref_button_new(NULL, GTK_STOCK_SAVE, NULL, FALSE,
1838                                  G_CALLBACK(config_window_save_cb), NULL);
1839         gtk_container_add(GTK_CONTAINER(hbox), button);
1840         GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1841         gtk_widget_show(button);
1842         
1843         button = pref_button_new(NULL, GTK_STOCK_APPLY, NULL, FALSE,
1844                                  G_CALLBACK(config_window_apply_cb), NULL);
1845         gtk_container_add(GTK_CONTAINER(hbox), button);
1846         GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1847         gtk_widget_show(button);
1848
1849         button = pref_button_new(NULL, GTK_STOCK_CANCEL, NULL, FALSE,
1850                                  G_CALLBACK(config_window_close_cb), NULL);
1851         gtk_container_add(GTK_CONTAINER(hbox), button);
1852         GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1853         gtk_widget_show(button);
1854
1855         if (!generic_dialog_get_alternative_button_order(configwindow))
1856                 {
1857                 gtk_box_reorder_child(GTK_BOX(hbox), ct_button, -1);
1858                 }
1859
1860         notebook = gtk_notebook_new();
1861         gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP);
1862         gtk_box_pack_start(GTK_BOX(win_vbox), notebook, TRUE, TRUE, 0);
1863
1864         config_tab_general(notebook);
1865         config_tab_image(notebook);
1866         config_tab_windows(notebook);
1867         config_tab_filtering(notebook);
1868 //      config_tab_editors(notebook);
1869         config_tab_properties(notebook);
1870         config_tab_advanced(notebook);
1871
1872         gtk_widget_show(notebook);
1873
1874         gtk_widget_show(configwindow);
1875 }
1876
1877 /*
1878  *-----------------------------------------------------------------------------
1879  * config window show (public)
1880  *-----------------------------------------------------------------------------
1881  */
1882
1883 void show_config_window(void)
1884 {
1885         if (configwindow)
1886                 {
1887                 gtk_window_present(GTK_WINDOW(configwindow));
1888                 return;
1889                 }
1890
1891         config_window_create();
1892 }
1893
1894 /*
1895  *-----------------
1896  * about window
1897  *-----------------
1898  */
1899
1900 static GtkWidget *about = NULL;
1901
1902 static gint about_delete_cb(GtkWidget *widget, GdkEventAny *event, gpointer data)
1903 {
1904         gtk_widget_destroy(about);
1905         about = NULL;
1906
1907         return TRUE;
1908 }
1909
1910 static void about_window_close(GtkWidget *widget, gpointer data)
1911 {
1912         if (!about) return;
1913
1914         gtk_widget_destroy(about);
1915         about = NULL;
1916 }
1917
1918 static void about_credits_cb(GtkWidget *widget, gpointer data)
1919 {
1920         help_window_show("credits");
1921 }
1922
1923 void show_about_window(void)
1924 {
1925         GtkWidget *vbox;
1926         GtkWidget *hbox;
1927         GtkWidget *label;
1928         GtkWidget *button;
1929         GdkPixbuf *pixbuf;
1930
1931         gchar *buf;
1932
1933         if (about)
1934                 {
1935                 gtk_window_present(GTK_WINDOW(about));
1936                 return;
1937                 }
1938
1939         about = window_new(GTK_WINDOW_TOPLEVEL, "about", NULL, NULL, _("About"));
1940         gtk_window_set_type_hint(GTK_WINDOW(about), GDK_WINDOW_TYPE_HINT_DIALOG);
1941         g_signal_connect(G_OBJECT(about), "delete_event",
1942                          G_CALLBACK(about_delete_cb), NULL);
1943
1944         gtk_container_set_border_width(GTK_CONTAINER(about), PREF_PAD_BORDER);
1945
1946         vbox = gtk_vbox_new(FALSE, PREF_PAD_SPACE);
1947         gtk_container_add(GTK_CONTAINER(about), vbox);
1948         gtk_widget_show(vbox);
1949
1950         pixbuf = pixbuf_inline(PIXBUF_INLINE_LOGO);
1951         button = gtk_image_new_from_pixbuf(pixbuf);
1952         g_object_unref(pixbuf);
1953         gtk_box_pack_start(GTK_BOX(vbox), button, TRUE, TRUE, 0);
1954         gtk_widget_show(button);
1955
1956         buf = g_strdup_printf(_("%s %s\n\nCopyright (c) 2006 John Ellis\nCopyright (c) %s The Geeqie Team\nwebsite: %s\nemail: %s\n\nReleased under the GNU General Public License"),
1957                               GQ_APPNAME,
1958                               VERSION,
1959                               "2008 - 2009",
1960                               GQ_WEBSITE,
1961                               GQ_EMAIL_ADDRESS);
1962         label = gtk_label_new(buf);
1963         g_free(buf);
1964
1965         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
1966         gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0);
1967         gtk_widget_show(label);
1968
1969         hbox = gtk_hbutton_box_new();
1970         gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END);
1971         gtk_box_set_spacing(GTK_BOX(hbox), PREF_PAD_BUTTON_GAP);
1972         gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1973         gtk_widget_show(hbox);
1974
1975         button = pref_button_new(NULL, NULL, _("Credits..."), FALSE,
1976                                  G_CALLBACK(about_credits_cb), NULL);
1977         gtk_container_add(GTK_CONTAINER(hbox), button);
1978         GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1979         gtk_widget_show(button);
1980
1981         button = pref_button_new(NULL, GTK_STOCK_CLOSE, NULL, FALSE,
1982                                  G_CALLBACK(about_window_close), NULL);
1983         gtk_container_add(GTK_CONTAINER(hbox), button);
1984         GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1985         gtk_widget_grab_default(button);
1986         gtk_widget_show(button);
1987
1988         gtk_widget_show(about);
1989 }
1990 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */