[evolution] Bug 733877 - Parse attachments on demand, not on message open ][



commit 7de1b173c90b240fdd38e1c3ff09ec7eff8a29b9
Author: Milan Crha <mcrha redhat com>
Date:   Fri May 29 12:38:59 2015 +0200

    Bug 733877 - Parse attachments on demand, not on message open ][

 em-format/e-mail-formatter-attachment.c |    2 +
 em-format/e-mail-part-attachment.c      |   62 ++++++++++++++++++++++++++++++-
 em-format/e-mail-part-attachment.h      |    5 ++
 mail/e-mail-display.c                   |   28 +------------
 4 files changed, 71 insertions(+), 26 deletions(-)
---
diff --git a/em-format/e-mail-formatter-attachment.c b/em-format/e-mail-formatter-attachment.c
index 643b839..48f4183 100644
--- a/em-format/e-mail-formatter-attachment.c
+++ b/em-format/e-mail-formatter-attachment.c
@@ -342,6 +342,8 @@ emfe_attachment_format (EMailFormatterExtension *extension,
 
                        g_string_append (buffer, "</div></td></tr>");
 
+                       e_mail_part_attachment_set_expandable (E_MAIL_PART_ATTACHMENT (part), TRUE);
+
                        g_free (wrapper_element_id);
                        g_free (inner_html_data);
                }
diff --git a/em-format/e-mail-part-attachment.c b/em-format/e-mail-part-attachment.c
index 9f6f92a..e12e555 100644
--- a/em-format/e-mail-part-attachment.c
+++ b/em-format/e-mail-part-attachment.c
@@ -23,11 +23,13 @@
 
 struct _EMailPartAttachmentPrivate {
        EAttachment *attachment;
+       gboolean expandable;
 };
 
 enum {
        PROP_0,
-       PROP_ATTACHMENT
+       PROP_ATTACHMENT,
+       PROP_EXPANDABLE
 };
 
 G_DEFINE_TYPE (
@@ -36,6 +38,23 @@ G_DEFINE_TYPE (
        E_TYPE_MAIL_PART)
 
 static void
+mail_part_attachment_set_property (GObject *object,
+                                  guint property_id,
+                                  const GValue *value,
+                                  GParamSpec *pspec)
+{
+       switch (property_id) {
+               case PROP_EXPANDABLE:
+                       e_mail_part_attachment_set_expandable (
+                               E_MAIL_PART_ATTACHMENT (object),
+                               g_value_get_boolean (value));
+                       return;
+       }
+
+       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
 mail_part_attachment_get_property (GObject *object,
                                    guint property_id,
                                    GValue *value,
@@ -48,6 +67,13 @@ mail_part_attachment_get_property (GObject *object,
                                e_mail_part_attachment_ref_attachment (
                                E_MAIL_PART_ATTACHMENT (object)));
                        return;
+
+               case PROP_EXPANDABLE:
+                       g_value_set_boolean (
+                               value,
+                               e_mail_part_attachment_get_expandable (
+                               E_MAIL_PART_ATTACHMENT (object)));
+                       return;
        }
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -125,6 +151,7 @@ e_mail_part_attachment_class_init (EMailPartAttachmentClass *class)
 
        object_class = G_OBJECT_CLASS (class);
        object_class->get_property = mail_part_attachment_get_property;
+       object_class->set_property = mail_part_attachment_set_property;
        object_class->dispose = mail_part_attachment_dispose;
        object_class->finalize = mail_part_attachment_finalize;
        object_class->constructed = mail_part_attachment_constructed;
@@ -139,12 +166,24 @@ e_mail_part_attachment_class_init (EMailPartAttachmentClass *class)
                        E_TYPE_ATTACHMENT,
                        G_PARAM_READABLE |
                        G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_EXPANDABLE,
+               g_param_spec_boolean (
+                       "expandable",
+                       "Expandable",
+                       "Whether the attachment can be expanded",
+                       FALSE,
+                       G_PARAM_READWRITE |
+                       G_PARAM_STATIC_STRINGS));
 }
 
 static void
 e_mail_part_attachment_init (EMailPartAttachment *part)
 {
        part->priv = E_MAIL_PART_ATTACHMENT_GET_PRIVATE (part);
+       part->priv->expandable = FALSE;
 }
 
 EMailPartAttachment *
@@ -166,3 +205,24 @@ e_mail_part_attachment_ref_attachment (EMailPartAttachment *part)
        return g_object_ref (part->priv->attachment);
 }
 
