From 070467d106c1916e1a27d2183e6bd08053c9e712 Mon Sep 17 00:00:00 2001 From: michael starke Date: Thu, 9 May 2013 14:41:09 +0200 Subject: [PATCH] Password input now works with document controller --- MacPass/MPDocument.m | 35 ++++------ MacPass/MPDocumentWindowController.h | 2 +- MacPass/MPDocumentWindowController.m | 17 ++--- MacPass/MPPasswordEditViewController.m | 13 ++-- MacPass/MPPasswordInputController.h | 2 - MacPass/MPPasswordInputController.m | 24 ++++--- MacPass/MacPass-Info.plist | 2 +- MacPass/PasswordInputView.xib | 89 +++++++++++++------------- 8 files changed, 80 insertions(+), 104 deletions(-) diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 0456ad1f..d9b8b21a 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -14,7 +14,10 @@ #import "KdbPassword.h" #import "MPDatabaseVersion.h" -@interface MPDocument () +@interface MPDocument () { +@private + BOOL _isDecrypted; +} @property (retain) KdbTree *tree; @property (retain) NSURL *file; @@ -34,6 +37,7 @@ - (id)initWithVersion:(MPDatabaseVersion)version { self = [super init]; if(self) { + _isDecrypted = NO; switch(version) { case MPDatabaseVersion3: self.tree = [[[Kdb3Tree alloc] init] autorelease]; @@ -81,29 +85,10 @@ - (BOOL)readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError { self.file = url; return YES; - // tell The window controller to display decrypt view -// - (void)openDocument:(id)sender { -// -// if(!self.passwordInputController) { -// self.passwordInputController = [[[MPPasswordInputController alloc] init] autorelease]; -// } -// -// NSOpenPanel *openPanel = [NSOpenPanel openPanel]; -// [openPanel setCanChooseDirectories:NO]; -// [openPanel setCanChooseFiles:YES]; -// [openPanel setCanCreateDirectories:NO]; -// [openPanel setAllowsMultipleSelection:NO]; -// [openPanel setAllowedFileTypes:@[ @"kdbx", @"kdb"]]; -// [openPanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result){ -// if(result == NSFileHandlingPanelOKButton) { -// NSURL *file = [[openPanel URLs] lastObject]; -// self.passwordInputController.fileURL = file; -// [self _setContentViewController:self.passwordInputController]; -// } -// }]; -// } -// - +} + +- (BOOL)isEntireFileLoaded { + return _isDecrypted; } - (BOOL)decryptWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL { @@ -123,6 +108,8 @@ else if( [self.tree isKindOfClass:[Kdb3Tree class]]) { self.version = MPDatabaseVersion3; } + _isDecrypted = YES; + return YES; } - (KdbPassword *)passwordHash { diff --git a/MacPass/MPDocumentWindowController.h b/MacPass/MPDocumentWindowController.h index 22ddd101..0b5787df 100644 --- a/MacPass/MPDocumentWindowController.h +++ b/MacPass/MPDocumentWindowController.h @@ -28,7 +28,7 @@ - (void)showEntries; -- (void)showMainWindow:(id)sender; +- (void)showPasswordInput; - (void)performFindPanelAction:(id)sender; - (void)clearOutlineSelection:(id)sender; - (IBAction)editPassword:(id)sender; diff --git a/MacPass/MPDocumentWindowController.m b/MacPass/MPDocumentWindowController.m index a2c1051d..deda99c6 100644 --- a/MacPass/MPDocumentWindowController.m +++ b/MacPass/MPDocumentWindowController.m @@ -221,9 +221,12 @@ return [self.toolbarDelegate validateToolbarItem:theItem]; } -- (void)showMainWindow:(id)sender { - [[self window] makeKeyAndOrderFront:sender]; - //[self showWindow:self.window]; + +- (void)showPasswordInput { + if(!self.passwordInputController) { + self.passwordInputController = [[[MPPasswordInputController alloc] init] autorelease]; + } + [self _setContentViewController:self.passwordInputController]; } - (void)clearOutlineSelection:(id)sender { @@ -268,12 +271,6 @@ } #pragma mark Notifications - -- (void)didOpenDocument:(NSNotification *)notification { - [self _updateWindowTitle]; - [self showEntries]; -} - - (void)showEntries { if(!self.entryViewController) { _entryViewController = [[MPEntryViewController alloc] init]; @@ -281,6 +278,4 @@ [self _setContentViewController:self.entryViewController]; } -- (IBAction)changedFileType:(id)sender { -} @end diff --git a/MacPass/MPPasswordEditViewController.m b/MacPass/MPPasswordEditViewController.m index c65b9fcb..73e0537d 100644 --- a/MacPass/MPPasswordEditViewController.m +++ b/MacPass/MPPasswordEditViewController.m @@ -9,8 +9,7 @@ #import "MPPasswordEditViewController.h" #import "MPKeyfilePathControlDelegate.h" #import "MPDocumentWindowController.h" -#import "MPDatabaseController.h" -#import "MPDatabaseDocument.h" +#import "MPDocument.h" @interface MPPasswordEditViewController () @property (assign) IBOutlet NSSecureTextField *passwordTextField; @@ -50,13 +49,13 @@ } - (IBAction)_change:(id)sender { - MPDatabaseDocument *database = [MPDatabaseController defaultController].database; - database.key = [self.keyfilePathControl URL]; - database.password = [self.passwordTextField stringValue]; - [database save]; + MPDocument *document = [[NSDocumentController sharedDocumentController] documentForWindow:[[self view] window]]; + if(document) { + document.key = [self.keyfilePathControl URL]; + document.password = [self.passwordTextField stringValue]; + } MPDocumentWindowController *mainWindowController = (MPDocumentWindowController *)[[[self view] window] windowController]; [mainWindowController showEntries]; - // save automatically? } - (IBAction)_cancel:(id)sender { diff --git a/MacPass/MPPasswordInputController.h b/MacPass/MPPasswordInputController.h index 9e15d17c..14608597 100644 --- a/MacPass/MPPasswordInputController.h +++ b/MacPass/MPPasswordInputController.h @@ -10,6 +10,4 @@ @interface MPPasswordInputController : MPViewController -@property (retain) NSURL *fileURL; - @end diff --git a/MacPass/MPPasswordInputController.m b/MacPass/MPPasswordInputController.m index 4f114fd7..8493ac71 100644 --- a/MacPass/MPPasswordInputController.m +++ b/MacPass/MPPasswordInputController.m @@ -7,7 +7,7 @@ // #import "MPPasswordInputController.h" -#import "MPDatabaseController.h" +#import "MPDocument.h" #import "MPKeyfilePathControlDelegate.h" @interface MPPasswordInputController () @@ -18,7 +18,7 @@ @property (assign) IBOutlet NSImageView *errorImageView; @property (assign) IBOutlet NSTextField *errorInfoTextField; -- (IBAction)_open:(id)sender; +- (IBAction)_decrypt:(id)sender; - (void)_showError; - (void)_reset; @@ -31,7 +31,6 @@ } - (void)dealloc { - [_fileURL release]; [_pathControlDelegate release]; [super dealloc]; } @@ -46,17 +45,16 @@ return self.passwordTextField; } - -- (IBAction)_open:(id)sender { - NSString *password = [self.passwordTextField stringValue]; - NSURL *keyfile = [self.keyPathControl URL]; - [self _reset]; - MPDatabaseDocument *document = [[MPDatabaseController defaultController] openDatabase:self.fileURL - password:password - keyfile:keyfile]; - if(!document) { - [self _showError]; +- (IBAction)_decrypt:(id)sender { + MPDocument *document = [[NSDocumentController sharedDocumentController] currentDocument]; + if(document) { + BOOL isOk = [document decryptWithPassword:[self.passwordTextField stringValue] keyFileURL:[self.keyPathControl URL]]; + if( isOk) { + [self _showError]; + } } + [self _reset]; + // show entries } - (void)_reset { diff --git a/MacPass/MacPass-Info.plist b/MacPass/MacPass-Info.plist index 1cf28993..eec3378b 100644 --- a/MacPass/MacPass-Info.plist +++ b/MacPass/MacPass-Info.plist @@ -46,7 +46,7 @@ CFBundleSignature ???? CFBundleVersion - 647 + 64C LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSHumanReadableCopyright diff --git a/MacPass/PasswordInputView.xib b/MacPass/PasswordInputView.xib index 001d2cd7..64de928b 100644 --- a/MacPass/PasswordInputView.xib +++ b/MacPass/PasswordInputView.xib @@ -43,7 +43,7 @@ NSApplication - + 268 @@ -273,7 +273,6 @@ {362, 268} - NSView @@ -296,14 +295,6 @@ 196 - - - _open: - - - - 199 - keyPathControl @@ -344,6 +335,14 @@ 294 + + + _decrypt: + + + + 295 + @@ -519,6 +518,38 @@ 40 3 + + + 9 + 0 + + 9 + 1 + + 0.0 + + 1000 + + 9 + 40 + 2 + + + + 3 + 1 + + 3 + 1 + + 20 + + 1000 + + 9 + 40 + 3 + 11 @@ -615,38 +646,6 @@ 24 2 - - - 9 - 0 - - 9 - 1 - - 0.0 - - 1000 - - 9 - 40 - 2 - - - - 3 - 1 - - 3 - 1 - - 20 - - 1000 - - 9 - 40 - 3 - 5 @@ -1005,14 +1004,14 @@ - - + + @@ -1084,7 +1083,7 @@ - 294 + 295 0