From: Philip Withnall Date: Mon, 18 Jun 2012 11:09:58 +0000 (+0100) Subject: eds: Fix invalid cast in Edsf.PersonaStore X-Git-Tag: FOLKS_0_7_2~38 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=79b83aeb6d97f6ce5b489e64e4cd13e5b2be06df;p=platform%2Fupstream%2Ffolks.git 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. --- 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)