* added primitive sanity checks for page 2 of account wizard
[modest] / src / modest-tny-msg-view.c
index 5cc8f63..dc6464a 100644 (file)
@@ -4,6 +4,8 @@
 
 #include "modest-tny-msg-view.h"
 #include "modest-tny-stream-gtkhtml.h"
+#include "modest-tny-msg-actions.h"
+
 #include <tny-text-buffer-stream.h>
 #include <string.h>
 #include <regex.h>
@@ -118,6 +120,7 @@ modest_tny_msg_view_init (ModestTnyMsgView *obj)
        priv->msg = NULL;
        
        priv->gtkhtml = gtk_html_new();
+
        gtk_html_set_editable        (GTK_HTML(priv->gtkhtml), FALSE);
         gtk_html_allow_selection     (GTK_HTML(priv->gtkhtml), TRUE);
         gtk_html_set_caret_mode      (GTK_HTML(priv->gtkhtml), FALSE);
@@ -135,11 +138,7 @@ modest_tny_msg_view_init (ModestTnyMsgView *obj)
 static void
 modest_tny_msg_view_finalize (GObject *obj)
 {      
-       ModestTnyMsgViewPrivate *priv;
-       priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE(obj);
-
-       if (priv->gtkhtml)
-               g_object_unref (G_OBJECT(priv->gtkhtml));
+       
 }
 
 GtkWidget*
@@ -264,8 +263,10 @@ hyperlinkify_plain_text (GString *txt)
                
                g_free (url);
                g_free (repl);
-               
+
+               g_free (cursor->data);  
        }
+       
        g_slist_free (match_list);
 }
 
@@ -429,26 +430,6 @@ fill_gtkhtml_with_txt (GtkHTML* gtkhtml, const gchar* txt)
 
 
 
-static TnyMsgMimePartIface *
-find_body_part (TnyMsgIface *msg, const gchar *mime_type)
-{
-       TnyMsgMimePartIface *part = NULL;
-       GList *parts;
-
-       g_return_val_if_fail (msg, NULL);
-       g_return_val_if_fail (mime_type, NULL);
-
-       parts  = (GList*) tny_msg_iface_get_parts (msg);
-       while (parts && !part) {
-               part = TNY_MSG_MIME_PART_IFACE(parts->data);
-               if (!tny_msg_mime_part_iface_content_type_is (part, mime_type))
-                       part = NULL;
-               parts = parts->next;
-       }
-       
-       return part;
-}
-
 static gboolean
 set_html_message (ModestTnyMsgView *self, TnyMsgMimePartIface *tny_body)
 {
@@ -509,52 +490,8 @@ set_text_message (ModestTnyMsgView *self, TnyMsgMimePartIface *tny_body)
        return TRUE;
 }
 
-/* WIP (az), unused */
-char *
-get_all_text(ModestTnyMsgView *self)
-{
-       GtkWidget *html;
-       ModestTnyMsgViewPrivate *priv;
-       GSList *list;
-       GString *str = g_string_new ("");
-       gchar *ptr;
-       gint id = 0;
-       GObject *obj;
-       //HtmlBoxText *text;
-       
-       g_return_if_fail (self);
-       priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE(self);
-       html = priv->gtkhtml;
-       
-       //list = view->sel_list;
-       
-       //if (view->sel_list == NULL)
-               //      return NULL;
-       
-       while (obj = gtk_html_get_object_by_id(GTK_HTML(html), id)) {
-               //text = HTML_BOX_TEXT (obj->data);
-
-               //list = list->next;
-               /*
-                * Some boxes may not have any text
-                */
-               //if (text->canon_text == NULL)
-               //      continue;
-               //ptr = (gchar *)text->canon_text;
-               //g_string_append_len (str, ptr, text->length);
-               printf("obj#%d\n", id);
-               id++;
-                       
-       }
-       ptr = str->str;
-       g_string_free (str, FALSE);
-       return ptr;
-
-}
-
-
-GtkTextBuffer *
-modest_tny_msg_view_get_selected (ModestTnyMsgView *self)
+gchar *
+modest_tny_msg_view_get_selected_text (ModestTnyMsgView *self)
 {
        ModestTnyMsgViewPrivate *priv;
        gchar *sel;
@@ -570,20 +507,13 @@ modest_tny_msg_view_get_selected (ModestTnyMsgView *self)
        
        /* I'm sure there is a better way to check for selected text */
        sel = gtk_html_get_selection_html(GTK_HTML(html), &len);
+       if (!sel)
+               return NULL;
        
-       /* and I hope we can get rid of this hack soon: */
-       if (sel == NULL)
-               gtk_html_select_all(GTK_HTML(html));
+       g_free(sel);
        
        clip = gtk_widget_get_clipboard(html, GDK_SELECTION_PRIMARY);
-       text = gtk_clipboard_wait_for_text(clip);
-       if (text == NULL)
-               return NULL;
-       
-       buf = gtk_text_buffer_new(NULL);
-       gtk_text_buffer_set_text(buf, text, -1);
-       g_free(text);
-       return buf;
+       return gtk_clipboard_wait_for_text(clip);
 }
 
 void
@@ -603,13 +533,13 @@ modest_tny_msg_view_set_message (ModestTnyMsgView *self, TnyMsgIface *msg)
        if (!msg) 
                return;
        
-       body = find_body_part (msg, "text/html");
+       body = modest_tny_msg_actions_find_body_part (msg, "text/html");
        if (body) {
                set_html_message (self, body);
                return;
        }
        
-       body = find_body_part (msg, "text/plain");
+       body = modest_tny_msg_actions_find_body_part (msg, "text/plain");
        if (body) {
                set_text_message (self, body);
                return;