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

chris at sita.openmoko.org chris at sita.openmoko.org
Wed Nov 21 19:31:56 CET 2007


Author: chris
Date: 2007-11-21 19:31:53 +0100 (Wed, 21 Nov 2007)
New Revision: 3471

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.h
Log:
        * src/sms-contacts.c: (sms_contacts_load_photo),
        (clear_numbers_cb), (clear_numbers), (contacts_store),
        (contacts_changed_cb), (contacts_removed_cb),
        (sms_contacts_page_new):
        Maintain a number->contact uid hash table

        * src/sms-contacts.h:
        Make contact photo-loading function public

        * src/sms-notes.c: (get_selected_contact), (note_changed_cb),
        (page_shown), (page_hidden), (send_clicked_cb),
        (sms_notes_data_func), (sms_notes_page_new):
        Don't use categories to determine outgoing status, retrieve avatars for
        conversation participants

        * src/sms.h:
        Extra variables for new features


Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/ChangeLog
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/ChangeLog	2007-11-21 17:07:03 UTC (rev 3470)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/ChangeLog	2007-11-21 18:31:53 UTC (rev 3471)
@@ -1,5 +1,25 @@
 2007-11-21  Chris Lord  <chris at openedhand.com>
 
+	* src/sms-contacts.c: (sms_contacts_load_photo),
+	(clear_numbers_cb), (clear_numbers), (contacts_store),
+	(contacts_changed_cb), (contacts_removed_cb),
+	(sms_contacts_page_new):
+	Maintain a number->contact uid hash table
+
+	* src/sms-contacts.h:
+	Make contact photo-loading function public
+
+	* src/sms-notes.c: (get_selected_contact), (note_changed_cb),
+	(page_shown), (page_hidden), (send_clicked_cb),
+	(sms_notes_data_func), (sms_notes_page_new):
+	Don't use categories to determine outgoing status, retrieve avatars for
+	conversation participants
+
+	* src/sms.h:
+	Extra variables for new features
+
+2007-11-21  Chris Lord  <chris at openedhand.com>
+
 	* src/sms-notes.c: (sms_notes_page_new):
 	Check if no-photo icon is NULL before reffing it
 

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-11-21 17:07:03 UTC (rev 3470)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.c	2007-11-21 18:31:53 UTC (rev 3471)
@@ -40,7 +40,7 @@
 }
 
 GdkPixbuf *
-contacts_load_photo (EContact *contact)
+sms_contacts_load_photo (EContact *contact)
 {
 	EContactPhoto *photo;
 	GdkPixbuf *pixbuf = NULL;
@@ -85,15 +85,50 @@
 	return pixbuf;
 }
 
+static const gchar *clear_numbers_uid;
+
 static void
+clear_numbers_cb (gchar *number, gchar *uid, GList **list)
+{
+	if (strcmp (uid, clear_numbers_uid) == 0)
+		*list = g_list_prepend (*list, number);
+}
+
+static void
+clear_numbers (SmsData *data, const gchar *uid)
+{
+	GList *n, *numbers = NULL;
+
+	clear_numbers_uid = uid;
+	g_hash_table_foreach (data->numbers,
+		(GHFunc)clear_numbers_cb, &numbers);
+	
+	for (n = numbers; n; n = n->next)
+		g_hash_table_remove (data->numbers, n->data);
+	g_list_free (numbers);
+}
+
+static void
 contacts_store (SmsData *data, GtkTreeIter *iter, EContact *contact)
 {
-	GdkPixbuf *photo = contacts_load_photo (contact);
+	gint i;
+	
+	GdkPixbuf *photo = sms_contacts_load_photo (contact);
+
 	gtk_list_store_set ((GtkListStore *)data->contacts_store, iter,
 		COL_UID, e_contact_get_const (contact, E_CONTACT_UID),
 		COL_NAME, e_contact_get_const (contact, E_CONTACT_FULL_NAME),
 		COL_ICON, photo, -1);
 	if (photo) g_object_unref (photo);
+	
+	for (i = E_CONTACT_FIRST_PHONE_ID; i <= E_CONTACT_LAST_PHONE_ID; i++) {
+		gchar *number = e_contact_get (contact, (EContactField)i);
+
+		if (!number) continue;
+		
+		g_hash_table_insert (data->numbers, number,
+			e_contact_get (contact, E_CONTACT_UID));
+	}
 }
 
 static void
