[folks] Generalize Edsf.PersonaStore._set_contact_attributes



commit 36c967607516279b606d6f2a88c0bb6942aa8a68
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Aug 16 14:06:33 2011 +0200

    Generalize Edsf.PersonaStore._set_contact_attributes
    
    We need to handle non-string field details values when we implement
    postal addresses.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=656659

 backends/eds/lib/edsf-persona-store.vala |   27 ++++++++++++++++++++-------
 1 files changed, 20 insertions(+), 7 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 40f8b9b..d4c1e58 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -239,7 +239,8 @@ public class Edsf.PersonaStore : Folks.PersonaStore
             {
               Set<EmailFieldDetails> email_addresses =
                 (Set<EmailFieldDetails>) v.get_object ();
-              yield this._set_contact_attributes (contact, email_addresses,
+              yield this._set_contact_attributes_string (contact,
+                  email_addresses,
                   "EMAIL", E.ContactField.EMAIL);
             }
           else if (k == Folks.PersonaStore.detail_key (PersonaDetail.AVATAR))
@@ -258,7 +259,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
             {
               Set<PhoneFieldDetails> phone_numbers =
                 (Set<PhoneFieldDetails>) v.get_object ();
-              yield this._set_contact_attributes (contact,
+              yield this._set_contact_attributes_string (contact,
                   phone_numbers, "TEL",
                   E.ContactField.TEL);
             }
@@ -881,7 +882,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
       try
         {
           E.Contact contact = ((Edsf.Persona) persona).contact;
-          yield this._set_contact_attributes (contact, emails, "EMAIL",
+          yield this._set_contact_attributes_string (contact, emails, "EMAIL",
               E.ContactField.EMAIL);
           yield this._addressbook.modify_contact (contact);
         }
@@ -898,7 +899,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
       try
         {
           E.Contact contact = ((Edsf.Persona) persona).contact;
-          yield this._set_contact_attributes (contact, phones, "TEL",
+          yield this._set_contact_attributes_string (contact, phones, "TEL",
               E.ContactField.TEL);
           yield this._addressbook.modify_contact (contact);
         }
@@ -957,8 +958,11 @@ public class Edsf.PersonaStore : Folks.PersonaStore
         }
     }
 
-  private async void _set_contact_attributes (E.Contact contact,
-      Set<AbstractFieldDetails<string>> new_attributes,
+  delegate void FieldToAttribute<T> (E.VCardAttribute attr, T value);
+
+  private async void _set_contact_attributes<T> (E.Contact contact,
+      Set<AbstractFieldDetails<T>> new_attributes,
+      FieldToAttribute<T> fill_attribute,
       string attrib_name, E.ContactField field_id)
     {
       var attributes = new GLib.List <E.VCardAttribute>();
@@ -966,7 +970,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
       foreach (var e in new_attributes)
         {
           var attr = new E.VCardAttribute (null, attrib_name);
-          attr.add_value (e.value);
+          fill_attribute (attr, e.value);
           foreach (var param_name in e.parameters.get_keys ())
             {
               var param = new E.VCardAttributeParam (param_name.up ());
@@ -982,6 +986,15 @@ public class Edsf.PersonaStore : Folks.PersonaStore
       contact.set_attributes (field_id, attributes);
     }
 
+  private async void _set_contact_attributes_string (E.Contact contact,
+      Set<AbstractFieldDetails<string>> new_attributes,
+      string attrib_name, E.ContactField field_id)
+    {
+      _set_contact_attributes<string> (contact, new_attributes,
+          (attr, value) => { attr.add_value (value); },
+          attrib_name, field_id);
+    }
+
   internal async void _set_full_name (Edsf.Persona persona,
       string full_name)
     {



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