Implemented new save_remote_draft virtual.
authorJose Dapena Paz <jdapena@igalia.com>
Tue, 14 Jul 2009 16:35:15 +0000 (18:35 +0200)
committerJose Dapena Paz <jdapena@igalia.com>
Tue, 14 Jul 2009 16:37:14 +0000 (18:37 +0200)
* src/modest-account-protocol.[ch]: Now we have a virtual method
  save_remote_draft that children can implement. This will be
  called just after message has been saved in local folder.
* src/modest-mail-operation.c: call save_remote_drafts if available just
  after saving local draft. Mail operation will last enough to also save
  the remote draft.

src/modest-account-protocol.c
src/modest-account-protocol.h
src/modest-mail-operation.c
src/modest-marshal.list

index 76aff6e..bd298ad 100644 (file)
@@ -32,6 +32,7 @@
 #include "modest-account-mgr-helpers.h"
 #include "widgets/modest-default-account-settings-dialog.h"
 #include "modest-runtime.h"
+#include "modest-marshal.h"
 
 enum {
        PROP_0,
@@ -111,6 +112,12 @@ static const GdkPixbuf *modest_account_protocol_get_service_icon_default (Modest
                                                                          const gchar *account_id,
                                                                          const gchar *mailbox,
                                                                          guint icon_size);
+static void modest_account_protocol_save_remote_draft_default (ModestAccountProtocol *self,
+                                                              const gchar *account_id,
+                                                              TnyMsg *new_msg,
+                                                              TnyMsg *old_msg,
+                                                              ModestAccountProtocolSaveRemoteDraftCallback callback,
+                                                              gpointer userdata);
 
 /* globals */
 static GObjectClass *parent_class = NULL;
@@ -210,6 +217,9 @@ modest_account_protocol_class_init (ModestAccountProtocolClass *klass)
                modest_account_protocol_get_service_name_default;
        account_class->get_service_icon =
                modest_account_protocol_get_service_icon_default;
+       account_class->save_remote_draft =
+               modest_account_protocol_save_remote_draft_default;
+
 }
 
 static void
@@ -659,7 +669,7 @@ modest_account_protocol_get_from_default (ModestAccountProtocol *self,
                                          const gchar *account_id,
                                          const gchar *mailbox)
 {
-       g_return_val_if_fail (MODEST_ACCOUNT_PROTOCOL (self), NULL);
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
 
        return NULL;
 }
@@ -674,7 +684,7 @@ static ModestPairList *
 modest_account_protocol_get_from_list_default (ModestAccountProtocol *self,
                                               const gchar *account_id)
 {
-       g_return_val_if_fail (MODEST_ACCOUNT_PROTOCOL (self), NULL);
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
 
        return NULL;
 }
