[gnome-contacts] Support postal addresses



commit 905d6c90451958dfd93e96585ac4f7041e1136a4
Author: Alexander Larsson <alexl redhat com>
Date:   Mon May 30 15:08:23 2011 +0200

    Support postal addresses

 src/contacts-app.vala     |   39 +++++++++++++++++++++++++++++++++++++++
 src/contacts-contact.vala |   40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+), 0 deletions(-)
---
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 6fed28c..cd7f04a 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -117,6 +117,7 @@ public class Contacts.App : Window {
   private struct DetailsRow {
     Clickable? clickable;
     Grid grid;
+    Label label;
   }
 
   private void add_label_spacer () {
@@ -173,11 +174,21 @@ public class Contacts.App : Window {
   private void add_string_label (string label, string val, string? icon_name, out DetailsRow row) {
     add_label (label, false, icon_name, out row);
     var v = new Label (val);
+    row.label = v;
     v.set_valign (Align.CENTER);
     v.set_halign (Align.START);
     row.grid.add (v);
   }
 
+  private void add_extra_row (string val, ref DetailsRow row) {
+    var more_label = new Label (val);
+    more_label.set_valign (Align.CENTER);
+    more_label.set_halign (Align.START);
+    row.grid.attach_next_to (more_label, row.label, PositionType.BOTTOM, 1, 1);
+    more_label.show ();
+    row.label = more_label;
+  }
+
   private bool add_string_property_label (string label, Contact contact, string pname, string? icon_name, out DetailsRow row) {
     Value prop_value;
     prop_value = Value (typeof (string));
@@ -331,6 +342,34 @@ public class Contacts.App : Window {
       }
     }
 
+    var postals = contact.individual.postal_addresses;
+    if (!postals.is_empty) {
+      add_label_spacer ();
+      add_header (_("Addresses"));
+      foreach (var addr in postals) {
+	var type = "";
+	var types = addr.types;
+	if (types != null) {
+	  var i = types.iterator();
+	  if (i.next())
+	    type = i.get();
+	}
+	string[] strs = Contact.format_address (addr);
+	if (strs.length > 0) {
+	  add_string_label (type, strs[0], null, out row);
+	  foreach (var s in strs[1:strs.length])
+	    add_extra_row (s, ref row);
+
+	  row.clickable.clicked.connect ( () => {
+	      try {
+		// How to call?
+	      } catch {
+	      }
+	    });
+	}
+      }
+    }
+
     add_label_spacer ();
     add_string_property_label (_("Alias"), contact, "alias", null, out row);
     add_label_spacer ();
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index 582000c..ecb8fd8 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -111,6 +111,46 @@ public class Contacts.Contact : GLib.Object  {
     return iconname;
   }
 
+
+  public static string[] format_address (PostalAddress addr) {
+    string[] lines = {};
+    string str;
+
+    str = addr.street;
+    if (str != null && str.length > 0)
+      lines += str;
+
+    str = addr.extension;
+    if (str != null && str.length > 0)
+      lines += str;
+
+    str = addr.locality;
+    if (str != null && str.length > 0)
+      lines += str;
+
+    str = addr.region;
+    if (str != null && str.length > 0)
+      lines += str;
+
+    str = addr.postal_code;
+    if (str != null && str.length > 0)
+      lines += str;
+
+    str = addr.po_box;
+    if (str != null && str.length > 0)
+      lines += str;
+
+    str = addr.country;
+    if (str != null && str.length > 0)
+      lines += str;
+
+    str = addr.address_format;
+    if (str != null && str.length > 0)
+      lines += str;
+
+    return lines;
+  }
+
   public Persona? find_im_persona (string protocol, string im_address) {
     foreach (var p in individual.personas) {
       var iid = protocol + ":" + im_address;



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