X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fwidgets%2Fmodest-gtkhtml-msg-view.c;h=43829fa0f8ca7e37d373b52d4c9e432517aaf250;hp=416bdf70c3b7f7c41bbae059d8d1b9a41992f7d3;hb=9ab597b587d2bdc0243c29be71db37b7acc649fd;hpb=282935ffbb85d08a26a7c7d57179dcbfc9170914;ds=sidebyside diff --git a/src/widgets/modest-gtkhtml-msg-view.c b/src/widgets/modest-gtkhtml-msg-view.c index 416bdf7..43829fa 100644 --- a/src/widgets/modest-gtkhtml-msg-view.c +++ b/src/widgets/modest-gtkhtml-msg-view.c @@ -41,11 +41,9 @@ #include #include #include -#ifdef MODEST_TOOLKIT_HILDON2 #include +#ifdef MODEST_TOOLKIT_HILDON2 #include -#else -#include #endif #include #include @@ -54,6 +52,8 @@ #include #include #include +#include +#include /* 'private'/'protected' functions */ static void modest_gtkhtml_msg_view_class_init (ModestGtkhtmlMsgViewClass *klass); @@ -224,6 +224,7 @@ static void remove_attachment (ModestGtkhtmlMsgView *view, TnyMimePart *attachme static void request_fetch_images (ModestGtkhtmlMsgView *view); static void set_branding (ModestGtkhtmlMsgView *view, const gchar *brand_name, const GdkPixbuf *brand_icon); static gboolean has_blocked_external_images (ModestGtkhtmlMsgView *view); +static void set_calendar (ModestGtkhtmlMsgView *self, TnyHeader *header, TnyMsg *msg); /* list properties */ enum { @@ -250,6 +251,10 @@ struct _ModestGtkhtmlMsgViewPrivate { GtkWidget *priority_box; GtkWidget *priority_icon; #endif + GtkWidget *calendar_box; + GtkWidget *calendar_icon; + GtkWidget *calendar_actions_box; + GtkWidget *calendar_actions_container; /* internal adjustments for set_scroll_adjustments */ GtkAdjustment *hadj; @@ -274,6 +279,8 @@ struct _ModestGtkhtmlMsgViewPrivate { /* link click management */ gchar *last_url; + + gboolean has_blocked_bs_images; }; #define MODEST_GTKHTML_MSG_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ @@ -1150,6 +1157,8 @@ modest_gtkhtml_msg_view_init (ModestGtkhtmlMsgView *obj) priv = MODEST_GTKHTML_MSG_VIEW_GET_PRIVATE(obj); + priv->has_blocked_bs_images = FALSE; + priv->idle_changes_count = 0; priv->idle_readjust_scroll_id = 0; priv->idle_resize_children_id = 0; @@ -1173,11 +1182,7 @@ modest_gtkhtml_msg_view_init (ModestGtkhtmlMsgView *obj) priv->msg = NULL; priv->body_view = GTK_WIDGET (g_object_new (MODEST_TYPE_GTKHTML_MIME_PART_VIEW, NULL)); -#ifdef MODEST_TOOLKIT_HILDON2 - priv->mail_header_view = GTK_WIDGET(modest_compact_mail_header_view_new ()); -#else - priv->mail_header_view = GTK_WIDGET(modest_expander_mail_header_view_new (TRUE)); -#endif + priv->mail_header_view = GTK_WIDGET (modest_compact_mail_header_view_new ()); gtk_widget_set_no_show_all (priv->mail_header_view, TRUE); priv->attachments_view = GTK_WIDGET(modest_attachments_view_new (NULL)); #ifdef MODEST_TOOLKIT_HILDON2 @@ -1239,6 +1244,20 @@ modest_gtkhtml_msg_view_init (ModestGtkhtmlMsgView *obj) gtk_widget_hide_all (priv->priority_box); } #endif + priv->calendar_actions_box = NULL; + priv->calendar_icon = gtk_image_new (); + gtk_image_set_from_icon_name (GTK_IMAGE (priv->calendar_icon), MODEST_HEADER_ICON_CALENDAR, GTK_ICON_SIZE_MENU); + gtk_misc_set_alignment (GTK_MISC (priv->calendar_icon), 0.0, 0.5); + if (priv->calendar_icon) { + priv->calendar_box = (GtkWidget *) + modest_mail_header_view_add_custom_header (MODEST_MAIL_HEADER_VIEW (priv->mail_header_view), + _("mail_fi_invitation"), + priv->calendar_icon, + FALSE, FALSE); + + gtk_widget_hide_all (priv->calendar_box); + } + if (priv->attachments_view) { #ifndef MODEST_TOOLKIT_HILDON2 gchar *att_label = g_strconcat (_("mcen_me_viewer_attachments"), ":", NULL); @@ -1255,6 +1274,11 @@ modest_gtkhtml_msg_view_init (ModestGtkhtmlMsgView *obj) g_free (att_label); } + priv->calendar_actions_container = gtk_vbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX (priv->headers_box), priv->calendar_actions_container, FALSE, FALSE, 0); + gtk_widget_hide_all (priv->calendar_actions_container); + gtk_widget_set_no_show_all (priv->calendar_actions_container, TRUE); + #ifndef MODEST_TOOLKIT_HILDON2 separator = gtk_hseparator_new (); gtk_box_pack_start (GTK_BOX(priv->headers_box), separator, FALSE, FALSE, 0); @@ -1441,8 +1465,7 @@ set_hadjustment (ModestGtkhtmlMsgView *self, GtkAdjustment *hadj) if (!hadj) hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0,0.0,0.0,0.0,0.0,0.0)); disconnect_hadjustment (self); - g_object_ref (G_OBJECT (hadj)); - gtk_object_sink (GTK_OBJECT (hadj)); + g_object_ref_sink (G_OBJECT (hadj)); priv->hadj = hadj; set_hadjustment_values (self, &value_changed); @@ -1470,8 +1493,7 @@ set_vadjustment (ModestGtkhtmlMsgView *self, GtkAdjustment *vadj) if (!vadj) vadj = (GtkAdjustment *) gtk_adjustment_new (0.0,0.0,0.0,0.0,0.0,0.0); disconnect_vadjustment (self); - g_object_ref (G_OBJECT (vadj)); - gtk_object_sink (GTK_OBJECT (vadj)); + g_object_ref_sink (G_OBJECT (vadj)); priv->vadj = vadj; set_vadjustment_values (self, &value_changed); @@ -1585,6 +1607,7 @@ request_fetch_images (ModestGtkhtmlMsgView *self) /* 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); + priv->has_blocked_bs_images = FALSE; 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); @@ -1607,7 +1630,8 @@ has_blocked_external_images (ModestGtkhtmlMsgView *self) { ModestGtkhtmlMsgViewPrivate *priv = MODEST_GTKHTML_MSG_VIEW_GET_PRIVATE (self); - return (modest_mime_part_view_has_external_images (MODEST_MIME_PART_VIEW (priv->body_view)) && + return ((modest_mime_part_view_has_external_images (MODEST_MIME_PART_VIEW (priv->body_view)) || + (priv->has_blocked_bs_images)) && !modest_mime_part_view_get_view_images (MODEST_MIME_PART_VIEW (priv->body_view))); } @@ -1643,6 +1667,22 @@ on_limit_error (GtkWidget *widget, ModestGtkhtmlMsgView *msg_view) g_signal_emit_by_name (G_OBJECT (msg_view), "limit-error"); } +static gboolean +part_cids_equal (const gchar *part_cid1, + const gchar *part_cid2) +{ + if (g_strcmp0 (part_cid1, part_cid2) == 0) + return TRUE; + + if (part_cid2 && part_cid2[0] == '<') { + const gchar *end; + end = g_strrstr_len (part_cid2, -1, ">"); + + if (end && strncmp (part_cid2 + 1, part_cid1, end - part_cid2 - 1) == 0) + return TRUE; + } + return FALSE; +} static TnyMimePart * find_cid_image (TnyMsg *msg, const gchar *cid) @@ -1671,8 +1711,8 @@ find_cid_image (TnyMsg *msg, const gchar *cid) */ if (!part_cid) part_cid = tny_mime_part_get_content_location (part); - - if (part_cid && strcmp (cid, part_cid) == 0) + + if (part_cids_equal (cid, part_cid)) break; if (tny_mime_part_content_type_is (part, "multipart/related")) { @@ -1686,9 +1726,10 @@ find_cid_image (TnyMsg *msg, const gchar *cid) while (!tny_iterator_is_done (related_iter)) { related_part = TNY_MIME_PART (tny_iterator_get_current (related_iter)); part_cid = tny_mime_part_get_content_id (related_part); - if (part_cid && strcmp (cid, part_cid) == 0) { + + if (part_cids_equal (cid, part_cid)) break; - } + g_object_unref (related_part); related_part = NULL; tny_iterator_next (related_iter); @@ -1715,6 +1756,11 @@ find_cid_image (TnyMsg *msg, const gchar *cid) return part; } +static void +fetch_url_decode_to_stream_cb (TnyMimePart *self, gboolean cancelled, TnyStream *stream, GError *err, gpointer user_data) +{ + tny_stream_close (stream); +} static gboolean on_fetch_url (GtkWidget *widget, const gchar *uri, @@ -1755,10 +1801,17 @@ on_fetch_url (GtkWidget *widget, const gchar *uri, } else { return FALSE; } + } else if (TNY_IS_CAMEL_BS_MIME_PART (part) && + !tny_camel_bs_mime_part_is_fetched (TNY_CAMEL_BS_MIME_PART (part))){ + if (!modest_mime_part_view_get_view_images (MODEST_MIME_PART_VIEW (priv->body_view)) || + !tny_device_is_online (modest_runtime_get_device ())) { + priv->has_blocked_bs_images = TRUE; + tny_stream_close (stream); + return TRUE; + } } - tny_mime_part_decode_to_stream ((TnyMimePart*)part, stream, NULL); - tny_stream_close (stream); + tny_mime_part_decode_to_stream_async ((TnyMimePart*)part, stream, fetch_url_decode_to_stream_cb, NULL, NULL); g_object_unref (G_OBJECT(part)); return TRUE; } @@ -1774,6 +1827,7 @@ set_message (ModestGtkhtmlMsgView *self, TnyMsg *msg, TnyMimePart *other_body) g_return_if_fail (self); priv = MODEST_GTKHTML_MSG_VIEW_GET_PRIVATE(self); + priv->has_blocked_bs_images = FALSE; modest_mail_header_view_set_loading (MODEST_MAIL_HEADER_VIEW (priv->mail_header_view), FALSE); gtk_widget_set_no_show_all (priv->mail_header_view, FALSE); modest_mime_part_view_set_view_images (MODEST_MIME_PART_VIEW (priv->body_view), FALSE); @@ -1794,6 +1848,8 @@ set_message (ModestGtkhtmlMsgView *self, TnyMsg *msg, TnyMimePart *other_body) #ifdef MODEST_TOOKIT_HILDON2 gtk_widget_hide_all (priv->priority_box); #endif + gtk_widget_hide_all (priv->calendar_box); + gtk_widget_hide_all (priv->calendar_actions_container); gtk_widget_set_no_show_all (priv->mail_header_view, TRUE); tny_mime_part_view_clear (TNY_MIME_PART_VIEW (priv->body_view)); @@ -1868,17 +1924,22 @@ set_message (ModestGtkhtmlMsgView *self, TnyMsg *msg, TnyMimePart *other_body) /* Refresh priority */ set_priority (self, tny_header_get_flags (header)); + set_calendar (self, header, msg); gtk_widget_show (priv->body_view); #ifdef MODEST_TOOLKIT_HILDON2 gtk_widget_set_no_show_all (priv->priority_box, TRUE); #endif + gtk_widget_set_no_show_all (priv->calendar_box, TRUE); + gtk_widget_set_no_show_all (priv->calendar_actions_container, TRUE); gtk_widget_set_no_show_all (priv->attachments_box, TRUE); gtk_widget_show_all (priv->mail_header_view); gtk_widget_set_no_show_all (priv->attachments_box, FALSE); #ifdef MODEST_TOOLKIT_HILDON2 gtk_widget_set_no_show_all (priv->priority_box, FALSE); #endif + gtk_widget_set_no_show_all (priv->calendar_box, FALSE); + gtk_widget_set_no_show_all (priv->calendar_actions_container, FALSE); gtk_widget_set_no_show_all (priv->mail_header_view, TRUE); html_vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->html_scroll)); @@ -1930,6 +1991,7 @@ set_header (ModestGtkhtmlMsgView *self, TnyHeader *header) } priv = MODEST_GTKHTML_MSG_VIEW_GET_PRIVATE(self); + priv->has_blocked_bs_images = FALSE; modest_mail_header_view_set_loading (MODEST_MAIL_HEADER_VIEW (priv->mail_header_view), TRUE); gtk_widget_set_no_show_all (priv->mail_header_view, FALSE); modest_mime_part_view_set_view_images (MODEST_MIME_PART_VIEW (priv->body_view), FALSE); @@ -1961,6 +2023,8 @@ set_header (ModestGtkhtmlMsgView *self, TnyHeader *header) #ifdef MODEST_TOOLKIT_HILDON2 gtk_widget_hide_all (priv->priority_box); #endif + gtk_widget_hide_all (priv->calendar_box); + gtk_widget_hide_all (priv->calendar_actions_container); gtk_widget_set_no_show_all (priv->mail_header_view, TRUE); tny_mime_part_view_clear (TNY_MIME_PART_VIEW (priv->body_view)); priv->idle_changes_count = 0; @@ -2721,3 +2785,42 @@ modest_gtkhtml_msg_view_has_blocked_external_images_default (ModestMsgView *self { return has_blocked_external_images (MODEST_GTKHTML_MSG_VIEW (self)); } + +static void +set_calendar (ModestGtkhtmlMsgView *self, TnyHeader *header, TnyMsg *msg) +{ + ModestGtkhtmlMsgViewPrivate *priv; + TnyMimePart *calendar_part; + + g_return_if_fail (MODEST_IS_GTKHTML_MSG_VIEW (self)); + priv = MODEST_GTKHTML_MSG_VIEW_GET_PRIVATE (self); + + if (priv->calendar_actions_box) { + gtk_widget_destroy (priv->calendar_actions_box); + priv->calendar_actions_box = NULL; + } + + calendar_part = modest_tny_msg_find_calendar (TNY_MSG (msg)); + + if (calendar_part) { + gboolean retval = FALSE; + priv->calendar_actions_box = gtk_vbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX (priv->calendar_actions_container), priv->calendar_actions_box, FALSE, FALSE, 0); + g_signal_emit_by_name (G_OBJECT (self), "handle-calendar", calendar_part, priv->calendar_actions_box, &retval); + if (retval) { + gtk_widget_show_all (priv->calendar_actions_container); + gtk_widget_show (priv->calendar_actions_box); + } else { + gtk_widget_hide_all (priv->calendar_actions_container); + gtk_widget_hide (priv->calendar_actions_box); + } + gtk_widget_show_all (priv->calendar_box); + g_object_unref (calendar_part); + } else { + gtk_widget_hide_all (priv->calendar_box); + gtk_widget_hide_all (priv->calendar_actions_container); + gtk_widget_hide (priv->calendar_actions_box); + } + + +}