* Fixes NB#99264, replaced the move to logical id
[modest] / src / modest-ui-actions.c
index 17984de..ffc10d4 100644 (file)
@@ -223,14 +223,38 @@ modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
        wizard = GTK_WINDOW (modest_platform_get_account_settings_wizard ());
        modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (wizard), (GtkWindow *) win);
 
+#ifndef MODEST_TOOLKIT_HILDON2
        /* always present a main window in the background 
         * we do it here, so we cannot end up with two wizards (as this
         * function might be called in modest_window_mgr_get_main_window as well */
-       if (!win) 
+       if (!win)
                win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
                                                         TRUE);  /* create if not existent */
+#else
+       if (!win) {
+               GList *window_list;
+               ModestWindowMgr *mgr;
+
+               mgr = modest_runtime_get_window_mgr ();
 
-       gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
+               window_list = modest_window_mgr_get_window_list (mgr);
+               if (window_list == NULL) {
+                       win = MODEST_WINDOW (modest_accounts_window_new ());
+                       modest_window_mgr_register_window (mgr, win, NULL);
+                       gtk_widget_show_all (GTK_WIDGET (win));
+
+                       win = MODEST_WINDOW (modest_folder_window_new (NULL));
+                       modest_window_mgr_register_window (mgr, win, NULL);
+
+                       gtk_widget_show_all (GTK_WIDGET (win));
+               } else {
+                       g_list_free (window_list);
+               }
+       }
+#endif
+
+       if (win)
+               gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
 
        /* make sure the mainwindow is visible. We need to present the
           wizard again to give it the focus back. show_all are needed
@@ -1007,6 +1031,15 @@ get_info_from_header (TnyHeader *header, gboolean *is_draft, gboolean *can_open)
                *is_draft = TRUE; /* Open in editor if the message is in the Drafts folder */
        }
 
+       if (!account) {
+               TnyAccount *acc = tny_folder_get_account (folder);
+               if (acc) {
+                       account =
+                               g_strdup (modest_tny_account_get_parent_modest_account_name_for_server_account (acc));
+                       g_object_unref (acc);
+               }
+       }
+
        g_object_unref (folder);
 
        return account;
@@ -1244,7 +1277,6 @@ get_account_from_header (TnyHeader *header)
                account = tny_folder_get_account (folder);
                g_object_unref (folder);
        }
-               
        return account;
 }
 
