diff options
author | Not Zed <NotZed@Ximian.com> | 2003-02-24 10:51:01 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2003-02-24 10:51:01 +0800 |
commit | 9491a06552c8c095132750aa505573d1315ca73f (patch) | |
tree | 966873787945d7ed4040b0df5afe57a9698102d5 /e-util/e-account-list.c | |
parent | 87f2abd1f0327a8fbd459ae90fbc6b50ab83a625 (diff) | |
download | gsoc2013-evolution-9491a06552c8c095132750aa505573d1315ca73f.tar.gz gsoc2013-evolution-9491a06552c8c095132750aa505573d1315ca73f.tar.zst gsoc2013-evolution-9491a06552c8c095132750aa505573d1315ca73f.zip |
helper to get the dfault account. (e_account_list_set_default): helper to
2003-02-20 Not Zed <NotZed@Ximian.com>
* e-account-list.c (e_account_list_get_default): helper to get the
dfault account.
(e_account_list_set_default): helper to set the default account.
(e_account_list_find): Helper to find accounts based on differnet
key types.
(e_account_list_add): helper to add account + emit added event.
(e_account_list_change): helper to emit changed event.
(e_account_list_remove): herlper to remove account + emit changed event.
svn path=/trunk/; revision=20015
Diffstat (limited to 'e-util/e-account-list.c')
-rw-r--r-- | e-util/e-account-list.c | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/e-util/e-account-list.c b/e-util/e-account-list.c index e7d2b2f66b..32d44451e7 100644 --- a/e-util/e-account-list.c +++ b/e-util/e-account-list.c @@ -286,3 +286,169 @@ e_account_list_save (EAccountList *account_list) gconf_client_suggest_sync (account_list->priv->gconf, NULL); } + +/** + * e_account_list_add: + * @accounts: + * @account: + * + * Add an account to the account list. Will emit the account-changed + * event. + **/ +void +e_account_list_add(EAccountList *accounts, EAccount *account) +{ + /* FIXME: should we check for duplicate accounts? */ + + e_list_append ((EList *)accounts, account); + g_signal_emit(accounts, signals[ACCOUNT_ADDED], 0, account); +} + +/** + * e_account_list_change: + * @accounts: + * @account: + * + * Signal that the details of an account have changed. + **/ +void +e_account_list_change(EAccountList *accounts, EAccount *account) +{ + /* maybe the account should do this itself ... */ + g_signal_emit(accounts, signals[ACCOUNT_CHANGED], 0, account); +} + +/** + * e_account_list_remove: + * @accounts: + * @account: + * + * Remove an account from the account list, and emit the + * account-removed signal. If the account was the default account, + * then reset the default to the first account. + **/ +void +e_account_list_remove(EAccountList *accounts, EAccount *account) +{ + if (account == e_account_list_get_default(accounts)) + gconf_client_unset (accounts->priv->gconf, "/apps/evolution/mail/default_account", NULL); + + /* not sure if need to ref but no harm */ + g_object_ref (account); + e_list_remove ((EList *) accounts, account); + g_signal_emit(accounts, signals[ACCOUNT_REMOVED], 0, account); + g_object_unref (account); +} + +/** + * e_account_list_get_default: + * @accounts: + * + * Get the default account. If no default is specified, or the default + * has become stale, then the first account is made the default. + * + * Return value: The account or NULL if no accounts are defined. + **/ +const EAccount * +e_account_list_get_default(EAccountList *accounts) +{ + char *uid; + EIterator *it; + const EAccount *account = NULL; + + uid = gconf_client_get_string (accounts->priv->gconf, "/apps/evolution/mail/default_account", NULL); + it = e_list_get_iterator ((EList *)accounts); + + if (uid) { + for (;e_iterator_is_valid (it);e_iterator_next (it)) { + account = (const EAccount *)e_iterator_get (it); + + if (!strcmp(uid, account->uid)) + break; + account = NULL; + } + e_iterator_reset(it); + } + + /* no uid or uid not found, @it will be at the first account */ + if (account == NULL && e_iterator_is_valid(it)) { + account = (const EAccount *) e_iterator_get (it); + gconf_client_set_string (accounts->priv->gconf, "/apps/evolution/mail/default_account", account->uid, NULL); + } + + g_object_unref(it); + g_free(uid); + + return account; +} + +/** + * e_account_list_set_default: + * @accounts: + * @account: + * + * Set the account @account to be the default account. + **/ +void +e_account_list_set_default(EAccountList *accounts, EAccount *account) +{ + gconf_client_set_string (accounts->priv->gconf, "/apps/evolution/mail/default_account", account->uid, NULL); +} + +/** + * e_account_list_find: + * @accounts: + * @type: Type of search. + * @key: Search key. + * + * Perform a search of the account list on a single key. + * + * @type must be set from one of the following search types: + * E_ACCOUNT_FIND_NAME - Find an account by account name. + * E_ACCOUNT_FIND_ID_NAME - Find an account by the owner's identity name. + * E_ACCOUNT_FIND_ID_ADDRESS - Find an account by the owner's identity address. + * + * Return value: The account or NULL if it doesn't exist. + **/ +const EAccount * +e_account_list_find(EAccountList *accounts, e_account_find_t type, const char *key) +{ + char *val; + EIterator *it; + const EAccount *account = NULL; + + /* this could use a callback for more flexibility ... + ... but this makes the common cases easier */ + + for (it = e_list_get_iterator ((EList *)accounts); + e_iterator_is_valid (it); + e_iterator_next (it)) { + int found = 0; + + account = (const EAccount *)e_iterator_get (it); + + val = NULL; + switch(type) { + case E_ACCOUNT_FIND_NAME: + found = strcmp(account->name, key) == 0; + break; + case E_ACCOUNT_FIND_ID_NAME: + if (account->id) + found = strcmp(account->id->name, key) == 0; + break; + case E_ACCOUNT_FIND_ID_ADDRESS: + if (account->id) + found = g_ascii_strcasecmp(account->id->address, key) == 0; + break; + } + + if (found) + break; + + account = NULL; + } + g_object_unref(it); + + return account; +} + |