Fix two more issues with modal dialog focus on Windows.
[claws.git] / src / prefs_summaries.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2005-2012 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 #include "claws-features.h"
23 #endif
24
25 #include "defs.h"
26
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 #include <glib.h>
31 #include <glib/gi18n.h>
32 #include <gtk/gtk.h>
33 #include <gdk/gdkkeysyms.h>
34
35 #ifdef G_OS_WIN32
36 #  include <w32lib.h>
37 #endif
38
39 #include "prefs_common.h"
40 #include "prefs_gtk.h"
41 #include "prefs_summary_open.h"
42 #include "prefs_summary_column.h"
43 #include "prefs_folder_column.h"
44
45 #include "gtk/menu.h"
46 #include "gtk/gtkutils.h"
47 #include "gtk/prefswindow.h"
48 #include "gtk/combobox.h"
49
50 #include "manage_window.h"
51
52 typedef struct _SummariesPage
53 {
54         PrefsPage page;
55
56         GtkWidget *window;
57
58         GtkWidget *checkbtn_transhdr;
59         GtkWidget *optmenu_folder_unread;
60         GtkWidget *spinbtn_ng_abbrev_len;
61         GtkWidget *checkbtn_useaddrbook;
62         GtkWidget *checkbtn_show_tooltips;
63         GtkWidget *checkbtn_threadsubj;
64         GtkWidget *button_datefmt;
65         GtkWidget *entry_datefmt;
66
67         GtkWidget *checkbtn_reopen_last_folder;
68         GtkWidget *optmenu_always_show_msg;
69         GtkWidget *checkbtn_mark_as_read_on_newwin;
70         GtkWidget *spinbtn_mark_as_read_delay;
71         GtkWidget *checkbtn_immedexec;
72         GtkWidget *checkbtn_ask_mark_all_read;
73         GtkWidget *optmenu_nextunreadmsgdialog;
74
75 } SummariesPage;
76
77 enum {
78         DATEFMT_FMT,
79         DATEFMT_TXT,
80         N_DATEFMT_COLUMNS
81 };
82
83 static void date_format_ok_btn_clicked          (GtkButton      *button,
84                                                  GtkWidget     **widget);
85 static void date_format_cancel_btn_clicked      (GtkButton      *button,
86                                                  GtkWidget     **widget);
87 static gboolean date_format_key_pressed         (GtkWidget      *keywidget,
88                                                  GdkEventKey    *event,
89                                                  GtkWidget     **widget);
90 static gboolean date_format_on_delete           (GtkWidget      *dialogwidget,
91                                                  GdkEventAny    *event,
92                                                  GtkWidget     **widget);
93 static void date_format_entry_on_change         (GtkEditable    *editable,
94                                                  GtkLabel       *example);
95 static void date_format_select_row              (GtkTreeView *list_view,
96                                                  GtkTreePath *path,
97                                                  GtkTreeViewColumn *column,
98                                                  GtkWidget *date_format);
99 static void mark_as_read_toggled                (GtkToggleButton *button,
100                                                  GtkWidget *spinbtn);
101
102 static GtkWidget *date_format_create(GtkButton *button, void *data)
103 {
104         static GtkWidget *datefmt_win = NULL;
105
106         GtkWidget *vbox1;
107         GtkWidget *scrolledwindow1;
108         GtkWidget *datefmt_list_view;
109         GtkWidget *table;
110         GtkWidget *label1;
111         GtkWidget *label2;
112         GtkWidget *label3;
113         GtkWidget *confirm_area;
114         GtkWidget *ok_btn;
115         GtkWidget *cancel_btn;
116         GtkWidget *datefmt_entry;
117         GtkListStore *store;
118
119         struct {
120                 gchar *fmt;
121                 gchar *txt;
122         } time_format[] = {
123                 { "%a", NULL },
124                 { "%A", NULL },
125                 { "%b", NULL },
126                 { "%B", NULL },
127                 { "%c", NULL },
128                 { "%C", NULL },
129                 { "%d", NULL },
130                 { "%H", NULL },
131                 { "%I", NULL },
132                 { "%j", NULL },
133                 { "%m", NULL },
134                 { "%M", NULL },
135                 { "%p", NULL },
136                 { "%S", NULL },
137                 { "%w", NULL },
138                 { "%x", NULL },
139                 { "%y", NULL },
140                 { "%Y", NULL },
141                 { "%Z", NULL }
142         };
143
144         gint i;
145         const gint TIME_FORMAT_ELEMS =
146                 sizeof time_format / sizeof time_format[0];
147
148         GtkCellRenderer *renderer;
149         GtkTreeViewColumn *column;
150         GtkTreeSelection *selection;
151
152         time_format[0].txt  = _("the abbreviated weekday name");
153         time_format[1].txt  = _("the full weekday name");
154         time_format[2].txt  = _("the abbreviated month name");
155         time_format[3].txt  = _("the full month name");
156         time_format[4].txt  = _("the preferred date and time for the current locale");
157         time_format[5].txt  = _("the century number (year/100)");
158         time_format[6].txt  = _("the day of the month as a decimal number");
159         time_format[7].txt  = _("the hour as a decimal number using a 24-hour clock");
160         time_format[8].txt  = _("the hour as a decimal number using a 12-hour clock");
161         time_format[9].txt  = _("the day of the year as a decimal number");
162         time_format[10].txt = _("the month as a decimal number");
163         time_format[11].txt = _("the minute as a decimal number");
164         time_format[12].txt = _("either AM or PM");
165         time_format[13].txt = _("the second as a decimal number");
166         time_format[14].txt = _("the day of the week as a decimal number");
167         time_format[15].txt = _("the preferred date for the current locale");
168         time_format[16].txt = _("the last two digits of a year");
169         time_format[17].txt = _("the year as a decimal number");
170         time_format[18].txt = _("the time zone or name or abbreviation");
171
172         if (datefmt_win) return datefmt_win;
173
174         store = gtk_list_store_new(N_DATEFMT_COLUMNS,
175                                    G_TYPE_STRING,
176                                    G_TYPE_STRING,
177                                    -1);
178
179         for (i = 0; i < TIME_FORMAT_ELEMS; i++) {
180                 GtkTreeIter iter;
181
182                 gtk_list_store_append(store, &iter);
183                 gtk_list_store_set(store, &iter,
184                                    DATEFMT_FMT, time_format[i].fmt,
185                                    DATEFMT_TXT, time_format[i].txt,
186                                    -1);
187         }
188
189         datefmt_win = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_summaries");
190         gtk_container_set_border_width(GTK_CONTAINER(datefmt_win), 8);
191         gtk_window_set_title(GTK_WINDOW(datefmt_win), _("Date format"));
192         gtk_window_set_position(GTK_WINDOW(datefmt_win), GTK_WIN_POS_CENTER);
193         gtk_widget_set_size_request(datefmt_win, 440, 280);
194
195         vbox1 = gtk_vbox_new(FALSE, 10);
196         gtk_widget_show(vbox1);
197         gtk_container_add(GTK_CONTAINER(datefmt_win), vbox1);
198
199         scrolledwindow1 = gtk_scrolled_window_new(NULL, NULL);
200         gtk_scrolled_window_set_policy
201                 (GTK_SCROLLED_WINDOW(scrolledwindow1),
202                  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
203         gtk_widget_show(scrolledwindow1);
204         gtk_box_pack_start(GTK_BOX(vbox1), scrolledwindow1, TRUE, TRUE, 0);
205
206         datefmt_list_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
207         g_object_unref(G_OBJECT(store));
208         gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(datefmt_list_view),
209                                      prefs_common.use_stripes_everywhere);
210         gtk_widget_show(datefmt_list_view);
211         gtk_container_add(GTK_CONTAINER(scrolledwindow1), datefmt_list_view);
212
213         renderer = gtk_cell_renderer_text_new();
214         column = gtk_tree_view_column_new_with_attributes
215                         (_("Specifier"), renderer, "text", DATEFMT_FMT,
216                          NULL);
217         gtk_tree_view_append_column(GTK_TREE_VIEW(datefmt_list_view), column);
218         
219         renderer = gtk_cell_renderer_text_new();
220         column = gtk_tree_view_column_new_with_attributes
221                         (_("Description"), renderer, "text", DATEFMT_TXT,
222                          NULL);
223         gtk_tree_view_append_column(GTK_TREE_VIEW(datefmt_list_view), column);
224         
225         /* gtk_cmclist_set_column_width(GTK_CMCLIST(datefmt_clist), 0, 80); */
226         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(datefmt_list_view));
227         gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
228
229         g_signal_connect(G_OBJECT(datefmt_list_view), "row_activated", 
230                          G_CALLBACK(date_format_select_row),
231                          datefmt_win);
232         
233         table = gtk_table_new(2, 2, FALSE);
234         gtk_widget_show(table);
235         gtk_box_pack_start(GTK_BOX(vbox1), table, FALSE, FALSE, 0);
236         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
237         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
238
239         label1 = gtk_label_new(_("Date format"));
240         gtk_widget_show(label1);
241         gtk_table_attach(GTK_TABLE(table), label1, 0, 1, 0, 1,
242                          GTK_FILL, 0, 0, 0);
243         gtk_label_set_justify(GTK_LABEL(label1), GTK_JUSTIFY_LEFT);
244         gtk_misc_set_alignment(GTK_MISC(label1), 0, 0.5);
245
246         datefmt_entry = gtk_entry_new();
247         gtk_entry_set_max_length(GTK_ENTRY(datefmt_entry), 256);
248         gtk_widget_show(datefmt_entry);
249         gtk_table_attach(GTK_TABLE(table), datefmt_entry, 1, 2, 0, 1,
250                          (GTK_EXPAND | GTK_FILL), 0, 0, 0);
251
252         /* we need the "sample" entry box; add it as data so callbacks can
253          * get the entry box */
254         g_object_set_data(G_OBJECT(datefmt_win), "datefmt_sample",
255                           datefmt_entry);
256
257         label2 = gtk_label_new(_("Example"));
258         gtk_widget_show(label2);
259         gtk_table_attach(GTK_TABLE(table), label2, 0, 1, 1, 2,
260                          GTK_FILL, 0, 0, 0);
261         gtk_label_set_justify(GTK_LABEL(label2), GTK_JUSTIFY_LEFT);
262         gtk_misc_set_alignment(GTK_MISC(label2), 0, 0.5);
263
264         label3 = gtk_label_new("");
265         gtk_widget_show(label3);
266         gtk_table_attach(GTK_TABLE(table), label3, 1, 2, 1, 2,
267                          (GTK_EXPAND | GTK_FILL), 0, 0, 0);
268         gtk_label_set_justify(GTK_LABEL(label3), GTK_JUSTIFY_LEFT);
269         gtk_misc_set_alignment(GTK_MISC(label3), 0, 0.5);
270
271         gtkut_stock_button_set_create(&confirm_area, &cancel_btn, GTK_STOCK_CANCEL,
272                                       &ok_btn, GTK_STOCK_OK, NULL, NULL);
273
274         gtk_box_pack_start(GTK_BOX(vbox1), confirm_area, FALSE, FALSE, 0);
275         gtk_widget_show(confirm_area);
276         gtk_widget_grab_default(ok_btn);
277
278         /* set the current format */
279         gtk_entry_set_text(GTK_ENTRY(datefmt_entry), prefs_common.date_format);
280         date_format_entry_on_change(GTK_EDITABLE(datefmt_entry),
281                                     GTK_LABEL(label3));
282
283         g_signal_connect(G_OBJECT(ok_btn), "clicked",
284                          G_CALLBACK(date_format_ok_btn_clicked),
285                          &datefmt_win);
286         g_signal_connect(G_OBJECT(cancel_btn), "clicked",
287                          G_CALLBACK(date_format_cancel_btn_clicked),
288                          &datefmt_win);
289         g_signal_connect(G_OBJECT(datefmt_win), "key_press_event",
290                          G_CALLBACK(date_format_key_pressed),
291                          &datefmt_win);
292         g_signal_connect(G_OBJECT(datefmt_win), "delete_event",
293                          G_CALLBACK(date_format_on_delete),
294                          &datefmt_win);
295         g_signal_connect(G_OBJECT(datefmt_entry), "changed",
296                          G_CALLBACK(date_format_entry_on_change),
297                          label3);
298
299         gtk_window_set_position(GTK_WINDOW(datefmt_win), GTK_WIN_POS_CENTER);
300
301         gtk_widget_show(datefmt_win);
302         manage_window_set_transient(GTK_WINDOW(datefmt_win));
303         gtk_window_set_modal(GTK_WINDOW(datefmt_win), TRUE);
304
305         gtk_widget_grab_focus(ok_btn);
306
307         return datefmt_win;
308 }
309
310 static void prefs_summaries_create_widget(PrefsPage *_page, GtkWindow *window, 
311                                   gpointer data)
312 {
313         SummariesPage *prefs_summaries = (SummariesPage *) _page;
314         
315         GtkWidget *vbox1;
316         GtkWidget *checkbtn_transhdr;
317         GtkWidget *hbox0;
318         GtkWidget *optmenu_folder_unread;
319         GtkWidget *hbox1;
320         GtkWidget *label_ng_abbrev;
321         GtkWidget *spinbtn_ng_abbrev_len;
322         GtkAdjustment *spinbtn_ng_abbrev_len_adj;
323         GtkWidget *vbox2;
324         GtkWidget *vbox3;
325         GtkWidget *checkbtn_useaddrbook;
326         GtkWidget *checkbtn_show_tooltips;
327         GtkWidget *checkbtn_threadsubj;
328         GtkWidget *label_datefmt;
329         GtkWidget *button_datefmt;
330         GtkWidget *entry_datefmt;
331         GtkWidget *hbox_dispitem;
332         GtkWidget *button_dispitem;
333         GtkWidget *hbox2;
334         GtkWidget *checkbtn_reopen_last_folder;
335         GtkWidget *optmenu_always_show_msg;
336         GtkWidget *spinbtn_mark_as_read_delay;
337         GtkAdjustment *spinbtn_mark_as_read_delay_adj;
338         GtkWidget *checkbtn_immedexec;
339         GtkWidget *checkbtn_ask_mark_all_read;
340         GtkWidget *label, *label_fill;
341         GtkListStore *menu;
342         GtkTreeIter iter;
343         GtkWidget *optmenu_nextunreadmsgdialog;
344         GtkWidget *folderview_frame;
345         GtkWidget *summaryview_frame;
346         GtkWidget *button_edit_actions;
347         GtkWidget *radio_mark_as_read_on_select;
348         GtkWidget *radio_mark_as_read_on_new_win;
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(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(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         hbox2 = gtk_hbox_new (FALSE, 8);
516         gtk_widget_show (hbox2);
517         gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, TRUE, 0);
518
519         label_datefmt = gtk_label_new (_("Date format"));
520         gtk_widget_show (label_datefmt);
521         gtk_box_pack_start (GTK_BOX (hbox2), label_datefmt, FALSE, FALSE, 0);
522
523         entry_datefmt = gtk_entry_new ();
524         gtk_widget_show (entry_datefmt);
525         gtk_widget_set_size_request(entry_datefmt, 200, -1);
526         gtk_box_pack_start (GTK_BOX (hbox2), entry_datefmt, FALSE, FALSE, 0);
527
528         button_datefmt = gtk_button_new_from_stock(GTK_STOCK_INFO);
529
530         gtk_widget_show (button_datefmt);
531         gtk_box_pack_start (GTK_BOX (hbox2), button_datefmt, FALSE, FALSE, 0);
532         g_signal_connect (G_OBJECT (button_datefmt), "clicked",
533                           G_CALLBACK (date_format_create), NULL);
534         
535         label_fill = gtk_label_new(" ");
536         gtk_box_pack_start(GTK_BOX(hbox2), label_fill, TRUE, FALSE, 0);
537         
538         CLAWS_SET_TIP(button_datefmt,
539                              _("Date format help"));
540                              
541         hbox_dispitem = gtk_hbox_new (FALSE, 8);
542         gtk_widget_show (hbox_dispitem);
543         gtk_box_pack_start(GTK_BOX(vbox2), hbox_dispitem, FALSE, TRUE, 0);
544         
545         label = gtk_label_new(_("Displayed columns"));
546         gtk_widget_show(label);
547         gtk_box_pack_start(GTK_BOX(hbox_dispitem), label, FALSE, FALSE, 0);
548         button_dispitem = gtk_button_new_from_stock(GTK_STOCK_EDIT);
549         gtk_widget_show (button_dispitem);
550         gtk_box_pack_start (GTK_BOX (hbox_dispitem), button_dispitem, FALSE, FALSE, 0);
551         g_signal_connect (G_OBJECT (button_dispitem), "clicked",
552                           G_CALLBACK (prefs_summary_column_open),
553                           NULL);
554
555         PACK_CHECK_BUTTON
556                 (vbox1, checkbtn_ask_mark_all_read,
557                  _("Confirm before marking all messages in a folder as read"));
558         PACK_CHECK_BUTTON
559                 (vbox1, checkbtn_transhdr,
560                  _("Translate header names"));
561         CLAWS_SET_TIP(checkbtn_transhdr,
562                              _("The display of standard headers (such as 'From:', 'Subject:') "
563                              "will be translated into your language."));
564         
565         hbox2 = gtk_hbox_new (FALSE, 8);
566         gtk_widget_show (hbox2);
567         gtk_box_pack_start (GTK_BOX (vbox1), hbox2, FALSE, FALSE, 0);
568
569         g_signal_connect(G_OBJECT(radio_mark_as_read_on_select), "toggled",
570                          G_CALLBACK(mark_as_read_toggled),
571                          spinbtn_mark_as_read_delay);
572
573         prefs_summaries->window                 = GTK_WIDGET(window);
574         
575         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_transhdr),
576                         prefs_common.trans_hdr);
577         combobox_select_by_data(GTK_COMBO_BOX(optmenu_folder_unread),
578                         prefs_common.display_folder_unread);
579         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_useaddrbook),
580                         prefs_common.use_addr_book);
581         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_show_tooltips),
582                         prefs_common.show_tooltips);
583         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_threadsubj),
584                         prefs_common.thread_by_subject);
585         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_ng_abbrev_len),
586                         prefs_common.ng_abbrev_len);
587         gtk_entry_set_text(GTK_ENTRY(entry_datefmt), 
588                         prefs_common.date_format?prefs_common.date_format:"");  
589
590         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_reopen_last_folder),
591                         prefs_common.goto_last_folder_on_startup);
592         combobox_select_by_data(GTK_COMBO_BOX(optmenu_always_show_msg),
593                         prefs_common.always_show_msg);
594         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_mark_as_read_on_new_win),
595                         prefs_common.mark_as_read_on_new_window);
596         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_mark_as_read_delay),
597                         prefs_common.mark_as_read_delay);
598         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_immedexec),
599                         prefs_common.immediate_exec);
600         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_ask_mark_all_read),
601                         prefs_common.ask_mark_all_read);
602
603         combobox_select_by_data(GTK_COMBO_BOX(optmenu_nextunreadmsgdialog),
604                         prefs_common.next_unread_msg_dialog);
605
606         prefs_summaries->checkbtn_transhdr = checkbtn_transhdr;
607         prefs_summaries->optmenu_folder_unread = optmenu_folder_unread;
608         prefs_summaries->spinbtn_ng_abbrev_len = spinbtn_ng_abbrev_len;
609         prefs_summaries->checkbtn_useaddrbook = checkbtn_useaddrbook;
610         prefs_summaries->checkbtn_show_tooltips = checkbtn_show_tooltips;
611         prefs_summaries->checkbtn_threadsubj = checkbtn_threadsubj;
612         prefs_summaries->entry_datefmt = entry_datefmt;
613
614         prefs_summaries->checkbtn_reopen_last_folder = checkbtn_reopen_last_folder;
615         prefs_summaries->optmenu_always_show_msg = optmenu_always_show_msg;
616         prefs_summaries->checkbtn_mark_as_read_on_newwin = radio_mark_as_read_on_new_win;
617         prefs_summaries->spinbtn_mark_as_read_delay = spinbtn_mark_as_read_delay;
618         prefs_summaries->checkbtn_immedexec = checkbtn_immedexec;
619         prefs_summaries->checkbtn_ask_mark_all_read = checkbtn_ask_mark_all_read;
620         prefs_summaries->optmenu_nextunreadmsgdialog = optmenu_nextunreadmsgdialog;
621
622         prefs_summaries->page.widget = vbox1;
623 }
624
625 static void prefs_summaries_save(PrefsPage *_page)
626 {
627         SummariesPage *page = (SummariesPage *) _page;
628
629         prefs_common.trans_hdr = gtk_toggle_button_get_active(
630                         GTK_TOGGLE_BUTTON(page->checkbtn_transhdr));
631
632
633         prefs_common.display_folder_unread = combobox_get_active_data(
634                         GTK_COMBO_BOX(page->optmenu_folder_unread));
635
636         prefs_common.use_addr_book = gtk_toggle_button_get_active(
637                         GTK_TOGGLE_BUTTON(page->checkbtn_useaddrbook));
638         prefs_common.show_tooltips = gtk_toggle_button_get_active(
639                         GTK_TOGGLE_BUTTON(page->checkbtn_show_tooltips));
640         prefs_common.thread_by_subject = gtk_toggle_button_get_active(
641                         GTK_TOGGLE_BUTTON(page->checkbtn_threadsubj));
642         prefs_common.ng_abbrev_len = gtk_spin_button_get_value_as_int(
643                         GTK_SPIN_BUTTON(page->spinbtn_ng_abbrev_len));
644         
645         g_free(prefs_common.date_format); 
646         prefs_common.date_format = gtk_editable_get_chars(
647                         GTK_EDITABLE(page->entry_datefmt), 0, -1);      
648
649         prefs_common.goto_last_folder_on_startup = gtk_toggle_button_get_active(
650                 GTK_TOGGLE_BUTTON(page->checkbtn_reopen_last_folder));
651         prefs_common.always_show_msg = combobox_get_active_data(
652                 GTK_COMBO_BOX(page->optmenu_always_show_msg));
653         prefs_common.mark_as_read_on_new_window = gtk_toggle_button_get_active(
654                 GTK_TOGGLE_BUTTON(page->checkbtn_mark_as_read_on_newwin));
655         prefs_common.immediate_exec = gtk_toggle_button_get_active(
656                 GTK_TOGGLE_BUTTON(page->checkbtn_immedexec));
657         prefs_common.ask_mark_all_read = gtk_toggle_button_get_active(
658                 GTK_TOGGLE_BUTTON(page->checkbtn_ask_mark_all_read));
659         prefs_common.mark_as_read_delay = gtk_spin_button_get_value_as_int(
660                         GTK_SPIN_BUTTON(page->spinbtn_mark_as_read_delay));
661
662         prefs_common.next_unread_msg_dialog = combobox_get_active_data(
663                         GTK_COMBO_BOX(page->optmenu_nextunreadmsgdialog));
664         main_window_reflect_prefs_all();
665 }
666
667 static void prefs_summaries_destroy_widget(PrefsPage *_page)
668 {
669 }
670
671 SummariesPage *prefs_summaries;
672
673 void prefs_summaries_init(void)
674 {
675         SummariesPage *page;
676         static gchar *path[3];
677
678         path[0] = _("Display");
679         path[1] = _("Summaries");
680         path[2] = NULL;
681
682         page = g_new0(SummariesPage, 1);
683         page->page.path = path;
684         page->page.create_widget = prefs_summaries_create_widget;
685         page->page.destroy_widget = prefs_summaries_destroy_widget;
686         page->page.save_page = prefs_summaries_save;
687         page->page.weight = 140.0;
688         prefs_gtk_register_page((PrefsPage *) page);
689         prefs_summaries = page;
690 }
691
692 void prefs_summaries_done(void)
693 {
694         prefs_gtk_unregister_page((PrefsPage *) prefs_summaries);
695         g_free(prefs_summaries);
696 }
697
698 static void date_format_ok_btn_clicked(GtkButton *button, GtkWidget **widget)
699 {
700         GtkWidget *datefmt_sample = NULL;
701         gchar *text;
702
703         cm_return_if_fail(widget != NULL);
704         cm_return_if_fail(*widget != NULL);
705         cm_return_if_fail(prefs_summaries->entry_datefmt != NULL);
706
707         datefmt_sample = GTK_WIDGET(g_object_get_data
708                                     (G_OBJECT(*widget), "datefmt_sample"));
709         cm_return_if_fail(datefmt_sample != NULL);
710
711         text = gtk_editable_get_chars(GTK_EDITABLE(datefmt_sample), 0, -1);
712         g_free(prefs_common.date_format);
713         prefs_common.date_format = text;
714         gtk_entry_set_text(GTK_ENTRY(prefs_summaries->entry_datefmt), text);
715
716         gtk_widget_destroy(*widget);
717         *widget = NULL;
718 }
719
720 static void date_format_cancel_btn_clicked(GtkButton *button,
721                                            GtkWidget **widget)
722 {
723         cm_return_if_fail(widget != NULL);
724         cm_return_if_fail(*widget != NULL);
725
726         gtk_widget_destroy(*widget);
727         *widget = NULL;
728 }
729
730 static gboolean date_format_key_pressed(GtkWidget *keywidget, GdkEventKey *event,
731                                         GtkWidget **widget)
732 {
733         if (event && event->keyval == GDK_KEY_Escape)
734                 date_format_cancel_btn_clicked(NULL, widget);
735         return FALSE;
736 }
737
738 static gboolean date_format_on_delete(GtkWidget *dialogwidget,
739                                       GdkEventAny *event, GtkWidget **widget)
740 {
741         cm_return_val_if_fail(widget != NULL, FALSE);
742         cm_return_val_if_fail(*widget != NULL, FALSE);
743
744         *widget = NULL;
745         return FALSE;
746 }
747
748 static void date_format_entry_on_change(GtkEditable *editable,
749                                         GtkLabel *example)
750 {
751         time_t cur_time;
752         struct tm *cal_time;
753         gchar buffer[100];
754         gchar *text;
755         struct tm lt;
756
757         cur_time = time(NULL);
758         cal_time = localtime_r(&cur_time, &lt);
759         buffer[0] = 0;
760         text = gtk_editable_get_chars(editable, 0, -1);
761         if (text)
762                 fast_strftime(buffer, sizeof buffer, text, cal_time); 
763
764         gtk_label_set_text(example, buffer);
765
766         g_free(text);
767 }
768
769 static void date_format_select_row(GtkTreeView *list_view,
770                                    GtkTreePath *path,
771                                    GtkTreeViewColumn *column,
772                                    GtkWidget *date_format)
773 {
774         gint cur_pos;
775         gchar *format;
776         const gchar *old_format;
777         gchar *new_format;
778         GtkWidget *datefmt_sample;
779         GtkTreeIter iter;
780         GtkTreeModel *model;
781         
782         cm_return_if_fail(date_format != NULL);
783
784         /* only on double click */
785         datefmt_sample = GTK_WIDGET(g_object_get_data(G_OBJECT(date_format), 
786                                                       "datefmt_sample"));
787
788         cm_return_if_fail(datefmt_sample != NULL);
789
790         model = gtk_tree_view_get_model(list_view);
791
792         /* get format from list */
793         if (!gtk_tree_model_get_iter(model, &iter, path))
794                 return;
795
796         gtk_tree_model_get(model, &iter, DATEFMT_FMT, &format, -1);             
797         
798         cur_pos = gtk_editable_get_position(GTK_EDITABLE(datefmt_sample));
799         old_format = gtk_entry_get_text(GTK_ENTRY(datefmt_sample));
800
801         /* insert the format into the text entry */
802         new_format = g_malloc(strlen(old_format) + 3);
803
804         strncpy(new_format, old_format, cur_pos);
805         new_format[cur_pos] = '\0';
806         strcat(new_format, format);
807         strcat(new_format, &old_format[cur_pos]);
808
809         gtk_entry_set_text(GTK_ENTRY(datefmt_sample), new_format);
810         gtk_editable_set_position(GTK_EDITABLE(datefmt_sample), cur_pos + 2);
811
812         g_free(new_format);
813 }
814
815 static void mark_as_read_toggled(GtkToggleButton *button, GtkWidget *spinbtn)
816 {
817        gtk_widget_set_sensitive(spinbtn,
818                gtk_toggle_button_get_active(button));
819 }
820