revert erroneous 2b0b467727d110b8505517bd92261608e499f57f; we need
[claws.git] / src / textview.c
index b7ead66ed250f04679cba7badec6ff9b767e9cae..9131f91f29b06fc52d46cac98b772c41df48f077 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2014 Hiroyuki Yamamoto 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
 #if HAVE_SYS_WAIT_H
 #include <sys/wait.h>
 #endif
-#if HAVE_LIBCOMPFACE
-#  include <compface.h>
-#endif
-
-#if HAVE_LIBCOMPFACE
-#define XPM_XFACE_HEIGHT       (HEIGHT + 3)  /* 3 = 1 header + 2 colors */
-#endif
 
 #include "main.h"
 #include "summaryview.h"
@@ -76,6 +69,8 @@
 #include "tags.h"
 #include "manage_window.h"
 #include "folder_item_prefs.h"
+#include "hooks.h"
+#include "avatars.h"
 
 static GdkColor quote_colors[3] = {
        {(gulong)0, (gushort)0, (gushort)0, (gushort)0},
@@ -636,34 +631,25 @@ void textview_show_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
        cm_return_if_fail(mimeinfo != NULL);
        cm_return_if_fail(fp != NULL);
 
-       if ((mimeinfo->type == MIMETYPE_MULTIPART) ||
-           ((mimeinfo->type == MIMETYPE_MESSAGE) && !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822"))) {
-               textview->loading = TRUE;
-               textview->stop_loading = FALSE;
-               
-               textview_clear(textview);
-               textview_add_parts(textview, mimeinfo);
-
-               textview->loading = FALSE;
-               textview->stop_loading = FALSE;
-               END_TIMING();
-               return;
-       }
        textview->loading = TRUE;
        textview->stop_loading = FALSE;
 
-       if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0)
-               perror("fseek");
-
        textview_clear(textview);
 
-       if (mimeinfo->type == MIMETYPE_MULTIPART)
+       if (mimeinfo->type == MIMETYPE_MULTIPART ||
+           (mimeinfo->type == MIMETYPE_MESSAGE && !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822"))) {
                textview_add_parts(textview, mimeinfo);
-       else
+       } else {
+               if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0)
+                       perror("fseek");
+
                textview_write_body(textview, mimeinfo);
+       }
 
        textview->loading = FALSE;
        textview->stop_loading = FALSE;
+       textview_set_position(textview, 0);
+
        END_TIMING();
 }
 
@@ -1762,6 +1748,7 @@ void textview_clear(TextView *textview)
        if (textview->image) 
                gtk_widget_destroy(textview->image);
        textview->image = NULL;
+       textview->avatar_type = 0;
 
        if (textview->messageview->mainwin->cursor_count == 0) {
                textview_set_cursor(window, text_cursor);
@@ -1969,26 +1956,32 @@ static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
        return sorted_headers;
 }
 
-static void textview_show_face(TextView *textview)
+static void textview_show_avatar(TextView *textview)
 {
        GtkAllocation allocation;
        GtkTextView *text = GTK_TEXT_VIEW(textview->text);
        MsgInfo *msginfo = textview->messageview->msginfo;
        int x = 0;
-       gchar *face;
+       AvatarRender *avatarr;
        
        if (prefs_common.display_header_pane || !prefs_common.display_xface)
                goto bail;
        
-       face = procmsg_msginfo_get_avatar(msginfo, AVATAR_FACE);
-       if (!face)
+       avatarr = avatars_avatarrender_new(msginfo);
+       hooks_invoke(AVATAR_IMAGE_RENDER_HOOKLIST, avatarr);
+
+       if (!avatarr->image) {
+               avatars_avatarrender_free(avatarr);
                goto bail;
+       }
 
        if (textview->image) 
                gtk_widget_destroy(textview->image);
        
-       textview->image = face_get_from_header(face);
-       cm_return_if_fail(textview->image != NULL);
+       textview->image = avatarr->image;
+       textview->avatar_type = avatarr->type;
+       avatarr->image = NULL; /* avoid destroying */
+       avatars_avatarrender_free(avatarr);
 
        gtk_widget_show(textview->image);
        
@@ -1999,13 +1992,13 @@ static void textview_show_face(TextView *textview)
                GTK_TEXT_WINDOW_TEXT, x, 5);
 
        gtk_widget_show_all(textview->text);
-       
 
        return;
 bail:
        if (textview->image) 
                gtk_widget_destroy(textview->image);
        textview->image = NULL; 
+       textview->avatar_type = 0;
 }
 
 void textview_show_icon(TextView *textview, const gchar *stock_id)
@@ -2034,60 +2027,6 @@ void textview_show_icon(TextView *textview, const gchar *stock_id)
        return;
 }
 
