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

chris at sita.openmoko.org chris at sita.openmoko.org
Thu Jan 17 16:24:50 CET 2008


Author: chris
Date: 2008-01-17 16:24:45 +0100 (Thu, 17 Jan 2008)
New Revision: 3868

Modified:
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/ChangeLog
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-compose.c
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-main.c
   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
Log:
        * src/sms-main.c: (new_clicked_cb):
        Don't clear the text input if the compose page is active

        * src/sms-compose.c: (page_shown):
        * src/sms-notes.c: (page_shown):
        * src/sms-utils.c: (hito_vcard_get_named_attributes),
        (hito_vcard_attribute_get_value_string),
        (sms_delete_selected_contact_messages),
        (sms_contacts_note_count_update):
        * src/sms-utils.h:
        Import two contacts-hito functions and use them to read numbers from
        EVCard instead of EContact


Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/ChangeLog
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/ChangeLog	2008-01-17 14:46:33 UTC (rev 3867)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/ChangeLog	2008-01-17 15:24:45 UTC (rev 3868)
@@ -1,3 +1,18 @@
+2008-01-17  Chris Lord  <chris at openedhand.com>
+
+	* src/sms-main.c: (new_clicked_cb):
+	Don't clear the text input if the compose page is active
+
+	* src/sms-compose.c: (page_shown):
+	* src/sms-notes.c: (page_shown):
+	* src/sms-utils.c: (hito_vcard_get_named_attributes),
+	(hito_vcard_attribute_get_value_string),
+	(sms_delete_selected_contact_messages),
+	(sms_contacts_note_count_update):
+	* src/sms-utils.h:
+	Import two contacts-hito functions and use them to read numbers from
+	EVCard instead of EContact
+
 2008-01-14  Chris Lord  <chris at openedhand.com>
 
 	* src/sms-main.c: (new_clicked_cb), (main):

Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-compose.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-compose.c	2008-01-17 14:46:33 UTC (rev 3867)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-compose.c	2008-01-17 15:24:45 UTC (rev 3868)
@@ -27,13 +27,11 @@
 page_shown (SmsData *data)
 {
 	GtkTreeModel *model;
+	GList *numbers, *n;
 	EContact *contact;
 	GdkPixbuf *photo;
 	gchar *string;
-	gint i;
 	
-	gboolean set = FALSE;
-	
 	/* Make delete(-all) buttons insensitive */
 	/* TODO: Replace these with more useful buttons? */
 	gtk_widget_set_sensitive (GTK_WIDGET (data->delete_button), FALSE);
@@ -77,28 +75,25 @@
 	g_free (string);
 	
 	/* Fill number combo */
-	for (i = E_CONTACT_FIRST_PHONE_ID; i <= E_CONTACT_LAST_PHONE_ID; i++) {
-		const gchar *number = e_contact_get_const (
-			contact, (EContactField)i);
+	numbers = hito_vcard_get_named_attributes (E_VCARD (contact), EVC_TEL);
+	for (n = numbers; n; n = n->next) {
+		gchar *number = hito_vcard_attribute_get_value_string (
+			(EVCardAttribute *)n->data);
 
 		if (!number) continue;
 		
-		if (((i == E_CONTACT_PHONE_MOBILE) ||
-		     (i == E_CONTACT_PHONE_PRIMARY)) && (!set)) {
-			gtk_entry_set_text (GTK_ENTRY (GTK_BIN (
-				data->number_combo)->child), number);
-			set = TRUE;
-		}
 		gtk_combo_box_append_text (GTK_COMBO_BOX (data->number_combo),
 			number);
+		g_free (number);
 	}
-	if (!set) {
-		gtk_entry_set_text (GTK_ENTRY (GTK_BIN (
-			data->number_combo)->child),
-			gtk_combo_box_get_active_text (
-				GTK_COMBO_BOX (data->number_combo)));
-	}
+	g_list_free (numbers);
 	
+	gtk_combo_box_set_active (GTK_COMBO_BOX (data->number_combo), 0);
+	gtk_entry_set_text (GTK_ENTRY (GTK_BIN (
+		data->number_combo)->child),
+		gtk_combo_box_get_active_text (
+			GTK_COMBO_BOX (data->number_combo)));
+	
 	g_object_unref (contact);
 }
 

Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-main.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-main.c	2008-01-17 14:46:33 UTC (rev 3867)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-main.c	2008-01-17 15:24:45 UTC (rev 3868)
@@ -49,6 +49,9 @@
 static void
 new_clicked_cb (GtkToolButton *button, SmsData *data)
 {
+	if (gtk_notebook_get_current_page (GTK_NOTEBOOK (data->notebook)) ==
+	    SMS_PAGE_COMPOSE) return;
+
 	gtk_text_buffer_set_text (gtk_text_view_get_buffer (
 		GTK_TEXT_VIEW (data->sms_textview)), "", -1);
 

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	2008-01-17 14:46:33 UTC (rev 3867)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-notes.c	2008-01-17 15:24:45 UTC (rev 3868)
@@ -174,7 +174,7 @@
 {
 	JanaStoreView *store_view;
 	GtkAdjustment *hadjust, *vadjust;
-	gint i;
+	GList *numbers, *n;
 
 	gboolean found_match = FALSE;
 	EContact *contact = NULL;
@@ -246,17 +246,21 @@
 		data->author_icon = g_object_ref (data->no_photo);
 	
 	store_view = jana_store_get_view (data->notes);
-	for (i = E_CONTACT_FIRST_PHONE_ID; i <= E_CONTACT_LAST_PHONE_ID; i++) {
-		const gchar *number = e_contact_get_const (
-			contact, (EContactField)i);
+	numbers = hito_vcard_get_named_attributes (E_VCARD (contact), EVC_TEL);
+	for (n = numbers; n; n = n->next) {
+		gchar *number = hito_vcard_attribute_get_value_string (
+			(EVCardAttribute *)n->data);
+		
 		if (!number) continue;
 		
 		jana_store_view_add_match (store_view,
 			JANA_STORE_VIEW_AUTHOR, number);
 		jana_store_view_add_match (store_view,
 			JANA_STORE_VIEW_RECIPIENT, number);
+		g_free (number);
 		found_match = TRUE;
 	}
+	g_list_free (numbers);
 	
 	if (found_match) {
 		jana_gtk_note_store_set_view (JANA_GTK_NOTE_STORE (

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	2008-01-17 14:46:33 UTC (rev 3867)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.c	2008-01-17 15:24:45 UTC (rev 3868)
@@ -25,6 +25,59 @@
 #  include <config.h>
 #endif
 
+/* Following two functions taken from contacts hito branch, written by
+ * Ross Burton, copyright OpenedHand 2007
+ */
+GList *
+hito_vcard_get_named_attributes (EVCard *contact, const char *name)
+{
+  GList *attrs = NULL, *l;
+
+  g_return_val_if_fail (E_IS_VCARD (contact), NULL);
+  g_return_val_if_fail (name != NULL, NULL);
+
+  for (l = e_vcard_get_attributes (E_VCARD (contact)); l; l = l->next)
+  {
+    EVCardAttribute *attr;
+    const char *n;
+
+    attr = (EVCardAttribute *) l->data;
+    n = e_vcard_attribute_get_name (attr);
+
+    if (strcmp (n, name) == 0)
+      attrs = g_list_prepend (attrs, attr);
+  }
+
+  return g_list_reverse (attrs);
+}
+
+/*
+ * load the attribute value, returning a newly allocated semicolon seperated
+ * string for multivalue attributes
+ */
+gchar*
+hito_vcard_attribute_get_value_string (EVCardAttribute *attr)
+{
+  gchar *attr_value = NULL;
+  GList *l;
+  l = e_vcard_attribute_get_values (attr);
+  if (l)
+  {
+    attr_value = g_strdup (l->data);
+
+    while ((l = g_list_next (l)))
+    {
+      gchar *old = attr_value;
+      if (old)
+        attr_value = g_strdup_printf ("%s; %s", old, (gchar*) l->data);
+      else
+        attr_value = g_strdup (l->data);
+      g_free (old);
+    }
+  }
+  return attr_value;
+}
+
 void
 sms_clear_combo_box_text (GtkComboBox *combo)
 {
@@ -135,20 +188,28 @@
 	gtk_widget_destroy (dialog);
 
 	if (contact) {
-		gint i, j;
+		gint i;
+		GList *n, *numbers;
 		
-		for (i = E_CONTACT_FIRST_PHONE_ID;
-		     i <= E_CONTACT_LAST_PHONE_ID; i++) {
+		numbers = hito_vcard_get_named_attributes (
+			E_VCARD (contact), EVC_TEL);
+		
+		for (n = numbers; n; n = n->next) {
 			SmsNoteCountData *ncdata;
-			const gchar *number = e_contact_get_const (
-				contact, (EContactField)i);
+
+			gchar *number = hito_vcard_attribute_get_value_string (
+				(EVCardAttribute *)n->data);
+
 			if (!number) continue;
 			
 			ncdata = g_hash_table_lookup (data->note_count, number);
-			if (!ncdata) continue;
+			if (!ncdata) {
+				g_free (number);
+				continue;
+			}
 			
-			for (j = 0; j < 2; j++) {
-				GList *uids = j ? ncdata->read : ncdata->unread;
+			for (i = 0; i < 2; i++) {
+				GList *uids = i ? ncdata->read : ncdata->unread;
 				for (; uids; uids = uids->next) {
 					/* TODO: Add
 					 * jana_store_remove_component_from_uid
@@ -165,8 +226,10 @@
 			}
 			
 			g_hash_table_remove (data->note_count, number);
+			g_free (number);
 		}
 		
+		g_list_free (numbers);
 		g_object_unref (contact);
 	} else {
 		while (data->unassigned_notes) {
@@ -281,7 +344,7 @@
 		return FALSE;
 	
 	do {
-		gint i;
+		GList *numbers, *n;
 		EContact *contact;
 		gchar *uid;
 		gboolean unknown;
@@ -306,20 +369,25 @@
 		
 		unread = 0;
 		read = 0;
-		for (i = E_CONTACT_FIRST_PHONE_ID;
-		     i <= E_CONTACT_LAST_PHONE_ID; i++) {
+		numbers = hito_vcard_get_named_attributes (
+			E_VCARD (contact), EVC_TEL);
+		for (n = numbers; n; n = n->next) {
 			SmsNoteCountData *ncdata;
-			const gchar *number = e_contact_get_const (
-				contact, (EContactField)i);
+			
+			gchar *number = hito_vcard_attribute_get_value_string (
+				(EVCardAttribute *)n->data);
+			
 			if (!number) continue;
 			
 			ncdata = g_hash_table_lookup (data->note_count, number);
+			g_free (number);
 			if (!ncdata) continue;
 			
 			read += g_list_length (ncdata->read);
 			unread += g_list_length (ncdata->unread);
 			ncdata->assigned = assignment;
 		}
+		g_list_free (numbers);
 		
 		set_message_count (data, &iter, read, unread, FALSE);
 	} while (gtk_tree_model_iter_next (data->contacts_store, &iter));

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	2008-01-17 14:46:33 UTC (rev 3867)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.h	2008-01-17 15:24:45 UTC (rev 3868)
@@ -22,6 +22,9 @@
 
 #include "sms.h"
 
+GList *hito_vcard_get_named_attributes (EVCard *contact, const char *name);
+gchar *hito_vcard_attribute_get_value_string (EVCardAttribute *attr);
+
 void sms_clear_combo_box_text (GtkComboBox *combo);
 EContact *sms_get_selected_contact (SmsData *data);
 GdkPixbuf *sms_contact_load_photo (EContact *contact);





More information about the commitlog mailing list