From 620200be2f4a1248e3ea4cf09b50dd61cc542284 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Mon, 26 Oct 2015 16:00:28 +0100 Subject: [PATCH] ZRTP: add confirmation popup on call start --- Classes/ChatConversationView.m | 2 + Classes/ChatsListView.m | 2 + Classes/ContactDetailsView.m | 2 + Classes/ContactsListView.m | 2 + Classes/HistoryListView.m | 2 + .../LinphoneUI/Base.lproj/StatusBarView.xib | 18 ++++--- Classes/LinphoneUI/StatusBarView.h | 7 +-- Classes/LinphoneUI/StatusBarView.m | 51 +++++++++---------- Classes/LinphoneUI/UIConfirmationDialog.h | 5 +- Classes/LinphoneUI/UIConfirmationDialog.m | 13 +++++ Classes/LinphoneUI/UIConfirmationDialog.xib | 9 ++-- Classes/LinphoneUI/UIRoundBorderedButton.m | 5 +- 12 files changed, 75 insertions(+), 43 deletions(-) diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index c827ebf6a..5bc64c185 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -452,6 +452,8 @@ static void message_status(LinphoneChatMessage *msg, LinphoneChatMessageState st [NSString stringWithFormat:NSLocalizedString(@"Are you sure that you want to delete %d messages?", nil), _tableController.selectedItems.count]; [UIConfirmationDialog ShowWithMessage:msg + cancelMessage:nil + confirmMessage:nil onCancelClick:^() { [self onEditionChangeClick:nil]; } diff --git a/Classes/ChatsListView.m b/Classes/ChatsListView.m index 19e287c9c..b0a9c5292 100644 --- a/Classes/ChatsListView.m +++ b/Classes/ChatsListView.m @@ -83,6 +83,8 @@ static UICompositeViewDescription *compositeDescription = nil; [NSString stringWithFormat:NSLocalizedString(@"Are you sure that you want to delete %d conversations?", nil), _tableController.selectedItems.count]; [UIConfirmationDialog ShowWithMessage:msg + cancelMessage:nil + confirmMessage:nil onCancelClick:^() { [self onEditionChangeClick:nil]; } diff --git a/Classes/ContactDetailsView.m b/Classes/ContactDetailsView.m index e339501ef..721284c48 100644 --- a/Classes/ContactDetailsView.m +++ b/Classes/ContactDetailsView.m @@ -260,6 +260,8 @@ static UICompositeViewDescription *compositeDescription = nil; - (IBAction)onDeleteClick:(id)sender { NSString *msg = NSLocalizedString(@"Are you sure that you want to delete your contact?", nil); [UIConfirmationDialog ShowWithMessage:msg + cancelMessage:nil + confirmMessage:nil onCancelClick:nil onConfirmationClick:^() { [self setEditing:FALSE]; diff --git a/Classes/ContactsListView.m b/Classes/ContactsListView.m index 0b79efeb2..c4ef44c9c 100644 --- a/Classes/ContactsListView.m +++ b/Classes/ContactsListView.m @@ -205,6 +205,8 @@ static UICompositeViewDescription *compositeDescription = nil; [NSString stringWithFormat:NSLocalizedString(@"Are you sure that you want to delete %d contacts?", nil), tableController.selectedItems.count]; [UIConfirmationDialog ShowWithMessage:msg + cancelMessage:nil + confirmMessage:nil onCancelClick:^() { [self onEditionChangeClick:nil]; } diff --git a/Classes/HistoryListView.m b/Classes/HistoryListView.m index 66870a1f8..2e848be6a 100644 --- a/Classes/HistoryListView.m +++ b/Classes/HistoryListView.m @@ -94,6 +94,8 @@ static UICompositeViewDescription *compositeDescription = nil; [NSString stringWithFormat:NSLocalizedString(@"Are you sure that you want to delete %d history?", nil), _tableController.selectedItems.count]; [UIConfirmationDialog ShowWithMessage:msg + cancelMessage:nil + confirmMessage:nil onCancelClick:^() { [self onEditionChangeClick:nil]; } diff --git a/Classes/LinphoneUI/Base.lproj/StatusBarView.xib b/Classes/LinphoneUI/Base.lproj/StatusBarView.xib index 9c1932967..8bcf7bea8 100644 --- a/Classes/LinphoneUI/Base.lproj/StatusBarView.xib +++ b/Classes/LinphoneUI/Base.lproj/StatusBarView.xib @@ -1,6 +1,7 @@ - + + @@ -86,6 +87,9 @@ + + + @@ -94,12 +98,12 @@ - - - - - - + + + + + + diff --git a/Classes/LinphoneUI/StatusBarView.h b/Classes/LinphoneUI/StatusBarView.h index 8a0961ae6..5fa0cdd4a 100644 --- a/Classes/LinphoneUI/StatusBarView.h +++ b/Classes/LinphoneUI/StatusBarView.h @@ -19,10 +19,10 @@ #import #import "TPMultiLayoutViewController.h" -#import "DTActionSheet.h" +#import "UIConfirmationDialog.h" -@interface StatusBarView : TPMultiLayoutViewController { - DTActionSheet *securitySheet; +@interface StatusBarView : TPMultiLayoutViewController { + UIConfirmationDialog *securityDialog; } @property(weak, nonatomic) IBOutlet UIButton *registrationState; @@ -35,5 +35,6 @@ - (IBAction)onSecurityClick:(id)sender; - (IBAction)onSideMenuClick:(id)sender; +- (IBAction)onRegistrationStateClick:(id)sender; @end diff --git a/Classes/LinphoneUI/StatusBarView.m b/Classes/LinphoneUI/StatusBarView.m index a9377c59d..668729b7a 100644 --- a/Classes/LinphoneUI/StatusBarView.m +++ b/Classes/LinphoneUI/StatusBarView.m @@ -139,6 +139,12 @@ // show voice mail only when there is no call [self updateUI:linphone_core_get_calls([LinphoneManager getLc]) != NULL]; [self updateVoicemail]; + + LinphoneCall *currentCall = linphone_core_get_current_call([LinphoneManager getLc]); + if (currentCall && !linphone_call_get_authentication_token_verified(currentCall) && + linphone_call_get_state(currentCall) == LinphoneCallStreamsRunning) { + [self onSecurityClick:nil]; + } } #pragma mark - @@ -242,8 +248,8 @@ const MSList *list = linphone_core_get_calls([LinphoneManager getLc]); if (list == NULL) { - if (securitySheet) { - [securitySheet dismissWithClickedButtonIndex:securitySheet.destructiveButtonIndex animated:TRUE]; + if (securityDialog) { + [securityDialog dismiss]; } } else { callSecurityButton.hidden = NO; @@ -291,29 +297,22 @@ linphone_call_params_get_media_encryption(linphone_call_get_current_params(call)); if (enc == LinphoneMediaEncryptionZRTP) { bool valid = linphone_call_get_authentication_token_verified(call); - NSString *message = nil; - if (valid) { - message = NSLocalizedString(@"Remove trust in the peer?", nil); - } else { - message = [NSString - stringWithFormat:NSLocalizedString(@"Confirm the following SAS with the peer:\n%s", nil), - linphone_call_get_authentication_token(call)]; - } - if (securitySheet == nil) { + NSString *message = + [NSString stringWithFormat:NSLocalizedString(@"Confirm the following SAS with peer:\n%s", nil), + linphone_call_get_authentication_token(call)]; + if (securityDialog == nil) { __block __strong StatusBarView *weakSelf = self; - securitySheet = [[DTActionSheet alloc] initWithTitle:message]; - [securitySheet setDelegate:self]; - [securitySheet addButtonWithTitle:NSLocalizedString(@"Ok", nil) - block:^() { - linphone_call_set_authentication_token_verified(call, !valid); - weakSelf->securitySheet = nil; - }]; - - [securitySheet addDestructiveButtonWithTitle:NSLocalizedString(@"Cancel", nil) - block:^() { - weakSelf->securitySheet = nil; - }]; - [securitySheet showInView:PhoneMainView.instance.view]; + [UIConfirmationDialog ShowWithMessage:message + cancelMessage:NSLocalizedString(@"DENY", nil) + confirmMessage:NSLocalizedString(@"ACCEPT", nil) + onCancelClick:^() { + linphone_call_set_authentication_token_verified(call, NO); + weakSelf->securityDialog = nil; + } + onConfirmationClick:^() { + linphone_call_set_authentication_token_verified(call, !valid); + weakSelf->securityDialog = nil; + }]; } } } @@ -329,8 +328,8 @@ } } -- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex { - securitySheet = nil; +- (IBAction)onRegistrationStateClick:(id)sender { + linphone_core_refresh_registers([LinphoneManager getLc]); } #pragma mark - TPMultiLayoutViewController Functions diff --git a/Classes/LinphoneUI/UIConfirmationDialog.h b/Classes/LinphoneUI/UIConfirmationDialog.h index 42729ab46..fe8abc591 100644 --- a/Classes/LinphoneUI/UIConfirmationDialog.h +++ b/Classes/LinphoneUI/UIConfirmationDialog.h @@ -11,12 +11,13 @@ typedef void (^UIConfirmationBlock)(void); @interface UIConfirmationDialog : UIViewController { - UIConfirmationBlock onCancelCb; UIConfirmationBlock onConfirmCb; } + (void)ShowWithMessage:(NSString *)message + cancelMessage:(NSString *)cancel + confirmMessage:(NSString *)confirm onCancelClick:(UIConfirmationBlock)onCancel onConfirmationClick:(UIConfirmationBlock)onConfirm; @@ -25,5 +26,5 @@ typedef void (^UIConfirmationBlock)(void); @property(weak, nonatomic) IBOutlet UILabel *titleLabel; - (IBAction)onCancelClick:(id)sender; - (IBAction)onConfirmationClick:(id)sender; - +- (void)dismiss; @end diff --git a/Classes/LinphoneUI/UIConfirmationDialog.m b/Classes/LinphoneUI/UIConfirmationDialog.m index 71c15395e..f61ffffef 100644 --- a/Classes/LinphoneUI/UIConfirmationDialog.m +++ b/Classes/LinphoneUI/UIConfirmationDialog.m @@ -12,6 +12,8 @@ @implementation UIConfirmationDialog + (void)ShowWithMessage:(NSString *)message + cancelMessage:(NSString *)cancel + confirmMessage:(NSString *)confirm onCancelClick:(UIConfirmationBlock)onCancel onConfirmationClick:(UIConfirmationBlock)onConfirm { UIConfirmationDialog *dialog = @@ -24,6 +26,13 @@ dialog->onConfirmCb = onConfirm; [dialog.titleLabel setText:message]; + if (cancel) { + [dialog.cancelButton setTitle:cancel forState:UIControlStateNormal]; + } + if (confirm) { + [dialog.confirmationButton setTitle:confirm forState:UIControlStateNormal]; + } + dialog.confirmationButton.layer.borderColor = [[UIColor colorWithPatternImage:[UIImage imageNamed:@"color_A.png"]] CGColor]; dialog.cancelButton.layer.borderColor = @@ -45,4 +54,8 @@ onConfirmCb(); } } + +- (void)dismiss { + [self onCancelClick:nil]; +} @end diff --git a/Classes/LinphoneUI/UIConfirmationDialog.xib b/Classes/LinphoneUI/UIConfirmationDialog.xib index da599a181..d0046cd28 100644 --- a/Classes/LinphoneUI/UIConfirmationDialog.xib +++ b/Classes/LinphoneUI/UIConfirmationDialog.xib @@ -1,6 +1,7 @@ - + + @@ -58,9 +59,9 @@ - - - + + + diff --git a/Classes/LinphoneUI/UIRoundBorderedButton.m b/Classes/LinphoneUI/UIRoundBorderedButton.m index f4ca6e8f5..bea257061 100644 --- a/Classes/LinphoneUI/UIRoundBorderedButton.m +++ b/Classes/LinphoneUI/UIRoundBorderedButton.m @@ -24,7 +24,10 @@ UIControlStateSelected | UIControlStateHighlighted, UIControlStateSelected | UIControlStateDisabled}; for (int i = 0; i < sizeof(states) / sizeof(UIControlState); i++) { - [self setTitle:[[self titleForState:states[i]] uppercaseString] forState:states[i]]; + if (![[self titleForState:UIControlStateNormal] + .uppercaseString isEqualToString:[self titleForState:states[i]]]) { + [self setTitle:[[self titleForState:states[i]] uppercaseString] forState:states[i]]; + } } return self; }