* Added per-message size limit to send&receive
authorSergio Villar Senin <svillar@igalia.com>
Thu, 24 May 2007 15:25:31 +0000 (15:25 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Thu, 24 May 2007 15:25:31 +0000 (15:25 +0000)
* Added per-account amount limit to s&r
* Added per-account retrieve last N feature
* Added an unique id to each mail operation
* Renamed id field of mail operation by operation type
* Added ModestMailOperationState to provide progress information
* Added a new parameter of type ModestMailOperationState to progress-changed signal
* Added an internal object to mail operation to get the new messages after a refresh

pmo-trunk-r1972

src/dbus_api/modest-dbus-callbacks.c
src/maemo/modest-main-window.c
src/maemo/modest-msg-view-window.c
src/maemo/modest-progress-bar-widget.c
src/modest-mail-operation-queue.c
src/modest-mail-operation.c
src/modest-mail-operation.h
src/modest-main.c
src/modest-ui-actions.c
src/widgets/modest-folder-view.c
src/widgets/modest-header-view.c

index 29ebea8..103c497 100644 (file)
@@ -89,7 +89,7 @@ on_idle_send_mail(gpointer user_data)
                if (!from) {
                        g_printerr ("modest: no from address for account '%s'\n", account_name);
                } else {
-                       ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND, NULL);
+                       ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, NULL);
                        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
                        
                        modest_mail_operation_send_new_mail (mail_operation,
index f1e93f4..6a91ba5 100644 (file)
@@ -1447,7 +1447,7 @@ on_queue_changed (ModestMailOperationQueue *queue,
                  ModestMainWindow *self)
 {
        ModestMainWindowPrivate *priv;
-       ModestMailOperationId op_id;
+       ModestMailOperationTypeOperation op_type;
        ModestToolBarModes mode;
        GSList *tmp;
        gboolean mode_changed = FALSE;
@@ -1457,10 +1457,10 @@ on_queue_changed (ModestMailOperationQueue *queue,
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
               
        /* Get toolbar mode from operation id*/
-       op_id = modest_mail_operation_get_id (mail_op);
-       switch (op_id) {
-       case MODEST_MAIL_OPERATION_ID_SEND:
-       case MODEST_MAIL_OPERATION_ID_RECEIVE:
+       op_type = modest_mail_operation_get_type_operation (mail_op);
+       switch (op_type) {
+       case MODEST_MAIL_OPERATION_TYPE_SEND:
+       case MODEST_MAIL_OPERATION_TYPE_RECEIVE:
                mode = TOOLBAR_MODE_TRANSFER;
                if (priv->current_toolbar_mode == TOOLBAR_MODE_NORMAL)
                        mode_changed = TRUE;
index 229cb72..572f321 100644 (file)
@@ -952,7 +952,7 @@ modest_msg_view_window_select_next_message (ModestMsgViewWindow *window)
                                tny_header_set_flags (header, flags | TNY_HEADER_FLAG_SEEN);
 
                        /* New mail operation */
-                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(window));
+                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(window));
                        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
                        modest_mail_operation_get_msg (mail_op, header, view_msg_cb, NULL);
                        g_object_unref (mail_op);
@@ -999,7 +999,7 @@ modest_msg_view_window_select_first_message (ModestMsgViewWindow *self)
                tny_header_set_flags (header, flags | TNY_HEADER_FLAG_SEEN);
        
        /* New mail operation */
-       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(self));
+       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(self));
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
        modest_mail_operation_get_msg (mail_op, header, view_msg_cb, NULL);
        g_object_unref (mail_op);
@@ -1046,7 +1046,7 @@ modest_msg_view_window_select_previous_message (ModestMsgViewWindow *window)
                                tny_header_set_flags (header, flags | TNY_HEADER_FLAG_SEEN);
 
                        /* New mail operation */
-                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(window));
+                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(window));
                        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
                        modest_mail_operation_get_msg (mail_op, header, view_msg_cb, NULL);             
 