@@ -127,7 +162,10 @@
 		
 		uid = e_contact_get_const (contact, E_CONTACT_UID);
 		iter = g_hash_table_lookup (data->contacts, uid);
-		if (iter) contacts_store (data, iter, contact);
+		if (iter) {
+			clear_numbers (data, uid);
+			contacts_store (data, iter, contact);
+		}
 	}
 }
 
@@ -140,6 +178,7 @@
 
 		if (!iter) continue;
 		
+		clear_numbers (data, (const gchar *)uids->data);
 		gtk_list_store_remove ((GtkListStore *)
 			data->contacts_store, iter);
 		g_hash_table_remove (data->contacts, uids->data);
@@ -270,6 +309,8 @@
 		data->contacts_store), COL_NAME, GTK_SORT_ASCENDING);
 	data->contacts = g_hash_table_new_full (g_str_hash, g_str_equal,
 		(GDestroyNotify)g_free, (GDestroyNotify)free_iter_slice);
+	data->numbers = g_hash_table_new_full (g_str_hash, g_str_equal,
+		(GDestroyNotify)g_free, (GDestroyNotify)g_free);
 	
 	/* Create filter */
 	data->contacts_filter = gtk_tree_model_filter_new (

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-11-21 17:07:03 UTC (rev 3470)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.h	2007-11-21 18:31:53 UTC (rev 3471)
@@ -31,6 +31,7 @@
 };
 
 GtkWidget *sms_contacts_page_new (SmsData *data);
+GdkPixbuf *sms_contacts_load_photo (EContact *contact);
 
 #endif
 

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-11-21 17:07:03 UTC (rev 3470)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-notes.c	2007-11-21 18:31:53 UTC (rev 3471)
@@ -36,7 +36,6 @@
 	GtkTreeModel *model;
 	EContact *contact;
 	GtkTreeIter iter;
-	gchar *uid;
 	
 	GError *error = NULL;
 	
@@ -45,21 +44,67 @@
 	
 	if (!gtk_tree_selection_get_selected (selection, &model, &iter))
 		return NULL;
-	gtk_tree_model_get (model, &iter, COL_UID, &uid,
+	gtk_tree_model_get (model, &iter, COL_UID, &data->author_uid,
 		COL_ICON, &data->author_icon, -1);
 	
-	if (!e_book_get_contact (data->ebook, uid, &contact, &error)) {
+	if (!e_book_get_contact (data->ebook,
+	     data->author_uid, &contact, &error)) {
 		g_warning ("Error retrieving contact: %s", error->message);
 		g_error_free (error);
 		contact = NULL;
 	}
 	
-	g_free (uid);
-	
 	return contact;
 }
 
 static void
+note_changed_cb (JanaStoreView *store_view, GList *components, SmsData *data)
+{
+	if (data->recipient_number) goto note_changed_cb_end;
+	
+	/* Set recipient icon */
+	for (; components; components = components->next) {
+		EContact *contact;
+		const gchar *uid;
+		JanaNote *note;
+		
+		GError *error = NULL;
+
+		note = JANA_NOTE (components->data);
+		data->recipient_number = jana_note_get_recipient (note);
+		
+		if (!data->recipient_number) continue;
+		
+		uid = g_hash_table_lookup (data->numbers,
+			data->recipient_number);
+		if ((!uid) || (!data->author_uid) ||
+		    strcmp (uid, data->author_uid) == 0) {
+			g_free (data->recipient_number);
+			data->recipient_number = NULL;
+			continue;
+		}
+
+		if (!e_book_get_contact (data->ebook, uid, &contact, &error)) {
+			/* TODO: Unknown contact, probably */
+		} else {
+			data->recipient_icon =
+				sms_contacts_load_photo (contact);
+			if ((!data->recipient_icon) && (data->no_photo))
+				data->recipient_icon =
+					g_object_ref (data->no_photo);
+			g_object_unref (contact);
+			break;
+		}
+	}
+
+note_changed_cb_end:
+	/* Remove handlers */
+	if (data->recipient_number)
+		g_signal_handlers_disconnect_by_func (
+			store_view, note_changed_cb, data);
+}
+
+static void
 page_shown (SmsData *data)
 {
 	JanaStoreView *store_view;
@@ -88,6 +133,10 @@
 	if (found_match) {
 		jana_gtk_note_store_set_view (JANA_GTK_NOTE_STORE (
 			data->note_store), store_view);
+		g_signal_connect (store_view, "added",
+			G_CALLBACK (note_changed_cb), data);
+		g_signal_connect (store_view, "modified",
+			G_CALLBACK (note_changed_cb), data);
 		jana_store_view_start (store_view);
 	}
 	g_object_unref (store_view);
@@ -102,6 +151,18 @@
 		data->note_store), NULL);
 	gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
 		data->new_button), FALSE);
