[jana] jana-ecal-store: Support passwords for authenticated calendars in Jana.



commit 547bdc340ad4eab75ea7104f430e61fe7f9f16af
Author: Srinivasa Ragavan <sragavan gnome org>
Date:   Mon Apr 26 18:18:05 2010 +0530

    jana-ecal-store: Support passwords for authenticated calendars in Jana.

 configure.ac                   |    2 ++
 libjana-ecal/Makefile.am       |    4 ++--
 libjana-ecal/jana-ecal-store.c |   36 +++++++++++++++++++++++++++++++++++-
 3 files changed, 39 insertions(+), 3 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 798c453..5a984f9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,6 +23,8 @@ PKG_CHECK_MODULES(GOBJECT, gobject-2.0 >= 2.12.0)
 PKG_CHECK_MODULES(GTHREAD, gthread-2.0)
 PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.6.0)
 PKG_CHECK_MODULES(ECAL, libecal-1.2 >= 1.4.0)
+PKG_CHECK_MODULES(EDATASERVERUI, libedataserverui-1.2)
+
 PKG_CHECK_MODULES(GCONF, gconf-2.0)
 
 old_cflags=$CFLAGS
diff --git a/libjana-ecal/Makefile.am b/libjana-ecal/Makefile.am
index bef8727..93866c8 100644
--- a/libjana-ecal/Makefile.am
+++ b/libjana-ecal/Makefile.am
@@ -1,8 +1,8 @@
 SUBDIRS = . doc
 
 localedir = $(datadir)/locale
-AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" -DPKGDATADIR=\"$(pkgdatadir)\" $(GOBJECT_CFLAGS) $(ECAL_CFLAGS) $(GCONF_CFLAGS) -Wall
-AM_LDFLAGS = $(GOBJECT_LIBS) $(ECAL_LIBS) $(GCONF_LIBS)
+AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" -DPKGDATADIR=\"$(pkgdatadir)\" $(GOBJECT_CFLAGS) $(ECAL_CFLAGS) $(EDATASERVERUI_CFLAGS) $(GCONF_CFLAGS) -Wall
+AM_LDFLAGS = $(GOBJECT_LIBS) $(ECAL_LIBS) $(GCONF_LIBS) $(EDATASERVERUI_LIBS)
 
 source_h = jana-ecal.h \
 	jana-ecal-component.h \
diff --git a/libjana-ecal/jana-ecal-store.c b/libjana-ecal/jana-ecal-store.c
index f9dc1dc..5d2f166 100644
--- a/libjana-ecal/jana-ecal-store.c
+++ b/libjana-ecal/jana-ecal-store.c
@@ -33,6 +33,7 @@
 #define HANDLE_LIBICAL_MEMORY 1
 
 #include <libjana/jana-utils.h>
+#include <libedataserverui/e-passwords.h>
 #include "jana-ecal-component.h"
 #include "jana-ecal-event.h"
 #include "jana-ecal-note.h"
@@ -40,6 +41,8 @@
 #include "jana-ecal-store-view.h"
 #include "jana-ecal-store.h"
 
+static gint init_passwords = 0;
+
 static void store_interface_init (gpointer g_iface, gpointer iface_data);
 
 static void		store_open			(JanaStore *self);
@@ -55,8 +58,12 @@ static void	store_remove_component	(JanaStore *self, JanaComponent *comp);
 
 static void	store_cal_opened_cb	(ECal *ecal, gint arg1,
 					 JanaStore *self);
+static gchar *	auth_func_cb 		(ECal       *ecal,
+					 const gchar *prompt,
+					 const gchar *key,
+					 gpointer    user_data);
 
-G_DEFINE_TYPE_WITH_CODE (JanaEcalStore, 
+G_DEFINE_TYPE_WITH_CODE (JanaEcalStore,
                         jana_ecal_store, 
                         G_TYPE_OBJECT,
                         G_IMPLEMENT_INTERFACE (JANA_TYPE_STORE,
@@ -105,6 +112,7 @@ jana_ecal_store_set_property (GObject *object, guint property_id,
 	switch (property_id) {
 	    case PROP_ECAL :
 		priv->ecal = E_CAL (g_value_dup_object (value));
+		e_cal_set_auth_func (priv->ecal, auth_func_cb, NULL);
 		g_signal_connect (G_OBJECT (priv->ecal), "cal-opened",
 			G_CALLBACK (store_cal_opened_cb), object);
 		break;
@@ -128,6 +136,9 @@ jana_ecal_store_dispose (GObject *object)
 
 	if (G_OBJECT_CLASS (jana_ecal_store_parent_class)->dispose)
 		G_OBJECT_CLASS (jana_ecal_store_parent_class)->dispose (object);
+
+	if (g_atomic_int_dec_and_test (&init_passwords))
+		e_passwords_shutdown ();
 }
 
 static void
@@ -245,10 +256,32 @@ jana_ecal_store_new (JanaComponentType type)
 		return NULL;
 	}
 	
+	g_atomic_int_inc (&init_passwords);
+	
+	if (g_atomic_int_get(&init_passwords) == 1) {
+		e_passwords_init ();
+	}
 	return JANA_STORE (g_object_new (JANA_ECAL_TYPE_STORE,
 		"ecal", ecal, "type", type, NULL));
 }
 
+static gchar *
+auth_func_cb (ECal       *ecal,
+	      const gchar *prompt,
+	      const gchar *key,
+	      gpointer    user_data)
+{
+	ESource *source;
+	const gchar *auth_domain;
+	const gchar *component_name;
+
+	source = e_cal_get_source (ecal);
+	auth_domain = e_source_get_property (source, "auth-domain");
+	component_name = auth_domain ? auth_domain : "Calendar";
+
+	return e_passwords_get_password (component_name, key);
+}
+
 static gboolean
 store_cal_opened_signal_cb (JanaStore *self)
 {
@@ -298,6 +331,7 @@ jana_ecal_store_new_from_uri (const gchar *uri, JanaComponentType type)
 	}
 	
 	if ((ecal = e_cal_new_from_uri (uri, etype))) {
+		e_cal_set_auth_func (ecal, auth_func_cb, NULL);
 		return JANA_STORE (g_object_new (JANA_ECAL_TYPE_STORE,
 			"ecal", ecal, "type", type, NULL));
 	} else {



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