aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--camel/ChangeLog19
-rw-r--r--camel/camel-folder.c41
-rw-r--r--camel/camel-folder.h17
-rw-r--r--camel/camel-store.c229
-rw-r--r--camel/camel-store.h39
-rw-r--r--camel/providers/mbox/camel-mbox-store.c26
-rw-r--r--camel/providers/pop3/camel-pop3-store.c31
7 files changed, 287 insertions, 115 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 28bc79c521..8a9babf597 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,22 @@
+2000-04-06 Dan Winship <danw@helixcode.com>
+
+ * camel-store.[ch]: Reorganize the folder-fetching methods and
+ implement a folder cache so that multiple requests for the same
+ folder will yield the same CamelFolder object (as long as it
+ remains active). Includes some code to remove no-longer-active
+ folders from the cache, but it doesn't get used since nothing is
+ ever unref'ed in Camel right now...
+
+ * providers/mbox/camel-mbox-store.c:
+ * providers/pop3/camel-pop3-store.c: update for CamelStore
+ changes.
+
+ * camel-folder.[ch]: Remove the (unused) CamelException argument
+ from camel_folder_get_name and camel_folder_get_full_name.
+ (camel_folder_set_name): make this go away since changing a
+ folder's name after it has been created could result in it
+ conflicting with a separately-issued folder.
+
2000-04-05 Dan Winship <danw@helixcode.com>
* g_url_new really wanted to take a CamelException. So, rename
diff --git a/camel/camel-folder.c b/camel/camel-folder.c
index e6ab27b876..dffbb7d011 100644
--- a/camel/camel-folder.c
+++ b/camel/camel-folder.c
@@ -70,9 +70,8 @@ static void _close_async (CamelFolder *folder,
static void _set_name (CamelFolder *folder,
const gchar *name,
CamelException *ex);
-static const gchar *_get_name (CamelFolder *folder,
- CamelException *ex);
-static const gchar *_get_full_name (CamelFolder *folder, CamelException *ex);
+static const gchar *_get_name (CamelFolder *folder);
+static const gchar *_get_full_name (CamelFolder *folder);
static gboolean _can_hold_folders (CamelFolder *folder);
@@ -270,7 +269,7 @@ _init (CamelFolder *folder, CamelStore *parent_store,
folder->open_mode = FOLDER_OPEN_UNKNOWN;
folder->open_state = FOLDER_CLOSE;
folder->separator = separator;
- camel_folder_set_name (folder, name, ex);
+ CF_CLASS (folder)->set_name (folder, name, ex);
}
@@ -462,8 +461,7 @@ _set_name (CamelFolder *folder,
if (folder->parent_folder) {
parent_full_name =
- camel_folder_get_full_name (folder->parent_folder, ex);
- if (camel_exception_get_id (ex)) return;
+ camel_folder_get_full_name (folder->parent_folder);
full_name = g_strdup_printf ("%s%c%s", parent_full_name,
folder->separator, name);
@@ -479,24 +477,9 @@ _set_name (CamelFolder *folder,
}
-/**
- * camel_folder_set_name:set the (short) name of the folder
- * @folder: folder
- * @name: new name of the folder
- * @ex: exception object
- **/
-void
-camel_folder_set_name (CamelFolder *folder, const gchar *name,
- CamelException *ex)
-{
- g_assert (folder != NULL);
- CF_CLASS (folder)->set_name (folder, name, ex);
-}
-
-
static const gchar *
-_get_name (CamelFolder *folder, CamelException *ex)
+_get_name (CamelFolder *folder)
{
return folder->name;
}
@@ -512,16 +495,16 @@ _get_name (CamelFolder *folder, CamelException *ex)
* Return value: name of the folder
**/
const gchar *
-camel_folder_get_name (CamelFolder *folder, CamelException *ex)
+camel_folder_get_name (CamelFolder *folder)
{
g_assert (folder != NULL);
- return CF_CLASS (folder)->get_name (folder, ex);
+ return CF_CLASS (folder)->get_name (folder);
}
static const gchar *
-_get_full_name (CamelFolder *folder, CamelException *ex)
+_get_full_name (CamelFolder *folder)
{
return folder->full_name;
}
@@ -535,10 +518,10 @@ _get_full_name (CamelFolder *folder, CamelException *ex)
* Return value: full name of the folder
**/
const gchar *
-camel_folder_get_full_name (CamelFolder *folder, CamelException *ex)
+camel_folder_get_full_name (CamelFolder *folder)
{
g_assert (folder != NULL);
- return CF_CLASS (folder)->get_full_name (folder, ex);
+ return CF_CLASS (folder)->get_full_name (folder);
}
@@ -648,9 +631,7 @@ _get_subfolder (CamelFolder *folder,
g_assert (folder->parent_store != NULL);
- current_folder_full_name = camel_folder_get_full_name (folder, ex);
- if (camel_exception_get_id (ex)) return NULL;
-
+ current_folder_full_name = camel_folder_get_full_name (folder);
full_name = g_strdup_printf ("%s%c%s", current_folder_full_name,
folder->separator, folder_name);
diff --git a/camel/camel-folder.h b/camel/camel-folder.h
index c6a36cd3a7..9a717e3db6 100644
--- a/camel/camel-folder.h
+++ b/camel/camel-folder.h
@@ -115,11 +115,9 @@ typedef struct {
const gchar *name,
CamelException *ex);
- const gchar * (*get_name) (CamelFolder *folder,
- CamelException *ex);
+ const gchar * (*get_name) (CamelFolder *folder);
- const gchar * (*get_full_name) (CamelFolder *folder,
- CamelException *ex);
+ const gchar * (*get_full_name) (CamelFolder *folder);
gboolean (*can_hold_folders) (CamelFolder *folder);
@@ -253,14 +251,9 @@ GList * camel_folder_expunge (CamelFolder *folder,
CamelException *ex);
-/* folder name manipulation operations */
-void camel_folder_set_name (CamelFolder *folder,
- const gchar *name,
- CamelException *ex);
-const gchar * camel_folder_get_name (CamelFolder *folder,
- CamelException *ex);
-const gchar * camel_folder_get_full_name (CamelFolder *folder,
- CamelException *ex);
+/* folder name operations */
+const gchar * camel_folder_get_name (CamelFolder *folder);
+const gchar * camel_folder_get_full_name (CamelFolder *folder);
/* various properties accessors */
diff --git a/camel/camel-store.c b/camel/camel-store.c
index a8a72c4d25..58079bdab6 100644
--- a/camel/camel-store.c
+++ b/camel/camel-store.c
@@ -1,10 +1,11 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camelStore.c : Abstract class for an email store */
+/* camel-store.c : Abstract class for an email store */
/*
*
- * Author :
+ * Authors:
* Bertrand Guiheneuf <bertrand@helixcode.com>
+ * Dan Winship <danw@helixcode.com>
*
* Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com)
*
@@ -25,6 +26,7 @@
*/
#include <config.h>
#include "camel-store.h"
+#include "camel-folder.h"
#include "camel-exception.h"
#include "camel-log.h"
@@ -33,35 +35,50 @@ static CamelServiceClass *parent_class = NULL;
/* Returns the class for a CamelStore */
#define CS_CLASS(so) CAMEL_STORE_CLASS (GTK_OBJECT(so)->klass)
-static CamelFolder *_get_root_folder(CamelStore *store, CamelException *ex);
-static CamelFolder *_get_default_folder(CamelStore *store, CamelException *ex);
-static CamelFolder *_get_folder (CamelStore *store, const gchar *folder_name, CamelException *ex);
+static CamelFolder *get_folder (CamelStore *store, const char *folder_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);
+static char *get_default_folder_name (CamelStore *store, CamelException *ex);
+
+static CamelFolder *lookup_folder (CamelStore *store, const char *folder_name);
+static void cache_folder (CamelStore *store, const char *folder_name,
+ CamelFolder *folder);
+static void uncache_folder (CamelStore *store, CamelFolder *folder);
+
+static void finalize (GtkObject *object);
static void
camel_store_class_init (CamelStoreClass *camel_store_class)
{
+ GtkObjectClass *gtk_object_class =
+ GTK_OBJECT_CLASS (camel_store_class);
parent_class = gtk_type_class (camel_service_get_type ());
-
- /* virtual method definition */
- camel_store_class->get_folder = _get_folder;
- camel_store_class->get_root_folder = _get_root_folder;
- camel_store_class->get_default_folder = _get_default_folder;
-}
-
-
-
+ /* virtual method definition */
+ camel_store_class->get_folder = get_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;
+ camel_store_class->lookup_folder = lookup_folder;
+ camel_store_class->cache_folder = cache_folder;
+ camel_store_class->uncache_folder = uncache_folder;
+ /* virtual method override */
+ gtk_object_class->finalize = finalize;
+}
GtkType
camel_store_get_type (void)
{
static GtkType camel_store_type = 0;
-
- if (!camel_store_type) {
- GtkTypeInfo camel_store_info =
+
+ if (!camel_store_type) {
+ GtkTypeInfo camel_store_info =
{
"CamelStore",
sizeof (CamelStore),
@@ -72,73 +89,187 @@ camel_store_get_type (void)
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
-
+
camel_store_type = gtk_type_unique (CAMEL_SERVICE_TYPE, &camel_store_info);
}
-
+
return camel_store_type;
}
+static void
+finalize (GtkObject *object)
+{
+ CamelStore *store = CAMEL_STORE (object);
+ if (store->folders) {
+ if (g_hash_table_size (store->folders) != 0) {
+ g_warning ("Folder cache for store %p contains "
+ "%d folders at destruction.", store,
+ g_hash_table_size (store->folders));
+ }
+ g_hash_table_destroy (store->folders);
+ }
+}
+
+
+static CamelFolder *
+get_folder (CamelStore *store, const char *folder_name, CamelException *ex)
+{
+ g_warning ("CamelStore::get_folder not implemented for `%s'",
+ gtk_type_name (GTK_OBJECT_TYPE (store)));
+ return NULL;
+}
+
+static char *
+get_folder_name (CamelStore *store, const char *folder_name,
+ CamelException *ex)
+{
+ g_warning ("CamelStore::get_folder_name not implemented for `%s'",
+ gtk_type_name (GTK_OBJECT_TYPE (store)));
+ return NULL;
+}
+
+static char *
+get_root_folder_name (CamelStore *store, CamelException *ex)
+{
+ return g_strdup ("/");
+}
+
+static char *
+get_default_folder_name (CamelStore *store, CamelException *ex)
+{
+ return CS_CLASS (store)->get_root_folder_name (store, ex);
+}
static CamelFolder *
-_get_folder (CamelStore *store, const gchar *folder_name, CamelException *ex)
+lookup_folder (CamelStore *store, const char *folder_name)
{
+ if (store->folders)
+ return g_hash_table_lookup (store->folders, folder_name);
return NULL;
}
+static void
+cache_folder (CamelStore *store, const char *folder_name, CamelFolder *folder)
+{
+ if (!store->folders)
+ return;
+
+ if (g_hash_table_lookup (store->folders, folder_name)) {
+ g_warning ("Caching folder %s that already exists.",
+ folder_name);
+ }
+ g_hash_table_insert (store->folders, (gpointer)folder_name, folder);
+ gtk_signal_connect_object (GTK_OBJECT (folder), "destroy",
+ GTK_SIGNAL_FUNC (CS_CLASS (store)->uncache_folder),
+ GTK_OBJECT (store));
+}
+
+static void
+uncache_folder (CamelStore *store, CamelFolder *folder)
+{
+ g_hash_table_remove (store->folders,
+ camel_folder_get_full_name (folder));
+}
+
+
+static CamelFolder *
+get_folder_internal (CamelStore *store, const char *folder_name,
+ CamelException *ex)
+{
+ CamelFolder *folder = NULL;
+
+ /* Try cache first. */
+ folder = CS_CLASS (store)->lookup_folder (store, folder_name);
+
+ if (!folder) {
+ folder = CS_CLASS (store)->get_folder (store, folder_name, ex);
+ if (!folder)
+ return NULL;
+
+ CS_CLASS (store)->cache_folder (store, folder_name, folder);
+ }
+
+ gtk_object_ref (GTK_OBJECT (folder));
+ return folder;
+}
+
+
/**
- * camel_store_get_folder: return the folder corresponding to a path.
- * @store: store
+ * camel_store_get_folder: Return the folder corresponding to a path.
+ * @store: a CamelStore
* @folder_name: name of the folder to get
+ * @ex: a CamelException
*
- * Returns the folder corresponding to the path "name".
- * If the path begins with the separator caracter, it
- * is relative to the root folder. Otherwise, it is
- * relative to the default folder.
- * The folder does not necessarily exist on the store.
- * To make sure it already exists, use its "exists" method.
- * If it does not exist, you can create it with its
- * "create" method.
- *
+ * Returns the folder corresponding to the path "name". If the path
+ * begins with the separator character, it is relative to the root
+ * folder. Otherwise, it is relative to the default folder. The folder
+ * does not necessarily already exist on the store. To test if it
+ * already exists, use its "exists" method. If it does not exist, you
+ * can create it with its "create" method.
*
* Return value: the folder
**/
CamelFolder *
-camel_store_get_folder (CamelStore *store, const gchar *folder_name, CamelException *ex)
+camel_store_get_folder (CamelStore *store, const char *folder_name,
+ CamelException *ex)
{
- return CS_CLASS(store)->get_folder (store, folder_name, ex);
+ char *name;
+ CamelFolder *folder = NULL;
+
+ name = CS_CLASS (store)->get_folder_name (store, folder_name, ex);
+ if (name) {
+ folder = get_folder_internal (store, name, ex);
+ g_free (name);
+ }
+ return folder;
}
/**
- * camel_store_get_root_folder : return the toplevel folder
+ * camel_store_get_root_folder: return the top-level folder
*
- * Returns the folder which is at the top of the folder
- * hierarchy. This folder is generally different from
- * the default folder.
+ * Returns the folder which is at the top of the folder hierarchy.
+ * This folder may or may not be the same as the default folder.
*
- * @Return value: the toplevel folder.
+ * Return value: the top-level folder.
**/
-static CamelFolder *
-_get_root_folder (CamelStore *store, CamelException *ex)
+CamelFolder *
+camel_store_get_root_folder (CamelStore *store, CamelException *ex)
{
- return NULL;
+ char *name;
+ CamelFolder *folder = NULL;
+
+ name = CS_CLASS (store)->get_root_folder_name (store, ex);
+ if (name) {
+ folder = get_folder_internal (store, name, ex);
+ g_free (name);
+ }
+ return folder;
}
/**
- * camel_store_get_default_folder : return the store default folder
+ * camel_store_get_default_folder: return the store default folder
*
- * The default folder is the folder which is presented
- * to the user in the default configuration. The default
- * is often the root folder.
+ * The default folder is the folder which is presented to the user in
+ * the default configuration. This defaults to the root folder if
+ * the store doesn't override it.
*
- * @Return value: the default folder.
+ * Return value: the default folder.
**/
-static CamelFolder *
-_get_default_folder (CamelStore *store, CamelException *ex)
+CamelFolder *
+camel_store_get_default_folder (CamelStore *store, CamelException *ex)
{
- return NULL;
+ char *name;
+ CamelFolder *folder = NULL;
+
+ name = CS_CLASS (store)->get_default_folder_name (store, ex);
+ if (name) {
+ folder = get_folder_internal (store, name, ex);
+ g_free (name);
+ }
+ return folder;
}
+
diff --git a/camel/camel-store.h b/camel/camel-store.h
index af5aa959a6..d66e6344b5 100644
--- a/camel/camel-store.h
+++ b/camel/camel-store.h
@@ -46,32 +46,51 @@ extern "C" {
struct _CamelStore
{
- CamelService parent_object;
-
+ CamelService parent_object;
+
+ GHashTable *folders;
+
};
typedef struct {
CamelServiceClass parent_class;
-
- CamelFolder * (*get_folder) (CamelStore *store,
- const gchar *folder_name,
+
+ CamelFolder * (*get_folder) (CamelStore *store,
+ const char *folder_name,
+ CamelException *ex);
+
+ char * (*get_folder_name) (CamelStore *store,
+ const char *folder_name,
CamelException *ex);
- CamelFolder * (*get_root_folder) (CamelStore *store,
+ char * (*get_root_folder_name) (CamelStore *store,
CamelException *ex);
- CamelFolder * (*get_default_folder) (CamelStore *store,
+ char * (*get_default_folder_name) (CamelStore *store,
CamelException *ex);
-} CamelStoreClass;
+ CamelFolder * (*lookup_folder) (CamelStore *store,
+ const char *folder_name);
+ void (*cache_folder) (CamelStore *store,
+ const char *folder_name,
+ CamelFolder *folder);
+ void (*uncache_folder) (CamelStore *store,
+ CamelFolder *folder);
+} CamelStoreClass;
-/* public methods */
/* Standard Gtk function */
GtkType camel_store_get_type (void);
-CamelFolder * camel_store_get_folder (CamelStore *store, const gchar *folder_name, CamelException *ex);
+/* public methods */
+CamelFolder * camel_store_get_folder (CamelStore *store,
+ const char *folder_name,
+ CamelException *ex);
+CamelFolder * camel_store_get_root_folder (CamelStore *store,
+ CamelException *ex);
+CamelFolder * camel_store_get_default_folder (CamelStore *store,
+ CamelException *ex);
#ifdef __cplusplus
}
diff --git a/camel/providers/mbox/camel-mbox-store.c b/camel/providers/mbox/camel-mbox-store.c
index 32d25becf1..0081aedb0e 100644
--- a/camel/providers/mbox/camel-mbox-store.c
+++ b/camel/providers/mbox/camel-mbox-store.c
@@ -35,8 +35,10 @@
#define CF_CLASS(so) CAMEL_FOLDER_CLASS (GTK_OBJECT(so)->klass)
#define CMBOXF_CLASS(so) CAMEL_MBOX_FOLDER_CLASS (GTK_OBJECT(so)->klass)
-static CamelFolder *_get_folder (CamelStore *store, const gchar *folder_name, CamelException *ex);
-
+static CamelFolder *get_folder (CamelStore *store, const char *folder_name,
+ CamelException *ex);
+static char *get_folder_name (CamelStore *store, const char *folder_name,
+ CamelException *ex);
static void
camel_mbox_store_class_init (CamelMboxStoreClass *camel_mbox_store_class)
@@ -44,7 +46,8 @@ camel_mbox_store_class_init (CamelMboxStoreClass *camel_mbox_store_class)
CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS (camel_mbox_store_class);
/* virtual method overload */
- camel_store_class->get_folder = _get_folder;
+ camel_store_class->get_folder = get_folder;
+ camel_store_class->get_folder_name = get_folder_name;
}
@@ -53,8 +56,12 @@ static void
camel_mbox_store_init (gpointer object, gpointer klass)
{
CamelService *service = CAMEL_SERVICE (object);
+ CamelStore *store = CAMEL_STORE (object);
service->url_flags = CAMEL_SERVICE_URL_NEED_PATH;
+
+ /* mbox names are filenames, so they are case-sensitive. */
+ store->folders = g_hash_table_new (g_str_hash, g_str_equal);
}
@@ -97,15 +104,11 @@ camel_mbox_store_get_toplevel_dir (CamelMboxStore *store)
static CamelFolder *
-_get_folder (CamelStore *store, const gchar *folder_name, CamelException *ex)
+get_folder (CamelStore *store, const char *folder_name, CamelException *ex)
{
CamelMboxFolder *new_mbox_folder;
CamelFolder *new_folder;
- /* check if folder has already been created */
- /* call the standard routine for that when */
- /* it is done ... */
-
CAMEL_LOG_FULL_DEBUG ("Entering CamelMboxStore::get_folder\n");
new_mbox_folder = gtk_type_new (CAMEL_MBOX_FOLDER_TYPE);
new_folder = CAMEL_FOLDER (new_mbox_folder);
@@ -121,3 +124,10 @@ _get_folder (CamelStore *store, const gchar *folder_name, CamelException *ex)
return new_folder;
}
+
+static char *
+get_folder_name (CamelStore *store, const char *folder_name,
+ CamelException *ex)
+{
+ return g_strdup (folder_name);
+}
diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c
index f14ed1dc55..b63cd30342 100644
--- a/camel/providers/pop3/camel-pop3-store.c
+++ b/camel/providers/pop3/camel-pop3-store.c
@@ -55,8 +55,11 @@ static gboolean pop3_disconnect (CamelService *service, CamelException *ex);
static GList *query_auth_types (CamelService *service);
static void free_auth_types (CamelService *service, GList *authtypes);
-static CamelFolder *get_folder (CamelStore *store, const gchar *folder_name,
+static CamelFolder *get_folder (CamelStore *store, const char *folder_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);
static void
@@ -79,9 +82,9 @@ camel_pop3_store_class_init (CamelPop3StoreClass *camel_pop3_store_class)
camel_service_class->query_auth_types = query_auth_types;
camel_service_class->free_auth_types = free_auth_types;
- camel_store_class->get_root_folder = camel_pop3_folder_new;
- camel_store_class->get_default_folder = camel_pop3_folder_new;
camel_store_class->get_folder = get_folder;
+ camel_store_class->get_folder_name = get_folder_name;
+ camel_store_class->get_root_folder_name = get_root_folder_name;
}
@@ -90,9 +93,11 @@ static void
camel_pop3_store_init (gpointer object, gpointer klass)
{
CamelService *service = CAMEL_SERVICE (object);
+ CamelStore *store = CAMEL_STORE (object);
service->url_flags = ( CAMEL_SERVICE_URL_NEED_USER |
CAMEL_SERVICE_URL_NEED_HOST );
+ store->folders = g_hash_table_new (g_str_hash, g_str_equal);
}
@@ -324,11 +329,18 @@ pop3_disconnect (CamelService *service, CamelException *ex)
return TRUE;
}
-static CamelFolder *get_folder (CamelStore *store, const gchar *folder_name,
- CamelException *ex)
+static CamelFolder *
+get_folder (CamelStore *store, const char *folder_name, CamelException *ex)
+{
+ return camel_pop3_folder_new (store, ex);
+}
+
+static char *
+get_folder_name (CamelStore *store, const char *folder_name,
+ CamelException *ex)
{
if (!strcasecmp (folder_name, "inbox"))
- return camel_pop3_folder_new (store, ex);
+ return g_strdup ("inbox");
else {
camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID,
"No such folder `%s'.", folder_name);
@@ -336,6 +348,13 @@ static CamelFolder *get_folder (CamelStore *store, const gchar *folder_name,
}
}
+static char *
+get_root_folder_name (CamelStore *store, CamelException *ex)
+{
+ return g_strdup ("inbox");
+}
+
+
/**
* camel_pop3_command: Send a command to a POP3 server.
* @store: the POP3 store