[evolution-data-server/account-mgmt: 10/28] Adapt address book backends to the new ESource API.



commit b1431262bbb8f9adb58b24adabfa17144e40e23c
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Nov 12 17:46:14 2010 -0500

    Adapt address book backends to the new ESource API.

 addressbook/backends/file/e-book-backend-file.c    |   50 ++++++++-----------
 .../backends/google/e-book-backend-google.c        |   53 +++++++++----------
 2 files changed, 46 insertions(+), 57 deletions(-)
---
diff --git a/addressbook/backends/file/e-book-backend-file.c b/addressbook/backends/file/e-book-backend-file.c
index 5020a0f..81bfb9e 100644
--- a/addressbook/backends/file/e-book-backend-file.c
+++ b/addressbook/backends/file/e-book-backend-file.c
@@ -877,25 +877,12 @@ static gchar *
 e_book_backend_file_extract_path_from_source (ESource *source)
 {
 	const gchar *user_data_dir;
-	const gchar *source_dir;
-	gchar *mangled_source_dir;
-	gchar *filename;
+	const gchar *uid;
 
+	uid = e_source_get_uid (source);
 	user_data_dir = e_get_user_data_dir ();
-	source_dir = e_source_peek_relative_uri (source);
 
-	if (!source_dir || !g_str_equal (source_dir, "system"))
-		source_dir = e_source_peek_uid (source);
-
-	/* Mangle the URI to not contain invalid characters. */
-	mangled_source_dir = g_strdelimit (g_strdup (source_dir), ":/", '_');
-
-	filename = g_build_filename (
-		user_data_dir, "addressbook", mangled_source_dir, NULL);
-
-	g_free (mangled_source_dir);
-
-	return filename;
+	return g_build_filename (user_data_dir, "addressbook", uid, NULL);
 }
 
 static void
@@ -1324,28 +1311,31 @@ select_changes (const gchar *name)
 	return TRUE;
 }
 
