* src/modest-tny-msg.[ch]:
authorJose Dapena Paz <jdapena@igalia.com>
Mon, 30 Jul 2007 11:15:49 +0000 (11:15 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Mon, 30 Jul 2007 11:15:49 +0000 (11:15 +0000)
        * Now modest_tny_msg_get_body tells if the original body was
          plain text or html.
* src/widgets/modest-msg-edit-window.h:
        * Now modest_msg_edit_window_new gets a new parameter
          preserve_is_rich, that sets the format to the one in the
          original message in case it's set.
* src/maemo/modest-msg-edit-window.c:
        * Preserves the plain text format in case it's requested
          (fixes NB#64170).
        * Now we reset modified status on constructor to prevent getting
          modifications from construction process.
* src/modest-ui-actions.c:
        * Use the new modest_msg_edit_window_new api. For messages
          opened from drafts, it preserves the format (plain or html).
          For other messages, it respects the configuration preference.
* src/gnome/modest-msg-edit-window.c:
        * Fill the new is_html parameter in modest_tny_msg_new method.

pmo-trunk-r2846

src/dbus_api/modest-dbus-callbacks.c
src/gnome/modest-msg-edit-window.c
src/maemo/modest-msg-edit-window.c
src/modest-tny-msg.c
src/modest-tny-msg.h
src/modest-ui-actions.c
src/widgets/modest-msg-edit-window.h

index 6ab191d..c90efe0 100644 (file)
@@ -261,7 +261,7 @@ on_idle_mail_to(gpointer user_data)
                                        tny_folder_add_msg (folder, msg, NULL); /* TODO: check err */
                                        gdk_threads_enter ();
 
-                                       ModestWindow *win = modest_msg_edit_window_new (msg, account_name);
+                                       ModestWindow *win = modest_msg_edit_window_new (msg, account_name, FALSE);
                                        modest_window_mgr_register_window (modest_runtime_get_window_mgr (), win);
                                        gtk_widget_show_all (GTK_WIDGET (win));
 
@@ -366,7 +366,7 @@ on_idle_compose_mail(gpointer user_data)
 
                                        gdk_threads_enter ();
        
-                                       ModestWindow *win = modest_msg_edit_window_new (msg, account_name);
+                                       ModestWindow *win = modest_msg_edit_window_new (msg, account_name, FALSE);
 
                                        /* it seems Sketch at least sends a leading ',' -- take that into account,
                                         * ie strip that ,*/
@@ -596,7 +596,7 @@ on_idle_open_message (gpointer user_data)
                if (is_draft) {
                        /* TODO: Maybe the msg_uid should be registered for edit windows too,
                         * so we can open the same window again next time: */
-                       msg_view = modest_msg_edit_window_new (msg, modest_account_name);
+                       msg_view = modest_msg_edit_window_new (msg, modest_account_name, TRUE);
                } else {
                        msg_view = modest_msg_view_window_new (msg, modest_account_name,
                                                       msg_uid);
index f14113b..95cf505 100644 (file)
@@ -314,7 +314,7 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg)
 
        
        buf  = gtk_text_view_get_buffer (GTK_TEXT_VIEW(priv->msg_body));
-       body = modest_tny_msg_get_body (msg, FALSE);
+       body = modest_tny_msg_get_body (msg, FALSE, NULL);
        if (body) 
                gtk_text_buffer_set_text (buf, body, -1);
        g_free (body);
index fc777c2..c4ba604 100644 (file)
@@ -702,7 +702,7 @@ update_last_cid (ModestMsgEditWindow *self, GList *attachments)
 }
 
 static void
-set_msg (ModestMsgEditWindow *self, TnyMsg *msg)
+set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
 {
        TnyHeader *header;
        const gchar *to, *cc, *bcc, *subject;
@@ -711,6 +711,7 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg)
        GtkTextIter iter;
        TnyHeaderFlags priority_flags;
        TnyFolder *msg_folder;
+       gboolean is_html = FALSE;
        
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self));
        g_return_if_fail (TNY_IS_MSG (msg));
@@ -750,11 +751,12 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg)
        update_window_title (self);
 
        wp_text_buffer_reset_buffer (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
-       body = modest_tny_msg_get_body (msg, TRUE);
+       body = modest_tny_msg_get_body (msg, TRUE, &is_html);
 
        if ((body == NULL)||(body[0] == '\0')) {
                g_free (body);
                body = modest_text_utils_convert_to_html ("");
+               is_html = FALSE;
        }
        wp_text_buffer_load_document_begin (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
        wp_text_buffer_load_document_write (WP_TEXT_BUFFER (priv->text_buffer),
@@ -763,8 +765,10 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg)
        wp_text_buffer_load_document_end (WP_TEXT_BUFFER (priv->text_buffer));
        g_free (body);
 
+       if (preserve_is_rich && !is_html) {
+               wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
        /* Get the default format required from configuration */
-       if (!modest_conf_get_bool (modest_runtime_get_conf (), MODEST_CONF_PREFER_FORMATTED_TEXT, NULL)) {
+       } else if (!modest_conf_get_bool (modest_runtime_get_conf (), MODEST_CONF_PREFER_FORMATTED_TEXT, NULL)) {
                wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
        }
 
@@ -1000,7 +1004,7 @@ modest_msg_edit_window_setup_toolbar (ModestMsgEditWindow *window)
 
 
 ModestWindow*
-modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name)
+modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean preserve_is_rich)
 {
        GObject *obj;
        ModestWindowPrivate *parent_priv;
@@ -1094,7 +1098,7 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name)
        if (account_pair != NULL)
                modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->from_field), account_pair->first);
 
