Also queue resize on body
[modest] / src / widgets / modest-mozembed-msg-view.c
index 8d47941..6dc5952 100644 (file)
@@ -118,6 +118,7 @@ static gboolean modest_msg_view_search_default (ModestISearchView *self, const g
 static gboolean modest_msg_view_search_next (ModestISearchView *self);
 static gboolean modest_msg_view_search_next_default (ModestISearchView *self);
 /* ModestMsgView implementation */
+static void modest_mozembed_msg_view_set_msg_with_other_body (ModestMsgView *self, TnyMsg *msg, TnyMimePart *part);
 static GtkAdjustment *modest_mozembed_msg_view_get_vadjustment (ModestMsgView *self);
 static GtkAdjustment *modest_mozembed_msg_view_get_hadjustment (ModestMsgView *self);
 static void modest_mozembed_msg_view_set_vadjustment (ModestMsgView *self, GtkAdjustment *vadj);
@@ -130,6 +131,10 @@ 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 void modest_mozembed_msg_view_set_branding (ModestMsgView *view, const gchar *brand_name, const GdkPixbuf *brand_icon);
+static gboolean modest_mozembed_msg_view_has_blocked_external_images (ModestMsgView *view);
+static void modest_mozembed_msg_view_set_msg_with_other_body_default (ModestMsgView *self, TnyMsg *msg, TnyMimePart *part);
 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);
@@ -142,11 +147,14 @@ 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);
+static void modest_mozembed_msg_view_set_branding_default (ModestMsgView *view, const gchar *brand_name, const GdkPixbuf *brand_icon);
 
 /* 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 void     set_message    (ModestMozembedMsgView *self, TnyMsg *msg, TnyMimePart *other_body);
 static gboolean is_empty       (ModestMozembedMsgView *self); 
 static void     set_zoom       (ModestMozembedMsgView *self, gdouble zoom);
 static gdouble  get_zoom       (ModestMozembedMsgView *self);
@@ -164,6 +172,9 @@ 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 void set_branding (ModestMozembedMsgView *view, const gchar *brand_name, const GdkPixbuf *brand_icon);
+static gboolean has_blocked_external_images (ModestMozembedMsgView *view);
 
 typedef struct _ModestMozembedMsgViewPrivate ModestMozembedMsgViewPrivate;
 struct _ModestMozembedMsgViewPrivate {
@@ -320,6 +331,7 @@ modest_mozembed_msg_view_class_init (ModestMozembedMsgViewClass *klass)
        klass->zoom_plus_func = modest_msg_view_zoom_plus_default;
        klass->search_func = modest_msg_view_search_default;
        klass->search_next_func = modest_msg_view_search_next_default;
+       klass->set_msg_with_other_body_func = modest_mozembed_msg_view_set_msg_with_other_body_default;
        klass->get_vadjustment_func = modest_mozembed_msg_view_get_vadjustment_default;
        klass->get_hadjustment_func = modest_mozembed_msg_view_get_hadjustment_default;
        klass->set_vadjustment_func = modest_mozembed_msg_view_set_vadjustment_default;
@@ -332,6 +344,9 @@ 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->set_branding_func = modest_mozembed_msg_view_set_branding_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));
 
@@ -533,6 +548,41 @@ 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 void
+set_branding (ModestMozembedMsgView *self, const gchar *brand_name, const GdkPixbuf *brand_icon)
+{
+       ModestMozembedMsgViewPrivate *priv = MODEST_MOZEMBED_MSG_VIEW_GET_PRIVATE (self);
+
+       modest_mail_header_view_set_branding (MODEST_MAIL_HEADER_VIEW (priv->mail_header_view), brand_name, brand_icon);
+}
+
+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)
 {
@@ -654,7 +704,7 @@ on_fetch_url (GtkWidget *widget, const gchar *uri,
 }
 
 static void
-set_message (ModestMozembedMsgView *self, TnyMsg *msg)
+set_message (ModestMozembedMsgView *self, TnyMsg *msg, TnyMimePart *other_body)
 {
        TnyMimePart *body;
        ModestMozembedMsgViewPrivate *priv;
@@ -688,9 +738,15 @@ set_message (ModestMozembedMsgView *self, TnyMsg *msg)
        g_object_unref (header);
 
        modest_attachments_view_set_message (MODEST_ATTACHMENTS_VIEW(priv->attachments_view),
-                                            msg);
+                                            other_body?NULL:msg);
        
-       body = modest_tny_msg_find_body_part (msg, TRUE);
+       if (other_body) {
+               body = other_body;
+               g_object_ref (body);
+       } else {
+               body = modest_tny_msg_find_body_part (msg, TRUE);
+       }
+
        if (body) {
                tny_mime_part_view_set_part (TNY_MIME_PART_VIEW (priv->body_view), body);
 
@@ -719,7 +775,7 @@ set_header (ModestMozembedMsgView *self, TnyHeader *header)
        g_return_if_fail (self);
 
        if (header == NULL)
-               set_message (self, NULL);
+               set_message (self, NULL, NULL);
        
        priv = MODEST_MOZEMBED_MSG_VIEW_GET_PRIVATE(self);
        gtk_widget_set_no_show_all (priv->mail_header_view, FALSE);
@@ -923,7 +979,7 @@ modest_msg_view_clear_header (TnyHeaderView *self)
 static void
 modest_msg_view_clear_header_default (TnyHeaderView *self)
 {
-       set_message (MODEST_MOZEMBED_MSG_VIEW (self), NULL);
+       set_message (MODEST_MOZEMBED_MSG_VIEW (self), NULL, NULL);
 }
 
 /* TNY MSG IMPLEMENTATION */
