[evolution/webkit] Render attachment button description as HTML again



commit 2d4e10607bfdf51cfc84fbdd82ca7c2848053f46
Author: Dan VrÃtil <dvratil redhat com>
Date:   Fri Feb 10 20:40:56 2012 +0100

    Render attachment button description as HTML again
    
     - also remember the last created EAttachmentView so that it can
       be assigned to a new EAttachmentButton

 mail/em-format-html-display.c |   71 ++++++++++++++++++++++++++++++++++-------
 1 files changed, 59 insertions(+), 12 deletions(-)
---
diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c
index 58f7953..f5caba5 100644
--- a/mail/em-format-html-display.c
+++ b/mail/em-format-html-display.c
@@ -74,7 +74,9 @@
 #define d(x)
 
 struct _EMFormatHTMLDisplayPrivate {
-                gint dummy;
+
+        EAttachmentView *last_view;
+
 };
 
 /* TODO: move the dialogue elsehwere */
@@ -124,14 +126,14 @@ static void efhd_builtin_init (EMFormatHTMLDisplayClass *efhc);
 static gpointer parent_class;
 
 static EAttachmentStore*
-find_parent_attachment_store (EMFormatHTMLDisplay *efhd, GString *part_id)
+find_parent_attachment_store (EMFormatHTMLDisplay *efhd, const gchar *part_id)
 {
 	EMFormat *emf = (EMFormat *) efhd;
 	EMFormatAttachmentBarPURI *abp;
 	gchar *tmp, *pos;
         GList *item;
 
-	tmp = g_strdup (part_id->str);
+	tmp = g_strdup (part_id);
 
 	do {
 		gchar *id;
@@ -141,7 +143,7 @@ find_parent_attachment_store (EMFormatHTMLDisplay *efhd, GString *part_id)
 			break;
 
 		g_free (tmp);
-		tmp = g_strndup (part_id->str, pos - tmp);
+		tmp = g_strndup (part_id, pos - tmp);
 		id = g_strdup_printf ("%s.attachment-bar", tmp);
 
 		item = g_hash_table_lookup (emf->mail_part_table, id);
@@ -510,7 +512,6 @@ efhd_parse_attachment (EMFormat *emf,
 
 	if (handler) {
                 CamelContentType *ct;
-                puri->puri.write_func = handler->write_func;
 
                 /* This mime_type is important for WebKit to determine content type.
                  * We have converted text/ * to text/html, other (binary) formats remained
@@ -543,7 +544,7 @@ efhd_parse_attachment (EMFormat *emf,
         }
 	e_attachment_set_can_show (puri->attachment, puri->handle != NULL && puri->handle->write_func);
 
-	store = find_parent_attachment_store (efhd, part_id);
+	store = find_parent_attachment_store (efhd, part_id->str);
 	e_attachment_store_add_attachment (store, puri->attachment);
 
 	if (emf->folder && emf->folder->summary && emf->message_uid) {
@@ -709,16 +710,45 @@ efhd_write_attachment (EMFormat *emf,
                        EMFormatWriterInfo *info,
                        GCancellable *cancellable)
 {
-        gchar *str;
+        gchar *str, *desc;
+        const gchar *mime_type;
+
+        EMFormatAttachmentPURI *efa = (EMFormatAttachmentPURI *) puri;
+
+        if (efa->handle)
+                mime_type = efa->handle->mime_type;
+        else
+                mime_type = efa->snoop_mime_type;
 
+        desc = em_format_describe_part (puri->part, mime_type);
 	str = g_strdup_printf (
-                "<object type=\"application/x-attachment\" "
-		"height=\"20\" width=\"100%%\" "
-                "data=\"%s\"></object>", puri->uri);
+                "<table width=\"100%%\" border=\"0\">"
+                "<tr valign=\"middle\">"
+                "<td align=\"left\" width=\"100\">"
+                "<object type=\"application/x-attachment-button\" "
+		"height=\"20\" width=\"100\" data=\"%s\"></object>"
+                "</td>"
+                "<td align=\"left\">%s</td>"
+                "</tr>"
+                "</table>", puri->uri, desc);
 
         camel_stream_write_string (stream, str, cancellable, NULL);
+        g_free (desc);
 
-        g_free (str);
+        /* If we know how to write the attachment, then do it */
+        if (efa->handle && efa->handle->write_func) {
+
+                str = g_strdup_printf (
+                        "<div class=\"attachment-wrapper\" id=\"%s\">",
+                        puri->uri);
+
+                camel_stream_write_string (stream, str, cancellable, NULL);
+                g_free (str);
+
+                efa->handle->write_func (emf, puri, stream, info, cancellable);
+
+                camel_stream_write_string (stream, "</div>", cancellable, NULL);
+        }
 }
 
 static void
@@ -753,10 +783,19 @@ efhd_finalize (GObject *object)
 }
 
 static void
+efhd_preparse (EMFormat *emf)
+{
+        EMFormatHTMLDisplay *efhd = (EMFormatHTMLDisplay *) emf;
+
+        efhd->priv->last_view = NULL;
+}
+
+static void
 efhd_class_init (EMFormatHTMLDisplayClass *class)
 {
 	GObjectClass *object_class;
 	EMFormatHTMLClass *format_html_class;
+        EMFormatClass *format_class;
 
 	parent_class = g_type_class_peek_parent (class);
 	g_type_class_add_private (class, sizeof (EMFormatHTMLDisplayPrivate));
@@ -767,6 +806,9 @@ efhd_class_init (EMFormatHTMLDisplayClass *class)
 	format_html_class = EM_FORMAT_HTML_CLASS (class);
 	format_html_class->html_widget_type = E_TYPE_MAIL_DISPLAY;
 
+        format_class = EM_FORMAT_CLASS (class);
+        format_class->preparse = efhd_preparse;
+
 	efhd_builtin_init (class);
 }
 
@@ -937,6 +979,10 @@ efhd_attachment_button (EMFormat *emf,
 	widget = e_attachment_button_new ();
 	e_attachment_button_set_attachment (
 		E_ATTACHMENT_BUTTON (widget), info->attachment);
+        e_attachment_button_set_view (
+                E_ATTACHMENT_BUTTON (widget),
+                EM_FORMAT_HTML_DISPLAY (emf)->priv->last_view);
+
 	gtk_widget_set_can_focus (widget, TRUE);
 	gtk_widget_show (widget);
 
@@ -951,7 +997,8 @@ efhd_attachment_bar (EMFormat *emf,
 	EMFormatAttachmentBarPURI *abp = (EMFormatAttachmentBarPURI *) puri;
 	GtkWidget *widget;
 
-	widget = e_mail_attachment_bar_new (abp->store);
+        widget = e_mail_attachment_bar_new (abp->store);
+        EM_FORMAT_HTML_DISPLAY (emf)->priv->last_view = (EAttachmentView *) widget;
 
 	return widget;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]