-       set_msg (MODEST_MSG_EDIT_WINDOW (obj), msg);
+       set_msg (MODEST_MSG_EDIT_WINDOW (obj), msg, preserve_is_rich);
 
        text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (obj));
 
@@ -1142,6 +1146,8 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name)
 
        update_paste_dimming (MODEST_MSG_EDIT_WINDOW (obj));
        priv->update_caption_visibility = TRUE;
+
+       reset_modified (MODEST_MSG_EDIT_WINDOW (obj));
        
        return (ModestWindow*) obj;
 }
index a9b7cbf..73df2d0 100644 (file)
@@ -274,13 +274,14 @@ add_attachments (TnyMsg *msg, GList *attachments_list)
 
 
 gchar * 
-modest_tny_msg_get_body (TnyMsg *msg, gboolean want_html)
+modest_tny_msg_get_body (TnyMsg *msg, gboolean want_html, gboolean *is_html)
 {
        TnyStream *stream;
        TnyMimePart *body;
        GtkTextBuffer *buf;
        GtkTextIter start, end;
        gchar *to_quote;
+       gboolean result_was_html = TRUE;
 
        body = modest_tny_msg_find_body_part(msg, want_html);
        if (!body)
@@ -298,12 +299,16 @@ modest_tny_msg_get_body (TnyMsg *msg, gboolean want_html)
                gchar *to_quote_converted = modest_text_utils_convert_to_html (to_quote);
                g_free (to_quote);
                to_quote = to_quote_converted;
+               result_was_html = FALSE;
        }
 
        g_object_unref (buf);
        g_object_unref (G_OBJECT(stream));
        g_object_unref (G_OBJECT(body));
 
+       if (is_html != NULL)
+               *is_html = result_was_html;
+
        return to_quote;
 }
 
index f43b9b5..14133b5 100644 (file)
@@ -116,6 +116,7 @@ TnyMimePart*  modest_tny_msg_find_body_part  (TnyMsg * self, gboolean want_html)
  * modest_tny_msg_find_body:
  * @self: 
  * @want_html: 
+ * @is_html: if the original body was html or plain text
  * 
  * gets the body of a message as text, if @want_html is true, try HTML mail
  * first.
@@ -123,7 +124,7 @@ TnyMimePart*  modest_tny_msg_find_body_part  (TnyMsg * self, gboolean want_html)
  * Returns: the body of the message as text, or NULL if it is not found
  * the text should be freed with 
  **/
-gchar*        modest_tny_msg_get_body        (TnyMsg *self, gboolean want_html);
+gchar*        modest_tny_msg_get_body        (TnyMsg *self, gboolean want_html, gboolean *is_html);
 
 
 /**
index 65ee0c5..7d397c5 100644 (file)
@@ -684,7 +684,7 @@ modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
 
        /* Create and register edit window */
        /* This is destroyed by TOOD. */
-       msg_win = modest_msg_edit_window_new (msg, account_name);
+       msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
        mgr = modest_runtime_get_window_mgr ();
        modest_window_mgr_register_window (mgr, msg_win);
 
@@ -772,7 +772,7 @@ open_msg_cb (ModestMailOperation *mail_op,
                        run_account_setup_wizard(parent_win);
                        goto cleanup;
                }
-               win = modest_msg_edit_window_new (msg, account);
+               win = modest_msg_edit_window_new (msg, account, TRUE);
                
        } else {
                gchar *uid = modest_tny_folder_get_header_unique_id (header);
@@ -1079,7 +1079,7 @@ reply_forward_cb (ModestMailOperation *mail_op,
        }
 
        /* Create and register the windows */
-       msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name);
+       msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
        mgr = modest_runtime_get_window_mgr ();
        modest_window_mgr_register_window (mgr, msg_win);
 
index bdc8d4a..6e28271 100644 (file)
@@ -104,14 +104,17 @@ GType        modest_msg_edit_window_get_type    (void) G_GNUC_CONST;
 
 /**
  * modest_msg_edit_window_new:
- * #msg: a #TnyMsg instance
- * #account_name: the account this message applies to
+ * @msg: a #TnyMsg instance
+ * @account_name: the account this message applies to
+ * @preserve_is_rich: if @msg is not rich, open the message as plain text
  * 
  * instantiates a new #ModestMsgEditWindow widget
  *
  * Returns: a new #ModestMsgEditWindow, or NULL in case of error
  */
-ModestWindow*   modest_msg_edit_window_new         (TnyMsg *msg, const gchar *account_name);
+ModestWindow*   modest_msg_edit_window_new         (TnyMsg *msg, 
+                                                   const gchar *account_name, 
+                                                   gboolean preserve_is_rich);
 
 
 /**