2007-01-13 [colin] 2.7.0cvs21
[claws.git] / src / prefs_summaries.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 2 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, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 #include "prefs_summary_column.h"
37 #include "prefs_folder_column.h"
38
39 #include "gtk/menu.h"
40 #include "gtk/gtkutils.h"
41 #include "gtk/prefswindow.h"
42
43 #include "manage_window.h"
44
45 typedef struct _SummariesPage
46 {
47         PrefsPage page;
48
49         GtkWidget *window;
50
51         GtkWidget *chkbtn_transhdr;
52         GtkWidget *chkbtn_folder_unread;
53         GtkWidget *spinbtn_ng_abbrev_len;
54         GtkWidget *chkbtn_useaddrbook;
55         GtkWidget *chkbtn_threadsubj;
56         GtkWidget *button_datefmt;
57         GtkWidget *entry_datefmt;
58
59         GtkWidget *checkbtn_always_show_msg;
60         GtkWidget *checkbtn_mark_as_read_on_newwin;
61         GtkWidget *spinbtn_mark_as_read_delay;
62         GtkWidget *checkbtn_immedexec;
63         GtkWidget *checkbtn_ask_mark_all_read;
64         GtkWidget *optmenu_select_on_entry;
65         GtkWidget *optmenu_nextunreadmsgdialog;
66
67 } SummariesPage;
68
69 enum {
70         DATEFMT_FMT,
71         DATEFMT_TXT,
72         N_DATEFMT_COLUMNS
73 };
74
75 static void date_format_ok_btn_clicked          (GtkButton      *button,
76                                                  GtkWidget     **widget);
77 static void date_format_cancel_btn_clicked      (GtkButton      *button,
78                                                  GtkWidget     **widget);
79 static gboolean date_format_key_pressed         (GtkWidget      *keywidget,
80                                                  GdkEventKey    *event,
81                                                  GtkWidget     **widget);
82 static gboolean date_format_on_delete           (GtkWidget      *dialogwidget,
83                                                  GdkEventAny    *event,
84                                                  GtkWidget     **widget);
85 static void date_format_entry_on_change         (GtkEditable    *editable,
86                                                  GtkLabel       *example);
87 static void date_format_select_row              (GtkTreeView *list_view,
88                                                  GtkTreePath *path,
89                                                  GtkTreeViewColumn *column,
90                                                  GtkWidget *date_format);
91
92 static GtkWidget *date_format_create(GtkButton *button, void *data)
93 {
94         static GtkWidget *datefmt_win = NULL;
95
96         GtkWidget *vbox1;
97         GtkWidget *scrolledwindow1;
98         GtkWidget *datefmt_list_view;
99         GtkWidget *table;
100         GtkWidget *label1;
101         GtkWidget *label2;
102         GtkWidget *label3;
103         GtkWidget *confirm_area;
104         GtkWidget *ok_btn;
105         GtkWidget *cancel_btn;
106         GtkWidget *datefmt_entry;
107         GtkListStore *store;
108
109         struct {
110                 gchar *fmt;
111                 gchar *txt;
112         } time_format[] = {
113                 { "%a", NULL },
114                 { "%A", NULL },
115                 { "%b", NULL },
116                 { "%B", NULL },
117                 { "%c", NULL },
118                 { "%C", NULL },
119                 { "%d", NULL },
120                 { "%H", NULL },
121                 { "%I", NULL },
122                 { "%j", NULL },
123                 { "%m", NULL },
124                 { "%M", NULL },
125                 { "%p", NULL },
126                 { "%S", NULL },
127                 { "%w", NULL },
128                 { "%x", NULL },
129                 { "%y", NULL },
130                 { "%Y", NULL },
131                 { "%Z", NULL }
132         };
133
134         gint i;
135         const gint TIME_FORMAT_ELEMS =
136                 sizeof time_format / sizeof time_format[0];
137
138         GtkCellRenderer *renderer;
139         GtkTreeViewColumn *column;
140         GtkTreeSelection *selection;
141
142         time_format[0].txt  = _("the full abbreviated weekday name");
143         time_format[1].txt  = _("the full weekday name");
144         time_format[2].txt  = _("the abbreviated month name");
145         time_format[3].txt  = _("the full month name");
146         time_format[4].txt  = _("the preferred date and time for the current locale");
147         time_format[5].txt  = _("the century number (year/100)");
148         time_format[6].txt  = _("the day of the month as a decimal number");
149         time_format[7].txt  = _("the hour as a decimal number using a 24-hour clock");
150         time_format[8].txt  = _("the hour as a decimal number using a 12-hour clock");
151         time_format[9].txt  = _("the day of the year as a decimal number");
152         time_format[10].txt = _("the month as a decimal number");
153         time_format[11].txt = _("the minute as a decimal number");
154         time_format[12].txt = _("either AM or PM");
155         time_format[13].txt = _("the second as a decimal number");
156         time_format[14].txt = _("the day of the week as a decimal number");
157         time_format[15].txt = _("the preferred date for the current locale");
158         time_format[16].txt = _("the last two digits of a year");
159         time_format[17].txt = _("the year as a decimal number");
160         time_format[18].txt = _("the time zone or name or abbreviation");
161
162         if (datefmt_win) return datefmt_win;
163
164         store = gtk_list_store_new(N_DATEFMT_COLUMNS,
165                                    G_TYPE_STRING,
166                                    G_TYPE_STRING,
167                                    -1);
168
169         for (i = 0; i < TIME_FORMAT_ELEMS; i++) {
170                 GtkTreeIter iter;
171
172                 gtk_list_store_append(store, &iter);
173                 gtk_list_store_set(store, &iter,
174                                    DATEFMT_FMT, time_format[i].fmt,
175                                    DATEFMT_TXT, time_format[i].txt,
176                                    -1);
177         }
178
179         datefmt_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
180         gtk_container_set_border_width(GTK_CONTAINER(datefmt_win), 8);
181         gtk_window_set_title(GTK_WINDOW(datefmt_win), _("Date format"));
182         gtk_window_set_position(GTK_WINDOW(datefmt_win), GTK_WIN_POS_CENTER);
183         gtk_widget_set_size_request(datefmt_win, 440, 280);
184
185         vbox1 = gtk_vbox_new(FALSE, 10);
186         gtk_widget_show(vbox1);
187         gtk_container_add(GTK_CONTAINER(datefmt_win), vbox1);
188
189         scrolledwindow1 = gtk_scrolled_window_new(NULL, NULL);
190         gtk_scrolled_window_set_policy
191                 (GTK_SCROLLED_WINDOW(scrolledwindow1),
192                  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
193         gtk_widget_show(scrolledwindow1);
194         gtk_box_pack_start(GTK_BOX(vbox1), scrolledwindow1, TRUE, TRUE, 0);
195
196         datefmt_list_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
197         g_object_unref(G_OBJECT(store));
198         gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(datefmt_list_view),
199                                      prefs_common.use_stripes_everywhere);
200         gtk_widget_show(datefmt_list_view);
201         gtk_container_add(GTK_CONTAINER(scrolledwindow1), datefmt_list_view);
202
203         renderer = gtk_cell_renderer_text_new();
204         column = gtk_tree_view_column_new_with_attributes
205                         (_("Specifier"), renderer, "text", DATEFMT_FMT,
206                          NULL);
207         gtk_tree_view_append_column(GTK_TREE_VIEW(datefmt_list_view), column);
208         
209         renderer = gtk_cell_renderer_text_new();
210         column = gtk_tree_view_column_new_with_attributes
211                         (_("Description"), renderer, "text", DATEFMT_TXT,
212                          NULL);
213         gtk_tree_view_append_column(GTK_TREE_VIEW(datefmt_list_view), column);
214         
215         /* gtk_clist_set_column_width(GTK_CLIST(datefmt_clist), 0, 80); */
216         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(datefmt_list_view));
217         gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
218
219         g_signal_connect(G_OBJECT(datefmt_list_view), "row_activated", 
220                          G_CALLBACK(date_format_select_row),
221                          datefmt_win);
222         
223         table = gtk_table_new(2, 2, FALSE);
224         gtk_widget_show(table);
225         gtk_box_pack_start(GTK_BOX(vbox1), table, FALSE, FALSE, 0);
226         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
227         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
228
229         label1 = gtk_label_new(_("Date format"));
230         gtk_widget_show(label1);
231         gtk_table_attach(GTK_TABLE(table), label1, 0, 1, 0, 1,
232                          GTK_FILL, 0, 0, 0);
233         gtk_label_set_justify(GTK_LABEL(label1), GTK_JUSTIFY_LEFT);
234         gtk_misc_set_alignment(GTK_MISC(label1), 0, 0.5);
235
236         datefmt_entry = gtk_entry_new();
237         gtk_entry_set_max_length(GTK_ENTRY(datefmt_entry), 256);
238         gtk_widget_show(datefmt_entry);
239         gtk_table_attach(GTK_TABLE(table), datefmt_entry, 1, 2, 0, 1,
240                          (GTK_EXPAND | GTK_FILL), 0, 0, 0);
241
242         /* we need the "sample" entry box; add it as data so callbacks can
243          * get the entry box */
244         g_object_set_data(G_OBJECT(datefmt_win), "datefmt_sample",
245                           datefmt_entry);
246
247         label2 = gtk_label_new(_("Example"));
248         gtk_widget_show(label2);
249         gtk_table_attach(GTK_TABLE(table), label2, 0, 1, 1, 2,
250                          GTK_FILL, 0, 0, 0);
251         gtk_label_set_justify(GTK_LABEL(label2), GTK_JUSTIFY_LEFT);
252         gtk_misc_set_alignment(GTK_MISC(label2), 0, 0.5);
253
254         label3 = gtk_label_new("");
255         gtk_widget_show(label3);
256         gtk_table_attach(GTK_TABLE(table), label3, 1, 2, 1, 2,
257                          (GTK_EXPAND | GTK_FILL), 0, 0, 0);
258         gtk_label_set_justify(GTK_LABEL(label3), GTK_JUSTIFY_LEFT);
259         gtk_misc_set_alignment(GTK_MISC(label3), 0, 0.5);
260
261         gtkut_stock_button_set_create(&confirm_area, &cancel_btn, GTK_STOCK_CANCEL,
262                                       &ok_btn, GTK_STOCK_OK, NULL, NULL);
263
264         gtk_box_pack_start(GTK_BOX(vbox1), confirm_area, FALSE, FALSE, 0);
265         gtk_widget_show(confirm_area);
266         gtk_widget_grab_default(ok_btn);
267
268         /* set the current format */
269         gtk_entry_set_text(GTK_ENTRY(datefmt_entry), prefs_common.date_format);
270         date_format_entry_on_change(GTK_EDITABLE(datefmt_entry),
271                                     GTK_LABEL(label3));
272
273         g_signal_connect(G_OBJECT(ok_btn), "clicked",
274                          G_CALLBACK(date_format_ok_btn_clicked),
275                          &datefmt_win);
276         g_signal_connect(G_OBJECT(cancel_btn), "clicked",
277                          G_CALLBACK(date_format_cancel_btn_clicked),
278                          &datefmt_win);
279         g_signal_connect(G_OBJECT(datefmt_win), "key_press_event",
280                          G_CALLBACK(date_format_key_pressed),
281                          &datefmt_win);
282         g_signal_connect(G_OBJECT(datefmt_win), "delete_event",
283                          G_CALLBACK(date_format_on_delete),
284                          &datefmt_win);
285         g_signal_connect(G_OBJECT(datefmt_entry), "changed",
286                          G_CALLBACK(date_format_entry_on_change),
287                          label3);
288
289         gtk_window_set_position(GTK_WINDOW(datefmt_win), GTK_WIN_POS_CENTER);
290         gtk_window_set_modal(GTK_WINDOW(datefmt_win), TRUE);
291
292         gtk_widget_show(datefmt_win);
293         manage_window_set_transient(GTK_WINDOW(datefmt_win));
294
295         gtk_widget_grab_focus(ok_btn);
296
297         return datefmt_win;
298 }
299
300 static struct KeybindDialog {
301         GtkWidget *window;
302         GtkWidget *combo;
303 } keybind;
304
305 static void prefs_keybind_select                (void);
306 static gint prefs_keybind_deleted               (GtkWidget      *widget,
307                                                  GdkEventAny    *event,
308                                                  gpointer        data);
309 static gboolean prefs_keybind_key_pressed       (GtkWidget      *widget,
310                                                  GdkEventKey    *event,
311                                                  gpointer        data);
312 static void prefs_keybind_cancel                (void);
313 static void prefs_keybind_apply_clicked         (GtkWidget      *widget);
314
315
316 static void prefs_keybind_select(void)
317 {
318         GtkWidget *window;
319         GtkWidget *vbox1;
320         GtkWidget *hbox1;
321         GtkWidget *label;
322         GtkWidget *combo;
323         GtkWidget *confirm_area;
324         GtkWidget *ok_btn;
325         GtkWidget *cancel_btn;
326
327         window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
328         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
329         gtk_window_set_title (GTK_WINDOW (window), _("Select key bindings"));
330         gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
331         gtk_window_set_modal (GTK_WINDOW (window), TRUE);
332         gtk_window_set_resizable(GTK_WINDOW (window), FALSE);
333         manage_window_set_transient (GTK_WINDOW (window));
334
335         vbox1 = gtk_vbox_new (FALSE, VSPACING);
336         gtk_container_add (GTK_CONTAINER (window), vbox1);
337         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
338
339         hbox1 = gtk_hbox_new (FALSE, 8);
340         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
341
342         label = gtk_label_new
343                 (_("Select preset:"));
344         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
345         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
346
347         combo = gtk_combo_new ();
348         gtk_box_pack_start (GTK_BOX (hbox1), combo, TRUE, TRUE, 0);
349         gtkut_combo_set_items (GTK_COMBO (combo),
350                                _("Default"),
351                                "Mew / Wanderlust",
352                                "Mutt",
353                                _("Old Sylpheed"),
354                                NULL);
355         gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO (combo)->entry), FALSE);
356
357         hbox1 = gtk_hbox_new (FALSE, 8);
358         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
359
360         label = gtk_label_new
361                 (_("You can also modify each menu shortcut by pressing\n"
362                    "any key(s) when focusing the mouse pointer on the item."));
363         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
364         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
365         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
366         gtkut_widget_set_small_font_size (label);
367
368         hbox1 = gtk_hbox_new (FALSE, 8);
369         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
370
371         gtkut_stock_button_set_create (&confirm_area, &cancel_btn, GTK_STOCK_CANCEL,
372                                        &ok_btn, GTK_STOCK_OK,
373                                        NULL, NULL);
374         gtk_box_pack_end (GTK_BOX (hbox1), confirm_area, FALSE, FALSE, 0);
375         gtk_widget_grab_focus (ok_btn);
376
377         MANAGE_WINDOW_SIGNALS_CONNECT(window);
378         g_signal_connect (G_OBJECT (window), "delete_event",
379                           G_CALLBACK (prefs_keybind_deleted), NULL);
380         g_signal_connect (G_OBJECT (window), "key_press_event",
381                           G_CALLBACK (prefs_keybind_key_pressed), NULL);
382         g_signal_connect (G_OBJECT (ok_btn), "clicked",
383                           G_CALLBACK (prefs_keybind_apply_clicked),
384                           NULL);
385         g_signal_connect (G_OBJECT (cancel_btn), "clicked",
386                           G_CALLBACK (prefs_keybind_cancel),
387                           NULL);
388
389         gtk_widget_show_all(window);
390
391         keybind.window = window;
392         keybind.combo = combo;
393 }
394
395 static gboolean prefs_keybind_key_pressed(GtkWidget *widget, GdkEventKey *event,
396                                           gpointer data)
397 {
398         if (event && event->keyval == GDK_Escape)
399                 prefs_keybind_cancel();
400         return FALSE;
401 }
402
403 static gint prefs_keybind_deleted(GtkWidget *widget, GdkEventAny *event,
404                                   gpointer data)
405 {
406         prefs_keybind_cancel();
407         return TRUE;
408 }
409
410 static void prefs_keybind_cancel(void)
411 {
412         gtk_widget_destroy(keybind.window);
413         keybind.window = NULL;
414         keybind.combo = NULL;
415 }
416   
417 struct KeyBind {
418         const gchar *accel_path;
419         const gchar *accel_key;
420 };
421
422 static void prefs_keybind_apply(struct KeyBind keybind[], gint num)
423 {
424         gint i;
425         guint key;
426         GdkModifierType mods;
427
428         for (i = 0; i < num; i++) {
429                 const gchar *accel_key
430                         = keybind[i].accel_key ? keybind[i].accel_key : "";
431                 gtk_accelerator_parse(accel_key, &key, &mods);
432                 gtk_accel_map_change_entry(keybind[i].accel_path,
433                                            key, mods, TRUE);
434         }
435 }
436
437 static void prefs_keybind_apply_clicked(GtkWidget *widget)
438 {
439         GtkEntry *entry = GTK_ENTRY(GTK_COMBO(keybind.combo)->entry);
440         const gchar *text;
441         struct KeyBind *menurc;
442         gint n_menurc;
443
444         static struct KeyBind default_menurc[] = {
445                 {"<Main>/File/Empty all Trash folders",         "<shift>D"},
446                 {"<Main>/File/Save as...",                      "<control>S"},
447                 {"<Main>/File/Print...",                        "<control>P"},
448                 {"<Main>/File/Work offline",                    "<control>W"},
449                 {"<Main>/File/Synchronise folders",             "<control><shift>S"},
450                 {"<Main>/File/Exit",                            "<control>Q"},
451
452                 {"<Main>/Edit/Copy",                            "<control>C"},
453                 {"<Main>/Edit/Select all",                      "<control>A"},
454                 {"<Main>/Edit/Find in current message...",      "<control>F"},
455                 {"<Main>/Edit/Search folder...",                "<shift><control>F"},
456                 {"<Main>/Edit/Quick search",                    "slash"},
457
458                 {"<Main>/View/Show or hide/Message View",       "V"},
459                 {"<Main>/View/Thread view",                     "<control>T"},
460                 {"<Main>/View/Go to/Previous message",          "P"},
461                 {"<Main>/View/Go to/Next message",              "N"},
462                 {"<Main>/View/Go to/Previous unread message",   "<shift>P"},
463                 {"<Main>/View/Go to/Next unread message",       "<shift>N"},
464                 {"<Main>/View/Go to/Other folder...",           "G"},
465                 {"<Main>/View/Open in new window",              "<control><alt>N"},
466                 {"<Main>/View/Message source",                  "<control>U"},
467                 {"<Main>/View/All headers",                     "<control>H"},
468                 {"<Main>/View/Update summary",                  "<control><alt>U"},
469
470                 {"<Main>/Message/Receive/Get from current account",
471                                                                 "<control>I"},
472                 {"<Main>/Message/Receive/Get from all accounts","<shift><control>I"},
473                 {"<Main>/Message/Compose an email message",     "<control>M"},
474                 {"<Main>/Message/Reply",                        "<control>R"},
475                 {"<Main>/Message/Reply to/all",                 "<shift><control>R"},
476                 {"<Main>/Message/Reply to/sender",              ""},
477                 {"<Main>/Message/Reply to/mailing list",        "<control>L"},
478                 {"<Main>/Message/Forward",                      "<control><alt>F"},
479                 /* {"<Main>/Message/Forward as attachment",      ""}, */
480                 {"<Main>/Message/Move...",                      "<control>O"},
481                 {"<Main>/Message/Copy...",                      "<shift><control>O"},
482                 {"<Main>/Message/Move to trash",                "<control>D"},
483                 {"<Main>/Message/Mark/Mark",                    "<shift>asterisk"},
484                 {"<Main>/Message/Mark/Unmark",                  "U"},
485                 {"<Main>/Message/Mark/Mark as unread",          "<shift>exclam"},
486                 {"<Main>/Message/Mark/Mark as read",            ""},
487
488                 {"<Main>/Tools/Address book",                   "<shift><control>A"},
489                 {"<Main>/Tools/Execute",                        "X"},
490                 {"<Main>/Tools/Log window",                     "<shift><control>L"},
491
492                 {"<Compose>/Message/Send",                              "<control>Return"},
493                 {"<Compose>/Message/Send later",                        "<shift><control>S"},
494                 {"<Compose>/Message/Attach file",                       "<control>M"},
495                 {"<Compose>/Message/Insert file",                       "<control>I"},
496                 {"<Compose>/Message/Insert signature",                  "<control>G"},
497                 {"<Compose>/Message/Save",                              "<control>S"},
498                 {"<Compose>/Message/Close",                             "<control>W"},
499                 {"<Compose>/Edit/Undo",                                 "<control>Z"},
500                 {"<Compose>/Edit/Redo",                                 "<control>Y"},
501                 {"<Compose>/Edit/Cut",                                  "<control>X"},
502                 {"<Compose>/Edit/Copy",                                 "<control>C"},
503                 {"<Compose>/Edit/Paste",                                "<control>V"},
504                 {"<Compose>/Edit/Select all",                           "<control>A"},
505                 {"<Compose>/Edit/Advanced/Move a character backward",   "<control>B"},
506                 {"<Compose>/Edit/Advanced/Move a character forward",    "<control>F"},
507                 {"<Compose>/Edit/Advanced/Move a word backward,"        ""},
508                 {"<Compose>/Edit/Advanced/Move a word forward",         ""},
509                 {"<Compose>/Edit/Advanced/Move to beginning of line",   ""},
510                 {"<Compose>/Edit/Advanced/Move to end of line",         "<control>E"},
511                 {"<Compose>/Edit/Advanced/Move to previous line",       "<control>P"},
512                 {"<Compose>/Edit/Advanced/Move to next line",           "<control>N"},
513                 {"<Compose>/Edit/Advanced/Delete a character backward", "<control>H"},
514                 {"<Compose>/Edit/Advanced/Delete a character forward",  "<control>D"},
515                 {"<Compose>/Edit/Advanced/Delete a word backward",      ""},
516                 {"<Compose>/Edit/Advanced/Delete a word forward",       ""},
517                 {"<Compose>/Edit/Advanced/Delete line",                 "<control>U"},
518                 {"<Compose>/Edit/Advanced/Delete entire line",          ""},
519                 {"<Compose>/Edit/Advanced/Delete to end of line",       "<control>K"},
520                 {"<Compose>/Edit/Wrap current paragraph",               "<control>L"},
521                 {"<Compose>/Edit/Wrap all long lines",                  "<control><alt>L"},
522                 {"<Compose>/Edit/Auto wrapping",                        "<shift><control>L"},
523                 {"<Compose>/Edit/Edit with external editor",            "<shift><control>X"},
524                 {"<Compose>/Tools/Address book",                        "<shift><control>A"},
525         };
526
527         static struct KeyBind mew_wl_menurc[] = {
528                 {"<Main>/File/Empty all Trash folders",         "<shift>D"},
529                 {"<Main>/File/Save as...",                      "Y"},
530                 {"<Main>/File/Print...",                        "<shift>numbersign"},
531                 {"<Main>/File/Exit",                            "<shift>Q"},
532
533                 {"<Main>/Edit/Copy",                            "<control>C"},
534                 {"<Main>/Edit/Select all",                      "<control>A"},
535                 {"<Main>/Edit/Find in current message...",      "<control>F"},
536                 {"<Main>/Edit/Search folder...",                "<control>S"},
537
538                 {"<Main>/View/Show or hide/Message View",       ""},
539                 {"<Main>/View/Thread view",                     "<shift>T"},
540                 {"<Main>/View/Go to/Previous message",          "P"},
541                 {"<Main>/View/Go to/Next message",              "N"},
542                 {"<Main>/View/Go to/Previous unread message",   "<shift>P"},
543                 {"<Main>/View/Go to/Next unread message",       "<shift>N"},
544                 {"<Main>/View/Go to/Other folder...",           "G"},
545                 {"<Main>/View/Open in new window",              "<control><alt>N"},
546                 {"<Main>/View/Message source",                  "<control>U"},
547                 {"<Main>/View/All headers",                     "<shift>H"},
548                 {"<Main>/View/Update summary",                  "<shift>S"},
549
550                 {"<Main>/Message/Receive/Get from current account",
551                                                                 "<control>I"},
552                 {"<Main>/Message/Receive/Get from all accounts","<shift><control>I"},
553                 {"<Main>/Message/Compose an email message",     "W"},
554                 {"<Main>/Message/Reply",                        "<control>R"},
555                 {"<Main>/Message/Reply to/all",                 "<shift>A"},
556                 {"<Main>/Message/Reply to/sender",              ""},
557                 {"<Main>/Message/Reply to/mailing list",        "<control>L"},
558                 {"<Main>/Message/Forward",                      "F"},
559                 /* {"<Main>/Message/Forward as attachment", "<shift>F"}, */
560                 {"<Main>/Message/Move...",                      "O"},
561                 {"<Main>/Message/Copy...",                      "<shift>O"},
562                 {"<Main>/Message/Delete",                       "D"},
563                 {"<Main>/Message/Mark/Mark",                    "<shift>asterisk"},
564                 {"<Main>/Message/Mark/Unmark",                  "U"},
565                 {"<Main>/Message/Mark/Mark as unread",          "<shift>exclam"},
566                 {"<Main>/Message/Mark/Mark as read",            "<shift>R"},
567
568                 {"<Main>/Tools/Address book",                   "<shift><control>A"},
569                 {"<Main>/Tools/Execute",                        "X"},
570                 {"<Main>/Tools/Log window",                     "<shift><control>L"},
571
572                 {"<Compose>/Message/Close",                             "<alt>W"},
573                 {"<Compose>/Edit/Select all",                           ""},
574                 {"<Compose>/Edit/Advanced/Move a word backward,"        "<alt>B"},
575                 {"<Compose>/Edit/Advanced/Move a word forward",         "<alt>F"},
576                 {"<Compose>/Edit/Advanced/Move to beginning of line",   "<control>A"},
577                 {"<Compose>/Edit/Advanced/Delete a word backward",      "<control>W"},
578                 {"<Compose>/Edit/Advanced/Delete a word forward",       "<alt>D"},
579         };
580
581         static struct KeyBind mutt_menurc[] = {
582                 {"<Main>/File/Empty all Trash folders",         ""},
583                 {"<Main>/File/Save as...",                      "S"},
584                 {"<Main>/File/Print...",                        "P"},
585                 {"<Main>/File/Exit",                            "Q"},
586
587                 {"<Main>/Edit/Copy",                            "<control>C"},
588                 {"<Main>/Edit/Select all",                      "<control>A"},
589                 {"<Main>/Edit/Find in current message...",      "<control>F"},
590                 {"<Main>/Edit/Search messages...",              "slash"},
591
592                 {"<Main>/View/Show or hide/Message view",       "V"},
593                 {"<Main>/View/Thread view",                     "<control>T"},
594                 {"<Main>/View/Go to/Previous message",          ""},
595                 {"<Main>/View/Go to/Next message",              ""},
596                 {"<Main>/View/Go to/Previous unread message",   ""},
597                 {"<Main>/View/Go to/Next unread message",       ""},
598                 {"<Main>/View/Go to/Other folder...",           "C"},
599                 {"<Main>/View/Open in new window",              "<control><alt>N"},
600                 {"<Main>/View/Message source",                  "<control>U"},
601                 {"<Main>/View/All headers",                     "<control>H"},
602                 {"<Main>/View/Update summary",                  "<control><alt>U"},
603
604                 {"<Main>/Message/Receive/Get from current account",
605                                                                 "<control>I"},
606                 {"<Main>/Message/Receive/Get from all accounts","<shift><control>I"},
607                 {"<Main>/Message/Compose an email message",             "M"},
608                 {"<Main>/Message/Reply",                        "R"},
609                 {"<Main>/Message/Reply to/all",                 "G"},
610                 {"<Main>/Message/Reply to/sender",              ""},
611                 {"<Main>/Message/Reply to/mailing list",        "<control>L"},
612                 {"<Main>/Message/Forward",                      "F"},
613                 {"<Main>/Message/Forward as attachment",        ""},
614                 {"<Main>/Message/Move...",                      "<control>O"},
615                 {"<Main>/Message/Copy...",                      "<shift>C"},
616                 {"<Main>/Message/Delete",                       "D"},
617                 {"<Main>/Message/Mark/Mark",                    "<shift>F"},
618                 {"<Main>/Message/Mark/Unmark",                  "U"},
619                 {"<Main>/Message/Mark/Mark as unread",          "<shift>N"},
620                 {"<Main>/Message/Mark/Mark as read",            ""},
621
622                 {"<Main>/Tools/Address book",                   "<shift><control>A"},
623                 {"<Main>/Tools/Execute",                        "X"},
624                 {"<Main>/Tools/Log window",                     "<shift><control>L"},
625
626                 {"<Compose>/Message/Close",                             "<alt>W"},
627                 {"<Compose>/Edit/Select all",                           ""},
628                 {"<Compose>/Edit/Advanced/Move a word backward",        "<alt>B"},
629                 {"<Compose>/Edit/Advanced/Move a word forward",         "<alt>F"},
630                 {"<Compose>/Edit/Advanced/Move to beginning of line",   "<control>A"},
631                 {"<Compose>/Edit/Advanced/Delete a word backward",      "<control>W"},
632                 {"<Compose>/Edit/Advanced/Delete a word forward",       "<alt>D"},
633         };
634
635         static struct KeyBind old_sylpheed_menurc[] = {
636                 {"<Main>/File/Empty all Trash folders",         ""},
637                 {"<Main>/File/Save as...",                      ""},
638                 {"<Main>/File/Print...",                        "<alt>P"},
639                 {"<Main>/File/Exit",                            "<alt>Q"},
640
641                 {"<Main>/Edit/Copy",                            "<control>C"},
642                 {"<Main>/Edit/Select all",                      "<control>A"},
643                 {"<Main>/Edit/Find in current message...",      "<control>F"},
644                 {"<Main>/Edit/Search folder...",                "<control>S"},
645
646                 {"<Main>/View/Show or hide/Message View",       ""},
647                 {"<Main>/View/Thread view",                     "<control>T"},
648                 {"<Main>/View/Go to/Previous message",          "P"},
649                 {"<Main>/View/Go to/Next message",              "N"},
650                 {"<Main>/View/Go to/Previous unread message",   "<shift>P"},
651                 {"<Main>/View/Go to/Next unread message",       "<shift>N"},
652                 {"<Main>/View/Go to/Other folder...",           "<alt>G"},
653                 {"<Main>/View/Open in new window",              "<shift><control>N"},
654                 {"<Main>/View/Message source",                  "<control>U"},
655                 {"<Main>/View/All headers",                     "<control>H"},
656                 {"<Main>/View/Update summary",                  "<alt>U"},
657
658                 {"<Main>/Message/Receive/Get from current account",
659                                                                 "<alt>I"},
660                 {"<Main>/Message/Receive/Get from all accounts","<shift><alt>I"},
661                 {"<Main>/Message/Compose an email message",     "<alt>N"},
662                 {"<Main>/Message/Reply",                        "<alt>R"},
663                 {"<Main>/Message/Reply to/all",                 "<shift><alt>R"},
664                 {"<Main>/Message/Reply to/sender",              "<control><alt>R"},
665                 {"<Main>/Message/Reply to/mailing list",        "<control>L"},
666                 {"<Main>/Message/Forward",                       "<shift><alt>F"},
667                 /* "(menu-path \"<Main>/Message/Forward as attachment", "<shift><control>F"}, */
668                 {"<Main>/Message/Move...",                      "<alt>O"},
669                 {"<Main>/Message/Copy...",                      ""},
670                 {"<Main>/Message/Delete",                       "<alt>D"},
671                 {"<Main>/Message/Mark/Mark",                    "<shift>asterisk"},
672                 {"<Main>/Message/Mark/Unmark",                  "U"},
673                 {"<Main>/Message/Mark/Mark as unread",          "<shift>exclam"},
674                 {"<Main>/Message/Mark/Mark as read",            ""},
675
676                 {"<Main>/Tools/Address book",                   "<alt>A"},
677                 {"<Main>/Tools/Execute",                        "<alt>X"},
678                 {"<Main>/Tools/Log window",                     "<alt>L"},
679
680                 {"<Compose>/Message/Close",                             "<alt>W"},
681                 {"<Compose>/Edit/Select all",                           ""},
682                 {"<Compose>/Edit/Advanced/Move a word backward",        "<alt>B"},
683                 {"<Compose>/Edit/Advanced/Move a word forward",         "<alt>F"},
684                 {"<Compose>/Edit/Advanced/Move to beginning of line",   "<control>A"},
685                 {"<Compose>/Edit/Advanced/Delete a word backward",      "<control>W"},
686                 {"<Compose>/Edit/Advanced/Delete a word forward",       "<alt>D"},
687         };
688   
689         text = gtk_entry_get_text(entry);
690   
691         if (!strcmp(text, _("Default"))) {
692                 menurc = default_menurc;
693                 n_menurc = G_N_ELEMENTS(default_menurc);
694         } else if (!strcmp(text, "Mew / Wanderlust")) {
695                 menurc = mew_wl_menurc;
696                 n_menurc = G_N_ELEMENTS(mew_wl_menurc);
697         } else if (!strcmp(text, "Mutt")) {
698                 menurc = mutt_menurc;
699                 n_menurc = G_N_ELEMENTS(mutt_menurc);
700         } else if (!strcmp(text, _("Old Sylpheed"))) {
701                 menurc = old_sylpheed_menurc;
702                 n_menurc = G_N_ELEMENTS(old_sylpheed_menurc);
703         } else {
704                 return;
705         }
706
707         /* prefs_keybind_apply(empty_menurc, G_N_ELEMENTS(empty_menurc)); */
708         prefs_keybind_apply(menurc, n_menurc);
709
710         gtk_widget_destroy(keybind.window);
711         keybind.window = NULL;
712         keybind.combo = NULL;
713 }
714
715 void prefs_summaries_create_widget(PrefsPage *_page, GtkWindow *window, 
716                                   gpointer data)
717 {
718         SummariesPage *prefs_summaries = (SummariesPage *) _page;
719         
720         GtkWidget *vbox1;
721         GtkWidget *chkbtn_transhdr;
722         GtkWidget *chkbtn_folder_unread;
723         GtkWidget *hbox1;
724         GtkWidget *label_ng_abbrev;
725         GtkWidget *spinbtn_ng_abbrev_len;
726         GtkObject *spinbtn_ng_abbrev_len_adj;
727         GtkWidget *vbox2;
728         GtkWidget *chkbtn_useaddrbook;
729         GtkWidget *chkbtn_threadsubj;
730         GtkWidget *label_datefmt;
731         GtkWidget *button_datefmt;
732         GtkWidget *entry_datefmt;
733         GtkTooltips *tip_datefmt;
734         GtkWidget *hbox_dispitem;
735         GtkWidget *button_dispitem;
736
737         GtkWidget *hbox2;
738         GtkWidget *checkbtn_always_show_msg;
739         GtkWidget *checkbtn_mark_as_read_on_newwin;
740         GtkWidget *spinbtn_mark_as_read_delay;
741         GtkObject *spinbtn_mark_as_read_delay_adj;
742         GtkWidget *checkbtn_immedexec;
743         GtkWidget *checkbtn_ask_mark_all_read;
744         GtkTooltips *immedexec_tooltip;
745         GtkWidget *label, *label_fill;
746         GtkWidget *menu;
747         GtkWidget *menuitem;
748         GtkWidget *button_keybind;
749         GtkWidget *optmenu_select_on_entry;
750         GtkWidget *optmenu_nextunreadmsgdialog;
751         GtkWidget *folderview_frame;
752         GtkWidget *summaryview_frame;
753         GtkTooltips *tooltips;
754
755         tooltips = gtk_tooltips_new();
756
757         vbox1 = gtk_vbox_new (FALSE, VSPACING);
758         gtk_widget_show (vbox1);
759         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
760         
761         vbox2 = gtkut_get_options_frame(vbox1, &folderview_frame, _("Folder list"));
762
763         PACK_CHECK_BUTTON (vbox2, chkbtn_folder_unread,
764                            _("Display unread number next to folder name"));
765
766         hbox1 = gtk_hbox_new (FALSE, 8);
767         gtk_widget_show (hbox1);
768         gtk_box_pack_start(GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
769
770         label_ng_abbrev = gtk_label_new
771                 (_("Abbreviate newsgroup names longer than"));
772         gtk_widget_show (label_ng_abbrev);
773         gtk_box_pack_start (GTK_BOX (hbox1), label_ng_abbrev, FALSE, FALSE, 0);
774
775         spinbtn_ng_abbrev_len_adj = gtk_adjustment_new (16, 0, 999, 1, 10, 10);
776         spinbtn_ng_abbrev_len = gtk_spin_button_new
777                 (GTK_ADJUSTMENT (spinbtn_ng_abbrev_len_adj), 1, 0);
778         gtk_widget_show (spinbtn_ng_abbrev_len);
779         gtk_box_pack_start (GTK_BOX (hbox1), spinbtn_ng_abbrev_len,
780                             FALSE, FALSE, 0);
781         gtk_widget_set_size_request (spinbtn_ng_abbrev_len, 56, -1);
782         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_ng_abbrev_len),
783                                      TRUE);
784
785         label_ng_abbrev = gtk_label_new (_("letters"));
786         gtk_widget_show (label_ng_abbrev);
787         gtk_box_pack_start (GTK_BOX (hbox1), label_ng_abbrev, FALSE, FALSE, 0);
788
789         hbox_dispitem = gtk_hbox_new (FALSE, 8);
790         gtk_widget_show (hbox_dispitem);
791         gtk_box_pack_start(GTK_BOX(vbox2), hbox_dispitem, FALSE, TRUE, 0);
792
793         label = gtk_label_new(_("Displayed columns"));
794         gtk_widget_show(label);
795         gtk_box_pack_start(GTK_BOX(hbox_dispitem), label, FALSE, FALSE, 0);
796         button_dispitem = gtk_button_new_from_stock(GTK_STOCK_EDIT);
797         gtk_widget_show (button_dispitem);
798         gtk_box_pack_start (GTK_BOX (hbox_dispitem), button_dispitem, FALSE, FALSE, 0);
799         g_signal_connect (G_OBJECT (button_dispitem), "clicked",
800                           G_CALLBACK (prefs_folder_column_open),
801                           NULL);
802
803         vbox2 = gtkut_get_options_frame(vbox1, &summaryview_frame, _("Message list"));
804
805         hbox1 = gtk_hbox_new (FALSE, 10);
806         gtk_widget_show (hbox1);
807         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, TRUE, 0);
808
809         label = gtk_label_new (_("When entering a folder"));
810         gtk_widget_show (label);
811         gtk_box_pack_start(GTK_BOX(hbox1), label, FALSE, FALSE, 0);
812
813         optmenu_select_on_entry = gtk_option_menu_new ();
814         gtk_widget_show (optmenu_select_on_entry);
815         
816         menu = gtk_menu_new ();
817         MENUITEM_ADD (menu, menuitem, _("Do nothing"), SELECTONENTRY_NOTHING);
818         MENUITEM_ADD (menu, menuitem, _("Select first unread (or new or marked) message"),
819                       SELECTONENTRY_UNM);
820         MENUITEM_ADD (menu, menuitem, _("Select first unread (or marked or new) message"),
821                       SELECTONENTRY_UMN);
822         MENUITEM_ADD (menu, menuitem, _("Select first new (or unread or marked) message"),
823                       SELECTONENTRY_NUM);
824         MENUITEM_ADD (menu, menuitem, _("Select first new (or marked or unread) message"),
825                       SELECTONENTRY_NMU);
826         MENUITEM_ADD (menu, menuitem, _("Select first marked (or new or unread) message"),
827                       SELECTONENTRY_MNU);
828         MENUITEM_ADD (menu, menuitem, _("Select first marked (or unread or new) message"),
829                       SELECTONENTRY_MUN);
830
831         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_select_on_entry), menu);
832         gtk_box_pack_start(GTK_BOX(hbox1), optmenu_select_on_entry, FALSE, FALSE, 0);
833
834         /* Next Unread Message Dialog */
835         hbox1 = gtk_hbox_new (FALSE, 10);
836         gtk_widget_show (hbox1);
837         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);   
838
839         label = gtk_label_new (_("Show \"no unread (or new) message\" dialog"));
840         gtk_widget_show (label);
841         gtk_box_pack_start(GTK_BOX(hbox1), label, FALSE, FALSE, 0);
842         
843         optmenu_nextunreadmsgdialog = gtk_option_menu_new ();
844         gtk_widget_show (optmenu_nextunreadmsgdialog);
845
846         menu = gtk_menu_new ();
847         MENUITEM_ADD (menu, menuitem, _("Always"), NEXTUNREADMSGDIALOG_ALWAYS);
848         MENUITEM_ADD (menu, menuitem, _("Assume 'Yes'"), 
849                       NEXTUNREADMSGDIALOG_ASSUME_YES);
850         MENUITEM_ADD (menu, menuitem, _("Assume 'No'"), 
851                       NEXTUNREADMSGDIALOG_ASSUME_NO);
852
853         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_nextunreadmsgdialog), menu);
854         gtk_box_pack_start(GTK_BOX(hbox1), optmenu_nextunreadmsgdialog, FALSE, FALSE, 0);
855
856         PACK_CHECK_BUTTON
857                 (vbox2, checkbtn_always_show_msg,
858                  _("Always open message when selected"));
859         PACK_CHECK_BUTTON
860                 (vbox2, chkbtn_threadsubj,
861                  _("Thread using subject in addition to standard headers"));
862
863         immedexec_tooltip = gtk_tooltips_new();
864
865         PACK_CHECK_BUTTON
866                 (vbox2, checkbtn_immedexec,
867                  _("Execute immediately when moving or deleting messages"));
868         gtk_tooltips_set_tip(GTK_TOOLTIPS(immedexec_tooltip), checkbtn_immedexec,
869                              _("Defers moving, copying and deleting of messages"
870                                " until you choose 'Tools/Execute'"),
871                              NULL);
872         PACK_CHECK_BUTTON
873                 (vbox2, checkbtn_mark_as_read_on_newwin,
874                  _("Only mark message as read when opened in a new window"));
875                  
876         hbox1 = gtk_hbox_new (FALSE, 8);
877         gtk_widget_show (hbox1);
878         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, TRUE, 0);
879
880         gtk_box_pack_start (GTK_BOX (hbox1), gtk_label_new
881                 (_("Mark messages as read after")), FALSE, FALSE, 0);
882
883         spinbtn_mark_as_read_delay_adj = gtk_adjustment_new (0, 0, 60, 1, 10, 10);
884         spinbtn_mark_as_read_delay = gtk_spin_button_new
885                 (GTK_ADJUSTMENT (spinbtn_mark_as_read_delay_adj), 1, 0);
886         gtk_box_pack_start (GTK_BOX (hbox1), spinbtn_mark_as_read_delay,
887                             FALSE, FALSE, 0);
888         gtk_widget_set_size_request (spinbtn_mark_as_read_delay, 56, -1);
889         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_mark_as_read_delay),
890                                      TRUE);
891         gtk_box_pack_start (GTK_BOX (hbox1), gtk_label_new
892                 (_("seconds")), FALSE, FALSE, 0);
893         gtk_widget_show_all(hbox1);
894
895         PACK_CHECK_BUTTON
896                 (vbox2, chkbtn_useaddrbook,
897                  _("Display sender using address book"));
898                  
899         hbox2 = gtk_hbox_new (FALSE, 8);
900         gtk_widget_show (hbox2);
901         gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, TRUE, 0);
902
903         label_datefmt = gtk_label_new (_("Date format"));
904         gtk_widget_show (label_datefmt);
905         gtk_box_pack_start (GTK_BOX (hbox2), label_datefmt, FALSE, FALSE, 0);
906
907         entry_datefmt = gtk_entry_new ();
908         gtk_widget_show (entry_datefmt);
909         gtk_widget_set_size_request(entry_datefmt, 200, -1);
910         gtk_box_pack_start (GTK_BOX (hbox2), entry_datefmt, FALSE, FALSE, 0);
911
912 #if GTK_CHECK_VERSION(2, 8, 0)
913         button_datefmt = gtk_button_new_from_stock(GTK_STOCK_INFO);
914 #else
915         button_datefmt = gtk_button_new_with_label ("Info...");
916 #endif
917
918         gtk_widget_show (button_datefmt);
919         gtk_box_pack_start (GTK_BOX (hbox2), button_datefmt, FALSE, FALSE, 0);
920         g_signal_connect (G_OBJECT (button_datefmt), "clicked",
921                           G_CALLBACK (date_format_create), NULL);
922         
923         label_fill = gtk_label_new(" ");
924         gtk_box_pack_start(GTK_BOX(hbox2), label_fill, TRUE, FALSE, 0);
925         
926         tip_datefmt = gtk_tooltips_new();
927         gtk_tooltips_set_tip(GTK_TOOLTIPS(tip_datefmt),
928                              button_datefmt,
929                              _("Date format help"), NULL);
930                              
931         hbox_dispitem = gtk_hbox_new (FALSE, 8);
932         gtk_widget_show (hbox_dispitem);
933         gtk_box_pack_start(GTK_BOX(vbox2), hbox_dispitem, FALSE, TRUE, 0);
934         
935         label = gtk_label_new(_("Displayed columns"));
936         gtk_widget_show(label);
937         gtk_box_pack_start(GTK_BOX(hbox_dispitem), label, FALSE, FALSE, 0);
938         button_dispitem = gtk_button_new_from_stock(GTK_STOCK_EDIT);
939         gtk_widget_show (button_dispitem);
940         gtk_box_pack_start (GTK_BOX (hbox_dispitem), button_dispitem, FALSE, FALSE, 0);
941         g_signal_connect (G_OBJECT (button_dispitem), "clicked",
942                           G_CALLBACK (prefs_summary_column_open),
943                           NULL);
944
945         PACK_CHECK_BUTTON
946                 (vbox1, checkbtn_ask_mark_all_read,
947                  _("Confirm before marking all mails in a folder as read"));
948         PACK_CHECK_BUTTON
949                 (vbox1, chkbtn_transhdr,
950                  _("Translate header names"));
951         gtk_tooltips_set_tip(tooltips, chkbtn_transhdr,
952                              _("The display of standard headers (such as 'From:', 'Subject:') "
953                              "will be translated into your language."), NULL);
954         
955         hbox2 = gtk_hbox_new (FALSE, 8);
956         gtk_widget_show (hbox2);
957         gtk_box_pack_start (GTK_BOX (vbox1), hbox2, FALSE, FALSE, 0);
958
959         button_keybind = gtk_button_new_with_label (_(" Set key bindings... "));
960         gtk_widget_show (button_keybind);
961         gtk_box_pack_start (GTK_BOX (hbox2), button_keybind, FALSE, FALSE, 0);
962         g_signal_connect (G_OBJECT (button_keybind), "clicked",
963                           G_CALLBACK (prefs_keybind_select), NULL);
964
965
966         prefs_summaries->window                 = GTK_WIDGET(window);
967         
968         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_transhdr),
969                         prefs_common.trans_hdr);
970         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_folder_unread),
971                         prefs_common.display_folder_unread);
972         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_useaddrbook),
973                         prefs_common.use_addr_book);
974         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_threadsubj),
975                         prefs_common.thread_by_subject);
976         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_ng_abbrev_len),
977                         prefs_common.ng_abbrev_len);
978         gtk_entry_set_text(GTK_ENTRY(entry_datefmt), 
979                         prefs_common.date_format?prefs_common.date_format:"");  
980
981         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_always_show_msg),
982                         prefs_common.always_show_msg);
983         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_mark_as_read_on_newwin),
984                         prefs_common.mark_as_read_on_new_window);
985         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_mark_as_read_delay),
986                         prefs_common.mark_as_read_delay);
987         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_immedexec),
988                         prefs_common.immediate_exec);
989         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_ask_mark_all_read),
990                         prefs_common.ask_mark_all_read);
991
992         gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu_select_on_entry),
993                         prefs_common.select_on_entry);
994         gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu_nextunreadmsgdialog),
995                         prefs_common.next_unread_msg_dialog);
996
997         prefs_summaries->chkbtn_transhdr = chkbtn_transhdr;
998         prefs_summaries->chkbtn_folder_unread = chkbtn_folder_unread;
999         prefs_summaries->spinbtn_ng_abbrev_len = spinbtn_ng_abbrev_len;
1000         prefs_summaries->chkbtn_useaddrbook = chkbtn_useaddrbook;
1001         prefs_summaries->chkbtn_threadsubj = chkbtn_threadsubj;
1002         prefs_summaries->entry_datefmt = entry_datefmt;
1003
1004         prefs_summaries->checkbtn_always_show_msg = checkbtn_always_show_msg;
1005         prefs_summaries->checkbtn_mark_as_read_on_newwin = checkbtn_mark_as_read_on_newwin;
1006         prefs_summaries->spinbtn_mark_as_read_delay = spinbtn_mark_as_read_delay;
1007         prefs_summaries->checkbtn_immedexec = checkbtn_immedexec;
1008         prefs_summaries->checkbtn_ask_mark_all_read = checkbtn_ask_mark_all_read;
1009         prefs_summaries->optmenu_select_on_entry = optmenu_select_on_entry;
1010         prefs_summaries->optmenu_nextunreadmsgdialog = optmenu_nextunreadmsgdialog;
1011
1012         prefs_summaries->page.widget = vbox1;
1013 }
1014
1015 void prefs_summaries_save(PrefsPage *_page)
1016 {
1017         SummariesPage *page = (SummariesPage *) _page;
1018         GtkWidget *menu;
1019         GtkWidget *menuitem;
1020
1021         prefs_common.trans_hdr = gtk_toggle_button_get_active(
1022                         GTK_TOGGLE_BUTTON(page->chkbtn_transhdr));
1023         prefs_common.display_folder_unread = gtk_toggle_button_get_active(
1024                         GTK_TOGGLE_BUTTON(page->chkbtn_folder_unread));
1025         prefs_common.use_addr_book = gtk_toggle_button_get_active(
1026                         GTK_TOGGLE_BUTTON(page->chkbtn_useaddrbook));
1027         prefs_common.thread_by_subject = gtk_toggle_button_get_active(
1028                         GTK_TOGGLE_BUTTON(page->chkbtn_threadsubj));
1029         prefs_common.ng_abbrev_len = gtk_spin_button_get_value_as_int(
1030                         GTK_SPIN_BUTTON(page->spinbtn_ng_abbrev_len));
1031         
1032         g_free(prefs_common.date_format); 
1033         prefs_common.date_format = gtk_editable_get_chars(
1034                         GTK_EDITABLE(page->entry_datefmt), 0, -1);      
1035
1036         prefs_common.always_show_msg = gtk_toggle_button_get_active(
1037                 GTK_TOGGLE_BUTTON(page->checkbtn_always_show_msg));
1038         prefs_common.mark_as_read_on_new_window = gtk_toggle_button_get_active(
1039                 GTK_TOGGLE_BUTTON(page->checkbtn_mark_as_read_on_newwin));
1040         prefs_common.immediate_exec = gtk_toggle_button_get_active(
1041                 GTK_TOGGLE_BUTTON(page->checkbtn_immedexec));
1042         prefs_common.ask_mark_all_read = gtk_toggle_button_get_active(
1043                 GTK_TOGGLE_BUTTON(page->checkbtn_ask_mark_all_read));
1044         prefs_common.mark_as_read_delay = gtk_spin_button_get_value_as_int(
1045                         GTK_SPIN_BUTTON(page->spinbtn_mark_as_read_delay));
1046
1047         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_select_on_entry));
1048         menuitem = gtk_menu_get_active(GTK_MENU(menu));
1049         prefs_common.select_on_entry = GPOINTER_TO_INT
1050                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
1051         
1052         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_nextunreadmsgdialog));
1053         menuitem = gtk_menu_get_active(GTK_MENU(menu));
1054         prefs_common.next_unread_msg_dialog = GPOINTER_TO_INT
1055                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
1056         main_window_reflect_prefs_all();
1057 }
1058
1059 static void prefs_summaries_destroy_widget(PrefsPage *_page)
1060 {
1061 }
1062
1063 SummariesPage *prefs_summaries;
1064
1065 void prefs_summaries_init(void)
1066 {
1067         SummariesPage *page;
1068         static gchar *path[3];
1069
1070         path[0] = _("Display");
1071         path[1] = _("Summaries");
1072         path[2] = NULL;
1073
1074         page = g_new0(SummariesPage, 1);
1075         page->page.path = path;
1076         page->page.create_widget = prefs_summaries_create_widget;
1077         page->page.destroy_widget = prefs_summaries_destroy_widget;
1078         page->page.save_page = prefs_summaries_save;
1079         page->page.weight = 140.0;
1080         prefs_gtk_register_page((PrefsPage *) page);
1081         prefs_summaries = page;
1082 }
1083
1084 void prefs_summaries_done(void)
1085 {
1086         prefs_gtk_unregister_page((PrefsPage *) prefs_summaries);
1087         g_free(prefs_summaries);
1088 }
1089
1090 static void date_format_ok_btn_clicked(GtkButton *button, GtkWidget **widget)
1091 {
1092         GtkWidget *datefmt_sample = NULL;
1093         gchar *text;
1094
1095         g_return_if_fail(widget != NULL);
1096         g_return_if_fail(*widget != NULL);
1097         g_return_if_fail(prefs_summaries->entry_datefmt != NULL);
1098
1099         datefmt_sample = GTK_WIDGET(g_object_get_data
1100                                     (G_OBJECT(*widget), "datefmt_sample"));
1101         g_return_if_fail(datefmt_sample != NULL);
1102
1103         text = gtk_editable_get_chars(GTK_EDITABLE(datefmt_sample), 0, -1);
1104         g_free(prefs_common.date_format);
1105         prefs_common.date_format = text;
1106         gtk_entry_set_text(GTK_ENTRY(prefs_summaries->entry_datefmt), text);
1107
1108         gtk_widget_destroy(*widget);
1109         *widget = NULL;
1110 }
1111
1112 static void date_format_cancel_btn_clicked(GtkButton *button,
1113                                            GtkWidget **widget)
1114 {
1115         g_return_if_fail(widget != NULL);
1116         g_return_if_fail(*widget != NULL);
1117
1118         gtk_widget_destroy(*widget);
1119         *widget = NULL;
1120 }
1121
1122 static gboolean date_format_key_pressed(GtkWidget *keywidget, GdkEventKey *event,
1123                                         GtkWidget **widget)
1124 {
1125         if (event && event->keyval == GDK_Escape)
1126                 date_format_cancel_btn_clicked(NULL, widget);
1127         return FALSE;
1128 }
1129
1130 static gboolean date_format_on_delete(GtkWidget *dialogwidget,
1131                                       GdkEventAny *event, GtkWidget **widget)
1132 {
1133         g_return_val_if_fail(widget != NULL, FALSE);
1134         g_return_val_if_fail(*widget != NULL, FALSE);
1135
1136         *widget = NULL;
1137         return FALSE;
1138 }
1139
1140 static void date_format_entry_on_change(GtkEditable *editable,
1141                                         GtkLabel *example)
1142 {
1143         time_t cur_time;
1144         struct tm *cal_time;
1145         gchar buffer[100];
1146         gchar *text;
1147
1148         cur_time = time(NULL);
1149         cal_time = localtime(&cur_time);
1150         buffer[0] = 0;
1151         text = gtk_editable_get_chars(editable, 0, -1);
1152         if (text)
1153                 fast_strftime(buffer, sizeof buffer, text, cal_time); 
1154         g_free(text);
1155
1156         text = conv_codeset_strdup(buffer,
1157                                    conv_get_locale_charset_str(),
1158                                    CS_UTF_8);
1159         if (!text)
1160                 text = g_strdup(buffer);
1161
1162         gtk_label_set_text(example, text);
1163
1164         g_free(text);
1165 }
1166
1167 static void date_format_select_row(GtkTreeView *list_view,
1168                                    GtkTreePath *path,
1169                                    GtkTreeViewColumn *column,
1170                                    GtkWidget *date_format)
1171 {
1172         gint cur_pos;
1173         gchar *format;
1174         const gchar *old_format;
1175         gchar *new_format;
1176         GtkWidget *datefmt_sample;
1177         GtkTreeIter iter;
1178         GtkTreeModel *model;
1179         
1180         g_return_if_fail(date_format != NULL);
1181
1182         /* only on double click */
1183         datefmt_sample = GTK_WIDGET(g_object_get_data(G_OBJECT(date_format), 
1184                                                       "datefmt_sample"));
1185
1186         g_return_if_fail(datefmt_sample != NULL);
1187
1188         model = gtk_tree_view_get_model(list_view);
1189
1190         /* get format from list */
1191         if (!gtk_tree_model_get_iter(model, &iter, path))
1192                 return;
1193
1194         gtk_tree_model_get(model, &iter, DATEFMT_FMT, &format, -1);             
1195         
1196         cur_pos = gtk_editable_get_position(GTK_EDITABLE(datefmt_sample));
1197         old_format = gtk_entry_get_text(GTK_ENTRY(datefmt_sample));
1198
1199         /* insert the format into the text entry */
1200         new_format = g_malloc(strlen(old_format) + 3);
1201
1202         strncpy(new_format, old_format, cur_pos);
1203         new_format[cur_pos] = '\0';
1204         strcat(new_format, format);
1205         strcat(new_format, &old_format[cur_pos]);
1206
1207         gtk_entry_set_text(GTK_ENTRY(datefmt_sample), new_format);
1208         gtk_editable_set_position(GTK_EDITABLE(datefmt_sample), cur_pos + 2);
1209
1210         g_free(new_format);
1211 }