Notifies the user when "save to draft", "open attachment" or "send msg" operations fail
because the disk is full. It also improves general error notification in more general scenarios.
pmo-trunk-r3962
gchar *filepath = NULL;
const gchar *att_filename = tny_mime_part_get_filename (mime_part);
const gchar *content_type;
+ gboolean show_error_banner = FALSE;
+ GError *err;
TnyFsStream *temp_stream = NULL;
temp_stream = modest_utils_create_temp_stream (att_filename, attachment_uid,
&filepath);
if (temp_stream != NULL) {
content_type = tny_mime_part_get_content_type (mime_part);
- tny_mime_part_decode_to_stream (mime_part, TNY_STREAM (temp_stream));
+ if (tny_mime_part_decode_to_stream (mime_part, TNY_STREAM (temp_stream), &err) >= 0) {
+ /* make the file read-only */
+ if (g_chmod(filepath, 0444) != 0)
+ g_warning ("%s: failed to set file '%s' to read-only: %s",
+ __FUNCTION__, filepath, strerror(errno));
- /* make the file read-only */
- if (g_chmod(filepath, 0444) != 0)
- g_warning ("%s: failed to set file '%s' to read-only: %s",
- __FUNCTION__, filepath, strerror(errno));
-
- modest_platform_activate_file (filepath, content_type);
+ modest_platform_activate_file (filepath, content_type);
+ } else {
+ /* error while saving attachment, maybe cerm_device_memory_full */
+ show_error_banner = TRUE;
+ if (err != NULL) {
+ g_warning ("%s: tny_mime_part_decode_to_stream failed (%s)", __FUNCTION__, err->message);
+ g_error_free (err);
+ }
+ }
g_object_unref (temp_stream);
g_free (filepath);
/* NOTE: files in the temporary area will be automatically
* cleaned after some time if they are no longer in use */
- } else if (filepath != NULL) {
- /* the file may already exist but it isn't writable,
- * let's try to open it anyway */
- content_type = tny_mime_part_get_content_type (mime_part);
- modest_platform_activate_file (filepath, content_type);
- g_free (filepath);
+ } else {
+ if (filepath != NULL) {
+ /* the file may already exist but it isn't writable,
+ * let's try to open it anyway */
+ content_type = tny_mime_part_get_content_type (mime_part);
+ modest_platform_activate_file (filepath, content_type);
+ g_free (filepath);
+ } else {
+ g_warning ("%s: modest_utils_create_temp_stream failed", __FUNCTION__);
+ show_error_banner = TRUE;
+ }
}
+ if (show_error_banner)
+ modest_platform_information_banner (NULL, NULL, _("mail_ib_file_operation_failed"));
} else {
/* message attachment */
TnyHeader *header = NULL;
GnomeVFSHandle *handle;
TnyStream *stream;
SaveMimePartPair *pair = (SaveMimePartPair *) info->pairs->data;
+ gboolean decode_result = TRUE;
result = gnome_vfs_create (&handle, pair->filename, GNOME_VFS_OPEN_WRITE, FALSE, 0644);
if (result == GNOME_VFS_OK) {
stream = tny_vfs_stream_new (handle);
- tny_mime_part_decode_to_stream (pair->part, stream);
+ if (tny_mime_part_decode_to_stream (pair->part, stream, NULL) < 0) {
+ decode_result = FALSE;
+ }
g_object_unref (G_OBJECT (stream));
g_object_unref (pair->part);
g_slice_free (SaveMimePartPair, pair);
info->pairs = g_list_delete_link (info->pairs, info->pairs);
- info->result = TRUE;
+ info->result = decode_result;
} else {
save_mime_part_info_free (info, FALSE);
info->result = FALSE;
buf = gtk_text_buffer_new (NULL);
stream = TNY_STREAM (tny_gtk_text_buffer_stream_new (buf));
tny_stream_reset (stream);
- tny_mime_part_decode_to_stream (body, stream);
+ tny_mime_part_decode_to_stream (body, stream, NULL);
tny_stream_reset (stream);
g_object_unref (G_OBJECT(stream));
} else {
/* Add the msg to the queue */
modest_mail_operation_notify_start (self);
- modest_tny_send_queue_add (MODEST_TNY_SEND_QUEUE(send_queue),
- msg,
- &(priv->error));
-
- priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
info = g_slice_new0 (SendMsgInfo);
info->mail_op = g_object_ref (self);
info->msg = g_object_ref (msg);
info->msg_sent_handler = g_signal_connect (G_OBJECT (send_queue), "msg-sent",
- G_CALLBACK (send_mail_msg_sent_handler), info);
+ G_CALLBACK (send_mail_msg_sent_handler), info);
info->error_happened_handler = g_signal_connect (G_OBJECT (send_queue), "error-happened",
- G_CALLBACK (send_mail_error_happened_handler), info);
+ G_CALLBACK (send_mail_error_happened_handler), info);
+
+ modest_tny_send_queue_add (MODEST_TNY_SEND_QUEUE(send_queue),
+ msg,
+ &(priv->error));
+
+ priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
}
}
if (msgid2 == NULL) msgid2 = "(null)";
if (!strcmp (msgid1, msgid2)) {
+ if (error != NULL)
+ g_warning ("%s: %s\n", __FUNCTION__, error->message);
ModestMailOperationPrivate *priv = MODEST_MAIL_OPERATION_GET_PRIVATE (info->mail_op);
priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
buf = gtk_text_buffer_new (NULL);
stream = TNY_STREAM (tny_gtk_text_buffer_stream_new (buf));
tny_stream_reset (stream);
- tny_mime_part_decode_to_stream (body, stream);
+ tny_mime_part_decode_to_stream (body, stream, NULL);
tny_stream_reset (stream);
gtk_text_buffer_get_bounds (buf, &start, &end);
edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
- /* If there was any error do nothing */
- if (modest_mail_operation_get_error (mail_op) != NULL)
+ /* It might not be a good idea to do nothing if there was an error,
+ * so let's at least show a generic error banner. */
+ /* TODO error while saving attachment, show "Saving draft failed" banner */
+ if (modest_mail_operation_get_error (mail_op) != NULL) {
+ g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_op))->message);
+ modest_platform_information_banner (NULL, NULL, _("mail_ib_file_operation_failed"));
return;
+ }
modest_msg_edit_window_set_draft (edit_window, saved_draft);
}
ModestAttachmentViewPrivate *priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (view);
TnyStream *stream;
gsize total = 0;
+ gssize result = 0;
stream = modest_count_stream_new();
- tny_mime_part_decode_to_stream (priv->mime_part, stream);
+ result = tny_mime_part_decode_to_stream (priv->mime_part, stream, NULL);
total = modest_count_stream_get_count(MODEST_COUNT_STREAM (stream));
if (total == 0) {
modest_count_stream_reset_count(MODEST_COUNT_STREAM (stream));
- tny_mime_part_write_to_stream (priv->mime_part, stream);
+ result = tny_mime_part_write_to_stream (priv->mime_part, stream, NULL);
total = modest_count_stream_get_count(MODEST_COUNT_STREAM (stream));
}
- priv->size = (guint64)total;
-
- g_idle_add (idle_get_mime_part_size_cb, g_object_ref (view));
+
+ /* if there was an error, don't set the size (this is pretty uncommon) */
+ if (result < 0) {
+ g_warning ("%s: error while writing mime part to stream\n", __FUNCTION__);
+ } else {
+ priv->size = (guint64)total;
+ g_idle_add (idle_get_mime_part_size_cb, g_object_ref (view));
+ }
g_object_unref (stream);
g_object_unref (view);
tny_stream = TNY_STREAM(modest_tny_stream_gtkhtml_new (gtkhtml_stream));
tny_stream_reset (tny_stream);
- tny_mime_part_decode_to_stream ((TnyMimePart*)part, tny_stream);
+ tny_mime_part_decode_to_stream ((TnyMimePart*)part, tny_stream, NULL);
g_object_unref (G_OBJECT(tny_stream));
gtk_html_stream_destroy (gtkhtml_stream);
modest_stream_text_to_html_set_full_limit (MODEST_STREAM_TEXT_TO_HTML (text_to_html_stream), 640*1024);
// FIXME: tinymail
- tny_mime_part_decode_to_stream ((TnyMimePart*)part, text_to_html_stream);
+ tny_mime_part_decode_to_stream ((TnyMimePart*)part, text_to_html_stream, NULL);
tny_stream_reset (text_to_html_stream);
g_object_unref (G_OBJECT(text_to_html_stream));
return FALSE;
}
- tny_mime_part_decode_to_stream ((TnyMimePart*)part, stream);
+ tny_mime_part_decode_to_stream ((TnyMimePart*)part, stream, NULL);
g_object_unref (G_OBJECT(part));
return TRUE;
}
result = FALSE;
} else {
tny_mime_part_decode_to_stream ((TnyMimePart*)part,
- stream);
+ stream, NULL);
g_object_unref (G_OBJECT(part));
result = TRUE;
}