From: Justin Anderson Date: Thu, 2 Oct 2008 20:56:14 +0000 (+0000) Subject: Select identity switched to using new NSDictionary based options and change password... X-Git-Tag: krb5-1.7-alpha1~354 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=da722ccb10717515730114dceafac7d582bee909;p=krb5.git Select identity switched to using new NSDictionary based options and change password menu item support ticket: 6055 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20817 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/kim/agent/mac/IPCClient.m b/src/kim/agent/mac/IPCClient.m index 62b6dd0f8..d024f0b6c 100644 --- a/src/kim/agent/mac/IPCClient.m +++ b/src/kim/agent/mac/IPCClient.m @@ -113,7 +113,8 @@ enum krb_agent_client_state { { self.currentInfo = [[info mutableCopy] autorelease]; self.state = ipc_client_state_select; - + + [self.selectController setContent:self.currentInfo]; [self.selectController showWindow:nil]; return 0; @@ -123,7 +124,6 @@ enum krb_agent_client_state { options: (NSDictionary *) options wantsChangePassword: (BOOL) wantsChangePassword { - NSLog(@"%s %@ %@", __FUNCTION__, identityString, options); [self.currentInfo setObject:identityString forKey:@"identity_string"]; // if the user set custom options, use those if (options) { diff --git a/src/kim/agent/mac/Identities.m b/src/kim/agent/mac/Identities.m index c388de46f..ae9cea86b 100644 --- a/src/kim/agent/mac/Identities.m +++ b/src/kim/agent/mac/Identities.m @@ -616,7 +616,6 @@ } if (!err) { - kimIdentity = NULL; /* take ownership */ [newFavoriteIdentities addObject: identity]; } @@ -625,17 +624,20 @@ identity = nil; } + kim_options_free(&kimOptions); kim_identity_free (&kimIdentity); } kim_preferences_free(&preferences); } + if (!err) { self.favoriteIdentities = newFavoriteIdentities; if (!favoriteIdentities) { err = ENOMEM; } } - + + if (newFavoriteIdentities) { [newFavoriteIdentities release]; newFavoriteIdentities = nil; @@ -666,7 +668,7 @@ } // Build list of identities with existing ccaches -// NSLog(@"updating %@", [[NSThread currentThread] description]); + //NSLog(@"updating %@", [[NSThread currentThread] description]); while (!err) { kim_ccache ccache = NULL; kim_identity an_identity = NULL; @@ -723,6 +725,7 @@ kim_ccache_iterator_free (&iterator); + // Copy ccache state to favorites for (Identity *identity in self.favoriteIdentities) { Identity *matchingIdentity = [newIdentities member:identity]; @@ -735,14 +738,18 @@ identity.expirationDate = [NSDate distantPast]; } } - + + // Add unused favorites [newIdentities unionSet:[NSSet setWithArray:self.favoriteIdentities]]; if (!err) { - [self.identities removeAllObjects]; - [self.identities addObjectsFromArray:[newIdentities allObjects]]; - [self.identities sortUsingSelector:@selector(compare:)]; +// [self.identities removeAllObjects]; +// [self.identities addObjectsFromArray:[newIdentities allObjects]]; +// [self.identities sortUsingSelector:@selector(compare:)]; + + self.identities = [[[[newIdentities allObjects] sortedArrayUsingSelector:@selector(compare:)] mutableCopy] autorelease]; + if (!identities) { err = ENOMEM; } } else { @@ -759,7 +766,9 @@ kim_error err = KIM_NO_ERROR; if (![self.identities containsObject:anIdentity]) { - [self.identities addObject:anIdentity]; + NSMutableArray *newArray = [[self.identities mutableCopy] autorelease]; + [newArray addObject:anIdentity]; + self.identities = newArray; } else { err = KIM_IDENTITY_ALREADY_IN_LIST_ERR; } diff --git a/src/kim/agent/mac/KerberosAgentListener.m b/src/kim/agent/mac/KerberosAgentListener.m index e192e1991..6c4c8d7c8 100644 --- a/src/kim/agent/mac/KerberosAgentListener.m +++ b/src/kim/agent/mac/KerberosAgentListener.m @@ -179,6 +179,7 @@ static KerberosAgentListener *sharedListener = nil; options = [KIMUtilities kimOptionsForDictionary:[info objectForKey:@"options"]]; } + if (!err) { err = kim_handle_reply_enter_identity(reply_port, identity, options, wants_change_password, error); } @@ -214,7 +215,6 @@ static KerberosAgentListener *sharedListener = nil; kim_identity identity = NULL; kim_options options = NULL; BOOL wants_change_password = [[info objectForKey:@"wants_change_password"] boolValue]; - NSLog(@"%s", __FUNCTION__); if (identityString) { err = kim_identity_create_from_string(&identity, [identityString UTF8String]); diff --git a/src/kim/agent/mac/SelectIdentityController.h b/src/kim/agent/mac/SelectIdentityController.h index 494d79913..29b3c0dd4 100644 --- a/src/kim/agent/mac/SelectIdentityController.h +++ b/src/kim/agent/mac/SelectIdentityController.h @@ -27,10 +27,14 @@ #import "Identities.h" @class IPCClient; +@class KerberosTimeFormatter; @interface SelectIdentityController : NSWindowController { IPCClient *associatedClient; + IBOutlet KerberosTimeFormatter *shortTimeFormatter; + IBOutlet KerberosTimeFormatter *longTimeFormatter; + IBOutlet NSObjectController *identitiesController; IBOutlet NSArrayController *identityArrayController; @@ -79,7 +83,6 @@ - (IBAction) cancel: (id) sender; - (IBAction) sliderDidChange: (id) sender; -- (void)controlTextDidChange:(NSNotification *)aNotification; - (void) showOptions: (NSString *) contextInfo; - (void) didEndSheet: (NSWindow *) sheet returnCode: (int) returnCode contextInfo: (void *) contextInfo; diff --git a/src/kim/agent/mac/SelectIdentityController.m b/src/kim/agent/mac/SelectIdentityController.m index 243670e77..66da11e2c 100644 --- a/src/kim/agent/mac/SelectIdentityController.m +++ b/src/kim/agent/mac/SelectIdentityController.m @@ -24,6 +24,7 @@ #import "SelectIdentityController.h" #import "IPCClient.h" +#import "KerberosFormatters.h" #define identities_key_path @"identities" @@ -42,6 +43,7 @@ - (void) dealloc { + [identityOptionsController removeObserver:self forKeyPath:identity_string_keypath]; [refreshTimer release]; [identities release]; [super dealloc]; @@ -57,6 +59,9 @@ // We need to float over the loginwindow and SecurityAgent so use its hardcoded level. [[self window] center]; [[self window] setLevel:NSScreenSaverWindowLevel]; + + longTimeFormatter.displaySeconds = NO; + longTimeFormatter.displayShortFormat = NO; [identityTableView setDoubleAction:@selector(select:)]; identities = [[Identities alloc] init]; @@ -76,7 +81,20 @@ associatedClient.name]; } [headerTextField setStringValue:message]; - [explanationTextField setStringValue:@"explanation!"]; + + [identityOptionsController addObserver:self + forKeyPath:identity_string_keypath + options:NSKeyValueObservingOptionNew + context:NULL]; +} + +- (void) observeValueForKeyPath:(NSString *) keyPath ofObject: (id) object change: (NSDictionary *) change context:(void *) context +{ + if ([keyPath isEqualToString:identity_string_keypath]) { + BOOL enabled = [KIMUtilities validateIdentity:[identityOptionsController valueForKeyPath:identity_string_keypath]]; + [identityOptionsController setValue:[NSNumber numberWithBool:enabled] + forKeyPath:@"content.canClickOK"]; + } } // --------------------------------------------------------------------------- @@ -84,18 +102,15 @@ - (void) setContent: (NSMutableDictionary *) newContent { [self window]; // wake up the nib connections -// [glueController setContent:newContent]; + [glueController setContent:newContent]; } // --------------------------------------------------------------------------- - (IBAction) newIdentity: (id) sender { - Identity *newIdentity = [[Identity alloc] init]; - - newIdentity.favorite = TRUE; - identityOptionsController.content = newIdentity; - [newIdentity release]; + identityOptionsController.content = [[[glueController valueForKeyPath:@"content.hints.options"] + mutableCopy] autorelease]; [self showOptions:@"new"]; } @@ -117,7 +132,7 @@ - (IBAction) removeFromFavorites: (id) sender { Identity *anIdentity = [identityArrayController.selectedObjects lastObject]; - identityOptionsController.content = anIdentity; + identityOptionsController.content = nil; anIdentity.favorite = FALSE; @@ -128,7 +143,17 @@ - (IBAction) changePassword: (id) sender { + Identity *selectedIdentity = nil; + + // ignore double-click on header + if ([sender respondsToSelector:@selector(clickedRow)] && [sender clickedRow] < 0) { + return; + } + selectedIdentity = [[identityArrayController selectedObjects] lastObject]; + [associatedClient didSelectIdentity: selectedIdentity.identity + options: [identityOptionsController valueForKeyPath:@"content.options"] + wantsChangePassword: YES]; } // --------------------------------------------------------------------------- @@ -162,7 +187,8 @@ { Identity *anIdentity = [identityArrayController.selectedObjects lastObject]; anIdentity.favorite = TRUE; - [identityOptionsController setContent: anIdentity]; + + [identityOptionsController setContent:anIdentity.options]; [self showOptions:@"edit"]; } @@ -171,9 +197,8 @@ - (IBAction) resetOptions: (id) sender { - Identity *anIdentity = identityOptionsController.content; - // reset options to default settings - [anIdentity resetOptions]; + Identity *anIdentity = [identityArrayController.selectedObjects lastObject]; + [identityOptionsController setContent:anIdentity.options]; } // --------------------------------------------------------------------------- @@ -197,16 +222,27 @@ [NSApp endSheet: identityOptionsWindow]; } -- (IBAction) sliderDidChange: (id) sender -{ - -} +// --------------------------------------------------------------------------- -- (void)controlTextDidChange:(NSNotification *)aNotification +- (IBAction) sliderDidChange: (id) sender { -// BOOL valid = [KIMUtilities validateIdentity:]; - [ticketOptionsOkButton setEnabled:false]; - [ticketOptionsOkButton setNeedsDisplay]; + NSInteger increment = 0; + NSInteger newValue = 0; + NSString *keyPath = nil; + if ([sender isEqual:validLifetimeSlider]) { + increment = VALID_LIFETIME_INCREMENT; + keyPath = valid_lifetime_keypath; + } + else if ([sender isEqual:renewableLifetimeSlider]) { + increment = RENEWABLE_LIFETIME_INCREMENT; + keyPath = renewal_lifetime_keypath; + } + if (increment > 0) { + newValue = ([sender integerValue] / increment) * increment; + [identityOptionsController setValue:[NSNumber numberWithInteger: + (newValue < increment) ? increment : newValue] + forKeyPath:keyPath]; + } } // --------------------------------------------------------------------------- @@ -214,16 +250,11 @@ - (void) showOptions: (NSString *) contextInfo { Identity *anIdentity = [[identityArrayController selectedObjects] lastObject]; - // use a copy of the current options - [identityOptionsController setContent: - [[[glueController valueForKeyPath:options_keypath] mutableCopy] autorelease]]; - - [identityField setStringValue:anIdentity.identity]; - [staticIdentityField setStringValue:anIdentity.identity]; - - [identityOptionsController setContent: - [[[glueController valueForKeyPath:options_keypath] mutableCopy] autorelease]]; + BOOL isIdentityNameNotEditable = (!anIdentity.hasCCache || [contextInfo isEqualToString:@"new"]); + NSString *identityString = ([contextInfo isEqualToString:@"new"]) ? @"" : anIdentity.identity; + [identityOptionsController setValue:identityString + forKeyPath:identity_string_keypath]; [identityOptionsController setValue:[NSNumber numberWithInteger:[KIMUtilities minValidLifetime]] forKeyPath:min_valid_keypath]; [identityOptionsController setValue:[NSNumber numberWithInteger:[KIMUtilities maxValidLifetime]] @@ -232,6 +263,8 @@ forKeyPath:min_renewable_keypath]; [identityOptionsController setValue:[NSNumber numberWithInteger:[KIMUtilities maxRenewableLifetime]] forKeyPath:max_renewable_keypath]; + [identityOptionsController setValue:[NSNumber numberWithBool:!isIdentityNameNotEditable] + forKeyPath:@"content.hasCCache"]; [validLifetimeSlider setIntegerValue: [[identityOptionsController valueForKeyPath:valid_lifetime_keypath] integerValue]]; @@ -254,19 +287,34 @@ kim_error err = KIM_NO_ERROR; if (returnCode != NSUserCancelledError) { if ([(NSString *)contextInfo isEqualToString:@"new"]) { - Identity *newIdentity = identityOptionsController.content; + Identity *newIdentity = [[Identity alloc] + initWithIdentity:[identityOptionsController valueForKeyPath:identity_string_keypath] + options:identityOptionsController.content]; + newIdentity.favorite = YES; + err = [identities addIdentity:newIdentity]; - + if (err) { NSLog(@"%s received error %@ trying to add identity %@", _cmd, [KIMUtilities stringForLastKIMError:err], [newIdentity description]); } + [newIdentity release]; [self saveOptions]; + } else if ([(NSString *)contextInfo isEqualToString:@"edit"]) { + Identity *editedIdentity = [[identityArrayController selectedObjects] lastObject]; + editedIdentity.favorite = YES; + editedIdentity.identity = [identityOptionsController valueForKeyPath:identity_string_keypath]; + editedIdentity.options = identityOptionsController.content; + [self saveOptions]; + } + } else { + [identityOptionsController setContent:nil]; } [sheet orderOut:self]; + } // --------------------------------------------------------------------------- @@ -289,7 +337,8 @@ b = [identityArrayController.content indexOfObject:anIdentity]; c = [identityArrayController.content count] - 1; - + + [identityArrayController setSelectionIndex: (b == NSNotFound) ? (a > c) ? c : a : b]; } diff --git a/src/kim/agent/mac/resources/English.lproj/SelectIdentity.xib b/src/kim/agent/mac/resources/English.lproj/SelectIdentity.xib index 38b494bd5..bda5885e6 100644 --- a/src/kim/agent/mac/resources/English.lproj/SelectIdentity.xib +++ b/src/kim/agent/mac/resources/English.lproj/SelectIdentity.xib @@ -8,8 +8,7 @@ 352.00 YES - - + YES @@ -29,7 +28,7 @@ 13 2 - {{279, 568}, {398, 260}} + {{516, 414}, {400, 273}} 1886913536 Select a Kerberos Identity @@ -38,7 +37,8 @@ View - {600, 600} + {800, 800} + {400, 273} 256 @@ -47,7 +47,7 @@ 266 - {{101, 213}, {280, 17}} + {{101, 226}, {282, 17}} YES @@ -83,7 +83,7 @@ 266 - {{101, 168}, {280, 37}} + {{101, 181}, {282, 37}} YES @@ -103,7 +103,7 @@ 289 - {{297, 12}, {87, 32}} + {{299, 12}, {87, 32}} YES @@ -124,7 +124,7 @@ 289 - {{215, 12}, {82, 32}} + {{217, 12}, {82, 32}} YES @@ -145,7 +145,7 @@ 268 - {{20, 176}, {64, 64}} + {{20, 189}, {64, 64}} BadgedImageView @@ -186,13 +186,13 @@ 256 - {356, 83} + {358, 96} YES 256 - {356, 17} + {358, 17} @@ -206,7 +206,7 @@ YES identityColumn - 1.740000e+02 + 1.760000e+02 4.000000e+01 1.000000e+03 @@ -327,7 +327,7 @@ YES - {{1, 17}, {356, 83}} + {{1, 17}, {358, 96}} @@ -361,7 +361,7 @@ YES - {{1, 0}, {356, 17}} + {{1, 0}, {358, 17}} @@ -370,7 +370,7 @@ - {{20, 59}, {358, 101}} + {{20, 59}, {360, 114}} 530 @@ -473,6 +473,7 @@ + 4 YES 2 YES @@ -481,11 +482,12 @@ - {398, 260} + {400, 273} - {{0, 0}, {1920, 1178}} - {600, 622} + {{0, 0}, {1440, 878}} + {400, 295} + {800, 822} @@ -495,6 +497,7 @@ isFavorite principalString favorite + identity Identity YES @@ -527,8 +530,9 @@ 266 - {{78, 306}, {338, 22}} + {{78, 306}, {329, 22}} + YES -1804468671 @@ -557,6 +561,7 @@ 268 {{17, 308}, {60, 17}} + YES 68288064 @@ -583,6 +588,7 @@ 266 {{24, 179}, {337, 25}} + YES 67501824 @@ -607,6 +613,7 @@ 268 {{13, 211}, {185, 17}} + YES 67239424 @@ -623,6 +630,7 @@ 266 {{23, 157}, {339, 14}} + YES 67239424 @@ -639,6 +647,7 @@ 268 {{13, 132}, {133, 17}} + YES 67239424 @@ -655,6 +664,7 @@ 266 {{42, 34}, {301, 25}} + YES 67501824 @@ -683,6 +693,7 @@ 268 {{24, 86}, {303, 18}} + YES 67239424 @@ -706,6 +717,7 @@ 268 {{24, 108}, {351, 18}} + YES 67239424 @@ -727,6 +739,7 @@ 268 {{24, 64}, {248, 18}} + YES 67239424 @@ -748,6 +761,7 @@ 266 {{41, 12}, {303, 14}} + YES 67239424 @@ -762,10 +776,12 @@ {{3, 3}, {387, 238}} + {{17, 56}, {393, 244}} + {0, 0} 67239424 @@ -789,9 +805,10 @@ 289 {{331, 12}, {82, 32}} + YES - 604110336 + 67239424 134217728 OK @@ -809,6 +826,7 @@ 289 {{249, 12}, {82, 32}} + YES 67239424 @@ -829,6 +847,7 @@ 289 {{129, 12}, {120, 32}} + YES 67239424 @@ -847,8 +866,9 @@ -2147483380 - {{75, 308}, {344, 17}} + {{75, 308}, {335, 17}} + YES 68288064 @@ -863,6 +883,7 @@ {427, 348} + {{0, 0}, {1280, 778}} {3.40282e+38, 3.40282e+38} @@ -886,11 +907,18 @@ identity renewable_lifetime valid_lifetime + renewal_lifetime + identity_string + canClickOK YES + + YES + hints.explanation + YES @@ -908,6 +936,9 @@ Identities + + KerberosTimeFormatter + @@ -1049,26 +1080,6 @@ 300245 - - - value: arrangedObjects.principalString - - - - - - value: arrangedObjects.principalString - value - arrangedObjects.principalString - - NSConditionallySetsEditable - - - 2 - - - 300246 - delegate @@ -1106,7 +1117,7 @@ arrangedObjects.expirationDate NSConditionallySetsEditable - + 2 @@ -1154,22 +1165,6 @@ 300328 - - - enabled: selection.isRenewable - - - - - - enabled: selection.isRenewable - enabled - selection.isRenewable - 2 - - - 300356 - identityOptionsController @@ -1492,22 +1487,6 @@ 300486 - - - value: selection.identity - - - - - - value: selection.identity - value - selection.identity - 2 - - - 300487 - value: selection.identity @@ -1521,7 +1500,7 @@ selection.identity NSContinuouslyUpdatesValue - + 2 @@ -1578,35 +1557,179 @@ - value: selection.renewable_lifetime + value: selection.valid_lifetime + + + + + + value: selection.valid_lifetime + value + selection.valid_lifetime + 2 + + + 300494 + + + + value: selection.hints.explanation + + + + + + value: selection.hints.explanation + value + selection.hints.explanation + 2 + + + 300495 + + + + glueController + + + + 300496 + + + + enabled: selection.renewable + + + + + + enabled: selection.renewable + enabled + selection.renewable + 2 + + + 300497 + + + + formatter + + + + 300499 + + + + formatter + + + + 300500 + + + + value: selection.renewal_lifetime - value: selection.renewable_lifetime + value: selection.renewal_lifetime value - selection.renewable_lifetime + selection.renewal_lifetime 2 - 300493 + 300501 + + + + longTimeFormatter + + + + 300502 + + + + shortTimeFormatter + + + + 300503 - value: selection.valid_lifetime - + value: arrangedObjects.identity + + + + + + value: arrangedObjects.identity + value + arrangedObjects.identity + + NSConditionallySetsEditable + + + 2 + + + 300504 + + + + value: selection.identity_string + - + - value: selection.valid_lifetime + value: selection.identity_string value - selection.valid_lifetime + selection.identity_string 2 - 300494 + 300506 + + + + value: selection.identity_string + + + + + + value: selection.identity_string + value + selection.identity_string + + NSContinuouslyUpdatesValue + + + 2 + + + 300509 + + + + enabled: selection.canClickOK + + + + + + enabled: selection.canClickOK + enabled + selection.canClickOK + 2 + + + 300510 @@ -1652,9 +1775,9 @@ - + @@ -1735,7 +1858,7 @@ 300196 - Time Formatter + Short Time Formatter 300206 @@ -2163,6 +2286,12 @@ + + 300498 + + + Long Time Formatter + @@ -2247,6 +2376,7 @@ 300432.IBPluginDependency 300462.IBPluginDependency 300485.IBPluginDependency + 300498.IBPluginDependency 5.IBEditorWindowLastContentRect 5.IBPluginDependency 5.IBWindowTemplateEditedContentRect @@ -2334,7 +2464,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{535, 82}, {203, 103}} + {{610, 271}, {203, 103}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2342,16 +2472,17 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{508, 407}, {398, 260}} com.apple.InterfaceBuilder.CocoaPlugin - {{508, 407}, {398, 260}} + {{574, 332}, {400, 273}} + com.apple.InterfaceBuilder.CocoaPlugin + {{574, 332}, {400, 273}} {{503, 256}, {419, 465}} - - {600, 600} - {419, 298} + + {800, 800} + {400, 273} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2378,7 +2509,7 @@ - 300494 + 300510 @@ -2463,8 +2594,10 @@ identityOptionsWindow identityTableView kerberosIconImageView + longTimeFormatter renewableLifetimeSlider selectIdentityButton + shortTimeFormatter staticIdentityField ticketOptionsOkButton validLifetimeSlider @@ -2484,8 +2617,10 @@ NSWindow NSTableView BadgedImageView + KerberosTimeFormatter NSSlider NSButton + KerberosTimeFormatter NSTextField NSButton NSSlider