diff options
author | Dan Winship <danw@src.gnome.org> | 2000-10-03 02:23:40 +0800 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2000-10-03 02:23:40 +0800 |
commit | 0212cbae5fbe76635365cfff575fd5f2f38b3e35 (patch) | |
tree | e1e9e9e5a1c4ead5c034bcf6a833a59054c05038 /camel/providers/cache/camel-cache-store.c | |
parent | 1c2eec1fd409b7ec7a6742684c678bcd258aec53 (diff) | |
download | gsoc2013-evolution-0212cbae5fbe76635365cfff575fd5f2f38b3e35.tar gsoc2013-evolution-0212cbae5fbe76635365cfff575fd5f2f38b3e35.tar.gz gsoc2013-evolution-0212cbae5fbe76635365cfff575fd5f2f38b3e35.tar.bz2 gsoc2013-evolution-0212cbae5fbe76635365cfff575fd5f2f38b3e35.tar.lz gsoc2013-evolution-0212cbae5fbe76635365cfff575fd5f2f38b3e35.tar.xz gsoc2013-evolution-0212cbae5fbe76635365cfff575fd5f2f38b3e35.tar.zst gsoc2013-evolution-0212cbae5fbe76635365cfff575fd5f2f38b3e35.zip |
More updating... still not usable, or even compilable
svn path=/trunk/; revision=5661
Diffstat (limited to 'camel/providers/cache/camel-cache-store.c')
-rw-r--r-- | camel/providers/cache/camel-cache-store.c | 169 |
1 files changed, 126 insertions, 43 deletions
diff --git a/camel/providers/cache/camel-cache-store.c b/camel/providers/cache/camel-cache-store.c index b779b4ca55..544cca69a1 100644 --- a/camel/providers/cache/camel-cache-store.c +++ b/camel/providers/cache/camel-cache-store.c @@ -45,16 +45,21 @@ #include "md5-utils.h" static CamelServiceClass *service_class = NULL; +#define CS_CLASS(so) CAMEL_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so)) static void finalize (CamelObject *object); static gboolean cache_connect (CamelService *service, CamelException *ex); static gboolean cache_disconnect (CamelService *service, CamelException *ex); +static char *get_path (CamelService *service); +static char *get_name (CamelService *service, gboolean brief); static CamelFolder *get_folder (CamelStore *store, const char *folder_name, gboolean create, CamelException *ex); static void delete_folder (CamelStore *store, const char *folder_name, CamelException *ex); +static void rename_folder (CamelStore *store, const char *old_name, + const char *new_name, CamelException *ex); static char *get_folder_name (CamelStore *store, const char *folder_name, CamelException *ex); static char *get_root_folder_name (CamelStore *store, CamelException *ex); @@ -74,24 +79,18 @@ camel_cache_store_class_init (CamelCacheStoreClass *camel_cache_store_class) /* virtual method overload */ camel_service_class->connect = cache_connect; camel_service_class->disconnect = cache_disconnect; + camel_service_class->get_path = get_path; + camel_service_class->get_name = get_name; camel_store_class->get_folder = get_folder; camel_store_class->delete_folder = delete_folder; + camel_store_class->rename_folder = rename_folder; camel_store_class->get_folder_name = get_folder_name; camel_store_class->get_root_folder_name = get_root_folder_name; camel_store_class->get_default_folder_name = get_default_folder_name; } -static void -camel_cache_store_init (gpointer object, gpointer klass) -{ - CamelService *service = CAMEL_SERVICE (object); - - service->url_flags = CAMEL_SERVICE_URL_NEED_PATH; -} - - CamelType camel_cache_store_get_type (void) { @@ -104,7 +103,7 @@ camel_cache_store_get_type (void) sizeof (CamelCacheStoreClass), (CamelObjectClassInitFunc) camel_cache_store_class_init, NULL, - (CamelObjectInitFunc) camel_cache_store_init, + NULL, (CamelObjectFinalizeFunc) finalize); } @@ -118,6 +117,7 @@ finalize (CamelObject *object) camel_object_unref (CAMEL_OBJECT (cache_store->local)); camel_object_unref (CAMEL_OBJECT (cache_store->remote)); + g_free (cache_store->local_base); } @@ -126,40 +126,38 @@ cache_connect (CamelService *service, CamelException *ex) { CamelCacheStore *cache_store = CAMEL_CACHE_STORE (service); - if (!cache_store->remote) { - cache_store->remote = - camel_session_get_store (service->session, - service->url->path, - ex); - if (camel_exception_is_set (ex)) - return FALSE; - - cache_store->local = XXX; - if (camel_exception_is_set (ex)) - return FALSE; - } - - if (!camel_service_connect (CAMEL_SERVICE (cache_store->remote), ex)) - return FALSE; - if (!camel_service_connect (CAMEL_SERVICE (cache_store->local), ex)) { - camel_service_disconnect (CAMEL_SERVICE (cache_store->remote), - NULL); - return FALSE; - } - - return service_class->connect (service, ex); + return camel_service_connect (CAMEL_SERVICE (cache_store->remote), ex) && + camel_service_connect (CAMEL_SERVICE (cache_store->local), ex); } static gboolean cache_disconnect (CamelService *service, CamelException *ex) { - CamelCacheStore *store = CAMEL_CACHE_STORE (service); + CamelCacheStore *cache_store = CAMEL_CACHE_STORE (service); + + return camel_service_disconnect (CAMEL_SERVICE (cache_store->local), ex) && + camel_service_disconnect (CAMEL_SERVICE (cache_store->remote), ex); +} + +static char * +get_path (CamelService *service) +{ + CamelCacheStore *cache_store = CAMEL_CACHE_STORE (service); + char *path, *subpath; - if (!service_class->disconnect (service, ex)) - return FALSE; + subpath = camel_service_get_path (CAMEL_SERVICE (cache_store->remote)); + path = g_strdup_printf ("cache/%s", subpath); + g_free (subpath); + return path; +} + +static char * +get_name (CamelService *service, gboolean brief) +{ + CamelCacheStore *cache_store = CAMEL_CACHE_STORE (service); - return camel_service_disconnect (CAMEL_SERVICE (store->local), ex) && - camel_service_disconnect (CAMEL_SERVICE (store->remote), ex); + return camel_service_get_name (CAMEL_SERVICE (cache_store->remote), + brief); } static CamelFolder * @@ -167,7 +165,7 @@ get_folder (CamelStore *store, const char *folder_name, gboolean create, CamelException *ex) { CamelCacheStore *cache_store = CAMEL_CACHE_STORE (store); - CamelFolder *rf, *lf; + CamelFolder *parent, *rf, *lf; rf = camel_store_get_folder (cache_store->remote, folder_name, create, ex); @@ -184,7 +182,34 @@ get_folder (CamelStore *store, const char *folder_name, return NULL; } - return camel_cache_folder_new (cache_store, rf, lf, ex); + return camel_cache_folder_new (store, parent, rf, lf, ex); +} + +/* XXX these two need to be better about failure recovery. */ +static void +delete_folder (CamelStore *store, const char *folder_name, + CamelException *ex) +{ + CamelCacheStore *cache_store = CAMEL_CACHE_STORE (store); + + camel_store_delete_folder (cache_store->remote, folder_name, ex); + if (camel_exception_is_set (ex)) + return; + camel_store_delete_folder (cache_store->local, folder_name, NULL); +} + +static void +rename_folder (CamelStore *store, const char *old_name, + const char *new_name, CamelException *ex) +{ + CamelCacheStore *cache_store = CAMEL_CACHE_STORE (store); + + camel_store_rename_folder (cache_store->remote, old_name, + new_name, ex); + if (camel_exception_is_set (ex)) + return; + camel_store_rename_folder (cache_store->local, old_name, + new_name, NULL); } static char * @@ -193,8 +218,8 @@ get_folder_name (CamelStore *store, const char *folder_name, { CamelCacheStore *cache_store = CAMEL_CACHE_STORE (store); - return camel_store_get_folder_name (cache_store->remote, - folder_name, ex); + return CS_CLASS (cache_store->remote)->get_folder_name ( + cache_store->remote, folder_name, ex); } static char * @@ -202,7 +227,8 @@ get_root_folder_name (CamelStore *store, CamelException *ex) { CamelCacheStore *cache_store = CAMEL_CACHE_STORE (store); - return camel_store_get_root_folder_name (cache_store->remote, ex); + return CS_CLASS (cache_store->remote)->get_root_folder_name ( + cache_store->remote, ex); } static char * @@ -210,5 +236,62 @@ get_default_folder_name (CamelStore *store, CamelException *ex) { CamelCacheStore *cache_store = CAMEL_CACHE_STORE (store); - return camel_store_get_default_folder_name (cache_store->remote, ex); + return CS_CLASS (cache_store->remote)->get_default_folder_name ( + cache_store->remote, ex); +} + + +/** + * camel_cache_store_new: + * @remote: a remote store + * @ex: a CamelException + * + * Return value: a CamelCacheStore for the given remote store. + **/ +CamelStore * +camel_cache_store_new (CamelStore *remote, CamelException *ex) +{ + CamelCacheStore *cache_store; + CamelService *remote_service = (CamelService *)remote; + CamelSession *session; + char *url_string; + CamelURL *url; + + session = camel_service_get_session (remote_service); + + url_string = camel_service_get_url (remote_service); + url = camel_url_new (url_string, ex); + g_free (url_string); + + if (!url) + return NULL; + + cache_store = (CamelCacheStore *) + camel_service_new (CAMEL_CACHE_STORE_TYPE, session, + camel_service_get_provider (remote_service), + url, ex); + if (camel_exception_is_set (ex)) { + camel_url_free (url); + return NULL; + } + + cache_store->remote = remote; + camel_object_ref (CAMEL_OBJECT (remote)); + + cache_store->local_base = camel_session_get_storage_path ( + session, (CamelService *)cache_store, ex); + if (camel_exception_is_set (ex)) { + camel_object_unref (CAMEL_OBJECT (cache_store)); + return NULL; + } + + url_string = g_strdup_printf ("mbox:%s", cache_store->local_base); + cache_store->local = camel_session_get_store (session, url_string, ex); + g_free (url_string); + if (camel_exception_is_set (ex)) { + camel_object_unref (CAMEL_OBJECT (cache_store)); + return NULL; + } + + return (CamelStore *)cache_store; } |