sync with 0.9.10cvs11
[claws.git] / src / prefs_display_header.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2004 Hiroyuki Yamamoto
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <gtk/gtk.h>
28 #include <gdk/gdkkeysyms.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <errno.h>
33
34 #include "intl.h"
35 #include "prefs_gtk.h"
36 #include "prefs_display_header.h"
37 #include "prefs_common.h"
38 #include "manage_window.h"
39 #include "alertpanel.h"
40 #include "displayheader.h"
41 #include "utils.h"
42 #include "gtkutils.h"
43
44 static struct DisplayHeader {
45         GtkWidget *window;
46
47         GtkWidget *ok_btn;
48         GtkWidget *cancel_btn;
49
50         GtkWidget *hdr_combo;
51         GtkWidget *hdr_entry;
52         GtkWidget *key_check;
53         GtkWidget *headers_clist;
54         GtkWidget *hidden_headers_clist;
55
56         GtkWidget *other_headers;
57 } dispheader;
58
59 /* widget creating functions */
60 static void prefs_display_header_create (void);
61
62 static void prefs_display_header_set_dialog     (void);
63 static void prefs_display_header_set_list       (void);
64 static gint prefs_display_header_clist_set_row  (gboolean hidden);
65
66 /* callback functions */
67 static void prefs_display_header_register_cb    (GtkButton      *btn,
68                                                  gpointer        hidden_data);
69 static void prefs_display_header_delete_cb      (GtkButton      *btn,
70                                                  gpointer        clist_data);
71 static void prefs_display_header_up             (void);
72 static void prefs_display_header_down           (void);
73
74 static void prefs_display_header_row_moved      (GtkCList       *clist,
75                                                  gint            source_row,
76                                                  gint            dest_row,
77                                                  gpointer        data);
78
79 static void prefs_display_header_key_pressed    (GtkWidget      *widget,
80                                                  GdkEventKey    *event,
81                                                  gpointer        data);
82 static void prefs_display_header_ok             (void);
83 static void prefs_display_header_cancel         (void);
84 static gint prefs_display_header_deleted        (GtkWidget      *widget,
85                                                  GdkEventAny    *event,
86                                                  gpointer        data);
87
88 static gchar *defaults[] =
89 {
90         "From",
91         "To",
92         "Cc",
93         "Reply-To",
94         "Newsgroups",
95         "Followup-To",
96         "Subject",
97         "Date",
98         "Sender",
99         "Organization",
100         "X-Mailer",
101         "X-Newsreader",
102         "User-Agent",
103         "-Received",
104         "-Message-Id",
105         "-In-Reply-To",
106         "-References",
107         "-Mime-Version",
108         "-Content-Type",
109         "-Content-Transfer-Encoding",
110         "-X-UIDL",
111         "-Precedence",
112         "-Status",
113         "-Priority",
114         "-X-Face"
115 };
116
117 static void prefs_display_header_set_default(void)
118 {
119         gint i;
120         DisplayHeaderProp *dp;
121
122         for(i = 0; i < sizeof(defaults) / sizeof(defaults[0]); i++) {
123                 dp = display_header_prop_read_str(defaults[i]);
124                 prefs_common.disphdr_list =
125                         g_slist_append(prefs_common.disphdr_list, dp);
126         }
127 }
128
129 void prefs_display_header_open(void)
130 {
131         if (prefs_rc_is_readonly(DISPLAY_HEADER_RC))
132                 return;
133
134         if (!dispheader.window) {
135                 prefs_display_header_create();
136         }
137
138         manage_window_set_transient(GTK_WINDOW(dispheader.window));
139         gtk_widget_grab_focus(dispheader.ok_btn);
140
141         prefs_display_header_set_dialog();
142
143         gtk_widget_show(dispheader.window);
144 }
145
146 static void prefs_display_header_create(void)
147 {
148         GtkWidget *window;
149         GtkWidget *vbox;
150         GtkWidget *btn_hbox;
151         GtkWidget *ok_btn;
152         GtkWidget *cancel_btn;
153         GtkWidget *confirm_area;
154
155         GtkWidget *vbox1;
156
157         GtkWidget *hbox1;
158         GtkWidget *hdr_label;
159         GtkWidget *hdr_combo;
160
161         GtkWidget *btn_vbox;
162         GtkWidget *reg_btn;
163         GtkWidget *del_btn;
164         GtkWidget *up_btn;
165         GtkWidget *down_btn;
166
167         GtkWidget *clist_hbox;
168         GtkWidget *clist_hbox1;
169         GtkWidget *clist_hbox2;
170         GtkWidget *clist_scrolledwin;
171         GtkWidget *headers_clist;
172         GtkWidget *hidden_headers_clist;
173
174         GtkWidget *checkbtn_other_headers;
175
176         gchar *title[1];
177
178         debug_print("Creating display header setting window...\n");
179
180         window = gtk_window_new (GTK_WINDOW_DIALOG);
181         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
182         gtk_window_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
183         gtk_window_set_modal (GTK_WINDOW (window), TRUE);
184         gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, FALSE);
185
186         vbox = gtk_vbox_new (FALSE, 6);
187         gtk_widget_show (vbox);
188         gtk_container_add (GTK_CONTAINER (window), vbox);
189
190         btn_hbox = gtk_hbox_new (FALSE, 8);
191         gtk_widget_show (btn_hbox);
192         gtk_box_pack_end (GTK_BOX (vbox), btn_hbox, FALSE, FALSE, 0);
193
194         gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
195                                 &cancel_btn, _("Cancel"), NULL, NULL);
196         gtk_widget_show (confirm_area);
197         gtk_box_pack_end (GTK_BOX(btn_hbox), confirm_area, FALSE, FALSE, 0);
198         gtk_widget_grab_default (ok_btn);
199
200         gtk_window_set_title (GTK_WINDOW(window),
201                               _("Displayed header configuration"));
202         MANAGE_WINDOW_SIGNALS_CONNECT(window);
203         gtk_signal_connect (GTK_OBJECT(window), "delete_event",
204                             GTK_SIGNAL_FUNC(prefs_display_header_deleted),
205                             NULL);
206         gtk_signal_connect (GTK_OBJECT(window), "key_press_event",
207                             GTK_SIGNAL_FUNC(prefs_display_header_key_pressed),
208                             NULL);
209         gtk_signal_connect (GTK_OBJECT(ok_btn), "clicked",
210                             GTK_SIGNAL_FUNC(prefs_display_header_ok),
211                             NULL);
212         gtk_signal_connect (GTK_OBJECT(cancel_btn), "clicked",
213                             GTK_SIGNAL_FUNC(prefs_display_header_cancel),
214                             NULL);
215
216         vbox1 = gtk_vbox_new (FALSE, VSPACING);
217         gtk_widget_show (vbox1);
218         gtk_box_pack_start (GTK_BOX (vbox), vbox1, TRUE, TRUE, 0);
219         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
220
221         hbox1 = gtk_hbox_new (FALSE, 8);
222         gtk_widget_show (hbox1);
223         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, TRUE, 0);
224
225         hdr_label = gtk_label_new (_("Header name"));
226         gtk_widget_show (hdr_label);
227         gtk_box_pack_start (GTK_BOX (hbox1), hdr_label, FALSE, FALSE, 0);
228
229         hdr_combo = gtk_combo_new ();
230         gtk_widget_show (hdr_combo);
231         gtk_box_pack_start (GTK_BOX (hbox1), hdr_combo, TRUE, TRUE, 0);
232         gtk_widget_set_usize (hdr_combo, 150, -1);
233         gtkut_combo_set_items (GTK_COMBO (hdr_combo),
234                                "From", "To", "Cc", "Subject", "Date",
235                                "Reply-To", "Sender", "User-Agent", "X-Mailer",
236                                NULL);
237
238         clist_hbox = gtk_hbox_new (FALSE, 10);
239         gtk_widget_show (clist_hbox);
240         gtk_box_pack_start (GTK_BOX (vbox1), clist_hbox, TRUE, TRUE, 0);
241
242         /* display headers list */
243
244         clist_hbox1 = gtk_hbox_new (FALSE, 8);
245         gtk_widget_show (clist_hbox1);
246         gtk_box_pack_start (GTK_BOX (clist_hbox), clist_hbox1, TRUE, TRUE, 0);
247
248         clist_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
249         gtk_widget_set_usize (clist_scrolledwin, 200, 210);
250         gtk_widget_show (clist_scrolledwin);
251         gtk_box_pack_start (GTK_BOX (clist_hbox1), clist_scrolledwin,
252                             TRUE, TRUE, 0);
253         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (clist_scrolledwin),
254                                         GTK_POLICY_AUTOMATIC,
255                                         GTK_POLICY_AUTOMATIC);
256
257         title[0] = _("Displayed Headers");
258         headers_clist = gtk_clist_new_with_titles(1, title);
259         gtk_widget_show (headers_clist);
260         gtk_container_add (GTK_CONTAINER (clist_scrolledwin), headers_clist);
261         gtk_clist_set_selection_mode (GTK_CLIST (headers_clist),
262                                       GTK_SELECTION_BROWSE);
263         gtk_clist_set_reorderable (GTK_CLIST (headers_clist), TRUE);
264         gtk_clist_set_use_drag_icons (GTK_CLIST (headers_clist), FALSE);
265         GTK_WIDGET_UNSET_FLAGS (GTK_CLIST (headers_clist)->column[0].button,
266                                 GTK_CAN_FOCUS);
267         gtk_signal_connect_after
268                 (GTK_OBJECT (headers_clist), "row_move",
269                  GTK_SIGNAL_FUNC (prefs_display_header_row_moved), NULL);
270
271         btn_vbox = gtk_vbox_new (FALSE, 8);
272         gtk_widget_show (btn_vbox);
273         gtk_box_pack_start (GTK_BOX (clist_hbox1), btn_vbox, FALSE, FALSE, 0);
274
275         reg_btn = gtk_button_new_with_label (_("Add"));
276         gtk_widget_show (reg_btn);
277         gtk_box_pack_start (GTK_BOX (btn_vbox), reg_btn, FALSE, TRUE, 0);
278         gtk_signal_connect (GTK_OBJECT (reg_btn), "clicked",
279                             GTK_SIGNAL_FUNC (prefs_display_header_register_cb),
280                             GINT_TO_POINTER(FALSE));
281         del_btn = gtk_button_new_with_label (_("Delete"));
282         gtk_widget_show (del_btn);
283         gtk_box_pack_start (GTK_BOX (btn_vbox), del_btn, FALSE, TRUE, 0);
284         gtk_signal_connect (GTK_OBJECT (del_btn), "clicked",
285                             GTK_SIGNAL_FUNC (prefs_display_header_delete_cb),
286                             headers_clist);
287
288         up_btn = gtk_button_new_with_label (_("Up"));
289         gtk_widget_show (up_btn);
290         gtk_box_pack_start (GTK_BOX (btn_vbox), up_btn, FALSE, FALSE, 0);
291         gtk_signal_connect (GTK_OBJECT (up_btn), "clicked",
292                             GTK_SIGNAL_FUNC (prefs_display_header_up), NULL);
293
294         down_btn = gtk_button_new_with_label (_("Down"));
295         gtk_widget_show (down_btn);
296         gtk_box_pack_start (GTK_BOX (btn_vbox), down_btn, FALSE, FALSE, 0);
297         gtk_signal_connect (GTK_OBJECT (down_btn), "clicked",
298                             GTK_SIGNAL_FUNC (prefs_display_header_down), NULL);
299
300         /* hidden headers list */
301
302         clist_hbox2 = gtk_hbox_new (FALSE, 8);
303         gtk_widget_show (clist_hbox2);
304         gtk_box_pack_start (GTK_BOX (clist_hbox), clist_hbox2, TRUE, TRUE, 0);
305
306         clist_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
307         gtk_widget_set_usize (clist_scrolledwin, 200, 210);
308         gtk_widget_show (clist_scrolledwin);
309         gtk_box_pack_start (GTK_BOX (clist_hbox2), clist_scrolledwin,
310                             TRUE, TRUE, 0);
311         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (clist_scrolledwin),
312                                         GTK_POLICY_AUTOMATIC,
313                                         GTK_POLICY_AUTOMATIC);
314
315         title[0] = _("Hidden headers");
316         hidden_headers_clist = gtk_clist_new_with_titles(1, title);
317         gtk_widget_show (hidden_headers_clist);
318         gtk_container_add (GTK_CONTAINER (clist_scrolledwin),
319                            hidden_headers_clist);
320         gtk_clist_set_selection_mode (GTK_CLIST (hidden_headers_clist),
321                                       GTK_SELECTION_BROWSE);
322         gtk_clist_set_auto_sort(GTK_CLIST (hidden_headers_clist), TRUE);
323         GTK_WIDGET_UNSET_FLAGS (GTK_CLIST (hidden_headers_clist)->
324                                 column[0].button, GTK_CAN_FOCUS);
325
326         btn_vbox = gtk_vbox_new (FALSE, 8);
327         gtk_widget_show (btn_vbox);
328         gtk_box_pack_start (GTK_BOX (clist_hbox2), btn_vbox, FALSE, FALSE, 0);
329
330         reg_btn = gtk_button_new_with_label (_("Add"));
331         gtk_widget_show (reg_btn);
332         gtk_box_pack_start (GTK_BOX (btn_vbox), reg_btn, FALSE, TRUE, 0);
333         gtk_signal_connect (GTK_OBJECT (reg_btn), "clicked",
334                             GTK_SIGNAL_FUNC
335                             (prefs_display_header_register_cb),
336                             GINT_TO_POINTER(TRUE));
337         del_btn = gtk_button_new_with_label (_("Delete"));
338         gtk_widget_show (del_btn);
339         gtk_box_pack_start (GTK_BOX (btn_vbox), del_btn, FALSE, TRUE, 0);
340         gtk_signal_connect (GTK_OBJECT (del_btn), "clicked",
341                             GTK_SIGNAL_FUNC (prefs_display_header_delete_cb),
342                             hidden_headers_clist);
343
344         PACK_CHECK_BUTTON (btn_hbox, checkbtn_other_headers,
345                            _("Show all unspecified headers"));
346         SET_TOGGLE_SENSITIVITY (checkbtn_other_headers, clist_hbox2);
347
348         gtk_widget_show_all(window);
349
350         dispheader.window        = window;
351         dispheader.ok_btn        = ok_btn;
352         dispheader.cancel_btn    = cancel_btn;
353
354         dispheader.hdr_combo     = hdr_combo;
355         dispheader.hdr_entry     = GTK_COMBO (hdr_combo)->entry;
356
357         dispheader.headers_clist        = headers_clist;
358         dispheader.hidden_headers_clist = hidden_headers_clist;
359
360         dispheader.other_headers = checkbtn_other_headers;
361 }
362
363 void prefs_display_header_read_config(void)
364 {
365         gchar *rcpath;
366         FILE *fp;
367         gchar buf[PREFSBUFSIZE];
368         DisplayHeaderProp *dp;
369
370         debug_print("Reading configuration for displaying headers...\n");
371
372         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
373                              DISPLAY_HEADER_RC, NULL);
374         if ((fp = fopen(rcpath, "rb")) == NULL) {
375                 if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
376                 g_free(rcpath);
377                 prefs_common.disphdr_list = NULL;
378                 prefs_display_header_set_default();
379                 return;
380         }
381         g_free(rcpath);
382
383         /* remove all previous headers list */
384         while (prefs_common.disphdr_list != NULL) {
385                 dp = (DisplayHeaderProp *)prefs_common.disphdr_list->data;
386                 display_header_prop_free(dp);
387                 prefs_common.disphdr_list =
388                         g_slist_remove(prefs_common.disphdr_list, dp);
389         }
390
391         while (fgets(buf, sizeof(buf), fp) != NULL) {
392                 g_strdelimit(buf, "\r\n", '\0');
393                 dp = display_header_prop_read_str(buf);
394                 if (dp)
395                         prefs_common.disphdr_list =
396                                 g_slist_append(prefs_common.disphdr_list, dp);
397         }
398
399         fclose(fp);
400 }
401
402 void prefs_display_header_write_config(void)
403 {
404         gchar *rcpath;
405         PrefFile *pfile;
406         GSList *cur;
407
408         debug_print("Writing configuration for displaying headers...\n");
409
410         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
411                              DISPLAY_HEADER_RC, NULL);
412
413         if ((pfile = prefs_write_open(rcpath)) == NULL) {
414                 g_warning("failed to write configuration to file\n");
415                 g_free(rcpath);
416                 return;
417         }
418
419         for (cur = prefs_common.disphdr_list; cur != NULL;
420              cur = cur->next) {
421                 DisplayHeaderProp *dp = (DisplayHeaderProp *)cur->data;
422                 gchar *dpstr;
423
424                 dpstr = display_header_prop_get_str(dp);
425                 if (fputs(dpstr, pfile->fp) == EOF ||
426                     fputc('\n', pfile->fp) == EOF) {
427                         FILE_OP_ERROR(rcpath, "fputs || fputc");
428                         prefs_file_close_revert(pfile);
429                         g_free(rcpath);
430                         g_free(dpstr);
431                         return;
432                 }
433                 g_free(dpstr);
434         }
435
436         g_free(rcpath);
437
438         if (prefs_file_close(pfile) < 0) {
439                 g_warning("failed to write configuration to file\n");
440                 return;
441         }
442 }
443
444 static void prefs_display_header_set_dialog(void)
445 {
446         GtkCList *clist = GTK_CLIST(dispheader.headers_clist);
447         GtkCList *hidden_clist = GTK_CLIST(dispheader.hidden_headers_clist);
448         GSList *cur;
449         gchar *dp_str[1];
450         gint row;
451
452         gtk_clist_freeze(clist);
453         gtk_clist_freeze(hidden_clist);
454
455         gtk_clist_clear(clist);
456         gtk_clist_clear(hidden_clist);
457
458         for (cur = prefs_common.disphdr_list; cur != NULL;
459              cur = cur->next) {
460                 DisplayHeaderProp *dp = (DisplayHeaderProp *)cur->data;
461
462                 dp_str[0] = dp->name;
463
464                 if (dp->hidden) {
465                         row = gtk_clist_append(hidden_clist, dp_str);
466                         gtk_clist_set_row_data(hidden_clist, row, dp);
467                 } else {
468                         row = gtk_clist_append(clist, dp_str);
469                         gtk_clist_set_row_data(clist, row, dp);
470                 }
471         }
472
473         gtk_clist_thaw(hidden_clist);
474         gtk_clist_thaw(clist);
475
476         gtk_toggle_button_set_active
477                 (GTK_TOGGLE_BUTTON(dispheader.other_headers),
478                  prefs_common.show_other_header);
479 }
480
481 static void prefs_display_header_set_list()
482 {
483         gint row = 0;
484         DisplayHeaderProp *dp;
485
486         g_slist_free(prefs_common.disphdr_list);
487         prefs_common.disphdr_list = NULL;
488
489         while ((dp = gtk_clist_get_row_data
490                 (GTK_CLIST(dispheader.headers_clist), row)) != NULL) {
491                 prefs_common.disphdr_list =
492                         g_slist_append(prefs_common.disphdr_list, dp);
493                 row++;
494         }
495
496         row = 0;
497         while ((dp = gtk_clist_get_row_data
498                 (GTK_CLIST(dispheader.hidden_headers_clist), row)) != NULL) {
499                 prefs_common.disphdr_list =
500                         g_slist_append(prefs_common.disphdr_list, dp);
501                 row++;
502         }
503 }
504
505 static gint prefs_display_header_find_header(GtkCList *clist,
506                                              const gchar *header)
507 {
508         gint row = 0;
509         DisplayHeaderProp *dp;
510
511         while ((dp = gtk_clist_get_row_data(clist, row)) != NULL) {
512                 if (g_strcasecmp(dp->name, header) == 0)
513                         return row;
514                 row++;
515         }
516
517         return -1;
518 }
519
520 static gint prefs_display_header_clist_set_row(gboolean hidden)
521 {
522         GtkCList *clist;
523         DisplayHeaderProp *dp;
524         gchar *entry_text;
525         gchar *dp_str[1];
526         gint row;
527
528         entry_text = gtk_entry_get_text(GTK_ENTRY(dispheader.hdr_entry));
529         if (entry_text[0] == '\0') {
530                 alertpanel_error(_("Header name is not set."));
531                 return -1;
532         }
533
534         if (hidden)
535                 clist = GTK_CLIST(dispheader.hidden_headers_clist);
536         else
537                 clist = GTK_CLIST(dispheader.headers_clist);
538
539         if (prefs_display_header_find_header(clist, entry_text) != -1) {
540                 alertpanel_error(_("This header is already in the list."));
541                 return -1;
542         }
543
544         dp = g_new0(DisplayHeaderProp, 1);
545
546         dp->name = g_strdup(entry_text);
547         dp->hidden = hidden;
548
549         dp_str[0] = dp->name;
550         row = gtk_clist_append(clist, dp_str);
551         gtk_clist_set_row_data(clist, row, dp);
552
553         prefs_display_header_set_list();
554
555         return row;
556 }
557
558 static void prefs_display_header_register_cb(GtkButton *btn,
559                                              gpointer hidden_data)
560 {
561         prefs_display_header_clist_set_row(GPOINTER_TO_INT(hidden_data));
562 }
563
564 static void prefs_display_header_delete_cb(GtkButton *btn, gpointer clist_data)
565 {
566         GtkCList *clist = GTK_CLIST(clist_data);
567         DisplayHeaderProp *dp;
568         gint row;
569
570         if (!clist->selection) return;
571         row = GPOINTER_TO_INT(clist->selection->data);
572
573         dp = gtk_clist_get_row_data(clist, row);
574         display_header_prop_free(dp);
575         gtk_clist_remove(clist, row);
576         prefs_common.disphdr_list =
577                 g_slist_remove(prefs_common.disphdr_list, dp);
578 }
579
580 static void prefs_display_header_up(void)
581 {
582         GtkCList *clist = GTK_CLIST(dispheader.headers_clist);
583         gint row;
584
585         if (!clist->selection) return;
586
587         row = GPOINTER_TO_INT(clist->selection->data);
588         if (row > 0)
589                 gtk_clist_row_move(clist, row, row - 1);
590 }
591
592 static void prefs_display_header_down(void)
593 {
594         GtkCList *clist = GTK_CLIST(dispheader.headers_clist);
595         gint row;
596
597         if (!clist->selection) return;
598
599         row = GPOINTER_TO_INT(clist->selection->data);
600         if (row >= 0 && row < clist->rows - 1)
601                 gtk_clist_row_move(clist, row, row + 1);
602 }
603
604 static void prefs_display_header_row_moved(GtkCList *clist, gint source_row,
605                                            gint dest_row, gpointer data)
606 {
607         prefs_display_header_set_list();
608 }
609
610 static void prefs_display_header_key_pressed(GtkWidget *widget,
611                                              GdkEventKey *event,
612                                              gpointer data)
613 {
614         if (event && event->keyval == GDK_Escape)
615                 prefs_display_header_cancel();
616 }
617
618 static void prefs_display_header_ok(void)
619 {
620         prefs_common.show_other_header =
621                 gtk_toggle_button_get_active
622                         (GTK_TOGGLE_BUTTON(dispheader.other_headers));
623         prefs_display_header_write_config();
624         gtk_widget_hide(dispheader.window);
625 }
626
627 static void prefs_display_header_cancel(void)
628 {
629         prefs_display_header_read_config();
630         gtk_widget_hide(dispheader.window);
631 }
632
633 static gint prefs_display_header_deleted(GtkWidget *widget, GdkEventAny *event,
634                                          gpointer data)
635 {
636         prefs_display_header_cancel();
637         return TRUE;
638 }