* all:
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Wed, 24 Jan 2007 08:13:29 +0000 (08:13 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Wed, 24 Jan 2007 08:13:29 +0000 (08:13 +0000)
- implemented 'default' account concept

pmo-trunk-r724

src/modest-account-mgr-helpers.c
src/modest-account-mgr-helpers.h
src/modest-account-mgr-priv.h
src/modest-account-mgr.c
src/modest-defs.h

index 593de5b..ffe4445 100644 (file)
@@ -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);
+
+}
+
+
+
index d122daf..8d63aba 100644 (file)
@@ -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__ */
index aadc41e..7c1f099 100644 (file)
@@ -31,6 +31,7 @@
 #define __MODEST_ACCOUNT_MGR_PRIV_H__
 
 #include <glib.h>
+#include <modest-conf.h>
 
 /*
  * 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__ */
index ccbe841..196a9fa 100644 (file)
 #include <modest-marshal.h>
 #include <modest-account-mgr.h>
 #include <modest-account-mgr-priv.h>
+#include <modest-account-mgr-helpers.h>
 
 /* '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,
index dec93bb..2aa0e99 100644 (file)
@@ -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 */