@@ -1284,7 +1316,6 @@ open_msg_performer(gboolean canceled,
        gchar *error_msg;
        ModestProtocolType proto;
        TnyConnectionStatus status;
-       gboolean show_open_draft = FALSE;
        OpenMsgHelper *helper = NULL;
        ModestProtocol *protocol;
        ModestProtocolRegistry *protocol_registry;
@@ -1322,6 +1353,8 @@ open_msg_performer(gboolean canceled,
                error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
        }
 
+#ifndef MODEST_TOOLKIT_HILDON2
+       gboolean show_open_draft = FALSE;
        if (modest_protocol_registry_protocol_type_has_tag (protocol_registry,
                                                            proto,
                                                            MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS)) { 
@@ -1333,6 +1366,7 @@ open_msg_performer(gboolean canceled,
                show_open_draft = (folder_type == TNY_FOLDER_TYPE_DRAFTS);
                g_object_unref (folder);
        }
+#endif
 
 #ifdef MODEST_TOOLKIT_HILDON2
        gboolean is_draft;
@@ -1380,17 +1414,17 @@ open_msg_performer(gboolean canceled,
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                         mail_op);
 
+
+#ifndef MODEST_TOOLKIT_HILDON2
        if (show_open_draft) {
                helper->banner_info = g_slice_new (OpenMsgBannerInfo);
-#ifdef MODEST_TOOLKIT_HILDON2
-               helper->banner_info->message = g_strdup (_("mail_me_opening"));
-#else
                helper->banner_info->message = g_strdup (_("mail_ib_opening_draft_message"));
-#endif
                helper->banner_info->banner = NULL;
                helper->banner_info->idle_handler = g_timeout_add (500, open_msg_banner_idle, 
                                                                   helper->banner_info);
        }
+#endif
+
 
        TnyList *headers;
        headers = TNY_LIST (tny_simple_list_new ());
@@ -1424,7 +1458,7 @@ open_msg_from_header (TnyHeader *header, GtkTreeRowReference *rowref, ModestWind
        GtkWidget *header_view = NULL;
        OpenMsgHelper *helper;
        ModestWindow *window;
-               
+
        g_return_if_fail (header != NULL && rowref != NULL);
 
        mgr = modest_runtime_get_window_mgr ();
@@ -1441,7 +1475,7 @@ open_msg_from_header (TnyHeader *header, GtkTreeRowReference *rowref, ModestWind
 
        window = NULL;
        found = modest_window_mgr_find_registered_header (mgr, header, &window);
-               
+
        /* Do not open again the message and present the
           window to the user */
        if (found) {
@@ -3267,6 +3301,46 @@ do_create_folder_cb (ModestMailOperation *mail_op,
        g_object_unref (source_win);
 }
 
+typedef struct {
+       gchar *folder_name;
+       TnyFolderStore *parent;
+} CreateFolderConnect;
+
+static void
+do_create_folder_performer (gboolean canceled, 
+                        GError *err,
+                        GtkWindow *parent_window, 
+                        TnyAccount *account, 
+                        gpointer user_data)
+{
+       CreateFolderConnect *helper = (CreateFolderConnect *) user_data;
+       ModestMailOperation *mail_op;
+
+       if (canceled || err) {
+               /* In memory full conditions we could get this error here */
+               check_memory_full_error ((GtkWidget *) parent_window, err);
+               goto frees;
+       }
+
+       mail_op  = modest_mail_operation_new ((GObject *) parent_window);
+       modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
+                                        mail_op);
+       modest_mail_operation_create_folder (mail_op,
+                                            helper->parent,
+                                            (const gchar *) helper->folder_name,
+                                            do_create_folder_cb,
+                                            g_strdup (helper->folder_name));
+       g_object_unref (mail_op);
+
+ frees:
+       if (helper->parent)
+               g_object_unref (helper->parent);
+       if (helper->folder_name)
+               g_free (helper->folder_name);
+       g_slice_free (CreateFolderConnect, helper);
+}
+
+
 static void
 do_create_folder (GtkWindow *parent_window, 
                  TnyFolderStore *suggested_parent, 
@@ -3283,80 +3357,42 @@ do_create_folder (GtkWindow *parent_window,
                                                        &parent_folder);
 
        if (result == GTK_RESPONSE_ACCEPT && parent_folder) {
-               ModestMailOperation *mail_op;
+               CreateFolderConnect *helper = (CreateFolderConnect *) g_slice_new0 (CreateFolderHelper);
+               helper->folder_name = g_strdup (folder_name);
+               helper->parent = g_object_ref (parent_folder);
 
-               mail_op  = modest_mail_operation_new ((GObject *) parent_window);
-               modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
-                                                mail_op);
-               modest_mail_operation_create_folder (mail_op,
-                                                    parent_folder,
-                                                    (const gchar *) folder_name,
-                                                    do_create_folder_cb,
-                                                    folder_name);
-               g_object_unref (mail_op);
+               modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window),
+                                                              TRUE,
+                                                              parent_folder,
+                                                              do_create_folder_performer,
+                                                              helper);
        }
 
+       if (folder_name)
+               g_free (folder_name);
        if (parent_folder)
                g_object_unref (parent_folder);
 }
 
 static void
-create_folder_performer (gboolean canceled, 
-                        GError *err,
-                        GtkWindow *parent_window, 
-                        TnyAccount *account, 
-                        gpointer user_data)
-{
-       TnyFolderStore *parent_folder = TNY_FOLDER_STORE (user_data);
-
-       if (canceled || err) {
-               /* In memory full conditions we could get this error here */
-               check_memory_full_error ((GtkWidget *) parent_window, err);
-               goto frees;
-       }
-
-       /* Run the new folder dialog */
-       do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL);
-
- frees:
-       g_object_unref (parent_folder);
-}
-
-static void
 modest_ui_actions_create_folder(GtkWidget *parent_window,
                                 GtkWidget *folder_view)
 {
        TnyFolderStore *parent_folder;
 
 #ifdef MODEST_TOOLKIT_HILDON2
-       const gchar *active_account;
-       TnyAccount *account;
        ModestTnyAccountStore *acc_store;
 
-       /* In hildon 2.2 we use the current account as default parent */
        acc_store = modest_runtime_get_account_store ();
-       active_account = modest_window_get_active_account (MODEST_WINDOW (parent_window));
-       if (active_account) {
-               account = modest_tny_account_store_get_server_account (acc_store,
-                                                                      active_account,
-                                                                      TNY_ACCOUNT_TYPE_STORE);
-               parent_folder = TNY_FOLDER_STORE (account);
-       } else {
-               parent_folder = (TnyFolderStore *) 
-                       modest_tny_account_store_get_local_folders_account (acc_store);
-       }
+
+       parent_folder = (TnyFolderStore *) 
+               modest_tny_account_store_get_local_folders_account (acc_store);
 #else
        parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
 #endif
 
-       if (parent_folder) {
-               /* The parent folder will be freed in the callback */
-               modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window),
-                                                              TRUE,
-                                                              parent_folder,
-                                                              create_folder_performer,
-                                                              parent_folder);
-       }
+       if (parent_folder)
+               do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL);
 }
 
 void