-static void
-e_book_backend_file_remove (EBookBackendSync *backend,
-			    EDataBook        *book,
-			    guint32           opid,
-			    GError          **perror)
+static gboolean
+e_book_backend_file_remove (EBookBackend *backend,
+                            GError **error)
 {
 	EBookBackendFile *bf = E_BOOK_BACKEND_FILE (backend);
 	GDir *dir;
 
-	if (-1 == g_unlink (bf->priv->filename)) {
+	if (g_unlink (bf->priv->filename) == -1) {
 		if (errno == EACCES || errno == EPERM) {
-			g_propagate_error (perror, EDB_ERROR (PERMISSION_DENIED));
+			g_propagate_error (
+				error, EDB_ERROR (PERMISSION_DENIED));
 		} else {
-			g_propagate_error (perror, e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR, "Failed to remove file '%s': %s", bf->priv->filename, g_strerror (errno)));
+			g_propagate_error (
+				error, e_data_book_create_error_fmt (
+				E_DATA_BOOK_STATUS_OTHER_ERROR,
+				"Failed to remove file '%s': %s",
+				bf->priv->filename, g_strerror (errno)));
 		}
-		return;
+		return FALSE;
 	}
 
 	/* unref the summary before we remove the file so it's not written out again */
 	g_object_unref (bf->priv->summary);
 	bf->priv->summary = NULL;
-	if (-1 == g_unlink (bf->priv->summary_filename))
+	if (g_unlink (bf->priv->summary_filename) == -1)
 		g_warning ("failed to remove summary file `%s`: %s", bf->priv->summary_filename, g_strerror (errno));
 
 	dir = g_dir_open (bf->priv->dirname, 0, NULL);
@@ -1355,7 +1345,7 @@ e_book_backend_file_remove (EBookBackendSync *backend,
 		while ((name = g_dir_read_name (dir))) {
 			if (select_changes (name)) {
 				gchar *full_path = g_build_filename (bf->priv->dirname, name, NULL);
-				if (-1 == g_unlink (full_path)) {
+				if (g_unlink (full_path) == -1) {
 					g_warning ("failed to remove change db `%s': %s", full_path, g_strerror (errno));
 				}
 				g_free (full_path);
@@ -1365,7 +1355,7 @@ e_book_backend_file_remove (EBookBackendSync *backend,
 		g_dir_close (dir);
 	}
 
-	if (-1 == g_rmdir (bf->priv->dirname))
+	if (g_rmdir (bf->priv->dirname) == -1)
 		g_warning ("failed to remove directory `%s`: %s", bf->priv->dirname, g_strerror (errno));
 
 	/* we may not have actually succeeded in removing the
@@ -1373,6 +1363,8 @@ e_book_backend_file_remove (EBookBackendSync *backend,
 	   it here..  the only time we should return failure is if we
 	   failed to remove the actual data.  a failure should mean
 	   that the addressbook is still valid */
+
+	return TRUE;
 }
 
 static gchar *
@@ -1520,13 +1512,13 @@ e_book_backend_file_class_init (EBookBackendFileClass *klass)
 
 	/* Set the virtual methods. */
 	backend_class->load_source			= e_book_backend_file_load_source;
+	backend_class->remove				= e_book_backend_file_remove;
 	backend_class->get_static_capabilities		= e_book_backend_file_get_static_capabilities;
 	backend_class->start_book_view			= e_book_backend_file_start_book_view;
 	backend_class->stop_book_view			= e_book_backend_file_stop_book_view;
 	backend_class->cancel_operation			= e_book_backend_file_cancel_operation;
 	backend_class->set_mode				= e_book_backend_file_set_mode;
 	backend_class->sync				= e_book_backend_file_sync;
-	sync_class->remove_sync				= e_book_backend_file_remove;
 	sync_class->create_contact_sync			= e_book_backend_file_create_contact;
 	sync_class->remove_contacts_sync		= e_book_backend_file_remove_contacts;
 	sync_class->modify_contact_sync			= e_book_backend_file_modify_contact;
diff --git a/addressbook/backends/google/e-book-backend-google.c b/addressbook/backends/google/e-book-backend-google.c
index 76c1684..358757c 100644
--- a/addressbook/backends/google/e-book-backend-google.c
+++ b/addressbook/backends/google/e-book-backend-google.c
@@ -27,7 +27,9 @@
 
 #include <glib/gi18n-lib.h>
 #include <libedataserver/e-proxy.h>
-#include <libebook/e-vcard.h>
+#include <libedataserver/e-source-offline.h>
+#include <libedataserver/e-source-refresh.h>
+#include <libedataserver/e-source-security.h>
 #include <libebook/e-contact.h>
 #include <libedata-book/e-data-book.h>
 #include <libedata-book/e-data-book-view.h>
@@ -1496,19 +1498,18 @@ e_book_backend_google_get_changes (EBookBackend *backend, EDataBook *book, guint
 }
 
 static void
-e_book_backend_google_remove (EBookBackend *backend, EDataBook *book, guint32 opid)
-{
-	__debug__ (G_STRFUNC);
-	e_data_book_respond_remove (book, opid, NULL);
-}
-
-static void
-e_book_backend_google_load_source (EBookBackend *backend, ESource *source, gboolean only_if_exists, GError **error)
+e_book_backend_google_load_source (EBookBackend *backend,
+                                   ESource *source,
+                                   gboolean only_if_exists,
+                                   GError **error)
 {
 	EBookBackendGooglePrivate *priv = E_BOOK_BACKEND_GOOGLE (backend)->priv;
-	const gchar *refresh_interval_str, *use_ssl_str, *use_cache_str;
-	guint refresh_interval;
+	ESourceOffline *offline_extension;
+	ESourceRefresh *refresh_extension;
+	ESourceSecurity *security_extension;
+	guint interval_in_minutes;
 	gboolean use_ssl, use_cache;
+	const gchar *extension_name;
 
 	__debug__ (G_STRFUNC);
 
@@ -1517,24 +1518,21 @@ e_book_backend_google_load_source (EBookBackend *backend, ESource *source, gbool
 		return;
 	}
 
-	/* Parse various other properties */
-	refresh_interval_str = e_source_get_property (source, "refresh-interval");
-	use_ssl_str = e_source_get_property (source, "ssl");
-	use_cache_str = e_source_get_property (source, "offline_sync");
+	extension_name = E_SOURCE_EXTENSION_OFFLINE;
+	offline_extension = e_source_get_extension (source, extension_name);
 
-	refresh_interval = 3600;
-	if (refresh_interval_str && sscanf (refresh_interval_str, "%u", &refresh_interval) != 1) {
-		g_warning ("Could not parse refresh-interval!");
-		refresh_interval = 3600;
-	}
+	extension_name = E_SOURCE_EXTENSION_REFRESH;
+	refresh_extension = e_source_get_extension (source, extension_name);
+
+	extension_name = E_SOURCE_EXTENSION_SECURITY;
+	security_extension = e_source_get_extension (source, extension_name);
+
+	interval_in_minutes =
+		e_source_refresh_get_interval_minutes (refresh_extension);
 
-	use_ssl = TRUE;
-	if (use_ssl_str && (g_ascii_strcasecmp (use_ssl_str, "false") == 0 || strcmp (use_ssl_str, "0") == 0))
-		use_ssl = FALSE;
+	use_ssl = e_source_security_get_secure (security_extension);
 
-	use_cache = TRUE;
-	if (use_cache_str && (g_ascii_strcasecmp (use_cache_str, "false") == 0 || strcmp (use_cache_str, "0") == 0))
-		use_cache = FALSE;
+	use_cache = e_source_offline_get_stay_synchronized (offline_extension);
 
 	/* Set up our object */
 	priv->groups_by_id = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
@@ -1542,7 +1540,7 @@ e_book_backend_google_load_source (EBookBackend *backend, ESource *source, gbool
 	priv->cancellables = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref);
 	cache_init (backend, use_cache);
 	priv->use_ssl = use_ssl;
-	priv->refresh_interval = refresh_interval;
+	priv->refresh_interval = interval_in_minutes * 60;
 
 	/* Remove and re-add the timeout */
 	if (priv->refresh_id != 0) {
@@ -1686,7 +1684,6 @@ e_book_backend_google_class_init (EBookBackendGoogleClass *klass)
 	backend_class->stop_book_view               = e_book_backend_google_stop_book_view;
 	backend_class->cancel_operation             = e_book_backend_google_cancel_operation;
 	backend_class->set_mode                     = e_book_backend_google_set_mode;
-	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;
 	backend_class->modify_contact               = e_book_backend_google_modify_contact;



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