r3615 - in trunk/src/target/OM-2007.2/applications/openmoko-messages2: . src

chris at sita.openmoko.org chris at sita.openmoko.org
Fri Dec 7 19:08:03 CET 2007


Author: chris
Date: 2007-12-07 19:08:01 +0100 (Fri, 07 Dec 2007)
New Revision: 3615

Modified:
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/ChangeLog
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.c
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.h
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-notes.c
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.c
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.h
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms.h
Log:
        * src/sms-contacts.c: (contacts_added_cb), (contacts_changed_cb),
        (contacts_removed_cb), (contacts_iter_compare_func),
        (sms_contacts_page_new):
        * src/sms-contacts.h:
        * src/sms-notes.c: (global_note_added_cb),
        (global_note_modified_cb), (global_note_removed_ghrfunc),
        (global_note_removed_cb), (store_opened_cb), (free_count_data),
        (sms_notes_page_new):
        * src/sms-utils.c: (sms_contacts_note_count_update):
        * src/sms-utils.h: 
        * src/sms.h:
        Keep a count of read/unread notes per number and generate detail strings
        for contacts to display their read/unread message count


Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/ChangeLog
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/ChangeLog	2007-12-07 16:30:55 UTC (rev 3614)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/ChangeLog	2007-12-07 18:08:01 UTC (rev 3615)
@@ -1,3 +1,19 @@
+2007-12-07  Chris Lord  <chris at openedhand.com>
+
+	* src/sms-contacts.c: (contacts_added_cb), (contacts_changed_cb),
+	(contacts_removed_cb), (contacts_iter_compare_func),
+	(sms_contacts_page_new):
+	* src/sms-contacts.h:
+	* src/sms-notes.c: (global_note_added_cb),
+	(global_note_modified_cb), (global_note_removed_ghrfunc),
+	(global_note_removed_cb), (store_opened_cb), (free_count_data),
+	(sms_notes_page_new):
+	* src/sms-utils.c: (sms_contacts_note_count_update):
+	* src/sms-utils.h:
+	* src/sms.h:
+	Keep a count of read/unread notes per number and generate detail strings
+	for contacts to display their read/unread message count
+
 2007-12-06  Chris Lord  <chris at openedhand.com>
 
 	* src/sms-compose.c: (send_clicked_cb):

Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.c	2007-12-07 16:30:55 UTC (rev 3614)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.c	2007-12-07 18:08:01 UTC (rev 3615)
@@ -18,6 +18,7 @@
  */
 
 #include "sms-contacts.h"
+#include "sms-utils.h"
 #include <libmokoui2/moko-finger-scroll.h>
 #include <libmokoui2/moko-search-bar.h>
 #include <string.h>
@@ -87,6 +88,9 @@
 		g_hash_table_insert (data->contacts,
 			e_contact_get (contact, E_CONTACT_UID), iter);
 	}
+
+	if (!data->note_count_idle) data->note_count_idle =
+		g_idle_add ((GSourceFunc)sms_contacts_note_count_update, data);
 }
 
 static void
@@ -107,6 +111,9 @@
 			contacts_store (data, iter, contact);
 		}
 	}
+
+	if (!data->note_count_idle) data->note_count_idle =
+		g_idle_add ((GSourceFunc)sms_contacts_note_count_update, data);
 }
 
 static void
@@ -123,6 +130,9 @@
 			data->contacts_store, iter);
 		g_hash_table_remove (data->contacts, uids->data);
 	}
+
+	if (!data->note_count_idle) data->note_count_idle =
+		g_idle_add ((GSourceFunc)sms_contacts_note_count_update, data);
 }
 
 static void
@@ -162,9 +172,13 @@
 contacts_iter_compare_func (GtkTreeModel *model, GtkTreeIter *a,
 			    GtkTreeIter *b, SmsData *data)
 {
-	gint result;
+	gint result, prio1, prio2;
 	gchar *name1, *name2, *name1c, *name2c;
 	
+	gtk_tree_model_get (model, a, COL_PRIORITY, &prio1, -1);
+	gtk_tree_model_get (model, b, COL_PRIORITY, &prio2, -1);
+	if (prio1 != prio2) return prio1 - prio2;
+	
 	gtk_tree_model_get (model, a, COL_NAME, &name1, -1);
 	gtk_tree_model_get (model, b, COL_NAME, &name2, -1);
 	
@@ -241,7 +255,8 @@
 
 	/* Create contacts model */
 	data->contacts_store = (GtkTreeModel *)gtk_list_store_new (COL_LAST,
-		G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF);
+		G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF,
+		G_TYPE_INT);
 	gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (
 		data->contacts_store), COL_NAME,
 		(GtkTreeIterCompareFunc)contacts_iter_compare_func,
