When moving messages to a local folder don't try to connect if the
[modest] / src / modest-ui-actions.c
index 0a8dba0..bcef523 100644 (file)
@@ -149,7 +149,53 @@ static gboolean connect_to_get_msg (
                                                GtkWindow *win,
                                                gint num_of_uncached_msgs);
 
+static gboolean remote_folder_is_pop (const TnyFolderStore *folder);
 
+static gboolean msgs_already_deleted_from_server ( TnyList *headers,
+                                                   const TnyFolderStore *src_folder);
+
+
+/*
+ * This function checks whether a TnyFolderStore is a pop account
+ */
+static gboolean
+remote_folder_is_pop (const TnyFolderStore *folder)
+{
+        const gchar *proto = NULL;
+        TnyAccount *account = NULL;
+
+        g_return_val_if_fail (TNY_IS_FOLDER_STORE(folder), FALSE);
+
+        if (TNY_IS_ACCOUNT (folder)) {
+                account = TNY_ACCOUNT(folder);
+                g_object_ref(account);
+        } else if (TNY_IS_FOLDER (folder)) {
+                account = tny_folder_get_account(TNY_FOLDER(folder));
+        }
+
+        proto = tny_account_get_proto(account);
+        g_object_unref (account);
+
+        return proto &&
+          (modest_protocol_info_get_transport_store_protocol (proto) == MODEST_PROTOCOL_STORE_POP);
+}
+
+/*
+ * This functions checks whether if a list of messages are already
+ * deleted from the server: that is, if the server is a POP account
+ * and all messages are already cached.
+ */
+static gboolean
+msgs_already_deleted_from_server (TnyList *headers, const TnyFolderStore *src_folder)
+{
+        g_return_val_if_fail (TNY_IS_FOLDER_STORE(src_folder), FALSE);
+        g_return_val_if_fail (TNY_IS_LIST(headers), FALSE);
+
+        gboolean src_is_pop = remote_folder_is_pop (src_folder);
+        gint uncached_msgs = header_list_count_uncached_msgs (headers);
+
+        return (src_is_pop && !uncached_msgs);
+}
 
 /* Show the account creation wizard dialog.
  * returns: TRUE if an account was created. FALSE if the user cancelled.
@@ -3760,7 +3806,6 @@ has_retrieved_msgs (TnyList *list)
  * GTK_RESPONSE_OK
  *
  * This one is used by the next functions:
- *     modest_ui_actions_xfer_messages_from_move_to
  *     modest_ui_actions_on_paste                      - commented out
  *     drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
  */
@@ -4040,7 +4085,6 @@ modest_ui_actions_xfer_messages_from_move_to (TnyFolderStore *dst_folder,
                                              ModestWindow *win)
 {
        TnyList *headers = NULL;
-       gint response = 0;
        TnyAccount *dst_account = NULL;
        const gchar *proto_str = NULL;
        gboolean dst_is_pop = FALSE;
@@ -4075,39 +4119,30 @@ modest_ui_actions_xfer_messages_from_move_to (TnyFolderStore *dst_folder,
                return;
        }
 
-       /* Ask for user confirmation */
-       response = msgs_move_to_confirmation (GTK_WINDOW (win), 
-                                             TNY_FOLDER (dst_folder), 
-                                             TRUE,
-                                             headers);
-
-       /* Transfer messages */
-       if (response == GTK_RESPONSE_OK) {
-                GtkWidget *inf_note;
-               inf_note = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
-                                                            _CS("ckct_nw_pasting"));
-               if (inf_note != NULL)  {
-                       gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
-                       gtk_widget_show (GTK_WIDGET(inf_note));
-               }
+        GtkWidget *inf_note;
+       inf_note = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
+                                                    _CS("ckct_nw_pasting"));
+       if (inf_note != NULL)  {
+               gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
+               gtk_widget_show (GTK_WIDGET(inf_note));
+       }
 
-               ModestMailOperation *mail_op = 
-                       modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, 
-                                                                      G_OBJECT(win),
-                                                                      modest_ui_actions_move_folder_error_handler,
-                                                                      NULL);
-               modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
-                                                mail_op);
+       ModestMailOperation *mail_op = 
+               modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, 
+                                                              G_OBJECT(win),
+                                                              modest_ui_actions_move_folder_error_handler,
+                                                              NULL);
+       modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
+                                        mail_op);
 
-               modest_mail_operation_xfer_msgs (mail_op, 
-                                                headers,
-                                                TNY_FOLDER (dst_folder),
-                                                TRUE,
-                                                move_to_cb,
-                                                inf_note);
+       modest_mail_operation_xfer_msgs (mail_op, 
+                                        headers,
+                                        TNY_FOLDER (dst_folder),
+                                        TRUE,
+                                        move_to_cb,
+                                        inf_note);
 
-               g_object_unref (G_OBJECT (mail_op));
-       }
+       g_object_unref (G_OBJECT (mail_op));
        g_object_unref (headers);
 }
 
@@ -4189,10 +4224,14 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
                 gboolean do_xfer = TRUE;
                 /* Ask for confirmation if the source folder is remote and we're not connected */
                 if (!online && modest_platform_is_network_folderstore(src_folder)) {
-                        guint num_headers = modest_header_view_count_selected_headers(header_view);
-                        if (!connect_to_get_msg(GTK_WINDOW(win), num_headers)) {
-                                do_xfer = FALSE;
+                        TnyList *headers = modest_header_view_get_selected_headers(header_view);
+                        if (!msgs_already_deleted_from_server(headers, src_folder)) {
+                                guint num_headers = tny_list_get_length(headers);
+                                if (!connect_to_get_msg(GTK_WINDOW(win), num_headers)) {
+                                        do_xfer = FALSE;
+                                }
                         }
+                        g_object_unref(headers);
                 }
                 if (do_xfer) /* Transfer messages */
                         modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
@@ -4221,7 +4260,7 @@ modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
        g_object_unref (header);
 
        /* Transfer the message if online or confirmed by the user */
-        if (tny_device_is_online (modest_runtime_get_device()) ||
+        if (tny_device_is_online (modest_runtime_get_device()) || remote_folder_is_pop(src_folder) ||
             (modest_platform_is_network_folderstore(src_folder) && connect_to_get_msg(GTK_WINDOW(win), 1))) {
                modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
         }