Statistics
| Revision:

root / src / prefs_customheader.c @ 540

History | View | Annotate | Download (13.8 kB)

1 1 hiro
/*
2 1 hiro
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 31 hiro
 * Copyright (C) 1999-2005 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 92 hiro
#include <glib/gi18n.h>
28 1 hiro
#include <gtk/gtk.h>
29 1 hiro
#include <gdk/gdkkeysyms.h>
30 1 hiro
31 1 hiro
#include "main.h"
32 1 hiro
#include "prefs.h"
33 527 hiro
#include "prefs_ui.h"
34 1 hiro
#include "prefs_customheader.h"
35 1 hiro
#include "prefs_common.h"
36 1 hiro
#include "prefs_account.h"
37 1 hiro
#include "mainwindow.h"
38 1 hiro
#include "foldersel.h"
39 1 hiro
#include "manage_window.h"
40 1 hiro
#include "customheader.h"
41 1 hiro
#include "folder.h"
42 1 hiro
#include "utils.h"
43 1 hiro
#include "gtkutils.h"
44 1 hiro
#include "alertpanel.h"
45 1 hiro
46 1 hiro
static struct CustomHdr {
47 1 hiro
        GtkWidget *window;
48 1 hiro
49 1 hiro
        GtkWidget *ok_btn;
50 1 hiro
        GtkWidget *cancel_btn;
51 1 hiro
52 1 hiro
        GtkWidget *hdr_combo;
53 1 hiro
        GtkWidget *hdr_entry;
54 1 hiro
        GtkWidget *val_entry;
55 1 hiro
        GtkWidget *customhdr_clist;
56 1 hiro
} customhdr;
57 1 hiro
58 1 hiro
/* widget creating functions */
59 1 hiro
static void prefs_custom_header_create        (void);
60 1 hiro
61 1 hiro
static void prefs_custom_header_set_dialog        (PrefsAccount *ac);
62 1 hiro
static void prefs_custom_header_set_list        (PrefsAccount *ac);
63 1 hiro
static gint prefs_custom_header_clist_set_row        (PrefsAccount *ac,
64 1 hiro
                                                 gint               row);
65 1 hiro
66 1 hiro
/* callback functions */
67 1 hiro
static void prefs_custom_header_add_cb                (void);
68 1 hiro
static void prefs_custom_header_delete_cb        (void);
69 1 hiro
static void prefs_custom_header_up                (void);
70 1 hiro
static void prefs_custom_header_down                (void);
71 1 hiro
static void prefs_custom_header_select                (GtkCList        *clist,
72 1 hiro
                                                 gint                 row,
73 1 hiro
                                                 gint                 column,
74 1 hiro
                                                 GdkEvent        *event);
75 1 hiro
76 1 hiro
static void prefs_custom_header_row_moved        (GtkCList        *clist,
77 1 hiro
                                                 gint                 source_row,
78 1 hiro
                                                 gint                 dest_row,
79 1 hiro
                                                 gpointer         data);
80 1 hiro
81 1 hiro
static gboolean prefs_custom_header_key_pressed        (GtkWidget        *widget,
82 1 hiro
                                                 GdkEventKey        *event,
83 1 hiro
                                                 gpointer         data);
84 1 hiro
static void prefs_custom_header_ok                (void);
85 1 hiro
static void prefs_custom_header_cancel                (void);
86 1 hiro
static gint prefs_custom_header_deleted                (GtkWidget        *widget,
87 1 hiro
                                                 GdkEventAny        *event,
88 1 hiro
                                                 gpointer         data);