@@ -694,7 +704,7 @@ modest_account_protocol_get_signature_default (ModestAccountProtocol *self,
                                               const gchar *mailbox,
                                               gboolean *has_signature)
 {
-       g_return_val_if_fail (MODEST_ACCOUNT_PROTOCOL (self), NULL);
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
        if (has_signature)
                *has_signature = FALSE;
 
@@ -714,7 +724,7 @@ static const GdkPixbuf *
 modest_account_protocol_get_icon_default (ModestAccountProtocol *self, ModestAccountProtocolIconType icon_type, 
                                          GObject *object, guint icon_size)
 {
-       g_return_val_if_fail (MODEST_ACCOUNT_PROTOCOL (self), NULL);
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
 
        return NULL;
 }
@@ -732,7 +742,7 @@ modest_account_protocol_get_service_name_default (ModestAccountProtocol *self,
                                                  const gchar *account_id,
                                                  const gchar *mailbox)
 {
-       g_return_val_if_fail (MODEST_ACCOUNT_PROTOCOL (self), NULL);
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
 
        return NULL;
 }
@@ -752,8 +762,34 @@ modest_account_protocol_get_service_icon_default (ModestAccountProtocol *self,
                                                  const gchar *mailbox,
                                                  guint icon_size)
 {
-       g_return_val_if_fail (MODEST_ACCOUNT_PROTOCOL (self), NULL);
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
 
        return NULL;
 }
 
+void
+modest_account_protocol_save_remote_draft (ModestAccountProtocol *self,
+                                          const gchar *account_id,
+                                          TnyMsg *new_msg,
+                                          TnyMsg *old_msg,
+                                          ModestAccountProtocolSaveRemoteDraftCallback callback,
+                                          gpointer userdata)
+{
+       MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->save_remote_draft (self, account_id, 
+                                                                    new_msg, old_msg,
+                                                                    callback, userdata);
+}
+
+static void
+modest_account_protocol_save_remote_draft_default (ModestAccountProtocol *self,
+                                                  const gchar *account_id,
+                                                  TnyMsg *new_msg,
+                                                  TnyMsg *old_msg,
+                                                  ModestAccountProtocolSaveRemoteDraftCallback callback,
+                                                  gpointer userdata)
+{
+       if (callback) {
+               callback (self, NULL, account_id, NULL, new_msg, old_msg, userdata);
+       }
+}
+
index da39cdb..25a6b3c 100644 (file)
@@ -62,6 +62,13 @@ typedef enum {
 
 typedef void (*ModestAccountProtocolCheckSupportFunc) (ModestAccountProtocol *self, 
                                                       gboolean supported, gpointer userdata);
+typedef void (*ModestAccountProtocolSaveRemoteDraftCallback) (ModestAccountProtocol *self,
+                                                             GError *error,
+                                                             const gchar *account_id,
+                                                             TnyMsg *new_remote_msg,
+                                                             TnyMsg *new_msg,
+                                                             TnyMsg *old_msg,
+                                                             gpointer userdata);
 
 
 struct _ModestAccountProtocol {
@@ -87,9 +94,12 @@ struct _ModestAccountProtocolClass {
                                       GObject *object, guint icon_size);
        gchar * (*get_service_name) (ModestAccountProtocol *self, const gchar *account_id, const gchar *mailbox);
        const GdkPixbuf * (*get_service_icon) (ModestAccountProtocol *self, const gchar *account_id, const gchar *mailbox, guint icon_size);
+       void (*save_remote_draft) (ModestAccountProtocol *self, 
+                                  const gchar *account_id, TnyMsg *new_msg, TnyMsg *old_msg,
+                                  ModestAccountProtocolSaveRemoteDraftCallback callback,
+                                  gpointer userdata);
 
        /* Padding for future expansions */
-       void (*_reserved3) (void);
        void (*_reserved4) (void);
        void (*_reserved5) (void);
        void (*_reserved6) (void);
@@ -434,6 +444,24 @@ const GdkPixbuf *modest_account_protocol_get_service_icon (ModestAccountProtocol
                                                           const gchar *mailbox,
                                                           guint icon_size);
 
+/**
+ * modest_account_protocol_save_remote_draft:
+ * @self: a #ModestAccountProtocol
+ * @account_id: a transport account_name
+ * @new_msg: the newly created message in local storage.
+ * @old_msg: the old message
+ * @callback: the code that should be executed on finishing the remote message saving
+ * @userdata: a #gpointer
+ *
+ * Saves the just-saved to local draft, into a remote storage.
+ */
+void modest_account_protocol_save_remote_draft (ModestAccountProtocol *self,
+                                                   const gchar *account_id,
+                                                   TnyMsg *new_msg,
+                                                   TnyMsg *old_msg,
+                                                   ModestAccountProtocolSaveRemoteDraftCallback callback,
+                                                   gpointer userdata);
+
 
 G_END_DECLS
 
index 19f8954..4e1fee9 100644 (file)
@@ -66,6 +66,7 @@
 #ifdef MODEST_USE_LIBTIME
 #include <clockd/libtime.h>
 #endif
+#include "modest-account-protocol.h"
 
 #define KB 1024
 
@@ -1139,6 +1140,46 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
 
 typedef struct
 {
+       ModestMailOperation *mailop;
+       TnyMsg *msg;
+       SaveToDraftstCallback callback;
+       gpointer userdata;
+} FinishSaveRemoteDraftInfo;
+
+static void
+finish_save_remote_draft (ModestAccountProtocol *protocol,
+                         GError *err,
+                         const gchar *account_id,
+                         TnyMsg *new_remote_msg,
+                         TnyMsg *new_msg,
+                         TnyMsg *old_msg,
+                         gpointer userdata)
+{
+       FinishSaveRemoteDraftInfo *info = (FinishSaveRemoteDraftInfo *) userdata;
+       ModestMailOperationPrivate *priv = NULL;
+
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE(info->mailop);
+
+       if (!priv->error && err != NULL) {
+               /* Priority for errors in save to local stage */
+               priv->error = g_error_copy (err);
+               priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
+       }
+
+       if (info->callback)
+               info->callback (info->mailop, info->msg, info->userdata);
+
+       if (info->msg)
+               g_object_unref (info->msg);
+
+       modest_mail_operation_notify_end (info->mailop);
+       g_object_unref (info->mailop);
+
+       g_slice_free (FinishSaveRemoteDraftInfo, info);
+}
+
+typedef struct
+{
        TnyTransportAccount *transport_account;
        TnyMsg *draft_msg;
        SaveToDraftstCallback callback;
@@ -1157,6 +1198,7 @@ modest_mail_operation_save_to_drafts_add_msg_cb(TnyFolder *self,
        ModestMailOperationPrivate *priv = NULL;
        SaveToDraftsAddMsgInfo *info = (SaveToDraftsAddMsgInfo *) userdata;
        GError *io_error = NULL;
+       gboolean callback_called = FALSE;
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(info->mailop);
 
@@ -1201,8 +1243,32 @@ modest_mail_operation_save_to_drafts_add_msg_cb(TnyFolder *self,
                priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
        }
 
+       if (info->transport_account) {
+               ModestProtocolType transport_protocol_type;
+               ModestProtocol *transport_protocol;
+
+               transport_protocol_type = modest_tny_account_get_protocol_type (TNY_ACCOUNT (info->transport_account));
+
+               transport_protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
+                                                                                   transport_protocol_type);
+               if (transport_protocol && MODEST_IS_ACCOUNT_PROTOCOL (transport_protocol)) {
+                       FinishSaveRemoteDraftInfo *srd_info = g_slice_new (FinishSaveRemoteDraftInfo);
+                       srd_info->mailop = info->mailop?g_object_ref (info->mailop):NULL;
+                       srd_info->msg = info->msg?g_object_ref (info->msg):NULL;
+                       srd_info->callback = info->callback;
+                       srd_info->userdata = info->user_data;
+                       modest_account_protocol_save_remote_draft (MODEST_ACCOUNT_PROTOCOL (transport_protocol), 
+                                                                  tny_account_get_id (TNY_ACCOUNT (info->transport_account)),
+                                                                  info->msg, info->draft_msg,
+                                                                  finish_save_remote_draft,
+                                                                  srd_info);
+                                                                  
+                       callback_called = TRUE;
+               }
+       }
+
        /* Call the user callback */
-       if (info->callback)
+       if (!callback_called && info->callback)
                info->callback (info->mailop, info->msg, info->user_data);
 
        if (info->transport_account)
@@ -1214,7 +1280,8 @@ modest_mail_operation_save_to_drafts_add_msg_cb(TnyFolder *self,
        if (info->msg)
                g_object_unref (G_OBJECT (info->msg));
 
-       modest_mail_operation_notify_end (info->mailop);
+       if (!callback_called)
+               modest_mail_operation_notify_end (info->mailop);
        g_object_unref(info->mailop);
        g_slice_free (SaveToDraftsAddMsgInfo, info);
 }
index e2272e2..94d596a 100644 (file)
@@ -13,3 +13,4 @@ BOOL:STRING
 BOOL:STRING,OBJECT
 BOOL:ENUM,BOOL
 BOOL:ENUM
+VOID:OBJECT,OBJECT