[evolution-data-server/account-mgmt: 12/30] Add an ESource extension for the vcf backend.



commit 0ef828e2c26c55f2ac617ed9163b50681cd2366d
Author: Matthew Barnes <mbarnes redhat com>
Date:   Thu Nov 18 18:53:48 2010 -0500

    Add an ESource extension for the vcf backend.

 addressbook/backends/vcf/Makefile.am               |    4 +-
 .../backends/vcf/e-book-backend-vcf-factory.c      |    8 +-
 addressbook/backends/vcf/e-book-backend-vcf.c      |   33 ++--
 addressbook/backends/vcf/e-source-vcf.c            |  154 ++++++++++++++++++++
 addressbook/backends/vcf/e-source-vcf.h            |   68 +++++++++
 5 files changed, 246 insertions(+), 21 deletions(-)
---
diff --git a/addressbook/backends/vcf/Makefile.am b/addressbook/backends/vcf/Makefile.am
index d8159ae..53db599 100644
--- a/addressbook/backends/vcf/Makefile.am
+++ b/addressbook/backends/vcf/Makefile.am
@@ -12,7 +12,9 @@ libebookbackendvcf_la_CPPFLAGS = \
 libebookbackendvcf_la_SOURCES =			\
 	e-book-backend-vcf.c			\
 	e-book-backend-vcf.h			\
-	e-book-backend-vcf-factory.c
+	e-book-backend-vcf-factory.c		\
+	e-source-vcf.c				\
+	e-source-vcf.h
 
 libebookbackendvcf_la_LIBADD =						\
 	$(top_builddir)/addressbook/libebook/libebook-1.2.la		\
diff --git a/addressbook/backends/vcf/e-book-backend-vcf-factory.c b/addressbook/backends/vcf/e-book-backend-vcf-factory.c
index cc3e716..b7369f4 100644
--- a/addressbook/backends/vcf/e-book-backend-vcf-factory.c
+++ b/addressbook/backends/vcf/e-book-backend-vcf-factory.c
@@ -28,19 +28,21 @@
 #include "libebackend/e-data-server-module.h"
 #include "libedata-book/e-book-backend-factory.h"
 #include "e-book-backend-vcf.h"
+#include "e-source-vcf.h"
 
 E_BOOK_BACKEND_FACTORY_SIMPLE (vcf, VCF, e_book_backend_vcf_new)
 
 static GType  vcf_type;
 
 void
-eds_module_initialize (GTypeModule *module)
+eds_module_initialize (GTypeModule *type_module)
 {
-	vcf_type = _vcf_factory_get_type (module);
+	e_source_vcf_type_register (type_module);
+	vcf_type = _vcf_factory_get_type (type_module);
 }
 
 void
-eds_module_shutdown   (void)
+eds_module_shutdown (void)
 {
 }
 
diff --git a/addressbook/backends/vcf/e-book-backend-vcf.c b/addressbook/backends/vcf/e-book-backend-vcf.c
index 29c8b5e..ce522c5 100644
--- a/addressbook/backends/vcf/e-book-backend-vcf.c
+++ b/addressbook/backends/vcf/e-book-backend-vcf.c
@@ -50,6 +50,7 @@
 #include "libedata-book/e-book-backend-sexp.h"
 
 #include "e-book-backend-vcf.h"
+#include "e-source-vcf.h"
 
 #define PAS_ID_PREFIX "pas-id-"
 #define FILE_FLUSH_TIMEOUT 5000
@@ -531,14 +532,6 @@ e_book_backend_vcf_stop_book_view (EBookBackend  *backend,
 		g_thread_join (closure->thread);
 }
 
