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);
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);
{
TnyTransportAccount *transport_account;
TnyMsg *draft_msg;
- ModestMsgEditWindow *edit_window;
+ SaveToDraftstCallback callback;
+ gpointer user_data;
} SaveToDraftsInfo;
static void
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)
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;
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,
/**
* 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.
*
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 {
* 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,
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
/* 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)
{
modest_mail_operation_save_to_drafts (mail_operation,
transport_account,
data->draft_msg,
- edit_window,
from,
data->to,
data->cc,
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);