From 8ab272179e216a77a20d9db7e124ecd8f62dfac4 Mon Sep 17 00:00:00 2001 From: michael starke Date: Fri, 15 Feb 2013 02:51:01 +0100 Subject: [PATCH] Basic (buggy) Tree handling --- MacPass/MPAppDelegate.m | 2 +- MacPass/MPDatabaseController.h | 1 - MacPass/MPDatabaseDocument.h | 2 ++ MacPass/MPDatabaseDocument.m | 5 +++++ MacPass/MPMainWindowController.h | 2 +- MacPass/MPMainWindowController.m | 11 ++++++++--- MacPass/MPOutlineDataSource.m | 13 ++++++++++++- MacPass/MPOutlineViewDelegate.m | 6 +++++- MacPass/PasswordView.xib | 10 +++++++++- 9 files changed, 43 insertions(+), 9 deletions(-) diff --git a/MacPass/MPAppDelegate.m b/MacPass/MPAppDelegate.m index 4d50822c..bb2dd802 100644 --- a/MacPass/MPAppDelegate.m +++ b/MacPass/MPAppDelegate.m @@ -53,7 +53,7 @@ if(result == NSFileHandlingPanelOKButton) { NSURL *file = [[openPanel URLs] lastObject]; if(file) { - [self.mainWindowController presentPasswordInput]; + [self.mainWindowController presentPasswordInput:(NSURL *)file]; } } }]; diff --git a/MacPass/MPDatabaseController.h b/MacPass/MPDatabaseController.h index 339b3a8e..bce3b72e 100644 --- a/MacPass/MPDatabaseController.h +++ b/MacPass/MPDatabaseController.h @@ -10,7 +10,6 @@ @class MPDatabaseDocument; - typedef enum{ MPDatabaseVersion1, MPDatabaseVersion2 diff --git a/MacPass/MPDatabaseDocument.h b/MacPass/MPDatabaseDocument.h index 679fbf4f..46ddd689 100644 --- a/MacPass/MPDatabaseDocument.h +++ b/MacPass/MPDatabaseDocument.h @@ -12,9 +12,11 @@ APPKIT_EXTERN NSString *const MPDidLoadDataBaseNotification; APPKIT_EXTERN NSString *const MPDataBaseDocumentDocumentKey; @class KdbPassword; +@class KdbGroup; @interface MPDatabaseDocument : NSObject +@property (retain, readonly) KdbGroup *root; @property (retain, readonly) NSURL *file; @property (retain, readonly) KdbPassword *password; + (id)documentWithFile:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key; diff --git a/MacPass/MPDatabaseDocument.m b/MacPass/MPDatabaseDocument.m index 7501f56b..433b6b3b 100644 --- a/MacPass/MPDatabaseDocument.m +++ b/MacPass/MPDatabaseDocument.m @@ -81,6 +81,11 @@ NSString *const MPDidLoadDataBaseNotification = @"DidLoadDataBaseNotification"; return self; } +- (KdbGroup *)root { + return [self.tree root]; +} + + - (BOOL)save { NSError *fileError; if( self.password && [self.file checkResourceIsReachableAndReturnError:&fileError] ) { diff --git a/MacPass/MPMainWindowController.h b/MacPass/MPMainWindowController.h index b7e90120..903eee56 100644 --- a/MacPass/MPMainWindowController.h +++ b/MacPass/MPMainWindowController.h @@ -17,6 +17,6 @@ APPKIT_EXTERN NSString *const MPMainWindowControllerKeyfileKey; @property (readonly, retain) MPDatabaseDocument *database; -- (void)presentPasswordInput; +- (void)presentPasswordInput:(NSURL *)file; @end diff --git a/MacPass/MPMainWindowController.m b/MacPass/MPMainWindowController.m index b9cc26d4..670b7b13 100644 --- a/MacPass/MPMainWindowController.m +++ b/MacPass/MPMainWindowController.m @@ -28,6 +28,7 @@ NSString *const kOutlineViewIdentifier = @"OutlineView"; @property (assign) IBOutlet NSPathControl *keyPathControl; @property (assign) IBOutlet NSView *contentView; +@property (retain) NSURL *openFile; @property (retain) MPOutlineDataSource *datasource; @property (retain) MPOutlineViewDelegate *outlineDelegate; @property (retain) MPMainWindowDelegate *windowDelegate; @@ -60,20 +61,24 @@ NSString *const kOutlineViewIdentifier = @"OutlineView"; [self.window setDelegate:self.windowDelegate]; [[self.outlineView outlineTableColumn] setIdentifier:kColumnIdentifier]; [self.outlineView setDelegate:self.outlineDelegate]; + [self.outlineView setDataSource:self.datasource]; } - (void)updateData { - [_outlineView reloadData]; + [self.outlineView reloadData]; } -- (void)presentPasswordInput { +- (void)presentPasswordInput:(NSURL *)file { NSArray *topLevelObjects; + self.openFile = file; [[NSBundle mainBundle] loadNibNamed:@"PasswordView" owner:self topLevelObjects:&topLevelObjects]; [self.contentView addSubview:self.passwordView]; } - (void)usePassword:(id)sender { - [[MPDatabaseController defaultController] openDatabase:nil password:nil keyfile:nil]; + NSString *password = [self.passwordTextField stringValue]; + + [[MPDatabaseController defaultController] openDatabase:self.openFile password:password keyfile:nil]; [self updateData]; } diff --git a/MacPass/MPOutlineDataSource.m b/MacPass/MPOutlineDataSource.m index 8c5e7d52..e68c7034 100644 --- a/MacPass/MPOutlineDataSource.m +++ b/MacPass/MPOutlineDataSource.m @@ -7,13 +7,17 @@ // #import "MPOutlineDataSource.h" +#import "MPDatabaseController.h" #import "MPDatabaseDocument.h" #import "KdbLib.h" @implementation MPOutlineDataSource - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item { - + if(!item) { + MPDatabaseController *dbController = [MPDatabaseController defaultController]; + return [[dbController.database.root groups] count]; + } if( [item isKindOfClass:[KdbGroup class]]) { KdbGroup *group = item; return [[group groups] count]; @@ -21,6 +25,10 @@ return 0; } - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item { + if(!item) { + MPDatabaseController *dbController = [MPDatabaseController defaultController]; + return dbController.database.root; + } if( [item isKindOfClass:[KdbGroup class]]) { KdbGroup *group = item; if( [[group groups] count] > index ) { @@ -30,6 +38,9 @@ return nil; } - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item { + if(!item) { + return true; + } return [item isKindOfClass:[KdbGroup class]]; } diff --git a/MacPass/MPOutlineViewDelegate.m b/MacPass/MPOutlineViewDelegate.m index 73b8874c..f7d7746f 100644 --- a/MacPass/MPOutlineViewDelegate.m +++ b/MacPass/MPOutlineViewDelegate.m @@ -7,13 +7,17 @@ // #import "MPOutlineViewDelegate.h" +#import "KdbLib.h" @implementation MPOutlineViewDelegate - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item { NSTableCellView *view = [outlineView makeViewWithIdentifier:@"DataCell" owner:self]; [view.imageView setImage:[NSImage imageNamed:NSImageNameFolder]]; - [view.textField setStringValue:@"Test"]; + if([item isKindOfClass:[KdbGroup class]]) { + KdbGroup *group = item; + [view.textField setStringValue:[group name]]; + } return view; } diff --git a/MacPass/PasswordView.xib b/MacPass/PasswordView.xib index 04e2bbdf..02a30dd5 100644 --- a/MacPass/PasswordView.xib +++ b/MacPass/PasswordView.xib @@ -274,6 +274,14 @@ 101 + + + usePassword: + + + + 102 + @@ -686,7 +694,7 @@ - 101 + 102