Commit 61d41162 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

account creation: add backup view

Change-Id: I9d2ff356cd07069c0bb9d7ea0c83d4c8eb26e387
parent c7e68f3c
......@@ -184,6 +184,8 @@ SET(ringclient_CONTROLLERS
src/CallInConferenceVC.h
src/ConnectToAccManagerVC.mm
src/ConnectToAccManagerVC.h
src/AccountBackupVC.mm
src/AccountBackupVC.h
)
SET(ringclient_VIEWS
......@@ -286,6 +288,7 @@ SET(ringclient_XIBS
ChooseContactVC
CallInConferenceVC
ConnectToAccManagerVC
AccountBackupVC
)
# Icons
......
/*
* Copyright (C) 2019 Savoir-faire Linux Inc.
* Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
*
* 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 3 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import <Cocoa/Cocoa.h>
#import "LrcModelsProtocol.h"
#import <string>
@protocol AccountBackupDelegate <NSObject>
-(void)completedWithSuccess:(BOOL) success;
-(void)showView:(NSView*)view;
@end
@interface AccountBackupVC : NSViewController <LrcModelsProtocol>
@property (retain, nonatomic) id <AccountBackupDelegate> delegate;
@property std::string accountToBackup;
-(void)show;
@end
/*
* Copyright (C) 2019 Savoir-faire Linux Inc.
* Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
*
* 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 3 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import "AccountBackupVC.h"
#import "Constants.h"
//LRC
#import <api/lrc.h>
#import <api/newaccountmodel.h>
@interface AccountBackupVC () {
__unsafe_unretained IBOutlet NSView* initialView;
__unsafe_unretained IBOutlet NSView* errorView;
__unsafe_unretained IBOutlet NSButton* skipBackupButton;
}
@end
@implementation AccountBackupVC
@synthesize accountModel, accountToBackup;
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountmodel:(lrc::api::NewAccountModel*) accountModel {
if (self = [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
self.accountModel = accountModel;
}
return self;
}
-(void)show {
[self.view setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[initialView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[errorView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
BOOL skipBackup = [[NSUserDefaults standardUserDefaults] boolForKey: SkipBackUpPage];
[skipBackupButton setState: !skipBackup];
[self.delegate showView: initialView];
}
- (IBAction)skip:(id)sender
{
[self.delegate completedWithSuccess:YES];
}
- (IBAction)startAgain:(id)sender
{
[self.delegate showView: initialView];
}
- (IBAction)alwaysSkipBackup:(id)sender
{
[[NSUserDefaults standardUserDefaults] setBool:![sender state] forKey:SkipBackUpPage];
}
- (IBAction)exportAccount:(id)sender
{
NSSavePanel* filePicker = [NSSavePanel savePanel];
NSString* name = [@(self.accountToBackup.c_str()) stringByAppendingString: @".gz"];
[filePicker setNameFieldStringValue: name];
if ([filePicker runModal] != NSFileHandlingPanelOKButton) {
return;
}
NSString *password = @"";
const char* fullPath = [[filePicker URL] fileSystemRepresentation];
lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.accountToBackup);
if(accountProperties.archiveHasPassword) {
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"OK"];
[alert addButtonWithTitle:@"Cancel"];
[alert setMessageText: NSLocalizedString(@"Enter account password",
@"Backup enter password")];
NSTextField *input = [[NSSecureTextField alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)];
[alert setAccessoryView:input];
if ([alert runModal] != NSAlertFirstButtonReturn) {
return;
}
password = [input stringValue];
}
if (self.accountModel->exportToFile(self.accountToBackup, fullPath, [password UTF8String])) {
[self.delegate completedWithSuccess:YES];
} else {
[self.delegate showView: errorView];
}
}
@end
......@@ -39,4 +39,6 @@ namespace Preferences {
NSString * const DownloadFolder = @"download_folder";
}
NSString * const SkipBackUpPage = @"always_skip_backup_page";
const CGFloat MAX_IMAGE_SIZE = 1024;
......@@ -19,9 +19,10 @@
#import <Cocoa/Cocoa.h>
#import "LrcModelsProtocol.h"
#import <string>
@protocol RingWizardNewDelegate <NSObject>
- (void)didCreateAccountWithSuccess:(BOOL)success;
- (void)didCreateAccountWithSuccess:(BOOL)success accountId:(std::string)accountId;
- (void)showView:(NSView*)view;
@end
......
......@@ -120,6 +120,7 @@ NSInteger const ERROR_REPEAT_MISMATCH = -2;
- (void)prepareViewToShow {
[self.view setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[creationView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[loadingView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[passwordField setHidden: YES];
[repeatPasswordView setHidden: YES];
buttonTopConstraint.constant = 35;
......@@ -271,7 +272,7 @@ NSInteger const ERROR_REPEAT_MISMATCH = -2;
accountProperties.Ringtone.ringtonePath = [defaultRingtonePath() UTF8String];
self.accountModel->setAccountConfig(accountID, accountProperties);
[self registerDefaultPreferences];
[self.delegate didCreateAccountWithSuccess:YES];
[self.delegate didCreateAccountWithSuccess:YES accountId: accountToCreate];
});
//if account creation failed remove loading view
accountRemoved = QObject::connect(self.accountModel,
......@@ -282,7 +283,7 @@ NSInteger const ERROR_REPEAT_MISMATCH = -2;
}
QObject::disconnect(accountCreated);
QObject::disconnect(accountRemoved);
[self.delegate didCreateAccountWithSuccess:NO];
[self.delegate didCreateAccountWithSuccess:NO accountId: accountToCreate];
});
[self display:loadingView];
[progressBar startAnimation:nil];
......@@ -311,7 +312,7 @@ NSInteger const ERROR_REPEAT_MISMATCH = -2;
- (IBAction)cancel:(id)sender
{
[self.delegate didCreateAccountWithSuccess:NO];
[self.delegate didCreateAccountWithSuccess:NO accountId: accountToCreate];
}
#pragma mark - UserNameRegistration delegate methods
......
......@@ -24,10 +24,11 @@
#import "LrcModelsProtocol.h"
#import "AddSIPAccountVC.h"
#import "ConnectToAccManagerVC.h"
#import "AccountBackupVC.h"
@interface RingWizardWC : NSWindowController <NSWindowDelegate, NSPathControlDelegate,
NSOpenSavePanelDelegate, RingWizardChooseDelegate, RingWizardNewDelegate,
RingWizardLinkDelegate, AddSIPAccountDelegate, RingWizardAccManagerDelegate,
RingWizardLinkDelegate, AddSIPAccountDelegate, RingWizardAccManagerDelegate, AccountBackupDelegate,
LrcModelsProtocol>
- (void)showChooseWithCancelButton:(BOOL)showCancel;
- (void)showNewAccountVC;
......
......@@ -26,10 +26,6 @@
#import "Constants.h"
#import "views/NSImage+Extensions.h"
#import "views/NSColor+RingTheme.h"
#import "RingWizardNewAccountVC.h"
#import "RingWizardLinkAccountVC.h"
#import "RingWizardChooseVC.h"
#import "ConnectToAccManagerVC.h"
@interface RingWizardWC ()
......@@ -45,6 +41,7 @@
IBOutlet RingWizardChooseVC* chooseActiontWC;
IBOutlet AddSIPAccountVC* addSIPAccountVC;
IBOutlet ConnectToAccManagerVC* connectToAccManagerVC;
IBOutlet AccountBackupVC* accountBackupVC;
BOOL isCancelable;
}
......@@ -68,10 +65,12 @@
linkAccountWC = [[RingWizardLinkAccountVC alloc] initWithNibName:@"RingWizardLinkAccount" bundle:nil accountmodel:self.accountModel];
addSIPAccountVC = [[AddSIPAccountVC alloc] initWithNibName:@"AddSIPAccountVC" bundle:nil accountmodel:self.accountModel];
connectToAccManagerVC = [[ConnectToAccManagerVC alloc] initWithNibName:@"ConnectToAccManagerVC" bundle:nil accountmodel:self.accountModel];
accountBackupVC = [[AccountBackupVC alloc] initWithNibName:@"AccountBackupVC" bundle:nil accountmodel:self.accountModel];
[addSIPAccountVC setDelegate:self];
[chooseActiontWC setDelegate:self];
[linkAccountWC setDelegate:self];
[newAccountWC setDelegate:self];
[accountBackupVC setDelegate:self];
[connectToAccManagerVC setDelegate:self];
[self showChooseWithCancelButton:isCancelable];
}
......@@ -192,9 +191,14 @@
#pragma - WizardCreateAccountDelegate methods
- (void)didCreateAccountWithSuccess:(BOOL)success
- (void)didCreateAccountWithSuccess:(BOOL)success accountId:(std::string)accountId;
{
[self completedWithSuccess:success];
BOOL skipBackup = [[NSUserDefaults standardUserDefaults] boolForKey: SkipBackUpPage];
if (skipBackup || !success) {
[self completedWithSuccess:success];
return;
}
[self showBackUpAccount: accountId];
}
#pragma - WizardLinkAccountDelegate methods
......@@ -210,6 +214,16 @@
[self completedWithSuccess:success];
}
- (void)showBackUpAccount:(std::string)accountId{
[self.windowHeader setStringValue: NSLocalizedString(@"Backup your account",
@"Backup account")];
[ringImage setHidden: YES];
titleConstraint.constant = 0;
accountBackupVC.accountToBackup = accountId;
[self showView: accountBackupVC.view];
[accountBackupVC show];
}
-(void) completedWithSuccess:(BOOL) success {
if (success) {
[self.window close];
......
/* Class = "NSButtonCell"; title = "Skip"; ObjectID = "73h-fa-4yX"; */
"73h-fa-4yX.title" = "Skip";
/* Class = "NSTextFieldCell"; title = "An error occured during the backup. Please check your credentials."; ObjectID = "7lU-Qy-WOb"; */
"7lU-Qy-WOb.title" = "An error occured during the backup. Please check your credentials.";
/* Class = "NSButtonCell"; title = "Never show me this again"; ObjectID = "PVF-bb-Yoi"; */
"PVF-bb-Yoi.title" = "Never show me this again";
/* Class = "NSTextFieldCell"; title = "This account only exists on this device. If you lost your device or uninstall the application, your account will be deleted. You can backup your account now or later."; ObjectID = "SUG-lC-TDL"; */
"SUG-lC-TDL.title" = "This account only exists on this device. If you lost your device or uninstall the application, your account will be deleted. You can backup your account now or later.";
/* Class = "NSButtonCell"; title = "Export account"; ObjectID = "cod-s7-SPd"; */
"cod-s7-SPd.title" = "Export account";
/* Class = "NSButtonCell"; title = "OK"; ObjectID = "ruw-Kp-tCz"; */
"ruw-Kp-tCz.title" = "OK";
This diff is collapsed.
Binary files a/ui/Base.lproj/ConnectToAccManagerVC.strings and /dev/null differ
......@@ -219,3 +219,6 @@
/* Recording view explanation label */
"Could not record message during call" = "Could not record message during call";
/* Backup account */
"Backup your account" = "Backup your account";
Binary files a/ui/Base.lproj/RingWizardChoose.strings and /dev/null differ
Binary files a/ui/Base.lproj/RingWizardNewAccount.strings and /dev/null differ
......@@ -514,11 +514,11 @@ Gw
</popover>
<userDefaultsController representsSharedInstance="YES" id="JOT-gS-qe2"/>
<customView id="WWd-Hs-Pwi">
<rect key="frame" x="0.0" y="0.0" width="413" height="60"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<rect key="frame" x="0.0" y="0.0" width="400" height="150"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="1hK-Hw-cJh">
<rect key="frame" x="35" y="-12" width="344" height="17"/>
<rect key="frame" x="28" y="78" width="344" height="17"/>
<constraints>
<constraint firstAttribute="width" constant="340" id="tHE-Zh-IYn"/>
</constraints>
......@@ -529,7 +529,7 @@ Gw
</textFieldCell>
</textField>
<progressIndicator wantsLayer="YES" maxValue="100" indeterminate="YES" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="1rt-CR-Wpz">
<rect key="frame" x="159" y="13" width="96" height="32"/>
<rect key="frame" x="152" y="103" width="96" height="32"/>
<constraints>
<constraint firstAttribute="width" constant="96" id="g01-Ci-luV"/>
</constraints>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment