[evolution/kill-bonobo] Bug 323037 – Folder emblem to show new mail arrival



commit aefa76d0b3a1497f3b7fed75070733b6848127e2
Author: Milan Crha <mcrha redhat com>
Date:   Sat May 30 01:07:39 2009 -0400

    Bug 323037 â?? Folder emblem to show new mail arrival
---
 mail/em-folder-tree-model.c |   51 ++++++++++++++++++++++++----------
 mail/em-folder-tree-model.h |    1 +
 mail/em-folder-tree.c       |   64 ++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 97 insertions(+), 19 deletions(-)

diff --git a/mail/em-folder-tree-model.c b/mail/em-folder-tree-model.c
index 659eaa7..b1ee7ef 100644
--- a/mail/em-folder-tree-model.c
+++ b/mail/em-folder-tree-model.c
@@ -70,19 +70,6 @@ struct _EMFolderTreeModelPrivate {
 	gpointer shell_backend;  /* weak pointer */
 };
 
-static GType col_types[] = {
-	G_TYPE_STRING,   /* display name */
-	G_TYPE_POINTER,  /* store object */
-	G_TYPE_STRING,   /* full name */
-	G_TYPE_STRING,   /* icon name */
-	G_TYPE_STRING,   /* uri */
-	G_TYPE_UINT,     /* unread count */
-	G_TYPE_UINT,     /* flags */
-	G_TYPE_BOOLEAN,  /* is a store node */
-	G_TYPE_BOOLEAN,  /* is a folder node */
-	G_TYPE_BOOLEAN,  /* has not-yet-loaded subfolders */
-};
-
 static void account_changed (EAccountList *accounts, EAccount *account, gpointer user_data);
 static void account_removed (EAccountList *accounts, EAccount *account, gpointer user_data);
 
@@ -365,6 +352,20 @@ folder_tree_model_init (EMFolderTreeModel *model)
 	GHashTable *store_hash;
 	GHashTable *uri_hash;
 
