forked from mipstian/catch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCTCPreferencesController.m
88 lines (69 loc) · 2.83 KB
/
CTCPreferencesController.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
78
79
80
81
82
83
84
85
86
87
88
#import "CTCPreferencesController.h"
#import "CTCDefaults.h"
#import "CTCScheduler.h"
#import "NSWindow+ShakeAnimation.h"
@interface CTCPreferencesController ()
@property (weak) IBOutlet NSImageView *feedURLWarningImageView;
@property (weak) IBOutlet NSImageView *torrentsSavePathWarningImageView;
@end
@implementation CTCPreferencesController
- (void)awakeFromNib {
[self showFeeds:self];
// If the configuration isn't valid, pop up immediately
if (!CTCDefaults.isConfigurationValid) [self showWindow:self];
[NSUserDefaults.standardUserDefaults addObserver:self
forKeyPath:@"savePath"
options:NSKeyValueObservingOptionNew
context:NULL];
[NSUserDefaults.standardUserDefaults addObserver:self
forKeyPath:@"feedURL"
options:NSKeyValueObservingOptionNew
context:NULL];
}
- (IBAction)showWindow:(id)sender {
[self refreshInvalidInputMarkers];
[NSApp activateIgnoringOtherApps:YES];
[super showWindow:sender];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
[self refreshInvalidInputMarkers];
}
- (void)refreshInvalidInputMarkers {
NSImage *validImage = [NSImage imageNamed:@"success"];
NSImage *invalidImage = [NSImage imageNamed:@"warning"];
self.torrentsSavePathWarningImageView.image = CTCDefaults.isTorrentsSavePathValid ? validImage : invalidImage;
self.feedURLWarningImageView.image = CTCDefaults.isFeedURLValid ? validImage : invalidImage;
}
- (IBAction)savePreferences:(id)sender {
[CTCDefaults save];
if (CTCDefaults.isConfigurationValid) {
// Hide the Preferences window
[self.window close];
// Apply the login item setting
[CTCDefaults refreshLoginItemStatus];
// Also force check
[CTCScheduler.sharedScheduler forceCheck];
}
else {
// Show the Feeds tab because all possible invalid inputs are currently there
[self showFeeds:self];
// Shake the window to signal invalid input
[self.window performShakeAnimation];
}
}
- (IBAction)showFeeds:(id)sender {
// Select the Feeds tab
self.window.toolbar.selectedItemIdentifier = @"Feed";
}
- (IBAction)showTweaks:(id)sender {
// Select the Tweaks tab
self.window.toolbar.selectedItemIdentifier = @"Tweaks";
}
- (void)dealloc {
[NSUserDefaults.standardUserDefaults removeObserver:self forKeyPath:@"savePath"];
[NSUserDefaults.standardUserDefaults removeObserver:self forKeyPath:@"feedURL"];
}
@end