* Some more changes related to the migration to the new tinymail "architecture"
[modest] / src / widgets / modest-folder-view.c
index 25979ac..28d8808 100644 (file)
@@ -77,8 +77,9 @@ static void         on_account_removed     (TnyAccountStore *self,
                                            TnyAccount *account,
                                            gpointer user_data);
 
-/* static void         on_accounts_reloaded   (TnyAccountStore *store,  */
-/*                                         gpointer user_data); */
+static void         on_account_inserted    (TnyAccountStore *self, 
+                                           TnyAccount *account,
+                                           gpointer user_data);
 
 static gint         cmp_rows               (GtkTreeModel *tree_model, 
                                            GtkTreeIter *iter1, 
@@ -151,7 +152,7 @@ struct _ModestFolderViewPrivate {
 
        gulong                account_update_signal;
        gulong                changed_signal;
-/*     gulong                accounts_reloaded_signal; */
+       gulong                account_inserted_signal;
        gulong                account_removed_signal;
        gulong                conf_key_signal;
        
@@ -696,8 +697,8 @@ modest_folder_view_finalize (GObject *obj)
        if (priv->account_store) {
                g_signal_handler_disconnect (G_OBJECT(priv->account_store),
                                             priv->account_update_signal);
-/*             g_signal_handler_disconnect (G_OBJECT(priv->account_store), */
-/*                                          priv->accounts_reloaded_signal); */
+               g_signal_handler_disconnect (G_OBJECT(priv->account_store),
+                                            priv->account_inserted_signal);
                g_signal_handler_disconnect (G_OBJECT(priv->account_store),
                                             priv->account_removed_signal);
                g_object_unref (G_OBJECT(priv->account_store));
@@ -761,10 +762,10 @@ modest_folder_view_set_account_store (TnyAccountStoreView *self, TnyAccountStore
                                                   priv->account_update_signal))
                        g_signal_handler_disconnect (G_OBJECT (priv->account_store), 
                                                     priv->account_update_signal);
-/*             if (g_signal_handler_is_connected (G_OBJECT (priv->account_store),  */
-/*                                                priv->accounts_reloaded_signal)) */
-/*                     g_signal_handler_disconnect (G_OBJECT (priv->account_store),  */
-/*                                                  priv->accounts_reloaded_signal); */
+               if (g_signal_handler_is_connected (G_OBJECT (priv->account_store),
+                                                  priv->account_inserted_signal))
+                       g_signal_handler_disconnect (G_OBJECT (priv->account_store),
+                                                    priv->account_inserted_signal);
                if (g_signal_handler_is_connected (G_OBJECT (priv->account_store), 
                                                   priv->account_removed_signal))
                        g_signal_handler_disconnect (G_OBJECT (priv->account_store), 
@@ -783,28 +784,58 @@ modest_folder_view_set_account_store (TnyAccountStoreView *self, TnyAccountStore
                g_signal_connect (G_OBJECT(account_store), "account_removed",
                                  G_CALLBACK (on_account_removed), self);
 
-/*     priv->accounts_reloaded_signal =  */
-/*             g_signal_connect (G_OBJECT(account_store), "accounts_reloaded", */
-/*                               G_CALLBACK (on_accounts_reloaded), self); */
+       priv->account_inserted_signal =
+               g_signal_connect (G_OBJECT(account_store), "account_inserted",
+                                 G_CALLBACK (on_account_inserted), self);
+
 
 /*     g_signal_connect (G_OBJECT(account_store), "connecting_finished", */
 /*                             G_CALLBACK (on_accounts_reloaded), self); */
 
 /*     on_accounts_reloaded (account_store, (gpointer ) self); */
+
+       modest_folder_view_update_model (MODEST_FOLDER_VIEW (self), account_store);
        
        g_object_unref (G_OBJECT (device));
 }
 
 static void
+on_account_inserted (TnyAccountStore *account_store, 
+                    TnyAccount *account,
+                    gpointer user_data)
+{
+       GtkTreeModel *sort_model, *filter_model;
+
+       /* TODO: invalidate the cur_folder_* and folder_to_select things */
+
+       /* Get the inner model */
+       filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (user_data));
+       sort_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model));
+
+       /* Insert the account in the model */
+       tny_list_append (TNY_LIST (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model))), 
+                        G_OBJECT (account));
+}
+
+static void
 on_account_removed (TnyAccountStore *account_store, 
                    TnyAccount *account,
                    gpointer user_data)
 {
        ModestFolderView *self = MODEST_FOLDER_VIEW (user_data);
        ModestFolderViewPrivate *priv;
+       GtkTreeModel *sort_model, *filter_model;
 
        priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
 
+       /* TODO: invalidate the cur_folder_* and folder_to_select things */
+
+       /* Remove the account from the model */
+       filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
+       sort_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model));
+       tny_list_remove (TNY_LIST (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model))),
+                        G_OBJECT (account));
+
        /* If the removed account is the currently viewed one then
           clear the configuration value. The new visible account will be the default account */
        if (priv->visible_account_id &&