Sync Spanish manual
[claws.git] / src / prefs_display_header.c
blobf6bc931c55c70712510a7df71f170977029bb10b
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2022 the Claws Mail team and Hiroyuki Yamamoto
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 3 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #include "claws-features.h"
23 #endif
25 #include "defs.h"
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 #include <gtk/gtk.h>
30 #include <gdk/gdkkeysyms.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <errno.h>
36 #include "prefs_gtk.h"
37 #include "prefs_display_header.h"
38 #include "prefs_common.h"
39 #include "manage_window.h"
40 #include "alertpanel.h"
41 #include "displayheader.h"
42 #include "utils.h"
43 #include "gtkutils.h"
44 #include "file-utils.h"
46 enum {
47 PREFS_HDR_HEADER,
48 PREFS_HDR_DATA,
49 N_PREFS_HDR_COLUMNS
52 static struct DisplayHeader {
53 GtkWidget *window;
55 GtkWidget *ok_btn;
56 GtkWidget *cancel_btn;
58 GtkWidget *hdr_combo;
59 GtkWidget *key_check;
60 GtkWidget *headers_list_view;
61 GtkWidget *hidden_headers_list_view;
63 GtkWidget *other_headers;
64 } dispheader;
66 /* widget creating functions */
67 static void prefs_display_header_create (void);
69 static void prefs_display_header_set_dialog (void);
70 static void prefs_display_header_set_list (void);
71 static void prefs_display_header_list_view_set_row (gboolean hidden);
73 /* callback functions */
74 static void prefs_display_header_register_cb (GtkButton *btn,
75 gpointer hidden_data);
76 static void prefs_display_header_delete_cb (GtkButton *btn,
77 gpointer list_view_data);
78 static void prefs_display_header_up (void);
79 static void prefs_display_header_down (void);
81 static gboolean prefs_display_header_key_pressed (GtkWidget *widget,
82 GdkEventKey *event,
83 gpointer data);
84 static void prefs_display_header_ok (void);
85 static void prefs_display_header_cancel (void);
86 static gint prefs_display_header_deleted (GtkWidget *widget,
87 GdkEventAny *event,
88 gpointer data);
91 static GtkListStore *prefs_display_header_create_store (void);
92 static void prefs_display_header_insert_header (GtkListStore *store,
93 gchar *name,
94 DisplayHeaderProp *dp);
95 static GtkWidget *prefs_display_header_list_view_create (const gchar *name);
96 static void prefs_filtering_create_list_view_columns (GtkWidget *list_view,
97 const gchar *name);
98 static void headers_list_model_rows_reordered (GtkTreeModel *model,
99 GtkTreePath *path,
100 GtkTreeIter *iter,
101 gpointer arg,
102 GtkTreeView *list_view);
104 static void drag_end (GtkTreeView *list_view,
105 GdkDragContext *context,
106 gpointer data);
108 #ifndef GENERIC_UMPC
109 static gchar *defaults[] =
111 "From",
112 "To",
113 "Cc",
114 "Bcc",
115 "Subject",
116 "Date",
117 "Reply-To",
118 "Sender",
119 "User-Agent",
120 "X-Mailer",
121 "Newsgroups",
122 "Followup-To",
123 "Organization",
124 "X-Newsreader",
125 "-Received",
126 "-Message-ID",
127 "-In-Reply-To",
128 "-References",
129 "-MIME-Version",
130 "-Content-Type",
131 "-Content-Transfer-Encoding",
132 "-X-UIDL",
133 "-Precedence",
134 "-Status",
135 "-Priority",
136 "-X-Face"
138 #else
139 static gchar *defaults[] =
141 "From",
142 "To",
143 "Cc",
144 "Bcc",
145 "Subject",
146 "Date",
147 "Newsgroups",
148 "Followup-To",
149 "-Reply-To",
150 "-Sender",
151 "-User-Agent",
152 "-X-Mailer",
153 "-Organization",
154 "-X-Newsreader",
155 "-Received",
156 "-Message-ID",
157 "-In-Reply-To",
158 "-References",
159 "-MIME-Version",
160 "-Content-Type",
161 "-Content-Transfer-Encoding",
162 "-X-UIDL",
163 "-Precedence",
164 "-Status",
165 "-Priority",
166 "-X-Face"
168 #endif
169 static void prefs_display_header_set_default(void)
171 gint i;
172 DisplayHeaderProp *dp;
174 for(i = 0; i < sizeof(defaults) / sizeof(defaults[0]); i++) {
175 dp = display_header_prop_read_str(defaults[i]);
176 prefs_common.disphdr_list =
177 g_slist_append(prefs_common.disphdr_list, dp);
181 void prefs_display_header_open(void)
183 if (prefs_rc_is_readonly(DISPLAY_HEADER_RC))
184 return;
186 if (!dispheader.window) {
187 prefs_display_header_create();
190 manage_window_set_transient(GTK_WINDOW(dispheader.window));
191 gtk_widget_grab_focus(dispheader.ok_btn);
193 prefs_display_header_set_dialog();
195 gtk_widget_show(dispheader.window);
196 gtk_window_set_modal(GTK_WINDOW(dispheader.window), TRUE);
199 static void prefs_display_header_create(void)
201 GtkWidget *window;
202 GtkWidget *vbox;
203 GtkWidget *btn_hbox;
204 GtkWidget *ok_btn;
205 GtkWidget *cancel_btn;
206 GtkWidget *confirm_area;
208 GtkWidget *vbox1;
210 GtkWidget *hbox1;
211 GtkWidget *hdr_label;
212 GtkWidget *hdr_combo;
214 GtkWidget *btn_vbox;
215 GtkWidget *reg_btn;
216 GtkWidget *del_btn;
217 GtkWidget *up_btn;
218 GtkWidget *down_btn;
220 GtkWidget *list_view_hbox;
221 GtkWidget *list_view_hbox1;
222 GtkWidget *list_view_hbox2;
223 GtkWidget *list_view_scrolledwin;
224 GtkWidget *headers_list_view;
225 GtkWidget *hidden_headers_list_view;
227 GtkWidget *checkbtn_other_headers;
228 gint i;
230 debug_print("Creating display header setting window...\n");
232 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_display_header");
233 gtk_container_set_border_width (GTK_CONTAINER (window), 8);
234 gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
235 gtk_window_set_resizable(GTK_WINDOW (window), TRUE);
236 gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
238 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
239 gtk_widget_show (vbox);
240 gtk_container_add (GTK_CONTAINER (window), vbox);
242 btn_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
243 gtk_widget_show (btn_hbox);
244 gtk_box_pack_end (GTK_BOX (vbox), btn_hbox, FALSE, FALSE, 0);
246 gtkut_stock_button_set_create(&confirm_area, &cancel_btn, NULL, _("_Cancel"),
247 &ok_btn, NULL, _("_OK"), NULL, NULL, NULL);
248 gtk_widget_show (confirm_area);
249 gtk_box_pack_end (GTK_BOX(btn_hbox), confirm_area, FALSE, FALSE, 0);
250 gtk_widget_grab_default (ok_btn);
252 gtk_window_set_title (GTK_WINDOW(window),
253 _("Displayed header configuration"));
254 MANAGE_WINDOW_SIGNALS_CONNECT(window);
255 g_signal_connect (G_OBJECT(window), "delete_event",
256 G_CALLBACK(prefs_display_header_deleted),
257 NULL);
258 g_signal_connect (G_OBJECT(window), "key_press_event",
259 G_CALLBACK(prefs_display_header_key_pressed),
260 NULL);
261 g_signal_connect (G_OBJECT(ok_btn), "clicked",
262 G_CALLBACK(prefs_display_header_ok),
263 NULL);
264 g_signal_connect (G_OBJECT(cancel_btn), "clicked",
265 G_CALLBACK(prefs_display_header_cancel),
266 NULL);
268 vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
269 gtk_widget_show (vbox1);
270 gtk_box_pack_start (GTK_BOX (vbox), vbox1, TRUE, TRUE, 0);
271 gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
273 hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
274 gtk_widget_show (hbox1);
275 gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, TRUE, 0);
277 hdr_label = gtk_label_new (_("Header name"));
278 gtk_widget_show (hdr_label);
279 gtk_box_pack_start (GTK_BOX (hbox1), hdr_label, FALSE, FALSE, 0);
281 hdr_combo = gtk_combo_box_text_new_with_entry();
282 for(i=0; i < 9 ; i++)
283 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT (hdr_combo),
284 (*defaults[i] == '-') ? defaults[i]+1 : defaults[i]);
285 gtk_combo_box_set_active(GTK_COMBO_BOX(hdr_combo), 0);
286 gtk_widget_show (hdr_combo);
287 gtk_box_pack_start (GTK_BOX (hbox1), hdr_combo, TRUE, TRUE, 0);
288 gtk_widget_set_size_request (hdr_combo, 150, -1);
290 list_view_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
291 gtk_widget_show (list_view_hbox);
292 gtk_box_pack_start (GTK_BOX (vbox1), list_view_hbox, TRUE, TRUE, 0);
294 /* hidden headers list */
296 list_view_hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
297 gtk_widget_show (list_view_hbox2);
298 gtk_box_pack_start (GTK_BOX (list_view_hbox), list_view_hbox2, TRUE, TRUE, 0);
300 list_view_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
301 gtk_widget_set_size_request (list_view_scrolledwin, 200, 210);
302 gtk_widget_show (list_view_scrolledwin);
303 gtk_box_pack_start (GTK_BOX (list_view_hbox2), list_view_scrolledwin,
304 TRUE, TRUE, 0);
305 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (list_view_scrolledwin),
306 GTK_POLICY_AUTOMATIC,
307 GTK_POLICY_AUTOMATIC);
308 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_view_scrolledwin),
309 GTK_SHADOW_IN);
311 hidden_headers_list_view = prefs_display_header_list_view_create
312 (_("Hidden headers"));
313 gtk_widget_show (hidden_headers_list_view);
314 gtk_container_add (GTK_CONTAINER (list_view_scrolledwin),
315 hidden_headers_list_view);
317 btn_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
318 gtk_widget_show (btn_vbox);
319 gtk_box_pack_start (GTK_BOX (list_view_hbox2), btn_vbox, FALSE, FALSE, 0);
321 reg_btn = gtkut_stock_button("list-add", _("_Add"));
322 gtk_widget_show (reg_btn);
323 gtk_box_pack_start (GTK_BOX (btn_vbox), reg_btn, FALSE, TRUE, 0);
324 g_signal_connect (G_OBJECT (reg_btn), "clicked",
325 G_CALLBACK
326 (prefs_display_header_register_cb),
327 GINT_TO_POINTER(TRUE));
328 del_btn = gtkut_stock_button("edit-delete", _("_Delete"));
329 gtk_widget_show (del_btn);
330 gtk_box_pack_start (GTK_BOX (btn_vbox), del_btn, FALSE, TRUE, 0);
331 g_signal_connect (G_OBJECT (del_btn), "clicked",
332 G_CALLBACK (prefs_display_header_delete_cb),
333 hidden_headers_list_view);
335 /* display headers list */
337 list_view_hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
338 gtk_widget_show (list_view_hbox1);
339 gtk_box_pack_start (GTK_BOX (list_view_hbox), list_view_hbox1, TRUE, TRUE, 0);
341 list_view_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
342 gtk_widget_set_size_request (list_view_scrolledwin, 200, 210);
343 gtk_widget_show (list_view_scrolledwin);
344 gtk_box_pack_start (GTK_BOX (list_view_hbox1), list_view_scrolledwin,
345 TRUE, TRUE, 0);
346 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (list_view_scrolledwin),
347 GTK_POLICY_AUTOMATIC,
348 GTK_POLICY_AUTOMATIC);
349 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_view_scrolledwin),
350 GTK_SHADOW_IN);
352 headers_list_view = prefs_display_header_list_view_create
353 (_("Displayed Headers"));
354 gtk_widget_show (headers_list_view);
355 gtk_container_add(GTK_CONTAINER(list_view_scrolledwin), headers_list_view);
356 gtk_tree_view_set_reorderable(GTK_TREE_VIEW(headers_list_view), TRUE);
358 g_signal_connect(G_OBJECT(headers_list_view), "drag_end",
359 G_CALLBACK(drag_end),
360 headers_list_view);
362 /* connect rows change for this list view's model */
363 g_signal_connect(G_OBJECT(gtk_tree_view_get_model(GTK_TREE_VIEW(headers_list_view))),
364 "rows-reordered",
365 G_CALLBACK(headers_list_model_rows_reordered),
366 headers_list_view);
368 btn_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
369 gtk_widget_show (btn_vbox);
370 gtk_box_pack_start (GTK_BOX (list_view_hbox1), btn_vbox, FALSE, FALSE, 0);
372 reg_btn = gtkut_stock_button("list-add", _("_Add"));
373 gtk_widget_show (reg_btn);
374 gtk_box_pack_start (GTK_BOX (btn_vbox), reg_btn, FALSE, TRUE, 0);
375 g_signal_connect (G_OBJECT (reg_btn), "clicked",
376 G_CALLBACK (prefs_display_header_register_cb),
377 GINT_TO_POINTER(FALSE));
378 del_btn = gtkut_stock_button("list-remove", _("_Remove"));
379 gtk_widget_show (del_btn);
380 gtk_box_pack_start (GTK_BOX (btn_vbox), del_btn, FALSE, TRUE, 0);
381 g_signal_connect (G_OBJECT (del_btn), "clicked",
382 G_CALLBACK (prefs_display_header_delete_cb),
383 headers_list_view);
385 up_btn = gtkut_stock_button("go-up", _("_Up"));
386 gtk_widget_show (up_btn);
387 gtk_box_pack_start (GTK_BOX (btn_vbox), up_btn, FALSE, FALSE, 0);
388 g_signal_connect (G_OBJECT (up_btn), "clicked",
389 G_CALLBACK (prefs_display_header_up), NULL);
391 down_btn = gtkut_stock_button("go-down", _("_Down"));
392 gtk_widget_show (down_btn);
393 gtk_box_pack_start (GTK_BOX (btn_vbox), down_btn, FALSE, FALSE, 0);
394 g_signal_connect (G_OBJECT (down_btn), "clicked",
395 G_CALLBACK (prefs_display_header_down), NULL);
397 PACK_CHECK_BUTTON (vbox, checkbtn_other_headers,
398 _("Show all unspecified headers"));
399 SET_TOGGLE_SENSITIVITY (checkbtn_other_headers, list_view_hbox2);
401 gtk_widget_show_all(window);
403 dispheader.window = window;
404 dispheader.ok_btn = ok_btn;
405 dispheader.cancel_btn = cancel_btn;
407 dispheader.hdr_combo = hdr_combo;
409 dispheader.headers_list_view = headers_list_view;
410 dispheader.hidden_headers_list_view = hidden_headers_list_view;
412 dispheader.other_headers = checkbtn_other_headers;
415 void prefs_display_header_read_config(void)
417 gchar *rcpath;
418 FILE *fp;
419 gchar buf[PREFSBUFSIZE];
420 DisplayHeaderProp *dp;
422 debug_print("Reading configuration for displaying headers...\n");
424 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
425 DISPLAY_HEADER_RC, NULL);
426 if ((fp = claws_fopen(rcpath, "rb")) == NULL) {
427 if (ENOENT != errno) FILE_OP_ERROR(rcpath, "claws_fopen");
428 g_free(rcpath);
429 prefs_common.disphdr_list = NULL;
430 prefs_display_header_set_default();
431 return;
433 g_free(rcpath);
435 /* remove all previous headers list */
436 while (prefs_common.disphdr_list != NULL) {
437 dp = (DisplayHeaderProp *)prefs_common.disphdr_list->data;
438 prefs_common.disphdr_list =
439 g_slist_remove(prefs_common.disphdr_list, dp);
440 display_header_prop_free(dp);
443 while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
444 g_strdelimit(buf, "\r\n", '\0');
445 dp = display_header_prop_read_str(buf);
446 if (dp)
447 prefs_common.disphdr_list =
448 g_slist_append(prefs_common.disphdr_list, dp);
451 claws_fclose(fp);
454 static void prefs_display_header_write_config(void)
456 gchar *rcpath;
457 PrefFile *pfile;
458 GSList *cur;
460 debug_print("Writing configuration for displaying headers...\n");
462 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
463 DISPLAY_HEADER_RC, NULL);
465 if ((pfile = prefs_write_open(rcpath)) == NULL) {
466 g_warning("failed to write configuration to file");
467 g_free(rcpath);
468 return;
471 for (cur = prefs_common.disphdr_list; cur != NULL;
472 cur = cur->next) {
473 DisplayHeaderProp *dp = (DisplayHeaderProp *)cur->data;
474 gchar *dpstr;
476 dpstr = display_header_prop_get_str(dp);
477 if (claws_fputs(dpstr, pfile->fp) == EOF ||
478 claws_fputc('\n', pfile->fp) == EOF) {
479 FILE_OP_ERROR(rcpath, "claws_fputs || claws_fputc");
480 prefs_file_close_revert(pfile);
481 g_free(rcpath);
482 g_free(dpstr);
483 return;
485 g_free(dpstr);
488 g_free(rcpath);
490 if (prefs_file_close(pfile) < 0) {
491 g_warning("failed to write configuration to file");
492 return;
496 static void prefs_display_header_set_dialog(void)
498 GtkTreeView *list_view = GTK_TREE_VIEW(dispheader.headers_list_view);
499 GtkTreeView *hidden_list_view = GTK_TREE_VIEW(dispheader.hidden_headers_list_view);
500 GSList *cur;
501 GtkTreeModel *model_list, *model_hidden;
503 model_list = gtk_tree_view_get_model(list_view);
504 model_hidden = gtk_tree_view_get_model(hidden_list_view);
506 gtk_list_store_clear(GTK_LIST_STORE(model_list));
507 gtk_list_store_clear(GTK_LIST_STORE(model_hidden));
509 for (cur = prefs_common.disphdr_list; cur != NULL;
510 cur = cur->next) {
511 DisplayHeaderProp *dp = (DisplayHeaderProp *)cur->data;
513 if (dp->hidden)
514 prefs_display_header_insert_header(GTK_LIST_STORE
515 (model_hidden), dp->name, dp);
516 else
517 prefs_display_header_insert_header(GTK_LIST_STORE
518 (model_list), dp->name, dp);
521 gtk_toggle_button_set_active
522 (GTK_TOGGLE_BUTTON(dispheader.other_headers),
523 prefs_common.show_other_header);
526 static void prefs_display_header_set_list(void)
528 gint row = 0;
529 DisplayHeaderProp *dp;
530 GtkTreeModel *model;
531 GtkTreeIter iter;
533 g_slist_free(prefs_common.disphdr_list);
534 prefs_common.disphdr_list = NULL;
536 model = gtk_tree_view_get_model(GTK_TREE_VIEW(dispheader.headers_list_view));
537 while (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
538 gtk_tree_model_get(model, &iter, PREFS_HDR_DATA, &dp, -1);
539 if (dp)
540 prefs_common.disphdr_list =
541 g_slist_append(prefs_common.disphdr_list, dp);
542 row++;
545 model = gtk_tree_view_get_model
546 (GTK_TREE_VIEW(dispheader.hidden_headers_list_view));
547 row = 0;
548 while (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
549 gtk_tree_model_get(model, &iter, PREFS_HDR_DATA, &dp, -1);
550 if (dp)
551 prefs_common.disphdr_list =
552 g_slist_append(prefs_common.disphdr_list, dp);
553 row++;
557 static gint prefs_display_header_find_header(GtkTreeView *list_view,
558 const gchar *header)
560 gint row = 0;
561 DisplayHeaderProp *dp;
562 GtkTreeModel *model;
563 GtkTreeIter iter;
565 model = gtk_tree_view_get_model(list_view);
566 while (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
567 gtk_tree_model_get(model, &iter, PREFS_HDR_DATA, &dp, -1);
568 if (dp && g_ascii_strcasecmp(dp->name, header) == 0)
569 return row;
570 row++;
573 return -1;
576 static void prefs_display_header_list_view_set_row(gboolean hidden)
578 GtkTreeView *list_view;
579 DisplayHeaderProp *dp;
580 gchar *entry_text;
581 GtkTreeModel *model;
583 entry_text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(dispheader.hdr_combo));
584 if (!entry_text)
585 entry_text = gtk_editable_get_chars(
586 GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(dispheader.hdr_combo))),0,-1);
587 if (!entry_text || entry_text[0] == '\0') {
588 alertpanel_error(_("Header name is not set."));
589 return;
592 if (hidden)
593 list_view = GTK_TREE_VIEW(dispheader.hidden_headers_list_view);
594 else
595 list_view = GTK_TREE_VIEW(dispheader.headers_list_view);
597 if (prefs_display_header_find_header(list_view, entry_text) != -1) {
598 alertpanel_error(_("This header is already in the list."));
599 return;
602 dp = g_new0(DisplayHeaderProp, 1);
604 dp->name = g_strdup(entry_text);
605 dp->hidden = hidden;
607 model = gtk_tree_view_get_model(list_view);
608 prefs_display_header_insert_header(GTK_LIST_STORE(model),
609 dp->name, dp);
611 prefs_display_header_set_list();
613 g_free(entry_text);
616 static void prefs_display_header_register_cb(GtkButton *btn,
617 gpointer hidden_data)
619 prefs_display_header_list_view_set_row(GPOINTER_TO_INT(hidden_data));
622 static void prefs_display_header_delete_cb(GtkButton *btn, gpointer list_view_data)
624 GtkTreeView *list_view = GTK_TREE_VIEW(list_view_data);
625 DisplayHeaderProp *dp;
626 GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
627 GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
628 GtkTreeIter iter;
630 if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
631 return;
633 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, PREFS_HDR_DATA, &dp, -1);
634 if (!dp)
635 return;
637 prefs_common.disphdr_list =
638 g_slist_remove(prefs_common.disphdr_list, dp);
639 display_header_prop_free(dp);
640 gtk_list_store_remove(store, &iter);
643 static void prefs_display_header_up(void)
645 GtkTreePath *prev, *sel, *try;
646 GtkTreeIter isel;
647 GtkListStore *store = NULL;
648 GtkTreeModel *model = NULL;
649 GtkTreeIter iprev;
651 if (!gtk_tree_selection_get_selected
652 (gtk_tree_view_get_selection
653 (GTK_TREE_VIEW(dispheader.headers_list_view)),
654 &model,
655 &isel))
656 return;
657 store = (GtkListStore *)model;
658 sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
659 if (!sel)
660 return;
662 /* no move if we're at row 0... */
663 try = gtk_tree_path_copy(sel);
664 if (!gtk_tree_path_prev(try)) {
665 gtk_tree_path_free(try);
666 gtk_tree_path_free(sel);
667 return;
670 prev = try;
671 gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
672 &iprev, prev);
673 gtk_list_store_swap(store, &iprev, &isel);
675 gtk_tree_path_free(sel);
676 gtk_tree_path_free(prev);
679 static void prefs_display_header_down(void)
681 GtkListStore *store = NULL;
682 GtkTreeModel *model = NULL;
683 GtkTreeIter next, sel;
684 GtkTreePath *try;
686 if (!gtk_tree_selection_get_selected
687 (gtk_tree_view_get_selection
688 (GTK_TREE_VIEW(dispheader.headers_list_view)),
689 &model,
690 &sel))
691 return;
692 store = (GtkListStore *)model;
693 try = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &sel);
694 if (!try)
695 return;
697 next = sel;
698 if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next))
699 gtk_list_store_swap(store, &next, &sel);
701 gtk_tree_path_free(try);
704 static gboolean prefs_display_header_key_pressed(GtkWidget *widget,
705 GdkEventKey *event,
706 gpointer data)
708 if (event && event->keyval == GDK_KEY_Escape)
709 prefs_display_header_cancel();
710 return FALSE;
713 static void prefs_display_header_ok(void)
715 prefs_common.show_other_header =
716 gtk_toggle_button_get_active
717 (GTK_TOGGLE_BUTTON(dispheader.other_headers));
718 prefs_display_header_write_config();
719 gtk_widget_hide(dispheader.window);
720 gtk_window_set_modal(GTK_WINDOW(dispheader.window), FALSE);
723 static void prefs_display_header_cancel(void)
725 prefs_display_header_read_config();
726 gtk_widget_hide(dispheader.window);
727 gtk_window_set_modal(GTK_WINDOW(dispheader.window), FALSE);
730 static gint prefs_display_header_deleted(GtkWidget *widget, GdkEventAny *event,
731 gpointer data)
733 prefs_display_header_cancel();
734 return TRUE;
737 static GtkListStore *prefs_display_header_create_store(void)
739 return gtk_list_store_new(N_PREFS_HDR_COLUMNS,
740 G_TYPE_STRING,
741 G_TYPE_POINTER,
742 -1);
745 static void prefs_display_header_insert_header(GtkListStore *store,
746 gchar *name,
747 DisplayHeaderProp *dp)
749 GtkTreeIter iter;
751 /* add new */
752 gtk_list_store_append(store, &iter);
753 gtk_list_store_set(store, &iter,
754 PREFS_HDR_HEADER,
755 name,
756 PREFS_HDR_DATA, dp,
757 -1);
760 static GtkWidget *prefs_display_header_list_view_create(const gchar *name)
762 GtkWidget *list_view;
763 GtkTreeSelection *selector;
764 GtkTreeModel *model;
766 model = GTK_TREE_MODEL(prefs_display_header_create_store());
767 list_view = gtk_tree_view_new_with_model(model);
768 g_object_unref(G_OBJECT(model));
770 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(list_view),
771 prefs_common.use_stripes_everywhere);
773 selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
774 gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
776 prefs_filtering_create_list_view_columns(GTK_WIDGET(list_view), name);
778 return list_view;
781 static void prefs_filtering_create_list_view_columns(GtkWidget *list_view,
782 const gchar *name)
784 GtkTreeViewColumn *column;
785 GtkCellRenderer *renderer;
787 renderer = gtk_cell_renderer_text_new();
788 column = gtk_tree_view_column_new_with_attributes
789 (name, renderer, "text", PREFS_HDR_HEADER, NULL);
790 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
794 *\brief Called as a result of a gtk_list_store_swap()
796 static void headers_list_model_rows_reordered(GtkTreeModel *model,
797 GtkTreePath *path,
798 GtkTreeIter *iter,
799 gpointer arg,
800 GtkTreeView *list_view)
802 prefs_display_header_set_list();
806 *\brief Called as a result of a drag & drop
808 static void drag_end(GtkTreeView *list_view,
809 GdkDragContext *context,
810 gpointer data)
812 prefs_display_header_set_list();