[evolution] Add mail_folder_cache_has_folder_info().



commit 4de572679748a0586b9a9c3bf34c40ea5102e826
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Jul 15 09:45:22 2013 -0400

    Add mail_folder_cache_has_folder_info().
    
    Returns whether MailFolderCache has information about the folder
    described by the CamelStore and folder name.  This does not necessarily
    mean it has the CamelFolder instance, but it at least has some meta-data
    about it.
    
    You can use this function as a folder existence test.

 libemail-engine/mail-folder-cache.c |   38 ++++++++++++++++++++++++++++++++
 libemail-engine/mail-folder-cache.h |    4 +++
 libemail-engine/mail-vfolder.c      |   41 ++++++++++++++++++++++++++--------
 3 files changed, 73 insertions(+), 10 deletions(-)
---
diff --git a/libemail-engine/mail-folder-cache.c b/libemail-engine/mail-folder-cache.c
index 7c778ca..bf4e8b3 100644
--- a/libemail-engine/mail-folder-cache.c
+++ b/libemail-engine/mail-folder-cache.c
@@ -1628,6 +1628,44 @@ mail_folder_cache_note_folder (MailFolderCache *cache,
 }
 
 /**
+ * mail_folder_cache_has_folder_info:
+ * @cache: a #MailFolderCache
+ * @store: a #CamelStore
+ * @folder_name: a folder name
+ *
+ * Returns whether @cache has information about the folder described by
+ * @store and @folder_name.  This does not necessarily mean it has the
+ * #CamelFolder instance, but it at least has some meta-data about it.
+ *
+ * You can use this function as a folder existence test.
+ *
+ * Returns: %TRUE if @cache has folder info, %FALSE otherwise
+ **/
+gboolean
+mail_folder_cache_has_folder_info (MailFolderCache *cache,
+                                   CamelStore *store,
+                                   const gchar *folder_name)
+{
+       StoreInfo *si;
+       gboolean has_info = FALSE;
+
+       g_return_val_if_fail (MAIL_IS_FOLDER_CACHE (cache), FALSE);
+       g_return_val_if_fail (CAMEL_IS_STORE (store), FALSE);
+       g_return_val_if_fail (folder_name != NULL, FALSE);
+
+       if (cache->priv->stores == NULL)
+               return FALSE;
+
+       g_rec_mutex_lock (&cache->priv->stores_mutex);
+       si = g_hash_table_lookup (cache->priv->stores, store);
+       if (si != NULL)
+               has_info = g_hash_table_contains (si->folders, folder_name);
+       g_rec_mutex_unlock (&cache->priv->stores_mutex);
+
+       return has_info;
+}
+
+/**
  * mail_folder_cache_get_folder_from_uri:
  *
  * Gets the #CamelFolder for the supplied @uri.
diff --git a/libemail-engine/mail-folder-cache.h b/libemail-engine/mail-folder-cache.h
index 4581552..02c305e 100644
--- a/libemail-engine/mail-folder-cache.h
+++ b/libemail-engine/mail-folder-cache.h
@@ -117,6 +117,10 @@ void               mail_folder_cache_note_store    (MailFolderCache *cache,
                                                 gpointer data);
 void           mail_folder_cache_note_folder   (MailFolderCache *cache,
                                                 CamelFolder *folder);
+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,
diff --git a/libemail-engine/mail-vfolder.c b/libemail-engine/mail-vfolder.c
index fbddfd8..afd7a03 100644
--- a/libemail-engine/mail-vfolder.c
+++ b/libemail-engine/mail-vfolder.c
@@ -57,6 +57,32 @@ static void rule_changed (EFilterRule *rule, CamelFolder *folder);
 
 /* ********************************************************************** */
 
+static gboolean
+vfolder_cache_has_folder_info (EMailSession *session,
+                               const gchar *folder_uri)
+{
+       MailFolderCache *folder_cache;
+       CamelStore *store = NULL;
+       gchar *folder_name = NULL;
+       gboolean cache_has_info = FALSE;
+
+       folder_cache = e_mail_session_get_folder_cache (session);
+
+       e_mail_folder_uri_parse (
+               CAMEL_SESSION (session), folder_uri,
+               &store, &folder_name, NULL);
+
+       if (store != NULL && folder_name != NULL) {
+               cache_has_info = mail_folder_cache_has_folder_info (
+                       folder_cache, store, folder_name);
+       }
+
+       g_clear_object (&store);
+       g_free (folder_name);
+
+       return cache_has_info;
+}
+
 static GList *
 vfolder_get_include_subfolders_uris (EMailSession *session,
                                      const gchar *base_uri,
@@ -292,17 +318,15 @@ vfolder_adduri_exec (struct _adduri_msg *m,
                      GError **error)
 {
        CamelFolder *folder = NULL;
-       MailFolderCache *folder_cache;
+       gboolean cache_has_info;
 
        if (vfolder_shutdown)
                return;
 
-       folder_cache = e_mail_session_get_folder_cache (m->session);
-
-       /* we dont try lookup the cache if we are removing it, its no longer there */
+       cache_has_info = vfolder_cache_has_folder_info (
+               m->session, m->uri[0] == '*' ? m->uri + 1 : m->uri);
 
-       if (!m->remove &&
-           !mail_folder_cache_get_folder_from_uri (folder_cache, m->uri[0] == '*' ? m->uri + 1 : m->uri, 
NULL)) {
+       if (!m->remove && !cache_has_info) {
                g_warning (
                        "Folder '%s' disappeared while I was "
                        "adding/removing it to/from my vfolder", m->uri);
@@ -767,18 +791,15 @@ rule_add_sources (EMailSession *session,
                   EMVFolderRule *rule)
 {
        GList *sources_uri = *sources_urip;
-       MailFolderCache *folder_cache;
        GList *head, *link;
 
-       folder_cache = e_mail_session_get_folder_cache (session);
-
        head = g_queue_peek_head_link (queue);
        for (link = head; link != NULL; link = g_list_next (link)) {
                const gchar *uri = link->data;
 
                /* always pick fresh folders - they are
                 * from CamelStore's folders bag anyway */
-               if (mail_folder_cache_get_folder_from_uri (folder_cache, uri, NULL)) {
+               if (vfolder_cache_has_folder_info (session, uri)) {
                        /* "tag" uris with subfolders with a star prefix */
                        if (!rule || !em_vfolder_rule_source_get_include_subfolders (rule, uri))
                                sources_uri = g_list_prepend (sources_uri, g_strdup (uri));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]