2007-06-05 Murray Cumming <murrayc@murrayc.com>modest/trunk] > more ChangeLog2
[modest] / src / widgets / modest-folder-view.c
index 7e1cff1..523873b 100644 (file)
 #include <tny-folder.h>
 #include <tny-camel-folder.h>
 #include <tny-simple-list.h>
-#include <tny-merge-folder.h>
 #include <modest-tny-folder.h>
-#include <modest-tny-simple-folder-store.h>
+#include <modest-tny-local-folders-account.h>
 #include <modest-marshal.h>
 #include <modest-icon-names.h>
 #include <modest-tny-account-store.h>
-#include <modest-tny-outbox-account.h>
 #include <modest-text-utils.h>
 #include <modest-runtime.h>
 #include "modest-folder-view.h"
@@ -54,7 +52,7 @@
 #include <modest-platform.h>
 #include <modest-account-mgr-helpers.h>
 #include <modest-widget-memory.h>
-
+#include <modest-ui-actions.h>
 
 /* 'private'/'protected' functions */
 static void modest_folder_view_class_init  (ModestFolderViewClass *klass);
@@ -140,7 +138,6 @@ struct _ModestFolderViewPrivate {
        gulong                changed_signal;
        gulong                accounts_reloaded_signal;
        
-       GtkTreeSelection     *cur_selection;
        TnyFolderStoreQuery  *query;
        guint                 timer_expander;
 
@@ -299,26 +296,14 @@ text_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
 
        } else if (TNY_IS_ACCOUNT (instance)) {
                /* If it's a server account */
-               const gchar * account_id = tny_account_get_id (TNY_ACCOUNT (instance));
-               if (!strcmp (account_id, MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID)) {
+               if (modest_tny_account_is_virtual_local_folders (
+                               TNY_ACCOUNT (instance))) {
                        item_name = g_strdup (priv->local_account_name);
+                       item_weight = 400;
                } else {
-                       if (!strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) {
-                               /* TODO: get MMC card name */
-                               item_name = g_strdup (_("MMC"));
-                       } else {
-                               item_name = g_strdup (fname);
-                       }
+                       item_name = g_strdup (fname);
+                       item_weight = 800;
                }
-
-               item_weight = 800;
-       } else if (modest_tny_folder_store_is_virtual_local_folders (
-               TNY_FOLDER_STORE(instance)))
-       {
-               /* We use ModestTnySimpleFolder store to group the outboxes and 
-                * the other local folders together: */
-               item_name = g_strdup (_("Local Folders"));
-               item_weight = 400;
        }
        
        if (!item_name)
@@ -379,23 +364,19 @@ icon_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
        switch (type) {
        case TNY_FOLDER_TYPE_ROOT:
                if (TNY_IS_ACCOUNT (instance)) {
-                       account_id = tny_account_get_id (TNY_ACCOUNT (instance));
-                       /*
-                       if (!strcmp (account_id, MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID)) {
+                       
+                       if (modest_tny_account_is_virtual_local_folders (
+                               TNY_ACCOUNT (instance))) {
                                pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_LOCAL_FOLDERS);
-                       } else {
-                       */
+                       }
+                       else {
+                               account_id = tny_account_get_id (TNY_ACCOUNT (instance));
+                               
                                if (!strcmp (account_id, MODEST_MMC_ACCOUNT_ID))
                                        pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_MMC);
                                else
                                        pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_ACCOUNT);
-                       /*
                        }
-                       */
-               }
-               else if (modest_tny_folder_store_is_virtual_local_folders (
-                       TNY_FOLDER_STORE (instance))) {
-                       pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_LOCAL_FOLDERS);
                }
                break;
        case TNY_FOLDER_TYPE_INBOX:
@@ -493,9 +474,6 @@ modest_folder_view_init (ModestFolderView *obj)
        /* Setup drag and drop */
        setup_drag_and_drop (GTK_TREE_VIEW(obj));
 
