[gnome-contacts] Make FakePersona.make_real_and_set take a GValue instead of Object



commit 5e5a4de0bb58484a59ac649f8aeeed56e67a5537
Author: Alexander Larsson <alexl redhat com>
Date:   Fri Aug 26 12:27:14 2011 +0200

    Make FakePersona.make_real_and_set take a GValue instead of Object
    
    This way we can also use it for strings later

 src/contacts-contact-pane.vala |   38 ++++++++++++++++----------------------
 src/contacts-contact.vala      |    6 +++---
 2 files changed, 19 insertions(+), 25 deletions(-)
---
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index 1efbcf9..bdfb826 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -352,45 +352,37 @@ public class Contacts.ContactPane : EventBox {
 
   private signal void save_data ();
 
-  private void set_persona_property (Persona persona,
-				     string property_name,
-				     Object value) {
+  private async Persona? set_persona_property (Persona persona,
+					       string property_name,
+					       Value value) throws GLib.Error {
     if (persona is FakePersona) {
       var fake = persona as FakePersona;
-      fake.make_real_and_set.begin (property_name, value, (obj, result) => {
-	  try {
-	    fake.make_real_and_set.end (result);
-	  } catch (Error e) {
-	    warning ("Unable to create writeable persona: %s", e.message);
-	  }
-	});
+      return yield fake.make_real_and_set (property_name, value);
     } else {
-      persona.set (property_name, value);
+      persona.set_property (property_name, value);
+      return null;
     }
   }
 
   private void update_detail_property (string property_name,
 				       Set<AbstractFieldDetails> detail_set) {
     var editing_backup = editing_persona;
-    if (editing_persona is FakePersona) {
-      var fake = editing_persona as FakePersona;
-      fake.make_real_and_set.begin (property_name, detail_set, (obj, result) => {
+    var value = Value (detail_set.get_type ());
+    value.set_object (detail_set);
+    set_persona_property.begin (editing_persona, property_name, value, (obj, result) => {
 	  try {
-	    var p = fake.make_real_and_set.end (result);
+	    var p = set_persona_property.end (result);
 	    if (p != null &&
 		display_mode == DisplayMode.EDIT &&
 		editing_persona == editing_backup) {
-	      update_persona_buttons (fake.contact, p);
+	      update_persona_buttons (selected_contact, p);
 	      editing_persona = p;
+	      editing_persona_primary = p;
 	    }
 	  } catch (Error e) {
 	    warning ("Unable to create writeable persona: %s", e.message);
 	  }
-	});
-    } else {
-      editing_persona.set_data ("contacts-unedited", null);
-      editing_persona.set (property_name, detail_set);
-    }
+      });
   }
 
   private void update_edit_detail_type (Set<AbstractFieldDetails> detail_set,
@@ -789,7 +781,9 @@ public class Contacts.ContactPane : EventBox {
       }
 
       if (modified) {
-	set_persona_property (persona, "notes", notes);
+	var value = Value(notes.get_type ());
+	value.set_object (notes);
+	set_persona_property.begin (persona, "notes", value);
       }
     }
   }
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index f10ce99..2c00c8a 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -899,7 +899,7 @@ public class Contacts.FakePersona : Persona {
   public Contact contact;
   private class PropVal {
     public string property;
-    public Object value;
+    public Value value;
   }
   private ArrayList<PropVal> prop_vals;
   private bool now_real;
@@ -926,7 +926,7 @@ public class Contacts.FakePersona : Persona {
     }
 
   public async Persona? make_real_and_set (string property,
-					   Object value) throws GLib.Error {
+					   Value value) throws GLib.Error {
     var v = new PropVal ();
     v.property = property;
     v.value = value;
@@ -936,7 +936,7 @@ public class Contacts.FakePersona : Persona {
       Persona p = yield contact.ensure_primary_persona ();
       p.set ("full-name", contact.display_name);
       foreach (var pv in prop_vals) {
-	p.set (pv.property, pv.value);
+	p.set_property (pv.property, pv.value);
       }
       now_real = true;
       return p;



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