+	GType col_types[] = {
+		G_TYPE_STRING,   /* display name */
+		G_TYPE_POINTER,  /* store object */
+		G_TYPE_STRING,   /* full name */
+		G_TYPE_STRING,   /* icon name */
+		G_TYPE_STRING,   /* uri */
+		G_TYPE_UINT,     /* unread count */
+		G_TYPE_UINT,     /* flags */
+		G_TYPE_BOOLEAN,  /* is a store node */
+		G_TYPE_BOOLEAN,  /* is a folder node */
+		G_TYPE_BOOLEAN,  /* has not-yet-loaded subfolders */
+		G_TYPE_UINT      /* last known unread count */
+	};
+
 	store_hash = g_hash_table_new_full (
 		g_direct_hash, g_direct_equal,
 		(GDestroyNotify) NULL,
@@ -668,10 +669,13 @@ em_folder_tree_model_set_folder_info (EMFolderTreeModel *model, GtkTreeIter *ite
 		COL_BOOL_IS_STORE, FALSE,
 		COL_BOOL_IS_FOLDER, TRUE,
 		COL_BOOL_LOAD_SUBDIRS, load,
+		COL_UINT_UNREAD_LAST_SEL, 0,
 		-1);
 
 	if (unread != ~0)
-		gtk_tree_store_set (tree_store, iter, COL_UINT_UNREAD, unread, -1);
+		gtk_tree_store_set (
+			tree_store, iter, COL_UINT_UNREAD, unread,
+			COL_UINT_UNREAD_LAST_SEL, unread, -1);
 
 	if (load) {
 		/* create a placeholder node for our subfolders... */
@@ -687,6 +691,7 @@ em_folder_tree_model_set_folder_info (EMFolderTreeModel *model, GtkTreeIter *ite
 			COL_BOOL_IS_FOLDER, FALSE,
 			COL_STRING_URI, NULL,
 			COL_UINT_UNREAD, 0,
+			COL_UINT_UNREAD_LAST_SEL, 0,
 			-1);
 
 		path = gtk_tree_model_get_path ((GtkTreeModel *) model, iter);
@@ -994,6 +999,7 @@ em_folder_tree_model_add_store (EMFolderTreeModel *model, CamelStore *store, con
 			    COL_BOOL_IS_STORE, FALSE,
 			    COL_STRING_URI, NULL,
 			    COL_UINT_UNREAD, 0,
+			    COL_UINT_UNREAD_LAST_SEL, 0,
 			    -1);
 
 	g_free (uri);
@@ -1448,6 +1454,8 @@ em_folder_tree_model_set_unread_count (EMFolderTreeModel *model, CamelStore *sto
 	GtkTreeRowReference *row;
 	GtkTreePath *tree_path;
 	GtkTreeIter iter;
+	guint old_unread = 0;
+	gchar *uri, *sel_uri;
 
 	g_return_if_fail (EM_IS_FOLDER_TREE_MODEL (model));
 	g_return_if_fail (CAMEL_IS_STORE (store));
@@ -1476,7 +1484,20 @@ em_folder_tree_model_set_unread_count (EMFolderTreeModel *model, CamelStore *sto
 
 	gtk_tree_path_free (tree_path);
 
-	gtk_tree_store_set ((GtkTreeStore *) model, &iter, COL_UINT_UNREAD, unread, -1);
+	sel_uri = em_folder_tree_model_get_selected (model);
+	gtk_tree_model_get (
+		GTK_TREE_MODEL (model), &iter,
+		COL_UINT_UNREAD_LAST_SEL, &old_unread,
+		COL_STRING_URI, &uri, -1);
+	if (!(g_strcmp0 (sel_uri, uri) != 0 && unread > old_unread))
+		old_unread = unread;
+	gtk_tree_store_set (
+		GTK_TREE_STORE (model), &iter,
+		COL_UINT_UNREAD, unread,
+		COL_UINT_UNREAD_LAST_SEL, old_unread, -1);
+
+	g_free (uri);
+	g_free (sel_uri);
 
 	/* May be this is from where we should propagate unread count to parents etc. */
 	emft_model_unread_count_changed (GTK_TREE_MODEL (model), &iter);
diff --git a/mail/em-folder-tree-model.h b/mail/em-folder-tree-model.h
index 20bc30a..418248a 100644
--- a/mail/em-folder-tree-model.h
+++ b/mail/em-folder-tree-model.h
@@ -69,6 +69,7 @@ enum {
 	COL_BOOL_LOAD_SUBDIRS,    /* %TRUE only if the store/folder
 				   * has subfolders which have not yet
 				   * been added to the tree */
+	COL_UINT_UNREAD_LAST_SEL, /* last known unread count */
 	NUM_COLUMNS
 };
 
diff --git a/mail/em-folder-tree.c b/mail/em-folder-tree.c
index 77bcdee..a98b1c9 100644
--- a/mail/em-folder-tree.c
+++ b/mail/em-folder-tree.c
@@ -412,6 +412,49 @@ render_display_name (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
 	g_free (display);
 }
 
+static void
+render_icon (GtkTreeViewColumn *column,
+             GtkCellRenderer *renderer,
+             GtkTreeModel *model,
+             GtkTreeIter *iter)
+{
+	GIcon *icon;
+	guint unread;
+	guint old_unread;
+	gchar *icon_name;
+
+	gtk_tree_model_get (
+		model, iter,
+		COL_STRING_ICON_NAME, &icon_name,
+		COL_UINT_UNREAD_LAST_SEL, &old_unread,
+		COL_UINT_UNREAD, &unread, -1);
+
+	if (icon_name == NULL)
+		return;
+
+	icon = g_themed_icon_new (icon_name);
+
+	/* Show an emblem if there's new mail. */
+	if (unread > old_unread) {
+		GIcon *temp_icon;
+		GEmblem *emblem;
+
+		temp_icon = g_themed_icon_new ("emblem-new");
+		emblem = g_emblem_new (temp_icon);
+		g_object_unref (temp_icon);
+
+		temp_icon = g_emblemed_icon_new (icon, emblem);
+		g_object_unref (emblem);
+		g_object_unref (icon);
+
+		icon = temp_icon;
+	}
+
+	g_object_set (renderer, "gicon", icon, NULL);
+
+	g_object_unref (icon);
+}
+
 static gboolean
 emft_select_func(GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, gboolean selected, gpointer data)
 {
@@ -462,9 +505,10 @@ folder_tree_new (EMFolderTree *emft, EMFolderTreeModel *model)
 	renderer = gtk_cell_renderer_pixbuf_new ();
 	gtk_tree_view_column_pack_start (column, renderer, FALSE);
 	gtk_tree_view_column_add_attribute (
-		column, renderer, "icon-name", COL_STRING_ICON_NAME);
-	gtk_tree_view_column_add_attribute (
 		column, renderer, "visible", COL_BOOL_IS_FOLDER);
+	gtk_tree_view_column_set_cell_data_func (
+		column, renderer, (GtkTreeCellDataFunc)
+		render_icon, NULL, NULL);
 
 	renderer = gtk_cell_renderer_text_new ();
 	if (!gconf_client_get_bool (gconf, "/apps/evolution/mail/display/no_folder_dots", NULL))
@@ -2031,6 +2075,8 @@ emft_tree_selection_changed (GtkTreeSelection *selection, EMFolderTree *emft)
 	GtkTreeModel *model;
 	GtkTreeIter iter;
 	guint32 flags;
+	guint unread = 0;
+	guint old_unread = 0;
 
 	if (!emft_selection_get_selected (selection, &model, &iter)) {
 		em_folder_tree_model_set_selected (emft->priv->model, NULL);
@@ -2039,8 +2085,18 @@ emft_tree_selection_changed (GtkTreeSelection *selection, EMFolderTree *emft)
 		return;
 	}
 
-	gtk_tree_model_get (model, &iter, COL_STRING_FULL_NAME, &full_name,
-			    COL_STRING_URI, &uri, COL_UINT_FLAGS, &flags, -1);
+	gtk_tree_model_get (
+		model, &iter,
+		COL_STRING_FULL_NAME, &full_name,
+		COL_STRING_URI, &uri, COL_UINT_FLAGS, &flags,
+		COL_UINT_UNREAD, &unread, COL_UINT_UNREAD_LAST_SEL,
+		&old_unread, -1);
+
+	/* Sync unread counts to distinguish new incoming mail. */
+	if (unread != old_unread)
+		gtk_tree_store_set (
+			GTK_TREE_STORE (model), &iter,
+			COL_UINT_UNREAD_LAST_SEL, unread, -1);
 
 	g_signal_emit (emft, signals[FOLDER_SELECTED], 0, full_name, uri, flags);
 	g_free(uri);



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