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