mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 21:42:32 +00:00
Merge pull request #1 from nmadura/master
Implemented beginnings of new file creation
This commit is contained in:
@@ -117,6 +117,8 @@
|
||||
4CE8246F16E2E93400573141 /* MPOverlayWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8246E16E2E93400573141 /* MPOverlayWindowController.m */; };
|
||||
4CE8247516E2F2B900573141 /* MPOverlayView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8247416E2F2B900573141 /* MPOverlayView.m */; };
|
||||
4CFC53BF16E94729007396BE /* MPShadowBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CFC53BE16E94729007396BE /* MPShadowBox.m */; };
|
||||
6E71971217203FB700E4C5FC /* MPCreationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E71971017203FB600E4C5FC /* MPCreationViewController.m */; };
|
||||
6E71971317203FB700E4C5FC /* CreationView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6E71971117203FB600E4C5FC /* CreationView.xib */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
@@ -320,6 +322,10 @@
|
||||
4CE8247416E2F2B900573141 /* MPOverlayView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOverlayView.m; sourceTree = "<group>"; };
|
||||
4CFC53BD16E94729007396BE /* MPShadowBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPShadowBox.h; sourceTree = "<group>"; };
|
||||
4CFC53BE16E94729007396BE /* MPShadowBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPShadowBox.m; sourceTree = "<group>"; };
|
||||
6E71970F17203FB600E4C5FC /* MPCreationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPCreationViewController.h; sourceTree = "<group>"; };
|
||||
6E71971017203FB600E4C5FC /* MPCreationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPCreationViewController.m; sourceTree = "<group>"; };
|
||||
6E71971117203FB600E4C5FC /* CreationView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CreationView.xib; sourceTree = "<group>"; };
|
||||
6E719715172058BA00E4C5FC /* MPDatabaseVersion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPDatabaseVersion.h; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -340,6 +346,7 @@
|
||||
4C06398C15B980480004DE27 /* Views */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
6E71971117203FB600E4C5FC /* CreationView.xib */,
|
||||
4C25D58616CF0FAA00F6806C /* EntryView.xib */,
|
||||
4CA0B2EF15BCADC800654E32 /* GeneralSettings.xib */,
|
||||
4C77E37B15B84A240093A587 /* MainMenu.xib */,
|
||||
@@ -415,6 +422,7 @@
|
||||
4C37A83F15B8B474005EF8EE /* MPOutlineDataSource.m */,
|
||||
4CBA981615BA0DB600721965 /* MPDatabaseDocument.h */,
|
||||
4CBA981715BA0DB600721965 /* MPDatabaseDocument.m */,
|
||||
6E719715172058BA00E4C5FC /* MPDatabaseVersion.h */,
|
||||
);
|
||||
name = Model;
|
||||
sourceTree = "<group>";
|
||||
@@ -643,6 +651,8 @@
|
||||
4C40AC5B170782730073D1C3 /* MPAbstractSettingsViewController.m */,
|
||||
4C5A11FB1708DE8700223D8A /* MPPasswordCreatorViewController.h */,
|
||||
4C5A11FC1708DE8700223D8A /* MPPasswordCreatorViewController.m */,
|
||||
6E71970F17203FB600E4C5FC /* MPCreationViewController.h */,
|
||||
6E71971017203FB600E4C5FC /* MPCreationViewController.m */,
|
||||
);
|
||||
name = "View Controller";
|
||||
sourceTree = "<group>";
|
||||
@@ -841,6 +851,7 @@
|
||||
4C888C9016EB6C91003D34A1 /* Localizable.strings in Resources */,
|
||||
4CE39AC116ECE359000FE29D /* IconSelection.xib in Resources */,
|
||||
4C5A11FF1708DE8800223D8A /* PasswordCreatorView.xib in Resources */,
|
||||
6E71971317203FB700E4C5FC /* CreationView.xib in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -946,6 +957,7 @@
|
||||
4C46B88B1706D16E0046109A /* NSData+MPRandomBytes.m in Sources */,
|
||||
4C40AC5C170782730073D1C3 /* MPAbstractSettingsViewController.m in Sources */,
|
||||
4C5A11FE1708DE8700223D8A /* MPPasswordCreatorViewController.m in Sources */,
|
||||
6E71971217203FB700E4C5FC /* MPCreationViewController.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
1248
MacPass/CreationView.xib
Normal file
1248
MacPass/CreationView.xib
Normal file
File diff suppressed because it is too large
Load Diff
15
MacPass/MPCreationViewController.h
Normal file
15
MacPass/MPCreationViewController.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// MPCreationViewController.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Nathaniel Madura on 18/04/13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPViewController.h"
|
||||
|
||||
@interface MPCreationViewController : MPViewController
|
||||
|
||||
@property (retain) NSURL *fileURL;
|
||||
|
||||
@end
|
||||
76
MacPass/MPCreationViewController.m
Normal file
76
MacPass/MPCreationViewController.m
Normal file
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// MPCreationViewController.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Nathaniel Madura on 18/04/13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPCreationViewController.h"
|
||||
#import "MPKeyfilePathControlDelegate.h"
|
||||
#import "MPDatabaseController.h"
|
||||
#import "MPDatabaseDocument.h"
|
||||
|
||||
@interface MPCreationViewController ()
|
||||
|
||||
@property (assign) IBOutlet NSSecureTextField *passwordTextField;
|
||||
@property (assign) IBOutlet NSSecureTextField *validatePasswordTextField;
|
||||
@property (assign) IBOutlet NSPathControl *keyPathControl;
|
||||
@property (retain) MPKeyfilePathControlDelegate *pathControlDelegate;
|
||||
@property (assign) IBOutlet NSTextField *errorInfoTextField;
|
||||
|
||||
- (IBAction)_new:(id)sender;
|
||||
- (void)_showError;
|
||||
- (void)_reset;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPCreationViewController
|
||||
|
||||
- (id)init {
|
||||
return [[MPCreationViewController alloc] initWithNibName:@"CreationView" bundle:nil];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_fileURL release];
|
||||
[_pathControlDelegate release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)didLoadView {
|
||||
[self.keyPathControl setDelegate:self.pathControlDelegate];
|
||||
[self _reset];
|
||||
}
|
||||
|
||||
- (NSResponder *)reconmendedFirstResponder {
|
||||
return self.passwordTextField;
|
||||
}
|
||||
|
||||
- (IBAction)_new:(id)sender {
|
||||
NSString *password = self.passwordTextField.stringValue;
|
||||
NSURL *keyfile = [self.keyPathControl URL];
|
||||
if ([password compare:self.validatePasswordTextField.stringValue] != NSOrderedSame)
|
||||
{
|
||||
[self.errorInfoTextField setStringValue:@"Passwords do not match"];
|
||||
[self.errorInfoTextField setHidden:NO];
|
||||
}
|
||||
[self _reset];
|
||||
|
||||
[[MPDatabaseController defaultController] newDatabaseAtURL:self.fileURL
|
||||
databaseVersion:MPDatabaseVersion4
|
||||
password:password
|
||||
keyfile:keyfile];
|
||||
}
|
||||
|
||||
- (void)_reset {
|
||||
[self.passwordTextField setStringValue:@""];
|
||||
[self.validatePasswordTextField setStringValue:@""];
|
||||
[self.keyPathControl setURL:nil];
|
||||
[self.errorInfoTextField setHidden:YES];
|
||||
}
|
||||
|
||||
- (void)_showError {
|
||||
[self.errorInfoTextField setHidden:NO];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "MPDatabaseVersion.h"
|
||||
|
||||
/*
|
||||
Notification is posted, when a database is loaded
|
||||
@@ -30,7 +31,8 @@ APPKIT_EXTERN NSString *const MPDatabaseControllerDatabaseKey;
|
||||
+ (MPDatabaseController *)defaultController;
|
||||
+ (BOOL)hasOpenDatabase;
|
||||
|
||||
//- (MPDatabaseDocument *)createDatabase:(MPDatabaseVersion )version password:(NSString *)password keyfile:(NSURL *)key;
|
||||
- (MPDatabaseDocument *)createDatabase:(MPDatabaseVersion)version password:(NSString *)password keyfile:(NSURL *)key;
|
||||
- (MPDatabaseDocument *)openDatabase:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key;
|
||||
- (MPDatabaseDocument *)newDatabaseAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)version password:(NSString *)password keyfile:(NSURL *)key;
|
||||
|
||||
@end
|
||||
|
||||
@@ -53,6 +53,11 @@ NSString *const MPDatabaseControllerDatabaseKey = @"com.macpass.MPDatabaseContro
|
||||
return self.database;
|
||||
}
|
||||
|
||||
- (MPDatabaseDocument *)newDatabaseAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)version password:(NSString *)password keyfile:(NSURL *)key {
|
||||
self.database = [MPDatabaseDocument newDocumentAtURL:url databaseVersion:version password:password keyfile:key];
|
||||
return self.database;
|
||||
}
|
||||
|
||||
- (MPDatabaseDocument *)openDatabase:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key {
|
||||
self.database = [MPDatabaseDocument documentWithFile:file password:password keyfile:key];
|
||||
return self.database;
|
||||
|
||||
@@ -7,15 +7,11 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "MPDatabaseVersion.h"
|
||||
|
||||
APPKIT_EXTERN NSString *const MPDidLoadDatabaseNotification;
|
||||
APPKIT_EXTERN NSString *const MPDatabaseDocumentDocumentKey;
|
||||
|
||||
typedef enum {
|
||||
MPDatabaseVersion3,
|
||||
MPDatabaseVersion4
|
||||
} MPDatabaseVersion;
|
||||
|
||||
@class KdbPassword;
|
||||
@class KdbGroup;
|
||||
@class KdbEntry;
|
||||
@@ -30,8 +26,10 @@ typedef enum {
|
||||
|
||||
+ (id)documentWithFile:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key;
|
||||
+ (id)documentWithNewDatabase:(MPDatabaseVersion)version;
|
||||
+ (id)newDocumentAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)dbversion password:(NSString *)password keyfile:(NSURL *)key;
|
||||
- (id)initWithFile:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key;
|
||||
- (id)initWithNewDatabase:(MPDatabaseVersion)version;
|
||||
- (id)initNewDocumentAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)dbversion password:(NSString *)password keyfile:(NSURL *)key;
|
||||
/*
|
||||
Saves the current database to the filesystem
|
||||
Tries to use the stored password and file path
|
||||
|
||||
@@ -19,6 +19,7 @@ NSString *const MPDidLoadDatabaseNotification = @"DidLoadDataBaseNotification";
|
||||
@property (retain) NSURL *file;
|
||||
@property (nonatomic, readonly) KdbPassword *passwordHash;
|
||||
@property (assign) MPDatabaseVersion version;
|
||||
@property (readonly)BOOL isNewFile;
|
||||
|
||||
@end
|
||||
|
||||
@@ -32,11 +33,42 @@ NSString *const MPDidLoadDatabaseNotification = @"DidLoadDataBaseNotification";
|
||||
return [[[MPDatabaseDocument alloc] initWithNewDatabase:version] autorelease];
|
||||
}
|
||||
|
||||
+ (id)newDocumentAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)dbversion password:(NSString *)password keyfile:(NSURL *)key
|
||||
{
|
||||
return [[[MPDatabaseDocument alloc] initNewDocumentAtURL:url databaseVersion:dbversion password:password keyfile:key] autorelease];
|
||||
}
|
||||
|
||||
- (id)init {
|
||||
// create empty document
|
||||
return [self initWithFile:nil password:nil keyfile:nil];
|
||||
}
|
||||
|
||||
|
||||
- (id)initNewDocumentAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)dbversion password:(NSString *)password keyfile:(NSURL *)key
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
self.file = url;
|
||||
self.key = key;
|
||||
self.password = password;
|
||||
_isNewFile = YES;
|
||||
switch(dbversion) {
|
||||
case MPDatabaseVersion3:
|
||||
self.tree = [[[Kdb3Tree alloc] init] autorelease];
|
||||
break;
|
||||
case MPDatabaseVersion4:
|
||||
self.tree = [[[Kdb4Tree alloc] init] autorelease];
|
||||
break;
|
||||
default:
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
KdbGroup *newGroup = [self.tree createGroup:self.tree.root];
|
||||
newGroup.name = @"Default";
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
Initalizer for creating
|
||||
*/
|
||||
@@ -109,7 +141,7 @@ NSString *const MPDidLoadDatabaseNotification = @"DidLoadDataBaseNotification";
|
||||
|
||||
- (BOOL)save {
|
||||
NSError *fileError;
|
||||
if( [self.file checkResourceIsReachableAndReturnError:&fileError] ) {
|
||||
if(self.isNewFile || [self.file checkResourceIsReachableAndReturnError:&fileError] ) {
|
||||
@try {
|
||||
[KdbWriterFactory persist:self.tree file:[self.file path] withPassword:self.passwordHash];
|
||||
}
|
||||
@@ -119,6 +151,11 @@ NSString *const MPDidLoadDatabaseNotification = @"DidLoadDataBaseNotification";
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"File Error: %@", fileError);
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)saveAsFile:(NSURL *)file withPassword:(NSString *)password keyfile:(NSURL *)key {
|
||||
|
||||
17
MacPass/MPDatabaseVersion.h
Normal file
17
MacPass/MPDatabaseVersion.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// MPDatabaseVersion.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Nathaniel Madura on 18/04/13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef MacPass_MPDatabaseVersion_h
|
||||
#define MacPass_MPDatabaseVersion_h
|
||||
|
||||
typedef enum {
|
||||
MPDatabaseVersion3,
|
||||
MPDatabaseVersion4
|
||||
} MPDatabaseVersion;
|
||||
|
||||
#endif
|
||||
@@ -13,6 +13,7 @@
|
||||
@class MPInspectorTabViewController;
|
||||
@class MPPasswordInputController;
|
||||
@class MPOutlineViewController;
|
||||
@class MPCreationViewController;
|
||||
|
||||
@interface MPMainWindowController : NSWindowController
|
||||
|
||||
@@ -20,6 +21,7 @@
|
||||
@property (readonly, retain) MPEntryViewController *entryViewController;
|
||||
@property (readonly, retain) MPOutlineViewController *outlineViewController;
|
||||
@property (readonly, retain) MPInspectorTabViewController *inspectorTabViewController;
|
||||
@property (readonly, retain) MPCreationViewController *creationViewController;
|
||||
|
||||
|
||||
- (void)showEntries;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#import "MPMainWindowSplitViewDelegate.h"
|
||||
#import "MPInspectorTabViewController.h"
|
||||
#import "MPAppDelegate.h"
|
||||
#import "MPCreationViewController.h"
|
||||
|
||||
@interface MPMainWindowController ()
|
||||
|
||||
@@ -32,6 +33,7 @@
|
||||
@property (retain) MPEntryViewController *entryViewController;
|
||||
@property (retain) MPOutlineViewController *outlineViewController;
|
||||
@property (retain) MPInspectorTabViewController *inspectorTabViewController;
|
||||
@property (retain) MPCreationViewController *creationViewController;
|
||||
|
||||
@property (retain) MPToolbarDelegate *toolbarDelegate;
|
||||
@property (retain) MPMainWindowSplitViewDelegate *splitViewDelegate;
|
||||
@@ -54,6 +56,7 @@
|
||||
_outlineViewController = [[MPOutlineViewController alloc] init];
|
||||
_inspectorTabViewController = [[MPInspectorTabViewController alloc] init];
|
||||
_splitViewDelegate = [[MPMainWindowSplitViewDelegate alloc] init];
|
||||
_creationViewController = [[MPCreationViewController alloc] init];
|
||||
|
||||
[[NSBundle mainBundle] loadNibNamed:@"WelcomeView" owner:self topLevelObjects:NULL];
|
||||
[self.welcomeView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||
@@ -76,6 +79,7 @@
|
||||
[_entryViewController release];
|
||||
[_outlineViewController release];
|
||||
[_inspectorTabViewController release];
|
||||
[_creationViewController release];
|
||||
|
||||
[_toolbarDelegate release];
|
||||
[_splitViewDelegate release];
|
||||
@@ -248,6 +252,31 @@
|
||||
- (void)showEditForm:(id)sender {
|
||||
}
|
||||
|
||||
- (void)newDocument:(id)sender {
|
||||
if (!self.creationViewController) {
|
||||
self.creationViewController = [[[MPCreationViewController alloc] init] autorelease];
|
||||
}
|
||||
|
||||
NSSavePanel *savePanel = [NSSavePanel savePanel];
|
||||
[savePanel setAllowedFileTypes:@[@"kdbx", @"kdb"]];
|
||||
[savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
|
||||
if (result == NSFileHandlingPanelOKButton) {
|
||||
NSURL *file = [savePanel URL];
|
||||
NSLog(@"Will create file at: %@", file);
|
||||
self.creationViewController.fileURL = file;
|
||||
[self _setContentViewController:self.creationViewController];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)saveDocument:(id)sender
|
||||
{
|
||||
NSLog(@"Attempting to save document");
|
||||
if ([[MPDatabaseController defaultController].database save])
|
||||
NSLog(@"Save successful");
|
||||
else
|
||||
NSLog(@"Save failed");
|
||||
}
|
||||
|
||||
#pragma mark Helper
|
||||
|
||||
|
||||
Reference in New Issue
Block a user