From 32320a187c364c57585a45475acee9f6f9ce88c1 Mon Sep 17 00:00:00 2001 From: Silvan Marco Fin Date: Wed, 21 Jun 2006 16:22:46 +0000 Subject: [PATCH] * added better support for passwords - now get_password returns either the password from the corresponding account - or if triggered by the forget_password function emits the signal which leads to asking for a new password. * corrected some indentations / adopted coding style pmo-trunk-r307 --- src/gtk-glade/modest-ui.c | 22 +++---- src/modest-account-mgr.c | 54 ++++++++-------- src/modest-tny-account-store.c | 136 +++++++++++++++++++++++----------------- 3 files changed, 115 insertions(+), 97 deletions(-) diff --git a/src/gtk-glade/modest-ui.c b/src/gtk-glade/modest-ui.c index fbd0f61..6ec89e1 100644 --- a/src/gtk-glade/modest-ui.c +++ b/src/gtk-glade/modest-ui.c @@ -139,12 +139,12 @@ static void on_accounts_reloaded (ModestTnyAccountStore *account_store, gpointer user_data) { ModestUIPrivate *priv = user_data; - + g_return_if_fail (MODEST_IS_TNY_FOLDER_TREE_VIEW (priv->folder_view)); g_return_if_fail (MODEST_IS_TNY_HEADER_TREE_VIEW (priv->header_view)); - + modest_tny_header_tree_view_set_folder (priv->header_view, NULL); - + modest_tny_folder_tree_view_update_model(priv->folder_view, account_store); } @@ -236,13 +236,13 @@ modest_ui_last_window_closed (GObject *obj, gpointer data) static void on_password_requested (ModestTnyAccountStore *account_store, - const gchar *account_name, gpointer user_data) -{ + const gchar *account_name, + gpointer user_data) { GtkWidget *passdialog; GtkWidget *vbox; GtkWidget *infolabel; - GtkWidget *passentry; + GtkWidget *passentry; gint retval; const gchar *infostring = g_strconcat(_("Please enter the password for "), account_name, ".", NULL); @@ -267,18 +267,18 @@ on_password_requested (ModestTnyAccountStore *account_store, retval = gtk_dialog_run (GTK_DIALOG(passdialog)); switch (retval) { - case GTK_RESPONSE_ACCEPT: - modest_account_mgr_set_server_account_string(modest_tny_account_store_get_accout_mgr(account_store), + case GTK_RESPONSE_ACCEPT: + modest_account_mgr_set_server_account_string(modest_tny_account_store_get_accout_mgr(account_store), account_name, "password", gtk_entry_get_text(GTK_ENTRY(passentry)), NULL); - break; - case GTK_RESPONSE_CANCEL: + break; + case GTK_RESPONSE_CANCEL: /* FIXME: * What happens, if canceled?" */ - break; + break; } gtk_widget_destroy (passdialog); diff --git a/src/modest-account-mgr.c b/src/modest-account-mgr.c index 854fe87..4bbc96a 100644 --- a/src/modest-account-mgr.c +++ b/src/modest-account-mgr.c @@ -51,7 +51,7 @@ delete_account_from_list (GSList *list, const gchar *name) result = g_slist_delete_link (list, iter); break; } - + iter = g_slist_next (iter); } return result; @@ -69,52 +69,52 @@ find_account_in_list (GSList *list, const gchar *name) 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 + * 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, +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 "/") + + if ((strlen (key) > strlen (MODEST_SERVER_ACCOUNT_NAMESPACE "/") && g_str_has_prefix (key, MODEST_SERVER_ACCOUNT_NAMESPACE))) { gchar *subkey = g_strdup(key + strlen (MODEST_SERVER_ACCOUNT_NAMESPACE "/")); - + if (! strstr (subkey, "/")) { /* no more '/' means an account was modified */ if (!new_value) { - priv->current_accounts = + 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) && strstr (param, MODEST_ACCOUNT_PROTO)) { - priv->current_accounts = + 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_free (subkey); } } @@ -160,21 +160,21 @@ modest_account_mgr_class_init (ModestAccountMgrClass * klass) sizeof (ModestAccountMgrPrivate)); /* signal definitions */ - signals[ACCOUNT_ADD_SIGNAL] = - g_signal_newv ("account-add", + 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", + + 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", + 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, @@ -218,10 +218,10 @@ modest_account_mgr_new (ModestConf * conf) * ModestConf should outlive the ModestAccountMgr though */ 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_signal_connect (G_OBJECT (conf), "key-changed", G_CALLBACK (modest_account_mgr_check_change), obj); return obj; } @@ -488,8 +488,8 @@ modest_account_mgr_account_names (ModestAccountMgr * self, GError ** err) static gchar * get_account_string (ModestAccountMgr * self, const gchar * name, - const gchar * key, gboolean server_account, GError ** err) -{ + const gchar * key, gboolean server_account, GError ** err) { + ModestAccountMgrPrivate *priv; gchar *keyname; diff --git a/src/modest-tny-account-store.c b/src/modest-tny-account-store.c index 9579bd8..e9fba72 100644 --- a/src/modest-tny-account-store.c +++ b/src/modest-tny-account-store.c @@ -39,6 +39,12 @@ enum { LAST_SIGNAL }; +/* Password Status */ +enum { + PW_NOT_INVALID, + PW_INVALID, +}; + static const gchar *transport_protocols[] = { "smtp", NULL }; typedef struct _ModestTnyAccountStorePrivate ModestTnyAccountStorePrivate; @@ -53,7 +59,8 @@ struct _ModestTnyAccountStorePrivate { TnySessionCamel *tny_session_camel; TnyDeviceIface *device; - ModestAccountMgr *modest_acc_mgr; + ModestAccountMgr *modest_acc_mgr; + gint pw_invalid; }; #define MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ MODEST_TYPE_TNY_ACCOUNT_STORE, \ @@ -132,7 +139,9 @@ modest_tny_account_store_init (ModestTnyAccountStore *obj) priv->transport_accounts = NULL; priv->cache_dir = NULL; - priv->tny_session_camel = NULL; + priv->tny_session_camel = NULL; + /* Meaning: if not indicated otherwise, we have valid password data */ + priv->pw_invalid = PW_NOT_INVALID; } @@ -155,13 +164,15 @@ free_gobject_list (GList *list) } static gchar* -get_password (TnyAccountIface *account, const gchar *prompt, gboolean *cancel) -{ +get_password (TnyAccountIface *account, + const gchar *prompt, + gboolean *cancel) { + const gchar *key; const TnyAccountStoreIface *account_store; ModestTnyAccountStore *self; ModestTnyAccountStorePrivate *priv; - gchar *val; + gchar *retval; g_return_val_if_fail (account, NULL); @@ -171,24 +182,32 @@ get_password (TnyAccountIface *account, const gchar *prompt, gboolean *cancel) self = MODEST_TNY_ACCOUNT_STORE (account_store); priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self); - val = modest_account_mgr_get_server_account_string (priv->modest_acc_mgr, key, - MODEST_ACCOUNT_PASSWORD, NULL); - if (!val) { - /* FIXME: - * append the prompt to the emitted signal, - * so the password dialog shows the prompt supplied by the caller of this function. - */ - g_signal_emit (G_OBJECT(self), signals[PASSWORD_REQUESTED_SIGNAL], 0, key); - } - - return val; + if (priv->pw_invalid==PW_NOT_INVALID) { + retval = modest_account_mgr_get_server_account_string (priv->modest_acc_mgr, + key, + MODEST_ACCOUNT_PASSWORD, + NULL); + } else { + g_signal_emit(G_OBJECT(self), signals[PASSWORD_REQUESTED_SIGNAL], 0, key); + priv->pw_invalid=PW_NOT_INVALID; + retval=NULL; + } + return retval; } static void -forget_password (TnyAccountIface *account) -{ - g_warning (__FUNCTION__); +forget_password (TnyAccountIface *account) { + + ModestTnyAccountStore *self; + ModestTnyAccountStorePrivate *priv; + const TnyAccountStoreIface *account_store; + + account_store = tny_account_iface_get_account_store(account); + self = MODEST_TNY_ACCOUNT_STORE (account_store); + priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self); + + priv->pw_invalid=PW_INVALID; } @@ -222,7 +241,7 @@ tny_account_from_key (ModestTnyAccountStore *self, const gchar *key, /* id */ tny_account_iface_set_id (tny_account, key); tny_account_iface_set_name (tny_account, key); - + /* proto */ val = modest_account_mgr_get_server_account_string (priv->modest_acc_mgr, key, MODEST_ACCOUNT_PROTO, NULL); @@ -288,7 +307,7 @@ tny_accounts_from_server_accounts (ModestTnyAccountStore *self, GSList *accounts } -static void +static void manager_new_account (ModestAccountMgr *modest_acc_mgr, gchar *name, gpointer data) { ModestTnyAccountStore *self = data; @@ -297,17 +316,16 @@ manager_new_account (ModestAccountMgr *modest_acc_mgr, gchar *name, gpointer dat gchar *proto; gint i = 0; gboolean is_store = TRUE; - + g_print ("new account signal %s\n", name); - - + proto = modest_account_mgr_get_server_account_string (priv->modest_acc_mgr, name, MODEST_ACCOUNT_PROTO, NULL); if (!proto) { g_printerr ("Cannot add account: unknown type."); return; } - + while (transport_protocols [i]) { if (!strcmp (transport_protocols [i], proto)) { is_store = FALSE; @@ -315,14 +333,14 @@ manager_new_account (ModestAccountMgr *modest_acc_mgr, gchar *name, gpointer dat } i++; } - + /* fill account lists */ if (!priv->store_accounts) modest_tny_account_store_get_store_accounts (TNY_ACCOUNT_STORE_IFACE(self)); if (!priv->transport_accounts) modest_tny_account_store_get_transport_accounts (TNY_ACCOUNT_STORE_IFACE(self)); - + if (is_store) { new_account = tny_account_from_key (self, name, is_store); g_mutex_lock (priv->store_lock); @@ -334,35 +352,35 @@ manager_new_account (ModestAccountMgr *modest_acc_mgr, gchar *name, gpointer dat priv->transport_accounts = g_list_append (priv->transport_accounts, new_account); g_mutex_unlock (priv->transport_lock); } - g_signal_emit (self, + g_signal_emit (self, tny_account_store_iface_signals [TNY_ACCOUNT_STORE_IFACE_ACCOUNT_INSERTED], 0, new_account); } -static void +static void manager_remove_account (ModestAccountMgr *modest_acc_mgr, gchar *name, gpointer data) { g_print ("remove account signal %s\n", name); } -static void -manager_change_account (ModestAccountMgr *modest_acc_mgr, gchar *accountname, +static void +manager_change_account (ModestAccountMgr *modest_acc_mgr, gchar *accountname, gchar *key, gchar* value, gpointer data) { ModestTnyAccountStore *self = data; ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self); GList *iter; TnyAccountIface *account = NULL; - + g_print ("account change signal: account: %s key: %s value: %s\n", accountname, key, value); - + /* fill account lists */ if (!priv->store_accounts) modest_tny_account_store_get_store_accounts (TNY_ACCOUNT_STORE_IFACE(self)); if (!priv->transport_accounts) modest_tny_account_store_get_transport_accounts (TNY_ACCOUNT_STORE_IFACE(self)); - + for (iter = priv->store_accounts; iter; iter = iter->next) { TnyAccountIface *acc = iter->data; if (!strcmp (tny_account_iface_get_name (acc), accountname)) { @@ -370,7 +388,7 @@ manager_change_account (ModestAccountMgr *modest_acc_mgr, gchar *accountname, break; } } - + if (!account) for (iter = priv->transport_accounts; iter; iter = iter->next) { TnyAccountIface *acc = iter->data; @@ -379,23 +397,23 @@ manager_change_account (ModestAccountMgr *modest_acc_mgr, gchar *accountname, break; } } - + if (!account) { g_printerr ("Couldn't find account - returning without applying changes."); return; } - + g_mutex_lock (priv->store_lock); g_mutex_lock (priv->transport_lock); - + if (!strcmp (key, MODEST_ACCOUNT_HOSTNAME)) tny_account_iface_set_hostname (account, value); if (!strcmp (key, MODEST_ACCOUNT_USERNAME)) tny_account_iface_set_user (account, value); - + g_mutex_unlock (priv->transport_lock); g_mutex_unlock (priv->store_lock); - + /* TODO: handle protocol and password changes */ g_signal_emit (self, tny_account_store_iface_signals [TNY_ACCOUNT_STORE_IFACE_ACCOUNTS_RELOADED], 0); @@ -409,13 +427,13 @@ modest_tny_account_store_finalize (GObject *obj) ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self); - g_signal_handlers_disconnect_by_func (G_OBJECT (priv->modest_acc_mgr), + g_signal_handlers_disconnect_by_func (G_OBJECT (priv->modest_acc_mgr), G_CALLBACK(manager_new_account), NULL); - g_signal_handlers_disconnect_by_func (G_OBJECT (priv->modest_acc_mgr), + g_signal_handlers_disconnect_by_func (G_OBJECT (priv->modest_acc_mgr), G_CALLBACK(manager_remove_account), NULL); - g_signal_handlers_disconnect_by_func (G_OBJECT (priv->modest_acc_mgr), + g_signal_handlers_disconnect_by_func (G_OBJECT (priv->modest_acc_mgr), G_CALLBACK(manager_change_account), NULL); - + if (priv->modest_acc_mgr) { g_object_unref (G_OBJECT(priv->modest_acc_mgr)); priv->modest_acc_mgr = NULL; @@ -434,7 +452,7 @@ modest_tny_account_store_finalize (GObject *obj) g_mutex_lock (priv->store_lock); priv->store_accounts = free_gobject_list (priv->store_accounts); g_mutex_unlock (priv->store_lock); - + g_mutex_lock (priv->transport_lock); priv->transport_accounts = free_gobject_list (priv->store_accounts); g_mutex_unlock (priv->transport_lock); @@ -442,7 +460,7 @@ modest_tny_account_store_finalize (GObject *obj) g_mutex_free (priv->store_lock); g_mutex_free (priv->transport_lock); - + g_free (priv->cache_dir); priv->cache_dir = NULL; @@ -450,8 +468,8 @@ modest_tny_account_store_finalize (GObject *obj) GObject* -modest_tny_account_store_new (ModestAccountMgr *modest_acc_mgr) -{ +modest_tny_account_store_new (ModestAccountMgr *modest_acc_mgr) { + GObject *obj; ModestTnyAccountStorePrivate *priv; @@ -460,13 +478,13 @@ modest_tny_account_store_new (ModestAccountMgr *modest_acc_mgr) obj = G_OBJECT(g_object_new(MODEST_TYPE_TNY_ACCOUNT_STORE, NULL)); priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(obj); - + g_object_ref(G_OBJECT(modest_acc_mgr)); priv->modest_acc_mgr = modest_acc_mgr; - + priv->store_lock = g_mutex_new (); priv->transport_lock = g_mutex_new (); - + priv->device = (TnyDeviceIface*)tny_device_new(); if (!priv->device) { g_warning ("Cannot create Device instance"); @@ -480,12 +498,12 @@ modest_tny_account_store_new (ModestAccountMgr *modest_acc_mgr) g_object_unref (obj); return NULL; } - - g_signal_connect (G_OBJECT (modest_acc_mgr), "account-add", + + g_signal_connect (G_OBJECT (modest_acc_mgr), "account-add", G_CALLBACK(manager_new_account), obj); - g_signal_connect (G_OBJECT (modest_acc_mgr), "account-remove", + g_signal_connect (G_OBJECT (modest_acc_mgr), "account-remove", G_CALLBACK(manager_remove_account), obj); - g_signal_connect (G_OBJECT (modest_acc_mgr), "account-change", + g_signal_connect (G_OBJECT (modest_acc_mgr), "account-change", G_CALLBACK(manager_change_account), obj); return obj; @@ -493,8 +511,8 @@ modest_tny_account_store_new (ModestAccountMgr *modest_acc_mgr) static gboolean -add_account (TnyAccountStoreIface *self, TnyAccountIface *account) -{ +add_account (TnyAccountStoreIface *self, TnyAccountIface *account) { + TnyAccountIface *account_iface; ModestTnyAccountStore *account_store; ModestTnyAccountStorePrivate *priv; @@ -567,7 +585,7 @@ modest_tny_account_store_get_store_accounts (TnyAccountStoreIface *iface) priv->store_accounts = tny_accounts_from_server_accounts (self, accounts, TRUE); g_mutex_unlock (priv->store_lock); g_slist_free (accounts); - } + } return priv->store_accounts; } @@ -585,7 +603,7 @@ modest_tny_account_store_get_transport_accounts (TnyAccountStoreIface *iface) self = MODEST_TNY_ACCOUNT_STORE(iface); priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self); - + if (!priv->transport_accounts) { accounts = modest_account_mgr_server_account_names (priv->modest_acc_mgr, -- 1.7.9.5