* Migrated the Dnd of folders to use the new connect_and_perform
authorSergio Villar Senin <svillar@igalia.com>
Tue, 13 Nov 2007 11:31:55 +0000 (11:31 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Tue, 13 Nov 2007 11:31:55 +0000 (11:31 +0000)
* Show an error if move folder fails even if the mail operation has no source

pmo-trunk-r3719

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

index 89a5f41..5d583b1 100644 (file)
@@ -1027,7 +1027,6 @@ modest_main_window_on_show (GtkWidget *self, gpointer user_data)
        
        priv->folder_view = MODEST_FOLDER_VIEW (modest_platform_create_folder_view (NULL));
        wrap_in_scrolled_window (folder_win, GTK_WIDGET(priv->folder_view));
-/*     wrap_in_scrolled_window (priv->contents_widget, GTK_WIDGET(priv->header_view)); */
 
        gtk_widget_show (GTK_WIDGET (priv->folder_view));
 
@@ -1045,12 +1044,6 @@ modest_main_window_on_show (GtkWidget *self, gpointer user_data)
        /* Restore window & widget settings */  
        restore_settings (MODEST_MAIN_WINDOW(self), TRUE);
 
-/*     /\* The UI spec wants us to show a connection dialog when the application is  */
-/*      * started by the user, if there is no connection. */
-/*      * Do this before showing the account wizard,  */
-/*      * because wizard needs a connection to discover capabilities. *\/ */
-/*      modest_platform_connect_and_wait (GTK_WINDOW (self), NULL); */
-        
        /* Check if accounts exist and show the account wizard if not */
        gboolean accounts_exist = 
                modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
index e54bb20..d92d4ae 100644 (file)
@@ -1963,8 +1963,10 @@ modest_platform_connect_and_perform_if_network_account (GtkWindow *parent_window
 }
  
 void
-modest_platform_connect_and_perform_if_network_folderstore (GtkWindow *parent_window, TnyFolderStore *folder_store, 
-                                                           ModestConnectedPerformer callback, gpointer user_data)
+modest_platform_connect_and_perform_if_network_folderstore (GtkWindow *parent_window, 
+                                                           TnyFolderStore *folder_store, 
+                                                           ModestConnectedPerformer callback, 
+                                                           gpointer user_data)
 {
        if (!folder_store) {
  
index ae35380..29d7f87 100644 (file)
@@ -41,7 +41,7 @@
 #include <modest-address-book.h>
 #include "modest-error.h"
 #include "modest-ui-actions.h"
-
+#include "modest-protocol-info.h"
 #include "modest-tny-platform-factory.h"
 #include "modest-platform.h"
 #include <tny-mime-part.h>
@@ -4062,10 +4062,9 @@ modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
 
        /* Show notification dialog */
        win = modest_mail_operation_get_source (mail_op);
-       if (G_IS_OBJECT (win)) {
-               modest_platform_run_information_dialog (GTK_WINDOW (win), message);
+       modest_platform_run_information_dialog ((GtkWindow *) win, message);
+       if (win)
                g_object_unref (win);
-       }
 }
 
 void
@@ -4930,3 +4929,37 @@ modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
        if (selected_folder != NULL)
                g_object_unref (selected_folder);
 }
+
+void 
+modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
+                                              TnyAccount *account)
+{
+       ModestTransportStoreProtocol proto;
+       const gchar *proto_name;
+       gchar *error_note = NULL;
+       
+       proto_name = tny_account_get_proto (account);
+       proto = modest_protocol_info_get_transport_store_protocol (proto_name);
+       
+       switch (proto) {
+       case MODEST_PROTOCOL_STORE_POP:
+               error_note = g_strdup_printf (_("emev_ni_ui_pop3_msg_connect_error"), 
+                                             tny_account_get_hostname (account));
+               break;
+       case MODEST_PROTOCOL_STORE_IMAP:
+               error_note = g_strdup_printf (_("emev_ni_ui_imap_connect_server_error"), 
+                                             tny_account_get_hostname (account));
+               break;
+       case MODEST_PROTOCOL_STORE_MAILDIR:
+       case MODEST_PROTOCOL_STORE_MBOX:
+               error_note = g_strdup (_("emev_nc_mailbox_notavailable"));
+               break;
+       default:
+               g_warning ("%s: This should not be reached", __FUNCTION__);
+       }
+
+       if (error_note) {
+               modest_platform_run_information_dialog (parent_window, error_note);
+               g_free (error_note);
+       }
+}
index 99ba265..89679f5 100644 (file)
@@ -485,13 +485,16 @@ void modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_qu
  * @param body_str Body of the message (without signature), or NULL
  * @param attachments List of file URIs to attach
  */
