* Fixes NB#76991, the send/receive refreshes the current folder as well
[modest] / src / modest-ui-actions.c
index 9708e5c..369e4be 100644 (file)
@@ -53,6 +53,7 @@
 #include "maemo/modest-osso-state-saving.h"
 #include "maemo/modest-maemo-utils.h"
 #include "maemo/modest-hildon-includes.h"
+#include "maemo/modest-connection-specific-smtp-window.h"
 #endif /* MODEST_PLATFORM_MAEMO */
 
 #include "widgets/modest-ui-constants.h"
@@ -63,7 +64,6 @@
 #include <widgets/modest-attachments-view.h>
 #include "widgets/modest-folder-view.h"
 #include "widgets/modest-global-settings-dialog.h"
-#include "modest-connection-specific-smtp-window.h"
 #include "modest-account-mgr-helpers.h"
 #include "modest-mail-operation.h"
 #include "modest-text-utils.h"
@@ -215,6 +215,7 @@ gboolean
 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
 {
        gboolean result = FALSE;        
+#ifdef MODEST_PLATFORM_MAEMO
        GtkWindow *dialog, *wizard;
        gint dialog_response;
 
@@ -255,7 +256,7 @@ modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
                /* Check whether an account was created: */
                result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
        }
-       
+#endif 
        return result;
 }
 
@@ -709,6 +710,7 @@ modest_ui_actions_on_accounts (GtkAction *action,
 #endif /* MODEST_PLATFORM_MAEMO */
 }
 
+#ifdef MODEST_PLATFORM_MAEMO
 static void
 on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
 {
@@ -717,7 +719,7 @@ on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
                        MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window));
        gtk_widget_destroy (GTK_WIDGET (window));
 }
-
+#endif
 
 
 void
@@ -1704,7 +1706,8 @@ do_send_receive_performer (gboolean canceled,
 
        /* Send & receive. */
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
-       modest_mail_operation_update_account (mail_op, info->account_name, new_messages_arrived, info->win);
+       modest_mail_operation_update_account (mail_op, info->account_name, (info->win) ? FALSE : TRUE,
+                                             new_messages_arrived, info->win);
        g_object_unref (G_OBJECT (mail_op));
        
  clean:
@@ -1860,13 +1863,49 @@ void
 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
 {
        /* Check if accounts exist */
-       gboolean accounts_exist = 
+       gboolean accounts_exist;
+
+       accounts_exist =
                modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
        
        /* If not, allow the user to create an account before trying to send/receive. */
        if (!accounts_exist)
                modest_ui_actions_on_accounts (NULL, win);
        
+       /* Refresh the current folder. The if is always TRUE it's just an extra check */
+       if (MODEST_IS_MAIN_WINDOW (win)) {
+               GtkWidget *header_view, *folder_view;
+               TnyFolderStore *folder_store;
+
+               folder_view = 
+                       modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win), 
+                                                            MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+               if (!folder_view)
+                       return;
+               
+               folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
+       
+               /* No need to refresh the INBOX the send_receive will do it for us */
+               if (folder_store && TNY_IS_FOLDER (folder_store) && 
+                   tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
+                       header_view = 
+                               modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
+                                                                    MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
+                
+                       /* We do not need to set the contents style
+                          because it hasn't changed. We also do not
+                          need to save the widget status. Just force
+                           a refresh */
+                       modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
+                                                      TNY_FOLDER (folder_store),
+                                                      folder_refreshed_cb,
+                                                      MODEST_MAIN_WINDOW (win));
+               }
+       
+               if (folder_store)
+                       g_object_unref (folder_store);
+       }       
+       
        /* Refresh the active account */
        modest_ui_actions_do_send_receive (NULL, win);
 }
@@ -1952,7 +1991,7 @@ modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
                return;
 
        if (modest_header_view_count_selected_headers (header_view) > 1) {
-               hildon_banner_show_information (NULL, NULL, _("mcen_ib_select_one_message"));
+               modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
                return;
        }
 
@@ -2399,6 +2438,10 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
                                             data->attachments,
                                             data->images,
                                             data->priority_flags);
+
+       if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
+               modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
+
                                             
        /* Free data: */
        g_free (from);
@@ -2595,7 +2638,7 @@ modest_ui_actions_create_folder(GtkWidget *parent_window,
                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"));
+                       modest_platform_information_banner (NULL, NULL, _("mail_in_ui_folder_create_error"));
                }
                g_object_unref (account);
 
@@ -2683,6 +2726,59 @@ modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
        modest_platform_information_banner (GTK_WIDGET (window), NULL, message);
 }
 
