-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsWindowController.m
More file actions
executable file
·105 lines (88 loc) · 3.28 KB
/
SettingsWindowController.m
File metadata and controls
executable file
·105 lines (88 loc) · 3.28 KB
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
//
// SettingsWindowController.m
// Pastebin
//
// Created by pixfid on 15.05.14.
// Copyright (c) 2014 commonsoft. All rights reserved.
//
#import "SettingsWindowController.h"
@interface SettingsWindowController () {
}
@end
@implementation SettingsWindowController {
@private
ResourcesManager *rm;
NSUserDefaults *defaults;
}
#define helperAppBundleIdentifier @"com.commonsoft.Pastebin-Helper"
#define terminateNotification @"TERMINATEHELPER"
@synthesize launchAtLoginButton;
- (id)initWithWindowNibName:(NSString *)nibBundleOrNil {
self = [super initWithWindowNibName:nibBundleOrNil];
if (self) {}
return self;
}
- (void)awakeFromNib {
rm = [ResourcesManager getInstance];
defaults = [rm getUserDefaults];
if (defaults) {
NSString *api_dev_key = [defaults valueForKey:@"api_dev_key"];
if (api_dev_key) {
[_devApi setStringValue:api_dev_key];
}
NSString *api_user_name = [defaults valueForKey:@"api_user_name"];
if (api_user_name) {
[_userName setStringValue:api_user_name];
}
NSString *api_user_password = [defaults valueForKey:@"api_user_password"];
if (api_user_password) {
[_userPassword setStringValue:api_user_password];
}
NSInteger auto_login_enabled = [defaults integerForKey:@"auto_login_enabled"];
switch (auto_login_enabled) {
case 0:
[launchAtLoginButton selectSegmentWithTag:1];
break;
case 1:
[launchAtLoginButton selectSegmentWithTag:0];
default:
break;
}
}
}
- (IBAction)toggleLaunchAtLogin:(id)sender {
NSSegmentedControl *control = (NSSegmentedControl *) sender;
NSInteger clickedSegment = [control selectedSegment];
defaults = [rm getUserDefaults];
if (clickedSegment == 0) { // ON
// Turn on launch at login
[defaults setInteger:1 forKey:@"auto_login_enabled"];
if (!SMLoginItemSetEnabled((__bridge CFStringRef) helperAppBundleIdentifier, YES)) {
NSAlert *alert = [NSAlert alertWithMessageText:@"An error ocurred" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"Couldn't add Helper App to launch at login item list."];
[alert runModal];
}
}
if (clickedSegment == 1) { // OFF
// Turn off launch at login
[defaults setInteger:0 forKey:@"auto_login_enabled"];
if (!SMLoginItemSetEnabled((__bridge CFStringRef) helperAppBundleIdentifier, NO)) {
NSAlert *alert = [NSAlert alertWithMessageText:@"An error ocurred" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"Couldn't remove Helper App from launch at login item list."];
[alert runModal];
}
}
}
- (IBAction)save:(id)sender {
rm = [ResourcesManager getInstance];
defaults = [rm getUserDefaults];
if (defaults) {
[defaults setValue:[_devApi stringValue] forKey:@"api_dev_key"];
[defaults setValue:[_userName stringValue] forKey:@"api_user_name"];
[defaults setValue:[_userPassword stringValue] forKey:@"api_user_password"];
}
[[PBPastebinAccount getInstance] reInit];
[self close];
}
- (void)windowDidLoad {
[super windowDidLoad];
}
@end