2006-02-05 [colin] 2.0.0cvs13
[claws.git] / src / textview.c
index 4b4539ed431c5e6cf3aca800262aabbd40663d1d..27eb5c5c6a5b23274bb14d06f83e4b5a802d50c8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2005 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws 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
@@ -61,6 +61,7 @@
 #include "menu.h"
 #include "image_viewer.h"
 #include "filesel.h"
+#include "base64.h"
 
 struct _RemoteURI
 {
@@ -240,7 +241,6 @@ static GtkItemFactoryEntry textview_file_popup_entries[] =
 
 static void scrolled_cb (GtkAdjustment *adj, TextView *textview)
 {
-#if HAVE_LIBCOMPFACE
        if (textview->image) {
                gint x, y, x1;
                x1 = textview->text->allocation.width - WIDTH - 5;
@@ -250,7 +250,6 @@ static void scrolled_cb (GtkAdjustment *adj, TextView *textview)
                gtk_text_view_move_child(GTK_TEXT_VIEW(textview->text), 
                        textview->image, x1, y);
        }
-#endif
 }
 
 static void textview_size_allocate_cb  (GtkWidget      *widget,
@@ -360,7 +359,7 @@ TextView *textview_create(void)
        textview->mail_popup_factory = mail_popupfactory;
        textview->file_popup_menu    = file_popupmenu;
        textview->file_popup_factory = file_popupfactory;
-
+       textview->image              = NULL;
        return textview;
 }
 
@@ -567,7 +566,9 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
 
        g_free(content_type);                      
 
-       if (mimeinfo->disposition == DISPOSITIONTYPE_ATTACHMENT) {
+       if (mimeinfo->disposition == DISPOSITIONTYPE_ATTACHMENT
+       || (mimeinfo->disposition == DISPOSITIONTYPE_INLINE && 
+           mimeinfo->type != MIMETYPE_TEXT)) {
                gtk_text_buffer_insert(buffer, &iter, buf, -1);
                if (mimeinfo->type == MIMETYPE_IMAGE  &&
                    prefs_common.inline_img ) {
@@ -1030,7 +1031,6 @@ static void textview_write_line(TextView *textview, const gchar *str,
                conv_localetodisp(buf, sizeof(buf), str);
                
        strcrchomp(buf);
-       //if (prefs_common.conv_mb_alnum) conv_mb_alnum(buf);
        fg_color = NULL;
 
        /* change color of quotation
@@ -1298,6 +1298,69 @@ static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
        return sorted_headers;
 }
 
+static void textview_show_face(TextView *textview)
+{
+       gchar face[2048];
+       gchar face_png[2048];
+       gint pngsize;
+       GdkPixbuf *pixbuf;
+       GError *error = NULL;
+       GtkTextView *text = GTK_TEXT_VIEW(textview->text);
+       MsgInfo *msginfo = textview->messageview->msginfo;
+       int x = 0;
+
+       if (!msginfo->face) {
+               goto bail;
+       }
+
+       strncpy2(face, msginfo->face, sizeof(face));
+
+       unfold_line(face); /* strip all whitespace and linebreaks */
+       remove_space(face);
+
+       pngsize = base64_decode(face_png, face, strlen(face));
+
+       GdkPixbufLoader *loader = gdk_pixbuf_loader_new ();
+       if (!gdk_pixbuf_loader_write (loader, face_png, pngsize, &error) ||
+           !gdk_pixbuf_loader_close (loader, &error)) {
+               g_warning("loading face failed\n");
+               g_object_unref(loader);
+               goto bail;
+       }
+
+       pixbuf = g_object_ref(gdk_pixbuf_loader_get_pixbuf(loader));
+
+       g_object_unref(loader);
+
+       if ((gdk_pixbuf_get_width(pixbuf) != 48) || (gdk_pixbuf_get_height(pixbuf) != 48)) {
+               g_object_unref(pixbuf);
+               g_warning("wrong_size");
+               goto bail;
+       }
+
+       if (textview->image) 
+               gtk_widget_destroy(textview->image);
+       
+       textview->image = gtk_image_new_from_pixbuf(pixbuf);
+       gtk_widget_show(textview->image);
+       
+       x = textview->text->allocation.width - WIDTH -5;
+
+       gtk_text_view_add_child_in_window(text, textview->image, 
+               GTK_TEXT_WINDOW_TEXT, x, 5);
+
+       g_object_unref(pixbuf);
+       
+       gtk_widget_show_all(textview->text);
+       
+
+       return;
+bail:
+       if (textview->image) 
+               gtk_widget_destroy(textview->image);
+       textview->image = NULL; 
+}
+
 #if HAVE_LIBCOMPFACE
 static void textview_show_xface(TextView *textview)
 {
@@ -1316,6 +1379,9 @@ static void textview_show_xface(TextView *textview)
        if (!msginfo)
                goto bail;
 
+       if (msginfo->face)
+               return;
+       
        if (!msginfo->xface || strlen(msginfo->xface) < 5) {
                goto bail;
        }
@@ -1416,6 +1482,8 @@ static void textview_show_header(TextView *textview, GPtrArray *headers)
                gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "\n", 1,
                                                         "header", NULL);
        }
+       
+       textview_show_face(textview);
 #if HAVE_LIBCOMPFACE
        textview_show_xface(textview);
 #endif
@@ -2035,10 +2103,10 @@ static gboolean textview_uri_security_check(TextView *textview, RemoteURI *uri)
                                        "Open it anyway?"),
                                      uri->uri, visible_str);
                aval = alertpanel_full(_("Fake URL warning"), msg,
-                                      GTK_STOCK_YES, GTK_STOCK_NO, NULL, FALSE,
-                                      NULL, ALERT_WARNING, G_ALERTALTERNATE);
+                                      GTK_STOCK_CANCEL, _("_Open URL"), NULL, FALSE,
+                                      NULL, ALERT_WARNING, G_ALERTDEFAULT);
                g_free(msg);
-               if (aval == G_ALERTDEFAULT)
+               if (aval == G_ALERTALTERNATE)
                        retval = TRUE;
        }
 
@@ -2176,10 +2244,10 @@ static void save_file_cb (TextView *textview, guint action, void *data)
                
                res = g_strdup_printf(_("Overwrite existing file '%s'?"),
                                      filename);
-               aval = alertpanel(_("Overwrite"), res, GTK_STOCK_OK
-                                 GTK_STOCK_CANCEL, NULL);
+               aval = alertpanel(_("Overwrite"), res, GTK_STOCK_CANCEL
+                                 GTK_STOCK_OK, NULL);
                g_free(res);                                      
-               if (G_ALERTDEFAULT != aval) 
+               if (G_ALERTALTERNATE != aval)
                        return;
        }