From 9ced3fce0b7e4dd443d7dcd8779a9e35dc02cf5a Mon Sep 17 00:00:00 2001 From: michael starke Date: Mon, 22 Jul 2013 00:02:14 +0200 Subject: [PATCH] Changed password/keyfile requesting. No password/keyfile is enforced until you want to save the file. --- MacPass.xcodeproj/project.pbxproj | 2 + MacPass/DatabaseSettingsWindow.xib | 40 ++++++++++---------- MacPass/MPDatabaseSettingsDelegate.h | 17 +++++++++ MacPass/MPDatabaseSettingsWindowController.h | 6 +++ MacPass/MPDatabaseSettingsWindowController.m | 31 +++++++++++++-- MacPass/MPDocumentWindowController.h | 3 +- MacPass/MPDocumentWindowController.m | 30 ++++++++++++--- 7 files changed, 97 insertions(+), 32 deletions(-) create mode 100644 MacPass/MPDatabaseSettingsDelegate.h diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 93c542e1..6a1a02fb 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -670,6 +670,7 @@ 4CD884B615BD47080042BBF8 /* DocumentWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DocumentWindow.xib; sourceTree = ""; }; 4CDB5C401794AA4F0017667E /* KPKTree+Serializing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KPKTree+Serializing.h"; sourceTree = ""; }; 4CDB5C411794AA4F0017667E /* KPKTree+Serializing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "KPKTree+Serializing.m"; sourceTree = ""; }; + 4CDE28D0179C8E010036C771 /* MPDatabaseSettingsDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPDatabaseSettingsDelegate.h; sourceTree = ""; }; 4CDF01A116D1B76700D0AC08 /* MPEntryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryViewController.h; sourceTree = ""; }; 4CDF01A216D1B76700D0AC08 /* MPEntryViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntryViewController.m; sourceTree = ""; }; 4CE298E91795FC2A00DF7BDB /* MPEntryMenuDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryMenuDelegate.h; sourceTree = ""; }; @@ -1352,6 +1353,7 @@ children = ( 4CF6C715176F5183007A811D /* MPServerRequestHandler.h */, 4CA0B30D15BCB6FD00654E32 /* MPSettingsTab.h */, + 4CDE28D0179C8E010036C771 /* MPDatabaseSettingsDelegate.h */, ); name = Protocolls; sourceTree = ""; diff --git a/MacPass/DatabaseSettingsWindow.xib b/MacPass/DatabaseSettingsWindow.xib index 429b538c..4765e9b7 100644 --- a/MacPass/DatabaseSettingsWindow.xib +++ b/MacPass/DatabaseSettingsWindow.xib @@ -71,7 +71,6 @@ {{473, 13}, {59, 32}} - _NS:9 YES @@ -100,7 +99,6 @@ {{13, 41}, {520, 246}} - _NS:9 @@ -212,7 +210,7 @@ 2322 {278, 121} - + _NS:13 @@ -328,7 +326,7 @@ {{136, 17}, {280, 123}} - + _NS:9 133138 @@ -1193,7 +1191,7 @@ - {{0, 0}, {2560, 1418}} + {{0, 0}, {1920, 1058}} {10000000000000, 10000000000000} YES @@ -1312,14 +1310,6 @@ 955 - - - close: - - - - 961 - save: @@ -1400,6 +1390,14 @@ 1262 + + + cancel: + + + + 1264 + @@ -4259,7 +4257,7 @@ - 1262 + 1264 @@ -4294,18 +4292,18 @@ MPDatabaseSettingsWindowController NSWindowController + id id - id id id - - clearKey: + + cancel: id - - close: + + clearKey: id @@ -4321,7 +4319,7 @@ NSButton NSTextView NSTextField - HNHRoundedTextField + HNHRoundendTextField NSButton NSButton NSTextField @@ -4354,7 +4352,7 @@ defaultUsernameTextField - HNHRoundedTextField + HNHRoundendTextField emptyRecycleBinOnQuitCheckButton diff --git a/MacPass/MPDatabaseSettingsDelegate.h b/MacPass/MPDatabaseSettingsDelegate.h new file mode 100644 index 00000000..9c917dce --- /dev/null +++ b/MacPass/MPDatabaseSettingsDelegate.h @@ -0,0 +1,17 @@ +// +// MPDatabaseSettingsDelegate.h +// MacPass +// +// Created by Michael Starke on 21.07.13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import + +@protocol MPDatabaseSettingsDelegate + +@optional +- (void)didCancelDatabaseSettings; +- (void)didSaveDatabaseSettings; + +@end diff --git a/MacPass/MPDatabaseSettingsWindowController.h b/MacPass/MPDatabaseSettingsWindowController.h index 0e502773..987a3163 100644 --- a/MacPass/MPDatabaseSettingsWindowController.h +++ b/MacPass/MPDatabaseSettingsWindowController.h @@ -7,6 +7,7 @@ // #import +#import "MPDatabaseSettingsDelegate.h" typedef NS_ENUM(NSUInteger, MPDatabaseSettingsTab) { MPDatabaseSettingsTabGeneral, @@ -22,6 +23,8 @@ typedef NS_ENUM(NSUInteger, MPDatabaseSettingsTab) { @interface MPDatabaseSettingsWindowController : NSWindowController +@property (nonatomic,weak) id delegate; + @property (weak) IBOutlet NSTabView *sectionTabView; @property (weak) IBOutlet NSButton *saveButton; @property (weak) IBOutlet NSButton *cancelButton; @@ -65,4 +68,7 @@ typedef NS_ENUM(NSUInteger, MPDatabaseSettingsTab) { - (void)update; + @end + + diff --git a/MacPass/MPDatabaseSettingsWindowController.m b/MacPass/MPDatabaseSettingsWindowController.m index 25ef4c9a..eeafd4d6 100644 --- a/MacPass/MPDatabaseSettingsWindowController.m +++ b/MacPass/MPDatabaseSettingsWindowController.m @@ -64,6 +64,17 @@ [self update]; } +- (void)setDelegate:(id)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 */ @@ -109,14 +120,26 @@ [defaults setBool:protectUsername forKey:kMPSettingsKeyLegacyHideUsername]; [defaults synchronize]; } - - /* Close to finish */ - [self close:nil]; + [self closeDidSave:YES]; } -- (IBAction)close:(id)sender { +- (IBAction)cancel:(id)sender { + [self closeDidSave:NO]; +} +- (void)closeDidSave:(BOOL)didSave { + /* Remove the window first */ [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]; + } + } } diff --git a/MacPass/MPDocumentWindowController.h b/MacPass/MPDocumentWindowController.h index c4d68702..1346e0a4 100644 --- a/MacPass/MPDocumentWindowController.h +++ b/MacPass/MPDocumentWindowController.h @@ -7,6 +7,7 @@ // #import +#import "MPDatabaseSettingsDelegate.h" @class MPViewController; @class MPEntryViewController; @@ -19,7 +20,7 @@ APPKIT_EXTERN NSString *const MPCurrentItemChangedNotification; -@interface MPDocumentWindowController : NSWindowController +@interface MPDocumentWindowController : NSWindowController @property (readonly, strong) MPPasswordInputController *passwordInputController; @property (readonly, strong) MPEntryViewController *entryViewController; diff --git a/MacPass/MPDocumentWindowController.m b/MacPass/MPDocumentWindowController.m index 05428af5..188539fc 100644 --- a/MacPass/MPDocumentWindowController.m +++ b/MacPass/MPDocumentWindowController.m @@ -24,7 +24,7 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur @interface MPDocumentWindowController () { @private id _firstResponder; - BOOL _requestPassword; // We did open a new document, request teh password + BOOL _saveAfterPasswordEdit; // Flag to indicat that the document needs to be saved after password edit did finish } @property (strong) IBOutlet NSSplitView *splitView; @@ -55,7 +55,7 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur _entryViewController = [[MPEntryViewController alloc] init]; _inspectorViewController = [[MPInspectorViewController alloc] init]; _currentItem = nil; - _requestPassword = NO; + _saveAfterPasswordEdit = NO; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_updateCurrentItem:) name:MPOutlineViewDidChangeGroupSelection object:_outlineViewController]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_updateCurrentItem:) name:MPDidChangeSelectedEntryNotification object:_entryViewController]; @@ -71,7 +71,7 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur - (void)windowDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didRevertDocument:) name:MPDocumentDidRevertNotifiation object:[self document]]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(editPassword:) name:MPDocumentRequestPasswordSaveNotification object:[self document]]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_setPasswordAndSave) name:MPDocumentRequestPasswordSaveNotification object:[self document]]; [_entryViewController setupNotifications:self]; [_inspectorViewController setupNotifications:self]; @@ -269,11 +269,11 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur } - (void)editPassword:(id)sender { - [self _showDatabaseSetting:MPDatabaseSettingsTabPassword]; + [self _showDatabaseSetting:MPDatabaseSettingsTabPassword saveDocument:NO]; } - (void)showDatabaseSettings:(id)sender { - [self _showDatabaseSetting:MPDatabaseSettingsTabGeneral]; + [self _showDatabaseSetting:MPDatabaseSettingsTabGeneral saveDocument:NO]; } - (IBAction)lock:(id)sender { @@ -405,11 +405,29 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur // } //} +#pragma mark MPDatabaseSettingsDelegate +- (void)didCancelDatabaseSettings { + _saveAfterPasswordEdit = NO; // Just Reset the flag +} + +- (void)didSaveDatabaseSettings { + if (_saveAfterPasswordEdit) { + _saveAfterPasswordEdit = NO; + } + [[self document] saveDocument:nil]; +} + #pragma mark Helper -- (void)_showDatabaseSetting:(MPDatabaseSettingsTab)tab { +- (void)_setPasswordAndSave { + _saveAfterPasswordEdit = YES; + [self editPassword:nil]; +} + +- (void)_showDatabaseSetting:(MPDatabaseSettingsTab)tab saveDocument:(BOOL)save{ if(!self.documentSettingsWindowController) { _documentSettingsWindowController = [[MPDatabaseSettingsWindowController alloc] initWithDocument:[self document]]; + [_documentSettingsWindowController setDelegate:self]; } [self.documentSettingsWindowController update]; [self.documentSettingsWindowController showSettingsTab:tab];