commit daea250f36c7346e018cdc8a759f10ff0c9834f5
parent a3ec21768c199ad01785f8ec177cf60470824759
Author: Ricardo Mones <ricardo@mones.org>
Date: Sat, 15 Feb 2014 20:40:43 +0100
New hooklist for rendering avatars and some utils
• Create and destroy hooklist parameter structs
• Initialization function to install default handler
Diffstat:
4 files changed, 162 insertions(+), 0 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
@@ -130,6 +130,7 @@ claws_mail_SOURCES = \
advsearch.c \
alertpanel.c \
autofaces.c \
+ avatars.c \
codeconv.c \
compose.c \
crash.c \
@@ -244,6 +245,7 @@ claws_mailinclude_HEADERS = \
advsearch.h \
alertpanel.h \
autofaces.h \
+ avatars.h \
codeconv.h \
compose.h \
crash.h \
diff --git a/src/avatars.c b/src/avatars.c
@@ -0,0 +1,110 @@
+/*
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2014 Ricardo Mones and the Claws Mail team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#include "claws-features.h"
+#endif
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "defs.h"
+#include "hooks.h"
+#include "gtkutils.h"
+#include "procmsg.h"
+#include "prefs_common.h"
+#include "avatars.h"
+
+static guint avatar_render_hook_id = -1;
+
+AvatarRender *avatars_avatarrender_new(MsgInfo *msginfo)
+{
+ AvatarRender *ar = g_new0(AvatarRender, 1);
+ ar->full_msginfo = msginfo;
+ ar->image = NULL;
+
+ return ar;
+}
+
+void avatars_avatarrender_free(AvatarRender *avrender)
+{
+ if (avrender == NULL)
+ return;
+
+ if (avrender->image != NULL) {
+ gtk_widget_destroy(avrender->image);
+ }
+ g_free(avrender);
+}
+
+gboolean avatars_internal_rendering_hook(gpointer source, gpointer data)
+{
+ AvatarRender *avatarr = (AvatarRender *)source;
+ gchar *aface;
+
+ if (!(prefs_common.enable_avatars | AVATARS_ENABLE_RENDER)) {
+ debug_print("Internal rendering of avatars is disabled");
+ return FALSE;
+ }
+
+ if (avatarr == NULL) {
+ g_warning("Internal rendering invoked with NULL argument");
+ return FALSE;
+ }
+
+ if (avatarr->image != NULL) {
+ g_warning("Memory leak: image widget not destroyed");
+ }
+
+ aface = procmsg_msginfo_get_avatar(avatarr->full_msginfo, AVATAR_FACE);
+ if (aface) {
+ avatarr->image = face_get_from_header(aface);
+ }
+#if HAVE_LIBCOMPFACE
+ else {
+ aface = procmsg_msginfo_get_avatar(avatarr->full_msginfo, AVATAR_XFACE);
+ if (aface) {
+ avatarr->image = xface_get_from_header(aface);
+ }
+ }
+#endif
+ return FALSE;
+}
+
+void avatars_init(void)
+{
+ if (avatar_render_hook_id != -1) {
+ g_warning(_("Internal avatars rendering already initialized"));
+ return;
+ }
+ avatar_render_hook_id = hooks_register_hook(AVATAR_IMAGE_RENDER_HOOKLIST, avatars_internal_rendering_hook, NULL);
+ if (avatar_render_hook_id == -1) {
+ g_warning(_("Failed to register avatars internal rendering hook"));
+ }
+}
+
+void avatars_done(void)
+{
+ if (avatar_render_hook_id != -1) {
+ hooks_unregister_hook(AVATAR_IMAGE_RENDER_HOOKLIST, avatar_render_hook_id);
+ avatar_render_hook_id = -1;
+ }
+}
+
diff --git a/src/avatars.h b/src/avatars.h
@@ -0,0 +1,47 @@
+/*
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2014 Ricardo Mones and the Claws Mail team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __AVATARS_H__
+#define __AVATARS_H__
+
+#include <glib.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+
+#include "proctypes.h"
+
+#define AVATAR_IMAGE_RENDER_HOOKLIST "avatar_image_render"
+
+typedef struct _AvatarRender AvatarRender;
+
+struct _AvatarRender
+{
+ MsgInfo *full_msginfo;
+ GtkWidget *image;
+};
+
+AvatarRender *avatars_avatarrender_new (MsgInfo *msginfo);
+void avatars_avatarrender_free (AvatarRender *avrender);
+
+gboolean avatars_internal_rendering_hook (gpointer source,
+ gpointer data);
+
+void avatars_init (void);
+void avatars_done (void);
+
+#endif
diff --git a/src/main.c b/src/main.c
@@ -126,6 +126,7 @@
#include "menu.h"
#include "quicksearch.h"
#include "advsearch.h"
+#include "avatars.h"
#ifdef HAVE_LIBETPAN
#include "imap-thread.h"
@@ -1403,6 +1404,7 @@ int main(int argc, char *argv[])
claws_register_idle_function(claws_gtk_idle);
+ avatars_init();
prefs_toolbar_init();
num_folder_class = g_list_length(folder_get_list());
@@ -1655,6 +1657,7 @@ static void exit_claws(MainWindow *mainwin)
matcher_done();
prefs_toolbar_done();
+ avatars_done();
#ifndef USE_NEW_ADDRBOOK
addressbook_destroy();