+void
+modest_folder_view_set_account_id_of_visible_server_account (ModestFolderView *self,
+ const gchar *account_id)
+{
+ ModestFolderViewPrivate *priv;
+ GtkTreeModel *model;
+
+ g_return_if_fail (self);
+
+ priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
+
+ /* This will be used by the filter_row callback,
+ * to decided which rows to show: */
+ if (priv->visible_account_id) {
+ g_free (priv->visible_account_id);
+ priv->visible_account_id = NULL;
+ }
+ if (account_id)
+ priv->visible_account_id = g_strdup (account_id);
+
+ /* Refilter */
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
+ if (GTK_IS_TREE_MODEL_FILTER (model))
+ gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
+
+ /* Save settings to gconf */
+ modest_widget_memory_save (modest_runtime_get_conf (), G_OBJECT(self),
+ MODEST_CONF_FOLDER_VIEW_KEY);
+}
+
+const gchar *
+modest_folder_view_get_account_id_of_visible_server_account (ModestFolderView *self)
+{
+ ModestFolderViewPrivate *priv;
+
+ g_return_val_if_fail (self, NULL);
+
+ priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
+
+ return (const gchar *) priv->visible_account_id;
+}
+
+static gboolean
+find_inbox_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *inbox_iter)
+{
+ do {
+ GtkTreeIter child;
+ TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN;
+ gchar *name = NULL;
+
+ gtk_tree_model_get (model, iter,
+ TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &name,
+ TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN,
+ &type, -1);
+
+ /*
+ printf ("DEBUG: %s: name=%s, type=%d, TNY_FOLDER_TYPE_INBOX=%d\n",
+ __FUNCTION__, name, type, TNY_FOLDER_TYPE_INBOX);
+ */
+
+ gboolean result = FALSE;
+ if (type == TNY_FOLDER_TYPE_INBOX) {
+ result = TRUE;
+ } else if (type == TNY_FOLDER_TYPE_NORMAL) {
+ /* tinymail's camel implementation only provides TNY_FOLDER_TYPE_NORMAL
+ * when getting folders from the cache, before connectin, so we do
+ * an extra check. We could fix this in tinymail, but it's easier
+ * to do here.
+ */
+ if (strcmp (name, "Inbox") == 0)
+ result = TRUE;
+ }
+
+ g_free (name);
+
+ if (result) {
+ *inbox_iter = *iter;
+ return TRUE;
+ }
+
+ if (gtk_tree_model_iter_children (model, &child, iter)) {
+ if (find_inbox_iter (model, &child, inbox_iter))
+ return TRUE;
+ }
+
+ } while (gtk_tree_model_iter_next (model, iter));
+
+ return FALSE;
+}
+
+void
+modest_folder_view_select_first_inbox_or_local (ModestFolderView *self)
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter, inbox_iter;
+ GtkTreeSelection *sel;
+
+ /* Do not set it if the folder view was not painted */
+ if (!GTK_WIDGET_MAPPED (self))
+ return;
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
+ if (!model)
+ return;
+
+ expand_root_items (self);
+ sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
+
+ gtk_tree_model_get_iter_first (model, &iter);
+ if (find_inbox_iter (model, &iter, &inbox_iter)) {
+ gtk_tree_selection_select_iter (sel, &inbox_iter);
+ }
+ else {
+ gtk_tree_model_get_iter_first (model, &iter);
+ gtk_tree_selection_select_iter (sel, &iter);
+ }