+void
+e_mail_part_attachment_set_expandable (EMailPartAttachment *part,
+                                      gboolean expandable)
+{
+       g_return_if_fail (E_IS_MAIL_PART_ATTACHMENT (part));
+
+       if ((part->priv->expandable ? 1 : 0) == (expandable ? 1 : 0))
+               return;
+
+       part->priv->expandable = expandable;
+
+       g_object_notify (G_OBJECT (part), "expandable");
+}
+
+gboolean
+e_mail_part_attachment_get_expandable (EMailPartAttachment *part)
+{
+       g_return_val_if_fail (E_IS_MAIL_PART_ATTACHMENT (part), FALSE);
+
+       return part->priv->expandable;
+}
diff --git a/em-format/e-mail-part-attachment.h b/em-format/e-mail-part-attachment.h
index 4cfa49c..bdf859c 100644
--- a/em-format/e-mail-part-attachment.h
+++ b/em-format/e-mail-part-attachment.h
@@ -68,6 +68,11 @@ EMailPartAttachment *
                                                 const gchar *id);
 EAttachment *  e_mail_part_attachment_ref_attachment
                                                (EMailPartAttachment *part);
+void           e_mail_part_attachment_set_expandable
+                                               (EMailPartAttachment *part,
+                                                gboolean expandable);
+gboolean       e_mail_part_attachment_get_expandable
+                                               (EMailPartAttachment *part);
 
 G_END_DECLS
 
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index 4f70f5d..0640234 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -829,37 +829,15 @@ mail_display_plugin_widget_requested (WebKitWebView *web_view,
                /* Bind visibility of DOM element containing related
                 * attachment with 'expanded' property of this
                 * attachment button. */
-               WebKitDOMElement *attachment;
-               WebKitDOMDocument *document;
                EMailPartAttachment *empa = (EMailPartAttachment *) part;
-               gchar *attachment_part_id;
-               gchar *wrapper_element_id;
 
-               if (empa->attachment_view_part_id)
-                       attachment_part_id = empa->attachment_view_part_id;
-               else
-                       attachment_part_id = part_id;
+               e_attachment_button_set_expandable (E_ATTACHMENT_BUTTON (widget),
+                       e_mail_part_attachment_get_expandable (empa));
 
-               /* Find attachment-wrapper div which contains
-                * the content of the attachment (iframe). */
-               document = webkit_web_view_get_dom_document (
-                       WEBKIT_WEB_VIEW (display));
-               wrapper_element_id = g_strconcat (
-                       attachment_part_id, ".wrapper", NULL);
-               attachment = find_element_by_id (document, wrapper_element_id);
-               g_free (wrapper_element_id);
-
-               /* None found? Attachment cannot be expanded */
-               if (attachment == NULL) {
-                       e_attachment_button_set_expandable (
-                               E_ATTACHMENT_BUTTON (widget), FALSE);
-               } else {
+               if (e_mail_part_attachment_get_expandable (empa)) {
                        CamelMimePart *mime_part;
                        const CamelContentDisposition *disposition;
 
-                       e_attachment_button_set_expandable (
-                               E_ATTACHMENT_BUTTON (widget), TRUE);
-
                        /* Show/hide the attachment when the EAttachmentButton
                         * is expanded/collapsed or shown/hidden. */
                        g_signal_connect (


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