Fixes NB#63571
[modest] / src / modest-ui-actions.c
index 8c2d36f..049da20 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:
@@ -1952,7 +1955,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;
        }
 
@@ -2197,7 +2200,18 @@ on_save_to_drafts_cb (ModestMailOperation *mail_op,
                      gpointer user_data)
 {
        ModestMsgEditWindow *edit_window;
-       char *info_text;
+       ModestMainWindow *win;
+
+       /* FIXME. Make the header view sensitive again. This is a
+        * temporary hack. See modest_ui_actions_on_save_to_drafts()
+        * for details */
+       win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
+                                        modest_runtime_get_window_mgr(), FALSE));
+       if (win != NULL) {
+               GtkWidget *hdrview = modest_main_window_get_child_widget(
+                       win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
+               if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
+       }
 
        edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
 
@@ -2206,9 +2220,6 @@ on_save_to_drafts_cb (ModestMailOperation *mail_op,
                return;
 
        modest_msg_edit_window_set_draft (edit_window, saved_draft);
-       info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
-       modest_platform_information_banner (NULL, NULL, info_text);
-       g_free (info_text);
 }
 
 void
@@ -2219,6 +2230,7 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
        MsgData *data;
        gchar *account_name, *from;
        ModestAccountMgr *account_mgr;
+       char *info_text;
 
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
        
@@ -2272,7 +2284,11 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
                                              data->priority_flags,
                                              on_save_to_drafts_cb,
                                              edit_window);
+       info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
+       modest_platform_information_banner (NULL, NULL, info_text);
+
        /* Frees */
+       g_free (info_text);
        g_free (from);
        g_free (account_name);
        g_object_unref (G_OBJECT (transport_account));
@@ -2280,6 +2296,43 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
 
        modest_msg_edit_window_free_msg_data (edit_window, data);
        modest_msg_edit_window_reset_modified (edit_window);
+
+       /* ** FIXME **
+        * If the drafts folder is selected then make the header view
+        * insensitive while the message is being saved to drafts
+        * (it'll be sensitive again in on_save_to_drafts_cb()). This
+        * is not very clean but it avoids letting the drafts folder
+        * in an inconsistent state: the user could edit the message
+        * being saved and undesirable things would happen.
+        * In the average case the user won't notice anything at
+        * all. In the worst case (the user is editing a really big
+        * file from Drafts) the header view will be insensitive
+        * during the saving process (10 or 20 seconds, depending on
+        * the message). Anyway this is just a quick workaround: once
+        * we find a better solution it should be removed
+        * See NB#65125 (commend #18) for details.
+        */
+       ModestMainWindow *win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
+               modest_runtime_get_window_mgr(), FALSE));
+       if (win != NULL) {
+               ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
+                       win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
+               if (view != NULL) {
+                       TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
+                       if (folder) {
+                               if (modest_tny_folder_is_local_folder(folder)) {
+                                       TnyFolderType folder_type;
+                                       folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
+                                       if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
+                                               GtkWidget *hdrview = modest_main_window_get_child_widget(
+                                                       win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
+                                               if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
+                                       }
+                               }
+                       }
+                       if (folder != NULL) g_object_unref(folder);
+               }
+       }
 }
 
 /* For instance, when clicking the Send toolbar button when editing a message: */
@@ -2349,6 +2402,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);
@@ -2545,7 +2602,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);
 
@@ -2633,6 +2690,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)
@@ -2664,7 +2774,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));
@@ -2673,42 +2783,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);
@@ -2760,7 +2842,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);
@@ -2819,7 +2901,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)); */
@@ -4373,7 +4455,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))
@@ -4426,7 +4508,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);
@@ -4466,7 +4548,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))) {