On failing to retrieve a message in view and closing, show header window
[modest] / src / hildon2 / modest-msg-view-window.c
index 6b0f9db..33a405d 100644 (file)
@@ -67,6 +67,7 @@
 #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>
 
 #define MYDOCS_ENV "MYDOCSDIR"
@@ -2169,6 +2170,59 @@ view_msg_cb (ModestMailOperation *mail_op,
                        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));
@@ -3631,7 +3685,6 @@ modest_msg_view_window_add_to_contacts (ModestMsgViewWindow *self)
        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) {
@@ -3647,51 +3700,11 @@ modest_msg_view_window_add_to_contacts (ModestMsgViewWindow *self)
                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