@@ -1413,7 +1413,7 @@ on_queue_changed (ModestMailOperationQueue *queue,
 {
        GSList *tmp;
        ModestMsgViewWindowPrivate *priv;
-       ModestMailOperationId op_id;
+       ModestMailOperationTypeOperation op_type;
        ModestToolBarModes mode;
        
        g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (self));
@@ -1424,10 +1424,10 @@ on_queue_changed (ModestMailOperationQueue *queue,
            return;
 
        /* Get toolbar mode from operation id*/
-       op_id = modest_mail_operation_get_id (mail_op);
-       switch (op_id) {
-       case MODEST_MAIL_OPERATION_ID_SEND:
-       case MODEST_MAIL_OPERATION_ID_RECEIVE:
+       op_type = modest_mail_operation_get_type_operation (mail_op);
+       switch (op_type) {
+       case MODEST_MAIL_OPERATION_TYPE_SEND:
+       case MODEST_MAIL_OPERATION_TYPE_RECEIVE:
                mode = TOOLBAR_MODE_TRANSFER;
                break;
        default:
index a3af5c9..c302d3c 100644 (file)
@@ -51,6 +51,7 @@ static guint
 modest_progress_bar_num_pending_operations (ModestProgressObject *self);
 
 static void on_progress_changed                    (ModestMailOperation  *mail_op, 
+                                                   ModestMailOperationState *state,
                                                    ModestProgressBarWidget *self);
 
 static gboolean     progressbar_clean        (GtkProgressBar *bar);
@@ -320,47 +321,45 @@ modest_progress_bar_cancel_current_operation (ModestProgressObject *self)
 }
 static void 
 on_progress_changed (ModestMailOperation  *mail_op, 
+                    ModestMailOperationState *state,
                     ModestProgressBarWidget *self)
 {
        ModestProgressBarWidgetPrivate *priv;
        gboolean determined = FALSE;
-       ModestMailOperationId id;
 
        priv = MODEST_PROGRESS_BAR_WIDGET_GET_PRIVATE (self);
 
        /* If the mail operation is the currently shown one */
        if (priv->current == mail_op) {
                gchar *msg = NULL;
-               guint done  = modest_mail_operation_get_task_done (mail_op);
-               guint total = modest_mail_operation_get_task_total (mail_op);
                
-               determined = (done > 0 && total > 0) & !(done == 1 && total == 100);
-               id = modest_mail_operation_get_id (mail_op);
+               determined = (state->done > 0 && state->total > 0) & 
+                       !(state->done == 1 && state->total == 100);
 
-               switch (id) {
-               case MODEST_MAIL_OPERATION_ID_RECEIVE:          
+               switch (state->op_type) {
+               case MODEST_MAIL_OPERATION_TYPE_RECEIVE:                
                        if (determined)
 /*                             msg = g_strdup_printf(_("mcen_me_receiving"), done, total); */
-                               msg = g_strdup_printf("Receiving %d/%d", done, total);
+                               msg = g_strdup_printf("Receiving %d/%d", state->done, state->total);
                        else 
 /*                             msg = g_strdup(_("mail_me_receiving")); */
                                msg = g_strdup("Receiving ...");
                        break;
-               case MODEST_MAIL_OPERATION_ID_SEND:             
+               case MODEST_MAIL_OPERATION_TYPE_SEND:           
                        if (determined)
-                               msg = g_strdup_printf(_("mcen_me_sending"), done, total);
+                               msg = g_strdup_printf(_("mcen_me_sending"), state->done, state->total);
                        else 
                                msg = g_strdup(_("mail_me_sending"));
                        break;
                        
-               case MODEST_MAIL_OPERATION_ID_OPEN:             
+               case MODEST_MAIL_OPERATION_TYPE_OPEN:           
                        msg = g_strdup(_("mail_me_opening"));
                        break;
                default:
                        msg = g_strdup("");
                }
                
-               modest_progress_bar_widget_set_progress (self, msg, done, total);
+               modest_progress_bar_widget_set_progress (self, msg, state->done, state->total);
                g_free (msg);
        }
 }
index 4524d57..4ca6236 100644 (file)
@@ -53,6 +53,7 @@ typedef struct _ModestMailOperationQueuePrivate ModestMailOperationQueuePrivate;
 struct _ModestMailOperationQueuePrivate {
        GQueue *op_queue;
        GMutex *queue_lock;
+       guint   op_id;
 };
 #define MODEST_MAIL_OPERATION_QUEUE_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                          MODEST_TYPE_MAIL_OPERATION_QUEUE, \
@@ -127,6 +128,7 @@ modest_mail_operation_queue_init (ModestMailOperationQueue *obj)
 
        priv->op_queue   = g_queue_new ();
        priv->queue_lock = g_mutex_new ();
+       priv->op_id = 0;
 }
 
 static void
@@ -172,6 +174,7 @@ modest_mail_operation_queue_add (ModestMailOperationQueue *self,
 
        g_mutex_lock (priv->queue_lock);
        g_queue_push_tail (priv->op_queue, g_object_ref (mail_op));
+       modest_mail_operation_set_id (mail_op, priv->op_id++);
        g_mutex_unlock (priv->queue_lock);
 
        /* Notify observers */
index a551a16..5c91b9e 100644 (file)
@@ -39,6 +39,7 @@
 #include <tny-simple-list.h>
 #include <tny-send-queue.h>
 #include <tny-status.h>
+#include <tny-folder-observer.h>
 #include <camel/camel-stream-mem.h>
 #include <glib/gi18n.h>
 #include "modest-platform.h"
@@ -80,13 +81,14 @@ enum _ModestMailOperationSignals
 
 typedef struct _ModestMailOperationPrivate ModestMailOperationPrivate;
 struct _ModestMailOperationPrivate {
+       guint                      id;
        guint                      done;
        guint                      total;
-       ModestMailOperationStatus  status;      
-       ModestMailOperationId      id;          
        GObject                   *source;
-       ErrorCheckingUserCallback  error_checking;
        GError                    *error;
+       ErrorCheckingUserCallback  error_checking;
+       ModestMailOperationStatus  status;      
+       ModestMailOperationTypeOperation op_type;
 };
 
 #define MODEST_MAIL_OPERATION_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
@@ -172,8 +174,8 @@ modest_mail_operation_class_init (ModestMailOperationClass *klass)
                              G_SIGNAL_RUN_FIRST,
                              G_STRUCT_OFFSET (ModestMailOperationClass, progress_changed),
                              NULL, NULL,
-                             g_cclosure_marshal_VOID__VOID,
-                             G_TYPE_NONE, 0);
+                             g_cclosure_marshal_VOID__POINTER,
+                             G_TYPE_NONE, 1, G_TYPE_POINTER);
 }
 
 static void
@@ -183,12 +185,14 @@ modest_mail_operation_init (ModestMailOperation *obj)
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
 
-       priv->status   = MODEST_MAIL_OPERATION_STATUS_INVALID;
-       priv->id       = MODEST_MAIL_OPERATION_ID_UNKNOWN;
-       priv->error    = NULL;
-       priv->done     = 0;
-       priv->total    = 0;
-       priv->source = NULL;
+       priv->status         = MODEST_MAIL_OPERATION_STATUS_INVALID;
+       priv->op_type        = MODEST_MAIL_OPERATION_TYPE_UNKNOWN;
+       priv->error          = NULL;
+       priv->error_checking = NULL;
+       priv->id             = 0;
+       priv->done           = 0;
+       priv->total          = 0;
+       priv->source         = NULL;
 }
 
 static void
@@ -211,7 +215,7 @@ modest_mail_operation_finalize (GObject *obj)
 }
 
 ModestMailOperation*
