Commit 14366819 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Andreas Traczyk

fix: export account

This patch:
- use right account id for exported account
- fix path selection

Change-Id: I4df8b8ad8705cf5a27a91eadc3dc32e49f7260fa
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent fec65d67
......@@ -398,6 +398,7 @@ typedef NS_ENUM(NSInteger, TagViews) {
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];
}
......
......@@ -33,11 +33,12 @@
@end
@interface BackupAccountWC : AbstractLoadingWC <LrcModelsProtocol>
@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
......@@ -73,24 +73,17 @@
- (IBAction)completeAction:(id)sender
{
auto accounts = accountModel->getAccountList();
if(accounts.empty()) {
return;
}
auto selectedAccountID = accounts.at(0);
auto finalURL = [path.URL URLByAppendingPathComponent:[@"Account_" stringByAppendingString: @(selectedAccountID.c_str())]];
auto finalURL = [path.URL URLByAppendingPathComponent:[@"Account_" stringByAppendingString: @(std::string(self.selectedAccountID + ".gz").c_str())]];
[self showLoading];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if (self.accountModel->exportToFile(selectedAccountID, finalURL.path.UTF8String)) {
if (delegateRespondsTo.didCompleteExport) {
[((id<BackupAccountDelegate>)self.delegate) didCompleteExportWithPath:finalURL];
}
[self close];
[self.window.sheetParent endSheet: self.window];
} else {
[self showError];
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
......@@ -102,4 +95,24 @@
[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
{
NSLog(@"willDisplayOpenPanel");
[openPanel setAllowsMultipleSelection:NO];
[openPanel setResolvesAliases:YES];
[openPanel setDirectory:NSHomeDirectory()];
[openPanel setDelegate:self];
}
@end
......@@ -87,9 +87,13 @@ DQ
<rect key="frame" x="47" y="74" width="286" height="26"/>
<pathCell key="cell" selectable="YES" editable="YES" alignment="left" pathStyle="popUp" id="S8N-6a-Pll">
<font key="font" metaFont="system"/>
<url key="url" string="file:///Users/"/>
<url key="url" string="file:///Downloads"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</pathCell>
<connections>
<action selector="pathControlSingleClick:" target="-2" id="ATY-Ld-Sok"/>
<outlet property="delegate" destination="-2" id="m1j-G8-TUK"/>
</connections>
</pathControl>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="CR7-hP-0ow">
<rect key="frame" x="18" y="128" width="344" height="20"/>
......
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