3 /* insert (c)/licensing information) */
6 #include <gtkhtml/gtkhtml.h>
8 /* TODO: put in auto* */
9 #include <tny-text-buffer-stream.h>
10 #include <tny-msg-mime-part-iface.h>
11 #include <tny-msg-iface.h>
15 #endif /*HAVE_CONFIG_H */
17 #include "modest-tny-msg-actions.h"
18 #include "modest-text-utils.h"
22 static gchar *quote_msg (const TnyMsgIface * src, const gchar * from,
23 time_t sent_date, gint limit, gboolean textorhtml);
24 static GtkTextBuffer *htmltotext (TnyMsgMimePartIface * body);
27 static GtkTextBuffer *
28 htmltotext (TnyMsgMimePartIface * body)
32 #ifdef ACTIVATE_HACKS /* it still doesn't work, don't bother! */
33 GtkWidget *html, *win;
34 TnyStreamIface *stream;
38 win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
39 html = gtk_html_new ();
40 gtk_container_add (GTK_CONTAINER (win), html);
42 gtk_html_set_editable (GTK_HTML (html), FALSE);
43 gtk_html_allow_selection (GTK_HTML (html), TRUE);
44 stream = TNY_STREAM_IFACE (modest_tny_stream_gtkhtml_new
45 (gtk_html_begin (GTK_HTML (html))));
47 tny_stream_iface_reset (stream);
48 tny_msg_mime_part_iface_decode_to_stream (body, stream);
49 tny_stream_iface_reset (stream);
50 g_object_unref (G_OBJECT (stream));
52 gtk_widget_show_all (win);
53 gtk_html_select_all (GTK_HTML (html));
54 clip = gtk_widget_get_clipboard (html, GDK_SELECTION_PRIMARY);
55 /*clip = gtk_widget_get_clipboard(html, GDK_SELECTION_CLIPBOARD);*/
56 text = gtk_clipboard_wait_for_text (clip);
58 buf = gtk_text_buffer_new (NULL);
59 gtk_text_buffer_set_text (buf, text, -1);
61 /* destroy win & html */
63 buf = gtk_text_buffer_new (NULL);
69 modest_tny_msg_actions_quote (const TnyMsgIface * self, const gchar * from,
70 time_t sent_date, gint limit,
77 /* a) quote text from selection */
78 if (to_quote != NULL) {
79 return modest_text_utils_quote (to_quote, from, sent_date,
83 /* b) try to find a text/plain part in the msg and quote it */
84 quoted = quote_msg (self, from, sent_date, limit, FALSE);
88 /* c) if that fails, try text/html */
89 return quote_msg (self, from, sent_date, limit, TRUE);
94 quote_msg (const TnyMsgIface * src, const gchar * from, time_t sent_date,
95 gint limit, gboolean textorhtml)
97 TnyStreamIface *stream;
98 TnyMsgMimePartIface *body;
100 GtkTextIter start, end;
101 const gchar *to_quote;
104 /* the cast makes me uneasy... */
105 body = modest_tny_msg_actions_find_body_part((TnyMsgIface *) src,
106 textorhtml ? "text/html" : "text/plain");
111 if (textorhtml == TRUE) {
112 buf = htmltotext (body);
114 buf = gtk_text_buffer_new (NULL);
115 stream = TNY_STREAM_IFACE (tny_text_buffer_stream_new (buf));
116 tny_stream_iface_reset (stream);
117 tny_msg_mime_part_iface_decode_to_stream (body, stream);
118 tny_stream_iface_reset (stream);
119 g_object_unref (stream);
122 gtk_text_buffer_get_bounds (buf, &start, &end);
123 to_quote = gtk_text_buffer_get_text (buf, &start, &end, FALSE);
124 quoted = modest_text_utils_quote (to_quote, from, sent_date, limit);
125 g_object_unref (buf);
130 TnyMsgMimePartIface *
131 modest_tny_msg_actions_find_body_part (TnyMsgIface *self, const gchar *mime_type)
133 TnyMsgMimePartIface *part = NULL;
136 g_return_val_if_fail (self, NULL);
137 g_return_val_if_fail (mime_type, NULL);
139 parts = (GList*) tny_msg_iface_get_parts (self);
140 while (parts && !part) {
141 part = TNY_MSG_MIME_PART_IFACE(parts->data);
142 if (!tny_msg_mime_part_iface_content_type_is (part, mime_type))