fix: export account
This patch:
- use right account id for exported account
- fix path selection
Change-Id: I4df8b8ad8705cf5a27a91eadc3dc32e49f7260fa
Reviewed-by: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
diff --git a/src/AccRingGeneralVC.mm b/src/AccRingGeneralVC.mm
index fb5bdc2..1486a83 100644
--- a/src/AccRingGeneralVC.mm
+++ b/src/AccRingGeneralVC.mm
@@ -398,6 +398,7 @@
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];
}
diff --git a/src/BackupAccountWC.h b/src/BackupAccountWC.h
index b1e1905..d68b42e 100644
--- a/src/BackupAccountWC.h
+++ b/src/BackupAccountWC.h
@@ -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
diff --git a/src/BackupAccountWC.mm b/src/BackupAccountWC.mm
index 803ab94..6729392 100644
--- a/src/BackupAccountWC.mm
+++ b/src/BackupAccountWC.mm
@@ -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