Work to improve drafts folder management (fixes NB#56483).
authorJose Dapena Paz <jdapena@igalia.com>
Mon, 4 Jun 2007 16:37:38 +0000 (16:37 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Mon, 4 Jun 2007 16:37:38 +0000 (16:37 +0000)
* src/widgets/modest-msg-edit-window.h:
        * Now the message data contains the draft message the editor was
          created from, if any, and the account name of the From: email
          address we'll use.
* src/modest-ui-actions.c:
        * Now it retrieves the account name from the editor to be able
          to send the message from local folders.
        * Now it retrieves the draft message on trying to send a mail,
          to be able to delete it on send.
        * Now it retrieves the draft message on trying to save to
          drafts, to delete it and replace it with the new edited
          version.
* src/maemo/modest-msg-edit-window.c:
        * Obtains the account name and adds a reference to the drafts
          message on getting message data, to be able to handle sending
          on local folders, and removing drafts that should be removed.
* src/modest-mail-operation.[ch]:
        * Now send new mail removes the draft message the mail is coming
          from, if any.
        * Now save to drafts removes previous draft message if any.
* src/modest-main.c:
        * API update on send_new_mail method.
* src/dbus_api/modest-dbus-callbacks.c:
        * API update on send_new_mail method.

Other fixes:
* src/widgets/modest-msg-edit-window-ui.h:
        * Added non implemented actions for global search and find in
          page.
* src/maemo/ui/modest-msg-edit-window-ui.xml:
        * Add ui manager actions for find in page and global search.
* src/maemo/modest-msg-edit-window.c:
        * Some changes on font size update code.

pmo-trunk-r2061

src/dbus_api/modest-dbus-callbacks.c
src/gnome/modest-msg-edit-window.c
src/maemo/modest-msg-edit-window.c
src/maemo/ui/modest-msg-edit-window-ui.xml
src/modest-mail-operation.c
src/modest-mail-operation.h
src/modest-main.c
src/modest-ui-actions.c
src/widgets/modest-msg-edit-window-ui.h
src/widgets/modest-msg-edit-window.h

index 455bb32..ee307d1 100644 (file)
@@ -100,6 +100,7 @@ on_idle_send_mail(gpointer user_data)
                        
                        modest_mail_operation_send_new_mail (mail_operation,
                                             transport_account,
+                                            NULL,
                                             from, /* from */
                                             idle_data->to, idle_data->cc, idle_data->bcc, idle_data->subject, 
                                             idle_data->body, /* plain_body */
index 3adfc52..1788690 100644 (file)
@@ -409,13 +409,14 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window)
        }
        
        
-
+       
        data = g_slice_new0 (MsgData);
-       data->from    =  from_string, /* will be freed when data is freed */
-       data->to      =  g_strdup (gtk_entry_get_text (GTK_ENTRY(priv->to_field))));
+       data->from    =  from_string; /* will be freed when data is freed */
+       data->to      =  g_strdup (gtk_entry_get_text (GTK_ENTRY(priv->to_field)));
        data->cc      =  g_strdup ( gtk_entry_get_text (GTK_ENTRY(priv->cc_field)));
        data->bcc     =  g_strdup ( gtk_entry_get_text (GTK_ENTRY(priv->bcc_field)));
        data->subject =  g_strdup ( gtk_entry_get_text (GTK_ENTRY(priv->subject_field)));
+       data->msg_id = NULL;
 
        GtkTextBuffer *buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->msg_body));
        GtkTextIter b, e;
index aca186d..4405abe 100644 (file)
@@ -952,10 +952,16 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window)
        data = g_slice_new0 (MsgData);
        data->from    =  modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
                                                             account_name);
+       data->account_name = g_strdup (account_name);
        data->to      =  g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->to_field)));
        data->cc      =  g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->cc_field)));
        data->bcc     =  g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->bcc_field)));
        data->subject =  g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->subject_field)));
+       if (priv->draft_msg) {
+               data->draft_msg = g_object_ref (priv->draft_msg);
+       } else {
+               data->draft_msg = NULL;
+       }
 
        GtkTextBuffer *buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->msg_body));
        GtkTextIter b, e;
