* maemo/modest-main-window.c:
authorJavier Fernandez Garcia-Boente <jfernandez@igalia.com>
Fri, 18 May 2007 14:17:48 +0000 (14:17 +0000)
committerJavier Fernandez Garcia-Boente <jfernandez@igalia.com>
Fri, 18 May 2007 14:17:48 +0000 (14:17 +0000)
  - use mail_operation error handling capabilities when
   operation os removed from queue.
* modest-mail-operation.c:
  - folder_copy_async works fine now.
  - added a new private field, error_handler to perfomrs
    required operations during an error state.
* modest-ui-actions.c
  - use a mail operation with error handling capabilities
   to perform copy_async operation.
  - get message header from tree model, when message is
   deleted using toolitem of viewer view. (Fixes: #NB55370)

pmo-trunk-r1912

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

index 0d137bd..1d67a75 100644 (file)
@@ -1397,6 +1397,7 @@ on_queue_changed (ModestMailOperationQueue *queue,
        ModestToolBarModes mode;
        GSList *tmp;
        gboolean mode_changed = FALSE;
+       ModestMailOperationStatus status;
 
        g_return_if_fail (MODEST_IS_MAIN_WINDOW (self));
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
@@ -1431,6 +1432,12 @@ 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) {
                                modest_progress_object_remove_operation (MODEST_PROGRESS_OBJECT (tmp->data),
@@ -1444,8 +1451,10 @@ on_queue_changed (ModestMailOperationQueue *queue,
                                
                        }
                }
+
                break;
        }       
+
 }
 
 static void 
index 6a58e85..4ca932b 100644 (file)
@@ -41,6 +41,7 @@
 #include <tny-status.h>
 #include <camel/camel-stream-mem.h>
 #include <glib/gi18n.h>
+#include "modest-platform.h"
 #include <modest-tny-account.h>
 #include <modest-tny-send-queue.h>
 #include <modest-runtime.h>
@@ -84,6 +85,7 @@ struct _ModestMailOperationPrivate {
        ModestMailOperationStatus  status;      
        ModestMailOperationId      id;          
        GObject                   *source;
+       ErrorCheckingUserCallback  error_checking;
        GError                    *error;
 };
 
@@ -225,6 +227,35 @@ modest_mail_operation_new (ModestMailOperationId id,
        return obj;
 }
 
+ModestMailOperation*
+modest_mail_operation_new_with_error_handling (ModestMailOperationId id,
+                                              GObject *source,
+                                              ErrorCheckingUserCallback error_handler)
+{
+       ModestMailOperation *obj;
+       ModestMailOperationPrivate *priv;
+               
+       obj = modest_mail_operation_new (id, source);
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
+       
+       g_return_val_if_fail (error_handler != NULL, obj);
+       priv->error_checking = error_handler;
+
+       return obj;
+}
+
+void
+modest_mail_operation_execute_error_handler (ModestMailOperation *self)
+{
+       ModestMailOperationPrivate *priv;
+       
+       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);
+}
+
 
 ModestMailOperationId
 modest_mail_operation_get_id (ModestMailOperation *self)
@@ -833,7 +864,6 @@ modest_mail_operation_rename_folder (ModestMailOperation *self,
                             _("FIXME: unable to rename"));
        } else {
                /* Rename. Camel handles folder subscription/unsubscription */
-
                TnyFolderStore *into;
                TnyFolder *nfol;
 
@@ -845,6 +875,7 @@ modest_mail_operation_rename_folder (ModestMailOperation *self,
                        g_object_unref (nfol);
 
                CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED);
+               
        }
 
        /* Notify the queue */
