* src/maemo/modest-msg-view-window.c:
[modest] / src / modest-ui-actions.c
index 38fdd3d..5dc7a56 100644 (file)
@@ -73,6 +73,8 @@
 #include <tny-device.h>
 #include <tny-merge-folder.h>
 
+#include <gtkhtml/gtkhtml.h>
+
 typedef struct _GetMsgAsyncHelper {    
        ModestWindow *window;
        ModestMailOperation *mail_op;
@@ -490,9 +492,9 @@ modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
                        return;
        }
        
-       account_name = g_strdup(modest_window_get_active_account (win));
+       account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
        if (!account_name)
-               account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
+               account_name = g_strdup (modest_window_get_active_account (win));
        if (!account_name) {
                g_printerr ("modest: no account found\n");
                goto cleanup;
@@ -582,9 +584,9 @@ open_msg_cb (ModestMailOperation *mail_op,
        headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
 
        /* Get account */
-       account =  g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
+       account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
        if (!account)
-               account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
+               account =  g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
        
        /* Gets folder type (OUTBOX headers will be opened in edit window */
        if (modest_tny_folder_is_local_folder (folder))
@@ -1253,6 +1255,7 @@ folder_refreshed_cb (const GObject *obj,
                     TnyFolder *folder, 
                     gpointer user_data)
 {
+       printf ("DEBUG: %s\n", __FUNCTION__);
        ModestMainWindow *win = NULL;
        GtkWidget *header_view;
 
@@ -1264,9 +1267,20 @@ folder_refreshed_cb (const GObject *obj,
 
        /* Check if folder is empty and set headers view contents style */
        if (tny_folder_get_all_count (folder) == 0) {
+       printf ("DEBUG: %s: tny_folder_get_all_count() returned 0.\n", __FUNCTION__);
                modest_main_window_set_contents_style (win,
                                                       MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
        } else {
+               printf ("DEBUG: %s: tny_folder_get_all_count() returned >0.\n", __FUNCTION__);
+
+               /* Set the header view, we could change it to
+                  the empty view after the refresh. We do not
+                  need to save the configuration because we
+                  have already done that when unselecting the
+                  folder */
+               modest_main_window_set_contents_style (win, 
+                                                      MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
+
                /* Restore configuration. There is no need to set the
                   contents style to headers because it was already
                   being done in folder_selection_changed */
@@ -1309,15 +1323,6 @@ modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
                                g_object_unref (account);
                        }
 
-                       /* Set the header view, we could change it to
-                          the empty view after the refresh */
-                       modest_main_window_set_contents_style (main_window, 
-                                                              MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
-                       
-                       modest_widget_memory_save (modest_runtime_get_conf(),
-                                                  G_OBJECT(header_view),
-                                                  MODEST_CONF_HEADER_VIEW_KEY);
-
                        /* Set folder on header view. This function
                           will call tny_folder_refresh_async so we
                           pass a callback that will be called when
@@ -2242,6 +2247,8 @@ modest_ui_actions_on_select_all (GtkAction *action,
                /* Select all messages */
                selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
                gtk_tree_selection_select_all (selection);
+       } else if (GTK_IS_HTML (focused_widget)) {
+               gtk_html_select_all (GTK_HTML (focused_widget));
        }
 }
 
@@ -2570,7 +2577,7 @@ create_move_to_dialog (ModestWindow *win,
                                         GTK_POLICY_AUTOMATIC);
 
        /* Create folder view */
-       *tree_view = modest_folder_view_new (NULL);
+       *tree_view = modest_platform_create_folder_view (NULL);
 
        /* It could happen that we're trying to move a message from a
           window (msg window for example) after the main window was
@@ -2591,6 +2598,9 @@ create_move_to_dialog (ModestWindow *win,
 
        gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
 
+       /* Select INBOX or local account */
+       modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (*tree_view));
+
        return dialog;
 }
 
@@ -2673,16 +2683,17 @@ msgs_move_to_confirmation (GtkWindow *win,
 
 
 static void
-tranasfer_msgs_from_viewer_cb (const GObject *object, gpointer user_data)
+transfer_msgs_from_viewer_cb (const GObject *object, gpointer user_data)
 {
        ModestMsgViewWindow *self = NULL;
-       gboolean found = FALSE;
 
        g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (object));
        self = MODEST_MSG_VIEW_WINDOW (object);
 
-       found = modest_msg_view_window_select_first_message (self);
-       g_return_if_fail (found);
+       /* If there are not more messages don't do anything. The
+          viewer will show the same message */
+       if (!modest_msg_view_window_select_first_message (self))
+           return;
 }
 
 void
@@ -2855,7 +2866,7 @@ modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
                                                         headers,
                                                         TNY_FOLDER (folder_store),
                                                         TRUE,
-                                                        tranasfer_msgs_from_viewer_cb,
+                                                        transfer_msgs_from_viewer_cb,
                                                         NULL);
                        g_object_unref (G_OBJECT (mail_op));
                }
@@ -2891,22 +2902,34 @@ do_headers_action (ModestWindow *win,
 {
        TnyList *headers_list;
        TnyIterator *iter;
+       TnyHeader *header;
+       TnyFolder *folder;
 
        /* Get headers */
        headers_list = get_selected_headers (win);
        if (!headers_list)
                return;
 
-       /* Call the function for each header */
+       /* Get the folder */
        iter = tny_list_create_iterator (headers_list);
-       while (!tny_iterator_is_done (iter)) {
-               TnyHeader *header;
+       header = TNY_HEADER (tny_iterator_get_current (iter));
+       folder = tny_header_get_folder (header);
+       g_object_unref (header);
 
+       /* Call the function for each header */
+       while (!tny_iterator_is_done (iter)) {
                header = TNY_HEADER (tny_iterator_get_current (iter));
                func (header, win, user_data);
                g_object_unref (header);
                tny_iterator_next (iter);
        }
+
+       /* Trick: do a poke status in order to speed up the signaling
+          of observers */
+       tny_folder_poke_status (folder);
+
+       /* Frees */
+       g_object_unref (folder);
        g_object_unref (iter);
        g_object_unref (headers_list);
 }