* moved identity-related functionality from modest-account-mgr to the new modest...
authorArne Zellentin <arne@kernelconcepts.de>
Tue, 30 May 2006 19:45:09 +0000 (19:45 +0000)
committerArne Zellentin <arne@kernelconcepts.de>
Tue, 30 May 2006 19:45:09 +0000 (19:45 +0000)
* my anjuta reformatted modest-account-*, if this bothers anybody, we should be able to revert to the 2nd previous version. I think I only changed some typos.

* implemented (i.e. copied) the missing modest-identity-mgr-* methods

* changed to using the identity-mgr where aprropriate

pmo-trunk-r128

src/Makefile.am
src/gtk-glade/modest-ui.c
src/modest-account-keys.h
src/modest-account-mgr.c
src/modest-account-mgr.h
src/modest-identity-keys.h [new file with mode: 0644]
src/modest-identity-mgr.c [new file with mode: 0644]
src/modest-identity-mgr.h [new file with mode: 0644]
src/modest-main.c

index 5a3b731..b05b07d 100644 (file)
@@ -20,6 +20,9 @@ modest_SOURCES=\
        modest-conf-keys.h\
        modest-conf.h \
        modest-conf-gconf.c\
+       modest-identity-keys.h\
+       modest-identity-mgr.h\
+       modest-identity-mgr.c\
        modest-account-keys.h\
        modest-account-mgr.h\
        modest-account-mgr.c\
index ba5a004..75ff923 100644 (file)
@@ -17,6 +17,7 @@
 #include "../modest-ui.h"
 #include "../modest-window-mgr.h"
 #include "../modest-account-mgr.h"
+#include "../modest-identity-mgr.h"
 
 #include "../modest-tny-account-store.h"
 #include "../modest-tny-folder-tree-view.h"
@@ -82,6 +83,7 @@ struct _ModestUIPrivate {
 
        ModestConf           *modest_conf;
        ModestAccountMgr     *modest_acc_mgr;
+       ModestIdentityMgr    *modest_id_mgr;
        ModestWindowMgr      *modest_window_mgr;
        TnyAccountStoreIface *account_store;
 
@@ -147,6 +149,7 @@ modest_ui_init (ModestUI *obj)
        ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
 
        priv->modest_acc_mgr    = NULL;
+       priv->modest_id_mgr     = NULL;
        priv->modest_conf       = NULL;
        priv->modest_window_mgr = NULL;
        priv->glade_xml         = NULL;
@@ -161,6 +164,10 @@ modest_ui_finalize (GObject *obj)
        if (priv->modest_acc_mgr)
                g_object_unref (priv->modest_acc_mgr);
        priv->modest_acc_mgr = NULL;
+       
+       if (priv->modest_id_mgr)
+               g_object_unref (priv->modest_id_mgr);
+       priv->modest_id_mgr = NULL;
 
        if (priv->modest_conf)
                g_object_unref (priv->modest_conf);
@@ -177,6 +184,7 @@ modest_ui_new (ModestConf *modest_conf)
        GObject *obj;
        ModestUIPrivate *priv;
        ModestAccountMgr *modest_acc_mgr;
+       ModestIdentityMgr *modest_id_mgr;
        TnyAccountStoreIface *account_store_iface;
 
        g_return_val_if_fail (modest_conf, NULL);
@@ -191,6 +199,14 @@ modest_ui_new (ModestConf *modest_conf)
                g_object_unref (obj);
                return NULL;
        }
+       
+       modest_id_mgr =
+               MODEST_IDENTITY_MGR(modest_identity_mgr_new (modest_conf));
+       if (!modest_id_mgr) {
+               g_warning ("could not create ModestIdentityMgr instance");
+               g_object_unref (obj);
+               return NULL;
+       }
 
        account_store_iface =
                TNY_ACCOUNT_STORE_IFACE(modest_tny_account_store_new (modest_acc_mgr));
@@ -215,6 +231,7 @@ modest_ui_new (ModestConf *modest_conf)
         */
 
        priv->modest_acc_mgr = modest_acc_mgr;
+       priv->modest_id_mgr  = modest_id_mgr;
        g_object_ref (priv->modest_conf = modest_conf);
 
        priv->account_store = account_store_iface;
@@ -756,7 +773,7 @@ on_send_button_clicked (GtkWidget *widget, ModestUI *modest_ui)
        const GList *transport_accounts;
        TnyTransportAccountIface *transport_account;
        ModestConf       *conf;
-       ModestAccountMgr *acc_mgr;
+       ModestIdentityMgr *id_mgr;
 
        g_return_if_fail (modest_ui);
 
@@ -785,16 +802,11 @@ on_send_button_clicked (GtkWidget *widget, ModestUI *modest_ui)
        gtk_text_buffer_get_bounds (buf, &start, &end);
        body    = gtk_text_buffer_get_text (buf, &start, &end, FALSE);
 
-       /* FIXME: HACK! */
-       conf = MODEST_CONF(modest_conf_new());
-       acc_mgr = MODEST_ACCOUNT_MGR(modest_account_mgr_new (conf));
-       if (!acc_mgr) {
-               g_warning ("failed to instantiate account mgr");
-               return;
-       }
-       email_from = modest_account_mgr_get_identity_string(acc_mgr, "myidentity", MODEST_ACCOUNT_EMAIL, NULL);
-       /* end HACK */
-       
+       id_mgr = priv->modest_id_mgr;
+       email_from = modest_identity_mgr_get_identity_string(id_mgr,
+                                                                                                                MODEST_IDENTITY_DEFAULT_IDENTITY,
+                                                                                                                MODEST_IDENTITY_EMAIL, NULL);
+                       
        g_message("sending \"%s\" %s ==> %s", subject, email_from, to);
        modest_tny_transport_actions_send_message (actions,
                                                   transport_account,
index d8b0b3e..80dbc21 100644 (file)
@@ -9,7 +9,6 @@
 /* configuration key definitions for modest */
 #define MODEST_ACCOUNT_NAMESPACE         MODEST_CONF_NAMESPACE "/" "accounts"
 #define MODEST_SERVER_ACCOUNT_NAMESPACE  MODEST_CONF_NAMESPACE "/" "server_accounts"
-#define MODEST_IDENTITY_NAMESPACE        MODEST_CONF_NAMESPACE "/" "identities"
 
 /* per-account data */
 #define MODEST_ACCOUNT_DISPLAY_NAME      "display_name"      /* string */
 #define MODEST_ACCOUNT_LEAVE_ON_SERVER   "leave_on_server"   /* boolean */
 #define MODEST_ACCOUNT_PREFERRED_CNX     "preferred_cnx"     /* string */
 
-/* user identity keys */
-#define MODEST_ACCOUNT_EMAIL             "email"             /* string */
-#define MODEST_ACCOUNT_REPLYTO           "replyto"           /* string */
-#define MODEST_ACCOUNT_SIGNATURE         "signature"         /* string */
-#define MODEST_ACCOUNT_USE_SIGNATURE     "use_signature"     /* boolean */
-#define MODEST_ACCOUNT_ID_VIA            "id_via"            /* string */
-#define MODEST_ACCOUNT_USE_ID_VIA        "use_id_via"        /* boolean */
-/* MISSING: everything related to gpg */
-
 #endif /*__MODEST_CONF_KEYS_H__*/
index c5dfd8c..56c213f 100644 (file)
@@ -6,13 +6,13 @@
 #include "modest-account-mgr.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);
+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);
 
-static gchar*   get_account_keyname (const gchar *accname, const gchar *name);
-static gchar*   get_server_account_keyname (const gchar *accname, const gchar *name);
-static gchar*   get_identity_keyname (const gchar *accname, const gchar *name);
+static gchar *get_account_keyname (const gchar * accname, const gchar * name);
+static gchar *get_server_account_keyname (const gchar * accname,
+                                         const gchar * name);
 
 /* list my signals */
 enum {
@@ -25,6 +25,7 @@ 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))
@@ -38,36 +39,39 @@ GType
 modest_account_mgr_get_type (void)
 {
        static GType my_type = 0;
+
        if (!my_type) {
                static const GTypeInfo my_info = {
-                       sizeof(ModestAccountMgrClass),
-                       NULL,           /* base init */
-                       NULL,           /* base finalize */
+                       sizeof (ModestAccountMgrClass),
+                       NULL,   /* base init */
+                       NULL,   /* base finalize */
                        (GClassInitFunc) modest_account_mgr_class_init,
-                       NULL,           /* class finalize */
-                       NULL,           /* class data */
-                       sizeof(ModestAccountMgr),
-                       1,              /* n_preallocs */
+                       NULL,   /* class finalize */
+                       NULL,   /* class data */
+                       sizeof (ModestAccountMgr),
+                       1,      /* n_preallocs */
                        (GInstanceInitFunc) modest_account_mgr_init,
                };
 
                my_type = g_type_register_static (G_TYPE_OBJECT,
-                                                 "ModestAccountMgr",
-                                                 &my_info, 0);
+                                                 "ModestAccountMgr",
+                                                 &my_info, 0);
        }
        return my_type;
 }
 
 static void
