Fixes NB#114785, fixes a crash when removing attachments.
[modest] / src / widgets / modest-mozembed-msg-view.c
index 1be3392..c398a9a 100644 (file)
@@ -40,7 +40,7 @@
 #include <modest-tny-msg.h>
 #include <modest-text-utils.h>
 #include <widgets/modest-msg-view.h>
-#include <widgets/modest-mail-header-view.h>
+#include <widgets/modest-compact-mail-header-view.h>
 #include <widgets/modest-attachments-view.h>
 #include <modest-marshal.h>
 #include <widgets/modest-isearch-view.h>
@@ -51,6 +51,7 @@
 
 /* 'private'/'protected' functions */
 static void     modest_mozembed_msg_view_class_init   (ModestMozembedMsgViewClass *klass);
+static void     tny_header_view_init (gpointer g, gpointer iface_data);
 static void     tny_msg_view_init (gpointer g, gpointer iface_data);
 static void     tny_mime_part_view_init (gpointer g, gpointer iface_data);
 static void     modest_mime_part_view_init (gpointer g, gpointer iface_data);
@@ -84,6 +85,11 @@ static TnyMimePart* modest_msg_view_mp_get_part_default (TnyMimePartView *self);
 /* ModestMimePartView implementation */
 static gboolean modest_msg_view_mp_is_empty (ModestMimePartView *self);
 static gboolean modest_msg_view_mp_is_empty_default (ModestMimePartView *self);
+/* TnyHeaderView implementation */
+static void modest_msg_view_set_header (TnyHeaderView *self, TnyHeader *header);
+static void modest_msg_view_set_header_default (TnyHeaderView *self, TnyHeader *header);
+static void modest_msg_view_clear_header (TnyHeaderView *self);
+static void modest_msg_view_clear_header_default (TnyHeaderView *self);
 /* TnyMsgView implementation */
 static TnyMsg *modest_msg_view_get_msg (TnyMsgView *self);
 static TnyMsg *modest_msg_view_get_msg_default (TnyMsgView *self);
