6a10846e24bcee57fc32ce70411a84d2ae1d5b9a
[claws.git] / src / prefs_other.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2005-2011 Colin Leroy <colin@colino.net> & The Claws Mail Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <stdio.h>
27 #include <stdlib.h>
28
29 #include <glib.h>
30 #include <glib/gi18n.h>
31 #include <gtk/gtk.h>
32 #include <gdk/gdkkeysyms.h>
33
34 #include "prefs_common.h"
35 #include "prefs_gtk.h"
36
37 #include "gtk/gtkutils.h"
38 #include "gtk/prefswindow.h"
39 #include "combobox.h"
40
41 #include "manage_window.h"
42 #ifdef HAVE_LIBETPAN
43 #include "imap-thread.h"
44 #endif
45
46 typedef struct _OtherPage
47 {
48         PrefsPage page;
49
50         GtkWidget *window;
51
52         GtkWidget *checkbtn_addaddrbyclick;
53         GtkWidget *checkbtn_confonexit;
54         GtkWidget *checkbtn_cleanonexit;
55         GtkWidget *checkbtn_askonclean;
56         GtkWidget *checkbtn_warnqueued;
57         GtkWidget *spinbtn_iotimeout;
58         GtkWidget *checkbtn_gtk_can_change_accels;
59         GtkWidget *checkbtn_askonfilter;
60         GtkWidget *checkbtn_use_shred;
61         GtkWidget *checkbtn_real_time_sync;
62         GtkWidget *flush_metadata_faster_radiobtn;
63         GtkWidget *flush_metadata_safer_radiobtn;
64 } OtherPage;
65
66 static struct KeybindDialog {
67         GtkWidget *window;
68         GtkWidget *combo;
69 } keybind;
70
71 static void prefs_keybind_select                (void);
72 static gint prefs_keybind_deleted               (GtkWidget      *widget,
73                                                  GdkEventAny    *event,
74                                                  gpointer        data);
75 static gboolean prefs_keybind_key_pressed       (GtkWidget      *widget,
76                                                  GdkEventKey    *event,
77                                                  gpointer        data);
78 static void prefs_keybind_cancel                (void);
79 static void prefs_keybind_apply_clicked         (GtkWidget      *widget);
80
81
82 static void prefs_keybind_select(void)
83 {
84         GtkWidget *window;
85         GtkWidget *vbox1;
86         GtkWidget *hbox1;
87         GtkWidget *label;
88         GtkWidget *combo;
89         GtkWidget *confirm_area;
90         GtkWidget *ok_btn;
91         GtkWidget *cancel_btn;
92
93         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_other");
94         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
95         gtk_window_set_title (GTK_WINDOW (window), 
96                                 _("Choose preset keyboard shortcuts"));
97         gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
98         gtk_window_set_modal (GTK_WINDOW (window), TRUE);
99         gtk_window_set_resizable(GTK_WINDOW (window), FALSE);
100         manage_window_set_transient (GTK_WINDOW (window));
101
102         vbox1 = gtk_vbox_new (FALSE, VSPACING);
103         gtk_container_add (GTK_CONTAINER (window), vbox1);
104         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
105
106         hbox1 = gtk_hbox_new (FALSE, 8);
107         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
108
109         label = gtk_label_new
110                 (_("Select preset:"));
111         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
112         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
113
114         combo = combobox_text_new(FALSE,
115                                _("Default"),
116                                "Mew / Wanderlust",
117                                "Mutt",
118                                NULL);
119         gtk_box_pack_start (GTK_BOX (hbox1), combo, TRUE, TRUE, 0);
120
121         hbox1 = gtk_hbox_new (FALSE, 8);
122         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
123
124         label = gtk_label_new
125                 (_("You can also modify each menu shortcut by pressing\n"
126                    "any key(s) when focusing the mouse pointer on the item."));
127         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
128         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
129         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
130         gtkut_widget_set_small_font_size (label);
131
132         hbox1 = gtk_hbox_new (FALSE, 8);
133         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
134
135         gtkut_stock_button_set_create (&confirm_area, &cancel_btn, GTK_STOCK_CANCEL,
136                                        &ok_btn, GTK_STOCK_OK,
137                                        NULL, NULL);
138         gtk_box_pack_end (GTK_BOX (hbox1), confirm_area, FALSE, FALSE, 0);
139         gtk_widget_grab_focus (ok_btn);
140
141         MANAGE_WINDOW_SIGNALS_CONNECT(window);
142         g_signal_connect (G_OBJECT (window), "delete_event",
143                           G_CALLBACK (prefs_keybind_deleted), NULL);
144         g_signal_connect (G_OBJECT (window), "key_press_event",
145                           G_CALLBACK (prefs_keybind_key_pressed), NULL);
146         g_signal_connect (G_OBJECT (ok_btn), "clicked",
147                           G_CALLBACK (prefs_keybind_apply_clicked),
148                           NULL);
149         g_signal_connect (G_OBJECT (cancel_btn), "clicked",
150                           G_CALLBACK (prefs_keybind_cancel),
151                           NULL);
152
153         gtk_widget_show_all(window);
154
155         keybind.window = window;
156         keybind.combo = combo;
157 }
158
159 static gboolean prefs_keybind_key_pressed(GtkWidget *widget, GdkEventKey *event,
160                                           gpointer data)
161 {
162         if (event && event->keyval == GDK_Escape)
163                 prefs_keybind_cancel();
164         return FALSE;
165 }
166
167 static gint prefs_keybind_deleted(GtkWidget *widget, GdkEventAny *event,
168                                   gpointer data)
169 {
170         prefs_keybind_cancel();
171         return TRUE;
172 }
173
174 static void prefs_keybind_cancel(void)
175 {
176         gtk_widget_destroy(keybind.window);
177         keybind.window = NULL;
178         keybind.combo = NULL;
179 }
180   
181 struct KeyBind {
182         const gchar *accel_path;
183         const gchar *accel_key;
184 };
185
186 static void prefs_keybind_apply(struct KeyBind keybind[], gint num)
187 {
188         gint i;
189         guint key;
190         GdkModifierType mods;
191
192         for (i = 0; i < num; i++) {
193                 const gchar *accel_key
194                         = keybind[i].accel_key ? keybind[i].accel_key : "";
195                 gtk_accelerator_parse(accel_key, &key, &mods);
196                 gtk_accel_map_change_entry(keybind[i].accel_path,
197                                            key, mods, TRUE);
198         }
199 }
200
201 static void prefs_keybind_apply_clicked(GtkWidget *widget)
202 {
203         gchar *text;
204         struct KeyBind *menurc;
205         gint n_menurc;
206
207         static struct KeyBind default_menurc[] = {
208                 /* main */
209                 {"<Actions>/Menu/File/EmptyTrashes",                    "<shift>D"},
210                 {"<Actions>/Menu/File/SaveAs",                          "<control>S"},
211                 {"<Actions>/Menu/File/Print",                           "<control>P"},
212                 {"<Actions>/Menu/File/OfflineMode",                     "<control>W"},
213                 {"<Actions>/Menu/File/SynchroniseFolders",              "<control><shift>S"},
214                 {"<Actions>/Menu/File/Exit",                            "<control>Q"},
215
216                 {"<Actions>/Menu/Edit/Copy",                            "<control>C"},
217                 {"<Actions>/Menu/Edit/SelectAll",                       "<control>A"},
218                 {"<Actions>/Menu/Edit/Find",                            "<control>F"},
219                 {"<Actions>/Menu/Edit/SearchFolder",                    "<shift><control>F"},
220                 {"<Actions>/Menu/Edit/QuickSearch",                     "slash"},
221
222                 {"<Actions>/Menu/View/ShowHide/MessageView",            "V"},
223                 {"<Actions>/Menu/View/ThreadView",                      "<control>T"},
224                 {"<Actions>/Menu/View/GoTo/Prev",                       "P"},
225                 {"<Actions>/Menu/View/GoTo/Next",                       "N"},
226                 {"<Actions>/Menu/View/GoTo/PrevUnread",                 "<shift>P"},
227                 {"<Actions>/Menu/View/GoTo/NextUnread",                 "<shift>N"},
228                 {"<Actions>/Menu/View/GoTo/OtherFolder",                "G"},
229                 {"<Actions>/Menu/View/OpenNewWindow",                   "<control><alt>N"},
230                 {"<Actions>/Menu/View/MessageSource",                   "<control>U"},
231                 {"<Actions>/Menu/View/AllHeaders",                      "<control>H"},
232                 {"<Actions>/Menu/View/UpdateSummary",                   "<control><alt>U"},
233
234                 {"<Actions>/Menu/Message/Receive/CurrentAccount",
235                                                                         "<control>I"},
236                 {"<Actions>/Menu/Message/Receive/AllAccounts",          "<shift><control>I"},
237                 {"<Actions>/Menu/Message/ComposeEmail",                 "<control>M"},
238                 {"<Actions>/Menu/Message/Reply",                        "<control>R"},
239                 {"<Actions>/Menu/Message/ReplyTo/All",                  "<shift><control>R"},
240                 {"<Actions>/Menu/Message/ReplyTo/Sender",               ""},
241                 {"<Actions>/Menu/Message/ReplyTo/List",                 "<control>L"},
242                 {"<Actions>/Menu/Message/Forward",                      "<control><alt>F"},
243                 {"<Actions>/Menu/Message/Move",                         "<control>O"},
244                 {"<Actions>/Menu/Message/Copy",                         "<shift><control>O"},
245                 {"<Actions>/Menu/Message/Trash",                        "<control>D"},
246                 {"<Actions>/Menu/Message/Mark/Mark",                    "<shift>asterisk"},
247                 {"<Actions>/Menu/Message/Mark/Unmark",                  "U"},
248                 {"<Actions>/Menu/Message/Mark/MarkUnread",              "<shift>exclam"},
249                 {"<Actions>/Menu/Message/Mark/MarkRead",                ""},
250
251                 {"<Actions>/Menu/Tools/AddressBook",                    "<shift><control>A"},
252                 {"<Actions>/Menu/Tools/Execute",                        "X"},
253                 {"<Actions>/Menu/Tools/NetworkLog",                     "<shift><control>L"},
254                 /* compose */
255                 {"<Actions>/Menu/Message/Send",                         "<control>Return"},
256                 {"<Actions>/Menu/Message/SendLater",                    "<shift><control>S"},
257                 {"<Actions>/Menu/Message/AttachFile",                   "<control>M"},
258                 {"<Actions>/Menu/Message/InsertFile",                   "<control>I"},
259                 {"<Actions>/Menu/Message/InsertSig",                    "<control>G"},
260                 {"<Actions>/Menu/Message/Save",                         "<control>S"},
261                 {"<Actions>/Menu/Message/Close",                        "<control>W"},
262                 {"<Actions>/Menu/Edit/Undo",                            "<control>Z"},
263                 {"<Actions>/Menu/Edit/Redo",                            "<control>Y"},
264                 {"<Actions>/Menu/Edit/Cut",                             "<control>X"},
265                 {"<Actions>/Menu/Edit/Copy",                            "<control>C"},
266                 {"<Actions>/Menu/Edit/Paste",                           "<control>V"},
267                 {"<Actions>/Menu/Edit/SelectAll",                       "<control>A"},
268                 {"<Actions>/Menu/Edit/Advanced/BackChar",               "<control>B"},
269                 {"<Actions>/Menu/Edit/Advanced/ForwChar",               "<control>F"},
270                 {"<Actions>/Menu/Edit/Advanced/BackWord",               ""},
271                 {"<Actions>/Menu/Edit/Advanced/ForwWord",               ""},
272                 {"<Actions>/Menu/Edit/Advanced/BegLine",                ""},
273                 {"<Actions>/Menu/Edit/Advanced/EndLine",                "<control>E"},
274                 {"<Actions>/Menu/Edit/Advanced/PrevLine",               "<control>P"},
275                 {"<Actions>/Menu/Edit/Advanced/NextLine",               "<control>N"},
276                 {"<Actions>/Menu/Edit/Advanced/DelBackChar",            "<control>H"},
277                 {"<Actions>/Menu/Edit/Advanced/DelForwChar",            "<control>D"},
278                 {"<Actions>/Menu/Edit/Advanced/DelBackWord",            ""},
279                 {"<Actions>/Menu/Edit/Advanced/DelForwWord",            ""},
280                 {"<Actions>/Menu/Edit/Advanced/DelLine",                "<control>U"},
281                 {"<Actions>/Menu/Edit/Advanced/DelEndLine",             "<control>K"},
282                 {"<Actions>/Menu/Edit/WrapPara",                        "<control>L"},
283                 {"<Actions>/Menu/Edit/WrapAllLines",                    "<control><alt>L"},
284                 {"<Actions>/Menu/Edit/AutoWrap",                        "<shift><control>L"},
285                 {"<Actions>/Menu/Edit/ExtEditor",                       "<shift><control>X"},
286                 {"<Actions>/Menu/Tools/AddressBook",                    "<shift><control>A"},
287         };
288
289         static struct KeyBind mew_wl_menurc[] = {
290                 /* main */
291                 {"<Actions>/Menu/File/EmptyTrashes",                    "<shift>D"},
292                 {"<Actions>/Menu/File/SaveAs",                          "Y"},
293                 {"<Actions>/Menu/File/Print",                           "<control>numbersign"},
294                 {"<Actions>/Menu/File/Exit",                            "<shift>Q"},
295
296                 {"<Actions>/Menu/Edit/Copy",                            "<control>C"},
297                 {"<Actions>/Menu/Edit/SelectAll",                       "<control>A"},
298                 {"<Actions>/Menu/Edit/Find",                            "<control>F"},
299                 {"<Actions>/Menu/Edit/SearchFolder",                    "<control>S"},
300                 {"<Actions>/Menu/Edit/QuickSearch",                     "slash"},
301
302                 {"<Actions>/Menu/View/ShowHide/MessageView",            ""},
303                 {"<Actions>/Menu/View/ThreadView",                      "<shift>T"},
304                 {"<Actions>/Menu/View/GoTo/Prev",                       "P"},
305                 {"<Actions>/Menu/View/GoTo/Next",                       "N"},
306                 {"<Actions>/Menu/View/GoTo/PrevUnread",                 "<shift>P"},
307                 {"<Actions>/Menu/View/GoTo/NextUnread",                 "<shift>N"},
308                 {"<Actions>/Menu/View/GoTo/OtherFolder",                "G"},
309                 {"<Actions>/Menu/View/OpenNewWindow",                   "<control><alt>N"},
310                 {"<Actions>/Menu/View/MessageSource",                   "<control>U"},
311                 {"<Actions>/Menu/View/AllHeaders",                      "<shift>H"},
312                 {"<Actions>/Menu/View/UpdateSummary",                   "<shift>S"},
313
314                 {"<Actions>/Menu/Message/Receive/CurrentAccount",
315                                                                         "<control>I"},
316                 {"<Actions>/Menu/Message/Receive/AllAccounts",          "<shift><control>I"},
317                 {"<Actions>/Menu/Message/ComposeEmail",                 "W"},
318                 {"<Actions>/Menu/Message/Reply",                        "<control>R"},
319                 {"<Actions>/Menu/Message/ReplyTo/All",                  "<shift>A"},
320                 {"<Actions>/Menu/Message/ReplyTo/Sender",               ""},
321                 {"<Actions>/Menu/Message/ReplyTo/List",                 "<control>L"},
322                 {"<Actions>/Menu/Message/Forward",                      "F"},
323                 {"<Actions>/Menu/Message/Move",                         "O"},
324                 {"<Actions>/Menu/Message/Copy",                         "<shift>O"},
325                 {"<Actions>/Menu/Message/Trash",                        "D"},
326                 {"<Actions>/Menu/Message/Mark/Mark",                    "<shift>asterisk"},
327                 {"<Actions>/Menu/Message/Mark/Unmark",                  "U"},
328                 {"<Actions>/Menu/Message/Mark/MarkUnread",              "<shift>exclam"},
329                 {"<Actions>/Menu/Message/Mark/MarkRead",                "<shift>R"},
330
331                 {"<Actions>/Menu/Tools/AddressBook",                    "<shift><control>A"},
332                 {"<Actions>/Menu/Tools/Execute",                        "X"},
333                 {"<Actions>/Menu/Tools/NetworkLog",                     "<shift><control>L"},
334                 /* compose */
335                 {"<Actions>/Menu/Message/Close",                        "<alt>W"},
336                 {"<Actions>/Menu/Edit/SelectAll",                       ""},
337                 {"<Actions>/Menu/Edit/Advanced/BackChar",               "<alt>B"},
338                 {"<Actions>/Menu/Edit/Advanced/ForwChar",               "<alt>F"},
339                 {"<Actions>/Menu/Edit/Advanced/BackWord",               ""},
340                 {"<Actions>/Menu/Edit/Advanced/ForwWord",               ""},
341                 {"<Actions>/Menu/Edit/Advanced/BegLine",                "<control>A"},
342                 {"<Actions>/Menu/Edit/Advanced/DelBackWord",            "<control>W"},
343                 {"<Actions>/Menu/Edit/Advanced/DelForwWord",            "<alt>D"},
344         };
345
346         static struct KeyBind mutt_menurc[] = {
347                 /* main */
348                 {"<Actions>/Menu/File/EmptyTrashes",                    ""},
349                 {"<Actions>/Menu/File/SaveAs",                          "S"},
350                 {"<Actions>/Menu/File/Print",                           "P"},
351                 {"<Actions>/Menu/File/Exit",                            "Q"},
352
353                 {"<Actions>/Menu/Edit/Copy",                            "<control>C"},
354                 {"<Actions>/Menu/Edit/SelectAll",                       "<control>A"},
355                 {"<Actions>/Menu/Edit/Find",                            "<control>F"},
356                 {"<Actions>/Menu/Edit/SearchFolder",                    "/"},
357
358                 {"<Actions>/Menu/View/ShowHide/MessageView",            "V"},
359                 {"<Actions>/Menu/View/ThreadView",                      "<control>T"},
360                 {"<Actions>/Menu/View/GoTo/Prev",                       ""},
361                 {"<Actions>/Menu/View/GoTo/Next",                       ""},
362                 {"<Actions>/Menu/View/GoTo/PrevUnread",                 ""},
363                 {"<Actions>/Menu/View/GoTo/NextUnread",                 ""},
364                 {"<Actions>/Menu/View/GoTo/OtherFolder",                "C"},
365                 {"<Actions>/Menu/View/OpenNewWindow",                   "<control><alt>N"},
366                 {"<Actions>/Menu/View/MessageSource",                   "<control>U"},
367                 {"<Actions>/Menu/View/AllHeaders",                      "<control>H"},
368                 {"<Actions>/Menu/View/UpdateSummary",                   "<control><alt>U"},
369
370                 {"<Actions>/Menu/Message/Receive/CurrentAccount",
371                                                                         "<control>I"},
372                 {"<Actions>/Menu/Message/Receive/AllAccounts",          "<shift><control>I"},
373                 {"<Actions>/Menu/Message/ComposeEmail",                 "M"},
374                 {"<Actions>/Menu/Message/Reply",                        "R"},
375                 {"<Actions>/Menu/Message/ReplyTo/All",                  "G"},
376                 {"<Actions>/Menu/Message/ReplyTo/Sender",               ""},
377                 {"<Actions>/Menu/Message/ReplyTo/List",                 "<control>L"},
378                 {"<Actions>/Menu/Message/Forward",                      "F"},
379                 {"<Actions>/Menu/Message/Move",                         "<control>O"},
380                 {"<Actions>/Menu/Message/Copy",                         "<shift>C"},
381                 {"<Actions>/Menu/Message/Trash",                        "D"},
382                 {"<Actions>/Menu/Message/Mark/Mark",                    "<shift>F"},
383                 {"<Actions>/Menu/Message/Mark/Unmark",                  "U"},
384                 {"<Actions>/Menu/Message/Mark/MarkUnread",              "<shift>N"},
385                 {"<Actions>/Menu/Message/Mark/MarkRead",                ""},
386
387                 {"<Actions>/Menu/Tools/AddressBook",                    "<shift><control>A"},
388                 {"<Actions>/Menu/Tools/Execute",                        "X"},
389                 {"<Actions>/Menu/Tools/NetworkLog",                     "<shift><control>L"},
390                 /* compose */
391                 {"<Actions>/Menu/Message/Close",                        "<alt>W"},
392                 {"<Actions>/Menu/Edit/SelectAll",                       ""},
393                 {"<Actions>/Menu/Edit/Advanced/BackWord",               "<alt>B"},
394                 {"<Actions>/Menu/Edit/Advanced/ForwWord",               "<alt>F"},
395                 {"<Actions>/Menu/Edit/Advanced/BegLine",                "<control>A"},
396                 {"<Actions>/Menu/Edit/Advanced/DelBackWord",            "<control>W"},
397                 {"<Actions>/Menu/Edit/Advanced/DelForwWord",            "<alt>D"},
398         };
399
400         text = gtk_combo_box_text_get_active_text(
401                 GTK_COMBO_BOX_TEXT(keybind.combo));
402
403         if (!strcmp(text, _("Default"))) {
404                 menurc = default_menurc;
405                 n_menurc = G_N_ELEMENTS(default_menurc);
406         } else if (!strcmp(text, "Mew / Wanderlust")) {
407                 menurc = mew_wl_menurc;
408                 n_menurc = G_N_ELEMENTS(mew_wl_menurc);
409         } else if (!strcmp(text, "Mutt")) {
410                 menurc = mutt_menurc;
411                 n_menurc = G_N_ELEMENTS(mutt_menurc);
412         } else {
413                 g_free(text);
414                 return;
415         }
416         g_free(text);
417
418         prefs_keybind_apply(menurc, n_menurc);
419
420         gtk_widget_destroy(keybind.window);
421         keybind.window = NULL;
422         keybind.combo = NULL;
423 }
424
425 static void prefs_other_create_widget(PrefsPage *_page, GtkWindow *window, 
426                                   gpointer data)
427 {
428         OtherPage *prefs_other = (OtherPage *) _page;
429         
430         GtkWidget *vbox1;
431         GtkWidget *hbox1;
432
433         GtkWidget *frame_addr;
434         GtkWidget *vbox_addr;
435         GtkWidget *checkbtn_addaddrbyclick;
436         
437         GtkWidget *frame_exit;
438         GtkWidget *vbox_exit;
439         GtkWidget *checkbtn_confonexit;
440         GtkWidget *checkbtn_cleanonexit;
441         GtkWidget *checkbtn_warnqueued;
442
443         GtkWidget *frame_keys;
444         GtkWidget *vbox_keys;
445         GtkWidget *checkbtn_gtk_can_change_accels;
446         GtkWidget *button_keybind;
447
448         GtkWidget *label_iotimeout;
449         GtkWidget *spinbtn_iotimeout;
450         GtkObject *spinbtn_iotimeout_adj;
451
452         GtkWidget *vbox2;
453         GtkWidget *checkbtn_askonclean;
454         GtkWidget *checkbtn_askonfilter;
455         GtkWidget *checkbtn_use_shred;
456         GtkWidget *checkbtn_real_time_sync;
457
458         GtkWidget *frame_metadata;
459         GtkWidget *vbox_metadata;
460         GtkWidget *metadata_label;
461         GtkWidget *flush_metadata_faster_radiobtn;
462         GtkWidget *flush_metadata_safer_radiobtn;
463
464         gchar *shred_binary = NULL;
465         CLAWS_TIP_DECL();
466
467         vbox1 = gtk_vbox_new (FALSE, VSPACING);
468         gtk_widget_show (vbox1);
469         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
470
471         vbox_addr = gtkut_get_options_frame(vbox1, &frame_addr, _("Address book"));
472
473         PACK_CHECK_BUTTON
474                 (vbox_addr, checkbtn_addaddrbyclick,
475                  _("Add address to destination when double-clicked"));
476
477         /* On Exit */
478         vbox_exit = gtkut_get_options_frame(vbox1, &frame_exit, _("On exit"));
479
480         PACK_CHECK_BUTTON (vbox_exit, checkbtn_confonexit,
481                            _("Confirm on exit"));
482
483         hbox1 = gtk_hbox_new (FALSE, 32);
484         gtk_widget_show (hbox1);
485         gtk_box_pack_start (GTK_BOX (vbox_exit), hbox1, FALSE, FALSE, 0);
486
487         PACK_CHECK_BUTTON (hbox1, checkbtn_cleanonexit,
488                            _("Empty trash on exit"));
489
490         PACK_CHECK_BUTTON (vbox_exit, checkbtn_warnqueued,
491                            _("Warn if there are queued messages"));
492
493         vbox_keys = gtkut_get_options_frame(vbox1, &frame_keys, _("Keyboard shortcuts"));
494
495         PACK_CHECK_BUTTON(vbox_keys, checkbtn_gtk_can_change_accels,
496                         _("Enable customisable keyboard shortcuts"));
497
498         CLAWS_SET_TIP(checkbtn_gtk_can_change_accels,
499                         _("If checked, you can change the keyboard shortcuts of "
500                                 "most of the menu items by focusing on the menu "
501                                 "item and pressing a key combination.\n"
502                                 "Uncheck this option if you want to lock all "
503                                 "existing keyboard shortcuts."));
504
505         button_keybind = gtk_button_new_with_label(
506                                 _(" Choose preset keyboard shortcuts... "));
507         gtk_widget_show (button_keybind);
508         hbox1 = gtk_hbox_new (FALSE, 8);
509         gtk_widget_show (hbox1);
510         gtk_box_pack_start (GTK_BOX (vbox_keys), hbox1, FALSE, FALSE, 0);
511         gtk_box_pack_start (GTK_BOX (hbox1), button_keybind, FALSE, FALSE, 0);
512         g_signal_connect (G_OBJECT (button_keybind), "clicked",
513                           G_CALLBACK (prefs_keybind_select), NULL);
514
515
516         vbox_metadata = gtkut_get_options_frame(vbox1, &frame_metadata, _("Metadata handling"));
517         metadata_label = gtk_label_new(_("Safer mode asks the OS to write metadata to disk directly;\n"
518                                          "it avoids data loss after crashes but can take some time."));
519         gtk_misc_set_alignment(GTK_MISC(metadata_label), 0, 0);
520         gtk_box_pack_start (GTK_BOX (vbox_metadata), metadata_label, FALSE, FALSE, 0);
521         flush_metadata_safer_radiobtn = gtk_radio_button_new_with_label(NULL, _("Safer"));
522         flush_metadata_faster_radiobtn = gtk_radio_button_new_with_label_from_widget(
523                                            GTK_RADIO_BUTTON(flush_metadata_safer_radiobtn), _("Faster"));
524         hbox1 = gtk_hbox_new (FALSE, 8);
525         gtk_widget_show (hbox1);
526         gtk_box_pack_start (GTK_BOX (vbox_metadata), hbox1, FALSE, FALSE, 0);
527         gtk_box_pack_start (GTK_BOX (hbox1), flush_metadata_safer_radiobtn, FALSE, FALSE, 0);
528         gtk_box_pack_start (GTK_BOX (hbox1), flush_metadata_faster_radiobtn, FALSE, FALSE, 0);
529         
530         if (prefs_common.flush_metadata)
531                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(flush_metadata_safer_radiobtn), TRUE);
532         else
533                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(flush_metadata_faster_radiobtn), TRUE);
534
535         gtk_widget_show_all(frame_metadata);
536
537         hbox1 = gtk_hbox_new (FALSE, 8);
538         gtk_widget_show (hbox1);
539         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
540
541         label_iotimeout = gtk_label_new (_("Socket I/O timeout"));
542         gtk_widget_show (label_iotimeout);
543         gtk_box_pack_start (GTK_BOX (hbox1), label_iotimeout, FALSE, FALSE, 0);
544
545         spinbtn_iotimeout_adj = gtk_adjustment_new (60, 0, 1000, 1, 10, 0);
546         spinbtn_iotimeout = gtk_spin_button_new
547                 (GTK_ADJUSTMENT (spinbtn_iotimeout_adj), 1, 0);
548         gtk_widget_show (spinbtn_iotimeout);
549         gtk_box_pack_start (GTK_BOX (hbox1), spinbtn_iotimeout,
550                             FALSE, FALSE, 0);
551         gtk_widget_set_size_request (spinbtn_iotimeout, 64, -1);
552         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_iotimeout), TRUE);
553
554         label_iotimeout = gtk_label_new (_("seconds"));
555         gtk_widget_show (label_iotimeout);
556         gtk_box_pack_start (GTK_BOX (hbox1), label_iotimeout, FALSE, FALSE, 0);
557
558         vbox2 = gtk_vbox_new (FALSE, 8);
559         gtk_widget_show (vbox2);
560         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
561
562         PACK_CHECK_BUTTON (vbox2, checkbtn_askonclean, 
563                            _("Ask before emptying trash"));
564         PACK_CHECK_BUTTON (vbox2, checkbtn_askonfilter,
565                            _("Ask about account specific filtering rules when "
566                              "filtering manually"));
567         shred_binary = g_find_program_in_path("shred");
568         if (shred_binary) {
569                 PACK_CHECK_BUTTON (vbox2, checkbtn_use_shred,
570                                    _("Use secure file deletion if possible"));
571                 g_free(shred_binary);
572         } else {
573                 PACK_CHECK_BUTTON (vbox2, checkbtn_use_shred,
574                                    _("Use secure file deletion if possible\n"
575                                      "(the 'shred' program is not available)"));
576                 gtk_widget_set_sensitive(checkbtn_use_shred, FALSE);
577         }
578         CLAWS_SET_TIP(checkbtn_use_shred,
579                         _("Use the 'shred' program to overwrite files with random data before "
580                           "deleting them. This slows down deletion. Be sure to "
581                           "read shred's man page for caveats."));
582         PACK_CHECK_BUTTON (vbox2, checkbtn_real_time_sync,
583                            _("Synchronise offline folders as soon as possible"));
584
585         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_addaddrbyclick), 
586                 prefs_common.add_address_by_click);
587         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_confonexit), 
588                 prefs_common.confirm_on_exit);
589         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_cleanonexit), 
590                 prefs_common.clean_on_exit);
591         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_askonclean), 
592                 prefs_common.ask_on_clean);
593         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_warnqueued), 
594                 prefs_common.warn_queued_on_exit);
595         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_gtk_can_change_accels),
596                 prefs_common.gtk_can_change_accels);
597
598         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_iotimeout),
599                 prefs_common.io_timeout_secs);
600
601         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_askonfilter), 
602                 prefs_common.ask_apply_per_account_filtering_rules);
603         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_use_shred), 
604                 prefs_common.use_shred);
605         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_real_time_sync), 
606                 prefs_common.real_time_sync);
607
608         prefs_other->checkbtn_addaddrbyclick = checkbtn_addaddrbyclick;
609         prefs_other->checkbtn_confonexit = checkbtn_confonexit;
610         prefs_other->checkbtn_cleanonexit = checkbtn_cleanonexit;
611         prefs_other->checkbtn_askonclean = checkbtn_askonclean;
612         prefs_other->checkbtn_warnqueued = checkbtn_warnqueued;
613         prefs_other->spinbtn_iotimeout = spinbtn_iotimeout;
614         prefs_other->checkbtn_gtk_can_change_accels = checkbtn_gtk_can_change_accels;
615         prefs_other->checkbtn_askonfilter = checkbtn_askonfilter;
616         prefs_other->checkbtn_use_shred = checkbtn_use_shred;
617         prefs_other->checkbtn_real_time_sync = checkbtn_real_time_sync;
618         prefs_other->flush_metadata_safer_radiobtn = flush_metadata_safer_radiobtn;
619         prefs_other->flush_metadata_faster_radiobtn = flush_metadata_faster_radiobtn;
620         prefs_other->page.widget = vbox1;
621 }
622
623 static void prefs_other_save(PrefsPage *_page)
624 {
625         OtherPage *page = (OtherPage *) _page;
626         gboolean gtk_can_change_accels;
627
628         prefs_common.add_address_by_click = gtk_toggle_button_get_active(
629                 GTK_TOGGLE_BUTTON(page->checkbtn_addaddrbyclick));
630         prefs_common.confirm_on_exit = gtk_toggle_button_get_active(
631                 GTK_TOGGLE_BUTTON(page->checkbtn_confonexit));
632         prefs_common.clean_on_exit = gtk_toggle_button_get_active(
633                 GTK_TOGGLE_BUTTON(page->checkbtn_cleanonexit)); 
634         prefs_common.ask_on_clean = gtk_toggle_button_get_active(
635                 GTK_TOGGLE_BUTTON(page->checkbtn_askonclean));
636         prefs_common.warn_queued_on_exit = gtk_toggle_button_get_active(
637                 GTK_TOGGLE_BUTTON(page->checkbtn_warnqueued)); 
638         prefs_common.io_timeout_secs = gtk_spin_button_get_value_as_int(
639                 GTK_SPIN_BUTTON(page->spinbtn_iotimeout));
640         prefs_common.flush_metadata = gtk_toggle_button_get_active(
641                 GTK_TOGGLE_BUTTON(page->flush_metadata_safer_radiobtn));
642         sock_set_io_timeout(prefs_common.io_timeout_secs);
643 #ifdef HAVE_LIBETPAN
644         imap_main_set_timeout(prefs_common.io_timeout_secs);
645 #endif
646         prefs_common.ask_apply_per_account_filtering_rules = 
647                 gtk_toggle_button_get_active(
648                         GTK_TOGGLE_BUTTON(page->checkbtn_askonfilter)); 
649         prefs_common.use_shred = 
650                 gtk_toggle_button_get_active(
651                         GTK_TOGGLE_BUTTON(page->checkbtn_use_shred)); 
652         prefs_common.real_time_sync = 
653                 gtk_toggle_button_get_active(
654                         GTK_TOGGLE_BUTTON(page->checkbtn_real_time_sync)); 
655
656         gtk_can_change_accels = gtk_toggle_button_get_active(
657                 GTK_TOGGLE_BUTTON(page->checkbtn_gtk_can_change_accels));
658
659         if (prefs_common.gtk_can_change_accels != gtk_can_change_accels) {
660
661                 prefs_common.gtk_can_change_accels = gtk_can_change_accels;
662
663                 gtk_settings_set_long_property(gtk_settings_get_default(),
664                                 "gtk-can-change-accels",
665                                 (glong)prefs_common.gtk_can_change_accels,
666                                 "XProperty");
667
668                 /* gtk_can_change_accels value changed : we have (only if changed)
669                  * to apply the gtk property to all widgets : */
670                 gtk_rc_reparse_all_for_settings(gtk_settings_get_default(), TRUE);
671         }
672 }
673
674 static void prefs_other_destroy_widget(PrefsPage *_page)
675 {
676 }
677
678 OtherPage *prefs_other;
679
680 void prefs_other_init(void)
681 {
682         OtherPage *page;
683         static gchar *path[3];
684
685         path[0] = _("Other");
686         path[1] = _("Miscellaneous");
687         path[2] = NULL;
688
689         page = g_new0(OtherPage, 1);
690         page->page.path = path;
691         page->page.create_widget = prefs_other_create_widget;
692         page->page.destroy_widget = prefs_other_destroy_widget;
693         page->page.save_page = prefs_other_save;
694         page->page.weight = 5.0;
695         prefs_gtk_register_page((PrefsPage *) page);
696         prefs_other = page;
697
698         gtk_settings_set_long_property(gtk_settings_get_default(),
699                         "gtk-can-change-accels",
700                         (glong)prefs_common.gtk_can_change_accels,
701                         "XProperty");
702 }
703
704 void prefs_other_done(void)
705 {
706         prefs_gtk_unregister_page((PrefsPage *) prefs_other);
707         g_free(prefs_other);
708 }