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