-
Notifications
You must be signed in to change notification settings - Fork 1
/
GBPreferenceController.m
227 lines (181 loc) · 6.91 KB
/
GBPreferenceController.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// This file is part of hdhomerunner.
// hdhomerunner 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.
// hdhomerunner 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/>.
//
// GBPreferenceController.m
// hdhomerunner
//
// Created by Gregory Barchard on 6/23/07.
// Copyright 2007 __MyCompanyName__. All rights reserved.
//
#import "GBPreferenceController.h"
@implementation GBPreferenceController
-(id)init{
if(self = [super init]){
[self initWithWindowNibName:@"PrefWindow"];
}
return self;
}
-(void)awakeFromNib{
// Set up the preference window's toolbar
[self setupToolbar];
[self setView:_generalview];
}
- (void)setupToolbar{
//NSLog(@"Setting up toolbar");
_update = [[NSToolbarItem alloc] initWithItemIdentifier:@"Update"];
[_update setAction:@selector(goTo:)];
[_update setTarget:self];
_donate = [[NSToolbarItem alloc] initWithItemIdentifier:@"Donate"];
[_donate setAction:@selector(goTo:)];
[_donate setTarget:self];
_general = [[NSToolbarItem alloc] initWithItemIdentifier:@"General"];
[_general setAction:@selector(goTo:)];
[_general setTarget:self];
NSToolbar *toolbar;
toolbar = [[NSToolbar alloc] initWithIdentifier:@"toolbah"];
[toolbar setDelegate:self];
// Make the toolbar configurable
[toolbar setAllowsUserCustomization:NO];
[toolbar setAutosavesConfiguration:NO];
// Attach the toolbar to the window
[[self window] setToolbar:toolbar];
// toolbar is retained by the window
[toolbar release];
}
-(IBAction)goTo:(id)sender{
//NSLog(@"class = %@", [sender className]);
if([[sender className] isEqualToString:@"NSToolbarItem"]){
if([[sender itemIdentifier] isEqual:[_donate itemIdentifier]]){
//NSLog(@"Going to pane %@", [sender itemIdentifier]);
[self setView:_donateview];
} else if([[sender itemIdentifier] isEqual:[_update itemIdentifier]]){
//NSLog(@"Going to pane %@", [sender itemIdentifier]);
[self setView:_updateview];
} else if([[sender itemIdentifier] isEqual:[_general itemIdentifier]]){
//NSLog(@"Going to pane %@", [sender itemIdentifier]);
[self setView:_generalview];
}
}
if([[sender className] isEqualToString:@"NSButton"]){
if(sender == _donatelink){
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=donation%40barchard%2enet&item_name=hdhomerunner&no_shipping=1&cn=Optional%20Feedback%3a&tax=0¤cy_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8"]];
}
}
}
-(void)setView:(NSView *)newView{
if(newView){
NSSize currentViewSize = [[[self window] contentView] bounds].size;
NSSize currentWindowSize = [[self window] frame].size;
NSSize newViewSize = [newView bounds].size;
NSPoint currentWindowOrigin = [[self window] frame].origin;
float x = currentWindowOrigin.x;//[[self window] frame].origin.x;
float y = currentWindowOrigin.y + currentViewSize.height - newViewSize.height;//[[self window] frame].origin.y;
float w = newViewSize.width;
float h = currentWindowSize.height - currentViewSize.height + newViewSize.height;//[newView bounds].size.height;
[[self window] setContentView:[[[NSView alloc] initWithFrame:NSZeroRect] autorelease]];
[[self window] setFrame:NSMakeRect(x, y, w, h) display:YES animate:YES];
//[[self window] setTitle:[[_view window] title]];
[[self window] setContentView:newView];
}
}
-(int)DHCP_state{
return DHCP_state;
}
-(void)setDHCP_state:(int)newState{
NSLog(@"setting dhcp state");
if(newState){
DHCP_state = newState;
}
}
/*- (NSToolbarItem *)toolbar:(NSToolbar *)tb
itemForItemIdentifier:(NSString *)tbit
willBeInsertedIntoToolbar:(BOOL)flag
{
NSToolbarItem *tbi;
// I'm setting up all the items identically.
// Obviously, you would not.
tbi = [[NSToolbarItem alloc]initWithItemIdentifier:tbit];
[tbi setAction:@selector(go:)];
[tbi setTarget:self];
// This is the label that will appear in the toolbar
[tbi setLabel:tbit];
// This is the label that will appear in the config panel
[tbi setPaletteLabel:tbit];
//[tbi setImage:image];
[tbi autorelease];
return tbi;
}*/
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag
{
NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
[item setAction:@selector(goTo:)];
[item setTarget:self];
// This is the label that will appear in the toolbar
[item setLabel:itemIdentifier];
if ( [itemIdentifier isEqualToString:@"General"] ) {
[item setPaletteLabel:[item label]];
[item setImage:[NSImage imageNamed:@"General Preferences"]];
} else if ( [itemIdentifier isEqualToString:@"Donate"] ) {
[item setPaletteLabel:[item label]];
[item setImage:[NSImage imageNamed:@"Users"]];
} else if ( [itemIdentifier isEqualToString:@"Update"] ) {
[item setPaletteLabel:[item label]];
[item setImage:[NSImage imageNamed:@"reload"]];
}
return [item autorelease];
}
/*- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
{
return [NSArray arrayWithObjects:@"Tool 0", @"Tool 1",NSToolbarSeparatorItemIdentifier, @"Tool 4", nil];
}*/
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
{
return [NSArray arrayWithObjects:[_general itemIdentifier], [_update itemIdentifier], [_donate itemIdentifier], NSToolbarFlexibleSpaceItemIdentifier, nil];
}
/*- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
{
NSString *tbit;
int i;
NSMutableArray *ma = [NSMutableArray array];
// Fill the array with strings
for (i=0; i <10; i++){
tbit = [NSString stringWithFormat:@"Tool %d", i];
[ma addObject:tbit];
}
// Put in a couple of standard tool bar items
[ma addObject:NSToolbarSeparatorItemIdentifier];
[ma addObject:NSToolbarShowColorsItemIdentifier];
return ma;
}*/
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
{
return [NSArray arrayWithObjects:NSToolbarSeparatorItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier, nil];
}
// You can also disable toolbar items
/*- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
{
// Here I am disabling Tool 4
if ([[theItem itemIdentifier] isEqual:@"Tool 4"]) {
return NO;
} else {
return YES;
}
}*/
-(void)dealloc{
[super dealloc];
}
@end