89 1 hiro
90 1 hiro
static PrefsAccount *cur_ac = NULL;
91 1 hiro
92 1 hiro
void prefs_custom_header_open(PrefsAccount *ac)
93 1 hiro
{
94 1 hiro
        if (!customhdr.window) {
95 1 hiro
                prefs_custom_header_create();
96 1 hiro
        }
97 1 hiro
98 1 hiro
        manage_window_set_transient(GTK_WINDOW(customhdr.window));
99 1 hiro
        gtk_widget_grab_focus(customhdr.ok_btn);
100 1 hiro
101 1 hiro
        prefs_custom_header_set_dialog(ac);
102 1 hiro
103 1 hiro
        cur_ac = ac;
104 1 hiro
105 1 hiro
        gtk_widget_show(customhdr.window);
106 1 hiro
}
107 1 hiro
108 1 hiro
static void prefs_custom_header_create(void)
109 1 hiro
{
110 1 hiro
        GtkWidget *window;
111 1 hiro
        GtkWidget *vbox;
112 1 hiro
113 1 hiro
        GtkWidget *ok_btn;
114 1 hiro
        GtkWidget *cancel_btn;
115 1 hiro
116 1 hiro
        GtkWidget *confirm_area;
117 1 hiro
118 1 hiro
        GtkWidget *vbox1;
119 1 hiro
120 1 hiro
        GtkWidget *table1;
121 1 hiro
        GtkWidget *hdr_label;
122 1 hiro
        GtkWidget *hdr_combo;
123 1 hiro
        GtkWidget *val_label;
124 1 hiro
        GtkWidget *val_entry;
125 1 hiro
126 1 hiro
        GtkWidget *reg_hbox;
127 1 hiro
        GtkWidget *btn_hbox;
128 1 hiro
        GtkWidget *arrow;
129 1 hiro
        GtkWidget *add_btn;
130 1 hiro
        GtkWidget *del_btn;
131 1 hiro
132 1 hiro
        GtkWidget *ch_hbox;
133 1 hiro
        GtkWidget *ch_scrolledwin;
134 1 hiro
        GtkWidget *customhdr_clist;
135 1 hiro
136 1 hiro
        GtkWidget *btn_vbox;
137 1 hiro
        GtkWidget *up_btn;
138 1 hiro
        GtkWidget *down_btn;
139 1 hiro
140 1 hiro
        gchar *title[1];
141 1 hiro
142 1 hiro
        debug_print("Creating custom header setting window...\n");
143 1 hiro
144 1 hiro
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
145 1 hiro
        gtk_container_set_border_width (GTK_CONTAINER (window), 8);
146 1 hiro
        gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
147 1 hiro
        gtk_window_set_modal (GTK_WINDOW (window), TRUE);
148 1 hiro
        gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, FALSE);
149 1 hiro
150 1 hiro
        vbox = gtk_vbox_new (FALSE, 6);
151 1 hiro
        gtk_widget_show (vbox);
152 1 hiro
        gtk_container_add (GTK_CONTAINER (window), vbox);
153 1 hiro
154 31 hiro
        gtkut_stock_button_set_create(&confirm_area, &ok_btn, GTK_STOCK_OK,
155 31 hiro
                                      &cancel_btn, GTK_STOCK_CANCEL,
156 31 hiro
                                      NULL, NULL);
157 1 hiro
        gtk_widget_show (confirm_area);
