diff options
author | 9 <NotZed@Ximian.com> | 2001-09-19 16:29:13 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2001-09-19 16:29:13 +0800 |
commit | 73c74dd70d7e023cc24f7e28d52417b3c4e72805 (patch) | |
tree | 79596aab616dd7f2abd55c6f6a86c1abb3687d76 /mail/mail-folder-cache.c | |
parent | bef39dc4e0bbdb334fef71f973bcb7781dce65df (diff) | |
download | gsoc2013-evolution-73c74dd70d7e023cc24f7e28d52417b3c4e72805.tar.gz gsoc2013-evolution-73c74dd70d7e023cc24f7e28d52417b3c4e72805.tar.zst gsoc2013-evolution-73c74dd70d7e023cc24f7e28d52417b3c4e72805.zip |
General cleanup of mail debug printfs.
2001-09-19 <NotZed@Ximian.com>
* General cleanup of mail debug printfs.
* mail-folder-cache.[ch]: Completely rewritten. Removed all calls
to the old code everywhere they were used. Nuff said.
* folder-browser.h: Add shell_view to folder_browser & api to set
it.
* folder-browser-factory.c (control_activate): Set the shell-view
on the folder_browser.
(control_deactivate): And clear it here.
* folder-browser.c (folder_browser_destroy): Unhook from changed
events on the folder before giving it away.
(got_folder): Hook onto the folder-changed events.
(folder_changed): Event hook proxy for folder_changed events
(main_folder_changed): And the main code version.
(update_status_bar): And the one that actually does the work.
(on_selection_changed): Also call update_status_bar() to update
the selection count.
(folder_browser_set_shell_view): Implement function to set the
shell_view on the folder_browser.
(folder_browser_destroy): Release the shell_view here too.
* mail-tools.c (mail_tool_uri_to_folder): Dont 'note' the new
folder if its from a file: url, this is handled by hte local store
(yeeruughck).
* mail-local.c (mls_init):
(free_info):
(mls_finalise): Setup init/finalise funcs for the folderinfo hash.
(local_storage_removed_folder_cb): re-enable.
2001-09-18 <NotZed@Ximian.com>
* mail-local.c (MailLocalStore): Add a hash table to store
uri<>folderinfo data.
(mail_local_store_add_folder): Add a new folderinfo to our hash.
(mail_local_store_remove_folder): Remove a folder by uri.
(storage_listener_startup): Add this store to those monitored by
the folder tree.
svn path=/trunk/; revision=12974
Diffstat (limited to 'mail/mail-folder-cache.c')
-rw-r--r-- | mail/mail-folder-cache.c | 1111 |
1 files changed, 228 insertions, 883 deletions
diff --git a/mail/mail-folder-cache.c b/mail/mail-folder-cache.c index a4174fa477..9514724271 100644 --- a/mail/mail-folder-cache.c +++ b/mail/mail-folder-cache.c @@ -1,8 +1,7 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* mail-folder-cache.c: Stores information about open folders */ - -/* +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * * Authors: Peter Williams <peterw@ximian.com> + * Michael Zucchi <notzed@ximian.com> * * Copyright 2000,2001 Ximian, Inc. (www.ximian.com) * @@ -29,1007 +28,353 @@ #ifdef G_LOG_DOMAIN #undef G_LOG_DOMAIN #endif -#define G_LOG_DOMAIN "folder cache" +#define G_LOG_DOMAIN "folder tree" + +#include <pthread.h> #include <bonobo/bonobo-exception.h> +#include <camel/camel-store.h> +#include <camel/camel-folder.h> #include "mail-mt.h" #include "mail-folder-cache.h" +#include "mail-ops.h" -#define ld(x) #define d(x) -/* Structures */ - -typedef enum mail_folder_info_flags { - MAIL_FIF_UNREAD_VALID = (1 << 0), - MAIL_FIF_TOTAL_VALID = (1 << 1), - MAIL_FIF_HIDDEN_VALID = (1 << 2), - MAIL_FIF_FOLDER_VALID = (1 << 3), - MAIL_FIF_NEED_UPDATE = (1 << 4), - MAIL_FIF_PATH_VALID = (1 << 5), - MAIL_FIF_NAME_VALID = (1 << 6), - MAIL_FIF_FB_VALID = (1 << 8), - MAIL_FIF_SELECTED_VALID = (1 << 9) -} mfif; - -typedef enum mail_folder_info_update_mode { - MAIL_FIUM_UNKNOWN, - MAIL_FIUM_EVOLUTION_STORAGE, - MAIL_FIUM_LOCAL_STORAGE /*,*/ - /*MAIL_FIUM_SHELL_VIEW*/ -} mfium; - -typedef union mail_folder_info_update_info { - EvolutionStorage *es; - GNOME_Evolution_Storage ls; -} mfiui; - -typedef struct _mail_folder_info { - gchar *uri; - gchar *path; - - CamelFolder *folder; - gchar *name; - - guint flags; - guint unread, total, hidden, selected; - - FolderBrowser *fb; - - int timeout_id; - int mail_info_id; - - mfium update_mode; - mfiui update_info; -} mail_folder_info; - -static GHashTable *folders = NULL; -static GStaticMutex folders_lock = G_STATIC_MUTEX_INIT; - -#define LOCK_FOLDERS() G_STMT_START { ld(g_message ("Locking folders")); g_static_mutex_lock (&folders_lock); } G_STMT_END -#define UNLOCK_FOLDERS() G_STMT_START { ld(g_message ("Unocking folders")); g_static_mutex_unlock (&folders_lock); } G_STMT_END - -static GNOME_Evolution_ShellView shell_view = CORBA_OBJECT_NIL; -static FolderBrowser *folder_browser = NULL; - -extern CamelFolder *outbox_folder; - -/* Private functions */ - -/* call this with the folders locked */ -static mail_folder_info * -get_folder_info (const gchar *uri) -{ - mail_folder_info *mfi; - - g_return_val_if_fail (uri, NULL); - - if (folders == NULL) { - d(g_message("Initializing")); - folders = g_hash_table_new (g_str_hash, g_str_equal); - } - - mfi = g_hash_table_lookup (folders, uri); - - if (!mfi) { - d(g_message("New entry for uri %s", uri)); - - mfi = g_new (mail_folder_info, 1); - mfi->uri = g_strdup (uri); /* XXX leak leak leak */ - mfi->path = NULL; - mfi->folder = NULL; - mfi->name = NULL; - mfi->fb = NULL; - mfi->flags = 0; - mfi->update_mode = MAIL_FIUM_UNKNOWN; - mfi->update_info.es = NULL; - mfi->timeout_id = 0; - mfi->mail_info_id = 0; - mfi->unread = 0; - - g_hash_table_insert (folders, mfi->uri, mfi); - } else - d(g_message("Hit cache for uri %s", uri)); - - return mfi; -} +/* note that many things are effectively serialised by having them run in + the main loop thread which they need to do because of corba/gtk calls */ +#define LOCK(x) pthread_mutex_lock(&x) +#define UNLOCK(x) pthread_mutex_unlock(&x) -/* call with the folders locked */ +static pthread_mutex_t info_lock = PTHREAD_MUTEX_INITIALIZER; -static gchar * -make_folder_status (mail_folder_info *mfi) -{ - gboolean set_one = FALSE; - GString *work; - gchar *ret; +struct _folder_info { + struct _store_info *store_info; /* 'parent' link */ - /* Build the display string */ + char *path; + char *name; /* shell display name? */ + CamelFolder *folder; /* if known */ +}; - work = g_string_new (""); +struct _store_info { + GHashTable *folders; /* by path */ - if (mfi->flags & MAIL_FIF_UNREAD_VALID) { - g_string_sprintfa (work, _("%d new"), mfi->unread); - set_one = TRUE; - } - - if (mfi->flags & MAIL_FIF_HIDDEN_VALID && mfi->hidden) { - if (set_one) - work = g_string_append (work, _(", ")); - g_string_sprintfa (work, _("%d hidden"), mfi->hidden); - set_one = TRUE; - } - - if (mfi->flags & MAIL_FIF_SELECTED_VALID && mfi->selected > 1) { - if (set_one) - work = g_string_append (work, _(", ")); - g_string_sprintfa (work, _("%d selected"), mfi->selected); - set_one = TRUE; - } - - if (mfi->flags & MAIL_FIF_TOTAL_VALID) { - if (set_one) - work = g_string_append (work, _(", ")); - - if (mfi->flags & MAIL_FIF_FOLDER_VALID && mfi->folder == outbox_folder) - g_string_sprintfa (work, _("%d unsent"), mfi->total); - else - g_string_sprintfa (work, _("%d total"), mfi->total); - } + /* only 1 should be set */ + EvolutionStorage *storage; + GNOME_Evolution_Storage corba_storage; +}; - ret = work->str; - g_string_free (work, FALSE); - return ret; -} +static GHashTable *stores; -static gboolean -update_idle (gpointer user_data) +static void +update_1folder(struct _folder_info *mfi, CamelFolderInfo *info) { - mail_folder_info *mfi = (mail_folder_info *) user_data; - gchar *f_status; - gchar *uri, *path; - mfiui info; - mfium mode; - FolderBrowser *fb; + struct _store_info *si; + CamelFolder *folder; + int unread; CORBA_Environment ev; - LOCK_FOLDERS (); - - d(g_message("update_idle called")); - - mfi->timeout_id = 0; - - /* Check if this makes sense */ - - if (!(mfi->flags & MAIL_FIF_NAME_VALID)) { - g_warning ("Folder cache update info of \'%s\' without \'name\' set", mfi->uri); - UNLOCK_FOLDERS (); - return FALSE; - } - - if (mfi->update_mode == MAIL_FIUM_UNKNOWN) { - g_warning ("Folder cache update info of \'%s\' without \'mode\' set", mfi->uri); - UNLOCK_FOLDERS (); - return FALSE; - } + si = mfi->store_info; - /* Get the display string */ - - f_status = make_folder_status (mfi); - - /* Set the value */ - - /* Who knows how long these corba calls will take? - * Copy the data from mfi so we can UNLOCK_FOLDERS - * before the calls. - */ - - info = mfi->update_info; - uri = g_strdup (mfi->uri); - if (mfi->flags & MAIL_FIF_PATH_VALID) - path = g_strdup (mfi->path); + LOCK(info_lock); + folder = mfi->folder; + if (folder) + unread = camel_folder_get_unread_message_count(folder); + else if (info) + unread = info->unread_message_count; else - path = NULL; - mode = mfi->update_mode; - if (mfi->flags & MAIL_FIF_FB_VALID) - fb = mfi->fb; - else - fb = NULL; - - UNLOCK_FOLDERS (); - - switch (mode) { - case MAIL_FIUM_LOCAL_STORAGE: - CORBA_exception_init (&ev); - GNOME_Evolution_Storage_updateFolder (info.ls, - mfi->path, - mfi->name, - mfi->unread, - &ev); - if (BONOBO_EX (&ev)) - g_warning ("Exception in local storage update: %s", - bonobo_exception_get_text (&ev)); - CORBA_exception_free (&ev); - break; - case MAIL_FIUM_EVOLUTION_STORAGE: - d(g_message("Updating via EvolutionStorage")); - evolution_storage_update_folder_by_uri (info.es, - uri, - mfi->name, - mfi->unread); - break; - case MAIL_FIUM_UNKNOWN: - default: - g_assert_not_reached (); - break; - } - - /* Now set the folder bar if reasonable -- we need a shell view, - * and the active folder browser should be the one associated with - * this MFI */ - - if (shell_view != CORBA_OBJECT_NIL && - fb && folder_browser == fb) { - d(g_message("Updating via ShellView")); - CORBA_exception_init (&ev); - GNOME_Evolution_ShellView_setFolderBarLabel (shell_view, - f_status, - &ev); - if (BONOBO_EX (&ev)) - g_warning ("Exception in folder bar label update: %s", - bonobo_exception_get_text (&ev)); - CORBA_exception_free (&ev); - -#if 0 - GNOME_Evolution_ShellView_setTitle (shell_view, - wide, - &ev); - if (BONOBO_EX (&ev)) - g_warning ("Exception in shell view title update: %s", - bonobo_exception_get_text (&ev)); - CORBA_exception_free (&ev); -#endif + unread = -1; + UNLOCK(info_lock); + + if (si->storage == NULL) { + d(printf("Updating existing (local) folder: %s\n", mfi->path)); + CORBA_exception_init(&ev); + GNOME_Evolution_Storage_updateFolder(si->corba_storage, mfi->path, mfi->name, unread, &ev); + CORBA_exception_free(&ev); + } else { + d(printf("Updating existing folder: %s\n", mfi->path)); + evolution_storage_update_folder(si->storage, mfi->path, mfi->name, unread); } - - /* Cleanup */ - - g_free (uri); - g_free (path); - g_free (f_status); - return FALSE; } static void -maybe_update (mail_folder_info *mfi) +setup_folder(const char *path, CamelFolderInfo *fi, struct _store_info *si) { - if (mfi->timeout_id) - return; - - mfi->timeout_id = g_timeout_add (100, update_idle, mfi); + struct _folder_info *mfi; + char *type; + int unread = fi->unread_message_count; + + LOCK(info_lock); + mfi = g_hash_table_lookup(si->folders, path); + if (mfi) { + UNLOCK(info_lock); + update_1folder(mfi, fi); + } else { + /* always 'add it', but only 'add it' to non-local stores */ + d(printf("Adding new folder: %s (%s)\n", path, fi->url)); + mfi = g_malloc0(sizeof(*mfi)); + mfi->path = g_strdup(path); + mfi->name = g_strdup(fi->name); + mfi->store_info = si; + g_hash_table_insert(si->folders, mfi->path, mfi); + UNLOCK(info_lock); + + if (si->storage != NULL) { + type = (strncmp(fi->url, "vtrash:", 7)==0)?"vtrash":"mail"; + evolution_storage_new_folder(si->storage, path, mfi->name, type, + fi->url, mfi->name, unread); + } + } } static void -update_message_counts_main (CamelObject *object, gpointer event_data, - gpointer user_data) +real_folder_changed(CamelFolder *folder, void *event_data, void *data) { - mail_folder_info *mfi; - gchar *uri = (gchar *) user_data; - - LOCK_FOLDERS (); - - mfi = get_folder_info (uri); + struct _folder_info *mfi = data; - /* if folder is no longer valid, these numbers are useless */ - if (mfi->flags & MAIL_FIF_FOLDER_VALID) { - d(g_message("Message counts in CamelFolder changed, queuing idle")); - mfi->flags &= (~MAIL_FIF_NEED_UPDATE); - maybe_update (mfi); - } - - UNLOCK_FOLDERS (); - - g_free (uri); + update_1folder(mfi, NULL); } static void -update_message_counts (CamelObject *object, gpointer event_data, - gpointer user_data) +folder_changed(CamelObject *o, gpointer event_data, gpointer user_data) { - CamelFolder *folder = CAMEL_FOLDER (object); - mail_folder_info *mfi; - gchar *uri = g_quark_to_string (GPOINTER_TO_UINT (user_data)); - int unread; - int total; + struct _folder_info *mfi = user_data; - d(g_message("CamelFolder %p changed, examining message counts", object)); - - unread = camel_folder_get_unread_message_count (folder); - total = camel_folder_get_message_count (folder); - - LOCK_FOLDERS (); - - mfi = get_folder_info (uri); - - /* we might have been removed in the meantime... this could - * conceivably fail if _note_folder was called immediately - * after the URL was removed, and we would get the counts - * for the wrong folder, but the chances of that happening - * are miniscule. - */ - - if (!(mfi->flags & MAIL_FIF_FOLDER_VALID)) { - d(g_message("-> Folder is no longer valid, cancelling updates")); - UNLOCK_FOLDERS (); + if (mfi->folder != CAMEL_FOLDER(o)) return; - } - mfi->flags &= (~MAIL_FIF_NEED_UPDATE); - - /* '-1' seems to show up a lot, just skip it. - * Probably a better way. */ - if (unread == -1) { - /* nuttzing */ - } else if (mfi->flags & MAIL_FIF_UNREAD_VALID) { - if (mfi->unread != unread) { - d(g_message("-> Unread value is changed")); - mfi->unread = unread; - mfi->flags |= MAIL_FIF_NEED_UPDATE; - } else - d(g_message("-> Unread value is the same")); - } else { - d(g_message("-> Unread value being initialized")); - mfi->flags |= (MAIL_FIF_UNREAD_VALID | MAIL_FIF_NEED_UPDATE); - mfi->unread = unread; - } - - if (mfi->flags & MAIL_FIF_TOTAL_VALID) { - if (mfi->total != total) { - d(g_message("-> Total value is changed")); - mfi->total = total; - mfi->flags |= MAIL_FIF_NEED_UPDATE; - } else - d(g_message("-> Total value is the same")); - } else { - d(g_message("-> Total value being initialized")); - mfi->flags |= (MAIL_FIF_TOTAL_VALID | MAIL_FIF_NEED_UPDATE); - mfi->total = total; - } - - /* while we're here... */ - if (!(mfi->flags & MAIL_FIF_NAME_VALID)) { - mfi->name = g_strdup (camel_folder_get_name (CAMEL_FOLDER (object))); - d(g_message("-> setting name to %s as well", mfi->name)); - mfi->flags |= MAIL_FIF_NAME_VALID; - } - - if (mfi->flags & MAIL_FIF_NEED_UPDATE) { - UNLOCK_FOLDERS (); - d(g_message("-> Queuing change")); - mail_proxy_event (update_message_counts_main, object, event_data, g_strdup (uri)); - } else { - UNLOCK_FOLDERS (); - d(g_message("-> No proxy event needed")); - } + d(printf("Fodler changed!\n")); + mail_msg_wait(mail_proxy_event((CamelObjectEventHookFunc)real_folder_changed, o, NULL, mfi)); } static void -camel_folder_finalized (CamelObject *object, gpointer event_data, - gpointer user_data) +folder_finalised(CamelObject *o, gpointer event_data, gpointer user_data) { - mail_folder_info *mfi; - gchar *uri = g_quark_to_string (GPOINTER_TO_UINT (user_data)); - - d(g_message("CamelFolder %p finalized, unsetting FOLDER_VALID", object)); - - LOCK_FOLDERS (); - - mfi = get_folder_info (uri); + struct _folder_info *mfi = user_data; - /* we could check for FOLDER_VALID, but why bother? */ - mfi->flags &= (~MAIL_FIF_FOLDER_VALID); + d(printf("Folder finalised!\n")); mfi->folder = NULL; - - UNLOCK_FOLDERS (); } static void -message_list_built (MessageList *ml, gpointer user_data) +real_note_folder(CamelFolder *folder, char *path, void *data) { - mail_folder_info *mfi; - gchar *uri = g_quark_to_string (GPOINTER_TO_UINT (user_data)); - - d(g_message("Message list %p rebuilt, checking hidden", ml)); + CamelStore *store = folder->parent_store; + struct _store_info *si; + struct _folder_info *mfi; + + LOCK(info_lock); + si = g_hash_table_lookup(stores, store); + UNLOCK(info_lock); + if (si == NULL) { + g_free(path); + g_warning("Adding a folder `%s' to a store which hasn't been added yet?\n", folder->full_name); + camel_object_unref((CamelObject *)folder); + return; + } - LOCK_FOLDERS (); + if (path == NULL) + path = g_strdup_printf("/%s", folder->full_name); - mfi = get_folder_info (uri); + LOCK(info_lock); + mfi = g_hash_table_lookup(si->folders, path); + UNLOCK(info_lock); - if (!(mfi->flags & MAIL_FIF_FB_VALID)) { - d(g_message ("-> we seem to have been removed. Returning.")); - UNLOCK_FOLDERS (); + if (mfi == NULL) { + g_warning("Adding a folder `%s' that I dont know about yet?\n path='%s'", folder->full_name, path); + g_free(path); + camel_object_unref((CamelObject *)folder); return; } + g_free(path); - if (ml->folder != mfi->folder) { - g_warning ("folder cache: different folders in cache and messagelist"); - gtk_signal_disconnect_by_data (GTK_OBJECT (ml), user_data); - UNLOCK_FOLDERS (); + /* dont do anything if we already have this */ + if (mfi->folder == folder) return; - } - - MESSAGE_LIST_LOCK (ml, hide_lock); - if (ml->hidden) - mfi->hidden = g_hash_table_size (ml->hidden); - else - mfi->hidden = 0; - MESSAGE_LIST_UNLOCK (ml, hide_lock); - mfi->flags |= MAIL_FIF_HIDDEN_VALID; + mfi->folder = folder; + update_1folder(mfi, NULL); - UNLOCK_FOLDERS (); + camel_object_hook_event((CamelObject *)folder, "folder_changed", folder_changed, mfi); + camel_object_hook_event((CamelObject *)folder, "message_changed", folder_changed, mfi); + camel_object_hook_event((CamelObject *)folder, "finalised", folder_finalised, mfi); - maybe_update (mfi); + camel_object_unref((CamelObject *)folder); } -static void -selection_changed (ESelectionModel *esm, gpointer user_data) +/* supply path if different from folder->full_name? */ +void mail_note_folder(CamelFolder *folder, const char *path) { - mail_folder_info *mfi; - gchar *uri = g_quark_to_string (GPOINTER_TO_UINT (user_data)); - - d(g_message ("Selection model %p changed, checking selected", esm)); - - LOCK_FOLDERS (); + char *real = NULL; - mfi = get_folder_info (uri); - - if (!(mfi->flags & MAIL_FIF_FB_VALID)) { - d(g_message ("-> hm, fb is not valid. We must have been removed.")); - UNLOCK_FOLDERS (); + if (stores == NULL) { + g_warning("Adding a folder `%s' to a store which hasn't been added yet?\n", folder->full_name); return; } - mfi->selected = e_selection_model_selected_count (esm); - mfi->flags |= MAIL_FIF_SELECTED_VALID; - - UNLOCK_FOLDERS (); - - maybe_update (mfi); + camel_object_ref((CamelObject *)folder); + if (path) + real = g_strdup_printf("/%s", path); + mail_proxy_event((CamelObjectEventHookFunc)real_note_folder, (CamelObject *)folder, real, NULL); } static void -folder_browser_destroyed (GtkObject *fb, gpointer user_data) +real_folder_created(CamelStore *store, void *event_data, CamelFolderInfo *fi) { - mail_folder_info *mfi; - gchar *uri = g_quark_to_string (GPOINTER_TO_UINT (user_data)); - - d(g_message ("folder browser destroyed. Unsetting FB_VALID.")); - - LOCK_FOLDERS (); - - mfi = get_folder_info (uri); - - /* we could check for FB_VALID, but why bother? */ - mfi->flags &= (~MAIL_FIF_FB_VALID); - mfi->fb = NULL; - UNLOCK_FOLDERS (); -} - -static void -check_for_fb_match (gpointer key, gpointer value, gpointer user_data) -{ - mail_folder_info *mfi = (mail_folder_info *) value; - - d(g_message("-> checking uri \"%s\" if it has active fb", (gchar *) key)); - /* This should only be true for one item, but no real - * way to stop the foreach... - */ - - if (mfi->fb == folder_browser) { - d(g_message("-> -> it does!")); - maybe_update (mfi); + struct _store_info *si; + char *path; + + d(printf("real_folder_created: %s (%s)\n", fi->full_name, fi->url)); + + LOCK(info_lock); + si = g_hash_table_lookup(stores, store); + UNLOCK(info_lock); + if (si) { + path = g_strdup_printf("/%s", fi->full_name); + setup_folder(path, fi, si); + g_free(path); + } else { + /* leaks, so what */ + g_warning("real_folder_created: can't find store: %s\n", + camel_url_to_string(((CamelService *)store)->url, 0)); } } -/* get folder info operation */ - -struct get_mail_info_msg { - struct _mail_msg msg; - - CamelFolder *folder; - gchar *uri; -}; - -static char * -get_mail_info_describe (struct _mail_msg *msg, int complete) -{ - struct get_mail_info_msg *gmim = (struct get_mail_info_msg *) msg; - - return g_strdup_printf ("Examining \'%s\'", camel_folder_get_full_name (gmim->folder)); -} - static void -get_mail_info_receive (struct _mail_msg *msg) +store_folder_created(CamelObject *o, void *event_data, void *data) { - struct get_mail_info_msg *gmim = (struct get_mail_info_msg *) msg; - mail_folder_info *mfi; - - LOCK_FOLDERS (); + CamelFolderInfo *info = event_data; - mfi = get_folder_info (gmim->uri); + d(printf("folder added: %s\n", info->full_name)); + d(printf("uri = '%s'\n", info->url)); - if (!(mfi->flags & MAIL_FIF_NAME_VALID)) { - mfi->name = g_strdup (camel_folder_get_name (gmim->folder)); - mfi->flags |= MAIL_FIF_NAME_VALID; - } - - mfi->unread = camel_folder_get_unread_message_count (gmim->folder); - if (mfi->unread != -1) - mfi->flags |= MAIL_FIF_UNREAD_VALID; - - mfi->total = camel_folder_get_message_count (gmim->folder); - mfi->flags |= MAIL_FIF_TOTAL_VALID; - - UNLOCK_FOLDERS (); + /* dont need to copy info since we're waiting for it to complete */ + mail_msg_wait(mail_proxy_event((CamelObjectEventHookFunc)real_folder_created, o, NULL, info)); } static void -get_mail_info_reply (struct _mail_msg *msg) +store_folder_deleted(CamelObject *o, void *event_data, void *data) { - struct get_mail_info_msg *gmim = (struct get_mail_info_msg *) msg; - mail_folder_info *mfi; + CamelStore *store = (CamelStore *)o; + CamelFolderInfo *info = event_data; - LOCK_FOLDERS (); + store = store; + info = info; - mfi = get_folder_info (gmim->uri); - maybe_update (mfi); - mfi->mail_info_id = 0; - - UNLOCK_FOLDERS (); + /* should really remove it? */ + d(printf("folder deleted: %s\n", info->full_name)); } static void -get_mail_info_destroy (struct _mail_msg *msg) -{ - struct get_mail_info_msg *gmim = (struct get_mail_info_msg *) msg; - - camel_object_unref (CAMEL_OBJECT (gmim->folder)); - g_free (gmim->uri); -} - -static mail_msg_op_t get_mail_info_op = { - get_mail_info_describe, - get_mail_info_receive, - get_mail_info_reply, - get_mail_info_destroy -}; - -static int -get_mail_info (CamelFolder *folder, const char *uri) -{ - struct get_mail_info_msg *gmim; - int id; - - gmim = mail_msg_new (&get_mail_info_op, NULL, sizeof (*gmim)); - gmim->folder = folder; - camel_object_ref (CAMEL_OBJECT (folder)); - gmim->uri = g_strdup (uri); - - id = gmim->msg.seq; - e_thread_put (mail_thread_new, (EMsg *) gmim); - return id; -} - -/* Public functions */ - -void -mail_folder_cache_set_update_estorage (const gchar *uri, - EvolutionStorage *estorage) -{ - mail_folder_info *mfi; - - g_return_if_fail (uri); - - LOCK_FOLDERS (); - - mfi = get_folder_info (uri); - - if (mfi->update_mode != MAIL_FIUM_UNKNOWN) { - /* we could check to see that update_mode = ESTORAGE */ - /*g_warning ("folder cache: update mode already set??");*/ - UNLOCK_FOLDERS (); - return; - } - - d(g_message("Uri %s updates with EVOLUTION_STORAGE", uri)); - mfi->update_mode = MAIL_FIUM_EVOLUTION_STORAGE; - mfi->update_info.es = estorage; - - UNLOCK_FOLDERS (); -} - -void -mail_folder_cache_set_update_lstorage (const gchar *uri, - GNOME_Evolution_Storage lstorage, - const gchar *path) +free_folder_info(char *path, struct _folder_info *info, void *data) { - mail_folder_info *mfi; - - g_return_if_fail (uri); - - LOCK_FOLDERS (); - - mfi = get_folder_info (uri); - - if (mfi->update_mode != MAIL_FIUM_UNKNOWN) { - /*we could check to see that update_mode = lstorage */ - /*g_warning ("folder cache: update mode already set??");*/ - UNLOCK_FOLDERS (); - return; - } - - d(g_message("Uri %s updates with LOCAL_STORAGE", uri)); - /* Note that we don't dup the object or anything. Too lazy. */ - mfi->update_mode = MAIL_FIUM_LOCAL_STORAGE; - mfi->update_info.ls = lstorage; - - mfi->path = g_strdup (path); - mfi->flags |= MAIL_FIF_PATH_VALID; - - UNLOCK_FOLDERS (); + g_free(info->path); + g_free(info->name); } -void -mail_folder_cache_remove_folder (const gchar *uri) +static void +store_finalised(CamelObject *o, void *event_data, void *data) { - mail_folder_info *mfi; - GQuark uri_key; - - g_return_if_fail (uri); - - LOCK_FOLDERS (); - - mfi = g_hash_table_lookup (folders, uri); - if (!mfi) { - UNLOCK_FOLDERS (); - g_warning ("folder cache: trying to remove uri \"%s\": not found in the cache", - uri); - return; - } - g_hash_table_remove (folders, uri); - - d(g_message ("folder cache: removing uri \"%s\".", uri)); - - if (mfi->timeout_id) - g_source_remove (mfi->timeout_id); - - if (mfi->mail_info_id) - mail_msg_cancel (mfi->mail_info_id); - - uri_key = g_quark_from_string (uri); - - if (mfi->flags & MAIL_FIF_FB_VALID) { - ESelectionModel *esm; - - esm = e_tree_get_selection_model (mfi->fb->message_list->tree); - - gtk_signal_disconnect_by_data (GTK_OBJECT (mfi->fb), GUINT_TO_POINTER (uri_key)); - gtk_signal_disconnect_by_data (GTK_OBJECT (mfi->fb->message_list), - GUINT_TO_POINTER (uri_key)); - gtk_signal_disconnect_by_data (GTK_OBJECT (esm), GUINT_TO_POINTER (uri_key)); - } - - if (mfi->flags & MAIL_FIF_FOLDER_VALID) { - camel_object_unhook_event (CAMEL_OBJECT (mfi->folder), "message_changed", - update_message_counts, GUINT_TO_POINTER (uri_key)); - camel_object_unhook_event (CAMEL_OBJECT (mfi->folder), "folder_changed", - update_message_counts, GUINT_TO_POINTER (uri_key)); - camel_object_unhook_event (CAMEL_OBJECT (mfi->folder), "finalize", - camel_folder_finalized, GUINT_TO_POINTER (uri_key)); - } - - UNLOCK_FOLDERS (); - - g_free (mfi->uri); - g_free (mfi->path); - g_free (mfi->name); - g_free (mfi); + CamelStore *store = (CamelStore *)o; + struct _store_info *si; + + d(printf("store finalised!!\n")); + LOCK(info_lock); + si = g_hash_table_lookup(stores, store); + if (si) { + g_hash_table_remove(stores, store); + g_hash_table_foreach(si->folders, free_folder_info, NULL); + g_hash_table_destroy(si->folders); + g_free(si); + } + UNLOCK(info_lock); } -void -mail_folder_cache_note_folder (const gchar *uri, CamelFolder *folder) +static void +create_folders(const char *prefix, CamelFolderInfo *fi, struct _store_info *si) { - mail_folder_info *mfi; - GQuark uri_key; - - g_return_if_fail (uri); - g_return_if_fail (CAMEL_IS_FOLDER (folder)); - - LOCK_FOLDERS (); - - mfi = get_folder_info (uri); + char *path; - if (mfi->flags & MAIL_FIF_FOLDER_VALID) { - if (mfi->folder != folder) - g_warning ("folder cache: CamelFolder being changed for %s??? I refuse.", uri); - UNLOCK_FOLDERS (); - return; - } - - d(g_message("Setting uri %s to watch folder %p", uri, folder)); - - mfi->flags |= MAIL_FIF_FOLDER_VALID; - mfi->folder = folder; + path = g_strdup_printf ("%s/%s", prefix, fi->name); + setup_folder(path, fi, si); - if (mfi->mail_info_id == 0) - mfi->mail_info_id = get_mail_info (folder, uri); + if (fi->child) + create_folders(path, fi->child, si); - UNLOCK_FOLDERS (); - - uri_key = g_quark_from_string (uri); - camel_object_hook_event (CAMEL_OBJECT (folder), "message_changed", - update_message_counts, GUINT_TO_POINTER (uri_key)); - camel_object_hook_event (CAMEL_OBJECT (folder), "folder_changed", - update_message_counts, GUINT_TO_POINTER (uri_key)); - camel_object_hook_event (CAMEL_OBJECT (folder), "finalize", - camel_folder_finalized, GUINT_TO_POINTER (uri_key)); + g_free(path); + if (fi->sibling) + create_folders(prefix, fi->sibling, si); } -void -mail_folder_cache_note_fb (const gchar *uri, FolderBrowser *fb) +static void +update_folders(CamelStore *store, CamelFolderInfo *info, void *data) { - mail_folder_info *mfi; - GQuark uri_key; + struct _store_info *si = data; - g_return_if_fail (uri); - g_return_if_fail (IS_FOLDER_BROWSER (fb)); - - LOCK_FOLDERS (); - - mfi = get_folder_info (uri); - - if (!(mfi->flags & MAIL_FIF_FOLDER_VALID)) { - d(g_message("No folder specified so ignoring NOTE_FB at %s", uri)); - UNLOCK_FOLDERS (); - return; + if (info) { + if (si->storage) + gtk_object_set_data (GTK_OBJECT (si->storage), "connected", GINT_TO_POINTER (TRUE)); + create_folders("", info, si); } - - d(g_message("Noting folder browser %p for %s", fb, uri)); - - mfi->fb = fb; - mfi->flags |= MAIL_FIF_FB_VALID; - - uri_key = g_quark_from_string (uri); - gtk_signal_connect (GTK_OBJECT (fb->message_list), "message_list_built", - message_list_built, GUINT_TO_POINTER (uri_key)); - gtk_signal_connect (GTK_OBJECT (e_tree_get_selection_model (fb->message_list->tree)), - "selection_changed", selection_changed, GUINT_TO_POINTER (uri_key)); - gtk_signal_connect (GTK_OBJECT (fb), "destroy", - folder_browser_destroyed, GUINT_TO_POINTER (uri_key)); - - UNLOCK_FOLDERS (); - - d(g_message("-> faking message_list_built")); - message_list_built (fb->message_list, GUINT_TO_POINTER (uri_key)); } -void -mail_folder_cache_note_folderinfo (const gchar *uri, CamelFolderInfo *fi) +static void +setup_store(CamelStore *store, EvolutionStorage *storage, GNOME_Evolution_Storage corba_storage) { - mail_folder_info *mfi; + struct _store_info *si; - g_return_if_fail (uri); - g_return_if_fail (fi); + LOCK(info_lock); - LOCK_FOLDERS (); + if (stores == NULL) + stores = g_hash_table_new(NULL, NULL); - mfi = get_folder_info (uri); + si = g_hash_table_lookup(stores, store); + if (si == NULL) { - d(g_message("Noting folderinfo %p for %s", fi, uri)); + d(printf("Noting a new store: %p: %s\n", store, camel_url_to_string(((CamelService *)store)->url, 0))); - if (fi->unread_message_count != -1) { - mfi->unread = fi->unread_message_count; - mfi->flags |= MAIL_FIF_UNREAD_VALID; - } + si = g_malloc0(sizeof(*si)); + si->folders = g_hash_table_new(g_str_hash, g_str_equal); + si->storage = storage; + si->corba_storage = corba_storage; + g_hash_table_insert(stores, store, si); - if (!(mfi->flags & MAIL_FIF_NAME_VALID)) { - d(g_message("-> setting name %s", fi->name)); - mfi->name = g_strdup (fi->name); - mfi->flags |= MAIL_FIF_NAME_VALID; + camel_object_hook_event((CamelObject *)store, "folder_created", store_folder_created, NULL); + camel_object_hook_event((CamelObject *)store, "folder_deleted", store_folder_deleted, NULL); + camel_object_hook_event((CamelObject *)store, "finalised", store_finalised, NULL); } - UNLOCK_FOLDERS (); + UNLOCK(info_lock); - maybe_update (mfi); + mail_msg_wait(mail_get_folderinfo(store, update_folders, si)); } -void -mail_folder_cache_note_name (const gchar *uri, const gchar *name) -{ - mail_folder_info *mfi; - - g_return_if_fail (uri); - g_return_if_fail (name); - - LOCK_FOLDERS (); - - mfi = get_folder_info (uri); - d(g_message("Noting name %s for %s", name, uri)); - - if (mfi->flags & MAIL_FIF_NAME_VALID) { - /* we could complain.. */ - d(g_message("-> name already set: %s", mfi->name)); - UNLOCK_FOLDERS (); - return; - } - - mfi->name = g_strdup (name); - mfi->flags |= MAIL_FIF_NAME_VALID; - - UNLOCK_FOLDERS (); - - maybe_update (mfi); -} - -CamelFolder * -mail_folder_cache_try_folder (const gchar *uri) +void mail_note_store(CamelStore *store) { - mail_folder_info *mfi; - CamelFolder *ret; + EvolutionStorage *storage; + /* i'm not including all the sht in mail.h just for this !*/ + EvolutionStorage *mail_lookup_storage (CamelStore *store); - g_return_val_if_fail (uri, NULL); - - LOCK_FOLDERS (); - - mfi = get_folder_info (uri); - - if (mfi->flags & MAIL_FIF_FOLDER_VALID) - ret = mfi->folder; - else - ret = NULL; - - UNLOCK_FOLDERS (); - - return ret; -} + g_assert(CAMEL_IS_STORE(store)); + g_assert(pthread_self() == mail_gui_thread); -gchar * -mail_folder_cache_try_name (const gchar *uri) -{ - mail_folder_info *mfi; - gchar *ret; - - g_return_val_if_fail (uri, NULL); - - LOCK_FOLDERS (); - - mfi = get_folder_info (uri); - - if (mfi->flags & MAIL_FIF_NAME_VALID) - ret = g_strdup (mfi->name); - else - ret = NULL; - - UNLOCK_FOLDERS (); - - return ret; -} - -void -mail_folder_cache_set_shell_view (GNOME_Evolution_ShellView sv) -{ - CORBA_Environment ev; - - g_return_if_fail (sv != CORBA_OBJECT_NIL); - - CORBA_exception_init (&ev); - - if (shell_view != CORBA_OBJECT_NIL) - CORBA_Object_release (shell_view, &ev); - - if (BONOBO_EX (&ev)) - g_warning ("Exception in releasing old shell view: %s", - bonobo_exception_get_text (&ev)); - CORBA_exception_free (&ev); - - shell_view = CORBA_Object_duplicate (sv, &ev); - if (BONOBO_EX (&ev)) - g_warning ("Exception in duping new shell view: %s", - bonobo_exception_get_text (&ev)); - CORBA_exception_free (&ev); -} - -void -mail_folder_cache_set_folder_browser (FolderBrowser *fb) -{ - d(g_message("Setting new folder browser: %p", fb)); - - if (folder_browser != NULL) { - d(g_message("Unreffing old folder browser %p", folder_browser)); - gtk_object_unref (GTK_OBJECT (folder_browser)); + storage = mail_lookup_storage(store); + if (storage == NULL) { + g_warning("Trying to monitor a store for which there is no storage: %s", + camel_url_to_string(((CamelService *)store)->url, 0)); + return; } - folder_browser = fb; - - if (fb) { - d(g_message("Reffing new browser %p", fb)); - gtk_object_ref (GTK_OBJECT (fb)); - - LOCK_FOLDERS (); - d(g_message("Checking folders for this fb")); - g_hash_table_foreach (folders, check_for_fb_match, fb); - UNLOCK_FOLDERS (); - } else if (shell_view != CORBA_OBJECT_NIL) { - CORBA_Environment ev; - - CORBA_exception_init (&ev); - GNOME_Evolution_ShellView_setFolderBarLabel (shell_view, - "", - &ev); - if (BONOBO_EX (&ev)) - g_warning ("Exception in folder bar label clear: %s", - bonobo_exception_get_text (&ev)); - CORBA_exception_free (&ev); - } + setup_store(store, storage, CORBA_OBJECT_NIL); } - -#if d(!)0 -#include <stdio.h> -static void -print_item (gpointer key, gpointer value, gpointer user_data) +void mail_note_local_store(CamelStore *store, GNOME_Evolution_Storage corba_storage) { - gchar *uri = key; - mail_folder_info *mfi = value; - - printf ("* %s\n", uri); - - if (mfi->flags & MAIL_FIF_PATH_VALID) - printf (" Path: %s\n", mfi->path); - if (mfi->flags & MAIL_FIF_NAME_VALID) - printf (" Name: %s\n", mfi->name); - if (mfi->flags & MAIL_FIF_FOLDER_VALID) - printf (" Folder: %p\n", mfi->folder); - if (mfi->flags & MAIL_FIF_UNREAD_VALID) - printf (" Unread: %d\n", mfi->unread); - if (mfi->flags & MAIL_FIF_HIDDEN_VALID) - printf (" Hidden: %d\n", mfi->hidden); - if (mfi->flags & MAIL_FIF_TOTAL_VALID) - printf (" Total: %d\n", mfi->total); - if (mfi->flags & MAIL_FIF_NEED_UPDATE) - printf (" Needs an update\n"); - switch (mfi->update_mode) { - case MAIL_FIUM_UNKNOWN: - printf (" Update mode: UNKNOWN\n"); - break; - case MAIL_FIUM_EVOLUTION_STORAGE: - printf (" Update mode: Evolution\n"); - break; - case MAIL_FIUM_LOCAL_STORAGE: - printf (" Update mode: Local\n"); - break; -/* - case MAIL_FIUM_SHELL_VIEW: - printf (" Update mode: Shell View\n"); - break; -*/ - } + g_assert(CAMEL_IS_STORE(store)); + g_assert(pthread_self() == mail_gui_thread); - printf ("\n"); + setup_store(store, NULL, corba_storage); } - -void mail_folder_cache_dump_cache (void); - -void -mail_folder_cache_dump_cache (void) -{ - printf ("********** MAIL FOLDER CACHE DUMP ************\n\n"); - LOCK_FOLDERS (); - g_hash_table_foreach (folders, print_item, NULL); - UNLOCK_FOLDERS (); - printf ("********** END OF CACHE DUMP. ****************\n"); -} - -#endif |