[evolution-data-server] Adapt EBookBackendGoogle to libedata-book changes.



commit a0dc131e9c93c69921432a3baad6537a364f8ba0
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Sep 9 13:18:37 2011 -0400

    Adapt EBookBackendGoogle to libedata-book changes.

 .../google/e-book-backend-google-factory.c         |   47 ++++++++++++-----
 .../backends/google/e-book-backend-google.c        |   58 +++++++++-----------
 .../backends/google/e-book-backend-google.h        |   41 ++++++++++-----
 3 files changed, 89 insertions(+), 57 deletions(-)
---
diff --git a/addressbook/backends/google/e-book-backend-google-factory.c b/addressbook/backends/google/e-book-backend-google-factory.c
index 7093806..36116ac 100644
--- a/addressbook/backends/google/e-book-backend-google-factory.c
+++ b/addressbook/backends/google/e-book-backend-google-factory.c
@@ -21,29 +21,50 @@
 
 #include <config.h>
 
-#include <libebackend/e-data-server-module.h>
 #include <libedata-book/e-book-backend-factory.h>
 #include "e-book-backend-google.h"
 
-E_BOOK_BACKEND_FACTORY_SIMPLE (google, Google, e_book_backend_google_new)
+#define FACTORY_NAME "google"
 
-GType google_type;
+typedef EBookBackendFactory EBookBackendGoogleFactory;
+typedef EBookBackendFactoryClass EBookBackendGoogleFactoryClass;
 
-void
-eds_module_initialize (GTypeModule *module)
+/* Module Entry Points */
+void e_module_load (GTypeModule *type_module);
+void e_module_unload (GTypeModule *type_module);
+
+/* Forward Declarations */
+GType e_book_backend_google_factory_get_type (void);
+
+G_DEFINE_DYNAMIC_TYPE (
+	EBookBackendGoogleFactory,
+	e_book_backend_google_factory,
+	E_TYPE_BOOK_BACKEND_FACTORY)
+
+static void
+e_book_backend_google_factory_class_init (EBookBackendFactoryClass *class)
+{
+	class->factory_name = FACTORY_NAME;
+	class->backend_type = E_TYPE_BOOK_BACKEND_GOOGLE;
+}
+
+static void
+e_book_backend_google_factory_class_finalize (EBookBackendFactoryClass *class)
+{
+}
+
+static void
+e_book_backend_google_factory_init (EBookBackendFactory *factory)
 {
-    google_type = _google_factory_get_type (module);
 }
 
-void
-eds_module_shutdown (void)
+G_MODULE_EXPORT void
+e_module_load (GTypeModule *type_module)
 {
+	e_book_backend_google_factory_register_type (type_module);
 }
 
-void
-eds_module_list_types (const GType **types,
-                       gint *num_types)
+G_MODULE_EXPORT void
+e_module_unload (GTypeModule *type_module)
 {
-    *types = &google_type;
-    *num_types = 1;
 }
