[gnome-contacts] Do fake => real persona conversion in place



commit 0162e22503e146caee5323adb3943a2d818254a3
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Aug 25 21:42:12 2011 +0200

    Do fake => real persona conversion in place
    
    This avoids re-creating widgetry and thus messing with the ui state
    (i.e. focus or whatnot).

 src/contacts-contact-pane.vala |   23 ++++++++---------------
 src/contacts-contact.vala      |   11 +++++++++++
 2 files changed, 19 insertions(+), 15 deletions(-)
---
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index 529d70c..9aea2c1 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -356,22 +356,15 @@ public class Contacts.ContactPane : EventBox {
 				       Set<AbstractFieldDetails> detail_set) {
     var editing_backup = editing_persona;
     if (editing_persona is FakePersona) {
-      var c = selected_contact;
-      c.ensure_primary_persona.begin ( (obj, result) => {
+      var fake = editing_persona as FakePersona;
+      fake.make_real_and_set.begin (property_name, detail_set, (obj, result) => {
 	  try {
-	    var p = c.ensure_primary_persona.end (result);
-	    p.set (property_name, detail_set);
-	    /* HACK: We don't seem to get any callbacks from folks when the actual
-	     * new property value is availibile, so we add a small timeout here...
-	     * I'm very sorry...
-	     */
-	    Timeout.add (100, () => {
-		if (c == selected_contact && display_mode == DisplayMode.EDIT &&
-		    editing_persona == editing_backup) {
-		  display_edit (selected_contact, p, false);
-		}
-		return false;
-	      });
+	    var p = fake.make_real_and_set.end (result);
+	    if (display_mode == DisplayMode.EDIT &&
+		editing_persona == editing_backup) {
+	      update_persona_buttons (fake.contact, p);
+	      editing_persona = p;
+	    }
 	  } catch (Error e) {
 	    warning ("Unable to create writable persona: %s", e.message);
 	  }
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index dc2bafc..274375d 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -882,6 +882,8 @@ public class Contacts.Contact : GLib.Object  {
 }
 
 public class Contacts.FakePersona : Persona {
+  public Contact contact;
+
   public static FakePersona? maybe_create_for (Contact contact) {
     var primary_persona = contact.find_primary_persona ();
 
@@ -903,11 +905,20 @@ public class Contacts.FakePersona : Persona {
       get { return this._writeable_properties; }
     }
 
+  public async Persona make_real_and_set (string property_name,
+					  void *value) throws GLib.Error {
+    Persona p;
+    p = yield contact.ensure_primary_persona ();
+    p.set (property_name, value);
+    return p;
+  }
+
   public FakePersona (Contact contact, PersonaStore store) {
     Object (display_id: "display_id",
 	    uid: "uid",
 	    iid: "iid",
 	    store: store,
 	    is_user: false);
+    this.contact = contact;
   }
 }



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