* Added a destroyer to the error handler of the mail operation for the user data
authorSergio Villar Senin <svillar@igalia.com>
Tue, 9 Oct 2007 15:59:46 +0000 (15:59 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Tue, 9 Oct 2007 15:59:46 +0000 (15:59 +0000)
* Fixes NB#63115, show the proper message when opening a mail fails

pmo-trunk-r3479

src/maemo/modest-msg-view-window.c
src/modest-mail-operation.c
src/modest-mail-operation.h
src/modest-ui-actions.c
src/widgets/modest-folder-view.c

index 1b56900..904a218 100644 (file)
@@ -1601,7 +1601,7 @@ message_reader (ModestMsgViewWindow *window,
        /* New mail operation */
        mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(window),
                                                                 modest_ui_actions_get_msgs_full_error_handler, 
-                                                                NULL);
+                                                                NULL, NULL);
                                
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
        modest_mail_operation_get_msg (mail_op, header, view_msg_cb, row_reference);
index 357843f..c67acb8 100644 (file)
@@ -101,6 +101,7 @@ struct _ModestMailOperationPrivate {
        GError                    *error;
        ErrorCheckingUserCallback  error_checking;
        gpointer                   error_checking_user_data;
+       ErrorCheckingUserDataDestroyer error_checking_user_data_destroyer;
        ModestMailOperationStatus  status;      
        ModestMailOperationTypeOperation op_type;
 };
@@ -330,7 +331,8 @@ modest_mail_operation_new (GObject *source)
 ModestMailOperation*
 modest_mail_operation_new_with_error_handling (GObject *source,
                                               ErrorCheckingUserCallback error_handler,
-                                              gpointer user_data)
+                                              gpointer user_data,
+                                              ErrorCheckingUserDataDestroyer error_handler_destroyer)
 {
        ModestMailOperation *obj;
        ModestMailOperationPrivate *priv;
@@ -341,6 +343,7 @@ modest_mail_operation_new_with_error_handling (GObject *source,
        g_return_val_if_fail (error_handler != NULL, obj);
        priv->error_checking = error_handler;
        priv->error_checking_user_data = user_data;
+       priv->error_checking_user_data_destroyer = error_handler_destroyer;
 
        return obj;
 }
@@ -353,6 +356,7 @@ 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);     
 
+       /* Call the user callback */
        if (priv->error_checking != NULL)
                priv->error_checking (self, priv->error_checking_user_data);
 }
@@ -2013,42 +2017,31 @@ modest_mail_operation_get_msg (ModestMailOperation *self,
        priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
        priv->op_type = MODEST_MAIL_OPERATION_TYPE_RECEIVE;
 
-       /* Get message from folder */
-       if (folder) {
-               /* Get account and set it into mail_operation */
-               priv->account = modest_tny_folder_get_account (TNY_FOLDER(folder));
+       /* Get account and set it into mail_operation */
+       priv->account = modest_tny_folder_get_account (TNY_FOLDER(folder));
+       
+       /* Check for cached messages */
+       if (tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED)
+               priv->op_type = MODEST_MAIL_OPERATION_TYPE_OPEN;
+       else 
+               priv->op_type = MODEST_MAIL_OPERATION_TYPE_RECEIVE;
+       
+       helper = g_slice_new0 (GetMsgAsyncHelper);
+       helper->mail_op = self;
+       helper->user_callback = user_callback;
+       helper->user_data = user_data;
+       helper->header = g_object_ref (header);
                
-               /* Check for cached messages */
-               if (tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED)
-                       priv->op_type = MODEST_MAIL_OPERATION_TYPE_OPEN;
-               else 
-                       priv->op_type = MODEST_MAIL_OPERATION_TYPE_RECEIVE;
-
-               helper = g_slice_new0 (GetMsgAsyncHelper);
-               helper->mail_op = self;
-               helper->user_callback = user_callback;
-               helper->user_data = user_data;
-               helper->header = g_object_ref (header);
-
-               // The callback's reference so that the mail op is not
-               // finalized until the async operation is completed even if
-               // the user canceled the request meanwhile.
-               g_object_ref (G_OBJECT (helper->mail_op));
-
-               modest_mail_operation_notify_start (self);
-               tny_folder_get_msg_async (folder, header, get_msg_cb, get_msg_status_cb, helper);
+       /* The callback's reference so that the mail op is not
+        * finalized until the async operation is completed even if
+        * the user canceled the request meanwhile.
+        */
+       g_object_ref (G_OBJECT (helper->mail_op));
 
-               g_object_unref (G_OBJECT (folder));
-       } else {
-               /* Set status failed and set an error */
-               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 get a message. No folder found for header"));
+       modest_mail_operation_notify_start (self);
+       tny_folder_get_msg_async (folder, header, get_msg_cb, get_msg_status_cb, helper);
 
-               /* Notify the queue */
-               modest_mail_operation_notify_end (self);
-       }
+       g_object_unref (G_OBJECT (folder));
 }
 
 static void
