[gnome-contacts] Bug 657991 — Use asynchronous property setters



commit 461395e64fd49846384bb87f3befb553162a5c94
Author: Philip Withnall <philip tecnocode co uk>
Date:   Thu Sep 1 19:31:50 2011 +0100

    Bug 657991 â Use asynchronous property setters
    
    Port the contact pane to use the new asynchronous property setters in folks.
    This isn't as tidy as it should be: ideally each editing widget constructor
    would take an async delegate which it calls to set the appropriate property
    values in folks. However, async. delegates aren't supported yet by Vala
    (see: bgo#604827). Therefore we have to make do with a big switch statement
    on the property names. :-(
    
    Closes: bgo#657991

 src/contacts-contact-pane.vala |   16 +++++----
 src/contacts-contact.vala      |   70 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 78 insertions(+), 8 deletions(-)
---
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index a7c97a3..6407f5c 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -330,14 +330,14 @@ public class Contacts.ContactPane : Grid {
 
   private async Persona? set_persona_property (Persona persona,
 					       string property_name,
-					       Value value) throws GLib.Error {
+					       Value value) throws GLib.Error, PropertyError {
     selected_contact.is_unedited = false;
     if (persona is FakePersona) {
       var fake = persona as FakePersona;
       return yield fake.make_real_and_set (property_name, value);
     } else {
       persona.set_data ("contacts-unedited", true);
-      persona.set_property (property_name, value);
+      yield Contact.set_persona_property (persona, property_name, value);
       return null;
     }
   }
@@ -348,13 +348,13 @@ public class Contacts.ContactPane : Grid {
    */
   private async Persona? set_individual_property (Contact contact,
 						  string property_name,
-						  Value value) throws GLib.Error {
+						  Value value) throws GLib.Error, PropertyError {
     selected_contact.is_unedited = false;
     bool did_set = false;
     foreach (var p in contact.individual.personas) {
       if (property_name in p.writeable_properties) {
 	did_set = true;
-	p.set_property (property_name, value);
+        yield Contact.set_persona_property (p, property_name, value);
       }
     }
 
@@ -378,8 +378,10 @@ public class Contacts.ContactPane : Grid {
 	      editing_persona = p;
 	      editing_persona_primary = p;
 	    }
-	  } catch (Error e) {
-	    warning ("Unable to create writeable persona: %s", e.message);
+          } catch (PropertyError e1) {
+            warning ("Unable to edit property '%s': %s", property_name, e1.message);
+          } catch (Error e2) {
+            warning ("Unable to create writeable persona: %s", e2.message);
 	  }
       });
   }
@@ -645,7 +647,7 @@ public class Contacts.ContactPane : Grid {
     string[] nice = {_("Street"), _("Extension"), _("City"), _("State/Province"), _("Zip/Postal Code"), _("PO box"), _("Country")};
 
     detail_set.add (detail);
-    add_detail_combo (layout, TypeSet.general, detail_set, detail, "postal_addresses");
+    add_detail_combo (layout, TypeSet.general, detail_set, detail, "postal-addresses");
 
     Widget main = null;
     layout.begin_detail_box ();
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index ada5554..5269b2e 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -977,6 +977,74 @@ public class Contacts.Contact : GLib.Object  {
 
     return null;
   }
+
+  internal static async void set_persona_property (Persona persona,
+                                                   string property_name, Value new_value) throws PropertyError {
+    /* FIXME: It should be possible to move these all to being delegates which are
+     * passed to the functions which currently call this one; but only once bgo#604827 is fixed. */
+    switch (property_name) {
+      case "alias":
+        yield (persona as AliasDetails).change_alias ((string) new_value);
+        return;
+      case "avatar":
+        yield (persona as AvatarDetails).change_avatar ((LoadableIcon?) new_value);
+        return;
+      case "birthday":
+        yield (persona as BirthdayDetails).change_birthday ((DateTime?) new_value);
+        return;
+      case "calendar-event-id":
+        yield (persona as BirthdayDetails).change_calendar_event_id ((string?) new_value);
+        return;
+      case "email-addresses":
+        yield (persona as EmailDetails).change_email_addresses ((Set<EmailFieldDetails>) new_value);
+        return;
+      case "is-favourite":
+        yield (persona as FavouriteDetails).change_is_favourite ((bool) new_value);
+        return;
+      case "gender":
+        yield (persona as GenderDetails).change_gender ((Gender) new_value);
+        return;
+      case "groups":
+        yield (persona as GroupDetails).change_groups ((Set<string>) new_value);
+        return;
+      case "im-addresses":
+        yield (persona as ImDetails).change_im_addresses ((MultiMap<string, ImFieldDetails>) new_value);
+        return;
+      case "local-ids":
+        yield (persona as LocalIdDetails).change_local_ids ((Set<string>) new_value);
+        return;
+      case "structured-name":
+        yield (persona as NameDetails).change_structured_name ((StructuredName?) new_value);
+        return;
+      case "full-name":
+        yield (persona as NameDetails).change_full_name ((string) new_value);
+        return;
+      case "nickname":
+        yield (persona as NameDetails).change_nickname ((string) new_value);
+        return;
+      case "notes":
+        yield (persona as NoteDetails).change_notes ((Set<NoteFieldDetails>) new_value);
+        return;
+      case "phone-numbers":
+        yield (persona as PhoneDetails).change_phone_numbers ((Set<PhoneFieldDetails>) new_value);
+        return;
+      case "postal-addresses":
+        yield (persona as PostalAddressDetails).change_postal_addresses ((Set<PostalAddressFieldDetails>) new_value);
+        return;
+      case "roles":
+        yield (persona as RoleDetails).change_roles ((Set<RoleFieldDetails>) new_value);
+        return;
+      case "urls":
+        yield (persona as UrlDetails).change_urls ((Set<UrlFieldDetails>) new_value);
+        return;
+      case "web-service-addresses":
+        yield (persona as WebServiceDetails).change_web_service_addresses ((MultiMap<string, WebServiceFieldDetails>) new_value);
+        return;
+      default:
+        critical ("Unknown property '%s' in Contact.set_persona_property().", property_name);
+        return;
+    }
+  }
 }
 
 public class Contacts.FakePersona : Persona {
@@ -1025,7 +1093,7 @@ public class Contacts.FakePersona : Persona {
       if (!has_full_name)
 	p.set ("full-name", contact.display_name);
       foreach (var pv in prop_vals) {
-	p.set_property (pv.property, pv.value);
+        yield Contact.set_persona_property (p, pv.property, pv.value);
       }
       now_real = true;
       return p;



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