Reverted again the gdk_threads_enter/leave sentences:
[modest] / src / widgets / modest-msg-view.c
index b91e125..728ec5d 100644 (file)
@@ -1367,21 +1367,24 @@ modest_msg_view_set_message (ModestMsgView *self, TnyMsg *msg)
        modest_attachments_view_set_message (MODEST_ATTACHMENTS_VIEW(priv->attachments_view),
                                             msg);
        
-       body = modest_tny_msg_find_body_part (msg,TRUE);
+       body = modest_tny_msg_find_body_part (msg, TRUE);
        if (body) {
-               GList *att_children;
                if (tny_mime_part_content_type_is (body, "text/html"))
                        set_html_message (self, body, msg);
                else
                        set_text_message (self, body, msg);
 
-               att_children = gtk_container_get_children (GTK_CONTAINER (priv->attachments_view));
-               if (att_children != NULL) {
+               if(modest_attachments_view_has_attachments (MODEST_ATTACHMENTS_VIEW (priv->attachments_view))) {
                        gtk_widget_show_all (priv->attachments_box);
-                       g_list_free (att_children);
                } else {
                        gtk_widget_hide_all (priv->attachments_box);
                }
+
+/*             g_print ("---\nfilename %s\ncontent_location %s\ncontent_id%s\ncontent_type%s\n", */
+/*                      tny_mime_part_get_filename (body), */
+/*                      tny_mime_part_get_content_location (body), */
+/*                      tny_mime_part_get_content_id (body), */
+/*                      tny_mime_part_get_content_type (body)); */
                        
        } else 
                set_empty_message (self);
@@ -1407,9 +1410,16 @@ modest_msg_view_set_message (ModestMsgView *self, TnyMsg *msg)
 TnyMsg*
 modest_msg_view_get_message (ModestMsgView *self)
 {
-       g_return_val_if_fail (self, NULL);
+       TnyMsg *msg;
+
+       g_return_val_if_fail (MODEST_IS_MSG_VIEW (self), NULL);
+
+       msg = MODEST_MSG_VIEW_GET_PRIVATE(self)->msg;
+
+       if (msg)
+               g_object_ref (msg);
        
-       return MODEST_MSG_VIEW_GET_PRIVATE(self)->msg;
+       return msg;
 }
 
 gboolean 
@@ -1430,8 +1440,22 @@ modest_msg_view_search (ModestMsgView *self, const gchar *search)
        result = gtk_html_engine_search (GTK_HTML (priv->gtkhtml),
                                         search,
                                         FALSE, TRUE, TRUE);
+#if 0
+       if (result) {
+               gint x, y, w, h;
+               gdouble offset_top, offset_bottom;
+               GtkAdjustment *adj;
+               gtk_html_get_selection_area (GTK_HTML (priv->gtkhtml), &x, &y, &w, &h);
+               offset_top = (gdouble) (priv->headers_box->requisition.height + y);
+               offset_bottom = (gdouble) (priv->headers_box->requisition.height + y + h);
+               adj = GTK_ADJUSTMENT (priv->vadj);
+               if (offset_top < adj->value)
+                       gtk_adjustment_set_value (adj, offset_top + adj->page_increment - adj->page_size);
+               else if (offset_bottom > adj->value + adj->page_increment)
+                       gtk_adjustment_set_value (adj, offset_bottom - adj->page_increment);
+       }
+#endif
        y_offset = tmp_vadj->value;
-       g_message ("VALUE %f", y_offset);
        gtk_layout_set_vadjustment (GTK_LAYOUT (priv->gtkhtml), vadj);
        g_object_unref (vadj);
 
@@ -1448,13 +1472,22 @@ modest_msg_view_search_next (ModestMsgView *self)
 
        priv = MODEST_MSG_VIEW_GET_PRIVATE (self);
        result = gtk_html_engine_search_next (GTK_HTML (priv->gtkhtml));
-
-       {
+#if 0
+       if (result) {
+               gint x, y, w, h;
+               gdouble offset_top, offset_bottom;
                GtkAdjustment *adj;
-
-               adj = gtk_container_get_focus_vadjustment (GTK_CONTAINER (priv->gtkhtml));
-               g_message ("ADJ value %f", adj->value);
+               gtk_html_get_selection_area (GTK_HTML (priv->gtkhtml), &x, &y, &w, &h);
+               g_message ("SELECTION AREA x%d y%d w%d h%d", x, y, w, h);
+               offset_top = (gdouble) (priv->headers_box->requisition.height + y);
+               offset_bottom = (gdouble) (priv->headers_box->requisition.height + y + h);
+               adj = GTK_ADJUSTMENT (priv->vadj);
+               if (offset_top < adj->value)
+                       gtk_adjustment_set_value (adj, offset_top + adj->page_increment - adj->page_size);
+               else if (offset_bottom > adj->value + adj->page_increment)
+                       gtk_adjustment_set_value (adj, offset_bottom - adj->page_increment);
        }
+#endif
 
        return result;
 }
@@ -1510,3 +1543,42 @@ modest_msg_view_set_priority (ModestMsgView *self, TnyHeaderFlags flags)
 
        modest_mail_header_view_set_priority (MODEST_MAIL_HEADER_VIEW (priv->mail_header_view), flags);
 }
+
+GList *
+modest_msg_view_get_selected_attachments (ModestMsgView *self)
+{
+       ModestMsgViewPrivate *priv;
+
+       g_return_val_if_fail (MODEST_IS_MSG_VIEW (self), NULL);
+       priv = MODEST_MSG_VIEW_GET_PRIVATE (self);
+
+       return modest_attachments_view_get_selection (MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
+       
+}
+
+void
+modest_msg_view_grab_focus (ModestMsgView *view)
+{
+       ModestMsgViewPrivate *priv = NULL;
+
+       g_return_if_fail (MODEST_IS_MSG_VIEW (view));
+       priv = MODEST_MSG_VIEW_GET_PRIVATE (view);
+
+       gtk_widget_grab_focus (priv->gtkhtml);
+}
+
+void
+modest_msg_view_remove_attachment (ModestMsgView *view, TnyMimePart *attachment)
+{
+       TnyMsg *msg;
+       ModestMsgViewPrivate *priv;
+
+       g_return_if_fail (MODEST_IS_MSG_VIEW (view));
+       g_return_if_fail (TNY_IS_MIME_PART (attachment));
+       priv = MODEST_MSG_VIEW_GET_PRIVATE (view);
+
+       msg = modest_msg_view_get_message (view);
+       modest_attachments_view_remove_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
+                                                  attachment);
+       
+}