+ if (moving_folder) {
+ TnyFolderStore *moved_folder = NULL, *parent = NULL;
+
+ /* Get the folder to move */
+ moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
+
+ /* Check that we're not moving to the same folder */
+ if (TNY_IS_FOLDER (moved_folder)) {
+ parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
+ if (parent == folder_store)
+ ok_sensitive = FALSE;
+ g_object_unref (parent);
+ }
+
+ if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
+ /* Do not allow to move to an account unless it's the
+ local folders account */
+ if (!is_local_account)
+ ok_sensitive = FALSE;
+ }
+
+ if (ok_sensitive && (moved_folder == folder_store)) {
+ /* Do not allow to move to itself */
+ ok_sensitive = FALSE;
+ }
+ g_object_unref (moved_folder);
+ } else {
+ TnyHeader *header = NULL;
+ TnyFolder *src_folder = NULL;
+
+ /* Moving a message */
+ if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
+ header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (user_data));
+ src_folder = tny_header_get_folder (header);
+ g_object_unref (header);
+ } else {
+ src_folder =
+ TNY_FOLDER (modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)));
+ }
+
+ /* Do not allow to move the msg to the same folder */
+ /* Do not allow to move the msg to an account */
+ if ((gpointer) src_folder == (gpointer) folder_store ||
+ TNY_IS_ACCOUNT (folder_store))
+ ok_sensitive = FALSE;
+ g_object_unref (src_folder);
+ }
+
+ end:
+ /* Set sensitivity of the OK button */
+ gtk_widget_set_sensitive (ok_button, ok_sensitive);
+ /* Set sensitivity of the NEW button */
+ gtk_widget_set_sensitive (new_button, new_sensitive);
+}
+
+static GtkWidget*
+create_move_to_dialog (GtkWindow *win,
+ GtkWidget *folder_view,
+ GtkWidget **tree_view)
+{
+ GtkWidget *dialog, *scroll;
+ GtkWidget *new_button;
+
+ dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
+ GTK_WINDOW (win),
+ GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
+ NULL);
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
+ /* We do this manually so GTK+ does not associate a response ID for
+ * the button. */
+ new_button = gtk_button_new_from_stock (_("mcen_bd_new"));
+ gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
+ gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_REJECT);
+
+ /* Create scrolled window */
+ scroll = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+
+ /* Create folder view */
+ *tree_view = modest_platform_create_folder_view (NULL);
+
+ /* Track changes in the selection to
+ * disable the OK button whenever "Move to" is not possible
+ * disbale NEW button whenever New is not possible */
+ g_signal_connect (*tree_view,
+ "folder_selection_changed",
+ G_CALLBACK (on_move_to_dialog_folder_selection_changed),
+ win);
+
+ /* Listen to clicks on New button */
+ g_signal_connect (G_OBJECT (new_button),
+ "clicked",
+ G_CALLBACK(create_move_to_dialog_on_new_folder),
+ *tree_view);
+
+ /* It could happen that we're trying to move a message from a
+ window (msg window for example) after the main window was
+ closed, so we can not just get the model of the folder
+ view */
+ if (MODEST_IS_FOLDER_VIEW (folder_view)) {
+ const gchar *visible_id = NULL;
+
+ modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
+ MODEST_FOLDER_VIEW(*tree_view));
+
+ visible_id =
+ modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
+
+ /* Show the same account than the one that is shown in the main window */
+ modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(*tree_view),
+ visible_id);
+ } else {
+ const gchar *active_account_name = NULL;
+ ModestAccountMgr *mgr = NULL;
+ ModestAccountData *acc_data = NULL;
+
+ modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
+ TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
+
+ active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
+ mgr = modest_runtime_get_account_mgr ();
+ acc_data = modest_account_mgr_get_account_data (mgr, active_account_name);
+
+ /* Set the new visible & active account */
+ if (acc_data && acc_data->store_account) {
+ modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (*tree_view),
+ acc_data->store_account->account_name);
+ modest_account_mgr_free_account_data (mgr, acc_data);
+ }
+ }
+
+ /* Hide special folders */
+ modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
+
+ gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
+
+ /* Add scroll to dialog */
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
+ scroll, TRUE, TRUE, 0);
+
+ gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
+ gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);