Work to improve drafts handling, mainly from the UI pov. This, with
authorJose Dapena Paz <jdapena@igalia.com>
Thu, 5 Jul 2007 20:23:03 +0000 (20:23 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Thu, 5 Jul 2007 20:23:03 +0000 (20:23 +0000)
the last changes in tinymail, fixes NB#62652.
* src/widgets/modest-platform.h, src/maemo/modest-platform.c:
        * Added new function modest_platform_run_yes_no_dialog. It's
          required in some dialogs in specs.
* src/widgets/modest-msg-edit-window.h,
  src/maemo/modest-msg-edit-window.c:
        * New method to set the draft message from outside. This is used
          to properly update the draft message when it's a new one.
        * On setting a new draft message, it replaces the registered
          header in the window manager. This way we can open a drafts
          message more than one time.
* src/widgets/modest-window-mgr.c:
        * Now the save to drafts confirmation dialog shows Yes/no
          alternatives instead of Ok/Cancel.
* src/modest-ui-actions.c:
        * Now, when a draft is saved from the editor, we set the
          created draft as the new draft message of editor. This
          should make saving drafts more than one time work as
          expected.
* src/modest-mail-operation.[ch]:
        * Now ..._save_to_drafts returns the newly created message.

pmo-trunk-r2601

src/maemo/modest-msg-edit-window.c
src/maemo/modest-platform.c
src/modest-mail-operation.c
src/modest-mail-operation.h
src/modest-platform.h
src/modest-ui-actions.c
src/widgets/modest-msg-edit-window.h
src/widgets/modest-window-mgr.c

index d0df0ea..1a1c242 100644 (file)
@@ -546,6 +546,11 @@ modest_msg_edit_window_finalize (GObject *obj)
        }
        
        if (priv->draft_msg != NULL) {
        }
        
        if (priv->draft_msg != NULL) {
+               TnyHeader *header = tny_msg_get_header (priv->draft_msg);
+               if (TNY_IS_HEADER (header)) {
+                       ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
+                       modest_window_mgr_unregister_header (mgr, header);
+               }
                g_object_unref (priv->draft_msg);
                priv->draft_msg = NULL;
        }
                g_object_unref (priv->draft_msg);
                priv->draft_msg = NULL;
        }
@@ -3016,3 +3021,33 @@ modest_msg_edit_window_set_sent (ModestMsgEditWindow *window,
 }
 
 
 }
 
 
+void            
+modest_msg_edit_window_set_draft (ModestMsgEditWindow *window,
+                                 TnyMsg *draft)
+{
+       ModestMsgEditWindowPrivate *priv;
+       TnyHeader *header = NULL;
+
+       g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
+       g_return_if_fail ((draft == NULL)||(TNY_IS_MSG (draft)));
+
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+       ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
+
+       if (priv->draft_msg != NULL) {
+               header = tny_msg_get_header (priv->draft_msg);
+               if (TNY_IS_HEADER (header)) {
+                       modest_window_mgr_unregister_header (mgr, header);
+               }
+               g_object_unref (priv->draft_msg);
+       }
+
+       if (draft != NULL) {
+               g_object_ref (draft);
+               header = tny_msg_get_header (draft);
+               if (TNY_IS_HEADER (header))
+                       modest_window_mgr_register_header (mgr, header);
+       }
+
+       priv->draft_msg = draft;
+}
index 914b112..174774e 100644 (file)
@@ -872,6 +872,26 @@ modest_platform_run_confirmation_dialog (GtkWindow *parent_window,
        return response;
 }
 
        return response;
 }
 
+gint
+modest_platform_run_yes_no_dialog (GtkWindow *parent_window,
+                                  const gchar *message)
+{
+       GtkWidget *dialog;
+       gint response;
+
+       dialog = hildon_note_new_confirmation_add_buttons (parent_window, message,
+                                                          _("mcen_bd_yes"), GTK_RESPONSE_YES,
+                                                          _("mcen_bd_no"), GTK_RESPONSE_NO,
+                                                          NULL);
+       gtk_window_set_modal (GTK_WINDOW(dialog), TRUE);
+
+       response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+       gtk_widget_destroy (GTK_WIDGET (dialog));
+
+       return response;
+}
+
 void
 modest_platform_run_information_dialog (GtkWindow *parent_window,
                                        const gchar *message)
 void
 modest_platform_run_information_dialog (GtkWindow *parent_window,
                                        const gchar *message)
