Changed password/keyfile requesting. No password/keyfile is enforced until you want to save the file.

This commit is contained in:
michael starke
2013-07-22 00:02:14 +02:00
parent acc800c9e6
commit 9ced3fce0b
7 changed files with 97 additions and 32 deletions

View File

@@ -670,6 +670,7 @@
4CD884B615BD47080042BBF8 /* DocumentWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DocumentWindow.xib; sourceTree = "<group>"; }; 4CD884B615BD47080042BBF8 /* DocumentWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DocumentWindow.xib; sourceTree = "<group>"; };
4CDB5C401794AA4F0017667E /* KPKTree+Serializing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KPKTree+Serializing.h"; sourceTree = "<group>"; }; 4CDB5C401794AA4F0017667E /* KPKTree+Serializing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KPKTree+Serializing.h"; sourceTree = "<group>"; };
4CDB5C411794AA4F0017667E /* KPKTree+Serializing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "KPKTree+Serializing.m"; sourceTree = "<group>"; }; 4CDB5C411794AA4F0017667E /* KPKTree+Serializing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "KPKTree+Serializing.m"; sourceTree = "<group>"; };
4CDE28D0179C8E010036C771 /* MPDatabaseSettingsDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPDatabaseSettingsDelegate.h; sourceTree = "<group>"; };
4CDF01A116D1B76700D0AC08 /* MPEntryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryViewController.h; sourceTree = "<group>"; }; 4CDF01A116D1B76700D0AC08 /* MPEntryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryViewController.h; sourceTree = "<group>"; };
4CDF01A216D1B76700D0AC08 /* MPEntryViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntryViewController.m; sourceTree = "<group>"; }; 4CDF01A216D1B76700D0AC08 /* MPEntryViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntryViewController.m; sourceTree = "<group>"; };
4CE298E91795FC2A00DF7BDB /* MPEntryMenuDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryMenuDelegate.h; sourceTree = "<group>"; }; 4CE298E91795FC2A00DF7BDB /* MPEntryMenuDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryMenuDelegate.h; sourceTree = "<group>"; };
@@ -1352,6 +1353,7 @@
children = ( children = (
4CF6C715176F5183007A811D /* MPServerRequestHandler.h */, 4CF6C715176F5183007A811D /* MPServerRequestHandler.h */,
4CA0B30D15BCB6FD00654E32 /* MPSettingsTab.h */, 4CA0B30D15BCB6FD00654E32 /* MPSettingsTab.h */,
4CDE28D0179C8E010036C771 /* MPDatabaseSettingsDelegate.h */,
); );
name = Protocolls; name = Protocolls;
sourceTree = "<group>"; sourceTree = "<group>";

View File

