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