[gnome-contacts] TypeSet: fix a regression from the previous commit



commit 43e298a3bf1cf173f78a34ae9d29f0060a372a47
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sun Dec 16 18:29:13 2018 +0100

    TypeSet: fix a regression from the previous commit
    
    In some cases, a null-TypeDescriptor could be returned, spawning a
    g_critical() in the ContactSheet. Also, the VcardTypMapping.matches
    function didn't always correctly return the right value.

 src/contacts-typeset.vala            | 14 ++++++++------
 src/contacts-vcard-type-mapping.vala |  6 +++---
 2 files changed, 11 insertions(+), 9 deletions(-)
---
diff --git a/src/contacts-typeset.vala b/src/contacts-typeset.vala
index 4b5a5e4..c0071f1 100644
--- a/src/contacts-typeset.vala
+++ b/src/contacts-typeset.vala
@@ -57,7 +57,7 @@ public class Contacts.TypeSet : Object  {
   public void get_iter_for_field_details (AbstractFieldDetails detail, out TreeIter iter) {
     // Note that we shouldn't have null here, but it's there just to be sure.
     var d = lookup_descriptor_for_field_details (detail);
-    iter = (d != null)? d.iter : other_dummy.iter;
+    iter = d.iter;
   }
 
   /**
@@ -84,7 +84,7 @@ public class Contacts.TypeSet : Object  {
    */
   public string format_type (AbstractFieldDetails detail) {
     var d = lookup_descriptor_for_field_details (detail);
-    return (d != null)? d.display_name : _("Other");
+    return d.display_name;
   }
 
   /**
@@ -179,7 +179,7 @@ public class Contacts.TypeSet : Object  {
     return null;
   }
 
-  private TypeDescriptor? lookup_descriptor_for_field_details (AbstractFieldDetails detail) {
+  public TypeDescriptor lookup_descriptor_for_field_details (AbstractFieldDetails detail) {
     if (detail.parameters.contains (TypeDescriptor.X_GOOGLE_LABEL)) {
       var label = Utils.get_first<string> (detail.parameters[TypeDescriptor.X_GOOGLE_LABEL]);
       var descriptor = get_descriptor_for_custom_label (label);
@@ -190,15 +190,17 @@ public class Contacts.TypeSet : Object  {
     }
 
     var types = detail.get_parameter_values ("type");
-    if (types == null || types.is_empty)
-      return null;
+    if (types == null || types.is_empty) {
+      warning ("No types given in the AbstractFieldDetails");
+      return this.other_dummy;
+    }
 
     foreach (VcardTypeMapping? d in this.vcard_type_mappings) {
       if (d.matches (types))
         return lookup_descriptor_in_store (d.name);
     }
 
-    return null;
+    return this.other_dummy;
   }
 
 
diff --git a/src/contacts-vcard-type-mapping.vala b/src/contacts-vcard-type-mapping.vala
index 35ce3e0..08ed7ac 100644
--- a/src/contacts-vcard-type-mapping.vala
+++ b/src/contacts-vcard-type-mapping.vala
@@ -46,10 +46,10 @@ internal struct Contacts.VcardTypeMapping {
    */
   public bool matches (Collection<string> types) {
     for (int i = 0; i < MAX_TYPES && this.types[i] != null; i++) {
-      bool occurs_in_list = true;
+      bool occurs_in_list = false;
       foreach (var type in types) {
-        if (!types_are_equal (type, this.types[i])) {
-          occurs_in_list = false;
+        if (types_are_equal (type, this.types[i])) {
+          occurs_in_list = true;
           break;
         }
       }


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