[folks] eds: Fix invalid cast in Edsf.PersonaStore



commit 79b83aeb6d97f6ce5b489e64e4cd13e5b2be06df
Author: Philip Withnall <philip tecnocode co uk>
Date:   Mon Jun 18 12:09:58 2012 +0100

    eds: Fix invalid cast in Edsf.PersonaStore
    
    E.SourceRegistry.find_extension() always returns an E.Source â we must then
    call get_extension() on that E.Source to get the relevant extension. This
    commit fixes an invalid cast here and factors out code to check for backend
    name matches for things like the âgoogleâ and âldapâ address book backends.
    
    Note that this depends on a new GIR annotation in EDataServer.

 backends/eds/lib/edsf-persona-store.vala |   41 ++++++++++++++----------------
 1 files changed, 19 insertions(+), 22 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 8b4d8fa..ef34982 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -2191,26 +2191,30 @@ public class Edsf.PersonaStore : Folks.PersonaStore
           error_in.message);
     }
 
-  /* Try and work out whether this address book is Google Contacts. If so, we
-   * can enable things like setting favourite status based on Android groups. */
-  internal bool _is_google_contacts_address_book ()
+  private bool _backend_name_matches (string backend_name)
     {
       if (this.source.has_extension (SOURCE_EXTENSION_ADDRESS_BOOK))
         {
-          var extension = (E.SourceAddressBook)
+          unowned E.SourceAddressBook extension = (E.SourceAddressBook)
             this.source.get_extension (SOURCE_EXTENSION_ADDRESS_BOOK);
 
-          var backend_name = ((!) extension).get_backend_name ();
-          /* backend name should be google for Google Contacts address books */
-          if (backend_name.has_prefix ("google"))
-            {
-              return true;
-            }
+          return (extension.get_backend_name () == backend_name);
         }
 
       return false;
     }
 
+  /* Try and work out whether this address book is Google Contacts. If so, we
+   * can enable things like setting favourite status based on Android groups. */
+  internal bool _is_google_contacts_address_book ()
+    {
+      /* Should only ever be called from property getters/setters. */
+      assert (this._source_registry != null);
+
+      /* backend name should be âgoogleâ for Google Contacts address books */
+      return this._backend_name_matches ("google");
+    }
+
   private bool _is_in_source_registry ()
     {
       /* Should only ever be called from a callback from the source list itself,
@@ -2262,21 +2266,14 @@ public class Edsf.PersonaStore : Folks.PersonaStore
     {
       /* We may be called before prepare() has finished (and it may then fail),
        * but _addressbook should always be non-null when we're called. */
+      assert (this._source_registry != null);
       assert (this._addressbook != null);
 
-      if (this._source_registry != null &&
-          this.source.has_extension (SOURCE_EXTENSION_ADDRESS_BOOK))
+      /* backend_name should be âldapâ for LDAP based address books */
+      if (this._backend_name_matches ("ldap"))
         {
-          var extension = (E.SourceAddressBook)
-            this.source.get_extension (SOURCE_EXTENSION_ADDRESS_BOOK);
-
-          var backend_name = ((!) extension).get_backend_name ();
-          /* base_uri should be ldap:// for LDAP based address books */
-          if (backend_name.has_prefix ("ldap"))
-            {
-              this.trust_level = PersonaStoreTrust.PARTIAL;
-              return;
-            }
+          this.trust_level = PersonaStoreTrust.PARTIAL;
+          return;
         }
 
       if (((!) this._addressbook).readonly)



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