-modest_mail_operation_new (ModestMailOperationId id, 
+modest_mail_operation_new (ModestMailOperationTypeOperation op_type, 
                           GObject *source)
 {
        ModestMailOperation *obj;
@@ -220,7 +224,7 @@ modest_mail_operation_new (ModestMailOperationId id,
        obj = MODEST_MAIL_OPERATION(g_object_new(MODEST_TYPE_MAIL_OPERATION, NULL));
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
 
-       priv->id = id;
+       priv->op_type = op_type;
        if (source != NULL)
                priv->source = g_object_ref(source);
 
@@ -228,14 +232,14 @@ modest_mail_operation_new (ModestMailOperationId id,
 }
 
 ModestMailOperation*
-modest_mail_operation_new_with_error_handling (ModestMailOperationId id,
+modest_mail_operation_new_with_error_handling (ModestMailOperationTypeOperation op_type,
                                               GObject *source,
                                               ErrorCheckingUserCallback error_handler)
 {
        ModestMailOperation *obj;
        ModestMailOperationPrivate *priv;
                
-       obj = modest_mail_operation_new (id, source);
+       obj = modest_mail_operation_new (op_type, source);
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
        
        g_return_val_if_fail (error_handler != NULL, obj);
@@ -252,19 +256,20 @@ modest_mail_operation_execute_error_handler (ModestMailOperation *self)
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
        g_return_if_fail(priv->status != MODEST_MAIL_OPERATION_STATUS_SUCCESS);     
 
-       if (priv->error_checking == NULL) return;       
+       if (priv->error_checking == NULL) 
+               return; 
        priv->error_checking (priv->source, self);
 }
 
 
-ModestMailOperationId
-modest_mail_operation_get_id (ModestMailOperation *self)
+ModestMailOperationTypeOperation
+modest_mail_operation_get_type_operation (ModestMailOperation *self)
 {
        ModestMailOperationPrivate *priv;
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
        
-       return priv->id;
+       return priv->op_type;
 }
 
 gboolean 
@@ -289,6 +294,152 @@ modest_mail_operation_get_source (ModestMailOperation *self)
        return g_object_ref (priv->source);
 }
 
+ModestMailOperationStatus
+modest_mail_operation_get_status (ModestMailOperation *self)
+{
+       ModestMailOperationPrivate *priv;
+
+       g_return_val_if_fail (self, MODEST_MAIL_OPERATION_STATUS_INVALID);
+       g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self),
+                             MODEST_MAIL_OPERATION_STATUS_INVALID);
+
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
+       return priv->status;
+}
+
+const GError *
+modest_mail_operation_get_error (ModestMailOperation *self)
+{
+       ModestMailOperationPrivate *priv;
+
+       g_return_val_if_fail (self, NULL);
+       g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), NULL);
+
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
+       return priv->error;
+}
+
+gboolean 
+modest_mail_operation_cancel (ModestMailOperation *self)
+{
+       ModestMailOperationPrivate *priv;
+
+       if (!MODEST_IS_MAIL_OPERATION (self)) {
+               g_warning ("%s: invalid parametter", G_GNUC_FUNCTION);
+               return FALSE;
+       }
+
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
+
+       /* TODO: Tinymail does not support cancel operation  */
+/*     tny_account_cancel (); */
+
+       /* Set new status */
+       priv->status = MODEST_MAIL_OPERATION_STATUS_CANCELED;
+
+       /* Notify about operation end */
+       modest_mail_operation_notify_end (self);
+
+       return TRUE;
+}
+
+guint 
+modest_mail_operation_get_task_done (ModestMailOperation *self)
+{
+       ModestMailOperationPrivate *priv;
+
+       g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), 0);
+
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
+       return priv->done;
+}
+
+guint 
+modest_mail_operation_get_task_total (ModestMailOperation *self)
+{
+       ModestMailOperationPrivate *priv;
+
+       g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), 0);
+
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
+       return priv->total;
+}
+
+gboolean
+modest_mail_operation_is_finished (ModestMailOperation *self)
+{
+       ModestMailOperationPrivate *priv;
+       gboolean retval = FALSE;
+
+       if (!MODEST_IS_MAIL_OPERATION (self)) {
+               g_warning ("%s: invalid parametter", G_GNUC_FUNCTION);
+               return retval;
+       }
+
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
+
+       if (priv->status == MODEST_MAIL_OPERATION_STATUS_SUCCESS   ||
+           priv->status == MODEST_MAIL_OPERATION_STATUS_FAILED    ||
+           priv->status == MODEST_MAIL_OPERATION_STATUS_CANCELED  ||
+           priv->status == MODEST_MAIL_OPERATION_STATUS_FINISHED_WITH_ERRORS) {
+               retval = TRUE;
+       } else {
+               retval = FALSE;
+       }
+
+       return retval;
+}
+
+guint
+modest_mail_operation_get_id (ModestMailOperation *self)
+{
+       ModestMailOperationPrivate *priv;
+
+       g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), 0);
+
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
+       return priv->done;
+}
+
+guint 
+modest_mail_operation_set_id (ModestMailOperation *self,
+                             guint id)
+{
+       ModestMailOperationPrivate *priv;
+
+       g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), 0);
+
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
+       return priv->done;
+}
+
+/*
+ * Creates an image of the current state of a mail operation, the
+ * caller must free it
+ */
+static ModestMailOperationState *
+modest_mail_operation_clone_state (ModestMailOperation *self)
+{
+       ModestMailOperationState *state;
+       ModestMailOperationPrivate *priv;
+
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
+
+       state = g_slice_new (ModestMailOperationState);
+
+       state->status = priv->status;
+       state->op_type = priv->op_type;
+       state->done = priv->done;
+       state->total = priv->total;
+       state->finished = modest_mail_operation_is_finished (self);
+
+       return state;
+}
+
+/* ******************************************************************* */
+/* ************************** SEND   ACTIONS ************************* */
+/* ******************************************************************* */
+
 void
 modest_mail_operation_send_mail (ModestMailOperation *self,
                                 TnyTransportAccount *transport_account,
@@ -432,6 +583,88 @@ typedef struct
        gchar *retrieve_type;
 } UpdateAccountInfo;
 
