Permalink
Browse files

Prettied up the pairing code window

Added a connection delegate handler for the client cancelling the pairing
  • Loading branch information...
1 parent 280826d commit 9147ec0a5bc457cd90119635d3c6fca65c87dd7c Michael Fey committed Aug 18, 2010
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 1330480E121C7E98007A3AAE /* PairingCodeFieldBackground.png in Resources */ = {isa = PBXBuildFile; fileRef = 1330480C121C7E98007A3AAE /* PairingCodeFieldBackground.png */; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
B6345A9711D458B4005D1A9A /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B691FB5E10ED867C00207210 /* CoreData.framework */; };
B6345A9811D458BA005D1A9A /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B6345A4E11D4580D005D1A9A /* QuartzCore.framework */; };
@@ -45,6 +46,7 @@
/* Begin PBXFileReference section */
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
+ 1330480C121C7E98007A3AAE /* PairingCodeFieldBackground.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = PairingCodeFieldBackground.png; sourceTree = "<group>"; };
13337CFE121255150040AF6A /* ServerBrowser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServerBrowser.h; sourceTree = "<group>"; };
13337CFF121255150040AF6A /* ServerBrowser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ServerBrowser.m; sourceTree = "<group>"; };
13337D00121255150040AF6A /* ServerBrowserDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServerBrowserDelegate.h; sourceTree = "<group>"; };
@@ -187,6 +189,7 @@
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
+ 1330480C121C7E98007A3AAE /* PairingCodeFieldBackground.png */,
B691FB3E10ED855F00207210 /* InfoPlist.strings */,
B691FB4010ED855F00207210 /* MainMenu.xib */,
);
@@ -361,6 +364,7 @@
B691FB8C10ED875800207210 /* PairingWindow.xib in Resources */,
B63F9C2211B2EA2800811EB1 /* menubar.png in Resources */,
B6DEEC0611BA16A90036A137 /* icon.icns in Resources */,
+ 1330480E121C7E98007A3AAE /* PairingCodeFieldBackground.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -30,19 +30,25 @@
@protocol PairingCodeDelegate
-- (void)pairingCodeWindowController:(id)controller codeEntered:(NSString*)code;
-- (void)pairingCodeWindowControllerCancelled:(PairingCodeWindowController*)controller;
+- (void)pairingCodeWindowController:(id)controller codeEntered:(NSString *)code;
+- (void)pairingCodeWindowControllerCancelled:(PairingCodeWindowController *)controller;
@end
@interface PairingCodeWindowController : NSWindowController
{
- NSTextField *textField;
+ NSTextField *textField1;
+ NSTextField *textField2;
+ NSTextField *textField3;
+ NSTextField *textField4;
id<PairingCodeDelegate> delegate;
}
-@property (assign) IBOutlet NSTextField *textField;
+@property (retain) IBOutlet NSTextField *textField1;
+@property (retain) IBOutlet NSTextField *textField2;
+@property (retain) IBOutlet NSTextField *textField3;
+@property (retain) IBOutlet NSTextField *textField4;
@property (assign) id<PairingCodeDelegate> delegate;
- (id)initWithDelegate:(id<PairingCodeDelegate>)delegate;
@@ -37,7 +37,9 @@ @implementation PairingCodeWindowController
- (id)initWithDelegate:(id<PairingCodeDelegate>)aDelegate;
{
- if (![super initWithWindowNibName:@"PairingWindow"]) return nil;
+ if (![super initWithWindowNibName:@"PairingWindow"]) {
+ return nil;
+ }
[self setDelegate:aDelegate];
@@ -51,20 +53,61 @@ - (void)windowDidLoad
[NSApp activateIgnoringOtherApps:YES];
[[self window] center];
- [[self textField] setStringValue:@""];
+ [[self textField1] setStringValue:@""];
+ [[self textField2] setStringValue:@""];
+ [[self textField3] setStringValue:@""];
+ [[self textField4] setStringValue:@""];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name:NSControlTextDidChangeNotification object:[self textField1]];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name:NSControlTextDidChangeNotification object:[self textField2]];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name:NSControlTextDidChangeNotification object:[self textField3]];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name:NSControlTextDidChangeNotification object:[self textField4]];
+
[[self window] makeKeyAndOrderFront:self];
- [[self textField] becomeFirstResponder];
+ [[self textField1] becomeFirstResponder];
+}
+
+- (void)textDidChange:(NSNotification *)aNotification
+{
+ NSTextField *textField = [aNotification object];
+ if ([textField isEqual:[self textField1]]) {
+ if ([[textField stringValue] length] > 0) {
+ [[textField nextKeyView] becomeFirstResponder];
+ }
+ } else if ([textField isEqual:[self textField2]]) {
+ if ([[textField stringValue] length] > 0) {
+ [[textField nextKeyView] becomeFirstResponder];
+ } else {
+ [[self textField1] becomeFirstResponder];
+ }
+ } else if ([textField isEqual:[self textField3]]) {
+ if ([[textField stringValue] length] > 0) {
+ [[textField nextKeyView] becomeFirstResponder];
+ } else {
+ [[self textField2] becomeFirstResponder];
+ }
+ } else if ([textField isEqual:[self textField4]]) {
+ if ([[textField stringValue] length] == 0) {
+ [[self textField3] becomeFirstResponder];
+ }
+ }
}
-- (void) dealloc
+- (void)dealloc
{
+ [textField1 release], textField1 = nil;
+ [textField2 release], textField2 = nil;
+ [textField3 release], textField3 = nil;
+ [textField4 release], textField4 = nil;
+
DLog(@"window released cleanly");
[super dealloc];
}
- (IBAction)enterCode:(id)sender;
{
- [[self delegate] pairingCodeWindowController:self codeEntered:[[self textField] stringValue]];
+ NSString *pairingCode = [[[self textField1] stringValue] stringByAppendingFormat:@"%@%@%@", [[self textField2] stringValue], [[self textField3] stringValue], [[self textField4] stringValue]];
+ [[self delegate] pairingCodeWindowController:self codeEntered:pairingCode];
}
- (IBAction)cancel:(id)sender;
@@ -73,7 +116,7 @@ - (IBAction)cancel:(id)sender;
[NSApp hide:self];
}
-- (CAKeyframeAnimation*)shakeAnimation:(NSRect)frame
+- (CAKeyframeAnimation *)shakeAnimation:(NSRect)frame
{
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"frame"];
@@ -93,11 +136,17 @@ - (void)refuseCode;
NSRect frame = [[self window] frame];
[[self window] setAnimations:[NSDictionary dictionaryWithObject:[self shakeAnimation:frame] forKey:@"frame"]];
[[[self window] animator] setFrame:frame display:NO];
- [[self textField] setStringValue:@""];
- [[self textField] becomeFirstResponder];
+ [[self textField1] setStringValue:@""];
+ [[self textField2] setStringValue:@""];
+ [[self textField3] setStringValue:@""];
+ [[self textField4] setStringValue:@""];
+ [[self textField1] becomeFirstResponder];
}
-@synthesize textField;
+@synthesize textField1;
+@synthesize textField2;
+@synthesize textField3;
+@synthesize textField4;
@synthesize delegate;
@end
@@ -503,6 +503,13 @@ - (BOOL)connection:(BLIPConnection *)connection receivedRequest:(BLIPRequest *)r
[self performSelector:@selector(performSync) withObject:nil afterDelay:0.01];
return YES;
+ case zsActionCancelPairing:
+ DLog(@"%s zsActionCancelPairing", __PRETTY_FUNCTION__);
+ if (codeController) {
+ [[codeController window] orderOut:nil];
+ }
+ return YES;
+
default:
DLog(@"%s default", __PRETTY_FUNCTION__);
ALog(@"Unknown action received: %i", action);
Oops, something went wrong.

0 comments on commit 9147ec0

Please sign in to comment.