* Fixes NB#57522
authorSergio Villar Senin <svillar@igalia.com>
Tue, 29 May 2007 17:12:03 +0000 (17:12 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Tue, 29 May 2007 17:12:03 +0000 (17:12 +0000)
        * Slightly modified the mail operations error handler signature
        * Added the code that launches the mail operation error handlers
        * Added information note that is shown when the message size limit is exceeded

pmo-trunk-r1989

src/maemo/modest-main-window.c
src/modest-mail-operation-queue.c
src/modest-mail-operation.c
src/modest-mail-operation.h
src/modest-ui-actions.c

index ef562e5..1df7e28 100644 (file)
@@ -1545,11 +1545,6 @@ on_queue_changed (ModestMailOperationQueue *queue,
                }
                break;
        case MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED:
-               /* If mail_op is mine, check errors */
-/*             status = modest_mail_operation_get_status (mail_op); */
-/*             if (status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) */
-/*                     modest_mail_operation_execute_error_handler (mail_op); */
-
                /* Change toolbar mode */
                if (mode == TOOLBAR_MODE_TRANSFER) {                    
                        while (tmp) {
index 4ca6236..981417a 100644 (file)
@@ -187,6 +187,7 @@ modest_mail_operation_queue_remove (ModestMailOperationQueue *self,
                                    ModestMailOperation *mail_op)
 {
        ModestMailOperationQueuePrivate *priv;
+       ModestMailOperationStatus status;
 
        g_return_if_fail (MODEST_IS_MAIL_OPERATION_QUEUE (self));
        g_return_if_fail (MODEST_IS_MAIL_OPERATION (mail_op));
@@ -197,18 +198,15 @@ modest_mail_operation_queue_remove (ModestMailOperationQueue *self,
        g_queue_remove (priv->op_queue, mail_op);
        g_mutex_unlock (priv->queue_lock);
 
-       /* Debug code */
-       {
-               const GError *err;
-               err = modest_mail_operation_get_error (mail_op);
-               if (err)
-                       g_printerr ("Error in %s: %s\n", __FUNCTION__, err->message);
-       }
-
        /* Notify observers */
        g_signal_emit (self, signals[QUEUE_CHANGED_SIGNAL], 0,
                       mail_op, MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED);
 
+       /* Check errors */
+       status = modest_mail_operation_get_status (mail_op);
+       if (status != MODEST_MAIL_OPERATION_STATUS_SUCCESS)
+               modest_mail_operation_execute_error_handler (mail_op);
+
        /* Free object */
        modest_runtime_verify_object_last_ref (mail_op, "");
        g_object_unref (G_OBJECT (mail_op));
index fe628e7..363a043 100644 (file)
@@ -87,6 +87,7 @@ struct _ModestMailOperationPrivate {
        GObject                   *source;
        GError                    *error;
        ErrorCheckingUserCallback  error_checking;
+       gpointer                   error_checking_user_data;
        ModestMailOperationStatus  status;      
        ModestMailOperationTypeOperation op_type;
 };
@@ -183,10 +184,11 @@ modest_mail_operation_init (ModestMailOperation *obj)
        priv->status         = MODEST_MAIL_OPERATION_STATUS_INVALID;
        priv->op_type        = MODEST_MAIL_OPERATION_TYPE_UNKNOWN;
        priv->error          = NULL;
-       priv->error_checking = NULL;
        priv->done           = 0;
        priv->total          = 0;
        priv->source         = NULL;
+       priv->error_checking = NULL;
+       priv->error_checking_user_data = NULL;
 }
 
 static void
@@ -233,7 +235,8 @@ modest_mail_operation_new (ModestMailOperationTypeOperation op_type,
 ModestMailOperation*
 modest_mail_operation_new_with_error_handling (ModestMailOperationTypeOperation op_type,
                                               GObject *source,
-                                              ErrorCheckingUserCallback error_handler)
+                                              ErrorCheckingUserCallback error_handler,
+                                              gpointer user_data)
 {
        ModestMailOperation *obj;
        ModestMailOperationPrivate *priv;
@@ -255,9 +258,8 @@ 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; 
-       priv->error_checking (priv->source, self);
+       if (priv->error_checking != NULL)
+               priv->error_checking (self, priv->error_checking_user_data);
 }
 
 
@@ -1637,8 +1639,8 @@ modest_mail_operation_get_msgs_full (ModestMailOperation *self,
                priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
                /* FIXME: the error msg is different for pop */
                g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
-                            MODEST_MAIL_OPERATION_ERROR_BAD_PARAMETER,
-                            _("emev_ni_ui_imap_msg_sizelimit_error"));
+                            MODEST_MAIL_OPERATION_ERROR_SIZE_LIMIT,
+                            _("emev_ni_ui_imap_msg_size_exceed_error"));
                /* Remove from queue and free resources */
                modest_mail_operation_notify_end (self);
                if (notify)
index 5275270..9b3d16f 100644 (file)
@@ -75,15 +75,15 @@ typedef enum {
 } ModestMailOperationTypeOperation;
 
 /**
- * ErroCheckingAsyncUserCallback:
+ * ErrorCheckingAsyncUserCallback:
  *
- * @obj: a #GObject generic object which has created current mail operation.
+ * @mail_op: the current mail operation.
  * @user_data: generic data passed to user defined function.
  *
  * This function implements required actions to performs under error
  * states.  
  */
-typedef void (*ErrorCheckingUserCallback) (const GObject *obj, gpointer user_data);
+typedef void (*ErrorCheckingUserCallback) (ModestMailOperation *mail_op, gpointer user_data);
 
 /**
  * GetMsgAsyncUserCallback:
@@ -165,13 +165,15 @@ ModestMailOperation*    modest_mail_operation_new     (ModestMailOperationTypeOp
  **/
 ModestMailOperation*    modest_mail_operation_new_with_error_handling     (ModestMailOperationTypeOperation op_type,
                                                                           GObject *source,
-                                                                          ErrorCheckingUserCallback error_handler);
+                                                                          ErrorCheckingUserCallback error_handler,
+                                                                          gpointer user_data);
 /**
  * modest_mail_operation_execute_error_handler
  * @self: a #ModestMailOperation
  * 
- * Executes error handler, if it exists, passing @self objsect as
- * user_data argument of error handling function. 
+ * Executes error handler if exists. The error handler is the one that
+ * MUST free the user data passed to the
+ * modest_mail_operation_new_with_error_handling constructor
  **/
 void
 modest_mail_operation_execute_error_handler (ModestMailOperation *self);
index 45321f1..a1b6a7c 100644 (file)
@@ -38,7 +38,7 @@
 #include <modest-tny-msg.h>
 #include <modest-tny-account.h>
 #include <modest-address-book.h>
-
+#include "modest-error.h"
 #include "modest-ui-actions.h"
 
 #include "modest-tny-platform-factory.h"
@@ -590,6 +590,23 @@ open_msg_cb (ModestMailOperation *mail_op,
 }
 
 /*
+ * This function is the error handler of the
+ * modest_mail_operation_get_msgs_full operation
+ */
+static void
+modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
+                                              gpointer user_data)
+{
+       const GError *error;
+
+       error = modest_mail_operation_get_error (mail_op);
+       if (error->code == MODEST_MAIL_OPERATION_ERROR_SIZE_LIMIT) {
+               modest_platform_run_information_dialog (GTK_WINDOW (modest_mail_operation_get_source (mail_op)),
+                                                       error->message);
+       }
+}
+
+/*
  * This function is used by both modest_ui_actions_on_open and
  * modest_ui_actions_on_header_activated. This way we always do the
  * same when trying to open messages.
@@ -620,7 +637,10 @@ _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
        }
 
        /* Open each message */
-       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT (win));
+       mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, 
+                                                                G_OBJECT (win), 
+                                                                modest_ui_actions_get_msgs_full_error_handler, 
+                                                                NULL);
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
        modest_mail_operation_get_msgs_full (mail_op, 
                                             headers, 
@@ -868,7 +888,10 @@ 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_TYPE_RECEIVE, G_OBJECT(win));
+               mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, 
+                                                                        G_OBJECT(win),
+                                                                        modest_ui_actions_get_msgs_full_error_handler, 
+                                                                        NULL);
                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
                modest_mail_operation_get_msgs_full (mail_op, 
                                                     header_list, 
@@ -2765,7 +2788,10 @@ modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
                return;
 
        /* Create mail operation */
-       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT (window));
+       mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, 
+                                                                G_OBJECT (window),
+                                                                modest_ui_actions_get_msgs_full_error_handler, 
+                                                                NULL);
        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);