+/***** I N T E R N A L    F O L D E R    O B S E R V E R *****/
+/* We use this folder observer to track the headers that have been
+ * added to a folder */
+typedef struct {
+       GObject parent;
+       TnyList *new_headers;
+} InternalFolderObserver;
+
+typedef struct {
+       GObjectClass parent;
+} InternalFolderObserverClass;
+
+static void tny_folder_observer_init (TnyFolderObserverIface *idace);
+
+G_DEFINE_TYPE_WITH_CODE (InternalFolderObserver,
+                        internal_folder_observer,
+                        G_TYPE_OBJECT,
+                        G_IMPLEMENT_INTERFACE(TNY_TYPE_FOLDER_OBSERVER, tny_folder_observer_init));
+
+
+static void
+foreach_add_item (gpointer header, gpointer user_data)
+{
+       tny_list_prepend (TNY_LIST (user_data), 
+                         g_object_ref (G_OBJECT (header)));
+}
+
+/* This is the method that looks for new messages in a folder */
+static void
+internal_folder_observer_update (TnyFolderObserver *self, TnyFolderChange *change)
+{
+       TnyFolderChangeChanged changed;
+
+       changed = tny_folder_change_get_changed (change);
+
+       if (changed & TNY_FOLDER_CHANGE_CHANGED_ADDED_HEADERS) {
+               TnyList *list;
+
+               /* Get added headers */
+               list = tny_simple_list_new ();
+               tny_folder_change_get_added_headers (change, list);
+
+               /* Add them to the folder observer */
+               tny_list_foreach (list, foreach_add_item, 
+                                 ((InternalFolderObserver *)self)->new_headers);
+
+               g_object_unref (G_OBJECT (list));
+       }
+}
+
+static void
+internal_folder_observer_init (InternalFolderObserver *self) 
+{
+       self->new_headers = tny_simple_list_new ();
+}
+static void
+internal_folder_observer_finalize (GObject *object) 
+{
+       InternalFolderObserver *self;
+
+       self = (InternalFolderObserver *) object;
+       g_object_unref (self->new_headers);
+
+       G_OBJECT_CLASS (internal_folder_observer_parent_class)->finalize (object);
+}
+static void
+tny_folder_observer_init (TnyFolderObserverIface *iface) 
+{
+       iface->update_func = internal_folder_observer_update;
+}
+static void
+internal_folder_observer_class_init (InternalFolderObserverClass *klass) 
+{
+       GObjectClass *object_class;
+
+       internal_folder_observer_parent_class = g_type_class_peek_parent (klass);
+       object_class = (GObjectClass*) klass;
+       object_class->finalize = internal_folder_observer_finalize;
+}
+
+/*****************/
+
 static void
 recurse_folders (TnyFolderStore *store, TnyFolderStoreQuery *query, TnyList *all_folders)
 {
@@ -456,20 +689,44 @@ recurse_folders (TnyFolderStore *store, TnyFolderStoreQuery *query, TnyList *all
 }
 
 /* 
- * Used by update_account_thread to emit the "progress-changed" signal
- * from the main loop. We call it inside an idle call to achieve that
+ * Issues the "progress-changed" signal. The timer won't be removed,
+ * so you must call g_source_remove to stop the signal emission
  */
 static gboolean
-notify_update_account_observers (gpointer data)
+idle_notify_progress (gpointer data)
 {
        ModestMailOperation *mail_op = MODEST_MAIL_OPERATION (data);
+       ModestMailOperationState *state;
 
-       g_signal_emit (G_OBJECT (mail_op), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
+       state = modest_mail_operation_clone_state (mail_op);
+       g_signal_emit (G_OBJECT (mail_op), signals[PROGRESS_CHANGED_SIGNAL], 0, state, NULL);
+       g_slice_free (ModestMailOperationState, state);
 
        return TRUE;
 }
 
 /* 
+ * Issues the "progress-changed" signal and removes the timer. It uses
+ * a lock to ensure that the progress information of the mail
+ * operation is not modified while there are notifications pending
+ */
+static gboolean
+idle_notify_progress_once (gpointer data)
+{
+       ModestPair *pair;
+
+       pair = (ModestPair *) data;
+
+       g_signal_emit (G_OBJECT (pair->first), signals[PROGRESS_CHANGED_SIGNAL], 0, pair->second, NULL);
+
+       /* Free the state and the reference to the mail operation */
+       g_slice_free (ModestMailOperationState, (ModestMailOperationState*)pair->second);
+       g_object_unref (pair->first);
+
+       return FALSE;
+}
+
+/* 
  * Used by update_account_thread to notify the queue from the main
  * loop. We call it inside an idle call to achieve that
  */
@@ -488,12 +745,12 @@ static gpointer
 update_account_thread (gpointer thr_user_data)
 {
        UpdateAccountInfo *info;
-       TnyList *all_folders = NULL;
+       TnyList *all_folders = NULL, *new_headers;
        TnyIterator *iter = NULL;
        TnyFolderStoreQuery *query = NULL;
        ModestMailOperationPrivate *priv;
        ModestTnySendQueue *send_queue;
-       gint timeout;
+       gint timeout, msg_num;
 
        info = (UpdateAccountInfo *) thr_user_data;
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(info->mail_op);
@@ -527,26 +784,43 @@ update_account_thread (gpointer thr_user_data)
           Gtk+. We use a timeout in order to provide more status
           information, because the sync tinymail call does not
           provide it for the moment */
-       timeout = g_timeout_add (250, notify_update_account_observers, info->mail_op);
+       timeout = g_timeout_add (250, idle_notify_progress, info->mail_op);
 
        /* Refresh folders */
+       new_headers = tny_simple_list_new ();
        iter = tny_list_create_iterator (all_folders);
        while (!tny_iterator_is_done (iter) && !priv->error) {
 
+               InternalFolderObserver *observer;
                TnyFolderStore *folder = TNY_FOLDER_STORE (tny_iterator_get_current (iter));
 
                /* Refresh the folder */
+               observer = g_object_new (internal_folder_observer_get_type (), NULL);
+               tny_folder_add_observer (TNY_FOLDER (folder), TNY_FOLDER_OBSERVER (observer));
                tny_folder_refresh (TNY_FOLDER (folder), &(priv->error));
 
-               /* TODO: Apply retrieval types */
+               /* If the retrieve type is headers only do nothing more */
+               if (!strcmp (info->retrieve_type, MODEST_ACCOUNT_RETRIEVE_VALUE_MESSAGES) || 
+                   !strcmp (info->retrieve_type, MODEST_ACCOUNT_RETRIEVE_VALUE_MESSAGES_AND_ATTACHMENTS)) {
+                       TnyIterator *iter;
 
-               /* TODO: apply per-message size limits */
+                       iter = tny_list_create_iterator (observer->new_headers);
+                       while (!tny_iterator_is_done (iter)) {
+                               TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
+                               /* Apply per-message size limits */
+                               if (tny_header_get_message_size (header) < info->max_size)
+                                       tny_list_prepend (new_headers, G_OBJECT (header));
 
-               /* TODO: apply message count limit */
+                               g_object_unref (header);
+                               tny_iterator_next (iter);
+                       }
+                       g_object_unref (iter);
+               }
+               tny_folder_remove_observer (TNY_FOLDER (folder), TNY_FOLDER_OBSERVER (observer));
+               g_object_unref (observer);
 
-               if (priv->error) {
+               if (priv->error)
                        priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
-               }
 
                g_object_unref (G_OBJECT (folder));
                tny_iterator_next (iter);
@@ -554,12 +828,48 @@ update_account_thread (gpointer thr_user_data)
        g_object_unref (G_OBJECT (iter));
        g_source_remove (timeout);
 
+
+       /* Apply message count limit */
+       /* TODO if the number of messages exceeds the maximum, ask the
+          user to download them all */
+       msg_num = 0;
+       priv->total = MIN (tny_list_get_length (new_headers), info->retrieve_limit);
+       iter = tny_list_create_iterator (new_headers);
+       while ((msg_num < info->retrieve_limit) && !tny_iterator_is_done (iter)) {
+
+               TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
+               TnyFolder *folder = tny_header_get_folder (header);
+               TnyMsg *msg       = tny_folder_get_msg (folder, header, NULL);
+               ModestMailOperationState *state;
+               ModestPair* pair;
+
+               priv->done++;
+               /* We can not just use the mail operation because the
+                  values of done and total could change before the
+                  idle is called */
+               state = modest_mail_operation_clone_state (info->mail_op);
+               pair = modest_pair_new (g_object_ref (info->mail_op), state, FALSE);
+               g_idle_add_full (G_PRIORITY_HIGH_IDLE, idle_notify_progress_once,
+                                pair, (GDestroyNotify) modest_pair_free);
+
+               g_object_unref (msg);
+               g_object_unref (folder);
+               g_object_unref (header);
+
+               msg_num++;
+               tny_iterator_next (iter);
+       }
+       g_object_unref (iter);
+       g_object_unref (new_headers);
+
        /* Perform send */
-       priv->id = MODEST_MAIL_OPERATION_ID_SEND;
+       priv->op_type = MODEST_MAIL_OPERATION_TYPE_SEND;
+       priv->done = 0;
+       priv->total = 0;
 
        send_queue = modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(info->transport_account));
 
-       timeout = g_timeout_add (250, notify_update_account_observers, info->mail_op);
+       timeout = g_timeout_add (250, idle_notify_progress, info->mail_op);
        modest_tny_send_queue_flush (send_queue);
        g_source_remove (timeout);
 
@@ -651,118 +961,30 @@ modest_mail_operation_update_account (ModestMailOperation *self,
        info->account = modest_account;
        info->transport_account = transport_account;
 
-       /* Get the message retrieval global and per-account settings */
-       info->max_size  = modest_conf_get_int (modest_runtime_get_conf (), MODEST_CONF_MSG_SIZE_LIMIT, NULL);
+       /* Get the message size limit */
+       info->max_size  = modest_conf_get_int (modest_runtime_get_conf (), 
+                                              MODEST_CONF_MSG_SIZE_LIMIT, NULL);
        if (info->max_size == 0)
                info->max_size = G_MAXINT;
        else
-               info->max_size = info->max_size * KB; /* TODO: review this fix */
+               info->max_size = info->max_size * KB;
 
+       /* Get per-account retrieval type */
        mgr = modest_runtime_get_account_mgr ();
-       info->retrieve_type = modest_account_mgr_get_string (mgr, account_name, MODEST_ACCOUNT_RETRIEVE, FALSE);
-       info->retrieve_limit = modest_account_mgr_get_int (mgr, account_name, MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE);
+       info->retrieve_type = modest_account_mgr_get_string (mgr, account_name, 
+                                                            MODEST_ACCOUNT_RETRIEVE, FALSE);
 
-       thread = g_thread_create (update_account_thread, info, FALSE, NULL);
-
-       return TRUE;
-}
-
-ModestMailOperationStatus
-modest_mail_operation_get_status (ModestMailOperation *self)
-{
-       ModestMailOperationPrivate *priv;
-
-       g_return_val_if_fail (self, MODEST_MAIL_OPERATION_STATUS_INVALID);
-       g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self),
-                             MODEST_MAIL_OPERATION_STATUS_INVALID);
-
-       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
-       return priv->status;
-}
-
-const GError *
-modest_mail_operation_get_error (ModestMailOperation *self)
-{
-       ModestMailOperationPrivate *priv;
-
-       g_return_val_if_fail (self, NULL);
-       g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), NULL);
-
-       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
-       return priv->error;
-}
+       /* Get per-account message amount retrieval limit */
+       info->retrieve_limit = modest_account_mgr_get_int (mgr, account_name, 
+                                                          MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE);
+       if (info->retrieve_limit == 0)
+               info->retrieve_limit = G_MAXINT;
 
