2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2014 Ricardo Mones 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"
25 #include <glib/gi18n.h>
32 #include "prefs_common.h"
35 static guint avatar_render_hook_id = -1;
37 AvatarRender *avatars_avatarrender_new(MsgInfo *msginfo)
39 AvatarRender *ar = g_new0(AvatarRender, 1);
40 ar->full_msginfo = msginfo;
46 void avatars_avatarrender_free(AvatarRender *avrender)
51 if (avrender->image != NULL) {
52 gtk_widget_destroy(avrender->image);
57 gboolean avatars_internal_rendering_hook(gpointer source, gpointer data)
59 AvatarRender *avatarr = (AvatarRender *)source;
62 if (!(prefs_common.enable_avatars | AVATARS_ENABLE_RENDER)) {
63 debug_print("Internal rendering of avatars is disabled");
67 if (avatarr == NULL) {
68 g_warning("Internal rendering invoked with NULL argument");
72 if (avatarr->image != NULL) {
73 g_warning("Memory leak: image widget not destroyed");
76 aface = procmsg_msginfo_get_avatar(avatarr->full_msginfo, AVATAR_FACE);
78 avatarr->image = face_get_from_header(aface);
82 aface = procmsg_msginfo_get_avatar(avatarr->full_msginfo, AVATAR_XFACE);
84 avatarr->image = xface_get_from_header(aface);
91 void avatars_init(void)
93 if (avatar_render_hook_id != -1) {
94 g_warning(_("Internal avatars rendering already initialized"));
97 avatar_render_hook_id = hooks_register_hook(AVATAR_IMAGE_RENDER_HOOKLIST, avatars_internal_rendering_hook, NULL);
98 if (avatar_render_hook_id == -1) {
99 g_warning(_("Failed to register avatars internal rendering hook"));
103 void avatars_done(void)
105 if (avatar_render_hook_id != -1) {
106 hooks_unregister_hook(AVATAR_IMAGE_RENDER_HOOKLIST, avatar_render_hook_id);
107 avatar_render_hook_id = -1;