forked from mirrors/linphone-iphone
Modify & Use FastAddressBook
Show avatar on call & incoming
This commit is contained in:
parent
c4d8a9ee63
commit
5f70424bf6
13 changed files with 207 additions and 194 deletions
|
|
@ -53,8 +53,6 @@
|
|||
|
||||
@synthesize contactID;
|
||||
|
||||
static const NSString *CONTACT_SIP_FIELD = @"SIP";
|
||||
|
||||
#pragma mark - Lifecycle Functions
|
||||
|
||||
- (void)initContactDetailsTableViewController {
|
||||
|
|
@ -72,7 +70,7 @@ static const NSString *CONTACT_SIP_FIELD = @"SIP";
|
|||
footerController = [[UIContactDetailsFooter alloc] init];
|
||||
|
||||
addressBook = ABAddressBookCreate();
|
||||
ABAddressBookRegisterExternalChangeCallback(addressBook, sync_toc_address_book, self);
|
||||
ABAddressBookRegisterExternalChangeCallback(addressBook, sync_address_book, self);
|
||||
}
|
||||
|
||||
- (id)init {
|
||||
|
|
@ -92,7 +90,7 @@ static const NSString *CONTACT_SIP_FIELD = @"SIP";
|
|||
}
|
||||
|
||||
- (void)dealloc {
|
||||
ABAddressBookUnregisterExternalChangeCallback(addressBook, sync_toc_address_book, self);
|
||||
ABAddressBookUnregisterExternalChangeCallback(addressBook, sync_address_book, self);
|
||||
CFRelease(addressBook);
|
||||
|
||||
[labelArray release];
|
||||
|
|
@ -159,7 +157,7 @@ static const NSString *CONTACT_SIP_FIELD = @"SIP";
|
|||
return [dict autorelease];
|
||||
}
|
||||
|
||||
static void sync_toc_address_book (ABAddressBookRef addressBook, CFDictionaryRef info, void *context) {
|
||||
static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef info, void *context) {
|
||||
ContactDetailsTableViewController* controller = (ContactDetailsTableViewController*)context;
|
||||
if(!controller->inhibUpdate) {
|
||||
[controller resetData];
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
addressBookMap = [[OrderedDictionary alloc] init];
|
||||
|
||||
addressBook = ABAddressBookCreate();
|
||||
ABAddressBookRegisterExternalChangeCallback(addressBook, sync_toc_address_book, self);
|
||||
ABAddressBookRegisterExternalChangeCallback(addressBook, sync_address_book, self);
|
||||
}
|
||||
|
||||
- (id)init {
|
||||
|
|
@ -53,7 +53,7 @@
|
|||
}
|
||||
|
||||
- (void)dealloc {
|
||||
ABAddressBookUnregisterExternalChangeCallback(addressBook, sync_toc_address_book, self);
|
||||
ABAddressBookUnregisterExternalChangeCallback(addressBook, sync_address_book, self);
|
||||
CFRelease(addressBook);
|
||||
[addressBookMap removeAllObjects];
|
||||
[super dealloc];
|
||||
|
|
@ -70,12 +70,13 @@
|
|||
|
||||
#pragma mark -
|
||||
|
||||
static void sync_toc_address_book (ABAddressBookRef addressBook, CFDictionaryRef info, void *context) {
|
||||
static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef info, void *context) {
|
||||
ContactsTableViewController* controller = (ContactsTableViewController*)context;
|
||||
ABAddressBookRevert(addressBook);
|
||||
[(UITableView *)controller.view reloadData];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - ViewController Functions
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#import "IncomingCallViewController.h"
|
||||
#import "LinphoneManager.h"
|
||||
#import "FastAddressBook.h"
|
||||
|
||||
@implementation IncomingCallViewController
|
||||
|
||||
|
|
@ -83,15 +84,45 @@
|
|||
#pragma mark - Property Functions
|
||||
|
||||
- (void)setCall:(LinphoneCall*)acall {
|
||||
call = acall;
|
||||
[self update];
|
||||
}
|
||||
|
||||
- (void)update {
|
||||
[self view]; //Force view load
|
||||
|
||||
call = acall;
|
||||
const char* userNameChars=linphone_address_get_username(linphone_call_get_remote_address(call));
|
||||
NSString* userName = userNameChars?[[[NSString alloc] initWithUTF8String:userNameChars] autorelease]:NSLocalizedString(@"Unknown",nil);
|
||||
const char* displayNameChars = linphone_address_get_display_name(linphone_call_get_remote_address(call));
|
||||
NSString* displayName = [displayNameChars?[[NSString alloc] initWithUTF8String:displayNameChars]:@"" autorelease];
|
||||
UIImage *image;
|
||||
NSString* address;
|
||||
const LinphoneAddress* addr = linphone_call_get_remote_address(call);
|
||||
if (addr != NULL) {
|
||||
// contact name
|
||||
const char* lAddress = linphone_address_as_string_uri_only(addr);
|
||||
const char* lDisplayName = linphone_address_get_display_name(addr);
|
||||
const char* lUserName = linphone_address_get_username(addr);
|
||||
if (lDisplayName)
|
||||
address = [NSString stringWithUTF8String:lDisplayName];
|
||||
else if(lUserName)
|
||||
address = [NSString stringWithUTF8String:lUserName];
|
||||
if(lAddress) {
|
||||
NSString *address = [FastAddressBook normalizeSipURI:[NSString stringWithUTF8String:lAddress]];
|
||||
ABRecordRef contact = [[[LinphoneManager instance] fastAddressBook] getContact:address];
|
||||
image = [FastAddressBook getContactImage:contact thumbnail:false];
|
||||
}
|
||||
} else {
|
||||
[addressLabel setText:@"Unknown"];
|
||||
}
|
||||
|
||||
[addressLabel setText:([displayName length]>0)?displayName:userName];
|
||||
// Set Image
|
||||
if(image == nil) {
|
||||
image = [UIImage imageNamed:@"avatar_unknown.png"];
|
||||
}
|
||||
[avatarImage setImage:image];
|
||||
|
||||
// Set Address
|
||||
if(address == nil) {
|
||||
address = @"Unknown";
|
||||
}
|
||||
[addressLabel setText:address];
|
||||
}
|
||||
|
||||
- (LinphoneCall*) getCall {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@
|
|||
|
||||
#include "linphonecore.h"
|
||||
|
||||
extern const NSString *CONTACT_SIP_FIELD;
|
||||
|
||||
typedef enum _Connectivity {
|
||||
wifi,
|
||||
wwan
|
||||
|
|
@ -64,10 +66,11 @@ typedef struct _LinphoneCallAppData {
|
|||
bool isbackgroundModeEnabled;
|
||||
|
||||
Connectivity connectivity;
|
||||
FastAddressBook* mFastAddressBook;
|
||||
const char* frontCamId;
|
||||
const char* backCamId;
|
||||
|
||||
FastAddressBook* fastAddressBook;
|
||||
|
||||
id<IASKSettingsStore> settingsStore;
|
||||
sqlite3 *database;
|
||||
|
||||
|
|
@ -93,8 +96,6 @@ typedef struct _LinphoneCallAppData {
|
|||
- (BOOL)enterBackgroundMode;
|
||||
- (void)becomeActive;
|
||||
- (void)kickOffNetworkConnection;
|
||||
- (NSString*)getDisplayNameFromAddressBook:(NSString*) number andUpdateCallLog:(LinphoneCallLog*)log;
|
||||
- (UIImage*)getImageFromAddressBook:(NSString*) number;
|
||||
|
||||
- (void)setupNetworkReachabilityCallback;
|
||||
- (void)refreshRegisters;
|
||||
|
|
@ -103,7 +104,7 @@ typedef struct _LinphoneCallAppData {
|
|||
- (BOOL)isSpeakerEnabled;
|
||||
|
||||
@property (nonatomic, retain) id<IASKSettingsStore> settingsStore;
|
||||
|
||||
@property (readonly) FastAddressBook* fastAddressBook;
|
||||
@property Connectivity connectivity;
|
||||
@property (nonatomic) int defaultExpires;
|
||||
@property (readonly) const char* frontCamId;
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
|
||||
static LinphoneCore* theLinphoneCore=nil;
|
||||
static LinphoneManager* theLinphoneManager=nil;
|
||||
const NSString *CONTACT_SIP_FIELD = @"SIP";
|
||||
|
||||
extern void libmsilbc_init();
|
||||
#ifdef HAVE_AMR
|
||||
|
|
@ -66,6 +67,7 @@ extern void libmsbcg729_init();
|
|||
@synthesize defaultExpires;
|
||||
@synthesize settingsStore;
|
||||
@synthesize database;
|
||||
@synthesize fastAddressBook;
|
||||
|
||||
struct codec_name_pref_table{
|
||||
const char *name;
|
||||
|
|
@ -112,7 +114,7 @@ struct codec_name_pref_table codec_pref_table[]={
|
|||
- (id)init {
|
||||
assert (!theLinphoneManager);
|
||||
if ((self = [super init])) {
|
||||
mFastAddressBook = [[FastAddressBook alloc] init];
|
||||
fastAddressBook = [[FastAddressBook alloc] init];
|
||||
database = NULL;
|
||||
theLinphoneManager = self;
|
||||
self.defaultExpires = 600;
|
||||
|
|
@ -122,7 +124,7 @@ struct codec_name_pref_table codec_pref_table[]={
|
|||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[mFastAddressBook release];
|
||||
[fastAddressBook release];
|
||||
[self closeDatabase];
|
||||
|
||||
[super dealloc];
|
||||
|
|
@ -164,50 +166,7 @@ struct codec_name_pref_table codec_pref_table[]={
|
|||
return theLinphoneManager;
|
||||
}
|
||||
|
||||
-(NSString*) getDisplayNameFromAddressBook:(NSString*) number andUpdateCallLog:(LinphoneCallLog*)log {
|
||||
//1 normalize
|
||||
NSString* lNormalizedNumber = [FastAddressBook normalizePhoneNumber:number];
|
||||
Contact* lContact = [mFastAddressBook getMatchingRecord:lNormalizedNumber];
|
||||
if (lContact) {
|
||||
CFStringRef lDisplayName = ABRecordCopyCompositeName(lContact.record);
|
||||
|
||||
if (log) {
|
||||
//add phone type
|
||||
char ltmpString[256];
|
||||
CFStringRef lFormatedString = CFStringCreateWithFormat(NULL,NULL,CFSTR("phone_type:%@;"),lContact.numberType);
|
||||
CFStringGetCString(lFormatedString, ltmpString,sizeof(ltmpString), kCFStringEncodingUTF8);
|
||||
linphone_call_log_set_ref_key(log, ltmpString);
|
||||
CFRelease(lFormatedString);
|
||||
}
|
||||
return [(NSString*)lDisplayName autorelease];
|
||||
}
|
||||
//[number release];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(UIImage*) getImageFromAddressBook:(NSString *)number {
|
||||
NSString* lNormalizedNumber = [FastAddressBook normalizePhoneNumber:number];
|
||||
Contact* lContact = [mFastAddressBook getMatchingRecord:lNormalizedNumber];
|
||||
if (lContact) {
|
||||
ABRecordRef person = ABAddressBookGetPersonWithRecordID(mFastAddressBook.addressBook, ABRecordGetRecordID(lContact.record));
|
||||
if (ABPersonHasImageData(person)) {
|
||||
NSData* d;
|
||||
// ios 4.1+
|
||||
if ( &ABPersonCopyImageDataWithFormat != nil) {
|
||||
d = (NSData*)ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail);
|
||||
} else {
|
||||
d = (NSData*)ABPersonCopyImageData(person);
|
||||
}
|
||||
return [UIImage imageWithData:[d autorelease]];
|
||||
}
|
||||
}
|
||||
/* return default image */
|
||||
return [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"contact_vide" ofType:@"png"]];
|
||||
//return nil;
|
||||
}
|
||||
|
||||
-(void) updateCallWithAddressBookData:(LinphoneCall*) call {
|
||||
-(void) updateCallWithAddressBookData:(LinphoneCall*) call {/*
|
||||
//1 copy adress book
|
||||
LinphoneCallLog* lLog = linphone_call_get_call_log(call);
|
||||
LinphoneAddress* lAddress;
|
||||
|
|
@ -232,7 +191,7 @@ struct codec_name_pref_table codec_pref_table[]={
|
|||
}
|
||||
|
||||
[lE164Number release];
|
||||
return;
|
||||
return;*/
|
||||
}
|
||||
|
||||
- (void)onCall:(LinphoneCall*)call StateChanged:(LinphoneCallState)state withMessage:(const char *)message {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#import "UICallCell.h"
|
||||
|
||||
#import "LinphoneManager.h"
|
||||
#import "FastAddressBook.h"
|
||||
|
||||
@implementation UICallCellData
|
||||
|
||||
|
|
@ -150,29 +151,37 @@
|
|||
if(data != nil && data->call != NULL) {
|
||||
call = data->call;
|
||||
const LinphoneAddress* addr = linphone_call_get_remote_address(call);
|
||||
|
||||
UIImage *image;
|
||||
NSString* address;
|
||||
if (addr != NULL) {
|
||||
const char* lUserNameChars = linphone_address_get_username(addr);
|
||||
NSString* lUserName = lUserNameChars?[[[NSString alloc] initWithUTF8String:lUserNameChars] autorelease]:NSLocalizedString(@"Unknown",nil);
|
||||
NSMutableString* mss = [[NSMutableString alloc] init];
|
||||
// contact name
|
||||
const char* n = linphone_address_get_display_name(addr);
|
||||
if (n)
|
||||
[mss appendFormat:@"%s", n, nil];
|
||||
else
|
||||
[mss appendFormat:@"%@",lUserName , nil];
|
||||
|
||||
[addressLabel setText:mss];
|
||||
|
||||
// TODO
|
||||
//imageView.image = [[LinphoneManager instance] getImageFromAddressBook:lUserName];
|
||||
[mss release];
|
||||
const char* lAddress = linphone_address_as_string_uri_only(addr);
|
||||
const char* lDisplayName = linphone_address_get_display_name(addr);
|
||||
const char* lUserName = linphone_address_get_username(addr);
|
||||
if (lDisplayName)
|
||||
address = [NSString stringWithUTF8String:lDisplayName];
|
||||
else if(lUserName)
|
||||
address = [NSString stringWithUTF8String:lUserName];
|
||||
if(lAddress) {
|
||||
NSString *address = [FastAddressBook normalizeSipURI:[NSString stringWithUTF8String:lAddress]];
|
||||
ABRecordRef contact = [[[LinphoneManager instance] fastAddressBook] getContact:address];
|
||||
image = [FastAddressBook getContactImage:contact thumbnail:false];
|
||||
}
|
||||
} else {
|
||||
[addressLabel setText:@"Unknown"];
|
||||
//TODO
|
||||
//imageView.image = nil;
|
||||
}
|
||||
|
||||
|
||||
// Set Image
|
||||
if(image == nil) {
|
||||
image = [UIImage imageNamed:@"avatar_unknown.png"];
|
||||
}
|
||||
[avatarImage setImage:image];
|
||||
|
||||
// Set Address
|
||||
if(address == nil) {
|
||||
address = @"Unknown";
|
||||
}
|
||||
[addressLabel setText:address];
|
||||
|
||||
LinphoneCallState state = linphone_call_get_state(call);
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#import "UIContactCell.h"
|
||||
|
||||
#import "FastAddressBook.h"
|
||||
|
||||
@implementation UIContactCell
|
||||
|
||||
@synthesize firstNameLabel;
|
||||
|
|
@ -26,6 +28,7 @@
|
|||
@synthesize avatarImage;
|
||||
@synthesize contact;
|
||||
|
||||
|
||||
#pragma mark - Lifecycle Functions
|
||||
|
||||
- (id)initWithIdentifier:(NSString*)identifier {
|
||||
|
|
@ -92,17 +95,12 @@
|
|||
if(lFirstName != nil)
|
||||
CFRelease(lFirstName);
|
||||
|
||||
if(ABPersonHasImageData(contact)) {
|
||||
CFDataRef imgData = ABPersonCopyImageDataWithFormat(contact, kABPersonImageFormatThumbnail);
|
||||
UIImage *img = [[UIImage alloc] initWithData:(NSData*)imgData];
|
||||
[avatarImage setImage:img];
|
||||
[img release];
|
||||
CFRelease(imgData);
|
||||
} else {
|
||||
[avatarImage setImage:[UIImage imageNamed:@"avatar_unknown_small.png"]];
|
||||
// Avatar
|
||||
UIImage *image = [FastAddressBook getContactImage:contact thumbnail:true];
|
||||
if(image == nil) {
|
||||
image = [UIImage imageNamed:@"avatar_unknown_small.png"];
|
||||
}
|
||||
|
||||
|
||||
[avatarImage setImage:image];
|
||||
|
||||
//
|
||||
// Adapt size
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#import "UIContactDetailsHeader.h"
|
||||
|
||||
#import "UIEditableTableViewCell.h"
|
||||
#import "FastAddressBook.h"
|
||||
|
||||
@implementation UIContactDetailsHeader
|
||||
|
||||
|
|
@ -78,32 +79,16 @@
|
|||
if(contact) {
|
||||
// Avatar image
|
||||
{
|
||||
if(ABPersonHasImageData(contact)) {
|
||||
CFDataRef imgData = ABPersonCopyImageDataWithFormat(contact, kABPersonImageFormatThumbnail);
|
||||
UIImage *img = [[UIImage alloc] initWithData:(NSData *)imgData];
|
||||
[avatarImage setImage:img];
|
||||
[img release];
|
||||
CFRelease(imgData);
|
||||
} else {
|
||||
[avatarImage setImage:[UIImage imageNamed:@"avatar_unknown_small.png"]];
|
||||
UIImage *image = [FastAddressBook getContactImage:contact thumbnail:true];
|
||||
if(image == nil) {
|
||||
image = [UIImage imageNamed:@"avatar_unknown_small.png"];
|
||||
}
|
||||
[avatarImage setImage:image];
|
||||
}
|
||||
|
||||
// Contact label
|
||||
{
|
||||
CFStringRef lFirstName = ABRecordCopyValue(contact, kABPersonFirstNameProperty);
|
||||
CFStringRef lLocalizedFirstName = (lFirstName != nil)?ABAddressBookCopyLocalizedLabel(lFirstName):nil;
|
||||
CFStringRef lLastName = ABRecordCopyValue(contact, kABPersonLastNameProperty);
|
||||
CFStringRef lLocalizedLastName = (lFirstName != nil)?ABAddressBookCopyLocalizedLabel(lLastName):nil;
|
||||
[contactLabel setText:[NSString stringWithFormat:@"%@ %@", (NSString*)lLocalizedFirstName, (NSString*)lLocalizedLastName]];
|
||||
if(lLocalizedLastName != nil)
|
||||
CFRelease(lLocalizedLastName);
|
||||
if(lLastName != nil)
|
||||
CFRelease(lLastName);
|
||||
if(lLocalizedFirstName != nil)
|
||||
CFRelease(lLocalizedFirstName);
|
||||
if(lFirstName != nil)
|
||||
CFRelease(lFirstName);
|
||||
[contactLabel setText:[FastAddressBook getContactDisplayName:contact]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,26 +20,17 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
#import <AddressBook/AddressBook.h>
|
||||
|
||||
@interface Contact : NSObject {
|
||||
ABRecordRef record;
|
||||
NSString* numberType;
|
||||
}
|
||||
-(id) initWithRecord:(ABRecordRef) record ofType:(NSString*) type;
|
||||
@property (nonatomic, readonly) ABRecordRef record;
|
||||
@property (nonatomic, readonly) NSString* numberType;
|
||||
@end
|
||||
|
||||
@interface FastAddressBook : NSObject {
|
||||
NSMutableDictionary* mAddressBookMap;
|
||||
|
||||
ABAddressBookRef addressBook;
|
||||
}
|
||||
|
||||
-(Contact*) getMatchingRecord:(NSString*) number ;
|
||||
+(NSString*) appendCountryCodeIfPossible:(NSString*) number ;
|
||||
+(NSString*) normalizePhoneNumber:(NSString*) number ;
|
||||
-(id) init ;
|
||||
|
||||
@property (nonatomic, readonly) ABAddressBookRef addressBook;
|
||||
+ (NSString*)getContactDisplayName:(ABRecordRef)contact;
|
||||
+ (UIImage*)getContactImage:(ABRecordRef)contact thumbnail:(BOOL)thumbnail;
|
||||
- (ABRecordRef)getContact:(NSString*)address;
|
||||
+ (NSString*)appendCountryCodeIfPossible:(NSString*)number;
|
||||
+ (NSString*)normalizePhoneNumber:(NSString*)number;
|
||||
+ (NSString*)normalizeSipURI:(NSString*)address;
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -22,15 +22,36 @@
|
|||
|
||||
@implementation FastAddressBook
|
||||
|
||||
@synthesize addressBook;
|
||||
|
||||
- (Contact*)getMatchingRecord:(NSString*) number {
|
||||
@synchronized (mAddressBookMap){
|
||||
return (Contact*) [mAddressBookMap objectForKey:number];
|
||||
}
|
||||
+ (NSString*)getContactDisplayName:(ABRecordRef)contact {
|
||||
NSString *retString = nil;
|
||||
if (contact) {
|
||||
CFStringRef lDisplayName = ABRecordCopyCompositeName(contact);
|
||||
if(lDisplayName != NULL) {
|
||||
retString = [NSString stringWithString:(NSString*)lDisplayName];
|
||||
CFRelease(lDisplayName);
|
||||
}
|
||||
}
|
||||
return retString;
|
||||
}
|
||||
|
||||
+ (NSString*)appendCountryCodeIfPossible:(NSString*) number {
|
||||
+ (UIImage*)getContactImage:(ABRecordRef)contact thumbnail:(BOOL)thumbnail {
|
||||
UIImage* retImage = nil;
|
||||
if (contact && ABPersonHasImageData(contact)) {
|
||||
CFDataRef imgData = ABPersonCopyImageDataWithFormat(contact, thumbnail?
|
||||
kABPersonImageFormatThumbnail: kABPersonImageFormatOriginalSize);
|
||||
retImage = [[[UIImage alloc] initWithData:(NSData *)imgData] autorelease];
|
||||
CFRelease(imgData);
|
||||
}
|
||||
return retImage;
|
||||
}
|
||||
|
||||
- (ABRecordRef)getContact:(NSString*)address {
|
||||
@synchronized (mAddressBookMap){
|
||||
return (ABRecordRef)[mAddressBookMap objectForKey:address];
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSString*)appendCountryCodeIfPossible:(NSString*)number {
|
||||
if (![number hasPrefix:@"+"] && ![number hasPrefix:@"00"]) {
|
||||
NSString* lCountryCode = [[LinphoneManager instance].settingsStore objectForKey:@"countrycode_preference"];
|
||||
if (lCountryCode && [lCountryCode length]>0) {
|
||||
|
|
@ -41,13 +62,29 @@
|
|||
return number;
|
||||
}
|
||||
|
||||
+ (NSString*)normalizePhoneNumber:(NSString*) number {
|
||||
NSString* lNormalizedNumber = [(NSString*)number stringByReplacingOccurrencesOfString:@" " withString:@""];
|
||||
lNormalizedNumber = [lNormalizedNumber stringByReplacingOccurrencesOfString:@"(" withString:@""];
|
||||
lNormalizedNumber = [lNormalizedNumber stringByReplacingOccurrencesOfString:@")" withString:@""];
|
||||
lNormalizedNumber = [lNormalizedNumber stringByReplacingOccurrencesOfString:@"-" withString:@""];
|
||||
lNormalizedNumber = [FastAddressBook appendCountryCodeIfPossible:lNormalizedNumber];
|
||||
return lNormalizedNumber;
|
||||
+ (NSString*)normalizeSipURI:(NSString*)address {
|
||||
return address;
|
||||
}
|
||||
|
||||
+ (NSString*)normalizePhoneNumber:(NSString*)address {
|
||||
NSMutableString* lNormalizedAddress = [NSMutableString stringWithString:address];
|
||||
[lNormalizedAddress replaceOccurrencesOfString:@" "
|
||||
withString:@""
|
||||
options:0
|
||||
range:NSMakeRange(0, [lNormalizedAddress length])];
|
||||
[lNormalizedAddress replaceOccurrencesOfString:@"("
|
||||
withString:@""
|
||||
options:0
|
||||
range:NSMakeRange(0, [lNormalizedAddress length])];
|
||||
[lNormalizedAddress replaceOccurrencesOfString:@")"
|
||||
withString:@""
|
||||
options:0
|
||||
range:NSMakeRange(0, [lNormalizedAddress length])];
|
||||
[lNormalizedAddress replaceOccurrencesOfString:@"-"
|
||||
withString:@""
|
||||
options:0
|
||||
range:NSMakeRange(0, [lNormalizedAddress length])];
|
||||
return [FastAddressBook appendCountryCodeIfPossible:lNormalizedAddress];
|
||||
}
|
||||
|
||||
void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef info, void *context) {
|
||||
|
|
@ -57,27 +94,49 @@ void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef info, void
|
|||
|
||||
NSArray *lContacts = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
|
||||
for (id lPerson in lContacts) {
|
||||
ABMutableMultiValueRef lPhoneNumbers = ABRecordCopyValue((ABRecordRef)lPerson, kABPersonPhoneProperty);
|
||||
for ( int i=0; i<ABMultiValueGetCount(lPhoneNumbers); i++) {
|
||||
CFStringRef lValue = ABMultiValueCopyValueAtIndex(lPhoneNumbers,i);
|
||||
CFStringRef lLabel = ABMultiValueCopyLabelAtIndex(lPhoneNumbers,i);
|
||||
CFStringRef lLocalizedLabel = ABAddressBookCopyLocalizedLabel(lLabel);
|
||||
NSString* lNormalizedKey = [FastAddressBook normalizePhoneNumber:(NSString*)lValue];
|
||||
Contact* lContact = [[Contact alloc] initWithRecord:lPerson ofType:(NSString *)lLocalizedLabel];
|
||||
[lAddressBookMap setObject:lContact forKey:lNormalizedKey];
|
||||
CFRelease(lValue);
|
||||
[lContact release];
|
||||
if (lLabel) CFRelease(lLabel);
|
||||
if (lLocalizedLabel) CFRelease(lLocalizedLabel);
|
||||
// Phone
|
||||
{
|
||||
ABMultiValueRef lMap = ABRecordCopyValue((ABRecordRef)lPerson, kABPersonPhoneProperty);
|
||||
if(lMap) {
|
||||
for (int i=0; i<ABMultiValueGetCount(lMap); i++) {
|
||||
CFStringRef lValue = ABMultiValueCopyValueAtIndex(lMap, i);
|
||||
CFStringRef lLabel = ABMultiValueCopyLabelAtIndex(lMap, i);
|
||||
CFStringRef lLocalizedLabel = ABAddressBookCopyLocalizedLabel(lLabel);
|
||||
NSString* lNormalizedKey = [FastAddressBook normalizePhoneNumber:(NSString*)lValue];
|
||||
[lAddressBookMap setObject:lPerson forKey:lNormalizedKey];
|
||||
CFRelease(lValue);
|
||||
if (lLabel) CFRelease(lLabel);
|
||||
if (lLocalizedLabel) CFRelease(lLocalizedLabel);
|
||||
}
|
||||
CFRelease(lMap);
|
||||
}
|
||||
}
|
||||
|
||||
// SIP
|
||||
{
|
||||
ABMultiValueRef lMap = ABRecordCopyValue((ABRecordRef)lPerson, kABPersonInstantMessageProperty);
|
||||
if(lMap) {
|
||||
for(int i = 0; i < ABMultiValueGetCount(lMap); ++i) {
|
||||
CFDictionaryRef lDict = ABMultiValueCopyValueAtIndex(lMap, i);
|
||||
if(CFDictionaryContainsKey(lDict, kABPersonInstantMessageServiceKey)) {
|
||||
if(CFStringCompare((CFStringRef)CONTACT_SIP_FIELD, CFDictionaryGetValue(lDict, kABPersonInstantMessageServiceKey), kCFCompareCaseInsensitive) == 0) {
|
||||
CFStringRef lValue = CFDictionaryGetValue(lDict, kABPersonInstantMessageUsernameKey);
|
||||
NSString* lNormalizedKey = [FastAddressBook normalizeSipURI:(NSString*)lValue];
|
||||
[lAddressBookMap setObject:lPerson forKey:lNormalizedKey];
|
||||
}
|
||||
}
|
||||
CFRelease(lDict);
|
||||
}
|
||||
CFRelease(lMap);
|
||||
}
|
||||
}
|
||||
CFRelease(lPhoneNumbers);
|
||||
}
|
||||
CFRelease(lContacts);
|
||||
}
|
||||
}
|
||||
|
||||
- (FastAddressBook*)init {
|
||||
if ((self = [super init])) {
|
||||
if ((self = [super init]) != nil) {
|
||||
mAddressBookMap = [[NSMutableDictionary alloc] init];
|
||||
addressBook = ABAddressBookCreate();
|
||||
ABAddressBookRegisterExternalChangeCallback (addressBook, sync_address_book, mAddressBookMap);
|
||||
|
|
@ -93,22 +152,3 @@ void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef info, void
|
|||
}
|
||||
|
||||
@end
|
||||
@implementation Contact
|
||||
@synthesize record;
|
||||
@synthesize numberType;
|
||||
|
||||
- (id)initWithRecord:(ABRecordRef) aRecord ofType:(NSString*) type {
|
||||
if ((self = [super init])) {
|
||||
record=CFRetain(aRecord);
|
||||
numberType= [type?type:@"unknown" retain];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
CFRelease(record);
|
||||
[numberType release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@
|
|||
<string key="NSFrameSize">{320, 460}</string>
|
||||
<reference key="NSSuperview"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView"/>
|
||||
<reference key="NSNextKeyView" ref="844572400"/>
|
||||
<string key="NSReuseIdentifierKey">_NS:9</string>
|
||||
<reference key="IBUIBackgroundColor" ref="981989056"/>
|
||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
||||
|
|
@ -404,9 +404,9 @@
|
|||
<object class="IBUITextInputTraits" key="IBUITextInputTraits">
|
||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
||||
</object>
|
||||
<object class="NSCustomResource" key="IBUIBackground" id="875835263">
|
||||
<object class="NSCustomResource" key="IBUIBackground" id="814678829">
|
||||
<string key="NSClassName">NSImage</string>
|
||||
<string key="NSResourceName">setup_label.png</string>
|
||||
<string key="NSResourceName">field_background.png</string>
|
||||
</object>
|
||||
<object class="IBUIFontDescription" key="IBUIFontDescription" id="119426708">
|
||||
<int key="type">1</int>
|
||||
|
|
@ -444,7 +444,7 @@
|
|||
<bool key="IBUISecureTextEntry">YES</bool>
|
||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
||||
</object>
|
||||
<reference key="IBUIBackground" ref="875835263"/>
|
||||
<reference key="IBUIBackground" ref="814678829"/>
|
||||
<reference key="IBUIFontDescription" ref="119426708"/>
|
||||
<reference key="IBUIFont" ref="87746142"/>
|
||||
</object>
|
||||
|
|
@ -474,7 +474,7 @@
|
|||
<bool key="IBUISecureTextEntry">YES</bool>
|
||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
||||
</object>
|
||||
<reference key="IBUIBackground" ref="875835263"/>
|
||||
<reference key="IBUIBackground" ref="814678829"/>
|
||||
<reference key="IBUIFontDescription" ref="119426708"/>
|
||||
<reference key="IBUIFont" ref="87746142"/>
|
||||
</object>
|
||||
|
|
@ -503,7 +503,7 @@
|
|||
<object class="IBUITextInputTraits" key="IBUITextInputTraits">
|
||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
||||
</object>
|
||||
<reference key="IBUIBackground" ref="875835263"/>
|
||||
<reference key="IBUIBackground" ref="814678829"/>
|
||||
<reference key="IBUIFontDescription" ref="119426708"/>
|
||||
<reference key="IBUIFont" ref="87746142"/>
|
||||
</object>
|
||||
|
|
@ -629,7 +629,7 @@
|
|||
<bool key="IBUISecureTextEntry">YES</bool>
|
||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
||||
</object>
|
||||
<reference key="IBUIBackground" ref="875835263"/>
|
||||
<reference key="IBUIBackground" ref="814678829"/>
|
||||
<reference key="IBUIFontDescription" ref="119426708"/>
|
||||
<reference key="IBUIFont" ref="87746142"/>
|
||||
</object>
|
||||
|
|
@ -658,7 +658,7 @@
|
|||
<object class="IBUITextInputTraits" key="IBUITextInputTraits">
|
||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
||||
</object>
|
||||
<reference key="IBUIBackground" ref="875835263"/>
|
||||
<reference key="IBUIBackground" ref="814678829"/>
|
||||
<reference key="IBUIFontDescription" ref="119426708"/>
|
||||
<reference key="IBUIFont" ref="87746142"/>
|
||||
</object>
|
||||
|
|
@ -736,7 +736,7 @@
|
|||
<object class="IBUITextInputTraits" key="IBUITextInputTraits">
|
||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
||||
</object>
|
||||
<reference key="IBUIBackground" ref="875835263"/>
|
||||
<reference key="IBUIBackground" ref="814678829"/>
|
||||
<reference key="IBUIFontDescription" ref="119426708"/>
|
||||
<reference key="IBUIFont" ref="87746142"/>
|
||||
</object>
|
||||
|
|
@ -766,7 +766,7 @@
|
|||
<bool key="IBUISecureTextEntry">YES</bool>
|
||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
||||
</object>
|
||||
<reference key="IBUIBackground" ref="875835263"/>
|
||||
<reference key="IBUIBackground" ref="814678829"/>
|
||||
<reference key="IBUIFontDescription" ref="119426708"/>
|
||||
<reference key="IBUIFont" ref="87746142"/>
|
||||
</object>
|
||||
|
|
@ -795,7 +795,7 @@
|
|||
<object class="IBUITextInputTraits" key="IBUITextInputTraits">
|
||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
||||
</object>
|
||||
<reference key="IBUIBackground" ref="875835263"/>
|
||||
<reference key="IBUIBackground" ref="814678829"/>
|
||||
<reference key="IBUIFontDescription" ref="119426708"/>
|
||||
<reference key="IBUIFont" ref="87746142"/>
|
||||
</object>
|
||||
|
|
@ -1461,13 +1461,13 @@
|
|||
<dictionary class="NSMutableDictionary" key="IBDocument.LastKnownImageSizes">
|
||||
<string key="button_background_default.png">{550, 101}</string>
|
||||
<string key="button_background_over.png">{550, 101}</string>
|
||||
<string key="field_background.png">{16, 16}</string>
|
||||
<string key="setup_back_default.png">{320, 154}</string>
|
||||
<string key="setup_back_disabled.png">{320, 154}</string>
|
||||
<string key="setup_back_over.png">{320, 154}</string>
|
||||
<string key="setup_cancel_default.png">{320, 154}</string>
|
||||
<string key="setup_cancel_disabled.png">{320, 154}</string>
|
||||
<string key="setup_cancel_over.png">{320, 154}</string>
|
||||
<string key="setup_label.png">{542, 88}</string>
|
||||
<string key="setup_start_default.png">{320, 154}</string>
|
||||
<string key="setup_start_disabled.png">{320, 154}</string>
|
||||
<string key="setup_start_over.png">{320, 154}</string>
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
|
|
@ -291,8 +291,8 @@
|
|||
D350F22115A43D3400149E54 /* setup_cancel_default.png in Resources */ = {isa = PBXBuildFile; fileRef = D350F21515A43D3400149E54 /* setup_cancel_default.png */; };
|
||||
D350F22215A43D3400149E54 /* setup_cancel_over.png in Resources */ = {isa = PBXBuildFile; fileRef = D350F21615A43D3400149E54 /* setup_cancel_over.png */; };
|
||||
D350F22315A43D3400149E54 /* setup_cancel_over.png in Resources */ = {isa = PBXBuildFile; fileRef = D350F21615A43D3400149E54 /* setup_cancel_over.png */; };
|
||||
D350F22415A43D3400149E54 /* setup_label.png in Resources */ = {isa = PBXBuildFile; fileRef = D350F21715A43D3400149E54 /* setup_label.png */; };
|
||||
D350F22515A43D3400149E54 /* setup_label.png in Resources */ = {isa = PBXBuildFile; fileRef = D350F21715A43D3400149E54 /* setup_label.png */; };
|
||||
D350F22415A43D3400149E54 /* field_background.png in Resources */ = {isa = PBXBuildFile; fileRef = D350F21715A43D3400149E54 /* field_background.png */; };
|
||||
D350F22515A43D3400149E54 /* field_background.png in Resources */ = {isa = PBXBuildFile; fileRef = D350F21715A43D3400149E54 /* field_background.png */; };
|
||||
D350F22615A43D3400149E54 /* setup_start_default.png in Resources */ = {isa = PBXBuildFile; fileRef = D350F21815A43D3400149E54 /* setup_start_default.png */; };
|
||||
D350F22715A43D3400149E54 /* setup_start_default.png in Resources */ = {isa = PBXBuildFile; fileRef = D350F21815A43D3400149E54 /* setup_start_default.png */; };
|
||||
D350F22815A43D3400149E54 /* setup_start_over.png in Resources */ = {isa = PBXBuildFile; fileRef = D350F21915A43D3400149E54 /* setup_start_over.png */; };
|
||||
|
|
@ -1139,7 +1139,7 @@
|
|||
D350F21415A43D3400149E54 /* setup_back_over.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = setup_back_over.png; path = Resources/setup_back_over.png; sourceTree = "<group>"; };
|
||||
D350F21515A43D3400149E54 /* setup_cancel_default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = setup_cancel_default.png; path = Resources/setup_cancel_default.png; sourceTree = "<group>"; };
|
||||
D350F21615A43D3400149E54 /* setup_cancel_over.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = setup_cancel_over.png; path = Resources/setup_cancel_over.png; sourceTree = "<group>"; };
|
||||
D350F21715A43D3400149E54 /* setup_label.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = setup_label.png; path = Resources/setup_label.png; sourceTree = "<group>"; };
|
||||
D350F21715A43D3400149E54 /* field_background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = field_background.png; path = Resources/field_background.png; sourceTree = "<group>"; };
|
||||
D350F21815A43D3400149E54 /* setup_start_default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = setup_start_default.png; path = Resources/setup_start_default.png; sourceTree = "<group>"; };
|
||||
D350F21915A43D3400149E54 /* setup_start_over.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = setup_start_over.png; path = Resources/setup_start_over.png; sourceTree = "<group>"; };
|
||||
D350F21A15A43D3400149E54 /* setup_title_assistant.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = setup_title_assistant.png; path = Resources/setup_title_assistant.png; sourceTree = "<group>"; };
|
||||
|
|
@ -2135,6 +2135,7 @@
|
|||
D38327ED1580FE3A00FA0D23 /* dialer_default.png */,
|
||||
D38327EE1580FE3A00FA0D23 /* dialer_over.png */,
|
||||
D3C2814A15A2D38D0098AA42 /* dialer_selected.png */,
|
||||
D350F21715A43D3400149E54 /* field_background.png */,
|
||||
D3F83EFA158205A100336684 /* hangup_default.png */,
|
||||
D3F83EFB158205A100336684 /* hangup_over.png */,
|
||||
D36C43CE158F2F370048BA40 /* header_conference.png */,
|
||||
|
|
@ -2225,7 +2226,6 @@
|
|||
D350F21515A43D3400149E54 /* setup_cancel_default.png */,
|
||||
D3A8BB7915A6CC3200F96BE5 /* setup_cancel_disabled.png */,
|
||||
D350F21615A43D3400149E54 /* setup_cancel_over.png */,
|
||||
D350F21715A43D3400149E54 /* setup_label.png */,
|
||||
D350F21815A43D3400149E54 /* setup_start_default.png */,
|
||||
D3A8BB7A15A6CC3200F96BE5 /* setup_start_disabled.png */,
|
||||
D350F21915A43D3400149E54 /* setup_start_over.png */,
|
||||
|
|
@ -2684,7 +2684,7 @@
|
|||
D350F21E15A43D3400149E54 /* setup_back_over.png in Resources */,
|
||||
D350F22015A43D3400149E54 /* setup_cancel_default.png in Resources */,
|
||||
D350F22215A43D3400149E54 /* setup_cancel_over.png in Resources */,
|
||||
D350F22415A43D3400149E54 /* setup_label.png in Resources */,
|
||||
D350F22415A43D3400149E54 /* field_background.png in Resources */,
|
||||
D350F22615A43D3400149E54 /* setup_start_default.png in Resources */,
|
||||
D350F22815A43D3400149E54 /* setup_start_over.png in Resources */,
|
||||
D350F22A15A43D3400149E54 /* setup_title_assistant.png in Resources */,
|
||||
|
|
@ -2923,7 +2923,7 @@
|
|||
D350F21F15A43D3400149E54 /* setup_back_over.png in Resources */,
|
||||
D350F22115A43D3400149E54 /* setup_cancel_default.png in Resources */,
|
||||
D350F22315A43D3400149E54 /* setup_cancel_over.png in Resources */,
|
||||
D350F22515A43D3400149E54 /* setup_label.png in Resources */,
|
||||
D350F22515A43D3400149E54 /* field_background.png in Resources */,
|
||||
D350F22715A43D3400149E54 /* setup_start_default.png in Resources */,
|
||||
D350F22915A43D3400149E54 /* setup_start_over.png in Resources */,
|
||||
D350F22B15A43D3400149E54 /* setup_title_assistant.png in Resources */,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue