aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorJonathon Jongsma <jonathon@quotidian.org>2009-12-12 04:37:49 +0800
committerJonathon Jongsma <jonathon@quotidian.org>2009-12-16 04:16:09 +0800
commit9c644867fe24587339531267d9e27890513c6292 (patch)
treeaf7bcb29e22814f5b39eafb20cfc2a2678973b63 /mail
parent0eef4618ca677cd11d54ce0ae8804b5b1ededf3b (diff)
downloadgsoc2013-evolution-9c644867fe24587339531267d9e27890513c6292.tar.gz
gsoc2013-evolution-9c644867fe24587339531267d9e27890513c6292.tar.zst
gsoc2013-evolution-9c644867fe24587339531267d9e27890513c6292.zip
MailFolderCache: add signal for updated unread counts
Emit a signal when we have an updated unread count for a folder rather than pushing the update directly to a particular treemodel. This doesn't yet remove the dependency on EMFolderTreeModel, but it's a first step. https://bugzilla.gnome.org/show_bug.cgi?id=604627
Diffstat (limited to 'mail')
-rw-r--r--mail/em-folder-tree-model.c122
-rw-r--r--mail/em-folder-tree-model.h5
-rw-r--r--mail/mail-folder-cache.c23
3 files changed, 88 insertions, 62 deletions
diff --git a/mail/em-folder-tree-model.c b/mail/em-folder-tree-model.c
index 4833277a71..19697a4f6a 100644
--- a/mail/em-folder-tree-model.c
+++ b/mail/em-folder-tree-model.c
@@ -372,6 +372,69 @@ folder_tree_model_class_init (EMFolderTreeModelClass *class)
}
static void
+em_folder_tree_model_set_unread_count (EMFolderTreeModel *model,
+ CamelStore *store,
+ const gchar *full,
+ gint unread)
+{
+ EMFolderTreeModelStoreInfo *si;
+ GtkTreeRowReference *reference;
+ GtkTreeModel *tree_model;
+ GtkTreePath *path;
+ GtkTreeIter parent;
+ GtkTreeIter iter;
+ guint old_unread = 0;
+
+ g_return_if_fail (EM_IS_FOLDER_TREE_MODEL (model));
+ g_return_if_fail (CAMEL_IS_STORE (store));
+ g_return_if_fail (full != NULL);
+
+ if (unread < 0)
+ return;
+
+ si = em_folder_tree_model_lookup_store_info (model, store);
+ if (si == NULL)
+ return;
+
+ reference = g_hash_table_lookup (si->full_hash, full);
+ if (!gtk_tree_row_reference_valid (reference))
+ return;
+
+ tree_model = GTK_TREE_MODEL (model);
+
+ path = gtk_tree_row_reference_get_path (reference);
+ gtk_tree_model_get_iter (tree_model, &iter, path);
+ gtk_tree_path_free (path);
+
+ gtk_tree_model_get (
+ tree_model, &iter,
+ COL_UINT_UNREAD_LAST_SEL, &old_unread, -1);
+
+ gtk_tree_store_set (
+ GTK_TREE_STORE (model), &iter,
+ COL_UINT_UNREAD, unread,
+ COL_UINT_UNREAD_LAST_SEL, MIN (old_unread, unread), -1);
+
+ /* Folders are displayed with a bold weight to indicate that
+ * they contain unread messages. We signal that parent rows
+ * have changed here to update them. */
+ while (gtk_tree_model_iter_parent (tree_model, &parent, &iter)) {
+ path = gtk_tree_model_get_path (tree_model, &parent);
+ gtk_tree_model_row_changed (tree_model, path, &parent);
+ gtk_tree_path_free (path);
+ iter = parent;
+ }
+}
+
+static void
+folder_unread_updated_cb (MailFolderCache *cache, CamelStore *store,
+ const gchar *full_name, int unread, gpointer user_data)
+{
+ EMFolderTreeModel *model = (EMFolderTreeModel*) user_data;
+ em_folder_tree_model_set_unread_count (model, store, full_name, unread);
+}
+
+static void
folder_tree_model_init (EMFolderTreeModel *model)
{
GHashTable *store_index;
@@ -425,6 +488,10 @@ folder_tree_model_init (EMFolderTreeModel *model)
model->priv->account_removed_id = g_signal_connect (
model->priv->accounts, "account-removed",
G_CALLBACK (account_removed_cb), model);
+
+ g_signal_connect (mail_folder_cache_get_default (),
+ "folder-unread-updated",
+ G_CALLBACK (folder_unread_updated_cb), model);
}
GType
@@ -1173,61 +1240,6 @@ em_folder_tree_model_get_folder_name (EMFolderTreeModel *model,
return name;
}
-void
-em_folder_tree_model_set_unread_count (EMFolderTreeModel *model,
- CamelStore *store,
- const gchar *full,
- gint unread)
-{
- EMFolderTreeModelStoreInfo *si;
- GtkTreeRowReference *reference;
- GtkTreeModel *tree_model;
- GtkTreePath *path;
- GtkTreeIter parent;
- GtkTreeIter iter;
- guint old_unread = 0;
-
- g_return_if_fail (EM_IS_FOLDER_TREE_MODEL (model));
- g_return_if_fail (CAMEL_IS_STORE (store));
- g_return_if_fail (full != NULL);
-
- if (unread < 0)
- return;
-
- si = em_folder_tree_model_lookup_store_info (model, store);
- if (si == NULL)
- return;
-
- reference = g_hash_table_lookup (si->full_hash, full);
- if (!gtk_tree_row_reference_valid (reference))
- return;
-
- tree_model = GTK_TREE_MODEL (model);
-
- path = gtk_tree_row_reference_get_path (reference);
- gtk_tree_model_get_iter (tree_model, &iter, path);
- gtk_tree_path_free (path);
-
- gtk_tree_model_get (
- tree_model, &iter,
- COL_UINT_UNREAD_LAST_SEL, &old_unread, -1);
-
- gtk_tree_store_set (
- GTK_TREE_STORE (model), &iter,
- COL_UINT_UNREAD, unread,
- COL_UINT_UNREAD_LAST_SEL, MIN (old_unread, unread), -1);
-
- /* Folders are displayed with a bold weight to indicate that
- * they contain unread messages. We signal that parent rows
- * have changed here to update them. */
- while (gtk_tree_model_iter_parent (tree_model, &parent, &iter)) {
- path = gtk_tree_model_get_path (tree_model, &parent);
- gtk_tree_model_row_changed (tree_model, path, &parent);
- gtk_tree_path_free (path);
- iter = parent;
- }
-}
-
EMFolderTreeModelStoreInfo *
em_folder_tree_model_lookup_store_info (EMFolderTreeModel *model,
CamelStore *store)
diff --git a/mail/em-folder-tree-model.h b/mail/em-folder-tree-model.h
index 00e2d39282..e0a73e03b8 100644
--- a/mail/em-folder-tree-model.h
+++ b/mail/em-folder-tree-model.h
@@ -137,11 +137,6 @@ void em_folder_tree_model_remove_folders
(EMFolderTreeModel *model,
EMFolderTreeModelStoreInfo *si,
GtkTreeIter *toplevel);
-void em_folder_tree_model_set_unread_count
- (EMFolderTreeModel *model,
- CamelStore *store,
- const gchar *path,
- gint unread);
gboolean em_folder_tree_model_is_type_inbox
(EMFolderTreeModel *model,
CamelStore *store,
diff --git a/mail/mail-folder-cache.c b/mail/mail-folder-cache.c
index 769fa1df10..6b1be44753 100644
--- a/mail/mail-folder-cache.c
+++ b/mail/mail-folder-cache.c
@@ -98,6 +98,7 @@ enum
FOLDER_UNAVAILABLE,
FOLDER_DELETED,
FOLDER_RENAMED,
+ FOLDER_UNREAD_UPDATED,
LAST_SIGNAL
};
@@ -198,8 +199,8 @@ real_flush_updates (gpointer o, gpointer event_data, gpointer data)
}
/* update unread counts */
- em_folder_tree_model_set_unread_count (
- default_model, up->store, up->full_name, up->unread);
+ g_signal_emit (self, signals[FOLDER_UNREAD_UPDATED], 0,
+ up->store, up->full_name, up->unread);
if (up->uri) {
EMEvent *e = em_event_peek();
@@ -1268,6 +1269,24 @@ mail_folder_cache_class_init (MailFolderCacheClass *klass)
e_marshal_VOID__POINTER_STRING_STRING,
G_TYPE_NONE, 3,
G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING);
+
+ /**
+ * MailFolderCache::folder-unread-updated
+ * @store: the #CamelStore containing the folder
+ * @name: the name of the folder
+ * @unread: the number of unread mails in the folder
+ *
+ * Emitted when a we receive an update to the unread count for a folder
+ **/
+ signals[FOLDER_UNREAD_UPDATED] =
+ g_signal_new ("folder-unread-updated",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ 0, /* struct offset */
+ NULL, NULL, /* accumulator */
+ e_marshal_VOID__POINTER_STRING_INT,
+ G_TYPE_NONE, 3,
+ G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_INT);
}
static void