1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <glib/gi18n.h>
33 #include <glib/gstdio.h>
35 #include <tny-account-store.h>
36 #include <tny-fs-stream.h>
40 #include <modest-account-mgr.h>
41 #include <modest-account-mgr-helpers.h>
43 #include <widgets/modest-msg-edit-window.h>
44 #include <widgets/modest-combo-box.h>
45 #include <widgets/modest-recpt-editor.h>
46 #include <widgets/modest-attachments-view.h>
48 #include <modest-runtime.h>
50 #include "modest-platform.h"
51 #include "modest-icon-names.h"
52 #include "modest-widget-memory.h"
53 #include "modest-window-priv.h"
54 #include "modest-mail-operation.h"
55 #include "modest-tny-platform-factory.h"
56 #include "modest-tny-msg.h"
57 #include "modest-address-book.h"
58 #include <tny-simple-list.h>
59 #include <wptextview.h>
60 #include <wptextbuffer.h>
61 #include <hildon-widgets/hildon-color-selector.h>
62 #include <hildon-widgets/hildon-color-button.h>
63 #include <hildon-widgets/hildon-banner.h>
64 #include <hildon-widgets/hildon-caption.h>
65 #include <hildon-widgets/hildon-note.h>
66 #include <hildon-widgets/hildon-scroll-area.h>
67 #include <hildon-widgets/hildon-font-selection-dialog.h>
68 #include "widgets/modest-msg-edit-window-ui.h"
70 #ifdef MODEST_HILDON_VERSION_0
71 #include <hildon-widgets/hildon-file-chooser-dialog.h>
73 #include <hildon/hildon-file-chooser-dialog.h>
75 #endif /*MODEST_HILDON_VERSION_0 */
79 #define DEFAULT_FONT_SIZE 3
80 #define DEFAULT_FONT 2
81 #define DEFAULT_SIZE_BUTTON_FONT_FAMILY "Sans"
82 #define DEFAULT_SIZE_COMBOBOX_WIDTH 80
83 #define DEFAULT_MAIN_VBOX_SPACING 6
84 #define SUBJECT_MAX_LENGTH 1000
86 static void modest_msg_edit_window_class_init (ModestMsgEditWindowClass *klass);
87 static void modest_msg_edit_window_init (ModestMsgEditWindow *obj);
88 static void modest_msg_edit_window_finalize (GObject *obj);
90 static void text_buffer_refresh_attributes (WPTextBuffer *buffer, ModestMsgEditWindow *window);
91 static void text_buffer_mark_set (GtkTextBuffer *buffer, GtkTextIter *location, GtkTextMark *mark, gpointer userdata);
92 static void modest_msg_edit_window_color_button_change (ModestMsgEditWindow *window,
94 static void modest_msg_edit_window_size_change (GtkCheckMenuItem *menu_item,
96 static void modest_msg_edit_window_font_change (GtkCheckMenuItem *menu_item,
98 static void modest_msg_edit_window_setup_toolbar (ModestMsgEditWindow *window);
99 static gboolean modest_msg_edit_window_window_state_event (GtkWidget *widget,
100 GdkEventWindowState *event,
102 static void modest_msg_edit_window_open_addressbook (ModestMsgEditWindow *window,
103 ModestRecptEditor *editor);
105 /* ModestWindow methods implementation */
106 static void modest_msg_edit_window_set_zoom (ModestWindow *window, gdouble zoom);
107 static gdouble modest_msg_edit_window_get_zoom (ModestWindow *window);
108 static gboolean modest_msg_edit_window_zoom_minus (ModestWindow *window);
109 static gboolean modest_msg_edit_window_zoom_plus (ModestWindow *window);
110 static void modest_msg_edit_window_show_toolbar (ModestWindow *window,
111 gboolean show_toolbar);
114 /* list my signals */
121 typedef struct _ModestMsgEditWindowPrivate ModestMsgEditWindowPrivate;
122 struct _ModestMsgEditWindowPrivate {
124 GtkWidget *header_box;
125 GtkWidget *from_field;
128 GtkWidget *bcc_field;
129 GtkWidget *subject_field;
130 GtkWidget *attachments_view;
131 GtkWidget *priority_icon;
132 GtkWidget *add_attachment_button;
134 GtkWidget *cc_caption;
135 GtkWidget *bcc_caption;
136 GtkWidget *attachments_caption;
138 GtkTextBuffer *text_buffer;
140 GtkWidget *font_color_button;
141 GSList *font_items_group;
142 GtkWidget *font_tool_button_label;
143 GSList *size_items_group;
144 GtkWidget *size_tool_button_label;
151 TnyHeaderFlags priority_flags;
156 #define MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
157 MODEST_TYPE_MSG_EDIT_WINDOW, \
158 ModestMsgEditWindowPrivate))
160 static GtkWindowClass *parent_class = NULL;
162 /* uncomment the following if you have defined any signals */
163 /* static guint signals[LAST_SIGNAL] = {0}; */
166 modest_msg_edit_window_get_type (void)
168 static GType my_type = 0;
170 static const GTypeInfo my_info = {
171 sizeof(ModestMsgEditWindowClass),
172 NULL, /* base init */
173 NULL, /* base finalize */
174 (GClassInitFunc) modest_msg_edit_window_class_init,
175 NULL, /* class finalize */
176 NULL, /* class data */
177 sizeof(ModestMsgEditWindow),
179 (GInstanceInitFunc) modest_msg_edit_window_init,
182 my_type = g_type_register_static (MODEST_TYPE_WINDOW,
183 "ModestMsgEditWindow",
186 wp_text_buffer_library_init ();
192 modest_msg_edit_window_class_init (ModestMsgEditWindowClass *klass)
194 GObjectClass *gobject_class;
195 ModestWindowClass *modest_window_class;
196 gobject_class = (GObjectClass*) klass;
197 modest_window_class = (ModestWindowClass*) klass;
199 parent_class = g_type_class_peek_parent (klass);
200 gobject_class->finalize = modest_msg_edit_window_finalize;
202 modest_window_class->set_zoom_func = modest_msg_edit_window_set_zoom;
203 modest_window_class->get_zoom_func = modest_msg_edit_window_get_zoom;
204 modest_window_class->zoom_plus_func = modest_msg_edit_window_zoom_plus;
205 modest_window_class->zoom_minus_func = modest_msg_edit_window_zoom_minus;
206 modest_window_class->show_toolbar_func = modest_msg_edit_window_show_toolbar;
208 g_type_class_add_private (gobject_class, sizeof(ModestMsgEditWindowPrivate));
212 modest_msg_edit_window_init (ModestMsgEditWindow *obj)
214 ModestMsgEditWindowPrivate *priv;
215 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(obj);
217 priv->msg_body = NULL;
218 priv->from_field = NULL;
219 priv->to_field = NULL;
220 priv->cc_field = NULL;
221 priv->bcc_field = NULL;
222 priv->subject_field = NULL;
223 priv->attachments = NULL;
225 priv->zoom_level = 1.0;
227 priv->cc_caption = NULL;
228 priv->bcc_caption = NULL;
230 priv->priority_flags = 0;
236 save_settings (ModestMsgEditWindow *self)
238 modest_widget_memory_save (modest_runtime_get_conf(),
239 G_OBJECT(self), "modest-edit-msg-window");
244 restore_settings (ModestMsgEditWindow *self)
246 modest_widget_memory_restore (modest_runtime_get_conf(),
247 G_OBJECT(self), "modest-edit-msg-window");
251 /* FIXME: this is a dup from the one in gtk/ */
252 static ModestPairList*
253 get_transports (void)
255 ModestAccountMgr *account_mgr;
256 GSList *transports = NULL;
257 GSList *cursor, *accounts;
259 account_mgr = modest_runtime_get_account_mgr();
260 cursor = accounts = modest_account_mgr_account_names (account_mgr);
262 gchar *account_name = (gchar*)cursor->data;
263 gchar *from_string = modest_account_mgr_get_from_string (account_mgr,
266 /* something went wrong: ignore this one */
267 g_free (account_name);
271 pair = modest_pair_new ((gpointer) account_name,
272 (gpointer) from_string , TRUE);
273 transports = g_slist_prepend (transports, pair);
274 } /* don't free account name; it's freed when the transports list is freed */
275 cursor = cursor->next;
277 g_slist_free (accounts);
283 text_buffer_mark_set (GtkTextBuffer *buffer, GtkTextIter *iter, GtkTextMark *mark, gpointer userdata)
285 ModestMsgEditWindow *window;
286 ModestMsgEditWindowPrivate *priv;
287 GdkRectangle location;
288 gint v_scroll_min_value = 0;
289 gint v_scroll_max_value = 0;
290 gint v_scroll_visible;
292 GtkTextMark *insert_mark;
293 GtkTextIter insert_iter;
295 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (userdata));
296 g_return_if_fail (GTK_IS_TEXT_MARK (mark));
297 window = MODEST_MSG_EDIT_WINDOW (userdata);
298 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
300 insert_mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (priv->text_buffer));
301 gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (priv->text_buffer), &insert_iter, insert_mark);
302 gtk_text_view_get_iter_location (GTK_TEXT_VIEW (priv->msg_body), &insert_iter, &location);
304 if (priv->header_box)
305 v_scroll_min_value += priv->header_box->allocation.height + DEFAULT_MAIN_VBOX_SPACING;
306 v_scroll_min_value += location.y;
307 v_scroll_max_value = v_scroll_min_value + location.height;
309 v_scroll_visible = GTK_WIDGET (window)->allocation.height;
311 vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->scroll));
313 if (((gdouble) v_scroll_min_value) < vadj->value)
314 gtk_adjustment_set_value (vadj, v_scroll_min_value);
315 else if (((gdouble) v_scroll_max_value) > (vadj->value + vadj->page_size))
316 gtk_adjustment_set_value (vadj, ((gdouble)v_scroll_max_value) - vadj->page_size);
320 init_window (ModestMsgEditWindow *obj)
322 GtkWidget *from_caption, *to_caption, *subject_caption;
323 GtkWidget *main_vbox;
324 ModestMsgEditWindowPrivate *priv;
325 ModestPairList *protos;
326 GtkSizeGroup *size_group;
328 GtkWidget *scroll_area;
329 GtkWidget *subject_box;
330 GtkWidget *attachment_icon;
332 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(obj);
334 size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
336 protos = get_transports ();
337 priv->from_field = modest_combo_box_new (protos, g_str_equal);
338 modest_pair_list_free (protos);
340 priv->to_field = modest_recpt_editor_new ();
341 priv->cc_field = modest_recpt_editor_new ();
342 priv->bcc_field = modest_recpt_editor_new ();
343 subject_box = gtk_hbox_new (FALSE, 0);
344 priv->priority_icon = gtk_image_new ();
345 gtk_box_pack_start (GTK_BOX (subject_box), priv->priority_icon, FALSE, FALSE, 0);
346 priv->subject_field = gtk_entry_new_with_max_length (SUBJECT_MAX_LENGTH);
347 g_object_set (G_OBJECT (priv->subject_field), "hildon-input-mode", HILDON_GTK_INPUT_MODE_FULL, NULL);
348 gtk_box_pack_start (GTK_BOX (subject_box), priv->subject_field, TRUE, TRUE, 0);
349 priv->add_attachment_button = gtk_button_new ();
350 gtk_button_set_relief (GTK_BUTTON (priv->add_attachment_button), GTK_RELIEF_NONE);
351 gtk_button_set_focus_on_click (GTK_BUTTON (priv->add_attachment_button), FALSE);
352 gtk_button_set_alignment (GTK_BUTTON (priv->add_attachment_button), 1.0, 1.0);
353 attachment_icon = gtk_image_new_from_icon_name (MODEST_HEADER_ICON_ATTACH, GTK_ICON_SIZE_BUTTON);
354 gtk_container_add (GTK_CONTAINER (priv->add_attachment_button), attachment_icon);
355 gtk_box_pack_start (GTK_BOX (subject_box), priv->add_attachment_button, FALSE, FALSE, 0);
356 priv->attachments_view = modest_attachments_view_new (NULL);
358 priv->header_box = gtk_vbox_new (FALSE, 0);
360 from_caption = hildon_caption_new (size_group, _("mail_va_from"), priv->from_field, NULL, 0);
361 to_caption = hildon_caption_new (size_group, _("mail_va_to"), priv->to_field, NULL, 0);
362 priv->cc_caption = hildon_caption_new (size_group, _("mail_va_cc"), priv->cc_field, NULL, 0);
363 priv->bcc_caption = hildon_caption_new (size_group, _("mail_va_hotfix1"), priv->bcc_field, NULL, 0);
364 subject_caption = hildon_caption_new (size_group, _("mail_va_subject"), subject_box, NULL, 0);
365 priv->attachments_caption = hildon_caption_new (size_group, _("mail_va_attachment"), priv->attachments_view, NULL, 0);
366 g_object_unref (size_group);
368 size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
369 modest_recpt_editor_set_field_size_group (MODEST_RECPT_EDITOR (priv->to_field), size_group);
370 modest_recpt_editor_set_field_size_group (MODEST_RECPT_EDITOR (priv->cc_field), size_group);
371 modest_recpt_editor_set_field_size_group (MODEST_RECPT_EDITOR (priv->bcc_field), size_group);
372 gtk_size_group_add_widget (size_group, priv->subject_field);
373 gtk_size_group_add_widget (size_group, priv->attachments_view);
374 g_object_unref (size_group);
376 gtk_box_pack_start (GTK_BOX (priv->header_box), from_caption, FALSE, FALSE, 0);
377 gtk_box_pack_start (GTK_BOX (priv->header_box), to_caption, FALSE, FALSE, 0);
378 gtk_box_pack_start (GTK_BOX (priv->header_box), priv->cc_caption, FALSE, FALSE, 0);
379 gtk_box_pack_start (GTK_BOX (priv->header_box), priv->bcc_caption, FALSE, FALSE, 0);
380 gtk_box_pack_start (GTK_BOX (priv->header_box), subject_caption, FALSE, FALSE, 0);
381 gtk_box_pack_start (GTK_BOX (priv->header_box), priv->attachments_caption, FALSE, FALSE, 0);
382 gtk_widget_set_no_show_all (priv->attachments_caption, TRUE);
385 priv->msg_body = wp_text_view_new ();
386 gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (priv->msg_body), GTK_WRAP_WORD_CHAR);
387 priv->text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->msg_body));
388 g_object_set (priv->text_buffer, "font_scale", 1.0, NULL);
389 wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
390 /* gtk_text_buffer_set_can_paste_rich_text (priv->text_buffer, TRUE); */
391 wp_text_buffer_reset_buffer (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
393 g_signal_connect (G_OBJECT (priv->text_buffer), "refresh_attributes",
394 G_CALLBACK (text_buffer_refresh_attributes), obj);
395 g_signal_connect (G_OBJECT (priv->text_buffer), "mark-set",
396 G_CALLBACK (text_buffer_mark_set), obj);
397 g_signal_connect (G_OBJECT (obj), "window-state-event",
398 G_CALLBACK (modest_msg_edit_window_window_state_event),
400 g_signal_connect_swapped (G_OBJECT (priv->to_field), "open-addressbook",
401 G_CALLBACK (modest_msg_edit_window_open_addressbook), obj);
403 priv->scroll = gtk_scrolled_window_new (NULL, NULL);
404 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
405 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scroll), GTK_SHADOW_NONE);
407 main_vbox = gtk_vbox_new (FALSE, DEFAULT_MAIN_VBOX_SPACING);
409 gtk_box_pack_start (GTK_BOX(main_vbox), priv->header_box, FALSE, FALSE, 0);
410 frame = gtk_frame_new (NULL);
411 gtk_box_pack_start (GTK_BOX(main_vbox), frame, TRUE, TRUE, 0);
413 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (priv->scroll), main_vbox);
414 gtk_container_set_focus_vadjustment (GTK_CONTAINER (main_vbox), gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->scroll)));
415 gtk_widget_show_all (GTK_WIDGET(priv->scroll));
417 if (!modest_conf_get_bool(modest_runtime_get_conf(), MODEST_CONF_SHOW_CC, NULL))
418 gtk_widget_hide (priv->cc_field);
419 if (!modest_conf_get_bool(modest_runtime_get_conf(), MODEST_CONF_SHOW_BCC, NULL))
420 gtk_widget_hide (priv->bcc_field);
422 gtk_container_add (GTK_CONTAINER(obj), priv->scroll);
423 scroll_area = hildon_scroll_area_new (priv->scroll, priv->msg_body);
424 gtk_container_add (GTK_CONTAINER (frame), scroll_area);
425 gtk_container_set_focus_vadjustment (GTK_CONTAINER (scroll_area),
426 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->scroll)));
432 modest_msg_edit_window_finalize (GObject *obj)
434 G_OBJECT_CLASS(parent_class)->finalize (obj);
440 on_delete_event (GtkWidget *widget, GdkEvent *event, ModestMsgEditWindow *self)
442 save_settings (self);
447 menubar_to_menu (GtkUIManager *ui_manager)
449 GtkWidget *main_menu;
453 /* Create new main menu */
454 main_menu = gtk_menu_new();
456 /* Get the menubar from the UI manager */
457 menubar = gtk_ui_manager_get_widget (ui_manager, "/MenuBar");
459 iter = gtk_container_get_children (GTK_CONTAINER (menubar));
463 menu = GTK_WIDGET (iter->data);
464 gtk_widget_reparent(menu, main_menu);
466 iter = g_list_next (iter);
473 set_msg (ModestMsgEditWindow *self, TnyMsg *msg)
476 const gchar *to, *cc, *bcc, *subject, *body;
477 ModestMsgEditWindowPrivate *priv;
479 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self));
480 g_return_if_fail (TNY_IS_MSG (msg));
482 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
484 header = tny_msg_get_header (msg);
485 to = tny_header_get_to (header);
486 cc = tny_header_get_cc (header);
487 bcc = tny_header_get_bcc (header);
488 subject = tny_header_get_subject (header);
491 modest_recpt_editor_set_recipients (MODEST_RECPT_EDITOR (priv->to_field), to);
493 modest_recpt_editor_set_recipients (MODEST_RECPT_EDITOR (priv->cc_field), cc);
495 modest_recpt_editor_set_recipients (MODEST_RECPT_EDITOR (priv->bcc_field), bcc);
497 gtk_entry_set_text (GTK_ENTRY(priv->subject_field), subject);
499 /* gtk_text_buffer_set_can_paste_rich_text (priv->text_buffer, TRUE); */
500 wp_text_buffer_reset_buffer (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
501 body = modest_tny_msg_get_body (msg, FALSE);
502 if ((body!=NULL) && (body[0] != '\0')) {
503 wp_text_buffer_load_document_begin (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
504 wp_text_buffer_load_document_write (WP_TEXT_BUFFER (priv->text_buffer),
507 wp_text_buffer_load_document_end (WP_TEXT_BUFFER (priv->text_buffer));
509 WPTextBufferFormat fmt = {0};
511 fmt.font_size = DEFAULT_FONT_SIZE;
512 fmt.font = DEFAULT_FONT;
514 fmt.text_position = TEXT_POSITION_NORMAL;
515 fmt.justification = 0;
516 fmt.cs.font_size = 1;
518 fmt.cs.text_position = 1;
519 fmt.cs.justification = 1;
520 wp_text_buffer_set_format (WP_TEXT_BUFFER (priv->text_buffer), &fmt);
523 /* Set the default focus depending on having already a To: field or not */
524 if ((!to)||(*to == '\0')) {
525 gtk_widget_grab_focus (priv->to_field);
527 gtk_widget_grab_focus (priv->msg_body);
530 /* TODO: lower priority, select in the From: combo to the
531 value that comes from msg <- not sure, should it be
534 /* Add attachments to the view */
535 modest_attachments_view_set_message (MODEST_ATTACHMENTS_VIEW (priv->attachments_view), msg);
536 if (priv->attachments == NULL)
537 gtk_widget_hide_all (priv->attachments_caption);
541 menu_tool_button_clicked_popup (GtkMenuToolButton *item,
544 GList *item_children, *node;
545 GtkWidget *bin_child;
547 bin_child = gtk_bin_get_child (GTK_BIN(item));
549 item_children = gtk_container_get_children (GTK_CONTAINER (bin_child));
551 for (node = item_children; node != NULL; node = g_list_next (node)) {
552 if (GTK_IS_TOGGLE_BUTTON (node->data)) {
553 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (node->data), TRUE);
556 g_list_free (item_children);
560 menu_tool_button_dont_expand (GtkMenuToolButton *item)
563 GList *item_children, *node;
565 box = gtk_bin_get_child (GTK_BIN (item));
566 gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
567 item_children = gtk_container_get_children (GTK_CONTAINER (box));
569 for (node = item_children; node != NULL; node = g_list_next (node)) {
570 gtk_box_set_child_packing (GTK_BOX (box), GTK_WIDGET (node->data), TRUE, TRUE, 0, GTK_PACK_START);
571 if (GTK_IS_TOGGLE_BUTTON (node->data))
572 gtk_button_set_alignment (GTK_BUTTON (node->data), 0.0, 0.5);
573 else if (GTK_IS_BUTTON (node->data))
574 gtk_button_set_alignment (GTK_BUTTON (node->data), 1.0, 0.5);
576 g_list_free (item_children);
581 modest_msg_edit_window_setup_toolbar (ModestMsgEditWindow *window)
583 ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
584 ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
585 GtkWidget *placeholder;
586 GtkWidget *tool_item;
591 GtkWidget *sizes_menu;
592 GtkWidget *fonts_menu;
593 GSList *radio_group = NULL;
597 parent_priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar");
598 hildon_window_add_toolbar (HILDON_WINDOW (window), GTK_TOOLBAR (parent_priv->toolbar));
600 /* should we hide the toolbar? */
601 if (!modest_conf_get_bool (modest_runtime_get_conf (), MODEST_CONF_SHOW_TOOLBAR, NULL))
602 gtk_widget_hide (parent_priv->toolbar);
604 /* Font color placeholder */
605 placeholder = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/FontColor");
606 insert_index = gtk_toolbar_get_item_index(GTK_TOOLBAR (parent_priv->toolbar), GTK_TOOL_ITEM(placeholder));
609 tool_item = GTK_WIDGET (gtk_tool_item_new ());
610 priv->font_color_button = hildon_color_button_new ();
611 gtk_container_add (GTK_CONTAINER (tool_item), priv->font_color_button);
612 gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), TRUE);
613 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), TRUE);
614 gtk_toolbar_insert(GTK_TOOLBAR(parent_priv->toolbar), GTK_TOOL_ITEM (tool_item), insert_index);
615 g_signal_connect_swapped (G_OBJECT (priv->font_color_button), "notify::color", G_CALLBACK (modest_msg_edit_window_color_button_change), window);
617 /* Font size and face placeholder */
618 placeholder = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/FontAttributes");
619 insert_index = gtk_toolbar_get_item_index(GTK_TOOLBAR (parent_priv->toolbar), GTK_TOOL_ITEM(placeholder));
621 tool_item = GTK_WIDGET (gtk_menu_tool_button_new (NULL, NULL));
622 priv->size_tool_button_label = gtk_label_new (NULL);
623 snprintf(size_text, sizeof(size_text), "%d", wp_font_size[DEFAULT_FONT_SIZE]);
624 markup = g_strconcat ("<span font_family='", DEFAULT_SIZE_BUTTON_FONT_FAMILY, "'>",
625 size_text,"</span>", NULL);
626 gtk_label_set_markup (GTK_LABEL (priv->size_tool_button_label), markup);
628 gtk_tool_button_set_label_widget (GTK_TOOL_BUTTON (tool_item), priv->size_tool_button_label);
629 sizes_menu = gtk_menu_new ();
630 priv->size_items_group = NULL;
632 for (size_index = 0; size_index < WP_FONT_SIZE_COUNT; size_index++) {
633 GtkWidget *size_menu_item;
635 snprintf(size_text, sizeof(size_text), "%d", wp_font_size[size_index]);
636 size_menu_item = gtk_radio_menu_item_new_with_label (radio_group, size_text);
637 radio_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (size_menu_item));
638 gtk_menu_shell_append (GTK_MENU_SHELL (sizes_menu), size_menu_item);
639 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (size_menu_item), (wp_font_size[size_index] == 12));
640 gtk_widget_show (size_menu_item);
642 priv->size_items_group = g_slist_prepend (priv->size_items_group, size_menu_item);
644 g_signal_connect (G_OBJECT (size_menu_item), "toggled", G_CALLBACK (modest_msg_edit_window_size_change),
647 priv->size_items_group = g_slist_reverse (priv->size_items_group);
648 gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (tool_item), sizes_menu);
649 g_signal_connect (G_OBJECT (tool_item), "clicked", G_CALLBACK (menu_tool_button_clicked_popup), NULL);
650 gtk_toolbar_insert (GTK_TOOLBAR (parent_priv->toolbar), GTK_TOOL_ITEM (tool_item), insert_index);
651 gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), TRUE);
652 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), TRUE);
653 menu_tool_button_dont_expand (GTK_MENU_TOOL_BUTTON (tool_item));
656 tool_item = GTK_WIDGET (gtk_menu_tool_button_new (NULL, NULL));
657 priv->font_tool_button_label = gtk_label_new (NULL);
658 markup = g_strconcat ("<span font_family='", wp_get_font_name(DEFAULT_FONT), "'>Tt</span>", NULL);
659 gtk_label_set_markup (GTK_LABEL (priv->font_tool_button_label), markup);
661 gtk_tool_button_set_label_widget (GTK_TOOL_BUTTON (tool_item), priv->font_tool_button_label);
662 fonts_menu = gtk_menu_new ();
663 priv->font_items_group = NULL;
665 for (font_index = 0; font_index < wp_get_font_count (); font_index++) {
666 GtkWidget *font_menu_item;
667 GtkWidget *child_label;
669 font_menu_item = gtk_radio_menu_item_new_with_label (radio_group, "");
670 child_label = gtk_bin_get_child (GTK_BIN (font_menu_item));
671 markup = g_strconcat ("<span font_family='", wp_get_font_name (font_index),"'>",
672 wp_get_font_name (font_index), "</span>", NULL);
673 gtk_label_set_markup (GTK_LABEL (child_label), markup);
676 radio_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (font_menu_item));
677 gtk_menu_shell_append (GTK_MENU_SHELL (fonts_menu), font_menu_item);
678 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (font_menu_item), (font_index == DEFAULT_FONT));
679 gtk_widget_show (font_menu_item);
681 priv->font_items_group = g_slist_prepend (priv->font_items_group, font_menu_item);
683 g_signal_connect (G_OBJECT (font_menu_item), "toggled", G_CALLBACK (modest_msg_edit_window_font_change),
686 priv->font_items_group = g_slist_reverse (priv->font_items_group);
687 gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (tool_item), fonts_menu);
688 g_signal_connect (G_OBJECT (tool_item), "clicked", G_CALLBACK (menu_tool_button_clicked_popup), NULL);
689 gtk_toolbar_insert (GTK_TOOLBAR (parent_priv->toolbar), GTK_TOOL_ITEM (tool_item), insert_index);
690 gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), TRUE);
691 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), TRUE);
692 menu_tool_button_dont_expand (GTK_MENU_TOOL_BUTTON (tool_item));
694 /* Set expand and homogeneous for remaining items */
695 tool_item = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/ActionsSend");
696 gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), TRUE);
697 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), TRUE);
698 tool_item = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/ActionsBold");
699 gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), TRUE);
700 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), TRUE);
701 tool_item = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/ActionsItalics");
702 gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), TRUE);
703 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), TRUE);
711 modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name)
714 ModestWindowPrivate *parent_priv;
715 ModestMsgEditWindowPrivate *priv;
716 GtkActionGroup *action_group;
717 GError *error = NULL;
718 GdkPixbuf *window_icon = NULL;
720 g_return_val_if_fail (msg, NULL);
722 obj = g_object_new(MODEST_TYPE_MSG_EDIT_WINDOW, NULL);
724 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (obj);
725 parent_priv = MODEST_WINDOW_GET_PRIVATE (obj);
727 parent_priv->ui_manager = gtk_ui_manager_new();
728 action_group = gtk_action_group_new ("ModestMsgEditWindowActions");
729 gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
731 /* Add common actions */
732 gtk_action_group_add_actions (action_group,
733 modest_msg_edit_action_entries,
734 G_N_ELEMENTS (modest_msg_edit_action_entries),
736 gtk_action_group_add_toggle_actions (action_group,
737 modest_msg_edit_toggle_action_entries,
738 G_N_ELEMENTS (modest_msg_edit_toggle_action_entries),
740 gtk_action_group_add_radio_actions (action_group,
741 modest_msg_edit_alignment_radio_action_entries,
742 G_N_ELEMENTS (modest_msg_edit_alignment_radio_action_entries),
744 G_CALLBACK (modest_ui_actions_on_change_justify),
746 gtk_action_group_add_radio_actions (action_group,
747 modest_msg_edit_zoom_action_entries,
748 G_N_ELEMENTS (modest_msg_edit_zoom_action_entries),
750 G_CALLBACK (modest_ui_actions_on_change_zoom),
752 gtk_action_group_add_radio_actions (action_group,
753 modest_msg_edit_priority_action_entries,
754 G_N_ELEMENTS (modest_msg_edit_priority_action_entries),
756 G_CALLBACK (modest_ui_actions_msg_edit_on_change_priority),
758 gtk_action_group_add_radio_actions (action_group,
759 modest_msg_edit_file_format_action_entries,
760 G_N_ELEMENTS (modest_msg_edit_file_format_action_entries),
761 MODEST_FILE_FORMAT_FORMATTED_TEXT,
762 G_CALLBACK (modest_ui_actions_msg_edit_on_change_file_format),
764 gtk_ui_manager_insert_action_group (parent_priv->ui_manager, action_group, 0);
765 g_object_unref (action_group);
767 /* Load the UI definition */
768 gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager, MODEST_UIDIR "modest-msg-edit-window-ui.xml", &error);
770 g_warning ("Could not merge modest-msg-edit-window-ui.xml: %s", error->message);
771 g_error_free (error);
775 /* Add accelerators */
776 gtk_window_add_accel_group (GTK_WINDOW (obj),
777 gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
780 parent_priv->menubar = menubar_to_menu (parent_priv->ui_manager);
781 hildon_window_set_menu (HILDON_WINDOW (obj), GTK_MENU (parent_priv->menubar));
784 init_window (MODEST_MSG_EDIT_WINDOW(obj));
786 restore_settings (MODEST_MSG_EDIT_WINDOW(obj));
788 gtk_window_set_title (GTK_WINDOW(obj), "Modest");
789 gtk_window_set_icon_from_file (GTK_WINDOW(obj), MODEST_APP_ICON, NULL);
791 g_signal_connect (G_OBJECT(obj), "delete-event",
792 G_CALLBACK(on_delete_event), obj);
794 modest_window_set_active_account (MODEST_WINDOW(obj), account_name);
796 modest_msg_edit_window_setup_toolbar (MODEST_MSG_EDIT_WINDOW (obj));
798 set_msg (MODEST_MSG_EDIT_WINDOW (obj), msg);
800 text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (obj));
802 /* Set window icon */
803 window_icon = modest_platform_get_icon (MODEST_APP_MSG_EDIT_ICON);
804 gtk_window_set_icon (GTK_WINDOW (obj), window_icon);
806 return (ModestWindow*)obj;
810 get_formatted_data_cb (const gchar *buffer, gpointer user_data)
812 GString **string_buffer = (GString **) user_data;
814 *string_buffer = g_string_append (*string_buffer, buffer);
820 get_formatted_data (ModestMsgEditWindow *edit_window)
822 ModestMsgEditWindowPrivate *priv;
823 GString *string_buffer = g_string_new ("");
825 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (edit_window);
827 wp_text_buffer_save_document (WP_TEXT_BUFFER(priv->text_buffer), get_formatted_data_cb, &string_buffer);
829 return g_string_free (string_buffer, FALSE);
834 modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window)
837 const gchar *account_name;
840 ModestMsgEditWindowPrivate *priv;
842 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (edit_window), NULL);
844 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (edit_window);
846 account_name = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->from_field));
847 g_return_val_if_fail (account_name, NULL);
849 buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->msg_body));
850 gtk_text_buffer_get_bounds (buf, &b, &e);
852 /* don't free these (except from) */
853 data = g_slice_new0 (MsgData);
854 data->from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
856 data->to = (gchar*) modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR(priv->to_field));
857 data->cc = (gchar*) modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR(priv->cc_field));
858 data->bcc = (gchar*) modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR(priv->bcc_field));
859 data->subject = (gchar*) gtk_entry_get_text (GTK_ENTRY(priv->subject_field));
860 data->plain_body = (gchar *) gtk_text_buffer_get_text (priv->text_buffer, &b, &e, FALSE);
861 if (wp_text_buffer_is_rich_text (WP_TEXT_BUFFER (priv->text_buffer)))
862 data->html_body = get_formatted_data (edit_window);
864 data->html_body = NULL;
865 data->attachments = priv->attachments;
866 data->priority_flags = priv->priority_flags;
872 modest_msg_edit_window_free_msg_data (ModestMsgEditWindow *edit_window,
875 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (edit_window));
878 g_free (data->html_body);
879 g_free (data->plain_body);
880 g_slice_free (MsgData, data);
884 modest_msg_edit_window_get_format (ModestMsgEditWindow *self)
887 ModestMsgEditWindowPrivate *priv = NULL;
888 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self), MODEST_MSG_EDIT_FORMAT_HTML);
890 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
892 rich_text = wp_text_buffer_is_rich_text (WP_TEXT_BUFFER (priv->text_buffer));
894 return MODEST_MSG_EDIT_FORMAT_HTML;
896 return MODEST_MSG_EDIT_FORMAT_TEXT;
900 modest_msg_edit_window_set_format (ModestMsgEditWindow *self,
901 ModestMsgEditFormat format)
903 ModestMsgEditWindowPrivate *priv;
905 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self));
906 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
909 case MODEST_MSG_EDIT_FORMAT_HTML:
910 wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
912 case MODEST_MSG_EDIT_FORMAT_TEXT:
913 wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
916 g_return_if_reached ();
920 ModestMsgEditFormatState *
921 modest_msg_edit_window_get_format_state (ModestMsgEditWindow *self)
923 ModestMsgEditFormatState *format_state = NULL;
924 ModestMsgEditWindowPrivate *priv;
925 WPTextBufferFormat *buffer_format = g_new0 (WPTextBufferFormat, 1);
927 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self), NULL);
928 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
930 wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), buffer_format, TRUE);
932 format_state = g_new0 (ModestMsgEditFormatState, 1);
933 format_state->bold = buffer_format->bold&0x1;
934 format_state->italics = buffer_format->italic&0x1;
935 format_state->bullet = buffer_format->bullet&0x1;
936 format_state->color = buffer_format->color;
937 format_state->font_size = buffer_format->font_size;
938 format_state->font_family = wp_get_font_name (buffer_format->font);
939 format_state->justification = buffer_format->justification;
940 g_free (buffer_format);
947 modest_msg_edit_window_set_format_state (ModestMsgEditWindow *self,
948 const ModestMsgEditFormatState *format_state)
950 ModestMsgEditWindowPrivate *priv;
951 WPTextBufferFormat *buffer_format = g_new0 (WPTextBufferFormat, 1);
952 WPTextBufferFormat *current_format = g_new0 (WPTextBufferFormat, 1);
953 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self));
954 g_return_if_fail (format_state != NULL);
956 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
957 gtk_widget_grab_focus (priv->msg_body);
958 buffer_format->bold = (format_state->bold != FALSE);
959 buffer_format->italic = (format_state->italics != FALSE);
960 buffer_format->color = format_state->color;
961 buffer_format->font_size = format_state->font_size;
962 buffer_format->font = wp_get_font_index (format_state->font_family, 0);
963 buffer_format->justification = format_state->justification;
964 buffer_format->bullet = format_state->bullet;
966 wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), current_format, TRUE);
968 buffer_format->cs.bold = ((buffer_format->bold&0x1) != (current_format->bold&0x1));
969 buffer_format->cs.italic = ((buffer_format->italic&0x1) != (current_format->italic&0x1));
970 buffer_format->cs.color = gdk_color_equal(&(buffer_format->color), &(current_format->color));
971 buffer_format->cs.font_size = (buffer_format->font_size != current_format->font_size);
972 buffer_format->cs.font = (buffer_format->font != current_format->font);
973 buffer_format->cs.justification = (buffer_format->justification != current_format->justification);
974 buffer_format->cs.bullet = (buffer_format->bullet != current_format->bullet);
976 wp_text_buffer_freeze (WP_TEXT_BUFFER (priv->text_buffer));
977 if (buffer_format->cs.bold) {
978 wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BOLD, (gpointer) (buffer_format->bold&0x1));
980 if (buffer_format->cs.italic) {
981 wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_ITALIC, (gpointer) (buffer_format->italic&0x1));
983 if (buffer_format->cs.color) {
984 wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR, (gpointer) (&(buffer_format->color)));
986 if (buffer_format->cs.font_size) {
987 wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BOLD, (gpointer) (buffer_format->font_size));
989 if (buffer_format->cs.justification) {
990 switch (buffer_format->justification) {
991 case GTK_JUSTIFY_LEFT:
992 wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_LEFT, (gpointer) TRUE);
994 case GTK_JUSTIFY_CENTER:
995 wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_CENTER, (gpointer) TRUE);
997 case GTK_JUSTIFY_RIGHT:
998 wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_RIGHT, (gpointer) TRUE);
1005 if (buffer_format->cs.font) {
1006 wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BOLD, (gpointer) (buffer_format->font));
1008 if (buffer_format->cs.bullet) {
1009 wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BULLET, (gpointer) (buffer_format->bullet));
1011 /* wp_text_buffer_set_format (WP_TEXT_BUFFER (priv->text_buffer), buffer_format); */
1012 wp_text_buffer_thaw (WP_TEXT_BUFFER (priv->text_buffer));
1014 g_free (current_format);
1019 toggle_action_set_active_block_notify (GtkToggleAction *action,
1022 GSList *proxies = NULL;
1024 for (proxies = gtk_action_get_proxies (GTK_ACTION (action));
1025 proxies != NULL; proxies = g_slist_next (proxies)) {
1026 GtkWidget *widget = (GtkWidget *) proxies->data;
1027 gtk_action_block_activate_from (GTK_ACTION (action), widget);
1030 gtk_toggle_action_set_active (action, value);
1032 for (proxies = gtk_action_get_proxies (GTK_ACTION (action));
1033 proxies != NULL; proxies = g_slist_next (proxies)) {
1034 GtkWidget *widget = (GtkWidget *) proxies->data;
1035 gtk_action_unblock_activate_from (GTK_ACTION (action), widget);
1040 text_buffer_refresh_attributes (WPTextBuffer *buffer, ModestMsgEditWindow *window)
1042 WPTextBufferFormat *buffer_format = g_new0 (WPTextBufferFormat, 1);
1044 ModestWindowPrivate *parent_priv;
1045 ModestMsgEditWindowPrivate *priv;
1046 GtkWidget *new_size_menuitem;
1047 GtkWidget *new_font_menuitem;
1049 parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
1050 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
1052 wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), buffer_format, FALSE);
1054 action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ActionsBold");
1055 toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), buffer_format->bold);
1057 action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ActionsItalics");
1058 toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), buffer_format->italic);
1060 action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/BulletedListMenu");
1061 toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), buffer_format->bullet);
1063 g_signal_handlers_block_by_func (G_OBJECT (priv->font_color_button),
1064 G_CALLBACK (modest_msg_edit_window_color_button_change),
1066 hildon_color_button_set_color (HILDON_COLOR_BUTTON (priv->font_color_button), & (buffer_format->color));
1067 g_signal_handlers_unblock_by_func (G_OBJECT (priv->font_color_button),
1068 G_CALLBACK (modest_msg_edit_window_color_button_change),
1071 new_size_menuitem = GTK_WIDGET ((g_slist_nth (priv->size_items_group,
1072 buffer_format->font_size))->data);
1073 if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (new_size_menuitem))) {
1077 label = gtk_bin_get_child (GTK_BIN (new_size_menuitem));
1078 markup = g_strconcat ("<span font_family='Serif'>", gtk_label_get_text (GTK_LABEL (label)), "</span>", NULL);
1079 gtk_label_set_markup (GTK_LABEL (priv->size_tool_button_label), markup);
1081 g_signal_handlers_block_by_func (G_OBJECT (new_size_menuitem),
1082 G_CALLBACK (modest_msg_edit_window_size_change),
1084 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (new_size_menuitem), TRUE);
1085 g_signal_handlers_unblock_by_func (G_OBJECT (new_size_menuitem),
1086 G_CALLBACK (modest_msg_edit_window_size_change),
1090 new_font_menuitem = GTK_WIDGET ((g_slist_nth (priv->font_items_group,
1091 buffer_format->font))->data);
1092 if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (new_font_menuitem))) {
1096 label = gtk_bin_get_child (GTK_BIN (new_font_menuitem));
1097 markup = g_strconcat ("<span font_family='", gtk_label_get_text (GTK_LABEL (label)),"'>Tt</span>", NULL);
1098 gtk_label_set_markup (GTK_LABEL (priv->font_tool_button_label), markup);
1100 g_signal_handlers_block_by_func (G_OBJECT (new_font_menuitem),
1101 G_CALLBACK (modest_msg_edit_window_font_change),
1103 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (new_font_menuitem), TRUE);
1104 g_signal_handlers_unblock_by_func (G_OBJECT (new_font_menuitem),
1105 G_CALLBACK (modest_msg_edit_window_font_change),
1109 g_free (buffer_format);
1114 modest_msg_edit_window_select_color (ModestMsgEditWindow *window)
1117 WPTextBufferFormat *buffer_format = g_new0 (WPTextBufferFormat, 1);
1118 ModestMsgEditWindowPrivate *priv;
1119 GtkWidget *dialog = NULL;
1121 const GdkColor *new_color = NULL;
1123 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
1124 wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), buffer_format, FALSE);
1126 dialog = hildon_color_selector_new (GTK_WINDOW (window));
1127 hildon_color_selector_set_color (HILDON_COLOR_SELECTOR (dialog), & (buffer_format->color));
1128 g_free (buffer_format);
1130 response = gtk_dialog_run (GTK_DIALOG (dialog));
1132 case GTK_RESPONSE_OK:
1133 new_color = hildon_color_selector_get_color (HILDON_COLOR_SELECTOR (dialog));
1138 gtk_widget_destroy (dialog);
1140 if (new_color != NULL)
1141 wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR, (gpointer) new_color);
1146 modest_msg_edit_window_select_background_color (ModestMsgEditWindow *window)
1149 ModestMsgEditWindowPrivate *priv;
1150 GtkWidget *dialog = NULL;
1152 const GdkColor *old_color = NULL;
1153 const GdkColor *new_color = NULL;
1155 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
1156 old_color = wp_text_buffer_get_background_color (WP_TEXT_BUFFER (priv->text_buffer));
1158 dialog = hildon_color_selector_new (GTK_WINDOW (window));
1159 hildon_color_selector_set_color (HILDON_COLOR_SELECTOR (dialog), (GdkColor *) old_color);
1161 response = gtk_dialog_run (GTK_DIALOG (dialog));
1163 case GTK_RESPONSE_OK:
1164 new_color = hildon_color_selector_get_color (HILDON_COLOR_SELECTOR (dialog));
1169 gtk_widget_destroy (dialog);
1171 if (new_color != NULL)
1172 wp_text_buffer_set_background_color (WP_TEXT_BUFFER (priv->text_buffer), new_color);
1177 modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
1180 ModestMsgEditWindowPrivate *priv;
1181 GtkWidget *dialog = NULL;
1183 gchar *filename = NULL;
1185 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
1187 dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (window), GTK_FILE_CHOOSER_ACTION_OPEN);
1189 response = gtk_dialog_run (GTK_DIALOG (dialog));
1191 case GTK_RESPONSE_OK:
1192 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1197 gtk_widget_destroy (dialog);
1200 GdkPixbuf *pixbuf = NULL;
1201 GtkTextIter position;
1202 GtkTextMark *insert_mark;
1204 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1207 GdkPixbufFormat *pixbuf_format;
1209 image_file_id = g_open (filename, O_RDONLY, 0);
1210 pixbuf_format = gdk_pixbuf_get_file_info (filename, NULL, NULL);
1211 if ((image_file_id != -1)&&(pixbuf_format != NULL)) {
1212 TnyMimePart *image_part;
1213 TnyStream *image_stream;
1219 mime_types = gdk_pixbuf_format_get_mime_types (pixbuf_format);
1220 if ((mime_types != NULL) && (mime_types[0] != NULL)) {
1221 mime_type = mime_types[0];
1223 mime_type = "image/unknown";
1225 image_part = tny_platform_factory_new_mime_part
1226 (modest_runtime_get_platform_factory ());
1227 image_stream = TNY_STREAM (tny_fs_stream_new (image_file_id));
1229 tny_mime_part_construct_from_stream (image_part, image_stream, mime_type);
1230 g_strfreev (mime_types);
1232 content_id = g_strdup_printf ("%d", priv->last_cid);
1233 tny_mime_part_set_content_id (image_part, content_id);
1234 g_free (content_id);
1237 basename = g_path_get_basename (filename);
1238 tny_mime_part_set_filename (image_part, basename);
1241 insert_mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (priv->text_buffer));
1242 gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (priv->text_buffer), &position, insert_mark);
1243 wp_text_buffer_insert_image (WP_TEXT_BUFFER (priv->text_buffer), &position, g_strdup (tny_mime_part_get_content_id (image_part)), pixbuf);
1244 priv->attachments = g_list_prepend (priv->attachments, image_part);
1245 modest_attachments_view_add_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
1247 gtk_widget_set_no_show_all (priv->attachments_caption, FALSE);
1248 gtk_widget_show_all (priv->attachments_caption);
1249 } else if (image_file_id == -1) {
1250 close (image_file_id);
1259 modest_msg_edit_window_color_button_change (ModestMsgEditWindow *window,
1262 ModestMsgEditWindowPrivate *priv;
1263 GdkColor *new_color;
1265 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
1266 new_color = hildon_color_button_get_color (HILDON_COLOR_BUTTON (priv->font_color_button));
1268 wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR, (gpointer) new_color);
1269 gtk_window_set_focus (GTK_WINDOW (window), priv->msg_body);
1274 modest_msg_edit_window_size_change (GtkCheckMenuItem *menu_item,
1277 ModestMsgEditWindowPrivate *priv;
1278 gint new_size_index;
1279 ModestMsgEditWindow *window;
1282 window = MODEST_MSG_EDIT_WINDOW (userdata);
1283 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
1284 gtk_widget_grab_focus (GTK_WIDGET (priv->msg_body));
1286 if (gtk_check_menu_item_get_active (menu_item)) {
1289 label = gtk_bin_get_child (GTK_BIN (menu_item));
1291 new_size_index = atoi (gtk_label_get_text (GTK_LABEL (label)));
1293 if (!wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT_SIZE,
1294 (gpointer) wp_get_font_size_index (new_size_index, 12)))
1295 wp_text_view_reset_and_show_im (WP_TEXT_VIEW (priv->msg_body));
1297 text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (window));
1298 markup = g_strconcat ("<span font_family='Serif'>", gtk_label_get_text (GTK_LABEL (label)), "</span>", NULL);
1299 gtk_label_set_markup (GTK_LABEL (priv->size_tool_button_label), markup);
1305 modest_msg_edit_window_font_change (GtkCheckMenuItem *menu_item,
1308 ModestMsgEditWindowPrivate *priv;
1309 gint new_font_index;
1310 ModestMsgEditWindow *window;
1313 window = MODEST_MSG_EDIT_WINDOW (userdata);
1314 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
1315 gtk_widget_grab_focus (GTK_WIDGET (priv->msg_body));
1317 if (gtk_check_menu_item_get_active (menu_item)) {
1320 label = gtk_bin_get_child (GTK_BIN (menu_item));
1322 new_font_index = wp_get_font_index (gtk_label_get_text (GTK_LABEL (label)), DEFAULT_FONT);
1324 if (!wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT,
1325 (gpointer) new_font_index))
1326 wp_text_view_reset_and_show_im (WP_TEXT_VIEW (priv->msg_body));
1328 text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (window));
1329 markup = g_strconcat ("<span font_family='",gtk_label_get_text (GTK_LABEL (label)),"'>Tt</span>", NULL);
1330 gtk_label_set_markup (GTK_LABEL (priv->font_tool_button_label), markup);
1336 modest_msg_edit_window_set_zoom (ModestWindow *window,
1339 ModestMsgEditWindowPrivate *priv;
1341 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1343 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
1344 priv->zoom_level = zoom;
1345 wp_text_buffer_set_font_scaling_factor (WP_TEXT_BUFFER (priv->text_buffer), zoom);
1349 modest_msg_edit_window_get_zoom (ModestWindow *window)
1351 ModestMsgEditWindowPrivate *priv;
1353 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window), 1.0);
1355 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
1356 return priv->zoom_level;
1360 modest_msg_edit_window_zoom_plus (ModestWindow *window)
1362 ModestWindowPrivate *parent_priv;
1363 GtkRadioAction *zoom_radio_action;
1364 GSList *group, *node;
1366 parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
1367 zoom_radio_action = GTK_RADIO_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager,
1368 "/MenuBar/ViewMenu/ZoomMenu/Zoom50Menu"));
1370 group = gtk_radio_action_get_group (zoom_radio_action);
1372 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (group->data))) {
1373 hildon_banner_show_information (NULL, NULL, _("mcen_ib_max_zoom_level"));
1377 for (node = group; node != NULL; node = g_slist_next (node)) {
1378 if ((node->next != NULL) && gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (node->next->data))) {
1379 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (node->data), TRUE);
1387 modest_msg_edit_window_zoom_minus (ModestWindow *window)
1389 ModestWindowPrivate *parent_priv;
1390 GtkRadioAction *zoom_radio_action;
1391 GSList *group, *node;
1393 parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
1394 zoom_radio_action = GTK_RADIO_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager,
1395 "/MenuBar/ViewMenu/ZoomMenu/Zoom50Menu"));
1397 group = gtk_radio_action_get_group (zoom_radio_action);
1399 for (node = group; node != NULL; node = g_slist_next (node)) {
1400 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (node->data))) {
1401 if (node->next != NULL) {
1402 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (node->next->data), TRUE);
1405 hildon_banner_show_information (NULL, NULL, _("mcen_ib_min_zoom_level"));
1413 modest_msg_edit_window_window_state_event (GtkWidget *widget, GdkEventWindowState *event, gpointer userdata)
1415 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) {
1416 ModestWindowPrivate *parent_priv;
1417 ModestWindowMgr *mgr;
1418 gboolean is_fullscreen;
1419 GtkAction *fs_toggle_action;
1422 mgr = modest_runtime_get_window_mgr ();
1423 is_fullscreen = (modest_window_mgr_get_fullscreen_mode (mgr))?1:0;
1425 parent_priv = MODEST_WINDOW_GET_PRIVATE (widget);
1427 fs_toggle_action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewToggleFullscreenMenu");
1428 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (fs_toggle_action)))?1:0;
1429 if (is_fullscreen != active)
1430 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (fs_toggle_action), is_fullscreen);
1438 modest_msg_edit_window_toggle_fullscreen (ModestMsgEditWindow *window)
1440 ModestWindowPrivate *parent_priv;
1441 GtkAction *fs_toggle_action;
1444 parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
1446 fs_toggle_action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewToggleFullscreenMenu");
1447 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (fs_toggle_action));
1448 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (fs_toggle_action), !active);
1452 modest_msg_edit_window_show_cc (ModestMsgEditWindow *window,
1455 ModestMsgEditWindowPrivate *priv = NULL;
1456 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1458 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
1460 gtk_widget_show (priv->cc_caption);
1462 gtk_widget_hide (priv->cc_caption);
1466 modest_msg_edit_window_show_bcc (ModestMsgEditWindow *window,
1469 ModestMsgEditWindowPrivate *priv = NULL;
1470 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1472 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
1474 gtk_widget_show (priv->bcc_caption);
1476 gtk_widget_hide (priv->bcc_caption);
1480 modest_msg_edit_window_open_addressbook (ModestMsgEditWindow *window,
1481 ModestRecptEditor *editor)
1483 ModestMsgEditWindowPrivate *priv;
1485 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1486 g_return_if_fail ((editor == NULL) || (MODEST_IS_RECPT_EDITOR (editor)));
1487 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
1489 if (editor == NULL) {
1490 GtkWidget *view_focus;
1491 view_focus = gtk_window_get_focus (GTK_WINDOW (window));
1493 if (gtk_widget_get_parent (view_focus) &&
1494 MODEST_IS_RECPT_EDITOR (gtk_widget_get_parent (view_focus))) {
1495 editor = MODEST_RECPT_EDITOR (gtk_widget_get_parent (view_focus));
1497 editor = MODEST_RECPT_EDITOR (priv->to_field);
1501 modest_address_book_select_addresses (editor);
1505 modest_msg_edit_window_show_toolbar (ModestWindow *self,
1506 gboolean show_toolbar)
1508 ModestWindowPrivate *parent_priv;
1510 parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
1512 /* FIXME: we can not just use the code of
1513 modest_msg_edit_window_setup_toolbar because it has a
1514 mixture of both initialization and creation code. */
1517 gtk_widget_show (GTK_WIDGET (parent_priv->toolbar));
1519 gtk_widget_hide (GTK_WIDGET (parent_priv->toolbar));
1523 modest_msg_edit_window_set_priority_flags (ModestMsgEditWindow *window,
1524 TnyHeaderFlags priority_flags)
1526 ModestMsgEditWindowPrivate *priv;
1528 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1530 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
1531 priority_flags = priority_flags & (TNY_HEADER_FLAG_HIGH_PRIORITY);
1533 if (priv->priority_flags != priority_flags) {
1535 priv->priority_flags = priority_flags;
1537 switch (priority_flags) {
1538 case TNY_HEADER_FLAG_HIGH_PRIORITY:
1539 gtk_image_set_from_icon_name (GTK_IMAGE (priv->priority_icon), "qgn_list_messaging_high", GTK_ICON_SIZE_MENU);
1540 gtk_widget_show (priv->priority_icon);
1542 case TNY_HEADER_FLAG_LOW_PRIORITY:
1543 gtk_image_set_from_icon_name (GTK_IMAGE (priv->priority_icon), "qgn_list_messaging_low", GTK_ICON_SIZE_MENU);
1544 gtk_widget_show (priv->priority_icon);
1547 gtk_widget_hide (priv->priority_icon);
1554 modest_msg_edit_window_set_file_format (ModestMsgEditWindow *window,
1557 ModestMsgEditWindowPrivate *priv;
1558 gint current_format;
1560 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1562 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
1564 current_format = wp_text_buffer_is_rich_text (WP_TEXT_BUFFER (priv->text_buffer))
1565 ? MODEST_FILE_FORMAT_FORMATTED_TEXT : MODEST_FILE_FORMAT_PLAIN_TEXT;
1567 if (current_format != file_format) {
1568 switch (file_format) {
1569 case MODEST_FILE_FORMAT_FORMATTED_TEXT:
1570 wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
1572 case MODEST_FILE_FORMAT_PLAIN_TEXT:
1576 dialog = hildon_note_new_confirmation (NULL, _("emev_nc_formatting_lost"));
1577 response = gtk_dialog_run (GTK_DIALOG (dialog));
1578 gtk_widget_destroy (dialog);
1579 if (response == GTK_RESPONSE_OK)
1580 wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
1588 modest_msg_edit_window_select_font (ModestMsgEditWindow *window)
1591 ModestMsgEditWindowPrivate *priv;
1592 WPTextBufferFormat oldfmt, fmt;
1593 gint old_position = 0;
1597 GdkColor *color = NULL;
1598 gboolean bold, bold_set, italic, italic_set;
1599 gboolean underline, underline_set;
1600 gboolean strikethrough, strikethrough_set;
1601 gboolean position_set;
1602 gboolean font_size_set, font_set, color_set;
1605 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1606 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
1608 dialog = hildon_font_selection_dialog_new (NULL, NULL);
1610 /* First we get the currently selected font information */
1611 wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), &oldfmt, TRUE);
1612 g_object_set (G_OBJECT (dialog), "font-scaling", priv->zoom_level, NULL);
1614 switch (oldfmt.text_position) {
1615 case TEXT_POSITION_NORMAL:
1618 case TEXT_POSITION_SUPERSCRIPT:
1626 g_object_set (G_OBJECT (dialog),
1627 "bold", oldfmt.bold != FALSE,
1628 "bold-set", !oldfmt.cs.bold,
1629 "underline", oldfmt.underline != FALSE,
1630 "underline-set", !oldfmt.cs.underline,
1631 "italic", oldfmt.italic != FALSE,
1632 "italic-set", !oldfmt.cs.italic,
1633 "strikethrough", oldfmt.strikethrough != FALSE,
1634 "strikethrough-set", !oldfmt.cs.strikethrough,
1635 "color", &oldfmt.color,
1636 "color-set", !oldfmt.cs.color,
1637 "size", wp_font_size[oldfmt.font_size],
1638 "size-set", !oldfmt.cs.font_size,
1639 "position", old_position,
1640 "position-set", !oldfmt.cs.text_position,
1641 "family", wp_get_font_name (oldfmt.font),
1642 "family-set", !oldfmt.cs.font,
1645 gtk_widget_show_all (dialog);
1646 response = gtk_dialog_run (GTK_DIALOG (dialog));
1647 if (response == GTK_RESPONSE_OK) {
1649 g_object_get( dialog,
1651 "bold-set", &bold_set,
1652 "underline", &underline,
1653 "underline-set", &underline_set,
1655 "italic-set", &italic_set,
1656 "strikethrough", &strikethrough,
1657 "strikethrough-set", &strikethrough_set,
1659 "color-set", &color_set,
1661 "size-set", &font_size_set,
1662 "family", &font_name,
1663 "family-set", &font_set,
1664 "position", &position,
1665 "position-set", &position_set,
1670 gtk_widget_destroy (dialog);
1672 if (response == GTK_RESPONSE_OK) {
1673 memset(&fmt, 0, sizeof(fmt));
1679 fmt.italic = italic;
1680 fmt.cs.italic = TRUE;
1682 if (underline_set) {
1683 fmt.underline = underline;
1684 fmt.cs.underline = TRUE;
1686 if (strikethrough_set) {
1687 fmt.strikethrough = strikethrough;
1688 fmt.cs.strikethrough = TRUE;
1693 ? TEXT_POSITION_NORMAL
1694 : ( ( position == 1 )
1695 ? TEXT_POSITION_SUPERSCRIPT
1696 : TEXT_POSITION_SUBSCRIPT );
1697 fmt.cs.text_position = TRUE;
1701 fmt.cs.color = TRUE;
1703 gdk_color_free(color);
1705 fmt.font = wp_get_font_index(font_name,
1710 if (font_size_set) {
1711 fmt.font_size = wp_get_font_size_index(
1712 font_size, DEFAULT_FONT_SIZE);
1713 fmt.cs.font_size = TRUE;
1715 gtk_widget_grab_focus(GTK_WIDGET(priv->msg_body));
1716 wp_text_buffer_set_format(WP_TEXT_BUFFER(priv->text_buffer), &fmt);
1722 modest_msg_edit_window_undo (ModestMsgEditWindow *window)
1724 ModestMsgEditWindowPrivate *priv;
1726 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1727 priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
1729 wp_text_buffer_undo (WP_TEXT_BUFFER (priv->text_buffer));