[evolution-data-server/account-mgmt: 35/37] Adapt e-client-utils.c to the new ESource API.



commit e41e881f6d9c69f38e90b19f7449c5bfee190e90
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed May 25 21:17:41 2011 -0400

    Adapt e-client-utils.c to the new ESource API.

 .../libedataserverui/libedataserverui-sections.txt |    9 -
 .../libedataserverui/tmpl/e-client-utils.sgml      |   91 ---
 .../tmpl/libedataserverui-unused.sgml              |   84 +++
 libedataserverui/e-client-utils.c                  |  583 ++++++--------------
 libedataserverui/e-client-utils.h                  |   11 -
 5 files changed, 261 insertions(+), 517 deletions(-)
---
diff --git a/docs/reference/libedataserverui/libedataserverui-sections.txt b/docs/reference/libedataserverui/libedataserverui-sections.txt
index 22b40bd..a1f54f3 100644
--- a/docs/reference/libedataserverui/libedataserverui-sections.txt
+++ b/docs/reference/libedataserverui/libedataserverui-sections.txt
@@ -132,18 +132,9 @@ e_cell_renderer_color_get_type
 EClientSourceType
 EClientUtilsAuthenticateHandler
 e_client_utils_new
-e_client_utils_new_from_uri
-e_client_utils_new_system
-e_client_utils_new_default
-e_client_utils_set_default
-e_client_utils_set_default_source
-e_client_utils_get_sources
 e_client_utils_open_new
 e_client_utils_open_new_finish
 e_client_utils_authenticate_handler
-e_client_utils_forget_password
-e_credentials_authenticate_helper
-e_credentials_forget_password
 </SECTION>
 
 <SECTION>
diff --git a/docs/reference/libedataserverui/tmpl/e-client-utils.sgml b/docs/reference/libedataserverui/tmpl/e-client-utils.sgml
index 5d6c50e..5b8c392 100644
--- a/docs/reference/libedataserverui/tmpl/e-client-utils.sgml
+++ b/docs/reference/libedataserverui/tmpl/e-client-utils.sgml
@@ -53,70 +53,6 @@ EClient Utilities
 @Returns: 
 
 
-<!-- ##### FUNCTION e_client_utils_new_from_uri ##### -->
-<para>
-
-</para>
-
- uri: 
- source_type: 
- error: 
- Returns: 
-
-
-<!-- ##### FUNCTION e_client_utils_new_system ##### -->
-<para>
-
-</para>
-
- source_type: 
- error: 
- Returns: 
-
-
-<!-- ##### FUNCTION e_client_utils_new_default ##### -->
-<para>
-
-</para>
-
- source_type: 
- error: 
- Returns: 
-
-
-<!-- ##### FUNCTION e_client_utils_set_default ##### -->
-<para>
-
-</para>
-
- client: 
- source_type: 
- error: 
- Returns: 
-
-
-<!-- ##### FUNCTION e_client_utils_set_default_source ##### -->
-<para>
-
-</para>
-
- source: 
- source_type: 
- error: 
- Returns: 
-
-
-<!-- ##### FUNCTION e_client_utils_get_sources ##### -->
-<para>
-
-</para>
-
- sources: 
- source_type: 
- error: 
- Returns: 
-
-
 <!-- ##### FUNCTION e_client_utils_open_new ##### -->
 <para>
 
@@ -155,30 +91,3 @@ EClient Utilities
 @Returns: 
 
 
-<!-- ##### FUNCTION e_client_utils_forget_password ##### -->
-<para>
-
-</para>
-
- client: 
-
-
-<!-- ##### FUNCTION e_credentials_authenticate_helper ##### -->
-<para>
-
-</para>
-
- credentials: 
- parent: 
- remember_password: 
- Returns: 
-
-
-<!-- ##### FUNCTION e_credentials_forget_password ##### -->
-<para>
-
-</para>
-
- credentials: 
-
-
diff --git a/docs/reference/libedataserverui/tmpl/libedataserverui-unused.sgml b/docs/reference/libedataserverui/tmpl/libedataserverui-unused.sgml
index d82fc52..7d9da9b 100644
--- a/docs/reference/libedataserverui/tmpl/libedataserverui-unused.sgml
+++ b/docs/reference/libedataserverui/tmpl/libedataserverui-unused.sgml
@@ -94,6 +94,71 @@ ESourceOptionMenu
 </para>
 
 
