return selected_attachments;
}
+typedef struct {
+ gchar *filepath;
+ GtkWidget *banner;
+ guint banner_idle_id;
+} DecodeAsyncHelper;
+
+static gboolean
+decode_async_banner_idle (gpointer user_data)
+{
+ DecodeAsyncHelper *helper = (DecodeAsyncHelper *) user_data;
+
+ helper->banner_idle_id = 0;
+ helper->banner = hildon_banner_show_animation (NULL, NULL, _("mail_me_opening"));
+ g_object_ref (helper->banner);
+
+ return FALSE;
+}
+
+static void
+on_decode_to_stream_async_handler (TnyMimePart *mime_part,
+ gboolean cancelled,
+ TnyStream *stream,
+ GError *err,
+ gpointer user_data)
+{
+ DecodeAsyncHelper *helper = (DecodeAsyncHelper *) user_data;
+
+ if (helper->banner_idle_id > 0) {
+ g_source_remove (helper->banner_idle_id);
+ helper->banner_idle_id = 0;
+ }
+ if (helper->banner) {
+ gtk_widget_destroy (helper->banner);
+ }
+ if (cancelled || err) {
+ modest_platform_information_banner (NULL, NULL,
+ _("mail_ib_file_operation_failed"));
+ goto free;
+ }
+
+ /* make the file read-only */
+ g_chmod(helper->filepath, 0444);
+
+ /* Activate the file */
+ modest_platform_activate_file (helper->filepath, tny_mime_part_get_content_type (mime_part));
+
+ free:
+ /* Frees */
+ g_free (helper->filepath);
+ g_object_unref (helper->banner);
+ g_slice_free (DecodeAsyncHelper, helper);
+}
+
void
modest_msg_view_window_view_attachment (ModestMsgViewWindow *window, TnyMimePart *mime_part)
{
if (!modest_tny_mime_part_is_msg (mime_part)) {
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);
- 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));
-
- 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);
- }
- }
+ DecodeAsyncHelper *helper = g_slice_new (DecodeAsyncHelper);
+ helper->filepath = g_strdup (filepath);
+ helper->banner = NULL;
+ helper->banner_idle_id = g_timeout_add (1000, decode_async_banner_idle, helper);
+ tny_mime_part_decode_to_stream_async (mime_part, TNY_STREAM (temp_stream),
+ on_decode_to_stream_async_handler,
+ NULL,
+ helper);
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) {
+ const gchar *content_type;
/* 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);