summaryrefslogtreecommitdiffabout
path: root/pumpkin/ConfirmRequest.m
authorMichael Krelin <hacker@klever.net>2012-12-08 21:19:17 (UTC)
committer Michael Krelin <hacker@klever.net>2012-12-11 21:59:29 (UTC)
commit8808689fe340bec6e90ab13dd502292b0579cf1f (patch) (side-by-side diff)
tree45b7c863151341f687b74e40bffcbd7ab5468783 /pumpkin/ConfirmRequest.m
parent6e7e413ca364d79673e523c09767c18e7cff1bec (diff)
downloadpumpkin-osx/0.0.zip
pumpkin-osx/0.0.tar.gz
pumpkin-osx/0.0.tar.bz2
initial osx portosx/0.0
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'pumpkin/ConfirmRequest.m') (more/less context) (ignore whitespace changes)
-rw-r--r--pumpkin/ConfirmRequest.m57
1 files changed, 57 insertions, 0 deletions
diff --git a/pumpkin/ConfirmRequest.m b/pumpkin/ConfirmRequest.m
new file mode 100644
index 0000000..73dfcc1
--- a/dev/null
+++ b/pumpkin/ConfirmRequest.m
@@ -0,0 +1,57 @@
+
+#import "ConfirmRequest.h"
+#import "StringsAttached.h"
+
+@implementation ConfirmRequest
+@synthesize remoteHost;
+@synthesize remoteAction;
+@synthesize fileName;
+@synthesize fileExists;
+@synthesize isWriteRequest;
+
+-(void)sentence:(int)v {
+ [timeout invalidate], [timeout release], timeout=nil;
+ [xfer goOnWithVerdict:v];
+ [self.window performClose:nil];
+ [[[NSUserDefaultsController sharedUserDefaultsController] values]
+ setValue:@(v) forKey:isWriteRequest?@"WRQ.lastSentence":@"RRQ.lastSentence"];
+ [self release];
+}
+
+- (IBAction)letItBe:(id)sender { [self sentence:verdictAllow]; }
+- (IBAction)deny:(id)sender { [self sentence:verdictDeny]; }
+- (IBAction)rename:(id)sender { [self sentence:verdictRename]; }
+- (void)timeout { [self sentence:verdictDefault]; }
+
+- (ConfirmRequest*) initWithXfer:(XFer *)x {
+ enum TFTPOp op = x.initialPacket.op;
+ NSAssert(op==tftpOpRRQ || op==tftpOpWRQ,@"Invalid request to confirm");
+ if(!(self=[super initWithWindowNibName:@"ConfirmRequest"])) return self;
+ isWriteRequest = op==tftpOpWRQ;
+ remoteHost = [[NSString stringWithHostAddress:x.peer] retain];
+ remoteAction = isWriteRequest?@"tries to send you":@"requests the file";
+ fileName = x.xferFilename;
+ fileExists = [[NSFileManager defaultManager] fileExistsAtPath:x.localFile];
+ xfer = [x retain];
+ switch([[[[NSUserDefaultsController sharedUserDefaultsController] values] valueForKey:isWriteRequest?@"WRQ.lastSentence":@"RRQ.lastSentence"] intValue]) {
+ case verdictAllow: self.window.initialFirstResponder = self.allowButton; break;
+ case verdictDeny: self.window.initialFirstResponder = self.denyButton; break;
+ case verdictRename: self.window.initialFirstResponder = self.renameButton; break;
+ }
+ [self.window makeKeyAndOrderFront:nil];
+ timeout = [[NSTimer scheduledTimerWithTimeInterval:[[[[NSUserDefaultsController sharedUserDefaultsController] values] valueForKey:@"confirmationTimeout"] intValue] target:self selector:@selector(timeout) userInfo:nil repeats:NO] retain];
+ return self;
+}
+
+- (void) dealloc {
+ if(timeout) [timeout invalidate], [timeout release];
+ if(remoteHost) [remoteHost release];
+ if(xfer) [xfer release];
+ [super dealloc];
+}
+
++ (void) confirmationWithXfer:(XFer *)x {
+ [[self alloc] initWithXfer:x];
+}
+
+@end