Commit 740a5969 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

ui: export account

Use save panel to save exported account, as suggested by apple review

Change-Id: I98544588357278da6ab480dfbf450fd5d9299f92
parent 7f61fa5f
......@@ -124,8 +124,6 @@ SET(ringclient_CONTROLLERS
src/AccAdvancedRingVC.h
src/CertificateWC.mm
src/CertificateWC.h
src/BackupAccountWC.mm
src/BackupAccountWC.h
src/RestoreAccountWC.mm
src/RestoreAccountWC.h
src/AudioPrefsVC.mm
......@@ -248,7 +246,6 @@ SET(ringclient_XIBS
PreferencesWindow
RingWizard
CertificateWindow
BackupAccountWindow
RestoreAccountWindow
ExportPasswordWindow
MigrateRingAccountsWindow
......
......@@ -20,12 +20,11 @@
#import <Cocoa/Cocoa.h>
#import "LrcModelsProtocol.h"
#import "BackupAccountWC.h"
#import "RegisterNameWC.h"
#import "AccountSettingsVC.h"
#import "PasswordChangeWC.h"
@interface AccRingGeneralVC : NSViewController <NSTextFieldDelegate, LrcModelsProtocol, BackupAccountDelegate, RegisterNameDelegate, AccountGeneralProtocol, NSTableViewDelegate, NSTableViewDataSource, PasswordChangeDelegate>
@interface AccRingGeneralVC : NSViewController <NSTextFieldDelegate, LrcModelsProtocol, RegisterNameDelegate, AccountGeneralProtocol, NSTableViewDelegate, NSTableViewDataSource, PasswordChangeDelegate>
- (void) setSelectedAccount:(std::string) account;
......
......@@ -36,7 +36,6 @@
#import <interfaces/pixmapmanipulatori.h>
#import "RegisterNameWC.h"
#import "BackupAccountWC.h"
#import "views/NSColor+RingTheme.h"
#import "views/NSImage+Extensions.h"
#import "views/HoverTableRowView.h"
......@@ -428,12 +427,18 @@ typedef NS_ENUM(NSInteger, TagViews) {
- (IBAction)exportAccount:(id)sender
{
BackupAccountWC* passwordWC = [[BackupAccountWC alloc] initWithNibName:@"BackupAccountWindow" bundle: nil accountmodel: self.accountModel];
passwordWC.delegate = self;
[passwordWC setAllowFileSelection:NO];
passwordWC.selectedAccountID = self.selectedAccountID;
accountModal = passwordWC;
[self.view.window beginSheet:passwordWC.window completionHandler:nil];
NSSavePanel* filePicker = [NSSavePanel savePanel];
NSString* name = [@(self.selectedAccountID.c_str()) stringByAppendingString: @".gz"];
[filePicker setNameFieldStringValue: name];
if ([filePicker runModal] == NSFileHandlingPanelOKButton) {
const char* fullPath = [[filePicker URL] fileSystemRepresentation];
if (self.accountModel->exportToFile(self.selectedAccountID, fullPath)) {
[self didCompleteExportWithPath:[filePicker URL]];
} else {
[self showAlertWithTitle: @"" andText: NSLocalizedString(@"An error occured during the backup", @"Backup error")];
}
}
}
- (IBAction)startNameRegistration:(id)sender
......
/*
* Copyright (C) 2016-2019 Savoir-faire Linux Inc.
* Author: Alexandre Lision <alexandre.lision@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 <QtCore/qdir.h>
#import "LoadingWCDelegate.h"
#import "AbstractLoadingWC.h"
#import "LrcModelsProtocol.h"
@protocol BackupAccountDelegate <LoadingWCDelegate>
@optional
-(void) didCompleteExportWithPath:(NSURL*) path;
@end
@interface BackupAccountWC : AbstractLoadingWC <LrcModelsProtocol, NSPathControlDelegate, NSOpenSavePanelDelegate>
/**
* Allow the NSPathControl of this window to select files or not
*/
@property (nonatomic) BOOL allowFileSelection;
@property std::string selectedAccountID;
@end
/*
* Copyright (C) 2016-2019 Savoir-faire Linux Inc.
* Author: Alexandre Lision <alexandre.lision@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 "BackupAccountWC.h"
//LRC
#import <api/lrc.h>
#import <api/newaccountmodel.h>
//Ring
#import "views/ITProgressIndicator.h"
@interface BackupAccountWC() <NSTextFieldDelegate> {
__unsafe_unretained IBOutlet NSPathControl* path;
__unsafe_unretained IBOutlet ITProgressIndicator* progressIndicator;
__unsafe_unretained IBOutlet NSButton* cancelButton;
}
@end
@implementation BackupAccountWC {
struct {
unsigned int didCompleteExport:1;
} delegateRespondsTo;
}
@synthesize accountModel;
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountmodel:(lrc::api::NewAccountModel*) accountModel
{
if (self = [self initWithWindowNibName:nibNameOrNil])
{
self.accountModel= accountModel;
}
return self;
}
- (void)windowDidLoad
{
[super windowDidLoad];
NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDownloadsDirectory, NSUserDomainMask, YES);
if(paths.count <= 0) {
return;
}
NSString * downloadPath = [paths objectAtIndex:0];
[path setURL: [NSURL URLWithString: downloadPath]];
}
- (void)setDelegate:(id <BackupAccountDelegate>)aDelegate
{
if (self.delegate != aDelegate) {
[super setDelegate: aDelegate];
delegateRespondsTo.didCompleteExport = [self.delegate respondsToSelector:@selector(didCompleteExportWithPath:)];
}
}
- (void) setAllowFileSelection:(BOOL) b
{
_allowFileSelection = b;
[path setAllowedTypes:_allowFileSelection ? nil : [NSArray arrayWithObject:@"public.folder"]];
}
- (IBAction)completeAction:(id)sender
{
auto finalURL = [path.URL URLByAppendingPathComponent:[@"Account_" stringByAppendingString: @(std::string(self.selectedAccountID + ".gz").c_str())]];
[self showLoading];
if (self.accountModel->exportToFile(self.selectedAccountID, finalURL.path.UTF8String)) {
if (delegateRespondsTo.didCompleteExport) {
[((id<BackupAccountDelegate>)self.delegate) didCompleteExportWithPath:finalURL];
}
[self close];
[self.window.sheetParent endSheet: self.window];
} else {
[self showError];
}
}
- (void)showLoading
{
[progressIndicator setNumberOfLines:30];
[progressIndicator setWidthOfLine:2];
[progressIndicator setLengthOfLine:5];
[progressIndicator setInnerMargin:20];
[super showLoading];
}
- (IBAction)pathControlSingleClick:(id)sender {
[path setURL:[[path clickedPathComponentCell] URL]];
}
#pragma mark - NSPathControlDelegate
- (void)pathControl:(NSPathControl *)pathControl willPopUpMenu:(NSMenu *)menu {
while ([[menu itemArray] count] >= 4) {
[menu removeItemAtIndex:3];
}
}
- (void)pathControl:(NSPathControl *)pathControl willDisplayOpenPanel:(NSOpenPanel *)openPanel
{
[openPanel setAllowsMultipleSelection:NO];
[openPanel setResolvesAliases:YES];
NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDownloadsDirectory, NSUserDomainMask, YES);
if(paths.count <= 0) {
return;
}
NSString * downloadPath = [paths objectAtIndex:0];
[openPanel setDirectoryURL:[NSURL URLWithString: downloadPath]];
[openPanel setDelegate:self];
}
@end
This diff is collapsed.
......@@ -195,3 +195,6 @@
/* Explanation label when user have just ID */
"This is your ID. \nCopy and share it with your friends!" = "This is your ID. \nCopy and share it with your friends!";
/* Backup error */
"An error occured during the backup" = "An error occured during the backup";
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