[evolution/account-mgmt: 17/33] Adapt calendars/common to the new ESource API.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/account-mgmt: 17/33] Adapt calendars/common to the new ESource API.
- Date: Fri, 18 Mar 2011 01:53:26 +0000 (UTC)
commit 59266e59d1acc5f68685b63601dc94a36b53db9d
Author: Matthew Barnes <mbarnes redhat com>
Date: Wed Dec 8 09:58:13 2010 -0500
Adapt calendars/common to the new ESource API.
calendar/common/authentication.c | 99 ++++++++------------------------------
1 files changed, 21 insertions(+), 78 deletions(-)
---
diff --git a/calendar/common/authentication.c b/calendar/common/authentication.c
index 286b7d6..4cf4ace 100644
--- a/calendar/common/authentication.c
+++ b/calendar/common/authentication.c
@@ -28,6 +28,7 @@
#include <string.h>
#include <glib/gi18n.h>
#include <libedataserver/e-source.h>
+#include <libedataserver/e-source-authentication.h>
#include <libedataserverui/e-passwords.h>
#include "authentication.h"
#include <libedataserver/e-url.h>
@@ -38,66 +39,31 @@ auth_func_cb (ECal *ecal,
const gchar *key,
gpointer user_data)
{
- gboolean remember;
- gchar *password, *auth_domain;
ESource *source;
- const gchar *component_name;
+ gboolean remember;
+ gchar *password;
source = e_cal_get_source (ecal);
- auth_domain = e_source_get_duped_property (source, "auth-domain");
- component_name = auth_domain ? auth_domain : "Calendar";
- password = e_passwords_get_password (component_name, key);
+ password = e_passwords_get_password (source);
if (!password)
password = e_passwords_ask_password (
- _("Enter password"),
- component_name, key, prompt,
+ source, _("Enter password"), prompt,
E_PASSWORDS_REMEMBER_FOREVER |
E_PASSWORDS_SECRET |
E_PASSWORDS_ONLINE,
&remember, NULL);
- g_free (auth_domain);
-
return password;
}
-static gchar *
-build_pass_key (ECal *ecal)
-{
- gchar *euri_str;
- const gchar *uri;
- EUri *euri;
-
- uri = e_cal_get_uri (ecal);
-
- euri = e_uri_new (uri);
- euri_str = e_uri_to_string (euri, FALSE);
-
- e_uri_free (euri);
- return euri_str;
-}
-
void
e_auth_cal_forget_password (ECal *ecal)
{
- ESource *source = NULL;
- const gchar *auth_domain = NULL, *component_name = NULL, *auth_type = NULL;
+ ESource *source;
source = e_cal_get_source (ecal);
- auth_domain = e_source_get_property (source, "auth-domain");
- component_name = auth_domain ? auth_domain : "Calendar";
-
- auth_type = e_source_get_property (source, "auth-type");
- if (auth_type) {
- gchar *key = NULL;
-
- key = build_pass_key (ecal);
- e_passwords_forget_password (component_name, key);
- g_free (key);
- }
-
- e_passwords_forget_password (component_name, e_source_get_uri (source));
+ e_passwords_forget_password (source);
}
ECal *
@@ -153,50 +119,27 @@ load_cal_source_context_free (LoadContext *context)
g_slice_free (LoadContext, context);
}
-static void
-load_cal_source_get_auth_details (ESource *source,
- LoadContext *context)
-{
- const gchar *property;
-
- /* ECal figures out most of the details before invoking the
- * authentication callback, but we still need a component name
- * for e_passwords_ask_password(). */
-
- /* auth_component */
-
- property = e_source_get_property (source, "auth-domain");
-
- if (property == NULL)
- property = "Calendar";
-
- context->auth_component = g_strdup (property);
-}
-
static gchar *
load_cal_source_authenticate (ECal *cal,
const gchar *prompt,
- const gchar *uri,
+ const gchar *unused,
LoadContext *context)
{
+ ESource *source;
const gchar *title;
gboolean remember; /* not used */
gchar *password;
- /* Remember the URI so we don't have to reconstruct it if
- * authentication fails and we have to forget the password. */
- g_free (context->auth_uri);
- context->auth_uri = g_strdup (uri);
-
/* XXX Dialog windows should not have titles. */
title = "";
- password = e_passwords_get_password (context->auth_component, uri);
+ source = e_cal_get_source (cal);
+ password = e_passwords_get_password (source);
if (password == NULL)
password = e_passwords_ask_password (
- title, context->auth_component, uri,
- prompt, E_PASSWORDS_REMEMBER_FOREVER |
+ source, title, prompt,
+ E_PASSWORDS_REMEMBER_FOREVER |
E_PASSWORDS_SECRET | E_PASSWORDS_ONLINE,
&remember, context->parent);
@@ -265,8 +208,7 @@ fail:
if (g_error_matches (
error, E_CALENDAR_ERROR,
E_CALENDAR_STATUS_AUTHENTICATION_FAILED)) {
- e_passwords_forget_password (
- context->auth_component, context->auth_uri);
+ e_passwords_forget_password (source);
g_clear_error (&error);
goto try_again;
@@ -314,8 +256,13 @@ e_load_cal_source_async (ESource *source,
g_return_if_fail (E_IS_SOURCE (source));
- /* Source must have a group so we can obtain its URI. */
- g_return_if_fail (e_source_peek_group (source) != NULL);
+ /* XXX e_cal_open() will need to access the "Authentication"
+ * ESource extension, and e_cal_open() runs in a thread.
+ * Make sure the extension is loaded before spawning the
+ * thread to avoid "ESource::changed" emissions from the
+ * thread. Some widgets like ESourceSelector listen for
+ * that signal. */
+ e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION);
if (parent != NULL) {
g_return_if_fail (GTK_IS_WINDOW (parent));
@@ -339,10 +286,6 @@ e_load_cal_source_async (ESource *source,
context->source_type = source_type;
context->default_zone = default_zone;
- /* Extract authentication details from the ESource before
- * spawning the thread, since ESource is not thread-safe. */
- load_cal_source_get_auth_details (source, context);
-
simple = g_simple_async_result_new (
G_OBJECT (source), callback,
user_data, e_load_cal_source_async);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]