-gboolean 
-modest_mail_operation_cancel (ModestMailOperation *self)
-{
-       ModestMailOperationPrivate *priv;
-
-       if (!MODEST_IS_MAIL_OPERATION (self)) {
-               g_warning ("%s: invalid parametter", G_GNUC_FUNCTION);
-               return FALSE;
-       }
-
-       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
-
-       /* TODO: Tinymail does not support cancel operation  */
-/*     tny_account_cancel (); */
-
-       /* Set new status */
-       priv->status = MODEST_MAIL_OPERATION_STATUS_CANCELED;
-
-       /* Notify about operation end */
-       modest_mail_operation_notify_end (self);
+       thread = g_thread_create (update_account_thread, info, FALSE, NULL);
 
        return TRUE;
 }
 
-guint 
-modest_mail_operation_get_task_done (ModestMailOperation *self)
-{
-       ModestMailOperationPrivate *priv;
-
-       g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), 0);
-
-       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
-       return priv->done;
-}
-
-guint 
-modest_mail_operation_get_task_total (ModestMailOperation *self)
-{
-       ModestMailOperationPrivate *priv;
-
-       g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), 0);
-
-       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
-       return priv->total;
-}
-
-gboolean
-modest_mail_operation_is_finished (ModestMailOperation *self)
-{
-       ModestMailOperationPrivate *priv;
-       gboolean retval = FALSE;
-
-       if (!MODEST_IS_MAIL_OPERATION (self)) {
-               g_warning ("%s: invalid parametter", G_GNUC_FUNCTION);
-               return retval;
-       }
-
-       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
-
-       if (priv->status == MODEST_MAIL_OPERATION_STATUS_SUCCESS   ||
-           priv->status == MODEST_MAIL_OPERATION_STATUS_FAILED    ||
-           priv->status == MODEST_MAIL_OPERATION_STATUS_CANCELED  ||
-           priv->status == MODEST_MAIL_OPERATION_STATUS_FINISHED_WITH_ERRORS) {
-               retval = TRUE;
-       } else {
-               retval = FALSE;
-       }
-
-       return retval;
-}
-
 /* ******************************************************************* */
 /* ************************** STORE  ACTIONS ************************* */
 /* ******************************************************************* */