@@ -904,19 +935,20 @@ transfer_folder_cb (TnyFolder *folder, TnyFolderStore *into, gboolean cancelled,
        } else if (cancelled) {
                priv->status = MODEST_MAIL_OPERATION_STATUS_CANCELED;
                g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
-                            MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
-                            _("Error trying to refresh the contents of %s"),
+                            MODEST_MAIL_OPERATION_ERROR_OPERATION_CANCELED,
+                            _("Transference of %s was cancelled."),
                             tny_folder_get_name (folder));
        } else {
                priv->done = 1;
                priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
        }
-
+               
        /* Free */
        g_slice_free   (XFerFolderAsyncHelper, helper);
        g_object_unref (folder);
        g_object_unref (into);
-       g_object_unref (new_folder);
+       if (new_folder != NULL) 
+               g_object_unref (new_folder);
 
        /* Notify the queue */
        modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
index 77cbb83..caae5fb 100644 (file)
@@ -88,6 +88,17 @@ struct _ModestMailOperationClass {
 };
 
 /**
+ * ErroCheckingAsyncUserCallback:
+ *
+ * @obj: a #GObject generic object which has created 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);
+
+/**
  * GetMsgAsynUserCallback:
  *
  * @obj: a #GObject generic object which has created current mail operation.
@@ -128,6 +139,31 @@ ModestMailOperation*    modest_mail_operation_new     (ModestMailOperationId id,
                                                       GObject *source);
 
 /**
+ * modest_mail_operation_new_with_error_handling:
+ * @id: a #ModestMailOperationId identification of operation type.
+ * @source: a #GObject which creates this new operation.
+ * @error_handler: a #ErrorCheckingUserCallback function to performs operations when 
+ * an error occurs.
+ * 
+ * Creates a new instance of class #ModestMailOperation, using parameters
+ * to initialize its private structure. @source parameter may be NULL. 
+ * @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,
+                                                                          GObject *source,
+                                                                          ErrorCheckingUserCallback error_handler);
+/**
+ * modest_mail_operation_get_id
+ * @self: a #ModestMailOperation
+ * 
+ * Executes error handler, if it exists, passing @self objsect as
+ * user_data argument of error handling function. 
+ **/
+void
+modest_mail_operation_execute_error_handler (ModestMailOperation *self);
+
+/**
  * modest_mail_operation_get_id
  * @self: a #ModestMailOperation
  * 
@@ -332,6 +368,23 @@ TnyFolder*    modest_mail_operation_xfer_folder    (ModestMailOperation *self,
 
 
 
+/**
+ * modest_mail_operation_xfer_folder:
+ * @self: a #ModestMailOperation
+ * @folder: a #TnyFolder
+ * @parent: the new parent of the folder as #TnyFolderStore
+ * @delete_original: wheter or not delete the original folder
+ * 
+ * Sets the given @folder as child of a provided #TnyFolderStore. This
+ * operation also transfers all the messages contained in the folder
+ * and all of his children folders with their messages as well. This
+ * operation is synchronous, so the #ModestMailOperation should not be
+ * added to any #ModestMailOperationQueue.
+ *
+ * If @delete_original is TRUE this function moves the original
+ * folder, if it is FALSE the it just copies it
+ *
+ **/
 void    modest_mail_operation_xfer_folder_async    (ModestMailOperation *self,
                                                    TnyFolder *folder, 
                                                    TnyFolderStore *parent,
index 8e10f80..52b5e4f 100644 (file)
@@ -157,17 +157,16 @@ get_selected_headers (ModestWindow *win)
                
        } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
                /* for MsgViewWindows, we simply return a list with one element */
-               TnyMsg *msg;
                TnyHeader *header;
                TnyList *list = NULL;
                
-               msg  = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
-               if (msg) {
-                       header = tny_msg_get_header (msg);
+               header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
+               if (header != NULL) {
                        list = tny_simple_list_new ();
                        tny_list_prepend (list, G_OBJECT(header));
                        g_object_unref (G_OBJECT(header));
                }
+
                return list;
 
        } else
@@ -2367,6 +2366,19 @@ tranasfer_msgs_from_viewer_cb (const GObject *object, gpointer user_data)
        g_return_if_fail (found);
 }
 