+<!-- ##### FUNCTION e_client_utils_forget_password ##### -->
+<para>
+
+</para>
+
+ client: 
+
+<!-- ##### FUNCTION e_client_utils_get_sources ##### -->
+<para>
+
+</para>
+
+ sources: 
+ source_type: 
+ error: 
+ Returns: 
+
+<!-- ##### FUNCTION e_client_utils_new_default ##### -->
+<para>
+
+</para>
+
+ source_type: 
+ error: 
+ Returns: 
+
+<!-- ##### FUNCTION e_client_utils_new_from_uri ##### -->
+<para>
+
+</para>
+
+ uri: 
+ source_type: 
+ error: 
+ Returns: 
+
+<!-- ##### FUNCTION e_client_utils_new_system ##### -->
+<para>
+
+</para>
+
+ source_type: 
+ error: 
+ Returns: 
+
+<!-- ##### FUNCTION e_client_utils_set_default ##### -->
+<para>
+
+</para>
+
+ client: 
+ source_type: 
+ error: 
+ Returns: 
+
+<!-- ##### FUNCTION e_client_utils_set_default_source ##### -->
+<para>
+
+</para>
+
+ source: 
+ source_type: 
+ error: 
+ Returns: 
+
 <!-- ##### FUNCTION e_contact_store_add_book ##### -->
 <para>
 
@@ -127,6 +192,23 @@ ESourceOptionMenu
 @contact_store: 
 @book: 
 
+<!-- ##### FUNCTION e_credentials_authenticate_helper ##### -->
+<para>
+
+</para>
+
+ credentials: 
+ parent: 
+ remember_password: 
+ Returns: 
+
+<!-- ##### FUNCTION e_credentials_forget_password ##### -->
+<para>
+
+</para>
+
+ credentials: 
+
 <!-- ##### FUNCTION e_data_server_ui_marshal_BOOLEAN__BOXED_OBJECT_FLAGS_UINT ##### -->
 <para>
 
@@ -227,6 +309,8 @@ ESourceOptionMenu
 @source: 
 
 <!-- ##### FUNCTION find_contact_source_by_book_return_view ##### -->
+
+
 @contact_store: 
 @book: 
 @Returns: 
diff --git a/libedataserverui/e-client-utils.c b/libedataserverui/e-client-utils.c
index 948bc17..3e0b5f4 100644
--- a/libedataserverui/e-client-utils.c
+++ b/libedataserverui/e-client-utils.c
@@ -28,261 +28,128 @@
 #include <libsoup/soup.h>
 
 #include <libedataserver/e-client.h>
-#include "libedataserver/e-client-private.h"
+#include <libedataserver/e-source-authentication.h>
+#include <libedataserver/e-source-password.h>
 #include <libebook/e-book-client.h>
 #include <libecal/e-cal-client.h>
 
+#include "libedataserver/e-client-private.h"
+
 #include "e-passwords.h"
 #include "e-client-utils.h"
 
