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