+static void
+move_to_error_checking (const GObject *obj, gpointer user_data)
+{
+       ModestWindow *win = NULL;
+       
+       g_return_if_fail (MODEST_IS_WINDOW (obj));
+       win = MODEST_WINDOW (obj);
+
+       /* TODO: show error message */
+/*     modest_platform_run_information_dialog (GTK_WINDOW (win), */
+/*                                             _("mail_in_ui_folder_move_target_error")); */
+}
+
 /*
  * UI handler for the "Move to" action when invoked from the
  * ModestMainWindow
@@ -2375,9 +2387,10 @@ static void
 modest_ui_actions_on_main_window_move_to (GtkAction *action, 
                                          ModestMainWindow *win)
 {
-       GtkWidget *dialog, *folder_view, *tree_view = NULL;
+       GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
+       GtkWidget *header_view = NULL;
        gint result;
-       TnyFolderStore *folder_store;
+       TnyFolderStore *folder_store = NULL;
        ModestMailOperation *mail_op = NULL;
 
        g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
@@ -2386,6 +2399,10 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
        folder_view = modest_main_window_get_child_widget (win,
                                                           MODEST_WIDGET_TYPE_FOLDER_VIEW);
 
+       /* Get header view */
+       header_view = modest_main_window_get_child_widget (win,
+                                                          MODEST_WIDGET_TYPE_HEADER_VIEW);
+
        /* Create and run the dialog */
        dialog = create_move_to_dialog (MODEST_WINDOW (win), folder_view, &tree_view);
        result = gtk_dialog_run (GTK_DIALOG(dialog));
@@ -2405,8 +2422,13 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
                TnyFolderStore *src_folder;
                src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
 
+               /* Clean folder on header view before moving it */
+               modest_header_view_set_folder (MODEST_HEADER_VIEW (header_view), NULL); 
+
                if (TNY_IS_FOLDER (src_folder)) {
-                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
+                       mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_ID_RECEIVE, 
+                                                                                G_OBJECT(win),
+                                                                                move_to_error_checking);
                        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
                                                         mail_op);
 
@@ -2420,9 +2442,6 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
                /* Frees */
                g_object_unref (G_OBJECT (src_folder));
        } else {
-               GtkWidget *header_view;
-               header_view = modest_main_window_get_child_widget (win,
-                                                                  MODEST_WIDGET_TYPE_HEADER_VIEW);
                if (gtk_widget_is_focus (header_view)) {
                        TnyList *headers;
                        gint response;
index c91d4db..e16e202 100644 (file)
@@ -1054,11 +1054,11 @@ drag_and_drop_from_folder_view (GtkTreeModel     *source_model,
        g_signal_connect (G_OBJECT (mail_op), "progress-changed",
                          G_CALLBACK (on_progress_changed), helper);
 
-       modest_mail_operation_xfer_folder (mail_op, 
-                                          folder, 
-                                          parent_folder,
-                                          helper->delete_source);
-
+       modest_mail_operation_xfer_folder_async (mail_op, 
+                                                folder, 
+                                                parent_folder,
+                                                helper->delete_source);
+       
        /* Frees */
        g_object_unref (G_OBJECT (parent_folder));
        g_object_unref (G_OBJECT (folder));
@@ -1091,9 +1091,9 @@ on_drag_data_received (GtkWidget *widget,
        /* Do not allow further process */
        g_signal_stop_emission_by_name (widget, "drag-data-received");
 
-       /* Get the action */
-       if (context->action == GDK_ACTION_MOVE)
-               delete_source = TRUE;
+       /* Get the action (FIXME: only copy is currently implemented */
+/*     if (context->action == GDK_ACTION_MOVE) */
+/*             delete_source = TRUE; */
 
        /* Check if the get_data failed */
        if (selection_data == NULL || selection_data->length < 0)