@@ -989,6 +995,11 @@ modest_msg_edit_window_free_msg_data (ModestMsgEditWindow *edit_window,
        g_free (data->subject);
        g_free (data->plain_body);
        g_free (data->html_body);
+       if (data->draft_msg != NULL) {
+               g_object_unref (data->draft_msg);
+               data->draft_msg = NULL;
+       }
+       g_free (data->account_name);
 
        /* TODO: Free data->attachments? */
 
@@ -1556,14 +1567,19 @@ modest_msg_edit_window_size_change (GtkCheckMenuItem *menu_item,
 
        if (gtk_check_menu_item_get_active (menu_item)) {
                gchar *markup;
+               WPTextBufferFormat format;
 
                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));
+               memset (&format, 0, sizeof (format));
+               format.cs.font_size = TRUE;
+               format.font_size = wp_get_font_size_index (new_size_index, DEFAULT_FONT_SIZE);
+               wp_text_buffer_set_format (WP_TEXT_BUFFER (priv->text_buffer), &format);
+
+/*             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);
index 832366d..c0b3bd9 100644 (file)
        <menuitem name="MessagePriorityLowMenu" action="MessagePriorityLow"/>
       </menu>
       <separator/>
-<!--
-      <menuitem name="ToolsFindOnPageMenu" action="ToolsFindOnPage"/>
-      <menuitem name="ToolSearchMessagesMenu" action="ToolSearchMessages"/>
+      <menuitem name="FindInMessageMenu" action="FindInMessage"/>
+      <menuitem name="ToolSearchMessagesMenu" action="SearchMessages"/>
       <separator/>
--->
       <menuitem name="ToolsHelpMenu" action="Help"/>
     </menu>
 
index 8a37125..c86338d 100644 (file)
@@ -473,6 +473,7 @@ modest_mail_operation_send_mail (ModestMailOperation *self,
 void
 modest_mail_operation_send_new_mail (ModestMailOperation *self,
                                     TnyTransportAccount *transport_account,
+                                    TnyMsg *draft_msg,
                                     const gchar *from,  const gchar *to,
                                     const gchar *cc,  const gchar *bcc,
                                     const gchar *subject, const gchar *plain_body,
@@ -481,6 +482,7 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
                                     TnyHeaderFlags priority_flags)
 {
        TnyMsg *new_msg = NULL;
+       TnyFolder *folder = NULL;
        ModestMailOperationPrivate *priv = NULL;
 
        g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
@@ -517,6 +519,15 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
        /* Call mail operation */
        modest_mail_operation_send_mail (self, transport_account, new_msg);
 
+       folder = modest_tny_account_get_special_folder (TNY_ACCOUNT (transport_account), TNY_FOLDER_TYPE_DRAFTS);
+       if (folder) {
+               if (draft_msg != NULL) {
+                       TnyHeader *header = tny_msg_get_header (draft_msg);
+                       tny_folder_remove_msg (folder, header, NULL);
+                       g_object_unref (header);
+               }
+       }
+
        /* Free */
        g_object_unref (G_OBJECT (new_msg));
 }
@@ -524,6 +535,7 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
 void
 modest_mail_operation_save_to_drafts (ModestMailOperation *self,
                                      TnyTransportAccount *transport_account,
+                                     TnyMsg *draft_msg,
                                      const gchar *from,  const gchar *to,
                                      const gchar *cc,  const gchar *bcc,
                                      const gchar *subject, const gchar *plain_body,
@@ -562,6 +574,12 @@ modest_mail_operation_save_to_drafts (ModestMailOperation *self,
                             "modest: failed to create a new msg\n");
                goto end;
        }
+
+       if (draft_msg != NULL) {
+               TnyHeader *header = tny_msg_get_header (draft_msg);
+               tny_folder_remove_msg (folder, header, NULL);
+               g_object_unref (header);
+       }
        
        tny_folder_add_msg (folder, msg, &(priv->error));
        if (priv->error)
