From 78bf9d9d708dd255cc0966d64112aba56a4b2544 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 12 Jul 2010 11:26:47 -0400 Subject: Bug 624128 - Folder -> Subscriptions is always enabled --- e-util/e-account-utils.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'e-util/e-account-utils.c') diff --git a/e-util/e-account-utils.c b/e-util/e-account-utils.c index 4395542f7c..66242408ac 100644 --- a/e-util/e-account-utils.c +++ b/e-util/e-account-utils.c @@ -137,3 +137,45 @@ e_get_account_by_uid (const gchar *uid) /* XXX EAccountList misuses const. */ return (EAccount *) account; } + +/** + * e_get_any_enabled_account: + * + * Returns the default mail account if it's enabled, otherwise the first + * enabled mail account in the global #EAccountList, or finally %NULL if + * all mail accounts are disabled or none exist. + * + * Returns: an enabled #EAccount, or %NULL if there are none + **/ +EAccount * +e_get_any_enabled_account (void) +{ + EAccount *account; + EAccountList *account_list; + EIterator *iter; + + account = e_get_default_account (); + if (account != NULL && account->enabled) + return account; + + account = NULL; + + account_list = e_get_account_list (); + iter = e_list_get_iterator (E_LIST (account_list)); + + while (e_iterator_is_valid (iter) && account == NULL) { + EAccount *candidate; + + /* XXX EIterator misuses const. */ + candidate = (EAccount *) e_iterator_get (iter); + + if (candidate->enabled) + account = candidate; + else + e_iterator_next (iter); + } + + g_object_unref (iter); + + return account; +} -- cgit v1.2.3