+/*
+ * Checks if we need a connection to do the transfer and if the user
+ * wants to connect to complete it
+ */
+void
+modest_ui_actions_xfer_messages_check (GtkWindow *parent_window,
+ TnyFolderStore *src_folder,
+ TnyList *headers,
+ TnyFolder *dst_folder,
+ gboolean delete_originals,
+ gboolean *need_connection,
+ gboolean *do_xfer)
+{
+ TnyAccount *src_account;
+ gint uncached_msgs = 0;
+
+ uncached_msgs = header_list_count_uncached_msgs (headers);
+
+ /* We don't need any further check if
+ *
+ * 1- the source folder is local OR
+ * 2- the device is already online
+ */
+ if (!modest_tny_folder_store_is_remote (src_folder) ||
+ tny_device_is_online (modest_runtime_get_device())) {
+ *need_connection = FALSE;
+ *do_xfer = TRUE;
+ return;
+ }
+
+ /* We must ask for a connection when
+ *
+ * - the message(s) is not already cached OR
+ * - the message(s) is cached but the leave_on_server setting
+ * is FALSE (because we need to sync the source folder to
+ * delete the message from the server (for IMAP we could do it
+ * offline, it'll take place the next time we get a
+ * connection)
+ */
+ src_account = get_account_from_folder_store (src_folder);
+ if (uncached_msgs > 0) {
+ guint num_headers;
+ const gchar *msg;
+
+ *need_connection = TRUE;
+ num_headers = tny_list_get_length (headers);
+ msg = ngettext ("mcen_nc_get_msg", "mcen_nc_get_msgs", num_headers);
+
+ if (modest_platform_run_confirmation_dialog (parent_window, msg) ==
+ GTK_RESPONSE_CANCEL) {
+ *do_xfer = FALSE;
+ } else {
+ *do_xfer = TRUE;
+ }
+ } else {
+ /* The transfer is possible and the user wants to */
+ *do_xfer = TRUE;
+
+ if (remote_folder_is_pop (src_folder) && delete_originals) {
+ const gchar *account_name;
+ gboolean leave_on_server;
+
+ account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (src_account);
+ leave_on_server = modest_account_mgr_get_leave_on_server (modest_runtime_get_account_mgr (),
+ account_name);
+
+ if (leave_on_server == TRUE) {
+ *need_connection = FALSE;
+ } else {
+ *need_connection = TRUE;
+ }
+ } else {
+ *need_connection = FALSE;
+ }
+ }
+
+ /* Frees */
+ g_object_unref (src_account);
+}
+
+static void
+xfer_messages_error_handler (ModestMailOperation *mail_op,
+ gpointer user_data)
+{
+ 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 = 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);
+ }
+}
+