[evolution-data-server] Refactor ECalBackendCache.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Refactor ECalBackendCache.
- Date: Thu, 22 Jul 2010 01:23:44 +0000 (UTC)
commit 48edca37c899ac7ea5a6a25fa8f39fcc69c58916
Author: Matthew Barnes <mbarnes redhat com>
Date: Tue Jul 20 21:26:45 2010 -0400
Refactor ECalBackendCache.
ECalBackendCache doesn't need to know the URI of the backend, it just
needs a file name. Backends must now provide the name of the cache
file. This breaks the API, but eliminates duplicate logic.
Couple other miscellaneous functions removed:
e_book_backend_construct()
e_book_backend_cache_exists()
e_book_backend_db_cache_exists()
libedata-book's shared object name is bumped for the API break.
Adapt backends to the new API.
.../backends/google/e-book-backend-google.c | 9 +-
.../backends/groupwise/e-book-backend-groupwise.c | 22 +--
addressbook/backends/ldap/e-book-backend-ldap.c | 8 +-
.../backends/webdav/e-book-backend-webdav.c | 8 +-
addressbook/libedata-book/e-book-backend-cache.c | 193 ++------------------
addressbook/libedata-book/e-book-backend-cache.h | 3 +-
addressbook/libedata-book/e-book-backend.c | 16 +--
addressbook/libedata-book/e-book-backend.h | 1 -
configure.ac | 6 +-
.../libedata-book/libedata-book-sections.txt | 2 -
.../libedata-book/tmpl/e-book-backend-cache.sgml | 16 +--
.../libedata-book/tmpl/e-book-backend.sgml | 9 -
.../libedata-book/tmpl/libedata-book-unused.sgml | 22 +++
13 files changed, 73 insertions(+), 242 deletions(-)
---
diff --git a/addressbook/backends/google/e-book-backend-google.c b/addressbook/backends/google/e-book-backend-google.c
index 111ea0c..826167c 100644
--- a/addressbook/backends/google/e-book-backend-google.c
+++ b/addressbook/backends/google/e-book-backend-google.c
@@ -89,10 +89,17 @@ static void
cache_init (EBookBackend *backend, gboolean on_disk)
{
EBookBackendGooglePrivate *priv = E_BOOK_BACKEND_GOOGLE (backend)->priv;
+ const gchar *cache_dir;
+
+ cache_dir = e_book_backend_get_cache_dir (backend);
if (on_disk) {
+ gchar *filename;
+
+ filename = g_build_filename (cache_dir, "cache.xml", NULL);
priv->cache_type = ON_DISK_CACHE;
- priv->cache.on_disk = e_book_backend_cache_new (priv->username);
+ priv->cache.on_disk = e_book_backend_cache_new (filename);
+ g_free (filename);
} else {
priv->cache_type = IN_MEMORY_CACHE;
priv->cache.in_memory.contacts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
diff --git a/addressbook/backends/groupwise/e-book-backend-groupwise.c b/addressbook/backends/groupwise/e-book-backend-groupwise.c
index 32948ff..1af567f 100644
--- a/addressbook/backends/groupwise/e-book-backend-groupwise.c
+++ b/addressbook/backends/groupwise/e-book-backend-groupwise.c
@@ -3451,15 +3451,17 @@ e_book_backend_groupwise_load_source (EBookBackend *backend,
gchar *book_name;
gchar *uri;
gchar **tokens;
+ const gchar *cache_dir;
const gchar *port;
gint db_error;
DB *db;
DB_ENV *env;
EUri *parsed_uri;
- gint i;
const gchar *use_ssl;
const gchar *offline;
+ cache_dir = e_book_backend_get_cache_dir (backend);
+
if (enable_debug)
printf("\ne_book_backend_groupwise_load_source.. \n");
ebgw = E_BOOK_BACKEND_GROUPWISE (backend);
@@ -3499,24 +3501,12 @@ e_book_backend_groupwise_load_source (EBookBackend *backend,
priv->book_name = book_name;
- for (i = 0; i < strlen (uri); i++) {
- switch (uri[i]) {
- case ':' :
- case '/' :
- uri[i] = '_';
- }
- }
-
g_free (priv->summary_file_name);
- tmp = g_build_filename (
- e_get_user_data_dir (), "addressbook",
- uri, priv->book_name, NULL);
+ tmp = g_build_filename (cache_dir, priv->book_name, NULL);
priv->summary_file_name = g_strconcat (tmp, ".summary", NULL);
g_free (tmp);
- dirname = g_build_filename (
- g_get_user_cache_dir (), "addressbook",
- uri, priv->book_name, NULL);
+ dirname = g_build_filename (cache_dir, priv->book_name, NULL);
filename = g_build_filename (dirname, "cache.db", NULL);
db_error = e_db3_utils_maybe_recover (filename);
@@ -3643,7 +3633,7 @@ e_book_backend_groupwise_load_source (EBookBackend *backend,
}
if (priv->mode == E_DATA_BOOK_MODE_LOCAL)
- if (!e_book_backend_db_cache_exists (priv->original_uri)) {
+ if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
g_free (uri);
e_uri_free (parsed_uri);
g_propagate_error (perror, EDB_ERROR (OFFLINE_UNAVAILABLE));
diff --git a/addressbook/backends/ldap/e-book-backend-ldap.c b/addressbook/backends/ldap/e-book-backend-ldap.c
index 4a621e4..a0bc23b 100644
--- a/addressbook/backends/ldap/e-book-backend-ldap.c
+++ b/addressbook/backends/ldap/e-book-backend-ldap.c
@@ -5021,8 +5021,10 @@ e_book_backend_ldap_load_source (EBookBackend *backend,
gint limit = 100;
gint timeout = 60; /* 1 minute */
gchar *uri;
+ const gchar *cache_dir;
const gchar *str;
const gchar *offline;
+ gchar *filename;
GError *err;
gboolean auth_required;
@@ -5032,6 +5034,7 @@ e_book_backend_ldap_load_source (EBookBackend *backend,
printf ("e_book_backend_ldap_load_source ... \n");
uri = e_source_get_uri (source);
+ cache_dir = e_book_backend_get_cache_dir (backend);
offline = e_source_get_property (source, "offline_sync");
if (offline && g_str_equal (offline, "1"))
@@ -5086,7 +5089,10 @@ e_book_backend_ldap_load_source (EBookBackend *backend,
bl->priv->cache = NULL;
}
- bl->priv->cache = e_book_backend_cache_new (uri);
+ filename = g_build_filename (cache_dir, "cache.xml", NULL);
+ bl->priv->cache = e_book_backend_cache_new (filename);
+ g_free (filename);
+
g_free (uri);
if (bl->priv->mode == E_DATA_BOOK_MODE_LOCAL) {
diff --git a/addressbook/backends/webdav/e-book-backend-webdav.c b/addressbook/backends/webdav/e-book-backend-webdav.c
index 16997ef..3d6dc19 100644
--- a/addressbook/backends/webdav/e-book-backend-webdav.c
+++ b/addressbook/backends/webdav/e-book-backend-webdav.c
@@ -1193,14 +1193,18 @@ e_book_backend_webdav_load_source(EBookBackend *backend,
EBookBackendWebdav *webdav = E_BOOK_BACKEND_WEBDAV(backend);
EBookBackendWebdavPrivate *priv = webdav->priv;
gchar *uri;
+ const gchar *cache_dir;
const gchar *offline;
const gchar *use_ssl;
+ gchar *filename;
SoupSession *session;
SoupURI *suri;
/* will try fetch ctag for the first time, if it fails then sets this to FALSE */
priv->supports_getctag = TRUE;
+ cache_dir = e_book_backend_get_cache_dir (backend);
+
uri = e_source_get_uri(source);
if (uri == NULL) {
g_propagate_error (perror, EDB_ERROR_EX (OTHER_ERROR, "No uri given for addressbook"));
@@ -1270,7 +1274,9 @@ e_book_backend_webdav_load_source(EBookBackend *backend,
return;
}
- priv->cache = e_book_backend_cache_new(priv->uri);
+ filename = g_build_filename (cache_dir, "cache.xml", NULL);
+ priv->cache = e_book_backend_cache_new (filename);
+ g_free (filename);
session = soup_session_sync_new();
g_signal_connect(session, "authenticate", G_CALLBACK(soup_authenticate),
diff --git a/addressbook/libedata-book/e-book-backend-cache.c b/addressbook/libedata-book/e-book-backend-cache.c
index 7f7dffc..f7fd2dd 100644
--- a/addressbook/libedata-book/e-book-backend-cache.c
+++ b/addressbook/libedata-book/e-book-backend-cache.c
@@ -28,181 +28,45 @@
#include "e-book-backend-cache.h"
#include "e-book-backend-sexp.h"
-G_DEFINE_TYPE (EBookBackendCache, e_book_backend_cache, E_TYPE_FILE_CACHE)
+#define E_BOOK_BACKEND_CACHE_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_BOOK_BACKEND_CACHE, EBookBackendCachePrivate))
struct _EBookBackendCachePrivate {
- gchar *uri;
-};
-
-/* Property IDs */
-enum {
- PROP_0,
- PROP_URI
+ gint placeholder;
};
-static GObjectClass *parent_class = NULL;
-
-static gchar *
-get_filename_from_uri (const gchar *uri)
-{
- const gchar *user_cache_dir;
- gchar *mangled_uri, *filename;
-
- user_cache_dir = e_get_user_cache_dir ();
-
- /* Mangle the URI to not contain invalid characters. */
- mangled_uri = g_strdelimit (g_strdup (uri), ":/", '_');
-
- filename = g_build_filename (
- user_cache_dir, "addressbook",
- mangled_uri, "cache.xml", NULL);
-
- g_free (mangled_uri);
-
- return filename;
-}
-
-static void
-e_book_backend_cache_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
-{
- EBookBackendCache *cache;
- EBookBackendCachePrivate *priv;
- gchar *cache_file;
-
- cache = E_BOOK_BACKEND_CACHE (object);
- priv = cache->priv;
-
- switch (property_id) {
- case PROP_URI :
- cache_file = get_filename_from_uri (g_value_get_string (value));
- if (!cache_file)
- break;
-
- g_object_set (G_OBJECT (cache), "filename", cache_file, NULL);
- g_free (cache_file);
-
- if (priv->uri)
- g_free (priv->uri);
- priv->uri = g_value_dup_string (value);
- break;
- default :
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- }
-}
-
-static void
-e_book_backend_cache_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
-{
- EBookBackendCache *cache;
- EBookBackendCachePrivate *priv;
-
- cache = E_BOOK_BACKEND_CACHE (object);
- priv = cache->priv;
-
- switch (property_id) {
- case PROP_URI :
- g_value_set_string (value, priv->uri);
- break;
- default :
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- }
-}
-
-static void
-e_book_backend_cache_finalize (GObject *object)
-{
- EBookBackendCache *cache;
- EBookBackendCachePrivate *priv;
-
- cache = E_BOOK_BACKEND_CACHE (object);
- priv = cache->priv;
-
- if (priv) {
- if (priv->uri) {
- g_free (priv->uri);
- priv->uri = NULL;
- }
-
- g_free (priv);
- cache->priv = NULL;
- }
-
- parent_class->finalize (object);
-}
-
-static GObject *
-e_book_backend_cache_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_properties)
-{
- GObject *obj;
- const gchar *uri;
- gchar *cache_file;
-
- /* Invoke parent constructor. */
- obj = parent_class->constructor (type,
- n_construct_properties,
- construct_properties);
-
- /* extract uid */
- if (!g_ascii_strcasecmp ( g_param_spec_get_name (construct_properties->pspec), "uri")) {
- uri = g_value_get_string (construct_properties->value);
- cache_file = get_filename_from_uri (uri);
- if (cache_file)
- g_object_set (obj, "filename", cache_file, NULL);
- g_free (cache_file);
- }
-
- return obj;
-}
+G_DEFINE_TYPE (EBookBackendCache, e_book_backend_cache, E_TYPE_FILE_CACHE)
static void
-e_book_backend_cache_class_init (EBookBackendCacheClass *klass)
+e_book_backend_cache_class_init (EBookBackendCacheClass *class)
{
- GObjectClass *object_class;
-
- parent_class = g_type_class_peek_parent (klass);
-
- object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = e_book_backend_cache_finalize;
- object_class->set_property = e_book_backend_cache_set_property;
- object_class->get_property = e_book_backend_cache_get_property;
-
- object_class->constructor = e_book_backend_cache_constructor;
- g_object_class_install_property (object_class, PROP_URI,
- g_param_spec_string ("uri", NULL, NULL, "",
- G_PARAM_READABLE | G_PARAM_WRITABLE
- | G_PARAM_CONSTRUCT_ONLY));
+ g_type_class_add_private (class, sizeof (EBookBackendCachePrivate));
}
static void
e_book_backend_cache_init (EBookBackendCache *cache)
{
- EBookBackendCachePrivate *priv;
-
- priv = g_new0 (EBookBackendCachePrivate, 1);
-
- cache->priv = priv;
-
+ cache->priv = E_BOOK_BACKEND_CACHE_GET_PRIVATE (cache);
}
/**
* e_book_backend_cache_new
- * @uri: URI of the backend to be cached.
+ * @filename: file to write cached data
*
- * Creates a new #EBookBackendCache object, which implements a local
- * cache of #EContact objects, useful for remote backends.
+ * Creates a new #EBookBackendCache, which implements a local cache of
+ * #EContact objects, useful for remote backends.
*
- * Returns: A new #EBookBackendCache.
+ * Returns: a new #EBookBackendCache
*/
EBookBackendCache *
-e_book_backend_cache_new (const gchar *uri)
+e_book_backend_cache_new (const gchar *filename)
{
- EBookBackendCache *cache;
+ g_return_val_if_fail (filename != NULL, NULL);
- cache = g_object_new (E_TYPE_BOOK_BACKEND_CACHE, "uri", uri, NULL);
-
- return cache;
+ return g_object_new (
+ E_TYPE_BOOK_BACKEND_CACHE,
+ "filename", filename, NULL);
}
/**
@@ -408,29 +272,6 @@ e_book_backend_cache_search (EBookBackendCache *cache, const gchar *query)
}
/**
- * e_book_backend_cache_exists:
- * @uri: URI for the cache
- *
- * Checks if an #EBookBackendCache exists at @uri.
- *
- * Returns: %TRUE if cache exists, %FALSE if not.
- **/
-gboolean
-e_book_backend_cache_exists (const gchar *uri)
-{
- gchar *file_name;
- gboolean exists = FALSE;
- file_name = get_filename_from_uri (uri);
-
- if (file_name && g_file_test (file_name, G_FILE_TEST_EXISTS)) {
- exists = TRUE;
- g_free (file_name);
- }
-
- return exists;
-}
-
-/**
* e_book_backend_cache_set_populated:
* @cache: an #EBookBackendCache
*
diff --git a/addressbook/libedata-book/e-book-backend-cache.h b/addressbook/libedata-book/e-book-backend-cache.h
index ac7d045..83daa26 100644
--- a/addressbook/libedata-book/e-book-backend-cache.h
+++ b/addressbook/libedata-book/e-book-backend-cache.h
@@ -62,7 +62,7 @@ struct _EBookBackendCacheClass {
GType e_book_backend_cache_get_type (void);
EBookBackendCache *
- e_book_backend_cache_new (const gchar *uri);
+ e_book_backend_cache_new (const gchar *filename);
EContact * e_book_backend_cache_get_contact(EBookBackendCache *cache,
const gchar *uid);
gboolean e_book_backend_cache_add_contact(EBookBackendCache *cache,
@@ -76,7 +76,6 @@ gboolean e_book_backend_cache_check_contact
GList * e_book_backend_cache_get_contacts
(EBookBackendCache *cache,
const gchar *query);
-gboolean e_book_backend_cache_exists (const gchar *uri);
void e_book_backend_cache_set_populated
(EBookBackendCache *cache);
gboolean e_book_backend_cache_is_populated
diff --git a/addressbook/libedata-book/e-book-backend.c b/addressbook/libedata-book/e-book-backend.c
index 524b075..59ca595 100644
--- a/addressbook/libedata-book/e-book-backend.c
+++ b/addressbook/libedata-book/e-book-backend.c
@@ -194,22 +194,8 @@ e_book_backend_init (EBookBackend *backend)
}
/**
- * e_book_backend_construct:
- * @backend: an #EBookBackend
- *
- * Does nothing.
- *
- * Returns: %TRUE.
- **/
-gboolean
-e_book_backend_construct (EBookBackend *backend)
-{
- return TRUE;
-}
-
-/**
* e_book_backend_get_cache_dir:
- * @backend: en #EBookBackend
+ * @backend: an #EBookBackend
*
* Returns the cache directory for the given backend.
*
diff --git a/addressbook/libedata-book/e-book-backend.h b/addressbook/libedata-book/e-book-backend.h
index 9a01a3a..6d96b1a 100644
--- a/addressbook/libedata-book/e-book-backend.h
+++ b/addressbook/libedata-book/e-book-backend.h
@@ -81,7 +81,6 @@ struct _EBookBackendClass {
void (*_pas_reserved4) (void);
};
-gboolean e_book_backend_construct (EBookBackend *backend);
const gchar *e_book_backend_get_cache_dir (EBookBackend *backend);
void e_book_backend_set_cache_dir (EBookBackend *backend,
const gchar *cache_dir);
diff --git a/configure.ac b/configure.ac
index 5b3108d..bbfbfb5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -102,9 +102,9 @@ LIBEDATACAL_CURRENT=10
LIBEDATACAL_REVISION=0
LIBEDATACAL_AGE=0
-LIBEDATABOOK_CURRENT=7
-LIBEDATABOOK_REVISION=1
-LIBEDATABOOK_AGE=4
+LIBEDATABOOK_CURRENT=8
+LIBEDATABOOK_REVISION=0
+LIBEDATABOOK_AGE=0
LIBEBOOK_CURRENT=13
LIBEBOOK_REVISION=1
diff --git a/docs/reference/addressbook/libedata-book/libedata-book-sections.txt b/docs/reference/addressbook/libedata-book/libedata-book-sections.txt
index 381349d..7c77b88 100644
--- a/docs/reference/addressbook/libedata-book/libedata-book-sections.txt
+++ b/docs/reference/addressbook/libedata-book/libedata-book-sections.txt
@@ -31,7 +31,6 @@ e_book_backend_sync_get_type
<FILE>e-book-backend</FILE>
<TITLE>EBookBackend</TITLE>
EBookBackend
-e_book_backend_construct
e_book_backend_get_cache_dir
e_book_backend_set_cache_dir
e_book_backend_load_source
@@ -166,7 +165,6 @@ e_book_backend_cache_add_contact
e_book_backend_cache_remove_contact
e_book_backend_cache_check_contact
e_book_backend_cache_get_contacts
-e_book_backend_cache_exists
e_book_backend_cache_set_populated
e_book_backend_cache_is_populated
e_book_backend_cache_set_time
diff --git a/docs/reference/addressbook/libedata-book/tmpl/e-book-backend-cache.sgml b/docs/reference/addressbook/libedata-book/tmpl/e-book-backend-cache.sgml
index a584e7f..a066987 100644
--- a/docs/reference/addressbook/libedata-book/tmpl/e-book-backend-cache.sgml
+++ b/docs/reference/addressbook/libedata-book/tmpl/e-book-backend-cache.sgml
@@ -26,17 +26,12 @@ EBookBackendCache
</para>
-<!-- ##### ARG EBookBackendCache:uri ##### -->
-<para>
-
-</para>
-
<!-- ##### FUNCTION e_book_backend_cache_new ##### -->
<para>
</para>
- uri:
+ filename:
@Returns:
@@ -90,15 +85,6 @@ EBookBackendCache
@Returns:
-<!-- ##### FUNCTION e_book_backend_cache_exists ##### -->
-<para>
-
-</para>
-
- uri:
- Returns:
-
-
<!-- ##### FUNCTION e_book_backend_cache_set_populated ##### -->
<para>
diff --git a/docs/reference/addressbook/libedata-book/tmpl/e-book-backend.sgml b/docs/reference/addressbook/libedata-book/tmpl/e-book-backend.sgml
index 3e0b8cb..3dbea7d 100644
--- a/docs/reference/addressbook/libedata-book/tmpl/e-book-backend.sgml
+++ b/docs/reference/addressbook/libedata-book/tmpl/e-book-backend.sgml
@@ -38,15 +38,6 @@ EBookBackend
</para>
-<!-- ##### FUNCTION e_book_backend_construct ##### -->
-<para>
-
-</para>
-
- backend:
- Returns:
-
-
<!-- ##### FUNCTION e_book_backend_get_cache_dir ##### -->
<para>
diff --git a/docs/reference/addressbook/libedata-book/tmpl/libedata-book-unused.sgml b/docs/reference/addressbook/libedata-book/tmpl/libedata-book-unused.sgml
index 0481b2b..81e2ad8 100644
--- a/docs/reference/addressbook/libedata-book/tmpl/libedata-book-unused.sgml
+++ b/docs/reference/addressbook/libedata-book/tmpl/libedata-book-unused.sgml
@@ -46,6 +46,12 @@ e-data-book-marshal
e-data-book-types
+<!-- ##### ARG EBookBackendCache:uri ##### -->
+<para>
+
+</para>
+
+
<!-- ##### STRUCT EBookBackendCachePrivate ##### -->
<para>
@@ -164,6 +170,22 @@ e-data-book-types
</para>
+<!-- ##### FUNCTION e_book_backend_cache_exists ##### -->
+<para>
+
+</para>
+
+ uri:
+ Returns:
+
+<!-- ##### FUNCTION e_book_backend_construct ##### -->
+<para>
+
+</para>
+
+ backend:
+ Returns:
+
<!-- ##### FUNCTION e_data_book_factory_activate ##### -->
<para>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]