aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2011-05-18 22:34:51 +0800
committerMatthew Barnes <mbarnes@redhat.com>2011-05-19 04:07:13 +0800
commit158128ef783bde14a258429706a94e78b11a06a8 (patch)
tree8c15c3426b4a319758d0dc0c6cfb38f41eabc7ff
parent2a95b0fc0d8ded03166c77eff0cce597d6a6418c (diff)
downloadgsoc2013-evolution-158128ef783bde14a258429706a94e78b11a06a8.tar
gsoc2013-evolution-158128ef783bde14a258429706a94e78b11a06a8.tar.gz
gsoc2013-evolution-158128ef783bde14a258429706a94e78b11a06a8.tar.bz2
gsoc2013-evolution-158128ef783bde14a258429706a94e78b11a06a8.tar.lz
gsoc2013-evolution-158128ef783bde14a258429706a94e78b11a06a8.tar.xz
gsoc2013-evolution-158128ef783bde14a258429706a94e78b11a06a8.tar.zst
gsoc2013-evolution-158128ef783bde14a258429706a94e78b11a06a8.zip
Remove mail_get_folderinfo().
Use camel_store_get_folder_info() instead.
-rw-r--r--mail/mail-folder-cache.c84
-rw-r--r--mail/mail-ops.c96
-rw-r--r--mail/mail-ops.h6
3 files changed, 55 insertions, 131 deletions
diff --git a/mail/mail-folder-cache.c b/mail/mail-folder-cache.c
index 6f4829be7d..5ee3bc596d 100644
--- a/mail/mail-folder-cache.c
+++ b/mail/mail-folder-cache.c
@@ -709,12 +709,10 @@ store_folder_renamed_cb (CamelStore *store,
}
struct _update_data {
- gint id; /* id for cancellation */
- guint cancel:1; /* also tells us we're cancelled */
-
NoteDoneFunc done;
gpointer data;
MailFolderCache *cache;
+ GCancellable *cancellable;
};
static void
@@ -730,32 +728,48 @@ free_folder_info_hash (gchar *path, struct _folder_info *mfi, gpointer data)
free_folder_info (mfi);
}
-static gboolean
-update_folders (CamelStore *store, CamelFolderInfo *fi, gpointer data)
+static void
+update_folders (CamelStore *store,
+ GAsyncResult *result,
+ struct _update_data *ud)
{
- struct _update_data *ud = data;
+ CamelFolderInfo *fi;
struct _store_info *si;
- gboolean res = TRUE;
+ GError *error = NULL;
- d(printf("Got folderinfo for store %s\n", store->parent_object.provider->protocol));
+ fi = camel_store_get_folder_info_finish (store, result, &error);
+
+ if (error != NULL) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
g_mutex_lock (ud->cache->priv->stores_mutex);
si = g_hash_table_lookup (ud->cache->priv->stores, store);
- if (si && !ud->cancel) {
- /* the 'si' is still there, so we can remove ourselves from its list */
- /* otherwise its not, and we're on our own and free anyway */
+ if (si && !g_cancellable_is_cancelled (ud->cancellable)) {
+ /* The 'si' is still there, so we can remove ourselves from
+ * its list. Or else its not, and we're on our own and free
+ * anyway. */
g_queue_remove (&si->folderinfo_updates, ud);
- if (fi)
+ if (fi != NULL)
create_folders (ud->cache, fi, si);
}
g_mutex_unlock (ud->cache->priv->stores_mutex);
- if (ud->done)
- res = ud->done (ud->cache, store, fi, ud->data);
- g_free (ud);
+ if (fi != NULL) {
+ gboolean free_fi = TRUE;
- return res;
+ if (ud->done != NULL)
+ free_fi = ud->done (ud->cache, store, fi, ud->data);
+ if (free_fi)
+ camel_store_free_folder_info (store, fi);
+ }
+
+ if (ud->cancellable != NULL)
+ g_object_unref (ud->cancellable);
+
+ g_free (ud);
}
struct _ping_store_msg {
@@ -856,12 +870,21 @@ store_go_online_cb (CamelStore *store,
g_mutex_lock (ud->cache->priv->stores_mutex);
- if (g_hash_table_lookup (ud->cache->priv->stores, store) != NULL && !ud->cancel) {
- /* re-use the cancel id. we're already in the store update list too */
- ud->id = mail_get_folderinfo (store, NULL, update_folders, ud);
+ if (g_hash_table_lookup (ud->cache->priv->stores, store) != NULL &&
+ !g_cancellable_is_cancelled (ud->cancellable)) {
+ /* We're already in the store update list. */
+ camel_store_get_folder_info (
+ store, NULL,
+ CAMEL_STORE_FOLDER_INFO_FAST |
+ CAMEL_STORE_FOLDER_INFO_RECURSIVE |
+ CAMEL_STORE_FOLDER_INFO_SUBSCRIBED,
+ G_PRIORITY_DEFAULT, ud->cancellable,
+ (GAsyncReadyCallback) update_folders, ud);
} else {
- /* the store vanished, that means we were probably cancelled, or at any rate,
- need to clean ourselves up */
+ /* The store vanished, that means we were probably cancelled,
+ * or at any rate, need to clean ourselves up. */
+ if (ud->cancellable != NULL)
+ g_object_unref (ud->cancellable);
g_free (ud);
}
@@ -1114,9 +1137,11 @@ mail_folder_cache_note_store (MailFolderCache *self,
ud = g_malloc (sizeof (*ud));
ud->done = done;
ud->data = data;
- ud->cancel = 0;
ud->cache = self;
+ if (G_IS_CANCELLABLE (cancellable))
+ ud->cancellable = g_object_ref (cancellable);
+
/* We might get a race when setting up a store, such that it is
* still left in offline mode, after we've gone online. This
* catches and fixes it up when the shell opens us. */
@@ -1142,8 +1167,13 @@ mail_folder_cache_note_store (MailFolderCache *self,
}
} else {
normal_setup:
- ud->id = mail_get_folderinfo (
- store, cancellable, update_folders, ud);
+ camel_store_get_folder_info (
+ store, NULL,
+ CAMEL_STORE_FOLDER_INFO_FAST |
+ CAMEL_STORE_FOLDER_INFO_RECURSIVE |
+ CAMEL_STORE_FOLDER_INFO_SUBSCRIBED,
+ G_PRIORITY_DEFAULT, cancellable,
+ (GAsyncReadyCallback) update_folders, ud);
}
g_queue_push_tail (&si->folderinfo_updates, ud);
@@ -1210,11 +1240,7 @@ mail_folder_cache_note_store_remove (MailFolderCache *self,
while (link != NULL) {
struct _update_data *ud = link->data;
-
- d(printf("Cancelling outstanding folderinfo update %d\n", ud->id));
- mail_msg_cancel (ud->id);
- ud->cancel = 1;
-
+ g_cancellable_cancel (ud->cancellable);
link = g_list_next (link);
}
diff --git a/mail/mail-ops.c b/mail/mail-ops.c
index ad86c772d6..cbb50315ec 100644
--- a/mail/mail-ops.c
+++ b/mail/mail-ops.c
@@ -1031,102 +1031,6 @@ mail_transfer_messages (EMailSession *session,
mail_msg_slow_ordered_push (m);
}
-/* ** SCAN SUBFOLDERS ***************************************************** */
-
-struct _get_folderinfo_msg {
- MailMsg base;
-
- CamelStore *store;
- CamelFolderInfo *info;
- gboolean (*done)(CamelStore *store, CamelFolderInfo *info, gpointer data);
- gpointer data;
- gboolean can_clear; /* whether we can clear folder info */
-};
-
-static gchar *
-get_folderinfo_desc (struct _get_folderinfo_msg *m)
-{
- gchar *ret, *name;
-
- name = camel_service_get_name ((CamelService *) m->store, TRUE);
- ret = g_strdup_printf (_("Scanning folders in '%s'"), name);
- g_free (name);
- return ret;
-}
-
-static void
-get_folderinfo_exec (struct _get_folderinfo_msg *m,
- GCancellable *cancellable,
- GError **error)
-{
- guint32 flags;
-
- flags = CAMEL_STORE_FOLDER_INFO_RECURSIVE |
- CAMEL_STORE_FOLDER_INFO_FAST |
- CAMEL_STORE_FOLDER_INFO_SUBSCRIBED;
-
- m->info = camel_store_get_folder_info_sync (
- m->store, NULL, flags,
- cancellable, error);
-}
-
-static void
-get_folderinfo_done (struct _get_folderinfo_msg *m)
-{
- if (!m->info && m->base.error != NULL) {
- gchar *url;
-
- url = camel_service_get_url (CAMEL_SERVICE (m->store));
- w(g_warning ("Error getting folder info from store at %s: %s",
- url, m->base.error->message));
- g_free (url);
- }
-
- if (m->done)
- m->can_clear = m->done (m->store, m->info, m->data);
- else
- m->can_clear = TRUE;
-}
-
-static void
-get_folderinfo_free (struct _get_folderinfo_msg *m)
-{
- if (m->info && m->can_clear)
- camel_store_free_folder_info (m->store, m->info);
- g_object_unref (m->store);
-}
-
-static MailMsgInfo get_folderinfo_info = {
- sizeof (struct _get_folderinfo_msg),
- (MailMsgDescFunc) get_folderinfo_desc,
- (MailMsgExecFunc) get_folderinfo_exec,
- (MailMsgDoneFunc) get_folderinfo_done,
- (MailMsgFreeFunc) get_folderinfo_free
-};
-
-gint
-mail_get_folderinfo (CamelStore *store,
- GCancellable *cancellable,
- gboolean (*done)(CamelStore *store, CamelFolderInfo *info, gpointer data),
- gpointer data)
-{
- struct _get_folderinfo_msg *m;
- gint id;
-
- m = mail_msg_new (&get_folderinfo_info);
- if (G_IS_CANCELLABLE (cancellable))
- e_activity_set_cancellable (m->base.activity, cancellable);
- m->store = store;
- g_object_ref (store);
- m->done = done;
- m->data = data;
- id = m->base.seq;
-
- mail_msg_unordered_push (m);
-
- return id;
-}
-
/* ** REMOVE FOLDER ******************************************************* */
struct _remove_folder_msg {
diff --git a/mail/mail-ops.h b/mail/mail-ops.h
index 520cae61ce..8e808d42bb 100644
--- a/mail/mail-ops.h
+++ b/mail/mail-ops.h
@@ -60,12 +60,6 @@ void mail_empty_trash (EMailSession *session,
void (*done) (EAccount *account, gpointer data),
gpointer data);
-/* get folder info asynchronously */
-gint mail_get_folderinfo (CamelStore *store,
- GCancellable *cancellable,
- gboolean (*done)(CamelStore *store, CamelFolderInfo *info, gpointer data),
- gpointer data);
-
/* remove an existing folder */
void mail_remove_folder (CamelFolder *folder,
void (*done) (CamelFolder *folder, gboolean removed, GError **error, gpointer data),