+
+ g_object_unref (parent);
+}
+
+static gint
+order_by_acc_name (gconstpointer a,
+ gconstpointer b)
+{
+ ModestPair *pair_a, *pair_b;
+
+ pair_a = (ModestPair *) a;
+ pair_b = (ModestPair *) b;
+
+ if (pair_a->second && pair_b->second) {
+ gint compare = g_utf8_collate ((gchar *) pair_a->second,
+ (gchar *) pair_b->second);
+ if (compare > 0)
+ compare = -1;
+ else if (compare < 0)
+ compare = 1;
+
+ return compare;
+ } else {
+ return 0;
+ }
+}
+
+static ModestPairList *
+get_folders_accounts_list (void)
+{
+ GSList *list = NULL;
+ GSList *cursor, *account_names;
+ ModestAccountMgr *account_mgr;
+ ModestPair *pair;
+
+ account_mgr = modest_runtime_get_account_mgr ();
+
+ cursor = account_names = modest_account_mgr_account_names (account_mgr, TRUE /*only enabled*/);
+ while (cursor) {
+ gchar *account_name;
+ ModestAccountSettings *settings;
+ ModestServerAccountSettings *store_settings;
+
+ account_name = (gchar*)cursor->data;
+
+ settings = modest_account_mgr_load_account_settings (account_mgr, account_name);
+ if (!settings) {
+ g_printerr ("modest: failed to get account data for %s\n", account_name);
+ continue;
+ }
+ store_settings = modest_account_settings_get_store_settings (settings);
+
+ /* don't display accounts not able to show folders */
+ if (modest_server_account_settings_get_account_name (store_settings) != NULL) {
+ ModestProtocolType protocol_type;
+
+ protocol_type = modest_server_account_settings_get_protocol (store_settings);
+ /* we cannot create folders on accounts without folders */
+ if (modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
+ protocol_type,
+ MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS)) {
+ if (modest_account_settings_get_enabled (settings)) {
+
+ pair = modest_pair_new (
+ g_strdup (account_name),
+ g_strdup (modest_account_settings_get_display_name (settings)),
+ FALSE);
+ list = g_slist_insert_sorted (list, pair, order_by_acc_name);
+ }
+ }
+ }
+
+ g_object_unref (store_settings);
+ g_object_unref (settings);
+ cursor = cursor->next;
+ }
+
+ /* Create also entries for local account and mmc */
+ pair = modest_pair_new (g_strdup (MODEST_LOCAL_FOLDERS_ACCOUNT_ID),
+ g_strdup (MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME),
+ FALSE);
+ list = g_slist_insert_sorted (list, pair, order_by_acc_name);
+
+ /* TODO: add mmc account */
+
+ return (ModestPairList *) g_slist_reverse (list);