diff --git a/.gitmodules b/.gitmodules index c0b3e8588..fafbc42bc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -117,3 +117,6 @@ [submodule "submodules/externals/soci"] path = submodules/externals/soci url = git://git.linphone.org/soci +[submodule "submodules/externals/zxing-cpp"] + path = submodules/externals/zxing-cpp + url = git://git.linphone.org/zxing-cpp.git diff --git a/Classes/AssistantView.h b/Classes/AssistantView.h index 3184f85bc..815174526 100644 --- a/Classes/AssistantView.h +++ b/Classes/AssistantView.h @@ -21,6 +21,7 @@ #import "UICompositeView.h" #import "TPKeyboardAvoidingScrollView.h" #import "PhoneMainView.h" +#import @interface AssistantView : UIViewController { @@ -51,6 +52,7 @@ @property(nonatomic, strong) IBOutlet UIView *remoteProvisioningLoginView; @property(strong, nonatomic) IBOutlet UIView *remoteProvisioningView; @property (strong, nonatomic) IBOutlet UIView *createAccountActivateSMSView; +@property (strong, nonatomic) IBOutlet UIView *qrCodeView; @property(nonatomic, strong) IBOutlet UIImageView *welcomeLogoImage; @property(nonatomic, strong) IBOutlet UIButton *gotoCreateAccountButton; @@ -64,6 +66,7 @@ @property (weak, nonatomic) IBOutlet UILabel *activationSMSText; @property (weak, nonatomic) IBOutlet UILabel *accountLabel; +@property (weak, nonatomic) IBOutlet UITextField *urlLabel; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *createAccountNextButtonPositionConstraint; + (NSString *)StringForXMLRPCError:(const char *)err; @@ -92,6 +95,7 @@ - (IBAction)onLoginClick:(id)sender; - (IBAction)onRemoteProvisioningLoginClick:(id)sender; - (IBAction)onRemoteProvisioningDownloadClick:(id)sender; +- (IBAction)onLaunchQRCodeView:(id)sender; - (IBAction)onCreateAccountCheckActivatedClick:(id)sender; - (IBAction)onLinkAccountClick:(id)sender; diff --git a/Classes/AssistantView.m b/Classes/AssistantView.m index 8c8e238eb..e6adb5790 100644 --- a/Classes/AssistantView.m +++ b/Classes/AssistantView.m @@ -28,6 +28,7 @@ #import "PhoneMainView.h" #import "UIAssistantTextField.h" #import "UITextField+DoneButton.h" +#import "LinphoneAppDelegate.h" typedef enum _ViewElement { ViewElement_Username = 100, @@ -134,6 +135,8 @@ static UICompositeViewDescription *compositeDescription = nil; [_contentView setContentSize:frame.size]; [_contentView contentSizeToFit]; + + _qrCodeView.frame = [[UIScreen mainScreen] bounds]; } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { @@ -474,6 +477,13 @@ static UICompositeViewDescription *compositeDescription = nil; view = _linphoneLoginView; } } + + if (currentView == _qrCodeView) { + linphone_core_enable_video_preview(LC, FALSE); + linphone_core_enable_qrcode_video_preview(LC, FALSE); + LinphoneAppDelegate *delegate = (LinphoneAppDelegate *)UIApplication.sharedApplication.delegate; + delegate.onlyPortrait = FALSE; + } // Animation if (animation && ANIMATED) { @@ -1396,6 +1406,49 @@ void assistant_is_account_linked(LinphoneAccountCreator *creator, LinphoneAccoun }); } +- (IBAction)onLaunchQRCodeView:(id)sender { + [NSNotificationCenter.defaultCenter addObserver:self + selector:@selector(qrCodeFound:) + name:kLinphoneQRCodeFound + object:nil]; + LinphoneAppDelegate *delegate = (LinphoneAppDelegate *)UIApplication.sharedApplication.delegate; + delegate.onlyPortrait = TRUE; + NSNumber *value = [NSNumber numberWithInt:UIDeviceOrientationPortrait]; + [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; + //[UIViewController attemptRotationToDeviceOrientation]; + AVCaptureDevice *backCamera = [AVCaptureDevice defaultDeviceWithDeviceType:AVCaptureDeviceTypeBuiltInWideAngleCamera mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionBack]; + if (![[NSString stringWithUTF8String:linphone_core_get_video_device(LC)] containsString:[backCamera uniqueID]]) { + + bctbx_list_t *deviceList = linphone_core_get_video_devices_list(LC); + NSMutableArray *devices = [NSMutableArray array]; + + while (deviceList) { + char *data = deviceList->data; + [devices addObject:[NSString stringWithUTF8String:data]]; + deviceList = deviceList->next; + } + bctbx_list_free(deviceList); + + for (NSString *device in devices) { + if ([device containsString:backCamera.uniqueID]) { + linphone_core_set_video_device(LC, device.UTF8String); + } + } + } + + + linphone_core_set_native_preview_window_id(LC, (__bridge void *)(_qrCodeView)); + linphone_core_enable_video_preview(LC, TRUE); + linphone_core_enable_qrcode_video_preview(LC, TRUE); + + [NSNotificationCenter.defaultCenter addObserver:self + selector:@selector(qrCodeFound:) + name:kLinphoneQRCodeFound + object:nil]; + + [self changeView:_qrCodeView back:FALSE animation:TRUE]; +} + - (void)refreshYourUsername { UIAssistantTextField *username = [self findTextField:ViewElement_Username]; UIAssistantTextField *phone = [self findTextField:ViewElement_Phone]; @@ -1509,7 +1562,7 @@ void assistant_is_account_linked(LinphoneAccountCreator *creator, LinphoneAccoun - (IBAction)onBackClick:(id)sender { if ([historyViews count] > 0) { - if (currentView == _createAccountActivateSMSView || currentView == _createAccountActivateEmailView) { + if (currentView == _createAccountActivateSMSView || currentView == _createAccountActivateEmailView || currentView == _qrCodeView) { UIView *view = [historyViews lastObject]; [historyViews removeLastObject]; [self changeView:view back:TRUE animation:TRUE]; @@ -1532,7 +1585,7 @@ void assistant_is_account_linked(LinphoneAccountCreator *creator, LinphoneAccoun #pragma mark - select country delegate -- (void)didSelectCountry:(NSDictionary *)country{ +- (void)didSelectCountry:(NSDictionary *)country { UIRoundBorderedButton *phoneButton = [self findButton:ViewElement_PhoneButton]; [phoneButton setTitle:[country objectForKey:@"name"] forState:UIControlStateNormal]; UIAssistantTextField* countryCodeField = [self findTextField:ViewElement_PhoneCC]; @@ -1541,4 +1594,23 @@ void assistant_is_account_linked(LinphoneAccountCreator *creator, LinphoneAccoun [self shouldEnableNextButton]; } +-(void)qrCodeFound:(NSNotification *)notif { + if ([notif.userInfo count] == 0){ + return; + } + [NSNotificationCenter.defaultCenter removeObserver:self name:kLinphoneQRCodeFound object:nil]; + dispatch_async(dispatch_get_main_queue(), ^{ + self.urlLabel.text = [notif.userInfo objectForKey:@"qrcode"]; + }); + if ([historyViews count] > 0) { + if (currentView == _qrCodeView) { + UIView *view = [historyViews lastObject]; + [historyViews removeLastObject]; + [self changeView:view back:TRUE animation:TRUE]; + } else { + [self changeView:_welcomeView back:TRUE animation:TRUE]; + } + } +} + @end diff --git a/Classes/Base.lproj/AssistantViewScreens.xib b/Classes/Base.lproj/AssistantViewScreens.xib index 5d2c6dc86..6cfab070c 100644 --- a/Classes/Base.lproj/AssistantViewScreens.xib +++ b/Classes/Base.lproj/AssistantViewScreens.xib @@ -1,13 +1,12 @@ - + - + - @@ -31,9 +30,11 @@ + + @@ -338,7 +339,7 @@ - + @@ -359,7 +360,7 @@ - + @@ -389,7 +390,7 @@ - + @@ -418,7 +419,7 @@