fcea198db72b35730429d0b104163d12c2b91175
[claws.git] / src / prefs_customheader.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 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 "main.h"
36 #include "prefs.h"
37 #include "prefs_customheader.h"
38 #include "prefs_common.h"
39 #include "prefs_account.h"
40 #include "mainwindow.h"
41 #include "foldersel.h"
42 #include "manage_window.h"
43 #include "customheader.h"
44 #include "folder.h"
45 #include "utils.h"
46 #include "gtkutils.h"
47 #include "alertpanel.h"
48
49 static struct Headers {
50         GtkWidget *window;
51
52         GtkWidget *ok_btn;
53         GtkWidget *cancel_btn;
54
55         GtkWidget *hdr_combo;
56         GtkWidget *hdr_entry;
57         GtkWidget *key_entry;
58         GtkWidget *headers_clist;
59 } headers;
60
61 #define VSPACING                12
62 #define VSPACING_NARROW         4
63 #define DEFAULT_ENTRY_WIDTH     80
64 #define PREFSBUFSIZE            1024
65
66 /* widget creating functions */
67 static void prefs_headers_create        (void);
68
69 static void prefs_headers_set_dialog    (PrefsAccount *ac);
70 static void prefs_headers_set_list      (PrefsAccount *ac);
71 static gint prefs_headers_clist_set_row (PrefsAccount *ac,
72                                          gint          row);
73
74 /* callback functions */
75 static void prefs_headers_register_cb   (void);
76 static void prefs_headers_substitute_cb (void);
77 static void prefs_headers_delete_cb     (void);
78 static void prefs_headers_up            (void);
79 static void prefs_headers_down          (void);
80 static void prefs_headers_select        (GtkCList       *clist,
81                                          gint            row,
82                                          gint            column,
83                                          GdkEvent       *event);
84
85 static void prefs_headers_key_pressed   (GtkWidget      *widget,
86                                          GdkEventKey    *event,
87                                          gpointer        data);
88 static void prefs_headers_ok            (GtkButton      *button);
89 static void prefs_headers_cancel        (GtkButton      *button);
90 static gint prefs_headers_deleted       (GtkWidget      *widget,
91                                          GdkEventAny    *event,
92                                          gpointer        data);
93
94 static PrefsAccount *cur_ac = NULL;
95
96 void prefs_headers_open(PrefsAccount *ac)
97 {
98         if (!headers.window) {
99                 prefs_headers_create();
100         }
101
102         manage_window_set_transient(GTK_WINDOW(headers.window));
103         gtk_widget_grab_focus(headers.ok_btn);
104
105         prefs_headers_set_dialog(ac);
106
107         cur_ac = ac;
108
109         gtk_widget_show(headers.window);
110 }
111
112 static void prefs_headers_create(void)
113 {
114         GtkWidget *window;
115         GtkWidget *vbox;
116
117         GtkWidget *ok_btn;
118         GtkWidget *cancel_btn;
119
120         GtkWidget *confirm_area;
121
122         GtkWidget *vbox1;
123
124         GtkWidget *table1;
125         GtkWidget *hdr_label;
126         GtkWidget *hdr_combo;
127         GtkWidget *key_label;
128         GtkWidget *key_entry;
129
130         GtkWidget *reg_hbox;
131         GtkWidget *btn_hbox;
132         GtkWidget *arrow;
133         GtkWidget *reg_btn;
134         GtkWidget *subst_btn;
135         GtkWidget *del_btn;
136
137         GtkWidget *ch_hbox;
138         GtkWidget *ch_scrolledwin;
139         GtkWidget *headers_clist;
140
141         GtkWidget *btn_vbox;
142         GtkWidget *up_btn;
143         GtkWidget *down_btn;
144
145         gchar *title[] = {_("Custom headers")};
146
147         debug_print(_("Creating headers setting window...\n"));
148
149         window = gtk_window_new (GTK_WINDOW_DIALOG);
150         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
151         gtk_window_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
152         gtk_window_set_modal (GTK_WINDOW (window), TRUE);
153         gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, FALSE);
154
155         vbox = gtk_vbox_new (FALSE, 6);
156         gtk_widget_show (vbox);
157         gtk_container_add (GTK_CONTAINER (window), vbox);
158
159         gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
160                                 &cancel_btn, _("Cancel"), NULL, NULL);
161         gtk_widget_show (confirm_area);
162         gtk_box_pack_end (GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
163         gtk_widget_grab_default (ok_btn);
164
165         gtk_window_set_title (GTK_WINDOW(window),
166                               _("Headers setting"));
167         gtk_signal_connect (GTK_OBJECT(window), "delete_event",
168                             GTK_SIGNAL_FUNC(prefs_headers_deleted), NULL);
169         gtk_signal_connect (GTK_OBJECT(window), "key_press_event",
170                             GTK_SIGNAL_FUNC(prefs_headers_key_pressed), NULL);
171         gtk_signal_connect (GTK_OBJECT(window), "focus_in_event",
172                             GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
173         gtk_signal_connect (GTK_OBJECT(window), "focus_out_event",
174                             GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
175         gtk_signal_connect (GTK_OBJECT(ok_btn), "clicked",
176                             GTK_SIGNAL_FUNC(prefs_headers_ok), NULL);
177         gtk_signal_connect (GTK_OBJECT(cancel_btn), "clicked",
178                             GTK_SIGNAL_FUNC(prefs_headers_cancel), NULL);
179
180         vbox1 = gtk_vbox_new (FALSE, VSPACING);
181         gtk_widget_show (vbox1);
182         gtk_box_pack_start (GTK_BOX (vbox), vbox1, TRUE, TRUE, 0);
183         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
184
185         table1 = gtk_table_new (2, 2, FALSE);
186         gtk_widget_show (table1);
187         gtk_box_pack_start (GTK_BOX (vbox1), table1,
188                             FALSE, FALSE, 0);
189         gtk_table_set_row_spacings (GTK_TABLE (table1), 8);
190         gtk_table_set_col_spacings (GTK_TABLE (table1), 8);
191
192         hdr_label = gtk_label_new (_("Header"));
193         gtk_widget_show (hdr_label);
194         gtk_table_attach (GTK_TABLE (table1), hdr_label, 0, 1, 0, 1,
195                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
196                           0, 0, 0);
197         gtk_misc_set_alignment (GTK_MISC (hdr_label), 0, 0.5);
198         
199         hdr_combo = gtk_combo_new ();
200         gtk_widget_show (hdr_combo);
201         gtk_table_attach (GTK_TABLE (table1), hdr_combo, 0, 1, 1, 2,
202                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
203                           0, 0, 0);
204         gtk_widget_set_usize (hdr_combo, 150 /* 96 */, -1);
205         gtkut_combo_set_items (GTK_COMBO (hdr_combo),
206                                "User-Agent", "X-Operating-System", NULL);
207
208         key_label = gtk_label_new (_("Value"));
209         gtk_widget_show (key_label);
210         gtk_table_attach (GTK_TABLE (table1), key_label, 1, 2, 0, 1,
211                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
212                           0, 0, 0);
213         gtk_misc_set_alignment (GTK_MISC (key_label), 0, 0.5);
214         
215         key_entry = gtk_entry_new ();
216         gtk_widget_show (key_entry);
217         gtk_table_attach (GTK_TABLE (table1), key_entry, 1, 2, 1, 2,
218                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
219                           0, 0, 0);
220
221         /* register / substitute / delete */
222
223         reg_hbox = gtk_hbox_new (FALSE, 4);
224         gtk_widget_show (reg_hbox);
225         gtk_box_pack_start (GTK_BOX (vbox1), reg_hbox,
226                             FALSE, FALSE, 0);
227
228         arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
229         gtk_widget_show (arrow);
230         gtk_box_pack_start (GTK_BOX (reg_hbox), arrow, FALSE, FALSE, 0);
231         gtk_widget_set_usize (arrow, -1, 16);
232
233         btn_hbox = gtk_hbox_new (TRUE, 4);
234         gtk_widget_show (btn_hbox);
235         gtk_box_pack_start (GTK_BOX (reg_hbox), btn_hbox, FALSE, FALSE, 0);
236
237         reg_btn = gtk_button_new_with_label (_("Add"));
238         gtk_widget_show (reg_btn);
239         gtk_box_pack_start (GTK_BOX (btn_hbox), reg_btn, FALSE, TRUE, 0);
240         gtk_signal_connect (GTK_OBJECT (reg_btn), "clicked",
241                             GTK_SIGNAL_FUNC (prefs_headers_register_cb), NULL);
242
243         subst_btn = gtk_button_new_with_label (_(" Substitute "));
244         gtk_widget_show (subst_btn);
245         gtk_box_pack_start (GTK_BOX (btn_hbox), subst_btn, FALSE, TRUE, 0);
246         gtk_signal_connect (GTK_OBJECT (subst_btn), "clicked",
247                             GTK_SIGNAL_FUNC (prefs_headers_substitute_cb),
248                             NULL);
249
250         del_btn = gtk_button_new_with_label (_("Delete"));
251         gtk_widget_show (del_btn);
252         gtk_box_pack_start (GTK_BOX (btn_hbox), del_btn, FALSE, TRUE, 0);
253         gtk_signal_connect (GTK_OBJECT (del_btn), "clicked",
254                             GTK_SIGNAL_FUNC (prefs_headers_delete_cb), NULL);
255
256
257         ch_hbox = gtk_hbox_new (FALSE, 8);
258         gtk_widget_show (ch_hbox);
259         gtk_box_pack_start (GTK_BOX (vbox1), ch_hbox,
260                             TRUE, TRUE, 0);
261
262         ch_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
263         gtk_widget_set_usize (ch_scrolledwin, -1, 100);
264         gtk_widget_show (ch_scrolledwin);
265         gtk_box_pack_start (GTK_BOX (ch_hbox), ch_scrolledwin,
266                             TRUE, TRUE, 0);
267         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (ch_scrolledwin),
268                                         GTK_POLICY_AUTOMATIC,
269                                         GTK_POLICY_AUTOMATIC);
270
271         headers_clist = gtk_clist_new_with_titles(1, title);
272         gtk_widget_show (headers_clist);
273         gtk_container_add (GTK_CONTAINER (ch_scrolledwin), headers_clist);
274         gtk_clist_set_column_width (GTK_CLIST (headers_clist), 0, 80);
275         gtk_clist_set_selection_mode (GTK_CLIST (headers_clist),
276                                       GTK_SELECTION_BROWSE);
277         GTK_WIDGET_UNSET_FLAGS (GTK_CLIST (headers_clist)->column[0].button,
278                                 GTK_CAN_FOCUS);
279         gtk_signal_connect (GTK_OBJECT (headers_clist), "select_row",
280                             GTK_SIGNAL_FUNC (prefs_headers_select),
281                             NULL);
282
283
284         btn_vbox = gtk_vbox_new (FALSE, 8);
285         gtk_widget_show (btn_vbox);
286         gtk_box_pack_start (GTK_BOX (ch_hbox), btn_vbox, FALSE, FALSE, 0);
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_headers_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_headers_down), NULL);
299
300         gtk_widget_show_all(window);
301
302         headers.window     = window;
303         headers.ok_btn     = ok_btn;
304         headers.cancel_btn = cancel_btn;
305
306         headers.hdr_combo  = hdr_combo;
307         headers.hdr_entry  = GTK_COMBO (hdr_combo)->entry;
308         headers.key_entry  = key_entry;
309
310         headers.headers_clist   = headers_clist;
311 }
312
313 void prefs_headers_read_config(PrefsAccount *ac)
314 {
315         gchar *rcpath;
316         FILE *fp;
317         gchar buf[PREFSBUFSIZE];
318         CustomHeader *ch;
319
320         debug_print(_("Reading headers configuration...\n"));
321
322         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
323                              CUSTOM_HEADER_RC, NULL);
324         if ((fp = fopen(rcpath, "r")) == NULL) {
325                 if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
326                 g_free(rcpath);
327                 ac->customhdr_list = NULL;
328                 return;
329         }
330         g_free(rcpath);
331
332         /* remove all previous headers list */
333         while (ac->customhdr_list != NULL) {
334                 ch = (CustomHeader *)ac->customhdr_list->data;
335                 custom_header_free(ch);
336                 ac->customhdr_list = g_slist_remove(ac->customhdr_list, ch);
337         }
338
339         while (fgets(buf, sizeof(buf), fp) != NULL) {
340                 g_strchomp(buf);
341                 ch = custom_header_read_str(buf);
342                 if (ch) {
343                         if (ch->account_id == ac->account_id) {
344                                 ac->customhdr_list =
345                                         g_slist_append(ac->customhdr_list, ch);
346                         } else
347                                 custom_header_free(ch);
348                 }
349         }
350
351         fclose(fp);
352 }
353
354 void prefs_headers_write_config(PrefsAccount *ac)
355 {
356         gchar *rcpath;
357         PrefFile *pfile;
358         GSList *cur;
359         gchar buf[PREFSBUFSIZE];
360         FILE * fp;
361         CustomHeader *ch;
362
363         GSList *all_hdrs = NULL;
364
365         debug_print(_("Writing headers configuration...\n"));
366
367         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
368                              CUSTOM_HEADER_RC, NULL);
369
370         if ((fp = fopen(rcpath, "r")) == NULL) {
371                 if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
372         } else {
373                 all_hdrs = NULL;
374
375                 while (fgets(buf, sizeof(buf), fp) != NULL) {
376                         g_strchomp(buf);
377                         ch = custom_header_read_str(buf);
378                         if (ch) {
379                                 if (ch->account_id != ac->account_id)
380                                         all_hdrs =
381                                                 g_slist_append(all_hdrs, ch);
382                                 else
383                                         custom_header_free(ch);
384                         }
385                 }
386
387                 fclose(fp);
388         }
389
390         if ((pfile = prefs_write_open(rcpath)) == NULL) {
391                 g_warning(_("failed to write configuration to file\n"));
392                 g_free(rcpath);
393                 return;
394         }
395
396         for (cur = all_hdrs; cur != NULL; cur = cur->next) {
397                 CustomHeader *hdr = (CustomHeader *)cur->data;
398                 gchar *chstr;
399
400                 chstr = custom_header_get_str(hdr);
401                 if (fputs(chstr, pfile->fp) == EOF ||
402                     fputc('\n', pfile->fp) == EOF) {
403                         FILE_OP_ERROR(rcpath, "fputs || fputc");
404                         prefs_write_close_revert(pfile);
405                         g_free(rcpath);
406                         g_free(chstr);
407                         return;
408                 }
409                 g_free(chstr);
410         }
411
412         for (cur = ac->customhdr_list; cur != NULL; cur = cur->next) {
413                 CustomHeader *hdr = (CustomHeader *)cur->data;
414                 gchar *chstr;
415
416                 chstr = custom_header_get_str(hdr);
417                 if (fputs(chstr, pfile->fp) == EOF ||
418                     fputc('\n', pfile->fp) == EOF) {
419                         FILE_OP_ERROR(rcpath, "fputs || fputc");
420                         prefs_write_close_revert(pfile);
421                         g_free(rcpath);
422                         g_free(chstr);
423                         return;
424                 }
425                 g_free(chstr);
426         }
427
428         g_free(rcpath);
429
430         while (all_hdrs != NULL) {
431                 ch = (CustomHeader *)all_hdrs->data;
432                 custom_header_free(ch);
433                 all_hdrs = g_slist_remove(all_hdrs, ch);
434         }
435
436         if (prefs_write_close(pfile) < 0) {
437                 g_warning(_("failed to write configuration to file\n"));
438                 return;
439         }
440 }
441
442 static void prefs_headers_set_dialog(PrefsAccount *ac)
443 {
444         GtkCList *clist = GTK_CLIST(headers.headers_clist);
445         GSList *cur;
446         gchar *ch_str[1];
447         gint row;
448
449         gtk_clist_freeze(clist);
450         gtk_clist_clear(clist);
451
452         ch_str[0] = _("(New)");
453         row = gtk_clist_append(clist, ch_str);
454         gtk_clist_set_row_data(clist, row, NULL);
455
456         for (cur = ac->customhdr_list; cur != NULL; cur = cur->next) {
457                 CustomHeader *ch = (CustomHeader *)cur->data;
458
459                 ch_str[0] = g_strdup_printf("%s: %s", ch->name, ch->value);
460                 row = gtk_clist_append(clist, ch_str);
461                 gtk_clist_set_row_data(clist, row, ch);
462
463                 g_free(ch_str[0]);
464         }
465
466         gtk_clist_thaw(clist);
467 }
468
469 static void prefs_headers_set_list(PrefsAccount *ac)
470 {
471         gint row = 1;
472         CustomHeader *ch;
473
474         g_slist_free(ac->customhdr_list);
475         ac->customhdr_list = NULL;
476
477         while ((ch = gtk_clist_get_row_data(GTK_CLIST(headers.headers_clist),
478                 row)) != NULL) {
479                 ac->customhdr_list = g_slist_append(ac->customhdr_list,
480                                                       ch);
481                 row++;
482         }
483 }
484
485 static gint prefs_headers_clist_set_row(PrefsAccount *ac, gint row)
486 {
487         GtkCList *clist = GTK_CLIST(headers.headers_clist);
488         CustomHeader *ch;
489         gchar *entry_text;
490         gchar *ch_str[1];
491
492         g_return_val_if_fail(row != 0, -1);
493
494         entry_text = gtk_entry_get_text(GTK_ENTRY(headers.hdr_entry));
495         if (entry_text[0] == '\0') {
496                 alertpanel_error(_("Header name is not set."));
497                 return -1;
498         }
499
500         ch = g_new0(CustomHeader, 1);
501
502         ch->account_id = ac->account_id;
503
504         ch->name = g_strdup(entry_text);
505
506         entry_text = gtk_entry_get_text(GTK_ENTRY(headers.key_entry));
507         if (entry_text[0] != '\0')
508                 ch->value = g_strdup(entry_text);
509
510         ch_str[0] = g_strdup_printf("%s: %s", ch->name, ch->value);
511
512         if (row < 0)
513                 row = gtk_clist_append(clist, ch_str);
514         else {
515                 CustomHeader *tmpch;
516
517                 gtk_clist_set_text(clist, row, 0, ch_str[0]);
518                 tmpch = gtk_clist_get_row_data(clist, row);
519                 if (tmpch)
520                         custom_header_free(tmpch);
521         }
522
523         gtk_clist_set_row_data(clist, row, ch);
524
525         g_free(ch_str[0]);
526
527         prefs_headers_set_list(cur_ac);
528
529         return row;
530 }
531
532 static void prefs_headers_register_cb(void)
533 {
534         prefs_headers_clist_set_row(cur_ac, -1);
535 }
536
537 static void prefs_headers_substitute_cb(void)
538 {
539         GtkCList *clist = GTK_CLIST(headers.headers_clist);
540         CustomHeader *ch;
541         gint row;
542
543         if (!clist->selection) return;
544
545         row = GPOINTER_TO_INT(clist->selection->data);
546         if (row == 0) return;
547
548         ch = gtk_clist_get_row_data(clist, row);
549         if (!ch) return;
550
551         prefs_headers_clist_set_row(cur_ac, row);
552 }
553
554 static void prefs_headers_delete_cb(void)
555 {
556         GtkCList *clist = GTK_CLIST(headers.headers_clist);
557         CustomHeader *ch;
558         gint row;
559
560         if (!clist->selection) return;
561         row = GPOINTER_TO_INT(clist->selection->data);
562         if (row == 0) return;
563
564         if (alertpanel(_("Delete header"),
565                        _("Do you really want to delete this header?"),
566                        _("Yes"), _("No"), NULL) == G_ALERTALTERNATE)
567                 return;
568
569         ch = gtk_clist_get_row_data(clist, row);
570         custom_header_free(ch);
571         gtk_clist_remove(clist, row);
572         cur_ac->customhdr_list = g_slist_remove(cur_ac->customhdr_list, ch);
573 }
574
575 static void prefs_headers_up(void)
576 {
577         GtkCList *clist = GTK_CLIST(headers.headers_clist);
578         gint row;
579
580         if (!clist->selection) return;
581
582         row = GPOINTER_TO_INT(clist->selection->data);
583         if (row > 1) {
584                 gtk_clist_row_move(clist, row, row - 1);
585                 prefs_headers_set_list(cur_ac);
586         }
587 }
588
589 static void prefs_headers_down(void)
590 {
591         GtkCList *clist = GTK_CLIST(headers.headers_clist);
592         gint row;
593
594         if (!clist->selection) return;
595
596         row = GPOINTER_TO_INT(clist->selection->data);
597         if (row > 0 && row < clist->rows - 1) {
598                 gtk_clist_row_move(clist, row, row + 1);
599                 prefs_headers_set_list(cur_ac);
600         }
601 }
602
603 #define ENTRY_SET_TEXT(entry, str) \
604         gtk_entry_set_text(GTK_ENTRY(entry), str ? str : "")
605
606 static void prefs_headers_select(GtkCList *clist, gint row, gint column,
607                                 GdkEvent *event)
608 {
609         CustomHeader *ch;
610         CustomHeader default_ch = { 0, "", NULL };
611  
612         ch = gtk_clist_get_row_data(clist, row);
613         if (!ch)
614                 ch = &default_ch;
615  
616         ENTRY_SET_TEXT(headers.hdr_entry, ch->name);
617         ENTRY_SET_TEXT(headers.key_entry, ch->value);
618 }
619
620 #undef ENTRY_SET_TEXT
621
622 static void prefs_headers_key_pressed(GtkWidget *widget, GdkEventKey *event,
623                                      gpointer data)
624 {
625         if (event && event->keyval == GDK_Escape)
626                 gtk_widget_hide(headers.window);
627 }
628
629 static void prefs_headers_ok(GtkButton *button)
630 {
631         prefs_headers_write_config(cur_ac);
632         gtk_widget_hide(headers.window);
633 }
634
635 static void prefs_headers_cancel(GtkButton *button)
636 {
637         prefs_headers_read_config(cur_ac); 
638         gtk_widget_hide(headers.window);
639 }
640
641 static gint prefs_headers_deleted(GtkWidget *widget, GdkEventAny *event,
642                                   gpointer data)
643 {
644         prefs_headers_cancel(GTK_BUTTON(widget));
645         return TRUE;
646 }