@@ -259,7 +274,7 @@
 	gtk_tree_model_filter_set_modify_func ((GtkTreeModelFilter *)
 		data->contacts_filter, COL_LAST,
 		(GType []){G_TYPE_STRING, G_TYPE_STRING,
-			G_TYPE_STRING, GDK_TYPE_PIXBUF},
+			G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_INT},
 		(GtkTreeModelFilterModifyFunc)nophoto_filter_func, data, NULL);
 	
 	/* Create groups model */

Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.h	2007-12-07 16:30:55 UTC (rev 3614)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.h	2007-12-07 18:08:01 UTC (rev 3615)
@@ -27,6 +27,7 @@
 	COL_NAME,
 	COL_DETAIL,
 	COL_ICON,
+	COL_PRIORITY,
 	COL_LAST
 };
 

Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-notes.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-notes.c	2007-12-07 16:30:55 UTC (rev 3614)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-notes.c	2007-12-07 18:08:01 UTC (rev 3615)
@@ -19,6 +19,7 @@
 
 #include "sms-notes.h"
 #include "sms-utils.h"
+#include <libjana/jana.h>
 #include <libjana-ecal/jana-ecal.h>
 #include <libmokoui2/moko-finger-scroll.h>
 #include <libmokoui2/moko-search-bar.h>
@@ -221,12 +222,171 @@
 }
 
 static void
+global_note_added_cb (JanaStoreView *store_view, GList *components,
+		      SmsData *data)
+{
+	for (; components; components = components->next) {
+		SmsNoteCountData *ncdata;
+		JanaNote *note;
+		gint i;
+		
+		if (!JANA_IS_NOTE (components->data)) continue;
+		
+		note = JANA_NOTE (components->data);
+		
+		for (i = 0; i < 2; i++) {
+			gchar *uid;
+			gchar *key = i ? jana_note_get_author (note) :
+				jana_note_get_recipient (note);
+			if (!key) continue;
+			ncdata = g_hash_table_lookup (data->note_count, key);
+			
+			if (!ncdata) {
+				ncdata = g_slice_new0 (SmsNoteCountData);
+				g_hash_table_insert (
+					data->note_count, key, ncdata);
+			}
+			
+			uid = jana_component_get_uid (
+				JANA_COMPONENT (note));
+			if (jana_utils_component_has_category (
+			     JANA_COMPONENT (note), "Read")) {
+				ncdata->read = g_list_prepend (
+					ncdata->read, uid);
+			} else {
+				ncdata->unread = g_list_prepend (
+					ncdata->unread, uid);
+			}
+		}
+	}
+	
+	if (!data->note_count_idle) data->note_count_idle =
+		g_idle_add ((GSourceFunc)sms_contacts_note_count_update, data);
+}
+
+static void
+global_note_modified_cb (JanaStoreView *store_view, GList *components,
+			 SmsData *data)
+{
+	for (; components; components = components->next) {
+		SmsNoteCountData *ncdata;
+		JanaNote *note;
+		gchar *uid;
+		gint i;
+		
+		if (!JANA_IS_NOTE (components->data)) continue;
+		
+		note = JANA_NOTE (components->data);
+		
+		uid = jana_component_get_uid (JANA_COMPONENT (note));
+		for (i = 0; i < 2; i++) {
+			GList *u, *r;
+			gchar *key = i ? jana_note_get_author (note) :
+				jana_note_get_recipient (note);
+			ncdata = g_hash_table_lookup (data->note_count, key);
+			g_free (key);
+			
+			if (!ncdata) continue;
+			
+			/* Swap from read/unread lists if necessary */
+			u = g_list_find_custom (ncdata->unread, uid,
+				(GCompareFunc)strcmp);
+			r = g_list_find_custom (ncdata->read, uid,
+				(GCompareFunc)strcmp);
+			if (jana_utils_component_has_category (
+			    JANA_COMPONENT (note), "Read")) {
+				if (u) {
+					ncdata->read = g_list_prepend (
+						ncdata->read, u->data);
+					ncdata->unread = g_list_delete_link (
+						ncdata->unread, u);
+				}
+			} else if (r) {
+				ncdata->unread = g_list_prepend (
+					ncdata->unread, r->data);
+				ncdata->read = g_list_delete_link (
+					ncdata->read, r);
+			}
+		}
+		g_free (uid);
+	}
+
+	if (!data->note_count_idle) data->note_count_idle =
+		g_idle_add ((GSourceFunc)sms_contacts_note_count_update, data);
+}
+
+static gboolean
+global_note_removed_ghrfunc (gchar *key, SmsNoteCountData *value,
+			     gchar *uid)
+{
+	GList *u, *r;
+	
+	u = g_list_find_custom (value->unread, uid, (GCompareFunc)strcmp);
+	r = g_list_find_custom (value->read, uid, (GCompareFunc)strcmp);
+	
+	if (u) {
+		g_free (u->data);
+		value->unread = g_list_delete_link (value->unread, u);
+	}
+	
+	if (r) {
+		g_free (r->data);
+		value->read = g_list_delete_link (value->read, r);
+	}
+	
+	if ((!value->read) && (!value->unread))
+		return TRUE;
+	else
+		return FALSE;
+}
+
+static void
+global_note_removed_cb (JanaStoreView *store_view, GList *uids,
+			SmsData *data)
+{
+	for (; uids; uids = uids->next) {
+		g_hash_table_foreach_remove (data->note_count,
+			(GHRFunc)global_note_removed_ghrfunc, uids->data);
+	}
+
+	if (!data->note_count_idle) data->note_count_idle =
+		g_idle_add ((GSourceFunc)sms_contacts_note_count_update, data);
+}
+
+static void
 store_opened_cb (JanaStore *store, SmsData *data)
 {
+	JanaStoreView *store_view;
+	
 	open = TRUE;
 	if (!hidden) page_shown (data);
+
+	/* Create and start global view to bind notes to contacts */
+	store_view = jana_store_get_view (store);
+	g_signal_connect (store_view, "added",
+		G_CALLBACK (global_note_added_cb), data);
+	g_signal_connect (store_view, "modified",
+		G_CALLBACK (global_note_modified_cb), data);
+	g_signal_connect (store_view, "removed",
+		G_CALLBACK (global_note_removed_cb), data);
+	jana_store_view_start (store_view);
 }
 
