r1069 - in trunk/src/target/OM-2007/applications/openmoko-contacts: . src

thomas at sita.openmoko.org thomas at sita.openmoko.org
Wed Feb 21 14:21:10 CET 2007


Author: thomas
Date: 2007-02-21 14:21:09 +0100 (Wed, 21 Feb 2007)
New Revision: 1069

Modified:
   trunk/src/target/OM-2007/applications/openmoko-contacts/ChangeLog
   trunk/src/target/OM-2007/applications/openmoko-contacts/src/contacts-contact-pane.c
Log:
* src/contacts-contact-pane.c:

- Add support for handling multi-valued attributes.
- Prevent removal of a field if it is the last of its type in the editor.


Modified: trunk/src/target/OM-2007/applications/openmoko-contacts/ChangeLog
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-contacts/ChangeLog	2007-02-21 03:00:42 UTC (rev 1068)
+++ trunk/src/target/OM-2007/applications/openmoko-contacts/ChangeLog	2007-02-21 13:21:09 UTC (rev 1069)
@@ -1,3 +1,10 @@
+2007-02-21  Thomas Wood  <thomas at openedhand.com>
+
+	* src/contacts-contact-pane.c:
+
+	- Add support for handling multi-valued attributes.
+	- Prevent removal of a field if it is the last of its type in the editor.
+
 2007-02-06  Thomas Wood  <thomas at openedhand.com>
 
 	* src/contacts-main.c: (start_query), (opened_book), (main): Fixed variable

Modified: trunk/src/target/OM-2007/applications/openmoko-contacts/src/contacts-contact-pane.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-contacts/src/contacts-contact-pane.c	2007-02-21 03:00:42 UTC (rev 1068)
+++ trunk/src/target/OM-2007/applications/openmoko-contacts/src/contacts-contact-pane.c	2007-02-21 13:21:09 UTC (rev 1069)
@@ -66,6 +66,7 @@
 
 static GQuark attr_quark = 0;
 static GQuark field_quark = 0;
+static GQuark entry_quark = 0;
 
 static FieldInfo fields[] = {
   { EVC_FN, "Name", NULL, TRUE, "<big><b>%s</b></big>", NULL },
@@ -185,8 +186,16 @@
   
   /* TODO: this only handles single-valued attributes at the moment */
   e_vcard_attribute_remove_values (attr);
-  e_vcard_attribute_add_value (attr, value);
 
+  int i = 0;
+  gchar* s;
+  gchar** values = g_strsplit (value, ";", 0);
+  while ((s = values[i])) {
+    e_vcard_attribute_add_value (attr, g_strstrip (s));
+    i++;
+  }
+  g_strfreev (values);
+
   pane->priv->dirty = TRUE;
 }
 
@@ -309,17 +318,45 @@
 static void
 field_button_remove_cb (GtkWidget *button,  ContactsContactPane *pane)
 {
-  GtkWidget*box;
+  GtkWidget *box, *entry;
   EVCardAttribute *attr;
+  FieldInfo *info;
+  GList *attrs;
+  gboolean remove = FALSE;
+  gchar *type, *old_type;
 
   box = button->parent->parent;
   if (!GTK_IS_HBOX (box))
     return;
 
   attr = g_object_get_qdata (G_OBJECT (box), attr_quark);
-  e_vcard_remove_attribute (E_VCARD (pane->priv->contact), attr);
+  entry = g_object_get_qdata (G_OBJECT (box), entry_quark);
+  info = g_object_get_qdata (G_OBJECT (box), field_quark);
 
-  gtk_container_remove (GTK_CONTAINER (pane), box);
+  /* check this wasn't the last attribute of it's type before removing it */
+  old_type = get_type (attr);
+  if (old_type) {
+    for (attrs = e_vcard_get_attributes (E_VCARD (pane->priv->contact));
+         (attrs = g_list_next (attrs)); ) {
+      type = get_type (attrs->data);
+      if (type && !strcmp (type, old_type)) {
+        remove = TRUE;
+        break;
+      }
+
+    }
+  }
+
+  if (remove) {
+    gtk_container_remove (GTK_CONTAINER (pane), box);
+    e_vcard_remove_attribute (E_VCARD (pane->priv->contact), attr);
+  }
+  else {
+    /* clear the attribute and entry widget */
+    e_vcard_attribute_remove_values (attr);
+    field_set_blank (GTK_ENTRY (entry), info);
+  }
+
 }
 
 static GtkWidget *
@@ -424,9 +461,23 @@
   
   /* The value field itself */
 
-  /* FIXME: fix this for multivalued attributes */
-  attr_value = e_vcard_attribute_get_value (attr);
+  /* load the attribute value, returning a semicolon seperated string for
+   * multivalue attributes
+   */
+  GList *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;
+      attr_value = g_strdup_printf ("%s; %s", old, (gchar*) l->data);
+      g_free (old);
+    }
+  }
+
+
   if (pane->priv->editable) {
     value = gtk_entry_new ();
     if (attr_value)
@@ -459,6 +510,7 @@
   /****/
   g_object_set_qdata (G_OBJECT (box), attr_quark, attr);
   g_object_set_qdata (G_OBJECT (box), field_quark, (gpointer)info);
+  g_object_set_qdata (G_OBJECT (box), entry_quark, value);
 
 
   gtk_widget_show_all (box);
@@ -588,6 +640,8 @@
   /* Initialise the quarks */
   attr_quark = g_quark_from_static_string("contact-pane-attribute");
   field_quark = g_quark_from_static_string("contact-pane-fieldinfo");
+  entry_quark = g_quark_from_static_string("contact-pane-entry");
+
 }
 
 static void





More information about the commitlog mailing list