2
0

Added "delete user", fixed some minor UI issues.

This commit is contained in:
Maarten Billemont 2014-06-07 20:13:53 -04:00
parent 113c3790fb
commit a713a639cd
6 changed files with 64 additions and 24 deletions

View File

@ -47,10 +47,12 @@
- (NSString *)generateContentNamed:(NSString *)name ofType:(MPElementType)type withCounter:(NSUInteger)counter usingKey:(MPKey *)key { - (NSString *)generateContentNamed:(NSString *)name ofType:(MPElementType)type withCounter:(NSUInteger)counter usingKey:(MPKey *)key {
static NSDictionary *MPTypes_ciphers = nil; static __strong NSDictionary *MPTypes_ciphers = nil;
if (MPTypes_ciphers == nil) static dispatch_once_t once = 0;
dispatch_once(&once, ^{
MPTypes_ciphers = [NSDictionary dictionaryWithContentsOfURL: MPTypes_ciphers = [NSDictionary dictionaryWithContentsOfURL:
[[NSBundle mainBundle] URLForResource:@"ciphers" withExtension:@"plist"]]; [[NSBundle mainBundle] URLForResource:@"ciphers" withExtension:@"plist"]];
});
// Determine the seed whose bytes will be used for calculating a password // Determine the seed whose bytes will be used for calculating a password
uint32_t ncounter = htonl(counter), nnameLength = htonl(name.length); uint32_t ncounter = htonl(counter), nnameLength = htonl(name.length);

View File

@ -23,6 +23,7 @@
@property(nonatomic, weak) IBOutlet NSMenuItem *openAtLoginItem; @property(nonatomic, weak) IBOutlet NSMenuItem *openAtLoginItem;
@property(nonatomic, weak) IBOutlet NSMenuItem *savePasswordItem; @property(nonatomic, weak) IBOutlet NSMenuItem *savePasswordItem;
@property(nonatomic, weak) IBOutlet NSMenuItem *createUserItem; @property(nonatomic, weak) IBOutlet NSMenuItem *createUserItem;
@property(nonatomic, weak) IBOutlet NSMenuItem *deleteUserItem;
@property(nonatomic, weak) IBOutlet NSMenuItem *usersItem; @property(nonatomic, weak) IBOutlet NSMenuItem *usersItem;
@property(nonatomic, weak) IBOutlet NSMenuItem *dialogStyleRegular; @property(nonatomic, weak) IBOutlet NSMenuItem *dialogStyleRegular;
@property(nonatomic, weak) IBOutlet NSMenuItem *dialogStyleHUD; @property(nonatomic, weak) IBOutlet NSMenuItem *dialogStyleHUD;

View File

@ -68,7 +68,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
- (void)updateUsers { - (void)updateUsers {
[[[self.usersItem submenu] itemArray] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [[[self.usersItem submenu] itemArray] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if (idx > 1) if (idx > 2)
[[self.usersItem submenu] removeItem:obj]; [[self.usersItem submenu] removeItem:obj];
}]; }];
@ -77,15 +77,24 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
self.createUserItem.title = @"New User (Not ready)"; self.createUserItem.title = @"New User (Not ready)";
self.createUserItem.enabled = NO; self.createUserItem.enabled = NO;
self.createUserItem.toolTip = @"Please wait until the app is fully loaded."; self.createUserItem.toolTip = @"Please wait until the app is fully loaded.";
self.deleteUserItem.title = @"Delete User (Not ready)";
self.deleteUserItem.enabled = NO;
self.deleteUserItem.toolTip = @"Please wait until the app is fully loaded.";
[self.usersItem.submenu addItemWithTitle:@"Loading..." action:NULL keyEquivalent:@""].enabled = NO; [self.usersItem.submenu addItemWithTitle:@"Loading..." action:NULL keyEquivalent:@""].enabled = NO;
return; return;
} }
MPUserEntity *activeUser = [self activeUserInContext:context];
self.createUserItem.title = @"New User"; self.createUserItem.title = @"New User";
self.createUserItem.enabled = YES; self.createUserItem.enabled = YES;
self.createUserItem.toolTip = nil; self.createUserItem.toolTip = nil;
self.deleteUserItem.title = activeUser? @"Delete User": @"Delete User (None Selected)";
self.deleteUserItem.enabled = activeUser != nil;
self.deleteUserItem.toolTip = activeUser? nil: @"First select the user to delete.";
NSError *error = nil; NSError *error = nil;
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass( [MPUserEntity class] )]; NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass( [MPUserEntity class] )];
fetchRequest.sortDescriptors = @[ [NSSortDescriptor sortDescriptorWithKey:@"lastUsed" ascending:NO] ]; fetchRequest.sortDescriptors = @[ [NSSortDescriptor sortDescriptorWithKey:@"lastUsed" ascending:NO] ];
@ -100,7 +109,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
@"Then give iCloud some time to sync the new user to your Mac."; @"Then give iCloud some time to sync the new user to your Mac.";
} }
MPUserEntity *activeUser = [self activeUserInContext:context]; self.usersItem.state = NSMixedState;
for (MPUserEntity *user in users) { for (MPUserEntity *user in users) {
NSMenuItem *userItem = [[NSMenuItem alloc] initWithTitle:user.name action:@selector(selectUser:) keyEquivalent:@""]; NSMenuItem *userItem = [[NSMenuItem alloc] initWithTitle:user.name action:@selector(selectUser:) keyEquivalent:@""];
[userItem setTarget:self]; [userItem setTarget:self];
@ -108,7 +117,14 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
[[self.usersItem submenu] addItem:userItem]; [[self.usersItem submenu] addItem:userItem];
if (!activeUser && [user.name isEqualToString:[MPMacConfig get].usedUserName]) if (!activeUser && [user.name isEqualToString:[MPMacConfig get].usedUserName])
[self selectUser:userItem]; [super setActiveUser:activeUser = user];
if ([activeUser isEqual:user]) {
userItem.state = NSOnState;
self.usersItem.state = NSOffState;
}
else
userItem.state = NSOffState;
} }
[self updateMenuItems]; [self updateMenuItems];
@ -200,6 +216,26 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
}]; }];
} }
- (IBAction)deleteUser:(NSMenuItem *)sender {
NSAlert *alert = [NSAlert alertWithMessageText:@"Delete User"
defaultButton:@"Delete" alternateButton:nil otherButton:@"Cancel"
informativeTextWithFormat:@"This will delete %@ and all his sites.", self.activeUserForMainThread.name];
if ([alert runModal] != NSAlertDefaultReturn)
return;
[MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *moc) {
[moc deleteObject:[self activeUserInContext:moc]];
[self setActiveUser:nil];
[moc saveToStore];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self updateUsers];
[self showPasswordWindow:nil];
}];
}];
}
- (IBAction)lock:(id)sender { - (IBAction)lock:(id)sender {
self.key = nil; self.key = nil;
@ -334,17 +370,11 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
[super setActiveUser:activeUser]; [super setActiveUser:activeUser];
self.usersItem.state = NSMixedState;
[[[self.usersItem submenu] itemArray] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([[obj representedObject] isEqual:[activeUser objectID]]) {
[obj setState:NSOnState];
self.usersItem.state = NSOffState;
}
else
[obj setState:NSOffState];
}];
[MPMacConfig get].usedUserName = activeUser.name; [MPMacConfig get].usedUserName = activeUser.name;
PearlMainQueue(^{
[self updateUsers];
});
} }
- (void)updateMenuItems { - (void)updateMenuItems {

View File

@ -1876,7 +1876,7 @@
); );
GCC_PREFIX_HEADER = "MasterPassword-Prefix.pch"; GCC_PREFIX_HEADER = "MasterPassword-Prefix.pch";
INFOPLIST_FILE = "MasterPassword-Info.plist"; INFOPLIST_FILE = "MasterPassword-Info.plist";
PROVISIONING_PROFILE = "923BEF9D-3682-4969-A451-8CAA949E579A"; PROVISIONING_PROFILE = "9FCC90BB-24CA-40E2-8565-860F95CCC039";
SKIP_INSTALL = NO; SKIP_INSTALL = NO;
WRAPPER_NAME = "Master Password.${WRAPPER_EXTENSION}"; WRAPPER_NAME = "Master Password.${WRAPPER_EXTENSION}";
}; };

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4514" systemVersion="13B3116" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13D65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies> <dependencies>
<deployment version="1070" defaultVersion="1080" identifier="macosx"/> <deployment version="1070" defaultVersion="1080" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
</dependencies> </dependencies>
<objects> <objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication"> <customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
@ -16,6 +16,7 @@
<customObject id="494" customClass="MPMacAppDelegate"> <customObject id="494" customClass="MPMacAppDelegate">
<connections> <connections>
<outlet property="createUserItem" destination="757" id="763"/> <outlet property="createUserItem" destination="757" id="763"/>
<outlet property="deleteUserItem" destination="ZgZ-p2-463" id="smU-PF-mKA"/>
<outlet property="dialogStyleHUD" destination="768" id="771"/> <outlet property="dialogStyleHUD" destination="768" id="771"/>
<outlet property="dialogStyleRegular" destination="767" id="772"/> <outlet property="dialogStyleRegular" destination="767" id="772"/>
<outlet property="lockItem" destination="720" id="726"/> <outlet property="lockItem" destination="720" id="726"/>
@ -41,6 +42,12 @@
<action selector="newUser:" target="494" id="761"/> <action selector="newUser:" target="494" id="761"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem title="Delete User" enabled="NO" toolTip="Creating users is not yet supported. Please use the iOS app with iCloud enabled to create users and sites." id="ZgZ-p2-463">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="deleteUser:" target="494" id="eia-X5-QMc"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="759"/> <menuItem isSeparatorItem="YES" id="759"/>
</items> </items>
</menu> </menu>
@ -146,7 +153,7 @@
<action selector="rebuildCloud:" target="494" id="780"/> <action selector="rebuildCloud:" target="494" id="780"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem title="Force our version of the truth upon all other devices." enabled="NO" id="779"> <menuItem title="Force this device's version of the truth upon all others." enabled="NO" id="779">
<attributedString key="attributedTitle"> <attributedString key="attributedTitle">
<fragment content="Force this device's version of the truth upon all others."> <fragment content="Force this device's version of the truth upon all others.">
<attributes> <attributes>
@ -163,7 +170,7 @@
<action selector="corruptCloud:" target="494" id="asr-sb-Zkz"/> <action selector="corruptCloud:" target="494" id="asr-sb-Zkz"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem title="Mark ourselves as corrupt and pull the truth from another." enabled="NO" id="6NL-ki-Jff"> <menuItem title="Force this device's version of the truth upon all others." enabled="NO" id="6NL-ki-Jff">
<attributedString key="attributedTitle"> <attributedString key="attributedTitle">
<fragment content="Force this device's version of the truth upon all others."> <fragment content="Force this device's version of the truth upon all others.">
<attributes> <attributes>

View File

@ -26,7 +26,7 @@
if ([self class] == [MPiOSAppDelegate class]) { if ([self class] == [MPiOSAppDelegate class]) {
[PearlLogger get].historyLevel = [[MPiOSConfig get].traceMode boolValue]? PearlLogLevelTrace: PearlLogLevelInfo; [PearlLogger get].historyLevel = [[MPiOSConfig get].traceMode boolValue]? PearlLogLevelTrace: PearlLogLevelInfo;
#ifdef DEBUG #ifdef DEBUG
[PearlLogger get].printLevel = PearlLogLevelDebug; [PearlLogger get].printLevel = PearlLogLevelDebug; //Trace;
#else #else
[PearlLogger get].printLevel = [[MPiOSConfig get].traceMode boolValue]? PearlLogLevelDebug: PearlLogLevelInfo; [PearlLogger get].printLevel = [[MPiOSConfig get].traceMode boolValue]? PearlLogLevelDebug: PearlLogLevelInfo;
#endif #endif