-void modest_ui_actions_compose_msg(ModestWindow *win,
-                                  const gchar *to_str,
-                                  const gchar *cc_str,
-                                  const gchar *bcc_str,
-                                  const gchar *subject_str,
-                                  const gchar *body_str,
-                                  GSList *attachments);
+void modest_ui_actions_compose_msg (ModestWindow *win,
+                                   const gchar *to_str,
+                                   const gchar *cc_str,
+                                   const gchar *bcc_str,
+                                   const gchar *subject_str,
+                                   const gchar *body_str,
+                                   GSList *attachments);
+
+void modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
+                                                   TnyAccount *account);
 
 G_END_DECLS
 #endif /* __MODEST_UI_ACTIONS_H__ */
index 8be8c19..b400c29 100644 (file)
@@ -903,14 +903,19 @@ free_pixbufs (ThreePixbufs *pixbufs)
 }
 
 static void
-icon_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
-                GtkTreeModel *tree_model,  GtkTreeIter *iter, gpointer data)
+icon_cell_data  (GtkTreeViewColumn *column,  
+                GtkCellRenderer *renderer,
+                GtkTreeModel *tree_model,  
+                GtkTreeIter *iter, 
+                gpointer data)
 {
-       GObject *rendobj = (GObject *) renderer, *instance = NULL;
+       GObject *rendobj = NULL, *instance = NULL;
        TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN;
        gboolean has_children;
        ThreePixbufs *pixbufs;
 
+       rendobj = (GObject *) renderer;
+
        gtk_tree_model_get (tree_model, iter,
                            TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
                            TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance,
@@ -1884,6 +1889,13 @@ typedef struct _DndHelper {
        guint time;
 } DndHelper;
 
+static void
+dnd_helper_destroyer (DndHelper *helper)
+{
+       /* Free the helper */
+       gtk_tree_path_free (helper->source_row);
+       g_slice_free (DndHelper, helper);
+}
 
 /*
  * This function is the callback of the
@@ -1915,8 +1927,7 @@ xfer_cb (ModestMailOperation *mail_op,
        gtk_drag_finish (helper->context, success, FALSE, helper->time);
 
        /* Free the helper */
-       gtk_tree_path_free (helper->source_row);
-       g_slice_free (DndHelper, helper);
+       dnd_helper_destroyer (helper);
 }
 
 /* get the folder for the row the treepath refers to. */
@@ -2042,6 +2053,103 @@ cleanup:
                g_object_unref (headers);
 }
 
