* Added a callback for the save_to_drafts operation
authorSergio Villar Senin <svillar@igalia.com>
Thu, 4 Oct 2007 13:39:59 +0000 (13:39 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Thu, 4 Oct 2007 13:39:59 +0000 (13:39 +0000)
* Removed a call to edit window directly from mail operations
* Fixed a bug caused by the old implementation, now if the message was saved when the editor was closed it unregisters the header in the window mgr, so we are able to open it again

pmo-trunk-r3470

src/modest-mail-operation.c
src/modest-mail-operation.h
src/modest-ui-actions.c

index 95e216d..96bf48a 100644 (file)
@@ -668,11 +668,8 @@ create_msg_thread (gpointer thread_data)
        if (info->callback) {
                CreateMsgIdleInfo *idle_info;
                idle_info = g_slice_new0 (CreateMsgIdleInfo);
-               idle_info->mail_op = info->mail_op;
-               g_object_ref (info->mail_op);
-               idle_info->msg = new_msg;
-               if (new_msg)
-                       g_object_ref (new_msg);
+               idle_info->mail_op = g_object_ref (info->mail_op);
+               idle_info->msg = (new_msg) ? g_object_ref (new_msg) : NULL;
                idle_info->callback = info->callback;
                idle_info->userdata = info->userdata;
                g_idle_add (idle_create_msg_cb, idle_info);
@@ -700,8 +697,7 @@ modest_mail_operation_create_msg (ModestMailOperation *self,
        CreateMsgInfo *info = NULL;
 
        info = g_slice_new0 (CreateMsgInfo);
-       info->mail_op = self;
-       g_object_ref (self);
+       info->mail_op = g_object_ref (self);
 
        info->from = g_strdup (from);
        info->to = g_strdup (to);
@@ -838,7 +834,8 @@ typedef struct
 {
        TnyTransportAccount *transport_account;
        TnyMsg *draft_msg;
-       ModestMsgEditWindow *edit_window;
+       SaveToDraftstCallback callback;
+       gpointer user_data;
 } SaveToDraftsInfo;
 
 static void
@@ -894,17 +891,15 @@ modest_mail_operation_save_to_drafts_cb (ModestMailOperation *self,
        else
                priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
 
-       if (info->edit_window)
-               modest_msg_edit_window_set_draft (info->edit_window, msg);
-
-
 end:
+       /* Call the user callback */
+       if (info->callback)
+               info->callback (self, msg, info->user_data);
+
        if (drafts)
                g_object_unref (G_OBJECT(drafts));
        if (src_folder)
                g_object_unref (G_OBJECT(src_folder));
-       if (info->edit_window)
-               g_object_unref (G_OBJECT(info->edit_window));
        if (info->draft_msg)
                g_object_unref (G_OBJECT (info->draft_msg));
        if (info->transport_account)
@@ -918,14 +913,15 @@ void
 modest_mail_operation_save_to_drafts (ModestMailOperation *self,
                                      TnyTransportAccount *transport_account,
                                      TnyMsg *draft_msg,
-                                     ModestMsgEditWindow *edit_window,
                                      const gchar *from,  const gchar *to,
                                      const gchar *cc,  const gchar *bcc,
                                      const gchar *subject, const gchar *plain_body,
                                      const gchar *html_body,
                                      const GList *attachments_list,
                                      const GList *images_list,
-                                     TnyHeaderFlags priority_flags)
+                                     TnyHeaderFlags priority_flags,
+                                     SaveToDraftstCallback callback,
+                                     gpointer user_data)
 {
        ModestMailOperationPrivate *priv = NULL;
        SaveToDraftsInfo *info = NULL;
@@ -941,12 +937,9 @@ modest_mail_operation_save_to_drafts (ModestMailOperation *self,
 
        info = g_slice_new0 (SaveToDraftsInfo);
        info->transport_account = g_object_ref (transport_account);
-       info->draft_msg = draft_msg;
-       if (draft_msg)
-               g_object_ref (draft_msg);
-       info->edit_window = edit_window;
-       if (edit_window)
-               g_object_ref (edit_window);
+       info->draft_msg = (draft_msg) ? g_object_ref (draft_msg) : NULL;
+       info->callback = callback;
+       info->user_data = user_data;
 
        modest_mail_operation_notify_start (self);
        modest_mail_operation_create_msg (self, from, to, cc, bcc, subject, plain_body, html_body,
index cf8fc2d..70c3678 100644 (file)
@@ -146,7 +146,7 @@ typedef void (*RefreshAsyncUserCallback) (ModestMailOperation *mail_op,
 /**
  * UpdateAccountCallback:
  *
- * @obj: a #GObject generic object which has created current mail operation.
+ * @self: a #ModestMailOperation
  * @new_headers: the list of new headers received
  * @user_data: generic data passed to user defined function.
  *
@@ -158,6 +158,22 @@ typedef void (*UpdateAccountCallback) (ModestMailOperation *self,
                                       TnyList *new_headers,
                                       gpointer user_data);
 
+
+/**
+ * SaveToDraftsCallback:
+ *
+ * @self: a #ModestMailOperation
+ * @saved_draft: the new draft message that has been saved
+ * @user_data: generic data passed to user defined function.
+ *
+ * This is the callback of the save_to_drafts operation. It returns
+ * the newly created msg stored in the Drafts folder
+ */
+typedef void (*SaveToDraftstCallback) (ModestMailOperation *self, 
+                                      TnyMsg *saved_draft,
+                                      gpointer user_data);
+
+
 /* This struct represents the internal state of a mail operation in a
    given time */
 typedef struct {
@@ -326,17 +342,16 @@ void    modest_mail_operation_send_new_mail   (ModestMailOperation *self,
  *             be sent with the plain body only.
  * @attachments_list: a #GList of attachments, each attachment must be a #TnyMimePart
  * @images_list: a #GList of image attachments, each attachment must be a #TnyMimePart
- * 
+ * @callback: the user callback, will be called when the operation finishes
+ * @user_data: data that will be passed to the user callback
+ *
  * Save a mail message to drafts using the provided
- * #TnyTransportAccount. This operation is synchronous, so the
- * #ModestMailOperation should not be added to any
- * #ModestMailOperationQueue
+ * #TnyTransportAccount. This operation is asynchronous.
  *
   **/
 void modest_mail_operation_save_to_drafts   (ModestMailOperation *self,
                                             TnyTransportAccount *transport_account,
                                             TnyMsg *draft_msg,
-                                            ModestMsgEditWindow *edit_window,
                                             const gchar *from,
                                             const gchar *to,
                                             const gchar *cc,
@@ -346,7 +361,9 @@ void modest_mail_operation_save_to_drafts   (ModestMailOperation *self,
                                             const gchar *html_body,
                                             const GList *attachments_list,
                                             const GList *images_list,
-                                            TnyHeaderFlags priority_flags);
+                                            TnyHeaderFlags priority_flags,
+                                            SaveToDraftstCallback callback,
+                                            gpointer user_data);
 /**
  * modest_mail_operation_update_account:
  * @self: a #ModestMailOperation
index 771cc85..a734068 100644 (file)
@@ -2104,6 +2104,22 @@ modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
        /* g_message ("%s %s", __FUNCTION__, address); */
 }
 
+static void
+on_save_to_drafts_cb (ModestMailOperation *mail_op, 
+                     TnyMsg *saved_draft,
+                     gpointer user_data)
+{
+       ModestMsgEditWindow *edit_window;
+
+       edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
+
+       /* If there was any error do nothing */
+       if (modest_mail_operation_get_error (mail_op) != NULL)
+               return;
+
+       modest_msg_edit_window_set_draft (edit_window, saved_draft);
+}
+
 void
 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
 {
@@ -2152,7 +2168,6 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
        modest_mail_operation_save_to_drafts (mail_operation,
                                              transport_account,
                                              data->draft_msg,
-                                             edit_window,
                                              from,
                                              data->to, 
                                              data->cc, 
@@ -2162,7 +2177,9 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
                                              data->html_body,
                                              data->attachments,
                                              data->images,
-                                             data->priority_flags);
+                                             data->priority_flags,
+                                             on_save_to_drafts_cb,
+                                             edit_window);
        /* Frees */
        g_free (from);
        g_free (account_name);