aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2003-02-24 10:51:01 +0800
committerMichael Zucci <zucchi@src.gnome.org>2003-02-24 10:51:01 +0800
commit9491a06552c8c095132750aa505573d1315ca73f (patch)
tree966873787945d7ed4040b0df5afe57a9698102d5
parent87f2abd1f0327a8fbd459ae90fbc6b50ab83a625 (diff)
downloadgsoc2013-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
-rw-r--r--e-util/ChangeLog11
-rw-r--r--e-util/e-account-list.c166
-rw-r--r--e-util/e-account-list.h25
3 files changed, 197 insertions, 5 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index 1601851dde..9c1e4b9296 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,14 @@
+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.
+
2003-02-22 Hans Petter Jansson <hpj@ximian.com>
* e-categories-config.c (e_categories_config_open_dialog_for_entry):
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;
+}
+
diff --git a/e-util/e-account-list.h b/e-util/e-account-list.h
index 6a8a1c7505..2ad0896307 100644
--- a/e-util/e-account-list.h
+++ b/e-util/e-account-list.h
@@ -32,6 +32,13 @@
typedef struct EAccountListPrivate EAccountListPrivate;
+/* search options for the find command */
+typedef enum _e_account_find_t {
+ E_ACCOUNT_FIND_NAME,
+ E_ACCOUNT_FIND_ID_NAME,
+ E_ACCOUNT_FIND_ID_ADDRESS,
+} e_account_find_t;
+
typedef struct {
EList parent_object;
@@ -48,12 +55,20 @@ typedef struct {
} EAccountListClass;
-GType e_account_list_get_type (void);
+GType e_account_list_get_type (void);
+
+EAccountList *e_account_list_new (GConfClient *gconf);
+void e_account_list_construct (EAccountList *account_list,
+ GConfClient *gconf);
+
+void e_account_list_save (EAccountList *account_list);
-EAccountList *e_account_list_new (GConfClient *gconf);
-void e_account_list_construct (EAccountList *account_list,
- GConfClient *gconf);
+void e_account_list_add (EAccountList *, EAccount *);
+void e_account_list_change (EAccountList *, EAccount *);
+void e_account_list_remove (EAccountList *, EAccount *);
-void e_account_list_save (EAccountList *account_list);
+const EAccount *e_account_list_get_default(EAccountList *);
+void e_account_list_set_default(EAccountList *, EAccount *);
+const EAccount *e_account_list_find (EAccountList *, e_account_find_t type, const char *key);
#endif /* __E_ACCOUNT_LIST__ */