-static gchar *
-e_book_backend_vcf_extract_path_from_uri (const gchar *uri)
-{
-	g_assert (g_ascii_strncasecmp (uri, "vcf://", 6) == 0);
-
-	return g_strdup (uri + 6);
-}
-
 static void
 e_book_backend_vcf_authenticate_user (EBookBackendSync *backend,
 				      EDataBook *book,
@@ -593,14 +586,16 @@ e_book_backend_vcf_load_source (EBookBackend             *backend,
 				GError                  **perror)
 {
 	EBookBackendVCF *bvcf = E_BOOK_BACKEND_VCF (backend);
-	gchar           *dirname;
+	ESourceVCF *vcf_extension;
+	const gchar *extension_name;
+	const gchar *dirname;
 	gboolean        writable = FALSE;
-	gchar          *uri;
 	gint fd;
 
-	uri = e_source_get_uri (source);
+	extension_name = E_SOURCE_EXTENSION_VCF_BACKEND;
+	vcf_extension = e_source_get_extension (source, extension_name);
 
-	dirname = e_book_backend_vcf_extract_path_from_uri (uri);
+	dirname = e_source_vcf_get_path (vcf_extension);
 	bvcf->priv->filename = g_build_filename (dirname, "addressbook.vcf", NULL);
 
 	fd = g_open (bvcf->priv->filename, O_RDWR | O_BINARY, 0);
@@ -650,10 +645,13 @@ e_book_backend_vcf_load_source (EBookBackend             *backend,
 	}
 
 	if (fd == -1) {
-		g_warning ("Failed to open addressbook at uri `%s'", uri);
+		g_warning ("Failed to open addressbook at `%s'", dirname);
 		g_warning ("error == %s", g_strerror(errno));
-		g_propagate_error (perror, e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR, "Failed to open addressbook at uri '%s': %s", uri, g_strerror (errno)));
-		g_free (uri);
+		g_propagate_error (
+			perror, e_data_book_create_error_fmt (
+			E_DATA_BOOK_STATUS_OTHER_ERROR,
+			"Failed to open addressbook at '%s': %s",
+			dirname, g_strerror (errno)));
 		return;
 	}
 
@@ -661,8 +659,6 @@ e_book_backend_vcf_load_source (EBookBackend             *backend,
 
 	e_book_backend_set_is_loaded (backend, TRUE);
 	e_book_backend_set_is_writable (backend, writable);
-
-	g_free (uri);
 }
 
 static gchar *
@@ -759,6 +755,9 @@ e_book_backend_vcf_class_init (EBookBackendVCFClass *klass)
 	sync_class->get_supported_fields_sync  = e_book_backend_vcf_get_supported_fields;
 
 	object_class->dispose = e_book_backend_vcf_dispose;
+
+	/* Register our ESource extension. */
+	E_TYPE_SOURCE_VCF;
 }
 
 static void
