2007-07-23 Murray Cumming <murrayc@murrayc.com>
[modest] / src / widgets / modest-msg-view.c
index 728ec5d..c3f5aff 100644 (file)
@@ -869,7 +869,6 @@ modest_msg_view_init (ModestMsgView *obj)
        priv->headers_window = NULL;
        priv->html_window = NULL;
 
-
        gtk_widget_push_composite_child ();
        priv->html_scroll = gtk_scrolled_window_new (NULL, NULL);
        gtk_widget_set_composite_name (priv->html_scroll, "contents");
@@ -1197,7 +1196,8 @@ find_cid_image (TnyMsg *msg, const gchar *cid)
                if (part_cid && strcmp (cid, part_cid) == 0)
                        break;
 
-               g_object_unref (G_OBJECT(part));
+               if (part)
+                       g_object_unref (G_OBJECT(part));
        
                part = NULL;
                tny_iterator_next (iter);
@@ -1323,6 +1323,7 @@ set_empty_message (ModestMsgView *self)
 
        gtk_html_load_from_string (GTK_HTML(priv->gtkhtml),
                                   "", 1);
+
        
        return TRUE;
 }
@@ -1422,6 +1423,33 @@ modest_msg_view_get_message (ModestMsgView *self)
        return msg;
 }
 
+static gboolean
+has_contents_receiver (gpointer engine, const gchar *data,
+                      size_t len, gboolean *has_contents)
+{
+       if (len > 1 || ((len == 1)&&(data[0]!='\n'))) {
+               *has_contents = TRUE;
+               return FALSE;
+       }
+       return TRUE;
+}
+
+gboolean 
+modest_msg_view_get_message_is_empty (ModestMsgView *self)
+{
+       /* TODO: Find some gtkhtml API to check whether there is any (visible, non markup)
+        * text in the message:
+        */
+       ModestMsgViewPrivate *priv = MODEST_MSG_VIEW_GET_PRIVATE (self);
+       gboolean has_contents = FALSE;
+
+       gtk_html_export (GTK_HTML (priv->gtkhtml), "text/plain", 
+                        (GtkHTMLSaveReceiverFn) has_contents_receiver, &has_contents);
+       
+       return !has_contents;
+}
+
+
 gboolean 
 modest_msg_view_search (ModestMsgView *self, const gchar *search)
 {
@@ -1440,6 +1468,8 @@ modest_msg_view_search (ModestMsgView *self, const gchar *search)
        result = gtk_html_engine_search (GTK_HTML (priv->gtkhtml),
                                         search,
                                         FALSE, TRUE, TRUE);
+
+// wait for the updated gtkhtml (w27) to enable this
 #if 0
        if (result) {
                gint x, y, w, h;
@@ -1454,7 +1484,8 @@ modest_msg_view_search (ModestMsgView *self, const gchar *search)
                else if (offset_bottom > adj->value + adj->page_increment)
                        gtk_adjustment_set_value (adj, offset_bottom - adj->page_increment);
        }
-#endif
+#endif 
+
        y_offset = tmp_vadj->value;
        gtk_layout_set_vadjustment (GTK_LAYOUT (priv->gtkhtml), vadj);
        g_object_unref (vadj);
@@ -1472,6 +1503,8 @@ modest_msg_view_search_next (ModestMsgView *self)
 
        priv = MODEST_MSG_VIEW_GET_PRIVATE (self);
        result = gtk_html_engine_search_next (GTK_HTML (priv->gtkhtml));
+
+// fixme wait for new gtkhtml
 #if 0
        if (result) {
                gint x, y, w, h;
@@ -1488,7 +1521,6 @@ modest_msg_view_search_next (ModestMsgView *self)
                        gtk_adjustment_set_value (adj, offset_bottom - adj->page_increment);
        }
 #endif
-
        return result;
 }
 
@@ -1556,6 +1588,18 @@ modest_msg_view_get_selected_attachments (ModestMsgView *self)
        
 }
 
+GList *
+modest_msg_view_get_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_attachments (MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
+       
+}
+
 void
 modest_msg_view_grab_focus (ModestMsgView *view)
 {