2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2016 Hiroyuki Yamamoto and the Claws Mail team
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/>.
21 #include "claws-features.h"
27 #include <glib/gi18n.h>
33 #include <gdk-pixbuf/gdk-pixbuf.h>
35 #include "headerview.h"
36 #include "prefs_common.h"
41 #include "addrindex.h"
45 static gint
headerview_show_avatar (HeaderView
*headerview
,
47 static gint
headerview_show_contact_pic (HeaderView
*headerview
,
49 static void headerview_save_contact_pic (HeaderView
*headerview
,
52 HeaderView
*headerview_create(void)
54 HeaderView
*headerview
;
60 GtkWidget
*from_header_label
;
61 GtkWidget
*from_body_label
;
62 GtkWidget
*to_header_label
;
63 GtkWidget
*to_body_label
;
64 GtkWidget
*ng_header_label
;
65 GtkWidget
*ng_body_label
;
66 GtkWidget
*subject_header_label
;
67 GtkWidget
*subject_body_label
;
68 GtkWidget
*tags_header_label
;
69 GtkWidget
*tags_body_label
;
71 debug_print("Creating header view...\n");
72 headerview
= g_new0(HeaderView
, 1);
74 hbox
= gtk_hbox_new(FALSE
, 0);
75 gtk_container_set_border_width(GTK_CONTAINER(hbox
), 2);
76 vbox
= gtk_vbox_new(FALSE
, 2);
77 gtk_box_pack_start(GTK_BOX(hbox
), vbox
, TRUE
, TRUE
, 0);
79 hbox1
= gtk_hbox_new(FALSE
, 4);
80 gtk_box_pack_start(GTK_BOX(vbox
), hbox1
, FALSE
, FALSE
, 0);
81 hbox2
= gtk_hbox_new(FALSE
, 4);
82 gtk_box_pack_start(GTK_BOX(vbox
), hbox2
, FALSE
, FALSE
, 0);
83 hbox3
= gtk_hbox_new(FALSE
, 4);
84 gtk_box_pack_start(GTK_BOX(vbox
), hbox3
, FALSE
, FALSE
, 0);
86 from_header_label
= gtk_label_new(prefs_common_translated_header_name("From:"));
87 from_body_label
= gtk_label_new("");
88 to_header_label
= gtk_label_new(prefs_common_translated_header_name("To:"));
89 to_body_label
= gtk_label_new("");
90 ng_header_label
= gtk_label_new(prefs_common_translated_header_name("Newsgroups:"));
91 ng_body_label
= gtk_label_new("");
92 subject_header_label
= gtk_label_new(prefs_common_translated_header_name("Subject:"));
93 subject_body_label
= gtk_label_new("");
94 tags_header_label
= gtk_label_new(_("Tags:"));
95 tags_body_label
= gtk_label_new("");
97 gtk_label_set_selectable(GTK_LABEL(from_body_label
), TRUE
);
98 gtk_label_set_selectable(GTK_LABEL(to_body_label
), TRUE
);
99 gtk_label_set_selectable(GTK_LABEL(ng_body_label
), TRUE
);
100 gtk_label_set_selectable(GTK_LABEL(subject_body_label
), TRUE
);
101 gtk_label_set_selectable(GTK_LABEL(tags_body_label
), TRUE
);
103 gtkut_widget_set_can_focus(from_body_label
, FALSE
);
104 gtkut_widget_set_can_focus(to_body_label
, FALSE
);
105 gtkut_widget_set_can_focus(ng_body_label
, FALSE
);
106 gtkut_widget_set_can_focus(subject_body_label
, FALSE
);
107 gtkut_widget_set_can_focus(tags_body_label
, FALSE
);
109 gtk_box_pack_start(GTK_BOX(hbox1
), from_header_label
, FALSE
, FALSE
, 0);
110 gtk_box_pack_start(GTK_BOX(hbox1
), from_body_label
, FALSE
, FALSE
, 0);
111 gtk_box_pack_start(GTK_BOX(hbox1
), to_header_label
, FALSE
, FALSE
, 0);
112 gtk_box_pack_start(GTK_BOX(hbox1
), to_body_label
, TRUE
, TRUE
, 0);
113 gtk_box_pack_start(GTK_BOX(hbox1
), ng_header_label
, FALSE
, FALSE
, 0);
114 gtk_box_pack_start(GTK_BOX(hbox1
), ng_body_label
, TRUE
, TRUE
, 0);
115 gtk_box_pack_start(GTK_BOX(hbox2
), subject_header_label
, FALSE
, FALSE
, 0);
116 gtk_box_pack_start(GTK_BOX(hbox2
), subject_body_label
, TRUE
, TRUE
, 0);
117 gtk_box_pack_start(GTK_BOX(hbox3
), tags_header_label
, FALSE
, FALSE
, 0);
118 gtk_box_pack_start(GTK_BOX(hbox3
), tags_body_label
, TRUE
, TRUE
, 0);
120 gtk_misc_set_alignment(GTK_MISC(to_body_label
), 0, 0.5);
121 gtk_misc_set_alignment(GTK_MISC(ng_body_label
), 0, 0.5);
122 gtk_misc_set_alignment(GTK_MISC(subject_body_label
), 0, 0.5);
123 gtk_misc_set_alignment(GTK_MISC(tags_body_label
), 0, 0.5);
124 gtk_label_set_ellipsize(GTK_LABEL(to_body_label
), PANGO_ELLIPSIZE_END
);
125 gtk_label_set_ellipsize(GTK_LABEL(ng_body_label
), PANGO_ELLIPSIZE_END
);
126 gtk_label_set_ellipsize(GTK_LABEL(subject_body_label
), PANGO_ELLIPSIZE_END
);
127 gtk_label_set_ellipsize(GTK_LABEL(tags_body_label
), PANGO_ELLIPSIZE_END
);
129 headerview
->hbox
= hbox
;
130 headerview
->from_header_label
= from_header_label
;
131 headerview
->from_body_label
= from_body_label
;
132 headerview
->to_header_label
= to_header_label
;
133 headerview
->to_body_label
= to_body_label
;
134 headerview
->ng_header_label
= ng_header_label
;
135 headerview
->ng_body_label
= ng_body_label
;
136 headerview
->subject_header_label
= subject_header_label
;
137 headerview
->subject_body_label
= subject_body_label
;
138 headerview
->tags_header_label
= tags_header_label
;
139 headerview
->tags_body_label
= tags_body_label
;
140 headerview
->image
= NULL
;
142 gtk_widget_show_all(hbox
);
147 void headerview_set_font(HeaderView
*headerview
)
149 PangoFontDescription
*boldfont
= NULL
;
150 PangoFontDescription
*normalfont
= NULL
;
152 normalfont
= pango_font_description_from_string(NORMAL_FONT
);
154 gtk_widget_modify_font(headerview
->from_body_label
, normalfont
);
155 gtk_widget_modify_font(headerview
->to_body_label
, normalfont
);
156 gtk_widget_modify_font(headerview
->ng_body_label
, normalfont
);
157 gtk_widget_modify_font(headerview
->subject_body_label
, normalfont
);
158 gtk_widget_modify_font(headerview
->tags_body_label
, normalfont
);
159 pango_font_description_free(normalfont
);
162 if (prefs_common
.derive_from_normal_font
|| !BOLD_FONT
) {
163 boldfont
= pango_font_description_from_string(NORMAL_FONT
);
164 pango_font_description_set_weight(boldfont
, PANGO_WEIGHT_BOLD
);
166 boldfont
= pango_font_description_from_string(BOLD_FONT
);
169 gtk_widget_modify_font(headerview
->from_header_label
, boldfont
);
170 gtk_widget_modify_font(headerview
->to_header_label
, boldfont
);
171 gtk_widget_modify_font(headerview
->ng_header_label
, boldfont
);
172 gtk_widget_modify_font(headerview
->subject_header_label
, boldfont
);
173 gtk_widget_modify_font(headerview
->tags_header_label
, boldfont
);
174 pango_font_description_free(boldfont
);
178 void headerview_init(HeaderView
*headerview
)
180 headerview_set_font(headerview
);
181 headerview_clear(headerview
);
182 headerview_set_visibility(headerview
, prefs_common
.display_header_pane
);
185 void headerview_show(HeaderView
*headerview
, MsgInfo
*msginfo
)
187 gchar
*tags
= procmsg_msginfo_get_tags_str(msginfo
);
189 headerview_clear(headerview
);
191 gtk_label_set_text(GTK_LABEL(headerview
->from_body_label
),
192 msginfo
->from
? msginfo
->from
: _("(No From)"));
194 gtk_label_set_text(GTK_LABEL(headerview
->to_body_label
),
196 gtk_widget_show(headerview
->to_header_label
);
197 gtk_widget_show(headerview
->to_body_label
);
199 if (msginfo
->newsgroups
) {
200 gtk_label_set_text(GTK_LABEL(headerview
->ng_body_label
),
201 msginfo
->newsgroups
);
202 gtk_widget_show(headerview
->ng_header_label
);
203 gtk_widget_show(headerview
->ng_body_label
);
205 gtk_label_set_text(GTK_LABEL(headerview
->subject_body_label
),
206 msginfo
->subject
? msginfo
->subject
:
209 gtk_label_set_text(GTK_LABEL(headerview
->tags_body_label
),
211 gtk_widget_show(headerview
->tags_header_label
);
212 gtk_widget_show(headerview
->tags_body_label
);
215 if (!headerview_show_avatar(headerview
, msginfo
))
218 if (!headerview_show_contact_pic(headerview
, msginfo
))
223 static gint
headerview_show_avatar (HeaderView
*headerview
, MsgInfo
*msginfo
)
225 AvatarRender
*avatarr
= avatars_avatarrender_new(msginfo
);
226 GtkWidget
*hbox
= headerview
->hbox
;
228 hooks_invoke(AVATAR_IMAGE_RENDER_HOOKLIST
, avatarr
);
230 if (!avatarr
->image
) {
231 if (headerview
->image
232 && gtk_widget_get_visible(headerview
->image
)) {
233 gtk_widget_hide(headerview
->image
);
234 gtk_widget_queue_resize(hbox
);
236 avatars_avatarrender_free(avatarr
);
239 if (!gtk_widget_get_visible(hbox
)) {
240 avatars_avatarrender_free(avatarr
);
244 if (headerview
->image
) {
245 gtk_widget_destroy(headerview
->image
);
246 headerview
->image
= NULL
;
249 gtk_box_pack_start(GTK_BOX(hbox
), avatarr
->image
, FALSE
, FALSE
, 0);
250 gtk_widget_show(avatarr
->image
);
252 headerview
->image
= avatarr
->image
;
253 avatarr
->image
= NULL
; /* avoid destroying */
254 avatars_avatarrender_free(avatarr
);
256 headerview_save_contact_pic(headerview
, msginfo
);
260 static void headerview_save_contact_pic (HeaderView
*headerview
, MsgInfo
*msginfo
)
262 #ifndef USE_ALT_ADDRBOOK
263 gchar
*filename
= NULL
;
264 GError
*error
= NULL
;
265 GdkPixbuf
*picture
= NULL
;
267 if (!gtk_widget_get_visible(headerview
->hbox
)) return;
269 if (headerview
->image
) {
270 picture
= gtk_image_get_pixbuf(GTK_IMAGE(headerview
->image
));
273 filename
= addrindex_get_picture_file(msginfo
->from
);
276 if (!is_file_exist(filename
)) {
277 gdk_pixbuf_save(picture
, filename
, "png", &error
, NULL
);
279 g_warning("Failed to save image: %s",
286 /* new address book */
290 static gint
headerview_show_contact_pic (HeaderView
*headerview
, MsgInfo
*msginfo
)
292 #ifndef USE_ALT_ADDRBOOK
293 GtkWidget
*hbox
= headerview
->hbox
;
295 gchar
*filename
= NULL
;
296 GError
*error
= NULL
;
297 GdkPixbuf
*picture
= NULL
;
300 if (!gtk_widget_get_visible(headerview
->hbox
)) return -1;
302 if (headerview
->image
) {
303 gtk_widget_destroy(headerview
->image
);
304 headerview
->image
= NULL
;
307 filename
= addrindex_get_picture_file(msginfo
->from
);
311 if (!is_file_exist(filename
)) {
315 gdk_pixbuf_get_file_info(filename
, &w
, &h
);
317 if (w
> 48 || h
> 48)
318 picture
= gdk_pixbuf_new_from_file_at_scale(filename
,
319 48, 48, TRUE
, &error
);
321 picture
= gdk_pixbuf_new_from_file(filename
, &error
);
325 debug_print("Failed to import image: %s\n",
331 image
= gtk_image_new_from_pixbuf(picture
);
335 g_object_unref(picture
);
337 gtk_box_pack_start(GTK_BOX(hbox
), image
, FALSE
, FALSE
, 0);
338 gtk_widget_show(image
);
341 headerview
->image
= image
;
347 /* new address book */
352 void headerview_clear(HeaderView
*headerview
)
354 if (headerview
== NULL
)
357 gtk_label_set_text(GTK_LABEL(headerview
->from_body_label
), "");
358 gtk_label_set_text(GTK_LABEL(headerview
->to_body_label
), "");
359 gtk_label_set_text(GTK_LABEL(headerview
->ng_body_label
), "");
360 gtk_label_set_text(GTK_LABEL(headerview
->subject_body_label
), "");
361 gtk_label_set_text(GTK_LABEL(headerview
->tags_body_label
), "");
362 gtk_widget_hide(headerview
->to_header_label
);
363 gtk_widget_hide(headerview
->to_body_label
);
364 gtk_widget_hide(headerview
->ng_header_label
);
365 gtk_widget_hide(headerview
->ng_body_label
);
366 gtk_widget_hide(headerview
->tags_header_label
);
367 gtk_widget_hide(headerview
->tags_body_label
);
369 if (headerview
->image
&& gtk_widget_get_visible(headerview
->image
)) {
370 gtk_widget_hide(headerview
->image
);
371 gtk_widget_queue_resize(headerview
->hbox
);
375 void headerview_set_visibility(HeaderView
*headerview
, gboolean visibility
)
378 gtk_widget_show(headerview
->hbox
);
380 gtk_widget_hide(headerview
->hbox
);
383 void headerview_destroy(HeaderView
*headerview
)