[gnome-contacts] Port to gee-0.8.



commit 6d2d93ddef2a14f50386f9fe0d2f2b502bb75c13
Author: Erick PÃrez Castellanos <erick red gmail com>
Date:   Wed Feb 13 22:57:23 2013 -0500

    Port to gee-0.8.
    
    Based on: https://bugzilla.gnome.org/show_bug.cgi?id=673918
    Fixes: Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=680274

 configure.ac                            |    2 +-
 src/contacts-contact.vala               |  123 ++++++++++++++++---------------
 src/contacts-linking.vala               |   33 ++++----
 src/contacts-shell-search-provider.vala |    2 +-
 4 files changed, 82 insertions(+), 78 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c38ada9..da9a0c4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,7 +45,7 @@ pkg_modules="gtk+-3.0 >= 3.4.0
             libebook-1.2 >= 3.5.3
             libedataserver-1.2 >= 3.5.3
             goa-1.0
-            gee-1.0
+            gee-0.8
             "
 PKG_CHECK_MODULES(CONTACTS, [$pkg_modules])
 
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index 9564d5b..3a67386 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -664,41 +664,6 @@ public class Contacts.Contact : GLib.Object  {
     return 0;
   }
 
-  public static int compare_persona_by_store (void *a, void *b) {
-    Persona persona_a = (Persona *)a;
-    Persona persona_b = (Persona *)b;
-    var store_a = persona_a.store;
-    var store_b = persona_b.store;
-
-    if (store_a == store_b) {
-      if (persona_is_google (persona_a)) {
-       /* Non-other google personas rank before others */
-       if (persona_is_google_other (persona_a) && !persona_is_google_other (persona_b))
-         return 1;
-       if (!persona_is_google_other (persona_a) && persona_is_google_other (persona_b))
-         return -1;
-      }
-
-      return 0;
-    }
-
-    if (store_a.is_primary_store && store_b.is_primary_store)
-      return 0;
-    if (store_a.is_primary_store)
-      return -1;
-    if (store_b.is_primary_store)
-      return 1;
-
-    if (store_a.type_id == "eds" && store_b.type_id == "eds")
-      return strcmp (store_a.id, store_b.id);
-    if (store_a.type_id == "eds")
-      return -1;
-    if (store_b.type_id == "eds")
-      return 1;
-
-    return strcmp (store_a.id, store_b.id);
-  }
-
   public static ArrayList<T> sort_fields<T> (Collection<T> fields) {
     var res = new ArrayList<T>();
     res.add_all (fields);
@@ -1134,6 +1099,42 @@ public class Contacts.Contact : GLib.Object  {
   }
 
   public Gee.List<Persona> get_personas_for_display () {
+    CompareDataFunc<Persona> compare_persona_by_store = (a, b) =>
+    {
+      Persona persona_a = (Persona *)a;
+      Persona persona_b = (Persona *)b;
+      var store_a = persona_a.store;
+      var store_b = persona_b.store;
+
+      if (store_a == store_b) {
+       if (persona_is_google (persona_a)) {
+         /* Non-other google personas rank before others */
+         if (persona_is_google_other (persona_a) && !persona_is_google_other (persona_b))
+           return 1;
+         if (!persona_is_google_other (persona_a) && persona_is_google_other (persona_b))
+           return -1;
+       }
+
+       return 0;
+      }
+
+      if (store_a.is_primary_store && store_b.is_primary_store)
+       return 0;
+      if (store_a.is_primary_store)
+       return -1;
+      if (store_b.is_primary_store)
+       return 1;
+
+      if (store_a.type_id == "eds" && store_b.type_id == "eds")
+       return strcmp (store_a.id, store_b.id);
+      if (store_a.type_id == "eds")
+       return -1;
+      if (store_b.type_id == "eds")
+       return 1;
+
+      return strcmp (store_a.id, store_b.id);
+    };
+
     var persona_list = new ArrayList<Persona>();
     int i = 0;
     persona_list.add_all (individual.personas);
@@ -1143,7 +1144,7 @@ public class Contacts.Contact : GLib.Object  {
       else
        i++;
     }
-    persona_list.sort (Contact.compare_persona_by_store);
+    persona_list.sort (compare_persona_by_store);
 
     return persona_list;
   }
@@ -1273,37 +1274,39 @@ public class Contacts.Contact : GLib.Object  {
     return store.display_name;
   }
 
-  public static int compare_properties (void *a, void *b) {
-    string [] sorted_array = { "email-addresses" , "phone-numbers" , "im-addresses", "urls", "nickname", 
"birthday", "notes", "postal-addresses" };
-    var sorted_map = new HashMap<string, int> ();
-    int i = 0;
-    foreach (var p in sorted_array) {
-      sorted_map.set (p, ++i);
-    }
+  public static string[] sorted_properties = { "email-addresses" , "phone-numbers" , "im-addresses", "urls", 
"nickname", "birthday", "notes", "postal-addresses" };
+
+  public static string []sort_persona_properties (string [] props) {
+    CompareDataFunc<string> compare_properties = (a, b) =>
+    {
+      var sorted_map = new HashMap<string, int> ();
+      int i = 0;
+      foreach (var p in sorted_properties) {
+       sorted_map.set (p, ++i);
+      }
 
-    string a_str = (string) a;
-    string b_str = (string) b;
+      string a_str = (string) a;
+      string b_str = (string) b;
 
-    if (sorted_map.has_key (a_str) && sorted_map.has_key (b_str)) {
-      if (sorted_map[a_str] < sorted_map[b_str])
+      if (sorted_map.has_key (a_str) && sorted_map.has_key (b_str)) {
+       if (sorted_map[a_str] < sorted_map[b_str])
+         return -1;
+       if (sorted_map[a_str] > sorted_map[b_str])
+         return 1;
+       return 0;
+      } else if (sorted_map.has_key (a_str))
        return -1;
-      if (sorted_map[a_str] > sorted_map[b_str])
+      else if (sorted_map.has_key (b_str))
        return 1;
-      return 0;
-    } else if (sorted_map.has_key (a_str))
-      return -1;
-    else if (sorted_map.has_key (b_str))
-      return 1;
-    else {
-      if (a_str < b_str)
-       return -1;
+      else {
+       if (a_str < b_str)
+         return -1;
       if (a_str > b_str)
        return 1;
       return 0;
-    }
-  }
+      }
+    };
 
-  public static string [] sort_persona_properties (string [] props) {
     var sorted_props = new ArrayList<string> ();
     foreach (var s in props) {
       sorted_props.add (s);
@@ -1342,7 +1345,7 @@ public class Contacts.Contact : GLib.Object  {
     if (t_persona != null && t_persona.contact != null) {
       unowned TelepathyGLib.Capabilities caps =
       t_persona.contact.get_capabilities ();
-      if (caps.supports_audio_call (TelepathyGLib.HandleType.CONTACT)) 
+      if (caps.supports_audio_call (TelepathyGLib.HandleType.CONTACT))
              return (t_persona.store as Tpf.PersonaStore).account;
     }
 
diff --git a/src/contacts-linking.vala b/src/contacts-linking.vala
index 1f2ce09..8bb310b 100644
--- a/src/contacts-linking.vala
+++ b/src/contacts-linking.vala
@@ -94,8 +94,8 @@ namespace Contacts {
     public string property_name;
 
     public static HashSet<PersonaAttribute> create_set () {
-      return new HashSet<PersonaAttribute>((GLib.HashFunc) PersonaAttribute.hash,
-                                          (GLib.EqualFunc) PersonaAttribute.equal);
+      return new HashSet<PersonaAttribute>((HashDataFunc<PersonaAttribute>) PersonaAttribute.hash,
+                                          (EqualDataFunc<PersonaAttribute>) PersonaAttribute.equal);
     }
 
     public virtual bool is_removable (Persona from_persona) {
@@ -254,23 +254,24 @@ namespace Contacts {
        return;
 
       var added_values = new HashMultiMap<string, ImFieldDetails> (null, null,
-                                                                  (GLib.HashFunc) ImFieldDetails.hash,
-                                                                  (GLib.EqualFunc) ImFieldDetails.equal);
+                                                                  AbstractFieldDetails<string>.hash_static,
+                                                                  AbstractFieldDetails<string>.equal_static);
       foreach (var added in added_attributes) {
        added_values.set (((PersonaAttributeImAddress)added).protocol, 
((PersonaAttributeImAddress)added).detail);
       }
 
       var removed_values = new HashMultiMap<string, ImFieldDetails> (null, null,
-                                                                    (GLib.HashFunc) ImFieldDetails.hash,
-                                                                    (GLib.EqualFunc) ImFieldDetails.equal);
+                                                                    AbstractFieldDetails<string>.hash_static,
+                                                                    
AbstractFieldDetails<string>.equal_static);
+
       foreach (var removed in removed_attributes) {
        removed_values.set (((PersonaAttributeImAddress)removed).protocol, 
((PersonaAttributeImAddress)removed).detail);
       }
 
       var new_values =
        new HashMultiMap<string, ImFieldDetails> (null, null,
-                                                 (GLib.HashFunc) ImFieldDetails.hash,
-                                                 (GLib.EqualFunc) ImFieldDetails.equal);
+                                                 AbstractFieldDetails<string>.hash_static,
+                                                 AbstractFieldDetails<string>.equal_static);
       bool changed = false;
       foreach (var proto1 in details.im_addresses.get_keys ()) {
        foreach (var detail1 in details.im_addresses.get (proto1)) {
@@ -362,23 +363,23 @@ namespace Contacts {
        return;
 
       var added_values = new HashMultiMap<string, WebServiceFieldDetails> (null, null,
-                                                                          (GLib.HashFunc) 
WebServiceFieldDetails.hash,
-                                                                          (GLib.EqualFunc) 
WebServiceFieldDetails.equal);
+                                                                          
AbstractFieldDetails<string>.hash_static,
+                                                                          
AbstractFieldDetails<string>.equal_static);
       foreach (var added in added_attributes) {
        added_values.set (((PersonaAttributeWebService)added).service, 
((PersonaAttributeWebService)added).detail);
       }
 
       var removed_values = new HashMultiMap<string, WebServiceFieldDetails> (null, null,
-                                                                            (GLib.HashFunc) 
WebServiceFieldDetails.hash,
-                                                                            (GLib.EqualFunc) 
WebServiceFieldDetails.equal);
+                                                                            
AbstractFieldDetails<string>.hash_static,
+                                                                            
AbstractFieldDetails<string>.equal_static);
       foreach (var removed in removed_attributes) {
        removed_values.set (((PersonaAttributeWebService)removed).service, 
((PersonaAttributeWebService)removed).detail);
       }
 
       var new_values =
        new HashMultiMap<string, WebServiceFieldDetails> (null, null,
-                                                         (GLib.HashFunc) WebServiceFieldDetails.hash,
-                                                         (GLib.EqualFunc) WebServiceFieldDetails.equal);
+                                                         AbstractFieldDetails<string>.hash_static,
+                                                         AbstractFieldDetails<string>.equal_static);
       bool changed = false;
       foreach (var srv1 in details.web_service_addresses.get_keys ()) {
        foreach (var detail1 in details.web_service_addresses.get (srv1)) {
@@ -475,7 +476,7 @@ namespace Contacts {
   }
 
   public static bool persona_can_link_to (Persona persona, Set<PersonaAttribute> attributes) {
-    var property_names = new HashSet<string>(str_hash, str_equal);
+    var property_names = new HashSet<string>();
     foreach (var a in attributes)
       property_names.add (a.property_name);
 
@@ -500,7 +501,7 @@ namespace Contacts {
                                                     Set<PersonaAttribute>? added_attributes,
                                                     Set<PersonaAttribute>? removed_attributes,
                                                     LinkOperation operation) {
-    var properties = new HashSet<PersonaAttribute>((GLib.HashFunc)attr_type_hash, (GLib.EqualFunc) 
attr_type_equal);
+    var properties = new HashSet<PersonaAttribute>();
 
     if (added_attributes != null) {
       foreach (var a1 in added_attributes) {
diff --git a/src/contacts-shell-search-provider.vala b/src/contacts-shell-search-provider.vala
index 9e1b076..cd448d9 100644
--- a/src/contacts-shell-search-provider.vala
+++ b/src/contacts-shell-search-provider.vala
@@ -62,7 +62,7 @@ public class Contacts.SearchProvider : Object {
           matches.add (c);
     }
 
-    matches.sort((CompareFunc<Contact>) compare_contacts);
+    matches.sort((CompareDataFunc<Contact>) compare_contacts);
 
     var results = new string[matches.size];
     for (int i = 0; i < matches.size; i++)


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