for release 3.15.1
[claws.git] / src / avatars.c
blobce03cdcf3d08da611f73db795014ea6de5b3c9fd
1 /*
2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2014-2016 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/>.
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #include "claws-features.h"
22 #endif
24 #include <glib.h>
25 #include <glib/gi18n.h>
26 #include <gtk/gtk.h>
28 #include "defs.h"
29 #include "hooks.h"
30 #include "gtkutils.h"
31 #include "procmsg.h"
32 #include "prefs_common.h"
33 #include "avatars.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;
41 ar->image = NULL;
42 ar->type = 0;
44 return ar;
47 void avatars_avatarrender_free(AvatarRender *avrender)
49 if (avrender == NULL)
50 return;
52 if (avrender->image != NULL) {
53 gtk_widget_destroy(avrender->image);
55 g_free(avrender);
58 gboolean avatars_internal_rendering_hook(gpointer source, gpointer data)
60 AvatarRender *avatarr = (AvatarRender *)source;
61 gchar *aface;
63 if (!(prefs_common.enable_avatars & AVATARS_ENABLE_RENDER)) {
64 debug_print("Internal rendering of avatars is disabled\n");
65 return FALSE;
68 if (avatarr == NULL) {
69 g_warning("Internal rendering invoked with NULL argument");
70 return FALSE;
73 if (avatarr->image != NULL) {
74 g_warning("Memory leak: image widget not destroyed");
77 aface = procmsg_msginfo_get_avatar(avatarr->full_msginfo, AVATAR_FACE);
78 if (aface) {
79 avatarr->image = face_get_from_header(aface);
80 avatarr->type = AVATAR_FACE;
82 #if HAVE_LIBCOMPFACE
83 else {
84 aface = procmsg_msginfo_get_avatar(avatarr->full_msginfo, AVATAR_XFACE);
85 if (aface) {
86 avatarr->image = xface_get_from_header(aface);
87 avatarr->type = AVATAR_XFACE;
90 #endif
91 return FALSE;
94 void avatars_init(void)
96 if (avatar_render_hook_id != -1) {
97 g_warning("Internal avatars rendering already initialized");
98 return;
100 avatar_render_hook_id = hooks_register_hook(AVATAR_IMAGE_RENDER_HOOKLIST, avatars_internal_rendering_hook, NULL);
101 if (avatar_render_hook_id == -1) {
102 g_warning("Failed to register avatars internal rendering hook");
106 void avatars_done(void)
108 if (avatar_render_hook_id != -1) {
109 hooks_unregister_hook(AVATAR_IMAGE_RENDER_HOOKLIST, avatar_render_hook_id);
110 avatar_render_hook_id = -1;