index 1674414..ab3e669 100644 (file)
@@ -593,7 +593,7 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
        g_object_unref (G_OBJECT (new_msg));
 }
 
        g_object_unref (G_OBJECT (new_msg));
 }
 
-void
+TnyMsg*
 modest_mail_operation_save_to_drafts (ModestMailOperation *self,
                                      TnyTransportAccount *transport_account,
                                      TnyMsg *draft_msg,
 modest_mail_operation_save_to_drafts (ModestMailOperation *self,
                                      TnyTransportAccount *transport_account,
                                      TnyMsg *draft_msg,
@@ -609,8 +609,8 @@ modest_mail_operation_save_to_drafts (ModestMailOperation *self,
        TnyHeader *header = NULL;
        ModestMailOperationPrivate *priv = NULL;
 
        TnyHeader *header = NULL;
        ModestMailOperationPrivate *priv = NULL;
 
-       g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
-       g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
+       g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), NULL);
+       g_return_val_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account), NULL);
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
 
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
 
@@ -662,12 +662,11 @@ modest_mail_operation_save_to_drafts (ModestMailOperation *self,
                priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
 
 end:
                priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
 
 end:
-       if (msg)
-               g_object_unref (G_OBJECT(msg));
        if (folder)
                g_object_unref (G_OBJECT(folder));
 
        modest_mail_operation_notify_end (self);
        if (folder)
                g_object_unref (G_OBJECT(folder));
 
        modest_mail_operation_notify_end (self);
+       return msg;
 }
 
 typedef struct 
 }
 
 typedef struct 
