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