From 4b14db5520cf99cb30d39e14c2bb38071d4cad2d Mon Sep 17 00:00:00 2001 From: 8 Date: Fri, 28 Sep 2001 23:54:30 +0000 Subject: Emit folder_deleted event. (remove_find_path): Fix, compare against path, 2001-09-28 * mail-local.c (mail_local_store_remove_folder): Emit folder_deleted event. (remove_find_path): Fix, compare against path, not full_name. * mail-tools.c (mail_tool_uri_to_folder): Dont vfolder_register_source anymore. * mail-vfolder.c (rule_changed): Changed to access mail_fodler_cahce to find out if the folder exist yet before trying to open them, also use the cache as a cache so we dont have to open the folder if its already been opened. (vfolder_register_source, register_source): Removed. (source_finalise): Removed, (check_source): Removed. All handled through diff mechanism. (mail_vfolder_add_uri): New function, records uri's of available folders, and adds them to any active vfolders if required. (mail_vfolder_remove_uri): New function, removes a uri from available folders, and checks any rules to see fi they need updating. (vfolder_adduri): New async function to add a uri to all vfolders that need it. (store_folder_deleted): oops! free user, not rule!! * mail-folder-cache.c: Add uri->folderinfo hashtable, and the store from which they come into the store info struct. Add uri to the folder_info. (setup_folder): Store the uri in the folderinfo. (setup_folder): And the uri in the folder_uri hashtable. (mail_note_store): Store the store in the storeinfo, and setup the folders_uri hashtable via the store's hash functions. (setup_folder): Call mail_vfolder_add_uri to note this newly setup folder uri. (store_folder_deleted): Proxy call to main thread. (real_folder_deleted): And tell the vfolder to remove this uri from its folder list. (setup_folder): Dont call vfolder_add_uri if noselect is set on the uri. 2001-09-27 * mail-vfolder.c: Removed vfolder_info struct, vfolder_storage. Neither used anymore. svn path=/trunk/; revision=13242 --- mail/mail-folder-cache.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 3 deletions(-) (limited to 'mail/mail-folder-cache.c') diff --git a/mail/mail-folder-cache.c b/mail/mail-folder-cache.c index 9ccf138a75..5d5f81e2a9 100644 --- a/mail/mail-folder-cache.c +++ b/mail/mail-folder-cache.c @@ -40,6 +40,7 @@ #include "mail-mt.h" #include "mail-folder-cache.h" #include "mail-ops.h" +#include "mail-vfolder.h" #define d(x) @@ -56,11 +57,16 @@ struct _folder_info { char *path; /* shell path */ char *name; /* shell display name? */ char *full_name; /* full name of folder/folderinfo */ + char *uri; /* uri of folder */ + CamelFolder *folder; /* if known */ }; struct _store_info { GHashTable *folders; /* by full_name */ + GHashTable *folders_uri; /* by uri */ + + CamelStore *store; /* the store for these folders */ /* only 1 should be set */ EvolutionStorage *storage; @@ -136,6 +142,7 @@ setup_folder(CamelFolderInfo *fi, struct _store_info *si) { struct _folder_info *mfi; char *type; + CamelStore *store; LOCK(info_lock); mfi = g_hash_table_lookup(si->folders, fi->full_name); @@ -149,8 +156,12 @@ setup_folder(CamelFolderInfo *fi, struct _store_info *si) mfi->path = g_strdup(fi->path); mfi->name = g_strdup(fi->name); mfi->full_name = g_strdup(fi->full_name); + mfi->uri = g_strdup(fi->url); mfi->store_info = si; g_hash_table_insert(si->folders, mfi->full_name, mfi); + g_hash_table_insert(si->folders_uri, mfi->uri, mfi); + store = si->store; + camel_object_ref((CamelObject *)store); UNLOCK(info_lock); if (si->storage != NULL) { @@ -160,6 +171,11 @@ setup_folder(CamelFolderInfo *fi, struct _store_info *si) evolution_storage_new_folder(si->storage, mfi->path, mfi->name, type, fi->url, mfi->name, unread); } + + if (strstr(fi->url, ";noselect") == NULL) + mail_vfolder_add_uri(store, fi->url); + + camel_object_unref((CamelObject *)store); } } @@ -248,7 +264,7 @@ real_folder_created(CamelStore *store, void *event_data, CamelFolderInfo *fi) { struct _store_info *si; - d(printf("real_folder_created: %s (%s)\n", fi->full_name, fi->url)); + (printf("real_folder_created: %s (%s)\n", fi->full_name, fi->url)); LOCK(info_lock); si = g_hash_table_lookup(stores, store); @@ -273,6 +289,15 @@ store_folder_created(CamelObject *o, void *event_data, void *data) mail_msg_wait(mail_proxy_event((CamelObjectEventHookFunc)real_folder_created, o, NULL, info)); } +static void +real_folder_deleted(CamelStore *store, void *event_data, CamelFolderInfo *fi) +{ + (printf("real_folder_deleted: %s (%s)\n", fi->full_name, fi->url)); + + if (strstr(fi->url, ";noselect") == NULL) + mail_vfolder_remove_uri(store, fi->url); +} + static void store_folder_deleted(CamelObject *o, void *event_data, void *data) { @@ -284,6 +309,8 @@ store_folder_deleted(CamelObject *o, void *event_data, void *data) /* should really remove it? */ d(printf("folder deleted: %s\n", info->full_name)); + + mail_msg_wait(mail_proxy_event((CamelObjectEventHookFunc)real_folder_deleted, o, NULL, info)); } static void @@ -292,6 +319,7 @@ free_folder_info(char *path, struct _folder_info *info, void *data) g_free(info->path); g_free(info->name); g_free(info->full_name); + g_free(info->uri); } static void @@ -315,8 +343,10 @@ store_finalised(CamelObject *o, void *event_data, void *data) static void create_folders(CamelFolderInfo *fi, struct _store_info *si) { + printf("Setup new folder: %s\n", fi->url); + setup_folder(fi, si); - + if (fi->child) create_folders(fi->child, si); if (fi->sibling) @@ -365,12 +395,15 @@ mail_note_store(CamelStore *store, EvolutionStorage *storage, GNOME_Evolution_St d(printf("Noting a new store: %p: %s\n", store, camel_url_to_string(((CamelService *)store)->url, 0))); - /* FIXME: Need to ref the storages or something?? */ + /* FIXME: Need to ref the storages & store or something?? */ si = g_malloc0(sizeof(*si)); si->folders = g_hash_table_new(g_str_hash, g_str_equal); + si->folders_uri = g_hash_table_new(CAMEL_STORE_CLASS(CAMEL_OBJECT_GET_CLASS(store))->hash_folder_name, + CAMEL_STORE_CLASS(CAMEL_OBJECT_GET_CLASS(store))->compare_folder_name); si->storage = storage; si->corba_storage = corba_storage; + si->store = store; g_hash_table_insert(stores, store, si); camel_object_hook_event((CamelObject *)store, "folder_created", store_folder_created, NULL); @@ -387,3 +420,39 @@ mail_note_store(CamelStore *store, EvolutionStorage *storage, GNOME_Evolution_St mail_get_folderinfo(store, update_folders, ud); } + +struct _find_info { + const char *uri; + struct _folder_info *fi; +}; + +/* look up on each storeinfo using proper hash function for that stores uri's */ +static void storeinfo_find_folder_info(CamelStore *store, struct _store_info *si, struct _find_info *fi) +{ + if (fi->fi == NULL) + fi->fi = g_hash_table_lookup(si->folders_uri, fi->uri); +} + +/* returns TRUE if the uri is available, folderp is set to a + reffed folder if the folder has also already been opened */ +int mail_note_get_folder_from_uri(const char *uri, CamelFolder **folderp) +{ + struct _find_info fi = { uri, NULL }; + + if (stores == NULL) + return FALSE; + + LOCK(info_lock); + g_hash_table_foreach(stores, (GHFunc)storeinfo_find_folder_info, &fi); + if (folderp) { + if (fi.fi && fi.fi->folder) { + *folderp = fi.fi->folder; + camel_object_ref((CamelObject *)*folderp); + } else { + *folderp = NULL; + } + } + UNLOCK(info_lock); + + return fi.fi != NULL; +} -- cgit v1.2.3