* check for a valid foldername
[modest] / src / modest-ui-actions.c
index b984c95..aed5f2c 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"
@@ -145,7 +148,7 @@ static void
 run_account_setup_wizard (ModestWindow *win)
 {
        ModestEasysetupWizardDialog *wizard;
-
+       
        g_return_if_fail (MODEST_IS_WINDOW(win));
        
        wizard = modest_easysetup_wizard_dialog_new ();
@@ -288,7 +291,10 @@ void modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow*
                modest_msg_view_window_first_message_selected (win)) {
                modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (win));
        } else {
-               modest_msg_view_window_select_next_message (win);
+               if (!modest_msg_view_window_select_next_message (win)) {
+                       gboolean ret_value;
+                       g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
+               }
        }
 }
 
@@ -315,9 +321,11 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
                        return;
        }
        
+       /* Get the headers, either from the header view (if win is the main window),
+        * 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;
@@ -378,6 +386,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)) {
@@ -421,6 +431,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));
 
@@ -1978,7 +2012,8 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
                account_name = modest_account_mgr_get_default_account (account_mgr);
                
        if (!account_name) {
-               g_printerr ("modest: no account found\n");
+               /* Run account setup wizard */
+               run_account_setup_wizard(MODEST_WINDOW(edit_window));
                return;
        }
        
@@ -1994,9 +2029,8 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
                                      (modest_runtime_get_account_store(),
                                       account_name));
        if (!transport_account) {
-               g_printerr ("modest: no transport account found for '%s'\n", account_name);
-               g_free (account_name);
-               modest_msg_edit_window_free_msg_data (edit_window, data);
+               /* Run account setup wizard */
+               run_account_setup_wizard(MODEST_WINDOW(edit_window));
                return;
        }
        
@@ -2455,9 +2489,15 @@ void
 modest_ui_actions_on_delete_folder (GtkAction *action,
                                     ModestMainWindow *main_window)
 {
+       GtkWidget *folder_view;
        g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
 
        delete_folder (main_window, FALSE);
+       folder_view = modest_main_window_get_child_widget (main_window,
+                                                          MODEST_WIDGET_TYPE_FOLDER_VIEW);
+       if (!folder_view)
+               return;
+       modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
 }
 
 void 
@@ -3648,6 +3688,9 @@ modest_ui_actions_xfer_messages_from_move_to (TnyFolderStore *dst_folder,
 {
        TnyList *headers = NULL;
        gint response = 0;
+       TnyAccount *dst_account = NULL;
+       const gchar *proto_str = NULL;
+       gboolean dst_is_pop = FALSE;
 
        if (!TNY_IS_FOLDER (dst_folder)) {
                modest_platform_information_banner (GTK_WIDGET (win),
@@ -3656,9 +3699,25 @@ modest_ui_actions_xfer_messages_from_move_to (TnyFolderStore *dst_folder,
                return;
        }
 
+       dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
+       proto_str = tny_account_get_proto (dst_account);
+       dst_is_pop = (modest_protocol_info_get_transport_store_protocol (proto_str) == 
+                     MODEST_PROTOCOL_STORE_POP);
+       g_object_unref (dst_account);
+
        /* Get selected headers */
        headers = get_selected_headers (MODEST_WINDOW (win));
 
+       if (dst_is_pop) {
+               modest_platform_information_banner (GTK_WIDGET (win),
+                                                   NULL,
+                                                   ngettext("mail_in_ui_folder_move_target_error",
+                                                            "mail_in_ui_folder_move_targets_error",
+                                                            tny_list_get_length (headers)));
+               g_object_unref (headers);
+               return;
+       }
+
        /* Ask for user confirmation */
        response = msgs_move_to_confirmation (GTK_WINDOW (win), 
                                              TNY_FOLDER (dst_folder), 
@@ -4024,8 +4083,12 @@ modest_ui_actions_on_email_menu_activated (GtkAction *action,
 {
        g_return_if_fail (MODEST_IS_WINDOW (window));
 
+       /* Init dimming rules init data */
+       
        /* Update dimmed */     
        modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");     
+
+       /* Free dimming ruls init data */
 }
 
 void