[evolution-data-server/openismus-work-master: 6/8] EBookBackendFile: Use the new ESourceAddressBookConfig to configure the summary



commit aa3f68bd6c1180b147d99c5963feb8229bbf471c
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Wed Nov 7 17:31:10 2012 +0900

    EBookBackendFile: Use the new ESourceAddressBookConfig to configure the summary

 addressbook/backends/file/e-book-backend-file.c |   77 ++++++++++++++++++++---
 1 files changed, 67 insertions(+), 10 deletions(-)
---
diff --git a/addressbook/backends/file/e-book-backend-file.c b/addressbook/backends/file/e-book-backend-file.c
index 11f8231..1eaf52d 100644
--- a/addressbook/backends/file/e-book-backend-file.c
+++ b/addressbook/backends/file/e-book-backend-file.c
@@ -63,6 +63,13 @@
 #define EDB_ERROR_EX(_code, _msg) e_data_book_create_error (E_DATA_BOOK_STATUS_ ## _code, _msg)
 #define EDB_NOT_OPENED_ERROR      EDB_ERROR(NOT_OPENED)
 
+
+/* This forces the GType to be registered in a way that
+ * avoids a "statement with no effect" compiler warning.
+ * FIXME Use g_type_ensure() once we require GLib 2.34. */
+#define REGISTER_TYPE(type) \
+	(g_type_class_unref (g_type_class_ref (type)))
+
 G_DEFINE_TYPE (EBookBackendFile, e_book_backend_file, E_TYPE_BOOK_BACKEND_SYNC)
 
 struct _EBookBackendFilePrivate {
@@ -1240,6 +1247,12 @@ e_book_backend_file_open (EBookBackendSync *backend,
 	ESource          *source;
 	GError           *local_error = NULL;
 	gboolean          populated;
+	ESourceAddressBookConfig *config;
+	EContactField    *summary_fields = NULL;
+	gint              n_summary_fields = 0;
+	EContactField    *indexed_fields = NULL;
+	EBookIndexType   *index_types = NULL;
+	gint              n_indexed_fields = 0;
 
 	source = e_backend_get_source (E_BACKEND (backend));
 	registry = e_book_backend_get_registry (E_BOOK_BACKEND (backend));
@@ -1248,15 +1261,26 @@ e_book_backend_file_open (EBookBackendSync *backend,
 	filename = g_build_filename (dirname, "addressbook.db", NULL);
 	backup   = g_build_filename (dirname, "addressbook.db.old", NULL);
 
+	REGISTER_TYPE (E_TYPE_SOURCE_ADDRESS_BOOK_CONFIG);
+
+	config         = e_source_get_extension (source, E_SOURCE_EXTENSION_ADDRESS_BOOK_CONFIG);
+	summary_fields = e_source_address_book_config_get_summary_fields  (config, &n_summary_fields);
+	indexed_fields = e_source_address_book_config_get_indexed_fields  (config, &index_types, &n_indexed_fields);
+ 
 	/* The old BDB exists, lets migrate that to sqlite right away
 	 */
 	if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
-		bf->priv->sqlitedb = e_book_backend_sqlitedb_new (
-			dirname,
+		bf->priv->sqlitedb = e_book_backend_sqlitedb_new_full (
+                        dirname,
 			SQLITEDB_EMAIL_ID,
 			SQLITEDB_FOLDER_ID,
 			SQLITEDB_FOLDER_NAME,
 			TRUE,
+			summary_fields,
+			n_summary_fields,
+			indexed_fields,
+			index_types,
+			n_indexed_fields,
 			&local_error);
 
 		if (!bf->priv->sqlitedb) {
@@ -1265,6 +1289,9 @@ e_book_backend_file_open (EBookBackendSync *backend,
 			g_free (dirname);
 			g_free (filename);
 			g_free (backup);
+			g_free (summary_fields);
+			g_free (index_types);
+			g_free (indexed_fields);
 			return;
 		}
 
@@ -1280,7 +1307,10 @@ e_book_backend_file_open (EBookBackendSync *backend,
 			g_free (dirname);
 			g_free (filename);
 			g_free (backup);
-
+			g_free (summary_fields);
+			g_free (index_types);
+			g_free (indexed_fields);
+ 
 			g_object_unref (bf->priv->sqlitedb);
 			bf->priv->sqlitedb = NULL;
 			return;
@@ -1302,6 +1332,9 @@ e_book_backend_file_open (EBookBackendSync *backend,
 			g_free (dirname);
 			g_free (filename);
 			g_free (backup);
+			g_free (summary_fields);
+			g_free (index_types);
+			g_free (indexed_fields);
 			bf->priv->sqlitedb = NULL;
 			return;
 		}
@@ -1321,16 +1354,25 @@ e_book_backend_file_open (EBookBackendSync *backend,
 			g_free (dirname);
 			g_free (filename);
 			g_free (backup);
-			return;
-		}
+			g_free (summary_fields);
+			g_free (index_types);
+			g_free (indexed_fields);
+ 			return;
+ 		}
 
 		/* Create the sqlitedb */
-		bf->priv->sqlitedb = e_book_backend_sqlitedb_new (
-			dirname,
+		bf->priv->sqlitedb = e_book_backend_sqlitedb_new_full (
+                        dirname,
 			SQLITEDB_EMAIL_ID,
 			SQLITEDB_FOLDER_ID,
 			SQLITEDB_FOLDER_NAME,
-			TRUE, &local_error);
+			TRUE,
+			summary_fields,
+			n_summary_fields,
+			indexed_fields,
+			index_types,
+			n_indexed_fields,
+			&local_error);
 
 		if (!bf->priv->sqlitedb) {
 			g_warning (G_STRLOC ": Failed to open sqlitedb: %s", local_error->message);
@@ -1338,8 +1380,11 @@ e_book_backend_file_open (EBookBackendSync *backend,
 			g_free (dirname);
 			g_free (filename);
 			g_free (backup);
-			return;
-		}
+			g_free (summary_fields);
+			g_free (index_types);
+			g_free (indexed_fields);
+ 			return;
+ 		}
 
 		/* An sqlite DB only 'exists' if the populated flag is set */
 		populated = e_book_backend_sqlitedb_get_is_populated (
@@ -1354,6 +1399,9 @@ e_book_backend_file_open (EBookBackendSync *backend,
 			g_free (dirname);
 			g_free (filename);
 			g_free (backup);
+			g_free (summary_fields);
+			g_free (index_types);
+			g_free (indexed_fields);
 
 			g_object_unref (bf->priv->sqlitedb);
 			bf->priv->sqlitedb = NULL;
@@ -1366,6 +1414,9 @@ e_book_backend_file_open (EBookBackendSync *backend,
 				g_free (dirname);
 				g_free (filename);
 				g_free (backup);
+				g_free (summary_fields);
+				g_free (index_types);
+				g_free (indexed_fields);
 				g_object_unref (bf->priv->sqlitedb);
 				bf->priv->sqlitedb = NULL;
 				g_propagate_error (perror, EDB_ERROR (NO_SUCH_BOOK));
@@ -1395,6 +1446,9 @@ e_book_backend_file_open (EBookBackendSync *backend,
 				g_free (dirname);
 				g_free (filename);
 				g_free (backup);
+				g_free (summary_fields);
+				g_free (index_types);
+				g_free (indexed_fields);
 				g_object_unref (bf->priv->sqlitedb);
 				bf->priv->sqlitedb = NULL;
 				return;
@@ -1405,6 +1459,9 @@ e_book_backend_file_open (EBookBackendSync *backend,
 	g_free (dirname);
 	g_free (filename);
 	g_free (backup);
+	g_free (summary_fields);
+	g_free (index_types);
+	g_free (indexed_fields);
 
 	/* Resolve the photo directory here */
 	dirname = e_book_backend_file_extract_path_from_source (



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