@@ -71,7 +71,6 @@
<string key="NSFrame">{{473, 13}, {59, 32}}</string> <string key="NSFrame">{{473, 13}, {59, 32}}</string>
<reference key="NSSuperview" ref="1006"/> <reference key="NSSuperview" ref="1006"/>
<reference key="NSWindow"/> <reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string> <string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool> <bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="800358251"> <object class="NSButtonCell" key="NSCell" id="800358251">
@@ -100,7 +99,6 @@
<string key="NSFrame">{{13, 41}, {520, 246}}</string> <string key="NSFrame">{{13, 41}, {520, 246}}</string>
<reference key="NSSuperview" ref="1006"/> <reference key="NSSuperview" ref="1006"/>
<reference key="NSWindow"/> <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="777708215"/>
<string key="NSReuseIdentifierKey">_NS:9</string> <string key="NSReuseIdentifierKey">_NS:9</string>
<array class="NSMutableArray" key="NSTabViewItems"> <array class="NSMutableArray" key="NSTabViewItems">
<object class="NSTabViewItem" id="993610707"> <object class="NSTabViewItem" id="993610707">
@@ -212,7 +210,7 @@
<int key="NSvFlags">2322</int> <int key="NSvFlags">2322</int>
<string key="NSFrameSize">{278, 121}</string> <string key="NSFrameSize">{278, 121}</string>
<reference key="NSSuperview" ref="401924003"/> <reference key="NSSuperview" ref="401924003"/>
<reference key="NSNextKeyView" ref="670917793"/> <reference key="NSNextKeyView" ref="580592620"/>
<string key="NSReuseIdentifierKey">_NS:13</string> <string key="NSReuseIdentifierKey">_NS:13</string>
<object class="NSTextContainer" key="NSTextContainer" id="411354001"> <object class="NSTextContainer" key="NSTextContainer" id="411354001">
<object class="NSLayoutManager" key="NSLayoutManager"> <object class="NSLayoutManager" key="NSLayoutManager">
@@ -328,7 +326,7 @@
</array> </array>
<string key="NSFrame">{{136, 17}, {280, 123}}</string> <string key="NSFrame">{{136, 17}, {280, 123}}</string>
<reference key="NSSuperview" ref="161117556"/> <reference key="NSSuperview" ref="161117556"/>
<reference key="NSNextKeyView" ref="580592620"/> <reference key="NSNextKeyView" ref="401924003"/>
<string key="NSReuseIdentifierKey">_NS:9</string> <string key="NSReuseIdentifierKey">_NS:9</string>
<int key="NSsFlags">133138</int> <int key="NSsFlags">133138</int>
<reference key="NSVScroller" ref="670917793"/> <reference key="NSVScroller" ref="670917793"/>
@@ -1193,7 +1191,7 @@
<reference key="NSWindow"/> <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="86072074"/> <reference key="NSNextKeyView" ref="86072074"/>
</object> </object>
<string key="NSScreenRect">{{0, 0}, {2560, 1418}}</string> <string key="NSScreenRect">{{0, 0}, {1920, 1058}}</string>
<string key="NSMaxSize">{10000000000000, 10000000000000}</string> <string key="NSMaxSize">{10000000000000, 10000000000000}</string>
<bool key="NSWindowIsRestorable">YES</bool> <bool key="NSWindowIsRestorable">YES</bool>
</object> </object>
@@ -1312,14 +1310,6 @@
</object> </object>
<int key="connectionID">955</int> <int key="connectionID">955</int>
</object> </object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">close:</string>
<reference key="source" ref="1001"/>
<reference key="destination" ref="115846238"/>
</object>
<int key="connectionID">961</int>
</object>
<object class="IBConnectionRecord"> <object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection"> <object class="IBActionConnection" key="connection">
<string key="label">save:</string> <string key="label">save:</string>
@@ -1400,6 +1390,14 @@
</object> </object>
<int key="connectionID">1262</int> <int key="connectionID">1262</int>
</object> </object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">cancel:</string>
<reference key="source" ref="1001"/>
<reference key="destination" ref="115846238"/>
</object>
<int key="connectionID">1264</int>
</object>
</array> </array>
<object class="IBMutableOrderedSet" key="objectRecords"> <object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects"> <array key="orderedObjects">
@@ -4259,7 +4257,7 @@
<nil key="activeLocalization"/> <nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/> <dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/> <nil key="sourceID"/>
<int key="maxID">1262</int> <int key="maxID">1264</int>
</object> </object>
<object class="IBClassDescriber" key="IBDocument.Classes"> <object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions"> <array class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -4294,18 +4292,18 @@
<string key="className">MPDatabaseSettingsWindowController</string> <string key="className">MPDatabaseSettingsWindowController</string>
<string key="superclassName">NSWindowController</string> <string key="superclassName">NSWindowController</string>
<dictionary class="NSMutableDictionary" key="actions"> <dictionary class="NSMutableDictionary" key="actions">
<string key="cancel:">id</string>
<string key="clearKey:">id</string> <string key="clearKey:">id</string>
<string key="close:">id</string>
<string key="generateKey:">id</string> <string key="generateKey:">id</string>
<string key="save:">id</string> <string key="save:">id</string>
</dictionary> </dictionary>
<dictionary class="NSMutableDictionary" key="actionInfosByName"> <dictionary class="NSMutableDictionary" key="actionInfosByName">
<object class="IBActionInfo" key="clearKey:"> <object class="IBActionInfo" key="cancel:">
<string key="name">clearKey:</string> <string key="name">cancel:</string>
<string key="candidateClassName">id</string> <string key="candidateClassName">id</string>
</object> </object>
<object class="IBActionInfo" key="close:"> <object class="IBActionInfo" key="clearKey:">
<string key="name">close:</string> <string key="name">clearKey:</string>
<string key="candidateClassName">id</string> <string key="candidateClassName">id</string>
</object> </object>
<object class="IBActionInfo" key="generateKey:"> <object class="IBActionInfo" key="generateKey:">
@@ -4321,7 +4319,7 @@
<string key="cancelButton">NSButton</string> <string key="cancelButton">NSButton</string>
<string key="databaseDescriptionTextView">NSTextView</string> <string key="databaseDescriptionTextView">NSTextView</string>
<string key="databaseNameTextField">NSTextField</string> <string key="databaseNameTextField">NSTextField</string>
<string key="defaultUsernameTextField">HNHRoundedTextField</string> <string key="defaultUsernameTextField">HNHRoundendTextField</string>
<string key="emptyRecycleBinOnQuitCheckButton">NSButton</string> <string key="emptyRecycleBinOnQuitCheckButton">NSButton</string>
<string key="enableRecycleBinCheckButton">NSButton</string> <string key="enableRecycleBinCheckButton">NSButton</string>
<string key="errorTextField">NSTextField</string> <string key="errorTextField">NSTextField</string>
@@ -4354,7 +4352,7 @@
</object> </object>
<object class="IBToOneOutletInfo" key="defaultUsernameTextField"> <object class="IBToOneOutletInfo" key="defaultUsernameTextField">
<string key="name">defaultUsernameTextField</string> <string key="name">defaultUsernameTextField</string>
<string key="candidateClassName">HNHRoundedTextField</string> <string key="candidateClassName">HNHRoundendTextField</string>
</object> </object>
<object class="IBToOneOutletInfo" key="emptyRecycleBinOnQuitCheckButton"> <object class="IBToOneOutletInfo" key="emptyRecycleBinOnQuitCheckButton">
<string key="name">emptyRecycleBinOnQuitCheckButton</string> <string key="name">emptyRecycleBinOnQuitCheckButton</string>

