root / src / headerview.c @ 3154
History | View | Annotate | Download (12.2 kB)
| 1 | /*
|
|---|---|
| 2 | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client |
| 3 | * Copyright (C) 1999-2012 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/gtkwidget.h> |
| 29 | #include <gtk/gtkstyle.h> |
| 30 | #include <gtk/gtkscrolledwindow.h> |
| 31 | #include <gtk/gtkhbox.h> |
| 32 | #include <gtk/gtkvbox.h> |
| 33 | #include <gtk/gtklabel.h> |
| 34 | #include <gtk/gtkpixmap.h> |
| 35 | #include <gtk/gtkimage.h> |
| 36 | #include <gtk/gtktooltips.h> |
| 37 | #include <stdio.h> |
| 38 | #include <string.h> |
| 39 | #include <time.h> |
| 40 | |
| 41 | #if HAVE_LIBCOMPFACE
|
| 42 | # include <compface.h> |
| 43 | #endif
|
| 44 | |
| 45 | #include "main.h" |
| 46 | #include "headerview.h" |
| 47 | #include "prefs_common.h" |
| 48 | #include "codeconv.h" |
| 49 | #include "gtkutils.h" |
| 50 | #include "utils.h" |
| 51 | |
| 52 | #define TR(str) (prefs_common.trans_hdr ? gettext(str) : str)
|
| 53 | |
| 54 | #if 0
|
| 55 | _("From:");
|
| 56 | _("To:");
|
| 57 | _("Cc:");
|
| 58 | _("Newsgroups:");
|
| 59 | _("Subject:");
|
| 60 | #endif |
| 61 | |
| 62 | #if HAVE_LIBCOMPFACE
|
| 63 | #define XPM_XFACE_HEIGHT (HEIGHT + 3) /* 3 = 1 header + 2 colors */ |
| 64 | |
| 65 | static gchar *xpm_xface[XPM_XFACE_HEIGHT];
|
| 66 | |
| 67 | static void headerview_show_xface (HeaderView *headerview, |
| 68 | MsgInfo *msginfo); |
| 69 | static gint create_xpm_from_xface (gchar *xpm[],
|
| 70 | const gchar *xface);
|
| 71 | #endif
|
| 72 | |
| 73 | HeaderView *headerview_create(void)
|
| 74 | {
|
| 75 | HeaderView *headerview; |
| 76 | GtkWidget *hbox; |
| 77 | GtkWidget *vbox; |
| 78 | GtkWidget *hbox1; |
| 79 | GtkWidget *hbox2; |
| 80 | GtkWidget *from_header_label; |
| 81 | GtkWidget *from_body_label; |
| 82 | GtkWidget *to_header_label; |
| 83 | GtkWidget *to_body_label; |
| 84 | GtkWidget *cc_header_label; |
| 85 | GtkWidget *cc_body_label; |
| 86 | GtkWidget *ng_header_label; |
| 87 | GtkWidget *ng_body_label; |
| 88 | GtkWidget *subject_header_label; |
| 89 | GtkWidget *subject_body_label; |
| 90 | GtkTooltips *tip; |
| 91 | |
| 92 | debug_print(_("Creating header view...\n"));
|
| 93 | headerview = g_new0(HeaderView, 1);
|
| 94 | |
| 95 | hbox = gtk_hbox_new(FALSE, 0);
|
| 96 | gtk_container_set_border_width(GTK_CONTAINER(hbox), 2);
|
| 97 | vbox = gtk_vbox_new(FALSE, 2);
|
| 98 | gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
|
| 99 | |
| 100 | hbox1 = gtk_hbox_new(FALSE, 4);
|
| 101 | gtk_box_pack_start(GTK_BOX(vbox), hbox1, FALSE, FALSE, 0);
|
| 102 | hbox2 = gtk_hbox_new(FALSE, 4);
|
| 103 | gtk_box_pack_start(GTK_BOX(vbox), hbox2, FALSE, FALSE, 0);
|
| 104 | |
| 105 | from_header_label = gtk_label_new(TR("From:"));
|
| 106 | from_body_label = gtk_label_new("");
|
| 107 | to_header_label = gtk_label_new(TR("To:"));
|
| 108 | to_body_label = gtk_label_new("");
|
| 109 | cc_header_label = gtk_label_new(TR("Cc:"));
|
| 110 | cc_body_label = gtk_label_new("");
|
| 111 | ng_header_label = gtk_label_new(TR("Newsgroups:"));
|
| 112 | ng_body_label = gtk_label_new("");
|
| 113 | subject_header_label = gtk_label_new(TR("Subject:"));
|
| 114 | subject_body_label = gtk_label_new("");
|
| 115 | |
| 116 | gtk_label_set_selectable(GTK_LABEL(from_body_label), TRUE); |
| 117 | gtk_label_set_selectable(GTK_LABEL(to_body_label), TRUE); |
| 118 | gtk_label_set_selectable(GTK_LABEL(cc_body_label), TRUE); |
| 119 | gtk_label_set_selectable(GTK_LABEL(ng_body_label), TRUE); |
| 120 | gtk_label_set_selectable(GTK_LABEL(subject_body_label), TRUE); |
| 121 | |
| 122 | GTK_WIDGET_UNSET_FLAGS(from_body_label, GTK_CAN_FOCUS); |
| 123 | GTK_WIDGET_UNSET_FLAGS(to_body_label, GTK_CAN_FOCUS); |
| 124 | GTK_WIDGET_UNSET_FLAGS(cc_body_label, GTK_CAN_FOCUS); |
| 125 | GTK_WIDGET_UNSET_FLAGS(ng_body_label, GTK_CAN_FOCUS); |
| 126 | GTK_WIDGET_UNSET_FLAGS(subject_body_label, GTK_CAN_FOCUS); |
| 127 | |
| 128 | gtk_widget_add_events(from_body_label, GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK); |
| 129 | gtk_widget_add_events(to_body_label, GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK); |
| 130 | gtk_widget_add_events(cc_body_label, GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK); |
| 131 | gtk_widget_add_events(ng_body_label, GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK); |
| 132 | gtk_widget_add_events(subject_body_label, GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK); |
| 133 | |
| 134 | tip = gtk_tooltips_new(); |
| 135 | g_object_ref_sink(tip); |
| 136 | |
| 137 | gtk_box_pack_start(GTK_BOX(hbox1), from_header_label, FALSE, FALSE, 0);
|
| 138 | gtk_box_pack_start(GTK_BOX(hbox1), from_body_label, FALSE, FALSE, 0);
|
| 139 | gtk_box_pack_start(GTK_BOX(hbox1), to_header_label, FALSE, FALSE, 0);
|
| 140 | gtk_box_pack_start(GTK_BOX(hbox1), to_body_label, FALSE, FALSE, 0);
|
| 141 | gtk_box_pack_start(GTK_BOX(hbox1), cc_header_label, FALSE, FALSE, 0);
|
| 142 | gtk_box_pack_start(GTK_BOX(hbox1), cc_body_label, FALSE, FALSE, 0);
|
| 143 | gtk_box_pack_start(GTK_BOX(hbox1), ng_header_label, FALSE, FALSE, 0);
|
| 144 | gtk_box_pack_start(GTK_BOX(hbox1), ng_body_label, FALSE, FALSE, 0);
|
| 145 | gtk_box_pack_start(GTK_BOX(hbox2), subject_header_label, FALSE, FALSE, 0);
|
| 146 | gtk_box_pack_start(GTK_BOX(hbox2), subject_body_label, FALSE, FALSE, 0);
|
| 147 | |
| 148 | headerview->hbox = hbox; |
| 149 | headerview->from_header_label = from_header_label; |
| 150 | headerview->from_body_label = from_body_label; |
| 151 | headerview->to_header_label = to_header_label; |
| 152 | headerview->to_body_label = to_body_label; |
| 153 | headerview->cc_header_label = cc_header_label; |
| 154 | headerview->cc_body_label = cc_body_label; |
| 155 | headerview->ng_header_label = ng_header_label; |
| 156 | headerview->ng_body_label = ng_body_label; |
| 157 | headerview->subject_header_label = subject_header_label; |
| 158 | headerview->subject_body_label = subject_body_label; |
| 159 | |
| 160 | headerview->image = NULL;
|
| 161 | |
| 162 | headerview->tip = tip; |
| 163 | |
| 164 | gtk_widget_show_all(hbox); |
| 165 | |
| 166 | return headerview;
|
| 167 | } |
| 168 | |
| 169 | void headerview_init(HeaderView *headerview)
|
| 170 | {
|
| 171 | static PangoFontDescription *boldfont = NULL; |
| 172 | #ifdef G_OS_WIN32
|
| 173 | GtkStyle *style; |
| 174 | #endif
|
| 175 | |
| 176 | if (!boldfont) {
|
| 177 | boldfont = pango_font_description_new(); |
| 178 | pango_font_description_set_weight(boldfont, PANGO_WEIGHT_BOLD); |
| 179 | } |
| 180 | |
| 181 | if (boldfont) {
|
| 182 | gtk_widget_modify_font(headerview->from_header_label, boldfont); |
| 183 | gtk_widget_modify_font(headerview->to_header_label, boldfont); |
| 184 | gtk_widget_modify_font(headerview->cc_header_label, boldfont); |
| 185 | gtk_widget_modify_font(headerview->ng_header_label, boldfont); |
| 186 | gtk_widget_modify_font(headerview->subject_header_label, boldfont); |
| 187 | } |
| 188 | |
| 189 | #ifdef G_OS_WIN32
|
| 190 | #define SET_LABEL_STYLE(label) \
|
| 191 | style = gtk_widget_get_style(label); \ |
| 192 | gtk_widget_modify_base(label, GTK_STATE_ACTIVE, \ |
| 193 | &style->base[GTK_STATE_SELECTED]); \ |
| 194 | gtk_widget_modify_text(label, GTK_STATE_ACTIVE, \ |
| 195 | &style->text[GTK_STATE_SELECTED]); |
| 196 | |
| 197 | SET_LABEL_STYLE(headerview->from_body_label); |
| 198 | SET_LABEL_STYLE(headerview->to_body_label); |
| 199 | SET_LABEL_STYLE(headerview->cc_body_label); |
| 200 | SET_LABEL_STYLE(headerview->ng_body_label); |
| 201 | SET_LABEL_STYLE(headerview->subject_body_label); |
| 202 | |
| 203 | #undef SET_LABEL_STYLE
|
| 204 | #endif
|
| 205 | |
| 206 | headerview_clear(headerview); |
| 207 | headerview_set_visibility(headerview, prefs_common.display_header_pane); |
| 208 | |
| 209 | #if HAVE_LIBCOMPFACE
|
| 210 | {
|
| 211 | gint i; |
| 212 | |
| 213 | for (i = 0; i < XPM_XFACE_HEIGHT; i++) { |
| 214 | xpm_xface[i] = g_malloc(WIDTH + 1);
|
| 215 | *xpm_xface[i] = '\0';
|
| 216 | } |
| 217 | } |
| 218 | #endif
|
| 219 | } |
| 220 | |
| 221 | void headerview_show(HeaderView *headerview, MsgInfo *msginfo)
|
| 222 | {
|
| 223 | headerview_clear(headerview); |
| 224 | |
| 225 | gtk_tooltips_enable(headerview->tip); |
| 226 | |
| 227 | gtk_label_set_text(GTK_LABEL(headerview->from_body_label), |
| 228 | msginfo->from ? msginfo->from : _("(No From)"));
|
| 229 | if (msginfo->from) {
|
| 230 | gtk_widget_show(headerview->from_body_label); |
| 231 | gtk_tooltips_set_tip(headerview->tip, headerview->from_body_label, msginfo->from, NULL);
|
| 232 | } |
| 233 | |
| 234 | if (msginfo->to) {
|
| 235 | gtk_label_set_text(GTK_LABEL(headerview->to_body_label), |
| 236 | msginfo->to); |
| 237 | gtk_widget_show(headerview->to_header_label); |
| 238 | gtk_widget_show(headerview->to_body_label); |
| 239 | gtk_tooltips_set_tip(headerview->tip, headerview->to_body_label, msginfo->to, NULL);
|
| 240 | } |
| 241 | |
| 242 | if (msginfo->cc) {
|
| 243 | gtk_label_set_text(GTK_LABEL(headerview->cc_body_label), |
| 244 | msginfo->cc); |
| 245 | gtk_widget_show(headerview->cc_header_label); |
| 246 | gtk_widget_show(headerview->cc_body_label); |
| 247 | gtk_tooltips_set_tip(headerview->tip, headerview->cc_body_label, msginfo->cc, NULL);
|
| 248 | } |
| 249 | |
| 250 | if (msginfo->newsgroups) {
|
| 251 | gtk_label_set_text(GTK_LABEL(headerview->ng_body_label), |
| 252 | msginfo->newsgroups); |
| 253 | gtk_widget_show(headerview->ng_header_label); |
| 254 | gtk_widget_show(headerview->ng_body_label); |
| 255 | gtk_tooltips_set_tip(headerview->tip, headerview->ng_body_label, msginfo->newsgroups, NULL);
|
| 256 | } |
| 257 | |
| 258 | gtk_label_set_text(GTK_LABEL(headerview->subject_body_label), |
| 259 | msginfo->subject ? msginfo->subject |
| 260 | : _("(No Subject)"));
|
| 261 | if (msginfo->subject) {
|
| 262 | gtk_widget_show(headerview->subject_body_label); |
| 263 | gtk_tooltips_set_tip(headerview->tip, headerview->subject_body_label, msginfo->subject, NULL);
|
| 264 | } |
| 265 | |
| 266 | #if HAVE_LIBCOMPFACE
|
| 267 | headerview_show_xface(headerview, msginfo); |
| 268 | #endif
|
| 269 | } |
| 270 | |
| 271 | #if HAVE_LIBCOMPFACE
|
| 272 | static void headerview_show_xface(HeaderView *headerview, MsgInfo *msginfo) |
| 273 | {
|
| 274 | gchar xface[2048];
|
| 275 | GdkPixmap *pixmap; |
| 276 | GdkBitmap *mask; |
| 277 | GtkWidget *hbox = headerview->hbox; |
| 278 | |
| 279 | if (!msginfo->xface || strlen(msginfo->xface) < 5) { |
| 280 | if (headerview->image &&
|
| 281 | GTK_WIDGET_VISIBLE(headerview->image)) {
|
| 282 | gtk_widget_hide(headerview->image); |
| 283 | gtk_widget_queue_resize(hbox); |
| 284 | } |
| 285 | return;
|
| 286 | } |
| 287 | if (!GTK_WIDGET_VISIBLE(headerview->hbox)) return; |
| 288 | |
| 289 | strncpy(xface, msginfo->xface, sizeof(xface));
|
| 290 | |
| 291 | if (uncompface(xface) < 0) { |
| 292 | g_warning("uncompface failed\n");
|
| 293 | if (headerview->image)
|
| 294 | gtk_widget_hide(headerview->image); |
| 295 | return;
|
| 296 | } |
| 297 | |
| 298 | create_xpm_from_xface(xpm_xface, xface); |
| 299 | |
| 300 | pixmap = gdk_pixmap_create_from_xpm_d |
| 301 | (hbox->window, &mask, &hbox->style->white, xpm_xface); |
| 302 | |
| 303 | if (!headerview->image) {
|
| 304 | GtkWidget *image; |
| 305 | |
| 306 | image = gtk_image_new_from_pixmap(pixmap, mask); |
| 307 | gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
|
| 308 | gtk_widget_show(image); |
| 309 | headerview->image = image; |
| 310 | } else {
|
| 311 | gtk_image_set_from_pixmap(GTK_IMAGE(headerview->image), |
| 312 | pixmap, mask); |
| 313 | gtk_widget_show(headerview->image); |
| 314 | } |
| 315 | |
| 316 | gdk_pixmap_unref(pixmap); |
| 317 | } |
| 318 | #endif
|
| 319 | |
| 320 | void headerview_clear(HeaderView *headerview)
|
| 321 | {
|
| 322 | gtk_label_set_text(GTK_LABEL(headerview->from_body_label), "");
|
| 323 | gtk_label_set_text(GTK_LABEL(headerview->to_body_label), "");
|
| 324 | gtk_label_set_text(GTK_LABEL(headerview->cc_body_label), "");
|
| 325 | gtk_label_set_text(GTK_LABEL(headerview->ng_body_label), "");
|
| 326 | gtk_label_set_text(GTK_LABEL(headerview->subject_body_label), "");
|
| 327 | gtk_widget_hide(headerview->from_body_label); |
| 328 | gtk_widget_hide(headerview->to_header_label); |
| 329 | gtk_widget_hide(headerview->to_body_label); |
| 330 | gtk_widget_hide(headerview->cc_header_label); |
| 331 | gtk_widget_hide(headerview->cc_body_label); |
| 332 | gtk_widget_hide(headerview->ng_header_label); |
| 333 | gtk_widget_hide(headerview->ng_body_label); |
| 334 | gtk_widget_hide(headerview->subject_body_label); |
| 335 | |
| 336 | gtk_tooltips_disable(headerview->tip); |
| 337 | |
| 338 | if (headerview->image && GTK_WIDGET_VISIBLE(headerview->image)) {
|
| 339 | gtk_widget_hide(headerview->image); |
| 340 | gtk_widget_queue_resize(headerview->hbox); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | void headerview_set_visibility(HeaderView *headerview, gboolean visibility)
|
| 345 | {
|
| 346 | if (visibility)
|
| 347 | gtk_widget_show(headerview->hbox); |
| 348 | else
|
| 349 | gtk_widget_hide(headerview->hbox); |
| 350 | } |
| 351 | |
| 352 | void headerview_destroy(HeaderView *headerview)
|
| 353 | {
|
| 354 | g_object_unref(headerview->tip); |
| 355 | g_free(headerview); |
| 356 | } |
| 357 | |
| 358 | #if HAVE_LIBCOMPFACE
|
| 359 | static gint create_xpm_from_xface(gchar *xpm[], const gchar *xface) |
| 360 | {
|
| 361 | static gchar *bit_pattern[] = {
|
| 362 | "....",
|
| 363 | "...#",
|
| 364 | "..#.",
|
| 365 | "..##",
|
| 366 | ".#..",
|
| 367 | ".#.#",
|
| 368 | ".##.",
|
| 369 | ".###",
|
| 370 | "#...",
|
| 371 | "#..#",
|
| 372 | "#.#.",
|
| 373 | "#.##",
|
| 374 | "##..",
|
| 375 | "##.#",
|
| 376 | "###.",
|
| 377 | "####"
|
| 378 | }; |
| 379 | |
| 380 | static gchar *xface_header = "48 48 2 1"; |
| 381 | static gchar *xface_black = "# c #000000"; |
| 382 | static gchar *xface_white = ". c #ffffff"; |
| 383 | |
| 384 | gint i, line = 0;
|
| 385 | const guchar *p;
|
| 386 | gchar buf[WIDTH * 4 + 1]; /* 4 = strlen("0x0000") */ |
| 387 | |
| 388 | p = (const guchar *)xface;
|
| 389 | |
| 390 | strcpy(xpm[line++], xface_header); |
| 391 | strcpy(xpm[line++], xface_black); |
| 392 | strcpy(xpm[line++], xface_white); |
| 393 | |
| 394 | for (i = 0; i < HEIGHT; i++) { |
| 395 | gint col; |
| 396 | |
| 397 | buf[0] = '\0'; |
| 398 | |
| 399 | for (col = 0; col < 3; col++) { |
| 400 | gint figure; |
| 401 | |
| 402 | p += 2; /* skip '0x' */ |
| 403 | |
| 404 | for (figure = 0; figure < 4; figure++) { |
| 405 | gint n = 0;
|
| 406 | |
| 407 | if ('0' <= *p && *p <= '9') { |
| 408 | n = *p - '0';
|
| 409 | } else if ('a' <= *p && *p <= 'f') { |
| 410 | n = *p - 'a' + 10; |
| 411 | } else if ('A' <= *p && *p <= 'F') { |
| 412 | n = *p - 'A' + 10; |
| 413 | } |
| 414 | |
| 415 | strcat(buf, bit_pattern[n]); |
| 416 | p++; /* skip ',' */
|
| 417 | } |
| 418 | |
| 419 | p++; /* skip '\n' */
|
| 420 | } |
| 421 | |
| 422 | strcpy(xpm[line++], buf); |
| 423 | p++; |
| 424 | } |
| 425 | |
| 426 | return 0; |
| 427 | } |
| 428 | #endif
|