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 | |
parent | bef39dc4e0bbdb334fef71f973bcb7781dce65df (diff) | |
download | gsoc2013-evolution-73c74dd70d7e023cc24f7e28d52417b3c4e72805.tar gsoc2013-evolution-73c74dd70d7e023cc24f7e28d52417b3c4e72805.tar.gz gsoc2013-evolution-73c74dd70d7e023cc24f7e28d52417b3c4e72805.tar.bz2 gsoc2013-evolution-73c74dd70d7e023cc24f7e28d52417b3c4e72805.tar.lz gsoc2013-evolution-73c74dd70d7e023cc24f7e28d52417b3c4e72805.tar.xz 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')
-rw-r--r-- | mail/ChangeLog | 44 | ||||
-rw-r--r-- | mail/component-factory.c | 3 | ||||
-rw-r--r-- | mail/folder-browser-factory.c | 6 | ||||
-rw-r--r-- | mail/folder-browser.c | 84 | ||||
-rw-r--r-- | mail/folder-browser.h | 6 | ||||
-rw-r--r-- | mail/mail-callbacks.c | 3 | ||||
-rw-r--r-- | mail/mail-folder-cache.c | 1111 | ||||
-rw-r--r-- | mail/mail-folder-cache.h | 44 | ||||
-rw-r--r-- | mail/mail-local.c | 164 | ||||
-rw-r--r-- | mail/mail-ops.c | 11 | ||||
-rw-r--r-- | mail/mail-tools.c | 16 | ||||
-rw-r--r-- | mail/mail-vfolder.c | 33 | ||||
-rw-r--r-- | mail/message-list.c | 21 | ||||
-rw-r--r-- | mail/message-list.h | 1 | ||||
-rw-r--r-- | mail/subscribe-dialog.c | 2 |
15 files changed, 544 insertions, 1005 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index 0b32158e67..84ec972536 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,47 @@ +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. + 2001-09-18 Jeffrey Stedfast <fejj@ximian.com> * mail-mt.c (do_get_pass): Make the title translatable, and also diff --git a/mail/component-factory.c b/mail/component-factory.c index 5a5ea1cbae..89a615f9bd 100644 --- a/mail/component-factory.c +++ b/mail/component-factory.c @@ -990,7 +990,10 @@ add_storage (const char *name, const char *uri, CamelService *store, switch (res) { case EVOLUTION_STORAGE_OK: mail_hash_storage (store, storage); +/* mail_scan_subfolders (CAMEL_STORE (store), storage); +*/ + mail_note_store((CamelStore *)store); /* falllll */ case EVOLUTION_STORAGE_ERROR_ALREADYREGISTERED: case EVOLUTION_STORAGE_ERROR_EXISTS: diff --git a/mail/folder-browser-factory.c b/mail/folder-browser-factory.c index a7c45d822d..e0f808f149 100644 --- a/mail/folder-browser-factory.c +++ b/mail/folder-browser-factory.c @@ -92,8 +92,7 @@ control_activate (BonoboControl *control, folder_browser_ui_add_list (fb); folder_browser_ui_add_message (fb); - mail_folder_cache_set_shell_view (fb_get_svi (control)); - mail_folder_cache_set_folder_browser (fb); + folder_browser_set_shell_view(fb, fb_get_svi (control)); if (fb->folder) mail_refresh_folder (fb->folder, NULL, NULL); @@ -104,8 +103,6 @@ control_deactivate (BonoboControl *control, BonoboUIComponent *uic, FolderBrowser *fb) { - mail_folder_cache_set_folder_browser (NULL); - folder_browser_ui_rm_list (fb); folder_browser_ui_rm_all (fb); @@ -113,6 +110,7 @@ control_deactivate (BonoboControl *control, mail_sync_folder (fb->folder, NULL, NULL); folder_browser_set_ui_component (fb, NULL); + folder_browser_set_shell_view (fb, CORBA_OBJECT_NIL); } static void diff --git a/mail/folder-browser.c b/mail/folder-browser.c index a54451db92..daa26c49a3 100644 --- a/mail/folder-browser.c +++ b/mail/folder-browser.c @@ -61,6 +61,9 @@ #define PARENT_TYPE (gtk_table_get_type ()) +static void folder_changed(CamelObject *o, void *event_data, void *data); +static void main_folder_changed(CamelObject *o, void *event_data, void *data); + #define X_EVOLUTION_MESSAGE_TYPE "x-evolution-message" #define MESSAGE_RFC822_TYPE "message/rfc822" #define TEXT_URI_LIST_TYPE "text/uri-list" @@ -124,12 +127,19 @@ folder_browser_destroy (GtkObject *object) if (folder_browser->shell != CORBA_OBJECT_NIL) CORBA_Object_release (folder_browser->shell, &ev); + if (folder_browser->shell_view != CORBA_OBJECT_NIL) + CORBA_Object_release(folder_browser->shell_view, &ev); + if (folder_browser->uicomp) bonobo_object_unref (BONOBO_OBJECT (folder_browser->uicomp)); g_free (folder_browser->uri); if (folder_browser->folder) { + camel_object_unhook_event(CAMEL_OBJECT(folder_browser->folder), "folder_changed", + folder_changed, folder_browser); + camel_object_unhook_event(CAMEL_OBJECT(folder_browser->folder), "message_changed", + folder_changed, folder_browser); mail_sync_folder (folder_browser->folder, NULL, NULL); camel_object_unref (CAMEL_OBJECT (folder_browser->folder)); } @@ -680,6 +690,58 @@ folder_browser_paste (GtkWidget *menuitem, FolderBrowser *fb) GDK_CURRENT_TIME); } +/* all this crap so we can give the user a whoopee doo status bar */ +static void +update_status_bar(FolderBrowser *fb) +{ + CORBA_Environment ev; + int tmp; + GString *work; + extern CamelFolder *outbox_folder; + + if (fb->folder == NULL + || fb->message_list == NULL + || fb->shell_view == CORBA_OBJECT_NIL) + return; + + work = g_string_new(""); + g_string_sprintfa(work, _("%d new"), camel_folder_get_unread_message_count(fb->folder)); + tmp = message_list_hidden(fb->message_list); + if (tmp) { + g_string_append(work, _(", ")); + g_string_sprintfa(work, _("%d hidden"), tmp); + } + tmp = e_selection_model_selected_count(e_tree_get_selection_model(fb->message_list->tree)); + if (tmp) { + g_string_append(work, _(", ")); + g_string_sprintfa(work, _("%d selected"), tmp); + } + tmp = camel_folder_get_message_count(fb->folder); + g_string_append(work, _(", ")); + if (fb->folder == outbox_folder) + g_string_sprintfa(work, _("%d unsent"), tmp); + else + g_string_sprintfa(work, _("%d total"), tmp); + + CORBA_exception_init(&ev); + GNOME_Evolution_ShellView_setFolderBarLabel(fb->shell_view, work->str, &ev); + CORBA_exception_free(&ev); + + g_string_free(work, TRUE); +} + +static void main_folder_changed(CamelObject *o, void *event_data, void *data) +{ + FolderBrowser *fb = data; + + update_status_bar(fb); +} + +static void folder_changed(CamelObject *o, void *event_data, void *data) +{ + mail_msg_wait(mail_proxy_event(main_folder_changed, o, event_data, data)); +} + static void got_folder(char *uri, CamelFolder *folder, void *data) { @@ -700,8 +762,10 @@ got_folder(char *uri, CamelFolder *folder, void *data) folder_browser_is_outbox (fb)); vfolder_register_source (folder); - mail_folder_cache_note_folder (fb->uri, folder); - mail_folder_cache_note_fb (fb->uri, fb); + camel_object_hook_event(CAMEL_OBJECT(fb->folder), "folder_changed", + folder_changed, fb); + camel_object_hook_event(CAMEL_OBJECT(fb->folder), "message_changed", + folder_changed, fb); /* when loading a new folder, nothing is selected initially */ @@ -728,6 +792,20 @@ folder_browser_set_ui_component (FolderBrowser *fb, BonoboUIComponent *uicomp) fb->uicomp = uicomp; } +void +folder_browser_set_shell_view(FolderBrowser *fb, GNOME_Evolution_ShellView shell_view) +{ + CORBA_Environment ev; + + CORBA_exception_init(&ev); + if (fb->shell_view != CORBA_OBJECT_NIL) + CORBA_Object_release(fb->shell_view, &ev); + CORBA_exception_free(&ev); + + fb->shell_view = CORBA_Object_duplicate(shell_view, &ev); + CORBA_exception_free(&ev); +} + extern CamelFolder *drafts_folder, *sent_folder, *outbox_folder; /** @@ -1591,6 +1669,8 @@ on_selection_changed (GtkObject *obj, gpointer user_data) } folder_browser_ui_set_selection_state (fb, state); + + update_status_bar(fb); } static void diff --git a/mail/folder-browser.h b/mail/folder-browser.h index 82768f20b8..1e10b907a9 100644 --- a/mail/folder-browser.h +++ b/mail/folder-browser.h @@ -37,6 +37,8 @@ struct _FolderBrowser { BonoboPropertyBag *properties; GNOME_Evolution_Shell shell; + GNOME_Evolution_ShellView shell_view; + BonoboUIComponent *uicomp; /* @@ -98,8 +100,8 @@ GtkType folder_browser_get_type (void); GtkWidget *folder_browser_new (const GNOME_Evolution_Shell shell, const char *uri); -void folder_browser_set_ui_component (FolderBrowser *fb, - BonoboUIComponent *uicomp); +void folder_browser_set_ui_component (FolderBrowser *fb, BonoboUIComponent *uicomp); +void folder_browser_set_shell_view (FolderBrowser *fb, GNOME_Evolution_ShellView shell_view); void folder_browser_set_message_preview (FolderBrowser *folder_browser, gboolean show_message_preview); diff --git a/mail/mail-callbacks.c b/mail/mail-callbacks.c index 90e191612b..c2289b6898 100644 --- a/mail/mail-callbacks.c +++ b/mail/mail-callbacks.c @@ -2256,9 +2256,6 @@ create_folders (EvolutionStorage *storage, const char *prefix, CamelFolderInfo * { char *path; - mail_folder_cache_set_update_estorage (fi->url, storage); - mail_folder_cache_note_folderinfo (fi->url, fi); - path = g_strdup_printf ("%s/%s", prefix, fi->name); if (!strncmp (fi->url, "vtrash:", 7)) 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 diff --git a/mail/mail-folder-cache.h b/mail/mail-folder-cache.h index df99ef7283..7aab84d748 100644 --- a/mail/mail-folder-cache.h +++ b/mail/mail-folder-cache.h @@ -3,6 +3,7 @@ /* * Authors: Peter Williams <peterw@ximian.com> + * Michael Zucchi <notzed@ximian.com> * * Copyright 2000,2001 Ximian, Inc. (www.ximian.com) * @@ -25,40 +26,21 @@ #ifndef _MAIL_FOLDER_CACHE_H #define _MAIL_FOLDER_CACHE_H -#include <camel/camel-folder.h> -#include <camel/camel-store.h> #include <shell/evolution-storage.h> -#include <shell/Evolution.h> -#include "folder-browser.h" +/* Add a store whose folders should appear in the shell + The folders are scanned from the store, and/or added at + runtime via the folder_created event */ +void mail_note_store(struct _CamelStore *store); -/* No real order that these functions should be called. The idea is - * that whenever a chunk of the mailer gets some up-to-date - * information about a URI, it calls one of the _note_ functions and - * the folder cache sees to it that the information is put to good - * use. - * - * Thus there is no way to remove items from the cache. So it leaks a lot. */ - -void mail_folder_cache_set_update_estorage (const gchar *uri, EvolutionStorage *estorage); -void mail_folder_cache_set_update_lstorage (const gchar *uri, - GNOME_Evolution_Storage lstorage, - const gchar *path); - -void mail_folder_cache_remove_folder (const gchar *uri); - -/* We always update the shell view */ -/*void mail_folder_cache_set_update_shellview (const gchar *uri);*/ - -void mail_folder_cache_note_folder (const gchar *uri, CamelFolder *folder); -void mail_folder_cache_note_fb (const gchar *uri, FolderBrowser *fb); -void mail_folder_cache_note_folderinfo (const gchar *uri, CamelFolderInfo *fi); -void mail_folder_cache_note_name (const gchar *uri, const gchar *name); - -CamelFolder *mail_folder_cache_try_folder (const gchar *uri); -gchar * mail_folder_cache_try_name (const gchar *uri); +/* Similar to above, but do updates via a local GNOME_Evolutuion_Storage + rather than a remote proxy EvolutionStorage object */ +void mail_note_local_store(struct _CamelStore *store, GNOME_Evolution_Storage corba_storage); -void mail_folder_cache_set_shell_view (GNOME_Evolution_ShellView sv); -void mail_folder_cache_set_folder_browser (FolderBrowser *fb); +/* When a folder has been opened, notify it for watching. + The path may be NULL if the shell-equivalent path can be determined + from the folder->full_name, if it cannot, then the path must + be supplied */ +void mail_note_folder(struct _CamelFolder *folder, const char *path); #endif diff --git a/mail/mail-local.c b/mail/mail-local.c index fdba26c128..26ba476dd1 100644 --- a/mail/mail-local.c +++ b/mail/mail-local.c @@ -69,7 +69,12 @@ static GNOME_Evolution_Storage local_corba_storage = CORBA_OBJECT_NIL; #define MAIL_IS_LOCAL_STORE(o) (CAMEL_CHECK_TYPE((o), MAIL_LOCAL_STORE_TYPE)) typedef struct { - CamelStore parent_object; + CamelStore parent_object; + + /* stores CamelFolderInfo's of the folders we're supposed to know about, by uri */ + GHashTable *folder_infos; + GMutex *folder_info_lock; + } MailLocalStore; typedef struct { @@ -78,6 +83,8 @@ typedef struct { static CamelType mail_local_store_get_type (void); +static MailLocalStore *global_local_store; + /* ** MailLocalFolder ** (protos) ************************************************* */ #define MAIL_LOCAL_FOLDER_TYPE (mail_local_folder_get_type ()) @@ -85,6 +92,9 @@ static CamelType mail_local_store_get_type (void); #define MAIL_LOCAL_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), MAIL_LOCAL_FOLDER_TYPE, MailLocalFolderClass)) #define MAIL_IS_LOCAL_FOLDER(o) (CAMEL_CHECK_TYPE((o), MAIL_LOCAL_FOLDER_TYPE)) +#define LOCAL_STORE_LOCK(folder) (g_mutex_lock (((MailLocalStore *)folder)->folder_info_lock)) +#define LOCAL_STORE_UNLOCK(folder) (g_mutex_unlock (((MailLocalStore *)folder)->folder_info_lock)) + struct _local_meta { char *path; /* path of metainfo */ @@ -639,7 +649,8 @@ mls_get_folder(CamelStore *store, const char *folder_name, guint32 flags, CamelE { MailLocalStore *local_store = MAIL_LOCAL_STORE (store); MailLocalFolder *folder; - char *physical_uri, *name; + char *physical_uri; + CamelFolderInfo *info; d(printf("--LOCAL-- get_folder: %s", folder_name)); @@ -663,13 +674,20 @@ mls_get_folder(CamelStore *store, const char *folder_name, guint32 flags, CamelE } } - /* FIXME: why is this here? */ - physical_uri = g_strdup_printf("file://%s/%s", ((CamelService *)store)->url->path, folder_name); - mail_folder_cache_note_folder(physical_uri, CAMEL_FOLDER (folder)); - name = strrchr(folder_name, '/'); - if (name) /* should always be true... */ { - if (local_corba_storage != CORBA_OBJECT_NIL) - mail_folder_cache_set_update_lstorage(physical_uri, local_corba_storage, name); + physical_uri = g_strdup_printf("file:/%s/%s", ((CamelService *)store)->url->path, folder_name); + LOCAL_STORE_LOCK(local_store); + info = g_hash_table_lookup(local_store->folder_infos, physical_uri); + if (info) { + char *path = g_strdup(info->full_name); + + d(printf("noting folder: '%s' path = '%s'\n", info->url, info->full_name)); + + LOCAL_STORE_UNLOCK(local_store); + mail_note_folder((CamelFolder *)folder, path); + g_free(path); + } else { + LOCAL_STORE_UNLOCK(local_store); + g_warning("LocalStore opening a folder we weren't told existed!: %s", physical_uri); } g_free(physical_uri); @@ -729,6 +747,32 @@ mls_get_name (CamelService *service, gboolean brief) } static void +mls_init (MailLocalStore *mls, MailLocalStoreClass *mlsclass) +{ + mls->folder_infos = g_hash_table_new(g_str_hash, g_str_equal); + mls->folder_info_lock = g_mutex_new(); +} + +static void +free_info(void *key, void *value, void *data) +{ + CamelFolderInfo *info = value; + + g_free(info->url); + g_free(info->name); + g_free(info->full_name); + free(info); +} + +static void +mls_finalise(MailLocalStore *mls) +{ + g_hash_table_foreach(mls->folder_infos, (GHFunc)free_info, NULL); + g_hash_table_destroy(mls->folder_infos); + g_mutex_free(mls->folder_info_lock); +} + +static void mls_class_init (CamelObjectClass *camel_object_class) { CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS(camel_object_class); @@ -754,13 +798,67 @@ mail_local_store_get_type (void) sizeof (MailLocalStoreClass), (CamelObjectClassInitFunc) mls_class_init, NULL, - NULL, - NULL); + (CamelObjectInitFunc) mls_init, + (CamelObjectFinalizeFunc) mls_finalise); } return mail_local_store_type; } +static void mail_local_store_add_folder(MailLocalStore *mls, const char *uri, const char *path, const char *name) +{ + CamelFolderInfo *info; + + LOCAL_STORE_LOCK(mls); + + if (g_hash_table_lookup(mls->folder_infos, uri)) { + g_warning("Shell trying to add a folder I already have!"); + } else { + info = g_malloc0(sizeof(*info)); + info->url = g_strdup(uri); + info->full_name = g_strdup(path); + info->name = g_strdup(name); + info->unread_message_count = -1; + g_hash_table_insert(mls->folder_infos, info->url, info); + } + + LOCAL_STORE_UNLOCK(mls); + + d(printf("adding folder: '%s' path = '%s'\n", info->url, path)); + + camel_object_trigger_event((CamelObject *)mls, "folder_created", info); +} + +struct _search_info { + const char *path; + CamelFolderInfo *info; +}; + +static void +remove_find_path(char *uri, CamelFolderInfo *info, struct _search_info *data) +{ + if (!strcmp(info->full_name, data->path)) + data->info = info; +} + +static void mail_local_store_remove_folder(MailLocalStore *mls, const char *path) +{ + struct _search_info data = { path, NULL }; + + /* we're keyed on uri, not path, so have to search for it manually */ + + LOCAL_STORE_LOCK(mls); + g_hash_table_foreach(mls->folder_infos, (GHFunc)remove_find_path, &data); + if (data.info) { + g_hash_table_remove(mls->folder_infos, data.info->url); + g_free(data.info->url); + g_free(data.info->full_name); + g_free(data.info->name); + g_free(data.info); + } + LOCAL_STORE_UNLOCK(mls); +} + /* ** Local Provider ************************************************************** */ static CamelProvider local_provider = { @@ -815,24 +913,32 @@ local_storage_new_folder_cb (EvolutionStorageListener *storage_listener, if (strcmp (folder->type, "mail") != 0) return; - mail_folder_cache_set_update_lstorage (folder->physicalUri, - data, - path); - mail_folder_cache_note_name (folder->physicalUri, folder->displayName); + if (path[0] == '/') + path++; + + d(printf("Local folder new:\n")); + d(printf(" path = '%s'\n uri = '%s'\n display = '%s'\n", + path, folder->physicalUri, folder->displayName)); + + mail_local_store_add_folder(global_local_store, folder->physicalUri, path, folder->displayName); + + /* are we supposed to say anything about it? */ } -#if 0 + static void local_storage_removed_folder_cb (EvolutionStorageListener *storage_listener, const char *path, void *data) { - if (strcmp (folder->type, "mail") != 0) - return; + if (path[0] == '/') + path++; - /* anything to do? */ + d(printf("Local folder remove:\n")); + d(printf(" path = '%s'\n", path)); + + mail_local_store_remove_folder(global_local_store, path); } -#endif static void storage_listener_startup (EvolutionShellClient *shellclient) @@ -842,14 +948,17 @@ storage_listener_startup (EvolutionShellClient *shellclient) GNOME_Evolution_Storage corba_storage; CORBA_Environment ev; - printf("---- CALLING STORAGE LISTENER STARTUP ---\n"); + d(printf("---- CALLING STORAGE LISTENER STARTUP ---\n")); local_corba_storage = corba_storage = evolution_shell_client_get_local_storage (shellclient); if (corba_storage == CORBA_OBJECT_NIL) { g_warning ("No local storage available from shell client!"); return; } - + + /* setup to record this store's changes */ + mail_note_local_store((CamelStore *)global_local_store, local_corba_storage); + local_storage_listener = evolution_storage_listener_new (); corba_local_storage_listener = evolution_storage_listener_corba_objref ( local_storage_listener); @@ -862,11 +971,10 @@ storage_listener_startup (EvolutionShellClient *shellclient) "new_folder", GTK_SIGNAL_FUNC (local_storage_new_folder_cb), corba_storage); - /*gtk_signal_connect (GTK_OBJECT (local_storage_listener), - * "removed_folder", - * GTK_SIGNAL_FUNC (local_storage_removed_folder_cb), - * corba_storage); - */ + gtk_signal_connect (GTK_OBJECT (local_storage_listener), + "removed_folder", + GTK_SIGNAL_FUNC (local_storage_removed_folder_cb), + corba_storage); CORBA_exception_init (&ev); GNOME_Evolution_Storage_addListener (corba_storage, @@ -881,8 +989,6 @@ storage_listener_startup (EvolutionShellClient *shellclient) /* ** The rest ******************************************************************** */ -static MailLocalStore *global_local_store; - void mail_local_storage_startup (EvolutionShellClient *shellclient, const char *evolution_path) { diff --git a/mail/mail-ops.c b/mail/mail-ops.c index 71608f5856..09d857923e 100644 --- a/mail/mail-ops.c +++ b/mail/mail-ops.c @@ -404,12 +404,6 @@ do_update_subfolders_rec (CamelStore *store, CamelFolderInfo *info, EvolutionSto { char *path; - if (info->url) { - /* info->url == URI??? */ - mail_folder_cache_set_update_estorage (info->url, storage); - mail_folder_cache_note_folderinfo (info->url, info); - } - path = g_strdup_printf ("%s/%s", prefix, info->name); if (info->child) @@ -443,6 +437,8 @@ mail_update_subfolders (CamelStore *store, EvolutionStorage *storage, { struct _update_info *info; + /* FIXME: i'm not sure this function is needed anymore??? */ + /* FIXME: This wont actually work entirely right, as a failure may lose this data */ /* however, this isn't a big problem ... */ info = g_malloc0(sizeof(*info)); @@ -1460,8 +1456,7 @@ remove_folder_got (struct _mail_msg *mm) struct _remove_folder_msg *m = (struct _remove_folder_msg *)mm; if (m->removed) { - /* Remove this folder from the folder cache */ - mail_folder_cache_remove_folder (m->uri); + /* FIXME: Remove this folder from the folder cache ??? */ } if (m->done) diff --git a/mail/mail-tools.c b/mail/mail-tools.c index 1c151b9d5e..09603eb458 100644 --- a/mail/mail-tools.c +++ b/mail/mail-tools.c @@ -323,12 +323,6 @@ mail_tool_uri_to_folder (const char *uri, CamelException *ex) g_return_val_if_fail (uri != NULL, NULL); - folder = mail_folder_cache_try_folder (uri); - if (folder) { - camel_object_ref (CAMEL_OBJECT (folder)); - return folder; - } - /* This hack is still needed for file:/ since it's its own EvolutionStorage type */ if (!strncmp (uri, "vtrash:", 7)) offset = 7; @@ -353,8 +347,6 @@ mail_tool_uri_to_folder (const char *uri, CamelException *ex) name = ""; } - printf("opening folder '%s' on store (%p) '%s'\n", name, store, uri); - if (offset) folder = camel_store_get_trash (store, ex); else @@ -368,8 +360,12 @@ mail_tool_uri_to_folder (const char *uri, CamelException *ex) camel_object_unref (CAMEL_OBJECT (folder)); folder = NULL; } - } else - mail_folder_cache_note_folder (uri, folder); + } else { + /* we dont want to note file url's, they need to be noted elsewhere (sigh) */ + if (strncmp(uri, "file:", 5) != 0) + mail_note_folder(folder, NULL); + /*mail_folder_cache_note_folder (uri, folder);*/ + } camel_url_free (url); diff --git a/mail/mail-vfolder.c b/mail/mail-vfolder.c index 0f4c271255..51740bf30f 100644 --- a/mail/mail-vfolder.c +++ b/mail/mail-vfolder.c @@ -107,8 +107,6 @@ source_finalise(CamelFolder *folder, void *event_data, void *data) void vfolder_register_source (CamelFolder *folder) { - GList *l; - if (CAMEL_IS_VEE_FOLDER(folder)) return; @@ -245,16 +243,14 @@ rule_changed(FilterRule *rule, CamelFolder *folder) /* if the folder has changed name, then add it, then remove the old manually */ if (strcmp(folder->full_name, rule->name) != 0) { - char *uri, *path, *key; + char *path, *key; CamelFolder *old; gtk_signal_disconnect_by_func((GtkObject *)rule, rule_changed, folder); context_rule_added((RuleContext *)context, rule); - uri = g_strdup_printf("vfolder:%s/vfolder#%s", evolution_dir, folder->full_name); - mail_folder_cache_remove_folder(uri); - g_free(uri); + /* TODO: remove folder from folder info cache? */ path = g_strdup_printf("/%s", folder->full_name); evolution_storage_removed_folder(mail_lookup_storage(vfolder_store), path); @@ -299,7 +295,6 @@ rule_changed(FilterRule *rule, CamelFolder *folder) static void context_rule_added(RuleContext *ctx, FilterRule *rule) { CamelFolder *folder; - char *uri, *path; printf("rule added: %s\n", rule->name); @@ -310,37 +305,19 @@ static void context_rule_added(RuleContext *ctx, FilterRule *rule) g_hash_table_insert(vfolder_hash, g_strdup(rule->name), folder); - /* Ok, so the mail_folder_cache api is a complete fuckup, - I think this mess probably does what it is supposed to do */ - uri = g_strdup_printf("vfolder:%s/vfolder#%s", evolution_dir, rule->name); - printf("Noting folder '%s', storage = %p\n", uri, mail_lookup_storage(vfolder_store)); - path = g_strdup_printf("/%s", rule->name); - evolution_storage_new_folder(mail_lookup_storage(vfolder_store), - path, rule->name, - "mail", uri, - rule->name, - FALSE); - - mail_folder_cache_note_folder(uri, folder); - mail_folder_cache_set_update_estorage(uri, mail_lookup_storage(vfolder_store)); - g_free(uri); - g_free(path); - + mail_note_folder(folder, NULL); rule_changed(rule, folder); } } static void context_rule_removed(RuleContext *ctx, FilterRule *rule) { - char *uri, *key, *path; + char *key, *path; CamelFolder *folder; printf("rule removed; %s\n", rule->name); - /* have to remove this first before unrefing the folder, otherwise it gets itself lost */ - uri = g_strdup_printf("vfolder:%s/vfolder#%s", evolution_dir, rule->name); - mail_folder_cache_remove_folder(uri); - g_free(uri); + /* TODO: remove from folder info cache? */ path = g_strdup_printf("/%s", rule->name); evolution_storage_removed_folder(mail_lookup_storage(vfolder_store), path); diff --git a/mail/message-list.c b/mail/message-list.c index f91f5ce5ac..1dcd49bc48 100644 --- a/mail/message-list.c +++ b/mail/message-list.c @@ -1812,10 +1812,10 @@ main_folder_changed (CamelObject *o, gpointer event_data, gpointer user_data) CamelFolder *folder = (CamelFolder *)o; int i; - printf("folder changed event, changes = %p\n", changes); + d(printf("folder changed event, changes = %p\n", changes)); if (changes) { - printf("changed = %d added = %d removed = %d\n", - changes->uid_changed->len, changes->uid_added->len, changes->uid_removed->len); + d(printf("changed = %d added = %d removed = %d\n", + changes->uid_changed->len, changes->uid_added->len, changes->uid_removed->len)); /* check if the hidden state has changed, if so modify accordingly, then regenerate */ if (ml->hidedeleted) { @@ -2129,6 +2129,21 @@ message_list_length (MessageList *ml) return ml->hide_unhidden; } +/* returns number of hidden messages */ +unsigned int +message_list_hidden(MessageList *ml) +{ + unsigned int hidden = 0; + + MESSAGE_LIST_LOCK (ml, hide_lock); + if (ml->hidden) + hidden = g_hash_table_size (ml->hidden); + MESSAGE_LIST_UNLOCK (ml, hide_lock); + + return hidden; +} + + /* add a new expression to hide, or set the range. @expr: A new search expression - all matching messages will be hidden. May be %NULL. @lower: Use ML_HIDE_NONE_START to specify no messages hidden from the start of the list. diff --git a/mail/message-list.h b/mail/message-list.h index 26a6512d0d..380d57d46d 100644 --- a/mail/message-list.h +++ b/mail/message-list.h @@ -122,6 +122,7 @@ void message_list_select_uid (MessageList *message_list, /* info */ unsigned int message_list_length(MessageList *ml); +unsigned int message_list_hidden(MessageList *ml); /* hide specific messages */ void message_list_hide_add(MessageList *ml, const char *expr, unsigned int lower, unsigned int upper); diff --git a/mail/subscribe-dialog.c b/mail/subscribe-dialog.c index 81792f000a..d007bfee50 100644 --- a/mail/subscribe-dialog.c +++ b/mail/subscribe-dialog.c @@ -186,8 +186,6 @@ recursive_add_folder (EvolutionStorage *storage, const char *path, const char *n } evolution_storage_new_folder (storage, path, name, "mail", url, name, FALSE); - mail_folder_cache_set_update_estorage (url, storage); - mail_folder_cache_note_name (url, name); } /* ** Get one level of folderinfo ****************************************** */ |