+static void
+free_count_data (SmsNoteCountData *data)
+{
+	while (data->read) {
+		g_free (data->read->data);
+		data->read = g_list_delete_link (data->read, data->read);
+	}
+	while (data->unread) {
+		g_free (data->unread->data);
+		data->unread = g_list_delete_link (data->unread, data->unread);
+	}
+	
+	g_slice_free (SmsNoteCountData, data);
+}
+
 GtkWidget *
 sms_notes_page_new (SmsData *data)
 {
@@ -238,6 +398,9 @@
 	data->author_icon = NULL;
 	data->recipient_number = NULL;
 	data->recipient_icon = NULL;
+	data->note_count = g_hash_table_new_full (g_str_hash, g_str_equal,
+		(GDestroyNotify)g_free, (GDestroyNotify)free_count_data);
+	data->note_count_idle = 0;
 	
 	/* Create note store */
 	data->notes = jana_ecal_store_new (JANA_COMPONENT_NOTE);

Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.c	2007-12-07 16:30:55 UTC (rev 3614)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.c	2007-12-07 18:08:01 UTC (rev 3615)
@@ -109,3 +109,56 @@
 	
 	return pixbuf;
 }
+
+gboolean
+sms_contacts_note_count_update (SmsData *data)
+{
+	GtkTreeIter iter;
+	
+	if (!gtk_tree_model_get_iter_first (data->contacts_store, &iter)) {
+		data->note_count_idle = 0;
+		return FALSE;
+	}
+	
+	do {
+		gint i;
+		EContact *contact;
+		gchar *uid, *detail;
+		gint unread, read;
+		
+		gtk_tree_model_get (data->contacts_store, &iter, COL_UID,
+			&uid, -1);
+		if (!uid) continue;
+		
+		if (!e_book_get_contact (data->ebook, uid, &contact, NULL)) {
+			g_free (uid);
+			continue;
+		}
+		g_free (uid);
+		
+		unread = 0;
+		read = 0;
+		for (i = E_CONTACT_FIRST_PHONE_ID;
+		     i <= E_CONTACT_LAST_PHONE_ID; i++) {
+			SmsNoteCountData *ncdata;
+			const gchar *number = e_contact_get_const (
+				contact, (EContactField)i);
+			if (!number) continue;
+			
+			ncdata = g_hash_table_lookup (data->note_count, number);
+			if (!ncdata) continue;
+			
+			read += g_list_length (ncdata->read);
+			unread += g_list_length (ncdata->unread);
+		}
+		
+		detail = g_strdup_printf ("%d unread\n%d read", unread, read);
+		gtk_list_store_set (GTK_LIST_STORE (data->contacts_store),
+			&iter, COL_DETAIL, detail, -1);
+		g_free (detail);
+	} while (gtk_tree_model_iter_next (data->contacts_store, &iter));
+	
+	data->note_count_idle = 0;
+	
+	return FALSE;
+}

Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.h	2007-12-07 16:30:55 UTC (rev 3614)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.h	2007-12-07 18:08:01 UTC (rev 3615)
@@ -24,5 +24,6 @@
 
 EContact *sms_get_selected_contact (SmsData *data);
 GdkPixbuf *sms_contact_load_photo (EContact *contact);
+gboolean sms_contacts_note_count_update (SmsData *data);
 
 #endif /* SMS_UTILS_H */

Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms.h	2007-12-07 16:30:55 UTC (rev 3614)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms.h	2007-12-07 18:08:01 UTC (rev 3615)
@@ -28,11 +28,18 @@
 #include <libebook/e-book.h>
 
 typedef struct {
+	GList *unread;	/* List of JanaNote uids for unread messages */
+	GList *read;	/* The same for read messages */
+} SmsNoteCountData;
+
+typedef struct {
 	JanaStore *notes;
 	JanaStoreView *notes_view;
 	GtkTreeModel *note_store;
 	GtkTreeModel *note_filter;
-
+	GHashTable *note_count;
+	guint note_count_idle;
+	
 	EBook *ebook;
 	GtkTreeModel *contacts_store;
 	GtkTreeModel *contacts_filter;





More information about the commitlog mailing list