This repository has been archived by the owner on Jun 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGeneralPrefController.m
133 lines (122 loc) · 4.4 KB
/
GeneralPrefController.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
// GeneralPrefController.m
// MAL Updater OS X
//
// Created by Nanoha Takamachi on 2014/10/18.
// Copyright 2014 MAL Updater OS X Group. All rights reserved.
//
#import "GeneralPrefController.h"
#import <EasyNSURLConnection/EasyNSURLConnection.h>
#import "MAL_Updater_OS_XAppDelegate.h"
#import "AutoExceptions.h"
#import "Utility.h"
#import "NSBundle+LoginItem.h"
@implementation GeneralPrefController
@synthesize disablenewtitlebar;
@synthesize disablevibarency;
@synthesize startatlogin;
@synthesize indicator;
@synthesize updateexceptionsbtn;
@synthesize updateexceptionschk;
- (id)init
{
return [super initWithNibName:@"GeneralPreferenceView" bundle:nil];
}
- (IBAction)toggleLaunchAtStartup:(id)sender{
[self toggleLaunchAtStartup];
}
- (void)toggleLaunchAtStartup{
if ([[NSBundle mainBundle] isLoginItem]) {
[[NSBundle mainBundle] removeFromLoginItems];
}
else{
[[NSBundle mainBundle] addToLoginItems];
}
}
#pragma mark -
#pragma mark MASPreferencesViewController
- (void)loadView{
[super loadView];
if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_9) {
// Disable Yosemite UI options
[disablenewtitlebar setEnabled:NO];
[disablevibarency setEnabled: NO];
}
startatlogin.state = [NSBundle.mainBundle isLoginItem]; // Set Launch at Startup State
}
- (NSString *)identifier
{
return @"GeneralPreferences";
}
- (NSImage *)toolbarItemImage
{
return [NSImage imageNamed:NSImageNamePreferencesGeneral];
}
- (NSString *)toolbarItemLabel
{
return NSLocalizedString(@"General", @"Toolbar item name for the General preference pane");
}
#pragma mark General Preferences Functions
- (IBAction)clearSearchCache:(id)sender{
// Remove All cache data from Core Data Entity
MAL_Updater_OS_XAppDelegate *delegate = (MAL_Updater_OS_XAppDelegate *)[NSApplication sharedApplication].delegate;
NSManagedObjectContext *moc = delegate.managedObjectContext;
NSFetchRequest *allCaches = [[NSFetchRequest alloc] init];
allCaches.entity = [NSEntityDescription entityForName:@"Cache" inManagedObjectContext:moc];
NSError *error = nil;
NSArray *caches = [moc executeFetchRequest:allCaches error:&error];
//error handling goes here
for (NSManagedObject *cachentry in caches) {
[moc deleteObject:cachentry];
}
error = nil;
[moc save:&error];
}
- (IBAction)updateAutoExceptions:(id)sender{
// Updates Auto Exceptions List
dispatch_queue_t queue = dispatch_get_global_queue(
DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
// In a queue, download latest Auto Exceptions JSON, disable button until done and show progress wheel
dispatch_async(dispatch_get_main_queue(), ^{
[updateexceptionsbtn setEnabled:NO];
[updateexceptionschk setEnabled:NO];
[indicator startAnimation:self];});
[AutoExceptions updateAutoExceptions];
dispatch_async(dispatch_get_main_queue(), ^{
[indicator stopAnimation:self];
[updateexceptionsbtn setEnabled:YES];
[updateexceptionschk setEnabled:YES];
});
});
}
- (IBAction)disableAutoExceptions:(id)sender{
if (updateexceptionschk.state) {
[self updateAutoExceptions:sender];
}
else {
// Clears Exceptions if User chooses
// Set Up Prompt Message Window
NSAlert *alert = [[NSAlert alloc] init] ;
[alert addButtonWithTitle:@"Yes"];
[alert addButtonWithTitle:@"No"];
alert.messageText = @"Do you want to remove all Auto Exceptions Data?";
alert.informativeText = @"Since you are disabling Auto Exceptions, you can delete the Auto Exceptions Data. You will be able to download it again.";
// Set Message type to Warning
alert.alertStyle = NSWarningAlertStyle;
[alert beginSheetModalForWindow:self.view.window completionHandler:^(NSModalResponse returnCode) {
if (returnCode== NSAlertFirstButtonReturn) {
[AutoExceptions clearAutoExceptions];
}
}];
}
}
- (IBAction)changetimerinterval:(id)sender {
// Sets new time for the timer, if running
MAL_Updater_OS_XAppDelegate *delegate = (MAL_Updater_OS_XAppDelegate *)[NSApplication sharedApplication].delegate;
if (delegate.scrobbling) {
[delegate stoptimer];
[delegate starttimer];
}
}
@end