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