@@ -2862,6 +2855,10 @@ modest_mail_operation_notify_end (ModestMailOperation *self)
           not wrapp this emission because we assume that this
           function is always called from within the main lock */
        g_signal_emit (G_OBJECT (self), signals[OPERATION_FINISHED_SIGNAL], 0, NULL);
+
+       /* Remove the error user data */
+       if (priv->error_checking_user_data && priv->error_checking_user_data_destroyer)
+               priv->error_checking_user_data_destroyer (priv->error_checking_user_data);
 }
 
 TnyAccount *
index 70c3678..4c60822 100644 (file)
@@ -76,7 +76,7 @@ typedef enum {
 } ModestMailOperationTypeOperation;
 
 /**
- * ErrorCheckingAsyncUserCallback:
+ * ErrorCheckingUserCallback:
  *
  * @mail_op: the current mail operation.
  * @user_data: generic data passed to user defined function.
@@ -87,6 +87,17 @@ typedef enum {
 typedef void (*ErrorCheckingUserCallback) (ModestMailOperation *mail_op, gpointer user_data);
 
 /**
+ * ErrorCheckingUserDataDestroyer:
+ *
+ * @user_data: generic data passed to user defined function.
+ *
+ * This function is used to destroy the user_data passed to the error
+ * checking user callback function
+ */
+typedef void (*ErrorCheckingUserDataDestroyer) (gpointer user_data);
+
+
+/**
  * GetMsgAsyncUserCallback:
  *
  * @mail_op: the current #ModestMailOperation.
@@ -227,7 +238,8 @@ ModestMailOperation*    modest_mail_operation_new     (GObject *source);
  **/
 ModestMailOperation*    modest_mail_operation_new_with_error_handling     (GObject *source,
                                                                           ErrorCheckingUserCallback error_handler,
-                                                                          gpointer user_data);
+                                                                          gpointer user_data,
+                                                                          ErrorCheckingUserDataDestroyer error_handler_destroyer);
 /**
  * modest_mail_operation_execute_error_handler
  * @self: a #ModestMailOperation
index 15dcff7..f4522e9 100644 (file)
@@ -978,6 +978,20 @@ cleanup:
        g_object_unref (folder);
 }
 
+
+static void
+open_msg_error_handler (ModestMailOperation *mail_op,
+                       gpointer user_data)
+{
+       /* Show the message error */
+       GObject *win = modest_mail_operation_get_source (mail_op);
+
+       modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, 
+                                               (gchar *) user_data);
+       if (win)
+               g_object_unref (win);
+}
+
 void
 modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
                                               gpointer user_data)
@@ -1134,11 +1148,12 @@ _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
        iter_not_opened = NULL;
 
        /* Create the mail operation */
-       mail_op = modest_mail_operation_new_with_error_handling (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);
        if (tny_list_get_length (not_opened_headers) > 1) {
+               mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win), 
+                                                                        modest_ui_actions_get_msgs_full_error_handler, 
+                                                                        NULL, NULL);
+               modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
+               
                modest_mail_operation_get_msgs_full (mail_op, 
                                                     not_opened_headers, 
                                                     open_msg_cb, 
@@ -1147,7 +1162,32 @@ _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
        } else {
                TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
                TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
+               const gchar *proto_name;
+               gchar *error_msg;
+               ModestTransportStoreProtocol proto;
+
+               /* Get the error message depending on the protocol */
+               proto_name = tny_account_get_proto (account);
+               proto = modest_protocol_info_get_transport_store_protocol (proto_name);
+               
+               if (proto == MODEST_PROTOCOL_STORE_POP) {
+                       error_msg = g_strdup (_("emev_ni_ui_pop3_msg_recv_error"));
+               } else if (proto == MODEST_PROTOCOL_STORE_IMAP) {
+                       error_msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
+                                                    tny_header_get_subject (header));
+               } else {
+                       error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
+               }
+
+               /* Create and call the mail operation */
+               mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win), 
+                                                                        open_msg_error_handler, 
+                                                                        error_msg,
+                                                                        g_free);
+               modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
+
                modest_mail_operation_get_msg (mail_op, header, open_msg_cb, NULL);
