#include <modest-debug.h>
#include <modest-header-window.h>
#include <modest-account-protocol.h>
+#include <modest-hildon2-window-mgr.h>
+#include <tny-camel-msg.h>
+#include <tny-camel-bs-mime-part.h>
+#include <tny-camel-bs-msg.h>
#define MYDOCS_ENV "MYDOCSDIR"
#define DOCS_FOLDER ".documents"
GdkEvent *event,
gpointer userdata);
static void update_branding (ModestMsgViewWindow *self);
+static void sync_flags (ModestMsgViewWindow *self);
/* list my signals */
enum {
MODEST_HEADER_VIEW_OBSERVER(self));
}
}
-}
+}
static void
modest_msg_view_window_finalize (GObject *obj)
priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (window);
-
-
is_merge = g_str_has_prefix (msg_uid, "merge:");
/* Get the account */
account = tny_account_store_find_account (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()),
msg_uid);
-
if (is_merge || account) {
TnyFolder *folder = NULL;
update_window_title (MODEST_MSG_VIEW_WINDOW (window));
update_branding (MODEST_MSG_VIEW_WINDOW (window));
g_object_unref (msg);
+ /* Sync flags to server */
+ sync_flags (MODEST_MSG_VIEW_WINDOW (window));
} else {
message_reader (window, priv, NULL, msg_uid, folder, NULL);
}
info = (MsgReaderInfo *) user_data;
if (canceled || err) {
update_window_title (MODEST_MSG_VIEW_WINDOW (parent_window));
+ modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (parent_window));
goto frees;
}
gtk_tree_row_reference_free (row_reference);
self = (ModestMsgViewWindow *) modest_mail_operation_get_source (mail_op);
if (self) {
+ priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self);
+ /* First we check if the parent is a folder window */
+ if (priv->msg_uid && !modest_hildon2_window_mgr_get_folder_window (MODEST_HILDON2_WINDOW_MGR (modest_runtime_get_window_mgr ()))) {
+ gboolean is_merge;
+ TnyAccount *account = NULL;
+ GtkWidget *header_window = NULL;
+
+ is_merge = g_str_has_prefix (priv->msg_uid, "merge:");
+
+ /* Get the account */
+ if (!is_merge)
+ account = tny_account_store_find_account (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()),
+ priv->msg_uid);
+
+ if (is_merge || account) {
+ TnyFolder *folder = NULL;
+
+ /* Try to get the message, if it's already downloaded
+ we don't need to connect */
+ if (account) {
+ folder = modest_tny_folder_store_find_folder_from_uri (TNY_FOLDER_STORE (account),
+ priv->msg_uid);
+ } else {
+ ModestTnyAccountStore *account_store;
+ ModestTnyLocalFoldersAccount *local_folders_account;
+
+ account_store = modest_runtime_get_account_store ();
+ local_folders_account = MODEST_TNY_LOCAL_FOLDERS_ACCOUNT (
+ modest_tny_account_store_get_local_folders_account (account_store));
+ folder = modest_tny_local_folders_account_get_merged_outbox (local_folders_account);
+ g_object_unref (local_folders_account);
+ }
+ if (account) g_object_unref (account);
+
+ if (folder) {
+ header_window = (GtkWidget *)
+ modest_header_window_new (
+ folder,
+ modest_window_get_active_account (MODEST_WINDOW (self)),
+ modest_window_get_active_mailbox (MODEST_WINDOW (self)));
+ if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr (),
+ MODEST_WINDOW (header_window),
+ NULL)) {
+ gtk_widget_destroy (GTK_WIDGET (header_window));
+ } else {
+ gtk_widget_show_all (GTK_WIDGET (header_window));
+ }
+ g_object_unref (folder);
+ }
+ }
+ }
+
+
/* Restore window title */
update_window_title (self);
modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (self));
return;
}
+ if (msg && TNY_IS_CAMEL_BS_MSG (msg)) {
+ TnyMimePart *body;
+ body = modest_tny_msg_find_body_part (msg, TRUE);
+
+ if (body && !tny_camel_bs_mime_part_is_fetched (TNY_CAMEL_BS_MIME_PART (body))) {
+ /* We have body structure but not the body mime part. What we do
+ * is restarting load of message */
+ self = (ModestMsgViewWindow *) modest_mail_operation_get_source (mail_op);
+ priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self);
+
+ tny_header_unset_flag (TNY_HEADER (header), TNY_HEADER_FLAG_CACHED);
+
+ modest_msg_view_window_reload (self);
+
+ if (row_reference)
+ gtk_tree_row_reference_free (row_reference);
+ g_object_unref (body);
+ return;
+ }
+
+ if (body)
+ g_object_unref (body);
+ }
+
/* Get the window */
self = (ModestMsgViewWindow *) modest_mail_operation_get_source (mail_op);
g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (self));
}
/* Notify the observers */
- g_signal_emit (G_OBJECT (self), signals[MSG_CHANGED_SIGNAL],
+ g_signal_emit (G_OBJECT (self), signals[MSG_CHANGED_SIGNAL],
0, priv->header_model, priv->row_reference);
+ /* Sync the flags if the message is not opened from a header
+ model, i.e, if it's opened from a notification */
+ if (!priv->header_model)
+ sync_flags (self);
+
/* Frees */
g_object_unref (self);
if (row_reference)
- gtk_tree_row_reference_free (row_reference);
+ gtk_tree_row_reference_free (row_reference);
}
TnyFolderType
typedef struct {
ModestMsgViewWindow *self;
gchar *file_path;
+ gchar *attachment_uid;
} DecodeAsyncHelper;
static void
gpointer user_data)
{
DecodeAsyncHelper *helper = (DecodeAsyncHelper *) user_data;
-
- /* It could happen that the window was closed */
- if (GTK_WIDGET_VISIBLE (helper->self))
- set_progress_hint (helper->self, FALSE);
+ const gchar *content_type;
if (cancelled || err) {
if (err) {
- gchar *msg = g_strdup_printf (_KR("cerm_device_memory_full"), "");
+ gchar *msg;
+ if ((err->domain == TNY_ERROR_DOMAIN) &&
+ (err->code == TNY_IO_ERROR_WRITE) &&
+ (errno == ENOSPC)) {
+ msg = g_strdup_printf (_KR("cerm_device_memory_full"), "");
+ } else {
+ msg = g_strdup (_("mail_ib_file_operation_failed"));
+ }
modest_platform_information_banner (NULL, NULL, msg);
g_free (msg);
}
goto free;
}
- /* make the file read-only */
- g_chmod(helper->file_path, 0444);
+ /* It could happen that the window was closed. So we
+ assume it is a cancelation */
+ if (!GTK_WIDGET_VISIBLE (helper->self))
+ goto free;
+
+ /* Remove the progress hint */
+ set_progress_hint (helper->self, FALSE);
+
+ content_type = tny_mime_part_get_content_type (mime_part);
+ if (g_str_has_prefix (content_type, "message/rfc822")) {
+ ModestWindowMgr *mgr;
+ ModestWindow *msg_win = NULL;
+ TnyMsg * msg;
+ gchar *account;
+ const gchar *mailbox;
+ TnyStream *file_stream;
+ gint fd;
+
+ fd = g_open (helper->file_path, O_RDONLY, 0644);
+ if (fd != -1) {
+ file_stream = tny_fs_stream_new (fd);
+
+ mgr = modest_runtime_get_window_mgr ();
+
+ account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (helper->self)));
+ mailbox = modest_window_get_active_mailbox (MODEST_WINDOW (helper->self));
+
+ if (!account)
+ account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
- /* Activate the file */
- modest_platform_activate_file (helper->file_path, tny_mime_part_get_content_type (mime_part));
+ msg = tny_camel_msg_new ();
+ tny_camel_msg_parse (msg, file_stream);
+ msg_win = modest_msg_view_window_new_for_attachment (TNY_MSG (msg), account, mailbox, helper->attachment_uid);
+ modest_window_set_zoom (MODEST_WINDOW (msg_win),
+ modest_window_get_zoom (MODEST_WINDOW (helper->self)));
+ if (modest_window_mgr_register_window (mgr, msg_win, MODEST_WINDOW (helper->self)))
+ gtk_widget_show_all (GTK_WIDGET (msg_win));
+ else
+ gtk_widget_destroy (GTK_WIDGET (msg_win));
+ g_object_unref (msg);
+ g_object_unref (file_stream);
+ } else {
+ modest_platform_information_banner (NULL, NULL, _("mail_ib_file_operation_failed"));
+ }
+
+ } else {
+
+ /* make the file read-only */
+ g_chmod(helper->file_path, 0444);
+
+ /* Activate the file */
+ modest_platform_activate_file (helper->file_path, tny_mime_part_get_content_type (mime_part));
+ }
free:
/* Frees */
g_object_unref (helper->self);
g_free (helper->file_path);
+ g_free (helper->attachment_uid);
g_slice_free (DecodeAsyncHelper, helper);
}
+static void
+view_attachment_connect_handler (gboolean canceled,
+ GError *err,
+ GtkWindow *parent_window,
+ TnyAccount *account,
+ TnyMimePart *part)
+{
+
+ if (canceled || err) {
+ g_object_unref (part);
+ return;
+ }
+
+ modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (parent_window),
+ part);
+ g_object_unref (part);
+}
+
void
modest_msg_view_window_view_attachment (ModestMsgViewWindow *window,
TnyMimePart *mime_part)
if (tny_mime_part_is_purged (mime_part))
goto frees;
+ if (TNY_IS_CAMEL_BS_MIME_PART (mime_part) &&
+ !tny_camel_bs_mime_part_is_fetched (TNY_CAMEL_BS_MIME_PART (mime_part))) {
+ gboolean is_merge;
+ TnyAccount *account;
+
+ is_merge = g_str_has_prefix (priv->msg_uid, "merge:");
+ account = NULL;
+ /* Get the account */
+ if (!is_merge)
+ account = tny_account_store_find_account (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()),
+ priv->msg_uid);
+
+ if (!tny_device_is_online (modest_runtime_get_device())) {
+ modest_platform_connect_and_perform (GTK_WINDOW (window),
+ TRUE,
+ TNY_ACCOUNT (account),
+ (ModestConnectedPerformer) view_attachment_connect_handler,
+ g_object_ref (mime_part));
+ goto frees;
+ }
+ }
+
if (!modest_tny_mime_part_is_msg (mime_part) && tny_mime_part_get_filename (mime_part)) {
gchar *filepath = NULL;
const gchar *att_filename = tny_mime_part_get_filename (mime_part);
helper = g_slice_new0 (DecodeAsyncHelper);
helper->self = g_object_ref (window);
helper->file_path = g_strdup (filepath);
+ helper->attachment_uid = g_strdup (attachment_uid);
decode_in_provider = FALSE;
mgr = modest_runtime_get_account_mgr ();
account = modest_window_get_active_account (MODEST_WINDOW (window));
if (modest_account_mgr_account_is_multimailbox (mgr, account, &protocol)) {
if (MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
+ gchar *uri;
+ uri = g_strconcat ("file://", filepath, NULL);
decode_in_provider =
modest_account_protocol_decode_part_to_stream_async (
MODEST_ACCOUNT_PROTOCOL (protocol),
mime_part,
- NULL,
+ filepath,
TNY_STREAM (temp_stream),
on_decode_to_stream_async_handler,
NULL,
helper);
+ g_free (uri);
}
}
* hildon_banner_show_information is or does Gtk+ code */
gdk_threads_enter (); /* CHECKED */
- if (info->result == GNOME_VFS_OK) {
+ if (info->result == GNOME_VFS_ERROR_CANCELLED) {
+ /* nothing */
+ } else if (info->result == GNOME_VFS_OK) {
hildon_banner_show_information (NULL, NULL, _CS("sfil_ib_saved"));
} else if (info->result == GNOME_VFS_ERROR_NO_SPACE) {
gchar *msg = NULL;
return FALSE;
}
+static void
+save_mime_part_to_file_connect_handler (gboolean canceled,
+ GError *err,
+ GtkWindow *parent_window,
+ TnyAccount *account,
+ SaveMimePartInfo *info)
+{
+ if (canceled || err) {
+ if (canceled && !err) {
+ info->result = GNOME_VFS_ERROR_CANCELLED;
+ }
+ g_idle_add ((GSourceFunc) idle_save_mime_part_show_result, info);
+ } else {
+ g_thread_create ((GThreadFunc)save_mime_part_to_file, info, FALSE, NULL);
+ }
+}
+
+static gboolean
+save_mime_part_to_file_connect_idle (SaveMimePartInfo *info)
+{
+ gboolean is_merge;
+ TnyAccount *account;
+ ModestMsgViewWindowPrivate *priv;
+
+ priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (info->window);
+
+ is_merge = g_str_has_prefix (priv->msg_uid, "merge:");
+ account = NULL;
+
+ /* Get the account */
+ if (!is_merge)
+ account = tny_account_store_find_account (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()),
+ priv->msg_uid);
+
+ modest_platform_connect_and_perform (GTK_WINDOW (info->window),
+ TRUE,
+ TNY_ACCOUNT (account),
+ (ModestConnectedPerformer) save_mime_part_to_file_connect_handler,
+ info);
+ return FALSE;
+}
+
static gpointer
save_mime_part_to_file (SaveMimePartInfo *info)
{
TnyStream *stream;
SaveMimePartPair *pair = (SaveMimePartPair *) info->pairs->data;
+ if (TNY_IS_CAMEL_BS_MIME_PART (pair->part) &&
+ !tny_camel_bs_mime_part_is_fetched (TNY_CAMEL_BS_MIME_PART (pair->part))) {
+ g_idle_add ((GSourceFunc) save_mime_part_to_file_connect_idle, info);
+ return NULL;
+ }
+
info->result = gnome_vfs_create (&handle, pair->filename, GNOME_VFS_OPEN_WRITE, FALSE, 0644);
if (info->result == GNOME_VFS_OK) {
GError *error = NULL;
priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self);
GSList *recipients = NULL;
TnyMsg *msg = NULL;
- gboolean contacts_to_add = FALSE;
msg = tny_msg_view_get_msg (TNY_MSG_VIEW (priv->msg_view));
if (msg == NULL) {
g_object_unref (msg);
}
- if (recipients != NULL) {
- GtkWidget *picker_dialog;
- GtkWidget *selector;
- GSList *node;
- gchar *selected = NULL;
-
- selector = hildon_touch_selector_new_text ();
- g_object_ref (selector);
-
- for (node = recipients; node != NULL; node = g_slist_next (node)) {
- if (!modest_address_book_has_address ((const gchar *) node->data)) {
- hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
- (const gchar *) node->data);
- contacts_to_add = TRUE;
- }
- }
-
- if (contacts_to_add) {
- gint picker_result;
-
- picker_dialog = hildon_picker_dialog_new (GTK_WINDOW (self));
- gtk_window_set_title (GTK_WINDOW (picker_dialog), _("mcen_me_viewer_addtocontacts"));
-
- hildon_picker_dialog_set_selector (HILDON_PICKER_DIALOG (picker_dialog),
- HILDON_TOUCH_SELECTOR (selector));
-
- picker_result = gtk_dialog_run (GTK_DIALOG (picker_dialog));
-
- if (picker_result == GTK_RESPONSE_OK) {
- selected = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
- }
- gtk_widget_destroy (picker_dialog);
-
- if (selected)
- modest_address_book_add_address (selected, (GtkWindow *) self);
- g_free (selected);
-
- } else {
-
- g_object_unref (selector);
-
- }
+ if (recipients) {
+ /* Offer the user to add recipients to the address book */
+ modest_address_book_add_address_list_with_selector (recipients, (GtkWindow *) self);
+ g_slist_foreach (recipients, (GFunc) g_free, NULL); g_slist_free (recipients);
}
-
- if (recipients) {g_slist_foreach (recipients, (GFunc) g_free, NULL); g_slist_free (recipients);}
}
static gboolean
modest_msg_view_set_branding (MODEST_MSG_VIEW (priv->msg_view), service_name, service_icon);
g_free (service_name);
}
+
+static void
+sync_flags (ModestMsgViewWindow *self)
+{
+ TnyHeader *header = NULL;
+
+ header = modest_msg_view_window_get_header (self);
+ if (!header) {
+ TnyMsg *msg = modest_msg_view_window_get_message (self);
+ if (msg) {
+ header = tny_msg_get_header (msg);
+ g_object_unref (msg);
+ }
+ }
+
+ if (header) {
+ TnyFolder *folder = tny_header_get_folder (header);
+
+ if (folder) {
+ ModestMailOperation *mail_op;
+
+ /* Sync folder, we need this to save the seen flag */
+ mail_op = modest_mail_operation_new (NULL);
+ modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
+ mail_op);
+ modest_mail_operation_sync_folder (mail_op, folder, FALSE, NULL, NULL);
+ g_object_unref (mail_op);
+ g_object_unref (folder);
+ }
+ g_object_unref (header);
+ }
+}