3b2b3a2e24abfc8b996819fbffa7a22d97b67575
[claws.git] / src / prefs_summaries.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2005-2015 Colin Leroy and The Claws Mail Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifdef HAVE_CONFIG_H
20 #  include "config.h"
21 #include "claws-features.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 #ifdef G_OS_WIN32
35 #  include <w32lib.h>
36 #endif
37
38 #include "prefs_common.h"
39 #include "prefs_gtk.h"
40 #include "prefs_summary_open.h"
41 #include "prefs_summary_column.h"
42 #include "prefs_folder_column.h"
43
44 #include "gtk/menu.h"
45 #include "gtk/gtkutils.h"
46 #include "gtk/prefswindow.h"
47 #include "gtk/combobox.h"
48
49 #include "manage_window.h"
50
51 typedef struct _SummariesPage
52 {
53         PrefsPage page;
54
55         GtkWidget *window;
56
57         GtkWidget *checkbtn_transhdr;
58         GtkWidget *optmenu_folder_unread;
59         GtkWidget *spinbtn_ng_abbrev_len;
60         GtkWidget *checkbtn_useaddrbook;
61         GtkWidget *checkbtn_show_tooltips;
62         GtkWidget *checkbtn_threadsubj;
63         GtkWidget *button_datefmt;
64         GtkWidget *entry_datefmt;
65
66         GtkWidget *checkbtn_reopen_last_folder;
67         GtkWidget *optmenu_always_show_msg;
68         GtkWidget *checkbtn_mark_as_read_on_newwin;
69         GtkWidget *spinbtn_mark_as_read_delay;
70         GtkWidget *checkbtn_immedexec;
71         GtkWidget *checkbtn_ask_mark_all_read;
72         GtkWidget *optmenu_sort_key;
73         GtkWidget *optmenu_sort_type;
74         GtkWidget *optmenu_nextunreadmsgdialog;
75
76 } SummariesPage;
77
78 enum {
79         DATEFMT_FMT,
80         DATEFMT_TXT,
81         N_DATEFMT_COLUMNS
82 };
83
84 static void date_format_ok_btn_clicked          (GtkButton      *button,
85                                                  GtkWidget     **widget);
86 static void date_format_cancel_btn_clicked      (GtkButton      *button,
87                                                  GtkWidget     **widget);
88 static gboolean date_format_key_pressed         (GtkWidget      *keywidget,
89                                                  GdkEventKey    *event,
90                                                  GtkWidget     **widget);
91 static gboolean date_format_on_delete           (GtkWidget      *dialogwidget,
92                                                  GdkEventAny    *event,
93                                                  GtkWidget     **widget);
94 static void date_format_entry_on_change         (GtkEditable    *editable,
95                                                  GtkLabel       *example);
96 static void date_format_select_row              (GtkTreeView *list_view,
97                                                  GtkTreePath *path,
98                                                  GtkTreeViewColumn *column,
99                                                  GtkWidget *date_format);
100 static void mark_as_read_toggled                (GtkToggleButton *button,
101                                                  GtkWidget *spinbtn);
102
103 static GtkWidget *date_format_create(GtkButton *button, void *data)
104 {
105         static GtkWidget *datefmt_win = NULL;
106
107         GtkWidget *vbox1;
108         GtkWidget *scrolledwindow1;
109         GtkWidget *datefmt_list_view;
110         GtkWidget *table;
111         GtkWidget *label1;
112         GtkWidget *label2;
113         GtkWidget *label3;
114         GtkWidget *confirm_area;
115         GtkWidget *ok_btn;
116         GtkWidget *cancel_btn;
117         GtkWidget *datefmt_entry;
118         GtkListStore *store;
119
120         struct {
121                 gchar *fmt;
122                 gchar *txt;
123         } time_format[] = {
124                 { "%a", NULL },
125                 { "%A", NULL },
126                 { "%b", NULL },
127                 { "%B", NULL },
128                 { "%c", NULL },
129                 { "%C", NULL },
130                 { "%d", NULL },
131                 { "%H", NULL },
132                 { "%I", NULL },
133                 { "%j", NULL },
134                 { "%m", NULL },
135                 { "%M", NULL },
136                 { "%p", NULL },
137                 { "%S", NULL },
138                 { "%w", NULL },
139                 { "%x", NULL },
140                 { "%y", NULL },
141                 { "%Y", NULL },
142                 { "%Z", NULL }
143         };
144
145         gint i;
146         const gint TIME_FORMAT_ELEMS =
147                 sizeof time_format / sizeof time_format[0];
148
149         GtkCellRenderer *renderer;
150         GtkTreeViewColumn *column;
151         GtkTreeSelection *selection;
152
153         time_format[0].txt  = _("the abbreviated weekday name");
154         time_format[1].txt  = _("the full weekday name");
155         time_format[2].txt  = _("the abbreviated month name");
156         time_format[3].txt  = _("the full month name");
157         time_format[4].txt  = _("the preferred date and time for the current locale");
158         time_format[5].txt  = _("the century number (year/100)");
159         time_format[6].txt  = _("the day of the month as a decimal number");
160         time_format[7].txt  = _("the hour as a decimal number using a 24-hour clock");
161         time_format[8].txt  = _("the hour as a decimal number using a 12-hour clock");
162         time_format[9].txt  = _("the day of the year as a decimal number");
163         time_format[10].txt = _("the month as a decimal number");
164         time_format[11].txt = _("the minute as a decimal number");
165         time_format[12].txt = _("either AM or PM");
166         time_format[13].txt = _("the second as a decimal number");
167         time_format[14].txt = _("the day of the week as a decimal number");
168         time_format[15].txt = _("the preferred date for the current locale");
169         time_format[16].txt = _("the last two digits of a year");
170         time_format[17].txt = _("the year as a decimal number");
171         time_format[18].txt = _("the time zone or name or abbreviation");
172
173         if (datefmt_win) return datefmt_win;
174
175         store = gtk_list_store_new(N_DATEFMT_COLUMNS,
176                                    G_TYPE_STRING,
177                                    G_TYPE_STRING,
178                                    -1);
179
180         for (i = 0; i < TIME_FORMAT_ELEMS; i++) {
181                 GtkTreeIter iter;
182
183                 gtk_list_store_append(store, &iter);
184                 gtk_list_store_set(store, &iter,
185                                    DATEFMT_FMT, time_format[i].fmt,
186                                    DATEFMT_TXT, time_format[i].txt,
187                                    -1);
188         }
189
190         datefmt_win = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_summaries");
191         gtk_container_set_border_width(GTK_CONTAINER(datefmt_win), 8);
192         gtk_window_set_title(GTK_WINDOW(datefmt_win), _("Date format"));
193         gtk_window_set_position(GTK_WINDOW(datefmt_win), GTK_WIN_POS_CENTER);
194         gtk_widget_set_size_request(datefmt_win, 440, 280);
195
196         vbox1 = gtk_vbox_new(FALSE, 10);
197         gtk_widget_show(vbox1);
198         gtk_container_add(GTK_CONTAINER(datefmt_win), vbox1);
199
200         scrolledwindow1 = gtk_scrolled_window_new(NULL, NULL);
201         gtk_scrolled_window_set_policy
202                 (GTK_SCROLLED_WINDOW(scrolledwindow1),
203                  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
204         gtk_widget_show(scrolledwindow1);
205         gtk_box_pack_start(GTK_BOX(vbox1), scrolledwindow1, TRUE, TRUE, 0);
206
207         datefmt_list_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
208         g_object_unref(G_OBJECT(store));
209         gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(datefmt_list_view),
210                                      prefs_common.use_stripes_everywhere);
211         gtk_widget_show(datefmt_list_view);
212         gtk_container_add(GTK_CONTAINER(scrolledwindow1), datefmt_list_view);
213
214         renderer = gtk_cell_renderer_text_new();
215         column = gtk_tree_view_column_new_with_attributes
216                         (_("Specifier"), renderer, "text", DATEFMT_FMT,
217                          NULL);
218         gtk_tree_view_append_column(GTK_TREE_VIEW(datefmt_list_view), column);
219         
220         renderer = gtk_cell_renderer_text_new();
221         column = gtk_tree_view_column_new_with_attributes
222                         (_("Description"), renderer, "text", DATEFMT_TXT,
223                          NULL);
224         gtk_tree_view_append_column(GTK_TREE_VIEW(datefmt_list_view), column);
225         
226         /* gtk_cmclist_set_column_width(GTK_CMCLIST(datefmt_clist), 0, 80); */
227         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(datefmt_list_view));
228         gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
229
230         g_signal_connect(G_OBJECT(datefmt_list_view), "row_activated", 
231                          G_CALLBACK(date_format_select_row),
232                          datefmt_win);
233         
234         table = gtk_table_new(2, 2, FALSE);
235         gtk_widget_show(table);
236         gtk_box_pack_start(GTK_BOX(vbox1), table, FALSE, FALSE, 0);
237         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
238         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
239
240         label1 = gtk_label_new(_("Date format"));
241         gtk_widget_show(label1);
242         gtk_table_attach(GTK_TABLE(table), label1, 0, 1, 0, 1,
243                          GTK_FILL, 0, 0, 0);
244         gtk_label_set_justify(GTK_LABEL(label1), GTK_JUSTIFY_LEFT);
245         gtk_misc_set_alignment(GTK_MISC(label1), 0, 0.5);
246
247         datefmt_entry = gtk_entry_new();
248         gtk_entry_set_max_length(GTK_ENTRY(datefmt_entry), 256);
249         gtk_widget_show(datefmt_entry);
250         gtk_table_attach(GTK_TABLE(table), datefmt_entry, 1, 2, 0, 1,
251                          (GTK_EXPAND | GTK_FILL), 0, 0, 0);
252
253         /* we need the "sample" entry box; add it as data so callbacks can
254          * get the entry box */
255         g_object_set_data(G_OBJECT(datefmt_win), "datefmt_sample",
256                           datefmt_entry);
257
258         label2 = gtk_label_new(_("Example"));
259         gtk_widget_show(label2);
260         gtk_table_attach(GTK_TABLE(table), label2, 0, 1, 1, 2,
261                          GTK_FILL, 0, 0, 0);
262         gtk_label_set_justify(GTK_LABEL(label2), GTK_JUSTIFY_LEFT);
263         gtk_misc_set_alignment(GTK_MISC(label2), 0, 0.5);
264
265         label3 = gtk_label_new("");
266         gtk_widget_show(label3);
267         gtk_table_attach(GTK_TABLE(table), label3, 1, 2, 1, 2,
268                          (GTK_EXPAND | GTK_FILL), 0, 0, 0);
269         gtk_label_set_justify(GTK_LABEL(label3), GTK_JUSTIFY_LEFT);
270         gtk_misc_set_alignment(GTK_MISC(label3), 0, 0.5);
271
272         gtkut_stock_button_set_create(&confirm_area, &cancel_btn, GTK_STOCK_CANCEL,
273                                       &ok_btn, GTK_STOCK_OK, NULL, NULL);
274
275         gtk_box_pack_start(GTK_BOX(vbox1), confirm_area, FALSE, FALSE, 0);
276         gtk_widget_show(confirm_area);
277         gtk_widget_grab_default(ok_btn);
278
279         /* set the current format */
280         gtk_entry_set_text(GTK_ENTRY(datefmt_entry), prefs_common.date_format);
281         date_format_entry_on_change(GTK_EDITABLE(datefmt_entry),
282                                     GTK_LABEL(label3));
283
284         g_signal_connect(G_OBJECT(ok_btn), "clicked",
285                          G_CALLBACK(date_format_ok_btn_clicked),
286                          &datefmt_win);
287         g_signal_connect(G_OBJECT(cancel_btn), "clicked",
288                          G_CALLBACK(date_format_cancel_btn_clicked),
289                          &datefmt_win);
290         g_signal_connect(G_OBJECT(datefmt_win), "key_press_event",
291                          G_CALLBACK(date_format_key_pressed),
292                          &datefmt_win);
293         g_signal_connect(G_OBJECT(datefmt_win), "delete_event",
294                          G_CALLBACK(date_format_on_delete),
295                          &datefmt_win);
296         g_signal_connect(G_OBJECT(datefmt_entry), "changed",
297                          G_CALLBACK(date_format_entry_on_change),
298                          label3);
299
300         gtk_window_set_position(GTK_WINDOW(datefmt_win), GTK_WIN_POS_CENTER);
301
302         gtk_widget_show(datefmt_win);
303         manage_window_set_transient(GTK_WINDOW(datefmt_win));
304         gtk_window_set_modal(GTK_WINDOW(datefmt_win), TRUE);
305
306         gtk_widget_grab_focus(ok_btn);
307
308         return datefmt_win;
309 }
310
311 static void prefs_summaries_create_widget(PrefsPage *_page, GtkWindow *window, 
312                                   gpointer data)
313 {
314         SummariesPage *prefs_summaries = (SummariesPage *) _page;
315         
316         GtkWidget *vbox1;
317         GtkWidget *checkbtn_transhdr;
318         GtkWidget *hbox0;
319         GtkWidget *optmenu_folder_unread;
320         GtkWidget *hbox1;
321         GtkWidget *label_ng_abbrev;
322         GtkWidget *spinbtn_ng_abbrev_len;
323         GtkAdjustment *spinbtn_ng_abbrev_len_adj;
324         GtkWidget *vbox2;
325         GtkWidget *vbox3;
326         GtkWidget *checkbtn_useaddrbook;
327         GtkWidget *checkbtn_show_tooltips;
328         GtkWidget *checkbtn_threadsubj;
329         GtkWidget *label_datefmt;
330         GtkWidget *button_datefmt;
331         GtkWidget *entry_datefmt;
332         GtkWidget *hbox_dispitem;
333         GtkWidget *button_dispitem;
334         GtkWidget *hbox2;
335         GtkWidget *checkbtn_reopen_last_folder;
336         GtkWidget *optmenu_always_show_msg;
337         GtkWidget *spinbtn_mark_as_read_delay;
338         GtkAdjustment *spinbtn_mark_as_read_delay_adj;
339         GtkWidget *checkbtn_immedexec;
340         GtkWidget *checkbtn_ask_mark_all_read;
341         GtkWidget *label, *label_fill;
342         GtkListStore *menu;
343         GtkTreeIter iter;
344         GtkWidget *optmenu_nextunreadmsgdialog;
345         GtkWidget *folderview_frame;
346         GtkWidget *summaryview_frame;
347         GtkWidget *button_edit_actions;
348         GtkWidget *radio_mark_as_read_on_select;
349         GtkWidget *radio_mark_as_read_on_new_win;
350         GtkWidget *optmenu_sort_key;
351         GtkWidget *optmenu_sort_type;
352
353         vbox1 = gtk_vbox_new (FALSE, VSPACING);
354         gtk_widget_show (vbox1);
355         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
356         
357         vbox2 = gtkut_get_options_frame(vbox1, &folderview_frame, _("Folder list"));
358
359         hbox0 = gtk_hbox_new (FALSE, 8);
360         gtk_widget_show (hbox0);
361         gtk_box_pack_start(GTK_BOX (vbox2), hbox0, FALSE, FALSE, 0);
362
363         label = gtk_label_new (_("Display message count next to folder name"));
364         gtk_widget_show (label);
365         gtk_box_pack_start(GTK_BOX(hbox0), label, FALSE, FALSE, 0);
366
367         optmenu_folder_unread = gtkut_sc_combobox_create(NULL, FALSE);
368         menu = GTK_LIST_STORE(gtk_combo_box_get_model(
369                                 GTK_COMBO_BOX(optmenu_folder_unread)));
370         gtk_widget_show (optmenu_folder_unread);
371         
372         COMBOBOX_ADD (menu, _("No"), 0);
373         COMBOBOX_ADD (menu, _("Unread messages"), 1);
374         COMBOBOX_ADD (menu, _("Unread and Total messages"), 2);
375
376         gtk_box_pack_start(GTK_BOX(hbox0), optmenu_folder_unread, FALSE, FALSE, 0);
377
378         hbox1 = gtk_hbox_new (FALSE, 8);
379         gtk_widget_show (hbox1);
380         gtk_box_pack_start(GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
381
382         PACK_CHECK_BUTTON
383                 (vbox2, checkbtn_reopen_last_folder,
384                  _("Open last opened folder at start-up"));
385
386         label_ng_abbrev = gtk_label_new
387                 (_("Abbreviate newsgroup names longer than"));
388         gtk_widget_show (label_ng_abbrev);
389         gtk_box_pack_start (GTK_BOX (hbox1), label_ng_abbrev, FALSE, FALSE, 0);
390
391         spinbtn_ng_abbrev_len_adj = GTK_ADJUSTMENT(gtk_adjustment_new (16, 0, 999, 1, 10, 0));
392         spinbtn_ng_abbrev_len = gtk_spin_button_new
393                 (GTK_ADJUSTMENT (spinbtn_ng_abbrev_len_adj), 1, 0);
394         gtk_widget_show (spinbtn_ng_abbrev_len);
395         gtk_box_pack_start (GTK_BOX (hbox1), spinbtn_ng_abbrev_len,
396                             FALSE, FALSE, 0);
397         gtk_widget_set_size_request (spinbtn_ng_abbrev_len, 56, -1);
398         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_ng_abbrev_len),
399                                      TRUE);
400
401         label_ng_abbrev = gtk_label_new (_("letters"));
402         gtk_widget_show (label_ng_abbrev);
403         gtk_box_pack_start (GTK_BOX (hbox1), label_ng_abbrev, FALSE, FALSE, 0);
404
405         hbox_dispitem = gtk_hbox_new (FALSE, 8);
406         gtk_widget_show (hbox_dispitem);
407         gtk_box_pack_start(GTK_BOX(vbox2), hbox_dispitem, FALSE, TRUE, 0);
408
409         label = gtk_label_new(_("Displayed columns"));
410         gtk_widget_show(label);
411         gtk_box_pack_start(GTK_BOX(hbox_dispitem), label, FALSE, FALSE, 0);
412         button_dispitem = gtk_button_new_from_stock(GTK_STOCK_EDIT);
413         gtk_widget_show (button_dispitem);
414         gtk_box_pack_start (GTK_BOX (hbox_dispitem), button_dispitem, FALSE, FALSE, 0);
415         g_signal_connect (G_OBJECT (button_dispitem), "clicked",
416                           G_CALLBACK (prefs_folder_column_open),
417                           NULL);
418
419         vbox2 = gtkut_get_options_frame(vbox1, &summaryview_frame, _("Message list"));
420
421         hbox1 = gtk_hbox_new(FALSE, 10);
422         gtk_widget_show(hbox1);
423         gtk_box_pack_start(GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
424
425         label = gtk_label_new(_("Sort new folders by"));
426         gtk_widget_show(label);
427         gtk_box_pack_start(GTK_BOX(hbox1), label, FALSE, FALSE, 0);
428
429         optmenu_sort_key = gtkut_sc_combobox_create(NULL, FALSE);
430         menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu_sort_key)));
431         gtk_widget_show(optmenu_sort_key);
432
433         COMBOBOX_ADD(menu, _("Number"), SORT_BY_NUMBER);
434         COMBOBOX_ADD(menu, _("Size"), SORT_BY_SIZE);
435         COMBOBOX_ADD(menu, _("Date"), SORT_BY_DATE);
436         COMBOBOX_ADD(menu, _("Thread date"), SORT_BY_THREAD_DATE);
437         COMBOBOX_ADD(menu, _("From"), SORT_BY_FROM);
438         COMBOBOX_ADD(menu, _("To"), SORT_BY_TO);
439         COMBOBOX_ADD(menu, _("Subject"), SORT_BY_SUBJECT);
440         COMBOBOX_ADD(menu, _("Color label"), SORT_BY_LABEL);
441         COMBOBOX_ADD(menu, _("Tag"), SORT_BY_TAGS);
442         COMBOBOX_ADD(menu, _("Mark"), SORT_BY_MARK);
443         COMBOBOX_ADD(menu, _("Status"), SORT_BY_STATUS);
444         COMBOBOX_ADD(menu, _("Attachment"), SORT_BY_MIME);
445         COMBOBOX_ADD(menu, _("Score"), SORT_BY_SCORE);
446         COMBOBOX_ADD(menu, _("Locked"), SORT_BY_LOCKED);
447         COMBOBOX_ADD(menu, _("Don't sort"), SORT_BY_NONE);
448
449         gtk_box_pack_start(GTK_BOX(hbox1), optmenu_sort_key, FALSE, FALSE, 0);
450
451         optmenu_sort_type = gtkut_sc_combobox_create(NULL, FALSE);
452         menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu_sort_type)));
453         gtk_widget_show(optmenu_sort_type);
454
455         COMBOBOX_ADD(menu, _("Ascending"), SORT_ASCENDING);
456         COMBOBOX_ADD(menu, _("Descending"), SORT_DESCENDING);
457
458         gtk_box_pack_start(GTK_BOX(hbox1), optmenu_sort_type, FALSE, FALSE, 0);
459
460         hbox1 = gtk_hbox_new (FALSE, 10);
461         gtk_widget_show (hbox1);
462         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, TRUE, 0);
463
464         button_edit_actions = gtk_button_new_with_label(_("Set default selection when entering a folder"));
465         gtk_widget_show (button_edit_actions);
466         gtk_box_pack_start (GTK_BOX (hbox1), button_edit_actions,
467                           FALSE, TRUE, 0);
468         g_signal_connect (G_OBJECT (button_edit_actions), "clicked",
469                           G_CALLBACK (prefs_summary_open_open),
470                           NULL);
471
472         /* Next Unread Message Dialog */
473         hbox1 = gtk_hbox_new (FALSE, 10);
474         gtk_widget_show (hbox1);
475         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);   
476
477         label = gtk_label_new (_("Show \"no unread (or new) message\" dialog"));
478         gtk_widget_show (label);
479         gtk_box_pack_start(GTK_BOX(hbox1), label, FALSE, FALSE, 0);
480         
481         optmenu_nextunreadmsgdialog = gtkut_sc_combobox_create(NULL, FALSE);
482         menu = GTK_LIST_STORE(gtk_combo_box_get_model(
483                                 GTK_COMBO_BOX(optmenu_nextunreadmsgdialog)));
484         gtk_widget_show (optmenu_nextunreadmsgdialog);
485
486         COMBOBOX_ADD (menu, _("Always"), NEXTUNREADMSGDIALOG_ALWAYS);
487         COMBOBOX_ADD (menu, _("Assume 'Yes'"), NEXTUNREADMSGDIALOG_ASSUME_YES);
488         COMBOBOX_ADD (menu, _("Assume 'No'"), NEXTUNREADMSGDIALOG_ASSUME_NO);
489
490         gtk_box_pack_start(GTK_BOX(hbox1), optmenu_nextunreadmsgdialog, FALSE, FALSE, 0);
491
492         /* Open message on select policy */
493         hbox1 = gtk_hbox_new (FALSE, 10);
494         gtk_widget_show (hbox1);
495         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);   
496         label = gtk_label_new (_("Open message when selected"));
497         gtk_widget_show (label);
498         gtk_box_pack_start(GTK_BOX(hbox1), label, FALSE, FALSE, 0);
499
500         optmenu_always_show_msg = gtkut_sc_combobox_create(NULL, FALSE);
501         menu = GTK_LIST_STORE(gtk_combo_box_get_model(
502                                 GTK_COMBO_BOX(optmenu_always_show_msg)));
503         gtk_widget_show (optmenu_always_show_msg);
504         COMBOBOX_ADD (menu, _("No"), OPENMSG_NO);
505         COMBOBOX_ADD (menu, _("Yes"), OPENMSG_YES);
506         COMBOBOX_ADD (menu, _("Only when message view is visible"),
507                         OPENMSG_WHEN_VIEW_VISIBLE);
508         gtk_box_pack_start(GTK_BOX(hbox1), optmenu_always_show_msg, FALSE, FALSE, 0);
509
510         PACK_CHECK_BUTTON
511                 (vbox2, checkbtn_threadsubj,
512                  _("Thread using subject in addition to standard headers"));
513
514         PACK_CHECK_BUTTON
515                 (vbox2, checkbtn_immedexec,
516                  _("Execute immediately when moving or deleting messages"));
517         CLAWS_SET_TIP(checkbtn_immedexec,
518                              _("Defers moving, copying and deleting of messages"
519                                " until you choose 'Tools/Execute'"));
520
521         vbox3 = gtkut_get_options_frame(vbox2, NULL, _("Mark message as read"));
522
523         radio_mark_as_read_on_select = gtk_radio_button_new_with_label(NULL,
524                         _("when selected, after"));
525
526         hbox1 = gtk_hbox_new (FALSE, 8);
527         gtk_box_pack_start (GTK_BOX (hbox1), radio_mark_as_read_on_select, FALSE, FALSE, 0);
528
529         spinbtn_mark_as_read_delay_adj = GTK_ADJUSTMENT(gtk_adjustment_new (0, 0, 60, 1, 10, 0));
530         spinbtn_mark_as_read_delay = gtk_spin_button_new
531                         (GTK_ADJUSTMENT (spinbtn_mark_as_read_delay_adj), 1, 0);
532         gtk_box_pack_start (GTK_BOX (hbox1), spinbtn_mark_as_read_delay,
533                             FALSE, FALSE, 0);
534         gtk_widget_set_size_request (spinbtn_mark_as_read_delay, 56, -1);
535         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_mark_as_read_delay),
536                                      TRUE);
537         gtk_box_pack_start (GTK_BOX (hbox1), gtk_label_new
538                         (_("seconds")), FALSE, FALSE, 0);
539
540         gtk_box_pack_start (GTK_BOX (vbox3), hbox1, FALSE, FALSE, 0);
541
542         radio_mark_as_read_on_new_win = gtk_radio_button_new_with_label_from_widget(
543                         GTK_RADIO_BUTTON(radio_mark_as_read_on_select),
544                         _("only when opened in a new window, or replied to"));
545         gtk_box_pack_start (GTK_BOX (vbox3), radio_mark_as_read_on_new_win,
546                         FALSE, FALSE, 0);
547         gtk_widget_show_all(vbox3);
548                                                                                              
549         PACK_CHECK_BUTTON
550                 (vbox2, checkbtn_useaddrbook,
551                  _("Display sender using address book"));
552                  
553         PACK_CHECK_BUTTON
554                 (vbox2, checkbtn_show_tooltips,
555                  _("Show tooltips"));
556
557         hbox2 = gtk_hbox_new (FALSE, 8);
558         gtk_widget_show (hbox2);
559         gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, TRUE, 0);
560
561         label_datefmt = gtk_label_new (_("Date format"));
562         gtk_widget_show (label_datefmt);
563         gtk_box_pack_start (GTK_BOX (hbox2), label_datefmt, FALSE, FALSE, 0);
564
565         entry_datefmt = gtk_entry_new ();
566         gtk_widget_show (entry_datefmt);
567         gtk_widget_set_size_request(entry_datefmt, 200, -1);
568         gtk_box_pack_start (GTK_BOX (hbox2), entry_datefmt, FALSE, FALSE, 0);
569
570         button_datefmt = gtk_button_new_from_stock(GTK_STOCK_INFO);
571
572         gtk_widget_show (button_datefmt);
573         gtk_box_pack_start (GTK_BOX (hbox2), button_datefmt, FALSE, FALSE, 0);
574         g_signal_connect (G_OBJECT (button_datefmt), "clicked",
575                           G_CALLBACK (date_format_create), NULL);
576         
577         label_fill = gtk_label_new(" ");
578         gtk_box_pack_start(GTK_BOX(hbox2), label_fill, TRUE, FALSE, 0);
579         
580         CLAWS_SET_TIP(button_datefmt,
581                              _("Date format help"));
582                              
583         hbox_dispitem = gtk_hbox_new (FALSE, 8);
584         gtk_widget_show (hbox_dispitem);
585         gtk_box_pack_start(GTK_BOX(vbox2), hbox_dispitem, FALSE, TRUE, 0);
586         
587         label = gtk_label_new(_("Displayed columns"));
588         gtk_widget_show(label);
589         gtk_box_pack_start(GTK_BOX(hbox_dispitem), label, FALSE, FALSE, 0);
590         button_dispitem = gtk_button_new_from_stock(GTK_STOCK_EDIT);
591         gtk_widget_show (button_dispitem);
592         gtk_box_pack_start (GTK_BOX (hbox_dispitem), button_dispitem, FALSE, FALSE, 0);
593         g_signal_connect (G_OBJECT (button_dispitem), "clicked",
594                           G_CALLBACK (prefs_summary_column_open),
595                           NULL);
596
597         PACK_CHECK_BUTTON
598                 (vbox1, checkbtn_ask_mark_all_read,
599                  _("Confirm before marking all messages in a folder as read"));
600         PACK_CHECK_BUTTON
601                 (vbox1, checkbtn_transhdr,
602                  _("Translate header names"));
603         CLAWS_SET_TIP(checkbtn_transhdr,
604                              _("The display of standard headers (such as 'From:', 'Subject:') "
605                              "will be translated into your language."));
606         
607         hbox2 = gtk_hbox_new (FALSE, 8);
608         gtk_widget_show (hbox2);
609         gtk_box_pack_start (GTK_BOX (vbox1), hbox2, FALSE, FALSE, 0);
610
611         g_signal_connect(G_OBJECT(radio_mark_as_read_on_select), "toggled",
612                          G_CALLBACK(mark_as_read_toggled),
613                          spinbtn_mark_as_read_delay);
614
615         prefs_summaries->window                 = GTK_WIDGET(window);
616         
617         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_transhdr),
618                         prefs_common.trans_hdr);
619         combobox_select_by_data(GTK_COMBO_BOX(optmenu_folder_unread),
620                         prefs_common.display_folder_unread);
621         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_useaddrbook),
622                         prefs_common.use_addr_book);
623         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_show_tooltips),
624                         prefs_common.show_tooltips);
625         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_threadsubj),
626                         prefs_common.thread_by_subject);
627         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_ng_abbrev_len),
628                         prefs_common.ng_abbrev_len);
629         gtk_entry_set_text(GTK_ENTRY(entry_datefmt), 
630                         prefs_common.date_format?prefs_common.date_format:"");  
631
632         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_reopen_last_folder),
633                         prefs_common.goto_last_folder_on_startup);
634         combobox_select_by_data(GTK_COMBO_BOX(optmenu_always_show_msg),
635                         prefs_common.always_show_msg);
636         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_mark_as_read_on_new_win),
637                         prefs_common.mark_as_read_on_new_window);
638         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_mark_as_read_delay),
639                         prefs_common.mark_as_read_delay);
640         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_immedexec),
641                         prefs_common.immediate_exec);
642         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_ask_mark_all_read),
643                         prefs_common.ask_mark_all_read);
644
645         combobox_select_by_data(GTK_COMBO_BOX(optmenu_sort_key),
646                         prefs_common.default_sort_key);
647         combobox_select_by_data(GTK_COMBO_BOX(optmenu_sort_type),
648                         prefs_common.default_sort_type);
649
650         combobox_select_by_data(GTK_COMBO_BOX(optmenu_nextunreadmsgdialog),
651                         prefs_common.next_unread_msg_dialog);
652
653         prefs_summaries->checkbtn_transhdr = checkbtn_transhdr;
654         prefs_summaries->optmenu_folder_unread = optmenu_folder_unread;
655         prefs_summaries->spinbtn_ng_abbrev_len = spinbtn_ng_abbrev_len;
656         prefs_summaries->checkbtn_useaddrbook = checkbtn_useaddrbook;
657         prefs_summaries->checkbtn_show_tooltips = checkbtn_show_tooltips;
658         prefs_summaries->checkbtn_threadsubj = checkbtn_threadsubj;
659         prefs_summaries->entry_datefmt = entry_datefmt;
660
661         prefs_summaries->checkbtn_reopen_last_folder = checkbtn_reopen_last_folder;
662         prefs_summaries->optmenu_always_show_msg = optmenu_always_show_msg;
663         prefs_summaries->checkbtn_mark_as_read_on_newwin = radio_mark_as_read_on_new_win;
664         prefs_summaries->spinbtn_mark_as_read_delay = spinbtn_mark_as_read_delay;
665         prefs_summaries->checkbtn_immedexec = checkbtn_immedexec;
666         prefs_summaries->checkbtn_ask_mark_all_read = checkbtn_ask_mark_all_read;
667         prefs_summaries->optmenu_sort_key = optmenu_sort_key;
668         prefs_summaries->optmenu_sort_type = optmenu_sort_type;
669         prefs_summaries->optmenu_nextunreadmsgdialog = optmenu_nextunreadmsgdialog;
670
671         prefs_summaries->page.widget = vbox1;
672 }
673
674 static void prefs_summaries_save(PrefsPage *_page)
675 {
676         SummariesPage *page = (SummariesPage *) _page;
677
678         prefs_common.trans_hdr = gtk_toggle_button_get_active(
679                         GTK_TOGGLE_BUTTON(page->checkbtn_transhdr));
680
681
682         prefs_common.display_folder_unread = combobox_get_active_data(
683                         GTK_COMBO_BOX(page->optmenu_folder_unread));
684
685         prefs_common.use_addr_book = gtk_toggle_button_get_active(
686                         GTK_TOGGLE_BUTTON(page->checkbtn_useaddrbook));
687         prefs_common.show_tooltips = gtk_toggle_button_get_active(
688                         GTK_TOGGLE_BUTTON(page->checkbtn_show_tooltips));
689         prefs_common.thread_by_subject = gtk_toggle_button_get_active(
690                         GTK_TOGGLE_BUTTON(page->checkbtn_threadsubj));
691         prefs_common.ng_abbrev_len = gtk_spin_button_get_value_as_int(
692                         GTK_SPIN_BUTTON(page->spinbtn_ng_abbrev_len));
693         
694         g_free(prefs_common.date_format); 
695         prefs_common.date_format = gtk_editable_get_chars(
696                         GTK_EDITABLE(page->entry_datefmt), 0, -1);      
697
698         prefs_common.goto_last_folder_on_startup = gtk_toggle_button_get_active(
699                 GTK_TOGGLE_BUTTON(page->checkbtn_reopen_last_folder));
700         prefs_common.always_show_msg = combobox_get_active_data(
701                 GTK_COMBO_BOX(page->optmenu_always_show_msg));
702         prefs_common.mark_as_read_on_new_window = gtk_toggle_button_get_active(
703                 GTK_TOGGLE_BUTTON(page->checkbtn_mark_as_read_on_newwin));
704         prefs_common.immediate_exec = gtk_toggle_button_get_active(
705                 GTK_TOGGLE_BUTTON(page->checkbtn_immedexec));
706         prefs_common.ask_mark_all_read = gtk_toggle_button_get_active(
707                 GTK_TOGGLE_BUTTON(page->checkbtn_ask_mark_all_read));
708         prefs_common.mark_as_read_delay = gtk_spin_button_get_value_as_int(
709                         GTK_SPIN_BUTTON(page->spinbtn_mark_as_read_delay));
710
711         prefs_common.default_sort_key = combobox_get_active_data(
712                         GTK_COMBO_BOX(page->optmenu_sort_key));
713         prefs_common.default_sort_type = combobox_get_active_data(
714                         GTK_COMBO_BOX(page->optmenu_sort_type));
715         prefs_common.next_unread_msg_dialog = combobox_get_active_data(
716                         GTK_COMBO_BOX(page->optmenu_nextunreadmsgdialog));
717         main_window_reflect_prefs_all();
718 }
719
720 static void prefs_summaries_destroy_widget(PrefsPage *_page)
721 {
722 }
723
724 SummariesPage *prefs_summaries;
725
726 void prefs_summaries_init(void)
727 {
728         SummariesPage *page;
729         static gchar *path[3];
730
731         path[0] = _("Display");
732         path[1] = _("Summaries");
733         path[2] = NULL;
734
735         page = g_new0(SummariesPage, 1);
736         page->page.path = path;
737         page->page.create_widget = prefs_summaries_create_widget;
738         page->page.destroy_widget = prefs_summaries_destroy_widget;
739         page->page.save_page = prefs_summaries_save;
740         page->page.weight = 140.0;
741         prefs_gtk_register_page((PrefsPage *) page);
742         prefs_summaries = page;
743 }
744
745 void prefs_summaries_done(void)
746 {
747         prefs_gtk_unregister_page((PrefsPage *) prefs_summaries);
748         g_free(prefs_summaries);
749 }
750
751 static void date_format_ok_btn_clicked(GtkButton *button, GtkWidget **widget)
752 {
753         GtkWidget *datefmt_sample = NULL;
754         gchar *text;
755
756         cm_return_if_fail(widget != NULL);
757         cm_return_if_fail(*widget != NULL);
758         cm_return_if_fail(prefs_summaries->entry_datefmt != NULL);
759
760         datefmt_sample = GTK_WIDGET(g_object_get_data
761                                     (G_OBJECT(*widget), "datefmt_sample"));
762         cm_return_if_fail(datefmt_sample != NULL);
763
764         text = gtk_editable_get_chars(GTK_EDITABLE(datefmt_sample), 0, -1);
765         g_free(prefs_common.date_format);
766         prefs_common.date_format = text;
767         gtk_entry_set_text(GTK_ENTRY(prefs_summaries->entry_datefmt), text);
768
769         gtk_widget_destroy(*widget);
770         *widget = NULL;
771 }
772
773 static void date_format_cancel_btn_clicked(GtkButton *button,
774                                            GtkWidget **widget)
775 {
776         cm_return_if_fail(widget != NULL);
777         cm_return_if_fail(*widget != NULL);
778
779         gtk_widget_destroy(*widget);
780         *widget = NULL;
781 }
782
783 static gboolean date_format_key_pressed(GtkWidget *keywidget, GdkEventKey *event,
784                                         GtkWidget **widget)
785 {
786         if (event && event->keyval == GDK_KEY_Escape)
787                 date_format_cancel_btn_clicked(NULL, widget);
788         return FALSE;
789 }
790
791 static gboolean date_format_on_delete(GtkWidget *dialogwidget,
792                                       GdkEventAny *event, GtkWidget **widget)
793 {
794         cm_return_val_if_fail(widget != NULL, FALSE);
795         cm_return_val_if_fail(*widget != NULL, FALSE);
796
797         *widget = NULL;
798         return FALSE;
799 }
800
801 static void date_format_entry_on_change(GtkEditable *editable,
802                                         GtkLabel *example)
803 {
804         time_t cur_time;
805         struct tm *cal_time;
806         gchar buffer[100];
807         gchar *text;
808         struct tm lt;
809
810         cur_time = time(NULL);
811         cal_time = localtime_r(&cur_time, &lt);
812         buffer[0] = 0;
813         text = gtk_editable_get_chars(editable, 0, -1);
814         if (text)
815                 fast_strftime(buffer, sizeof buffer, text, cal_time); 
816
817         gtk_label_set_text(example, buffer);
818
819         g_free(text);
820 }
821
822 static void date_format_select_row(GtkTreeView *list_view,
823                                    GtkTreePath *path,
824                                    GtkTreeViewColumn *column,
825                                    GtkWidget *date_format)
826 {
827         gint cur_pos;
828         gchar *format;
829         const gchar *old_format;
830         gchar *new_format;
831         GtkWidget *datefmt_sample;
832         GtkTreeIter iter;
833         GtkTreeModel *model;
834         
835         cm_return_if_fail(date_format != NULL);
836
837         /* only on double click */
838         datefmt_sample = GTK_WIDGET(g_object_get_data(G_OBJECT(date_format), 
839                                                       "datefmt_sample"));
840
841         cm_return_if_fail(datefmt_sample != NULL);
842
843         model = gtk_tree_view_get_model(list_view);
844
845         /* get format from list */
846         if (!gtk_tree_model_get_iter(model, &iter, path))
847                 return;
848
849         gtk_tree_model_get(model, &iter, DATEFMT_FMT, &format, -1);             
850         
851         cur_pos = gtk_editable_get_position(GTK_EDITABLE(datefmt_sample));
852         old_format = gtk_entry_get_text(GTK_ENTRY(datefmt_sample));
853
854         /* insert the format into the text entry */
855         new_format = g_malloc(strlen(old_format) + 3);
856
857         strncpy(new_format, old_format, cur_pos);
858         new_format[cur_pos] = '\0';
859         strcat(new_format, format);
860         strcat(new_format, &old_format[cur_pos]);
861
862         gtk_entry_set_text(GTK_ENTRY(datefmt_sample), new_format);
863         gtk_editable_set_position(GTK_EDITABLE(datefmt_sample), cur_pos + 2);
864
865         g_free(new_format);
866 }
867
868 static void mark_as_read_toggled(GtkToggleButton *button, GtkWidget *spinbtn)
869 {
870        gtk_widget_set_sensitive(spinbtn,
871                gtk_toggle_button_get_active(button));
872 }
873