diff options
author | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2009-05-07 20:30:32 +0000 |
---|---|---|
committer | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2009-05-07 20:30:32 +0000 |
commit | a2e889fc52ede2939474bd3f163bba0a549d8d25 (patch) | |
tree | 98336d9b603062026d51cff5c73196d40cd564a6 /AddressBook | |
parent | 198414941a8aab089c7546d4160f5ec236a6e4b9 (diff) |
[Author: dmaclach]
Fix up GTMABAddressBook to use iPhone native API.
R=gianno,altse
DELTA=17 (17 added, 0 deleted, 0 changed)
Diffstat (limited to 'AddressBook')
-rw-r--r-- | AddressBook/GTMABAddressBook.h | 1 | ||||
-rw-r--r-- | AddressBook/GTMABAddressBook.m | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/AddressBook/GTMABAddressBook.h b/AddressBook/GTMABAddressBook.h index 0601405..0393ed0 100644 --- a/AddressBook/GTMABAddressBook.h +++ b/AddressBook/GTMABAddressBook.h @@ -117,6 +117,7 @@ typedef CFIndex GTMABPropertyType; #else // GTM_IPHONE_SDK +@class NSImage; typedef NSString* GTMABRecordID; typedef NSString* GTMABPropertyID; typedef NSString* GTMABMultiValueIdentifier; diff --git a/AddressBook/GTMABAddressBook.m b/AddressBook/GTMABAddressBook.m index b7920fe..6113a5c 100644 --- a/AddressBook/GTMABAddressBook.m +++ b/AddressBook/GTMABAddressBook.m @@ -19,6 +19,12 @@ #import "GTMABAddressBook.h" #import "GTMGarbageCollection.h" +#if GTM_IPHONE_SDK +#import <UIKit/UIKit.h> +#else // GTM_IPHONE_SDK +#import <Cocoa/Cocoa.h> +#endif // GTM_IPHONE_SDK + NSString *const kGTMABUnknownPropertyName = @"UNKNOWN_PROPERTY"; typedef struct { @@ -225,8 +231,22 @@ typedef struct { // Performs a prefix search on the composite names of people in an address book // and returns an array of persons that match the search criteria. - (NSArray *)peopleWithCompositeNameWithPrefix:(NSString *)prefix { +#if GTM_IPHONE_SDK + NSArray *people = + GTMCFAutorelease(ABAddressBookCopyPeopleWithName(addressBook_, + (CFStringRef)prefix)); + NSMutableArray *gtmPeople = [NSMutableArray arrayWithCapacity:[people count]]; + id person; + GTM_FOREACH_OBJECT(person, people) { + GTMABPerson *gtmPerson = [GTMABPerson recordWithRecord:person]; + [gtmPeople addObject:gtmPerson]; + } + return gtmPeople; +#else // TODO(dmaclach): Change over to recordsMatchingSearchElement as an // optimization? + // TODO(dmaclach): Make this match the way that the iPhone does it (by + // checking both first and last names) and adding unittests for all this. NSArray *people = [self people]; NSMutableArray *foundPeople = [NSMutableArray array]; GTMABPerson *person; @@ -234,12 +254,15 @@ typedef struct { NSString *compositeName = [person compositeName]; NSRange range = [compositeName rangeOfString:prefix options:(NSCaseInsensitiveSearch + | NSDiacriticInsensitiveSearch + | NSWidthInsensitiveSearch | NSAnchoredSearch)]; if (range.location != NSNotFound) { [foundPeople addObject:person]; } } return foundPeople; +#endif } // Performs a prefix search on the composite names of groups in an address book @@ -252,6 +275,8 @@ typedef struct { NSString *compositeName = [group compositeName]; NSRange range = [compositeName rangeOfString:prefix options:(NSCaseInsensitiveSearch + | NSDiacriticInsensitiveSearch + | NSWidthInsensitiveSearch | NSAnchoredSearch)]; if (range.location != NSNotFound) { [foundGroups addObject:group]; |