@@ -5094,32 +5130,34 @@ void
 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op, 
                                             gpointer user_data)
 {
+       GObject *win = NULL;
+
+#ifndef MODEST_TOOLKIT_HILDON2
        ModestWindow *main_window = NULL;
-       
+
        /* Disable next automatic folder selection */
        main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
                                                         FALSE); /* don't create */
        if (main_window) {
-               GObject *win = NULL;
                GtkWidget *folder_view = NULL;
-       
+
                folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
                                                                   MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW); 
                modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
-               
+
                if (user_data && TNY_IS_FOLDER (user_data)) {
                        modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), 
                                                          TNY_FOLDER (user_data), FALSE);
                }
-
-               /* Show notification dialog only if the main window exists */
-               win = modest_mail_operation_get_source (mail_op);
-               modest_platform_run_information_dialog ((GtkWindow *) win, 
-                                                       _("mail_in_ui_folder_move_target_error"), 
-                                                       FALSE);
-               if (win)
-                       g_object_unref (win);
        }
+#endif
+       /* Show notification dialog only if the main window exists */
+       win = modest_mail_operation_get_source (mail_op);
+       modest_platform_run_information_dialog ((GtkWindow *) win, 
+                                               _("mail_in_ui_folder_move_target_error"), 
+                                               FALSE);
+       if (win)
+               g_object_unref (win);
 }
 
 static void
@@ -5469,12 +5507,14 @@ on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
        }
 
        MoveToHelper *helper = g_new0 (MoveToHelper, 1);
+#ifndef MODEST_TOOLKIT_HILDON2
        helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL,
                        _CS("ckct_nw_pasting"));
        if (helper->banner != NULL)  {
                g_object_ref (helper->banner);
                gtk_widget_show (GTK_WIDGET(helper->banner));
        }
+#endif
        /* Clean folder on header view before moving it */
        sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (info->folder_view));
        gtk_tree_selection_unselect_all (sel);
@@ -5748,6 +5788,7 @@ modest_ui_actions_on_edit_mode_move_to (ModestWindow *win)
        GtkWidget *dialog = NULL, *folder_view = NULL;
        ModestMainWindow *main_window;
        MoveToInfo *helper = NULL;
+       TnyList *list_to_move;
 
        g_return_val_if_fail (MODEST_IS_WINDOW (win), FALSE);
 
@@ -5766,6 +5807,16 @@ modest_ui_actions_on_edit_mode_move_to (ModestWindow *win)
        else
                folder_view = NULL;
 
+       list_to_move = modest_platform_get_list_to_move (MODEST_WINDOW (win));
+
+       if (!list_to_move)
+               return FALSE;
+
+       if (tny_list_get_length (list_to_move) < 1) {
+               g_object_unref (list_to_move);
+               return FALSE;
+       }
+
        /* Create and run the dialog */
        dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view);
        modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),