2011-10-22 [colin] 3.7.10cvs41
[claws.git] / src / prefs_summaries.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2005-2011 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 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         GtkAdjustment *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         GtkAdjustment *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
349         vbox1 = gtk_vbox_new (FALSE, VSPACING);
350         gtk_widget_show (vbox1);
351         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
352         
353         vbox2 = gtkut_get_options_frame(vbox1, &folderview_frame, _("Folder list"));
354
355         hbox0 = gtk_hbox_new (FALSE, 8);
356         gtk_widget_show (hbox0);
357         gtk_box_pack_start(GTK_BOX (vbox2), hbox0, FALSE, FALSE, 0);
358
359         label = gtk_label_new (_("Display message number next to folder name"));
360         gtk_widget_show (label);
361         gtk_box_pack_start(GTK_BOX(hbox0), label, FALSE, FALSE, 0);
362
363         optmenu_folder_unread = gtkut_sc_combobox_create(NULL, FALSE);
364         menu = GTK_LIST_STORE(gtk_combo_box_get_model(
365                                 GTK_COMBO_BOX(optmenu_folder_unread)));
366         gtk_widget_show (optmenu_folder_unread);
367         
368         COMBOBOX_ADD (menu, _("No"), 0);
369         COMBOBOX_ADD (menu, _("Unread messages"), 1);
370         COMBOBOX_ADD (menu, _("Unread and Total messages"), 2);
371
372         gtk_box_pack_start(GTK_BOX(hbox0), optmenu_folder_unread, FALSE, FALSE, 0);
373
374         hbox1 = gtk_hbox_new (FALSE, 8);
375         gtk_widget_show (hbox1);
376         gtk_box_pack_start(GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
377
378         PACK_CHECK_BUTTON
379                 (vbox2, checkbtn_reopen_last_folder,
380                  _("Open last opened folder at start-up"));
381
382         label_ng_abbrev = gtk_label_new
383                 (_("Abbreviate newsgroup names longer than"));
384         gtk_widget_show (label_ng_abbrev);
385         gtk_box_pack_start (GTK_BOX (hbox1), label_ng_abbrev, FALSE, FALSE, 0);
386
387         spinbtn_ng_abbrev_len_adj = gtk_adjustment_new (16, 0, 999, 1, 10, 0);
388         spinbtn_ng_abbrev_len = gtk_spin_button_new
389                 (GTK_ADJUSTMENT (spinbtn_ng_abbrev_len_adj), 1, 0);
390         gtk_widget_show (spinbtn_ng_abbrev_len);
391         gtk_box_pack_start (GTK_BOX (hbox1), spinbtn_ng_abbrev_len,
392                             FALSE, FALSE, 0);
393         gtk_widget_set_size_request (spinbtn_ng_abbrev_len, 56, -1);
394         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_ng_abbrev_len),
395                                      TRUE);
396
397         label_ng_abbrev = gtk_label_new (_("letters"));
398         gtk_widget_show (label_ng_abbrev);
399         gtk_box_pack_start (GTK_BOX (hbox1), label_ng_abbrev, FALSE, FALSE, 0);
400
401         hbox_dispitem = gtk_hbox_new (FALSE, 8);
402         gtk_widget_show (hbox_dispitem);
403         gtk_box_pack_start(GTK_BOX(vbox2), hbox_dispitem, FALSE, TRUE, 0);
404
405         label = gtk_label_new(_("Displayed columns"));
406         gtk_widget_show(label);
407         gtk_box_pack_start(GTK_BOX(hbox_dispitem), label, FALSE, FALSE, 0);
408         button_dispitem = gtk_button_new_from_stock(GTK_STOCK_EDIT);
409         gtk_widget_show (button_dispitem);
410         gtk_box_pack_start (GTK_BOX (hbox_dispitem), button_dispitem, FALSE, FALSE, 0);
411         g_signal_connect (G_OBJECT (button_dispitem), "clicked",
412                           G_CALLBACK (prefs_folder_column_open),
413                           NULL);
414
415         vbox2 = gtkut_get_options_frame(vbox1, &summaryview_frame, _("Message list"));
416
417         hbox1 = gtk_hbox_new (FALSE, 10);
418         gtk_widget_show (hbox1);
419         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, TRUE, 0);
420
421         button_edit_actions = gtk_button_new_with_label(_("Set default selection when entering a folder"));
422         gtk_widget_show (button_edit_actions);
423         gtk_box_pack_start (GTK_BOX (hbox1), button_edit_actions,
424                           FALSE, TRUE, 0);
425         g_signal_connect (G_OBJECT (button_edit_actions), "clicked",
426                           G_CALLBACK (prefs_summary_open_open),
427                           NULL);
428
429         /* Next Unread Message Dialog */
430         hbox1 = gtk_hbox_new (FALSE, 10);
431         gtk_widget_show (hbox1);
432         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);   
433
434         label = gtk_label_new (_("Show \"no unread (or new) message\" dialog"));
435         gtk_widget_show (label);
436         gtk_box_pack_start(GTK_BOX(hbox1), label, FALSE, FALSE, 0);
437         
438         optmenu_nextunreadmsgdialog = gtkut_sc_combobox_create(NULL, FALSE);
439         menu = GTK_LIST_STORE(gtk_combo_box_get_model(
440                                 GTK_COMBO_BOX(optmenu_nextunreadmsgdialog)));
441         gtk_widget_show (optmenu_nextunreadmsgdialog);
442
443         COMBOBOX_ADD (menu, _("Always"), NEXTUNREADMSGDIALOG_ALWAYS);
444         COMBOBOX_ADD (menu, _("Assume 'Yes'"), NEXTUNREADMSGDIALOG_ASSUME_YES);
445         COMBOBOX_ADD (menu, _("Assume 'No'"), NEXTUNREADMSGDIALOG_ASSUME_NO);
446
447         gtk_box_pack_start(GTK_BOX(hbox1), optmenu_nextunreadmsgdialog, FALSE, FALSE, 0);
448
449         /* Open message on select policy */
450         hbox1 = gtk_hbox_new (FALSE, 10);
451         gtk_widget_show (hbox1);
452         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);   
453         label = gtk_label_new (_("Open message when selected"));
454         gtk_widget_show (label);
455         gtk_box_pack_start(GTK_BOX(hbox1), label, FALSE, FALSE, 0);
456
457         optmenu_always_show_msg = gtkut_sc_combobox_create(NULL, FALSE);
458         menu = GTK_LIST_STORE(gtk_combo_box_get_model(
459                                 GTK_COMBO_BOX(optmenu_always_show_msg)));
460         gtk_widget_show (optmenu_always_show_msg);
461         COMBOBOX_ADD (menu, _("Never"), OPENMSG_REQUEST_ONLY);
462         COMBOBOX_ADD (menu, _("Always"), OPENMSG_ALWAYS);
463         COMBOBOX_ADD (menu, _("When message view is visible"),
464                         OPENMSG_WHEN_VIEW_VISIBLE);
465         gtk_box_pack_start(GTK_BOX(hbox1), optmenu_always_show_msg, FALSE, FALSE, 0);
466
467         PACK_CHECK_BUTTON
468                 (vbox2, checkbtn_threadsubj,
469                  _("Thread using subject in addition to standard headers"));
470
471         PACK_CHECK_BUTTON
472                 (vbox2, checkbtn_immedexec,
473                  _("Execute immediately when moving or deleting messages"));
474         CLAWS_SET_TIP(checkbtn_immedexec,
475                              _("Defers moving, copying and deleting of messages"
476                                " until you choose 'Tools/Execute'"));
477
478         vbox3 = gtkut_get_options_frame(vbox2, NULL, _("Mark message as read"));
479
480         radio_mark_as_read_on_select = gtk_radio_button_new_with_label(NULL,
481                         _("when selected, after"));
482
483         hbox1 = gtk_hbox_new (FALSE, 8);
484         gtk_box_pack_start (GTK_BOX (hbox1), radio_mark_as_read_on_select, FALSE, FALSE, 0);
485
486         spinbtn_mark_as_read_delay_adj = gtk_adjustment_new (0, 0, 60, 1, 10, 0);
487         spinbtn_mark_as_read_delay = gtk_spin_button_new
488                         (GTK_ADJUSTMENT (spinbtn_mark_as_read_delay_adj), 1, 0);
489         gtk_box_pack_start (GTK_BOX (hbox1), spinbtn_mark_as_read_delay,
490                             FALSE, FALSE, 0);
491         gtk_widget_set_size_request (spinbtn_mark_as_read_delay, 56, -1);
492         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_mark_as_read_delay),
493                                      TRUE);
494         gtk_box_pack_start (GTK_BOX (hbox1), gtk_label_new
495                         (_("seconds")), FALSE, FALSE, 0);
496
497         gtk_box_pack_start (GTK_BOX (vbox3), hbox1, FALSE, FALSE, 0);
498
499         radio_mark_as_read_on_new_win = gtk_radio_button_new_with_label_from_widget(
500                         GTK_RADIO_BUTTON(radio_mark_as_read_on_select),
501                         _("only when opened in a new window, or replied to"));
502         gtk_box_pack_start (GTK_BOX (vbox3), radio_mark_as_read_on_new_win,
503                         FALSE, FALSE, 0);
504         gtk_widget_show_all(vbox3);
505                                                                                              
506         PACK_CHECK_BUTTON
507                 (vbox2, checkbtn_useaddrbook,
508                  _("Display sender using address book"));
509                  
510         PACK_CHECK_BUTTON
511                 (vbox2, checkbtn_show_tooltips,
512                  _("Show tooltips"));
513
514 #if !GTK_CHECK_VERSION(2,12,0) && !GENERIC_UMPC
515         gtk_widget_hide(checkbtn_show_tooltips);
516 #endif
517         hbox2 = gtk_hbox_new (FALSE, 8);
518         gtk_widget_show (hbox2);
519         gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, TRUE, 0);
520
521         label_datefmt = gtk_label_new (_("Date format"));
522         gtk_widget_show (label_datefmt);
523         gtk_box_pack_start (GTK_BOX (hbox2), label_datefmt, FALSE, FALSE, 0);
524
525         entry_datefmt = gtk_entry_new ();
526         gtk_widget_show (entry_datefmt);
527         gtk_widget_set_size_request(entry_datefmt, 200, -1);
528         gtk_box_pack_start (GTK_BOX (hbox2), entry_datefmt, FALSE, FALSE, 0);
529
530         button_datefmt = gtk_button_new_from_stock(GTK_STOCK_INFO);
531
532         gtk_widget_show (button_datefmt);
533         gtk_box_pack_start (GTK_BOX (hbox2), button_datefmt, FALSE, FALSE, 0);
534         g_signal_connect (G_OBJECT (button_datefmt), "clicked",
535                           G_CALLBACK (date_format_create), NULL);
536         
537         label_fill = gtk_label_new(" ");
538         gtk_box_pack_start(GTK_BOX(hbox2), label_fill, TRUE, FALSE, 0);
539         
540         CLAWS_SET_TIP(button_datefmt,
541                              _("Date format help"));
542                              
543         hbox_dispitem = gtk_hbox_new (FALSE, 8);
544         gtk_widget_show (hbox_dispitem);
545         gtk_box_pack_start(GTK_BOX(vbox2), hbox_dispitem, FALSE, TRUE, 0);
546         
547         label = gtk_label_new(_("Displayed columns"));
548         gtk_widget_show(label);
549         gtk_box_pack_start(GTK_BOX(hbox_dispitem), label, FALSE, FALSE, 0);
550         button_dispitem = gtk_button_new_from_stock(GTK_STOCK_EDIT);
551         gtk_widget_show (button_dispitem);
552         gtk_box_pack_start (GTK_BOX (hbox_dispitem), button_dispitem, FALSE, FALSE, 0);
553         g_signal_connect (G_OBJECT (button_dispitem), "clicked",
554                           G_CALLBACK (prefs_summary_column_open),
555                           NULL);
556
557         PACK_CHECK_BUTTON
558                 (vbox1, checkbtn_ask_mark_all_read,
559                  _("Confirm before marking all messages in a folder as read"));
560         PACK_CHECK_BUTTON
561                 (vbox1, checkbtn_transhdr,
562                  _("Translate header names"));
563         CLAWS_SET_TIP(checkbtn_transhdr,
564                              _("The display of standard headers (such as 'From:', 'Subject:') "
565                              "will be translated into your language."));
566         
567         hbox2 = gtk_hbox_new (FALSE, 8);
568         gtk_widget_show (hbox2);
569         gtk_box_pack_start (GTK_BOX (vbox1), hbox2, FALSE, FALSE, 0);
570
571         g_signal_connect(G_OBJECT(radio_mark_as_read_on_select), "toggled",
572                          G_CALLBACK(mark_as_read_toggled),
573                          spinbtn_mark_as_read_delay);
574
575         prefs_summaries->window                 = GTK_WIDGET(window);
576         
577         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_transhdr),
578                         prefs_common.trans_hdr);
579         combobox_select_by_data(GTK_COMBO_BOX(optmenu_folder_unread),
580                         prefs_common.display_folder_unread);
581         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_useaddrbook),
582                         prefs_common.use_addr_book);
583         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_show_tooltips),
584                         prefs_common.show_tooltips);
585         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_threadsubj),
586                         prefs_common.thread_by_subject);
587         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_ng_abbrev_len),
588                         prefs_common.ng_abbrev_len);
589         gtk_entry_set_text(GTK_ENTRY(entry_datefmt), 
590                         prefs_common.date_format?prefs_common.date_format:"");  
591
592         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_reopen_last_folder),
593                         prefs_common.goto_last_folder_on_startup);
594         combobox_select_by_data(GTK_COMBO_BOX(optmenu_always_show_msg),
595                         prefs_common.always_show_msg);
596         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_mark_as_read_on_new_win),
597                         prefs_common.mark_as_read_on_new_window);
598         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_mark_as_read_delay),
599                         prefs_common.mark_as_read_delay);
600         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_immedexec),
601                         prefs_common.immediate_exec);
602         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_ask_mark_all_read),
603                         prefs_common.ask_mark_all_read);
604
605         combobox_select_by_data(GTK_COMBO_BOX(optmenu_nextunreadmsgdialog),
606                         prefs_common.next_unread_msg_dialog);
607
608         prefs_summaries->checkbtn_transhdr = checkbtn_transhdr;
609         prefs_summaries->optmenu_folder_unread = optmenu_folder_unread;
610         prefs_summaries->spinbtn_ng_abbrev_len = spinbtn_ng_abbrev_len;
611         prefs_summaries->checkbtn_useaddrbook = checkbtn_useaddrbook;
612         prefs_summaries->checkbtn_show_tooltips = checkbtn_show_tooltips;
613         prefs_summaries->checkbtn_threadsubj = checkbtn_threadsubj;
614         prefs_summaries->entry_datefmt = entry_datefmt;
615
616         prefs_summaries->checkbtn_reopen_last_folder = checkbtn_reopen_last_folder;
617         prefs_summaries->optmenu_always_show_msg = optmenu_always_show_msg;
618         prefs_summaries->checkbtn_mark_as_read_on_newwin = radio_mark_as_read_on_new_win;
619         prefs_summaries->spinbtn_mark_as_read_delay = spinbtn_mark_as_read_delay;
620         prefs_summaries->checkbtn_immedexec = checkbtn_immedexec;
621         prefs_summaries->checkbtn_ask_mark_all_read = checkbtn_ask_mark_all_read;
622         prefs_summaries->optmenu_nextunreadmsgdialog = optmenu_nextunreadmsgdialog;
623
624         prefs_summaries->page.widget = vbox1;
625 }
626
627 static void prefs_summaries_save(PrefsPage *_page)
628 {
629         SummariesPage *page = (SummariesPage *) _page;
630
631         prefs_common.trans_hdr = gtk_toggle_button_get_active(
632                         GTK_TOGGLE_BUTTON(page->checkbtn_transhdr));
633
634
635         prefs_common.display_folder_unread = combobox_get_active_data(
636                         GTK_COMBO_BOX(page->optmenu_folder_unread));
637
638         prefs_common.use_addr_book = gtk_toggle_button_get_active(
639                         GTK_TOGGLE_BUTTON(page->checkbtn_useaddrbook));
640         prefs_common.show_tooltips = gtk_toggle_button_get_active(
641                         GTK_TOGGLE_BUTTON(page->checkbtn_show_tooltips));
642         prefs_common.thread_by_subject = gtk_toggle_button_get_active(
643                         GTK_TOGGLE_BUTTON(page->checkbtn_threadsubj));
644         prefs_common.ng_abbrev_len = gtk_spin_button_get_value_as_int(
645                         GTK_SPIN_BUTTON(page->spinbtn_ng_abbrev_len));
646         
647         g_free(prefs_common.date_format); 
648         prefs_common.date_format = gtk_editable_get_chars(
649                         GTK_EDITABLE(page->entry_datefmt), 0, -1);      
650
651         prefs_common.goto_last_folder_on_startup = gtk_toggle_button_get_active(
652                 GTK_TOGGLE_BUTTON(page->checkbtn_reopen_last_folder));
653         prefs_common.always_show_msg = combobox_get_active_data(
654                 GTK_COMBO_BOX(page->optmenu_always_show_msg));
655         prefs_common.mark_as_read_on_new_window = gtk_toggle_button_get_active(
656                 GTK_TOGGLE_BUTTON(page->checkbtn_mark_as_read_on_newwin));
657         prefs_common.immediate_exec = gtk_toggle_button_get_active(
658                 GTK_TOGGLE_BUTTON(page->checkbtn_immedexec));
659         prefs_common.ask_mark_all_read = gtk_toggle_button_get_active(
660                 GTK_TOGGLE_BUTTON(page->checkbtn_ask_mark_all_read));
661         prefs_common.mark_as_read_delay = gtk_spin_button_get_value_as_int(
662                         GTK_SPIN_BUTTON(page->spinbtn_mark_as_read_delay));
663
664         prefs_common.next_unread_msg_dialog = combobox_get_active_data(
665                         GTK_COMBO_BOX(page->optmenu_nextunreadmsgdialog));
666         main_window_reflect_prefs_all();
667 }
668
669 static void prefs_summaries_destroy_widget(PrefsPage *_page)
670 {
671 }
672
673 SummariesPage *prefs_summaries;
674
675 void prefs_summaries_init(void)
676 {
677         SummariesPage *page;
678         static gchar *path[3];
679
680         path[0] = _("Display");
681         path[1] = _("Summaries");
682         path[2] = NULL;
683
684         page = g_new0(SummariesPage, 1);
685         page->page.path = path;
686         page->page.create_widget = prefs_summaries_create_widget;
687         page->page.destroy_widget = prefs_summaries_destroy_widget;
688         page->page.save_page = prefs_summaries_save;
689         page->page.weight = 140.0;
690         prefs_gtk_register_page((PrefsPage *) page);
691         prefs_summaries = page;
692 }
693
694 void prefs_summaries_done(void)
695 {
696         prefs_gtk_unregister_page((PrefsPage *) prefs_summaries);
697         g_free(prefs_summaries);
698 }
699
700 static void date_format_ok_btn_clicked(GtkButton *button, GtkWidget **widget)
701 {
702         GtkWidget *datefmt_sample = NULL;
703         gchar *text;
704
705         cm_return_if_fail(widget != NULL);
706         cm_return_if_fail(*widget != NULL);
707         cm_return_if_fail(prefs_summaries->entry_datefmt != NULL);
708
709         datefmt_sample = GTK_WIDGET(g_object_get_data
710                                     (G_OBJECT(*widget), "datefmt_sample"));
711         cm_return_if_fail(datefmt_sample != NULL);
712
713         text = gtk_editable_get_chars(GTK_EDITABLE(datefmt_sample), 0, -1);
714         g_free(prefs_common.date_format);
715         prefs_common.date_format = text;
716         gtk_entry_set_text(GTK_ENTRY(prefs_summaries->entry_datefmt), text);
717
718         gtk_widget_destroy(*widget);
719         *widget = NULL;
720 }
721
722 static void date_format_cancel_btn_clicked(GtkButton *button,
723                                            GtkWidget **widget)
724 {
725         cm_return_if_fail(widget != NULL);
726         cm_return_if_fail(*widget != NULL);
727
728         gtk_widget_destroy(*widget);
729         *widget = NULL;
730 }
731
732 static gboolean date_format_key_pressed(GtkWidget *keywidget, GdkEventKey *event,
733                                         GtkWidget **widget)
734 {
735         if (event && event->keyval == GDK_KEY_Escape)
736                 date_format_cancel_btn_clicked(NULL, widget);
737         return FALSE;
738 }
739
740 static gboolean date_format_on_delete(GtkWidget *dialogwidget,
741                                       GdkEventAny *event, GtkWidget **widget)
742 {
743         cm_return_val_if_fail(widget != NULL, FALSE);
744         cm_return_val_if_fail(*widget != NULL, FALSE);
745
746         *widget = NULL;
747         return FALSE;
748 }
749
750 static void date_format_entry_on_change(GtkEditable *editable,
751                                         GtkLabel *example)
752 {
753         time_t cur_time;
754         struct tm *cal_time;
755         gchar buffer[100];
756         gchar *text;
757         struct tm lt;
758
759         cur_time = time(NULL);
760         cal_time = localtime_r(&cur_time, &lt);
761         buffer[0] = 0;
762         text = gtk_editable_get_chars(editable, 0, -1);
763         if (text)
764                 fast_strftime(buffer, sizeof buffer, text, cal_time); 
765
766         gtk_label_set_text(example, buffer);
767
768         g_free(text);
769 }
770
771 static void date_format_select_row(GtkTreeView *list_view,
772                                    GtkTreePath *path,
773                                    GtkTreeViewColumn *column,
774                                    GtkWidget *date_format)
775 {
776         gint cur_pos;
777         gchar *format;
778         const gchar *old_format;
779         gchar *new_format;
780         GtkWidget *datefmt_sample;
781         GtkTreeIter iter;
782         GtkTreeModel *model;
783         
784         cm_return_if_fail(date_format != NULL);
785
786         /* only on double click */
787         datefmt_sample = GTK_WIDGET(g_object_get_data(G_OBJECT(date_format), 
788                                                       "datefmt_sample"));
789
790         cm_return_if_fail(datefmt_sample != NULL);
791
792         model = gtk_tree_view_get_model(list_view);
793
794         /* get format from list */
795         if (!gtk_tree_model_get_iter(model, &iter, path))
796                 return;
797
798         gtk_tree_model_get(model, &iter, DATEFMT_FMT, &format, -1);             
799         
800         cur_pos = gtk_editable_get_position(GTK_EDITABLE(datefmt_sample));
801         old_format = gtk_entry_get_text(GTK_ENTRY(datefmt_sample));
802
803         /* insert the format into the text entry */
804         new_format = g_malloc(strlen(old_format) + 3);
805
806         strncpy(new_format, old_format, cur_pos);
807         new_format[cur_pos] = '\0';
808         strcat(new_format, format);
809         strcat(new_format, &old_format[cur_pos]);
810
811         gtk_entry_set_text(GTK_ENTRY(datefmt_sample), new_format);
812         gtk_editable_set_position(GTK_EDITABLE(datefmt_sample), cur_pos + 2);
813
814         g_free(new_format);
815 }
816
817 static void mark_as_read_toggled(GtkToggleButton *button, GtkWidget *spinbtn)
818 {
819        gtk_widget_set_sensitive(spinbtn,
820                gtk_toggle_button_get_active(button));
821 }
822