+	if (data->author_uid) {
+		g_free (data->author_uid);
+		data->author_uid = NULL;
+	}
+	if (data->author_icon) {
+		g_object_unref (data->author_icon);
+		data->author_icon = NULL;
+	}
+	if (data->recipient_number) {
+		g_free (data->recipient_number);
+		data->recipient_number = NULL;
+	}
 	if (data->recipient_icon) {
 		g_object_unref (data->recipient_icon);
 		data->recipient_icon = NULL;
@@ -198,7 +259,7 @@
 		if (!dbus_g_proxy_call (data->sms_proxy, "Send", &error,
 			G_TYPE_STRING, number, G_TYPE_STRING, message,
 			G_TYPE_INVALID, G_TYPE_STRING, NULL, G_TYPE_INVALID)) {
-			g_debug ("Error sending message: %s", error->message);
+			g_warning ("Error sending message: %s", error->message);
 			g_error_free (error);
 		}
 		
@@ -214,9 +275,9 @@
 				 GtkTreeIter *iter,
 				 SmsData *data)
 {
-	gchar *author, *recipient, *body, **categories;
+	gchar *author, *recipient, *body;
 	JanaTime *created, *modified;
-	gboolean outgoing = FALSE;
+	gboolean outgoing;
 	gint i;
 	
 	gtk_tree_model_get (model, iter,
@@ -225,19 +286,13 @@
 		JANA_GTK_NOTE_STORE_COL_BODY, &body,
 		JANA_GTK_NOTE_STORE_COL_CREATED, &created,
 		JANA_GTK_NOTE_STORE_COL_MODIFIED, &modified,
-		JANA_GTK_NOTE_STORE_COL_CATEGORIES, &categories, -1);
+		-1);
 
-	if (categories) for (i = 0; categories[i]; i++) {
-		/* Note that this category is not meant for display and 
-		 * shouldn't be translated... (see phone-kit)
-		 */
-		if ((strcmp (categories[i], "Sent") == 0) ||
-		    (strcmp (categories[i], "Sending") == 0) ||
-		    (strcmp (categories[i], "Rejected") == 0)) {
-			outgoing = TRUE;
-			break;
-		}
-	}
+	if (recipient && data->recipient_number &&
+	    (strcmp (recipient, data->recipient_number) == 0))
+		outgoing = TRUE;
+	else
+		outgoing = FALSE;
 	
 	g_object_set (cell,
 		"author", author,
@@ -254,7 +309,6 @@
 	g_free (author);
 	g_free (recipient);
 	g_free (body);
-	g_strfreev (categories);
 	if (created) g_object_unref (created);
 	if (modified) g_object_unref (modified);
 }
@@ -274,9 +328,10 @@
 	GtkCellRenderer *renderer;
 	GHashTable *colours_hash;
 	
-	/* FIXME: Set recipient pixbuf */
-	data->recipient_icon = data->no_photo ?
-		g_object_ref (data->no_photo) : NULL;
+	data->author_uid = NULL;
+	data->author_icon = NULL;
+	data->recipient_number = NULL;
+	data->recipient_icon = NULL;
 	
 	/* Create note store */
 	data->notes = jana_ecal_store_new (JANA_COMPONENT_NOTE);

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-11-21 17:07:03 UTC (rev 3470)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms.h	2007-11-21 18:31:53 UTC (rev 3471)
@@ -37,6 +37,7 @@
 	GtkTreeModel *contacts_store;
 	GtkTreeModel *contacts_filter;
 	GHashTable *contacts;
+	GHashTable *numbers;
 	
 	GtkWidget *window;
 	GtkWidget *notebook;
@@ -49,6 +50,8 @@
 	GtkWidget *sms_textview;
 	GdkPixbuf *author_icon;
 	GdkPixbuf *recipient_icon;
+	gchar *recipient_number;
+	gchar *author_uid;
 
 	GtkWidget *contacts_treeview;
 	GtkWidget *contacts_combo;





More information about the commitlog mailing list