* Review fucntion 'has_retrieved_msgs' implementation
[modest] / src / modest-ui-actions.c
index e0cb74f..41aa482 100644 (file)
@@ -45,6 +45,9 @@
 #include "modest-tny-platform-factory.h"
 #include "modest-platform.h"
 #include <tny-mime-part.h>
+#include <tny-camel-folder.h>
+#include <tny-camel-imap-folder.h>
+#include <tny-camel-pop-folder.h>
 
 #ifdef MODEST_PLATFORM_MAEMO
 #include "maemo/modest-osso-state-saving.h"
@@ -141,6 +144,13 @@ download_uncached_messages (TnyList *header_list, GtkWindow *win,
                            gboolean reply_fwd);
 
 
+static gint
+msgs_move_to_confirmation (GtkWindow *win,
+                          TnyFolder *dest_folder,
+                          gboolean delete,
+                          TnyList *headers);
+
+
 static void
 run_account_setup_wizard (ModestWindow *win)
 {
@@ -322,7 +332,7 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
         * or from the message view window: */
        header_list = get_selected_headers (win);
        if (!header_list) return;
-
+                       
        /* Check if any of the headers are already opened, or in the process of being opened */
        if (MODEST_IS_MAIN_WINDOW (win)) {
                gboolean found;
@@ -383,6 +393,8 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
                GList *sel_list = NULL, *tmp = NULL;
                GtkTreeRowReference *row_reference = NULL;
                GtkTreePath *next_path = NULL;
+               TnyFolder *folder = NULL;
+               GError *err = NULL;
 
                /* Find last selected row */                    
                if (MODEST_IS_MAIN_WINDOW (win)) {
@@ -426,6 +438,30 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
                                gtk_tree_row_reference_free (row_reference);
                }
 
+               /* Get folder from first header and sync it */
+               iter = tny_list_create_iterator (header_list);
+               header = TNY_HEADER (tny_iterator_get_current (iter));
+               folder = tny_header_get_folder (header);
+               if (TNY_IS_CAMEL_IMAP_FOLDER (folder))
+/*                     tny_folder_sync_async(folder, FALSE, NULL, NULL, NULL); /\* FALSE --> don't expunge *\/ */
+                       tny_folder_sync (folder, FALSE, &err); /* FALSE --> don't expunge */
+/*             else if (TNY_IS_CAMEL_POP_FOLDER (folder)) */
+/*                     tny_folder_sync_async(folder, FALSE, NULL, NULL, NULL); /\* TRUE --> dont expunge *\/ */
+/*                     tny_folder_sync (folder, TRUE, &err); /\* TRUE --> expunge *\/ */
+               else
+                       /* local folders */
+/*                     tny_folder_sync_async(folder, TRUE, NULL, NULL, NULL); /\* TRUE --> expunge *\/ */
+                       tny_folder_sync (folder, TRUE, &err); /* TRUE --> expunge */
+
+               if (err != NULL) {
+                       printf ("DEBUG: %s: Error: code=%d, text=%s\n", __FUNCTION__, err->code, err->message);
+                       g_error_free(err);
+               }
+
+               g_object_unref (header);
+               g_object_unref (iter);
+               g_object_unref (folder);
+               
                /* Update toolbar dimming state */
                modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
 
@@ -2237,6 +2273,21 @@ modest_ui_actions_create_folder(GtkWidget *parent_window,
                gboolean finished = FALSE;
                gint result;
                gchar *folder_name = NULL, *suggested_name = NULL;
+               const gchar *proto_str = NULL;
+               TnyAccount *account;
+
+               if (TNY_IS_ACCOUNT (parent_folder))
+                       account = g_object_ref (parent_folder);
+               else
+                       account = tny_folder_get_account (TNY_FOLDER (parent_folder));
+               proto_str = tny_account_get_proto (TNY_ACCOUNT (account));
+
+               if (proto_str && modest_protocol_info_get_transport_store_protocol (proto_str) ==
+                   MODEST_PROTOCOL_STORE_POP) {
+                       finished = TRUE;
+                       hildon_banner_show_information (NULL, NULL, _("mail_in_ui_folder_create_error"));
+               }
+               g_object_unref (account);
 
                /* Run the new folder dialog */
                while (!finished) {
@@ -2903,30 +2954,50 @@ modest_ui_actions_on_paste (GtkAction *action,
 
                /* Create a new mail operation */
                mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(window));
-               modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
-                                                mail_op);
                
                /* Get destination folder */
                folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
 
-               /* Launch notification */
-               inf_note = modest_platform_animation_banner (GTK_WIDGET (window), 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));
-               }
-
                /* transfer messages  */
                if (data != NULL) {
-                       modest_mail_operation_xfer_msgs (mail_op, 
-                                                        data,
-                                                        TNY_FOLDER (folder_store),
-                                                        delete,
-                                                        paste_msgs_cb,
-                                                        inf_note);
+                       gint response = 0;
+
+                       /* Ask for user confirmation */
+                       response = msgs_move_to_confirmation (GTK_WINDOW (window), 
+                                                             TNY_FOLDER (folder_store), 
+                                                             delete,
+                                                             data);
+                       
+                       if (response == GTK_RESPONSE_OK) {
+                               /* Launch notification */
+                               inf_note = modest_platform_animation_banner (GTK_WIDGET (window), 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));
+                               }
+
+                               modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
+                               modest_mail_operation_xfer_msgs (mail_op, 
+                                                                data,
+                                                                TNY_FOLDER (folder_store),
+                                                                delete,
+                                                                paste_msgs_cb,
+                                                                inf_note);                             
+                       } else {
+                               g_object_unref (mail_op);
+                       }
                        
                } else if (src_folder != NULL) {                        
+                       /* Launch notification */
+                       inf_note = modest_platform_animation_banner (GTK_WIDGET (window), 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));
+                       }
+                       
+                       modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
                        modest_mail_operation_xfer_folder (mail_op, 
                                                           src_folder,
                                                           folder_store,
@@ -3367,14 +3438,15 @@ has_retrieved_msgs (TnyList *list)
        gboolean found = FALSE;
 
        iter = tny_list_create_iterator (list);
-       while (tny_iterator_is_done (iter) && !found) {
+       while (!tny_iterator_is_done (iter) && !found) {
                TnyHeader *header;
                TnyHeaderFlags flags = 0;
 
                header = TNY_HEADER (tny_iterator_get_current (iter));
                if (header) {
                        flags = tny_header_get_flags (header);
-                       if (!(flags & TNY_HEADER_FLAG_PARTIAL))
+                       if (flags & TNY_HEADER_FLAG_CACHED)
+/*                     if (!(flags & TNY_HEADER_FLAG_PARTIAL)) */
                                found = TRUE;
 
                        g_object_unref (header);
@@ -3397,12 +3469,14 @@ has_retrieved_msgs (TnyList *list)
 static gint
 msgs_move_to_confirmation (GtkWindow *win,
                           TnyFolder *dest_folder,
+                          gboolean delete,
                           TnyList *headers)
 {
        gint response = GTK_RESPONSE_OK;
 
-       /* If the destination is a local folder */
-       if (modest_tny_folder_is_local_folder (dest_folder)) {
+       /* If the destination is a local folder (or MMC folder )*/
+       if (!modest_tny_folder_is_remote_folder (dest_folder)) {
+/*     if (modest_tny_folder_is_local_folder (dest_folder)) { */
                TnyFolder *src_folder = NULL;
                TnyIterator *iter = NULL;
                TnyHeader *header = NULL;
@@ -3422,18 +3496,22 @@ msgs_move_to_confirmation (GtkWindow *win,
                        return GTK_RESPONSE_CANCEL;
 
                /* If the source is a remote folder */
-               if (!modest_tny_folder_is_local_folder (src_folder)) {
-                       const gchar *message;
-                       
-                       if (has_retrieved_msgs (headers))
+/*             if (!modest_tny_folder_is_local_folder (src_folder)) { */
+               if (modest_tny_folder_is_remote_folder (src_folder)) {
+                       const gchar *message = NULL;
+                       gboolean cached = has_retrieved_msgs (headers);
+                       if (cached) 
                                message = ngettext ("mcen_nc_move_retrieve", "mcen_nc_move_retrieves",
                                                    tny_list_get_length (headers));
                        else 
                                message = ngettext ("mcen_nc_move_header", "mcen_nc_move_headers",
                                                    tny_list_get_length (headers));
-
-                       response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
-                                                                           (const gchar *) message);
+                       
+                       if (cached && !delete)  
+                               response = GTK_RESPONSE_OK;
+                       else
+                               response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
+                                                                                   (const gchar *) message);
                }
                
                g_object_unref (src_folder);
@@ -3692,6 +3770,7 @@ modest_ui_actions_xfer_messages_from_move_to (TnyFolderStore *dst_folder,
        /* Ask for user confirmation */
        response = msgs_move_to_confirmation (GTK_WINDOW (win), 
                                              TNY_FOLDER (dst_folder), 
+                                             TRUE,
                                              headers);
 
        /* Transfer messages */
@@ -4053,7 +4132,7 @@ modest_ui_actions_on_email_menu_activated (GtkAction *action,
                                          ModestWindow *window)
 {
        g_return_if_fail (MODEST_IS_WINDOW (window));
-
+       
        /* Update dimmed */     
        modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");     
 }