From 6ad0c7e0fbf8462c0a41c0a42bf34adbb127fe4e Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 24 Jan 2007 08:13:29 +0000 Subject: [PATCH] * all: - implemented 'default' account concept pmo-trunk-r724 --- src/modest-account-mgr-helpers.c | 45 ++++++++++++++++++++++++++++++++++++++ src/modest-account-mgr-helpers.h | 44 +++++++++++++++++++++++-------------- src/modest-account-mgr-priv.h | 11 ++++++++++ src/modest-account-mgr.c | 10 +-------- src/modest-defs.h | 3 +++ 5 files changed, 87 insertions(+), 26 deletions(-) diff --git a/src/modest-account-mgr-helpers.c b/src/modest-account-mgr-helpers.c index 593de5b..ffe4445 100644 --- a/src/modest-account-mgr-helpers.c +++ b/src/modest-account-mgr-helpers.c @@ -175,3 +175,48 @@ modest_account_mgr_free_account_data (ModestAccountMgr *self, ModestAccountData } +gchar* +modest_account_mgr_get_default_account (ModestAccountMgr *self) +{ + gchar *account; + ModestConf *conf; + + g_return_val_if_fail (self, NULL); + + conf = MODEST_ACCOUNT_MGR_GET_PRIVATE (self)->modest_conf; + account = modest_conf_get_string (conf, MODEST_CONF_DEFAULT_ACCOUNT, + NULL); + + /* it's not really an error if there is no default account */ + if (!account) + return NULL; + + /* sanity check */ + if (!modest_account_mgr_account_exists (self, account, FALSE, NULL)) { + g_printerr ("modest: default account does not exist\n"); + g_free (account); + return NULL; + } + return account; +} + + +gboolean +modest_account_mgr_set_default_account (ModestAccountMgr *self, const gchar* account) +{ + ModestConf *conf; + + g_return_val_if_fail (self, FALSE); + g_return_val_if_fail (account, FALSE); + g_return_val_if_fail (modest_account_mgr_account_exists (self, account, FALSE, NULL), + FALSE); + + conf = MODEST_ACCOUNT_MGR_GET_PRIVATE (self)->modest_conf; + + return modest_conf_set_string (conf, MODEST_CONF_DEFAULT_ACCOUNT, + account, NULL); + +} + + + diff --git a/src/modest-account-mgr-helpers.h b/src/modest-account-mgr-helpers.h index d122daf..8d63aba 100644 --- a/src/modest-account-mgr-helpers.h +++ b/src/modest-account-mgr-helpers.h @@ -68,6 +68,28 @@ typedef struct { ModestAccountData *modest_account_mgr_get_account_data (ModestAccountMgr *self, const gchar* name); +/** + * modest_account_mgr_get_default_account: + * @self: a ModestAccountMgr instance + * + * get the default account name, or NULL if none is found + * + * Returns: the default account name (as newly allocated string, which + * must be g_free'd), or NULL + */ +gchar* modest_account_mgr_get_default_account (ModestAccountMgr *self); + +/** + * modest_account_mgr_get_default_account: + * @self: a ModestAccountMgr instance + * @account: the name of an existing account + * + * set the default account name (which must be valid account) + * + * Returns: TRUE if succeeded, FALSE otherwise + */ +gboolean modest_account_mgr_set_default_account (ModestAccountMgr *self, + const gchar* account); /** * modest_account_mgr_free_account_data: @@ -80,23 +102,6 @@ void modest_account_mgr_free_account_data (ModestAccountMgr *self, ModestAccountData *data); -/** - * modest_account_mgr_server_account_names: - * @self: a ModestAccountMgr instance - * @account_name: get only server accounts for @account_name, or NULL for any - * @type: get only server accounts from protocol type @type, or MODEST_PROTO_TYPE_ANY - * @proto: get only server account with protocol @proto, or NULL for any - * @only_enabled: get only enabled server accounts if TRUE - * - * list all the server account names - * - * Returns: a newly allocated list of server account names, or NULL in case of - * error or if there are no server accounts. The caller must free the returned GSList - */ -GSList* modest_account_mgr_search_server_accounts (ModestAccountMgr *self, - const gchar* account_name, - ModestProtocolType type, - ModestProtocol proto); /** * modest_account_mgr_account_set_enabled @@ -124,6 +129,11 @@ gboolean modest_account_mgr_account_set_enabled (ModestAccountMgr *self, const g gboolean modest_account_mgr_account_get_enabled (ModestAccountMgr *self, const gchar* name); + + + + + G_END_DECLS #endif /* __MODEST_ACCOUNT_MGR_H__ */ diff --git a/src/modest-account-mgr-priv.h b/src/modest-account-mgr-priv.h index aadc41e..7c1f099 100644 --- a/src/modest-account-mgr-priv.h +++ b/src/modest-account-mgr-priv.h @@ -31,6 +31,7 @@ #define __MODEST_ACCOUNT_MGR_PRIV_H__ #include +#include /* * private functions, only for use in modest-account-mgr and @@ -44,5 +45,15 @@ gchar* _modest_account_mgr_account_from_key (const gchar *key, gboolean *is_acco gchar * _modest_account_mgr_get_account_keyname (const gchar *account_name, const gchar * name, gboolean server_account); +/* below is especially very _private_ stuff */ +typedef struct _ModestAccountMgrPrivate ModestAccountMgrPrivate; +struct _ModestAccountMgrPrivate { + ModestConf *modest_conf; +}; + +#define MODEST_ACCOUNT_MGR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ + MODEST_TYPE_ACCOUNT_MGR, \ + ModestAccountMgrPrivate)) + G_END_DECLS #endif /* __MODEST_ACCOUNT_MGR_PRIV_H__ */ diff --git a/src/modest-account-mgr.c b/src/modest-account-mgr.c index ccbe841..196a9fa 100644 --- a/src/modest-account-mgr.c +++ b/src/modest-account-mgr.c @@ -31,21 +31,13 @@ #include #include #include +#include /* 'private'/'protected' functions */ static void modest_account_mgr_class_init (ModestAccountMgrClass * klass); static void modest_account_mgr_init (ModestAccountMgr * obj); static void modest_account_mgr_finalize (GObject * obj); - -typedef struct _ModestAccountMgrPrivate ModestAccountMgrPrivate; -struct _ModestAccountMgrPrivate { - ModestConf *modest_conf; -}; - -#define MODEST_ACCOUNT_MGR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ - MODEST_TYPE_ACCOUNT_MGR, \ - ModestAccountMgrPrivate)) /* list my signals */ enum { ACCOUNT_CHANGED_SIGNAL, diff --git a/src/modest-defs.h b/src/modest-defs.h index dec93bb..2aa0e99 100644 --- a/src/modest-defs.h +++ b/src/modest-defs.h @@ -65,10 +65,13 @@ enum { /* configuration key definitions for modest */ #define MODEST_ACCOUNT_NAMESPACE MODEST_CONF_NAMESPACE "/" "accounts" +#define MODEST_CONF_DEFAULT_ACCOUNT MODEST_CONF_NAMESPACE "/" "default_account" + #define MODEST_SERVER_ACCOUNT_NAMESPACE MODEST_CONF_NAMESPACE "/" "server_accounts" #define MODEST_CONF_REPLY_TYPE "reply_type" /* int */ #define MODEST_CONF_FORWARD_TYPE "forward_type" /* int */ + /* per-account data */ #define MODEST_ACCOUNT_DISPLAY_NAME "display_name" /* string */ #define MODEST_ACCOUNT_STORE_ACCOUNT "store_account" /* string */ -- 1.7.9.5