158 1 hiro
        gtk_box_pack_end (GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
159 1 hiro
        gtk_widget_grab_default (ok_btn);
160 1 hiro
161 1 hiro
        gtk_window_set_title (GTK_WINDOW(window), _("Custom header setting"));
162 1 hiro
        MANAGE_WINDOW_SIGNALS_CONNECT (window);
163 1 hiro
        g_signal_connect (G_OBJECT(window), "delete_event",
164 1 hiro
                          G_CALLBACK(prefs_custom_header_deleted),
165 1 hiro
                          NULL);
166 1 hiro
        g_signal_connect (G_OBJECT(window), "key_press_event",
167 1 hiro
                          G_CALLBACK(prefs_custom_header_key_pressed),
168 1 hiro
                          NULL);
169 1 hiro
        g_signal_connect (G_OBJECT(ok_btn), "clicked",
170 1 hiro
                          G_CALLBACK(prefs_custom_header_ok), NULL);
171 1 hiro
        g_signal_connect (G_OBJECT(cancel_btn), "clicked",
172 1 hiro
                          G_CALLBACK(prefs_custom_header_cancel), NULL);
173 1 hiro
174 1 hiro
        vbox1 = gtk_vbox_new (FALSE, VSPACING);
175 1 hiro
        gtk_widget_show (vbox1);
176 1 hiro
        gtk_box_pack_start (GTK_BOX (vbox), vbox1, TRUE, TRUE, 0);
177 1 hiro
        gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
178 1 hiro
179 1 hiro
        table1 = gtk_table_new (2, 2, FALSE);
180 1 hiro
        gtk_widget_show (table1);
181 1 hiro
        gtk_box_pack_start (GTK_BOX (vbox1), table1,
182 1 hiro
                            FALSE, FALSE, 0);
183 1 hiro
        gtk_table_set_row_spacings (GTK_TABLE (table1), 8);
184 1 hiro
        gtk_table_set_col_spacings (GTK_TABLE (table1), 8);
185 1 hiro
186 1 hiro
        hdr_label = gtk_label_new (_("Header"));
187 1 hiro
        gtk_widget_show (hdr_label);
188 1 hiro
        gtk_table_attach (GTK_TABLE (table1), hdr_label, 0, 1, 0, 1,
189 1 hiro
                          GTK_EXPAND | GTK_SHRINK | GTK_FILL,
190 1 hiro
                          0, 0, 0);
191 1 hiro
        gtk_misc_set_alignment (GTK_MISC (hdr_label), 0, 0.5);
192 1 hiro
193 1 hiro
        hdr_combo = gtk_combo_new ();
194 1 hiro
        gtk_widget_show (hdr_combo);
195 1 hiro
        gtk_table_attach (GTK_TABLE (table1), hdr_combo, 0, 1, 1, 2,
196 1 hiro
                          GTK_EXPAND | GTK_SHRINK | GTK_FILL,
197 1 hiro
                          0, 0, 0);
198 1 hiro
        gtk_widget_set_size_request (hdr_combo, 150, -1);
199 1 hiro
        gtkut_combo_set_items (GTK_COMBO (hdr_combo),
200 1 hiro
                               "User-Agent", "X-Face", "X-Operating-System",
201 1 hiro
                               NULL);
202 1 hiro
203 1 hiro
        val_label = gtk_label_new (_("Value"));
204 1 hiro
        gtk_widget_show (val_label);
205 1 hiro
        gtk_table_attach (GTK_TABLE (table1), val_label, 1, 2, 0, 1,
206 1 hiro
                          GTK_EXPAND | GTK_SHRINK | GTK_FILL,
207 1 hiro
                          0, 0, 0);
208 1 hiro
        gtk_misc_set_alignment (GTK_MISC (val_label), 0, 0.5);
209 1 hiro
210 1 hiro
        val_entry = gtk_entry_new ();
211 1 hiro
        gtk_widget_show (val_entry);
212 1 hiro
        gtk_table_attach (GTK_TABLE (table1), val_entry, 1, 2, 1, 2,
213 1 hiro
                          GTK_EXPAND | GTK_SHRINK | GTK_FILL,
214 1 hiro
                          0, 0, 0);
215 1 hiro
        gtk_widget_set_size_request (val_entry, 200, -1);
216 1 hiro
217 1 hiro
        /* add / delete */
218 1 hiro
219 1 hiro
        reg_hbox = gtk_hbox_new (FALSE, 4);
220 1 hiro
        gtk_widget_show (reg_hbox);
221 1 hiro
        gtk_box_pack_start (GTK_BOX (vbox1), reg_hbox, FALSE, FALSE, 0);
222 1 hiro
223 1 hiro
        arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
224 1 hiro
        gtk_widget_show (arrow);
225 1 hiro
        gtk_box_pack_start (GTK_BOX (reg_hbox), arrow, FALSE, FALSE, 0);
226 1 hiro
        gtk_widget_set_size_request (arrow, -1, 16);
227 1 hiro
228 1 hiro
        btn_hbox = gtk_hbox_new (TRUE, 4);
229 1 hiro
        gtk_widget_show (btn_hbox);
230 1 hiro
        gtk_box_pack_start (GTK_BOX (reg_hbox), btn_hbox, FALSE, FALSE, 0);
231 1 hiro
232 1 hiro
        add_btn = gtk_button_new_with_label (_("Add"));
233 1 hiro
        gtk_widget_show (add_btn);
234 1 hiro
        gtk_box_pack_start (GTK_BOX (btn_hbox), add_btn, FALSE, TRUE, 0);
235 1 hiro
        g_signal_connect (G_OBJECT (add_btn), "clicked",
236 1 hiro
                          G_CALLBACK (prefs_custom_header_add_cb), NULL);
237 1 hiro
238 1 hiro
        del_btn = gtk_button_new_with_label (_(" Delete "));
239 1 hiro
        gtk_widget_show (del_btn);
240 1 hiro
        gtk_box_pack_start (GTK_BOX (btn_hbox), del_btn, FALSE, TRUE, 0);
241 1 hiro
        g_signal_connect (G_OBJECT (del_btn), "clicked",
242 1 hiro
                          G_CALLBACK (prefs_custom_header_delete_cb), NULL);
243 1 hiro
244 1 hiro
245 1 hiro
        ch_hbox = gtk_hbox_new (FALSE, 8);
246 1 hiro
        gtk_widget_show (ch_hbox);
247 1 hiro
        gtk_box_pack_start (GTK_BOX (vbox1), ch_hbox, TRUE, TRUE, 0);
248 1 hiro
249 1 hiro
        ch_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
250 1 hiro
        gtk_widget_set_size_request (ch_scrolledwin, -1, 200);
251 1 hiro
        gtk_widget_show (ch_scrolledwin);
252 1 hiro
        gtk_box_pack_start (GTK_BOX (ch_hbox), ch_scrolledwin, TRUE, TRUE, 0);
253 1 hiro
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (ch_scrolledwin),
254 1 hiro
                                        GTK_POLICY_AUTOMATIC,
255 1 hiro
                                        GTK_POLICY_AUTOMATIC);
