diff --git a/Classes/ChatTableViewController.m b/Classes/ChatTableViewController.m index da927f422..30e900622 100644 --- a/Classes/ChatTableViewController.m +++ b/Classes/ChatTableViewController.m @@ -24,6 +24,7 @@ #import "PhoneMainView.h" #import "UACellBackgroundView.h" #import "UILinphone.h" +#import "Utils.h" @implementation ChatTableViewController @@ -90,11 +91,10 @@ ChatModel *chat = [data objectAtIndex:[indexPath row]]; // Go to ChatRoom view - [[PhoneMainView instance] changeView:PhoneView_ChatRoom - calls:[NSArray arrayWithObjects: - [AbstractCall abstractCall:@"setRemoteContact:", [chat remoteContact]], - nil] - push:TRUE]; + ChatRoomTableViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeView:PhoneView_ChatRoom push:TRUE], ChatRoomTableViewController); + if(controller != nil) { + [controller setRemoteContact:[chat remoteContact]]; + } } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/Classes/ContactDetailsTableViewController.m b/Classes/ContactDetailsTableViewController.m index 3264ba4a7..4d9701168 100644 --- a/Classes/ContactDetailsTableViewController.m +++ b/Classes/ContactDetailsTableViewController.m @@ -25,6 +25,7 @@ #import "UILinphone.h" #import "OrderedDictionary.h" #import "FastAddressBook.h" +#import "Utils.h" @interface Entry : NSObject @@ -454,10 +455,10 @@ NSString *displayName = [FastAddressBook getContactDisplayName:contact]; // Go to dialer view - [[PhoneMainView instance] changeView:PhoneView_Dialer - calls:[NSArray arrayWithObjects: - [AbstractCall abstractCall:@"call:displayName:", dest, displayName], - nil]]; + DialerViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeView:PhoneView_Dialer], DialerViewController); + if(controller != nil) { + [controller call:dest displayName:displayName]; + } } } else { NSString *key = nil; diff --git a/Classes/ContactsTableViewController.m b/Classes/ContactsTableViewController.m index 5690a34b7..fd8bea406 100644 --- a/Classes/ContactsTableViewController.m +++ b/Classes/ContactsTableViewController.m @@ -23,6 +23,7 @@ #import "PhoneMainView.h" #import "UACellBackgroundView.h" #import "UILinphone.h" +#import "Utils.h" @implementation ContactsTableViewController @@ -193,14 +194,15 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf ABRecordRef lPerson = [subDic objectForKey: [subDic keyAtIndex:[indexPath row]]]; // Go to Contact details view - NSArray * calls; - if(tempAddress == nil) { - calls = [NSArray arrayWithObject: [AbstractCall abstractCall:@"setContact:", lPerson]]; - } else { - calls = [NSArray arrayWithObject: [AbstractCall abstractCall:@"editContact:address:", lPerson, tempAddress]]; - [self setTempAddress:nil]; + ContactDetailsViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeView:PhoneView_ContactDetails push:TRUE], ContactDetailsViewController); + if(controller != nil) { + if(tempAddress == nil) { + [controller setContact:lPerson]; + } else { + [controller editContact:lPerson address:tempAddress]; + [self setTempAddress:nil]; + } } - [[PhoneMainView instance] changeView:PhoneView_ContactDetails calls:calls push:TRUE]; } @end diff --git a/Classes/ContactsViewController.m b/Classes/ContactsViewController.m index 28bb9e252..7aa950af7 100644 --- a/Classes/ContactsViewController.m +++ b/Classes/ContactsViewController.m @@ -19,8 +19,9 @@ #import "ContactsViewController.h" #import "PhoneMainView.h" +#import "Utils.h" -#import "AddressBook/ABPerson.h" +#import @implementation ContactsViewController @@ -149,14 +150,15 @@ typedef enum _HistoryView { - (IBAction)onAddContactClick:(id)event { // Go to Contact details view - NSArray * calls; - if([tableController tempAddress] == nil) { - calls = [NSArray arrayWithObject: [AbstractCall abstractCall:@"newContact"]]; - } else { - calls = [NSArray arrayWithObject: [AbstractCall abstractCall:@"newContact:", [tableController tempAddress]]]; - [tableController setTempAddress:nil]; + ContactDetailsViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeView:PhoneView_ContactDetails push:TRUE], ContactDetailsViewController); + if(controller != nil) { + if([tableController tempAddress] == nil) { + [controller newContact]; + } else { + [controller newContact:[tableController tempAddress]]; + [tableController setTempAddress:nil]; + } } - [[PhoneMainView instance] changeView:PhoneView_ContactDetails calls:calls push:TRUE]; } @end diff --git a/Classes/DialerViewController.h b/Classes/DialerViewController.h index 2eedfca28..b5a94af44 100644 --- a/Classes/DialerViewController.h +++ b/Classes/DialerViewController.h @@ -55,10 +55,11 @@ } - (void)setAddress:(NSString*)address; -- (void)setTransferMode:(NSNumber*)enable; - (void)call:(NSString*)address displayName:(NSString *)displayName; - (void)call:(NSString*)address; +@property (nonatomic, assign) BOOL transferMode; + @property (nonatomic, retain) IBOutlet UITextField* addressField; @property (nonatomic, retain) IBOutlet UIButton* addContactButton; @property (nonatomic, retain) IBOutlet UICallButton* callButton; diff --git a/Classes/DialerViewController.m b/Classes/DialerViewController.m index 0630ca319..64fc25db7 100644 --- a/Classes/DialerViewController.m +++ b/Classes/DialerViewController.m @@ -24,12 +24,15 @@ #import "IncallViewController.h" #import "LinphoneManager.h" #import "PhoneMainView.h" +#import "Utils.h" #include "linphonecore.h" #include "private.h" @implementation DialerViewController +@synthesize transferMode; + @synthesize addressField; @synthesize addContactButton; @synthesize cancelButton; @@ -186,8 +189,8 @@ [addressField setText:address]; } -- (void)setTransferMode:(NSNumber*) n { - transferMode = [n boolValue]; +- (void)setTransferMode:(BOOL)atransferMode { + transferMode = atransferMode; LinphoneCall* call = linphone_core_get_current_call([LinphoneManager getLc]); LinphoneCallState state = (call != NULL)?linphone_call_get_state(call): 0; [self callUpdate:call state:state]; @@ -220,9 +223,10 @@ #pragma mark - Action Functions - (IBAction)onAddContactClick: (id) event { - [[PhoneMainView instance] changeView:PhoneView_Contacts - calls:[NSArray arrayWithObject:[AbstractCall abstractCall:@"setAddress:", [addressField text]]] - push:TRUE]; + ContactsViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeView:PhoneView_Contacts push:TRUE], ContactsViewController); + if(controller != nil) { + [controller setAddress:[addressField text]]; + } } - (IBAction)onBackClick: (id) event { diff --git a/Classes/HistoryDetailsViewController.h b/Classes/HistoryDetailsViewController.h index c3e3b3e93..14da3917b 100644 --- a/Classes/HistoryDetailsViewController.h +++ b/Classes/HistoryDetailsViewController.h @@ -49,8 +49,6 @@ @property (nonatomic, retain) IBOutlet UIButton *addContactButton; @property (nonatomic, assign) LinphoneCallLog *callLog; -- (void)setCallLogValue:(NSValue*)vcallLog; - - (IBAction)onBackClick:(id)event; - (IBAction)onContactClick:(id)event; - (IBAction)onAddContactClick:(id)event; diff --git a/Classes/HistoryDetailsViewController.m b/Classes/HistoryDetailsViewController.m index 30b58ebd9..fb7101e0b 100644 --- a/Classes/HistoryDetailsViewController.m +++ b/Classes/HistoryDetailsViewController.m @@ -20,6 +20,7 @@ #import "HistoryDetailsViewController.h" #import "PhoneMainView.h" #import "FastAddressBook.h" +#import "Utils.h" @implementation HistoryDetailsViewController @@ -71,10 +72,6 @@ #pragma mark - Property Functions -- (void)setCallLogValue:(NSValue*)vcallLog { - [self setCallLog:[vcallLog pointerValue]]; -} - - (void)setCallLog:(LinphoneCallLog *)acallLog { self->callLog = acallLog; [self update]; @@ -254,16 +251,18 @@ - (IBAction)onContactClick:(id)event { if(contact) { - [[PhoneMainView instance] changeView:PhoneView_ContactDetails - calls:[NSArray arrayWithObject:[AbstractCall abstractCall:@"setContact:", contact]] - push:TRUE]; + ContactDetailsViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeView:PhoneView_ContactDetails push:TRUE], ContactDetailsViewController); + if(controller != nil) { + [controller setContact:contact]; + } } } - (IBAction)onAddContactClick:(id)event { - [[PhoneMainView instance] changeView:PhoneView_Contacts - calls:[NSArray arrayWithObject:[AbstractCall abstractCall:@"setAddress:", [[addressButton titleLabel] text]]] - push:TRUE]; + ContactsViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeView:PhoneView_Contacts push:TRUE], ContactsViewController); + if(controller != nil) { + [controller setAddress:[[addressButton titleLabel] text]]; + } } - (IBAction)onAddressClick:(id)event { @@ -288,18 +287,14 @@ displayName = [NSString stringWithUTF8String:lUserName]; } - if(displayName != nil) { - // Go to dialer view - [[PhoneMainView instance] changeView:PhoneView_Dialer - calls:[NSArray arrayWithObjects: - [AbstractCall abstractCall:@"call:displayName:", [NSString stringWithUTF8String:lAddress], displayName], - nil]]; - } else { - // Go to dialer view - [[PhoneMainView instance] changeView:PhoneView_Dialer - calls:[NSArray arrayWithObjects: - [AbstractCall abstractCall:@"call:", [NSString stringWithUTF8String:lAddress]], - nil]]; + + DialerViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeView:PhoneView_Dialer], DialerViewController); + if(controller != nil) { + if(displayName != nil) { + [controller call:[NSString stringWithUTF8String:lAddress] displayName:displayName]; + } else { + [controller call:[NSString stringWithUTF8String:lAddress]]; + } } } diff --git a/Classes/HistoryTableViewController.m b/Classes/HistoryTableViewController.m index c0b6d33cb..eb4dea67b 100644 --- a/Classes/HistoryTableViewController.m +++ b/Classes/HistoryTableViewController.m @@ -23,6 +23,7 @@ #import "PhoneMainView.h" #import "UACellBackgroundView.h" #import "UILinphone.h" +#import "Utils.h" @implementation HistoryTableViewController @@ -123,38 +124,46 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:NO]; - LinphoneCallLog *log = [[callLogs objectAtIndex:[indexPath row]] pointerValue]; - LinphoneAddress* partyToCall; - if (log->dir == LinphoneCallIncoming) { - partyToCall=log->from; + LinphoneCallLog *callLog = [[callLogs objectAtIndex:[indexPath row]] pointerValue]; + LinphoneAddress* addr; + if (callLog->dir == LinphoneCallIncoming) { + addr = callLog->from; } else { - partyToCall=log->to; - } - const char* username = linphone_address_get_username(partyToCall)!=0?linphone_address_get_username(partyToCall):""; - const char* displayName = linphone_address_get_display_name(partyToCall)!=0?linphone_address_get_display_name(partyToCall):""; - const char* domain = linphone_address_get_domain(partyToCall); - - LinphoneProxyConfig* proxyCfg; - linphone_core_get_default_proxy([LinphoneManager getLc],&proxyCfg); - - NSString* phoneNumber; - - if (proxyCfg && (strcmp(domain, linphone_proxy_config_get_domain(proxyCfg)) == 0)) { - phoneNumber = [[NSString alloc] initWithCString:username encoding:[NSString defaultCStringEncoding]]; - } else { - phoneNumber = [[NSString alloc] initWithCString:linphone_address_as_string_uri_only(partyToCall) encoding:[NSString defaultCStringEncoding]]; + addr = callLog->to; } - NSString* dispName = [[NSString alloc] initWithCString:displayName encoding:[NSString defaultCStringEncoding]]; + NSString* displayName = nil; + NSString* address = nil; + if(addr != NULL) { + BOOL useLinphoneAddress = true; + // contact name + const 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; + } + } + 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]; + } + } - // Go to dialer view - [[PhoneMainView instance] changeView:PhoneView_Dialer - calls:[NSArray arrayWithObjects: - [AbstractCall abstractCall:@"call:displayName:", phoneNumber, dispName], - nil]]; - - [phoneNumber release]; - [dispName release]; + if(address != nil) { + // Go to dialer view + DialerViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeView:PhoneView_Dialer], DialerViewController); + if(controller != nil) { + [controller call:address displayName:displayName]; + } + } } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/Classes/LinphoneUI/UICallBar.m b/Classes/LinphoneUI/UICallBar.m index 3bb67f760..abfa85b21 100644 --- a/Classes/LinphoneUI/UICallBar.m +++ b/Classes/LinphoneUI/UICallBar.m @@ -23,6 +23,7 @@ #import "CPAnimationSequence.h" #import "CPAnimationStep.h" +#import "Utils.h" #include "linphonecore.h" #include "private.h" @@ -366,21 +367,21 @@ - (IBAction)onOptionsTransferClick:(id)sender { [self hideOptions]; // Go to dialer view - [[PhoneMainView instance] changeView:PhoneView_Dialer - calls:[NSArray arrayWithObjects: - [AbstractCall abstractCall:@"setAddress:", @""], - [AbstractCall abstractCall:@"setTransferMode:", [NSNumber numberWithInt: TRUE]], - nil]]; + DialerViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeView:PhoneView_Dialer], DialerViewController); + if(controller != nil) { + [controller setAddress:@""]; + [controller setTransferMode:TRUE]; + } } - (IBAction)onOptionsAddClick:(id)sender { [self hideOptions]; - // Go to dialer view - [[PhoneMainView instance] changeView:PhoneView_Dialer - calls:[NSArray arrayWithObjects: - [AbstractCall abstractCall:@"setAddress:", @""], - [AbstractCall abstractCall:@"setTransferMode:", [NSNumber numberWithInt: FALSE]], - nil]]; + // Go to dialer view + DialerViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeView:PhoneView_Dialer], DialerViewController); + if(controller != nil) { + [controller setAddress:@""]; + [controller setTransferMode:FALSE]; + } } - (IBAction)onOptionsClick:(id)sender { diff --git a/Classes/LinphoneUI/UIChatCell.m b/Classes/LinphoneUI/UIChatCell.m index 4ce25c3d7..2b913ee9c 100644 --- a/Classes/LinphoneUI/UIChatCell.m +++ b/Classes/LinphoneUI/UIChatCell.m @@ -19,7 +19,7 @@ #import "UIChatCell.h" #import "PhoneMainView.h" - +#import "Utils.h" @implementation UIChatCell @@ -125,11 +125,10 @@ - (IBAction)onDetailsClick: (id) event { // Go to Chat room view - [[PhoneMainView instance] changeView:PhoneView_ChatRoom - calls:[NSArray arrayWithObjects: - [AbstractCall abstractCall:@"setRemoteContact:", [chat remoteContact]], - nil] - push:TRUE]; + ChatRoomViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeView:PhoneView_ChatRoom push:TRUE], ChatRoomViewController); + if(controller !=nil) { + [controller setRemoteContact:[chat remoteContact]]; + } } - (IBAction)onDeleteClick: (id) event { diff --git a/Classes/LinphoneUI/UIHistoryCell.m b/Classes/LinphoneUI/UIHistoryCell.m index 9e4aae335..efdfd0277 100644 --- a/Classes/LinphoneUI/UIHistoryCell.m +++ b/Classes/LinphoneUI/UIHistoryCell.m @@ -20,6 +20,7 @@ #import "UIHistoryCell.h" #import "LinphoneManager.h" #import "PhoneMainView.h" +#import "Utils.h" @implementation UIHistoryCell @@ -69,11 +70,10 @@ - (IBAction)onDetails:(id) event { if(callLog != NULL) { // Go to History details view - [[PhoneMainView instance] changeView:PhoneView_HistoryDetails - calls:[NSArray arrayWithObjects: - [AbstractCall abstractCall:@"setCallLogValue:", [NSValue valueWithPointer: callLog]], - nil] - push:TRUE]; + HistoryDetailsViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeView:PhoneView_HistoryDetails push:TRUE], HistoryDetailsViewController); + if(controller != nil) { + [controller setCallLog:callLog]; + } } } diff --git a/Classes/PhoneMainView.h b/Classes/PhoneMainView.h index 6b887e1b1..61234cdbe 100644 --- a/Classes/PhoneMainView.h +++ b/Classes/PhoneMainView.h @@ -20,10 +20,22 @@ #import #import "LinphoneManager.h" -#import "CallDelegate.h" #import "UICompositeViewController.h" #import "UIModalViewController.h" -#import "AbstractCall.h" + +#import "FirstLoginViewController.h" +#import "IncomingCallViewController.h" +#import "ChatRoomViewController.h" +#import "ChatViewController.h" +#import "DialerViewController.h" +#import "ContactsViewController.h" +#import "ContactDetailsViewController.h" +#import "HistoryViewController.h" +#import "HistoryDetailsViewController.h" +#import "InCallViewController.h" +#import "SettingsViewController.h" +#import "FirstLoginViewController.h" +#import "WizardViewController.h" typedef enum _PhoneView { PhoneView_Wizard, @@ -58,12 +70,9 @@ typedef enum _PhoneView { @property (nonatomic, retain) IBOutlet UICompositeViewController *mainViewController; -- (void)changeView:(PhoneView)view; -- (void)changeView:(PhoneView)view push:(BOOL)push; -- (void)changeView:(PhoneView)view calls:(NSArray *)calls; -- (void)changeView:(PhoneView)view calls:(NSArray *)calls push:(BOOL)push; -- (void)popView; -- (void)popView:(NSArray *)calls; +- (UIViewController*)changeView:(PhoneView)view; +- (UIViewController*)changeView:(PhoneView)view push:(BOOL)push; +- (UIViewController*)popView; - (void)showTabBar:(BOOL)show; - (void)fullScreen:(BOOL)enabled; - (PhoneView)currentView; diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index d7dcb9114..e5eb6acd8 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -20,22 +20,7 @@ #import #import "PhoneMainView.h" - -#import "FirstLoginViewController.h" -#import "IncomingCallViewController.h" - -#import "ChatRoomViewController.h" -#import "ChatViewController.h" -#import "DialerViewController.h" -#import "ContactsViewController.h" -#import "ContactDetailsViewController.h" -#import "HistoryViewController.h" -#import "HistoryDetailsViewController.h" -#import "InCallViewController.h" -#import "SettingsViewController.h" -#import "FirstLoginViewController.h" -#import "WizardViewController.h" - +#import "Utils.h" #import "UIView+ModalStack.h" static PhoneMainView* phoneMainViewInstance=nil; @@ -236,11 +221,11 @@ static PhoneMainView* phoneMainViewInstance=nil; [self dismissIncomingCall:call]; if (canHideInCallView) { // Go to dialer view - [self changeView:PhoneView_Dialer - calls:[NSArray arrayWithObjects: - [AbstractCall abstractCall:@"setAddress:", @""], - [AbstractCall abstractCall:@"setTransferMode:", [NSNumber numberWithInt: FALSE]], - nil]]; + DialerViewController *controller = DYNAMIC_CAST([self changeView:PhoneView_Dialer], DialerViewController); + if(controller != nil) { + [controller setAddress:@""]; + [controller setTransferMode:FALSE]; + } } else { [self changeView:PhoneView_InCall]; } @@ -325,32 +310,24 @@ static PhoneMainView* phoneMainViewInstance=nil; [mainViewController setFullScreen:enabled]; } -- (void)changeView:(PhoneView)view { - [self changeView:view calls:nil push:FALSE]; +- (UIViewController*)changeView:(PhoneView)view { + return [self changeView:view push:FALSE]; } -- (void)changeView:(PhoneView)view calls:(NSArray *)dict { - [self changeView:view calls:dict push:FALSE]; -} - -- (void)changeView:(PhoneView)view push:(BOOL)push { - [self changeView:view calls:nil push:push]; -} - -- (void)changeView:(PhoneView)view calls:(NSArray *)calls push:(BOOL)push { +- (UIViewController*)changeView:(PhoneView)view push:(BOOL)push { if(push && currentView != -1) { [viewStack addObject:[NSNumber numberWithInt: currentView]]; } else { [viewStack removeAllObjects]; } - [self _changeView:view calls:calls transition:nil]; + return [self _changeView:view transition:nil]; } -- (void)_changeView:(PhoneView)view calls:(NSArray *)calls transition:(CATransition*)transition { +- (UIViewController*)_changeView:(PhoneView)view transition:(CATransition*)transition { NSLog(@"PhoneMainView: change view %d", view); UICompositeViewDescription* description = [viewDescriptions objectForKey:[NSNumber numberWithInt: view]]; if(description == nil) - return; + return nil; if(view != currentView) { if(transition == nil) @@ -360,28 +337,26 @@ static PhoneMainView* phoneMainViewInstance=nil; currentView = view; } - // Call abstractCall - if(calls != nil) { - for(AbstractCall *call in calls) { - [call call:[mainViewController getCurrentViewController]]; - } - } - NSDictionary* mdict = [NSMutableDictionary dictionaryWithObject: [NSNumber numberWithInt:currentView] forKey:@"view"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"LinphoneMainViewChange" object:self userInfo:mdict]; + + return [mainViewController getCurrentViewController]; } -- (void)popView { - [self popView:nil]; +- (UIViewController*)popView { + return [self popView:nil]; } -- (void)popView:(NSArray *)calls { +- (UIViewController*)popView:(NSArray *)calls { NSLog(@"PhoneMainView: Pop!"); if([viewStack count] > 0) { PhoneView view = [[viewStack lastObject] intValue]; [viewStack removeLastObject]; - [self _changeView:view calls:calls transition:[PhoneMainView getBackwardTransition]]; + [self _changeView:view transition:[PhoneMainView getBackwardTransition]]; + + return [mainViewController getCurrentViewController]; } + return nil; } - (PhoneView)currentView { diff --git a/Classes/Utils/AbstractCall.m b/Classes/Utils/AbstractCall.m deleted file mode 100644 index 7c9f35780..000000000 --- a/Classes/Utils/AbstractCall.m +++ /dev/null @@ -1,90 +0,0 @@ -/* AbstractCall.m - * - * Copyright (C) 2012 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 "AbstractCall.h" - -@implementation AbstractCall - -@synthesize functionName; -@synthesize functionArgs; - -+ (id)abstractCall:(NSString *)name, ... { - AbstractCall *object; - va_list args; - va_start(args, name); - object = [[AbstractCall alloc] init:name args:args]; - va_end(args); - return [object autorelease]; -} - -- (id)init:(NSString *)name, ... { - AbstractCall *object; - va_list args; - va_start(args, name); - object = [self init:name args:args]; - va_end(args); - return object; -} - -- (id)init:(NSString *)name args:(va_list)args { - self = [super init]; - if(self != nil) { - self->functionName = name; - NSMutableArray *array = [[NSMutableArray alloc] init]; - int count = 0; - for(int i = 0; i < [self->functionName length]; ++i) { - if([self->functionName characterAtIndex:i] == ':') { - ++count; - } - } - for (int i = 0; i < count; ++i) { - id arg = va_arg(args, id); - [array addObject:arg]; - } - self->functionArgs = array; - } - return self; -} - -- (void)dealloc { - [functionName release]; - [functionArgs release]; - - [super dealloc]; -} - -- (void)call:(id)object { - @try { - SEL selector = NSSelectorFromString(functionName); - NSMethodSignature *signature = [object methodSignatureForSelector:selector]; - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; - [invocation setTarget:object]; - [invocation setSelector:selector]; - for(int i=0; i<[functionArgs count]; i++) - { - id arg = [functionArgs objectAtIndex:i]; - [invocation setArgument:&arg atIndex:i+2]; // The first two arguments are the hidden arguments self and _cmd - } - [invocation invoke]; // Invoke the selector - } @catch (NSException *exception) { - NSLog(@"Abstract Call: Can't call %@ with arguments %@ on %@", functionName, functionArgs, object); - } -} - -@end diff --git a/Classes/Utils/AbstractCall.h b/Classes/Utils/Utils.h similarity index 75% rename from Classes/Utils/AbstractCall.h rename to Classes/Utils/Utils.h index 0be1a57e0..26764f459 100644 --- a/Classes/Utils/AbstractCall.h +++ b/Classes/Utils/Utils.h @@ -1,4 +1,4 @@ -/* AbstractCall.h +/* Utils.h * * Copyright (C) 2012 Belledonne Comunications, Grenoble, France * @@ -17,19 +17,13 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#import +#ifndef LINPHONE_UTILS_H +#define LINPHONE_UTILS_H +#define DYNAMIC_CAST(x, cls) \ + ({ \ + cls *inst_ = (cls *)(x); \ + [inst_ isKindOfClass:[cls class]]? inst_ : nil; \ + }) -@interface AbstractCall : NSObject { - NSString *functionName; - NSArray *functionArgs; -} - -@property (retain) NSString *functionName; -@property (retain) NSArray *functionArgs; - -+ (id)abstractCall:(NSString *)name, ...; -- (id)init:(NSString *)name, ...; -- (void)call:(id) object; - -@end +#endif diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index cf09ecf6a..da2906f04 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -633,8 +633,6 @@ D3ED3EB4158738FB006C0DE4 /* HistoryViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D3ED3EB2158738FA006C0DE4 /* HistoryViewController.xib */; }; D3ED3EB81587392C006C0DE4 /* HistoryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D3ED3EB615873929006C0DE4 /* HistoryViewController.m */; }; D3ED3EB91587392C006C0DE4 /* HistoryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D3ED3EB615873929006C0DE4 /* HistoryViewController.m */; }; - D3F26BEC159869A6005F9CAB /* AbstractCall.m in Sources */ = {isa = PBXBuildFile; fileRef = D3F26BEB159869A6005F9CAB /* AbstractCall.m */; }; - D3F26BED159869A6005F9CAB /* AbstractCall.m in Sources */ = {isa = PBXBuildFile; fileRef = D3F26BEB159869A6005F9CAB /* AbstractCall.m */; }; D3F26BF115986B73005F9CAB /* IncomingCallViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D3F26BEF15986B71005F9CAB /* IncomingCallViewController.m */; }; D3F26BF215986B73005F9CAB /* IncomingCallViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D3F26BEF15986B71005F9CAB /* IncomingCallViewController.m */; }; D3F26BF315986B73005F9CAB /* IncomingCallViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D3F26BF015986B72005F9CAB /* IncomingCallViewController.xib */; }; @@ -1088,6 +1086,7 @@ C90FAA7615AF54E6002091CB /* HistoryDetailsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HistoryDetailsViewController.h; sourceTree = ""; }; C90FAA7715AF54E6002091CB /* HistoryDetailsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HistoryDetailsViewController.m; sourceTree = ""; }; C90FAA7815AF54E6002091CB /* HistoryDetailsViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HistoryDetailsViewController.xib; sourceTree = ""; }; + C9B3A6FD15B485DB006F52EE /* Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Utils.h; path = Utils/Utils.h; sourceTree = ""; }; C9C8253F15AE204D00D493FA /* options_add_disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = options_add_disabled.png; path = Resources/options_add_disabled.png; sourceTree = ""; }; C9C8254015AE204D00D493FA /* options_transfer_disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = options_transfer_disabled.png; path = Resources/options_transfer_disabled.png; sourceTree = ""; }; C9C8254115AE204D00D493FA /* transfer_call_default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = transfer_call_default.png; path = Resources/transfer_call_default.png; sourceTree = ""; }; @@ -1393,8 +1392,6 @@ D3ED3EB2158738FA006C0DE4 /* HistoryViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HistoryViewController.xib; sourceTree = ""; }; D3ED3EB515873928006C0DE4 /* HistoryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HistoryViewController.h; sourceTree = ""; }; D3ED3EB615873929006C0DE4 /* HistoryViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = HistoryViewController.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; - D3F26BEA159869A6005F9CAB /* AbstractCall.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AbstractCall.h; path = Utils/AbstractCall.h; sourceTree = ""; }; - D3F26BEB159869A6005F9CAB /* AbstractCall.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; name = AbstractCall.m; path = Utils/AbstractCall.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; D3F26BEE15986B71005F9CAB /* IncomingCallViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IncomingCallViewController.h; sourceTree = ""; }; D3F26BEF15986B71005F9CAB /* IncomingCallViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IncomingCallViewController.m; sourceTree = ""; }; D3F26BF015986B72005F9CAB /* IncomingCallViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = IncomingCallViewController.xib; sourceTree = ""; }; @@ -2335,8 +2332,6 @@ D326483415887D4400930C67 /* Utils */ = { isa = PBXGroup; children = ( - D3F26BEA159869A6005F9CAB /* AbstractCall.h */, - D3F26BEB159869A6005F9CAB /* AbstractCall.m */, D38935F715A6D06800A3A3AA /* CPAnimation */, D32B9DFA15A2F131000B6DEC /* FastAddressBook.h */, D32B9DFB15A2F131000B6DEC /* FastAddressBook.m */, @@ -2344,6 +2339,7 @@ D326483715887D5200930C67 /* OrderedDictionary.m */, D3F9A9DD15AF0FFE0045320F /* TPKeyboardAvoiding */, D3F9A9EB15AF27620045320F /* UACellBackgroundView */, + C9B3A6FD15B485DB006F52EE /* Utils.h */, ); name = Utils; sourceTree = ""; @@ -3150,7 +3146,6 @@ D3EA53FD159850E80037DC6B /* LinphoneManager.m in Sources */, D3EA540D1598528B0037DC6B /* ChatTableViewController.m in Sources */, D3EA5411159853750037DC6B /* UIChatCell.m in Sources */, - D3F26BEC159869A6005F9CAB /* AbstractCall.m in Sources */, D3F26BF115986B73005F9CAB /* IncomingCallViewController.m in Sources */, D31B4B21159876C0002E6C72 /* UICompositeViewController.m in Sources */, D3F34F351599C354005BE94F /* UIModalViewController.m in Sources */, @@ -3240,7 +3235,6 @@ D3EA53FE159850E80037DC6B /* LinphoneManager.m in Sources */, D3EA540E1598528B0037DC6B /* ChatTableViewController.m in Sources */, D3EA5412159853750037DC6B /* UIChatCell.m in Sources */, - D3F26BED159869A6005F9CAB /* AbstractCall.m in Sources */, D3F26BF215986B73005F9CAB /* IncomingCallViewController.m in Sources */, D31B4B22159876C0002E6C72 /* UICompositeViewController.m in Sources */, D3F34F361599C354005BE94F /* UIModalViewController.m in Sources */,