diff options
author | Dan Winship <danw@src.gnome.org> | 2000-06-07 08:06:29 +0800 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2000-06-07 08:06:29 +0800 |
commit | 4d5427769cfec587d9b8f727bd57ac1a1d2ae340 (patch) | |
tree | 4298b8ea452be219ecce2d96a4bc927782cabc31 /camel/camel-store.c | |
parent | ecd4fe3af090f79f30dd9df18bc4c087c366157b (diff) | |
download | gsoc2013-evolution-4d5427769cfec587d9b8f727bd57ac1a1d2ae340.tar.gz gsoc2013-evolution-4d5427769cfec587d9b8f727bd57ac1a1d2ae340.tar.zst gsoc2013-evolution-4d5427769cfec587d9b8f727bd57ac1a1d2ae340.zip |
Remove exists, create, delete. A CamelFolder now always references an
* camel-folder.c: Remove exists, create, delete. A CamelFolder
now always references an existing folder. Remove delete_messages
too since it wasn't being used. Add a "create" flag to
get_subfolder saying whether or not to create the subfolder if it
doesn't yet exist.
* camel-store.c (camel_store_get_folder): Add a "create" flag to
say whether or not to create the folder if it doesn't yet exist.
(camel_store_delete_folder): New method, moved from CamelFolder.
(cache_folder, uncache_folder): Fix up a bit.
(get_folder_name): Explain what this is for.
* providers/mbox/camel-mbox-folder.c:
* providers/mbox/camel-mbox-store.c: Update. Remove support for
hierarchical folders to simplify this for now, since we're not
using it, and it's not completely clear how they should work in an
ELocalStorage world. Needs to be revisited.
* providers/pop3/camel-pop3-folder.c (delete_messages): Remove.
* providers/pop3/camel-pop3-store.c (get_folder): Update.
* providers/vee/camel-vee-folder.c (exists): Remove.
* providers/vee/camel-vee-store.c (vee_get_folder): Update.
svn path=/trunk/; revision=3453
Diffstat (limited to 'camel/camel-store.c')
-rw-r--r-- | camel/camel-store.c | 94 |
1 files changed, 68 insertions, 26 deletions
diff --git a/camel/camel-store.c b/camel/camel-store.c index ab0c4241f7..d729bf10e7 100644 --- a/camel/camel-store.c +++ b/camel/camel-store.c @@ -35,7 +35,9 @@ static CamelServiceClass *parent_class = NULL; #define CS_CLASS(so) CAMEL_STORE_CLASS (GTK_OBJECT(so)->klass) static CamelFolder *get_folder (CamelStore *store, const char *folder_name, - CamelException *ex); + gboolean create, CamelException *ex); +static void delete_folder (CamelStore *store, const char *folder_name, + CamelException *ex); static char *get_folder_name (CamelStore *store, const char *folder_name, CamelException *ex); @@ -59,6 +61,7 @@ camel_store_class_init (CamelStoreClass *camel_store_class) /* virtual method definition */ camel_store_class->get_folder = get_folder; + camel_store_class->delete_folder = delete_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; @@ -120,13 +123,29 @@ finalize (GtkObject *object) static CamelFolder * -get_folder (CamelStore *store, const char *folder_name, CamelException *ex) +get_folder (CamelStore *store, const char *folder_name, + gboolean create, CamelException *ex) { g_warning ("CamelStore::get_folder not implemented for `%s'", gtk_type_name (GTK_OBJECT_TYPE (store))); return NULL; } +static void +delete_folder (CamelStore *store, const char *folder_name, CamelException *ex) +{ + g_warning ("CamelStore::delete_folder not implemented for `%s'", + gtk_type_name (GTK_OBJECT_TYPE (store))); +} + + +/* CamelStore::get_folder_name should: + * a) make sure that the provided name is valid + * b) return it in canonical form, in allocated memory. + * + * This is used to make sure that duplicate names for the same folder + * don't result in duplicate cache entries. + */ static char * get_folder_name (CamelStore *store, const char *folder_name, CamelException *ex) @@ -170,43 +189,44 @@ cache_folder (CamelStore *store, const char *folder_name, CamelFolder *folder) g_warning ("Caching folder %s that already exists.", folder_name); } - g_hash_table_insert (store->folders, camel_folder_get_full_name (folder), folder); + g_hash_table_insert (store->folders, g_strdup (folder_name), folder); gtk_signal_connect_object (GTK_OBJECT (folder), "destroy", GTK_SIGNAL_FUNC (CS_CLASS (store)->uncache_folder), GTK_OBJECT (store)); } +static gboolean +folder_matches (gpointer key, gpointer value, gpointer user_data) +{ + if (value == user_data) { + g_free (key); + return TRUE; + } else + return FALSE; +} + static void uncache_folder (CamelStore *store, CamelFolder *folder) { - /* FIXME: free name index */ - g_hash_table_remove (store->folders, - camel_folder_get_full_name (folder)); + g_hash_table_foreach_remove (store->folders, folder_matches, folder); } static CamelFolder * get_folder_internal (CamelStore *store, const char *folder_name, - CamelException *ex) + gboolean create, CamelException *ex) { CamelFolder *folder = NULL; - printf("Getting folder %p '%s'\n", store, folder_name); /* Try cache first. */ folder = CS_CLASS (store)->lookup_folder (store, folder_name); - if (folder) { - printf("Folder cached!\n"); - } else { - printf("Folder not cached!\n"); - } - if (!folder) { - folder = CS_CLASS (store)->get_folder (store, folder_name, ex); + folder = CS_CLASS (store)->get_folder (store, folder_name, + create, ex); if (!folder) return NULL; - printf("storing folder in cache: %p '%s'\n", store, folder_name); CS_CLASS (store)->cache_folder (store, folder_name, folder); } @@ -219,33 +239,55 @@ get_folder_internal (CamelStore *store, const char *folder_name, * camel_store_get_folder: Return the folder corresponding to a path. * @store: a CamelStore * @folder_name: name of the folder to get + * @create: whether or not to create the folder if it doesn't already exist * @ex: a CamelException * - * 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. + * Returns the folder corresponding to the path @folder_name. If the + * path begins with the separator character, it is relative to the + * root folder. Otherwise, it is relative to the default folder. If + * @create is %TRUE and the named folder does not already exist, it will + * be created. * * Return value: the folder **/ CamelFolder * camel_store_get_folder (CamelStore *store, const char *folder_name, - CamelException *ex) + gboolean create, CamelException *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); + folder = get_folder_internal (store, name, create, ex); g_free (name); } return folder; } +/** + * camel_store_delete_folder: Delete the folder corresponding to a path. + * @store: a CamelStore + * @folder_name: name of the folder to delete + * @ex: a CamelException + * + * Deletes the named folder. The folder must be empty. + **/ +void +camel_store_delete_folder (CamelStore *store, const char *folder_name, + CamelException *ex) +{ + char *name; + + name = CS_CLASS (store)->get_folder_name (store, folder_name, ex); + if (name) { + CS_CLASS (store)->delete_folder (store, name, ex); + g_free (name); + } +} + + /** * camel_store_get_root_folder: return the top-level folder * @@ -262,7 +304,7 @@ camel_store_get_root_folder (CamelStore *store, CamelException *ex) name = CS_CLASS (store)->get_root_folder_name (store, ex); if (name) { - folder = get_folder_internal (store, name, ex); + folder = get_folder_internal (store, name, TRUE, ex); g_free (name); } return folder; @@ -285,7 +327,7 @@ camel_store_get_default_folder (CamelStore *store, CamelException *ex) name = CS_CLASS (store)->get_default_folder_name (store, ex); if (name) { - folder = get_folder_internal (store, name, ex); + folder = get_folder_internal (store, name, TRUE, ex); g_free (name); } return folder; |