forked from SelfControlApp/selfcontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppController.h
executable file
·149 lines (115 loc) · 5.54 KB
/
AppController.h
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//
// AppController.h
// SelfControl
//
// Created by Charlie Stigler on 1/29/09.
// Copyright 2009 Eyebeam.
// This file is part of SelfControl.
//
// SelfControl is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Forward declaration to avoid compiler weirdness
@class TimerWindowController;
#import <Cocoa/Cocoa.h>
#import "DomainListWindowController.h"
#import "TimerWindowController.h"
#import <Security/Security.h>
#import <SystemConfiguration/SCNetwork.h>
#import <unistd.h>
#import "SelfControlCommon.h"
// The main controller for the SelfControl app, which includes several methods
// to handle command flow and acts as delegate for the initial window.
@interface AppController : NSObject <NSApplicationDelegate> {
IBOutlet NSSlider* blockDurationSlider_;
IBOutlet NSTextField* blockSliderTimeDisplayLabel_;
IBOutlet NSButton* submitButton_;
IBOutlet NSWindow* initialWindow_;
IBOutlet NSMenuItem* domainListMenuItem_;
IBOutlet NSButton* editBlacklistButton_;
IBOutlet DomainListWindowController* domainListWindowController_;
IBOutlet TimerWindowController* timerWindowController_;
NSWindowController* preferencesWindowController_;
NSUserDefaults* defaults_;
NSLock* refreshUILock_;
BOOL blockIsOn;
BOOL addingBlock;
}
@property (assign) BOOL addingBlock;
// Returns an autoreleased instance of the path to the helper tool inside
// SelfControl's bundle
@property (nonatomic, readonly, copy) NSString *selfControlHelperToolPath;
// Returns as a UTF-8 encoded C-string the path to the helper tool inside
// SelfControl's bundle
- (char*)selfControlHelperToolPathUTF8String;
// Called when the block duration slider is moved. Updates the label that gives
// the block duration in words (hours and minutes).
- (IBAction)updateTimeSliderDisplay:(id)sender;
/* // Gets authorization for and then immediately removes the block by calling
// SelfControl's helper tool with the appropriate arguments. This can be used
// for testing, but should not be called at all during normal execution of the
// program.
- (void)removeBlock; */
// Called when the main Start button is clicked. Launchs installBlock in another
// thread after some checking and syncing.
- (IBAction)addBlock:(id)sender;
// Checks whether the SelfControl block is active and accordingly changes the
// user interface. Called very often by several parts of the program.
- (void)refreshUserInterface;
// Called when the "Edit blacklist" button is clicked or the menu item is
// selected. Allocates a new DomainListWindowController if necessary and opens
// the domain blacklist window. Spawns an alert box if a block is in progress.
- (IBAction)showDomainList:(id)sender;
// Returns YES if, according to a flag set in the user defaults system, the
// SelfControl launchd daemon (and therefore the block) is loaded. Returns NO
// if it is not.
@property (nonatomic, readonly) BOOL selfControlLaunchDaemonIsLoaded;
// Allocates a new TimerWindowController if necessary and opens the timer window.
// Also calls TimerWindowController's reloadTimer method to begin the timer's
// countdown.
- (void)showTimerWindow;
// Calls the close method of our TimerWindowController
- (void)closeTimerWindow;
// Calls the close method of our DomainListWindowController
- (void)closeDomainList;
// Checks whether a network connection is available by checking the reachabilty
// of google.com This method may not be correct if the network configuration
// was just changed a few seconds ago.
@property (nonatomic, readonly) BOOL networkConnectionIsAvailable;
// Called by timerWindowController_ after its sheet returns, to add a specified
// host to the blacklist (and refresh the block to use the new blacklist). Launches
// a new thread with refreshBlock:
- (void)addToBlockList:(NSString*)host lock:(NSLock*)lock;
// Converts a failure exit code from a helper tool invocation into an NSError,
// ready to be presented to the user.
- (NSError*)errorFromHelperToolStatusCode:(int)status;
// Gets authorization for and then immediately adds the block by calling
// SelfControl's helper tool with the appropriate arguments. Meant to be called
// as a separate thread.
- (void)installBlock;
// Gets authorization for and then immediately refreshes the block by calling
// SelfControl's helper tool with the appropriate arguments. Meant to be called
// as a separate thread.
- (void)refreshBlock:(NSLock*)lockToUse;
// open preferences panel
- (IBAction)openPreferences:(id)sender;
- (IBAction)showGetStartedWindow:(id)sender;
// Opens a save panel and saves the blocklist.
- (IBAction)save:(id)sender;
// Opens an open panel and imports a blocklist, clearing the current one.
- (IBAction)open:(id)sender;
// Property allows initialWindow to be accessed from TimerWindowController
// @property (retain, nonatomic, readonly) id initialWindow;
// Changed property to manual accessor for pre-Leopard compatibility
@property (nonatomic, readonly, strong) id initialWindow;
@property (nonatomic) int blockLength;
- (IBAction)openFAQ:(id)sender;
- (void)switchedToWhitelist:(id)sender;
@end