* modest-conf.h, modest-main.c:
[modest] / src / modest-mail-operation.c
index 705cb9a..6eefdf6 100644 (file)
 #include <tny-store-account.h>
 #include <tny-folder-store.h>
 #include <tny-folder-store-query.h>
-#include <tny-camel-msg.h>
-#include <tny-camel-header.h>
 #include <tny-camel-stream.h>
-#include <tny-camel-mime-part.h>
 #include <tny-simple-list.h>
 #include <camel/camel-stream-mem.h>
 #include <glib/gi18n.h>
@@ -83,10 +80,10 @@ static void modest_mail_operation_xfer_folder (ModestMailOperation *self,
                                               TnyFolderStore *parent,
                                               gboolean delete_original);
 
-static void modest_mail_operation_xfer_msg    (ModestMailOperation *self,
-                                              TnyHeader *header, 
-                                              TnyFolder *folder, 
-                                              gboolean delete_original);
+static gboolean    modest_mail_operation_xfer_msg          (ModestMailOperation *self,
+                                                           TnyHeader *header, 
+                                                           TnyFolder *folder, 
+                                                           gboolean delete_original);
 
 static TnyFolder * modest_mail_operation_find_trash_folder (ModestMailOperation *self,
                                                            TnyStoreAccount *store_account);
@@ -237,6 +234,7 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
                                     const gchar *body,
                                     const GList *attachments_list)
 {
+       TnyPlatformFactory *fact;
        TnyMsg *new_msg;
        TnyHeader *header;
        gchar *content_type;
@@ -256,8 +254,9 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
        }
 
        /* Create new msg */
-       new_msg          = TNY_MSG (tny_camel_msg_new ());
-       header           = TNY_HEADER (tny_camel_header_new ());
+       fact    = modest_tny_platform_factory_get_instance ();
+       new_msg = tny_platform_factory_new_msg (fact);
+       header  = tny_platform_factory_new_header (fact);
 
        /* WARNING: set the header before assign values to it */
        tny_msg_set_header (new_msg, header);
