GError *err,
gpointer user_data);
+static gboolean _check_memory_low (ModestMailOperation *mail_op);
+
enum _ModestMailOperationSignals
{
PROGRESS_CHANGED_SIGNAL,
g_return_if_fail (TNY_IS_HEADER (header));
priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
- folder = tny_header_get_folder (header);
-
priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
priv->total = 1;
priv->done = 0;
+ /* Check memory low */
+ if (_check_memory_low (self)) {
+ if (user_callback)
+ user_callback (self, header, FALSE, NULL, priv->error, user_data);
+ modest_mail_operation_notify_end (self);
+ return;
+ }
+
/* Get account and set it into mail_operation */
+ folder = tny_header_get_folder (header);
priv->account = modest_tny_folder_get_account (TNY_FOLDER(folder));
/* Check for cached messages */
priv->done = 0;
priv->total = tny_list_get_length(header_list);
+ /* Check memory low */
+ if (_check_memory_low (self)) {
+ if (user_callback) {
+ TnyHeader *header = NULL;
+ TnyIterator *iter;
+
+ if (tny_list_get_length (header_list) > 0) {
+ iter = tny_list_create_iterator (header_list);
+ header = (TnyHeader *) tny_iterator_get_current (iter);
+ g_object_unref (iter);
+ }
+ user_callback (self, header, FALSE, NULL, priv->error, user_data);
+ if (header)
+ g_object_unref (header);
+ }
+ if (notify)
+ notify (user_data);
+ /* Notify about operation end */
+ modest_mail_operation_notify_end (self);
+ return;
+ }
+
/* Check uncached messages */
for (iter = tny_list_create_iterator (header_list), has_uncached_messages = FALSE;
!has_uncached_messages && !tny_iterator_is_done (iter);
&(helper->sum_total_bytes), helper->total_bytes, TRUE);
}
+static void
+transfer_msgs_sync_folder_cb (TnyFolder *self,
+ gboolean cancelled,
+ GError *err,
+ gpointer user_data)
+{
+ XFerMsgsAsyncHelper *helper;
+ /* We don't care here about the results of the
+ synchronization */
+ helper = (XFerMsgsAsyncHelper *) user_data;
+
+ /* Notify about operation end */
+ modest_mail_operation_notify_end (helper->mail_op);
+
+ /* If user defined callback function was defined, call it */
+ if (helper->user_callback)
+ helper->user_callback (helper->mail_op, helper->user_data);
+
+ /* Free */
+ if (helper->more_msgs)
+ g_object_unref (helper->more_msgs);
+ if (helper->headers)
+ g_object_unref (helper->headers);
+ if (helper->dest_folder)
+ g_object_unref (helper->dest_folder);
+ if (helper->mail_op)
+ g_object_unref (helper->mail_op);
+ g_slice_free (XFerMsgsAsyncHelper, helper);
+}
static void
transfer_msgs_cb (TnyFolder *folder, gboolean cancelled, GError *err, gpointer user_data)
}
if (finished) {
-
- /* Update folder counts */
- tny_folder_poke_status (folder);
- tny_folder_poke_status (helper->dest_folder);
-
- /* Notify about operation end */
- modest_mail_operation_notify_end (self);
-
- /* If user defined callback function was defined, call it */
- if (helper->user_callback) {
- /* This is not a GDK lock because we are a Tinymail callback and
- * Tinymail already acquires the Gdk lock */
-
- /* no gdk_threads_enter (), CHECKED */
- helper->user_callback (self, helper->user_data);
- /* no gdk_threads_leave (), CHECKED */
- }
-
- /* Free */
- if (helper->more_msgs)
- g_object_unref (helper->more_msgs);
- if (helper->headers)
- g_object_unref (helper->headers);
- if (helper->dest_folder)
- g_object_unref (helper->dest_folder);
- if (helper->mail_op)
- g_object_unref (helper->mail_op);
- g_slice_free (XFerMsgsAsyncHelper, helper);
+ /* Synchronize the source folder contents. This should
+ be done by tinymail but the camel_folder_sync it's
+ actually disabled in transfer_msgs_thread_clean
+ because it's supposed to cause hangs */
+ tny_folder_sync_async (folder, helper->delete,
+ transfer_msgs_sync_folder_cb,
+ NULL, helper);
} else {
/* Transfer more messages */
tny_folder_transfer_msgs_async (folder,
priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
- priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
+ /* Check memory low */
+ if (_check_memory_low (self)) {
+ if (user_callback)
+ user_callback (self, folder, user_data);
+ /* Notify about operation end */
+ modest_mail_operation_notify_end (self);
+ return;
+ }
/* Get account and set it into mail_operation */
+ priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
priv->account = modest_tny_folder_get_account (folder);
priv->op_type = MODEST_MAIL_OPERATION_TYPE_RECEIVE;
priv->done, priv->total,
priv->error && priv->error->message ? priv->error->message : "");
}
+
+/*
+ * Once the mail operations were objects this will be no longer
+ * needed. I don't like it, but we need it for the moment
+ */
+static gboolean
+_check_memory_low (ModestMailOperation *mail_op)
+{
+ if (modest_platform_check_memory_low (NULL, FALSE)) {
+ ModestMailOperationPrivate *priv;
+
+ priv = MODEST_MAIL_OPERATION_GET_PRIVATE (mail_op);
+ priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
+ g_set_error (&(priv->error),
+ MODEST_MAIL_OPERATION_ERROR,
+ MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY,
+ "Not enough memory to complete the operation");
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}