fix bug where actionsrc was not updated after mailbox name change
[claws.git] / src / prefs_other.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2005-2015 Colin Leroy and 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 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #include "claws-features.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 #ifndef PASSWORD_CRYPTO_OLD
41 #include "password.h"
42 #include "password_gtk.h"
43 #endif
44
45 #include "manage_window.h"
46 #ifdef HAVE_LIBETPAN
47 #include "imap-thread.h"
48 #endif
49
50 typedef struct _OtherPage
51 {
52         PrefsPage page;
53
54         GtkWidget *window;
55
56         GtkWidget *checkbtn_addaddrbyclick;
57         GtkWidget *checkbtn_confonexit;
58         GtkWidget *checkbtn_cleanonexit;
59         GtkWidget *checkbtn_askonclean;
60         GtkWidget *checkbtn_warnqueued;
61         GtkWidget *spinbtn_iotimeout;
62         GtkWidget *checkbtn_gtk_can_change_accels;
63         GtkWidget *checkbtn_askonfilter;
64         GtkWidget *checkbtn_use_shred;
65         GtkWidget *checkbtn_real_time_sync;
66         GtkWidget *flush_metadata_faster_radiobtn;
67         GtkWidget *flush_metadata_safer_radiobtn;
68 #ifndef PASSWORD_CRYPTO_OLD
69         GtkWidget *checkbtn_use_passphrase;
70 #endif
71 } OtherPage;
72
73 static struct KeybindDialog {
74         GtkWidget *window;
75         GtkWidget *combo;
76 } keybind;
77
78 static void prefs_keybind_select                (void);
79 static gint prefs_keybind_deleted               (GtkWidget      *widget,
80                                                  GdkEventAny    *event,
81                                                  gpointer        data);
82 static gboolean prefs_keybind_key_pressed       (GtkWidget      *widget,
83                                                  GdkEventKey    *event,
84                                                  gpointer        data);
85 static void prefs_keybind_cancel                (void);
86 static void prefs_keybind_apply_clicked         (GtkWidget      *widget);
87 #ifndef PASSWORD_CRYPTO_OLD
88 static void prefs_change_master_passphrase(GtkButton *button, gpointer data);
89 static void prefs_use_passphrase_toggled(GtkToggleButton *button, gpointer data);
90 #endif
91
92
93 static void prefs_keybind_select(void)
94 {
95         GtkWidget *window;
96         GtkWidget *vbox1;
97         GtkWidget *hbox1;
98         GtkWidget *label;
99         GtkWidget *combo;
100         GtkWidget *confirm_area;
101         GtkWidget *ok_btn;
102         GtkWidget *cancel_btn;
103
104         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_other");
105         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
106         gtk_window_set_title (GTK_WINDOW (window), 
107                                 _("Choose preset keyboard shortcuts"));
108         gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
109         gtk_window_set_modal (GTK_WINDOW (window), TRUE);
110         gtk_window_set_resizable(GTK_WINDOW (window), FALSE);
111         manage_window_set_transient (GTK_WINDOW (window));
112
113         vbox1 = gtk_vbox_new (FALSE, VSPACING);
114         gtk_container_add (GTK_CONTAINER (window), vbox1);
115         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
116
117         hbox1 = gtk_hbox_new (FALSE, 8);
118         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
119
120         label = gtk_label_new
121                 (_("Select preset:"));
122         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
123         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
124
125         combo = combobox_text_new(FALSE,
126                                _("Default"),
127                                "Mew / Wanderlust",
128                                "Mutt",
129                                NULL);
130         gtk_box_pack_start (GTK_BOX (hbox1), combo, TRUE, TRUE, 0);
131
132         hbox1 = gtk_hbox_new (FALSE, 8);
133         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
134
135         label = gtk_label_new
136                 (_("You can also modify each menu shortcut by pressing\n"
137                    "any key(s) when focusing the mouse pointer on the item."));
138         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
139         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
140         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
141         gtkut_widget_set_small_font_size (label);
142
143         hbox1 = gtk_hbox_new (FALSE, 8);
144         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
145
146         gtkut_stock_button_set_create (&confirm_area, &cancel_btn, GTK_STOCK_CANCEL,
147                                        &ok_btn, GTK_STOCK_OK,
148                                        NULL, NULL);
149         gtk_box_pack_end (GTK_BOX (hbox1), confirm_area, FALSE, FALSE, 0);
150         gtk_widget_grab_focus (ok_btn);
151
152         MANAGE_WINDOW_SIGNALS_CONNECT(window);
153         g_signal_connect (G_OBJECT (window), "delete_event",
154                           G_CALLBACK (prefs_keybind_deleted), NULL);
155         g_signal_connect (G_OBJECT (window), "key_press_event",
156                           G_CALLBACK (prefs_keybind_key_pressed), NULL);
157         g_signal_connect (G_OBJECT (ok_btn), "clicked",
158                           G_CALLBACK (prefs_keybind_apply_clicked),
159                           NULL);
160         g_signal_connect (G_OBJECT (cancel_btn), "clicked",
161                           G_CALLBACK (prefs_keybind_cancel),
162                           NULL);
163
164         gtk_widget_show_all(window);
165
166         keybind.window = window;
167         keybind.combo = combo;
168 }
169
170 static gboolean prefs_keybind_key_pressed(GtkWidget *widget, GdkEventKey *event,
171                                           gpointer data)
172 {
173         if (event && event->keyval == GDK_KEY_Escape)
174                 prefs_keybind_cancel();
175         return FALSE;
176 }
177
178 static gint prefs_keybind_deleted(GtkWidget *widget, GdkEventAny *event,
179                                   gpointer data)
180 {
181         prefs_keybind_cancel();
182         return TRUE;
183 }
184
185 static void prefs_keybind_cancel(void)
186 {
187         gtk_widget_destroy(keybind.window);
188         keybind.window = NULL;
189         keybind.combo = NULL;
190 }
191   
192 struct KeyBind {
193         const gchar *accel_path;
194         const gchar *accel_key;
195 };
196
197 static void prefs_keybind_apply(struct KeyBind keybind[], gint num)
198 {
199         gint i;
200         guint key;
201         GdkModifierType mods;
202
203         for (i = 0; i < num; i++) {
204                 const gchar *accel_key
205                         = keybind[i].accel_key ? keybind[i].accel_key : "";
206                 gtk_accelerator_parse(accel_key, &key, &mods);
207                 if (key == 0 && mods == 0) {
208                         g_message("Failed parsing accelerator '%s' for path '%s'\n",
209                                   accel_key, keybind[i].accel_path);
210                 }
211                 gtk_accel_map_change_entry(keybind[i].accel_path,
212                                            key, mods, TRUE);
213         }
214 }
215
216 static void prefs_keybind_apply_clicked(GtkWidget *widget)
217 {
218         gchar *text;
219         struct KeyBind *menurc;
220         gint n_menurc;
221
222         static struct KeyBind default_menurc[] = {
223                 /* main */
224                 {"<Actions>/Menu/File/EmptyTrashes",                    "<shift>D"},
225                 {"<Actions>/Menu/File/SaveAs",                          "<control>S"},
226                 {"<Actions>/Menu/File/Print",                           "<control>P"},
227                 {"<Actions>/Menu/File/OfflineMode",                     "<control>W"},
228                 {"<Actions>/Menu/File/SynchroniseFolders",              "<control><shift>S"},
229                 {"<Actions>/Menu/File/Exit",                            "<control>Q"},
230
231                 {"<Actions>/Menu/Edit/Copy",                            "<control>C"},
232                 {"<Actions>/Menu/Edit/SelectAll",                       "<control>A"},
233                 {"<Actions>/Menu/Edit/Find",                            "<control>F"},
234                 {"<Actions>/Menu/Edit/SearchFolder",                    "<shift><control>F"},
235                 {"<Actions>/Menu/Edit/QuickSearch",                     "slash"},
236
237                 {"<Actions>/Menu/View/ShowHide/MessageView",            "V"},
238                 {"<Actions>/Menu/View/ThreadView",                      "<control>T"},
239                 {"<Actions>/Menu/View/Goto/Prev",                       "P"},
240                 {"<Actions>/Menu/View/Goto/Next",                       "N"},
241                 {"<Actions>/Menu/View/Goto/PrevUnread",                 "<shift>P"},
242                 {"<Actions>/Menu/View/Goto/NextUnread",                 "<shift>N"},
243                 {"<Actions>/Menu/View/Goto/Folder",                     "G"},
244                 {"<Actions>/Menu/View/OpenNewWindow",                   "<control><alt>N"},
245                 {"<Actions>/Menu/View/MessageSource",                   "<control>U"},
246                 {"<Actions>/Menu/View/AllHeaders",                      "<control>H"},
247                 {"<Actions>/Menu/View/UpdateSummary",                   "<control><alt>U"},
248
249                 {"<Actions>/Menu/Message/Receive/CurrentAccount",
250                                                                         "<control>I"},
251                 {"<Actions>/Menu/Message/Receive/AllAccounts",          "<shift><control>I"},
252                 {"<Actions>/Menu/Message/ComposeEmail",                 "<control>M"},
253                 {"<Actions>/Menu/Message/Reply",                        "<control>R"},
254                 {"<Actions>/Menu/Message/ReplyTo/All",                  "<shift><control>R"},
255                 {"<Actions>/Menu/Message/ReplyTo/Sender",               ""},
256                 {"<Actions>/Menu/Message/ReplyTo/List",                 "<control>L"},
257                 {"<Actions>/Menu/Message/Forward",                      "<control><alt>F"},
258                 {"<Actions>/Menu/Message/Move",                         "<control>O"},
259                 {"<Actions>/Menu/Message/Copy",                         "<shift><control>O"},
260                 {"<Actions>/Menu/Message/Trash",                        "<control>D"},
261                 {"<Actions>/Menu/Message/Mark/Mark",                    "<shift>asterisk"},
262                 {"<Actions>/Menu/Message/Mark/Unmark",                  "U"},
263                 {"<Actions>/Menu/Message/Mark/MarkUnread",              "<shift>exclam"},
264                 {"<Actions>/Menu/Message/Mark/MarkRead",                ""},
265
266                 {"<Actions>/Menu/Tools/AddressBook",                    "<shift><control>A"},
267                 {"<Actions>/Menu/Tools/Execute",                        "X"},
268                 {"<Actions>/Menu/Tools/NetworkLog",                     "<shift><control>L"},
269                 /* compose */
270                 {"<Actions>/Menu/Message/Send",                         "<control>Return"},
271                 {"<Actions>/Menu/Message/SendLater",                    "<shift><control>S"},
272                 {"<Actions>/Menu/Message/AttachFile",                   "<control>M"},
273                 {"<Actions>/Menu/Message/InsertFile",                   "<control>I"},
274                 {"<Actions>/Menu/Message/InsertSig",                    "<control>G"},
275                 {"<Actions>/Menu/Message/Save",                         "<control>S"},
276                 {"<Actions>/Menu/Message/Close",                        "<control>W"},
277                 {"<Actions>/Menu/Edit/Undo",                            "<control>Z"},
278                 {"<Actions>/Menu/Edit/Redo",                            "<control>Y"},
279                 {"<Actions>/Menu/Edit/Cut",                             "<control>X"},
280                 {"<Actions>/Menu/Edit/Copy",                            "<control>C"},
281                 {"<Actions>/Menu/Edit/Paste",                           "<control>V"},
282                 {"<Actions>/Menu/Edit/SelectAll",                       "<control>A"},
283                 {"<Actions>/Menu/Edit/Advanced/BackChar",               "<control>B"},
284                 {"<Actions>/Menu/Edit/Advanced/ForwChar",               "<control>F"},
285                 {"<Actions>/Menu/Edit/Advanced/BackWord",               ""},
286                 {"<Actions>/Menu/Edit/Advanced/ForwWord",               ""},
287                 {"<Actions>/Menu/Edit/Advanced/BegLine",                ""},
288                 {"<Actions>/Menu/Edit/Advanced/EndLine",                "<control>E"},
289                 {"<Actions>/Menu/Edit/Advanced/PrevLine",               "<control>P"},
290                 {"<Actions>/Menu/Edit/Advanced/NextLine",               "<control>N"},
291                 {"<Actions>/Menu/Edit/Advanced/DelBackChar",            "<control>H"},
292                 {"<Actions>/Menu/Edit/Advanced/DelForwChar",            "<control>D"},
293                 {"<Actions>/Menu/Edit/Advanced/DelBackWord",            ""},
294                 {"<Actions>/Menu/Edit/Advanced/DelForwWord",            ""},
295                 {"<Actions>/Menu/Edit/Advanced/DelLine",                "<control>U"},
296                 {"<Actions>/Menu/Edit/Advanced/DelEndLine",             "<control>K"},
297                 {"<Actions>/Menu/Edit/WrapPara",                        "<control>L"},
298                 {"<Actions>/Menu/Edit/WrapAllLines",                    "<control><alt>L"},
299                 {"<Actions>/Menu/Edit/AutoWrap",                        "<shift><control>L"},
300                 {"<Actions>/Menu/Edit/ExtEditor",                       "<shift><control>X"},
301                 {"<Actions>/Menu/Tools/AddressBook",                    "<shift><control>A"},
302         };
303
304         static struct KeyBind mew_wl_menurc[] = {
305                 /* main */
306                 {"<Actions>/Menu/File/EmptyTrashes",                    "<shift>D"},
307                 {"<Actions>/Menu/File/SaveAs",                          "Y"},
308                 {"<Actions>/Menu/File/Print",                           "<control>numbersign"},
309                 {"<Actions>/Menu/File/Exit",                            "<shift>Q"},
310
311                 {"<Actions>/Menu/Edit/Copy",                            "<control>C"},
312                 {"<Actions>/Menu/Edit/SelectAll",                       "<control>A"},
313                 {"<Actions>/Menu/Edit/Find",                            "<control>F"},
314                 {"<Actions>/Menu/Edit/SearchFolder",                    "<control>S"},
315                 {"<Actions>/Menu/Edit/QuickSearch",                     "slash"},
316
317                 {"<Actions>/Menu/View/ShowHide/MessageView",            ""},
318                 {"<Actions>/Menu/View/ThreadView",                      "<shift>T"},
319                 {"<Actions>/Menu/View/Goto/Prev",                       "P"},
320                 {"<Actions>/Menu/View/Goto/Next",                       "N"},
321                 {"<Actions>/Menu/View/Goto/PrevUnread",                 "<shift>P"},
322                 {"<Actions>/Menu/View/Goto/NextUnread",                 "<shift>N"},
323                 {"<Actions>/Menu/View/Goto/Folder",                     "G"},
324                 {"<Actions>/Menu/View/OpenNewWindow",                   "<control><alt>N"},
325                 {"<Actions>/Menu/View/MessageSource",                   "<control>U"},
326                 {"<Actions>/Menu/View/AllHeaders",                      "<shift>H"},
327                 {"<Actions>/Menu/View/UpdateSummary",                   "<shift>S"},
328
329                 {"<Actions>/Menu/Message/Receive/CurrentAccount",
330                                                                         "<control>I"},
331                 {"<Actions>/Menu/Message/Receive/AllAccounts",          "<shift><control>I"},
332                 {"<Actions>/Menu/Message/ComposeEmail",                 "W"},
333                 {"<Actions>/Menu/Message/Reply",                        "<control>R"},
334                 {"<Actions>/Menu/Message/ReplyTo/All",                  "<shift>A"},
335                 {"<Actions>/Menu/Message/ReplyTo/Sender",               ""},
336                 {"<Actions>/Menu/Message/ReplyTo/List",                 "<control>L"},
337                 {"<Actions>/Menu/Message/Forward",                      "F"},
338                 {"<Actions>/Menu/Message/Move",                         "O"},
339                 {"<Actions>/Menu/Message/Copy",                         "<shift>O"},
340                 {"<Actions>/Menu/Message/Trash",                        "D"},
341                 {"<Actions>/Menu/Message/Mark/Mark",                    "<shift>asterisk"},
342                 {"<Actions>/Menu/Message/Mark/Unmark",                  "U"},
343                 {"<Actions>/Menu/Message/Mark/MarkUnread",              "<shift>exclam"},
344                 {"<Actions>/Menu/Message/Mark/MarkRead",                "<shift>R"},
345
346                 {"<Actions>/Menu/Tools/AddressBook",                    "<shift><control>A"},
347                 {"<Actions>/Menu/Tools/Execute",                        "X"},
348                 {"<Actions>/Menu/Tools/NetworkLog",                     "<shift><control>L"},
349                 /* compose */
350                 {"<Actions>/Menu/Message/Close",                        "<alt>W"},
351                 {"<Actions>/Menu/Edit/SelectAll",                       ""},
352                 {"<Actions>/Menu/Edit/Advanced/BackChar",               "<alt>B"},
353                 {"<Actions>/Menu/Edit/Advanced/ForwChar",               "<alt>F"},
354                 {"<Actions>/Menu/Edit/Advanced/BackWord",               ""},
355                 {"<Actions>/Menu/Edit/Advanced/ForwWord",               ""},
356                 {"<Actions>/Menu/Edit/Advanced/BegLine",                "<control>A"},
357                 {"<Actions>/Menu/Edit/Advanced/DelBackWord",            "<control>W"},
358                 {"<Actions>/Menu/Edit/Advanced/DelForwWord",            "<alt>D"},
359         };
360
361         static struct KeyBind mutt_menurc[] = {
362                 /* main */
363                 {"<Actions>/Menu/File/SaveAs",                          "S"}, /* save-message */
364                 {"<Actions>/Menu/File/Print",                           "P"}, /* print-message */
365                 {"<Actions>/Menu/File/Exit",                            "Q"}, /* quit */
366
367                 {"<Actions>/Menu/Edit/Copy",                            "<control>C"}, /* - */
368                 {"<Actions>/Menu/Edit/SelectAll",                       "<control>A"}, /* - */
369                 {"<Actions>/Menu/Edit/Find",                            "<alt>B"}, /* <esc>B: search in message bodies */
370                 {"<Actions>/Menu/Edit/SearchFolder",                    "slash"}, /* search */
371                 {"<Actions>/Menu/Edit/QuickSearch",                     "L"}, /* limit */
372
373                 {"<Actions>/Menu/View/ShowHide/MessageView",            "V"}, /* - */
374                 {"<Actions>/Menu/View/ThreadView",                      "<control>T"}, /* - */
375                 {"<Actions>/Menu/View/Goto/Prev",                       "K"}, /* previous-entry */
376                 {"<Actions>/Menu/View/Goto/Next",                       "J"}, /* next-entry */
377                 {"<Actions>/Menu/View/Goto/PrevUnread",                 "<alt>U"}, /* <esc>Tab: previous-new-then-unread */
378                 {"<Actions>/Menu/View/Goto/NextUnread",                 "U"}, /* Tab: next-new-then-unread */
379                 {"<Actions>/Menu/View/Goto/Folder",                     "C"}, /* change-folder */
380                 {"<Actions>/Menu/View/OpenNewWindow",                   "<control><alt>N"}, /* - */
381                 {"<Actions>/Menu/View/MessageSource",                   "E"}, /* edit the raw message */
382                 {"<Actions>/Menu/View/AllHeaders",                      "H"}, /* display-toggle-weed */
383                 {"<Actions>/Menu/View/UpdateSummary",                   "<control><alt>U"}, /* - */
384
385                 {"<Actions>/Menu/Message/Receive/CurrentAccount",       "<control>I"}, /* - */
386                 {"<Actions>/Menu/Message/Receive/AllAccounts",          "<shift>G"}, /* fetch-mail */
387                 {"<Actions>/Menu/Message/ComposeEmail",                 "M"}, /* mail */
388                 {"<Actions>/Menu/Message/Reply",                        "R"}, /* reply */
389                 {"<Actions>/Menu/Message/ReplyTo/All",                  "G"}, /* group-reply */
390                 {"<Actions>/Menu/Message/ReplyTo/List",                 "<shift>L"}, /* list-reply */
391                 {"<Actions>/Menu/Message/Forward",                      "F"}, /* forward-message */
392                 {"<Actions>/Menu/Message/Move",                         "<control>O"}, /* - */
393                 {"<Actions>/Menu/Message/Copy",                         "<shift>C"}, /* copy-message */
394                 {"<Actions>/Menu/Message/Trash",                        "D"}, /* delete-message */
395                 {"<Actions>/Menu/Message/Mark/Mark",                    "<shift>F"}, /* flag-message */
396                 {"<Actions>/Menu/Message/Mark/Unmark",                  "<control><shift>F"}, /* - */
397                 {"<Actions>/Menu/Message/Mark/MarkUnread",              "<shift>N"}, /* toggle-new */
398                 {"<Actions>/Menu/Message/Mark/MarkRead",                "<control>R"}, /* read-thread */
399
400                 {"<Actions>/Menu/Tools/AddressBook",                    "<shift><control>A"}, /* - */
401                 {"<Actions>/Menu/Tools/Execute",                        "dollar"}, /* sync-mailbox */
402                 {"<Actions>/Menu/Tools/NetworkLog",                     "<shift><control>L"}, /* - */
403                 /* compose */
404                 {"<Actions>/Menu/Message/Close",                        "<alt>W"}, /* - */
405                 {"<Actions>/Menu/Edit/Advanced/BackWord",               "<alt>B"}, /* - */
406                 {"<Actions>/Menu/Edit/Advanced/ForwWord",               "<alt>F"}, /* - */
407                 {"<Actions>/Menu/Edit/Advanced/BegLine",                "<control>A"}, /* - */
408                 {"<Actions>/Menu/Edit/Advanced/DelBackWord",            "<control>W"}, /* - */
409                 {"<Actions>/Menu/Edit/Advanced/DelForwWord",            "<alt>D"}, /* - */
410         };
411
412 #if !GTK_CHECK_VERSION(2, 24, 0)
413         text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(keybind.combo));
414 #else
415         text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(keybind.combo));
416 #endif
417
418         if (!strcmp(text, _("Default"))) {
419                 menurc = default_menurc;
420                 n_menurc = G_N_ELEMENTS(default_menurc);
421         } else if (!strcmp(text, "Mew / Wanderlust")) {
422                 menurc = mew_wl_menurc;
423                 n_menurc = G_N_ELEMENTS(mew_wl_menurc);
424         } else if (!strcmp(text, "Mutt")) {
425                 menurc = mutt_menurc;
426                 n_menurc = G_N_ELEMENTS(mutt_menurc);
427         } else {
428                 g_free(text);
429                 return;
430         }
431         g_free(text);
432
433         prefs_keybind_apply(menurc, n_menurc);
434
435         gtk_widget_destroy(keybind.window);
436         keybind.window = NULL;
437         keybind.combo = NULL;
438 }
439
440 static void prefs_other_create_widget(PrefsPage *_page, GtkWindow *window, 
441                                   gpointer data)
442 {
443         OtherPage *prefs_other = (OtherPage *) _page;
444         
445         GtkWidget *vbox1;
446         GtkWidget *hbox1;
447
448         GtkWidget *frame_addr;
449         GtkWidget *vbox_addr;
450         GtkWidget *checkbtn_addaddrbyclick;
451         
452         GtkWidget *frame_exit;
453         GtkWidget *vbox_exit;
454         GtkWidget *checkbtn_confonexit;
455         GtkWidget *checkbtn_cleanonexit;
456         GtkWidget *checkbtn_warnqueued;
457
458         GtkWidget *frame_keys;
459         GtkWidget *vbox_keys;
460         GtkWidget *checkbtn_gtk_can_change_accels;
461         GtkWidget *button_keybind;
462
463         GtkWidget *label_iotimeout;
464         GtkWidget *spinbtn_iotimeout;
465         GtkAdjustment *spinbtn_iotimeout_adj;
466
467         GtkWidget *vbox2;
468         GtkWidget *checkbtn_askonclean;
469         GtkWidget *checkbtn_askonfilter;
470         GtkWidget *checkbtn_use_shred;
471         GtkWidget *checkbtn_real_time_sync;
472
473         GtkWidget *frame_metadata;
474         GtkWidget *vbox_metadata;
475         GtkWidget *metadata_label;
476         GtkWidget *flush_metadata_faster_radiobtn;
477         GtkWidget *flush_metadata_safer_radiobtn;
478
479 #ifndef PASSWORD_CRYPTO_OLD
480         GtkWidget *vbox_passphrase;
481         GtkWidget *frame_passphrase;
482         GtkWidget *checkbtn_use_passphrase;
483         GtkWidget *button_change_passphrase;
484 #endif
485
486         gchar *shred_binary = NULL;
487
488         vbox1 = gtk_vbox_new (FALSE, VSPACING);
489         gtk_widget_show (vbox1);
490         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
491
492         vbox_addr = gtkut_get_options_frame(vbox1, &frame_addr, _("Address book"));
493
494         PACK_CHECK_BUTTON
495                 (vbox_addr, checkbtn_addaddrbyclick,
496                  _("Add address to destination when double-clicked"));
497
498         /* On Exit */
499         vbox_exit = gtkut_get_options_frame(vbox1, &frame_exit, _("On exit"));
500
501         PACK_CHECK_BUTTON (vbox_exit, checkbtn_confonexit,
502                            _("Confirm on exit"));
503
504         hbox1 = gtk_hbox_new (FALSE, 32);
505         gtk_widget_show (hbox1);
506         gtk_box_pack_start (GTK_BOX (vbox_exit), hbox1, FALSE, FALSE, 0);
507
508         PACK_CHECK_BUTTON (hbox1, checkbtn_cleanonexit,
509                            _("Empty trash on exit"));
510
511         PACK_CHECK_BUTTON (vbox_exit, checkbtn_warnqueued,
512                            _("Warn if there are queued messages"));
513
514         vbox_keys = gtkut_get_options_frame(vbox1, &frame_keys, _("Keyboard shortcuts"));
515
516         PACK_CHECK_BUTTON(vbox_keys, checkbtn_gtk_can_change_accels,
517                         _("Enable customisable keyboard shortcuts"));
518
519         CLAWS_SET_TIP(checkbtn_gtk_can_change_accels,
520                         _("If checked, you can change the keyboard shortcuts of "
521                                 "most of the menu items by focusing on the menu "
522                                 "item and pressing a key combination.\n"
523                                 "Uncheck this option if you want to lock all "
524                                 "existing keyboard shortcuts."));
525
526         button_keybind = gtk_button_new_with_label(
527                                 _(" Choose preset keyboard shortcuts... "));
528         gtk_widget_show (button_keybind);
529         hbox1 = gtk_hbox_new (FALSE, 8);
530         gtk_widget_show (hbox1);
531         gtk_box_pack_start (GTK_BOX (vbox_keys), hbox1, FALSE, FALSE, 0);
532         gtk_box_pack_start (GTK_BOX (hbox1), button_keybind, FALSE, FALSE, 0);
533         g_signal_connect (G_OBJECT (button_keybind), "clicked",
534                           G_CALLBACK (prefs_keybind_select), NULL);
535
536
537         vbox_metadata = gtkut_get_options_frame(vbox1, &frame_metadata, _("Metadata handling"));
538         metadata_label = gtk_label_new(_("Safer mode asks the OS to write metadata to disk directly;\n"
539                                          "it avoids data loss after crashes but can take some time."));
540         gtk_misc_set_alignment(GTK_MISC(metadata_label), 0, 0);
541         gtk_box_pack_start (GTK_BOX (vbox_metadata), metadata_label, FALSE, FALSE, 0);
542         flush_metadata_safer_radiobtn = gtk_radio_button_new_with_label(NULL, _("Safer"));
543         flush_metadata_faster_radiobtn = gtk_radio_button_new_with_label_from_widget(
544                                            GTK_RADIO_BUTTON(flush_metadata_safer_radiobtn), _("Faster"));
545         hbox1 = gtk_hbox_new (FALSE, 8);
546         gtk_widget_show (hbox1);
547         gtk_box_pack_start (GTK_BOX (vbox_metadata), hbox1, FALSE, FALSE, 0);
548         gtk_box_pack_start (GTK_BOX (hbox1), flush_metadata_safer_radiobtn, FALSE, FALSE, 0);
549         gtk_box_pack_start (GTK_BOX (hbox1), flush_metadata_faster_radiobtn, FALSE, FALSE, 0);
550         
551         if (prefs_common.flush_metadata)
552                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(flush_metadata_safer_radiobtn), TRUE);
553         else
554                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(flush_metadata_faster_radiobtn), TRUE);
555
556         gtk_widget_show_all(frame_metadata);
557
558         hbox1 = gtk_hbox_new (FALSE, 8);
559         gtk_widget_show (hbox1);
560         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
561
562         label_iotimeout = gtk_label_new (_("Socket I/O timeout"));
563         gtk_widget_show (label_iotimeout);
564         gtk_box_pack_start (GTK_BOX (hbox1), label_iotimeout, FALSE, FALSE, 0);
565
566         spinbtn_iotimeout_adj = GTK_ADJUSTMENT(gtk_adjustment_new (60, 0, 1000, 1, 10, 0));
567         spinbtn_iotimeout = gtk_spin_button_new
568                 (GTK_ADJUSTMENT (spinbtn_iotimeout_adj), 1, 0);
569         gtk_widget_show (spinbtn_iotimeout);
570         gtk_box_pack_start (GTK_BOX (hbox1), spinbtn_iotimeout,
571                             FALSE, FALSE, 0);
572         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_iotimeout), TRUE);
573
574         label_iotimeout = gtk_label_new (_("seconds"));
575         gtk_widget_show (label_iotimeout);
576         gtk_box_pack_start (GTK_BOX (hbox1), label_iotimeout, FALSE, FALSE, 0);
577
578         vbox2 = gtk_vbox_new (FALSE, 8);
579         gtk_widget_show (vbox2);
580         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
581
582         PACK_CHECK_BUTTON (vbox2, checkbtn_askonclean, 
583                            _("Ask before emptying trash"));
584         PACK_CHECK_BUTTON (vbox2, checkbtn_askonfilter,
585                            _("Ask about account specific filtering rules when "
586                              "filtering manually"));
587         shred_binary = g_find_program_in_path("shred");
588         if (shred_binary) {
589                 PACK_CHECK_BUTTON (vbox2, checkbtn_use_shred,
590                                    _("Use secure file deletion if possible"));
591                 g_free(shred_binary);
592         } else {
593                 PACK_CHECK_BUTTON (vbox2, checkbtn_use_shred,
594                                    _("Use secure file deletion if possible\n"
595                                      "(the 'shred' program is not available)"));
596                 gtk_widget_set_sensitive(checkbtn_use_shred, FALSE);
597         }
598         CLAWS_SET_TIP(checkbtn_use_shred,
599                         _("Use the 'shred' program to overwrite files with random data before "
600                           "deleting them. This slows down deletion. Be sure to "
601                           "read shred's man page for caveats."));
602         PACK_CHECK_BUTTON (vbox2, checkbtn_real_time_sync,
603                            _("Synchronise offline folders as soon as possible"));
604
605 #ifndef PASSWORD_CRYPTO_OLD
606         vbox_passphrase = gtkut_get_options_frame(vbox1, &frame_passphrase, _("Master passphrase"));
607
608         PACK_CHECK_BUTTON(vbox_passphrase, checkbtn_use_passphrase,
609                         _("Use a master passphrase"));
610
611         CLAWS_SET_TIP(checkbtn_use_passphrase,
612                         _("If checked, your saved account passwords will be protected "
613                                 "by a master passphrase. If no master passphrase is set, "
614                                 "you will be prompted to set one."));
615
616         button_change_passphrase = gtk_button_new_with_label(
617                         _("Change master passphrase"));
618         gtk_widget_show (button_change_passphrase);
619         hbox1 = gtk_hbox_new (FALSE, 8);
620         gtk_widget_show (hbox1);
621         gtk_box_pack_start (GTK_BOX (vbox_passphrase), hbox1, FALSE, FALSE, 0);
622         gtk_box_pack_start (GTK_BOX (hbox1), button_change_passphrase,
623                         FALSE, FALSE, 0);
624         g_signal_connect (G_OBJECT (checkbtn_use_passphrase), "toggled",
625                                 G_CALLBACK (prefs_use_passphrase_toggled), button_change_passphrase);
626         g_signal_connect (G_OBJECT (button_change_passphrase), "clicked",
627                           G_CALLBACK (prefs_change_master_passphrase), NULL);
628 #endif
629
630         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_addaddrbyclick), 
631                 prefs_common.add_address_by_click);
632         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_confonexit), 
633                 prefs_common.confirm_on_exit);
634         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_cleanonexit), 
635                 prefs_common.clean_on_exit);
636         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_askonclean), 
637                 prefs_common.ask_on_clean);
638         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_warnqueued), 
639                 prefs_common.warn_queued_on_exit);
640         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_gtk_can_change_accels),
641                 prefs_common.gtk_can_change_accels);
642
643         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_iotimeout),
644                 prefs_common.io_timeout_secs);
645
646         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_askonfilter), 
647                 prefs_common.ask_apply_per_account_filtering_rules);
648         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_use_shred), 
649                 prefs_common.use_shred);
650         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_real_time_sync), 
651                 prefs_common.real_time_sync);
652
653 #ifndef PASSWORD_CRYPTO_OLD
654         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_use_passphrase),
655                 prefs_common.use_master_passphrase);
656         gtk_widget_set_sensitive(button_change_passphrase,
657                         prefs_common.use_master_passphrase);
658 #endif
659
660         prefs_other->checkbtn_addaddrbyclick = checkbtn_addaddrbyclick;
661         prefs_other->checkbtn_confonexit = checkbtn_confonexit;
662         prefs_other->checkbtn_cleanonexit = checkbtn_cleanonexit;
663         prefs_other->checkbtn_askonclean = checkbtn_askonclean;
664         prefs_other->checkbtn_warnqueued = checkbtn_warnqueued;
665         prefs_other->spinbtn_iotimeout = spinbtn_iotimeout;
666         prefs_other->checkbtn_gtk_can_change_accels = checkbtn_gtk_can_change_accels;
667         prefs_other->checkbtn_askonfilter = checkbtn_askonfilter;
668         prefs_other->checkbtn_use_shred = checkbtn_use_shred;
669         prefs_other->checkbtn_real_time_sync = checkbtn_real_time_sync;
670         prefs_other->flush_metadata_safer_radiobtn = flush_metadata_safer_radiobtn;
671         prefs_other->flush_metadata_faster_radiobtn = flush_metadata_faster_radiobtn;
672 #ifndef PASSWORD_CRYPTO_OLD
673         prefs_other->checkbtn_use_passphrase = checkbtn_use_passphrase;
674 #endif
675         prefs_other->page.widget = vbox1;
676 }
677
678 static void prefs_other_save(PrefsPage *_page)
679 {
680         OtherPage *page = (OtherPage *) _page;
681         gboolean gtk_can_change_accels;
682
683         prefs_common.add_address_by_click = gtk_toggle_button_get_active(
684                 GTK_TOGGLE_BUTTON(page->checkbtn_addaddrbyclick));
685         prefs_common.confirm_on_exit = gtk_toggle_button_get_active(
686                 GTK_TOGGLE_BUTTON(page->checkbtn_confonexit));
687         prefs_common.clean_on_exit = gtk_toggle_button_get_active(
688                 GTK_TOGGLE_BUTTON(page->checkbtn_cleanonexit)); 
689         prefs_common.ask_on_clean = gtk_toggle_button_get_active(
690                 GTK_TOGGLE_BUTTON(page->checkbtn_askonclean));
691         prefs_common.warn_queued_on_exit = gtk_toggle_button_get_active(
692                 GTK_TOGGLE_BUTTON(page->checkbtn_warnqueued)); 
693         prefs_common.io_timeout_secs = gtk_spin_button_get_value_as_int(
694                 GTK_SPIN_BUTTON(page->spinbtn_iotimeout));
695         prefs_common.flush_metadata = gtk_toggle_button_get_active(
696                 GTK_TOGGLE_BUTTON(page->flush_metadata_safer_radiobtn));
697         sock_set_io_timeout(prefs_common.io_timeout_secs);
698 #ifdef HAVE_LIBETPAN
699         imap_main_set_timeout(prefs_common.io_timeout_secs);
700 #endif
701         prefs_common.ask_apply_per_account_filtering_rules = 
702                 gtk_toggle_button_get_active(
703                         GTK_TOGGLE_BUTTON(page->checkbtn_askonfilter)); 
704         prefs_common.use_shred = 
705                 gtk_toggle_button_get_active(
706                         GTK_TOGGLE_BUTTON(page->checkbtn_use_shred)); 
707         prefs_common.real_time_sync = 
708                 gtk_toggle_button_get_active(
709                         GTK_TOGGLE_BUTTON(page->checkbtn_real_time_sync));
710
711 #ifndef PASSWORD_CRYPTO_OLD
712         /* If we're disabling use of master passphrase, we need to reencrypt
713          * all account passwords with hardcoded key. */
714         if (!gtk_toggle_button_get_active(
715                         GTK_TOGGLE_BUTTON(page->checkbtn_use_passphrase))
716                         && master_passphrase_is_set()) {
717                 master_passphrase_change(NULL, NULL);
718
719                 /* In case user did not finish the passphrase change process
720                  * (e.g. did not enter a correct current master passphrase),
721                  * we need to enable the "use master passphrase" checkbox again,
722                  * since the old master passphrase is still valid. */
723                 if (master_passphrase_is_set()) {
724                         gtk_toggle_button_set_active(
725                                 GTK_TOGGLE_BUTTON(page->checkbtn_use_passphrase), TRUE);
726                 }
727         }
728
729         if (gtk_toggle_button_get_active(
730                         GTK_TOGGLE_BUTTON(page->checkbtn_use_passphrase))
731                         && !master_passphrase_is_set()) {
732                 master_passphrase_change_dialog();
733
734                 /* In case user cancelled the passphrase change dialog, we need
735                  * to disable the "use master passphrase" checkbox. */
736                 if (!master_passphrase_is_set()) {
737                         gtk_toggle_button_set_active(
738                                 GTK_TOGGLE_BUTTON(page->checkbtn_use_passphrase), FALSE);
739                 }
740         }
741
742         prefs_common.use_master_passphrase =
743                 gtk_toggle_button_get_active(
744                         GTK_TOGGLE_BUTTON(page->checkbtn_use_passphrase));
745 #endif
746
747         gtk_can_change_accels = gtk_toggle_button_get_active(
748                 GTK_TOGGLE_BUTTON(page->checkbtn_gtk_can_change_accels));
749
750         if (prefs_common.gtk_can_change_accels != gtk_can_change_accels) {
751
752                 prefs_common.gtk_can_change_accels = gtk_can_change_accels;
753
754                 gtk_settings_set_long_property(gtk_settings_get_default(),
755                                 "gtk-can-change-accels",
756                                 (glong)prefs_common.gtk_can_change_accels,
757                                 "XProperty");
758
759                 /* gtk_can_change_accels value changed : we have (only if changed)
760                  * to apply the gtk property to all widgets : */
761                 gtk_rc_reparse_all_for_settings(gtk_settings_get_default(), TRUE);
762         }
763 }
764
765 static void prefs_other_destroy_widget(PrefsPage *_page)
766 {
767 }
768
769 OtherPage *prefs_other;
770
771 void prefs_other_init(void)
772 {
773         OtherPage *page;
774         static gchar *path[3];
775
776         path[0] = _("Other");
777         path[1] = _("Miscellaneous");
778         path[2] = NULL;
779
780         page = g_new0(OtherPage, 1);
781         page->page.path = path;
782         page->page.create_widget = prefs_other_create_widget;
783         page->page.destroy_widget = prefs_other_destroy_widget;
784         page->page.save_page = prefs_other_save;
785         page->page.weight = 5.0;
786         prefs_gtk_register_page((PrefsPage *) page);
787         prefs_other = page;
788
789         gtk_settings_set_long_property(gtk_settings_get_default(),
790                         "gtk-can-change-accels",
791                         (glong)prefs_common.gtk_can_change_accels,
792                         "XProperty");
793 }
794
795 void prefs_other_done(void)
796 {
797         prefs_gtk_unregister_page((PrefsPage *) prefs_other);
798         g_free(prefs_other);
799 }
800
801 #ifndef PASSWORD_CRYPTO_OLD
802 void prefs_change_master_passphrase(GtkButton *button, gpointer data)
803 {
804         /* Call the passphrase change dialog */
805         master_passphrase_change_dialog();
806 }
807
808 void prefs_use_passphrase_toggled(GtkToggleButton *chkbtn, gpointer data)
809 {
810         GtkWidget *button = GTK_WIDGET(data);
811         gboolean active = gtk_toggle_button_get_active(chkbtn);
812
813         if (!active)
814                 gtk_widget_set_sensitive(button, active);
815 }
816 #endif