+/* modest_msg_view_window_update_dimmed (window); */
+
+}
+
+gboolean
+modest_msg_view_window_transfer_mode_enabled (ModestMsgViewWindow *self)
+{
+ ModestMsgViewWindowPrivate *priv;
+
+ g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (self), FALSE);
+ priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(self);
+
+ return priv->current_toolbar_mode == TOOLBAR_MODE_TRANSFER;
+}
+
+static void
+cancel_progressbar (GtkToolButton *toolbutton,
+ ModestMsgViewWindow *self)
+{
+ GSList *tmp;
+ ModestMsgViewWindowPrivate *priv;
+
+ priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(self);
+
+ /* Get operation observers and cancel its current operation */
+ tmp = priv->progress_widgets;
+ while (tmp) {
+ modest_progress_object_cancel_current_operation (MODEST_PROGRESS_OBJECT(tmp->data));
+ tmp=g_slist_next(tmp);
+ }
+}
+static gboolean
+observers_empty (ModestMsgViewWindow *self)
+{
+ GSList *tmp = NULL;
+ ModestMsgViewWindowPrivate *priv;
+ gboolean is_empty = TRUE;
+ guint pending_ops = 0;
+
+ priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(self);
+ tmp = priv->progress_widgets;
+
+ /* Check all observers */
+ while (tmp && is_empty) {
+ pending_ops = modest_progress_object_num_pending_operations (MODEST_PROGRESS_OBJECT(tmp->data));
+ is_empty = pending_ops == 0;
+
+ tmp = g_slist_next(tmp);
+ }
+
+ return is_empty;
+}
+
+static void
+on_account_removed (TnyAccountStore *account_store,
+ TnyAccount *account,
+ gpointer user_data)
+{
+ /* Do nothing if it's a transport account, because we only
+ show the messages of a store account */
+ if (tny_account_get_account_type(account) == TNY_ACCOUNT_TYPE_STORE) {
+ const gchar *parent_acc = NULL;
+ const gchar *our_acc = NULL;
+
+ our_acc = modest_window_get_active_account (MODEST_WINDOW (user_data));
+ parent_acc = modest_tny_account_get_parent_modest_account_name_for_server_account (account);
+
+ /* Close this window if I'm showing a message of the removed account */
+ if (strcmp (parent_acc, our_acc) == 0)
+ modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (user_data));
+ }
+}
+
+static void
+on_queue_changed (ModestMailOperationQueue *queue,
+ ModestMailOperation *mail_op,
+ ModestMailOperationQueueNotification type,
+ ModestMsgViewWindow *self)
+{
+ GSList *tmp;
+ ModestMsgViewWindowPrivate *priv;
+ ModestMailOperationTypeOperation op_type;
+ ModestToolBarModes mode;
+
+ g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (self));
+ priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(self);
+
+ /* If this operations was created by another window, do nothing */
+ if (!modest_mail_operation_is_mine (mail_op, G_OBJECT(self)))
+ return;
+
+ /* Get toolbar mode from operation id*/
+ op_type = modest_mail_operation_get_type_operation (mail_op);
+ switch (op_type) {
+/* case MODEST_MAIL_OPERATION_TYPE_SEND: */
+ case MODEST_MAIL_OPERATION_TYPE_RECEIVE:
+ case MODEST_MAIL_OPERATION_TYPE_OPEN:
+ mode = TOOLBAR_MODE_TRANSFER;
+ break;
+ default:
+ mode = TOOLBAR_MODE_NORMAL;
+
+ }
+
+ /* Add operation observers and change toolbar if neccessary*/
+ tmp = priv->progress_widgets;
+ switch (type) {
+ case MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED:
+ if (mode == TOOLBAR_MODE_TRANSFER) {
+ /* Enable transfer toolbar mode */
+ set_toolbar_transfer_mode(self);
+ while (tmp) {
+ modest_progress_object_add_operation (MODEST_PROGRESS_OBJECT (tmp->data),
+ mail_op);
+ tmp = g_slist_next (tmp);
+ }
+
+ }
+ break;
+ case MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED:
+ if (mode == TOOLBAR_MODE_TRANSFER) {
+ while (tmp) {
+ modest_progress_object_remove_operation (MODEST_PROGRESS_OBJECT (tmp->data),
+ mail_op);
+ tmp = g_slist_next (tmp);
+
+ }
+
+ /* If no more operations are being observed, NORMAL mode is enabled again */
+ if (observers_empty (self)) {
+ set_toolbar_mode (self, TOOLBAR_MODE_NORMAL);
+ }
+ }
+ break;
+ }
+}
+
+GList *
+modest_msg_view_window_get_attachments (ModestMsgViewWindow *win)
+{
+ ModestMsgViewWindowPrivate *priv;
+ GList *selected_attachments = NULL;
+
+ g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win), NULL);
+ priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (win);
+
+ selected_attachments = modest_msg_view_get_selected_attachments (MODEST_MSG_VIEW (priv->msg_view));
+
+ return selected_attachments;
+}
+
+void
+modest_msg_view_window_view_attachment (ModestMsgViewWindow *window, TnyMimePart *mime_part)
+{
+ ModestMsgViewWindowPrivate *priv;
+ g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window));
+ g_return_if_fail (TNY_IS_MIME_PART (mime_part) || (mime_part == NULL));
+
+ priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (window);
+
+ if (mime_part == NULL) {
+ gboolean error = FALSE;
+ GList *selected_attachments = modest_msg_view_get_selected_attachments (MODEST_MSG_VIEW (priv->msg_view));
+ if (selected_attachments == NULL) {
+ error = TRUE;
+ } else if (g_list_length (selected_attachments) > 1) {
+ hildon_banner_show_information (NULL, NULL, _("mcen_ib_unable_to_display_more"));
+ error = TRUE;
+ } else {
+ mime_part = (TnyMimePart *) selected_attachments->data;
+ g_object_ref (mime_part);
+ }
+ g_list_foreach (selected_attachments, (GFunc) g_object_unref, NULL);
+ g_list_free (selected_attachments);
+
+ if (error)
+ return;
+ } else {
+ g_object_ref (mime_part);
+ }
+
+ if (tny_mime_part_is_purged (mime_part)) {
+ g_object_unref (mime_part);
+ hildon_banner_show_information (NULL, NULL, _("mail_ib_attach_not_local"));
+ return;
+ }
+
+ if (!TNY_IS_MSG (mime_part)) {
+ gchar *filepath = NULL;
+ const gchar *att_filename = tny_mime_part_get_filename (mime_part);
+ gchar *extension = NULL;
+ TnyFsStream *temp_stream = NULL;
+
+ if (att_filename) {
+ extension = g_strrstr (att_filename, ".");
+ if (extension != NULL)
+ extension++;
+ }
+
+ temp_stream = modest_maemo_utils_create_temp_stream (extension, &filepath);
+
+ if (temp_stream) {
+ const gchar *content_type;
+ content_type = tny_mime_part_get_content_type (mime_part);
+ tny_mime_part_decode_to_stream (mime_part, TNY_STREAM (temp_stream));
+
+ modest_platform_activate_file (filepath, content_type);
+ g_object_unref (temp_stream);
+ g_free (filepath);
+ /* TODO: delete temporary file */
+ }
+ } else {
+ /* message attachment */
+ TnyHeader *header = NULL;
+ ModestWindowMgr *mgr;
+ ModestWindow *msg_win = NULL;
+ gboolean found;
+
+ header = tny_msg_get_header (TNY_MSG (mime_part));
+ mgr = modest_runtime_get_window_mgr ();
+ found = modest_window_mgr_find_registered_header (mgr, header, &msg_win);
+
+ if (found) {
+ if (msg_win) /* there is already a window for this uid; top it */
+ gtk_window_present (GTK_WINDOW(msg_win));
+ else
+ /* if it's found, but there is no msg_win, it's probably in the process of being created;
+ * thus, we don't do anything */
+ g_warning ("window for is already being created");
+ } else {
+ /* it's not found, so create a new window for it */
+ modest_window_mgr_register_header (mgr, header); /* register the uid before building the window */
+ gchar *account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (window)));
+ if (!account)
+ account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
+ msg_win = modest_msg_view_window_new (TNY_MSG (mime_part), account, NULL);
+ modest_window_set_zoom (MODEST_WINDOW (msg_win),
+ modest_window_get_zoom (MODEST_WINDOW (window)));
+ modest_window_mgr_register_window (mgr, msg_win);
+ gtk_window_set_transient_for (GTK_WINDOW (msg_win), GTK_WINDOW (window));
+ gtk_widget_show_all (GTK_WIDGET (msg_win));
+ }
+ }
+ g_object_unref (mime_part);
+}
+
+typedef struct
+{
+ gchar *filename;
+ TnyMimePart *part;
+} SaveMimePartPair;
+
+typedef struct
+{
+ GList *pairs;
+ GtkWidget *banner;
+ gboolean result;
+} SaveMimePartInfo;
+
+static void save_mime_part_info_free (SaveMimePartInfo *info, gboolean with_struct);
+static gboolean idle_save_mime_part_show_result (SaveMimePartInfo *info);
+static gpointer save_mime_part_to_file (SaveMimePartInfo *info);
+static void save_mime_parts_to_file_with_checks (SaveMimePartInfo *info);
+
+static void
+save_mime_part_info_free (SaveMimePartInfo *info, gboolean with_struct)
+{