+ if (!GTK_IS_TREE_VIEW(user_data)) {
+ g_warning ("BUG: %s: not a valid tree view", __FUNCTION__);
+ return;
+ }
+
+ /* Get the inner model */
+ /* check, is some rare cases, we did not get the right thing here,
+ * NB#84097 */
+ filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (user_data));
+ if (!GTK_IS_TREE_MODEL_FILTER(filter_model)) {
+ g_warning ("BUG: %s: not a valid filter model", __FUNCTION__);
+ return;
+ }
+
+ /* check, is some rare cases, we did not get the right thing here,
+ * NB#84097 */
+ sort_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model));
+ if (!GTK_IS_TREE_MODEL_SORT(sort_model)) {
+ g_warning ("BUG: %s: not a valid sort model", __FUNCTION__);
+ return;
+ }
+
+ /* 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));
+
+ /* Refilter the model */
+ gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filter_model));
+}
+
+
+static gboolean
+same_account_selected (ModestFolderView *self,
+ TnyAccount *account)
+{
+ ModestFolderViewPrivate *priv;
+ gboolean same_account = FALSE;
+
+ priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
+
+ if (priv->cur_folder_store) {
+ TnyAccount *selected_folder_account = NULL;
+
+ if (TNY_IS_FOLDER (priv->cur_folder_store)) {
+ selected_folder_account =
+ modest_tny_folder_get_account (TNY_FOLDER (priv->cur_folder_store));
+ } else {
+ selected_folder_account =
+ TNY_ACCOUNT (g_object_ref (priv->cur_folder_store));
+ }
+
+ if (selected_folder_account == account)
+ same_account = TRUE;
+
+ g_object_unref (selected_folder_account);
+ }
+ return same_account;
+}
+
+/**
+ *
+ * Selects the first inbox or the local account in an idle
+ */
+static gboolean
+on_idle_select_first_inbox_or_local (gpointer user_data)
+{
+ ModestFolderView *self = MODEST_FOLDER_VIEW (user_data);
+
+ gdk_threads_enter ();
+ modest_folder_view_select_first_inbox_or_local (self);
+ gdk_threads_leave ();
+
+ return FALSE;
+}
+
+static void
+on_account_changed (TnyAccountStore *account_store,
+ TnyAccount *tny_account,
+ gpointer user_data)
+{
+ ModestFolderView *self;
+ ModestFolderViewPrivate *priv;
+ GtkTreeModel *sort_model, *filter_model;
+ GtkTreeSelection *sel;
+ gboolean same_account;
+
+ /* Ignore transport account insertions, we're not showing them
+ in the folder view */
+ if (TNY_IS_TRANSPORT_ACCOUNT (tny_account))
+ return;
+
+ if (!MODEST_IS_FOLDER_VIEW(user_data)) {
+ g_warning ("BUG: %s: not a valid folder view", __FUNCTION__);
+ return;
+ }
+
+ self = MODEST_FOLDER_VIEW (user_data);
+ priv = MODEST_FOLDER_VIEW_GET_PRIVATE (user_data);
+
+ /* Get the inner model */
+ filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (user_data));
+ if (!GTK_IS_TREE_MODEL_FILTER(filter_model)) {
+ g_warning ("BUG: %s: not a valid filter model", __FUNCTION__);
+ return;