View File

@@ -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 <Foundation/Foundation.h>
@protocol MPDatabaseSettingsDelegate <NSObject>
@optional
- (void)didCancelDatabaseSettings;
- (void)didSaveDatabaseSettings;
@end

View File

@@ -7,6 +7,7 @@
// //
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import "MPDatabaseSettingsDelegate.h"
typedef NS_ENUM(NSUInteger, MPDatabaseSettingsTab) { typedef NS_ENUM(NSUInteger, MPDatabaseSettingsTab) {
MPDatabaseSettingsTabGeneral, MPDatabaseSettingsTabGeneral,
@@ -22,6 +23,8 @@ typedef NS_ENUM(NSUInteger, MPDatabaseSettingsTab) {
@interface MPDatabaseSettingsWindowController : NSWindowController <NSTextFieldDelegate, NSTabViewDelegate> @interface MPDatabaseSettingsWindowController : NSWindowController <NSTextFieldDelegate, NSTabViewDelegate>
@property (nonatomic,weak) id<MPDatabaseSettingsDelegate> delegate;
@property (weak) IBOutlet NSTabView *sectionTabView; @property (weak) IBOutlet NSTabView *sectionTabView;
@property (weak) IBOutlet NSButton *saveButton; @property (weak) IBOutlet NSButton *saveButton;
@property (weak) IBOutlet NSButton *cancelButton; @property (weak) IBOutlet NSButton *cancelButton;
@@ -65,4 +68,7 @@ typedef NS_ENUM(NSUInteger, MPDatabaseSettingsTab) {
- (void)update; - (void)update;
@end @end

View File

@@ -64,6 +64,17 @@
[self update]; [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 { - (IBAction)save:(id)sender {
/* Protection */ /* Protection */
@@ -109,14 +120,26 @@
[defaults setBool:protectUsername forKey:kMPSettingsKeyLegacyHideUsername]; [defaults setBool:protectUsername forKey:kMPSettingsKeyLegacyHideUsername];
[defaults synchronize]; [defaults synchronize];
} }
[self closeDidSave:YES];
/* Close to finish */
[self close:nil];
} }
- (IBAction)close:(id)sender { - (IBAction)cancel:(id)sender {
[self closeDidSave:NO];
}
- (void)closeDidSave:(BOOL)didSave {
/* Remove the window first */
[NSApp endSheet:[self window]]; [NSApp endSheet:[self window]];
[[self window] orderOut:nil]; [[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];
}
}
} }

View File

@@ -7,6 +7,7 @@
// //
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import "MPDatabaseSettingsDelegate.h"
@class MPViewController; @class MPViewController;
@class MPEntryViewController; @class MPEntryViewController;
@@ -19,7 +20,7 @@
APPKIT_EXTERN NSString *const MPCurrentItemChangedNotification; APPKIT_EXTERN NSString *const MPCurrentItemChangedNotification;
@interface MPDocumentWindowController : NSWindowController <NSWindowDelegate> @interface MPDocumentWindowController : NSWindowController <NSWindowDelegate, MPDatabaseSettingsDelegate>
@property (readonly, strong) MPPasswordInputController *passwordInputController; @property (readonly, strong) MPPasswordInputController *passwordInputController;
@property (readonly, strong) MPEntryViewController *entryViewController; @property (readonly, strong) MPEntryViewController *entryViewController;

View File

@@ -24,7 +24,7 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur
@interface MPDocumentWindowController () { @interface MPDocumentWindowController () {
@private @private
id _firstResponder; 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; @property (strong) IBOutlet NSSplitView *splitView;
@@ -55,7 +55,7 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur
_entryViewController = [[MPEntryViewController alloc] init]; _entryViewController = [[MPEntryViewController alloc] init];
_inspectorViewController = [[MPInspectorViewController alloc] init]; _inspectorViewController = [[MPInspectorViewController alloc] init];
_currentItem = nil; _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:MPOutlineViewDidChangeGroupSelection object:_outlineViewController];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_updateCurrentItem:) name:MPDidChangeSelectedEntryNotification object:_entryViewController]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_updateCurrentItem:) name:MPDidChangeSelectedEntryNotification object:_entryViewController];
@@ -71,7 +71,7 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur
- (void)windowDidLoad { - (void)windowDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didRevertDocument:) name:MPDocumentDidRevertNotifiation object:[self document]]; [[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]; [_entryViewController setupNotifications:self];
[_inspectorViewController setupNotifications:self]; [_inspectorViewController setupNotifications:self];
@@ -269,11 +269,11 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur
} }
- (void)editPassword:(id)sender { - (void)editPassword:(id)sender {
[self _showDatabaseSetting:MPDatabaseSettingsTabPassword]; [self _showDatabaseSetting:MPDatabaseSettingsTabPassword saveDocument:NO];
} }
- (void)showDatabaseSettings:(id)sender { - (void)showDatabaseSettings:(id)sender {
[self _showDatabaseSetting:MPDatabaseSettingsTabGeneral]; [self _showDatabaseSetting:MPDatabaseSettingsTabGeneral saveDocument:NO];
} }
- (IBAction)lock:(id)sender { - (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 #pragma mark Helper
- (void)_showDatabaseSetting:(MPDatabaseSettingsTab)tab { - (void)_setPasswordAndSave {
_saveAfterPasswordEdit = YES;
[self editPassword:nil];
}
- (void)_showDatabaseSetting:(MPDatabaseSettingsTab)tab saveDocument:(BOOL)save{
if(!self.documentSettingsWindowController) { if(!self.documentSettingsWindowController) {
_documentSettingsWindowController = [[MPDatabaseSettingsWindowController alloc] initWithDocument:[self document]]; _documentSettingsWindowController = [[MPDatabaseSettingsWindowController alloc] initWithDocument:[self document]];
[_documentSettingsWindowController setDelegate:self];
} }
[self.documentSettingsWindowController update]; [self.documentSettingsWindowController update];
[self.documentSettingsWindowController showSettingsTab:tab]; [self.documentSettingsWindowController showSettingsTab:tab];