X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fmodest-account-mgr.c;h=4b097442e391638445df2148b0eec1dd62125ff8;hb=d9d3ab7c86ed86701f468ff8d1e1fac33b850431;hp=9196af6839098f4b4d18d54ac4f406f412b3d484;hpb=e427d3062be82355bdca744951d7fe01c39e55e6;p=modest diff --git a/src/modest-account-mgr.c b/src/modest-account-mgr.c index 9196af6..4b09744 100644 --- a/src/modest-account-mgr.c +++ b/src/modest-account-mgr.c @@ -3,6 +3,8 @@ /* insert (c)/licensing information) */ #include +#include "modest-marshal.h" +#include "modest-account-keys.h" #include "modest-account-mgr.h" /* 'private'/'protected' functions */ @@ -16,14 +18,16 @@ static gchar *get_server_account_keyname (const gchar * accname, /* list my signals */ enum { - /* MY_SIGNAL_1, */ - /* MY_SIGNAL_2, */ + ACCOUNT_CHANGE_SIGNAL, + ACCOUNT_REMOVE_SIGNAL, + ACCOUNT_ADD_SIGNAL, LAST_SIGNAL }; typedef struct _ModestAccountMgrPrivate ModestAccountMgrPrivate; struct _ModestAccountMgrPrivate { ModestConf *modest_conf; + GSList *current_accounts; }; #define MODEST_ACCOUNT_MGR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ @@ -32,15 +36,89 @@ struct _ModestAccountMgrPrivate { /* globals */ 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; +} + +/* Map configuration changes to account changes. + * Doing this here makes sure all changes are available and external changes + * are covered as well. */ static void modest_account_mgr_check_change (ModestConf *conf, const gchar *key, const gchar *new_value, gpointer user_data) { ModestAccountMgr *amgr = user_data; + ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (amgr); + if ((strlen (key) > strlen (MODEST_SERVER_ACCOUNT_NAMESPACE "/") + && g_str_has_prefix (key, MODEST_SERVER_ACCOUNT_NAMESPACE))) { + gchar *subkey = key + strlen (MODEST_SERVER_ACCOUNT_NAMESPACE "/"); + if (! strstr (subkey, "/")) {/* no more '/' means an account was modified */ + if (new_value) { + /* covers only one case of two */ + priv->current_accounts = + g_slist_prepend (priv->current_accounts, g_strdup (subkey)); + g_signal_emit (amgr, signals[ACCOUNT_ADD_SIGNAL], 0, subkey); + } else { + priv->current_accounts = + delete_account_from_list (priv->current_accounts, subkey); + + g_signal_emit (amgr, signals[ACCOUNT_REMOVE_SIGNAL], 0, subkey); + } + } else { + gchar *param; + + param = strstr (subkey, "/"); + param [0] = 0; + param++; + + /* that's the second case for a new account */ + if (!find_account_in_list (priv->current_accounts, subkey)) { + priv->current_accounts = + g_slist_prepend (priv->current_accounts, g_strdup (subkey)); + g_signal_emit (amgr, signals[ACCOUNT_ADD_SIGNAL], 0, subkey); + } + + g_signal_emit (amgr, signals[ACCOUNT_CHANGE_SIGNAL], 0, subkey, param, new_value); + } + } + g_message ("value changed: %s %s\n", key, new_value); } @@ -74,6 +152,7 @@ static void modest_account_mgr_class_init (ModestAccountMgrClass * klass) { GObjectClass *gobject_class; + GType paramtypes[3] = {G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER}; gobject_class = (GObjectClass *) klass; @@ -83,12 +162,26 @@ modest_account_mgr_class_init (ModestAccountMgrClass * klass) g_type_class_add_private (gobject_class, sizeof (ModestAccountMgrPrivate)); - /* 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[ACCOUNT_ADD_SIGNAL] = + g_signal_newv ("account-add", + G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, + NULL, NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, paramtypes); + + signals[ACCOUNT_REMOVE_SIGNAL] = + g_signal_newv ("account-remove", + G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, + NULL, NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, paramtypes); + signals[ACCOUNT_CHANGE_SIGNAL] = + g_signal_newv ("account-change", + G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, + NULL, NULL, NULL, + modest_marshal_VOID__POINTER_POINTER_POINTER, + G_TYPE_NONE, 3, paramtypes); } @@ -129,6 +222,8 @@ modest_account_mgr_new (ModestConf * conf) */ g_object_ref (G_OBJECT (priv->modest_conf = conf)); + priv->current_accounts = modest_account_mgr_account_names (MODEST_ACCOUNT_MGR(obj), NULL); + g_signal_connect (G_OBJECT (conf), "key-changed", G_CALLBACK (modest_account_mgr_check_change), obj); return obj;