mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 22:52:26 +00:00
Password input now works with document controller
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
|
||||
- (void)showEntries;
|
||||
- (void)showMainWindow:(id)sender;
|
||||
- (void)showPasswordInput;
|
||||
- (void)performFindPanelAction:(id)sender;
|
||||
- (void)clearOutlineSelection:(id)sender;
|
||||
- (IBAction)editPassword:(id)sender;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -10,6 +10,4 @@
|
||||
|
||||
@interface MPPasswordInputController : MPViewController
|
||||
|
||||
@property (retain) NSURL *fileURL;
|
||||
|
||||
@end
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>647</string>
|
||||
<string>64C</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
<string key="NSClassName">NSApplication</string>
|
||||
</object>
|
||||
<object class="NSCustomView" id="1005">
|
||||
<reference key="NSNextResponder"/>
|
||||
<nil key="NSNextResponder"/>
|
||||
<int key="NSvFlags">268</int>
|
||||
<array class="NSMutableArray" key="NSSubviews">
|
||||
<object class="NSTextField" id="660673733">
|
||||
@@ -273,7 +273,6 @@
|
||||
</object>
|
||||
</array>
|
||||
<string key="NSFrameSize">{362, 268}</string>
|
||||
<reference key="NSSuperview"/>
|
||||
<reference key="NSNextKeyView" ref="204058255"/>
|
||||
<string key="NSClassName">NSView</string>
|
||||
</object>
|
||||
@@ -296,14 +295,6 @@
|
||||
</object>
|
||||
<int key="connectionID">196</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBActionConnection" key="connection">
|
||||
<string key="label">_open:</string>
|
||||
<reference key="source" ref="1001"/>
|
||||
<reference key="destination" ref="769513826"/>
|
||||
</object>
|
||||
<int key="connectionID">199</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">keyPathControl</string>
|
||||
@@ -344,6 +335,14 @@
|
||||
</object>
|
||||
<int key="connectionID">294</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBActionConnection" key="connection">
|
||||
<string key="label">_decrypt:</string>
|
||||
<reference key="source" ref="1001"/>
|
||||
<reference key="destination" ref="769513826"/>
|
||||
</object>
|
||||
<int key="connectionID">295</int>
|
||||
</object>
|
||||
</array>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<array key="orderedObjects">
|
||||
@@ -519,6 +518,38 @@
|
||||
<float key="scoringTypeFloat">40</float>
|
||||
<int key="contentType">3</int>
|
||||
</object>
|
||||
<object class="IBNSLayoutConstraint" id="912203343">
|
||||
<reference key="firstItem" ref="1005"/>
|
||||
<int key="firstAttribute">9</int>
|
||||
<int key="relation">0</int>
|
||||
<reference key="secondItem" ref="204058255"/>
|
||||
<int key="secondAttribute">9</int>
|
||||
<float key="multiplier">1</float>
|
||||
<object class="IBLayoutConstant" key="constant">
|
||||
<double key="value">0.0</double>
|
||||
</object>
|
||||
<float key="priority">1000</float>
|
||||
<reference key="containingView" ref="1005"/>
|
||||
<int key="scoringType">9</int>
|
||||
<float key="scoringTypeFloat">40</float>
|
||||
<int key="contentType">2</int>
|
||||
</object>
|
||||
<object class="IBNSLayoutConstraint" id="273022298">
|
||||
<reference key="firstItem" ref="204058255"/>
|
||||
<int key="firstAttribute">3</int>
|
||||
<int key="relation">1</int>
|
||||
<reference key="secondItem" ref="1005"/>
|
||||
<int key="secondAttribute">3</int>
|
||||
<float key="multiplier">1</float>
|
||||
<object class="IBNSLayoutSymbolicConstant" key="constant">
|
||||
<double key="value">20</double>
|
||||
</object>
|
||||
<float key="priority">1000</float>
|
||||
<reference key="containingView" ref="1005"/>
|
||||
<int key="scoringType">9</int>
|
||||
<float key="scoringTypeFloat">40</float>
|
||||
<int key="contentType">3</int>
|
||||
</object>
|
||||
<object class="IBNSLayoutConstraint" id="335819100">
|
||||
<reference key="firstItem" ref="333885704"/>
|
||||
<int key="firstAttribute">11</int>
|
||||
@@ -615,38 +646,6 @@
|
||||
<float key="scoringTypeFloat">24</float>
|
||||
<int key="contentType">2</int>
|
||||
</object>
|
||||
<object class="IBNSLayoutConstraint" id="912203343">
|
||||
<reference key="firstItem" ref="1005"/>
|
||||
<int key="firstAttribute">9</int>
|
||||
<int key="relation">0</int>
|
||||
<reference key="secondItem" ref="204058255"/>
|
||||
<int key="secondAttribute">9</int>
|
||||
<float key="multiplier">1</float>
|
||||
<object class="IBLayoutConstant" key="constant">
|
||||
<double key="value">0.0</double>
|
||||
</object>
|
||||
<float key="priority">1000</float>
|
||||
<reference key="containingView" ref="1005"/>
|
||||
<int key="scoringType">9</int>
|
||||
<float key="scoringTypeFloat">40</float>
|
||||
<int key="contentType">2</int>
|
||||
</object>
|
||||
<object class="IBNSLayoutConstraint" id="273022298">
|
||||
<reference key="firstItem" ref="204058255"/>
|
||||
<int key="firstAttribute">3</int>
|
||||
<int key="relation">1</int>
|
||||
<reference key="secondItem" ref="1005"/>
|
||||
<int key="secondAttribute">3</int>
|
||||
<float key="multiplier">1</float>
|
||||
<object class="IBNSLayoutSymbolicConstant" key="constant">
|
||||
<double key="value">20</double>
|
||||
</object>
|
||||
<float key="priority">1000</float>
|
||||
<reference key="containingView" ref="1005"/>
|
||||
<int key="scoringType">9</int>
|
||||
<float key="scoringTypeFloat">40</float>
|
||||
<int key="contentType">3</int>
|
||||
</object>
|
||||
<object class="IBNSLayoutConstraint" id="781301592">
|
||||
<reference key="firstItem" ref="662046682"/>
|
||||
<int key="firstAttribute">5</int>
|
||||
@@ -1005,14 +1004,14 @@
|
||||
<reference ref="975314961"/>
|
||||
<reference ref="97094814"/>
|
||||
<reference ref="781301592"/>
|
||||
<reference ref="273022298"/>
|
||||
<reference ref="912203343"/>
|
||||
<reference ref="151404172"/>
|
||||
<reference ref="649511608"/>
|
||||
<reference ref="207368608"/>
|
||||
<reference ref="679367678"/>
|
||||
<reference ref="640603863"/>
|
||||
<reference ref="335819100"/>
|
||||
<reference ref="273022298"/>
|
||||
<reference ref="912203343"/>
|
||||
<reference ref="862589174"/>
|
||||
<reference ref="1040549598"/>
|
||||
<reference ref="644024823"/>
|
||||
@@ -1084,7 +1083,7 @@
|
||||
<nil key="activeLocalization"/>
|
||||
<dictionary class="NSMutableDictionary" key="localizations"/>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">294</int>
|
||||
<int key="maxID">295</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes"/>
|
||||
<int key="IBDocument.localizationMode">0</int>
|
||||
|
||||
Reference in New Issue
Block a user