@@ -124,6 +130,8 @@ static TnyList *modest_mozembed_msg_view_get_selected_attachments (ModestMsgView
 static TnyList *modest_mozembed_msg_view_get_attachments (ModestMsgView *self);
 static void modest_mozembed_msg_view_grab_focus (ModestMsgView *self);
 static void modest_mozembed_msg_view_remove_attachment (ModestMsgView *view, TnyMimePart *attachment);
+static void modest_mozembed_msg_view_request_fetch_images (ModestMsgView *view);
+static gboolean modest_mozembed_msg_view_has_blocked_external_images (ModestMsgView *view);
 static GtkAdjustment *modest_mozembed_msg_view_get_vadjustment_default (ModestMsgView *self);
 static GtkAdjustment *modest_mozembed_msg_view_get_hadjustment_default (ModestMsgView *self);
 static void modest_mozembed_msg_view_set_vadjustment_default (ModestMsgView *self, GtkAdjustment *vadj);
@@ -136,8 +144,11 @@ static TnyList *modest_mozembed_msg_view_get_selected_attachments_default (Modes
 static TnyList *modest_mozembed_msg_view_get_attachments_default (ModestMsgView *self);
 static void modest_mozembed_msg_view_grab_focus_default (ModestMsgView *self);
 static void modest_mozembed_msg_view_remove_attachment_default (ModestMsgView *view, TnyMimePart *attachment);
+static gboolean modest_mozembed_msg_view_has_blocked_external_images_default (ModestMsgView *view);
+static void modest_mozembed_msg_view_request_fetch_images_default (ModestMsgView *view);
 
 /* internal api */
+static void     set_header     (ModestMozembedMsgView *self, TnyHeader *header);
 static TnyMsg   *get_message   (ModestMozembedMsgView *self);
 static void     set_message    (ModestMozembedMsgView *self, TnyMsg *tny_msg);
 static gboolean is_empty       (ModestMozembedMsgView *self); 
@@ -157,6 +168,8 @@ static TnyList *get_selected_attachments (ModestMozembedMsgView *self);
 static TnyList *get_attachments (ModestMozembedMsgView *self);
 static void grab_focus (ModestMozembedMsgView *self);
 static void remove_attachment (ModestMozembedMsgView *view, TnyMimePart *attachment);
+static void request_fetch_images (ModestMozembedMsgView *view);
+static gboolean has_blocked_external_images (ModestMozembedMsgView *view);
 
 typedef struct _ModestMozembedMsgViewPrivate ModestMozembedMsgViewPrivate;
 struct _ModestMozembedMsgViewPrivate {
@@ -216,6 +229,13 @@ modest_mozembed_msg_view_get_type (void)
                  NULL          /* interface_data */
                };
 
+               static const GInterfaceInfo tny_header_view_info = 
+               {
+                 (GInterfaceInitFunc) tny_header_view_init, /* interface_init */
+                 NULL,         /* interface_finalize */
+                 NULL          /* interface_data */
+               };
+
                static const GInterfaceInfo modest_mime_part_view_info = 
                {
                  (GInterfaceInitFunc) modest_mime_part_view_init, /* interface_init */
@@ -248,6 +268,9 @@ modest_mozembed_msg_view_get_type (void)
                                                  "ModestMozembedMsgView",
                                                  &my_info, 0);
 
+               g_type_add_interface_static (my_type, TNY_TYPE_HEADER_VIEW, 
+                       &tny_header_view_info);
+
                g_type_add_interface_static (my_type, TNY_TYPE_MIME_PART_VIEW, 
                        &tny_mime_part_view_info);
 
@@ -285,6 +308,8 @@ modest_mozembed_msg_view_class_init (ModestMozembedMsgViewClass *klass)
        gobject_class->finalize = modest_mozembed_msg_view_finalize;
        gtkobject_class->destroy = modest_mozembed_msg_view_destroy;
 
+       klass->set_header_func = modest_msg_view_set_header_default;
+       klass->clear_header_func = modest_msg_view_clear_header_default;
        klass->set_scroll_adjustments = NULL;
        klass->get_part_func = modest_msg_view_mp_get_part_default;
        klass->set_part_func = modest_msg_view_mp_set_part_default;
@@ -313,6 +338,8 @@ modest_mozembed_msg_view_class_init (ModestMozembedMsgViewClass *klass)
        klass->get_attachments_func = modest_mozembed_msg_view_get_attachments_default;
        klass->grab_focus_func = modest_mozembed_msg_view_grab_focus_default;
        klass->remove_attachment_func = modest_mozembed_msg_view_remove_attachment_default;
+       klass->request_fetch_images_func = modest_mozembed_msg_view_request_fetch_images_default;
+       klass->has_blocked_external_images_func = modest_mozembed_msg_view_has_blocked_external_images_default;
 
        g_type_class_add_private (gobject_class, sizeof(ModestMozembedMsgViewPrivate));
 
@@ -514,6 +541,33 @@ on_attachment_activated (ModestAttachmentsView * att_view, TnyMimePart *mime_par
        g_signal_emit_by_name (G_OBJECT(self), "attachment_clicked", mime_part);
 }
 
+
+static void
+request_fetch_images (ModestMozembedMsgView *self)
+{
+       ModestMozembedMsgViewPrivate *priv = MODEST_MOZEMBED_MSG_VIEW_GET_PRIVATE (self);
+       TnyMimePart *part;
+
+       /* The message could have not been downloaded yet */
+       if (priv->msg) {
+               modest_mime_part_view_set_view_images (MODEST_MIME_PART_VIEW (priv->body_view), TRUE);
+               part = tny_mime_part_view_get_part (TNY_MIME_PART_VIEW (priv->body_view));
+               if (part) {
+                       tny_mime_part_view_set_part (TNY_MIME_PART_VIEW (priv->body_view), part);
+                       g_object_unref (part);
+               }
+               tny_msg_set_allow_external_images (TNY_MSG (priv->msg), TRUE);
+       }
+}
+
+static gboolean
+has_blocked_external_images (ModestMozembedMsgView *self)
+{
+       ModestMozembedMsgViewPrivate *priv = MODEST_MOZEMBED_MSG_VIEW_GET_PRIVATE (self);
+
+       return modest_mime_part_view_has_external_images (MODEST_MIME_PART_VIEW (priv->body_view));
+}
+
 static gboolean
 on_activate_link (GtkWidget *widget, const gchar *uri, ModestMozembedMsgView *self)
 {
@@ -692,6 +746,31 @@ set_message (ModestMozembedMsgView *self, TnyMsg *msg)
 
 }
 
+static void
+set_header (ModestMozembedMsgView *self, TnyHeader *header)
+{
+       ModestMozembedMsgViewPrivate *priv;
+       
+       g_return_if_fail (self);
+
+       if (header == NULL)
+               set_message (self, NULL);
+       
+       priv = MODEST_MOZEMBED_MSG_VIEW_GET_PRIVATE(self);
+       gtk_widget_set_no_show_all (priv->mail_header_view, FALSE);
+
+       if (priv->msg)
+               g_object_unref (G_OBJECT(priv->msg));
+       priv->msg = NULL;
+       
+       tny_header_view_set_header (TNY_HEADER_VIEW (priv->mail_header_view), header);
+       modest_attachments_view_set_message (MODEST_ATTACHMENTS_VIEW (priv->attachments_view), NULL);
+       gtk_widget_show_all (priv->mail_header_view);
+       gtk_widget_hide_all (priv->attachments_box);
+       gtk_widget_set_no_show_all (priv->mail_header_view, TRUE);
+       tny_mime_part_view_clear (TNY_MIME_PART_VIEW (priv->body_view));
+}
+
 
 static TnyMsg*
 get_message (ModestMozembedMsgView *self)
@@ -843,6 +922,45 @@ remove_attachment (ModestMozembedMsgView *self, TnyMimePart *attachment)
        
 }
 
+/* TNY HEADER VIEW IMPLEMENTATION */
+
+static void
+tny_header_view_init (gpointer g, gpointer iface_data)
+{
+       TnyHeaderViewIface *klass = (TnyHeaderViewIface *)g;
+
+       klass->set_header = modest_msg_view_set_header;
+       klass->clear = modest_msg_view_clear_header;
+
+       return;
+}
+
+static void
+modest_msg_view_set_header (TnyHeaderView *self, TnyHeader *header)
+{
+       MODEST_MOZEMBED_MSG_VIEW_GET_CLASS (self)->set_header_func (self, header);
+}
+
+
+static void
+modest_msg_view_set_header_default (TnyHeaderView *self, TnyHeader *header)
+{
+       set_header (MODEST_MOZEMBED_MSG_VIEW (self), header);
+}
+
+static void
+modest_msg_view_clear_header (TnyHeaderView *self)
+{
+       MODEST_MOZEMBED_MSG_VIEW_GET_CLASS (self)->clear_header_func (self);
+}
+
+
+static void
+modest_msg_view_clear_header_default (TnyHeaderView *self)
+{
+       set_message (MODEST_MOZEMBED_MSG_VIEW (self), NULL);
+}
+
 /* TNY MSG IMPLEMENTATION */
 
 static void
@@ -1131,6 +1249,8 @@ modest_msg_view_init (gpointer g, gpointer iface_data)
        klass->get_attachments_func = modest_mozembed_msg_view_get_attachments;
        klass->grab_focus_func = modest_mozembed_msg_view_grab_focus;
        klass->remove_attachment_func = modest_mozembed_msg_view_remove_attachment;
+       klass->request_fetch_images_func = modest_mozembed_msg_view_request_fetch_images;
+       klass->has_blocked_external_images_func = modest_mozembed_msg_view_has_blocked_external_images;
 
        return;
 }
@@ -1279,3 +1399,26 @@ modest_mozembed_msg_view_remove_attachment_default (ModestMsgView *self, TnyMime
        remove_attachment (MODEST_MOZEMBED_MSG_VIEW (self), attachment);
 }
 
+static void
+modest_mozembed_msg_view_request_fetch_images (ModestMsgView *self)
+{
+       MODEST_MOZEMBED_MSG_VIEW_GET_CLASS (self)->request_fetch_images_func (self);
+}
+
+static void
+modest_mozembed_msg_view_request_fetch_images_default (ModestMsgView *self)
+{
+       request_fetch_images (MODEST_MOZEMBED_MSG_VIEW (self));
+}
+
+static gboolean
+modest_mozembed_msg_view_has_blocked_external_images (ModestMsgView *self)
+{
+       return MODEST_MOZEMBED_MSG_VIEW_GET_CLASS (self)->has_blocked_external_images_func (self);
+}
+
+static gboolean
+modest_mozembed_msg_view_has_blocked_external_images_default (ModestMsgView *self)
+{
+       return has_blocked_external_images (MODEST_MOZEMBED_MSG_VIEW (self));
+}