[evolution-mapi] Differentiate between user and system folders in local cache
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-mapi] Differentiate between user and system folders in local cache
- Date: Tue, 14 Feb 2012 08:11:25 +0000 (UTC)
commit e9f1d18e5a2eadfe0eba18acff1d17876d5a68f5
Author: Milan Crha <mcrha redhat com>
Date: Tue Feb 14 09:11:10 2012 +0100
Differentiate between user and system folders in local cache
src/camel/camel-mapi-folder.c | 17 +++++++++-----
src/camel/camel-mapi-store.c | 48 +++++++++++++++++++++++++++++++++++++---
2 files changed, 55 insertions(+), 10 deletions(-)
---
diff --git a/src/camel/camel-mapi-folder.c b/src/camel/camel-mapi-folder.c
index f573165..844cf50 100644
--- a/src/camel/camel-mapi-folder.c
+++ b/src/camel/camel-mapi-folder.c
@@ -1957,8 +1957,11 @@ camel_mapi_folder_init (CamelMapiFolder *mapi_folder)
}
CamelFolder *
-camel_mapi_folder_new (CamelStore *store, const gchar *folder_name, const gchar *folder_dir,
- guint32 flags, GError **error)
+camel_mapi_folder_new (CamelStore *store,
+ const gchar *folder_name,
+ const gchar *folder_dir,
+ guint32 flags,
+ GError **error)
{
CamelFolder *folder = NULL;
@@ -1985,8 +1988,10 @@ camel_mapi_folder_new (CamelStore *store, const gchar *folder_name, const gchar
folder = g_object_new (
CAMEL_TYPE_MAPI_FOLDER,
- "display-name", short_name, "full-name", folder_name,
- "parent-store", store, NULL);
+ "display-name", short_name,
+ "full-name", folder_name,
+ "parent-store", store,
+ NULL);
mapi_folder = CAMEL_MAPI_FOLDER(folder);
@@ -2002,12 +2007,12 @@ camel_mapi_folder_new (CamelStore *store, const gchar *folder_name, const gchar
}
/* set/load persistent state */
- state_file = g_strdup_printf ("%s/%s/cmeta", folder_dir, folder_name);
+ state_file = g_build_filename (folder_dir, short_name, "cmeta", NULL);
camel_object_set_state_filename (CAMEL_OBJECT (folder), state_file);
g_free(state_file);
camel_object_state_read (CAMEL_OBJECT (folder));
- state_file = g_strdup_printf ("%s/%s", folder_dir, folder_name);
+ state_file = g_build_filename (folder_dir, short_name, NULL);
mapi_folder->cache = camel_data_cache_new (state_file, error);
g_free (state_file);
if (!mapi_folder->cache) {
diff --git a/src/camel/camel-mapi-store.c b/src/camel/camel-mapi-store.c
index 4760bf9..1a967d5 100644
--- a/src/camel/camel-mapi-store.c
+++ b/src/camel/camel-mapi-store.c
@@ -1037,6 +1037,44 @@ mapi_store_can_refresh_folder (CamelStore *store,
return CAMEL_STORE_CLASS(camel_mapi_store_parent_class)->can_refresh_folder (store, info, error) || check_all;
}
+static gchar *
+mapi_build_folder_dir (const gchar *user_cache_dir,
+ const gchar *folder_name)
+{
+ GString *path;
+ gchar **elems;
+ gint ii;
+
+ g_return_val_if_fail (user_cache_dir != NULL, NULL);
+ g_return_val_if_fail (*user_cache_dir != 0, NULL);
+ g_return_val_if_fail (folder_name != NULL, NULL);
+
+ elems = g_strsplit (folder_name, "/", -1);
+ g_return_val_if_fail (elems != NULL, NULL);
+
+ path = g_string_new (user_cache_dir);
+ if (path->str[path->len - 1] != G_DIR_SEPARATOR)
+ g_string_append_c (path, G_DIR_SEPARATOR);
+ g_string_append (path, "folders");
+
+ for (ii = 0; elems[ii]; ii++) {
+ if (path->str[path->len - 1] != G_DIR_SEPARATOR)
+ g_string_append_c (path, G_DIR_SEPARATOR);
+
+ if (ii != 0) {
+ g_string_append (path, "sub");
+ g_string_append_c (path, G_DIR_SEPARATOR);
+ }
+
+ if (elems[ii + 1])
+ g_string_append (path, elems[ii]);
+ }
+
+ g_strfreev (elems);
+
+ return g_string_free (path, FALSE);
+}
+
static CamelFolder *
mapi_store_get_folder_sync (CamelStore *store,
const gchar *folder_name,
@@ -1049,7 +1087,7 @@ mapi_store_get_folder_sync (CamelStore *store,
CamelStoreInfo *si;
CamelFolder *folder;
const gchar *user_cache_dir;
- gchar *storage_path;
+ gchar *folder_dir;
si = camel_store_summary_path (mapi_store->summary, folder_name);
if (!si && (flags & CAMEL_STORE_FOLDER_CREATE) == CAMEL_STORE_FOLDER_CREATE) {
@@ -1082,9 +1120,11 @@ mapi_store_get_folder_sync (CamelStore *store,
service = CAMEL_SERVICE (store);
user_cache_dir = camel_service_get_user_cache_dir (service);
- storage_path = g_build_filename (user_cache_dir, "folders", NULL);
- folder = camel_mapi_folder_new (store, folder_name, storage_path, flags, error);
- g_free (storage_path);
+ folder_dir = mapi_build_folder_dir (user_cache_dir, folder_name);
+ g_return_val_if_fail (folder_dir != NULL, NULL);
+
+ folder = camel_mapi_folder_new (store, folder_name, folder_dir, flags, error);
+ g_free (folder_dir);
return folder;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]