+typedef struct {
+       TnyFolderStore *folder;
+       gchar *new_name;
+} RenameFolderInfo;
+
+static void
+on_rename_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window, 
+               TnyAccount *account, gpointer user_data)
+{
+       ModestMailOperation *mail_op = NULL;
+       GtkTreeSelection *sel = NULL;
+       GtkWidget *folder_view = NULL;
+       RenameFolderInfo *data = (RenameFolderInfo*)user_data;
+
+       if (MODEST_IS_MAIN_WINDOW(parent_window)) {
+
+               folder_view = modest_main_window_get_child_widget (
+                               MODEST_MAIN_WINDOW (parent_window),
+                               MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+
+               mail_op = 
+                       modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
+                                       modest_ui_actions_rename_folder_error_handler,
+                                       parent_window, NULL);
+
+               modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
+                               mail_op);
+
+               /* Clear the headers view */
+               sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
+               gtk_tree_selection_unselect_all (sel);
+
+               /* Select *after* the changes */
+               modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
+                               TNY_FOLDER(data->folder), TRUE);
+
+               /* Actually rename the folder */
+               modest_mail_operation_rename_folder (mail_op,
+                               TNY_FOLDER (data->folder),
+                               (const gchar *) (data->new_name));
+               
+               /* TODO folder view filter refilter */
+               /* 
+               GtkTreeModel *tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view));
+               if (GTK_IS_TREE_MODEL_FILTER (tree_model))
+                       gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (tree_model)); */
+       }
+
+       g_object_unref (mail_op);
+       g_free (data->new_name);
+       g_free (data);
+}
+
 void 
 modest_ui_actions_on_rename_folder (GtkAction *action,
                                     ModestMainWindow *main_window)
@@ -2714,7 +2810,7 @@ modest_ui_actions_on_rename_folder (GtkAction *action,
                gint response;
                const gchar *current_name;
                TnyFolderStore *parent;
-                gboolean do_rename = TRUE;
+               gboolean do_rename = TRUE;
 
                current_name = tny_folder_get_name (TNY_FOLDER (folder));
                parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
@@ -2723,42 +2819,14 @@ modest_ui_actions_on_rename_folder (GtkAction *action,
                                                                     &folder_name);
                g_object_unref (parent);
 
-                if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
-                        do_rename = FALSE;
-                } else if (modest_platform_is_network_folderstore(folder) &&
-                           !tny_device_is_online (modest_runtime_get_device())) {
-                        TnyAccount *account = tny_folder_get_account(TNY_FOLDER(folder));
-                        do_rename = modest_platform_connect_and_wait(GTK_WINDOW(main_window), account);
-                        g_object_unref(account);
-                }
-
-               if (do_rename) {
-                       ModestMailOperation *mail_op;
-                       GtkTreeSelection *sel = NULL;
-
-                       mail_op = 
-                               modest_mail_operation_new_with_error_handling (G_OBJECT(main_window),
-                                                                              modest_ui_actions_rename_folder_error_handler,
-                                                                              main_window, NULL);
-
-                       modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
-                                                        mail_op);
-
-                       /* Clear the headers view */
-                       sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
-                       gtk_tree_selection_unselect_all (sel);
-
-                       /* Select *after* the changes */
-                       modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
-                                                         TNY_FOLDER(folder), TRUE);
-
-                       /* Actually rename the folder */
-                       modest_mail_operation_rename_folder (mail_op,
-                                                            TNY_FOLDER (folder),
-                                                            (const gchar *) folder_name);
-
-                       g_object_unref (mail_op);
-                       g_free (folder_name);
+               if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
+                       do_rename = FALSE;
+               } else {
+                       RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
+                       rename_folder_data->folder = folder;
+                       rename_folder_data->new_name = folder_name;
+                       modest_platform_connect_if_remote_and_perform (GTK_WINDOW(main_window), 
+                                       folder, on_rename_folder_cb, rename_folder_data);
                }
        }
        g_object_unref (folder);
@@ -2810,7 +2878,7 @@ delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
 
         if (response != GTK_RESPONSE_OK) {
                 do_delete = FALSE;
-        } else if (modest_platform_is_network_folderstore(folder) &&
+        } else if (modest_tny_folder_store_is_remote(folder) &&
                    !tny_device_is_online (modest_runtime_get_device())) {
                 TnyAccount *account = tny_folder_get_account(TNY_FOLDER(folder));
                 do_delete = modest_platform_connect_and_wait(GTK_WINDOW(main_window), account);
@@ -2869,7 +2937,7 @@ modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainW
 static void
 show_error (GtkWidget *parent_widget, const gchar* text)
 {
-       hildon_banner_show_information(parent_widget, NULL, text);
+       modest_platform_information_banner(parent_widget, NULL, text);
        
 #if 0
        GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
@@ -4423,7 +4491,7 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
                 } else if (!TNY_IS_FOLDER (src_folder)) {
                        g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
                         do_xfer = FALSE;
-                } else if (!online && modest_platform_is_network_folderstore(src_folder)) {
+                } else if (!online && modest_tny_folder_store_is_remote(src_folder)) {
                         guint num_headers = tny_folder_get_all_count(TNY_FOLDER (src_folder));
                        TnyAccount *account = tny_folder_get_account (TNY_FOLDER (src_folder));
                         if (!connect_to_get_msg(MODEST_WINDOW (win), num_headers, account))
@@ -4476,7 +4544,7 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
        } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
                 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)) {
+                if (!online && modest_tny_folder_store_is_remote(src_folder)) {
                         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);
@@ -4516,7 +4584,7 @@ modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
        g_object_unref (header);
 
        account = tny_folder_get_account (src_folder);
-       if (!modest_platform_is_network_folderstore(TNY_FOLDER_STORE(src_folder))) {
+       if (!modest_tny_folder_store_is_remote(TNY_FOLDER_STORE(src_folder))) {
                /* Transfer if the source folder is local */
                do_xfer = TRUE;
        } else if (remote_folder_is_pop(TNY_FOLDER_STORE(src_folder))) {