From: Felipe Erias Morandeira Date: Fri, 21 Dec 2007 13:49:32 +0000 (+0000) Subject: Partially fixes NB#77528 X-Git-Tag: git_migration_finished~1880 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=3b214150a992267f0722e89c94759f8e3c637c0a Partially fixes NB#77528 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 --- diff --git a/src/maemo/modest-msg-view-window.c b/src/maemo/modest-msg-view-window.c index cdabd3a..b152574 100644 --- a/src/maemo/modest-msg-view-window.c +++ b/src/maemo/modest-msg-view-window.c @@ -2333,31 +2333,47 @@ modest_msg_view_window_view_attachment (ModestMsgViewWindow *window, TnyMimePart 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; @@ -2463,16 +2479,19 @@ save_mime_part_to_file (SaveMimePartInfo *info) 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; diff --git a/src/modest-formatter.c b/src/modest-formatter.c index 666278e..4e1e367 100644 --- a/src/modest-formatter.c +++ b/src/modest-formatter.c @@ -76,7 +76,7 @@ extract_text (ModestFormatter *self, TnyMimePart *body) 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)); diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index 34a5001..64e3d92 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -635,20 +635,21 @@ modest_mail_operation_send_mail (ModestMailOperation *self, } 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; } } @@ -707,6 +708,8 @@ send_mail_error_happened_handler (TnySendQueue *queue, TnyHeader *header, TnyMsg 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, diff --git a/src/modest-tny-msg.c b/src/modest-tny-msg.c index c2adec4..943f4bc 100644 --- a/src/modest-tny-msg.c +++ b/src/modest-tny-msg.c @@ -363,7 +363,7 @@ modest_tny_msg_get_body (TnyMsg *msg, gboolean want_html, gboolean *is_html) 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); diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index ef183ec..3cc1f10 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -2245,9 +2245,14 @@ on_save_to_drafts_cb (ModestMailOperation *mail_op, 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); } diff --git a/src/widgets/modest-attachment-view.c b/src/widgets/modest-attachment-view.c index a5b6aa4..0d171bf 100644 --- a/src/widgets/modest-attachment-view.c +++ b/src/widgets/modest-attachment-view.c @@ -125,18 +125,24 @@ get_mime_part_size_thread (gpointer thr_user_data) 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); diff --git a/src/widgets/modest-gtkhtml-mime-part-view.c b/src/widgets/modest-gtkhtml-mime-part-view.c index 324b568..0a3fd5d 100644 --- a/src/widgets/modest-gtkhtml-mime-part-view.c +++ b/src/widgets/modest-gtkhtml-mime-part-view.c @@ -373,7 +373,7 @@ set_html_part (ModestGtkhtmlMimePartView *self, TnyMimePart *part) 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); @@ -395,7 +395,7 @@ set_text_part (ModestGtkhtmlMimePartView *self, TnyMimePart *part) 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)); diff --git a/src/widgets/modest-gtkhtml-msg-view.c b/src/widgets/modest-gtkhtml-msg-view.c index a2d66c1..98c8e4b 100644 --- a/src/widgets/modest-gtkhtml-msg-view.c +++ b/src/widgets/modest-gtkhtml-msg-view.c @@ -1405,7 +1405,7 @@ on_fetch_url (GtkWidget *widget, const gchar *uri, 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; } diff --git a/src/widgets/modest-mozembed-msg-view.c b/src/widgets/modest-mozembed-msg-view.c index d843acb..e13accc 100644 --- a/src/widgets/modest-mozembed-msg-view.c +++ b/src/widgets/modest-mozembed-msg-view.c @@ -618,7 +618,7 @@ on_fetch_url (GtkWidget *widget, const gchar *uri, result = FALSE; } else { tny_mime_part_decode_to_stream ((TnyMimePart*)part, - stream); + stream, NULL); g_object_unref (G_OBJECT(part)); result = TRUE; }