index f8869b5..5d2b9f9 100644 (file)
@@ -233,6 +233,7 @@ void    modest_mail_operation_send_mail       (ModestMailOperation *self,
  * modest_mail_operation_send_new_mail:
  * @self: a #ModestMailOperation
  * @transport_account: a non-NULL #TnyTransportAccount
+ * @draft_msg: a #TnyMsg of the origin draft message, if any
  * @from: the email address of the mail sender
  * @to: a non-NULL email address of the mail receiver
  * @cc: a comma-separated list of email addresses where to send a carbon copy
@@ -250,6 +251,7 @@ void    modest_mail_operation_send_mail       (ModestMailOperation *self,
   **/
 void    modest_mail_operation_send_new_mail   (ModestMailOperation *self,
                                               TnyTransportAccount *transport_account,
+                                              TnyMsg *draft_msg,
                                               const gchar *from,
                                               const gchar *to,
                                               const gchar *cc,
@@ -265,6 +267,8 @@ void    modest_mail_operation_send_new_mail   (ModestMailOperation *self,
  * modest_mail_operation_save_to_drafts:
  * @self: a #ModestMailOperation
  * @transport_account: a non-NULL #TnyTransportAccount
+ * @draft_msg: the previous draft message, in case it's an update
+ * to an existing draft.
  * @from: the email address of the mail sender
  * @to: a non-NULL email address of the mail receiver
  * @cc: a comma-separated list of email addresses where to send a carbon copy
@@ -282,6 +286,7 @@ void    modest_mail_operation_send_new_mail   (ModestMailOperation *self,
   **/
 void    modest_mail_operation_save_to_drafts   (ModestMailOperation *self,
                                                TnyTransportAccount *transport_account,
+                                               TnyMsg *draft_msg,
                                                const gchar *from,
                                                const gchar *to,
                                                const gchar *cc,
index 030ac4f..5d048dc 100644 (file)
@@ -286,6 +286,7 @@ send_mail (const gchar* account_name,
        mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, NULL);
 
        modest_mail_operation_send_new_mail (mail_operation, account,
+                                            NULL,
                                             from_string, mailto,
                                             cc, bcc, subject, body, NULL /* html_body */,
                                             NULL /* attachments */, 0 /* priority */);
index 1b6ed49..b6f1bf3 100644 (file)
@@ -1392,6 +1392,11 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
                modest_msg_edit_window_free_msg_data (edit_window, data);
                return;
        }
+
+       if (!strcmp (account_name, MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID)) {
+               account_name = g_strdup (data->account_name);
+       }
+
        transport_account =
                TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
                                      (modest_runtime_get_account_store(),
@@ -1411,6 +1416,7 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
 
        modest_mail_operation_save_to_drafts (mail_operation,
                                              transport_account,
+                                             data->draft_msg,
                                              from,
                                              data->to, 
                                              data->cc, 
@@ -1453,6 +1459,11 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
                g_printerr ("modest: no account found\n");
                return;
        }
+       MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
+
+       if (!strcmp (account_name, MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID)) {
+               account_name = g_strdup (data->account_name);
+       }
        
        /* Get the currently-active transport account for this modest account: */
        TnyTransportAccount *transport_account =
@@ -1462,13 +1473,12 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
        if (!transport_account) {
                g_printerr ("modest: no transport account found for '%s'\n", account_name);
                g_free (account_name);
+               modest_msg_edit_window_free_msg_data (edit_window, data);
                return;
        }
        
        gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
 
-       MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
-
        /* mail content checks and dialogs */
        if (data->subject == NULL || data->subject[0] == '\0') {
                GtkResponseType response;
@@ -1502,6 +1512,7 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
 
        modest_mail_operation_send_new_mail (mail_operation,
                                             transport_account,
+                                            data->draft_msg,
                                             from,
                                             data->to, 
                                             data->cc, 
index 61970f1..7e403a1 100644 (file)
@@ -74,6 +74,7 @@ static const GtkActionEntry modest_msg_edit_action_entries [] = {
        { "CloseWindow", NULL, N_("mcen_me_inbox_close_window"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_close_window)},
        { "CloseAllWindows", NULL, N_("mcen_me_inbox_close_windows"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_quit) },
        { "Help", NULL, N_("mcen_me_inbox_help"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_help) },
+       { "SearchMessages",            NULL,      N_("mcen_me_inbox_search"),                      NULL, NULL,  NULL },
 
 
        /* KEY ACCELERATOR ACTIONS */
@@ -106,6 +107,9 @@ static const GtkToggleActionEntry modest_msg_edit_toggle_action_entries [] = {
        { "ActionsBold", GTK_STOCK_BOLD, NULL, NULL, NULL, G_CALLBACK (modest_ui_actions_on_toggle_bold), FALSE },
        { "ActionsItalics", GTK_STOCK_ITALIC, NULL, NULL, NULL, G_CALLBACK (modest_ui_actions_on_toggle_italics), FALSE },
 
+       /* Find in page */
+       { "FindInMessage", NULL, N_("mcen_me_viewer_find"), NULL, NULL, NULL, FALSE },
+
 };
 
 static const GtkRadioActionEntry modest_msg_edit_alignment_radio_action_entries [] = {
index a1e1a90..f3fafaa 100644 (file)
@@ -77,6 +77,8 @@ typedef struct  {
        gchar *from, *to, *cc, *bcc, *subject, *plain_body, *html_body;
        GList *attachments;
        TnyHeaderFlags priority_flags;
+       TnyMsg *draft_msg;
+       gchar *account_name;
 } MsgData;
 
 typedef struct {