2007-06-03 Armin Burgmeier <armin@openismus.com>
[modest] / src / widgets / modest-folder-view.c
index 6df05de..120725b 100644 (file)
@@ -54,7 +54,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 +140,6 @@ struct _ModestFolderViewPrivate {
        gulong                changed_signal;
        gulong                accounts_reloaded_signal;
        
-       GtkTreeSelection     *cur_selection;
        TnyFolderStoreQuery  *query;
        guint                 timer_expander;
 
@@ -303,12 +302,7 @@ text_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
                if (!strcmp (account_id, MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID)) {
                        item_name = g_strdup (priv->local_account_name);
                } 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;
@@ -317,7 +311,7 @@ text_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
        {
                /* We use ModestTnySimpleFolder store to group the outboxes and 
                 * the other local folders together: */
-               item_name = g_strdup (_("Local Folders"));
+               item_name = g_strdup (priv->local_account_name);
                item_weight = 400;
        }
        
@@ -493,9 +487,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 +588,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 +605,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 +684,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,11 +699,7 @@ 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 (strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) { 
                                /* Show only the visible account id */
                                ModestFolderViewPrivate *priv = 
                                        MODEST_FOLDER_VIEW_GET_PRIVATE (data);
@@ -714,6 +708,8 @@ filter_row (GtkTreeModel *model,
                        }
                }
        }
+       
+       /* The virtual local-folders folder store is also shown by default. */
 
        g_object_unref (instance);
 
@@ -822,7 +818,6 @@ static gboolean
 update_model (ModestFolderView *self, ModestTnyAccountStore *account_store)
 {
        ModestFolderViewPrivate *priv;
-
        GtkTreeModel     *model;
 
        g_return_val_if_fail (account_store, FALSE);
@@ -948,8 +943,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)
@@ -1158,18 +1152,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;
@@ -1214,7 +1209,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);
@@ -1226,7 +1221,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));
@@ -1275,7 +1270,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",
@@ -1673,7 +1671,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);
@@ -1686,10 +1683,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))