256 1 hiro
257 1 hiro
        title[0] = _("Custom headers");
258 1 hiro
        customhdr_clist = gtk_clist_new_with_titles(1, title);
259 1 hiro
        gtk_widget_show (customhdr_clist);
260 1 hiro
        gtk_container_add (GTK_CONTAINER (ch_scrolledwin), customhdr_clist);
261 1 hiro
        gtk_clist_set_column_width (GTK_CLIST (customhdr_clist), 0, 80);
262 1 hiro
        gtk_clist_set_selection_mode (GTK_CLIST (customhdr_clist),
263 1 hiro
                                      GTK_SELECTION_BROWSE);
264 1 hiro
        gtk_clist_set_reorderable (GTK_CLIST (customhdr_clist), TRUE);
265 1 hiro
        gtk_clist_set_use_drag_icons (GTK_CLIST (customhdr_clist), FALSE);
266 1 hiro
        GTK_WIDGET_UNSET_FLAGS (GTK_CLIST (customhdr_clist)->column[0].button,
267 1 hiro
                                GTK_CAN_FOCUS);
268 1 hiro
        g_signal_connect (G_OBJECT (customhdr_clist), "select_row",
269 1 hiro
                          G_CALLBACK (prefs_custom_header_select), NULL);
270 1 hiro
        g_signal_connect_after
271 1 hiro
                (G_OBJECT (customhdr_clist), "row_move",
272 1 hiro
                 G_CALLBACK (prefs_custom_header_row_moved), NULL);
273 1 hiro
274 1 hiro
        btn_vbox = gtk_vbox_new (FALSE, 8);
