From 929a5045e76bef5f12649d58bb86bd1cb6c16b88 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Tue, 29 Nov 2011 16:02:55 +0100 Subject: [PATCH] ZRTP in call UI --- Classes/ConferenceCallDetailView.xib | 91 ++++++++++----------- Classes/IncallViewController.h | 7 +- Classes/IncallViewController.m | 117 ++++++++++++++++++++------- Resources/unverified.png | Bin 0 -> 358 bytes linphone.xcodeproj/project.pbxproj | 20 ++++- 5 files changed, 157 insertions(+), 78 deletions(-) create mode 100644 Resources/unverified.png diff --git a/Classes/ConferenceCallDetailView.xib b/Classes/ConferenceCallDetailView.xib index d756d676e..3b80aa096 100644 --- a/Classes/ConferenceCallDetailView.xib +++ b/Classes/ConferenceCallDetailView.xib @@ -36,15 +36,15 @@ 274 - + 274 {320, 328} - + _NS:418 - + 3 MCAwAA @@ -52,25 +52,26 @@ IBCocoaTouchFramework YES 0 + NO YES 44 22 22 - + 292 {{107, 328}, {106, 66}} - + NO NO IBCocoaTouchFramework 0 0 - + 3 MQA @@ -78,7 +79,7 @@ 1 MC4xOTYwNzg0MzE0IDAuMzA5ODAzOTIxNiAwLjUyMTU2ODYyNzUAA - + 3 MC41AA @@ -94,35 +95,35 @@ NSImage micro.png - + 2 2 - + Helvetica-Bold 18 16 - + 292 {{213, 328}, {107, 66}} - - + + NO NO IBCocoaTouchFramework 0 0 - + 1 MC4xOTYwNzg0MzE0IDAuMzA5ODAzOTIxNiAwLjUyMTU2ODYyNzUAA - + NSImage HP_inverse.png @@ -131,10 +132,10 @@ NSImage HP.png - - + + - + 292 {{0, 394}, {320, 66}} @@ -150,12 +151,12 @@ IBCocoaTouchFramework 0 0 - + 1 MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA - + NSImage stopcall-red.png @@ -164,47 +165,47 @@ NSImage clavier-01-106px.png - + Helvetica-Bold Helvetica 2 15 - + Helvetica-Bold 15 16 - + 292 {{0, 328}, {107, 66}} - + NO IBCocoaTouchFramework 0 0 - + 1 MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA - + NSImage effacer.png - - + + {{0, 20}, {320, 460}} - + 3 MC42NjY2NjY2NjY3AA @@ -219,7 +220,7 @@ back - + 16 @@ -227,7 +228,7 @@ hangup - + 17 @@ -235,7 +236,7 @@ mute - + 18 @@ -243,7 +244,7 @@ speaker - + 19 @@ -259,14 +260,14 @@ table - + 23 dataSource - + 21 @@ -274,7 +275,7 @@ delegate - + 22 @@ -292,11 +293,11 @@ 1 - - - - - + + + + + @@ -313,31 +314,31 @@ 7 - + 10 - + mute 11 - + end 12 - + speaker 14 - + Erase diff --git a/Classes/IncallViewController.h b/Classes/IncallViewController.h index 55fc0d57f..e6ea4e234 100644 --- a/Classes/IncallViewController.h +++ b/Classes/IncallViewController.h @@ -24,7 +24,7 @@ #include "UILinphone.h" @class VideoViewController; -@interface IncallViewController : UIViewController { +@interface IncallViewController : UIViewController { UIView* controlSubView, *callControlSubView, *hangUpView; @@ -74,6 +74,9 @@ BOOL mVideoShown; BOOL mVideoIsPending; BOOL mIncallViewIsReady; + + UIImage* verified, *unverified; + UIActionSheet* zrtpVerificationSheet; } -(void)displayStatus:(NSString*) message; @@ -81,7 +84,7 @@ - (IBAction)doAction:(id)sender; +(LinphoneCall*) retrieveCallAtIndex: (NSInteger) index inConference:(bool) conf; -+ (void) updateCellImageView:(UIImageView*)imageView Label:(UILabel*)label DetailLabel:(UILabel*)detailLabel AndAccessoryView:(UIImageView*)accessoryView withCall:(LinphoneCall*) call; ++ (void) updateCellImageView:(UIImageView*)imageView Label:(UILabel*)label DetailLabel:(UILabel*)detailLabel AndAccessoryView:(UIButton*)accessoryView withCall:(LinphoneCall*) call; @property (nonatomic, retain) IBOutlet UIView* controlSubView; @property (nonatomic, retain) IBOutlet UIView* callControlSubView; diff --git a/Classes/IncallViewController.m b/Classes/IncallViewController.m index 5675b9c13..625621f20 100644 --- a/Classes/IncallViewController.m +++ b/Classes/IncallViewController.m @@ -95,7 +95,9 @@ int callCount(LinphoneCore* lc) { //Controls [mute initWithOnImage:[UIImage imageNamed:@"micro_inverse.png"] offImage:[UIImage imageNamed:@"micro.png"] ]; [speaker initWithOnImage:[UIImage imageNamed:@"HP_inverse.png"] offImage:[UIImage imageNamed:@"HP.png"] ]; - + + verified = [[UIImage imageNamed:@"secured.png"] retain]; + unverified = [[UIImage imageNamed:@"unverified.png"] retain]; //Dialer init [zero initWithNumber:'0']; @@ -218,6 +220,12 @@ int callCount(LinphoneCore* lc) { } } } +-(void) viewWillDisappear:(BOOL)animated { + if (zrtpVerificationSheet != nil) { + [zrtpVerificationSheet dismissWithClickedButtonIndex:2 animated:NO]; + } +} + - (void) viewDidDisappear:(BOOL)animated { if (durationRefreasher != nil) { [durationRefreasher invalidate]; @@ -230,8 +238,8 @@ int callCount(LinphoneCore* lc) { } - (void)viewDidUnload { - - + [verified release]; + [unverified release]; } @@ -473,7 +481,7 @@ int callCount(LinphoneCore* lc) { [self updateActive:(cell == activeCallCell) cell:cell]; } -+ (void) updateCellImageView:(UIImageView*)imageView Label:(UILabel*)label DetailLabel:(UILabel*)detailLabel AndAccessoryView:(UIImageView*)accessoryView withCall:(LinphoneCall*) call { ++ (void) updateCellImageView:(UIImageView*)imageView Label:(UILabel*)label DetailLabel:(UILabel*)detailLabel AndAccessoryView:(UIButton*)accessoryView withCall:(LinphoneCall*) call { if (call == NULL) { ms_warning("UpdateCell called with null call"); [label setText:@""]; @@ -524,13 +532,19 @@ int callCount(LinphoneCore* lc) { } if (accessoryView != nil) { - if (linphone_call_params_get_media_encryption(linphone_call_get_current_params(call)) != - LinphoneMediaEncryptionNone) { - if (accessoryView.image == nil) - accessoryView.image = [UIImage imageNamed:@"secured.png"]; + /* + LinphoneMediaEncryption enc = linphone_call_params_get_media_encryption(linphone_call_get_current_params(call)); + if (enc != LinphoneMediaEncryptionNone) { + if (accessoryView.imageView.image == nil) { + if (enc == LinphoneMediaEncryptionSRTP || linphone_call_get_authentication_token_verified(call)) { + [accessoryView setImage: verified forState:UIControlStateNormal]; + } else { + [accessoryView setImage: unverified forState:UIControlStateNormal]; + } + } } else { - accessoryView.image = nil; - } + [accessoryView setImage: (UIImage*)nil forState:UIControlStateNormal]; + }*/ } } @@ -559,9 +573,7 @@ int callCount(LinphoneCore* lc) { else [ms appendFormat:(isFirst?@"%s":@", %s"), linphone_address_get_username(addr), nil]; - //if (call == selectedCall) - // [self updateActive:YES cell:cell]; - LinphoneCall* selectedCall = linphone_core_get_current_call([LinphoneManager getLc]); + LinphoneCall* selectedCall = linphone_core_get_current_call([LinphoneManager getLc]); if (call == selectedCall) { [callTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; cell.selected = YES; @@ -573,11 +585,6 @@ int callCount(LinphoneCore* lc) { } [cell.detailTextLabel setText:ms]; cell.imageView.image = nil; - - /*if (linphone_core_is_in_conference(lc)) - cell.backgroundColor = [UIColor colorWithRed:0 green:1 blue:0 alpha:1]; - else - cell.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];*/ } -(void) tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath @@ -597,8 +604,6 @@ int callCount(LinphoneCore* lc) { cell.textLabel.font = [UIFont systemFontOfSize:40]; cell.textLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight; } - if (cell.accessoryView != nil) - ((UIImageView*)cell.accessoryView).image = nil; LinphoneCore* lc = [LinphoneManager getLc]; if (indexPath.row == 0 && linphone_core_get_conference_size(lc) > 0) { @@ -611,27 +616,79 @@ int callCount(LinphoneCore* lc) { else cell.accessoryType = UITableViewCellAccessoryNone; } else { + if (cell.accessoryView == nil) { + UIButton* b = [UIButton buttonWithType:UIButtonTypeCustom]; + [b setFrame:CGRectMake(0, 0, 28, 28)]; + [b setImage:nil forState:UIControlStateNormal]; + b.backgroundColor = [UIColor clearColor]; + b.userInteractionEnabled = YES; + cell.accessoryView = b; + } LinphoneCall* call = [IncallViewController retrieveCallAtIndex:indexPath.row inConference:NO]; - [IncallViewController updateCellImageView:cell.imageView Label:cell.textLabel DetailLabel:cell.detailTextLabel AndAccessoryView:(UIImageView*)cell.accessoryView withCall:call]; + [IncallViewController updateCellImageView:cell.imageView Label:cell.textLabel DetailLabel:cell.detailTextLabel AndAccessoryView:(UIButton*)cell.accessoryView withCall:call]; if (linphone_core_get_current_call(lc) == call) activeCallCell = cell; cell.accessoryType = UITableViewCellAccessoryNone; - if (cell.accessoryView == nil) - cell.accessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 28, 28)]; + + LinphoneMediaEncryption enc = linphone_call_params_get_media_encryption(linphone_call_get_current_params(call)); + + UIButton* accessoryBtn = (UIButton*) cell.accessoryView; + if (enc != LinphoneMediaEncryptionNone) { + if (enc == LinphoneMediaEncryptionSRTP || linphone_call_get_authentication_token_verified(call)) { + [accessoryBtn setImage: verified forState:UIControlStateNormal]; + } else { + [accessoryBtn setImage: unverified forState:UIControlStateNormal]; + } + } else { + [accessoryBtn setImage: (UIImage*)nil forState:UIControlStateNormal]; + } + + if (((UIButton*)cell.accessoryView).imageView.image != nil && linphone_call_params_get_media_encryption(linphone_call_get_current_params(call)) == LinphoneMediaEncryptionZRTP) { + [((UIButton*)cell.accessoryView) addTarget:self action:@selector(secureIconPressed:withEvent:) forControlEvents:UIControlEventTouchUpInside]; + } } cell.userInteractionEnabled = YES; cell.selectionStyle = UITableViewCellSelectionStyleNone; - //cell.selectionStyle = UITableViewCellSelectionStyleBlue; - - - - /*NSString *path = [[NSBundle mainBundle] pathForResource:[item objectForKey:@"imageKey"] ofType:@"png"]; - UIImage *theImage = [UIImage imageWithContentsOfFile:path]; - cell.imageView.image = theImage;*/ return cell; } +-(void) secureIconPressed:(UIControl*) button withEvent: (UIEvent*) evt { + NSSet* touches = [evt allTouches]; + UITouch* touch = [touches anyObject]; + CGPoint currentTouchPos = [touch locationInView:self.callTableView]; + NSIndexPath *path = [self.callTableView indexPathForRowAtPoint:currentTouchPos]; + if (path) { + LinphoneCall* call = [IncallViewController retrieveCallAtIndex:path.row inConference:NO]; + // start action sheet to validate/unvalidate zrtp code + CallDelegate* cd = [[CallDelegate alloc] init]; + cd.delegate = self; + cd.call = call; + + [(UIButton*)[callTableView cellForRowAtIndexPath:path].accessoryView setImage:nil forState:UIControlStateNormal]; + + zrtpVerificationSheet = [[UIActionSheet alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedString(@" Mark auth token '%s' as:",nil),linphone_call_get_authentication_token(call)] + delegate:cd + cancelButtonTitle:NSLocalizedString(@"Unverified",nil) + destructiveButtonTitle:NSLocalizedString(@"Verified",nil) + otherButtonTitles:nil]; + + zrtpVerificationSheet.actionSheetStyle = UIActionSheetStyleDefault; + [zrtpVerificationSheet showInView:self.view]; + [zrtpVerificationSheet release]; + } +} + +-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex withUserDatas:(void *)datas { + LinphoneCall* call = (LinphoneCall*)datas; + // maybe we could verify call validity + + if (buttonIndex == 0) + linphone_call_set_authentication_token_verified(call, YES); + else if (buttonIndex == 1) + linphone_call_set_authentication_token_verified(call, NO); + zrtpVerificationSheet = nil; +} // UITableViewDataSource (required) - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section diff --git a/Resources/unverified.png b/Resources/unverified.png new file mode 100644 index 0000000000000000000000000000000000000000..f824d40c406655fea7979ef5e991e3dc0f8c3d4a GIT binary patch literal 358 zcmeAS@N?(olHy`uVBq!ia0vp^l0YoZ!3HG%J$@n#q!^2X+?^QKos)S9?EK z*~r^$AmIA{rsB$#5e;UGH!yH7Nt|P%^MLh`+7=y$srL?*Nj2*vaZ0-fDisQCV)^#> z_nps-?k+5?c_FzI84bQQ#&+I!+gkcfByhr==!^}*wYJjttFN6tE2HCbfT4fss<^T% zr_X)Y^-S@+@kC*P(gGu2xf;DQo^9S-v59^r_c#{)F3!uEdZ*&5*sXWQeGEJI3p703 zK5?nSnzyH7+4~NBS$V8jo@HU{ru?3%|3xHU&1&2AtUCSrE^);TE|!7s{uXe4zHroA y(PxeDwq5E^dVX0RpR`3J>5!nkpjfQFhkol1Cn?K%hgU!!GkCiCxvX