1 | /****************************************************************************** |
---|
2 | * $Id: PrefsController.m 1645 2007-04-03 02:22:25Z livings124 $ |
---|
3 | * |
---|
4 | * Copyright (c) 2005-2007 Transmission authors and contributors |
---|
5 | * |
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
---|
7 | * copy of this software and associated documentation files (the "Software"), |
---|
8 | * to deal in the Software without restriction, including without limitation |
---|
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
---|
10 | * and/or sell copies of the Software, and to permit persons to whom the |
---|
11 | * Software is furnished to do so, subject to the following conditions: |
---|
12 | * |
---|
13 | * The above copyright notice and this permission notice shall be included in |
---|
14 | * all copies or substantial portions of the Software. |
---|
15 | * |
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
22 | * DEALINGS IN THE SOFTWARE. |
---|
23 | *****************************************************************************/ |
---|
24 | |
---|
25 | #import "PrefsController.h" |
---|
26 | #import "StringAdditions.h" |
---|
27 | #import "UKKQueue.h" |
---|
28 | |
---|
29 | #define DOWNLOAD_FOLDER 0 |
---|
30 | #define DOWNLOAD_TORRENT 2 |
---|
31 | #define DOWNLOAD_ASK 3 |
---|
32 | |
---|
33 | #define UPDATE_DAILY 0 |
---|
34 | #define UPDATE_WEEKLY 1 |
---|
35 | #define UPDATE_NEVER 2 |
---|
36 | |
---|
37 | #define TOOLBAR_GENERAL @"TOOLBAR_GENERAL" |
---|
38 | #define TOOLBAR_TRANSFERS @"TOOLBAR_TRANSFERS" |
---|
39 | #define TOOLBAR_BANDWIDTH @"TOOLBAR_BANDWIDTH" |
---|
40 | #define TOOLBAR_NETWORK @"TOOLBAR_NETWORK" |
---|
41 | |
---|
42 | @interface PrefsController (Private) |
---|
43 | |
---|
44 | - (void) setPrefView: (id) sender; |
---|
45 | |
---|
46 | - (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info; |
---|
47 | - (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info; |
---|
48 | - (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info; |
---|
49 | |
---|
50 | @end |
---|
51 | |
---|
52 | @implementation PrefsController |
---|
53 | |
---|
54 | - (id) initWithWindowNibName: (NSString *) name handle: (tr_handle_t *) handle |
---|
55 | { |
---|
56 | if ((self = [self initWithWindowNibName: name])) |
---|
57 | { |
---|
58 | fDefaults = [NSUserDefaults standardUserDefaults]; |
---|
59 | fHandle = handle; |
---|
60 | |
---|
61 | //checks for old version upload speed of -1 |
---|
62 | if ([fDefaults integerForKey: @"UploadLimit"] < 0) |
---|
63 | { |
---|
64 | [fDefaults setInteger: 20 forKey: @"UploadLimit"]; |
---|
65 | [fDefaults setBool: NO forKey: @"CheckUpload"]; |
---|
66 | } |
---|
67 | |
---|
68 | //set auto import |
---|
69 | if ([fDefaults boolForKey: @"AutoImport"]) |
---|
70 | [[UKKQueue sharedFileWatcher] addPath: |
---|
71 | [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]]; |
---|
72 | |
---|
73 | //set bind port |
---|
74 | int bindPort = [fDefaults integerForKey: @"BindPort"]; |
---|
75 | tr_setBindPort(fHandle, bindPort); |
---|
76 | |
---|
77 | //set NAT |
---|
78 | tr_natTraversalEnable(fHandle, [fDefaults boolForKey: @"NatTraversal"]); |
---|
79 | |
---|
80 | //actually set bandwidth limits |
---|
81 | [self applySpeedSettings: nil]; |
---|
82 | |
---|
83 | //set play sound |
---|
84 | NSMutableArray * sounds = [NSMutableArray array]; |
---|
85 | NSEnumerator * soundEnumerator; |
---|
86 | |
---|
87 | //get list of all sounds and sort alphabetically |
---|
88 | if (soundEnumerator = [[NSFileManager defaultManager] enumeratorAtPath: @"System/Library/Sounds"]) |
---|
89 | { |
---|
90 | NSString * sound; |
---|
91 | while ((sound = [soundEnumerator nextObject])) |
---|
92 | { |
---|
93 | sound = [sound stringByDeletingPathExtension]; |
---|
94 | if ([NSSound soundNamed: sound]) |
---|
95 | [sounds addObject: sound]; |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | fSounds = [[sounds sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)] retain]; |
---|
100 | } |
---|
101 | return self; |
---|
102 | } |
---|
103 | |
---|
104 | - (void) dealloc |
---|
105 | { |
---|
106 | if (fNatStatusTimer) |
---|
107 | [fNatStatusTimer invalidate]; |
---|
108 | [fSounds release]; |
---|
109 | |
---|
110 | [super dealloc]; |
---|
111 | } |
---|
112 | |
---|
113 | - (void) awakeFromNib |
---|
114 | { |
---|
115 | fHasLoaded = YES; |
---|
116 | |
---|
117 | fToolbar = [[NSToolbar alloc] initWithIdentifier: @"Preferences Toolbar"]; |
---|
118 | [fToolbar setDelegate: self]; |
---|
119 | [fToolbar setAllowsUserCustomization: NO]; |
---|
120 | [[self window] setToolbar: fToolbar]; |
---|
121 | [fToolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel]; |
---|
122 | [fToolbar setSizeMode: NSToolbarSizeModeRegular]; |
---|
123 | |
---|
124 | [fToolbar setSelectedItemIdentifier: TOOLBAR_GENERAL]; |
---|
125 | [self setPrefView: nil]; |
---|
126 | |
---|
127 | //set download folder |
---|
128 | NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"]; |
---|
129 | if ([downloadChoice isEqualToString: @"Constant"]) |
---|
130 | [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER]; |
---|
131 | else if ([downloadChoice isEqualToString: @"Torrent"]) |
---|
132 | [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT]; |
---|
133 | else |
---|
134 | [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK]; |
---|
135 | |
---|
136 | //set stop ratio |
---|
137 | [self updateRatioStopField]; |
---|
138 | |
---|
139 | //set limits |
---|
140 | [self updateLimitFields]; |
---|
141 | |
---|
142 | //set speed limit |
---|
143 | [fSpeedLimitUploadField setIntValue: [fDefaults integerForKey: @"SpeedLimitUploadLimit"]]; |
---|
144 | [fSpeedLimitDownloadField setIntValue: [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]]; |
---|
145 | |
---|
146 | //set port |
---|
147 | [fPortField setIntValue: [fDefaults integerForKey: @"BindPort"]]; |
---|
148 | [self updatePortStatus]; |
---|
149 | |
---|
150 | fNatStatus = -1; |
---|
151 | [self updateNatStatus]; |
---|
152 | fNatStatusTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0 target: self |
---|
153 | selector: @selector(updateNatStatus) userInfo: nil repeats: YES]; |
---|
154 | |
---|
155 | //set queue values |
---|
156 | [fQueueDownloadField setIntValue: [fDefaults integerForKey: @"QueueDownloadNumber"]]; |
---|
157 | [fQueueSeedField setIntValue: [fDefaults integerForKey: @"QueueSeedNumber"]]; |
---|
158 | |
---|
159 | //set update check |
---|
160 | NSString * updateCheck = [fDefaults stringForKey: @"UpdateCheck"]; |
---|
161 | if ([updateCheck isEqualToString: @"Weekly"]) |
---|
162 | [fUpdatePopUp selectItemAtIndex: UPDATE_WEEKLY]; |
---|
163 | else if ([updateCheck isEqualToString: @"Never"]) |
---|
164 | [fUpdatePopUp selectItemAtIndex: UPDATE_NEVER]; |
---|
165 | else |
---|
166 | [fUpdatePopUp selectItemAtIndex: UPDATE_DAILY]; |
---|
167 | } |
---|
168 | |
---|
169 | - (void) setUpdater: (SUUpdater *) updater |
---|
170 | { |
---|
171 | fUpdater = updater; |
---|
172 | } |
---|
173 | |
---|
174 | - (NSToolbarItem *) toolbar: (NSToolbar *) toolbar itemForItemIdentifier: (NSString *) ident |
---|
175 | willBeInsertedIntoToolbar: (BOOL) flag |
---|
176 | { |
---|
177 | NSToolbarItem * item; |
---|
178 | item = [[NSToolbarItem alloc] initWithItemIdentifier: ident]; |
---|
179 | |
---|
180 | if ([ident isEqualToString: TOOLBAR_GENERAL]) |
---|
181 | { |
---|
182 | [item setLabel: NSLocalizedString(@"General", "Preferences -> General toolbar item title")]; |
---|
183 | [item setImage: [NSImage imageNamed: @"Preferences.png"]]; |
---|
184 | [item setTarget: self]; |
---|
185 | [item setAction: @selector(setPrefView:)]; |
---|
186 | [item setAutovalidates: NO]; |
---|
187 | } |
---|
188 | else if ([ident isEqualToString: TOOLBAR_TRANSFERS]) |
---|
189 | { |
---|
190 | [item setLabel: NSLocalizedString(@"Transfers", "Preferences -> Transfers toolbar item title")]; |
---|
191 | [item setImage: [NSImage imageNamed: @"Transfers.png"]]; |
---|
192 | [item setTarget: self]; |
---|
193 | [item setAction: @selector(setPrefView:)]; |
---|
194 | [item setAutovalidates: NO]; |
---|
195 | } |
---|
196 | else if ([ident isEqualToString: TOOLBAR_BANDWIDTH]) |
---|
197 | { |
---|
198 | [item setLabel: NSLocalizedString(@"Bandwidth", "Preferences -> Bandwidth toolbar item title")]; |
---|
199 | [item setImage: [NSImage imageNamed: @"Bandwidth.png"]]; |
---|
200 | [item setTarget: self]; |
---|
201 | [item setAction: @selector(setPrefView:)]; |
---|
202 | [item setAutovalidates: NO]; |
---|
203 | } |
---|
204 | else if ([ident isEqualToString: TOOLBAR_NETWORK]) |
---|
205 | { |
---|
206 | [item setLabel: NSLocalizedString(@"Network", "Preferences -> Network toolbar item title")]; |
---|
207 | [item setImage: [NSImage imageNamed: @"Network.png"]]; |
---|
208 | [item setTarget: self]; |
---|
209 | [item setAction: @selector(setPrefView:)]; |
---|
210 | [item setAutovalidates: NO]; |
---|
211 | } |
---|
212 | else |
---|
213 | { |
---|
214 | [item release]; |
---|
215 | return nil; |
---|
216 | } |
---|
217 | |
---|
218 | return item; |
---|
219 | } |
---|
220 | |
---|
221 | - (NSArray *) toolbarSelectableItemIdentifiers: (NSToolbar *) toolbar |
---|
222 | { |
---|
223 | return [self toolbarDefaultItemIdentifiers: toolbar]; |
---|
224 | } |
---|
225 | |
---|
226 | - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar |
---|
227 | { |
---|
228 | return [self toolbarAllowedItemIdentifiers: toolbar]; |
---|
229 | } |
---|
230 | |
---|
231 | - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar |
---|
232 | { |
---|
233 | return [NSArray arrayWithObjects: TOOLBAR_GENERAL, TOOLBAR_TRANSFERS, |
---|
234 | TOOLBAR_BANDWIDTH, TOOLBAR_NETWORK, nil]; |
---|
235 | } |
---|
236 | |
---|
237 | - (void) setPort: (id) sender |
---|
238 | { |
---|
239 | int port = [sender intValue]; |
---|
240 | if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", port]]) |
---|
241 | { |
---|
242 | NSBeep(); |
---|
243 | [sender setIntValue: [fDefaults integerForKey: @"BindPort"]]; |
---|
244 | return; |
---|
245 | } |
---|
246 | |
---|
247 | [fDefaults setInteger: port forKey: @"BindPort"]; |
---|
248 | |
---|
249 | tr_setBindPort(fHandle, [fDefaults integerForKey: @"BindPort"]); |
---|
250 | [self updateNatStatus]; |
---|
251 | [self updatePortStatus]; |
---|
252 | } |
---|
253 | |
---|
254 | - (void) updatePortStatus |
---|
255 | { |
---|
256 | PortChecker * portChecker = [[PortChecker alloc] initWithDelegate: self]; |
---|
257 | |
---|
258 | [fPortStatusField setStringValue: [NSLocalizedString(@"Checking port status", |
---|
259 | "Preferences -> Network -> port status") stringByAppendingEllipsis]]; |
---|
260 | [fPortStatusImage setImage: nil]; |
---|
261 | [fPortStatusProgress startAnimation: self]; |
---|
262 | |
---|
263 | tr_handle_status_t * stat = tr_handleStatus(fHandle); |
---|
264 | [portChecker probePort: stat->publicPort]; |
---|
265 | } |
---|
266 | |
---|
267 | - (void) portCheckerDidFinishProbing: (PortChecker *) portChecker |
---|
268 | { |
---|
269 | [fPortStatusProgress stopAnimation: self]; |
---|
270 | switch ([portChecker status]) |
---|
271 | { |
---|
272 | case PORT_STATUS_OPEN: |
---|
273 | [fPortStatusField setStringValue: NSLocalizedString(@"Port is open", "Preferences -> Network -> port status")]; |
---|
274 | [fPortStatusImage setImage: [NSImage imageNamed: @"GreenDot.tiff"]]; |
---|
275 | break; |
---|
276 | case PORT_STATUS_STEALTH: |
---|
277 | [fPortStatusField setStringValue: NSLocalizedString(@"Port is stealth", "Preferences -> Network -> port status")]; |
---|
278 | [fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]]; |
---|
279 | break; |
---|
280 | case PORT_STATUS_CLOSED: |
---|
281 | [fPortStatusField setStringValue: NSLocalizedString(@"Port is closed", "Preferences -> Network -> port status")]; |
---|
282 | [fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]]; |
---|
283 | break; |
---|
284 | case PORT_STATUS_ERROR: |
---|
285 | [fPortStatusField setStringValue: NSLocalizedString(@"Unable to check port status", |
---|
286 | "Preferences -> Network -> port status")]; |
---|
287 | [fPortStatusImage setImage: [NSImage imageNamed: @"YellowDot.tiff"]]; |
---|
288 | break; |
---|
289 | } |
---|
290 | [portChecker release]; |
---|
291 | } |
---|
292 | |
---|
293 | - (void) setNat: (id) sender |
---|
294 | { |
---|
295 | tr_natTraversalEnable(fHandle, [fDefaults boolForKey: @"NatTraversal"]); |
---|
296 | [self updateNatStatus]; |
---|
297 | } |
---|
298 | |
---|
299 | - (void) updateNatStatus |
---|
300 | { |
---|
301 | tr_handle_status_t * stat = tr_handleStatus(fHandle); |
---|
302 | if (fNatStatus == stat->natTraversalStatus) |
---|
303 | return; |
---|
304 | fNatStatus = stat->natTraversalStatus; |
---|
305 | |
---|
306 | if (fNatStatus == TR_NAT_TRAVERSAL_MAPPED) |
---|
307 | { |
---|
308 | [fNatStatusField setStringValue: NSLocalizedString(@"Port successfully mapped", |
---|
309 | "Preferences -> Network -> port map status")]; |
---|
310 | [fNatStatusImage setImage: [NSImage imageNamed: @"GreenDot.tiff"]]; |
---|
311 | } |
---|
312 | else if (fNatStatus == TR_NAT_TRAVERSAL_NOTFOUND || fNatStatus == TR_NAT_TRAVERSAL_ERROR) |
---|
313 | { |
---|
314 | [fNatStatusField setStringValue: NSLocalizedString(@"Error mapping port", |
---|
315 | "Preferences -> Network -> port map status")]; |
---|
316 | [fNatStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]]; |
---|
317 | } |
---|
318 | else |
---|
319 | { |
---|
320 | [fNatStatusField setStringValue: @""]; |
---|
321 | [fNatStatusImage setImage: nil]; |
---|
322 | } |
---|
323 | |
---|
324 | [self updatePortStatus]; |
---|
325 | } |
---|
326 | |
---|
327 | - (void) applySpeedSettings: (id) sender |
---|
328 | { |
---|
329 | if ([fDefaults boolForKey: @"SpeedLimit"]) |
---|
330 | { |
---|
331 | tr_setGlobalUploadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]); |
---|
332 | tr_setGlobalDownloadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]); |
---|
333 | } |
---|
334 | else |
---|
335 | { |
---|
336 | tr_setGlobalUploadLimit(fHandle, [fDefaults boolForKey: @"CheckUpload"] |
---|
337 | ? [fDefaults integerForKey: @"UploadLimit"] : -1); |
---|
338 | tr_setGlobalDownloadLimit(fHandle, [fDefaults boolForKey: @"CheckDownload"] |
---|
339 | ? [fDefaults integerForKey: @"DownloadLimit"] : -1); |
---|
340 | } |
---|
341 | } |
---|
342 | |
---|
343 | - (void) applyRatioSetting: (id) sender |
---|
344 | { |
---|
345 | [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil]; |
---|
346 | } |
---|
347 | |
---|
348 | - (void) updateRatioStopField |
---|
349 | { |
---|
350 | if (!fHasLoaded) |
---|
351 | return; |
---|
352 | |
---|
353 | [fRatioStopField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]]; |
---|
354 | |
---|
355 | [self applyRatioSetting: nil]; |
---|
356 | } |
---|
357 | |
---|
358 | - (void) setRatioStop: (id) sender |
---|
359 | { |
---|
360 | float ratio = [sender floatValue]; |
---|
361 | if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%.2f", ratio]] || ratio < 0) |
---|
362 | { |
---|
363 | NSBeep(); |
---|
364 | [sender setFloatValue: [fDefaults floatForKey: @"RatioLimit"]]; |
---|
365 | return; |
---|
366 | } |
---|
367 | |
---|
368 | [fDefaults setFloat: ratio forKey: @"RatioLimit"]; |
---|
369 | |
---|
370 | [self applyRatioSetting: nil]; |
---|
371 | } |
---|
372 | |
---|
373 | - (void) updateLimitFields |
---|
374 | { |
---|
375 | if (!fHasLoaded) |
---|
376 | return; |
---|
377 | |
---|
378 | [fUploadField setIntValue: [fDefaults integerForKey: @"UploadLimit"]]; |
---|
379 | [fDownloadField setIntValue: [fDefaults integerForKey: @"DownloadLimit"]]; |
---|
380 | } |
---|
381 | |
---|
382 | - (void) setGlobalLimit: (id) sender |
---|
383 | { |
---|
384 | BOOL upload = sender == fUploadField; |
---|
385 | |
---|
386 | int limit = [sender intValue]; |
---|
387 | if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0) |
---|
388 | { |
---|
389 | NSBeep(); |
---|
390 | [sender setIntValue: [fDefaults integerForKey: upload ? @"UploadLimit" : @"DownloadLimit"]]; |
---|
391 | return; |
---|
392 | } |
---|
393 | |
---|
394 | [fDefaults setInteger: limit forKey: upload ? @"UploadLimit" : @"DownloadLimit"]; |
---|
395 | |
---|
396 | [self applySpeedSettings: self]; |
---|
397 | } |
---|
398 | |
---|
399 | - (void) setSpeedLimit: (id) sender |
---|
400 | { |
---|
401 | BOOL upload = sender == fSpeedLimitUploadField; |
---|
402 | |
---|
403 | int limit = [sender intValue]; |
---|
404 | if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]]) |
---|
405 | { |
---|
406 | NSBeep(); |
---|
407 | [sender setIntValue: [fDefaults integerForKey: upload ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit"]]; |
---|
408 | return; |
---|
409 | } |
---|
410 | |
---|
411 | [fDefaults setInteger: limit forKey: upload ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit"]; |
---|
412 | |
---|
413 | [self applySpeedSettings: self]; |
---|
414 | } |
---|
415 | |
---|
416 | - (void) setAutoSpeedLimit: (id) sender |
---|
417 | { |
---|
418 | [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSpeedLimitChange" object: self]; |
---|
419 | } |
---|
420 | |
---|
421 | - (void) setBadge: (id) sender |
---|
422 | { |
---|
423 | [[NSNotificationCenter defaultCenter] postNotificationName: @"DockBadgeChange" object: self]; |
---|
424 | } |
---|
425 | |
---|
426 | - (void) setSound: (id) sender |
---|
427 | { |
---|
428 | //play sound when selecting |
---|
429 | NSSound * sound; |
---|
430 | if ((sound = [NSSound soundNamed: [sender titleOfSelectedItem]])) |
---|
431 | [sound play]; |
---|
432 | } |
---|
433 | |
---|
434 | - (void) setUpdate: (id) sender |
---|
435 | { |
---|
436 | int index = [fUpdatePopUp indexOfSelectedItem]; |
---|
437 | NSString * update; |
---|
438 | NSTimeInterval seconds; |
---|
439 | if (index == UPDATE_DAILY) |
---|
440 | { |
---|
441 | update = @"Daily"; |
---|
442 | seconds = 86400; |
---|
443 | } |
---|
444 | else if (index == UPDATE_WEEKLY) |
---|
445 | { |
---|
446 | update = @"Weekly"; |
---|
447 | seconds = 604800; |
---|
448 | } |
---|
449 | else |
---|
450 | { |
---|
451 | update = @"Never"; |
---|
452 | seconds = 0; |
---|
453 | } |
---|
454 | |
---|
455 | [fDefaults setObject: update forKey: @"UpdateCheck"]; |
---|
456 | [fDefaults setInteger: seconds forKey: @"SUScheduledCheckInterval"]; |
---|
457 | |
---|
458 | if (fUpdater) |
---|
459 | [fUpdater scheduleCheckWithInterval: seconds]; |
---|
460 | } |
---|
461 | |
---|
462 | - (void) setQueue: (id) sender |
---|
463 | { |
---|
464 | [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self]; |
---|
465 | } |
---|
466 | |
---|
467 | - (void) setQueueNumber: (id) sender |
---|
468 | { |
---|
469 | BOOL download = sender == fQueueDownloadField; |
---|
470 | |
---|
471 | int limit = [sender intValue]; |
---|
472 | if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0) |
---|
473 | { |
---|
474 | NSBeep(); |
---|
475 | [sender setIntValue: [fDefaults integerForKey: download ? @"QueueDownloadNumber" : @"QueueSeedNumber"]]; |
---|
476 | return; |
---|
477 | } |
---|
478 | |
---|
479 | [fDefaults setInteger: limit forKey: download ? @"QueueDownloadNumber" : @"QueueSeedNumber"]; |
---|
480 | |
---|
481 | [self setQueue: nil]; |
---|
482 | } |
---|
483 | |
---|
484 | - (void) setDownloadLocation: (id) sender |
---|
485 | { |
---|
486 | switch ([fFolderPopUp indexOfSelectedItem]) |
---|
487 | { |
---|
488 | case DOWNLOAD_FOLDER: |
---|
489 | [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"]; |
---|
490 | break; |
---|
491 | case DOWNLOAD_TORRENT: |
---|
492 | [fDefaults setObject: @"Torrent" forKey: @"DownloadChoice"]; |
---|
493 | break; |
---|
494 | case DOWNLOAD_ASK: |
---|
495 | [fDefaults setObject: @"Ask" forKey: @"DownloadChoice"]; |
---|
496 | break; |
---|
497 | } |
---|
498 | } |
---|
499 | |
---|
500 | - (void) folderSheetShow: (id) sender |
---|
501 | { |
---|
502 | NSOpenPanel * panel = [NSOpenPanel openPanel]; |
---|
503 | |
---|
504 | [panel setPrompt: @"Select"]; |
---|
505 | [panel setAllowsMultipleSelection: NO]; |
---|
506 | [panel setCanChooseFiles: NO]; |
---|
507 | [panel setCanChooseDirectories: YES]; |
---|
508 | [panel setCanCreateDirectories: YES]; |
---|
509 | |
---|
510 | [panel beginSheetForDirectory: nil file: nil types: nil |
---|
511 | modalForWindow: [self window] modalDelegate: self didEndSelector: |
---|
512 | @selector(folderSheetClosed:returnCode:contextInfo:) contextInfo: nil]; |
---|
513 | } |
---|
514 | |
---|
515 | - (void) incompleteFolderSheetShow: (id) sender |
---|
516 | { |
---|
517 | NSOpenPanel * panel = [NSOpenPanel openPanel]; |
---|
518 | |
---|
519 | [panel setPrompt: @"Select"]; |
---|
520 | [panel setAllowsMultipleSelection: NO]; |
---|
521 | [panel setCanChooseFiles: NO]; |
---|
522 | [panel setCanChooseDirectories: YES]; |
---|
523 | [panel setCanCreateDirectories: YES]; |
---|
524 | |
---|
525 | [panel beginSheetForDirectory: nil file: nil types: nil |
---|
526 | modalForWindow: [self window] modalDelegate: self didEndSelector: |
---|
527 | @selector(incompleteFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil]; |
---|
528 | } |
---|
529 | |
---|
530 | - (void) setAutoImport: (id) sender |
---|
531 | { |
---|
532 | NSString * path = [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]; |
---|
533 | if ([fDefaults boolForKey: @"AutoImport"]) |
---|
534 | [[UKKQueue sharedFileWatcher] addPath: path]; |
---|
535 | else |
---|
536 | [[UKKQueue sharedFileWatcher] removePathFromQueue: path]; |
---|
537 | |
---|
538 | [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self]; |
---|
539 | } |
---|
540 | |
---|
541 | - (void) importFolderSheetShow: (id) sender |
---|
542 | { |
---|
543 | NSOpenPanel * panel = [NSOpenPanel openPanel]; |
---|
544 | |
---|
545 | [panel setPrompt: @"Select"]; |
---|
546 | [panel setAllowsMultipleSelection: NO]; |
---|
547 | [panel setCanChooseFiles: NO]; |
---|
548 | [panel setCanChooseDirectories: YES]; |
---|
549 | [panel setCanCreateDirectories: YES]; |
---|
550 | |
---|
551 | [panel beginSheetForDirectory: nil file: nil types: nil |
---|
552 | modalForWindow: [self window] modalDelegate: self didEndSelector: |
---|
553 | @selector(importFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil]; |
---|
554 | } |
---|
555 | |
---|
556 | - (void) setAutoSize: (id) sender |
---|
557 | { |
---|
558 | [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSizeSettingChange" object: self]; |
---|
559 | } |
---|
560 | |
---|
561 | - (void) helpForNetwork: (id) sender |
---|
562 | { |
---|
563 | [[NSHelpManager sharedHelpManager] openHelpAnchor: @"PortForwarding" |
---|
564 | inBook: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"]]; |
---|
565 | } |
---|
566 | |
---|
567 | @end |
---|
568 | |
---|
569 | @implementation PrefsController (Private) |
---|
570 | |
---|
571 | - (void) setPrefView: (id) sender |
---|
572 | { |
---|
573 | NSView * view = fGeneralView; |
---|
574 | if (sender) |
---|
575 | { |
---|
576 | NSString * identifier = [sender itemIdentifier]; |
---|
577 | if ([identifier isEqualToString: TOOLBAR_TRANSFERS]) |
---|
578 | view = fTransfersView; |
---|
579 | else if ([identifier isEqualToString: TOOLBAR_BANDWIDTH]) |
---|
580 | view = fBandwidthView; |
---|
581 | else if ([identifier isEqualToString: TOOLBAR_NETWORK]) |
---|
582 | view = fNetworkView; |
---|
583 | else; |
---|
584 | } |
---|
585 | |
---|
586 | NSWindow * window = [self window]; |
---|
587 | if ([window contentView] == view) |
---|
588 | return; |
---|
589 | |
---|
590 | NSRect windowRect = [window frame]; |
---|
591 | int difference = [view frame].size.height - [[window contentView] frame].size.height; |
---|
592 | windowRect.origin.y -= difference; |
---|
593 | windowRect.size.height += difference; |
---|
594 | |
---|
595 | [view setHidden: YES]; |
---|
596 | [window setContentView: view]; |
---|
597 | [window setFrame: windowRect display: YES animate: YES]; |
---|
598 | [view setHidden: NO]; |
---|
599 | |
---|
600 | //set title label |
---|
601 | if (sender) |
---|
602 | [window setTitle: [sender label]]; |
---|
603 | else |
---|
604 | { |
---|
605 | NSToolbarItem * item; |
---|
606 | NSEnumerator * enumerator = [[fToolbar items] objectEnumerator]; |
---|
607 | while ((item = [enumerator nextObject])) |
---|
608 | if ([[item itemIdentifier] isEqualToString: [fToolbar selectedItemIdentifier]]) |
---|
609 | { |
---|
610 | [window setTitle: [item label]]; |
---|
611 | break; |
---|
612 | } |
---|
613 | } |
---|
614 | |
---|
615 | //for network view make sure progress indicator hides itself |
---|
616 | if (view == fNetworkView && [fPortStatusImage image]) |
---|
617 | [fPortStatusProgress setDisplayedWhenStopped: NO]; |
---|
618 | } |
---|
619 | |
---|
620 | - (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info |
---|
621 | { |
---|
622 | if (code == NSOKButton) |
---|
623 | { |
---|
624 | [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER]; |
---|
625 | [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"DownloadFolder"]; |
---|
626 | [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"]; |
---|
627 | } |
---|
628 | else |
---|
629 | { |
---|
630 | //reset if cancelled |
---|
631 | NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"]; |
---|
632 | if ([downloadChoice isEqualToString: @"Constant"]) |
---|
633 | [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER]; |
---|
634 | else if ([downloadChoice isEqualToString: @"Torrent"]) |
---|
635 | [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT]; |
---|
636 | else |
---|
637 | [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK]; |
---|
638 | } |
---|
639 | } |
---|
640 | |
---|
641 | - (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info |
---|
642 | { |
---|
643 | if (code == NSOKButton) |
---|
644 | [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"IncompleteDownloadFolder"]; |
---|
645 | [fIncompleteFolderPopUp selectItemAtIndex: 0]; |
---|
646 | } |
---|
647 | |
---|
648 | - (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info |
---|
649 | { |
---|
650 | if (code == NSOKButton) |
---|
651 | { |
---|
652 | UKKQueue * sharedQueue = [UKKQueue sharedFileWatcher]; |
---|
653 | [sharedQueue removePathFromQueue: [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]]; |
---|
654 | |
---|
655 | [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"AutoImportDirectory"]; |
---|
656 | |
---|
657 | [sharedQueue addPath: [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]]; |
---|
658 | |
---|
659 | [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self]; |
---|
660 | } |
---|
661 | [fImportFolderPopUp selectItemAtIndex: 0]; |
---|
662 | } |
---|
663 | |
---|
664 | @end |
---|