mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 17:32:17 +00:00
Restrucutred Settings and extracts Password edit
Introduced custom save palen accessory view to enable save in different formats (unfunctional for now) Started reworking drag and drop of entries and groups
This commit is contained in:
@@ -26,26 +26,21 @@
|
||||
MPDocument *_document;
|
||||
NSString *_missingFeature;
|
||||
}
|
||||
|
||||
@property (nonatomic,assign) BOOL trashEnabled;
|
||||
@property (nonatomic,assign) BOOL showPassword;
|
||||
@property (nonatomic,assign) BOOL hasValidPasswordOrKey;
|
||||
@property (nonatomic,weak) NSURL *keyURL;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPDatabaseSettingsWindowController
|
||||
|
||||
- (id)init {
|
||||
return [self initWithDocument:nil];
|
||||
self = [self initWithDocument:nil];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithDocument:(MPDocument *)document {
|
||||
self = [super initWithWindowNibName:@"DatabaseSettingsWindow"];
|
||||
if(self) {
|
||||
_document = document;
|
||||
_showPassword = NO;
|
||||
_hasValidPasswordOrKey = NO;
|
||||
_missingFeature = NSLocalizedString(@"KDBX_ONLY_FEATURE", "Feature only available in kdbx databases");
|
||||
}
|
||||
return self;
|
||||
@@ -55,32 +50,11 @@
|
||||
[super windowDidLoad];
|
||||
|
||||
NSAssert(_document != nil, @"Document needs to be present");
|
||||
|
||||
[self.saveButton bind:NSEnabledBinding toObject:self withKeyPath:@"hasValidPasswordOrKey" options:nil];
|
||||
|
||||
[self.sectionTabView setDelegate:self];
|
||||
|
||||
|
||||
[self update];
|
||||
}
|
||||
|
||||
- (void)setDelegate:(id<MPDatabaseSettingsDelegate>)delegate {
|
||||
if(_delegate != delegate) {
|
||||
if([delegate conformsToProtocol:@protocol(MPDatabaseSettingsDelegate)]) {
|
||||
_delegate = delegate;
|
||||
}
|
||||
else{
|
||||
NSAssert(NO, @"Delegate needs to conform to MPDatabaseSettingsDelegate protocoll");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)save:(id)sender {
|
||||
|
||||
/* Protection */
|
||||
_document.password = [self.passwordTextField stringValue];
|
||||
_document.key = [self.keyfilePathControl URL];
|
||||
|
||||
/* General */
|
||||
_document.treeV4.databaseDescription = [self.databaseDescriptionTextView string];
|
||||
_document.treeV4.databaseName = [self.databaseNameTextField stringValue];
|
||||
@@ -121,37 +95,25 @@
|
||||
[defaults setBool:protectUsername forKey:kMPSettingsKeyLegacyHideUsername];
|
||||
[defaults synchronize];
|
||||
}
|
||||
[self closeDidSave:YES];
|
||||
[self close:nil];
|
||||
}
|
||||
|
||||
- (IBAction)cancel:(id)sender {
|
||||
[self closeDidSave:NO];
|
||||
}
|
||||
- (void)closeDidSave:(BOOL)didSave {
|
||||
/* Remove the window first */
|
||||
- (IBAction)close:(id)sender {
|
||||
[NSApp endSheet:[self window]];
|
||||
[[self window] orderOut:nil];
|
||||
|
||||
/* Then notify the delegate */
|
||||
if(self.delegate) {
|
||||
if(didSave && [self.delegate respondsToSelector:@selector(didSaveDatabaseSettings)]) {
|
||||
[self.delegate didSaveDatabaseSettings];
|
||||
}
|
||||
else if(!didSave && [self.delegate respondsToSelector:@selector(didCancelDatabaseSettings)]) {
|
||||
[self.delegate didCancelDatabaseSettings];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)update {
|
||||
- (void)updateView {
|
||||
if(!self.isDirty) {
|
||||
return;
|
||||
}
|
||||
/* Update all stuff that might have changed */
|
||||
Kdb4Tree *tree = _document.treeV4;
|
||||
[self _setupPasswordTab:tree];
|
||||
[self _setupDatabase:tree];
|
||||
[self _setupProtectionTab:tree];
|
||||
[self _setupAdvancedTab:tree];
|
||||
[self _setupTemplatesTab:tree];
|
||||
self.isDirty = NO;
|
||||
}
|
||||
|
||||
- (void)showSettingsTab:(MPDatabaseSettingsTab)tab {
|
||||
@@ -162,47 +124,18 @@
|
||||
if(![self window]) {
|
||||
return;
|
||||
}
|
||||
self.showPassword = NO;
|
||||
NSTabViewItem *tabViewItem = [self.sectionTabView tabViewItemAtIndex:tab];
|
||||
BOOL canSelectTab = [self tabView:self.sectionTabView shouldSelectTabViewItem:tabViewItem];
|
||||
if(!canSelectTab) {
|
||||
[self.sectionTabView selectTabViewItemAtIndex:MPDatabaseSettingsTabPassword];
|
||||
[self.sectionTabView selectTabViewItemAtIndex:MPDatabaseSettingsTabTemplates];
|
||||
}
|
||||
[self.sectionTabView selectTabViewItemAtIndex:tab];
|
||||
}
|
||||
|
||||
- (void)setShowPassword:(BOOL)showPassword {
|
||||
if(_showPassword != showPassword) {
|
||||
_showPassword = showPassword;
|
||||
|
||||
[self.passwordRepeatTextField setStringValue:@""];
|
||||
[self _verifyPasswordAndKey];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setKeyURL:(NSURL *)keyURL {
|
||||
_keyURL = keyURL;
|
||||
[self _verifyPasswordAndKey];
|
||||
}
|
||||
|
||||
#pragma mark Actions
|
||||
- (IBAction)clearKey:(id)sender {
|
||||
self.keyURL = nil;
|
||||
}
|
||||
|
||||
- (IBAction)generateKey:(id)sender {
|
||||
}
|
||||
|
||||
#pragma mark NSTextFieldDelegate
|
||||
- (void)controlTextDidChange:(NSNotification *)obj {
|
||||
[self _verifyPasswordAndKey];
|
||||
}
|
||||
|
||||
#pragma mark NSTableViewDelegate
|
||||
- (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem {
|
||||
NSUInteger index = [tabView indexOfTabViewItem:tabViewItem];
|
||||
switch ((MPDatabaseSettingsTab)index) {
|
||||
case MPDatabaseSettingsTabPassword:
|
||||
case MPDatabaseSettingsTabDisplay:
|
||||
return YES;
|
||||
|
||||
@@ -217,40 +150,6 @@
|
||||
}
|
||||
|
||||
#pragma mark Private Helper
|
||||
- (void)_verifyPasswordAndKey {
|
||||
NSString *password = [self.passwordTextField stringValue];
|
||||
NSString *repeat = [self.passwordRepeatTextField stringValue];
|
||||
BOOL hasKey = (self.keyURL != nil);
|
||||
BOOL keyOk = YES;
|
||||
if(hasKey) {
|
||||
keyOk = [self.keyURL checkResourceIsReachableAndReturnError:nil];
|
||||
}
|
||||
BOOL hasPassword = ![NSString isEmptyString:password];
|
||||
BOOL passwordOk = YES;
|
||||
if(hasPassword ) {
|
||||
passwordOk = [password isEqualToString:repeat] || self.showPassword;
|
||||
}
|
||||
BOOL hasPasswordOrKey = (hasKey || hasPassword);
|
||||
keyOk = hasKey ? keyOk : YES;
|
||||
passwordOk = hasPassword ? passwordOk : YES;
|
||||
self.hasValidPasswordOrKey = hasPasswordOrKey && passwordOk && keyOk;
|
||||
|
||||
if(!hasPasswordOrKey) {
|
||||
[self.errorTextField setStringValue:NSLocalizedString(@"ERROR_NO_PASSWORD_OR_KEYFILE", "Missing Key or Password")];
|
||||
return; // alldone
|
||||
}
|
||||
if(!passwordOk && !keyOk ) {
|
||||
[self.errorTextField setStringValue:NSLocalizedString(@"ERROR_PASSWORD_MISSMATCH_INVALID_KEYFILE", "Passwords do not match, keyfile is invalid")];
|
||||
}
|
||||
else if(!passwordOk) {
|
||||
[self.errorTextField setStringValue:NSLocalizedString(@"ERROR_PASSWORD_MISSMATCH", "Passwords do not match")];
|
||||
}
|
||||
else {
|
||||
[self.errorTextField setStringValue:NSLocalizedString(@"ERROR_INVALID_KEYFILE", "Keyfile not valid")];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void)_setupDatabase:(Kdb4Tree *)tree {
|
||||
BOOL isKdbx = (nil != tree);
|
||||
[self.databaseDescriptionTextView setEditable:isKdbx];
|
||||
@@ -296,25 +195,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_setupPasswordTab:(Kdb4Tree *)tree {
|
||||
[self.passwordTextField setStringValue:_document.password ? _document.password : @""];
|
||||
[self.passwordRepeatTextField setStringValue:[self.passwordTextField stringValue]];
|
||||
self.keyURL = _document.key;
|
||||
|
||||
NSDictionary *negateOption = @{ NSValueTransformerNameBindingOption : NSNegateBooleanTransformerName };
|
||||
[self.passwordTextField bind:@"showPassword" toObject:self withKeyPath:@"showPassword" options:nil];
|
||||
[self.togglePasswordButton bind:NSValueBinding toObject:self withKeyPath:@"showPassword" options:nil];
|
||||
[self.passwordRepeatTextField bind:NSEnabledBinding toObject:self withKeyPath:@"showPassword" options:negateOption];
|
||||
[self.errorTextField bind:NSHiddenBinding toObject:self withKeyPath:@"hasValidPasswordOrKey" options:nil];
|
||||
[self.keyfilePathControl bind:NSValueBinding toObject:self withKeyPath:@"keyURL" options:nil];
|
||||
|
||||
[self.passwordRepeatTextField setDelegate:self];
|
||||
[self.passwordTextField setDelegate:self];
|
||||
|
||||
/* Manually initate the first check */
|
||||
[self _verifyPasswordAndKey];
|
||||
}
|
||||
|
||||
- (void)_setupTemplatesTab:(Kdb4Tree *)tree {
|
||||
if(tree) {
|
||||
[self.defaultUsernameTextField setStringValue:tree.defaultUserName];
|
||||
@@ -344,10 +224,6 @@
|
||||
[[self window] makeFirstResponder:self.databaseNameTextField];
|
||||
break;
|
||||
|
||||
case MPDatabaseSettingsTabPassword:
|
||||
[[self window] makeFirstResponder:self.passwordTextField];
|
||||
break;
|
||||
|
||||
case MPDatabaseSettingsTabTemplates:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user