From 5de6e2a14b9d3e4fc3260cfa195921d020249a22 Mon Sep 17 00:00:00 2001 From: Michael Zucci Date: Fri, 21 Sep 2001 00:55:36 +0000 Subject: Setup unread count properly, and also setup the url properly. * providers/local/camel-local-folder.c (camel_local_folder_construct): Setup unread count properly, and also setup the url properly. (scan_dir): Dont include empty host part in url for folder. (scan_dir): Lookup folder counts for any folders we currenty have open. svn path=/trunk/; revision=13035 --- camel/providers/local/camel-local-folder.c | 6 +++-- camel/providers/local/camel-maildir-store.c | 34 ++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 12 deletions(-) (limited to 'camel/providers') diff --git a/camel/providers/local/camel-local-folder.c b/camel/providers/local/camel-local-folder.c index 2887fcce73..2e9e348695 100644 --- a/camel/providers/local/camel-local-folder.c +++ b/camel/providers/local/camel-local-folder.c @@ -224,9 +224,11 @@ camel_local_folder_construct(CamelLocalFolder *lf, CamelStore *parent_store, con fi = g_new0 (CamelFolderInfo, 1); fi->full_name = g_strdup (full_name); fi->name = g_strdup (name); - fi->url = g_strdup (lf->folder_path); - fi->unread_message_count = -1; + fi->url = g_strdup_printf("%s:%s#%s", ((CamelService *)parent_store)->url->protocol, + ((CamelService *)parent_store)->url->protocol, full_name); + fi->unread_message_count = camel_folder_get_unread_message_count(folder); camel_folder_info_build_path(fi, '/'); + camel_object_trigger_event(CAMEL_OBJECT (parent_store), "folder_created", fi); camel_folder_info_free(fi); diff --git a/camel/providers/local/camel-maildir-store.c b/camel/providers/local/camel-maildir-store.c index 974a66a038..b0d4c072f8 100644 --- a/camel/providers/local/camel-maildir-store.c +++ b/camel/providers/local/camel-maildir-store.c @@ -35,6 +35,7 @@ #include "camel-maildir-folder.h" #include "camel-exception.h" #include "camel-url.h" +#include "camel-private.h" #define d(x) @@ -141,11 +142,10 @@ static CamelFolder *get_folder(CamelStore * store, const char *folder_name, guin return folder; } -/* fixes bug #1138 */ static CamelFolder * get_inbox (CamelStore *store, CamelException *ex) { - return get_folder (store, "", 0, ex); + return get_folder (store, ".", 0, ex); } static void delete_folder(CamelStore * store, const char *folder_name, CamelException * ex) @@ -226,6 +226,8 @@ static CamelFolderInfo *camel_folder_info_new(const char *url, const char *full, fi->unread_message_count = unread; camel_folder_info_build_path(fi, '/'); + d(printf("Adding maildir info: '%s' '%s' '%s'\n", fi->path, fi->name, fi->full_name)); + return fi; } @@ -236,7 +238,7 @@ struct _inode { }; /* returns number of records found at or below this level */ -static int scan_dir(GHashTable *visited, char *root, const char *path, guint32 flags, CamelFolderInfo *parent, CamelFolderInfo **fip, CamelException *ex) +static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const char *path, guint32 flags, CamelFolderInfo *parent, CamelFolderInfo **fip, CamelException *ex) { DIR *dir; struct dirent *d; @@ -244,6 +246,8 @@ static int scan_dir(GHashTable *visited, char *root, const char *path, guint32 f const char *base; CamelFolderInfo *fi = NULL; struct stat st; + CamelFolder *folder; + int unread; /* look for folders matching the right structure, recursively */ name = g_strdup_printf("%s/%s", root, path); @@ -256,17 +260,27 @@ static int scan_dir(GHashTable *visited, char *root, const char *path, guint32 f if (stat(tmp, &st) == 0 && S_ISDIR(st.st_mode) && stat(cur, &st) == 0 && S_ISDIR(st.st_mode) - && stat(new, &st) == 0 && S_ISDIR(st.st_mode)) - uri = g_strdup_printf("maildir://%s#%s", root, path); - else - uri = g_strdup_printf("maildir://%s;noselect=yes#%s", root, path); + && stat(new, &st) == 0 && S_ISDIR(st.st_mode)) { + uri = g_strdup_printf("maildir:%s#%s", root, path); + } else + uri = g_strdup_printf("maildir:%s;noselect=yes#%s", root, path); base = strrchr(path, '/'); if (base) base++; else base = path; - fi = camel_folder_info_new(uri, path, base, -1); + + /* if we have this folder open, get the real unread count */ + CAMEL_STORE_LOCK(store, cache_lock); + folder = g_hash_table_lookup(store->folders, path); + if (folder) + unread = camel_folder_get_message_count(folder); + else + unread = 0; + CAMEL_STORE_UNLOCK(store, cache_lock); + + fi = camel_folder_info_new(uri, path, base, unread); d(printf("found! uri = %s\n", fi->url)); d(printf(" full_name = %s\n name = '%s'\n", fi->full_name, fi->name)); @@ -310,7 +324,7 @@ static int scan_dir(GHashTable *visited, char *root, const char *path, guint32 f *inew = in; g_hash_table_insert(visited, inew, inew); new = g_strdup_printf("%s/%s", path, d->d_name); - if (scan_dir(visited, root, new, flags, fi, &fi->child, ex) == -1) { + if (scan_dir(store, visited, root, new, flags, fi, &fi->child, ex) == -1) { g_free(tmp); g_free(new); closedir(dir); @@ -357,7 +371,7 @@ get_folder_info (CamelStore *store, const char *top, guint32 flags, CamelExcepti visited = g_hash_table_new(inode_hash, inode_equal); - if (scan_dir(visited, service->url->path, top?top:".", flags, NULL, &fi, ex) == -1 && fi != NULL) { + if (scan_dir(store, visited, service->url->path, top?top:".", flags, NULL, &fi, ex) == -1 && fi != NULL) { camel_store_free_folder_info_full(store, fi); fi = NULL; } -- cgit v1.2.3