-       /* Restore conf */
-       modest_widget_memory_restore (conf, G_OBJECT (obj), MODEST_CONF_FOLDER_VIEW_KEY);
-
        /* Connect signals */
        g_signal_connect (G_OBJECT (obj), 
                          "key-press-event", 
@@ -597,10 +575,6 @@ modest_folder_view_set_account_store (TnyAccountStoreView *self, TnyAccountStore
                g_signal_connect (G_OBJECT(account_store), "accounts_reloaded",
                                  G_CALLBACK (on_accounts_reloaded), self);
        
-       if (!update_model (MODEST_FOLDER_VIEW (self),
-                          MODEST_TNY_ACCOUNT_STORE (priv->account_store)))
-               g_printerr ("modest: failed to update model\n");
-
        g_object_unref (G_OBJECT (device));
 }
 
@@ -618,8 +592,12 @@ static void
 on_accounts_reloaded   (TnyAccountStore *account_store, 
                        gpointer user_data)
 {
+       ModestConf *conf = modest_runtime_get_conf ();
+
+       modest_widget_memory_save (conf, G_OBJECT (user_data), MODEST_CONF_FOLDER_VIEW_KEY);
        update_model (MODEST_FOLDER_VIEW (user_data), 
                      MODEST_TNY_ACCOUNT_STORE(account_store));
+       modest_widget_memory_restore (conf, G_OBJECT (user_data), MODEST_CONF_FOLDER_VIEW_KEY);
 }
 
 void
@@ -693,6 +671,13 @@ filter_row (GtkTreeModel *model,
                            TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance,
                            -1);
 
+       /* Do not show if there is no instance, this could indeed
+          happen when the model is being modified while it's being
+          drawn. This could occur for example when moving folders
+          using drag&drop */
+       if (!instance)
+               return FALSE;
+
        if (type == TNY_FOLDER_TYPE_ROOT) {
                /* TNY_FOLDER_TYPE_ROOT means that the instance is an account instead of a folder. */
                if (TNY_IS_ACCOUNT (instance)) {
@@ -701,21 +686,18 @@ filter_row (GtkTreeModel *model,
                        
                        /* If it isn't a special folder, 
                         * don't show it unless it is the visible account: */
-                       if (strcmp (account_id, MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID) &&
-                           strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) { 
-                               
-                               /* TODO: Merge the folders before we get to this point? */
-                               
+                       if (!modest_tny_account_is_virtual_local_folders (acc) &&
+                               strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) { 
                                /* Show only the visible account id */
-                               /*
                                ModestFolderViewPrivate *priv = 
                                        MODEST_FOLDER_VIEW_GET_PRIVATE (data);
                                if (priv->visible_account_id && strcmp (account_id, priv->visible_account_id))
                                        retval = FALSE;
-                               */
                        }
                }
        }
+       
+       /* The virtual local-folders folder store is also shown by default. */
 
        g_object_unref (instance);
 
@@ -732,99 +714,10 @@ static void on_tnylist_accounts_debug_print(gpointer data,  gpointer user_data)
 }
 */
 
-static void
-add_account_folders_to_merged_folder (TnyAccount *account, TnyMergeFolder* merge_folder)
-{
-       const gchar* account_id = tny_account_get_id (account);
-       const gboolean is_actual_local_folders_account = account_id && 
-               (strcmp (account_id, MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID) == 0);
-               
-       TnyList *list_outbox_folders = tny_simple_list_new ();
-       tny_folder_store_get_folders (TNY_FOLDER_STORE (account), 
-               list_outbox_folders, NULL, NULL);
-               
-       TnyIterator*  iter =  tny_list_create_iterator (list_outbox_folders);
-       while (!tny_iterator_is_done (iter))
-       {
-               TnyFolder *folder = TNY_FOLDER (tny_iterator_get_current (iter));
-               
-               if (folder) {
-                       gboolean add = TRUE;
-                       /* TODO: Do not add outboxes that are inside local-folders/, 
-                        * because these are just left-over from earlier Modest versions 
-                        * that put the outbox there: */
-                       if (is_actual_local_folders_account) {
-                               const TnyFolderType type = modest_tny_folder_get_local_folder_type (folder);
-                               if (type == TNY_FOLDER_TYPE_OUTBOX) {
-                                       add = FALSE;
-                               }
-                       }
-                       
-                       if (add)
-                               tny_merge_folder_add_folder (merge_folder, folder);
-                               
-                       g_object_unref (folder);        
-               }
-               
-               tny_iterator_next (iter);
-       }
-       
-       g_object_unref (list_outbox_folders);
-}
-
-
-static void
-add_account_folders_to_simple_folder_store (TnyAccount *account, ModestTnySimpleFolderStore* store)
-{
-       g_return_if_fail (account);
-       g_return_if_fail (store);
-               
-       TnyList *list_outbox_folders = tny_simple_list_new ();
-       tny_folder_store_get_folders (TNY_FOLDER_STORE (account), 
-               list_outbox_folders, NULL, NULL);
-       
-       /* Special handling for the .modest/local-folders account,
-        * to avoid adding unwanted folders.
-        * We cannot prevent them from being in the TnyAccount without 
-        * changing the libtinymail-camel. */
-       const gchar* account_id = tny_account_get_id (account);
-       const gboolean is_actual_local_folders_account = account_id && 
-               (strcmp (account_id, MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID) == 0);
-       
-       TnyIterator*  iter =  tny_list_create_iterator (list_outbox_folders);
-       while (!tny_iterator_is_done (iter))
-       {
-               TnyFolder *folder = TNY_FOLDER (tny_iterator_get_current (iter));
-               
-               if (folder) {
-                       gboolean add = TRUE;
-                       /* TODO: Do not add outboxes that are inside local-folders/, 
-                        * because these are just left-over from earlier Modest versions 
-                        * that put the outbox there: */
-                       if (is_actual_local_folders_account) {
-                               const TnyFolderType type = modest_tny_folder_get_local_folder_type (folder);
-                               if (type == TNY_FOLDER_TYPE_OUTBOX) {
-                                       add = FALSE;
-                               }
-                       }
-                       
-                       if (add)
-                               modest_tny_simple_folder_store_add_folder (store, folder);
-                               
-                       g_object_unref (folder);        
-               }
-               
-               tny_iterator_next (iter);
-       }
-       
-       g_object_unref (list_outbox_folders);
-}
-
 static gboolean
 update_model (ModestFolderView *self, ModestTnyAccountStore *account_store)
 {
        ModestFolderViewPrivate *priv;
-
        GtkTreeModel     *model;
 
        g_return_val_if_fail (account_store, FALSE);
@@ -845,68 +738,19 @@ update_model (ModestFolderView *self, ModestTnyAccountStore *account_store)
         * filling the TnyList via a get_accounts() call: */
        TnyList *model_as_list = TNY_LIST(model);
 
-       /* Create a virtual local-folders folder store, 
-        * containing the real local folders and the (merged) various per-account 
-        * outbox folders:
-        */
-       ModestTnySimpleFolderStore *store = modest_tny_simple_folder_store_new ();
-
        /* Get the accounts: */
-       TnyList *account_list = tny_simple_list_new ();
        tny_account_store_get_accounts (TNY_ACCOUNT_STORE(account_store),
-                                       account_list,
+                                       model_as_list,
                                        TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
-       TnyIterator* iter =  tny_list_create_iterator (account_list);
        
-       /* All per-account outbox folders are merged into one folders
-        * so that they appear as one outbox to the user: */
-       TnyMergeFolder *merged_outbox = TNY_MERGE_FOLDER (tny_merge_folder_new());
-       
-       while (!tny_iterator_is_done (iter))
-       {
-               GObject *cur = tny_iterator_get_current (iter);
-               TnyAccount *account = TNY_ACCOUNT (cur);
-               if (account) {
-                       /* Add both outbox account and local-folders account folders
-                        * to our one combined account:
-                        */
-                       if (MODEST_IS_TNY_OUTBOX_ACCOUNT (account)) {
-                               /* Add the folder to the merged folder.
-                                * We will add it later to the virtual local-folders store: */
-                               add_account_folders_to_merged_folder (account, merged_outbox);
-                       } else {
-                               const gchar *account_id = tny_account_get_id (account);
-                               if (account_id && !strcmp (account_id, MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID)) {
-                                       /* Add the folders to the virtual local-folders store: */
-                                       add_account_folders_to_simple_folder_store (account, store);
-                               }
-                               else {
-                                       /* Just add the account: */
-                                       tny_list_append (model_as_list, G_OBJECT (account));
-                               }
-                       }
-               }
-          
-               g_object_unref (cur);
-               tny_iterator_next (iter);
-       }
-       
-       /* Add the merged outbox folder to the virtual local-folders store: */
-       modest_tny_simple_folder_store_add_folder (store, TNY_FOLDER(merged_outbox));
-       g_object_unref (merged_outbox);
-       merged_outbox = NULL;
-       
-       /* Add the virtual local-folders store to the model: */
-       tny_list_append (model_as_list, G_OBJECT (store));
-       
-       
-       g_object_unref (account_list);
-       account_list = NULL;
        
        g_object_unref (model_as_list);
        model_as_list = NULL;   
-               
-       /* tny_list_foreach (account_list, on_tnylist_accounts_debug_print, "update_model: "); */
+       
+       /*      
+       if (account_list)
+               tny_list_foreach (account_list, on_tnylist_accounts_debug_print, "update_model: ");
+    */
                                                      
        GtkTreeModel *filter_model = NULL, *sortable = NULL;
 
@@ -950,8 +794,7 @@ on_selection_changed (GtkTreeSelection *sel, gpointer user_data)
        g_return_if_fail (user_data);
        
        priv = MODEST_FOLDER_VIEW_GET_PRIVATE(user_data);
-       priv->cur_selection = sel;
-       
+
        /* folder was _un_selected if true */
        if (!gtk_tree_selection_get_selected (sel, &model, &iter)) {
                if (priv->cur_folder_store)
@@ -1014,9 +857,9 @@ get_cmp_rows_type_pos (GObject *folder)
        /* Remote accounts -> Local account -> MMC account .*/
        /* 0, 1, 2 */
        
-       if (TNY_IS_FOLDER_STORE (folder) && 
-               modest_tny_folder_store_is_virtual_local_folders (
-                       TNY_FOLDER_STORE (folder))) {
+       if (TNY_IS_ACCOUNT (folder) && 
+               modest_tny_account_is_virtual_local_folders (
+                       TNY_ACCOUNT (folder))) {
                return 1;
        } else if (TNY_IS_ACCOUNT (folder)) {
                TnyAccount *account = TNY_ACCOUNT (folder);
@@ -1160,18 +1003,19 @@ typedef struct _DndHelper {
  * and drop action
  */
 static void
-on_progress_changed (ModestMailOperation *mail_op, gpointer user_data)
+on_progress_changed (ModestMailOperation *mail_op, 
+                    ModestMailOperationState *state,
+                    gpointer user_data)
 {
        gboolean success;
        DndHelper *helper;
 
        helper = (DndHelper *) user_data;
 
-       if (!modest_mail_operation_is_finished (mail_op))
+       if (!state->finished)
                return;
 
-       if (modest_mail_operation_get_status (mail_op) == 
-           MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
+       if (state->status == MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
                success = TRUE;
        } else {
                success = FALSE;
@@ -1216,7 +1060,7 @@ drag_and_drop_from_header_view (GtkTreeModel *source_model,
                            &folder, -1);
 
        /* Transfer message */
-       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, NULL);
+       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, NULL);
 
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                         mail_op);
@@ -1228,7 +1072,7 @@ drag_and_drop_from_header_view (GtkTreeModel *source_model,
        headers = tny_simple_list_new ();
        tny_list_append (headers, G_OBJECT (header));
        modest_mail_operation_xfer_msgs (mail_op, headers, folder, helper->delete_source, NULL, NULL);
-
+       
        /* Frees */
        g_object_unref (G_OBJECT (mail_op));
        g_object_unref (G_OBJECT (header));
@@ -1277,7 +1121,10 @@ drag_and_drop_from_folder_view (GtkTreeModel     *source_model,
                            &folder, -1);
 
        /* Do the mail operation */
-       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, NULL);
+       mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, 
+                                                                NULL,
+                                                                modest_ui_actions_move_folder_error_handler,
+                                                                NULL);
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
                                         mail_op);
        g_signal_connect (G_OBJECT (mail_op), "progress-changed",
@@ -1675,7 +1522,6 @@ modest_folder_view_set_account_id_of_visible_server_account (ModestFolderView *s
                                                             const gchar *account_id)
 {
        ModestFolderViewPrivate *priv;
-       ModestConf *conf;
        GtkTreeModel *model;
 
        g_return_if_fail (self);
@@ -1688,10 +1534,6 @@ modest_folder_view_set_account_id_of_visible_server_account (ModestFolderView *s
                g_free (priv->visible_account_id);
        priv->visible_account_id = g_strdup (account_id);
 
-       /* Save preferences */
-       conf = modest_runtime_get_conf ();
-       modest_widget_memory_save (conf, G_OBJECT (self), MODEST_CONF_FOLDER_VIEW_KEY);
-
        /* Refilter */
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
        if (GTK_IS_TREE_MODEL_FILTER (model))