@@ -909,6 +1131,7 @@ transfer_folder_status_cb (GObject *obj,
        XFerMsgAsyncHelper *helper = NULL;
        ModestMailOperation *self;
        ModestMailOperationPrivate *priv;
+       ModestMailOperationState *state;
 
        g_return_if_fail (status != NULL);
        g_return_if_fail (status->code == TNY_FOLDER_STATUS_CODE_COPY_FOLDER);
@@ -925,7 +1148,9 @@ transfer_folder_status_cb (GObject *obj,
        priv->done = status->position;
        priv->total = status->of_total;
 
-       g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
+       state = modest_mail_operation_clone_state (self);
+       g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, state, NULL);
+       g_slice_free (ModestMailOperationState, state);
 }
 
 
@@ -1122,6 +1347,7 @@ get_msg_status_cb (GObject *obj,
        GetMsgAsyncHelper *helper = NULL;
        ModestMailOperation *self;
        ModestMailOperationPrivate *priv;
+       ModestMailOperationState *state;
 
        g_return_if_fail (status != NULL);
        g_return_if_fail (status->code == TNY_FOLDER_STATUS_CODE_GET_MSG);
@@ -1129,11 +1355,6 @@ get_msg_status_cb (GObject *obj,
        helper = (GetMsgAsyncHelper *) user_data;
        g_return_if_fail (helper != NULL);       
 
-       /* Temporary FIX: useful when tinymail send us status
-          information *after* calling the function callback */
-       if (!MODEST_IS_MAIL_OPERATION (helper->mail_op))
-               return;
-
        self = helper->mail_op;
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
 
@@ -1143,7 +1364,9 @@ get_msg_status_cb (GObject *obj,
        priv->done = 1;
        priv->total = 1;
 
-       g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
+       state = modest_mail_operation_clone_state (self);
+       g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, state, NULL);
+       g_slice_free (ModestMailOperationState, state);
 }
 
 /****************************************************/
@@ -1155,20 +1378,6 @@ typedef struct {
        GDestroyNotify notify;
 } GetFullMsgsInfo;
 
-/* 
- * Used by get_msgs_full_thread to emit the "progress-changed" signal
- * from the main loop. We call it inside an idle call to achieve that
- */
-static gboolean
-notify_get_msgs_full_observers (gpointer data)
-{
-       ModestMailOperation *mail_op = MODEST_MAIL_OPERATION (data);
-
-       g_signal_emit (G_OBJECT (mail_op), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
-
-       return FALSE;
-}
-
 typedef struct {
        GetMsgAsyncUserCallback user_callback;
        TnyHeader *header;
@@ -1243,12 +1452,16 @@ get_msgs_full_thread (gpointer thr_user_data)
                        msg = tny_folder_get_msg (folder, header, &(priv->error));
 
                        if (msg) {
+                               ModestMailOperationState *state;
+                               ModestPair *pair;
+
                                priv->done++;
 
                                /* notify progress */
-                               g_idle_add_full (G_PRIORITY_HIGH_IDLE,
-                                                notify_get_msgs_full_observers, 
-                                                info->mail_op, NULL);
+                               state = modest_mail_operation_clone_state (info->mail_op);
+                               pair = modest_pair_new (g_object_ref (info->mail_op), state, FALSE);
+                               g_idle_add_full (G_PRIORITY_HIGH_IDLE, idle_notify_progress_once,
+                                                pair, (GDestroyNotify) modest_pair_free);
 
                                /* The callback is the responsible for
                                   freeing the message */
@@ -1433,6 +1646,8 @@ transfer_msgs_status_cb (GObject *obj,
        XFerMsgAsyncHelper *helper = NULL;
        ModestMailOperation *self;
        ModestMailOperationPrivate *priv;
+       ModestMailOperationState *state;
+
 
        g_return_if_fail (status != NULL);
        g_return_if_fail (status->code == TNY_FOLDER_STATUS_CODE_XFER_MSGS);
@@ -1449,7 +1664,9 @@ transfer_msgs_status_cb (GObject *obj,
        priv->done = status->position;
        priv->total = status->of_total;
 
-       g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
+       state = modest_mail_operation_clone_state (self);
+       g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, state, NULL);
+       g_slice_free (ModestMailOperationState, state);
 }
 
 
@@ -1602,22 +1819,20 @@ on_refresh_folder_status_update (GObject *obj,
 {
        ModestMailOperation *self;
        ModestMailOperationPrivate *priv;
+       ModestMailOperationState *state;
 
        g_return_if_fail (status != NULL);
        g_return_if_fail (status->code == TNY_FOLDER_STATUS_CODE_REFRESH);
 
-       /* Temporary FIX: useful when tinymail send us status
-          information *after* calling the function callback */
-       if (!MODEST_IS_MAIL_OPERATION (user_data))
-               return;
-
        self = MODEST_MAIL_OPERATION (user_data);
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
 
        priv->done = status->position;
        priv->total = status->of_total;
 
-       g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
+       state = modest_mail_operation_clone_state (self);
+       g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, state, NULL);
+       g_slice_free (ModestMailOperationState, state);
 }
 
 void 
@@ -1653,8 +1868,12 @@ modest_mail_operation_refresh_folder  (ModestMailOperation *self,
 static void
 modest_mail_operation_notify_end (ModestMailOperation *self)
 {
+       ModestMailOperationState *state;
+
        /* Notify the observers about the mail opertation end */
-       g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
+       state = modest_mail_operation_clone_state (self);
+       g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, state, NULL);
+       g_slice_free (ModestMailOperationState, state);
 
        /* Notify the queue */
        modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
index 3928049..5275270 100644 (file)
@@ -65,27 +65,14 @@ typedef enum _ModestMailOperationStatus {
  *
  * The id for identifying the type of mail operation
  */
-typedef enum _ModestMailOperationId {
-       MODEST_MAIL_OPERATION_ID_SEND,
-       MODEST_MAIL_OPERATION_ID_RECEIVE,
-       MODEST_MAIL_OPERATION_ID_OPEN,
-       MODEST_MAIL_OPERATION_ID_DELETE,
-       MODEST_MAIL_OPERATION_ID_INFO,
-       MODEST_MAIL_OPERATION_ID_UNKNOWN,
-} ModestMailOperationId;
-
-
-struct _ModestMailOperation {
-        GObject parent;
-       /* insert public members, if any */
-};
-
-struct _ModestMailOperationClass {
-       GObjectClass parent_class;
-
-       /* Signals */
-       void (*progress_changed) (ModestMailOperation *self, gpointer user_data);
-};
+typedef enum {
+       MODEST_MAIL_OPERATION_TYPE_SEND,
+       MODEST_MAIL_OPERATION_TYPE_RECEIVE,
+       MODEST_MAIL_OPERATION_TYPE_OPEN,
+       MODEST_MAIL_OPERATION_TYPE_DELETE,
+       MODEST_MAIL_OPERATION_TYPE_INFO,
+       MODEST_MAIL_OPERATION_TYPE_UNKNOWN,
+} ModestMailOperationTypeOperation;
 
 /**
  * ErroCheckingAsyncUserCallback:
@@ -127,6 +114,29 @@ typedef void (*GetMsgAsyncUserCallback) (ModestMailOperation *mail_op,
 typedef void (*XferMsgsAsynUserCallback) (const GObject *obj, gpointer user_data);
 
 
+/* This struct represents the internal state of a mail operation in a
+   given time */
+typedef struct {
+       guint      done;
+       guint      total;
+       gboolean   finished;
+       ModestMailOperationStatus        status;
+       ModestMailOperationTypeOperation op_type;               
+} ModestMailOperationState;
+
+
+struct _ModestMailOperation {
+        GObject parent;
+       /* insert public members, if any */
+};
+
+struct _ModestMailOperationClass {
+       GObjectClass parent_class;
+
+       /* Signals */
+       void (*progress_changed) (ModestMailOperation *self, ModestMailOperationState *state, gpointer user_data);
+};
+
 /* member functions */
 GType        modest_mail_operation_get_type    (void) G_GNUC_CONST;
 
@@ -138,7 +148,7 @@ GType        modest_mail_operation_get_type    (void) G_GNUC_CONST;
  * Creates a new instance of class #ModestMailOperation, using parameters
  * to initialize its private structure. @source parameter may be NULL.
  **/
-ModestMailOperation*    modest_mail_operation_new     (ModestMailOperationId id,
+ModestMailOperation*    modest_mail_operation_new     (ModestMailOperationTypeOperation type,
                                                       GObject *source);
 
 /**
@@ -153,11 +163,11 @@ ModestMailOperation*    modest_mail_operation_new     (ModestMailOperationId id,
  * @error_handler can not be NULL, but it will be returned an mail operation
  * object without error handling capability.
  **/
-ModestMailOperation*    modest_mail_operation_new_with_error_handling     (ModestMailOperationId id,
+ModestMailOperation*    modest_mail_operation_new_with_error_handling     (ModestMailOperationTypeOperation op_type,
                                                                           GObject *source,
                                                                           ErrorCheckingUserCallback error_handler);
 /**
- * modest_mail_operation_get_id
+ * modest_mail_operation_execute_error_handler
  * @self: a #ModestMailOperation
  * 
  * Executes error handler, if it exists, passing @self objsect as
@@ -167,14 +177,14 @@ void
 modest_mail_operation_execute_error_handler (ModestMailOperation *self);
 
 /**
- * modest_mail_operation_get_id
+ * modest_mail_operation_get_type_operation
  * @self: a #ModestMailOperation
  * 
- * Gets the private id field of mail operation. This id identifies
- * the class/type of mail operation.  
+ * Gets the private op_type field of mail operation. This op_type
+ * identifies the class/type of mail operation.
  **/
-ModestMailOperationId
-modest_mail_operation_get_id (ModestMailOperation *self);
+ModestMailOperationTypeOperation
+modest_mail_operation_get_type_operation (ModestMailOperation *self);
 
 /**
  * modest_mail_operation_is_mine
@@ -545,6 +555,11 @@ gboolean  modest_mail_operation_cancel          (ModestMailOperation *self);
 void      modest_mail_operation_refresh_folder  (ModestMailOperation *self,
                                                 TnyFolder *folder);
 
+guint     modest_mail_operation_get_id          (ModestMailOperation *self);
+
+guint     modest_mail_operation_set_id          (ModestMailOperation *self,
+                                                guint id);
+
 G_END_DECLS
 
 #endif /* __MODEST_MAIL_OPERATION_H__ */
index ca96b75..030ac4f 100644 (file)
@@ -283,7 +283,7 @@ send_mail (const gchar* account_name,
        from_string = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
                                                          account_name);
 
-       mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND, NULL);
+       mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, NULL);
 
        modest_mail_operation_send_new_mail (mail_operation, account,
                                             from_string, mailto,
index ae159df..4005177 100644 (file)
@@ -217,7 +217,7 @@ headers_action_delete (TnyHeader *header,
 {
        ModestMailOperation *mail_op = NULL;
 
-       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE, G_OBJECT(win));
+       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_DELETE, G_OBJECT(win));
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                         mail_op);
        
@@ -609,7 +609,7 @@ _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
        }
 
        /* Open each message */
-       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT (win));
+       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT (win));
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
        modest_mail_operation_get_msgs_full (mail_op, 
                                             headers, 
@@ -802,7 +802,7 @@ reply_forward (ReplyForwardAction action, ModestWindow *win)
                        reply_forward_cb (NULL, header, msg, rf_helper);
        } else {
                /* Retrieve messages */
-               mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
+               mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(win));
                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
                modest_mail_operation_get_msgs_full (mail_op, 
                                                     header_list, 
@@ -973,7 +973,7 @@ modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
        /* Create the mail operation */
        /* TODO: The spec wants us to first do any pending deletions, before receiving. */
        ModestMailOperation *mail_op;
-       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
+       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(win));
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
        modest_mail_operation_update_account (mail_op, acc_name);
        g_object_unref (G_OBJECT (mail_op));
@@ -1294,7 +1294,7 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
        from = modest_account_mgr_get_from_string (account_mgr, account_name);
 
        /* Create the mail operation */         
-       mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(edit_window));
+       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,
@@ -1362,7 +1362,7 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
        from = modest_account_mgr_get_from_string (account_mgr, account_name);
 
        /* Create the mail operation */         
-       mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND, G_OBJECT(edit_window));
+       mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, G_OBJECT(edit_window));
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
 
        modest_mail_operation_send_new_mail (mail_operation,
@@ -1603,7 +1603,7 @@ modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_windo
                        if (result == GTK_RESPONSE_REJECT) {
                                finished = TRUE;
                        } else {
-                               ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(main_window));
+                               ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO, G_OBJECT(main_window));
                                TnyFolder *new_folder = NULL;
 
                                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
