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