275 1 hiro
        gtk_widget_show (btn_vbox);
276 1 hiro
        gtk_box_pack_start (GTK_BOX (ch_hbox), btn_vbox, FALSE, FALSE, 0);
277 1 hiro
278 1 hiro
        up_btn = gtk_button_new_with_label (_("Up"));
279 1 hiro
        gtk_widget_show (up_btn);
280 1 hiro
        gtk_box_pack_start (GTK_BOX (btn_vbox), up_btn, FALSE, FALSE, 0);
281 1 hiro
        g_signal_connect (G_OBJECT (up_btn), "clicked",
282 1 hiro
                          G_CALLBACK (prefs_custom_header_up), NULL);
283 1 hiro
284 1 hiro
        down_btn = gtk_button_new_with_label (_("Down"));
285 1 hiro
        gtk_widget_show (down_btn);
286 1 hiro
        gtk_box_pack_start (GTK_BOX (btn_vbox), down_btn, FALSE, FALSE, 0);
287 1 hiro
        g_signal_connect (G_OBJECT (down_btn), "clicked",
288 1 hiro
                          G_CALLBACK (prefs_custom_header_down), NULL);
289 1 hiro
290 1 hiro
        gtk_widget_show_all(window);
291 1 hiro
292 1 hiro
        customhdr.window     = window;
293 1 hiro
        customhdr.ok_btn     = ok_btn;
294 1 hiro
        customhdr.cancel_btn = cancel_btn;
295 1 hiro
296 1 hiro
        customhdr.hdr_combo  = hdr_combo;
297 1 hiro
        customhdr.hdr_entry  = GTK_COMBO (hdr_combo)->entry;
298 1 hiro
        customhdr.val_entry  = val_entry;
299 1 hiro
300 1 hiro
        customhdr.customhdr_clist   = customhdr_clist;
