X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fmodest-tny-msg-actions.c;h=4adafaf2bd4f28f14828f2e963cf28d937b03c3c;hb=3e7206e4700d2bb49daa3b11c9b87be9f8014665;hp=cf405980c22404d588bf11ecd61e8c4ed2628ba8;hpb=8db724acde57179f20bbcba7298e631f9e6989f2;p=modest diff --git a/src/modest-tny-msg-actions.c b/src/modest-tny-msg-actions.c index cf40598..4adafaf 100644 --- a/src/modest-tny-msg-actions.c +++ b/src/modest-tny-msg-actions.c @@ -11,123 +11,137 @@ #ifdef HAVE_CONFIG_H #include -#endif /*HAVE_CONFIG_H*/ +#endif /*HAVE_CONFIG_H */ +#include "modest-tny-msg-actions.h" #include "modest-text-utils.h" /* private */ -static gchar *quote_msg(const TnyMsgIface *src, const gchar *from, time_t sent_date, gint limit, gboolean textorhtml); -static GtkTextBuffer *htmltotext(TnyMsgMimePartIface * body); +static gchar *quote_msg (const TnyMsgIface * src, const gchar * from, + time_t sent_date, gint limit, gboolean textorhtml); +static GtkTextBuffer *htmltotext (TnyMsgMimePartIface * body); static GtkTextBuffer * -htmltotext(TnyMsgMimePartIface * body) +htmltotext (TnyMsgMimePartIface * body) { GtkTextBuffer *buf; -#ifdef ACTIVATE_HACKS + +#ifdef ACTIVATE_HACKS /* it still doesn't work, don't bother! */ GtkWidget *html, *win; - TnyStreamIface *stream; + TnyStreamIface *stream; GtkClipboard *clip; gchar *text; - - win = gtk_window_new(GTK_WINDOW_TOPLEVEL); - html = gtk_html_new(); - gtk_container_add(GTK_CONTAINER(win), html); - - gtk_html_set_editable (GTK_HTML(html), FALSE); - gtk_html_allow_selection (GTK_HTML(html), TRUE); - gtk_html_set_caret_mode (GTK_HTML(html), FALSE); - gtk_html_set_blocking (GTK_HTML(html), FALSE); - gtk_html_set_images_blocking (GTK_HTML(html), FALSE); - - stream = TNY_STREAM_IFACE(modest_tny_stream_gtkhtml_new( - gtk_html_begin(GTK_HTML(html)))); - + + win = gtk_window_new (GTK_WINDOW_TOPLEVEL); + html = gtk_html_new (); + gtk_container_add (GTK_CONTAINER (win), html); + + gtk_html_set_editable (GTK_HTML (html), FALSE); + gtk_html_allow_selection (GTK_HTML (html), TRUE); + stream = TNY_STREAM_IFACE (modest_tny_stream_gtkhtml_new + (gtk_html_begin (GTK_HTML (html)))); + tny_stream_iface_reset (stream); tny_msg_mime_part_iface_decode_to_stream (body, stream); tny_stream_iface_reset (stream); - g_object_unref (G_OBJECT(stream)); - - gtk_widget_show_all(win); - gtk_html_select_all(GTK_HTML(html)); - clip = gtk_widget_get_clipboard(html, GDK_SELECTION_PRIMARY); - //clip = gtk_widget_get_clipboard(html, GDK_SELECTION_CLIPBOARD); - text = gtk_clipboard_wait_for_text(clip); - - buf = gtk_text_buffer_new(NULL); - gtk_text_buffer_set_text(buf, text, -1); - g_free(text); + g_object_unref (G_OBJECT (stream)); + + gtk_widget_show_all (win); + gtk_html_select_all (GTK_HTML (html)); + clip = gtk_widget_get_clipboard (html, GDK_SELECTION_PRIMARY); + /*clip = gtk_widget_get_clipboard(html, GDK_SELECTION_CLIPBOARD);*/ + text = gtk_clipboard_wait_for_text (clip); + + buf = gtk_text_buffer_new (NULL); + gtk_text_buffer_set_text (buf, text, -1); + g_free (text); /* destroy win & html */ #else - buf = gtk_text_buffer_new(NULL); + buf = gtk_text_buffer_new (NULL); #endif return buf; } gchar * -modest_tny_msg_actions_quote(const TnyMsgIface *self, const gchar *from, time_t sent_date, gint limit, GtkTextBuffer *to_quote) +modest_tny_msg_actions_quote (const TnyMsgIface * self, const gchar * from, + time_t sent_date, gint limit, + gchar * to_quote) { gchar *quoted; /* 3 cases: */ - + /* a) quote text from selection */ if (to_quote != NULL) { - return modest_text_utils_quote(to_quote, from, sent_date, limit); + return modest_text_utils_quote (to_quote, from, sent_date, + limit); } - + /* b) try to find a text/plain part in the msg and quote it */ - quoted = quote_msg(self, from, sent_date, limit, FALSE); + quoted = quote_msg (self, from, sent_date, limit, FALSE); if (quoted != NULL) return quoted; - + /* c) if that fails, try text/html */ - return quote_msg(self, from, sent_date, limit, TRUE); + return quote_msg (self, from, sent_date, limit, TRUE); } - - + + static gchar * -quote_msg(const TnyMsgIface *src, const gchar *from, time_t sent_date, gint limit, gboolean textorhtml) +quote_msg (const TnyMsgIface * src, const gchar * from, time_t sent_date, + gint limit, gboolean textorhtml) { - - GList *parts; /* LEAK? */ - TnyStreamIface* stream; - TnyTextBufferStream *dest; - TnyMsgMimePartIface *body = NULL; - TnyMsgMimePartIface *part; + TnyStreamIface *stream; + TnyMsgMimePartIface *body; GtkTextBuffer *buf; + GtkTextIter start, end; + const gchar *to_quote; gchar *quoted; - - /* is the warning in this line due to a bug in tinymail? */ - parts = (GList*) tny_msg_iface_get_parts (src); - while (parts) { - part = TNY_MSG_MIME_PART_IFACE(parts->data); - if (tny_msg_mime_part_iface_content_type_is (part, textorhtml ? "text/html" : "text/plain")) { - body = part; - break; - } - parts = parts->next; - } + /* the cast makes me uneasy... */ + body = modest_tny_msg_actions_find_body_part((TnyMsgIface *) src, + textorhtml ? "text/html" : "text/plain"); - if (!body) { + if (!body) return NULL; - } - + if (textorhtml == TRUE) { - buf = htmltotext(body); + buf = htmltotext (body); } else { - buf = gtk_text_buffer_new (NULL); - stream = TNY_STREAM_IFACE(tny_text_buffer_stream_new (buf)); + buf = gtk_text_buffer_new (NULL); + stream = TNY_STREAM_IFACE (tny_text_buffer_stream_new (buf)); tny_stream_iface_reset (stream); tny_msg_mime_part_iface_decode_to_stream (body, stream); tny_stream_iface_reset (stream); + g_object_unref (stream); } - quoted = modest_text_utils_quote (buf, from, sent_date, limit); - - g_object_unref(stream); - g_object_unref(buf); + gtk_text_buffer_get_bounds (buf, &start, &end); + to_quote = gtk_text_buffer_get_text (buf, &start, &end, FALSE); + quoted = modest_text_utils_quote (to_quote, from, sent_date, limit); + g_object_unref (buf); return quoted; } + + +TnyMsgMimePartIface * +modest_tny_msg_actions_find_body_part (TnyMsgIface *self, const gchar *mime_type) +{ + TnyMsgMimePartIface *part = NULL; + GList *parts; + + g_return_val_if_fail (self, NULL); + g_return_val_if_fail (mime_type, NULL); + + parts = (GList*) tny_msg_iface_get_parts (self); + 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; +}