+typedef struct {
+       TnyFolderStore *src_folder;
+       TnyFolderStore *dst_folder;
+       DndHelper *helper; 
+} DndFolderInfo;
+
+static void
+dnd_folder_info_destroyer (DndFolderInfo *info)
+{
+       if (info->src_folder)
+               g_object_unref (info->src_folder);
+       if (info->dst_folder)
+               g_object_unref (info->dst_folder);
+       g_slice_free (DndFolderInfo, info);
+}
+
+static void
+dnd_on_connection_failed_destroyer (DndFolderInfo *info,
+                                   GtkWindow *parent_window,
+                                   TnyAccount *account)
+{
+       time_t dnd_time = info->helper->time;
+       GdkDragContext *context = info->helper->context;
+       
+       /* Show error */
+       modest_ui_actions_on_account_connection_error (parent_window, account);
+
+       /* Free the helper & info */
+       dnd_helper_destroyer (info->helper);
+       dnd_folder_info_destroyer (info);
+       
+       /* Notify the drag source. Never call delete, the monitor will
+          do the job if needed */
+       gtk_drag_finish (context, FALSE, FALSE, dnd_time);
+       return;
+}
+
+static void
+drag_and_drop_from_folder_view_src_folder_performer (gboolean canceled, 
+                                                    GError *err,
+                                                    GtkWindow *parent_window, 
+                                                    TnyAccount *account, 
+                                                    gpointer user_data)
+{
+       DndFolderInfo *info = NULL;
+       ModestMailOperation *mail_op;
+
+       info = (DndFolderInfo *) user_data;
+
+       if (err || canceled) {
+               dnd_on_connection_failed_destroyer (info, parent_window, account);
+               return;
+       }
+
+       /* Do the mail operation */
+       mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
+                                                                modest_ui_actions_move_folder_error_handler,
+                                                                info->src_folder, NULL);
+
+       modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
+                                        mail_op);
+
+       /* Transfer the folder */
+       modest_mail_operation_xfer_folder (mail_op,
+                                          TNY_FOLDER (info->src_folder),
+                                          info->dst_folder,
+                                          info->helper->delete_source,
+                                          xfer_cb,
+                                          info->helper);
+       
+       g_object_unref (G_OBJECT (mail_op));
+}
+
+
+static void
+drag_and_drop_from_folder_view_dst_folder_performer (gboolean canceled, 
+                                                    GError *err,
+                                                    GtkWindow *parent_window, 
+                                                    TnyAccount *account, 
+                                                    gpointer user_data)
+{
+       DndFolderInfo *info = NULL;
+
+       info = (DndFolderInfo *) user_data;
+
+       if (err || canceled) {
+               dnd_on_connection_failed_destroyer (info, parent_window, account);
+               return;
+       }
+
+       /* Connect to source folder and perform the copy/move */
+       modest_platform_connect_and_perform_if_network_folderstore (NULL, 
+                                                                   info->src_folder,
+                                                                   drag_and_drop_from_folder_view_src_folder_performer,
+                                                                   info);
+}
+
 /*
  * This function is used by drag_data_received_cb to manage drag and
  * drop of a folder, i.e, and drag from the folder view to the same
@@ -2054,12 +2162,12 @@ drag_and_drop_from_folder_view (GtkTreeModel     *source_model,
                                GtkSelectionData *selection_data,
                                DndHelper        *helper)
 {
-       ModestMailOperation *mail_op = NULL;
        GtkTreeIter dest_iter, iter;
        TnyFolderStore *dest_folder = NULL;
        TnyFolderStore *folder = NULL;
        gboolean forbidden = FALSE;
        ModestWindow *win;
+       DndFolderInfo *info = NULL;
 
        win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(), FALSE); /* don't create */
        if (!win) {
@@ -2113,31 +2221,21 @@ drag_and_drop_from_folder_view (GtkTreeModel     *source_model,
                            TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN,
                            &folder, -1);
 
-       /* Offer the connection dialog if necessary, for the destination parent folder and source folder: */
-       if (modest_platform_connect_and_wait_if_network_folderstore (NULL, dest_folder) && 
-           modest_platform_connect_and_wait_if_network_folderstore (NULL, TNY_FOLDER_STORE (folder))) {
-       
-               /* Do the mail operation */
-               mail_op = modest_mail_operation_new_with_error_handling ((GObject *) win,
-                                                                        modest_ui_actions_move_folder_error_handler,
-                                                                        folder, NULL);
-
-               modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
-                                                mail_op);
-
-               modest_mail_operation_xfer_folder (mail_op, 
-                                                  TNY_FOLDER (folder), 
-                                                  dest_folder,
-                                                  helper->delete_source,
-                                                  xfer_cb,
-                                                  helper);
-
-               g_object_unref (G_OBJECT (mail_op));
-       }
+       /* Create the info for the performer */
+       info = g_slice_new (DndFolderInfo);
+       info->src_folder = g_object_ref (folder);
+       info->dst_folder = g_object_ref (dest_folder);
+       info->helper = helper;
+
+       /* Connect to the destination folder and perform the copy/move */
+       modest_platform_connect_and_perform_if_network_folderstore (GTK_WINDOW (win), 
+                                                                   dest_folder,
+                                                                   drag_and_drop_from_folder_view_dst_folder_performer,
+                                                                   info);
        
        /* Frees */
-       g_object_unref (G_OBJECT (dest_folder));
-       g_object_unref (G_OBJECT (folder));
+       g_object_unref (dest_folder);
+       g_object_unref (folder);
 }
 
 /*