301 1 hiro
}
302 1 hiro
303 1 hiro
static void prefs_custom_header_set_dialog(PrefsAccount *ac)
304 1 hiro
{
305 1 hiro
        GtkCList *clist = GTK_CLIST(customhdr.customhdr_clist);
306 1 hiro
        GSList *cur;
307 1 hiro
        gchar *ch_str[1];
308 1 hiro
        gint row;
309 1 hiro
310 1 hiro
        gtk_clist_freeze(clist);
311 1 hiro
        gtk_clist_clear(clist);
312 1 hiro
313 1 hiro
        for (cur = ac->customhdr_list; cur != NULL; cur = cur->next) {
314 1 hiro
                 CustomHeader *ch = (CustomHeader *)cur->data;
315 1 hiro
316 1 hiro
                ch_str[0] = g_strdup_printf("%s: %s", ch->name,
317 1 hiro
                                            ch->value ? ch->value : "");
318 1 hiro
                row = gtk_clist_append(clist, ch_str);
319 1 hiro
                gtk_clist_set_row_data(clist, row, ch);
320 1 hiro
321 1 hiro
                g_free(ch_str[0]);
322 1 hiro
        }
323 1 hiro
324 1 hiro
        gtk_clist_thaw(clist);
325 1 hiro
}
326 1 hiro
327 1 hiro
static void prefs_custom_header_set_list(PrefsAccount *ac)
328 1 hiro
{
329 1 hiro
        gint row = 0;
330 1 hiro
        CustomHeader *ch;
331 1 hiro
332 1 hiro
        g_slist_free(ac->customhdr_list);
333 1 hiro
        ac->customhdr_list = NULL;
334 1 hiro
335 1 hiro
        while ((ch = gtk_clist_get_row_data
336 1 hiro
                (GTK_CLIST(customhdr.customhdr_clist), row)) != NULL) {
337 1 hiro
                ac->customhdr_list = g_slist_append(ac->customhdr_list, ch);
338 1 hiro
                row++;
339 1 hiro
        }
340 1 hiro
}
341 1 hiro
342 1 hiro
static gint prefs_custom_header_clist_set_row(PrefsAccount *ac, gint row)
343 1 hiro
{
344 1 hiro
        GtkCList *clist = GTK_CLIST(customhdr.customhdr_clist);
345 1 hiro
        CustomHeader *ch;
346 1 hiro
        const gchar *entry_text;
347 1 hiro
        gchar *ch_str[1];
348 1 hiro
349 1 hiro
        entry_text = gtk_entry_get_text(GTK_ENTRY(customhdr.hdr_entry));
350 1 hiro
        if (entry_text[0] == '\0') {
351 1 hiro
                alertpanel_error(_("Header name is not set."));
352 1 hiro
                return -1;
353 1 hiro
        }
354 1 hiro
355 1 hiro
        ch = g_new0(CustomHeader, 1);
356 1 hiro
357 1 hiro
        ch->account_id = ac->account_id;
358 1 hiro
359 1 hiro
        ch->name = g_strdup(entry_text);
360 1 hiro
        unfold_line(ch->name);
361 1 hiro
        g_strstrip(ch->name);
362 1 hiro
        gtk_entry_set_text(GTK_ENTRY(customhdr.hdr_entry), ch->name);
363 1 hiro
364 1 hiro
        entry_text = gtk_entry_get_text(GTK_ENTRY(customhdr.val_entry));
365 1 hiro
        if (entry_text[0] != '\0') {
366 1 hiro
                ch->value = g_strdup(entry_text);
367 1 hiro
                unfold_line(ch->value);
368 1 hiro
                g_strstrip(ch->value);
369 1 hiro
                gtk_entry_set_text(GTK_ENTRY(customhdr.val_entry), ch->value);
370 1 hiro
        }
371 1 hiro
372 1 hiro
        ch_str[0] = g_strdup_printf("%s: %s", ch->name,
373 1 hiro
                                    ch->value ? ch->value : "");
374 1 hiro
375 1 hiro
        if (row < 0)
376 1 hiro
                row = gtk_clist_append(clist, ch_str);
377 1 hiro
        else {
378 1 hiro
                CustomHeader *tmp_ch;
379 1 hiro
380 1 hiro
                gtk_clist_set_text(clist, row, 0, ch_str[0]);
381 1 hiro
                tmp_ch = gtk_clist_get_row_data(clist, row);
382 1 hiro
                if (tmp_ch)
383 1 hiro
                        custom_header_free(tmp_ch);
384 1 hiro
        }
385 1 hiro
386 1 hiro
        gtk_clist_set_row_data(clist, row, ch);
387 1 hiro
388 1 hiro
        g_free(ch_str[0]);
389 1 hiro
390 1 hiro
        prefs_custom_header_set_list(cur_ac);
391 1 hiro
392 1 hiro
        return row;
393 1 hiro
}
394 1 hiro
395 1 hiro
static void prefs_custom_header_add_cb(void)
396 1 hiro
{
397 1 hiro
        prefs_custom_header_clist_set_row(cur_ac, -1);
398 1 hiro
}
399 1 hiro
400 1 hiro
static void prefs_custom_header_delete_cb(void)
401 1 hiro
{
402 1 hiro
        GtkCList *clist = GTK_CLIST(customhdr.customhdr_clist);
403 1 hiro
        CustomHeader *ch;
404 1 hiro
        gint row;
405 1 hiro
406 1 hiro
        if (!clist->selection) return;
407 1 hiro
        row = GPOINTER_TO_INT(clist->selection->data);
408 1 hiro
409 1 hiro
        if (alertpanel(_("Delete header"),
410 1 hiro
                       _("Do you really want to delete this header?"),
411 47 hiro
                       GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT)
412 1 hiro
                return;
413 1 hiro
414 1 hiro
        ch = gtk_clist_get_row_data(clist, row);
415 1 hiro
        custom_header_free(ch);
416 1 hiro
        gtk_clist_remove(clist, row);
417 1 hiro
        cur_ac->customhdr_list = g_slist_remove(cur_ac->customhdr_list, ch);
418 1 hiro
}
419 1 hiro
420 1 hiro
static void prefs_custom_header_up(void)
421 1 hiro
{
422 1 hiro
        GtkCList *clist = GTK_CLIST(customhdr.customhdr_clist);
423 1 hiro
        gint row;
424 1 hiro
425 1 hiro
        if (!clist->selection) return;
426 1 hiro
427 1 hiro
        row = GPOINTER_TO_INT(clist->selection->data);
428 1 hiro
        if (row > 0)
429 1 hiro
                gtk_clist_row_move(clist, row, row - 1);
430 1 hiro
}
431 1 hiro
432 1 hiro
static void prefs_custom_header_down(void)
433 1 hiro
{
434 1 hiro
        GtkCList *clist = GTK_CLIST(customhdr.customhdr_clist);
435 1 hiro
        gint row;
436 1 hiro
437 1 hiro
        if (!clist->selection) return;
438 1 hiro
439 1 hiro
        row = GPOINTER_TO_INT(clist->selection->data);
440 1 hiro
        if (row >= 0 && row < clist->rows - 1)
441 1 hiro
                gtk_clist_row_move(clist, row, row + 1);
442 1 hiro
}
443 1 hiro
444 1 hiro
#define ENTRY_SET_TEXT(entry, str) \
445 1 hiro
        gtk_entry_set_text(GTK_ENTRY(entry), str ? str : "")
446 1 hiro
447 1 hiro
static void prefs_custom_header_select(GtkCList *clist, gint row, gint column,
448 1 hiro
                                       GdkEvent *event)
449 1 hiro
{
450 1 hiro
        CustomHeader *ch;
451 1 hiro
        CustomHeader default_ch = { 0, "", NULL };
452 1 hiro
453 1 hiro
        ch = gtk_clist_get_row_data(clist, row);
454 1 hiro
        if (!ch) ch = &default_ch;
455 1 hiro
456 1 hiro
        ENTRY_SET_TEXT(customhdr.hdr_entry, ch->name);
457 1 hiro
        ENTRY_SET_TEXT(customhdr.val_entry, ch->value);
458 1 hiro
}
459 1 hiro
460 1 hiro
#undef ENTRY_SET_TEXT
461 1 hiro
462 1 hiro
static void prefs_custom_header_row_moved(GtkCList *clist, gint source_row,
463 1 hiro
                                          gint dest_row, gpointer data)
464 1 hiro
{
465 1 hiro
        prefs_custom_header_set_list(cur_ac);
466 1 hiro
}
467 1 hiro
468 1 hiro
static gboolean prefs_custom_header_key_pressed(GtkWidget *widget,
469 1 hiro
                                                GdkEventKey *event,
470 1 hiro
                                                gpointer data)
471 1 hiro
{
472 1 hiro
        if (event && event->keyval == GDK_Escape)
473 1 hiro
                prefs_custom_header_cancel();
474 1 hiro
        return FALSE;
475 1 hiro
}
476 1 hiro
477 1 hiro
static void prefs_custom_header_ok(void)
478 1 hiro
{
479 534 hiro
        custom_header_write_config(cur_ac);
480 1 hiro
        gtk_widget_hide(customhdr.window);
481 1 hiro
}
482 1 hiro
483 1 hiro
static void prefs_custom_header_cancel(void)
484 1 hiro
{
485 534 hiro
        custom_header_read_config(cur_ac);
486 1 hiro
        gtk_widget_hide(customhdr.window);
487 1 hiro
}
488 1 hiro
489 1 hiro
static gint prefs_custom_header_deleted(GtkWidget *widget, GdkEventAny *event,
490 1 hiro
                                        gpointer data)
491 1 hiro
{
492 1 hiro
        prefs_custom_header_cancel();
493 1 hiro
        return TRUE;
494 1 hiro
}