2008-03-12 [paul] 3.3.1cvs21
[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_real_time_sync;
61 } OtherPage;
62
63 static struct KeybindDialog {
64         GtkWidget *window;
65         GtkWidget *combo;
66 } keybind;
67
68 static void prefs_keybind_select                (void);
69 static gint prefs_keybind_deleted               (GtkWidget      *widget,
70                                                  GdkEventAny    *event,
71                                                  gpointer        data);
72 static gboolean prefs_keybind_key_pressed       (GtkWidget      *widget,
73                                                  GdkEventKey    *event,
74                                                  gpointer        data);
75 static void prefs_keybind_cancel                (void);
76 static void prefs_keybind_apply_clicked         (GtkWidget      *widget);
77
78
79 static void prefs_keybind_select(void)
80 {
81         GtkWidget *window;
82         GtkWidget *vbox1;
83         GtkWidget *hbox1;
84         GtkWidget *label;
85         GtkWidget *combo;
86         GtkWidget *confirm_area;
87         GtkWidget *ok_btn;
88         GtkWidget *cancel_btn;
89
90         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_other");
91         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
92         gtk_window_set_title (GTK_WINDOW (window), _("Select key bindings"));
93         gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
94         gtk_window_set_modal (GTK_WINDOW (window), TRUE);
95         gtk_window_set_resizable(GTK_WINDOW (window), FALSE);
96         manage_window_set_transient (GTK_WINDOW (window));
97
98         vbox1 = gtk_vbox_new (FALSE, VSPACING);
99         gtk_container_add (GTK_CONTAINER (window), vbox1);
100         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
101
102         hbox1 = gtk_hbox_new (FALSE, 8);
103         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
104
105         label = gtk_label_new
106                 (_("Select preset:"));
107         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
108         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
109
110         combo = combobox_text_new(FALSE,
111                                _("Default"),
112                                "Mew / Wanderlust",
113                                "Mutt",
114                                _("Old Sylpheed"),
115                                NULL);
116         gtk_box_pack_start (GTK_BOX (hbox1), combo, TRUE, TRUE, 0);
117
118         hbox1 = gtk_hbox_new (FALSE, 8);
119         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
120
121         label = gtk_label_new
122                 (_("You can also modify each menu shortcut by pressing\n"
123                    "any key(s) when focusing the mouse pointer on the item."));
124         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
125         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
126         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
127         gtkut_widget_set_small_font_size (label);
128
129         hbox1 = gtk_hbox_new (FALSE, 8);
130         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
131
132         gtkut_stock_button_set_create (&confirm_area, &cancel_btn, GTK_STOCK_CANCEL,
133                                        &ok_btn, GTK_STOCK_OK,
134                                        NULL, NULL);
135         gtk_box_pack_end (GTK_BOX (hbox1), confirm_area, FALSE, FALSE, 0);
136         gtk_widget_grab_focus (ok_btn);
137
138         MANAGE_WINDOW_SIGNALS_CONNECT(window);
139         g_signal_connect (G_OBJECT (window), "delete_event",
140                           G_CALLBACK (prefs_keybind_deleted), NULL);
141         g_signal_connect (G_OBJECT (window), "key_press_event",
142                           G_CALLBACK (prefs_keybind_key_pressed), NULL);
143         g_signal_connect (G_OBJECT (ok_btn), "clicked",
144                           G_CALLBACK (prefs_keybind_apply_clicked),
145                           NULL);
146         g_signal_connect (G_OBJECT (cancel_btn), "clicked",
147                           G_CALLBACK (prefs_keybind_cancel),
148                           NULL);
149
150         gtk_widget_show_all(window);
151
152         keybind.window = window;
153         keybind.combo = combo;
154 }
155
156 static gboolean prefs_keybind_key_pressed(GtkWidget *widget, GdkEventKey *event,
157                                           gpointer data)
158 {
159         if (event && event->keyval == GDK_Escape)
160                 prefs_keybind_cancel();
161         return FALSE;
162 }
163
164 static gint prefs_keybind_deleted(GtkWidget *widget, GdkEventAny *event,
165                                   gpointer data)
166 {
167         prefs_keybind_cancel();
168         return TRUE;
169 }
170
171 static void prefs_keybind_cancel(void)
172 {
173         gtk_widget_destroy(keybind.window);
174         keybind.window = NULL;
175         keybind.combo = NULL;
176 }
177   
178 struct KeyBind {
179         const gchar *accel_path;
180         const gchar *accel_key;
181 };
182
183 static void prefs_keybind_apply(struct KeyBind keybind[], gint num)
184 {
185         gint i;
186         guint key;
187         GdkModifierType mods;
188
189         for (i = 0; i < num; i++) {
190                 const gchar *accel_key
191                         = keybind[i].accel_key ? keybind[i].accel_key : "";
192                 gtk_accelerator_parse(accel_key, &key, &mods);
193                 gtk_accel_map_change_entry(keybind[i].accel_path,
194                                            key, mods, TRUE);
195         }
196 }
197
198 static void prefs_keybind_apply_clicked(GtkWidget *widget)
199 {
200         gchar *text;
201         struct KeyBind *menurc;
202         gint n_menurc;
203
204         static struct KeyBind default_menurc[] = {
205                 {"<Main>/File/Empty all Trash folders",         "<shift>D"},
206                 {"<Main>/File/Save as...",                      "<control>S"},
207                 {"<Main>/File/Print...",                        "<control>P"},
208                 {"<Main>/File/Work offline",                    "<control>W"},
209                 {"<Main>/File/Synchronise folders",             "<control><shift>S"},
210                 {"<Main>/File/Exit",                            "<control>Q"},
211
212                 {"<Main>/Edit/Copy",                            "<control>C"},
213                 {"<Main>/Edit/Select all",                      "<control>A"},
214                 {"<Main>/Edit/Find in current message...",      "<control>F"},
215                 {"<Main>/Edit/Search folder...",                "<shift><control>F"},
216                 {"<Main>/Edit/Quick search",                    "slash"},
217
218                 {"<Main>/View/Show or hide/Message View",       "V"},
219                 {"<Main>/View/Thread view",                     "<control>T"},
220                 {"<Main>/View/Go to/Previous message",          "P"},
221                 {"<Main>/View/Go to/Next message",              "N"},
222                 {"<Main>/View/Go to/Previous unread message",   "<shift>P"},
223                 {"<Main>/View/Go to/Next unread message",       "<shift>N"},
224                 {"<Main>/View/Go to/Other folder...",           "G"},
225                 {"<Main>/View/Open in new window",              "<control><alt>N"},
226                 {"<Main>/View/Message source",                  "<control>U"},
227                 {"<Main>/View/All headers",                     "<control>H"},
228                 {"<Main>/View/Update summary",                  "<control><alt>U"},
229
230                 {"<Main>/Message/Receive/Get from current account",
231                                                                 "<control>I"},
232                 {"<Main>/Message/Receive/Get from all accounts","<shift><control>I"},
233                 {"<Main>/Message/Compose an email message",     "<control>M"},
234                 {"<Main>/Message/Reply",                        "<control>R"},
235                 {"<Main>/Message/Reply to/all",                 "<shift><control>R"},
236                 {"<Main>/Message/Reply to/sender",              ""},
237                 {"<Main>/Message/Reply to/mailing list",        "<control>L"},
238                 {"<Main>/Message/Forward",                      "<control><alt>F"},
239                 /* {"<Main>/Message/Forward as attachment",      ""}, */
240                 {"<Main>/Message/Move...",                      "<control>O"},
241                 {"<Main>/Message/Copy...",                      "<shift><control>O"},
242                 {"<Main>/Message/Move to trash",                "<control>D"},
243                 {"<Main>/Message/Mark/Mark",                    "<shift>asterisk"},
244                 {"<Main>/Message/Mark/Unmark",                  "U"},
245                 {"<Main>/Message/Mark/Mark as unread",          "<shift>exclam"},
246                 {"<Main>/Message/Mark/Mark as read",            ""},
247
248                 {"<Main>/Tools/Address book",                   "<shift><control>A"},
249                 {"<Main>/Tools/Execute",                        "X"},
250                 {"<Main>/Tools/Log window",                     "<shift><control>L"},
251
252                 {"<Compose>/Message/Send",                              "<control>Return"},
253                 {"<Compose>/Message/Send later",                        "<shift><control>S"},
254                 {"<Compose>/Message/Attach file",                       "<control>M"},
255                 {"<Compose>/Message/Insert file",                       "<control>I"},
256                 {"<Compose>/Message/Insert signature",                  "<control>G"},
257                 {"<Compose>/Message/Save",                              "<control>S"},
258                 {"<Compose>/Message/Close",                             "<control>W"},
259                 {"<Compose>/Edit/Undo",                                 "<control>Z"},
260                 {"<Compose>/Edit/Redo",                                 "<control>Y"},
261                 {"<Compose>/Edit/Cut",                                  "<control>X"},
262                 {"<Compose>/Edit/Copy",                                 "<control>C"},
263                 {"<Compose>/Edit/Paste",                                "<control>V"},
264                 {"<Compose>/Edit/Select all",                           "<control>A"},
265                 {"<Compose>/Edit/Advanced/Move a character backward",   "<control>B"},
266                 {"<Compose>/Edit/Advanced/Move a character forward",    "<control>F"},
267                 {"<Compose>/Edit/Advanced/Move a word backward,"        ""},
268                 {"<Compose>/Edit/Advanced/Move a word forward",         ""},
269                 {"<Compose>/Edit/Advanced/Move to beginning of line",   ""},
270                 {"<Compose>/Edit/Advanced/Move to end of line",         "<control>E"},
271                 {"<Compose>/Edit/Advanced/Move to previous line",       "<control>P"},
272                 {"<Compose>/Edit/Advanced/Move to next line",           "<control>N"},
273                 {"<Compose>/Edit/Advanced/Delete a character backward", "<control>H"},
274                 {"<Compose>/Edit/Advanced/Delete a character forward",  "<control>D"},
275                 {"<Compose>/Edit/Advanced/Delete a word backward",      ""},
276                 {"<Compose>/Edit/Advanced/Delete a word forward",       ""},
277                 {"<Compose>/Edit/Advanced/Delete line",                 "<control>U"},
278                 {"<Compose>/Edit/Advanced/Delete entire line",          ""},
279                 {"<Compose>/Edit/Advanced/Delete to end of line",       "<control>K"},
280                 {"<Compose>/Edit/Wrap current paragraph",               "<control>L"},
281                 {"<Compose>/Edit/Wrap all long lines",                  "<control><alt>L"},
282                 {"<Compose>/Edit/Auto wrapping",                        "<shift><control>L"},
283                 {"<Compose>/Edit/Edit with external editor",            "<shift><control>X"},
284                 {"<Compose>/Tools/Address book",                        "<shift><control>A"},
285         };
286
287         static struct KeyBind mew_wl_menurc[] = {
288                 {"<Main>/File/Empty all Trash folders",         "<shift>D"},
289                 {"<Main>/File/Save as...",                      "Y"},
290                 {"<Main>/File/Print...",                        "<shift>numbersign"},
291                 {"<Main>/File/Exit",                            "<shift>Q"},
292
293                 {"<Main>/Edit/Copy",                            "<control>C"},
294                 {"<Main>/Edit/Select all",                      "<control>A"},
295                 {"<Main>/Edit/Find in current message...",      "<control>F"},
296                 {"<Main>/Edit/Search folder...",                "<control>S"},
297
298                 {"<Main>/View/Show or hide/Message View",       ""},
299                 {"<Main>/View/Thread view",                     "<shift>T"},
300                 {"<Main>/View/Go to/Previous message",          "P"},
301                 {"<Main>/View/Go to/Next message",              "N"},
302                 {"<Main>/View/Go to/Previous unread message",   "<shift>P"},
303                 {"<Main>/View/Go to/Next unread message",       "<shift>N"},
304                 {"<Main>/View/Go to/Other folder...",           "G"},
305                 {"<Main>/View/Open in new window",              "<control><alt>N"},
306                 {"<Main>/View/Message source",                  "<control>U"},
307                 {"<Main>/View/All headers",                     "<shift>H"},
308                 {"<Main>/View/Update summary",                  "<shift>S"},
309
310                 {"<Main>/Message/Receive/Get from current account",
311                                                                 "<control>I"},
312                 {"<Main>/Message/Receive/Get from all accounts","<shift><control>I"},
313                 {"<Main>/Message/Compose an email message",     "W"},
314                 {"<Main>/Message/Reply",                        "<control>R"},
315                 {"<Main>/Message/Reply to/all",                 "<shift>A"},
316                 {"<Main>/Message/Reply to/sender",              ""},
317                 {"<Main>/Message/Reply to/mailing list",        "<control>L"},
318                 {"<Main>/Message/Forward",                      "F"},
319                 /* {"<Main>/Message/Forward as attachment", "<shift>F"}, */
320                 {"<Main>/Message/Move...",                      "O"},
321                 {"<Main>/Message/Copy...",                      "<shift>O"},
322                 {"<Main>/Message/Delete",                       "D"},
323                 {"<Main>/Message/Mark/Mark",                    "<shift>asterisk"},
324                 {"<Main>/Message/Mark/Unmark",                  "U"},
325                 {"<Main>/Message/Mark/Mark as unread",          "<shift>exclam"},
326                 {"<Main>/Message/Mark/Mark as read",            "<shift>R"},
327
328                 {"<Main>/Tools/Address book",                   "<shift><control>A"},
329                 {"<Main>/Tools/Execute",                        "X"},
330                 {"<Main>/Tools/Log window",                     "<shift><control>L"},
331
332                 {"<Compose>/Message/Close",                             "<alt>W"},
333                 {"<Compose>/Edit/Select all",                           ""},
334                 {"<Compose>/Edit/Advanced/Move a word backward,"        "<alt>B"},
335                 {"<Compose>/Edit/Advanced/Move a word forward",         "<alt>F"},
336                 {"<Compose>/Edit/Advanced/Move to beginning of line",   "<control>A"},
337                 {"<Compose>/Edit/Advanced/Delete a word backward",      "<control>W"},
338                 {"<Compose>/Edit/Advanced/Delete a word forward",       "<alt>D"},
339         };
340
341         static struct KeyBind mutt_menurc[] = {
342                 {"<Main>/File/Empty all Trash folders",         ""},
343                 {"<Main>/File/Save as...",                      "S"},
344                 {"<Main>/File/Print...",                        "P"},
345                 {"<Main>/File/Exit",                            "Q"},
346
347                 {"<Main>/Edit/Copy",                            "<control>C"},
348                 {"<Main>/Edit/Select all",                      "<control>A"},
349                 {"<Main>/Edit/Find in current message...",      "<control>F"},
350                 {"<Main>/Edit/Search messages...",              "slash"},
351
352                 {"<Main>/View/Show or hide/Message view",       "V"},
353                 {"<Main>/View/Thread view",                     "<control>T"},
354                 {"<Main>/View/Go to/Previous message",          ""},
355                 {"<Main>/View/Go to/Next message",              ""},
356                 {"<Main>/View/Go to/Previous unread message",   ""},
357                 {"<Main>/View/Go to/Next unread message",       ""},
358                 {"<Main>/View/Go to/Other folder...",           "C"},
359                 {"<Main>/View/Open in new window",              "<control><alt>N"},
360                 {"<Main>/View/Message source",                  "<control>U"},
361                 {"<Main>/View/All headers",                     "<control>H"},
362                 {"<Main>/View/Update summary",                  "<control><alt>U"},
363
364                 {"<Main>/Message/Receive/Get from current account",
365                                                                 "<control>I"},
366                 {"<Main>/Message/Receive/Get from all accounts","<shift><control>I"},
367                 {"<Main>/Message/Compose an email message",             "M"},
368                 {"<Main>/Message/Reply",                        "R"},
369                 {"<Main>/Message/Reply to/all",                 "G"},
370                 {"<Main>/Message/Reply to/sender",              ""},
371                 {"<Main>/Message/Reply to/mailing list",        "<control>L"},
372                 {"<Main>/Message/Forward",                      "F"},
373                 {"<Main>/Message/Forward as attachment",        ""},
374                 {"<Main>/Message/Move...",                      "<control>O"},
375                 {"<Main>/Message/Copy...",                      "<shift>C"},
376                 {"<Main>/Message/Delete",                       "D"},
377                 {"<Main>/Message/Mark/Mark",                    "<shift>F"},
378                 {"<Main>/Message/Mark/Unmark",                  "U"},
379                 {"<Main>/Message/Mark/Mark as unread",          "<shift>N"},
380                 {"<Main>/Message/Mark/Mark as read",            ""},
381
382                 {"<Main>/Tools/Address book",                   "<shift><control>A"},
383                 {"<Main>/Tools/Execute",                        "X"},
384                 {"<Main>/Tools/Log window",                     "<shift><control>L"},
385
386                 {"<Compose>/Message/Close",                             "<alt>W"},
387                 {"<Compose>/Edit/Select all",                           ""},
388                 {"<Compose>/Edit/Advanced/Move a word backward",        "<alt>B"},
389                 {"<Compose>/Edit/Advanced/Move a word forward",         "<alt>F"},
390                 {"<Compose>/Edit/Advanced/Move to beginning of line",   "<control>A"},
391                 {"<Compose>/Edit/Advanced/Delete a word backward",      "<control>W"},
392                 {"<Compose>/Edit/Advanced/Delete a word forward",       "<alt>D"},
393         };
394
395         static struct KeyBind old_sylpheed_menurc[] = {
396                 {"<Main>/File/Empty all Trash folders",         ""},
397                 {"<Main>/File/Save as...",                      ""},
398                 {"<Main>/File/Print...",                        "<alt>P"},
399                 {"<Main>/File/Exit",                            "<alt>Q"},
400
401                 {"<Main>/Edit/Copy",                            "<control>C"},
402                 {"<Main>/Edit/Select all",                      "<control>A"},
403                 {"<Main>/Edit/Find in current message...",      "<control>F"},
404                 {"<Main>/Edit/Search folder...",                "<control>S"},
405
406                 {"<Main>/View/Show or hide/Message View",       ""},
407                 {"<Main>/View/Thread view",                     "<control>T"},
408                 {"<Main>/View/Go to/Previous message",          "P"},
409                 {"<Main>/View/Go to/Next message",              "N"},
410                 {"<Main>/View/Go to/Previous unread message",   "<shift>P"},
411                 {"<Main>/View/Go to/Next unread message",       "<shift>N"},
412                 {"<Main>/View/Go to/Other folder...",           "<alt>G"},
413                 {"<Main>/View/Open in new window",              "<shift><control>N"},
414                 {"<Main>/View/Message source",                  "<control>U"},
415                 {"<Main>/View/All headers",                     "<control>H"},
416                 {"<Main>/View/Update summary",                  "<alt>U"},
417
418                 {"<Main>/Message/Receive/Get from current account",
419                                                                 "<alt>I"},
420                 {"<Main>/Message/Receive/Get from all accounts","<shift><alt>I"},
421                 {"<Main>/Message/Compose an email message",     "<alt>N"},
422                 {"<Main>/Message/Reply",                        "<alt>R"},
423                 {"<Main>/Message/Reply to/all",                 "<shift><alt>R"},
424                 {"<Main>/Message/Reply to/sender",              "<control><alt>R"},
425                 {"<Main>/Message/Reply to/mailing list",        "<control>L"},
426                 {"<Main>/Message/Forward",                       "<shift><alt>F"},
427                 /* "(menu-path \"<Main>/Message/Forward as attachment", "<shift><control>F"}, */
428                 {"<Main>/Message/Move...",                      "<alt>O"},
429                 {"<Main>/Message/Copy...",                      ""},
430                 {"<Main>/Message/Delete",                       "<alt>D"},
431                 {"<Main>/Message/Mark/Mark",                    "<shift>asterisk"},
432                 {"<Main>/Message/Mark/Unmark",                  "U"},
433                 {"<Main>/Message/Mark/Mark as unread",          "<shift>exclam"},
434                 {"<Main>/Message/Mark/Mark as read",            ""},
435
436                 {"<Main>/Tools/Address book",                   "<alt>A"},
437                 {"<Main>/Tools/Execute",                        "<alt>X"},
438                 {"<Main>/Tools/Log window",                     "<alt>L"},
439
440                 {"<Compose>/Message/Close",                             "<alt>W"},
441                 {"<Compose>/Edit/Select all",                           ""},
442                 {"<Compose>/Edit/Advanced/Move a word backward",        "<alt>B"},
443                 {"<Compose>/Edit/Advanced/Move a word forward",         "<alt>F"},
444                 {"<Compose>/Edit/Advanced/Move to beginning of line",   "<control>A"},
445                 {"<Compose>/Edit/Advanced/Delete a word backward",      "<control>W"},
446                 {"<Compose>/Edit/Advanced/Delete a word forward",       "<alt>D"},
447         };
448
449         text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(keybind.combo));
450
451         if (!strcmp(text, _("Default"))) {
452                 menurc = default_menurc;
453                 n_menurc = G_N_ELEMENTS(default_menurc);
454         } else if (!strcmp(text, "Mew / Wanderlust")) {
455                 menurc = mew_wl_menurc;
456                 n_menurc = G_N_ELEMENTS(mew_wl_menurc);
457         } else if (!strcmp(text, "Mutt")) {
458                 menurc = mutt_menurc;
459                 n_menurc = G_N_ELEMENTS(mutt_menurc);
460         } else if (!strcmp(text, _("Old Sylpheed"))) {
461                 menurc = old_sylpheed_menurc;
462                 n_menurc = G_N_ELEMENTS(old_sylpheed_menurc);
463         } else {
464                 g_free(text);
465                 return;
466         }
467         g_free(text);
468
469         /* prefs_keybind_apply(empty_menurc, G_N_ELEMENTS(empty_menurc)); */
470         prefs_keybind_apply(menurc, n_menurc);
471
472         gtk_widget_destroy(keybind.window);
473         keybind.window = NULL;
474         keybind.combo = NULL;
475 }
476
477 static void prefs_other_create_widget(PrefsPage *_page, GtkWindow *window, 
478                                   gpointer data)
479 {
480         OtherPage *prefs_other = (OtherPage *) _page;
481         
482         GtkWidget *vbox1;
483         GtkWidget *hbox1;
484
485         GtkWidget *frame_addr;
486         GtkWidget *vbox_addr;
487         GtkWidget *checkbtn_addaddrbyclick;
488         
489         GtkWidget *frame_exit;
490         GtkWidget *vbox_exit;
491         GtkWidget *checkbtn_confonexit;
492         GtkWidget *checkbtn_cleanonexit;
493         GtkWidget *checkbtn_warnqueued;
494
495         GtkWidget *frame_keys;
496         GtkWidget *vbox_keys;
497         GtkWidget *checkbtn_gtk_can_change_accels;
498         GtkTooltips *gtk_can_change_accels_tooltip;
499         GtkWidget *button_keybind;
500
501         GtkWidget *label_iotimeout;
502         GtkWidget *spinbtn_iotimeout;
503         GtkObject *spinbtn_iotimeout_adj;
504
505         GtkWidget *vbox2;
506         GtkWidget *checkbtn_askonclean;
507         GtkWidget *checkbtn_askonfilter;
508         GtkWidget *checkbtn_real_time_sync;
509         vbox1 = gtk_vbox_new (FALSE, VSPACING);
510         gtk_widget_show (vbox1);
511         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
512
513         vbox_addr = gtkut_get_options_frame(vbox1, &frame_addr, _("Address book"));
514
515         PACK_CHECK_BUTTON
516                 (vbox_addr, checkbtn_addaddrbyclick,
517                  _("Add address to destination when double-clicked"));
518
519         /* On Exit */
520         vbox_exit = gtkut_get_options_frame(vbox1, &frame_exit, _("On exit"));
521
522         PACK_CHECK_BUTTON (vbox_exit, checkbtn_confonexit,
523                            _("Confirm on exit"));
524
525         hbox1 = gtk_hbox_new (FALSE, 32);
526         gtk_widget_show (hbox1);
527         gtk_box_pack_start (GTK_BOX (vbox_exit), hbox1, FALSE, FALSE, 0);
528
529         PACK_CHECK_BUTTON (hbox1, checkbtn_cleanonexit,
530                            _("Empty trash on exit"));
531
532         PACK_CHECK_BUTTON (vbox_exit, checkbtn_warnqueued,
533                            _("Warn if there are queued messages"));
534
535         vbox_keys = gtkut_get_options_frame(vbox1, &frame_keys, _("Keyboard shortcuts"));
536
537         PACK_CHECK_BUTTON(vbox_keys, checkbtn_gtk_can_change_accels,
538                         _("Enable customisable menu shortcuts"));
539         gtk_can_change_accels_tooltip = gtk_tooltips_new();
540         gtk_tooltips_set_tip(GTK_TOOLTIPS(gtk_can_change_accels_tooltip),
541                         checkbtn_gtk_can_change_accels,
542                         _("If checked, you can change the keyboard shortcuts of "
543                                 "most of the menu items by focusing on the menu "
544                                 "item and pressing a key combination.\n"
545                                 "Uncheck this option if you want to lock all "
546                                 "existing menu shortcuts."),
547                         NULL);
548
549         button_keybind = gtk_button_new_with_label (_(" Set key bindings... "));
550         gtk_widget_show (button_keybind);
551         hbox1 = gtk_hbox_new (FALSE, 8);
552         gtk_widget_show (hbox1);
553         gtk_box_pack_start (GTK_BOX (vbox_keys), hbox1, FALSE, FALSE, 0);
554         gtk_box_pack_start (GTK_BOX (hbox1), button_keybind, FALSE, FALSE, 0);
555         g_signal_connect (G_OBJECT (button_keybind), "clicked",
556                           G_CALLBACK (prefs_keybind_select), NULL);
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_new (60, 0, 1000, 1, 10, 10);
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_widget_set_size_request (spinbtn_iotimeout, 64, -1);
573         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_iotimeout), TRUE);
574
575         label_iotimeout = gtk_label_new (_("seconds"));
576         gtk_widget_show (label_iotimeout);
577         gtk_box_pack_start (GTK_BOX (hbox1), label_iotimeout, FALSE, FALSE, 0);
578
579         vbox2 = gtk_vbox_new (FALSE, 8);
580         gtk_widget_show (vbox2);
581         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
582
583         PACK_CHECK_BUTTON (vbox2, checkbtn_askonclean, 
584                            _("Ask before emptying trash"));
585         PACK_CHECK_BUTTON (vbox2, checkbtn_askonfilter,
586                            _("Ask about account specific filtering rules when "
587                              "filtering manually"));
588         PACK_CHECK_BUTTON (vbox2, checkbtn_real_time_sync,
589                            _("Synchronise offline folders as soon as possible"));
590
591         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_addaddrbyclick), 
592                 prefs_common.add_address_by_click);
593         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_confonexit), 
594                 prefs_common.confirm_on_exit);
595         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_cleanonexit), 
596                 prefs_common.clean_on_exit);
597         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_askonclean), 
598                 prefs_common.ask_on_clean);
599         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_warnqueued), 
600                 prefs_common.warn_queued_on_exit);
601         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_gtk_can_change_accels),
602                 prefs_common.gtk_can_change_accels);
603
604         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_iotimeout),
605                 prefs_common.io_timeout_secs);
606
607         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_askonfilter), 
608                 prefs_common.ask_apply_per_account_filtering_rules);
609         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_real_time_sync), 
610                 prefs_common.real_time_sync);
611
612         prefs_other->checkbtn_addaddrbyclick = checkbtn_addaddrbyclick;
613         prefs_other->checkbtn_confonexit = checkbtn_confonexit;
614         prefs_other->checkbtn_cleanonexit = checkbtn_cleanonexit;
615         prefs_other->checkbtn_askonclean = checkbtn_askonclean;
616         prefs_other->checkbtn_warnqueued = checkbtn_warnqueued;
617         prefs_other->spinbtn_iotimeout = spinbtn_iotimeout;
618         prefs_other->checkbtn_gtk_can_change_accels = checkbtn_gtk_can_change_accels;
619         prefs_other->checkbtn_askonfilter = checkbtn_askonfilter;
620         prefs_other->checkbtn_real_time_sync = checkbtn_real_time_sync;
621
622         prefs_other->page.widget = vbox1;
623 }
624
625 static void prefs_other_save(PrefsPage *_page)
626 {
627         OtherPage *page = (OtherPage *) _page;
628         gboolean gtk_can_change_accels;
629
630         prefs_common.add_address_by_click = gtk_toggle_button_get_active(
631                 GTK_TOGGLE_BUTTON(page->checkbtn_addaddrbyclick));
632         prefs_common.confirm_on_exit = gtk_toggle_button_get_active(
633                 GTK_TOGGLE_BUTTON(page->checkbtn_confonexit));
634         prefs_common.clean_on_exit = gtk_toggle_button_get_active(
635                 GTK_TOGGLE_BUTTON(page->checkbtn_cleanonexit)); 
636         prefs_common.ask_on_clean = gtk_toggle_button_get_active(
637                 GTK_TOGGLE_BUTTON(page->checkbtn_askonclean));
638         prefs_common.warn_queued_on_exit = gtk_toggle_button_get_active(
639                 GTK_TOGGLE_BUTTON(page->checkbtn_warnqueued)); 
640         prefs_common.io_timeout_secs = gtk_spin_button_get_value_as_int(
641                 GTK_SPIN_BUTTON(page->spinbtn_iotimeout));
642         sock_set_io_timeout(prefs_common.io_timeout_secs);
643 #ifdef HAVE_LIBETPAN
644         imap_main_set_timeout(prefs_common.io_timeout_secs);
645 #endif
646         prefs_common.ask_apply_per_account_filtering_rules = 
647                 gtk_toggle_button_get_active(
648                         GTK_TOGGLE_BUTTON(page->checkbtn_askonfilter)); 
649         prefs_common.real_time_sync = 
650                 gtk_toggle_button_get_active(
651                         GTK_TOGGLE_BUTTON(page->checkbtn_real_time_sync)); 
652
653         gtk_can_change_accels = gtk_toggle_button_get_active(
654                 GTK_TOGGLE_BUTTON(page->checkbtn_gtk_can_change_accels));
655
656         if (prefs_common.gtk_can_change_accels != gtk_can_change_accels) {
657
658                 prefs_common.gtk_can_change_accels = gtk_can_change_accels;
659
660                 gtk_settings_set_long_property(gtk_settings_get_default(),
661                                 "gtk-can-change-accels",
662                                 (glong)prefs_common.gtk_can_change_accels,
663                                 "XProperty");
664
665                 /* gtk_can_change_accels value changed : we have (only if changed)
666                  * to apply the gtk property to all widgets : */
667                 gtk_rc_reparse_all_for_settings(gtk_settings_get_default(), TRUE);
668         }
669 }
670
671 static void prefs_other_destroy_widget(PrefsPage *_page)
672 {
673 }
674
675 OtherPage *prefs_other;
676
677 void prefs_other_init(void)
678 {
679         OtherPage *page;
680         static gchar *path[2];
681
682         path[0] = _("Other");
683         path[1] = NULL;
684
685         page = g_new0(OtherPage, 1);
686         page->page.path = path;
687         page->page.create_widget = prefs_other_create_widget;
688         page->page.destroy_widget = prefs_other_destroy_widget;
689         page->page.save_page = prefs_other_save;
690         page->page.weight = 5.0;
691         prefs_gtk_register_page((PrefsPage *) page);
692         prefs_other = page;
693
694         gtk_settings_set_long_property(gtk_settings_get_default(),
695                         "gtk-can-change-accels",
696                         (glong)prefs_common.gtk_can_change_accels,
697                         "XProperty");
698 }
699
700 void prefs_other_done(void)
701 {
702         prefs_gtk_unregister_page((PrefsPage *) prefs_other);
703         g_free(prefs_other);
704 }