fc6669f363fad0d6be838698e255e3648d60e27a
[claws.git] / src / prefs_other.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2005-2007 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 *checkbtn_session_passwords;
63 } OtherPage;
64
65 static struct KeybindDialog {
66         GtkWidget *window;
67         GtkWidget *combo;
68 } keybind;
69
70 static void prefs_keybind_select                (void);
71 static gint prefs_keybind_deleted               (GtkWidget      *widget,
72                                                  GdkEventAny    *event,
73                                                  gpointer        data);
74 static gboolean prefs_keybind_key_pressed       (GtkWidget      *widget,
75                                                  GdkEventKey    *event,
76                                                  gpointer        data);
77 static void prefs_keybind_cancel                (void);
78 static void prefs_keybind_apply_clicked         (GtkWidget      *widget);
79
80
81 static void prefs_keybind_select(void)
82 {
83         GtkWidget *window;
84         GtkWidget *vbox1;
85         GtkWidget *hbox1;
86         GtkWidget *label;
87         GtkWidget *combo;
88         GtkWidget *confirm_area;
89         GtkWidget *ok_btn;
90         GtkWidget *cancel_btn;
91
92         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_other");
93         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
94         gtk_window_set_title (GTK_WINDOW (window), 
95                                 _("Choose preset keyboard shortcuts"));
96         gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
97         gtk_window_set_modal (GTK_WINDOW (window), TRUE);
98         gtk_window_set_resizable(GTK_WINDOW (window), FALSE);
99         manage_window_set_transient (GTK_WINDOW (window));
100
101         vbox1 = gtk_vbox_new (FALSE, VSPACING);
102         gtk_container_add (GTK_CONTAINER (window), vbox1);
103         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
104
105         hbox1 = gtk_hbox_new (FALSE, 8);
106         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
107
108         label = gtk_label_new
109                 (_("Select preset:"));
110         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
111         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
112
113         combo = combobox_text_new(FALSE,
114                                _("Default"),
115                                "Mew / Wanderlust",
116                                "Mutt",
117                                _("Old Sylpheed"),
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>/File/Empty all Trash folders",         "<shift>D"},
209                 {"<Main>/File/Save as...",                      "<control>S"},
210                 {"<Main>/File/Print...",                        "<control>P"},
211                 {"<Main>/File/Work offline",                    "<control>W"},
212                 {"<Main>/File/Synchronise folders",             "<control><shift>S"},
213                 {"<Main>/File/Exit",                            "<control>Q"},
214
215                 {"<Main>/Edit/Copy",                            "<control>C"},
216                 {"<Main>/Edit/Select all",                      "<control>A"},
217                 {"<Main>/Edit/Find in current message...",      "<control>F"},
218                 {"<Main>/Edit/Search folder...",                "<shift><control>F"},
219                 {"<Main>/Edit/Quick search",                    "slash"},
220
221                 {"<Main>/View/Show or hide/Message View",       "V"},
222                 {"<Main>/View/Thread view",                     "<control>T"},
223                 {"<Main>/View/Go to/Previous message",          "P"},
224                 {"<Main>/View/Go to/Next message",              "N"},
225                 {"<Main>/View/Go to/Previous unread message",   "<shift>P"},
226                 {"<Main>/View/Go to/Next unread message",       "<shift>N"},
227                 {"<Main>/View/Go to/Other folder...",           "G"},
228                 {"<Main>/View/Open in new window",              "<control><alt>N"},
229                 {"<Main>/View/Message source",                  "<control>U"},
230                 {"<Main>/View/All headers",                     "<control>H"},
231                 {"<Main>/View/Update summary",                  "<control><alt>U"},
232
233                 {"<Main>/Message/Receive/Get from current account",
234                                                                 "<control>I"},
235                 {"<Main>/Message/Receive/Get from all accounts","<shift><control>I"},
236                 {"<Main>/Message/Compose an email message",     "<control>M"},
237                 {"<Main>/Message/Reply",                        "<control>R"},
238                 {"<Main>/Message/Reply to/all",                 "<shift><control>R"},
239                 {"<Main>/Message/Reply to/sender",              ""},
240                 {"<Main>/Message/Reply to/mailing list",        "<control>L"},
241                 {"<Main>/Message/Forward",                      "<control><alt>F"},
242                 /* {"<Main>/Message/Forward as attachment",      ""}, */
243                 {"<Main>/Message/Move...",                      "<control>O"},
244                 {"<Main>/Message/Copy...",                      "<shift><control>O"},
245                 {"<Main>/Message/Move to trash",                "<control>D"},
246                 {"<Main>/Message/Mark/Mark",                    "<shift>asterisk"},
247                 {"<Main>/Message/Mark/Unmark",                  "U"},
248                 {"<Main>/Message/Mark/Mark as unread",          "<shift>exclam"},
249                 {"<Main>/Message/Mark/Mark as read",            ""},
250
251                 {"<Main>/Tools/Address book",                   "<shift><control>A"},
252                 {"<Main>/Tools/Execute",                        "X"},
253                 {"<Main>/Tools/Log window",                     "<shift><control>L"},
254
255                 {"<Compose>/Message/Send",                              "<control>Return"},
256                 {"<Compose>/Message/Send later",                        "<shift><control>S"},
257                 {"<Compose>/Message/Attach file",                       "<control>M"},
258                 {"<Compose>/Message/Insert file",                       "<control>I"},
259                 {"<Compose>/Message/Insert signature",                  "<control>G"},
260                 {"<Compose>/Message/Save",                              "<control>S"},
261                 {"<Compose>/Message/Close",                             "<control>W"},
262                 {"<Compose>/Edit/Undo",                                 "<control>Z"},
263                 {"<Compose>/Edit/Redo",                                 "<control>Y"},
264                 {"<Compose>/Edit/Cut",                                  "<control>X"},
265                 {"<Compose>/Edit/Copy",                                 "<control>C"},
266                 {"<Compose>/Edit/Paste",                                "<control>V"},
267                 {"<Compose>/Edit/Select all",                           "<control>A"},
268                 {"<Compose>/Edit/Advanced/Move a character backward",   "<control>B"},
269                 {"<Compose>/Edit/Advanced/Move a character forward",    "<control>F"},
270                 {"<Compose>/Edit/Advanced/Move a word backward,"        ""},
271                 {"<Compose>/Edit/Advanced/Move a word forward",         ""},
272                 {"<Compose>/Edit/Advanced/Move to beginning of line",   ""},
273                 {"<Compose>/Edit/Advanced/Move to end of line",         "<control>E"},
274                 {"<Compose>/Edit/Advanced/Move to previous line",       "<control>P"},
275                 {"<Compose>/Edit/Advanced/Move to next line",           "<control>N"},
276                 {"<Compose>/Edit/Advanced/Delete a character backward", "<control>H"},
277                 {"<Compose>/Edit/Advanced/Delete a character forward",  "<control>D"},
278                 {"<Compose>/Edit/Advanced/Delete a word backward",      ""},
279                 {"<Compose>/Edit/Advanced/Delete a word forward",       ""},
280                 {"<Compose>/Edit/Advanced/Delete line",                 "<control>U"},
281                 {"<Compose>/Edit/Advanced/Delete entire line",          ""},
282                 {"<Compose>/Edit/Advanced/Delete to end of line",       "<control>K"},
283                 {"<Compose>/Edit/Wrap current paragraph",               "<control>L"},
284                 {"<Compose>/Edit/Wrap all long lines",                  "<control><alt>L"},
285                 {"<Compose>/Edit/Auto wrapping",                        "<shift><control>L"},
286                 {"<Compose>/Edit/Edit with external editor",            "<shift><control>X"},
287                 {"<Compose>/Tools/Address book",                        "<shift><control>A"},
288         };
289
290         static struct KeyBind mew_wl_menurc[] = {
291                 {"<Main>/File/Empty all Trash folders",         "<shift>D"},
292                 {"<Main>/File/Save as...",                      "Y"},
293                 {"<Main>/File/Print...",                        "<shift>numbersign"},
294                 {"<Main>/File/Exit",                            "<shift>Q"},
295
296                 {"<Main>/Edit/Copy",                            "<control>C"},
297                 {"<Main>/Edit/Select all",                      "<control>A"},
298                 {"<Main>/Edit/Find in current message...",      "<control>F"},
299                 {"<Main>/Edit/Search folder...",                "<control>S"},
300
301                 {"<Main>/View/Show or hide/Message View",       ""},
302                 {"<Main>/View/Thread view",                     "<shift>T"},
303                 {"<Main>/View/Go to/Previous message",          "P"},
304                 {"<Main>/View/Go to/Next message",              "N"},
305                 {"<Main>/View/Go to/Previous unread message",   "<shift>P"},
306                 {"<Main>/View/Go to/Next unread message",       "<shift>N"},
307                 {"<Main>/View/Go to/Other folder...",           "G"},
308                 {"<Main>/View/Open in new window",              "<control><alt>N"},
309                 {"<Main>/View/Message source",                  "<control>U"},
310                 {"<Main>/View/All headers",                     "<shift>H"},
311                 {"<Main>/View/Update summary",                  "<shift>S"},
312
313                 {"<Main>/Message/Receive/Get from current account",
314                                                                 "<control>I"},
315                 {"<Main>/Message/Receive/Get from all accounts","<shift><control>I"},
316                 {"<Main>/Message/Compose an email message",     "W"},
317                 {"<Main>/Message/Reply",                        "<control>R"},
318                 {"<Main>/Message/Reply to/all",                 "<shift>A"},
319                 {"<Main>/Message/Reply to/sender",              ""},
320                 {"<Main>/Message/Reply to/mailing list",        "<control>L"},
321                 {"<Main>/Message/Forward",                      "F"},
322                 /* {"<Main>/Message/Forward as attachment", "<shift>F"}, */
323                 {"<Main>/Message/Move...",                      "O"},
324                 {"<Main>/Message/Copy...",                      "<shift>O"},
325                 {"<Main>/Message/Delete",                       "D"},
326                 {"<Main>/Message/Mark/Mark",                    "<shift>asterisk"},
327                 {"<Main>/Message/Mark/Unmark",                  "U"},
328                 {"<Main>/Message/Mark/Mark as unread",          "<shift>exclam"},
329                 {"<Main>/Message/Mark/Mark as read",            "<shift>R"},
330
331                 {"<Main>/Tools/Address book",                   "<shift><control>A"},
332                 {"<Main>/Tools/Execute",                        "X"},
333                 {"<Main>/Tools/Log window",                     "<shift><control>L"},
334
335                 {"<Compose>/Message/Close",                             "<alt>W"},
336                 {"<Compose>/Edit/Select all",                           ""},
337                 {"<Compose>/Edit/Advanced/Move a word backward,"        "<alt>B"},
338                 {"<Compose>/Edit/Advanced/Move a word forward",         "<alt>F"},
339                 {"<Compose>/Edit/Advanced/Move to beginning of line",   "<control>A"},
340                 {"<Compose>/Edit/Advanced/Delete a word backward",      "<control>W"},
341                 {"<Compose>/Edit/Advanced/Delete a word forward",       "<alt>D"},
342         };
343
344         static struct KeyBind mutt_menurc[] = {
345                 {"<Main>/File/Empty all Trash folders",         ""},
346                 {"<Main>/File/Save as...",                      "S"},
347                 {"<Main>/File/Print...",                        "P"},
348                 {"<Main>/File/Exit",                            "Q"},
349
350                 {"<Main>/Edit/Copy",                            "<control>C"},
351                 {"<Main>/Edit/Select all",                      "<control>A"},
352                 {"<Main>/Edit/Find in current message...",      "<control>F"},
353                 {"<Main>/Edit/Search messages...",              "slash"},
354
355                 {"<Main>/View/Show or hide/Message view",       "V"},
356                 {"<Main>/View/Thread view",                     "<control>T"},
357                 {"<Main>/View/Go to/Previous message",          ""},
358                 {"<Main>/View/Go to/Next message",              ""},
359                 {"<Main>/View/Go to/Previous unread message",   ""},
360                 {"<Main>/View/Go to/Next unread message",       ""},
361                 {"<Main>/View/Go to/Other folder...",           "C"},
362                 {"<Main>/View/Open in new window",              "<control><alt>N"},
363                 {"<Main>/View/Message source",                  "<control>U"},
364                 {"<Main>/View/All headers",                     "<control>H"},
365                 {"<Main>/View/Update summary",                  "<control><alt>U"},
366
367                 {"<Main>/Message/Receive/Get from current account",
368                                                                 "<control>I"},
369                 {"<Main>/Message/Receive/Get from all accounts","<shift><control>I"},
370                 {"<Main>/Message/Compose an email message",             "M"},
371                 {"<Main>/Message/Reply",                        "R"},
372                 {"<Main>/Message/Reply to/all",                 "G"},
373                 {"<Main>/Message/Reply to/sender",              ""},
374                 {"<Main>/Message/Reply to/mailing list",        "<control>L"},
375                 {"<Main>/Message/Forward",                      "F"},
376                 {"<Main>/Message/Forward as attachment",        ""},
377                 {"<Main>/Message/Move...",                      "<control>O"},
378                 {"<Main>/Message/Copy...",                      "<shift>C"},
379                 {"<Main>/Message/Delete",                       "D"},
380                 {"<Main>/Message/Mark/Mark",                    "<shift>F"},
381                 {"<Main>/Message/Mark/Unmark",                  "U"},
382                 {"<Main>/Message/Mark/Mark as unread",          "<shift>N"},
383                 {"<Main>/Message/Mark/Mark as read",            ""},
384
385                 {"<Main>/Tools/Address book",                   "<shift><control>A"},
386                 {"<Main>/Tools/Execute",                        "X"},
387                 {"<Main>/Tools/Log window",                     "<shift><control>L"},
388
389                 {"<Compose>/Message/Close",                             "<alt>W"},
390                 {"<Compose>/Edit/Select all",                           ""},
391                 {"<Compose>/Edit/Advanced/Move a word backward",        "<alt>B"},
392                 {"<Compose>/Edit/Advanced/Move a word forward",         "<alt>F"},
393                 {"<Compose>/Edit/Advanced/Move to beginning of line",   "<control>A"},
394                 {"<Compose>/Edit/Advanced/Delete a word backward",      "<control>W"},
395                 {"<Compose>/Edit/Advanced/Delete a word forward",       "<alt>D"},
396         };
397
398         static struct KeyBind old_sylpheed_menurc[] = {
399                 {"<Main>/File/Empty all Trash folders",         ""},
400                 {"<Main>/File/Save as...",                      ""},
401                 {"<Main>/File/Print...",                        "<alt>P"},
402                 {"<Main>/File/Exit",                            "<alt>Q"},
403
404                 {"<Main>/Edit/Copy",                            "<control>C"},
405                 {"<Main>/Edit/Select all",                      "<control>A"},
406                 {"<Main>/Edit/Find in current message...",      "<control>F"},
407                 {"<Main>/Edit/Search folder...",                "<control>S"},
408
409                 {"<Main>/View/Show or hide/Message View",       ""},
410                 {"<Main>/View/Thread view",                     "<control>T"},
411                 {"<Main>/View/Go to/Previous message",          "P"},
412                 {"<Main>/View/Go to/Next message",              "N"},
413                 {"<Main>/View/Go to/Previous unread message",   "<shift>P"},
414                 {"<Main>/View/Go to/Next unread message",       "<shift>N"},
415                 {"<Main>/View/Go to/Other folder...",           "<alt>G"},
416                 {"<Main>/View/Open in new window",              "<shift><control>N"},
417                 {"<Main>/View/Message source",                  "<control>U"},
418                 {"<Main>/View/All headers",                     "<control>H"},
419                 {"<Main>/View/Update summary",                  "<alt>U"},
420
421                 {"<Main>/Message/Receive/Get from current account",
422                                                                 "<alt>I"},
423                 {"<Main>/Message/Receive/Get from all accounts","<shift><alt>I"},
424                 {"<Main>/Message/Compose an email message",     "<alt>N"},
425                 {"<Main>/Message/Reply",                        "<alt>R"},
426                 {"<Main>/Message/Reply to/all",                 "<shift><alt>R"},
427                 {"<Main>/Message/Reply to/sender",              "<control><alt>R"},
428                 {"<Main>/Message/Reply to/mailing list",        "<control>L"},
429                 {"<Main>/Message/Forward",                       "<shift><alt>F"},
430                 /* "(menu-path \"<Main>/Message/Forward as attachment", "<shift><control>F"}, */
431                 {"<Main>/Message/Move...",                      "<alt>O"},
432                 {"<Main>/Message/Copy...",                      ""},
433                 {"<Main>/Message/Delete",                       "<alt>D"},
434                 {"<Main>/Message/Mark/Mark",                    "<shift>asterisk"},
435                 {"<Main>/Message/Mark/Unmark",                  "U"},
436                 {"<Main>/Message/Mark/Mark as unread",          "<shift>exclam"},
437                 {"<Main>/Message/Mark/Mark as read",            ""},
438
439                 {"<Main>/Tools/Address book",                   "<alt>A"},
440                 {"<Main>/Tools/Execute",                        "<alt>X"},
441                 {"<Main>/Tools/Log window",                     "<alt>L"},
442
443                 {"<Compose>/Message/Close",                             "<alt>W"},
444                 {"<Compose>/Edit/Select all",                           ""},
445                 {"<Compose>/Edit/Advanced/Move a word backward",        "<alt>B"},
446                 {"<Compose>/Edit/Advanced/Move a word forward",         "<alt>F"},
447                 {"<Compose>/Edit/Advanced/Move to beginning of line",   "<control>A"},
448                 {"<Compose>/Edit/Advanced/Delete a word backward",      "<control>W"},
449                 {"<Compose>/Edit/Advanced/Delete a word forward",       "<alt>D"},
450         };
451
452         text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(keybind.combo));
453
454         if (!strcmp(text, _("Default"))) {
455                 menurc = default_menurc;
456                 n_menurc = G_N_ELEMENTS(default_menurc);
457         } else if (!strcmp(text, "Mew / Wanderlust")) {
458                 menurc = mew_wl_menurc;
459                 n_menurc = G_N_ELEMENTS(mew_wl_menurc);
460         } else if (!strcmp(text, "Mutt")) {
461                 menurc = mutt_menurc;
462                 n_menurc = G_N_ELEMENTS(mutt_menurc);
463         } else if (!strcmp(text, _("Old Sylpheed"))) {
464                 menurc = old_sylpheed_menurc;
465                 n_menurc = G_N_ELEMENTS(old_sylpheed_menurc);
466         } else {
467                 g_free(text);
468                 return;
469         }
470         g_free(text);
471
472         /* prefs_keybind_apply(empty_menurc, G_N_ELEMENTS(empty_menurc)); */
473         prefs_keybind_apply(menurc, n_menurc);
474
475         gtk_widget_destroy(keybind.window);
476         keybind.window = NULL;
477         keybind.combo = NULL;
478 }
479
480 static void prefs_other_create_widget(PrefsPage *_page, GtkWindow *window, 
481                                   gpointer data)
482 {
483         OtherPage *prefs_other = (OtherPage *) _page;
484         
485         GtkWidget *vbox1;
486         GtkWidget *hbox1;
487
488         GtkWidget *frame_addr;
489         GtkWidget *vbox_addr;
490         GtkWidget *checkbtn_addaddrbyclick;
491         
492         GtkWidget *frame_exit;
493         GtkWidget *vbox_exit;
494         GtkWidget *checkbtn_confonexit;
495         GtkWidget *checkbtn_cleanonexit;
496         GtkWidget *checkbtn_warnqueued;
497
498         GtkWidget *frame_keys;
499         GtkWidget *vbox_keys;
500         GtkWidget *checkbtn_gtk_can_change_accels;
501         GtkWidget *button_keybind;
502
503         GtkWidget *label_iotimeout;
504         GtkWidget *spinbtn_iotimeout;
505         GtkObject *spinbtn_iotimeout_adj;
506
507         GtkWidget *vbox2;
508         GtkWidget *checkbtn_askonclean;
509         GtkWidget *checkbtn_askonfilter;
510         GtkWidget *checkbtn_use_shred;
511         GtkWidget *checkbtn_real_time_sync;
512
513         GtkWidget *frame_sess_pass;
514         GtkWidget *vbox_sess_pass;
515         GtkWidget *checkbtn_session_passwords;
516         gchar *shred_binary = NULL;
517         CLAWS_TIP_DECL();
518
519         vbox1 = gtk_vbox_new (FALSE, VSPACING);
520         gtk_widget_show (vbox1);
521         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
522
523         vbox_addr = gtkut_get_options_frame(vbox1, &frame_addr, _("Address book"));
524
525         PACK_CHECK_BUTTON
526                 (vbox_addr, checkbtn_addaddrbyclick,
527                  _("Add address to destination when double-clicked"));
528
529         vbox_sess_pass = gtkut_get_options_frame(vbox1, &frame_sess_pass, _("Session passwords"));
530         
531         PACK_CHECK_BUTTON
532                 (vbox_sess_pass, checkbtn_session_passwords,
533                  _("Enable the option of keeping unsaved account passwords while running"));
534         /* On Exit */
535         vbox_exit = gtkut_get_options_frame(vbox1, &frame_exit, _("On exit"));
536
537         PACK_CHECK_BUTTON (vbox_exit, checkbtn_confonexit,
538                            _("Confirm on exit"));
539
540         hbox1 = gtk_hbox_new (FALSE, 32);
541         gtk_widget_show (hbox1);
542         gtk_box_pack_start (GTK_BOX (vbox_exit), hbox1, FALSE, FALSE, 0);
543
544         PACK_CHECK_BUTTON (hbox1, checkbtn_cleanonexit,
545                            _("Empty trash on exit"));
546
547         PACK_CHECK_BUTTON (vbox_exit, checkbtn_warnqueued,
548                            _("Warn if there are queued messages"));
549
550         vbox_keys = gtkut_get_options_frame(vbox1, &frame_keys, _("Keyboard shortcuts"));
551
552         PACK_CHECK_BUTTON(vbox_keys, checkbtn_gtk_can_change_accels,
553                         _("Enable customisable keyboard shortcuts"));
554
555         CLAWS_SET_TIP(checkbtn_gtk_can_change_accels,
556                         _("If checked, you can change the keyboard shortcuts of "
557                                 "most of the menu items by focusing on the menu "
558                                 "item and pressing a key combination.\n"
559                                 "Uncheck this option if you want to lock all "
560                                 "existing keyboard shortcuts."));
561
562         button_keybind = gtk_button_new_with_label(
563                                 _(" Choose preset keyboard shortcuts... "));
564         gtk_widget_show (button_keybind);
565         hbox1 = gtk_hbox_new (FALSE, 8);
566         gtk_widget_show (hbox1);
567         gtk_box_pack_start (GTK_BOX (vbox_keys), hbox1, FALSE, FALSE, 0);
568         gtk_box_pack_start (GTK_BOX (hbox1), button_keybind, FALSE, FALSE, 0);
569         g_signal_connect (G_OBJECT (button_keybind), "clicked",
570                           G_CALLBACK (prefs_keybind_select), NULL);
571
572         hbox1 = gtk_hbox_new (FALSE, 8);
573         gtk_widget_show (hbox1);
574         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
575
576         label_iotimeout = gtk_label_new (_("Socket I/O timeout"));
577         gtk_widget_show (label_iotimeout);
578         gtk_box_pack_start (GTK_BOX (hbox1), label_iotimeout, FALSE, FALSE, 0);
579
580         spinbtn_iotimeout_adj = gtk_adjustment_new (60, 0, 1000, 1, 10, 10);
581         spinbtn_iotimeout = gtk_spin_button_new
582                 (GTK_ADJUSTMENT (spinbtn_iotimeout_adj), 1, 0);
583         gtk_widget_show (spinbtn_iotimeout);
584         gtk_box_pack_start (GTK_BOX (hbox1), spinbtn_iotimeout,
585                             FALSE, FALSE, 0);
586         gtk_widget_set_size_request (spinbtn_iotimeout, 64, -1);
587         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_iotimeout), TRUE);
588
589         label_iotimeout = gtk_label_new (_("seconds"));
590         gtk_widget_show (label_iotimeout);
591         gtk_box_pack_start (GTK_BOX (hbox1), label_iotimeout, FALSE, FALSE, 0);
592
593         vbox2 = gtk_vbox_new (FALSE, 8);
594         gtk_widget_show (vbox2);
595         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
596
597         PACK_CHECK_BUTTON (vbox2, checkbtn_askonclean, 
598                            _("Ask before emptying trash"));
599         PACK_CHECK_BUTTON (vbox2, checkbtn_askonfilter,
600                            _("Ask about account specific filtering rules when "
601                              "filtering manually"));
602         shred_binary = g_find_program_in_path("shred");
603         if (shred_binary) {
604                 PACK_CHECK_BUTTON (vbox2, checkbtn_use_shred,
605                                    _("Use secure file deletion if possible"));
606                 g_free(shred_binary);
607         } else {
608                 PACK_CHECK_BUTTON (vbox2, checkbtn_use_shred,
609                                    _("Use secure file deletion if possible\n"
610                                      "(the 'shred' program is not available)"));
611                 gtk_widget_set_sensitive(checkbtn_use_shred, FALSE);
612         }
613         CLAWS_SET_TIP(checkbtn_use_shred,
614                         _("Use the 'shred' program to overwrite files with random data before "
615                           "deleting them. This slows down deletion. Be sure to "
616                           "read shred's man page for caveats."));
617         PACK_CHECK_BUTTON (vbox2, checkbtn_real_time_sync,
618                            _("Synchronise offline folders as soon as possible"));
619
620         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_addaddrbyclick), 
621                 prefs_common.add_address_by_click);
622         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_session_passwords), 
623                 prefs_common.session_passwords);
624         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_confonexit), 
625                 prefs_common.confirm_on_exit);
626         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_cleanonexit), 
627                 prefs_common.clean_on_exit);
628         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_askonclean), 
629                 prefs_common.ask_on_clean);
630         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_warnqueued), 
631                 prefs_common.warn_queued_on_exit);
632         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_gtk_can_change_accels),
633                 prefs_common.gtk_can_change_accels);
634
635         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_iotimeout),
636                 prefs_common.io_timeout_secs);
637
638         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_askonfilter), 
639                 prefs_common.ask_apply_per_account_filtering_rules);
640         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_use_shred), 
641                 prefs_common.use_shred);
642         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_real_time_sync), 
643                 prefs_common.real_time_sync);
644
645         prefs_other->checkbtn_addaddrbyclick = checkbtn_addaddrbyclick;
646         prefs_other->checkbtn_session_passwords = checkbtn_session_passwords;
647         prefs_other->checkbtn_confonexit = checkbtn_confonexit;
648         prefs_other->checkbtn_cleanonexit = checkbtn_cleanonexit;
649         prefs_other->checkbtn_askonclean = checkbtn_askonclean;
650         prefs_other->checkbtn_warnqueued = checkbtn_warnqueued;
651         prefs_other->spinbtn_iotimeout = spinbtn_iotimeout;
652         prefs_other->checkbtn_gtk_can_change_accels = checkbtn_gtk_can_change_accels;
653         prefs_other->checkbtn_askonfilter = checkbtn_askonfilter;
654         prefs_other->checkbtn_use_shred = checkbtn_use_shred;
655         prefs_other->checkbtn_real_time_sync = checkbtn_real_time_sync;
656
657         prefs_other->page.widget = vbox1;
658 }
659
660 static void prefs_other_save(PrefsPage *_page)
661 {
662         OtherPage *page = (OtherPage *) _page;
663         gboolean gtk_can_change_accels;
664         GList * list = NULL;
665
666         prefs_common.add_address_by_click = gtk_toggle_button_get_active(
667                 GTK_TOGGLE_BUTTON(page->checkbtn_addaddrbyclick));
668         prefs_common.session_passwords = gtk_toggle_button_get_active(
669                 GTK_TOGGLE_BUTTON(page->checkbtn_session_passwords));
670
671         if (!prefs_common.session_passwords) {
672                 for (list = account_get_list(); list != NULL; list = list->next) {
673                         PrefsAccount *account = list->data;
674                         if (account->session_passwd) {
675                                 g_free(account->session_passwd);
676                                 account->session_passwd = NULL;
677                         }
678                         if (account->session_smtp_passwd) {
679                                 g_free(account->session_smtp_passwd);
680                                 account->session_smtp_passwd = NULL;
681                         }
682                 }
683         }
684
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         sock_set_io_timeout(prefs_common.io_timeout_secs);
696 #ifdef HAVE_LIBETPAN
697         imap_main_set_timeout(prefs_common.io_timeout_secs);
698 #endif
699         prefs_common.ask_apply_per_account_filtering_rules = 
700                 gtk_toggle_button_get_active(
701                         GTK_TOGGLE_BUTTON(page->checkbtn_askonfilter)); 
702         prefs_common.use_shred = 
703                 gtk_toggle_button_get_active(
704                         GTK_TOGGLE_BUTTON(page->checkbtn_use_shred)); 
705         prefs_common.real_time_sync = 
706                 gtk_toggle_button_get_active(
707                         GTK_TOGGLE_BUTTON(page->checkbtn_real_time_sync)); 
708
709         gtk_can_change_accels = gtk_toggle_button_get_active(
710                 GTK_TOGGLE_BUTTON(page->checkbtn_gtk_can_change_accels));
711
712         if (prefs_common.gtk_can_change_accels != gtk_can_change_accels) {
713
714                 prefs_common.gtk_can_change_accels = gtk_can_change_accels;
715
716                 gtk_settings_set_long_property(gtk_settings_get_default(),
717                                 "gtk-can-change-accels",
718                                 (glong)prefs_common.gtk_can_change_accels,
719                                 "XProperty");
720
721                 /* gtk_can_change_accels value changed : we have (only if changed)
722                  * to apply the gtk property to all widgets : */
723                 gtk_rc_reparse_all_for_settings(gtk_settings_get_default(), TRUE);
724         }
725 }
726
727 static void prefs_other_destroy_widget(PrefsPage *_page)
728 {
729 }
730
731 OtherPage *prefs_other;
732
733 void prefs_other_init(void)
734 {
735         OtherPage *page;
736         static gchar *path[2];
737
738         path[0] = _("Other");
739         path[1] = NULL;
740
741         page = g_new0(OtherPage, 1);
742         page->page.path = path;
743         page->page.create_widget = prefs_other_create_widget;
744         page->page.destroy_widget = prefs_other_destroy_widget;
745         page->page.save_page = prefs_other_save;
746         page->page.weight = 5.0;
747         prefs_gtk_register_page((PrefsPage *) page);
748         prefs_other = page;
749
750         gtk_settings_set_long_property(gtk_settings_get_default(),
751                         "gtk-can-change-accels",
752                         (glong)prefs_common.gtk_can_change_accels,
753                         "XProperty");
754 }
755
756 void prefs_other_done(void)
757 {
758         prefs_gtk_unregister_page((PrefsPage *) prefs_other);
759         g_free(prefs_other);
760 }