-#if HAVE_LIBCOMPFACE
-static void textview_show_xface(TextView *textview)
-{
-       GtkAllocation allocation;
-       MsgInfo *msginfo = textview->messageview->msginfo;
-       GtkTextView *text = GTK_TEXT_VIEW(textview->text);
-       int x = 0;
-       GdkWindow *window = NULL;
-       gchar *face, *xface;
-       
-       if (prefs_common.display_header_pane || !prefs_common.display_xface)
-               goto bail;
-       
-       if (!msginfo || !msginfo->extradata || !msginfo->extradata->avatars)
-               goto bail;
-
-       face = procmsg_msginfo_get_avatar(msginfo, AVATAR_FACE);
-       if (face)
-               return;
-       
-       xface = procmsg_msginfo_get_avatar(msginfo, AVATAR_XFACE);
-       if (!xface || strlen(xface) < 5)
-               goto bail;
-
-       if (textview->image) 
-               gtk_widget_destroy(textview->image);
-
-       window = mainwindow_get_mainwindow() ?
-                       mainwindow_get_mainwindow()->window->window :
-                       textview->text->window;
-       textview->image = xface_get_from_header(xface,
-                               &textview->text->style->white,
-                               window);
-       cm_return_if_fail(textview->image != NULL);
-
-       gtk_widget_show(textview->image);
-       
-       gtk_widget_get_allocation(textview->text, &allocation);
-       x = allocation.width - WIDTH -5;
-
-       gtk_text_view_add_child_in_window(text, textview->image, 
-               GTK_TEXT_WINDOW_TEXT, x, 5);
-
-       gtk_widget_show_all(textview->text);
-       
-       return;
-bail:
-       if (textview->image) 
-               gtk_widget_destroy(textview->image);
-       textview->image = NULL;
-       
-}
-#endif
-
 static void textview_save_contact_pic(TextView *textview)
 {
 #ifndef USE_NEW_ADDRBOOK
@@ -2095,14 +2034,11 @@ static void textview_save_contact_pic(TextView *textview)
        gchar *filename = NULL;
        GError *error = NULL;
        GdkPixbuf *picture = NULL;
-       gchar *face, *xface;
-                               
+
        if (!msginfo->extradata || !msginfo->extradata->avatars)
                return;
 
-       face = procmsg_msginfo_get_avatar(msginfo, AVATAR_FACE);
-        xface = procmsg_msginfo_get_avatar(msginfo, AVATAR_XFACE);
-       if (!face && !xface)
+       if (textview->avatar_type > AVATAR_FACE)
                return;
 
        if (textview->image) 
@@ -2136,15 +2072,12 @@ static void textview_show_contact_pic(TextView *textview)
        GdkPixbuf *picture = NULL;
        gint w, h;
        GtkAllocation allocation;
-       gchar *face, *xface;
-                               
+
        if (prefs_common.display_header_pane
                || !prefs_common.display_xface)
                goto bail;
        
-       face = procmsg_msginfo_get_avatar(msginfo, AVATAR_FACE);
-       xface = procmsg_msginfo_get_avatar(msginfo, AVATAR_XFACE);
-       if (msginfo->extradata && (face || xface)) /* FIXME extradata not needed */
+       if (msginfo->extradata && msginfo->extradata->avatars)
                return;
 
        if (textview->image) 
@@ -2196,6 +2129,7 @@ bail:
        if (textview->image) 
                gtk_widget_destroy(textview->image);
        textview->image = NULL;
+       textview->avatar_type = 0;
 #else
        /* new address book */
 #endif 
@@ -2351,10 +2285,8 @@ static void textview_show_header(TextView *textview, GPtrArray *headers)
                                                         "header", NULL);
        }
        
-       textview_show_face(textview);
-#if HAVE_LIBCOMPFACE
-       textview_show_xface(textview);
-#endif
+       textview_show_avatar(textview);
+
        textview_save_contact_pic(textview);
        textview_show_contact_pic(textview);
 }
@@ -3176,7 +3108,7 @@ static void add_uri_to_addrbook_cb (GtkAction *action, TextView *textview)
        gchar *fromname, *fromaddress;
        ClickableText *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
                                           "menu_button");
-       GtkWidget *image = NULL;
+       AvatarRender *avatarr = NULL;
        GdkPixbuf *picture = NULL;
        gboolean use_picture = FALSE;
 
@@ -3194,28 +3126,16 @@ static void add_uri_to_addrbook_cb (GtkAction *action, TextView *textview)
        extract_address(fromaddress);
 
        if (use_picture) {
-               gchar *face = procmsg_msginfo_get_avatar(
-                                       textview->messageview->msginfo,
-                                       AVATAR_FACE);
-               if (face) {
-                       image = face_get_from_header(face);
-               }
-#if HAVE_LIBCOMPFACE 
-               else {
-                       gchar *xface = procmsg_msginfo_get_avatar(
-                                               textview->messageview->msginfo,
-                                               AVATAR_XFACE);
-                       if (xface) {
-                               image = xface_get_from_header(xface,
-                                               &textview->text->style->white,
-                                               mainwindow_get_mainwindow()->window->window);
-                       }
-               }
-#endif
+               avatarr = avatars_avatarrender_new(textview->messageview->msginfo);
+               hooks_invoke(AVATAR_IMAGE_RENDER_HOOKLIST, avatarr);
        }
 
-       if (image)
-               picture = gtk_image_get_pixbuf(GTK_IMAGE(image));
+       if (avatarr && avatarr->image) {
+               picture = gtk_image_get_pixbuf(GTK_IMAGE(avatarr->image));
+       }
+       if (avatarr) {
+               avatars_avatarrender_free(avatarr);
+       }
 
 #ifndef USE_NEW_ADDRBOOK
        addressbook_add_contact( fromname, fromaddress, NULL, picture);