index 2894a09..980b037 100644 (file)
@@ -316,8 +316,10 @@ void    modest_mail_operation_send_new_mail   (ModestMailOperation *self,
  * #TnyTransportAccount. This operation is synchronous, so the
  * #ModestMailOperation should not be added to any
  * #ModestMailOperationQueue
  * #TnyTransportAccount. This operation is synchronous, so the
  * #ModestMailOperation should not be added to any
  * #ModestMailOperationQueue
+ *
+ * Returns: the newly created message with an own reference.
   **/
   **/
-void    modest_mail_operation_save_to_drafts   (ModestMailOperation *self,
+TnyMsg* modest_mail_operation_save_to_drafts   (ModestMailOperation *self,
                                                TnyTransportAccount *transport_account,
                                                TnyMsg *draft_msg,
                                                const gchar *from,
                                                TnyTransportAccount *transport_account,
                                                TnyMsg *draft_msg,
                                                const gchar *from,
index 511f730..3b321b3 100644 (file)
@@ -179,6 +179,18 @@ gint      modest_platform_run_rename_folder_dialog        (GtkWindow *parent_win
 gint      modest_platform_run_confirmation_dialog      (GtkWindow *parent_window,
                                                        const gchar *message);
 
 gint      modest_platform_run_confirmation_dialog      (GtkWindow *parent_window,
                                                        const gchar *message);
 
+/**
+ * modest_platform_run_yes_no_dialog:
+ * @parent_window: the parent #GtkWindow of the dialog
+ * @message: the message to show to the user
+ * 
+ * runs a dialog that offers yes and no buttons.
+ * 
+ * Returns: GTK_RESPONSE_YES or GTK_RESPONSE_NO
+ **/
+gint      modest_platform_run_yes_no_dialog      (GtkWindow *parent_window,
+                                                 const gchar *message);
+
 
 /**
  * modest_platform_run_information_dialog:
 
 /**
  * modest_platform_run_information_dialog:
index 62494ed..e1ae608 100644 (file)
@@ -1673,6 +1673,7 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
        gchar *account_name, *from;
        ModestAccountMgr *account_mgr;
        gchar *info_text = NULL;
        gchar *account_name, *from;
        ModestAccountMgr *account_mgr;
        gchar *info_text = NULL;
+       TnyMsg *new_draft = NULL;
 
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
        
 
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
        
@@ -1709,18 +1710,18 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
        mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO, G_OBJECT(edit_window));
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
 
        mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO, G_OBJECT(edit_window));
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
 
-       modest_mail_operation_save_to_drafts (mail_operation,
-                                             transport_account,
-                                             data->draft_msg,
-                                             from,
-                                             data->to, 
-                                             data->cc, 
-                                             data->bcc,
-                                             data->subject, 
-                                             data->plain_body, 
-                                             data->html_body,
-                                             data->attachments,
-                                             data->priority_flags);
+       new_draft = modest_mail_operation_save_to_drafts (mail_operation,
+                                                         transport_account,
+                                                         data->draft_msg,
+                                                         from,
+                                                         data->to, 
+                                                         data->cc, 
+                                                         data->bcc,
+                                                         data->subject, 
+                                                         data->plain_body, 
+                                                         data->html_body,
+                                                         data->attachments,
+                                                         data->priority_flags);
        /* Frees */
        g_free (from);
        g_free (account_name);
        /* Frees */
        g_free (from);
        g_free (account_name);
@@ -1729,6 +1730,10 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
 
        modest_msg_edit_window_free_msg_data (edit_window, data);
 
 
        modest_msg_edit_window_free_msg_data (edit_window, data);
 
+       modest_msg_edit_window_set_draft (edit_window, new_draft);
+       if (new_draft != NULL)
+               g_object_unref (new_draft);
+
        info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
        modest_platform_information_banner (NULL, NULL, info_text);
        g_free (info_text);
        info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
        modest_platform_information_banner (NULL, NULL, info_text);
        g_free (info_text);
index b1fb3a0..4cb6e21 100644 (file)
@@ -346,6 +346,17 @@ gboolean        modest_msg_edit_window_get_sent            (ModestMsgEditWindow
 void            modest_msg_edit_window_set_sent            (ModestMsgEditWindow *window, 
                                                            gboolean sent);
 
 void            modest_msg_edit_window_set_sent            (ModestMsgEditWindow *window, 
                                                            gboolean sent);
 
+/**
+ * modest_msg_edit_window_set_draft:
+ * @window: a #ModestMsgEditWindow
+ * @draft: a #TnyMsg, or %NULL
+ *
+ * Set @draft as the original draft message of the editor. This
+ * message will be removed on saving or sending the message.
+ */
+void            modest_msg_edit_window_set_draft           (ModestMsgEditWindow *window,
+                                                           TnyMsg *draft);
+
 G_END_DECLS
 
 #endif /* __MODEST_MSG_EDIT_WINDOW_H__ */
 G_END_DECLS
 
 #endif /* __MODEST_MSG_EDIT_WINDOW_H__ */
index c49b026..1cb1ae7 100644 (file)
@@ -427,10 +427,10 @@ on_window_destroy (ModestWindow *window,
                        if (!sent && modest_msg_edit_window_is_modified (MODEST_MSG_EDIT_WINDOW (window))) {
                                
                                response =
                        if (!sent && modest_msg_edit_window_is_modified (MODEST_MSG_EDIT_WINDOW (window))) {
                                
                                response =
-                                       modest_platform_run_confirmation_dialog (GTK_WINDOW (window),
-                                                                                _("mcen_nc_no_email_message_modified_save_changes"));
+                                       modest_platform_run_yes_no_dialog (GTK_WINDOW (window),
+                                                                          _("mcen_nc_no_email_message_modified_save_changes"));
                                /* Save to drafts */
                                /* Save to drafts */
-                               if (response != GTK_RESPONSE_CANCEL)                            
+                               if (response != GTK_RESPONSE_NO)                                
                                        modest_ui_actions_on_save_to_drafts (NULL, MODEST_MSG_EDIT_WINDOW (window));
                                
                        }
                                        modest_ui_actions_on_save_to_drafts (NULL, MODEST_MSG_EDIT_WINDOW (window));
                                
                        }