[gnome-contacts] Don't unnecessarily create primary persona to set note



commit 27deed34423ef92bea3c974f172c5388ba036222
Author: Alexander Larsson <alexl redhat com>
Date:   Mon Sep 5 10:45:37 2011 +0200

    Don't unnecessarily create primary persona to set note
    
    If a contact doesn't have a primary persona but still lets you
    edit notes, we don't need to create a primary persona.
    Fixes bug #657966

 src/contacts-contact-pane.vala |   25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 deletions(-)
---
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index 60aa183..6fae601 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -1122,21 +1122,32 @@ public class Contacts.ContactPane : Grid {
     var widgets = new HashMultiMap<Persona?, TextView>();
     var main_text = add_note ();
 
-    Persona? primary_persona = selected_contact.find_primary_persona ();
-    if (primary_persona == null)
-      primary_persona = new FakePersona (selected_contact);
+    // We store the main note on the primay persona if any, otherwise
+    // on the first persona with a writable notes, falling back to
+    // a FakePersona that creates a primary persona as needed
+    Persona? notes_persona = selected_contact.find_primary_persona ();
+    if (notes_persona == null) {
+      foreach (var persona in selected_contact.individual.personas) {
+	if (Contact.persona_has_writable_property (persona, "notes")) {
+	  notes_persona = persona;
+	  break;
+	}
+      }
+      if (notes_persona == null)
+	notes_persona = new FakePersona (selected_contact);
+    }
 
-    widgets.set (primary_persona, main_text);
+    widgets.set (notes_persona, main_text);
 
-    bool primary_note_seen = false;
+    bool notes_persona_note_seen = false;
 
     foreach (var persona in selected_contact.individual.personas) {
       var notes = persona as NoteDetails;
       if (notes == null)
 	continue;
       foreach (var note in notes.notes) {
-	if (persona == primary_persona && !primary_note_seen) {
-	  primary_note_seen = true;
+	if (persona == notes_persona && !notes_persona_note_seen) {
+	  notes_persona_note_seen = true;
 	  update_note (main_text, note);
 	} else if (Contact.persona_has_writable_property (persona, "notes")) {
 	  var text = add_note ();



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