Make all dialogs beyond the change password sheet also appear as sheets
authorJustin Anderson <jander@mit.edu>
Fri, 17 Oct 2008 22:08:12 +0000 (22:08 +0000)
committerJustin Anderson <jander@mit.edu>
Fri, 17 Oct 2008 22:08:12 +0000 (22:08 +0000)
ticket:6145

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20894 dc483132-0cff-0310-8789-dd5450dbe970

src/kim/agent/mac/AuthenticationController.h
src/kim/agent/mac/AuthenticationController.m
src/kim/agent/mac/IPCClient.m
src/kim/agent/mac/resources/English.lproj/SelectIdentity.xib

index 2ee82b93a1687206fd3d2464bbf4fdda02c83d46..3b223f760659f18c97ec85219fd4aab2941551d9 100644 (file)
@@ -65,6 +65,7 @@
 
     IBOutlet NSWindow *ticketOptionsSheet;
     IBOutlet NSObjectController *ticketOptionsController;
+    BOOL visibleAsSheet;
     
     IBOutlet NSSlider *validLifetimeSlider;
     IBOutlet NSSlider *renewableLifetimeSlider;
 
 - (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;
 - (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;
index ad665fb2954237281141ad0e8e75b4e4d02b9558..de49b11de50a893a5468bb0db13b24c073c900be 100644 (file)
@@ -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;
     
     [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];
 
     [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];
     
 
     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;
     [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];
     
     [self swapView:samView];
     
-    [self showWindow:nil];
     [[self window] makeFirstResponder:samPromptField];
+    [self showWithParent:parentWindow];
 }
 
 - (void) showChangePassword: (NSWindow *) parentWindow
     
     [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];
     [self hideSpinny];
     [self swapView:errorView];
     
-    [self showWindow:nil];
+    [self showWithParent:parentWindow];
 }
 
 - (IBAction) checkboxDidChange: (id) sender
     [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];
 }
index 51bbf02ddfa7775c848282451e4fb0251d7dc6d1..8b9eb219420e602d7f026e1928324c06c5133ef0 100644 (file)
@@ -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];
 }
 
index f1822af44eb728b2318121f55c354a23bd476416..1a5ff962ee26f321ba9cc0ef148b46b9b4949442 100644 (file)
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>{{495, 457}, {500, 273}}</string>
                                        <reference ref="9"/>
-                                       <reference ref="9"/>
+                                       <integer value="0"/>
                                        <string>{{503, 256}, {419, 465}}</string>
                                        <reference ref="9"/>
                                        <reference ref="9"/>