+
                g_object_unref (header);
                g_object_unref (iter);
        }
@@ -1434,10 +1474,10 @@ reply_forward (ReplyForwardAction action, ModestWindow *win)
                if (header) {
                        /* Retrieve messages */
                        if (do_retrieve) {
-                               mail_op = modest_mail_operation_new_with_error_handling (
-                                       G_OBJECT(win),
-                                       modest_ui_actions_get_msgs_full_error_handler, 
-                                       NULL);
+                               mail_op = 
+                                       modest_mail_operation_new_with_error_handling (G_OBJECT(win),
+                                                                                      modest_ui_actions_get_msgs_full_error_handler, 
+                                                                                      NULL, NULL);
                                modest_mail_operation_queue_add (
                                        modest_runtime_get_mail_operation_queue (), mail_op);
                                
@@ -1644,7 +1684,7 @@ modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
 
        mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
                                                                 modest_ui_actions_send_receive_error_handler,
-                                                                NULL);
+                                                                NULL, NULL);
 
        g_signal_connect (G_OBJECT(mail_op), "operation-finished", 
                          G_CALLBACK (on_send_receive_finished), 
@@ -2505,7 +2545,7 @@ modest_ui_actions_create_folder(GtkWidget *parent_window,
 
                                mail_op  = modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
                                                                                          modest_ui_actions_new_folder_error_handler,
-                                                                                         parent_window);
+                                                                                         parent_window, NULL);
 
                                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
                                                                 mail_op);
@@ -2625,7 +2665,7 @@ modest_ui_actions_on_rename_folder (GtkAction *action,
                        mail_op = 
                                modest_mail_operation_new_with_error_handling (G_OBJECT(main_window),
                                                                               modest_ui_actions_rename_folder_error_handler,
-                                                                              main_window);
+                                                                              main_window, NULL);
 
                        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                                         mail_op);
@@ -2715,7 +2755,7 @@ delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
                mail_op =
                        modest_mail_operation_new_with_error_handling (G_OBJECT(main_window),
                                                                       modest_ui_actions_delete_folder_error_handler,
-                                                                      NULL);
+                                                                      NULL, NULL);
 
                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                                 mail_op);
@@ -4160,7 +4200,7 @@ modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
                modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header);
                mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
                                                                         modest_ui_actions_get_msgs_full_error_handler,
-                                                                        NULL);
+                                                                        NULL, NULL);
                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
                modest_mail_operation_get_msg (mail_op, header, open_msg_for_purge_cb, win);
                
@@ -4233,7 +4273,7 @@ modest_ui_actions_xfer_messages_from_move_to (TnyFolderStore *dst_folder,
        ModestMailOperation *mail_op = 
                modest_mail_operation_new_with_error_handling (G_OBJECT(win),
                                                               modest_ui_actions_move_folder_error_handler,
-                                                              NULL);
+                                                              NULL, NULL);
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
                                         mail_op);
 
@@ -4306,7 +4346,7 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
                         mail_op =
                           modest_mail_operation_new_with_error_handling (G_OBJECT(win),
                                                                          modest_ui_actions_move_folder_error_handler,
-                                                                         src_folder);
+                                                                         src_folder, NULL);
                         modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                                          mail_op);
 
@@ -4595,7 +4635,7 @@ modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
        /* Create mail operation */
        mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (window),
                                                                 modest_ui_actions_get_msgs_full_error_handler, 
-                                                                NULL);
+                                                                NULL, 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);
 
index c718fb5..9e47f22 100644 (file)
@@ -1641,7 +1641,7 @@ drag_and_drop_from_header_view (GtkTreeModel *source_model,
        /* Transfer messages */
        mail_op = modest_mail_operation_new_with_error_handling (NULL,
                                                                 modest_ui_actions_move_folder_error_handler,
-                                                                NULL);
+                                                                NULL, NULL);
 
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                         mail_op);
@@ -1735,7 +1735,7 @@ drag_and_drop_from_folder_view (GtkTreeModel     *source_model,
                mail_op = 
                        modest_mail_operation_new_with_error_handling (G_OBJECT (modest_window_mgr_get_main_window (mgr)),
                                                                       modest_ui_actions_move_folder_error_handler,
-                                                                      folder);
+                                                                      folder, NULL);
 
                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
                                                 mail_op);