-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSABnzbdDropDelegate.m
77 lines (61 loc) · 1.88 KB
/
SABnzbdDropDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// SABnzbdDropDelegate.m
// SABnzbdDropTarget
//
// Created by Thomas Schoendorfer on 10-10-08.
// Copyright 2010 Thomas Schoendorfer. All rights reserved.
//
#import "SABnzbdDropDelegate.h"
@implementation SABnzbdDropDelegate
@synthesize client;
- (id)init {
if(self = [super init]) {
classArray = [[NSArray arrayWithObject:[NSURL class]] retain];
options = [[NSDictionary alloc] init];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
client = [[SABnzbdClient alloc] initWithConnectionDetails:[defaults URLForKey:HostPrefKey]
withApiKey:[defaults objectForKey:APIKeyPrefKey]];
[defaults addObserver:self
forKeyPath:HostPrefKey
options:0
context:nil];
[defaults addObserver:self
forKeyPath:APIKeyPrefKey
options:0
context:nil];
}
return self;
}
- (void)didDrop:(NSPasteboard *)pasteboard {
if ([pasteboard canReadObjectForClasses:classArray options:options]) {
NSArray *objectsToPaste = [pasteboard readObjectsForClasses:classArray options:options];
NSURL *pastedURL = [objectsToPaste objectAtIndex:0];
NSLog(@"Pasted URL: %@", pastedURL);
if(![client addNzb:pastedURL])
NSLog(@"Failed to add pasted nzb");
else {
NSLog(@"Added pasted nzb succesfully");
}
}
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if([keyPath isEqualToString:HostPrefKey]) {
NSLog(@"Updated client host url");
[client setHost:[defaults URLForKey:HostPrefKey]];
}
if ([keyPath isEqualToString:APIKeyPrefKey]) {
NSLog(@"Updated client api key");
[client setApiKey:[defaults objectForKey:APIKeyPrefKey]];
}
}
-(void) dealloc {
[classArray release];
[options release];
[client release];
[super dealloc];
}
@end