diff --git a/addressbook/backends/google/e-book-backend-google.c b/addressbook/backends/google/e-book-backend-google.c
index 6f99867..1438959 100644
--- a/addressbook/backends/google/e-book-backend-google.c
+++ b/addressbook/backends/google/e-book-backend-google.c
@@ -68,7 +68,6 @@ typedef enum {
 } CacheType;
 
 struct _EBookBackendGooglePrivate {
-	gboolean is_online;
 	GList *bookviews;
 
 	CacheType cache_type;
@@ -418,7 +417,7 @@ cache_needs_update (EBookBackend *backend,
 		*remaining_secs = G_MAXUINT;
 
 	/* We never want to update in offline mode */
-	if (!priv->is_online)
+	if (!e_backend_get_online (E_BACKEND (backend)))
 		return FALSE;
 
 	rv = cache_get_last_update_tv (backend, &last);
@@ -1052,11 +1051,14 @@ cache_refresh_if_needed (EBookBackend *backend)
 	EBookBackendGooglePrivate *priv = E_BOOK_BACKEND_GOOGLE (backend)->priv;
 	guint remaining_secs;
 	gboolean install_timeout;
+	gboolean is_online;
 
 	__debug__ (G_STRFUNC);
 
-	if (!priv->is_online || !backend_is_authorized (backend)) {
-		__debug__ ("We are not connected to Google%s.", (!priv->is_online) ? " (offline mode)" : "");
+	is_online = e_backend_get_online (E_BACKEND (backend));
+
+	if (!is_online || !backend_is_authorized (backend)) {
+		__debug__ ("We are not connected to Google%s.", (!is_online) ? " (offline mode)" : "");
 		return TRUE;
 	}
 
@@ -1381,7 +1383,7 @@ e_book_backend_google_create_contact (EBookBackend *backend,
 
 	__debug__ ("Creating: %s", vcard_str);
 
-	if (!priv->is_online) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		e_data_book_respond_create (book, opid, EDB_ERROR (OFFLINE_UNAVAILABLE), NULL);
 		return;
 	}
@@ -1476,7 +1478,7 @@ e_book_backend_google_remove_contacts (EBookBackend *backend,
 
 	__debug__ (G_STRFUNC);
 
-	if (!priv->is_online) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		e_data_book_respond_remove_contacts (book, opid, EDB_ERROR (OFFLINE_UNAVAILABLE), NULL);
 		return;
 	}
@@ -1757,7 +1759,7 @@ e_book_backend_google_modify_contact (EBookBackend *backend,
 
 	__debug__ ("Updating: %s", vcard_str);
 
-	if (!priv->is_online) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		e_data_book_respond_modify (book, opid, EDB_ERROR (OFFLINE_UNAVAILABLE), NULL);
 		return;
 	}
@@ -2125,7 +2127,7 @@ e_book_backend_google_authenticate_user (EBookBackend *backend,
 
 	__debug__ (G_STRFUNC);
 
-	if (!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));
@@ -2199,7 +2201,8 @@ e_book_backend_google_open (EBookBackend *backend,
 	const gchar *refresh_interval_str, *use_ssl_str, *use_cache_str;
 	guint refresh_interval;
 	gboolean use_ssl, use_cache;
-	ESource *source = e_book_backend_get_source (backend);
+	ESource *source;
+	gboolean is_online;
 
 	__debug__ (G_STRFUNC);
 
@@ -2208,6 +2211,8 @@ e_book_backend_google_open (EBookBackend *backend,
 		return;
 	}
 
+	source = e_backend_get_source (E_BACKEND (backend));
+
 	/* Parse various other properties */
 	refresh_interval_str = e_source_get_property (source, "refresh-interval");
 	use_ssl_str = e_source_get_property (source, "ssl");
@@ -2242,10 +2247,11 @@ e_book_backend_google_open (EBookBackend *backend,
 	}
 
 	/* Set up ready to be interacted with */
-	e_book_backend_notify_online (backend, priv->is_online);
+	is_online = e_backend_get_online (E_BACKEND (backend));
+	e_book_backend_notify_online (backend, is_online);
 	e_book_backend_notify_readonly (backend, TRUE);
 
-	if (priv->is_online) {
+	if (is_online) {
 		request_authorization (backend);
 
 #ifdef HAVE_LIBGDATA_0_9
@@ -2255,7 +2261,7 @@ e_book_backend_google_open (EBookBackend *backend,
 #endif
 	}
 
-	if (!priv->is_online || backend_is_authorized (backend)) {
+	if (!is_online || backend_is_authorized (backend)) {
 		e_book_backend_notify_readonly (backend, FALSE);
 		e_book_backend_notify_opened (backend, NULL /* Success */);
 	}
@@ -2439,17 +2445,15 @@ google_cancel_all_operations (EBookBackend *backend)
 }
 
 static void
-e_book_backend_google_set_online (EBookBackend *backend,
-                                  gboolean is_online)
+e_book_backend_google_notify_online_cb (EBookBackend *backend,
+                                        GParamSpec *pspec)
 {
 	EBookBackendGooglePrivate *priv = E_BOOK_BACKEND_GOOGLE (backend)->priv;
-	__debug__ (G_STRFUNC);
-
-	if (is_online == priv->is_online)
-		return;
+	gboolean is_online;
 
-	priv->is_online = is_online;
+	__debug__ (G_STRFUNC);
 
+	is_online = e_backend_get_online (E_BACKEND (backend));
 	e_book_backend_notify_online (backend, is_online);
 
 	if (is_online && e_book_backend_is_opened (backend)) {
@@ -2537,7 +2541,6 @@ e_book_backend_google_class_init (EBookBackendGoogleClass *klass)
 	backend_class->get_backend_property	= e_book_backend_google_get_backend_property;
 	backend_class->start_book_view		= e_book_backend_google_start_book_view;
 	backend_class->stop_book_view		= e_book_backend_google_stop_book_view;
-	backend_class->set_online		= e_book_backend_google_set_online;
 	backend_class->remove			= e_book_backend_google_remove;
 	backend_class->create_contact		= e_book_backend_google_create_contact;
 	backend_class->remove_contacts		= e_book_backend_google_remove_contacts;
@@ -2561,6 +2564,10 @@ e_book_backend_google_init (EBookBackendGoogle *backend)
 		backend, E_TYPE_BOOK_BACKEND_GOOGLE,
 		EBookBackendGooglePrivate);
 
+	g_signal_connect (
+		backend, "notify::online",
+		G_CALLBACK (e_book_backend_google_notify_online_cb), NULL);
+
 	/* Set up our EProxy. */
 	backend->priv->proxy = e_proxy_new ();
 	e_proxy_setup_proxy (backend->priv->proxy);
@@ -2570,17 +2577,6 @@ e_book_backend_google_init (EBookBackendGoogle *backend)
 		G_CALLBACK (proxy_settings_changed), backend);
 }
 
-EBookBackend *
-e_book_backend_google_new (void)
-{
-	EBookBackendGoogle *backend;
-
-	__debug__ (G_STRFUNC);
-	backend = g_object_new (E_TYPE_BOOK_BACKEND_GOOGLE, NULL);
-
-	return E_BOOK_BACKEND (backend);
-}
-
 static void
 data_book_error_from_gdata_error (GError **dest_err,
                                   const GError *error)
diff --git a/addressbook/backends/google/e-book-backend-google.h b/addressbook/backends/google/e-book-backend-google.h
index c2ae59c..f75d256 100644
--- a/addressbook/backends/google/e-book-backend-google.h
+++ b/addressbook/backends/google/e-book-backend-google.h
@@ -19,20 +19,34 @@
  * Author: Joergen Scheibengruber <joergen.scheibengruber AT googlemail.com>
  */
 
-#ifndef __E_BOOK_BACKEND_GOOGLE_H__
-#define __E_BOOK_BACKEND_GOOGLE_H__
+#ifndef E_BOOK_BACKEND_GOOGLE_H
+#define E_BOOK_BACKEND_GOOGLE_H
 
 #include <libedata-book/e-book-backend.h>
 
-#define E_TYPE_BOOK_BACKEND_GOOGLE         (e_book_backend_google_get_type ())
-#define E_BOOK_BACKEND_GOOGLE(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), E_TYPE_BOOK_BACKEND_GOOGLE, EBookBackendGoogle))
-#define E_BOOK_BACKEND_GOOGLE_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), E_TYPE_BOOK_BACKEND_GOOGLE, EBookBackendGoogleClass))
-#define E_IS_BOOK_BACKEND_GOOGLE(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), E_TYPE_BOOK_BACKEND_GOOGLE))
-#define E_IS_BOOK_BACKEND_GOOGLE_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), E_TYPE_BOOK_BACKEND_GOOGLE))
-#define E_BOOK_BACKEND_GOOGLE_GET_CLASS(k) (G_TYPE_INSTANCE_GET_CLASS ((obj), E_TYPE_BOOK_BACKEND_GOOGLE, EBookBackendGoogleClass))
+/* Standard GObject macros */
+#define E_TYPE_BOOK_BACKEND_GOOGLE \
+	(e_book_backend_google_get_type ())
+#define E_BOOK_BACKEND_GOOGLE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), E_TYPE_BOOK_BACKEND_GOOGLE, EBookBackendGoogle))
+#define E_BOOK_BACKEND_GOOGLE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), E_TYPE_BOOK_BACKEND_GOOGLE, EBookBackendGoogleClass))
+#define E_IS_BOOK_BACKEND_GOOGLE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), E_TYPE_BOOK_BACKEND_GOOGLE))
+#define E_IS_BOOK_BACKEND_GOOGLE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), E_TYPE_BOOK_BACKEND_GOOGLE))
+#define E_BOOK_BACKEND_GOOGLE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), E_TYPE_BOOK_BACKEND_GOOGLE, EBookBackendGoogleClass))
 
-typedef struct _EBookBackendGoogle        EBookBackendGoogle;
-typedef struct _EBookBackendGoogleClass   EBookBackendGoogleClass;
+G_BEGIN_DECLS
+
+typedef struct _EBookBackendGoogle EBookBackendGoogle;
+typedef struct _EBookBackendGoogleClass EBookBackendGoogleClass;
 typedef struct _EBookBackendGooglePrivate EBookBackendGooglePrivate;
 
 struct _EBookBackendGoogle {
@@ -44,7 +58,8 @@ struct _EBookBackendGoogleClass {
 	EBookBackendClass parent_class;
 };
 
-EBookBackend *e_book_backend_google_new (void);
-GType e_book_backend_google_get_type (void);
+GType		e_book_backend_google_get_type	(void);
+
+G_END_DECLS
 
-#endif /* __E_BOOK_BACKEND_GOOGLE_H__ */
+#endif /* E_BOOK_BACKEND_GOOGLE_H */



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