aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-07-15 22:38:11 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-07-18 00:08:46 +0800
commitc36aa6b7498ac73a77624533516b010f5701f08b (patch)
tree8fbe15ebb84ad3e5ea1785bf203c09bddc17d803
parent4de572679748a0586b9a9c3bf34c40ea5102e826 (diff)
downloadgsoc2013-evolution-c36aa6b7498ac73a77624533516b010f5701f08b.tar
gsoc2013-evolution-c36aa6b7498ac73a77624533516b010f5701f08b.tar.gz
gsoc2013-evolution-c36aa6b7498ac73a77624533516b010f5701f08b.tar.bz2
gsoc2013-evolution-c36aa6b7498ac73a77624533516b010f5701f08b.tar.lz
gsoc2013-evolution-c36aa6b7498ac73a77624533516b010f5701f08b.tar.xz
gsoc2013-evolution-c36aa6b7498ac73a77624533516b010f5701f08b.tar.zst
gsoc2013-evolution-c36aa6b7498ac73a77624533516b010f5701f08b.zip
Add mail_folder_cache_ref_folder().
Replaces mail_folder_cache_get_folder_from_uri(). Returns the CamelFolder for the CamelStore and folder name if available, or else NULL if a CamelFolder instance is not yet cached. This function does not block.
-rw-r--r--libemail-engine/mail-folder-cache.c50
-rw-r--r--libemail-engine/mail-folder-cache.h7
-rw-r--r--mail/e-mail-backend.c29
-rw-r--r--mail/em-folder-tree-model.c17
4 files changed, 54 insertions, 49 deletions
diff --git a/libemail-engine/mail-folder-cache.c b/libemail-engine/mail-folder-cache.c
index bf4e8b3fdb..5b99f34c1b 100644
--- a/libemail-engine/mail-folder-cache.c
+++ b/libemail-engine/mail-folder-cache.c
@@ -1666,36 +1666,46 @@ mail_folder_cache_has_folder_info (MailFolderCache *cache,
}
/**
- * mail_folder_cache_get_folder_from_uri:
+ * mail_folder_cache_ref_folder:
+ * @cache: a #MailFolderCache
+ * @store: a #CamelStore
+ * @folder_name: a folder name
*
- * Gets the #CamelFolder for the supplied @uri.
+ * Returns the #CamelFolder for @store and @folder_name if available, or
+ * else %NULL if a #CamelFolder instance is not yet cached. This function
+ * does not block.
*
- * Returns: %TRUE if the URI is available, folderp is set to a reffed
- * folder if the folder has also already been opened
- */
-gboolean
-mail_folder_cache_get_folder_from_uri (MailFolderCache *cache,
- const gchar *uri,
- CamelFolder **folderp)
+ * The returned #CamelFolder is referenced for thread-safety and must be
+ * unreferenced with g_object_unref() when finished with it.
+ *
+ * Returns: a #CamelFolder, or %NULL
+ **/
+CamelFolder *
+mail_folder_cache_ref_folder (MailFolderCache *cache,
+ CamelStore *store,
+ const gchar *folder_name)
{
- struct _find_info fi = { uri, NULL };
+ StoreInfo *si;
+ struct _folder_info *fi;
+ CamelFolder *folder = NULL;
+
+ g_return_val_if_fail (MAIL_IS_FOLDER_CACHE (cache), NULL);
+ g_return_val_if_fail (CAMEL_IS_STORE (store), NULL);
+ g_return_val_if_fail (folder_name != NULL, NULL);
if (cache->priv->stores == NULL)
- return FALSE;
+ return NULL;
g_rec_mutex_lock (&cache->priv->stores_mutex);
- g_hash_table_foreach (
- cache->priv->stores, (GHFunc)
- storeinfo_find_folder_info, &fi);
- if (folderp) {
- if (fi.fi && fi.fi->folder)
- *folderp = g_object_ref (fi.fi->folder);
- else
- *folderp = NULL;
+ si = g_hash_table_lookup (cache->priv->stores, store);
+ if (si != NULL) {
+ fi = g_hash_table_lookup (si->folders, folder_name);
+ if (fi != NULL && fi->folder != NULL)
+ folder = g_object_ref (fi->folder);
}
g_rec_mutex_unlock (&cache->priv->stores_mutex);
- return fi.fi != NULL;
+ return folder;
}
gboolean
diff --git a/libemail-engine/mail-folder-cache.h b/libemail-engine/mail-folder-cache.h
index 02c305ecea..280502147c 100644
--- a/libemail-engine/mail-folder-cache.h
+++ b/libemail-engine/mail-folder-cache.h
@@ -121,10 +121,9 @@ gboolean mail_folder_cache_has_folder_info
(MailFolderCache *cache,
CamelStore *store,
const gchar *folder_name);
-gboolean mail_folder_cache_get_folder_from_uri
- (MailFolderCache *cache,
- const gchar *uri,
- CamelFolder **folderp);
+CamelFolder * mail_folder_cache_ref_folder (MailFolderCache *cache,
+ CamelStore *store,
+ const gchar *folder_name);
gboolean mail_folder_cache_get_folder_info_flags
(MailFolderCache *cache,
CamelFolder *folder,
diff --git a/mail/e-mail-backend.c b/mail/e-mail-backend.c
index d1ca660ab7..c2952daffd 100644
--- a/mail/e-mail-backend.c
+++ b/mail/e-mail-backend.c
@@ -673,35 +673,30 @@ mail_backend_folder_changed_cb (MailFolderCache *folder_cache,
EMEvent *event = em_event_peek ();
EMEventTargetFolder *target;
EMFolderTreeModel *model;
+ CamelFolder *folder;
gchar *folder_uri;
gint folder_type;
CamelFolderInfoFlags flags = 0;
folder_uri = e_mail_folder_uri_build (store, folder_name);
- if (folder_uri != NULL) {
- CamelFolder *folder = NULL;
-
- if (mail_folder_cache_get_folder_from_uri (
- folder_cache, folder_uri, &folder)) {
- if (folder != NULL &&
- !mail_folder_cache_get_folder_info_flags (
- folder_cache, folder, &flags)) {
- g_free (folder_uri);
- g_return_if_reached ();
- }
- }
-
- if (folder != NULL)
- g_object_unref (folder);
+ folder = mail_folder_cache_ref_folder (
+ folder_cache, store, folder_name);
+ if (folder != NULL) {
+ /* XXX Need to rethink this API. Why should we
+ * need the CamelFolder instance just to get
+ * folder flags? The flags are more readily
+ * available than the CamelFolder instance. */
+ mail_folder_cache_get_folder_info_flags (
+ folder_cache, folder, &flags);
+ g_object_unref (folder);
}
target = em_event_target_new_folder (
event, store, folder_uri, new_messages,
msg_uid, msg_sender, msg_subject);
- if (folder_uri)
- g_free (folder_uri);
+ g_free (folder_uri);
folder_type = (flags & CAMEL_FOLDER_TYPE_MASK);
target->is_inbox = (folder_type == CAMEL_FOLDER_TYPE_INBOX);
diff --git a/mail/em-folder-tree-model.c b/mail/em-folder-tree-model.c
index eaa6b92342..66f292695b 100644
--- a/mail/em-folder-tree-model.c
+++ b/mail/em-folder-tree-model.c
@@ -748,22 +748,23 @@ em_folder_tree_model_set_folder_info (EMFolderTreeModel *model,
/* XXX This is duplicated in mail-folder-cache too, should perhaps
* be functionised. */
unread = fi->unread;
- if (mail_folder_cache_get_folder_from_uri (
- folder_cache, uri, &folder) && folder) {
+ folder = mail_folder_cache_ref_folder (
+ folder_cache, si->store, fi->full_name);
+ if (folder != NULL) {
folder_is_drafts = em_utils_folder_is_drafts (registry, folder);
folder_is_outbox = em_utils_folder_is_outbox (registry, folder);
if (folder_is_drafts || folder_is_outbox) {
gint total;
+ gint deleted;
- if ((total = camel_folder_get_message_count (folder)) > 0) {
- gint deleted = camel_folder_get_deleted_message_count (folder);
+ total = camel_folder_get_message_count (folder);
+ deleted = camel_folder_get_deleted_message_count (folder);
- if (deleted != -1)
- total -= deleted;
- }
+ if (total > 0 && deleted != -1)
+ total -= deleted;
- unread = total > 0 ? total : 0;
+ unread = MAX (total, 0);
}
g_object_unref (folder);