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) (unidiff)
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 @@
1
2#import "ConfirmRequest.h"
3#import "StringsAttached.h"
4
5@implementation ConfirmRequest
6@synthesize remoteHost;
7@synthesize remoteAction;
8@synthesize fileName;
9@synthesize fileExists;
10@synthesize isWriteRequest;
11
12-(void)sentence:(int)v {
13 [timeout invalidate], [timeout release], timeout=nil;
14 [xfer goOnWithVerdict:v];
15 [self.window performClose:nil];
16 [[[NSUserDefaultsController sharedUserDefaultsController] values]
17 setValue:@(v) forKey:isWriteRequest?@"WRQ.lastSentence":@"RRQ.lastSentence"];
18 [self release];
19}
20
21- (IBAction)letItBe:(id)sender { [self sentence:verdictAllow]; }
22- (IBAction)deny:(id)sender { [self sentence:verdictDeny]; }
23- (IBAction)rename:(id)sender { [self sentence:verdictRename]; }
24- (void)timeout { [self sentence:verdictDefault]; }
25
26- (ConfirmRequest*) initWithXfer:(XFer *)x {
27 enum TFTPOp op = x.initialPacket.op;
28 NSAssert(op==tftpOpRRQ || op==tftpOpWRQ,@"Invalid request to confirm");
29 if(!(self=[super initWithWindowNibName:@"ConfirmRequest"])) return self;
30 isWriteRequest = op==tftpOpWRQ;
31 remoteHost = [[NSString stringWithHostAddress:x.peer] retain];
32 remoteAction = isWriteRequest?@"tries to send you":@"requests the file";
33 fileName = x.xferFilename;
34 fileExists = [[NSFileManager defaultManager] fileExistsAtPath:x.localFile];
35 xfer = [x retain];
36 switch([[[[NSUserDefaultsController sharedUserDefaultsController] values] valueForKey:isWriteRequest?@"WRQ.lastSentence":@"RRQ.lastSentence"] intValue]) {
37 case verdictAllow: self.window.initialFirstResponder = self.allowButton; break;
38 case verdictDeny: self.window.initialFirstResponder = self.denyButton; break;
39 case verdictRename: self.window.initialFirstResponder = self.renameButton; break;
40 }
41 [self.window makeKeyAndOrderFront:nil];
42 timeout = [[NSTimer scheduledTimerWithTimeInterval:[[[[NSUserDefaultsController sharedUserDefaultsController] values] valueForKey:@"confirmationTimeout"] intValue] target:self selector:@selector(timeout) userInfo:nil repeats:NO] retain];
43 return self;
44}
45
46- (void) dealloc {
47 if(timeout) [timeout invalidate], [timeout release];
48 if(remoteHost) [remoteHost release];
49 if(xfer) [xfer release];
50 [super dealloc];
51}
52
53+ (void) confirmationWithXfer:(XFer *)x {
54 [[self alloc] initWithXfer:x];
55}
56
57@end