[evolution-data-server] Adapt EBookBackendLDAP to libedata-book changes.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Adapt EBookBackendLDAP to libedata-book changes.
- Date: Mon, 26 Sep 2011 13:47:35 +0000 (UTC)
commit 5c87b5165ee87e3d9af48605356b75ba4d944498
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Sep 9 13:19:08 2011 -0400
Adapt EBookBackendLDAP to libedata-book changes.
.../backends/ldap/e-book-backend-ldap-factory.c | 50 ++++++++++----
addressbook/backends/ldap/e-book-backend-ldap.c | 68 ++++++++++----------
addressbook/backends/ldap/e-book-backend-ldap.h | 49 ++++++++++-----
3 files changed, 103 insertions(+), 64 deletions(-)
---
diff --git a/addressbook/backends/ldap/e-book-backend-ldap-factory.c b/addressbook/backends/ldap/e-book-backend-ldap-factory.c
index 75d9636..69d99b0 100644
--- a/addressbook/backends/ldap/e-book-backend-ldap-factory.c
+++ b/addressbook/backends/ldap/e-book-backend-ldap-factory.c
@@ -25,29 +25,51 @@
#include <config.h>
#endif
-#include "libebackend/e-data-server-module.h"
-#include "libedata-book/e-book-backend-factory.h"
+#include <libedata-book/e-book-backend-factory.h>
#include "e-book-backend-ldap.h"
-E_BOOK_BACKEND_FACTORY_SIMPLE (ldap, LDAP, e_book_backend_ldap_new)
+#define FACTORY_NAME "ldap"
-static GType ldap_type;
+typedef EBookBackendFactory EBookBackendLDAPFactory;
+typedef EBookBackendFactoryClass EBookBackendLDAPFactoryClass;
-void
-eds_module_initialize (GTypeModule *type_module)
+/* Module Entry Points */
+void e_module_load (GTypeModule *type_module);
+void e_module_unload (GTypeModule *type_module);
+
+/* Forward Declarations */
+GType e_book_backend_ldap_factory_get_type (void);
+
+G_DEFINE_DYNAMIC_TYPE (
+ EBookBackendLDAPFactory,
+ e_book_backend_ldap_factory,
+ E_TYPE_BOOK_BACKEND_FACTORY)
+
+static void
+e_book_backend_ldap_factory_class_init (EBookBackendFactoryClass *class)
+{
+ class->factory_name = FACTORY_NAME;
+ class->backend_type = E_TYPE_BOOK_BACKEND_LDAP;
+}
+
+static void
+e_book_backend_ldap_factory_class_finalize (EBookBackendFactoryClass *class)
{
- ldap_type = _ldap_factory_get_type (type_module);
}
-void
-eds_module_shutdown (void)
+static void
+e_book_backend_ldap_factory_init (EBookBackendFactory *factory)
{
}
-void
-eds_module_list_types (const GType **types,
- gint *num_types)
+G_MODULE_EXPORT void
+e_module_load (GTypeModule *type_module)
{
- *types = &ldap_type;
- *num_types = 1;
+ e_book_backend_ldap_factory_register_type (type_module);
}
+
+G_MODULE_EXPORT void
+e_module_unload (GTypeModule *type_module)
+{
+}
+
diff --git a/addressbook/backends/ldap/e-book-backend-ldap.c b/addressbook/backends/ldap/e-book-backend-ldap.c
index 808d0a1..ac3c2fc 100644
--- a/addressbook/backends/ldap/e-book-backend-ldap.c
+++ b/addressbook/backends/ldap/e-book-backend-ldap.c
@@ -211,7 +211,6 @@ struct _EBookBackendLDAPPrivate {
gboolean evolutionPersonChecked;
gboolean marked_for_offline;
- gboolean is_online;
/* our operations */
GStaticRecMutex op_hash_mutex;
GHashTable *id_to_op;
@@ -438,10 +437,20 @@ static struct prop_info {
static gboolean
can_browse (EBookBackend *backend)
{
- return backend &&
- e_book_backend_get_source (backend) &&
- e_source_get_property (e_book_backend_get_source (backend), "can-browse") &&
- strcmp (e_source_get_property (e_book_backend_get_source (backend), "can-browse"), "1") == 0;
+ ESource *source = NULL;
+ const gchar *can_browse;
+
+ /* XXX Backend can really be NULL here, or
+ * are we just being needlessly paranoid? */
+ if (backend == NULL)
+ return FALSE;
+
+ source = e_backend_get_source (E_BACKEND (backend));
+ g_return_val_if_fail (source != NULL, FALSE);
+
+ can_browse = e_source_get_property (source, "can-browse");
+
+ return (g_strcmp0 (can_browse, "1") == 0);
}
static gboolean
@@ -1615,7 +1624,7 @@ e_book_backend_ldap_create_contact (EBookBackend *backend,
LDAPMod **ldap_mods;
gchar *new_uid;
- if (!bl->priv->is_online) {
+ if (!e_backend_get_online (E_BACKEND (backend))) {
e_data_book_respond_create (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
return;
}
@@ -1815,7 +1824,7 @@ e_book_backend_ldap_remove_contacts (EBookBackend *backend,
gint remove_msgid;
gint ldap_error;
- if (!bl->priv->is_online) {
+ if (!e_backend_get_online (E_BACKEND (backend))) {
e_data_book_respond_remove_contacts (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
g_free (remove_op);
return;
@@ -2253,7 +2262,7 @@ e_book_backend_ldap_modify_contact (EBookBackend *backend,
gint modify_contact_msgid;
EDataBookView *book_view;
- if (!bl->priv->is_online) {
+ if (!e_backend_get_online (E_BACKEND (backend))) {
e_data_book_respond_modify (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
return;
}
@@ -2426,7 +2435,7 @@ e_book_backend_ldap_get_contact (EBookBackend *backend,
GTimeVal start, end;
gulong diff;
- if (!bl->priv->is_online) {
+ if (!e_backend_get_online (E_BACKEND (backend))) {
if (bl->priv->marked_for_offline && bl->priv->cache) {
EContact *contact = e_book_backend_cache_get_contact (bl->priv->cache, id);
gchar *vcard_str;
@@ -2650,7 +2659,7 @@ e_book_backend_ldap_get_contact_list (EBookBackend *backend,
g_get_current_time (&start);
}
- if (!bl->priv->is_online) {
+ if (!e_backend_get_online (E_BACKEND (backend))) {
if (bl->priv->marked_for_offline && bl->priv->cache) {
GList *contacts;
GSList *vcard_strings = NULL;
@@ -2862,7 +2871,7 @@ e_book_backend_ldap_get_contact_list_uids (EBookBackend *backend,
g_get_current_time (&start);
}
- if (!bl->priv->is_online) {
+ if (!e_backend_get_online (E_BACKEND (backend))) {
if (bl->priv->marked_for_offline && bl->priv->cache) {
GList *contacts;
GSList *uids = NULL;
@@ -4759,7 +4768,7 @@ e_book_backend_ldap_search (EBookBackendLDAP *bl,
g_get_current_time (&start);
}
- if (!bl->priv->is_online) {
+ if (!e_backend_get_online (E_BACKEND (bl))) {
if (!(bl->priv->marked_for_offline && bl->priv->cache)) {
GError *edb_err = EDB_ERROR (REPOSITORY_OFFLINE);
e_data_book_view_notify_complete (view, edb_err);
@@ -5053,12 +5062,13 @@ e_book_backend_ldap_authenticate_user (EBookBackend *backend,
g_static_rec_mutex_lock (&eds_ldap_handler_lock);
if (!auth_method || !*auth_method) {
- ESource *source = e_book_backend_get_source (backend);
+ ESource *source;
+ source = e_backend_get_source (E_BACKEND (backend));
auth_method = e_source_get_property (source, "auth");
}
- if (!bl->priv->is_online) {
+ if (!e_backend_get_online (E_BACKEND (backend))) {
e_book_backend_notify_readonly (backend, TRUE);
e_book_backend_notify_online (backend, FALSE);
e_book_backend_notify_opened (backend, EDB_ERROR (SUCCESS));
@@ -5251,7 +5261,7 @@ e_book_backend_ldap_open (EBookBackend *backend,
gboolean only_if_exists)
{
EBookBackendLDAP *bl = E_BOOK_BACKEND_LDAP (backend);
- ESource *source = e_book_backend_get_source (backend);
+ ESource *source;
LDAPURLDesc *lud;
gint ldap_error;
gint limit = 100;
@@ -5269,6 +5279,7 @@ e_book_backend_ldap_open (EBookBackend *backend,
if (enable_debug)
printf ("%s ... \n", G_STRFUNC);
+ source = e_backend_get_source (E_BACKEND (backend));
uri = e_source_get_uri (source);
cache_dir = e_book_backend_get_cache_dir (backend);
@@ -5334,7 +5345,7 @@ e_book_backend_ldap_open (EBookBackend *backend,
g_free (uri);
- if (!bl->priv->is_online) {
+ if (!e_backend_get_online (E_BACKEND (backend))) {
/* Offline */
e_book_backend_notify_readonly (backend, TRUE);
@@ -5506,15 +5517,11 @@ start_views (EBookBackend *backend)
#endif
static void
-e_book_backend_ldap_set_online (EBookBackend *backend,
- gboolean is_online)
+e_book_backend_ldap_notify_online_cb (EBookBackend *backend,
+ GParamSpec *pspec)
{
EBookBackendLDAP *bl = E_BOOK_BACKEND_LDAP (backend);
- if (bl->priv->is_online == is_online)
- return;
-
- bl->priv->is_online = is_online;
#if 0
stop_views (backend);
#endif
@@ -5522,7 +5529,7 @@ e_book_backend_ldap_set_online (EBookBackend *backend,
/* Cancel all running operations */
ldap_cancel_all_operations (backend);
- if (!is_online) {
+ if (!e_backend_get_online (E_BACKEND (backend))) {
/* Go offline */
e_book_backend_notify_readonly (backend, TRUE);
@@ -5567,15 +5574,6 @@ e_book_backend_ldap_set_online (EBookBackend *backend,
}
}
-/**
- * e_book_backend_ldap_new:
- */
-EBookBackend *
-e_book_backend_ldap_new (void)
-{
- return g_object_new (E_TYPE_BOOK_BACKEND_LDAP, NULL);
-}
-
static gboolean
call_dtor (gint msgid,
LDAPOp *op,
@@ -5680,7 +5678,6 @@ e_book_backend_ldap_class_init (EBookBackendLDAPClass *klass)
parent_class->start_book_view = e_book_backend_ldap_start_book_view;
parent_class->stop_book_view = e_book_backend_ldap_stop_book_view;
parent_class->authenticate_user = e_book_backend_ldap_authenticate_user;
- parent_class->set_online = e_book_backend_ldap_set_online;
object_class->dispose = e_book_backend_ldap_dispose;
}
@@ -5698,7 +5695,6 @@ e_book_backend_ldap_init (EBookBackendLDAP *backend)
priv->id_to_op = g_hash_table_new (g_int_hash, g_int_equal);
priv->poll_timeout = -1;
priv->marked_for_offline = FALSE;
- priv->is_online = TRUE;
priv->is_summary_ready = FALSE;
priv->reserved1 = NULL;
priv->reserved2 = NULL;
@@ -5710,4 +5706,8 @@ e_book_backend_ldap_init (EBookBackendLDAP *backend)
if (g_getenv ("LDAP_DEBUG"))
enable_debug = TRUE;
+
+ g_signal_connect (
+ backend, "notify::online",
+ G_CALLBACK (e_book_backend_ldap_notify_online_cb), NULL);
}
diff --git a/addressbook/backends/ldap/e-book-backend-ldap.h b/addressbook/backends/ldap/e-book-backend-ldap.h
index 7f2ece8..2968717 100644
--- a/addressbook/backends/ldap/e-book-backend-ldap.h
+++ b/addressbook/backends/ldap/e-book-backend-ldap.h
@@ -22,31 +22,48 @@
* Hans Petter Jansson <hpj novell com>
*/
-#ifndef __E_BOOK_BACKEND_LDAP_H__
-#define __E_BOOK_BACKEND_LDAP_H__
+#ifndef E_BOOK_BACKEND_LDAP_H
+#define E_BOOK_BACKEND_LDAP_H
#include <libedata-book/e-book-backend.h>
-#define E_TYPE_BOOK_BACKEND_LDAP (e_book_backend_ldap_get_type ())
-#define E_BOOK_BACKEND_LDAP(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), E_TYPE_BOOK_BACKEND_LDAP, EBookBackendLDAP))
-#define E_BOOK_BACKEND_LDAP_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), E_TYPE_BOOK_BACKEND_LDAP, EBookBackendLDAPClass))
-#define E_IS_BOOK_BACKEND_LDAP(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), E_TYPE_BOOK_BACKEND_LDAP))
-#define E_IS_BOOK_BACKEND_LDAP_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), E_TYPE_BOOK_BACKEND_LDAP))
-#define E_BOOK_BACKEND_LDAP_GET_CLASS(k) (G_TYPE_INSTANCE_GET_CLASS ((obj), E_TYPE_BOOK_BACKEND_LDAP, EBookBackendLDAPClass))
+/* Standard GObject macros */
+#define E_TYPE_BOOK_BACKEND_LDAP \
+ (e_book_backend_ldap_get_type ())
+#define E_BOOK_BACKEND_LDAP(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_BOOK_BACKEND_LDAP, EBookBackendLDAP))
+#define E_BOOK_BACKEND_LDAP_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_BOOK_BACKEND_LDAP, EBookBackendLDAPClass))
+#define E_IS_BOOK_BACKEND_LDAP(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_BOOK_BACKEND_LDAP))
+#define E_IS_BOOK_BACKEND_LDAP_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), E_TYPE_BOOK_BACKEND_LDAP))
+#define E_BOOK_BACKEND_LDAP_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_BOOK_BACKEND_LDAP, EBookBackendLDAPClass))
+G_BEGIN_DECLS
+
+typedef struct _EBookBackendLDAP EBookBackendLDAP;
+typedef struct _EBookBackendLDAPClass EBookBackendLDAPClass;
typedef struct _EBookBackendLDAPPrivate EBookBackendLDAPPrivate;
-typedef struct {
- EBookBackend parent_object;
+struct _EBookBackendLDAP {
+ EBookBackend parent;
EBookBackendLDAPPrivate *priv;
-} EBookBackendLDAP;
+};
-typedef struct {
+struct _EBookBackendLDAPClass {
EBookBackendClass parent_class;
-} EBookBackendLDAPClass;
+};
+
+GType e_book_backend_ldap_get_type (void);
-EBookBackend *e_book_backend_ldap_new (void);
-GType e_book_backend_ldap_get_type (void);
+G_END_DECLS
-#endif /* __E_BOOK_BACKEND_LDAP_H__ */
+#endif /* E_BOOK_BACKEND_LDAP_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]