From 451a8448222f86f3a320548b80074b8bcc082e52 Mon Sep 17 00:00:00 2001 From: Justin Anderson Date: Fri, 17 Oct 2008 22:08:12 +0000 Subject: [PATCH] Make all dialogs beyond the change password sheet also appear as sheets ticket:6145 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20894 dc483132-0cff-0310-8789-dd5450dbe970 --- src/kim/agent/mac/AuthenticationController.h | 17 +- src/kim/agent/mac/AuthenticationController.m | 152 ++++++++++-------- src/kim/agent/mac/IPCClient.m | 65 ++++++-- .../English.lproj/SelectIdentity.xib | 2 +- 4 files changed, 147 insertions(+), 89 deletions(-) diff --git a/src/kim/agent/mac/AuthenticationController.h b/src/kim/agent/mac/AuthenticationController.h index 2ee82b93a..3b223f760 100644 --- a/src/kim/agent/mac/AuthenticationController.h +++ b/src/kim/agent/mac/AuthenticationController.h @@ -65,6 +65,7 @@ IBOutlet NSWindow *ticketOptionsSheet; IBOutlet NSObjectController *ticketOptionsController; + BOOL visibleAsSheet; IBOutlet NSSlider *validLifetimeSlider; IBOutlet NSSlider *renewableLifetimeSlider; @@ -79,12 +80,12 @@ - (void) setContent: (NSMutableDictionary *) newContent; -- (void) showEnterIdentity; -- (void) showAuthPrompt; -- (void) showEnterPassword; -- (void) showSAM; +- (void) showEnterIdentity: (NSWindow *) parentWindow; +- (void) showAuthPrompt: (NSWindow *) parentWindow; +- (void) showEnterPassword: (NSWindow *) parentWindow; +- (void) showSAM: (NSWindow *) parentWindow; - (void) showChangePassword: (NSWindow *) parentWindow; -- (void) showError; +- (void) showError: (NSWindow *) parentWindow; - (IBAction) cancel: (id) sender; - (IBAction) enterIdentity: (id) sender; @@ -99,9 +100,9 @@ - (IBAction) cancelTicketOptions: (id) sender; - (IBAction) saveTicketOptions: (id) sender; -- (void) changePasswordSheetDidEnd: (NSWindow *) sheet - returnCode: (int) returnCode - contextInfo: (void *) contextInfo; +- (void) authSheetDidEnd: (NSWindow *) sheet + returnCode: (int) returnCode + contextInfo: (void *) contextInfo; - (void) ticketOptionsSheetDidEnd: (NSWindow *) sheet returnCode: (int) returnCode contextInfo: (void *) contextInfo; diff --git a/src/kim/agent/mac/AuthenticationController.m b/src/kim/agent/mac/AuthenticationController.m index ad665fb29..de49b11de 100644 --- a/src/kim/agent/mac/AuthenticationController.m +++ b/src/kim/agent/mac/AuthenticationController.m @@ -77,6 +77,8 @@ // We need to float over the loginwindow and SecurityAgent so use its hardcoded level. [[self window] setLevel:NSScreenSaverWindowLevel]; + visibleAsSheet = NO; + lifetimeFormatter.displaySeconds = NO; lifetimeFormatter.displayShortFormat = NO; @@ -148,13 +150,80 @@ [super showWindow:sender]; } +- (void) showWithParent: (NSWindow *) parentWindow +{ + // attach as sheet if given a parentWindow + if (parentWindow && !visibleAsSheet) { + [NSApp beginSheet:[self window] + modalForWindow:parentWindow + modalDelegate:self + didEndSelector:@selector(authSheetDidEnd:returnCode:contextInfo:) + contextInfo:NULL]; + } + // else, display as normal + else { + [self showWindow:nil]; + } +} + +- (void) windowWillBeginSheet: (NSNotification *) notification +{ + visibleAsSheet = YES; +} + +- (void) windowDidEndSheet: (NSNotification *) notification +{ + visibleAsSheet = NO; +} + - (void) setContent: (NSMutableDictionary *) newContent { [self window]; // wake up the nib connections [glueController setContent:newContent]; } -- (void) showEnterIdentity +- (void) swapView: (NSView *) aView +{ + NSWindow *theWindow = [self window]; + NSRect windowFrame; + NSRect viewFrame; + + [[containerView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)]; + + windowFrame = [theWindow frame]; + viewFrame = [theWindow frameRectForContentRect:[aView frame]]; + windowFrame.origin.y -= viewFrame.size.height - windowFrame.size.height; + + windowFrame.size.width = viewFrame.size.width; + windowFrame.size.height = viewFrame.size.height; + + [theWindow setFrame:windowFrame display:YES animate:YES]; + + [containerView addSubview:aView]; + +} + +- (void) showSpinny +{ + [enterSpinny startAnimation: nil]; + [passwordSpinny startAnimation: nil]; + [samSpinny startAnimation: nil]; + [changePasswordSpinny startAnimation: nil]; + [glueController setValue:[NSNumber numberWithBool:NO] + forKeyPath:accepting_input_keypath]; +} + +- (void) hideSpinny +{ + [enterSpinny stopAnimation: nil]; + [passwordSpinny stopAnimation: nil]; + [samSpinny stopAnimation: nil]; + [changePasswordSpinny stopAnimation: nil]; + [glueController setValue:[NSNumber numberWithBool:YES] + forKeyPath:accepting_input_keypath]; +} + +- (void) showEnterIdentity: (NSWindow *) parentWindow { kim_error err = KIM_NO_ERROR; NSWindow *theWindow = [self window]; @@ -224,10 +293,10 @@ [theWindow makeFirstResponder:identityField]; - [[self window] makeKeyAndOrderFront:nil]; + [self showWithParent: parentWindow]; } -- (void) showAuthPrompt +- (void) showAuthPrompt: (NSWindow *) parentWindow { uint32_t type = [[glueController valueForKeyPath:@"content.prompt_type"] unsignedIntegerValue]; @@ -235,14 +304,14 @@ switch (type) { case kim_prompt_type_password : - [self showEnterPassword]; break; + [self showEnterPassword: parentWindow]; break; case kim_prompt_type_preauth : default : - [self showSAM]; break; + [self showSAM: parentWindow]; break; } } -- (void) showEnterPassword +- (void) showEnterPassword: (NSWindow *) parentWindow { CGFloat shrinkBy; NSRect frame; @@ -282,51 +351,10 @@ [self swapView:passwordView]; [theWindow makeFirstResponder:passwordField]; - [self showWindow:nil]; -} - -- (void) swapView: (NSView *) aView -{ - NSWindow *theWindow = [self window]; - NSRect windowFrame; - NSRect viewFrame; - - [[containerView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)]; - - windowFrame = [theWindow frame]; - viewFrame = [theWindow frameRectForContentRect:[aView frame]]; - windowFrame.origin.y -= viewFrame.size.height - windowFrame.size.height; - - windowFrame.size.width = viewFrame.size.width; - windowFrame.size.height = viewFrame.size.height; - - [theWindow setFrame:windowFrame display:YES animate:YES]; - - [containerView addSubview:aView]; - + [self showWithParent:parentWindow]; } -- (void) showSpinny -{ - [enterSpinny startAnimation: nil]; - [passwordSpinny startAnimation: nil]; - [samSpinny startAnimation: nil]; - [changePasswordSpinny startAnimation: nil]; - [glueController setValue:[NSNumber numberWithBool:NO] - forKeyPath:accepting_input_keypath]; -} - -- (void) hideSpinny -{ - [enterSpinny stopAnimation: nil]; - [passwordSpinny stopAnimation: nil]; - [samSpinny stopAnimation: nil]; - [changePasswordSpinny stopAnimation: nil]; - [glueController setValue:[NSNumber numberWithBool:YES] - forKeyPath:accepting_input_keypath]; -} - -- (void) showSAM +- (void) showSAM: (NSWindow *) parentWindow { // set badge [samBadge setBadgePath:associatedClient.path]; @@ -336,8 +364,8 @@ [self swapView:samView]; - [self showWindow:nil]; [[self window] makeFirstResponder:samPromptField]; + [self showWithParent:parentWindow]; } - (void) showChangePassword: (NSWindow *) parentWindow @@ -381,22 +409,12 @@ [self swapView:changePasswordView]; - // attach as sheet if given a parentWindow - if (parentWindow) { - [NSApp beginSheet:theWindow - modalForWindow:parentWindow - modalDelegate:self - didEndSelector:@selector(changePasswordSheetDidEnd:returnCode:contextInfo:) - contextInfo:NULL]; - } - // else, display as normal - else { - [self showWindow:nil]; - } + [self showWithParent:parentWindow]; + [theWindow makeFirstResponder:oldPasswordField]; } -- (void) showError +- (void) showError: (NSWindow *) parentWindow { // wake up the nib connections and adjust window size [self window]; @@ -406,7 +424,7 @@ [self hideSpinny]; [self swapView:errorView]; - [self showWindow:nil]; + [self showWithParent:parentWindow]; } - (IBAction) checkboxDidChange: (id) sender @@ -496,9 +514,9 @@ [NSApp endSheet:ticketOptionsSheet]; } -- (void) changePasswordSheetDidEnd: (NSWindow *) sheet - returnCode: (int) returnCode - contextInfo: (void *) contextInfo +- (void) authSheetDidEnd: (NSWindow *) sheet + returnCode: (int) returnCode + contextInfo: (void *) contextInfo { [sheet orderOut:nil]; } diff --git a/src/kim/agent/mac/IPCClient.m b/src/kim/agent/mac/IPCClient.m index 51bbf02dd..8b9eb2194 100644 --- a/src/kim/agent/mac/IPCClient.m +++ b/src/kim/agent/mac/IPCClient.m @@ -33,7 +33,6 @@ enum krb_agent_client_state { ipc_client_state_init, ipc_client_state_enter, ipc_client_state_select, - ipc_client_state_select_change_password, ipc_client_state_auth_prompt, ipc_client_state_change_password, ipc_client_state_handle_error, @@ -128,12 +127,11 @@ enum krb_agent_client_state { else if (self.state == ipc_client_state_auth_prompt) { [KerberosAgentListener didPromptForAuth:self.currentInfo error:err]; } - else if (self.state == ipc_client_state_change_password || - self.state == ipc_client_state_select_change_password) { + else if (self.state == ipc_client_state_change_password) { [KerberosAgentListener didChangePassword:self.currentInfo error:err]; } - if (self.state == ipc_client_state_select_change_password) { + if ([[self.selectController window] isVisible]) { self.state = ipc_client_state_select; } else { @@ -178,11 +176,18 @@ enum krb_agent_client_state { - (kim_error) enterIdentity: (NSDictionary *) info { + NSWindow *parentWindow = nil; + [self.currentInfo addEntriesFromDictionary:info]; + + if ([[self.selectController window] isVisible]) { + parentWindow = [selectController window]; + } + self.state = ipc_client_state_enter; [self.authController setContent:self.currentInfo]; - [self.authController showEnterIdentity]; + [self.authController showEnterIdentity:parentWindow]; return 0; } @@ -196,7 +201,7 @@ enum krb_agent_client_state { [self.currentInfo setObject:[NSNumber numberWithBool:wantsChangePassword] forKey:@"wants_change_password"]; [KerberosAgentListener didEnterIdentity:self.currentInfo error:0]; - if (self.state == ipc_client_state_select_change_password) { + if ([[self.selectController window] isVisible]) { self.state = ipc_client_state_select; } else { @@ -206,11 +211,18 @@ enum krb_agent_client_state { - (kim_error) promptForAuth: (NSDictionary *) info { + NSWindow *parentWindow = nil; + [self.currentInfo addEntriesFromDictionary:info]; + + if ([[self.selectController window] isVisible]) { + parentWindow = [selectController window]; + } + self.state = ipc_client_state_auth_prompt; [self.authController setContent:self.currentInfo]; - [self.authController showAuthPrompt]; + [self.authController showAuthPrompt:parentWindow]; return 0; } @@ -220,6 +232,13 @@ enum krb_agent_client_state { [self.currentInfo setObject:responseString forKey:@"prompt_response"]; [self.currentInfo setObject:saveResponse forKey:@"save_response"]; [KerberosAgentListener didPromptForAuth:self.currentInfo error:0]; + + if ([[self.selectController window] isVisible]) { + self.state = ipc_client_state_select; + } + else { + self.state = ipc_client_state_idle; + } } - (kim_error) changePassword: (NSDictionary *) info @@ -228,13 +247,11 @@ enum krb_agent_client_state { [self.currentInfo addEntriesFromDictionary:info]; - if (self.state == ipc_client_state_select) { - self.state = ipc_client_state_select_change_password; + if ([[self.selectController window] isVisible]) { parentWindow = [selectController window]; } - else { - self.state = ipc_client_state_change_password; - } + + self.state = ipc_client_state_change_password; [self.authController setContent:self.currentInfo]; [self.authController showChangePassword:parentWindow]; @@ -249,23 +266,45 @@ enum krb_agent_client_state { [self.currentInfo setObject:oldPassword forKey:@"old_password"]; [self.currentInfo setObject:newPassword forKey:@"new_password"]; [self.currentInfo setObject:verifyPassword forKey:@"verify_password"]; + + if ([[self.selectController window] isVisible]) { + self.state = ipc_client_state_select; + } + else { + self.state = ipc_client_state_idle; + } + [KerberosAgentListener didChangePassword:self.currentInfo error:0]; } - (kim_error) handleError: (NSDictionary *) info { + NSWindow *parentWindow = nil; + [self.currentInfo addEntriesFromDictionary:info]; + + if ([[self.selectController window] isVisible]) { + parentWindow = [selectController window]; + } + self.state = ipc_client_state_handle_error; [self.authController setContent:self.currentInfo]; - [self.authController showError]; + [self.authController showError:parentWindow]; return 0; } - (void) didHandleError { + if ([[self.selectController window] isVisible]) { + self.state = ipc_client_state_select; + } + else { + self.state = ipc_client_state_idle; + } + [KerberosAgentListener didHandleError:self.currentInfo error:0]; } diff --git a/src/kim/agent/mac/resources/English.lproj/SelectIdentity.xib b/src/kim/agent/mac/resources/English.lproj/SelectIdentity.xib index f1822af44..1a5ff962e 100644 --- a/src/kim/agent/mac/resources/English.lproj/SelectIdentity.xib +++ b/src/kim/agent/mac/resources/English.lproj/SelectIdentity.xib @@ -2665,7 +2665,7 @@ com.apple.InterfaceBuilder.CocoaPlugin {{495, 457}, {500, 273}} - + {{503, 256}, {419, 465}} -- 2.26.2