@@ -993,7 +1049,7 @@ modest_msg_view_clear (TnyMsgView *self)
 static void
 modest_msg_view_clear_default (TnyMsgView *self)
 {
-       set_message (MODEST_MOZEMBED_MSG_VIEW (self), NULL);
+       set_message (MODEST_MOZEMBED_MSG_VIEW (self), NULL, NULL);
 }
 
 static TnyMimePartView*
@@ -1063,7 +1119,7 @@ modest_msg_view_mp_set_part_default (TnyMimePartView *self,
 {
        g_return_if_fail ((part == NULL) || TNY_IS_MSG (part));
 
-       set_message (MODEST_MOZEMBED_MSG_VIEW (self), TNY_MSG (part));
+       set_message (MODEST_MOZEMBED_MSG_VIEW (self), TNY_MSG (part), NULL);
 }
 
 static void
@@ -1202,6 +1258,7 @@ modest_msg_view_init (gpointer g, gpointer iface_data)
 {
        ModestMsgViewIface *klass = (ModestMsgViewIface *)g;
 
+       klass->set_msg_with_other_body_func = modest_mozembed_msg_view_set_msg_with_other_body;
        klass->get_vadjustment_func = modest_mozembed_msg_view_get_vadjustment;
        klass->get_hadjustment_func = modest_mozembed_msg_view_get_hadjustment;
        klass->set_vadjustment_func = modest_mozembed_msg_view_set_vadjustment;
@@ -1214,10 +1271,25 @@ 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->set_branding_func = modest_mozembed_msg_view_set_branding;
+       klass->has_blocked_external_images_func = modest_mozembed_msg_view_has_blocked_external_images;
 
        return;
 }
 
+static void
+modest_mozembed_msg_view_set_msg_with_other_body (ModestMsgView *self, TnyMsg *msg, TnyMimePart *other_body)
+{
+       MODEST_MOZEMBED_MSG_VIEW_GET_CLASS (self)->set_msg_with_other_body_func (self, msg, other_body);
+}
+
+static void
+modest_mozembed_msg_view_set_msg_with_other_body_default (ModestMsgView *self, TnyMsg *msg, TnyMimePart *other_body)
+{
+       set_message (MODEST_MOZEMBED_MSG_VIWE (self), msg, other_body);
+}
+
 static GtkAdjustment*
 modest_mozembed_msg_view_get_vadjustment (ModestMsgView *self)
 {
@@ -1362,3 +1434,38 @@ 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 void
+modest_mozembed_msg_view_set_branding (ModestMsgView *self, const gchar *brand_name, const GdkPixbuf *brand_icon)
+{
+       MODEST_MOZEMBED_MSG_VIEW_GET_CLASS (self)->set_branding_func (self, brand_name, brand_icon);
+}
+
+static void
+modest_mozembed_msg_view_set_branding_default (ModestMsgView *self, const gchar *brand_name, const GdkPixbuf *brand_icon)
+{
+       set_branding (MODEST_MOZEMBED_MSG_VIEW (self), brand_name, brand_icon);
+}
+
+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));
+}