-/**
- * e_client_utils_new:
- *
- * Proxy function for e_book_client_utils_new() and e_cal_client_utils_new().
- *
- * Since: 3.2
- **/
-EClient	*
-e_client_utils_new (ESource *source,
-                    EClientSourceType source_type,
-                    GError **error)
+static struct _PromptFlags {
+	EPasswordsRememberType flag_uint;
+	const gchar *flag_string;
+	gboolean is_bit_flag; /* if false, then checked against E_PASSWORDS_REMEMBER_MASK */
+} PromptFlags[] = {
+	{ E_PASSWORDS_REMEMBER_NEVER,	"remember-never",	FALSE },
+	{ E_PASSWORDS_REMEMBER_SESSION,	"remember-session",	FALSE },
+	{ E_PASSWORDS_REMEMBER_FOREVER,	"remember-forever",	FALSE },
+
+	{ E_PASSWORDS_SECRET,		"secret",		TRUE },
+	{ E_PASSWORDS_REPROMPT,		"reprompt",		TRUE },
+	{ E_PASSWORDS_ONLINE,		"online",		TRUE },
+	{ E_PASSWORDS_DISABLE_REMEMBER,	"disable-remember",	TRUE },
+	{ E_PASSWORDS_PASSPHRASE,		"passphrase",		TRUE }
+};
+
+/* Returned pointer can be passed to e_credentials_util_string_to prompt_flags()
+   to decode it back to flags. Free returned pointer with g_free ().
+*/
+static gchar *
+prompt_flags_to_string (guint prompt_flags)
 {
-	EClient *res = NULL;
-
-	g_return_val_if_fail (source != NULL, NULL);
-	g_return_val_if_fail (E_IS_SOURCE (source), NULL);
-
-	switch (source_type) {
-	case E_CLIENT_SOURCE_TYPE_CONTACTS:
-		res = E_CLIENT (e_book_client_new (source, error));
-		break;
-	case E_CLIENT_SOURCE_TYPE_EVENTS:
-		res = E_CLIENT (e_cal_client_new (source, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, error));
-		break;
-	case E_CLIENT_SOURCE_TYPE_MEMOS:
-		res = E_CLIENT (e_cal_client_new (source, E_CAL_CLIENT_SOURCE_TYPE_MEMOS, error));
-		break;
-	case E_CLIENT_SOURCE_TYPE_TASKS:
-		res = E_CLIENT (e_cal_client_new (source, E_CAL_CLIENT_SOURCE_TYPE_TASKS, error));
-		break;
-	default:
-		g_return_val_if_reached (NULL);
-		break;
-	}
-
-	return res;
-}
+	gint ii;
+	guint masked = prompt_flags & E_PASSWORDS_REMEMBER_MASK;
+	GString *str = g_string_new ("");
+
+	for (ii = 0; ii < G_N_ELEMENTS (PromptFlags); ii++) {
+		const gchar *add = NULL;
+
+		if (PromptFlags[ii].is_bit_flag) {
+			if ((prompt_flags & PromptFlags[ii].flag_uint) != 0)
+				add = PromptFlags[ii].flag_string;
+		} else if (masked == PromptFlags[ii].flag_uint) {
+			add = PromptFlags[ii].flag_string;
+		}
 
-/**
- * e_client_utils_new_from_uri:
- *
- * Proxy function for e_book_client_utils_new_from_uri() and e_cal_client_utils_new_from_uri().
- *
- * Since: 3.2
- **/
-EClient *
-e_client_utils_new_from_uri (const gchar *uri,
-                             EClientSourceType source_type,
-                             GError **error)
-{
-	EClient *res = NULL;
+		if (!add)
+			continue;
 
-	g_return_val_if_fail (uri != NULL, NULL);
+		if (str->len)
+			g_string_append (str, ",");
 
-	switch (source_type) {
-	case E_CLIENT_SOURCE_TYPE_CONTACTS:
-		res = E_CLIENT (e_book_client_new_from_uri (uri, error));
-		break;
-	case E_CLIENT_SOURCE_TYPE_EVENTS:
-		res = E_CLIENT (e_cal_client_new_from_uri (uri, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, error));
-		break;
-	case E_CLIENT_SOURCE_TYPE_MEMOS:
-		res = E_CLIENT (e_cal_client_new_from_uri (uri, E_CAL_CLIENT_SOURCE_TYPE_MEMOS, error));
-		break;
-	case E_CLIENT_SOURCE_TYPE_TASKS:
-		res = E_CLIENT (e_cal_client_new_from_uri (uri, E_CAL_CLIENT_SOURCE_TYPE_TASKS, error));
-		break;
-	default:
-		g_return_val_if_reached (NULL);
-		break;
+		g_string_append (str, add);
 	}
 
-	return res;
+	return g_string_free (str, FALSE);
 }
 
-/**
- * e_client_utils_new_system:
- *
- * Proxy function for e_book_client_utils_new_system() and e_cal_client_utils_new_system().
- *
- * Since: 3.2
- **/
-EClient *
-e_client_utils_new_system (EClientSourceType source_type,
-                           GError **error)
+static guint
+string_to_prompt_flags (const gchar *prompt_flags_string)
 {
-	EClient *res = NULL;
+	gchar **strv;
+	gint ii, jj;
+	guint flags = 0;
 
-	switch (source_type) {
-	case E_CLIENT_SOURCE_TYPE_CONTACTS:
-		res = E_CLIENT (e_book_client_new_system (error));
-		break;
-	case E_CLIENT_SOURCE_TYPE_EVENTS:
-		res = E_CLIENT (e_cal_client_new_system (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, error));
-		break;
-	case E_CLIENT_SOURCE_TYPE_MEMOS:
-		res = E_CLIENT (e_cal_client_new_system (E_CAL_CLIENT_SOURCE_TYPE_MEMOS, error));
-		break;
-	case E_CLIENT_SOURCE_TYPE_TASKS:
-		res = E_CLIENT (e_cal_client_new_system (E_CAL_CLIENT_SOURCE_TYPE_TASKS, error));
-		break;
-	default:
-		g_return_val_if_reached (NULL);
-		break;
-	}
+	if (!prompt_flags_string || !*prompt_flags_string)
+		return flags;
 
-	return res;
-}
+	strv = g_strsplit (prompt_flags_string, ",", -1);
+	if (!strv)
+		return flags;
 
-/**
- * e_client_utils_new_default:
- *
- * Proxy function for e_book_client_utils_new_default() and e_cal_client_utils_new_default().
- *
- * Since: 3.2
- **/
-EClient *
-e_client_utils_new_default (EClientSourceType source_type,
-                            GError **error)
-{
-	EClient *res = NULL;
+	for (jj = 0; strv[jj]; jj++) {
+		const gchar *str = strv[jj];
 
-	switch (source_type) {
-	case E_CLIENT_SOURCE_TYPE_CONTACTS:
-		res = E_CLIENT (e_book_client_new_default (error));
-		break;
-	case E_CLIENT_SOURCE_TYPE_EVENTS:
-		res = E_CLIENT (e_cal_client_new_default (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, error));
-		break;
-	case E_CLIENT_SOURCE_TYPE_MEMOS:
-		res = E_CLIENT (e_cal_client_new_default (E_CAL_CLIENT_SOURCE_TYPE_MEMOS, error));
-		break;
-	case E_CLIENT_SOURCE_TYPE_TASKS:
-		res = E_CLIENT (e_cal_client_new_default (E_CAL_CLIENT_SOURCE_TYPE_TASKS, error));
-		break;
-	default:
-		g_return_val_if_reached (NULL);
-		break;
+		for (ii = 0; ii < G_N_ELEMENTS (PromptFlags); ii++) {
+			if (g_str_equal (PromptFlags[ii].flag_string, str)) {
+				if (PromptFlags[ii].is_bit_flag)
+					flags |= PromptFlags[ii].flag_uint;
+				else
+					flags = (flags & (~E_PASSWORDS_REMEMBER_MASK)) | PromptFlags[ii].flag_uint;
+			}
+		}
 	}
 
-	return res;
-}
-
-/**
- * e_client_utils_set_default:
- *
- * Proxy function for e_book_client_utils_set_default() and e_book_client_utils_set_default().
- *
- * Since: 3.2
- **/
-gboolean
-e_client_utils_set_default (EClient *client,
-                            EClientSourceType source_type,
-                            GError **error)
-{
-	gboolean res = FALSE;
-
-	g_return_val_if_fail (client != NULL, FALSE);
-	g_return_val_if_fail (E_IS_CLIENT (client), FALSE);
+	g_strfreev (strv);
 
-	switch (source_type) {
-	case E_CLIENT_SOURCE_TYPE_CONTACTS:
-		g_return_val_if_fail (E_IS_BOOK_CLIENT (client), FALSE);
-		res = e_book_client_set_default (E_BOOK_CLIENT (client), error);
-		break;
-	case E_CLIENT_SOURCE_TYPE_EVENTS:
-	case E_CLIENT_SOURCE_TYPE_MEMOS:
-	case E_CLIENT_SOURCE_TYPE_TASKS:
-		g_return_val_if_fail (E_IS_CAL_CLIENT (client), FALSE);
-		res = e_cal_client_set_default (E_CAL_CLIENT (client), error);
-		break;
-	default:
-		g_return_val_if_reached (FALSE);
-		break;
-	}
-
-	return res;
+	return flags;
 }
 
 /**
- * e_client_utils_set_default_source:
- *
- * Proxy function for e_book_client_utils_set_default_source() and e_cal_client_utils_set_default_source().
- *
- * Since: 3.2
- **/
-gboolean
-e_client_utils_set_default_source (ESource *source,
-                                   EClientSourceType source_type,
-                                   GError **error)
-{
-	gboolean res = FALSE;
-
-	g_return_val_if_fail (source != NULL, FALSE);
-	g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
-
-	switch (source_type) {
-	case E_CLIENT_SOURCE_TYPE_CONTACTS:
-		res = e_book_client_set_default_source (source, error);
-		break;
-	case E_CLIENT_SOURCE_TYPE_EVENTS:
-		res = e_cal_client_set_default_source (source, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, error);
-		break;
-	case E_CLIENT_SOURCE_TYPE_MEMOS:
-		res = e_cal_client_set_default_source (source, E_CAL_CLIENT_SOURCE_TYPE_MEMOS, error);
-		break;
-	case E_CLIENT_SOURCE_TYPE_TASKS:
-		res = e_cal_client_set_default_source (source, E_CAL_CLIENT_SOURCE_TYPE_TASKS, error);
-		break;
-	default:
-		g_return_val_if_reached (FALSE);
-		break;
-	}
-
-	return res;
-}
-
-/**
- * e_client_utils_get_sources:
+ * e_client_utils_new:
  *
- * Proxy function for e_book_client_utils_get_sources() and e_cal_client_utils_get_sources().
+ * Proxy function for e_book_client_utils_new() and e_cal_client_utils_new().
  *
  * Since: 3.2
  **/
-gboolean
-e_client_utils_get_sources (ESourceList **sources,
-                            EClientSourceType source_type,
-                            GError **error)
+EClient	*
+e_client_utils_new (ESource *source,
+                    EClientSourceType source_type,
+                    GError **error)
 {
-	gboolean res = FALSE;
+	EClient *res = NULL;
 
-	g_return_val_if_fail (sources != NULL, FALSE);
+	g_return_val_if_fail (source != NULL, NULL);
+	g_return_val_if_fail (E_IS_SOURCE (source), NULL);
 
 	switch (source_type) {
 	case E_CLIENT_SOURCE_TYPE_CONTACTS:
-		res = e_book_client_get_sources (sources, error);
+		res = E_CLIENT (e_book_client_new (source, error));
 		break;
 	case E_CLIENT_SOURCE_TYPE_EVENTS:
-		res = e_cal_client_get_sources (sources, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, error);
+		res = E_CLIENT (e_cal_client_new (source, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, error));
 		break;
 	case E_CLIENT_SOURCE_TYPE_MEMOS:
-		res = e_cal_client_get_sources (sources, E_CAL_CLIENT_SOURCE_TYPE_MEMOS, error);
+		res = E_CLIENT (e_cal_client_new (source, E_CAL_CLIENT_SOURCE_TYPE_MEMOS, error));
 		break;
 	case E_CLIENT_SOURCE_TYPE_TASKS:
-		res = e_cal_client_get_sources (sources, E_CAL_CLIENT_SOURCE_TYPE_TASKS, error);
+		res = E_CLIENT (e_cal_client_new (source, E_CAL_CLIENT_SOURCE_TYPE_TASKS, error));
 		break;
 	default:
-		g_return_val_if_reached (FALSE);
+		g_return_val_if_reached (NULL);
 		break;
 	}
 
@@ -488,13 +355,9 @@ finish_or_retry_open (EClientUtilsAsyncOpData *async_data,
 
 	if (async_data->auth_handler && error && g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_AUTHENTICATION_FAILED)) {
 		if (async_data->used_credentials) {
-			const gchar *prompt_key;
-
-			prompt_key = e_credentials_peek (async_data->used_credentials, E_CREDENTIALS_KEY_PROMPT_KEY);
-
 			/* make sure the old password is forgotten when authentication failed */
-			if (prompt_key)
-				e_passwords_forget_password (NULL, prompt_key);
+			e_source_password_delete_sync (
+				async_data->source, NULL, NULL);
 
 			e_credentials_set (async_data->used_credentials, E_CREDENTIALS_KEY_PROMPT_REASON, error->message);
 		}
@@ -618,17 +481,17 @@ client_utils_open_new_auth_cb (EClient *client,
 
 			prompt_flags_str = e_credentials_get (credentials, E_CREDENTIALS_KEY_PROMPT_FLAGS);
 			if (prompt_flags_str) {
-				prompt_flags = e_credentials_util_string_to_prompt_flags (prompt_flags_str);
+				prompt_flags = string_to_prompt_flags (prompt_flags_str);
 				g_free (prompt_flags_str);
 			} else {
-				prompt_flags = E_CREDENTIALS_PROMPT_FLAG_REMEMBER_FOREVER
-					     | E_CREDENTIALS_PROMPT_FLAG_SECRET
-					     | E_CREDENTIALS_PROMPT_FLAG_ONLINE;
+				prompt_flags = E_PASSWORDS_REMEMBER_FOREVER
+					     | E_PASSWORDS_SECRET
+					     | E_PASSWORDS_ONLINE;
 			}
 
-			prompt_flags |= E_CREDENTIALS_PROMPT_FLAG_REPROMPT;
+			prompt_flags |= E_PASSWORDS_REPROMPT;
 
-			prompt_flags_str = e_credentials_util_prompt_flags_to_string (prompt_flags);
+			prompt_flags_str = prompt_flags_to_string (prompt_flags);
 			e_credentials_set (credentials, E_CREDENTIALS_KEY_PROMPT_FLAGS, prompt_flags_str);
 			g_free (prompt_flags_str);
 		}
@@ -751,27 +614,80 @@ e_client_utils_open_new_finish (ESource *source,
 	return *client != NULL;
 }
 
-/* free returned pointer with g_free() */
-static gchar *
-get_prompt_key (EClient *client,
-                const gchar *user_name)
+/* Asks for a password based on the provided credentials information.
+ * Credentials should have set following keys:
+ *    E_CREDENTIALS_KEY_PROMPT_TEXT
+ * all other keys are optional. If also E_CREDENTIALS_KEY_PASSWORD key is provided,
+ * then it implies a reprompt.
+ *
+ * When this returns TRUE, then the structure contains E_CREDENTIALS_KEY_PASSWORD set
+ * as entered by a user.
+ */
+static gboolean
+credentials_authenticate_helper (ESource *source,
+                                 ECredentials *credentials,
+                                 GtkWindow *parent,
+                                 gboolean *remember_password)
 {
-	SoupURI *suri;
-	gchar *uri_str;
+	gboolean fake_remember_password = FALSE;
+	guint prompt_flags;
+	gboolean success = FALSE;
 
-	g_return_val_if_fail (client != NULL, NULL);
+	g_return_val_if_fail (credentials != NULL, FALSE);
+	g_return_val_if_fail (e_credentials_has_key (credentials, E_CREDENTIALS_KEY_PROMPT_TEXT), FALSE);
 
-	suri = soup_uri_new (e_client_get_uri (client));
-	g_return_val_if_fail (suri != NULL, NULL);
+	if (e_credentials_has_key (credentials, E_CREDENTIALS_KEY_PROMPT_FLAGS)) {
+		prompt_flags = string_to_prompt_flags (e_credentials_peek (credentials, E_CREDENTIALS_KEY_PROMPT_FLAGS));
+	} else {
+		prompt_flags = E_PASSWORDS_REMEMBER_FOREVER
+			     | E_PASSWORDS_SECRET
+			     | E_PASSWORDS_ONLINE;
+	}
 
-	soup_uri_set_user (suri, user_name);
-	soup_uri_set_password (suri, NULL);
-	soup_uri_set_fragment (suri, NULL);
+	if (!remember_password) {
+		prompt_flags |= E_PASSWORDS_DISABLE_REMEMBER;
+		remember_password = &fake_remember_password;
+	}
 
-	uri_str = soup_uri_to_string (suri, FALSE);
-	soup_uri_free (suri);
+	if (e_credentials_has_key (credentials, E_CREDENTIALS_KEY_PASSWORD))
+		prompt_flags |= E_PASSWORDS_REPROMPT;
+
+	if (!(prompt_flags & E_PASSWORDS_REPROMPT)) {
+		gchar *password = NULL;
+
+		success = e_source_password_lookup_sync (
+			source, NULL, &password, NULL);
+		if (success) {
+			e_credentials_set (
+				credentials,
+				E_CREDENTIALS_KEY_PASSWORD,
+				password);
+			e_source_password_free (password);
+		}
+	}
 
-	return uri_str;
+	if (!success) {
+		gchar *password;
+		const gchar *prompt;
+
+		prompt = e_credentials_peek (
+			credentials, E_CREDENTIALS_KEY_PROMPT_TEXT);
+		password = e_passwords_ask_password (
+			source, "", prompt,
+			prompt_flags, remember_password, parent);
+		if (password != NULL) {
+			e_credentials_set (
+				credentials,
+				E_CREDENTIALS_KEY_PASSWORD,
+				password);
+			e_credentials_util_safe_free_string (password);
+			success = TRUE;
+		}
+	}
+
+	e_credentials_clear_peek (credentials);
+
+	return success;
 }
 
 /**
@@ -793,8 +709,11 @@ e_client_utils_authenticate_handler (EClient *client,
                                      gpointer gtk_window_parent)
 {
 	ESource *source;
-	gboolean is_book, is_cal, res, remember_password = FALSE;
-	const gchar *prop;
+	gboolean is_book, is_cal, res, remember_password;
+	ESourceAuthentication *auth_extension;
+	const gchar *extension_name;
+	const gchar *display_name;
+	const gchar *user;
 
 	g_return_val_if_fail (client != NULL, FALSE);
 	g_return_val_if_fail (credentials != NULL, FALSE);
@@ -805,47 +724,19 @@ e_client_utils_authenticate_handler (EClient *client,
 
 	source = e_client_get_source (client);
 	g_return_val_if_fail (source != NULL, FALSE);
+	display_name = e_source_get_display_name (source);
 
-	if (!e_credentials_has_key (credentials, E_CREDENTIALS_KEY_USERNAME)) {
-		const gchar *username;
-
-		username = e_source_get_property (source, "username");
-		if (!username) {
-			const gchar *auth;
-
-			auth = e_source_get_property (source, "auth");
-			if (g_strcmp0 (auth, "ldap/simple-binddn") == 0)
-				username = e_source_get_property (source, "binddn");
-			else
-				username = e_source_get_property (source, "email_addr");
-
-			if (!username)
-				username = "";
-		}
-
-		e_credentials_set (credentials, E_CREDENTIALS_KEY_USERNAME, username);
-
-		/* no username set on the source - deny authentication request until
-		 * username will be also enterable with e-passwords */
-		if (!e_credentials_has_key (credentials, E_CREDENTIALS_KEY_USERNAME))
-			return FALSE;
-	}
-
-	if (!e_credentials_has_key (credentials, E_CREDENTIALS_KEY_PROMPT_KEY)) {
-		gchar *prompt_key = get_prompt_key (client, e_credentials_peek (credentials, E_CREDENTIALS_KEY_USERNAME));
-
-		e_credentials_set (credentials, E_CREDENTIALS_KEY_PROMPT_KEY, prompt_key);
-
-		g_free (prompt_key);
-	}
+	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
+	auth_extension = e_source_get_extension (source, extension_name);
+	user = e_source_authentication_get_user (auth_extension);
 
 	if (!e_credentials_has_key (credentials, E_CREDENTIALS_KEY_PROMPT_TEXT)) {
 		gchar *prompt, *reason;
 		gchar *username_markup, *source_name_markup;
 
 		reason = e_credentials_get (credentials, E_CREDENTIALS_KEY_PROMPT_REASON);
-		username_markup = g_markup_printf_escaped ("<b>%s</b>", e_credentials_peek (credentials, E_CREDENTIALS_KEY_USERNAME));
-		source_name_markup = g_markup_printf_escaped ("<b>%s</b>", e_source_peek_name (source));
+		username_markup = g_markup_printf_escaped ("<b>%s</b>", user);
+		source_name_markup = g_markup_printf_escaped ("<b>%s</b>", display_name);
 
 		if (is_cal) {
 			switch (e_cal_client_get_source_type (E_CAL_CLIENT (client))) {
@@ -888,141 +779,21 @@ e_client_utils_authenticate_handler (EClient *client,
 		g_free (prompt);
 	}
 
-	prop = e_source_get_property (source, "remember_password");
-	remember_password = !prop || g_strcmp0 (prop, "true") == 0;
+	remember_password =
+		e_source_authentication_get_remember_password (auth_extension);
 
-	res = e_credentials_authenticate_helper (credentials, gtk_window_parent, &remember_password);
+	res = credentials_authenticate_helper (
+		source, credentials, gtk_window_parent, &remember_password);
 
-	if (res)
-		e_source_set_property (source, "remember_password", remember_password ? "true" : "false");
-
-	e_credentials_clear_peek (credentials);
-
-	return res;
-}
-
-/**
- * e_client_utils_forget_password:
- * @client: An #EClient
- *
- * Forgets stored password for the given @client.
- *
- * Since: 3.2
- **/
-void
-e_client_utils_forget_password (EClient *client)
-{
-	gchar *prompt_key;
-	ESource *source;
-
-	g_return_if_fail (client != NULL);
-	g_return_if_fail (E_IS_CLIENT (client));
-
-	source = e_client_get_source (client);
-	g_return_if_fail (source != NULL);
-
-	prompt_key = get_prompt_key (client, e_source_get_property (source, "username"));
-
-	e_passwords_forget_password (NULL, prompt_key);
-
-	g_free (prompt_key);
-}
-
-/** 
- * e_credentials_authenticate_helper:
- *
- * Asks for a password based on the provided credentials information.
- * Credentials should have set following keys:
- *    E_CREDENTIALS_KEY_USERNAME
- *    E_CREDENTIALS_KEY_PROMPT_KEY
- *    E_CREDENTIALS_KEY_PROMPT_TEXT
- * all other keys are optional. If also E_CREDENTIALS_KEY_PASSWORD key is provided,
- * then it implies a reprompt.
- *
- * When this returns TRUE, then the structure contains E_CREDENTIALS_KEY_PASSWORD set
- * as entered by a user.
- *
- * Since: 3.2
- **/
-gboolean
-e_credentials_authenticate_helper (ECredentials *credentials,
-                                   GtkWindow *parent,
-                                   gboolean *remember_password)
-{
-	gboolean res, fake_remember_password = FALSE;
-	guint prompt_flags;
-	gchar *password = NULL;
-	const gchar *title, *prompt_key;
-
-	g_return_val_if_fail (credentials != NULL, FALSE);
-	g_return_val_if_fail (e_credentials_has_key (credentials, E_CREDENTIALS_KEY_USERNAME), FALSE);
-	g_return_val_if_fail (e_credentials_has_key (credentials, E_CREDENTIALS_KEY_PROMPT_KEY), FALSE);
-	g_return_val_if_fail (e_credentials_has_key (credentials, E_CREDENTIALS_KEY_PROMPT_TEXT), FALSE);
-
-	if (e_credentials_has_key (credentials, E_CREDENTIALS_KEY_PROMPT_FLAGS)) {
-		prompt_flags = e_credentials_util_string_to_prompt_flags (e_credentials_peek (credentials, E_CREDENTIALS_KEY_PROMPT_FLAGS));
-	} else {
-		prompt_flags = E_CREDENTIALS_PROMPT_FLAG_REMEMBER_FOREVER
-			     | E_CREDENTIALS_PROMPT_FLAG_SECRET
-			     | E_CREDENTIALS_PROMPT_FLAG_ONLINE;
+	if (res) {
+		e_source_authentication_set_remember_password (
+			auth_extension, remember_password);
+#if 0  /* ACCOUNT_MGMT */
+		e_source_sync (source, NULL);
+#endif /* ACCOUNT_MGMT */
 	}
 
-	if (!remember_password) {
-		prompt_flags |= E_CREDENTIALS_PROMPT_FLAG_DISABLE_REMEMBER;
-		remember_password = &fake_remember_password;
-	}
-
-	if (e_credentials_has_key (credentials, E_CREDENTIALS_KEY_PASSWORD))
-		prompt_flags |= E_CREDENTIALS_PROMPT_FLAG_REPROMPT;
-
-	if (e_credentials_has_key (credentials, E_CREDENTIALS_KEY_PROMPT_TITLE))
-		title = e_credentials_peek (credentials, E_CREDENTIALS_KEY_PROMPT_TITLE);
-	else if (prompt_flags & E_CREDENTIALS_PROMPT_FLAG_PASSPHRASE)
-		title = _("Enter Passphrase");
-	else
-		title = _("Enter Password");
-
-	prompt_key = e_credentials_peek (credentials, E_CREDENTIALS_KEY_PROMPT_KEY);
-
-	if (!(prompt_flags & E_CREDENTIALS_PROMPT_FLAG_REPROMPT))
-		password = e_passwords_get_password (NULL, prompt_key);
-
-	if (!password)
-		password = e_passwords_ask_password (title, NULL, prompt_key,
-				e_credentials_peek (credentials, E_CREDENTIALS_KEY_PROMPT_TEXT),
-				prompt_flags, remember_password, parent);
-
-	res = password != NULL;
-
-	if (res)
-		e_credentials_set (credentials, E_CREDENTIALS_KEY_PASSWORD, password);
-
-	e_credentials_util_safe_free_string (password);
 	e_credentials_clear_peek (credentials);
 
 	return res;
 }
-
-/**
- * e_credentials_forget_password:
- * @credentials: an #ECredentials
- *
- * Forgets stored password for given @credentials, which should contain
- * E_CREDENTIALS_KEY_PROMPT_KEY.
- *
- * Since: 3.2
- **/
-void
-e_credentials_forget_password (const ECredentials *credentials)
-{
-	gchar *prompt_key;
-
-	g_return_if_fail (credentials != NULL);
-	g_return_if_fail (e_credentials_has_key (credentials, E_CREDENTIALS_KEY_PROMPT_KEY));
-
-	prompt_key = e_credentials_get (credentials, E_CREDENTIALS_KEY_PROMPT_KEY);
-
-	e_passwords_forget_password (NULL, prompt_key);
-
-	g_free (prompt_key);
-}
diff --git a/libedataserverui/e-client-utils.h b/libedataserverui/e-client-utils.h
index 1582a03..3a0205b 100644
--- a/libedataserverui/e-client-utils.h
+++ b/libedataserverui/e-client-utils.h
@@ -49,13 +49,6 @@ typedef enum {
 typedef gboolean (* EClientUtilsAuthenticateHandler) (EClient *client, ECredentials *credentials, gpointer user_data);
 
 EClient	*	e_client_utils_new			(ESource *source, EClientSourceType source_type, GError **error);
-EClient *	e_client_utils_new_from_uri		(const gchar *uri, EClientSourceType source_type, GError **error);
-EClient *	e_client_utils_new_system		(EClientSourceType source_type, GError **error);
-EClient *	e_client_utils_new_default		(EClientSourceType source_type, GError **error);
-
-gboolean	e_client_utils_set_default		(EClient *client, EClientSourceType source_type, GError **error);
-gboolean	e_client_utils_set_default_source	(ESource *source, EClientSourceType source_type, GError **error);
-gboolean	e_client_utils_get_sources		(ESourceList **sources, EClientSourceType source_type, GError **error);
 
 void		e_client_utils_open_new			(ESource *source, EClientSourceType source_type, gboolean only_if_exists, GCancellable *cancellable,
 							 EClientUtilsAuthenticateHandler auth_handler, gpointer auth_handler_user_data,
@@ -63,10 +56,6 @@ void		e_client_utils_open_new			(ESource *source, EClientSourceType source_type,
 gboolean	e_client_utils_open_new_finish		(ESource *source, GAsyncResult *result, EClient **client, GError **error);
 
 gboolean	e_client_utils_authenticate_handler	(EClient *client, ECredentials *credentials, gpointer gtk_window_parent);
-void		e_client_utils_forget_password		(EClient *client);
-
-gboolean	e_credentials_authenticate_helper	(ECredentials *credentials, GtkWindow *parent, gboolean *remember_password);
-void		e_credentials_forget_password		(const ECredentials *credentials);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]