+/*
+ * We use this function to implement the
+ * MODEST_FOLDER_VIEW_STYLE_SHOW_ONE style. We only show the default
+ * account in this case, and the local folders.
+ */
+static gboolean
+filter_row (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ gboolean retval = TRUE;
+ gint type = 0;
+ GObject *instance = NULL;
+
+ gtk_tree_model_get (model, iter,
+ TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
+ TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance,
+ -1);
+
+ 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)) {
+ TnyAccount *acc = TNY_ACCOUNT (instance);
+ const gchar *account_id = tny_account_get_id (acc);
+
+ /* 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? */
+
+ /* 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;
+ */
+ }
+ }
+ }
+
+ g_object_unref (instance);
+
+ return retval;
+}
+
+/*
+static void on_tnylist_accounts_debug_print(gpointer data, gpointer user_data)
+{
+ TnyAccount* account = TNY_ACCOUNT(data);
+ const gchar *prefix = (const gchar*)(user_data);
+
+ printf("%s account id=%s\n", prefix, tny_account_get_id (account));
+}
+*/
+
+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);
+}
+