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);
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;
+ }
+}
/* we check for low-mem; in that case, show a warning, and don't allow
* composing a message with attachments
*/
- if (attachments && modest_platform_check_memory_low (win))
+ if (attachments && modest_platform_check_memory_low (win, TRUE))
goto cleanup;
account_name = modest_account_mgr_get_default_account(mgr);
/* If there is no message or the operation was not successful */
status = modest_mail_operation_get_status (mail_op);
if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
+ const GError *error;
+
+ /* If it's a memory low issue, then show a banner */
+ error = modest_mail_operation_get_error (mail_op);
+ if (error && error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
+ GObject *source = modest_mail_operation_get_source (mail_op);
+ modest_platform_run_information_dialog (GTK_IS_WINDOW (source) ? GTK_WINDOW (source) : NULL,
+ dgettext("ke-recv","memr_ib_operation_disabled"),
+ TRUE);
+ g_object_unref (source);
+ }
/* Remove the header from the preregistered uids */
modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
/* we check for low-mem; in that case, show a warning, and don't allow
* opening
*/
- if (modest_platform_check_memory_low (MODEST_WINDOW(win)))
+ if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
return;
/* Get headers */
/* we check for low-mem; in that case, show a warning, and don't allow
* reply/forward (because it could potentially require a lot of memory */
- if (modest_platform_check_memory_low (MODEST_WINDOW(win)))
+ if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
return;
/* we check for low-mem; in that case, show a warning, and don't allow
* activating headers
*/
- if (modest_platform_check_memory_low (MODEST_WINDOW(main_window)))
+ if (modest_platform_check_memory_low (MODEST_WINDOW(main_window), TRUE))
return;
modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
{
ModestMainWindow *win = NULL;
GtkWidget *header_view;
+ const GError *error;
g_return_if_fail (TNY_IS_FOLDER (folder));
win = MODEST_MAIN_WINDOW (user_data);
+
+ /* Check if the operation failed due to memory low conditions */
+ error = modest_mail_operation_get_error (mail_op);
+ if (error && error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
+ modest_platform_run_information_dialog (GTK_WINDOW (win),
+ dgettext("ke-recv","memr_ib_operation_disabled"),
+ TRUE);
+ return;
+ }
+
header_view =
modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
/* we check for low-mem; in that case, show a warning, and don't allow
* viewing attachments
*/
- if (modest_platform_check_memory_low (MODEST_WINDOW(win)))
+ if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
return;
modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
*/
if (expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) {
- if (modest_platform_check_memory_low (MODEST_WINDOW(edit_window))) {
+ if (modest_platform_check_memory_low (MODEST_WINDOW(edit_window), TRUE)) {
modest_msg_edit_window_free_msg_data (edit_window, data);
return FALSE;
}
* this should still allow for sending anything critical...
*/
if (expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) {
- if (modest_platform_check_memory_low (MODEST_WINDOW(edit_window))) {
+ if (modest_platform_check_memory_low (MODEST_WINDOW(edit_window), TRUE)) {
modest_msg_edit_window_free_msg_data (edit_window, data);
return FALSE;
}
g_return_if_fail (GTK_IS_ACTION (action));
- if (modest_platform_check_memory_low (MODEST_WINDOW(window)))
+ if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
return;
if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
g_return_if_fail (GTK_IS_ACTION (action));
- if (modest_platform_check_memory_low (MODEST_WINDOW(window)))
+ if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
return;
modest_msg_edit_window_offer_attach_file (window);
{
if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
- if (modest_platform_check_memory_low (MODEST_WINDOW(window)))
+ if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
return;
modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
g_warning ("%s: no help for window %p", __FUNCTION__, win);
}
+static void
+retrieve_contents_cb (ModestMailOperation *mail_op,
+ TnyHeader *header,
+ gboolean canceled,
+ TnyMsg *msg,
+ GError *err,
+ gpointer user_data)
+{
+ /* We only need this callback to show an error in case of
+ memory low condition */
+ modest_ui_actions_msg_retrieval_check (mail_op, header, msg);
+}
+
static void
retrieve_msg_contents_performer (gboolean canceled,
GError *err,
modest_ui_actions_disk_operations_error_handler,
NULL, NULL);
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
- modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
+ modest_mail_operation_get_msgs_full (mail_op, headers, retrieve_contents_cb, NULL, NULL);
/* Frees */
g_object_unref (mail_op);
/* we check for low-mem; in that case, show a warning, and don't allow
* searching
*/
- if (modest_platform_check_memory_low (window))
+ if (modest_platform_check_memory_low (window, TRUE))
return;
modest_platform_show_search_messages (GTK_WINDOW (window));
/* we check for low-mem; in that case, show a warning, and don't allow
* for the addressbook
*/
- if (modest_platform_check_memory_low (win))
+ if (modest_platform_check_memory_low (win, TRUE))
return;