Statistics
| Revision:

root / src / prefs_display_header.c @ 1

History | View | Annotate | Download (17.2 kB)

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