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