@@ -1664,7 +1664,7 @@ modest_ui_actions_on_rename_folder (GtkAction *action,
                if (folder_name != NULL && strlen (folder_name) > 0) {
                        ModestMailOperation *mail_op;
 
-                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(main_window));
+                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO, G_OBJECT(main_window));
                        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                                         mail_op);
 
@@ -1713,7 +1713,7 @@ delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
        g_free (message);
 
        if (response == GTK_RESPONSE_OK) {
-               ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE, G_OBJECT(main_window));
+               ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_DELETE, G_OBJECT(main_window));
 
                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                                 mail_op);
@@ -2509,7 +2509,7 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
                modest_header_view_set_folder (MODEST_HEADER_VIEW (header_view), NULL); 
 
                if (TNY_IS_FOLDER (src_folder)) {
-                       mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_ID_RECEIVE, 
+                       mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, 
                                                                                 G_OBJECT(win),
                                                                                 move_to_error_checking);
                        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
@@ -2539,7 +2539,7 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
 
                        /* Transfer messages */
                        if (response == GTK_RESPONSE_OK) {
-                               mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
+                               mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(win));
                                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
                                                                 mail_op);
 
@@ -2607,7 +2607,7 @@ modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
                        ModestMailOperation *mail_op;
 
                        /* Create mail op */
