X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-identity-mgr.c;h=7998b6057820119006795c1c93c4e1cd35172655;hp=998802eb370c2f319c534ff47393b851fec9fbf3;hb=594df7314e513f2de2c2e7559c19bfdbdf1f7012;hpb=3165ffeeee3bfa260c86ad5ecee3f29bf686a798 diff --git a/src/modest-identity-mgr.c b/src/modest-identity-mgr.c index 998802e..7998b60 100644 --- a/src/modest-identity-mgr.c +++ b/src/modest-identity-mgr.c @@ -1,8 +1,37 @@ -/* modest-identity-mgr.c */ +/* Copyright (c) 2006, Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + -/* insert (c)/licensing information) */ +/* modest-identity-mgr.c */ #include +#include "modest-marshal.h" #include "modest-identity-mgr.h" /* 'private'/'protected' functions */ @@ -15,14 +44,16 @@ static gchar *get_identity_keyname (const gchar * accname, /* list my signals */ enum { - /* MY_SIGNAL_1, */ - /* MY_SIGNAL_2, */ + IDENTITY_CHANGE_SIGNAL, + IDENTITY_REMOVE_SIGNAL, + IDENTITY_ADD_SIGNAL, LAST_SIGNAL }; typedef struct _ModestIdentityMgrPrivate ModestIdentityMgrPrivate; struct _ModestIdentityMgrPrivate { ModestConf *modest_conf; + GSList *current_identities; }; #define MODEST_IDENTITY_MGR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ @@ -32,7 +63,82 @@ struct _ModestIdentityMgrPrivate { static GObjectClass *parent_class = NULL; /* uncomment the following if you have defined any signals */ -/* static guint signals[LAST_SIGNAL] = {0}; */ +static guint signals[LAST_SIGNAL] = {0}; + + +static GSList * +delete_account_from_list (GSList *list, const gchar *name) +{ + GSList *iter, *result; + + iter = list; + result = list; + while (iter) { + if (!strcmp (name, iter->data)) { + result = g_slist_delete_link (list, iter); + break; + } + + iter = g_slist_next (iter); + } + return result; +} + +static GSList * +find_account_in_list (GSList *list, const gchar *name) +{ + GSList *iter, *result; + + iter = list; + result = list; + while (iter) { + if (!strcmp (name, iter->data)) { + return iter; + break; + } + + iter = g_slist_next (iter); + } + return NULL; +} + + +static void +modest_identity_mgr_check_change (ModestConf *conf, + const gchar *key, + const gchar *new_value, + gpointer userdata) +{ + ModestIdentityMgr *id_mgr = userdata; + ModestIdentityMgrPrivate *priv = MODEST_IDENTITY_MGR_GET_PRIVATE(id_mgr); + gchar *subkey; + gchar *param; + + if ((strlen(key) > strlen(MODEST_IDENTITY_NAMESPACE "/") + && g_str_has_prefix(key, MODEST_IDENTITY_NAMESPACE))) { + subkey = g_strdup(key + strlen(MODEST_IDENTITY_NAMESPACE "/")); + if (! strstr(subkey, "/")) { /* no more '/' means an entry was modified */ + if (!new_value) { + priv->current_identities = + delete_account_from_list (priv->current_identities, subkey); + g_signal_emit(id_mgr, signals[IDENTITY_REMOVE_SIGNAL], 0, subkey); + } + } + else { + param = strstr(subkey, "/"); + param[0] = 0; + param++; + + if (!find_account_in_list(priv->current_identities, subkey)) { + priv->current_identities = + g_slist_prepend(priv->current_identities, g_strdup(subkey)); + g_signal_emit(id_mgr, signals[IDENTITY_ADD_SIGNAL], 0, subkey); + } + g_signal_emit(id_mgr, signals[IDENTITY_CHANGE_SIGNAL], 0, subkey, param, new_value); + } + g_free(subkey); + } +} GType modest_identity_mgr_get_type (void) @@ -63,6 +169,7 @@ static void modest_identity_mgr_class_init (ModestIdentityMgrClass * klass) { GObjectClass *gobject_class; + GType paramtypes[3] = {G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER}; gobject_class = (GObjectClass *) klass; @@ -72,12 +179,26 @@ modest_identity_mgr_class_init (ModestIdentityMgrClass * klass) 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. */ + /* signal definitions */ + signals[IDENTITY_ADD_SIGNAL] = + g_signal_newv ("identity-add", + G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, + NULL, NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, paramtypes); + + signals[IDENTITY_REMOVE_SIGNAL] = + g_signal_newv ("identity-remove", + G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, + NULL, NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, paramtypes); + signals[IDENTITY_CHANGE_SIGNAL] = + g_signal_newv ("identity-change", + G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, + NULL, NULL, NULL, + modest_marshal_VOID__POINTER_POINTER_POINTER, + G_TYPE_NONE, 3, paramtypes); } @@ -116,6 +237,13 @@ modest_identity_mgr_new (ModestConf * conf) * ModestConf should outlive the ModestIdentityMgr though */ g_object_ref (G_OBJECT (priv->modest_conf = conf)); + + priv->current_identities = modest_identity_mgr_identity_names (MODEST_IDENTITY_MGR(obj), NULL); + + g_signal_connect(G_OBJECT(conf), + "key-changed", + G_CALLBACK (modest_identity_mgr_check_change), + obj); return obj; } @@ -155,12 +283,13 @@ null_means_empty (const gchar * str) gboolean modest_identity_mgr_add_identity (ModestIdentityMgr * self, - const gchar * name, - const gchar * email, - const gchar * replyto, - const gchar * signature, + const gchar * name, + const gchar * realname, + const gchar * email, + const gchar * replyto, + const gchar * signature, const gboolean use_signature, - const gchar * id_via, + const gchar * id_via, const gboolean use_id_via) { ModestIdentityMgrPrivate *priv; @@ -180,6 +309,12 @@ modest_identity_mgr_add_identity (ModestIdentityMgr * self, //return FALSE; } + /* realname */ + key = g_strconcat (id_key, "/", MODEST_IDENTITY_REALNAME, NULL); + modest_conf_set_string (priv->modest_conf, key, + null_means_empty (realname), NULL); + g_free (key); + /* email */ key = g_strconcat (id_key, "/", MODEST_IDENTITY_EMAIL, NULL); modest_conf_set_string (priv->modest_conf, key, @@ -203,16 +338,17 @@ modest_identity_mgr_add_identity (ModestIdentityMgr * self, modest_conf_set_bool (priv->modest_conf, key, use_signature, NULL); g_free (key); - /* signature */ + /* id_via */ 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 */ + /* use_id_via */ 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 */ @@ -317,14 +453,14 @@ modest_identity_mgr_get_identity_bool (ModestIdentityMgr * self, 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); + 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_get_int (priv->modest_conf, keyname, err); + retval = modest_conf_get_bool (priv->modest_conf, keyname, err); g_free (keyname); return retval; @@ -384,9 +520,9 @@ modest_identity_mgr_set_identity_int (ModestIdentityMgr * self, gboolean -modest_identy_mgr_set_identity_bool (ModestIdentityMgr * self, - const gchar * name, const gchar * key, - gboolean val, GError ** err) +modest_identity_mgr_set_identity_bool (ModestIdentityMgr * self, + const gchar * name, const gchar * key, + gboolean val, GError ** err) { ModestIdentityMgrPrivate *priv;