@@ -303,6 +302,7 @@ add_if_attachment (gpointer data, gpointer user_data)
 static TnyMsg *
 create_reply_forward_mail (TnyMsg *msg, const gchar *from, gboolean is_reply, guint type)
 {
+       TnyPlatformFactory *fact;
        TnyMsg *new_msg;
        TnyHeader *new_header, *header;
        gchar *new_subject;
@@ -341,14 +341,16 @@ create_reply_forward_mail (TnyMsg *msg, const gchar *from, gboolean is_reply, gu
        g_object_unref (G_OBJECT (formatter));
 
        /* Fill the header */
-       new_header = TNY_HEADER (tny_camel_header_new ());
-       tny_msg_set_header  (new_msg, new_header);
+       fact = modest_tny_platform_factory_get_instance ();
+       new_header = TNY_HEADER (tny_platform_factory_new_header (fact));
+       tny_msg_set_header (new_msg, new_header);
        tny_header_set_from (new_header, from);
        tny_header_set_replyto (new_header, from);
 
        /* Change the subject */
-       new_subject = (gchar *) modest_text_utils_derived_subject (tny_header_get_subject(header), 
-                                                                  (is_reply) ? _("Re:") : _("Fwd:"));
+       new_subject = 
+               (gchar *) modest_text_utils_derived_subject (tny_header_get_subject(header), 
+                                                            (is_reply) ? _("Re:") : _("Fwd:"));
        tny_header_set_subject (new_header, (const gchar *) new_subject);
        g_free (new_subject);
 
@@ -837,26 +839,26 @@ modest_mail_operation_find_trash_folder (ModestMailOperation *self,
 /* **************************  MSG  ACTIONS  ************************* */
 /* ******************************************************************* */
 
-void 
+gboolean 
 modest_mail_operation_copy_msg (ModestMailOperation *self,
                                TnyHeader *header, 
                                TnyFolder *folder)
 {
-       g_return_if_fail (TNY_IS_HEADER (header));
-       g_return_if_fail (TNY_IS_FOLDER (folder));
+       g_return_val_if_fail (TNY_IS_HEADER (header), FALSE);
+       g_return_val_if_fail (TNY_IS_FOLDER (folder), FALSE);
 
-       modest_mail_operation_xfer_msg (self, header, folder, FALSE);
+       return modest_mail_operation_xfer_msg (self, header, folder, FALSE);
 }
 
-void 
+gboolean 
 modest_mail_operation_move_msg (ModestMailOperation *self,
                                TnyHeader *header, 
                                TnyFolder *folder)
 {
-       g_return_if_fail (TNY_IS_HEADER (header));
-       g_return_if_fail (TNY_IS_FOLDER (folder));
+       g_return_val_if_fail (TNY_IS_HEADER (header), FALSE);
+       g_return_val_if_fail (TNY_IS_FOLDER (folder), FALSE);
 
-       modest_mail_operation_xfer_msg (self, header, folder, TRUE);
+       return modest_mail_operation_xfer_msg (self, header, folder, TRUE);
 }
 
 void 
@@ -878,7 +880,19 @@ modest_mail_operation_remove_msg (ModestMailOperation *self,
                store_account = TNY_STORE_ACCOUNT (tny_folder_get_account (folder));
                trash_folder = modest_mail_operation_find_trash_folder (self, store_account);
 
-               modest_mail_operation_move_msg (self, header, trash_folder);
+               if (trash_folder) {
+                       modest_mail_operation_move_msg (self, header, trash_folder);
+/*                     g_object_unref (trash_folder); */
+               } else {
+                       ModestMailOperationPrivate *priv;
+
+                       /* Set status failed and set an error */
+                       priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
+                       priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
+                       g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
+                                    MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
+                                    _("Error trying to delete a message. Trash folder not found"));
+               }
 
                g_object_unref (G_OBJECT (store_account));
        } else {
@@ -891,24 +905,44 @@ modest_mail_operation_remove_msg (ModestMailOperation *self,
 }
 
 static void
+transfer_msgs_cb (TnyFolder *folder, GError **err, gpointer user_data)
+{
+       ModestMailOperationPrivate *priv;
+
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE(user_data);
+       priv->done = 1;
+       priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
+
+       g_signal_emit (G_OBJECT (user_data), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
+}
+
+static gboolean
 modest_mail_operation_xfer_msg (ModestMailOperation *self,
                                TnyHeader *header, 
                                TnyFolder *folder, 
                                gboolean delete_original)
 {
+       ModestMailOperationPrivate *priv;
        TnyFolder *src_folder;
        TnyList *headers;
 
        src_folder = tny_header_get_folder (header);
        headers = tny_simple_list_new ();
 
-       /* Move */
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
+       priv->total = 1;
+       priv->done = 0;
+       priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
+
        tny_list_prepend (headers, G_OBJECT (header));
-       tny_folder_transfer_msgs (src_folder, headers, folder, delete_original, NULL); /* FIXME */
+       tny_folder_transfer_msgs_async (src_folder, headers, folder, 
+                                       delete_original, transfer_msgs_cb, self);
 
        /* Free */
        g_object_unref (headers);
        g_object_unref (folder);
+
+       return TRUE;
 }
 
 
@@ -944,17 +978,6 @@ get_content_type(const gchar *s)
        return g_string_free(type, FALSE);
 }
 
-static GQuark 
-modest_error_quark (void)
-{
-       static GQuark err_q = 0;
-       
-       if (err_q == 0)
-               err_q = g_quark_from_static_string ("modest-error-quark");
-       
-       return err_q;
-}
-
 static void
 add_attachments (TnyMsg *msg, GList *attachments_list)
 {
@@ -963,13 +986,15 @@ add_attachments (TnyMsg *msg, GList *attachments_list)
        const gchar *attachment_content_type;
        const gchar *attachment_filename;
        TnyStream *attachment_stream;
+       TnyPlatformFactory *fact;
 
+       fact = modest_tny_platform_factory_get_instance ();
        for (pos = (GList *)attachments_list; pos; pos = pos->next) {
 
                old_attachment = pos->data;
                attachment_filename = tny_mime_part_get_filename (old_attachment);
                attachment_stream = tny_mime_part_get_stream (old_attachment);
-               attachment_part = TNY_MIME_PART (tny_camel_mime_part_new (camel_mime_part_new()));
+               attachment_part = tny_platform_factory_new_mime_part (fact);
                
                attachment_content_type = tny_mime_part_get_content_type (old_attachment);
                                 
@@ -994,6 +1019,9 @@ add_body_part (TnyMsg *msg,
 {
        TnyMimePart *text_body_part = NULL;
        TnyStream *text_body_stream;
+       TnyPlatformFactory *fact;
+
+       fact = modest_tny_platform_factory_get_instance ();
 
        /* Create the stream */
        text_body_stream = TNY_STREAM (tny_camel_stream_new
@@ -1002,8 +1030,7 @@ add_body_part (TnyMsg *msg,
 
        /* Create body part if needed */
        if (has_attachments)
-               text_body_part = 
-                       TNY_MIME_PART (tny_camel_mime_part_new (camel_mime_part_new()));
+               text_body_part = tny_platform_factory_new_mime_part (fact);
        else
                text_body_part = TNY_MIME_PART(msg);