-                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
+                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(win));
                        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
                                                         mail_op);
                        
@@ -2736,7 +2736,7 @@ modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
                return;
 
        /* Create mail operation */
-       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT (window));
+       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT (window));
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
        modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
 
index 1c7538e..84aa8e6 100644 (file)
@@ -1156,18 +1156,19 @@ typedef struct _DndHelper {
  * and drop action
  */
 static void
-on_progress_changed (ModestMailOperation *mail_op, gpointer user_data)
+on_progress_changed (ModestMailOperation *mail_op, 
+                    ModestMailOperationState *state,
+                    gpointer user_data)
 {
        gboolean success;
        DndHelper *helper;
 
        helper = (DndHelper *) user_data;
 
-       if (!modest_mail_operation_is_finished (mail_op))
+       if (!state->finished)
                return;
 
-       if (modest_mail_operation_get_status (mail_op) == 
-           MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
+       if (state->status == MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
                success = TRUE;
        } else {
                success = FALSE;
@@ -1212,7 +1213,7 @@ drag_and_drop_from_header_view (GtkTreeModel *source_model,
                            &folder, -1);
 
        /* Transfer message */
-       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, NULL);
+       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, NULL);
 
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                         mail_op);
@@ -1273,7 +1274,7 @@ drag_and_drop_from_folder_view (GtkTreeModel     *source_model,
                            &folder, -1);
 
        /* Do the mail operation */
-       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, NULL);
+       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, NULL);
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
                                         mail_op);
        g_signal_connect (G_OBJECT (mail_op), "progress-changed",
index 469c4cd..1f84bb2 100644 (file)
@@ -906,7 +906,7 @@ modest_header_view_set_folder (ModestHeaderView *self, TnyFolder *folder)
                g_signal_emit (G_OBJECT(self), signals[HEADER_SELECTED_SIGNAL], 0, NULL);
 
                /* Create the mail operation */
-               mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, NULL);
+               mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, NULL);
                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                                 mail_op);