-modest_account_mgr_class_init (ModestAccountMgrClass *klass)
+modest_account_mgr_class_init (ModestAccountMgrClass * klass)
 {
        GObjectClass *gobject_class;
-       gobject_class = (GObjectClass*) klass;
 
-       parent_class            = g_type_class_peek_parent (klass);
+       gobject_class = (GObjectClass *) klass;
+
+       parent_class = g_type_class_peek_parent (klass);
        gobject_class->finalize = modest_account_mgr_finalize;
 
-       g_type_class_add_private (gobject_class, sizeof(ModestAccountMgrPrivate));
+       g_type_class_add_private (gobject_class,
+                                 sizeof (ModestAccountMgrPrivate));
 
        /* signal definitions go here, e.g.: */
 /*     signals[MY_SIGNAL_1] = */
@@ -79,48 +83,48 @@ modest_account_mgr_class_init (ModestAccountMgrClass *klass)
 
 
 static void
-modest_account_mgr_init (ModestAccountMgr *obj)
+modest_account_mgr_init (ModestAccountMgr * obj)
 {
-       ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(obj);
-       priv->modest_conf = NULL;
+       ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (obj);
+
+       priv->modest_conf = NULL;
 }
 
 static void
-modest_account_mgr_finalize (GObject *obj)
+modest_account_mgr_finalize (GObject * obj)
 {
-       ModestAccountMgr *self = MODEST_ACCOUNT_MGR(obj);
-       ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
+       ModestAccountMgr *self = MODEST_ACCOUNT_MGR (obj);
+       ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
 
-       g_object_unref (G_OBJECT(priv->modest_conf));
+       g_object_unref (G_OBJECT (priv->modest_conf));
        priv->modest_conf = NULL;
 }
 
-GObject*
-modest_account_mgr_new (ModestConf *conf)
+GObject *
+modest_account_mgr_new (ModestConf * conf)
 {
        GObject *obj;
        ModestAccountMgrPrivate *priv;
 
        g_return_val_if_fail (conf, NULL);
 
-       obj  = G_OBJECT(g_object_new(MODEST_TYPE_ACCOUNT_MGR, NULL));
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(obj);
+       obj = G_OBJECT (g_object_new (MODEST_TYPE_ACCOUNT_MGR, NULL));
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (obj);
 
        /*
         * increase the ref count on the modest_conf. Normally, the
         * ModestConf should outlive the ModestAccountMgr though
         */
-       g_object_ref(G_OBJECT(priv->modest_conf = conf));
+       g_object_ref (G_OBJECT (priv->modest_conf = conf));
        return obj;
 }
 
 
-
 gboolean
-modest_account_mgr_add_account (ModestAccountMgr *self, const gchar* name,
-                               const gchar *store_account,
-                               const gchar *transport_account,
-                               GError **err)
+modest_account_mgr_add_account (ModestAccountMgr * self, const gchar * name,
+                               const gchar * store_account,
+                               const gchar * transport_account,
+                               GError ** err)
 {
        ModestAccountMgrPrivate *priv;
        gchar *key;
@@ -137,31 +141,35 @@ modest_account_mgr_add_account (ModestAccountMgr *self, const gchar* name,
         * we create the account by adding an account 'dir', with the name <name>,
         * and in that the 'display_name' string key
         */
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
 
        key = get_account_keyname (name, MODEST_ACCOUNT_DISPLAY_NAME);
        modest_conf_set_string (priv->modest_conf, key, name, err);
        g_free (key);
 
        if (store_account) {
-               key = get_account_keyname (name, MODEST_ACCOUNT_STORE_ACCOUNT);
-               modest_conf_set_string (priv->modest_conf, key, store_account, err);
+               key = get_account_keyname (name,
+                                          MODEST_ACCOUNT_STORE_ACCOUNT);
+               modest_conf_set_string (priv->modest_conf, key, store_account,
+                                       err);
                g_free (key);
        }
 
        if (transport_account) {
-               key = get_account_keyname (name, MODEST_ACCOUNT_TRANSPORT_ACCOUNT);
-               modest_conf_set_string (priv->modest_conf, key, transport_account, err);
+               key = get_account_keyname (name,
+                                          MODEST_ACCOUNT_TRANSPORT_ACCOUNT);
+               modest_conf_set_string (priv->modest_conf, key,
+                                       transport_account, err);
                g_free (key);
        }
 
-       return TRUE; /* TODO: error handling */
+       return TRUE;            /* TODO: error handling */
 }
 
 
 gboolean
-modest_account_mgr_remove_account (ModestAccountMgr *self, const gchar* name,
-                          GError **err)
+modest_account_mgr_remove_account (ModestAccountMgr * self,
+                                  const gchar * name, GError ** err)
 {
        ModestAccountMgrPrivate *priv;
        gchar *key;
@@ -175,7 +183,7 @@ modest_account_mgr_remove_account (ModestAccountMgr *self, const gchar* name,
                return FALSE;
        }
 
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
        key = get_account_keyname (name, NULL);
 
        retval = modest_conf_remove_key (priv->modest_conf, key, NULL);
@@ -185,20 +193,20 @@ modest_account_mgr_remove_account (ModestAccountMgr *self, const gchar* name,
 }
 
 
-static const gchar*
-null_means_empty(const gchar* str)
+static const gchar *
+null_means_empty (const gchar * str)
 {
        return str ? str : "";
 }
 
 
 gboolean
-modest_account_mgr_add_server_account    (ModestAccountMgr *self,
-                                         const gchar *name,
-                                         const gchar *hostname,
-                                         const gchar *username,
-                                         const gchar *password,
-                                         const gchar *proto)
+modest_account_mgr_add_server_account (ModestAccountMgr * self,
+                                      const gchar * name,
+                                      const gchar * hostname,
+                                      const gchar * username,
+                                      const gchar * password,
+                                      const gchar * proto)
 {
        ModestAccountMgrPrivate *priv;
        gchar *acckey, *key;
@@ -208,11 +216,11 @@ modest_account_mgr_add_server_account    (ModestAccountMgr *self,
 
        /* TODO: check already exists */
 
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
        acckey = g_strconcat (MODEST_SERVER_ACCOUNT_NAMESPACE, "/",
                              name, NULL);
 
-       if (modest_conf_key_exists(priv->modest_conf, acckey, NULL)) {
+       if (modest_conf_key_exists (priv->modest_conf, acckey, NULL)) {
                g_warning ("server account %s already exists", name);
                //g_free (acckey);
                //return FALSE;
@@ -221,68 +229,37 @@ modest_account_mgr_add_server_account    (ModestAccountMgr *self,
        /* hostname */
        key = g_strconcat (acckey, "/", MODEST_ACCOUNT_HOSTNAME, NULL);
        modest_conf_set_string (priv->modest_conf, key,
-                               null_means_empty(hostname), NULL);
+                               null_means_empty (hostname), NULL);
        g_free (key);
 
        /* username */
        key = g_strconcat (acckey, "/", MODEST_ACCOUNT_USERNAME, NULL);
        modest_conf_set_string (priv->modest_conf, key,
-                               null_means_empty(username), NULL);
+                               null_means_empty (username), NULL);
        g_free (key);
 
        /* password */
-        if (password)
-        {
-                key = g_strconcat (acckey, "/", MODEST_ACCOUNT_PASSWORD, NULL);
-                modest_conf_set_string (priv->modest_conf, key,
-                                        null_means_empty(password), NULL);
-                g_free (key);
-        }
+       if (password) {
+               key = g_strconcat (acckey, "/", MODEST_ACCOUNT_PASSWORD,
+                                  NULL);
+               modest_conf_set_string (priv->modest_conf, key,
+                                       null_means_empty (password), NULL);
+               g_free (key);
+       }
 
        /* proto */
        key = g_strconcat (acckey, "/", MODEST_ACCOUNT_PROTO, NULL);
        modest_conf_set_string (priv->modest_conf, key,
-                               null_means_empty(proto),
-                               NULL);
+                               null_means_empty (proto), NULL);
        g_free (key);
        g_free (acckey);
-               
-       return TRUE; /* FIXME: better error checking */
-}
-
-gboolean
-modest_account_mgr_remove_server_account    (ModestAccountMgr *self,
-                                            const gchar *name,
-                                            GError **err)
-{
-       ModestAccountMgrPrivate *priv;
-       gchar *acckey, *key;
-       gboolean retval;
-
-       g_return_val_if_fail (self, FALSE);
-       g_return_val_if_fail (name, FALSE);
-
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
-
-       acckey = g_strconcat (MODEST_SERVER_ACCOUNT_NAMESPACE, "/",
-                             name, NULL);
-
-       if (!modest_conf_key_exists(priv->modest_conf, acckey, NULL)) {
-               g_warning ("server account %s does not exist exist", name);
-               g_free (acckey);
-               return FALSE;
-       }
-
-       retval = modest_conf_remove_key (priv->modest_conf, acckey, NULL);
-       g_free (acckey);
 
-       return retval;
+       return TRUE;            /* FIXME: better error checking */
 }
 
 gboolean
-modest_account_mgr_remove_identity    (ModestAccountMgr *self,
-                                            const gchar *name,
-                                            GError **err)
+modest_account_mgr_remove_server_account (ModestAccountMgr * self,
+                                         const gchar * name, GError ** err)
 {
        ModestAccountMgrPrivate *priv;
        gchar *acckey, *key;
@@ -291,12 +268,12 @@ modest_account_mgr_remove_identity    (ModestAccountMgr *self,
        g_return_val_if_fail (self, FALSE);
        g_return_val_if_fail (name, FALSE);
 
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
 
-       acckey = g_strconcat (MODEST_IDENTITY_NAMESPACE, "/",
+       acckey = g_strconcat (MODEST_SERVER_ACCOUNT_NAMESPACE, "/",
                              name, NULL);
 
-       if (!modest_conf_key_exists(priv->modest_conf, acckey, NULL)) {
+       if (!modest_conf_key_exists (priv->modest_conf, acckey, NULL)) {
                g_warning ("server account %s does not exist exist", name);
                g_free (acckey);
                return FALSE;
@@ -309,85 +286,18 @@ modest_account_mgr_remove_identity    (ModestAccountMgr *self,
 }
 
 
-
-gboolean
-modest_account_mgr_add_identity (ModestAccountMgr *self,
-                      const gchar *name,
-                                         const gchar *email,
-                                         const gchar *replyto,
-                                         const gchar *signature,
-                      const gboolean use_signature,
-                      const gchar *id_via,
-                      const gboolean use_id_via)
-{
-       ModestAccountMgrPrivate *priv;
-       gchar *id_key, *key;
-
-       g_return_val_if_fail (self, FALSE);
-       g_return_val_if_fail (name, FALSE);
-
-       /* TODO: check already exists */
-
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
-       id_key = g_strconcat (MODEST_IDENTITY_NAMESPACE, "/",
-                             name, NULL);
-
-       if (modest_conf_key_exists(priv->modest_conf, id_key, NULL)) {
-               g_warning ("identity %s already exists", name);
-               //g_free (id_key);
-               //return FALSE;
-       }
-
-       /* email */
-       key = g_strconcat (id_key, "/", MODEST_ACCOUNT_EMAIL, NULL);
-       modest_conf_set_string (priv->modest_conf, key,
-                               null_means_empty(email), NULL);
-       g_free (key);
-
-       /* replyto */
-       key = g_strconcat (id_key, "/", MODEST_ACCOUNT_REPLYTO, NULL);
-       modest_conf_set_string (priv->modest_conf, key,
-                               null_means_empty(replyto), NULL);       
-       g_free (key);
-
-       /* signature */
-       key = g_strconcat (id_key, "/", MODEST_ACCOUNT_SIGNATURE, NULL);
-       modest_conf_set_string (priv->modest_conf, key,
-                               null_means_empty(signature), NULL);     
-       g_free (key);
-       
-       /* use_signature */
-       key = g_strconcat (id_key, "/", MODEST_ACCOUNT_USE_SIGNATURE, NULL);
-       modest_conf_set_bool (priv->modest_conf, key,
-                               use_signature, NULL);   
-       g_free (key);
-       
-       /* signature */
-       key = g_strconcat (id_key, "/", MODEST_ACCOUNT_ID_VIA, NULL);
-       modest_conf_set_string (priv->modest_conf, key,
-                               null_means_empty(id_via), NULL);        
-       g_free (key);
-       
-       /* use_signature */
-       key = g_strconcat (id_key, "/", MODEST_ACCOUNT_USE_ID_VIA, NULL);
-       modest_conf_set_bool (priv->modest_conf, key,
-                               use_id_via, NULL);      
-       g_free (key);
-       g_free (id_key);
-       
-       return TRUE; /* FIXME: better error checking */
-}
-
 /* strip the first /n/ character from each element */
 /* caller must make sure all elements are strings with
  * length >= n, and also that data can be freed.
  */
-static GSList*
-strip_prefix_from_elements (GSList *lst, guint n)
+static GSList *
+strip_prefix_from_elements (GSList * lst, guint n)
 {
        GSList *cursor = lst;
+
        while (cursor) {
-               gchar *str = (gchar*)cursor->data;
+               gchar *str = (gchar *) cursor->data;
+
                cursor->data = g_strdup (str + n);
                g_free (str);
                cursor = cursor->next;
@@ -396,13 +306,12 @@ strip_prefix_from_elements (GSList *lst, guint n)
 }
 
 
-
-GSList*
-modest_account_mgr_server_account_names   (ModestAccountMgr *self,
-                                          const gchar*    account_name,
-                                          ModestProtoType type,
-                                          const gchar*    proto,
-                                          gboolean only_enabled)
+GSList *
+modest_account_mgr_server_account_names (ModestAccountMgr * self,
+                                        const gchar * account_name,
+                                        ModestProtoType type,
+                                        const gchar * proto,
+                                        gboolean only_enabled)
 {
        GSList *accounts;
        GSList *cursor;
@@ -412,32 +321,36 @@ modest_account_mgr_server_account_names   (ModestAccountMgr *self,
 
        g_return_val_if_fail (self, NULL);
 
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
        accounts = modest_conf_list_subkeys (priv->modest_conf,
                                             MODEST_SERVER_ACCOUNT_NAMESPACE,
                                             NULL);
 
        /* no restrictions, return everything */
        if (type == MODEST_PROTO_TYPE_ANY && !proto)
-               return strip_prefix_from_elements (accounts,prefix_len);
+               return strip_prefix_from_elements (accounts, prefix_len);
 
        /* otherwise, filter out the none-matching ones */
        cursor = accounts;
        while (cursor) {
                gchar *keyspace, *proto_key, *acc_proto;
 
-               keyspace  = (gchar*) cursor->data;
-               proto_key = g_strconcat (keyspace, "/", MODEST_ACCOUNT_PROTO, NULL);
-               acc_proto = modest_conf_get_string (priv->modest_conf, proto_key,
-                                                   NULL);
+               keyspace = (gchar *) cursor->data;
+               proto_key =
+                       g_strconcat (keyspace, "/", MODEST_ACCOUNT_PROTO,
+                                    NULL);
+               acc_proto =
+                       modest_conf_get_string (priv->modest_conf, proto_key,
+                                               NULL);
                g_free (proto_key);
 
-               if ((!acc_proto) ||                              /* proto not defined? */
-                   (type != MODEST_PROTO_TYPE_ANY &&            /* proto type ...     */
-                    modest_proto_type (acc_proto) != type) ||   /* ... matches?       */
-                   (proto && strcmp(proto,acc_proto) != 0)) {   /* proto matches?     */
+               if ((!acc_proto) ||     /* proto not defined? */
+                   (type != MODEST_PROTO_TYPE_ANY &&   /* proto type ...     */
+                    modest_proto_type (acc_proto) != type) ||  /* ... matches?       */
+                   (proto && strcmp (proto, acc_proto) != 0)) {        /* proto matches?     */
                        /* no match: remove from the list */
                        GSList *nxt = cursor->next;
+
                        g_free (acc_proto);
                        accounts = g_slist_delete_link (accounts, cursor);
                        cursor = nxt;
@@ -449,37 +362,32 @@ modest_account_mgr_server_account_names   (ModestAccountMgr *self,
 }
 
 
-
-GSList*
-modest_account_mgr_account_names  (ModestAccountMgr *self, GError **err)
+GSList *
+modest_account_mgr_account_names (ModestAccountMgr * self, GError ** err)
 {
        GSList *accounts, *cursor;
        ModestAccountMgrPrivate *priv;
-       const size_t prefix_len =
-               strlen (MODEST_ACCOUNT_NAMESPACE "/");
+       const size_t prefix_len = strlen (MODEST_ACCOUNT_NAMESPACE "/");
 
 
        g_return_val_if_fail (self, NULL);
 
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
 
        accounts = modest_conf_list_subkeys (priv->modest_conf,
-                                            MODEST_ACCOUNT_NAMESPACE,
-                                            err);
+                                            MODEST_ACCOUNT_NAMESPACE, err);
        return strip_prefix_from_elements (accounts, prefix_len);
 }
 
 
-
-static gchar*
-get_account_string (ModestAccountMgr *self, const gchar *name,
-                   const gchar *key, gboolean server_account,
-                   GError **err)
+static gchar *
+get_account_string (ModestAccountMgr * self, const gchar * name,
+                   const gchar * key, gboolean server_account, GError ** err)
 {
        ModestAccountMgrPrivate *priv;
 
        gchar *keyname;
-       gchar * retval;
+       gchar *retval;
 
        g_return_val_if_fail (self, NULL);
        g_return_val_if_fail (name, NULL);
@@ -490,55 +398,36 @@ get_account_string (ModestAccountMgr *self, const gchar *name,
        else
                keyname = get_account_keyname (name, key);
 
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
-       retval = modest_conf_get_string (priv->modest_conf,keyname,err);
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+       retval = modest_conf_get_string (priv->modest_conf, keyname, err);
        g_free (keyname);
 
        return retval;
 }
 
 
-gchar*
-modest_account_mgr_get_server_account_string (ModestAccountMgr *self, const gchar *name,
-                                          const gchar *key, GError **err)
+gchar *
+modest_account_mgr_get_server_account_string (ModestAccountMgr * self,
+                                             const gchar * name,
+                                             const gchar * key,
+                                             GError ** err)
 {
        return get_account_string (self, name, key, TRUE, err);
 }
 
-gchar*
-modest_account_mgr_get_account_string (ModestAccountMgr *self, const gchar *name,
-                                   const gchar *key, GError **err)
-{
-       return get_account_string (self, name, key, FALSE, err);
-}
 
-gchar*
-modest_account_mgr_get_identity_string (ModestAccountMgr *self, const gchar *name,
-                   const gchar *key, GError **err)
+gchar *
+modest_account_mgr_get_account_string (ModestAccountMgr * self,
+                                      const gchar * name, const gchar * key,
+                                      GError ** err)
 {
-       ModestAccountMgrPrivate *priv;
-
-       gchar *keyname;
-       gchar * retval;
-
-       g_return_val_if_fail (self, NULL);
-       g_return_val_if_fail (name, NULL);
-       g_return_val_if_fail (key, NULL);
-
-       keyname = get_identity_keyname (name, key);
-       
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
-       retval = modest_conf_get_string (priv->modest_conf,keyname,err);
-       g_free (keyname);
-
-       return retval;
+       return get_account_string (self, name, key, FALSE, err);
 }
 
 
 static gint
-get_account_int (ModestAccountMgr *self, const gchar *name,
-                const gchar *key, gboolean server_account,
-                GError **err)
+get_account_int (ModestAccountMgr * self, const gchar * name,
+                const gchar * key, gboolean server_account, GError ** err)
 {
        ModestAccountMgrPrivate *priv;
 
@@ -554,8 +443,8 @@ get_account_int (ModestAccountMgr *self, const gchar *name,
        else
                keyname = get_account_keyname (name, key);
 
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
-       retval = modest_conf_get_int (priv->modest_conf,keyname,err);
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+       retval = modest_conf_get_int (priv->modest_conf, keyname, err);
        g_free (keyname);
 
        return retval;
@@ -563,25 +452,26 @@ get_account_int (ModestAccountMgr *self, const gchar *name,
 
 
 gint
-modest_account_mgr_get_server_account_int (ModestAccountMgr *self, const gchar *name,
-                                          const gchar *key, GError **err)
+modest_account_mgr_get_server_account_int (ModestAccountMgr * self,
+                                          const gchar * name,
+                                          const gchar * key, GError ** err)
 {
        return get_account_int (self, name, key, TRUE, err);
 }
 
+
 gint
-modest_account_mgr_get_account_int (ModestAccountMgr *self, const gchar *name,
-                                   const gchar *key, GError **err)
+modest_account_mgr_get_account_int (ModestAccountMgr * self,
+                                   const gchar * name, const gchar * key,
+                                   GError ** err)
 {
        return get_account_int (self, name, key, FALSE, err);
 }
 
 
-
 static gboolean
-get_account_bool (ModestAccountMgr *self, const gchar *name,
-                 const gchar *key, gboolean server_account,
-                 GError **err)
+get_account_bool (ModestAccountMgr * self, const gchar * name,
+                 const gchar * key, gboolean server_account, GError ** err)
 {
        ModestAccountMgrPrivate *priv;
 
@@ -597,37 +487,36 @@ get_account_bool (ModestAccountMgr *self, const gchar *name,
        else
                keyname = get_account_keyname (name, key);
 
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
-       retval = modest_conf_get_int (priv->modest_conf,keyname,err);
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+       retval = modest_conf_get_int (priv->modest_conf, keyname, err);
        g_free (keyname);
 
        return retval;
 }
 
 
-
 gint
-modest_account_mgr_get_server_account_bool (ModestAccountMgr *self, const gchar *name,
-                                          const gchar *key, GError **err)
+modest_account_mgr_get_server_account_bool (ModestAccountMgr * self,
+                                           const gchar * name,
+                                           const gchar * key, GError ** err)
 {
        return get_account_bool (self, name, key, TRUE, err);
 }
 
+
 gint
-modest_account_mgr_get_account_bool (ModestAccountMgr *self, const gchar *name,
-                                   const gchar *key, GError **err)
+modest_account_mgr_get_account_bool (ModestAccountMgr * self,
+                                    const gchar * name, const gchar * key,
+                                    GError ** err)
 {
        return get_account_bool (self, name, key, FALSE, err);
 }
 
 
-
-
-
 static gboolean
-set_account_string  (ModestAccountMgr *self, const gchar *name,
-                    const gchar *key, const gchar* val, gboolean server_account,
-                    GError **err)
+set_account_string (ModestAccountMgr * self, const gchar * name,
+                   const gchar * key, const gchar * val,
+                   gboolean server_account, GError ** err)
 {
        ModestAccountMgrPrivate *priv;
 
@@ -643,41 +532,40 @@ set_account_string  (ModestAccountMgr *self, const gchar *name,
        else
                keyname = get_account_keyname (name, key);
 
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
 
-       retval = modest_conf_set_string (priv->modest_conf,keyname,val,err);
+       retval = modest_conf_set_string (priv->modest_conf, keyname, val,
+                                        err);
 
        g_free (keyname);
        return retval;
 }
 
 
-
-
-
 gboolean
-modest_account_mgr_set_server_account_string  (ModestAccountMgr *self, const gchar *name,
-                                              const gchar *key, const gchar* val,
-                                              GError **err)
+modest_account_mgr_set_server_account_string (ModestAccountMgr * self,
+                                             const gchar * name,
+                                             const gchar * key,
+                                             const gchar * val,
+                                             GError ** err)
 {
        return set_account_string (self, name, key, val, TRUE, err);
 }
 
 
-
 gboolean
-modest_account_mgr_set_account_string  (ModestAccountMgr *self, const gchar *name,
-                                       const gchar *key, const gchar* val,
-                                       GError **err)
+modest_account_mgr_set_account_string (ModestAccountMgr * self,
+                                      const gchar * name, const gchar * key,
+                                      const gchar * val, GError ** err)
 {
        return set_account_string (self, name, key, val, FALSE, err);
 }
 
 
 static gboolean
-set_account_int  (ModestAccountMgr *self, const gchar *name,
-                 const gchar *key, gboolean server_account, int val,
-                 GError **err)
+set_account_int (ModestAccountMgr * self, const gchar * name,
+                const gchar * key, gboolean server_account, int val,
+                GError ** err)
 {
        ModestAccountMgrPrivate *priv;
 
@@ -693,40 +581,38 @@ set_account_int  (ModestAccountMgr *self, const gchar *name,
        else
                keyname = get_account_keyname (name, key);
 
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
 
-       retval = modest_conf_set_int (priv->modest_conf,keyname,val,err);
+       retval = modest_conf_set_int (priv->modest_conf, keyname, val, err);
 
        g_free (keyname);
        return retval;
 }
 
 
-
 gboolean
-modest_account_mgr_set_server_account_int (ModestAccountMgr *self, const gchar *name,
-                                          const gchar *key, int val,
-                                          GError **err)
+modest_account_mgr_set_server_account_int (ModestAccountMgr * self,
+                                          const gchar * name,
+                                          const gchar * key, int val,
+                                          GError ** err)
 {
        return set_account_int (self, name, key, val, TRUE, err);
 }
 
 
 gboolean
-modest_account_mgr_set_account_int  (ModestAccountMgr *self, const gchar *name,
-                                    const gchar *key, int val,
-                                    GError **err)
+modest_account_mgr_set_account_int (ModestAccountMgr * self,
+                                   const gchar * name, const gchar * key,
+                                   int val, GError ** err)
 {
        return set_account_int (self, name, key, val, FALSE, err);
 }
 
 
-
-
 static gboolean
-set_account_bool  (ModestAccountMgr *self, const gchar *name,
-                  const gchar *key, gboolean server_account, gboolean val,
-                  GError **err)
+set_account_bool (ModestAccountMgr * self, const gchar * name,
+                 const gchar * key, gboolean server_account, gboolean val,
+                 GError ** err)
 {
        ModestAccountMgrPrivate *priv;
 
@@ -742,9 +628,9 @@ set_account_bool  (ModestAccountMgr *self, const gchar *name,
        else
                keyname = get_account_keyname (name, key);
 
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
 
-       retval = modest_conf_set_bool (priv->modest_conf,keyname,val,err);
+       retval = modest_conf_set_bool (priv->modest_conf, keyname, val, err);
 
        g_free (keyname);
        return retval;
@@ -752,30 +638,27 @@ set_account_bool  (ModestAccountMgr *self, const gchar *name,
 
 
 gboolean
-modest_account_mgr_set_server_account_bool  (ModestAccountMgr *self, const gchar *name,
-                                            const gchar *key, gboolean val,
-                                            GError **err)
+modest_account_mgr_set_server_account_bool (ModestAccountMgr * self,
+                                           const gchar * name,
+                                           const gchar * key, gboolean val,
+                                           GError ** err)
 {
        return set_account_bool (self, name, key, val, TRUE, err);
 }
 
 
-
 gboolean
-modest_account_mgr_set_account_bool  (ModestAccountMgr *self, const gchar *name,
-                                       const gchar *key, gboolean val,
-                                       GError **err)
+modest_account_mgr_set_account_bool (ModestAccountMgr * self,
+                                    const gchar * name, const gchar * key,
+                                    gboolean val, GError ** err)
 {
        return set_account_bool (self, name, key, val, FALSE, err);
 }
 
 
-
-
-
 gboolean
-account_exists (ModestAccountMgr *self, const gchar *name, gboolean server_account,
-               GError **err)
+account_exists (ModestAccountMgr * self, const gchar * name,
+               gboolean server_account, GError ** err)
 {
        ModestAccountMgrPrivate *priv;
 
@@ -790,8 +673,8 @@ account_exists (ModestAccountMgr *self, const gchar *name, gboolean server_accou
        else
                keyname = get_server_account_keyname (name, NULL);
 
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
-       retval = modest_conf_key_exists (priv->modest_conf,keyname,err);
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+       retval = modest_conf_key_exists (priv->modest_conf, keyname, err);
 
        g_free (keyname);
        return retval;
@@ -799,68 +682,44 @@ account_exists (ModestAccountMgr *self, const gchar *name, gboolean server_accou
 
 
 gboolean
-modest_account_mgr_server_account_exists (ModestAccountMgr *self, const gchar *name,
-                                  GError **err)
+modest_account_mgr_server_account_exists (ModestAccountMgr * self,
+                                         const gchar * name, GError ** err)
 {
        return account_exists (self, name, TRUE, err);
 }
 
 
 gboolean
-modest_account_mgr_account_exists (ModestAccountMgr *self, const gchar *name,
-                                  GError **err)
+modest_account_mgr_account_exists (ModestAccountMgr * self,
+                                  const gchar * name, GError ** err)
 {
        return account_exists (self, name, FALSE, err);
 }
 
-gboolean
-modest_account_mgr_identity_exists (ModestAccountMgr *self, const gchar *name,
-                                  GError **err)
-{
-       return account_exists (self, name, TRUE, err);
-}
-
-
-
-/* must be freed by caller */
-static gchar*
-get_account_keyname (const gchar *accname, const gchar *name)
-{
-       if (name)
-               return g_strconcat
-                        (MODEST_ACCOUNT_NAMESPACE, "/",
-                         accname, "/", name, NULL);
-       else
-                return g_strconcat
-                        (MODEST_ACCOUNT_NAMESPACE, "/",
-                         accname, NULL);
-}
-
 
 /* must be freed by caller */
-static gchar*
-get_server_account_keyname (const gchar *accname, const gchar *name)
+static gchar *
+get_account_keyname (const gchar * accname, const gchar * name)
 {
        if (name)
                return g_strconcat
-                       (MODEST_SERVER_ACCOUNT_NAMESPACE, "/",
+                       (MODEST_ACCOUNT_NAMESPACE, "/",
                         accname, "/", name, NULL);
        else
                return g_strconcat
-                       (MODEST_SERVER_ACCOUNT_NAMESPACE, "/",
-                        accname, NULL);
+                       (MODEST_ACCOUNT_NAMESPACE, "/", accname, NULL);
 }
 
+
 /* must be freed by caller */
-static gchar*
-get_identity_keyname (const gchar *accname, const gchar *name)
+static gchar *
+get_server_account_keyname (const gchar * accname, const gchar * name)
 {
        if (name)
                return g_strconcat
-                       (MODEST_IDENTITY_NAMESPACE "/",
+                       (MODEST_SERVER_ACCOUNT_NAMESPACE, "/",
                         accname, "/", name, NULL);
        else
                return g_strconcat
-                       (MODEST_IDENTITY_NAMESPACE, "/",
-                        accname, NULL);
+                       (MODEST_SERVER_ACCOUNT_NAMESPACE, "/", accname, NULL);
 }
index fc3e46f..0d21a01 100644 (file)
@@ -126,47 +126,6 @@ gboolean modest_account_mgr_add_server_account    (ModestAccountMgr *self,
 gboolean        modest_account_mgr_remove_server_account    (ModestAccountMgr *self,
                                                             const gchar *name,
                                                             GError **err);
-                                                                /**
- * modest_account_mgr_remove_identity:
- * @self: a ModestAccountMgr instance
- * @name: the name for the identity
- * @err: a GError ptr, or NULL to ignore.
- * 
- * remove aidentity from the configuration
- * the identity with @name should exist
- *
- * Returns: TRUE if the removal succeeded, FALSE otherwise,
- * @err gives details in case of error
- */
-gboolean        modest_account_mgr_remove_identity (ModestAccountMgr *self,
-                                                            const gchar *name,
-                                                            GError **err);
-
-/**
- * modest_account_mgr_add_identity:
- * @self: a ModestAccountMgr instance
- * @name: the name (id) for the identity
- * @email: the user's email address
- * @replyto: default replyto address
- * @signature: the signature for this identity
- * @use_signature: whether to use this signature instead of the default one
- * @id_via: the transport to send emails for this identity via
- * @use_id_via: whether to use this via insteda of the default one
- * 
- * add a user identity to the configuration
- * 
- * Returns: TRUE if  succeeded, FALSE otherwise,
- */
-
-gboolean
-modest_account_mgr_add_identity (ModestAccountMgr *self,
-                      const gchar *name,
-                                         const gchar *email,
-                                         const gchar *replyto,
-                                         const gchar *signature,
-                      const gboolean use_signature,
-                      const gchar *id_via,
-                      const gboolean use_id_via);
 
 /**
  * modest_account_mgr_account_names:
@@ -242,10 +201,6 @@ gchar*             modest_account_mgr_get_account_string     (ModestAccountMgr *self
 gchar*         modest_account_mgr_get_server_account_string     (ModestAccountMgr *self,
                                                           const gchar *name,
                                                           const gchar *key, GError **err);
-gchar*         modest_account_mgr_get_identity_string     (ModestAccountMgr *self,
-                                                          const gchar *name,
-                                                          const gchar *key, GError **err);
-
 
 /**
  * modest_account_mgr_get_account_int:
diff --git a/src/modest-identity-keys.h b/src/modest-identity-keys.h
new file mode 100644 (file)
index 0000000..8f1967f
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef __MODEST_IDENTITY_KEYS_H__
+#define __MODEST_IDENTITY_KEYS_H__
+
+#include "modest-conf-keys.h"
+
+#define MODEST_IDENTITY_DEFAULT_IDENTITY  "myidentity"
+
+
+/* configuration key definitions for modest */
+#define MODEST_IDENTITY_NAMESPACE        MODEST_CONF_NAMESPACE "/" "identities"
+
+/* user identity keys */
+#define MODEST_IDENTITY_DISPLAY_NAME      "display_name"   /* string */
+#define MODEST_IDENTITY_EMAIL             "email"          /* string */
+#define MODEST_IDENTITY_REPLYTO           "replyto"        /* string */
+#define MODEST_IDENTITY_SIGNATURE         "signature"      /* string */
+#define MODEST_IDENTITY_USE_SIGNATURE     "use_signature"  /* boolean */
+#define MODEST_IDENTITY_ID_VIA            "id_via"         /* string */
+#define MODEST_IDENTITY_USE_ID_VIA        "use_id_via"     /* boolean */
+/* MISSING: everything related to gpg */
+
+#endif /*__MODEST_IDENTITY_KEYS_H__*/
diff --git a/src/modest-identity-mgr.c b/src/modest-identity-mgr.c
new file mode 100644 (file)
index 0000000..7c50f22
--- /dev/null
@@ -0,0 +1,444 @@
+/* modest-identity-mgr.c */
+
+/* insert (c)/licensing information) */
+
+#include <string.h>
+#include "modest-identity-mgr.h"
+
+/* 'private'/'protected' functions */
+static void modest_identity_mgr_class_init (ModestIdentityMgrClass * klass);
+static void modest_identity_mgr_init (ModestIdentityMgr * obj);
+static void modest_identity_mgr_finalize (GObject * obj);
+
+static gchar *get_identity_keyname (const gchar * accname,
+                                   const gchar * name);
+
+/* list my signals */
+enum {
+       /* MY_SIGNAL_1, */
+       /* MY_SIGNAL_2, */
+       LAST_SIGNAL
+};
+
+typedef struct _ModestIdentityMgrPrivate ModestIdentityMgrPrivate;
+struct _ModestIdentityMgrPrivate {
+       ModestConf *modest_conf;
+};
+
+#define MODEST_IDENTITY_MGR_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
+                                                MODEST_TYPE_IDENTITY_MGR, \
+                                                ModestIdentityMgrPrivate))
+/* globals */
+static GObjectClass *parent_class = NULL;
+
+/* uncomment the following if you have defined any signals */
+/* static guint signals[LAST_SIGNAL] = {0}; */
+
+GType
+modest_identity_mgr_get_type (void)
+{
+       static GType my_type = 0;
+
+       if (!my_type) {
+               static const GTypeInfo my_info = {
+                       sizeof (ModestIdentityMgrClass),
+                       NULL,   /* base init */
+                       NULL,   /* base finalize */
+                       (GClassInitFunc) modest_identity_mgr_class_init,
+                       NULL,   /* class finalize */
+                       NULL,   /* class data */
+                       sizeof (ModestIdentityMgr),
+                       1,      /* n_preallocs */
+                       (GInstanceInitFunc) modest_identity_mgr_init,
+               };
+
+               my_type = g_type_register_static (G_TYPE_OBJECT,
+                                                 "ModestIdentityMgr",
+                                                 &my_info, 0);
+       }
+       return my_type;
+}
+
+static void
+modest_identity_mgr_class_init (ModestIdentityMgrClass * klass)
+{
+       GObjectClass *gobject_class;
+
+       gobject_class = (GObjectClass *) klass;
+
+       parent_class = g_type_class_peek_parent (klass);
+       gobject_class->finalize = modest_identity_mgr_finalize;
+
+       g_type_class_add_private (gobject_class,
+                                 sizeof (ModestIdentityMgrPrivate));
+
+/* signal definitions go here, e.g.: */
+/*     signals[MY_SIGNAL_1] = */
+/*             g_signal_new ("my_signal_1",....); */
+/*     signals[MY_SIGNAL_2] = */
+/*             g_signal_new ("my_signal_2",....); */
+/*     etc. */
+}
+
+
+static void
+modest_identity_mgr_init (ModestIdentityMgr * obj)
+{
+       ModestIdentityMgrPrivate *priv =
+               MODEST_IDENTITY_MGR_GET_PRIVATE (obj);
+       priv->modest_conf = NULL;
+}
+
+static void
+modest_identity_mgr_finalize (GObject * obj)
+{
+       ModestIdentityMgr *self = MODEST_IDENTITY_MGR (obj);
+       ModestIdentityMgrPrivate *priv =
+               MODEST_IDENTITY_MGR_GET_PRIVATE (self);
+
+       g_object_unref (G_OBJECT (priv->modest_conf));
+       priv->modest_conf = NULL;
+}
+
+GObject *
+modest_identity_mgr_new (ModestConf * conf)
+{
+       GObject *obj;
+       ModestIdentityMgrPrivate *priv;
+
+       g_return_val_if_fail (conf, NULL);
+
+       obj = G_OBJECT (g_object_new (MODEST_TYPE_IDENTITY_MGR, NULL));
+       priv = MODEST_IDENTITY_MGR_GET_PRIVATE (obj);
+
+       /*
+        * increase the ref count on the modest_conf. Normally, the
+        * ModestConf should outlive the ModestIdentityMgr though
+        */
+       g_object_ref (G_OBJECT (priv->modest_conf = conf));
+       return obj;
+}
+
+
+gboolean
+modest_identity_mgr_remove_identity (ModestIdentityMgr * self,
+                                    const gchar * name, GError ** err)
+{
+       ModestIdentityMgrPrivate *priv;
+       gchar *key;
+       gboolean retval;
+
+       g_return_val_if_fail (self, FALSE);
+       g_return_val_if_fail (name, FALSE);
+
+       if (!modest_identity_mgr_identity_exists (self, name, err)) {
+               g_warning ("identity doest not exist");
+               return FALSE;
+       }
+
+       priv = MODEST_IDENTITY_MGR_GET_PRIVATE (self);
+       key = get_identity_keyname (name, NULL);
+
+       retval = modest_conf_remove_key (priv->modest_conf, key, NULL);
+
+       g_free (key);
+       return retval;
+}
+
+
+static const gchar *
+null_means_empty (const gchar * str)
+{
+       return str ? str : "";
+}
+
+
+gboolean
+modest_identity_mgr_add_identity (ModestIdentityMgr * self,
+                                 const gchar * name,
+                                 const gchar * email,
+                                 const gchar * replyto,
+                                 const gchar * signature,
+                                 const gboolean use_signature,
+                                 const gchar * id_via,
+                                 const gboolean use_id_via)
+{
+       ModestIdentityMgrPrivate *priv;
+       gchar *id_key, *key;
+
+       g_return_val_if_fail (self, FALSE);
+       g_return_val_if_fail (name, FALSE);
+
+       /* TODO: check already exists */
+
+       priv = MODEST_IDENTITY_MGR_GET_PRIVATE (self);
+       id_key = g_strconcat (MODEST_IDENTITY_NAMESPACE, "/", name, NULL);
+
+       if (modest_conf_key_exists (priv->modest_conf, id_key, NULL)) {
+               g_warning ("identity %s already exists", name);
+               //g_free (id_key);
+               //return FALSE;
+       }
+
+       /* email */
+       key = g_strconcat (id_key, "/", MODEST_IDENTITY_EMAIL, NULL);
+       modest_conf_set_string (priv->modest_conf, key,
+                               null_means_empty (email), NULL);
+       g_free (key);
+
+       /* replyto */
+       key = g_strconcat (id_key, "/", MODEST_IDENTITY_REPLYTO, NULL);
+       modest_conf_set_string (priv->modest_conf, key,
+                               null_means_empty (replyto), NULL);
+       g_free (key);
+
+       /* signature */
+       key = g_strconcat (id_key, "/", MODEST_IDENTITY_SIGNATURE, NULL);
+       modest_conf_set_string (priv->modest_conf, key,
+                               null_means_empty (signature), NULL);
+       g_free (key);
+
+       /* use_signature */
+       key = g_strconcat (id_key, "/", MODEST_IDENTITY_USE_SIGNATURE, NULL);
+       modest_conf_set_bool (priv->modest_conf, key, use_signature, NULL);
+       g_free (key);
+
+       /* signature */
+       key = g_strconcat (id_key, "/", MODEST_IDENTITY_ID_VIA, NULL);
+       modest_conf_set_string (priv->modest_conf, key,
+                               null_means_empty (id_via), NULL);
+       g_free (key);
+
+       /* use_signature */
+       key = g_strconcat (id_key, "/", MODEST_IDENTITY_USE_ID_VIA, NULL);
+       modest_conf_set_bool (priv->modest_conf, key, use_id_via, NULL);
+       g_free (key);
+       g_free (id_key);
+
+       return TRUE;            /* FIXME: better error checking */
+}
+
+/* strip the first /n/ character from each element */
+/* caller must make sure all elements are strings with
+ * length >= n, and also that data can be freed.
+ */
+/* this function is copied from modest-account-mgr. Maybe it should be moved
+ * to modest-list-utils or the like...
+ */
+static GSList *
+strip_prefix_from_elements (GSList * lst, guint n)
+{
+       GSList *cursor = lst;
+
+       while (cursor) {
+               gchar *str = (gchar *) cursor->data;
+
+               cursor->data = g_strdup (str + n);
+               g_free (str);
+               cursor = cursor->next;
+       }
+       return lst;
+}
+
+GSList *
+modest_identity_mgr_identity_names (ModestIdentityMgr * self, GError ** err)
+{
+       GSList *identities, *cursor;
+       ModestIdentityMgrPrivate *priv;
+       const size_t prefix_len = strlen (MODEST_IDENTITY_NAMESPACE "/");
+
+
+       g_return_val_if_fail (self, NULL);
+
+       priv = MODEST_IDENTITY_MGR_GET_PRIVATE (self);
+
+       identities = modest_conf_list_subkeys (priv->modest_conf,
+                                              MODEST_IDENTITY_NAMESPACE,
+                                              err);
+       return strip_prefix_from_elements (identities, prefix_len);
+}
+
+
+gchar *
+modest_identity_mgr_get_identity_string (ModestIdentityMgr * self,
+                                        const gchar * name,
+                                        const gchar * key, GError ** err)
+{
+       ModestIdentityMgrPrivate *priv;
+
+       gchar *keyname;
+       gchar *retval;
+
+       g_return_val_if_fail (self, NULL);
+       g_return_val_if_fail (name, NULL);
+       g_return_val_if_fail (key, NULL);
+
+       keyname = get_identity_keyname (name, key);
+
+       priv = MODEST_IDENTITY_MGR_GET_PRIVATE (self);
+       retval = modest_conf_get_string (priv->modest_conf, keyname, err);
+       g_free (keyname);
+
+       return retval;
+}
+
+
+gint
+modest_identity_mgr_get_identity_int (ModestIdentityMgr * self,
+                                     const gchar * name, const gchar * key,
+                                     GError ** err)
+{
+       ModestIdentityMgrPrivate *priv;
+
+       gchar *keyname;
+       gint retval;
+
+       g_return_val_if_fail (self, -1);
+       g_return_val_if_fail (name, -1);
+       g_return_val_if_fail (key, -1);
+
+       keyname = get_identity_keyname (name, key);
+       priv = MODEST_IDENTITY_MGR_GET_PRIVATE (self);
+       retval = modest_conf_get_int (priv->modest_conf, keyname, err);
+       g_free (keyname);
+
+       return retval;
+}
+
+
+
+gboolean
+modest_identity_mgr_get_identity_bool (ModestIdentityMgr * self,
+                                      const gchar * name, const gchar * key,
+                                      GError ** err)
+{
+       ModestIdentityMgrPrivate *priv;
+
+       gchar *keyname;
+       gboolean retval;
+
+       g_return_val_if_fail (self, -1);
+       g_return_val_if_fail (name, -1);
+       g_return_val_if_fail (key, -1);
+
+       keyname = get_identity_keyname (name, key);
+
+       priv = MODEST_IDENTITY_MGR_GET_PRIVATE (self);
+       retval = modest_conf_get_int (priv->modest_conf, keyname, err);
+       g_free (keyname);
+
+       return retval;
+}
+
+
+gboolean
+modest_identity_mgr_set_identity_string (ModestIdentityMgr * self,
+                                        const gchar * name,
+                                        const gchar * key, const gchar * val,
+                                        GError ** err)
+{
+       ModestIdentityMgrPrivate *priv;
+
+       gchar *keyname;
+       gboolean retval;
+
+       g_return_val_if_fail (self, FALSE);
+       g_return_val_if_fail (name, FALSE);
+       g_return_val_if_fail (key, FALSE);
+
+       keyname = get_identity_keyname (name, key);
+
+       priv = MODEST_IDENTITY_MGR_GET_PRIVATE (self);
+
+       retval = modest_conf_set_string (priv->modest_conf, keyname, val,
+                                        err);
+
+       g_free (keyname);
+       return retval;
+}
+
+
+gboolean
+modest_identity_mgr_set_identity_int (ModestIdentityMgr * self,
+                                     const gchar * name, const gchar * key,
+                                     const gint val, GError ** err)
+{
+       ModestIdentityMgrPrivate *priv;
+
+       gchar *keyname;
+       gboolean retval;
+
+       g_return_val_if_fail (self, FALSE);
+       g_return_val_if_fail (name, FALSE);
+       g_return_val_if_fail (key, FALSE);
+
+       keyname = get_identity_keyname (name, key);
+
+       priv = MODEST_IDENTITY_MGR_GET_PRIVATE (self);
+
+       retval = modest_conf_set_int (priv->modest_conf, keyname, val, err);
+
+       g_free (keyname);
+       return retval;
+}
+
+
+gboolean
+modest_identy_mgr_set_identity_bool (ModestIdentityMgr * self,
+                                    const gchar * name, const gchar * key,
+                                    gboolean val, GError ** err)
+{
+       ModestIdentityMgrPrivate *priv;
+
+       gchar *keyname;
+       gboolean retval;
+
+       g_return_val_if_fail (self, FALSE);
+       g_return_val_if_fail (name, FALSE);
+       g_return_val_if_fail (key, FALSE);
+
+       keyname = get_identity_keyname (name, key);
+
+       priv = MODEST_IDENTITY_MGR_GET_PRIVATE (self);
+
+       retval = modest_conf_set_bool (priv->modest_conf, keyname, val, err);
+
+       g_free (keyname);
+       return retval;
+}
+
+
+gboolean
+modest_identity_mgr_identity_exists (ModestIdentityMgr * self,
+                                    const gchar * name, GError ** err)
+{
+       ModestIdentityMgrPrivate *priv;
+
+       gchar *keyname;
+       gboolean retval;
+
+       g_return_val_if_fail (self, FALSE);
+       g_return_val_if_fail (name, FALSE);
+
+       keyname = get_identity_keyname (name, NULL);
+
+       priv = MODEST_IDENTITY_MGR_GET_PRIVATE (self);
+       retval = modest_conf_key_exists (priv->modest_conf, keyname, err);
+
+       g_free (keyname);
+       return retval;
+}
+
+
+/* must be freed by caller */
+static gchar *
+get_identity_keyname (const gchar * idname, const gchar * name)
+{
+       if (name)
+               return g_strconcat
+                       (MODEST_IDENTITY_NAMESPACE, "/",
+                        idname, "/", name, NULL);
+       else
+               return g_strconcat
+                       (MODEST_IDENTITY_NAMESPACE, "/", idname, NULL);
+}
diff --git a/src/modest-identity-mgr.h b/src/modest-identity-mgr.h
new file mode 100644 (file)
index 0000000..6d58360
--- /dev/null
@@ -0,0 +1,246 @@
+/* modest-identity-mgr.h */
+/* insert (c)/licensing information) */
+
+#ifndef __MODEST_IDENTITY_MGR_H__
+#define __MODEST_IDENTITY_MGR_H__
+
+#include <glib-object.h>
+#include "modest-conf.h"
+#include "modest-identity-keys.h"
+#include "modest-proto.h"
+
+G_BEGIN_DECLS
+/* convenience macros */
+#define MODEST_TYPE_IDENTITY_MGR             (modest_identity_mgr_get_type())
+#define MODEST_IDENTITY_MGR(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_IDENTITY_MGR,ModestIdentityMgr))
+#define MODEST_IDENTITY_MGR_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_IDENTITY_MGR,GObject))
+#define MODEST_IS_IDENTITY_MGR(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_IDENTITY_MGR))
+#define MODEST_IS_IDENTITY_MGR_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_IDENTITY_MGR))
+#define MODEST_IDENTITY_MGR_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_IDENTITY_MGR,ModestIdentityMgrClass))
+typedef struct _ModestIdentityMgr ModestIdentityMgr;
+typedef struct _ModestIdentityMgrClass ModestIdentityMgrClass;
+
+
+struct _ModestIdentityMgr {
+       GObject parent;
+       /* insert public members, if any */
+};
+
+struct _ModestIdentityMgrClass {
+       GObjectClass parent_class;
+       /* insert signal callback declarations, eg. */
+       /* void (* my_event) (ModestIdentityMgr* obj); */
+};
+
+
+/**
+ * modest_ui_get_type:
+ * 
+ * get the GType for ModestIdentityMgr
+ *  
+ * Returns: the GType
+ */
+GType modest_identity_mgr_get_type (void) G_GNUC_CONST;
+
+
+/**
+ * modest_identity_mgr_new:
+ * @modest_conf: a ModestConf instance 
+ *  
+ * Returns: a new ModestIdentityMgr, or NULL in case of error
+ */
+GObject * modest_identity_mgr_new (ModestConf * modest_conf);
+
+
+/**
+ * modest_identity_mgr_add_identity:
+ * @self: a ModestIdentityMgr instance
+ * @name: the name (id) for the identity
+ * @email: the user's email address which is used when sending email
+ * @replyto: the default replyto address
+ * @signature: the signature for this identity
+ * @use_signature: whether to use this signature instead of the default one
+ * @id_via: the transport to send emails for this identity via
+ * @use_id_via: whether to use this via instead of the default one
+ * 
+ * add a user identity to the configuration
+ * 
+ * Returns: TRUE if  succeeded, FALSE otherwise,
+ */
+gboolean modest_identity_mgr_add_identity (ModestIdentityMgr * self,
+                                                                                  const gchar * name,
+                                                                                  const gchar * email,
+                                                                                  const gchar * replyto,
+                                                                                  const gchar * signature,
+                                                                                  const gboolean use_signature,
+                                                                                  const gchar * id_via,
+                                                                                  const gboolean use_id_via);
+
+
+/**
+ * modest_identity_mgr_remove_identity:
+ * @self: a ModestIdentityMgr instance
+ * @name: the name of the identity to remove
+ * @err: a GError ptr, or NULL to ignore.
+ * 
+ * remove identity from the configuration
+ * the identity with @name should exist
+ *
+ * Returns: TRUE if the removal succeeded, FALSE otherwise,
+ * @err gives details in case of error
+ */
+gboolean modest_identity_mgr_remove_identity (ModestIdentityMgr * self,
+                                                                                         const gchar * name,
+                                                                                         GError ** err);
+
+
+/**
+ * modest_identity_mgr_identity_names:
+ * @self: a ModestIdentityMgr instance
+ * @err: a GError ptr, or NULL to ignore.
+ * 
+ * list all identities
+ *
+ * Returns: a newly allocated list of identities, or NULL in case of error or
+ * if there are no identities. The caller must free the returned GSList
+ * @err gives details in case of error
+ */
+GSList *modest_identity_mgr_identity_names (ModestIdentityMgr * self,
+                                                                                       GError ** err);
+
+
+/**
+ * modest_identity_mgr_identity_exists:
+ * @self: a ModestIdentityMgr instance
+ * @err: a GError ptr, or NULL to ignore.
+ * 
+ * check whether identity @name exists
+ *
+ * Returns: TRUE if the identity exists, FALSE otherwise (or in case of error)
+ * @err gives details in case of error
+ */
+gboolean modest_identity_mgr_identity_exists (ModestIdentityMgr * self,
+                                                                                         const gchar * name,
+                                                                                         GError ** err);
+
+
+/* identity specific functions */
+
+/**
+ * modest_identity_mgr_get_identity_string:
+ * @self: a ModestIdentityMgr instance
+ * @name: the name of the identity
+ * @key: the key of the value to retrieve
+ * @err: a GError ptr, or NULL to ignore.
+ * 
+ * get a config string from an identity
+ *
+ * Returns: a newly allocated string with the value for the key,
+ * or NULL in case of error. @err gives details in case of error
+ */
+gchar *modest_identity_mgr_get_identity_string (ModestIdentityMgr * self,
+                                                                                               const gchar * name,
+                                                                                               const gchar * key,
+                                                                                               GError ** err);
+
+
+/**
+ * modest_identity_mgr_get_identity_int:
+ * @self: a ModestIdentityMgr instance
+ * @name: the name of the identity
+ * @key: the key of the value to retrieve
+ * @err: a GError ptr, or NULL to ignore.
+ * 
+ * get a config int from an identity
+ *
+ * Returns: an integer with the value for the key, or -1 in case of
+ * error (but of course -1 does not necessarily imply an error)
+ * @err gives details in case of error
+ */
+gint modest_identity_mgr_get_identity_int (ModestIdentityMgr * self,
+                                                                                  const gchar * name,
+                                                                                  const gchar * key,
+                                                                                  GError ** err);
+
+
+/**
+ * modest_identity_mgr_get_identity_bool:
+ * @self: a ModestIdentityMgr instance
+ * @name: the name of the identity
+ * @key: the key of the value to retrieve
+ * @err: a GError ptr, or NULL to ignore.
+ * 
+ * get a config boolean from an identity
+ *
+ * Returns: an boolean with the value for the key, or FALSE in case of
+ * error (but of course FALSE does not necessarily imply an error)
+ * @err gives details in case of error
+ */
+gboolean modest_identity_mgr_get_identity_bool (ModestIdentityMgr * self,
+                                                                                               const gchar * name,
+                                                                                               const gchar * key,
+                                                                                               GError ** err);
+
+
+/**
+ * modest_identity_mgr_set_identity_string:
+ * @self: a ModestIdentityMgr instance
+ * @name: the name of the identity
+ * @key: the key of the value to set
+ * @val: the value to set
+ * @err: a GError ptr, or NULL to ignore.
+ * 
+ * set a config string for an identity
+ *
+ * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
+ * @err gives details in case of error
+ */
+gboolean modest_identity_mgr_set_identity_string (ModestIdentityMgr *
+                                                                                                 self,
+                                                                                                 const gchar * name,
+                                                                                                 const gchar * key,
+                                                                                                 const gchar * val,
+                                                                                                 GError ** err);
+
+
+/**
+ * modest_identity_mgr_set_identity_int:
+ * @self: a ModestIdentityMgr instance
+ * @name: the name of the identity
+ * @key: the key of the value to set
+ * @val: the value to set
+ * @err: a GError ptr, or NULL to ignore.
+ * 
+ * set a config int for an identity
+ *
+ * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
+ * @err gives details in case of error
+ */
+gboolean modest_identity_mgr_set_identity_int (ModestIdentityMgr * self,
+                                                                                          const gchar * name,
+                                                                                          const gchar * key,
+                                                                                          gint val, GError ** err);
+
+
+/**
+ * modest_identity_mgr_set_identity_bool:
+ * @self: a ModestIdentityMgr instance
+ * @name: the name of the identity
+ * @key: the key of the value to set
+ * @val: the value to set
+ * @err: a GError ptr, or NULL to ignore.
+ * 
+ * set a config bool for an identity
+ *
+ * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
+ * @err gives details in case of error
+ */
+gboolean modest_identity_mgr_set_identity_bool (ModestIdentityMgr * self,
+                                                                                               const gchar * name,
+                                                                                               const gchar * key,
+                                                                                               gboolean val,
+                                                                                               GError ** err);
+
+
+G_END_DECLS
+#endif /* __MODEST_IDENTITY_MGR_H__ */
index a2cbc78..77327c0 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "modest-conf.h"
 #include "modest-account-mgr.h"
+#include "modest-identity-mgr.h"
 #include "modest-ui.h"
 
 #ifdef HAVE_CONFIG_H
@@ -152,6 +153,7 @@ static void
 install_test_account (ModestConf *conf)
 {
        ModestAccountMgr *acc_mgr;
+       ModestIdentityMgr *id_mgr;
        const gchar *acc_name = "test";
        g_return_if_fail (conf);
 
@@ -177,13 +179,18 @@ install_test_account (ModestConf *conf)
                                                       NULL, "smtp");
                
        }
-       if (modest_account_mgr_identity_exists(acc_mgr, "myidentity", NULL)) {
-               if (!modest_account_mgr_remove_identity(acc_mgr, "myidentity", NULL)) {
+       id_mgr = MODEST_IDENTITY_MGR(modest_identity_mgr_new (conf));
+       if (modest_identity_mgr_identity_exists(id_mgr, "myidentity", NULL)) {
+               if (!modest_identity_mgr_remove_identity(id_mgr, "myidentity", NULL)) {
                        g_warning ("could not delete existing identity");
                }
        }
-       if (!modest_account_mgr_add_identity (acc_mgr, "myidentity", "user@localhost",
-                                      "", "", FALSE, NULL, FALSE ))
-               g_warning ("failed to add test account");
+       if (!modest_identity_mgr_add_identity (id_mgr,
+                                                                                  MODEST_IDENTITY_DEFAULT_IDENTITY,
+                                                                                  "user@localhost",
+                                                                                  "", "", FALSE, NULL, FALSE ))
+               g_warning ("failed to add test identity");
+       
        g_object_unref (G_OBJECT(acc_mgr));
+       g_object_unref (G_OBJECT(id_mgr));
 }