forked from mirrors/linphone-iphone
182 lines
6.1 KiB
Objective-C
182 lines
6.1 KiB
Objective-C
/* HistoryTableViewController.m
|
|
*
|
|
* Copyright (C) 2009 Belledonne Comunications, Grenoble, France
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#import "HistoryTableViewController.h"
|
|
#import "UIHistoryCell.h"
|
|
#import "LinphoneManager.h"
|
|
#import "PhoneMainView.h"
|
|
#import "UACellBackgroundView.h"
|
|
#import "UILinphone.h"
|
|
#import "Utils.h"
|
|
|
|
@implementation HistoryTableViewController
|
|
|
|
@synthesize missedFilter;
|
|
|
|
#pragma mark - Lifecycle Functions
|
|
|
|
- (void)initHistoryTableViewController {
|
|
callLogs = [[NSMutableArray alloc] init];
|
|
missedFilter = false;
|
|
}
|
|
|
|
- (id)init {
|
|
self = [super init];
|
|
if (self) {
|
|
[self initHistoryTableViewController];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (id)initWithCoder:(NSCoder *)decoder {
|
|
self = [super initWithCoder:decoder];
|
|
if (self) {
|
|
[self initHistoryTableViewController];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)dealloc {
|
|
[callLogs release];
|
|
[super dealloc];
|
|
}
|
|
|
|
|
|
#pragma mark - ViewController Functions
|
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
[super viewDidAppear:animated];
|
|
[self loadData];
|
|
}
|
|
|
|
|
|
#pragma mark - Property Functions
|
|
|
|
- (void)setMissedFilter:(BOOL)amissedFilter {
|
|
self->missedFilter = amissedFilter;
|
|
[self loadData];
|
|
[[self tableView] reloadData];
|
|
}
|
|
|
|
|
|
#pragma mark - UITableViewDataSource Functions
|
|
|
|
- (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 (log->status == LinphoneCallMissed) {
|
|
[callLogs addObject:[NSValue valueWithPointer: log]];
|
|
}
|
|
} else {
|
|
[callLogs addObject:[NSValue valueWithPointer: log]];
|
|
}
|
|
logs = ms_list_next(logs);
|
|
}
|
|
}
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
return 1;
|
|
}
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
return [callLogs count];
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
static NSString *kCellId = @"UIHistoryCell";
|
|
UIHistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId];
|
|
if (cell == nil) {
|
|
cell = [[[UIHistoryCell alloc] initWithIdentifier:kCellId] autorelease];
|
|
// Background View
|
|
UACellBackgroundView *selectedBackgroundView = [[[UACellBackgroundView alloc] initWithFrame:CGRectZero] autorelease];
|
|
cell.selectedBackgroundView = selectedBackgroundView;
|
|
[selectedBackgroundView setBackgroundColor:LINPHONE_TABLE_CELL_BACKGROUND_COLOR];
|
|
}
|
|
|
|
LinphoneCallLog *log = [[callLogs objectAtIndex:[indexPath row]] pointerValue];
|
|
[cell setCallLog:log];
|
|
|
|
return cell;
|
|
}
|
|
|
|
|
|
#pragma mark - UITableViewDelegate Functions
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
[tableView deselectRowAtIndexPath:indexPath animated:NO];
|
|
|
|
LinphoneCallLog *callLog = [[callLogs objectAtIndex:[indexPath row]] pointerValue];
|
|
LinphoneAddress* addr;
|
|
if (callLog->dir == LinphoneCallIncoming) {
|
|
addr = callLog->from;
|
|
} else {
|
|
addr = callLog->to;
|
|
}
|
|
|
|
NSString* displayName = nil;
|
|
NSString* address = nil;
|
|
if(addr != NULL) {
|
|
BOOL useLinphoneAddress = true;
|
|
// contact name
|
|
char* lAddress = linphone_address_as_string_uri_only(addr);
|
|
if(lAddress) {
|
|
address = [NSString stringWithUTF8String:lAddress];
|
|
NSString *normalizedSipAddress = [FastAddressBook normalizeSipURI:address];
|
|
ABRecordRef contact = [[[LinphoneManager instance] fastAddressBook] getContact:normalizedSipAddress];
|
|
if(contact) {
|
|
displayName = [FastAddressBook getContactDisplayName:contact];
|
|
useLinphoneAddress = false;
|
|
}
|
|
ms_free(lAddress);
|
|
}
|
|
if(useLinphoneAddress) {
|
|
const char* lDisplayName = linphone_address_get_display_name(addr);
|
|
const char* lUserName = linphone_address_get_username(addr);
|
|
if (lDisplayName)
|
|
displayName = [NSString stringWithUTF8String:lDisplayName];
|
|
else if(lUserName)
|
|
displayName = [NSString stringWithUTF8String:lUserName];
|
|
}
|
|
}
|
|
|
|
if(address != nil) {
|
|
// Go to dialer view
|
|
DialerViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[DialerViewController compositeViewDescription]], DialerViewController);
|
|
if(controller != nil) {
|
|
[controller call:address displayName:displayName];
|
|
}
|
|
}
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
if(editingStyle == UITableViewCellEditingStyleDelete) {
|
|
[tableView beginUpdates];
|
|
LinphoneCallLog *callLog = [[callLogs objectAtIndex:[indexPath row]] pointerValue];
|
|
linphone_core_remove_call_log([LinphoneManager getLc], callLog);
|
|
[callLogs removeObjectAtIndex:[indexPath row]];
|
|
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
|
[tableView endUpdates];
|
|
}
|
|
}
|
|
|
|
@end
|
|
|