[gnome-contacts] Clean up initial letter handling



commit b35388544d2c46f8b44b10315deafbebb7dbac50
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Aug 16 11:03:08 2011 +0200

    Clean up initial letter handling
    
    We put the code in a shared place and handle empty names better

 src/contacts-contact.vala   |    9 +++++++++
 src/contacts-list-pane.vala |    5 +++--
 src/contacts-store.vala     |    4 ++--
 3 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index ecfd170..e712232 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -128,6 +128,15 @@ public class Contacts.Contact : GLib.Object  {
     }
   }
 
+  public unichar initial_letter {
+    get {
+      string name = display_name;
+      if (name.length == 0)
+	return 0;
+      return name.get_char ().totitle ();
+    }
+  }
+
   private string filter_data;
 
   public signal void changed ();
diff --git a/src/contacts-list-pane.vala b/src/contacts-list-pane.vala
index 571759b..f92e712 100644
--- a/src/contacts-list-pane.vala
+++ b/src/contacts-list-pane.vala
@@ -318,8 +318,9 @@ public class Contacts.ListPane : Frame {
 	model.get (iter, 0, out contact);
 
 	string letter = "";
-	if (contacts_store.is_first (iter))
-	  letter = contact.display_name.get_char ().totitle ().to_string ();
+	if (contacts_store.is_first (iter)) {
+	  letter = contact.initial_letter.to_string ();
+	}
 	cell.set ("text", letter);
       });
 
diff --git a/src/contacts-store.vala b/src/contacts-store.vala
index 9891a53..ead5e55 100644
--- a/src/contacts-store.vala
+++ b/src/contacts-store.vala
@@ -130,8 +130,8 @@ public class Contacts.Store  {
     bool old_is_first = data.is_first;
 
     if (previous != null) {
-      unichar previous_initial = previous.contact.display_name.get_char ().totitle ();
-      unichar initial = data.contact.display_name.get_char ().totitle ();
+      unichar previous_initial = previous.contact.initial_letter;
+      unichar initial = data.contact.initial_letter;
       data.is_first = previous_initial != initial;
     } else {
       data.is_first = true;



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