diff --git a/Classes/HistoryDetailsViewController.h b/Classes/HistoryDetailsViewController.h index de8e57b62..35db4df6c 100644 --- a/Classes/HistoryDetailsViewController.h +++ b/Classes/HistoryDetailsViewController.h @@ -26,6 +26,7 @@ @interface HistoryDetailsViewController : UIViewController { @private ABRecordRef contact; + LinphoneCallLog *callLog; NSDateFormatter *dateFormatter; } @property (nonatomic, retain) IBOutlet UIImageView *avatarImage; @@ -41,7 +42,7 @@ @property (nonatomic, retain) IBOutlet UIButton *callButton; @property (nonatomic, retain) IBOutlet UIButton *messageButton; @property (nonatomic, retain) IBOutlet UIButton *addContactButton; -@property (nonatomic, assign) LinphoneCallLog *callLog; +@property (nonatomic, assign) NSString *callLogId; - (IBAction)onBackClick:(id)event; - (IBAction)onContactClick:(id)event; diff --git a/Classes/HistoryDetailsViewController.m b/Classes/HistoryDetailsViewController.m index de2867ab8..a95316da8 100644 --- a/Classes/HistoryDetailsViewController.m +++ b/Classes/HistoryDetailsViewController.m @@ -24,7 +24,7 @@ @implementation HistoryDetailsViewController -@synthesize callLog; +@synthesize callLogId; @synthesize avatarImage; @synthesize addressLabel; @synthesize dateLabel; @@ -57,6 +57,7 @@ [[NSNotificationCenter defaultCenter] removeObserver:self]; [dateFormatter release]; + [callLogId release]; [avatarImage release]; [addressLabel release]; @@ -98,8 +99,8 @@ static UICompositeViewDescription *compositeDescription = nil; #pragma mark - Property Functions -- (void)setCallLog:(LinphoneCallLog *)acallLog { - self->callLog = acallLog; +- (void)setCallLogId:(NSString *)acallLogId { + self->callLogId = [acallLogId copy]; [self update]; } @@ -123,6 +124,11 @@ static UICompositeViewDescription *compositeDescription = nil; selector:@selector(update) name:kLinphoneAddressBookUpdate object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(coreUpdateEvent:) + name:kLinphoneCoreUpdate + object:nil]; } - (void)viewWillDisappear:(BOOL)animated { @@ -131,6 +137,17 @@ static UICompositeViewDescription *compositeDescription = nil; [[NSNotificationCenter defaultCenter] removeObserver:self name:kLinphoneAddressBookUpdate object:nil]; + + [[NSNotificationCenter defaultCenter] removeObserver:self + name:kLinphoneCoreUpdate + object:nil]; +} + + +#pragma mark - Event Functions + +- (void)coreUpdateEvent:(NSNotification*)notif { + [self update]; } @@ -161,8 +178,25 @@ static UICompositeViewDescription *compositeDescription = nil; } - (void)update { - // Don't update if callLog is null + if(![LinphoneManager isLcReady]) { + return; + } + + // Look for the call log + callLog = NULL; + const MSList *list = linphone_core_get_call_logs([LinphoneManager getLc]); + while(list != NULL) { + LinphoneCallLog *log = (LinphoneCallLog *)list->data; + const char *cid = linphone_call_log_get_call_id(log); + if(cid != NULL && [callLogId isEqualToString:[NSString stringWithUTF8String:cid]]) { + callLog = log; + } + list = list->next; + } + + // Pop if callLog is null if(callLog == NULL) { + [[PhoneMainView instance] popCurrentView]; return; } diff --git a/Classes/HistoryTableViewController.m b/Classes/HistoryTableViewController.m index a87b89bf1..6091ab727 100644 --- a/Classes/HistoryTableViewController.m +++ b/Classes/HistoryTableViewController.m @@ -62,6 +62,36 @@ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(loadData) + name:kLinphoneAddressBookUpdate + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(coreUpdateEvent:) + name:kLinphoneCoreUpdate + object:nil]; + [self loadData]; +} + +- (void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + + [[NSNotificationCenter defaultCenter] removeObserver:self + name:kLinphoneAddressBookUpdate + object:nil]; + + [[NSNotificationCenter defaultCenter] removeObserver:self + name:kLinphoneCoreUpdate + object:nil]; + +} + + +#pragma mark - Event Functions + +- (void)coreUpdateEvent:(NSNotification*)notif { + // Invalid all pointers [self loadData]; } @@ -81,17 +111,19 @@ - (void)loadData { [callLogs removeAllObjects]; - const MSList * logs = linphone_core_get_call_logs([LinphoneManager getLc]); - while(logs != NULL) { - LinphoneCallLog* log = (LinphoneCallLog *) logs->data; - if(missedFilter) { - if (linphone_call_log_get_status(log) == LinphoneCallMissed) { + if([LinphoneManager isLcReady]) { + const MSList * logs = linphone_core_get_call_logs([LinphoneManager getLc]); + while(logs != NULL) { + LinphoneCallLog* log = (LinphoneCallLog *) logs->data; + if(missedFilter) { + if (linphone_call_log_get_status(log) == LinphoneCallMissed) { + [callLogs addObject:[NSValue valueWithPointer: log]]; + } + } else { [callLogs addObject:[NSValue valueWithPointer: log]]; } - } else { - [callLogs addObject:[NSValue valueWithPointer: log]]; + logs = ms_list_next(logs); } - logs = ms_list_next(logs); } [[self tableView] reloadData]; } diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 2a584c733..deedfea6f 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -238,12 +238,12 @@ } logs = logs->next; } - if(theLog != NULL) { + if(theLog != NULL && linphone_call_log_get_call_id(theLog) != NULL) { // Go to HistoryDetails view [[PhoneMainView instance] changeCurrentView:[HistoryViewController compositeViewDescription]]; HistoryDetailsViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[HistoryDetailsViewController compositeViewDescription] push:TRUE], HistoryDetailsViewController); if(controller != nil) { - [controller setCallLog:theLog]; + [controller setCallLogId:[NSString stringWithUTF8String:linphone_call_log_get_call_id(theLog)]]; } } } diff --git a/Classes/LinphoneUI/UIHistoryCell.m b/Classes/LinphoneUI/UIHistoryCell.m index 4591fee7a..948894570 100644 --- a/Classes/LinphoneUI/UIHistoryCell.m +++ b/Classes/LinphoneUI/UIHistoryCell.m @@ -68,11 +68,11 @@ #pragma mark - Action Functions - (IBAction)onDetails:(id) event { - if(callLog != NULL) { + if(callLog != NULL && linphone_call_log_get_call_id(callLog) != NULL) { // Go to History details view HistoryDetailsViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[HistoryDetailsViewController compositeViewDescription] push:TRUE], HistoryDetailsViewController); if(controller != nil) { - [controller setCallLog:callLog]; + [controller setCallLogId: [NSString stringWithUTF8String:linphone_call_log_get_call_id(callLog)]]; } } }