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