From 8563120ccac076a0baf9cb904c23a87bbb59d960 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Tue, 13 Apr 2004 15:58:56 +0000 Subject: implement the new counts, and get them all atomically so they're only 2004-04-13 Not Zed * camel-folder.c (folder_getv): implement the new counts, and get them all atomically so they're only calculated once and can return consistent results. * camel-folder.h: Added CAMEL_FOLDER_DELETED, CAMEL_FOLDER_JUNKED, and CAMEL_FOLDER_VISIBLE args, to support client display of various values. svn path=/trunk/; revision=25437 --- camel/camel-folder.c | 54 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 12 deletions(-) (limited to 'camel/camel-folder.c') diff --git a/camel/camel-folder.c b/camel/camel-folder.c index ca30bb24cd..853c49400d 100644 --- a/camel/camel-folder.c +++ b/camel/camel-folder.c @@ -313,6 +313,7 @@ folder_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args) CamelFolder *folder = (CamelFolder *)object; int i; guint32 tag; + int unread = -1, deleted = 0, junked = 0, visible = 0, count; for (i=0;iargc;i++) { CamelArgGet *arg = &args->argv[i]; @@ -343,21 +344,50 @@ folder_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args) case CAMEL_FOLDER_ARG_TOTAL: *arg->ca_int = camel_folder_summary_count(folder->summary); break; - case CAMEL_FOLDER_ARG_UNREAD: { - int j, unread = 0, count; - CamelMessageInfo *info; - - count = camel_folder_summary_count(folder->summary); - for (j=0; jsummary, j))) { - if (!(info->flags & CAMEL_MESSAGE_SEEN)) - unread++; - camel_folder_summary_info_free(folder->summary, info); + case CAMEL_FOLDER_ARG_UNREAD: + case CAMEL_FOLDER_ARG_DELETED: + case CAMEL_FOLDER_ARG_JUNKED: + case CAMEL_FOLDER_ARG_VISIBLE: + /* This is so we can get the values atomically, and also so we can calculate them only once */ + if (unread == -1) { + int j; + CamelMessageInfo *info; + + /* TODO: Locking? */ + unread = 0; + count = camel_folder_summary_count(folder->summary); + for (j=0; jsummary, j))) { + if (!(info->flags & CAMEL_MESSAGE_SEEN)) + unread++; + if (info->flags & CAMEL_MESSAGE_DELETED) + deleted++; + if (info->flags & CAMEL_MESSAGE_JUNK) + junked++; + if ((info->flags & (CAMEL_MESSAGE_DELETED|CAMEL_MESSAGE_JUNK)) == 0) + visible++; + camel_folder_summary_info_free(folder->summary, info); + } } } - *arg->ca_int = unread; - break; } + switch (tag & CAMEL_ARG_TAG) { + case CAMEL_FOLDER_ARG_UNREAD: + count = unread; + break; + case CAMEL_FOLDER_ARG_DELETED: + count = deleted; + break; + case CAMEL_FOLDER_ARG_JUNKED: + count = junked; + break; + case CAMEL_FOLDER_ARG_VISIBLE: + count = visible; + break; + } + + *arg->ca_int = count; + break; case CAMEL_FOLDER_ARG_UID_ARRAY: { int j, count; CamelMessageInfo *info; -- cgit v1.2.3