diff --git a/addressbook/backends/vcf/e-source-vcf.c b/addressbook/backends/vcf/e-source-vcf.c
new file mode 100644
index 0000000..1d68cf3
--- /dev/null
+++ b/addressbook/backends/vcf/e-source-vcf.c
@@ -0,0 +1,154 @@
+/*
+ * e-source-vcf.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "e-source-vcf.h"
+
+#define E_SOURCE_VCF_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), E_TYPE_SOURCE_VCF, ESourceVCFPrivate))
+
+struct _ESourceVCFPrivate {
+	gchar *path;
+};
+
+enum {
+	PROP_0,
+	PROP_PATH
+};
+
+G_DEFINE_DYNAMIC_TYPE (
+	ESourceVCF,
+	e_source_vcf,
+	E_TYPE_SOURCE_EXTENSION)
+
+static void
+source_vcf_set_property (GObject *object,
+                         guint property_id,
+                         const GValue *value,
+                         GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_PATH:
+			e_source_vcf_set_path (
+				E_SOURCE_VCF (object),
+				g_value_get_string (value));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+source_vcf_get_property (GObject *object,
+                         guint property_id,
+                         GValue *value,
+                         GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_PATH:
+			g_value_set_string (
+				value,
+				e_source_vcf_get_path (
+				E_SOURCE_VCF (object)));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+source_vcf_finalize (GObject *object)
+{
+	ESourceVCFPrivate *priv;
+
+	priv = E_SOURCE_VCF_GET_PRIVATE (object);
+
+	g_free (priv->path);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (e_source_vcf_parent_class)->finalize (object);
+}
+
+static void
+e_source_vcf_class_init (ESourceVCFClass *class)
+{
+	GObjectClass *object_class;
+	ESourceExtensionClass *extension_class;
+
+	g_type_class_add_private (class, sizeof (ESourceVCFPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->set_property = source_vcf_set_property;
+	object_class->get_property = source_vcf_get_property;
+	object_class->finalize = source_vcf_finalize;
+
+	extension_class = E_SOURCE_EXTENSION_CLASS (class);
+	extension_class->name = E_SOURCE_EXTENSION_VCF_BACKEND;
+
+	g_object_class_install_property (
+		object_class,
+		PROP_PATH,
+		g_param_spec_string (
+			"path",
+			"Path",
+			"Path to VCF file",
+			FALSE,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			E_SOURCE_PARAM_SETTING));
+}
+
+static void
+e_source_vcf_class_finalize (ESourceVCFClass *class)
+{
+}
+
+static void
+e_source_vcf_init (ESourceVCF *extension)
+{
+	extension->priv = E_SOURCE_VCF_GET_PRIVATE (extension);
+}
+
+void
+e_source_vcf_type_register (GTypeModule *type_module)
+{
+	/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
+	 *     function, so we have to wrap it with a public function in
+	 *     order to register types from a separate compilation unit. */
+	e_source_vcf_register_type (type_module);
+}
+
+const gchar *
+e_source_vcf_get_path (ESourceVCF *extension)
+{
+	g_return_val_if_fail (E_IS_SOURCE_VCF (extension), FALSE);
+
+	return extension->priv->path;
+}
+
+void
+e_source_vcf_set_path (ESourceVCF *extension,
+                       const gchar *path)
+{
+	g_return_if_fail (E_IS_SOURCE_VCF (extension));
+
+	g_free (extension->priv->path);
+	extension->priv->path = g_strdup (path);
+
+	g_object_notify (G_OBJECT (extension), "path");
+}
diff --git a/addressbook/backends/vcf/e-source-vcf.h b/addressbook/backends/vcf/e-source-vcf.h
new file mode 100644
index 0000000..4ae23f7
--- /dev/null
+++ b/addressbook/backends/vcf/e-source-vcf.h
@@ -0,0 +1,68 @@
+/*
+ * e-source-vcf.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef E_SOURCE_VCF_H
+#define E_SOURCE_VCF_H
+
+#include <libedataserver/e-source-extension.h>
+
+/* Standard GObject macros */
+#define E_TYPE_SOURCE_VCF \
+	(e_source_vcf_get_type ())
+#define E_SOURCE_VCF(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), E_TYPE_SOURCE_VCF, ESourceVCF))
+#define E_SOURCE_VCF_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), E_TYPE_SOURCE_VCF, ESourceVCFClass))
+#define E_IS_SOURCE_VCF(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), E_TYPE_SOURCE_VCF))
+#define E_IS_SOURCE_VCF_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), E_TYPE_SOURCE_VCF))
+#define E_SOURCE_VCF_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), E_TYPE_SOURCE_VCF, ESourceVCFClass))
+
+#define E_SOURCE_EXTENSION_VCF_BACKEND "VCF Backend"
+
+G_BEGIN_DECLS
+
+typedef struct _ESourceVCF ESourceVCF;
+typedef struct _ESourceVCFClass ESourceVCFClass;
+typedef struct _ESourceVCFPrivate ESourceVCFPrivate;
+
+struct _ESourceVCF {
+	ESourceExtension parent;
+	ESourceVCFPrivate *priv;
+};
+
+struct _ESourceVCFClass {
+	ESourceExtensionClass parent_class;
+};
+
+GType		e_source_vcf_get_type		(void);
+void		e_source_vcf_type_register	(GTypeModule *type_module);
+const gchar *	e_source_vcf_get_path		(ESourceVCF *extension);
+void		e_source_vcf_set_path		(ESourceVCF *extension,
+						 const gchar *path);
+
+G_END_DECLS
+
+#endif /* E_SOURCE_VCF_H */



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