+
+ModestMsgEditFormat
+modest_msg_edit_window_get_format (ModestMsgEditWindow *self)
+{
+ gboolean rich_text;
+ ModestMsgEditWindowPrivate *priv = NULL;
+ g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self), MODEST_MSG_EDIT_FORMAT_HTML);
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
+
+ rich_text = wp_text_buffer_is_rich_text (WP_TEXT_BUFFER (priv->text_buffer));
+ if (rich_text)
+ return MODEST_MSG_EDIT_FORMAT_HTML;
+ else
+ return MODEST_MSG_EDIT_FORMAT_TEXT;
+}
+
+void
+modest_msg_edit_window_set_format (ModestMsgEditWindow *self,
+ ModestMsgEditFormat format)
+{
+ ModestMsgEditWindowPrivate *priv;
+
+ g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self));
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
+
+ switch (format) {
+ case MODEST_MSG_EDIT_FORMAT_HTML:
+ wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
+ break;
+ case MODEST_MSG_EDIT_FORMAT_TEXT:
+ wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
+ break;
+ default:
+ g_return_if_reached ();
+ }
+}
+
+ModestMsgEditFormatState *
+modest_msg_edit_window_get_format_state (ModestMsgEditWindow *self)
+{
+ ModestMsgEditFormatState *format_state = NULL;
+ ModestMsgEditWindowPrivate *priv;
+ WPTextBufferFormat *buffer_format = g_new0 (WPTextBufferFormat, 1);
+
+ g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self), NULL);
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
+
+ wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), buffer_format, TRUE);
+
+ format_state = g_new0 (ModestMsgEditFormatState, 1);
+ format_state->bold = buffer_format->bold&0x1;
+ format_state->italics = buffer_format->italic&0x1;
+ format_state->bullet = buffer_format->bullet&0x1;
+ format_state->color = buffer_format->color;
+ format_state->font_size = buffer_format->font_size;
+ format_state->font_family = wp_get_font_name (buffer_format->font);
+ format_state->justification = buffer_format->justification;
+ g_free (buffer_format);
+
+ return format_state;
+
+}
+
+void
+modest_msg_edit_window_set_format_state (ModestMsgEditWindow *self,
+ const ModestMsgEditFormatState *format_state)
+{
+ ModestMsgEditWindowPrivate *priv;
+ WPTextBufferFormat *buffer_format = g_new0 (WPTextBufferFormat, 1);
+ WPTextBufferFormat *current_format = g_new0 (WPTextBufferFormat, 1);
+ g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self));
+ g_return_if_fail (format_state != NULL);
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
+ gtk_widget_grab_focus (priv->msg_body);
+ buffer_format->bold = (format_state->bold != FALSE);
+ buffer_format->italic = (format_state->italics != FALSE);
+ buffer_format->color = format_state->color;
+ buffer_format->font_size = format_state->font_size;
+ buffer_format->font = wp_get_font_index (format_state->font_family, 0);
+ buffer_format->justification = format_state->justification;
+ buffer_format->bullet = format_state->bullet;
+
+ wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), current_format, TRUE);
+
+ buffer_format->cs.bold = ((buffer_format->bold&0x1) != (current_format->bold&0x1));
+ buffer_format->cs.italic = ((buffer_format->italic&0x1) != (current_format->italic&0x1));
+ buffer_format->cs.color = gdk_color_equal(&(buffer_format->color), &(current_format->color));
+ buffer_format->cs.font_size = (buffer_format->font_size != current_format->font_size);
+ buffer_format->cs.font = (buffer_format->font != current_format->font);
+ buffer_format->cs.justification = (buffer_format->justification != current_format->justification);
+ buffer_format->cs.bullet = (buffer_format->bullet != current_format->bullet);
+
+ wp_text_buffer_freeze (WP_TEXT_BUFFER (priv->text_buffer));
+ if (buffer_format->cs.bold) {
+ wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BOLD, (gpointer) (buffer_format->bold&0x1));
+ }
+ if (buffer_format->cs.italic) {
+ wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_ITALIC, (gpointer) (buffer_format->italic&0x1));
+ }
+ if (buffer_format->cs.color) {
+ wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR, (gpointer) (&(buffer_format->color)));
+ }
+ if (buffer_format->cs.font_size) {
+ wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BOLD, (gpointer) (buffer_format->font_size));
+ }
+ if (buffer_format->cs.justification) {
+ switch (buffer_format->justification) {
+ case GTK_JUSTIFY_LEFT:
+ wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_LEFT, (gpointer) TRUE);
+ break;
+ case GTK_JUSTIFY_CENTER:
+ wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_CENTER, (gpointer) TRUE);
+ break;
+ case GTK_JUSTIFY_RIGHT:
+ wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_RIGHT, (gpointer) TRUE);
+ break;
+ default:
+ break;
+ }
+
+ }
+ if (buffer_format->cs.font) {
+ wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BOLD, (gpointer) (buffer_format->font));
+ }
+ if (buffer_format->cs.bullet) {
+ wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BULLET, (gpointer) (buffer_format->bullet));
+ }
+/* wp_text_buffer_set_format (WP_TEXT_BUFFER (priv->text_buffer), buffer_format); */
+ wp_text_buffer_thaw (WP_TEXT_BUFFER (priv->text_buffer));
+
+ g_free (current_format);
+
+}
+
+static void
+toggle_action_set_active_block_notify (GtkToggleAction *action,
+ gboolean value)
+{
+ GSList *proxies = NULL;
+
+ for (proxies = gtk_action_get_proxies (GTK_ACTION (action));
+ proxies != NULL; proxies = g_slist_next (proxies)) {
+ GtkWidget *widget = (GtkWidget *) proxies->data;
+ gtk_action_block_activate_from (GTK_ACTION (action), widget);
+ }
+
+ gtk_toggle_action_set_active (action, value);
+
+ for (proxies = gtk_action_get_proxies (GTK_ACTION (action));
+ proxies != NULL; proxies = g_slist_next (proxies)) {
+ GtkWidget *widget = (GtkWidget *) proxies->data;
+ gtk_action_unblock_activate_from (GTK_ACTION (action), widget);
+ }
+}
+
+static void
+text_buffer_refresh_attributes (WPTextBuffer *buffer, ModestMsgEditWindow *window)
+{
+ WPTextBufferFormat *buffer_format = g_new0 (WPTextBufferFormat, 1);
+ GtkAction *action;
+ ModestWindowPrivate *parent_priv;
+ ModestMsgEditWindowPrivate *priv;
+ GtkWidget *new_size_menuitem;
+ GtkWidget *new_font_menuitem;
+
+ parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+ if (wp_text_buffer_is_rich_text (WP_TEXT_BUFFER (priv->text_buffer))) {
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/FileFormatMenu/FileFormatFormattedTextMenu");
+ if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
+ toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), TRUE);
+ } else {
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/FileFormatMenu/FileFormatPlainTextMenu");
+ if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
+ toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), TRUE);
+ }
+
+ wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), buffer_format, FALSE);
+
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ActionsBold");
+ toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), buffer_format->bold);
+
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ActionsItalics");
+ toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), buffer_format->italic);
+
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/BulletedListMenu");
+ toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), buffer_format->bullet);
+
+ g_signal_handlers_block_by_func (G_OBJECT (priv->font_color_button),
+ G_CALLBACK (modest_msg_edit_window_color_button_change),
+ window);
+ hildon_color_button_set_color (HILDON_COLOR_BUTTON (priv->font_color_button), & (buffer_format->color));
+ g_signal_handlers_unblock_by_func (G_OBJECT (priv->font_color_button),
+ G_CALLBACK (modest_msg_edit_window_color_button_change),
+ window);
+
+ new_size_menuitem = GTK_WIDGET ((g_slist_nth (priv->size_items_group,
+ buffer_format->font_size))->data);
+ if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (new_size_menuitem))) {
+ GtkWidget *label;
+ gchar *markup;
+
+ label = gtk_bin_get_child (GTK_BIN (new_size_menuitem));
+ markup = g_strconcat ("<span font_family='Serif'>", gtk_label_get_text (GTK_LABEL (label)), "</span>", NULL);
+ gtk_label_set_markup (GTK_LABEL (priv->size_tool_button_label), markup);
+ g_free (markup);
+ g_signal_handlers_block_by_func (G_OBJECT (new_size_menuitem),
+ G_CALLBACK (modest_msg_edit_window_size_change),
+ window);
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (new_size_menuitem), TRUE);
+ g_signal_handlers_unblock_by_func (G_OBJECT (new_size_menuitem),
+ G_CALLBACK (modest_msg_edit_window_size_change),
+ window);
+ }
+
+ new_font_menuitem = GTK_WIDGET ((g_slist_nth (priv->font_items_group,
+ buffer_format->font))->data);
+ if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (new_font_menuitem))) {
+ GtkWidget *label;
+ gchar *markup;
+
+ label = gtk_bin_get_child (GTK_BIN (new_font_menuitem));
+ markup = g_strconcat ("<span font_family='", gtk_label_get_text (GTK_LABEL (label)),"'>Tt</span>", NULL);
+ gtk_label_set_markup (GTK_LABEL (priv->font_tool_button_label), markup);
+ g_free (markup);
+ g_signal_handlers_block_by_func (G_OBJECT (new_font_menuitem),
+ G_CALLBACK (modest_msg_edit_window_font_change),
+ window);
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (new_font_menuitem), TRUE);
+ g_signal_handlers_unblock_by_func (G_OBJECT (new_font_menuitem),
+ G_CALLBACK (modest_msg_edit_window_font_change),
+ window);
+ }
+
+ g_free (buffer_format);
+
+}
+
+
+void
+modest_msg_edit_window_select_color (ModestMsgEditWindow *window)
+{
+
+ WPTextBufferFormat *buffer_format = g_new0 (WPTextBufferFormat, 1);
+ ModestMsgEditWindowPrivate *priv;
+ GtkWidget *dialog = NULL;
+ gint response;
+ const GdkColor *new_color = NULL;
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+ wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), buffer_format, FALSE);
+
+#ifdef MODEST_HILDON_VERSION_0
+ dialog = hildon_color_selector_new (GTK_WINDOW (window));
+ hildon_color_selector_set_color (HILDON_COLOR_SELECTOR (dialog), &(buffer_format->color));
+#else
+ dialog = hildon_color_chooser_new ();
+ hildon_color_chooser_set_color (HILDON_COLOR_CHOOSER (dialog), &(buffer_format->color));
+#endif /*MODEST_HILDON_VERSION_0*/
+ g_free (buffer_format);
+
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+ switch (response) {
+ case GTK_RESPONSE_OK: {
+#ifdef MODEST_HILDON_VERSION_0
+ new_color = hildon_color_selector_get_color (HILDON_COLOR_SELECTOR (dialog));
+#else
+ GdkColor col;
+ hildon_color_chooser_get_color (HILDON_COLOR_CHOOSER(dialog), &col);
+ new_color = &col;
+#endif /*MODEST_HILDON_VERSION_0*/
+ }
+
+ break;
+ default:
+ break;
+ }
+ gtk_widget_destroy (dialog);
+
+ if (new_color != NULL)
+ wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR, (gpointer) new_color);
+
+}
+
+void
+modest_msg_edit_window_select_background_color (ModestMsgEditWindow *window)
+{
+
+ ModestMsgEditWindowPrivate *priv;
+ GtkWidget *dialog = NULL;
+ gint response;
+ GdkColor *old_color = NULL;
+ const GdkColor *new_color = NULL;
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+ old_color = (GdkColor*)wp_text_buffer_get_background_color (WP_TEXT_BUFFER (priv->text_buffer));
+
+#ifdef MODEST_HILDON_VERSION_0
+ dialog = hildon_color_selector_new (GTK_WINDOW (window));
+ hildon_color_selector_set_color (HILDON_COLOR_SELECTOR (dialog),(GdkColor*)old_color);
+#else
+ dialog = hildon_color_chooser_new ();
+ hildon_color_chooser_set_color (HILDON_COLOR_CHOOSER (dialog),(GdkColor*)old_color);
+#endif /*MODEST_HILDON_VERSION_9*/
+
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+ switch (response) {
+ case GTK_RESPONSE_OK: {
+#ifdef MODEST_HILDON_VERSION_0
+ new_color = hildon_color_selector_get_color (HILDON_COLOR_SELECTOR (dialog));
+#else
+ GdkColor col;
+ hildon_color_chooser_get_color (HILDON_COLOR_CHOOSER(dialog), &col);
+ new_color = &col;
+#endif /*MODEST_HILDON_VERSION_0*/
+ }
+ break;
+ default:
+ break;
+ }
+ gtk_widget_destroy (dialog);
+
+ if (new_color != NULL)
+ wp_text_buffer_set_background_color (WP_TEXT_BUFFER (priv->text_buffer), new_color);
+
+}
+
+void
+modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
+{
+
+ ModestMsgEditWindowPrivate *priv;
+ GtkWidget *dialog = NULL;
+ gint response = 0;
+ gchar *filename = NULL;
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+ dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (window), GTK_FILE_CHOOSER_ACTION_OPEN);
+
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+ switch (response) {
+ case GTK_RESPONSE_OK:
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ break;
+ default:
+ break;
+ }
+ gtk_widget_destroy (dialog);
+
+ if (filename) {
+ GdkPixbuf *pixbuf = NULL;
+ GtkTextIter position;
+ GtkTextMark *insert_mark;
+
+ pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
+ if (pixbuf) {
+ gint image_file_id;
+ GdkPixbufFormat *pixbuf_format;
+
+ image_file_id = g_open (filename, O_RDONLY, 0);
+ pixbuf_format = gdk_pixbuf_get_file_info (filename, NULL, NULL);
+ if ((image_file_id != -1)&&(pixbuf_format != NULL)) {
+ TnyMimePart *image_part;
+ TnyStream *image_stream;
+ gchar **mime_types;
+ gchar *mime_type;
+ gchar *basename;
+ gchar *content_id;
+
+ mime_types = gdk_pixbuf_format_get_mime_types (pixbuf_format);
+ if ((mime_types != NULL) && (mime_types[0] != NULL)) {
+ mime_type = mime_types[0];
+ } else {
+ mime_type = "image/unknown";
+ }
+ image_part = tny_platform_factory_new_mime_part
+ (modest_runtime_get_platform_factory ());
+ image_stream = TNY_STREAM (tny_fs_stream_new (image_file_id));
+
+ tny_mime_part_construct_from_stream (image_part, image_stream, mime_type);
+ g_strfreev (mime_types);
+
+ content_id = g_strdup_printf ("%d", priv->last_cid);
+ tny_mime_part_set_content_id (image_part, content_id);
+ g_free (content_id);
+ priv->last_cid++;
+
+ basename = g_path_get_basename (filename);
+ tny_mime_part_set_filename (image_part, basename);
+ g_free (basename);
+
+ insert_mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (priv->text_buffer));
+ gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (priv->text_buffer), &position, insert_mark);
+ wp_text_buffer_insert_image (WP_TEXT_BUFFER (priv->text_buffer), &position, g_strdup (tny_mime_part_get_content_id (image_part)), pixbuf);
+ priv->attachments = g_list_prepend (priv->attachments, image_part);
+ modest_attachments_view_add_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
+ image_part);
+ gtk_widget_set_no_show_all (priv->attachments_caption, FALSE);
+ gtk_widget_show_all (priv->attachments_caption);
+ } else if (image_file_id == -1) {
+ close (image_file_id);
+ }
+ }
+ }
+
+
+}
+
+static void
+modest_msg_edit_window_color_button_change (ModestMsgEditWindow *window,
+ gpointer userdata)
+{
+ ModestMsgEditWindowPrivate *priv;
+ GdkColor *new_color;
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+#ifdef MODEST_HILDON_VERSION_0
+ new_color = hildon_color_button_get_color (HILDON_COLOR_BUTTON (priv->font_color_button));
+#else
+ GdkColor col;
+ hildon_color_button_get_color (HILDON_COLOR_BUTTON(priv->font_color_button), &col);
+ new_color = &col;
+#endif /*MODEST_HILDON_VERSION_0*/
+
+ wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR, (gpointer) new_color);
+
+ gtk_window_set_focus (GTK_WINDOW (window), priv->msg_body);
+
+}
+
+static void
+modest_msg_edit_window_size_change (GtkCheckMenuItem *menu_item,
+ gpointer userdata)
+{
+ ModestMsgEditWindowPrivate *priv;
+ gint new_size_index;
+ ModestMsgEditWindow *window;
+ GtkWidget *label;
+
+ window = MODEST_MSG_EDIT_WINDOW (userdata);
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+ gtk_widget_grab_focus (GTK_WIDGET (priv->msg_body));
+
+ if (gtk_check_menu_item_get_active (menu_item)) {
+ gchar *markup;
+
+ label = gtk_bin_get_child (GTK_BIN (menu_item));
+
+ new_size_index = atoi (gtk_label_get_text (GTK_LABEL (label)));
+
+ if (!wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT_SIZE,
+ (gpointer) wp_get_font_size_index (new_size_index, 12)))
+ wp_text_view_reset_and_show_im (WP_TEXT_VIEW (priv->msg_body));
+
+ text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (window));
+ markup = g_strconcat ("<span font_family='Serif'>", gtk_label_get_text (GTK_LABEL (label)), "</span>", NULL);
+ gtk_label_set_markup (GTK_LABEL (priv->size_tool_button_label), markup);
+ g_free (markup);
+ }
+}
+
+static void
+modest_msg_edit_window_font_change (GtkCheckMenuItem *menu_item,
+ gpointer userdata)
+{
+ ModestMsgEditWindowPrivate *priv;
+ gint new_font_index;
+ ModestMsgEditWindow *window;
+ GtkWidget *label;
+
+ window = MODEST_MSG_EDIT_WINDOW (userdata);
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+ gtk_widget_grab_focus (GTK_WIDGET (priv->msg_body));
+
+ if (gtk_check_menu_item_get_active (menu_item)) {
+ gchar *markup;
+
+ label = gtk_bin_get_child (GTK_BIN (menu_item));
+
+ new_font_index = wp_get_font_index (gtk_label_get_text (GTK_LABEL (label)), DEFAULT_FONT);
+
+ if (!wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT,
+ (gpointer) new_font_index))
+ wp_text_view_reset_and_show_im (WP_TEXT_VIEW (priv->msg_body));
+
+ text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (window));
+ markup = g_strconcat ("<span font_family='",gtk_label_get_text (GTK_LABEL (label)),"'>Tt</span>", NULL);
+ gtk_label_set_markup (GTK_LABEL (priv->font_tool_button_label), markup);
+ g_free (markup);
+ }
+}
+
+static void
+modest_msg_edit_window_set_zoom (ModestWindow *window,
+ gdouble zoom)
+{
+ ModestMsgEditWindowPrivate *priv;
+
+ g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+ priv->zoom_level = zoom;
+ wp_text_buffer_set_font_scaling_factor (WP_TEXT_BUFFER (priv->text_buffer), zoom);
+}
+
+static gdouble
+modest_msg_edit_window_get_zoom (ModestWindow *window)
+{
+ ModestMsgEditWindowPrivate *priv;
+
+ g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window), 1.0);
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+ return priv->zoom_level;
+}
+
+static gboolean
+modest_msg_edit_window_zoom_plus (ModestWindow *window)
+{
+ ModestWindowPrivate *parent_priv;
+ GtkRadioAction *zoom_radio_action;
+ GSList *group, *node;
+
+ parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+ zoom_radio_action = GTK_RADIO_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager,
+ "/MenuBar/ViewMenu/ZoomMenu/Zoom50Menu"));
+
+ group = gtk_radio_action_get_group (zoom_radio_action);
+
+ if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (group->data))) {
+ hildon_banner_show_information (NULL, NULL, _("mcen_ib_max_zoom_level"));
+ return FALSE;
+ }
+
+ for (node = group; node != NULL; node = g_slist_next (node)) {
+ if ((node->next != NULL) && gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (node->next->data))) {
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (node->data), TRUE);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+static gboolean
+modest_msg_edit_window_zoom_minus (ModestWindow *window)
+{
+ ModestWindowPrivate *parent_priv;
+ GtkRadioAction *zoom_radio_action;
+ GSList *group, *node;
+
+ parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+ zoom_radio_action = GTK_RADIO_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager,
+ "/MenuBar/ViewMenu/ZoomMenu/Zoom50Menu"));
+
+ group = gtk_radio_action_get_group (zoom_radio_action);
+
+ for (node = group; node != NULL; node = g_slist_next (node)) {
+ if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (node->data))) {
+ if (node->next != NULL) {
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (node->next->data), TRUE);
+ return TRUE;
+ } else
+ hildon_banner_show_information (NULL, NULL, _("mcen_ib_min_zoom_level"));
+ break;
+ }
+ }
+ return FALSE;
+}
+
+static gboolean
+modest_msg_edit_window_window_state_event (GtkWidget *widget, GdkEventWindowState *event, gpointer userdata)
+{
+ if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) {
+ ModestWindowPrivate *parent_priv;
+ ModestWindowMgr *mgr;
+ gboolean is_fullscreen;
+ GtkAction *fs_toggle_action;
+ gboolean active;
+
+ mgr = modest_runtime_get_window_mgr ();
+ is_fullscreen = (modest_window_mgr_get_fullscreen_mode (mgr))?1:0;
+
+ parent_priv = MODEST_WINDOW_GET_PRIVATE (widget);
+
+ fs_toggle_action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewToggleFullscreenMenu");
+ active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (fs_toggle_action)))?1:0;
+ if (is_fullscreen != active)
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (fs_toggle_action), is_fullscreen);
+ }
+
+ return FALSE;
+
+}
+
+void
+modest_msg_edit_window_toggle_fullscreen (ModestMsgEditWindow *window)
+{
+ ModestWindowPrivate *parent_priv;
+ GtkAction *fs_toggle_action;
+ gboolean active;
+
+ parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+
+ fs_toggle_action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewToggleFullscreenMenu");
+ active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (fs_toggle_action));
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (fs_toggle_action), !active);
+}
+
+void
+modest_msg_edit_window_show_cc (ModestMsgEditWindow *window,
+ gboolean show)
+{
+ ModestMsgEditWindowPrivate *priv = NULL;
+ g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+ if (show)
+ gtk_widget_show (priv->cc_caption);
+ else
+ gtk_widget_hide (priv->cc_caption);
+}
+
+void
+modest_msg_edit_window_show_bcc (ModestMsgEditWindow *window,
+ gboolean show)
+{
+ ModestMsgEditWindowPrivate *priv = NULL;
+ g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+ if (show)
+ gtk_widget_show (priv->bcc_caption);
+ else
+ gtk_widget_hide (priv->bcc_caption);
+}
+
+static void
+modest_msg_edit_window_open_addressbook (ModestMsgEditWindow *window,
+ ModestRecptEditor *editor)
+{
+ ModestMsgEditWindowPrivate *priv;
+
+ g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
+ g_return_if_fail ((editor == NULL) || (MODEST_IS_RECPT_EDITOR (editor)));
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+ if (editor == NULL) {
+ GtkWidget *view_focus;
+ view_focus = gtk_window_get_focus (GTK_WINDOW (window));
+
+ /* This code should be kept in sync with ModestRecptEditor. The
+ textview inside the recpt editor is the one that really gets the
+ focus. As it's inside a scrolled window, and this one inside the
+ hbox recpt editor inherits from, we'll need to go up in the
+ hierarchy to know if the text view is part of the recpt editor
+ or if it's a different text entry */
+
+ if (gtk_widget_get_parent (view_focus)) {
+ GtkWidget *first_parent;
+
+ first_parent = gtk_widget_get_parent (view_focus);
+ if (gtk_widget_get_parent (first_parent) &&
+ MODEST_IS_RECPT_EDITOR (gtk_widget_get_parent (first_parent))) {
+ editor = MODEST_RECPT_EDITOR (gtk_widget_get_parent (first_parent));
+ }
+ }
+
+ if (editor == NULL)
+ editor = MODEST_RECPT_EDITOR (priv->to_field);
+
+ }
+
+ modest_address_book_select_addresses (editor);
+
+}
+
+void
+modest_msg_edit_window_select_contacts (ModestMsgEditWindow *window)
+{
+ g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
+
+ modest_msg_edit_window_open_addressbook (window, NULL);
+}
+
+static void
+modest_msg_edit_window_show_toolbar (ModestWindow *self,
+ gboolean show_toolbar)
+{
+ ModestWindowPrivate *parent_priv;
+
+ parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
+
+ /* FIXME: we can not just use the code of
+ modest_msg_edit_window_setup_toolbar because it has a
+ mixture of both initialization and creation code. */
+
+ if (show_toolbar)
+ gtk_widget_show (GTK_WIDGET (parent_priv->toolbar));
+ else
+ gtk_widget_hide (GTK_WIDGET (parent_priv->toolbar));
+}
+
+void
+modest_msg_edit_window_set_priority_flags (ModestMsgEditWindow *window,
+ TnyHeaderFlags priority_flags)
+{
+ ModestMsgEditWindowPrivate *priv;
+
+ g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+ priority_flags = priority_flags & (TNY_HEADER_FLAG_HIGH_PRIORITY);
+
+ if (priv->priority_flags != priority_flags) {
+
+ priv->priority_flags = priority_flags;
+
+ switch (priority_flags) {
+ case TNY_HEADER_FLAG_HIGH_PRIORITY:
+ gtk_image_set_from_icon_name (GTK_IMAGE (priv->priority_icon), "qgn_list_messaging_high", GTK_ICON_SIZE_MENU);
+ gtk_widget_show (priv->priority_icon);
+ break;
+ case TNY_HEADER_FLAG_LOW_PRIORITY:
+ gtk_image_set_from_icon_name (GTK_IMAGE (priv->priority_icon), "qgn_list_messaging_low", GTK_ICON_SIZE_MENU);
+ gtk_widget_show (priv->priority_icon);
+ break;
+ default:
+ gtk_widget_hide (priv->priority_icon);
+ break;
+ }
+ }
+}
+
+void
+modest_msg_edit_window_set_file_format (ModestMsgEditWindow *window,
+ gint file_format)
+{
+ ModestMsgEditWindowPrivate *priv;
+ gint current_format;
+
+ g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+ current_format = wp_text_buffer_is_rich_text (WP_TEXT_BUFFER (priv->text_buffer))
+ ? MODEST_FILE_FORMAT_FORMATTED_TEXT : MODEST_FILE_FORMAT_PLAIN_TEXT;
+
+ if (current_format != file_format) {
+ switch (file_format) {
+ case MODEST_FILE_FORMAT_FORMATTED_TEXT:
+ wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
+ break;
+ case MODEST_FILE_FORMAT_PLAIN_TEXT:
+ {
+ GtkWidget *dialog;
+ gint response;
+ dialog = hildon_note_new_confirmation (NULL, _("emev_nc_formatting_lost"));
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ if (response == GTK_RESPONSE_OK)
+ wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
+ }
+ break;
+ }
+ update_dimmed (window);
+ }
+}
+
+void
+modest_msg_edit_window_select_font (ModestMsgEditWindow *window)
+{
+ GtkWidget *dialog;
+ ModestMsgEditWindowPrivate *priv;
+ WPTextBufferFormat oldfmt, fmt;
+ gint old_position = 0;
+ gint response = 0;
+ gint position = 0;
+ gint font_size;
+ GdkColor *color = NULL;
+ gboolean bold, bold_set, italic, italic_set;
+ gboolean underline, underline_set;
+ gboolean strikethrough, strikethrough_set;
+ gboolean position_set;
+ gboolean font_size_set, font_set, color_set;
+ gchar *font_name;
+
+ g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+ dialog = hildon_font_selection_dialog_new (NULL, NULL);
+
+ /* First we get the currently selected font information */
+ wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), &oldfmt, TRUE);
+ g_object_set (G_OBJECT (dialog), "font-scaling", priv->zoom_level, NULL);
+
+ switch (oldfmt.text_position) {
+ case TEXT_POSITION_NORMAL:
+ old_position = 0;
+ break;
+ case TEXT_POSITION_SUPERSCRIPT:
+ old_position = 1;
+ break;
+ default:
+ old_position = -1;
+ break;
+ }
+
+ g_object_set (G_OBJECT (dialog),
+ "bold", oldfmt.bold != FALSE,
+ "bold-set", !oldfmt.cs.bold,
+ "underline", oldfmt.underline != FALSE,
+ "underline-set", !oldfmt.cs.underline,
+ "italic", oldfmt.italic != FALSE,
+ "italic-set", !oldfmt.cs.italic,
+ "strikethrough", oldfmt.strikethrough != FALSE,
+ "strikethrough-set", !oldfmt.cs.strikethrough,
+ "color", &oldfmt.color,
+ "color-set", !oldfmt.cs.color,
+ "size", wp_font_size[oldfmt.font_size],
+ "size-set", !oldfmt.cs.font_size,
+ "position", old_position,
+ "position-set", !oldfmt.cs.text_position,
+ "family", wp_get_font_name (oldfmt.font),
+ "family-set", !oldfmt.cs.font,
+ NULL);
+
+ gtk_widget_show_all (dialog);
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+ if (response == GTK_RESPONSE_OK) {
+
+ g_object_get( dialog,
+ "bold", &bold,
+ "bold-set", &bold_set,
+ "underline", &underline,
+ "underline-set", &underline_set,
+ "italic", &italic,
+ "italic-set", &italic_set,
+ "strikethrough", &strikethrough,
+ "strikethrough-set", &strikethrough_set,
+ "color", &color,
+ "color-set", &color_set,
+ "size", &font_size,
+ "size-set", &font_size_set,
+ "family", &font_name,
+ "family-set", &font_set,
+ "position", &position,
+ "position-set", &position_set,
+ NULL );
+
+ }
+
+ gtk_widget_destroy (dialog);
+
+ if (response == GTK_RESPONSE_OK) {
+ memset(&fmt, 0, sizeof(fmt));
+ if (bold_set) {
+ fmt.bold = bold;
+ fmt.cs.bold = TRUE;
+ }
+ if (italic_set) {
+ fmt.italic = italic;
+ fmt.cs.italic = TRUE;
+ }
+ if (underline_set) {
+ fmt.underline = underline;
+ fmt.cs.underline = TRUE;
+ }
+ if (strikethrough_set) {
+ fmt.strikethrough = strikethrough;
+ fmt.cs.strikethrough = TRUE;
+ }
+ if (position_set) {
+ fmt.text_position =
+ ( position == 0 )
+ ? TEXT_POSITION_NORMAL
+ : ( ( position == 1 )
+ ? TEXT_POSITION_SUPERSCRIPT
+ : TEXT_POSITION_SUBSCRIPT );
+ fmt.cs.text_position = TRUE;
+ }
+ if (color_set) {
+ fmt.color = *color;
+ fmt.cs.color = TRUE;
+ }
+ gdk_color_free(color);
+ if (font_set) {
+ fmt.font = wp_get_font_index(font_name,
+ DEFAULT_FONT);
+ fmt.cs.font = TRUE;
+ }
+ g_free(font_name);
+ if (font_size_set) {
+ fmt.font_size = wp_get_font_size_index(
+ font_size, DEFAULT_FONT_SIZE);
+ fmt.cs.font_size = TRUE;
+ }
+ gtk_widget_grab_focus(GTK_WIDGET(priv->msg_body));
+ wp_text_buffer_set_format(WP_TEXT_BUFFER(priv->text_buffer), &fmt);
+ }
+
+}
+
+void
+modest_msg_edit_window_undo (ModestMsgEditWindow *window)
+{
+ ModestMsgEditWindowPrivate *priv;
+
+ g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+ wp_text_buffer_undo (WP_TEXT_BUFFER (priv->text_buffer));
+
+ update_dimmed (window);
+
+}
+
+static void
+update_dimmed (ModestMsgEditWindow *window)
+{
+ ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+ ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+ GtkAction *action;
+ GtkWidget *widget;
+ gboolean rich_text;
+ gboolean editor_focused;
+
+ rich_text = wp_text_buffer_is_rich_text (WP_TEXT_BUFFER (priv->text_buffer));
+ editor_focused = gtk_widget_is_focus (priv->msg_body);
+
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/SelectFontMenu");
+ gtk_action_set_sensitive (action, rich_text && editor_focused);
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/BulletedListMenu");
+ gtk_action_set_sensitive (action, rich_text && editor_focused);
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu");
+ gtk_action_set_sensitive (action, rich_text && editor_focused);
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu/AlignmentLeftMenu");
+ gtk_action_set_sensitive (action, rich_text && editor_focused);
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu/AlignmentCenterMenu");
+ gtk_action_set_sensitive (action, rich_text && editor_focused);
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu/AlignmentRightMenu");
+ gtk_action_set_sensitive (action, rich_text && editor_focused);
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/AttachmentsMenu/InsertImageMenu");
+ gtk_action_set_sensitive (action, rich_text && editor_focused);
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ActionsBold");
+ gtk_action_set_sensitive (action, rich_text && editor_focused);
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ActionsItalics");
+ gtk_action_set_sensitive (action, rich_text && editor_focused);
+ widget = priv->font_color_button;
+ gtk_widget_set_sensitive (widget, rich_text && editor_focused);
+ widget = priv->font_size_toolitem;
+ gtk_widget_set_sensitive (widget, rich_text && editor_focused);
+ widget = priv->font_face_toolitem;
+ gtk_widget_set_sensitive (widget, rich_text && editor_focused);
+}
+
+static void
+setup_insensitive_handlers (ModestMsgEditWindow *window)
+{
+ ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+ ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+ GtkWidget *widget;
+
+ widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/ToolbarSend");
+ g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (send_insensitive_press), window);
+ widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar/EmailMenu/SendMenu");
+ g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (send_insensitive_press), window);
+
+ widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar/FormatMenu/SelectFontMenu");
+ g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
+ widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar/FormatMenu/BulletedListMenu");
+ g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
+ widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu");
+ g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
+ widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu/AlignmentLeftMenu");
+ g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
+ widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu/AlignmentCenterMenu");
+ g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
+ widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu/AlignmentRightMenu");
+ g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
+ widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar/AttachmentsMenu/InsertImageMenu");
+ g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
+ widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/ActionsBold");
+ g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
+ widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/ActionsItalics");
+ g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
+ widget = priv->font_color_button;
+ g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
+ widget = priv->font_size_toolitem;
+ g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
+ widget = priv->font_face_toolitem;
+ g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
+
+}
+
+static void
+text_buffer_can_undo (GtkTextBuffer *buffer, gboolean can_undo, ModestMsgEditWindow *window)
+{
+ ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+ GtkAction *action;
+
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/UndoMenu");
+ gtk_action_set_sensitive (action, can_undo);
+}
+
+static gboolean
+msg_body_focus (GtkWidget *focus,
+ GdkEventFocus *event,
+ gpointer userdata)
+{
+ update_dimmed (MODEST_MSG_EDIT_WINDOW (userdata));
+ return FALSE;
+}
+
+static void
+to_field_changed (GtkTextBuffer *buffer,
+ ModestMsgEditWindow *editor)
+{
+ ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (editor);
+ GtkAction *action;
+
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ToolbarSend");
+ gtk_action_set_sensitive (action, gtk_text_buffer_get_char_count (buffer) != 0);
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EmailMenu/SendMenu");
+ gtk_action_set_sensitive (action, gtk_text_buffer_get_char_count (buffer) != 0);
+}
+
+static void
+send_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor)
+{
+ hildon_banner_show_information (NULL, NULL, _("mcen_ib_add_recipients_first"));
+}
+
+static void
+style_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor)
+{
+ gboolean rich_text, editor_focused;
+
+ ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (editor);
+ rich_text = wp_text_buffer_is_rich_text (WP_TEXT_BUFFER (priv->text_buffer));
+ editor_focused = gtk_widget_is_focus (priv->msg_body);
+
+ if (!rich_text)
+ hildon_banner_show_information (NULL, NULL, _("mcen_ib_item_unavailable_plaintext"));
+ else if (!editor_focused)
+ hildon_banner_show_information (NULL, NULL, _("mcen_ib_move_cursor_to_message"));
+}
+
+static void
+reset_modified (ModestMsgEditWindow *editor)
+{
+ ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (editor);
+ GtkTextBuffer *buffer;
+
+ buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR(priv->to_field));
+ gtk_text_buffer_set_modified (buffer, FALSE);
+ buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR(priv->cc_field));
+ gtk_text_buffer_set_modified (buffer, FALSE);
+ buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR(priv->bcc_field));
+ gtk_text_buffer_set_modified (buffer, FALSE);
+ gtk_text_buffer_set_modified (priv->text_buffer, FALSE);
+}
+
+static gboolean
+is_modified (ModestMsgEditWindow *editor)
+{
+ ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (editor);
+ GtkTextBuffer *buffer;
+
+ buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR(priv->to_field));
+ if (gtk_text_buffer_get_modified (buffer))
+ return TRUE;
+ buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR(priv->cc_field));
+ if (gtk_text_buffer_get_modified (buffer))
+ return TRUE;
+ buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR(priv->bcc_field));
+ if (gtk_text_buffer_get_modified (buffer))
+ return TRUE;
+ if (gtk_text_buffer_get_modified (priv->text_buffer))
+ return TRUE;
+
+ return FALSE;
+}
+
+gboolean
+modest_msg_edit_window_check_names (ModestMsgEditWindow *window)
+{
+ ModestMsgEditWindowPrivate *priv = NULL;
+
+ g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window), FALSE);
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+ /* check if there's no recipient added */
+ if ((gtk_text_buffer_get_char_count (modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->to_field))) == 0) &&
+ (gtk_text_buffer_get_char_count (modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->cc_field))) == 0) &&
+ (gtk_text_buffer_get_char_count (modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->bcc_field))) == 0)) {
+ /* no recipient contents, then select contacts */
+ modest_msg_edit_window_open_addressbook (window, NULL);
+ return FALSE;
+ }
+
+ if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->to_field)))
+ return FALSE;
+ if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->cc_field)))
+ return FALSE;
+ if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->bcc_field)))
+ return FALSE;
+
+ modest_recpt_editor_grab_focus (MODEST_RECPT_EDITOR (priv->to_field));
+
+ return TRUE;
+
+}