aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2001-06-29 01:06:05 +0800
committerDan Winship <danw@src.gnome.org>2001-06-29 01:06:05 +0800
commit418a137c3a737a1a6cc8ed3cf3ecbd2f2751466a (patch)
treeac448a7ec158d933cfaeba5878ac19209da589b2 /mail
parentb7e09293e9b634262e7de82a8f09e890a58aeb3a (diff)
downloadgsoc2013-evolution-418a137c3a737a1a6cc8ed3cf3ecbd2f2751466a.tar.gz
gsoc2013-evolution-418a137c3a737a1a6cc8ed3cf3ecbd2f2751466a.tar.zst
gsoc2013-evolution-418a137c3a737a1a6cc8ed3cf3ecbd2f2751466a.zip
After finding a folder, attach to its "folder_changed" and
* mail-tools.c (mail_tool_uri_to_folder): After finding a folder, attach to its "folder_changed" and "message_changed" signals. (update_unread_count, update_unread_count_main): Moved here from folder-browser but basically unchanged. Doing this here lets us get folder tree updates for folders that have had messages moved/copied/filtered into them, but which don't yet have a view associated with them. * folder-browser.c (update_unread_count, update_unread_count_main, etc): Moved to mail-tools.c svn path=/trunk/; revision=10567
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog13
-rw-r--r--mail/folder-browser.c62
-rw-r--r--mail/mail-tools.c116
3 files changed, 123 insertions, 68 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index a066751d53..d106c69d5e 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,16 @@
+2001-06-28 Dan Winship <danw@ximian.com>
+
+ * mail-tools.c (mail_tool_uri_to_folder): After finding a folder,
+ attach to its "folder_changed" and "message_changed" signals.
+ (update_unread_count, update_unread_count_main): Moved here from
+ folder-browser but basically unchanged. Doing this here lets us
+ get folder tree updates for folders that have had messages
+ moved/copied/filtered into them, but which don't yet have a view
+ associated with them.
+
+ * folder-browser.c (update_unread_count, update_unread_count_main,
+ etc): Moved to mail-tools.c
+
2001-06-28 Radek Doulik <rodo@ximian.com>
* mail-config.c: use new fields everywhere
diff --git a/mail/folder-browser.c b/mail/folder-browser.c
index 78a7570edd..4948b685b4 100644
--- a/mail/folder-browser.c
+++ b/mail/folder-browser.c
@@ -75,8 +75,6 @@ static const int num_drag_types = sizeof (drag_types) / sizeof (drag_types[0]);
static GdkAtom clipboard_atom = GDK_NONE;
-static void update_unread_count (CamelObject *, gpointer, gpointer);
-
static GtkObjectClass *folder_browser_parent_class;
enum {
@@ -109,21 +107,8 @@ folder_browser_destroy (GtkObject *object)
g_free (folder_browser->uri);
if (folder_browser->folder) {
- CamelObject *folder = CAMEL_OBJECT (folder_browser->folder);
- EvolutionStorage *storage;
-
- if ((storage = mail_lookup_storage (folder_browser->folder->parent_store))) {
- gtk_object_unref (GTK_OBJECT (storage));
- camel_object_unhook_event (folder, "message_changed",
- update_unread_count,
- folder_browser);
- camel_object_unhook_event (folder, "folder_changed",
- update_unread_count,
- folder_browser);
- }
-
mail_sync_folder (folder_browser->folder, NULL, NULL);
- camel_object_unref (folder);
+ camel_object_unref (CAMEL_OBJECT (folder_browser->folder));
}
if (folder_browser->message_list)
@@ -182,40 +167,6 @@ folder_browser_class_init (GtkObjectClass *object_class)
}
static void
-update_unread_count_main(CamelObject *object, gpointer event_data, gpointer user_data)
-{
- CamelFolder *folder = (CamelFolder *)object;
- FolderBrowser *fb = user_data;
- EvolutionStorage *storage;
- char *name;
-
- storage = mail_lookup_storage (folder->parent_store);
-
- if (fb->unread_count == 0)
- name = g_strdup (camel_folder_get_name (folder));
- else
- name = g_strdup_printf ("%s (%d)", camel_folder_get_name (folder), fb->unread_count);
-
- evolution_storage_update_folder_by_uri (storage, fb->uri, name, fb->unread_count != 0);
- g_free (name);
- gtk_object_unref (GTK_OBJECT (storage));
-}
-
-static void
-update_unread_count (CamelObject *object, gpointer event_data, gpointer user_data)
-{
- CamelFolder *folder = (CamelFolder *)object;
- FolderBrowser *fb = user_data;
- int unread;
-
- unread = camel_folder_get_unread_message_count (folder);
- if (unread == fb->unread_count)
- return;
- fb->unread_count = unread;
- mail_proxy_event (update_unread_count_main, object, event_data, user_data);
-}
-
-static void
add_uid (MessageList *ml, const char *uid, gpointer data)
{
g_ptr_array_add ((GPtrArray *) data, g_strdup (uid));
@@ -638,7 +589,6 @@ static void
got_folder(char *uri, CamelFolder *folder, void *data)
{
FolderBrowser *fb = data;
- EvolutionStorage *storage;
d(printf ("got folder '%s' = %p\n", uri, folder));
@@ -656,16 +606,6 @@ got_folder(char *uri, CamelFolder *folder, void *data)
camel_object_ref (CAMEL_OBJECT (folder));
- if ((storage = mail_lookup_storage (folder->parent_store))) {
- gtk_object_unref (GTK_OBJECT (storage));
- fb->unread_count = camel_folder_get_unread_message_count (folder);
- update_unread_count_main (CAMEL_OBJECT (folder), NULL, fb);
- camel_object_hook_event (CAMEL_OBJECT (folder), "message_changed",
- update_unread_count, fb);
- camel_object_hook_event (CAMEL_OBJECT (folder), "folder_changed",
- update_unread_count, fb);
- }
-
gtk_widget_set_sensitive (GTK_WIDGET (fb->search), camel_folder_has_search_capability (folder));
message_list_set_threaded (fb->message_list, mail_config_get_thread_list (fb->uri));
message_list_set_folder (fb->message_list, folder,
diff --git a/mail/mail-tools.c b/mail/mail-tools.c
index 7a1a9e7607..5c458e0b2a 100644
--- a/mail/mail-tools.c
+++ b/mail/mail-tools.c
@@ -43,6 +43,7 @@
#include "mail.h" /*session*/
#include "mail-tools.h"
#include "mail-local.h"
+#include "mail-mt.h"
#include "e-util/e-html-utils.h"
/* **************************************** */
@@ -244,6 +245,90 @@ mail_tool_make_message_attachment (CamelMimeMessage *message)
return part;
}
+struct folder_cache_info {
+ char *uri;
+ CamelFolder *folder;
+ int unread;
+};
+
+static void
+update_unread_count_main (CamelObject *object, gpointer event_data,
+ gpointer user_data)
+{
+ CamelFolder *folder = (CamelFolder *)object;
+ struct folder_cache_info *fci = user_data;
+ EvolutionStorage *storage;
+ char *name;
+
+ storage = mail_lookup_storage (folder->parent_store);
+ if (fci->unread == 0)
+ name = g_strdup (camel_folder_get_name (folder));
+ else
+ name = g_strdup_printf ("%s (%d)", camel_folder_get_name (folder), fci->unread);
+
+ evolution_storage_update_folder_by_uri (storage, fci->uri, name,
+ fci->unread != 0);
+ g_free (name);
+ gtk_object_unref (GTK_OBJECT (storage));
+}
+
+static void
+update_unread_count (CamelObject *object, gpointer event_data,
+ gpointer user_data)
+{
+ CamelFolder *folder = (CamelFolder *)object;
+ struct folder_cache_info *fci = user_data;
+ int unread;
+
+ unread = camel_folder_get_unread_message_count (folder);
+ if (unread == fci->unread)
+ return;
+ fci->unread = unread;
+ mail_proxy_event (update_unread_count_main, object, event_data, user_data);
+}
+
+static GHashTable *folders = NULL;
+static GStaticMutex folders_lock = G_STATIC_MUTEX_INIT;
+
+static void
+uncache_folder (CamelObject *folder, gpointer event_data, gpointer user_data)
+{
+ struct folder_cache_info *fci = user_data;
+
+ g_static_mutex_lock (&folders_lock);
+ g_hash_table_remove (folders, fci->uri);
+ g_static_mutex_unlock (&folders_lock);
+
+ g_free (fci->uri);
+ g_free (fci);
+}
+
+static void
+cache_folder (CamelFolder *folder, const char *uri)
+{
+ CamelObject *object = CAMEL_OBJECT (folder);
+ EvolutionStorage *storage;
+ struct folder_cache_info *fci;
+
+ fci = g_new (struct folder_cache_info, 1);
+ fci->folder = folder;
+ fci->uri = g_strdup (uri);
+ fci->unread = 0;
+
+ g_hash_table_insert (folders, fci->uri, fci);
+ camel_object_hook_event (object, "finalize", uncache_folder, fci);
+
+ storage = mail_lookup_storage (folder->parent_store);
+ if (storage) {
+ gtk_object_unref (GTK_OBJECT (storage));
+ update_unread_count (object, NULL, fci);
+ camel_object_hook_event (object, "message_changed",
+ update_unread_count, fci);
+ camel_object_hook_event (object, "folder_changed",
+ update_unread_count, fci);
+ }
+}
+
CamelFolder *
mail_tool_uri_to_folder (const char *uri, CamelException *ex)
{
@@ -251,16 +336,31 @@ mail_tool_uri_to_folder (const char *uri, CamelException *ex)
CamelStore *store = NULL;
CamelFolder *folder = NULL;
int offset = 0;
-
+
g_return_val_if_fail (uri != NULL, NULL);
-
+
+ g_static_mutex_lock (&folders_lock);
+ if (folders) {
+ struct folder_cache_info *fci;
+
+ fci = g_hash_table_lookup (folders, uri);
+ if (fci) {
+ camel_object_ref (CAMEL_OBJECT (fci->folder));
+ g_static_mutex_unlock (&folders_lock);
+ return fci->folder;
+ }
+ } else
+ folders = g_hash_table_new (g_str_hash, g_str_equal);
+
if (!strncmp (uri, "vtrash:", 7))
offset = 7;
-
+
url = camel_url_new (uri + offset, ex);
- if (!url)
+ if (!url) {
+ g_static_mutex_unlock (&folders_lock);
return NULL;
-
+ }
+
if (!strcmp (url->protocol, "vfolder")) {
folder = vfolder_uri_to_folder (uri, ex);
} else {
@@ -284,6 +384,7 @@ mail_tool_uri_to_folder (const char *uri, CamelException *ex)
else
folder = camel_store_get_folder (store, name,
CAMEL_STORE_FOLDER_CREATE, ex);
+ camel_object_unref (CAMEL_OBJECT (store));
}
}
@@ -293,10 +394,11 @@ mail_tool_uri_to_folder (const char *uri, CamelException *ex)
folder = NULL;
}
}
- if (store)
- camel_object_unref (CAMEL_OBJECT (store));
camel_url_free (url);
+ cache_folder (folder, uri);
+ g_static_mutex_unlock (&folders_lock);
+
return folder;
}