aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-07-16 22:16:24 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-07-18 00:08:46 +0800
commit079fc1a78d35d79350b7390ca3a76f65f9f22841 (patch)
tree83467a96914e721af4aa8fe318a3b45eab2b8206
parent3f2d55fb7ffdaa06327f69c72c591b72ffea55ad (diff)
downloadgsoc2013-evolution-079fc1a78d35d79350b7390ca3a76f65f9f22841.tar
gsoc2013-evolution-079fc1a78d35d79350b7390ca3a76f65f9f22841.tar.gz
gsoc2013-evolution-079fc1a78d35d79350b7390ca3a76f65f9f22841.tar.bz2
gsoc2013-evolution-079fc1a78d35d79350b7390ca3a76f65f9f22841.tar.lz
gsoc2013-evolution-079fc1a78d35d79350b7390ca3a76f65f9f22841.tar.xz
gsoc2013-evolution-079fc1a78d35d79350b7390ca3a76f65f9f22841.tar.zst
gsoc2013-evolution-079fc1a78d35d79350b7390ca3a76f65f9f22841.zip
MailFolderCache: Add a read-only "main-context" property.
New functions: mail_folder_cache_ref_main_context()
-rw-r--r--libemail-engine/mail-folder-cache.c60
-rw-r--r--libemail-engine/mail-folder-cache.h2
2 files changed, 62 insertions, 0 deletions
diff --git a/libemail-engine/mail-folder-cache.c b/libemail-engine/mail-folder-cache.c
index 745bd5ba9d..7c778cae2a 100644
--- a/libemail-engine/mail-folder-cache.c
+++ b/libemail-engine/mail-folder-cache.c
@@ -60,6 +60,8 @@
typedef struct _StoreInfo StoreInfo;
struct _MailFolderCachePrivate {
+ GMainContext *main_context;
+
/* source id for the ping timeout callback */
guint ping_id;
/* Store to storeinfo table, active stores */
@@ -79,6 +81,11 @@ struct _MailFolderCachePrivate {
};
enum {
+ PROP_0,
+ PROP_MAIN_CONTEXT,
+};
+
+enum {
FOLDER_AVAILABLE,
FOLDER_UNAVAILABLE,
FOLDER_DELETED,
@@ -1059,12 +1066,32 @@ storeinfo_find_folder_info (CamelStore *store,
}
static void
+mail_folder_cache_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_MAIN_CONTEXT:
+ g_value_take_boxed (
+ value,
+ mail_folder_cache_ref_main_context (
+ MAIL_FOLDER_CACHE (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
mail_folder_cache_finalize (GObject *object)
{
MailFolderCachePrivate *priv;
priv = MAIL_FOLDER_CACHE_GET_PRIVATE (object);
+ g_main_context_unref (priv->main_context);
+
g_hash_table_destroy (priv->stores);
g_rec_mutex_clear (&priv->stores_mutex);
@@ -1252,12 +1279,25 @@ mail_folder_cache_class_init (MailFolderCacheClass *class)
g_type_class_add_private (class, sizeof (MailFolderCachePrivate));
object_class = G_OBJECT_CLASS (class);
+ object_class->get_property = mail_folder_cache_get_property;
object_class->finalize = mail_folder_cache_finalize;
class->folder_available = mail_folder_cache_folder_available;
class->folder_unavailable = mail_folder_cache_folder_unavailable;
class->folder_deleted = mail_folder_cache_folder_deleted;
+ g_object_class_install_property (
+ object_class,
+ PROP_MAIN_CONTEXT,
+ g_param_spec_boxed (
+ "main-context",
+ "Main Context",
+ "The main loop context on "
+ "which to attach event sources",
+ G_TYPE_MAIN_CONTEXT,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
/**
* MailFolderCache::folder-available
* @store: the #CamelStore containing the folder
@@ -1384,6 +1424,7 @@ mail_folder_cache_init (MailFolderCache *cache)
guint timeout;
cache->priv = MAIL_FOLDER_CACHE_GET_PRIVATE (cache);
+ cache->priv->main_context = g_main_context_ref_thread_default ();
/* initialize values */
cache->priv->stores = g_hash_table_new (NULL, NULL);
@@ -1409,6 +1450,25 @@ mail_folder_cache_new (void)
}
/**
+ * mail_folder_cache_ref_main_context:
+ *
+ * Returns the #GMainContext on which event sources for @cache are to be
+ * attached.
+ *
+ * The returned #GMainContext is referenced for thread-safety and should
+ * be unreferenced with g_main_context_unref() when finished with it.
+ *
+ * Returns: a #GMainContext
+ **/
+GMainContext *
+mail_folder_cache_ref_main_context (MailFolderCache *cache)
+{
+ g_return_val_if_fail (MAIL_IS_FOLDER_CACHE (cache), NULL);
+
+ return g_main_context_ref (cache->priv->main_context);
+}
+
+/**
* mail_folder_cache_note_store:
*
* Add a store whose folders should appear in the shell The folders are scanned
diff --git a/libemail-engine/mail-folder-cache.h b/libemail-engine/mail-folder-cache.h
index e1547f1bf1..4581552524 100644
--- a/libemail-engine/mail-folder-cache.h
+++ b/libemail-engine/mail-folder-cache.h
@@ -108,6 +108,8 @@ struct _MailFolderCacheClass {
GType mail_folder_cache_get_type (void) G_GNUC_CONST;
MailFolderCache *
mail_folder_cache_new (void);
+GMainContext * mail_folder_cache_ref_main_context
+ (MailFolderCache *cache);
void mail_folder_cache_note_store (MailFolderCache *cache,
CamelStore *store,
GCancellable *cancellable,