1 | /****************************************************************************** |
---|
2 | * $Id: PrefsController.m 1029 2006-10-24 21:25:03Z livings124 $ |
---|
3 | * |
---|
4 | * Copyright (c) 2005-2006 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 MIN_PORT 1 |
---|
30 | #define MAX_PORT 65535 |
---|
31 | |
---|
32 | #define DOWNLOAD_FOLDER 0 |
---|
33 | #define DOWNLOAD_TORRENT 2 |
---|
34 | #define DOWNLOAD_ASK 3 |
---|
35 | |
---|
36 | #define UPDATE_DAILY 0 |
---|
37 | #define UPDATE_WEEKLY 1 |
---|
38 | #define UPDATE_NEVER 2 |
---|
39 | |
---|
40 | #define TOOLBAR_GENERAL @"TOOLBAR_GENERAL" |
---|
41 | #define TOOLBAR_TRANSFERS @"TOOLBAR_TRANSFERS" |
---|
42 | #define TOOLBAR_BANDWIDTH @"TOOLBAR_BANDWIDTH" |
---|
43 | #define TOOLBAR_NETWORK @"TOOLBAR_NETWORK" |
---|
44 | |
---|
45 | @interface PrefsController (Private) |
---|
46 | |
---|
47 | - (void) setPrefView: (id) sender; |
---|
48 | |
---|
49 | - (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info; |
---|
50 | - (void) updatePopUp; |
---|
51 | |
---|
52 | - (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info; |
---|
53 | - (void) updateImportPopUp; |
---|
54 | |
---|
55 | @end |
---|
56 | |
---|
57 | @implementation PrefsController |
---|
58 | |
---|
59 | - (id) initWithWindowNibName: (NSString *) name handle: (tr_handle_t *) handle |
---|
60 | { |
---|
61 | if ((self = [self initWithWindowNibName: name])) |
---|
62 | { |
---|
63 | fDefaults = [NSUserDefaults standardUserDefaults]; |
---|
64 | fHandle = handle; |
---|
65 | |
---|
66 | //checks for old version upload speed of -1 |
---|
67 | if ([fDefaults integerForKey: @"UploadLimit"] < 0) |
---|
68 | { |
---|
69 | [fDefaults setInteger: 20 forKey: @"UploadLimit"]; |
---|
70 | [fDefaults setBool: NO forKey: @"CheckUpload"]; |
---|
71 | } |
---|
72 | |
---|
73 | [[self window] update]; //make sure nib is loaded right away |
---|
74 | } |
---|
75 | return self; |
---|
76 | } |
---|
77 | |
---|
78 | - (void) dealloc |
---|
79 | { |
---|
80 | [fNatStatusTimer invalidate]; |
---|
81 | |
---|
82 | [fDownloadFolder release]; |
---|
83 | [fImportFolder release]; |
---|
84 | [super dealloc]; |
---|
85 | } |
---|
86 | |
---|
87 | - (void) awakeFromNib |
---|
88 | { |
---|
89 | fToolbar = [[NSToolbar alloc] initWithIdentifier: @"Preferences Toolbar"]; |
---|
90 | [fToolbar setDelegate: self]; |
---|
91 | [fToolbar setAllowsUserCustomization: NO]; |
---|
92 | [[self window] setToolbar: fToolbar]; |
---|
93 | [fToolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel]; |
---|
94 | [fToolbar setSizeMode: NSToolbarSizeModeRegular]; |
---|
95 | |
---|
96 | [fToolbar setSelectedItemIdentifier: TOOLBAR_GENERAL]; |
---|
97 | [self setPrefView: nil]; |
---|
98 | |
---|
99 | //set download folder |
---|
100 | NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"]; |
---|
101 | fDownloadFolder = [[[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath] retain]; |
---|
102 | if ([downloadChoice isEqualToString: @"Constant"]) |
---|
103 | [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER]; |
---|
104 | else if ([downloadChoice isEqualToString: @"Torrent"]) |
---|
105 | [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT]; |
---|
106 | else |
---|
107 | [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK]; |
---|
108 | [self updatePopUp]; |
---|
109 | |
---|
110 | //set auto import |
---|
111 | fImportFolder = [[[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath] retain]; |
---|
112 | [self updateImportPopUp]; |
---|
113 | |
---|
114 | BOOL autoImport = [fDefaults boolForKey: @"AutoImport"]; |
---|
115 | [fAutoImportCheck setState: autoImport]; |
---|
116 | [fImportFolderPopUp setEnabled: autoImport]; |
---|
117 | |
---|
118 | if (autoImport) |
---|
119 | [[UKKQueue sharedFileWatcher] addPath: fImportFolder]; |
---|
120 | |
---|
121 | //set auto size |
---|
122 | [fAutoSizeCheck setState: [fDefaults boolForKey: @"AutoSize"]]; |
---|
123 | |
---|
124 | //set bind port |
---|
125 | int bindPort = [fDefaults integerForKey: @"BindPort"]; |
---|
126 | [fPortField setIntValue: bindPort]; |
---|
127 | tr_setBindPort(fHandle, bindPort); |
---|
128 | |
---|
129 | [self updatePortStatus]; |
---|
130 | |
---|
131 | //set NAT |
---|
132 | BOOL natShouldEnable = [fDefaults boolForKey: @"NatTraversal"]; |
---|
133 | if (natShouldEnable) |
---|
134 | tr_natTraversalEnable(fHandle); |
---|
135 | [fNatCheck setState: natShouldEnable]; |
---|
136 | |
---|
137 | fNatStatus = -1; |
---|
138 | [self updateNatStatus]; |
---|
139 | fNatStatusTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0 target: self |
---|
140 | selector: @selector(updateNatStatus) userInfo: nil repeats: YES]; |
---|
141 | |
---|
142 | //set upload limit |
---|
143 | BOOL checkUpload = [fDefaults boolForKey: @"CheckUpload"]; |
---|
144 | int uploadLimit = [fDefaults integerForKey: @"UploadLimit"]; |
---|
145 | |
---|
146 | [fUploadCheck setState: checkUpload]; |
---|
147 | [fUploadField setIntValue: uploadLimit]; |
---|
148 | [fUploadField setEnabled: checkUpload]; |
---|
149 | |
---|
150 | //set download limit |
---|
151 | BOOL checkDownload = [fDefaults boolForKey: @"CheckDownload"]; |
---|
152 | int downloadLimit = [fDefaults integerForKey: @"DownloadLimit"]; |
---|
153 | |
---|
154 | [fDownloadCheck setState: checkDownload]; |
---|
155 | [fDownloadField setIntValue: downloadLimit]; |
---|
156 | [fDownloadField setEnabled: checkDownload]; |
---|
157 | |
---|
158 | //set speed limit |
---|
159 | int speedLimitUploadLimit = [fDefaults integerForKey: @"SpeedLimitUploadLimit"]; |
---|
160 | [fSpeedLimitUploadField setIntValue: speedLimitUploadLimit]; |
---|
161 | |
---|
162 | int speedLimitDownloadLimit = [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]; |
---|
163 | [fSpeedLimitDownloadField setIntValue: speedLimitDownloadLimit]; |
---|
164 | |
---|
165 | //actually set bandwidth limits |
---|
166 | if ([fDefaults boolForKey: @"SpeedLimit"]) |
---|
167 | { |
---|
168 | tr_setUploadLimit(fHandle, speedLimitUploadLimit); |
---|
169 | tr_setDownloadLimit(fHandle, speedLimitDownloadLimit); |
---|
170 | } |
---|
171 | else |
---|
172 | { |
---|
173 | tr_setUploadLimit(fHandle, checkUpload ? uploadLimit : -1); |
---|
174 | tr_setDownloadLimit(fHandle, checkDownload ? downloadLimit : -1); |
---|
175 | } |
---|
176 | |
---|
177 | //set auto speed limit |
---|
178 | BOOL speedLimitAuto = [fDefaults boolForKey: @"SpeedLimitAuto"]; |
---|
179 | [fSpeedLimitAutoCheck setState: speedLimitAuto]; |
---|
180 | |
---|
181 | int speedLimitAutoOnHour = [fDefaults integerForKey: @"SpeedLimitAutoOnHour"]; |
---|
182 | [fSpeedLimitAutoOnField setStringValue: [NSString stringWithFormat: @"%02d", speedLimitAutoOnHour]]; |
---|
183 | [fSpeedLimitAutoOnField setEnabled: speedLimitAuto]; |
---|
184 | |
---|
185 | int speedLimitAutoOffHour = [fDefaults integerForKey: @"SpeedLimitAutoOffHour"]; |
---|
186 | [fSpeedLimitAutoOffField setStringValue: [NSString stringWithFormat: @"%02d", speedLimitAutoOffHour]]; |
---|
187 | [fSpeedLimitAutoOffField setEnabled: speedLimitAuto]; |
---|
188 | |
---|
189 | //set ratio limit |
---|
190 | BOOL ratioCheck = [fDefaults boolForKey: @"RatioCheck"]; |
---|
191 | [fRatioCheck setState: ratioCheck]; |
---|
192 | [fRatioField setEnabled: ratioCheck]; |
---|
193 | [fRatioField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]]; |
---|
194 | |
---|
195 | //set remove and quit prompts |
---|
196 | BOOL isQuitCheck = [fDefaults boolForKey: @"CheckQuit"], |
---|
197 | isRemoveCheck = [fDefaults boolForKey: @"CheckRemove"]; |
---|
198 | |
---|
199 | [fQuitCheck setState: isQuitCheck]; |
---|
200 | [fRemoveCheck setState: isRemoveCheck]; |
---|
201 | |
---|
202 | [fQuitDownloadingCheck setState: [fDefaults boolForKey: @"CheckQuitDownloading"]]; |
---|
203 | [fQuitDownloadingCheck setEnabled: isQuitCheck]; |
---|
204 | [fRemoveDownloadingCheck setState: [fDefaults boolForKey: @"CheckRemoveDownloading"]]; |
---|
205 | [fRemoveDownloadingCheck setEnabled: isRemoveCheck]; |
---|
206 | |
---|
207 | //set dock badging |
---|
208 | [fBadgeDownloadRateCheck setState: [fDefaults boolForKey: @"BadgeDownloadRate"]]; |
---|
209 | [fBadgeUploadRateCheck setState: [fDefaults boolForKey: @"BadgeUploadRate"]]; |
---|
210 | |
---|
211 | //set play sound |
---|
212 | NSMutableArray * sounds = [NSMutableArray array]; |
---|
213 | NSEnumerator * soundEnumerator, |
---|
214 | * soundDirectoriesEnumerator = [[NSArray arrayWithObjects: @"System/Library/Sounds", |
---|
215 | [NSHomeDirectory() stringByAppendingPathComponent: @"Library/Sounds"], nil] objectEnumerator]; |
---|
216 | NSString * soundPath, * sound; |
---|
217 | |
---|
218 | //get list of all sounds and sort alphabetically |
---|
219 | while ((soundPath = [soundDirectoriesEnumerator nextObject])) |
---|
220 | if (soundEnumerator = [[NSFileManager defaultManager] enumeratorAtPath: soundPath]) |
---|
221 | while ((sound = [soundEnumerator nextObject])) |
---|
222 | { |
---|
223 | sound = [sound stringByDeletingPathExtension]; |
---|
224 | if ([NSSound soundNamed: sound]) |
---|
225 | [sounds addObject: sound]; |
---|
226 | } |
---|
227 | |
---|
228 | [sounds sortUsingSelector: @selector(caseInsensitiveCompare:)]; |
---|
229 | |
---|
230 | //set download sound |
---|
231 | [fDownloadSoundPopUp removeAllItems]; |
---|
232 | [fDownloadSoundPopUp addItemsWithTitles: sounds]; |
---|
233 | |
---|
234 | BOOL playDownloadSound = [fDefaults boolForKey: @"PlayDownloadSound"]; |
---|
235 | [fPlayDownloadSoundCheck setState: playDownloadSound]; |
---|
236 | [fDownloadSoundPopUp setEnabled: playDownloadSound]; |
---|
237 | |
---|
238 | int downloadSoundIndex = [fDownloadSoundPopUp indexOfItemWithTitle: [fDefaults stringForKey: @"DownloadSound"]]; |
---|
239 | if (downloadSoundIndex >= 0) |
---|
240 | [fDownloadSoundPopUp selectItemAtIndex: downloadSoundIndex]; |
---|
241 | else |
---|
242 | [fDefaults setObject: [fDownloadSoundPopUp titleOfSelectedItem] forKey: @"DownloadSound"]; |
---|
243 | |
---|
244 | //set seeding sound |
---|
245 | [fSeedingSoundPopUp removeAllItems]; |
---|
246 | [fSeedingSoundPopUp addItemsWithTitles: sounds]; |
---|
247 | |
---|
248 | BOOL playSeedingSound = [fDefaults boolForKey: @"PlaySeedingSound"]; |
---|
249 | [fPlaySeedingSoundCheck setState: playSeedingSound]; |
---|
250 | [fSeedingSoundPopUp setEnabled: playSeedingSound]; |
---|
251 | |
---|
252 | int seedingSoundIndex = [fDownloadSoundPopUp indexOfItemWithTitle: [fDefaults stringForKey: @"SeedingSound"]]; |
---|
253 | if (seedingSoundIndex >= 0) |
---|
254 | [fSeedingSoundPopUp selectItemAtIndex: seedingSoundIndex]; |
---|
255 | else |
---|
256 | [fDefaults setObject: [fSeedingSoundPopUp titleOfSelectedItem] forKey: @"SeedingSound"]; |
---|
257 | |
---|
258 | //set start settings |
---|
259 | BOOL useQueue = [fDefaults boolForKey: @"Queue"]; |
---|
260 | [fQueueCheck setState: useQueue]; |
---|
261 | [fQueueNumberField setEnabled: useQueue]; |
---|
262 | [fQueueNumberField setIntValue: [fDefaults integerForKey: @"QueueDownloadNumber"]]; |
---|
263 | |
---|
264 | [fStartAtOpenCheck setState: [fDefaults boolForKey: @"AutoStartDownload"]]; |
---|
265 | |
---|
266 | //set private torrents |
---|
267 | BOOL copyTorrents = [fDefaults boolForKey: @"SavePrivateTorrent"]; |
---|
268 | [fCopyTorrentCheck setState: copyTorrents]; |
---|
269 | |
---|
270 | [fDeleteOriginalTorrentCheck setEnabled: copyTorrents]; |
---|
271 | [fDeleteOriginalTorrentCheck setState: [fDefaults boolForKey: @"DeleteOriginalTorrent"]]; |
---|
272 | |
---|
273 | //set update check |
---|
274 | NSString * updateCheck = [fDefaults stringForKey: @"UpdateCheck"]; |
---|
275 | if ([updateCheck isEqualToString: @"Weekly"]) |
---|
276 | [fUpdatePopUp selectItemAtIndex: UPDATE_WEEKLY]; |
---|
277 | else if ([updateCheck isEqualToString: @"Never"]) |
---|
278 | [fUpdatePopUp selectItemAtIndex: UPDATE_NEVER]; |
---|
279 | else |
---|
280 | [fUpdatePopUp selectItemAtIndex: UPDATE_DAILY]; |
---|
281 | } |
---|
282 | |
---|
283 | - (NSToolbarItem *) toolbar: (NSToolbar *) t itemForItemIdentifier: |
---|
284 | (NSString *) ident willBeInsertedIntoToolbar: (BOOL) flag |
---|
285 | { |
---|
286 | NSToolbarItem * item; |
---|
287 | item = [[NSToolbarItem alloc] initWithItemIdentifier: ident]; |
---|
288 | |
---|
289 | if ([ident isEqualToString: TOOLBAR_GENERAL]) |
---|
290 | { |
---|
291 | [item setLabel: NSLocalizedString(@"General", "Preferences -> General toolbar item title")]; |
---|
292 | [item setImage: [NSImage imageNamed: @"Preferences.png"]]; |
---|
293 | [item setTarget: self]; |
---|
294 | [item setAction: @selector(setPrefView:)]; |
---|
295 | } |
---|
296 | else if ([ident isEqualToString: TOOLBAR_TRANSFERS]) |
---|
297 | { |
---|
298 | [item setLabel: NSLocalizedString(@"Transfers", "Preferences -> Transfers toolbar item title")]; |
---|
299 | [item setImage: [NSImage imageNamed: @"Transfers.png"]]; |
---|
300 | [item setTarget: self]; |
---|
301 | [item setAction: @selector(setPrefView:)]; |
---|
302 | } |
---|
303 | else if ([ident isEqualToString: TOOLBAR_BANDWIDTH]) |
---|
304 | { |
---|
305 | [item setLabel: NSLocalizedString(@"Bandwidth", "Preferences -> Bandwidth toolbar item title")]; |
---|
306 | [item setImage: [NSImage imageNamed: @"Bandwidth.png"]]; |
---|
307 | [item setTarget: self]; |
---|
308 | [item setAction: @selector(setPrefView:)]; |
---|
309 | } |
---|
310 | else if ([ident isEqualToString: TOOLBAR_NETWORK]) |
---|
311 | { |
---|
312 | [item setLabel: NSLocalizedString(@"Network", "Preferences -> Network toolbar item title")]; |
---|
313 | [item setImage: [NSImage imageNamed: @"Network.png"]]; |
---|
314 | [item setTarget: self]; |
---|
315 | [item setAction: @selector(setPrefView:)]; |
---|
316 | } |
---|
317 | else |
---|
318 | { |
---|
319 | [item release]; |
---|
320 | return nil; |
---|
321 | } |
---|
322 | |
---|
323 | return item; |
---|
324 | } |
---|
325 | |
---|
326 | - (NSArray *) toolbarSelectableItemIdentifiers: (NSToolbar *) toolbar |
---|
327 | { |
---|
328 | return [self toolbarDefaultItemIdentifiers: toolbar]; |
---|
329 | } |
---|
330 | |
---|
331 | - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar |
---|
332 | { |
---|
333 | return [self toolbarAllowedItemIdentifiers: toolbar]; |
---|
334 | } |
---|
335 | |
---|
336 | - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar |
---|
337 | { |
---|
338 | return [NSArray arrayWithObjects: TOOLBAR_GENERAL, TOOLBAR_TRANSFERS, |
---|
339 | TOOLBAR_BANDWIDTH, TOOLBAR_NETWORK, nil]; |
---|
340 | } |
---|
341 | |
---|
342 | - (void) setPort: (id) sender |
---|
343 | { |
---|
344 | int bindPort = [sender intValue]; |
---|
345 | if (![[NSString stringWithInt: bindPort] isEqualToString: [sender stringValue]] |
---|
346 | || bindPort < MIN_PORT || bindPort > MAX_PORT) |
---|
347 | { |
---|
348 | NSBeep(); |
---|
349 | bindPort = [fDefaults integerForKey: @"BindPort"]; |
---|
350 | [sender setIntValue: bindPort]; |
---|
351 | } |
---|
352 | else |
---|
353 | { |
---|
354 | tr_setBindPort(fHandle, bindPort); |
---|
355 | [fDefaults setInteger: bindPort forKey: @"BindPort"]; |
---|
356 | |
---|
357 | [self updateNatStatus]; |
---|
358 | [self updatePortStatus]; |
---|
359 | } |
---|
360 | } |
---|
361 | |
---|
362 | - (void) updatePortStatus |
---|
363 | { |
---|
364 | long sytemVersion; |
---|
365 | [fPortStatusField setStringValue: @""]; |
---|
366 | [fPortStatusImage setImage: nil]; |
---|
367 | |
---|
368 | Gestalt('sysv', & sytemVersion); |
---|
369 | if (sytemVersion >= 0x1040) |
---|
370 | { |
---|
371 | //NSXML features are unfortunately only available since Mac OS X v10.4 |
---|
372 | PortChecker * checker = [[PortChecker alloc] initWithDelegate: self]; |
---|
373 | |
---|
374 | [fPortStatusField setStringValue: [NSLocalizedString(@"Checking port status", |
---|
375 | "Preferences -> Network -> port status") stringByAppendingEllipsis]]; |
---|
376 | [fPortStatusProgress startAnimation: self]; |
---|
377 | |
---|
378 | [checker probePort: [fDefaults integerForKey: @"BindPort"]]; |
---|
379 | } |
---|
380 | } |
---|
381 | |
---|
382 | - (void) portCheckerDidFinishProbing: (PortChecker *) portChecker |
---|
383 | { |
---|
384 | [fPortStatusProgress stopAnimation: self]; |
---|
385 | switch ([portChecker status]) |
---|
386 | { |
---|
387 | case PORT_STATUS_OPEN: |
---|
388 | [fPortStatusField setStringValue: NSLocalizedString(@"Port is open", "Preferences -> Network -> port status")]; |
---|
389 | [fPortStatusImage setImage: [NSImage imageNamed: @"GreenDot.tiff"]]; |
---|
390 | break; |
---|
391 | case PORT_STATUS_STEALTH: |
---|
392 | [fPortStatusField setStringValue: NSLocalizedString(@"Port is stealth", "Preferences -> Network -> port status")]; |
---|
393 | [fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]]; |
---|
394 | break; |
---|
395 | case PORT_STATUS_CLOSED: |
---|
396 | [fPortStatusField setStringValue: NSLocalizedString(@"Port is closed", "Preferences -> Network -> port status")]; |
---|
397 | [fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]]; |
---|
398 | break; |
---|
399 | case PORT_STATUS_ERROR: |
---|
400 | [fPortStatusField setStringValue: NSLocalizedString(@"Unable to check port status", |
---|
401 | "Preferences -> Network -> port status")]; |
---|
402 | [fPortStatusImage setImage: [NSImage imageNamed: @"YellowDot.tiff"]]; |
---|
403 | break; |
---|
404 | } |
---|
405 | [portChecker release]; |
---|
406 | } |
---|
407 | |
---|
408 | - (void) setNat: (id) sender |
---|
409 | { |
---|
410 | BOOL enable = [sender state] == NSOnState; |
---|
411 | enable ? tr_natTraversalEnable(fHandle) : tr_natTraversalDisable(fHandle); |
---|
412 | [fDefaults setBool: enable forKey: @"NatTraversal"]; |
---|
413 | |
---|
414 | [self updateNatStatus]; |
---|
415 | } |
---|
416 | |
---|
417 | - (void) updateNatStatus |
---|
418 | { |
---|
419 | int status = tr_natTraversalStatus(fHandle); |
---|
420 | if (fNatStatus == status) |
---|
421 | return; |
---|
422 | fNatStatus = status; |
---|
423 | |
---|
424 | if (status == 2) |
---|
425 | { |
---|
426 | [fNatStatusField setStringValue: NSLocalizedString(@"Port successfully mapped", |
---|
427 | "Preferences -> Network -> port map status")]; |
---|
428 | [fNatStatusImage setImage: [NSImage imageNamed: @"GreenDot.tiff"]]; |
---|
429 | } |
---|
430 | else if (status == 3 || status == 4) |
---|
431 | { |
---|
432 | [fNatStatusField setStringValue: NSLocalizedString(@"Error mapping port", |
---|
433 | "Preferences -> Network -> port map status")]; |
---|
434 | [fNatStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]]; |
---|
435 | } |
---|
436 | else |
---|
437 | { |
---|
438 | [fNatStatusField setStringValue: @""]; |
---|
439 | [fNatStatusImage setImage: nil]; |
---|
440 | } |
---|
441 | |
---|
442 | [self updatePortStatus]; |
---|
443 | } |
---|
444 | |
---|
445 | - (void) setLimit: (id) sender |
---|
446 | { |
---|
447 | NSString * key; |
---|
448 | NSButton * check; |
---|
449 | NSString * type; |
---|
450 | if (sender == fUploadField) |
---|
451 | { |
---|
452 | key = @"UploadLimit"; |
---|
453 | check = fUploadCheck; |
---|
454 | type = @"Upload"; |
---|
455 | } |
---|
456 | else |
---|
457 | { |
---|
458 | key = @"DownloadLimit"; |
---|
459 | check = fDownloadCheck; |
---|
460 | type = @"Download"; |
---|
461 | } |
---|
462 | |
---|
463 | int limit = [sender intValue]; |
---|
464 | if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0) |
---|
465 | { |
---|
466 | NSBeep(); |
---|
467 | limit = [fDefaults integerForKey: key]; |
---|
468 | [sender setIntValue: limit]; |
---|
469 | } |
---|
470 | else |
---|
471 | { |
---|
472 | if (![fDefaults boolForKey: @"SpeedLimit"]) |
---|
473 | { |
---|
474 | int realLimit = [check state] ? limit : -1; |
---|
475 | if (sender == fUploadField) |
---|
476 | tr_setUploadLimit(fHandle, realLimit); |
---|
477 | else |
---|
478 | tr_setDownloadLimit(fHandle, realLimit); |
---|
479 | } |
---|
480 | |
---|
481 | [fDefaults setInteger: limit forKey: key]; |
---|
482 | } |
---|
483 | |
---|
484 | NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: |
---|
485 | [NSNumber numberWithBool: [check state]], @"Enable", |
---|
486 | [NSNumber numberWithInt: limit], @"Limit", |
---|
487 | type, @"Type", nil]; |
---|
488 | [[NSNotificationCenter defaultCenter] postNotificationName: @"LimitGlobalChange" object: dict]; |
---|
489 | } |
---|
490 | |
---|
491 | - (void) setLimitCheck: (id) sender |
---|
492 | { |
---|
493 | NSString * key; |
---|
494 | NSTextField * field; |
---|
495 | if (sender == fUploadCheck) |
---|
496 | { |
---|
497 | key = @"CheckUpload"; |
---|
498 | field = fUploadField; |
---|
499 | } |
---|
500 | else |
---|
501 | { |
---|
502 | key = @"CheckDownload"; |
---|
503 | field = fDownloadField; |
---|
504 | } |
---|
505 | |
---|
506 | BOOL check = [sender state] == NSOnState; |
---|
507 | [self setLimit: field]; |
---|
508 | [field setEnabled: check]; |
---|
509 | |
---|
510 | [fDefaults setBool: check forKey: key]; |
---|
511 | } |
---|
512 | |
---|
513 | - (void) setLimitEnabled: (BOOL) enable type: (NSString *) type |
---|
514 | { |
---|
515 | NSButton * check = [type isEqualToString: @"Upload"] ? fUploadCheck : fDownloadCheck; |
---|
516 | [check setState: enable ? NSOnState : NSOffState]; |
---|
517 | [self setLimitCheck: check]; |
---|
518 | } |
---|
519 | |
---|
520 | - (void) setQuickLimit: (int) limit type: (NSString *) type |
---|
521 | { |
---|
522 | NSButton * check; |
---|
523 | if ([type isEqualToString: @"Upload"]) |
---|
524 | { |
---|
525 | [fUploadField setIntValue: limit]; |
---|
526 | check = fUploadCheck; |
---|
527 | } |
---|
528 | else |
---|
529 | { |
---|
530 | [fDownloadField setIntValue: limit]; |
---|
531 | check = fDownloadCheck; |
---|
532 | } |
---|
533 | [check setState: NSOnState]; |
---|
534 | [self setLimitCheck: check]; |
---|
535 | } |
---|
536 | |
---|
537 | - (void) enableSpeedLimit: (BOOL) enable |
---|
538 | { |
---|
539 | if ([fDefaults boolForKey: @"SpeedLimit"] != enable) |
---|
540 | { |
---|
541 | [fDefaults setBool: enable forKey: @"SpeedLimit"]; |
---|
542 | |
---|
543 | if (enable) |
---|
544 | { |
---|
545 | tr_setUploadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]); |
---|
546 | tr_setDownloadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]); |
---|
547 | } |
---|
548 | else |
---|
549 | { |
---|
550 | tr_setUploadLimit(fHandle, [fUploadCheck state] ? [fDefaults integerForKey: @"UploadLimit"] : -1); |
---|
551 | tr_setDownloadLimit(fHandle, [fDownloadCheck state] ? [fDefaults integerForKey: @"DownloadLimit"] : -1); |
---|
552 | } |
---|
553 | } |
---|
554 | } |
---|
555 | |
---|
556 | - (void) setSpeedLimit: (id) sender |
---|
557 | { |
---|
558 | NSString * key = sender == fSpeedLimitUploadField ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit"; |
---|
559 | |
---|
560 | int limit = [sender intValue]; |
---|
561 | if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0) |
---|
562 | { |
---|
563 | NSBeep(); |
---|
564 | limit = [fDefaults integerForKey: key]; |
---|
565 | [sender setIntValue: limit]; |
---|
566 | } |
---|
567 | else |
---|
568 | { |
---|
569 | if ([fDefaults boolForKey: @"SpeedLimit"]) |
---|
570 | { |
---|
571 | if (sender == fSpeedLimitUploadField) |
---|
572 | tr_setUploadLimit(fHandle, limit); |
---|
573 | else |
---|
574 | tr_setDownloadLimit(fHandle, limit); |
---|
575 | } |
---|
576 | |
---|
577 | [fDefaults setInteger: limit forKey: key]; |
---|
578 | } |
---|
579 | } |
---|
580 | |
---|
581 | - (void) setAutoSpeedLimitCheck: (id) sender |
---|
582 | { |
---|
583 | BOOL check = [sender state] == NSOnState; |
---|
584 | |
---|
585 | [fDefaults setBool: check forKey: @"SpeedLimitAuto"]; |
---|
586 | |
---|
587 | [self setAutoSpeedLimitHour: fSpeedLimitAutoOnField]; |
---|
588 | [fSpeedLimitAutoOnField setEnabled: check]; |
---|
589 | |
---|
590 | [self setAutoSpeedLimitHour: fSpeedLimitAutoOffField]; |
---|
591 | [fSpeedLimitAutoOffField setEnabled: check]; |
---|
592 | } |
---|
593 | |
---|
594 | - (void) setAutoSpeedLimitHour: (id) sender |
---|
595 | { |
---|
596 | NSString * key = (sender == fSpeedLimitAutoOnField) ? @"SpeedLimitAutoOnHour" : @"SpeedLimitAutoOffHour"; |
---|
597 | |
---|
598 | int hour = [sender intValue]; |
---|
599 | |
---|
600 | //allow numbers under ten in the format 0x |
---|
601 | if (!([[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", hour]] |
---|
602 | || [[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%02d", hour]]) || hour < 0 || hour > 23 |
---|
603 | || [fSpeedLimitAutoOnField intValue] == [fSpeedLimitAutoOffField intValue]) |
---|
604 | { |
---|
605 | NSBeep(); |
---|
606 | hour = [fDefaults integerForKey: key]; |
---|
607 | [sender setStringValue: [NSString stringWithFormat: @"%02d", hour]]; |
---|
608 | } |
---|
609 | else |
---|
610 | [fDefaults setInteger: hour forKey: key]; |
---|
611 | |
---|
612 | [sender setStringValue: [NSString stringWithFormat: @"%02d", hour]]; //ensure number has 2 digits |
---|
613 | |
---|
614 | [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSpeedLimitChange" object: self]; |
---|
615 | } |
---|
616 | |
---|
617 | - (void) setRatio: (id) sender |
---|
618 | { |
---|
619 | float ratioLimit = [sender floatValue]; |
---|
620 | if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%.2f", ratioLimit]] |
---|
621 | || ratioLimit < 0) |
---|
622 | { |
---|
623 | NSBeep(); |
---|
624 | ratioLimit = [fDefaults floatForKey: @"RatioLimit"]; |
---|
625 | [sender setFloatValue: ratioLimit]; |
---|
626 | } |
---|
627 | else |
---|
628 | [fDefaults setFloat: ratioLimit forKey: @"RatioLimit"]; |
---|
629 | |
---|
630 | NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: |
---|
631 | [NSNumber numberWithBool: [fRatioCheck state]], @"Enable", |
---|
632 | [NSNumber numberWithFloat: ratioLimit], @"Ratio", nil]; |
---|
633 | [[NSNotificationCenter defaultCenter] postNotificationName: @"RatioGlobalChange" object: dict]; |
---|
634 | } |
---|
635 | |
---|
636 | - (void) setRatioCheck: (id) sender |
---|
637 | { |
---|
638 | BOOL check = [sender state] == NSOnState; |
---|
639 | [self setRatio: fRatioField]; |
---|
640 | [fRatioField setEnabled: check]; |
---|
641 | |
---|
642 | [fDefaults setBool: check forKey: @"RatioCheck"]; |
---|
643 | } |
---|
644 | |
---|
645 | - (void) setRatioEnabled: (BOOL) enable |
---|
646 | { |
---|
647 | int state = enable ? NSOnState : NSOffState; |
---|
648 | |
---|
649 | [fRatioCheck setState: state]; |
---|
650 | [self setRatioCheck: fRatioCheck]; |
---|
651 | } |
---|
652 | |
---|
653 | - (void) setQuickRatio: (float) ratioLimit |
---|
654 | { |
---|
655 | [fRatioField setFloatValue: ratioLimit]; |
---|
656 | |
---|
657 | [fRatioCheck setState: NSOnState]; |
---|
658 | [self setRatioCheck: fRatioCheck]; |
---|
659 | } |
---|
660 | |
---|
661 | - (void) setShowMessage: (id) sender |
---|
662 | { |
---|
663 | BOOL state = [sender state]; |
---|
664 | |
---|
665 | if (sender == fQuitCheck) |
---|
666 | { |
---|
667 | [fDefaults setBool: state forKey: @"CheckQuit"]; |
---|
668 | [fQuitDownloadingCheck setEnabled: state]; |
---|
669 | } |
---|
670 | else if (sender == fRemoveCheck) |
---|
671 | { |
---|
672 | [fDefaults setBool: state forKey: @"CheckRemove"]; |
---|
673 | [fRemoveDownloadingCheck setEnabled: state]; |
---|
674 | } |
---|
675 | if (sender == fQuitDownloadingCheck) |
---|
676 | [fDefaults setBool: state forKey: @"CheckQuitDownloading"]; |
---|
677 | else if (sender == fRemoveDownloadingCheck) |
---|
678 | [fDefaults setBool: state forKey: @"CheckRemoveDownloading"]; |
---|
679 | else; |
---|
680 | } |
---|
681 | |
---|
682 | - (void) setBadge: (id) sender |
---|
683 | { |
---|
684 | if (sender == fBadgeDownloadRateCheck) |
---|
685 | [fDefaults setBool: [sender state] forKey: @"BadgeDownloadRate"]; |
---|
686 | else if (sender == fBadgeUploadRateCheck) |
---|
687 | [fDefaults setBool: [sender state] forKey: @"BadgeUploadRate"]; |
---|
688 | else; |
---|
689 | |
---|
690 | [[NSNotificationCenter defaultCenter] postNotificationName: @"DockBadgeChange" object: self]; |
---|
691 | } |
---|
692 | |
---|
693 | - (void) setPlaySound: (id) sender |
---|
694 | { |
---|
695 | BOOL state = [sender state]; |
---|
696 | |
---|
697 | if (sender == fPlayDownloadSoundCheck) |
---|
698 | { |
---|
699 | [fDownloadSoundPopUp setEnabled: state]; |
---|
700 | [fDefaults setBool: state forKey: @"PlayDownloadSound"]; |
---|
701 | } |
---|
702 | else if (sender == fPlaySeedingSoundCheck) |
---|
703 | { |
---|
704 | [fSeedingSoundPopUp setEnabled: state]; |
---|
705 | [fDefaults setBool: state forKey: @"PlaySeedingSound"]; |
---|
706 | } |
---|
707 | else; |
---|
708 | } |
---|
709 | |
---|
710 | - (void) setSound: (id) sender |
---|
711 | { |
---|
712 | //play sound when selecting |
---|
713 | NSString * soundName = [sender titleOfSelectedItem]; |
---|
714 | NSSound * sound; |
---|
715 | if ((sound = [NSSound soundNamed: soundName])) |
---|
716 | [sound play]; |
---|
717 | |
---|
718 | if (sender == fDownloadSoundPopUp) |
---|
719 | [fDefaults setObject: soundName forKey: @"DownloadSound"]; |
---|
720 | else if (sender == fSeedingSoundPopUp) |
---|
721 | [fDefaults setObject: soundName forKey: @"SeedingSound"]; |
---|
722 | else; |
---|
723 | } |
---|
724 | |
---|
725 | - (void) setUpdate: (id) sender |
---|
726 | { |
---|
727 | int index = [fUpdatePopUp indexOfSelectedItem]; |
---|
728 | NSTimeInterval seconds; |
---|
729 | if (index == UPDATE_DAILY) |
---|
730 | { |
---|
731 | [fDefaults setObject: @"Daily" forKey: @"UpdateCheck"]; |
---|
732 | seconds = 86400; |
---|
733 | } |
---|
734 | else if (index == UPDATE_WEEKLY) |
---|
735 | { |
---|
736 | [fDefaults setObject: @"Weekly" forKey: @"UpdateCheck"]; |
---|
737 | seconds = 604800; |
---|
738 | } |
---|
739 | else |
---|
740 | { |
---|
741 | [fDefaults setObject: @"Never" forKey: @"UpdateCheck"]; |
---|
742 | seconds = 0; |
---|
743 | } |
---|
744 | |
---|
745 | [fDefaults setInteger: seconds forKey: @"SUScheduledCheckInterval"]; |
---|
746 | [fUpdater scheduleCheckWithInterval: seconds]; |
---|
747 | } |
---|
748 | |
---|
749 | - (void) setStartAtOpen: (id) sender |
---|
750 | { |
---|
751 | [fDefaults setBool: [sender state] == NSOnState forKey: @"AutoStartDownload"]; |
---|
752 | } |
---|
753 | |
---|
754 | - (void) setUseQueue: (id) sender |
---|
755 | { |
---|
756 | BOOL useQueue = [sender state] == NSOnState; |
---|
757 | |
---|
758 | [fDefaults setBool: useQueue forKey: @"Queue"]; |
---|
759 | [self setQueueNumber: fQueueNumberField]; |
---|
760 | [fQueueNumberField setEnabled: useQueue]; |
---|
761 | } |
---|
762 | |
---|
763 | - (void) setQueueNumber: (id) sender |
---|
764 | { |
---|
765 | int queueNumber = [sender intValue]; |
---|
766 | if (![[sender stringValue] isEqualToString: [NSString stringWithInt: queueNumber]] || queueNumber < 1) |
---|
767 | { |
---|
768 | NSBeep(); |
---|
769 | queueNumber = [fDefaults integerForKey: @"QueueDownloadNumber"]; |
---|
770 | [sender setIntValue: queueNumber]; |
---|
771 | } |
---|
772 | else |
---|
773 | [fDefaults setInteger: queueNumber forKey: @"QueueDownloadNumber"]; |
---|
774 | |
---|
775 | [[NSNotificationCenter defaultCenter] postNotificationName: @"GlobalStartSettingChange" object: self]; |
---|
776 | } |
---|
777 | |
---|
778 | - (void) setMoveTorrent: (id) sender |
---|
779 | { |
---|
780 | int state = [sender state]; |
---|
781 | if (sender == fCopyTorrentCheck) |
---|
782 | { |
---|
783 | [fDefaults setBool: state forKey: @"SavePrivateTorrent"]; |
---|
784 | |
---|
785 | [fDeleteOriginalTorrentCheck setEnabled: state]; |
---|
786 | if (state == NSOffState) |
---|
787 | { |
---|
788 | [fDeleteOriginalTorrentCheck setState: NSOffState]; |
---|
789 | [fDefaults setBool: NO forKey: @"DeleteOriginalTorrent"]; |
---|
790 | } |
---|
791 | } |
---|
792 | else |
---|
793 | [fDefaults setBool: state forKey: @"DeleteOriginalTorrent"]; |
---|
794 | } |
---|
795 | |
---|
796 | - (void) setDownloadLocation: (id) sender |
---|
797 | { |
---|
798 | //Download folder |
---|
799 | switch ([fFolderPopUp indexOfSelectedItem]) |
---|
800 | { |
---|
801 | case DOWNLOAD_FOLDER: |
---|
802 | [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"]; |
---|
803 | break; |
---|
804 | case DOWNLOAD_TORRENT: |
---|
805 | [fDefaults setObject: @"Torrent" forKey: @"DownloadChoice"]; |
---|
806 | break; |
---|
807 | case DOWNLOAD_ASK: |
---|
808 | [fDefaults setObject: @"Ask" forKey: @"DownloadChoice"]; |
---|
809 | break; |
---|
810 | } |
---|
811 | } |
---|
812 | |
---|
813 | - (void) checkUpdate |
---|
814 | { |
---|
815 | [fUpdater checkForUpdates: nil]; |
---|
816 | } |
---|
817 | |
---|
818 | - (void) folderSheetShow: (id) sender |
---|
819 | { |
---|
820 | NSOpenPanel * panel = [NSOpenPanel openPanel]; |
---|
821 | |
---|
822 | [panel setPrompt: @"Select"]; |
---|
823 | [panel setAllowsMultipleSelection: NO]; |
---|
824 | [panel setCanChooseFiles: NO]; |
---|
825 | [panel setCanChooseDirectories: YES]; |
---|
826 | [panel setCanCreateDirectories: YES]; |
---|
827 | |
---|
828 | [panel beginSheetForDirectory: nil file: nil types: nil |
---|
829 | modalForWindow: [self window] modalDelegate: self didEndSelector: |
---|
830 | @selector(folderSheetClosed:returnCode:contextInfo:) contextInfo: nil]; |
---|
831 | } |
---|
832 | |
---|
833 | - (void) setAutoImport: (id) sender |
---|
834 | { |
---|
835 | int state = [fAutoImportCheck state]; |
---|
836 | [fDefaults setBool: state forKey: @"AutoImport"]; |
---|
837 | [fImportFolderPopUp setEnabled: state]; |
---|
838 | |
---|
839 | if (state == NSOnState) |
---|
840 | [[UKKQueue sharedFileWatcher] addPath: fImportFolder]; |
---|
841 | else |
---|
842 | [[UKKQueue sharedFileWatcher] removePathFromQueue: fImportFolder]; |
---|
843 | |
---|
844 | [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self]; |
---|
845 | } |
---|
846 | |
---|
847 | - (void) importFolderSheetShow: (id) sender |
---|
848 | { |
---|
849 | NSOpenPanel * panel = [NSOpenPanel openPanel]; |
---|
850 | |
---|
851 | [panel setPrompt: @"Select"]; |
---|
852 | [panel setAllowsMultipleSelection: NO]; |
---|
853 | [panel setCanChooseFiles: NO]; |
---|
854 | [panel setCanChooseDirectories: YES]; |
---|
855 | [panel setCanCreateDirectories: YES]; |
---|
856 | |
---|
857 | [panel beginSheetForDirectory: nil file: nil types: nil |
---|
858 | modalForWindow: [self window] modalDelegate: self didEndSelector: |
---|
859 | @selector(importFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil]; |
---|
860 | } |
---|
861 | |
---|
862 | - (void) setAutoSize: (id) sender |
---|
863 | { |
---|
864 | [fDefaults setBool: [sender state] forKey: @"AutoSize"]; |
---|
865 | |
---|
866 | [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSizeSettingChange" object: self]; |
---|
867 | } |
---|
868 | |
---|
869 | - (void) helpForNetwork: (id) sender |
---|
870 | { |
---|
871 | [[NSHelpManager sharedHelpManager] openHelpAnchor: @"PortForwarding" |
---|
872 | inBook: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"]]; |
---|
873 | } |
---|
874 | |
---|
875 | @end |
---|
876 | |
---|
877 | @implementation PrefsController (Private) |
---|
878 | |
---|
879 | - (void) setPrefView: (id) sender |
---|
880 | { |
---|
881 | NSView * view = fGeneralView; |
---|
882 | if (sender) |
---|
883 | { |
---|
884 | NSString * identifier = [sender itemIdentifier]; |
---|
885 | if ([identifier isEqualToString: TOOLBAR_TRANSFERS]) |
---|
886 | view = fTransfersView; |
---|
887 | else if ([identifier isEqualToString: TOOLBAR_BANDWIDTH]) |
---|
888 | view = fBandwidthView; |
---|
889 | else if ([identifier isEqualToString: TOOLBAR_NETWORK]) |
---|
890 | view = fNetworkView; |
---|
891 | else; |
---|
892 | } |
---|
893 | |
---|
894 | NSWindow * window = [self window]; |
---|
895 | if ([window contentView] == view) |
---|
896 | return; |
---|
897 | |
---|
898 | NSRect windowRect = [window frame]; |
---|
899 | int difference = [view frame].size.height - [[window contentView] frame].size.height; |
---|
900 | windowRect.origin.y -= difference; |
---|
901 | windowRect.size.height += difference; |
---|
902 | |
---|
903 | [view setHidden: YES]; |
---|
904 | [window setContentView: view]; |
---|
905 | [window setFrame: windowRect display: YES animate: YES]; |
---|
906 | [view setHidden: NO]; |
---|
907 | |
---|
908 | //set title label |
---|
909 | if (sender) |
---|
910 | [window setTitle: [sender label]]; |
---|
911 | else |
---|
912 | { |
---|
913 | NSToolbarItem * item; |
---|
914 | NSEnumerator * enumerator = [[fToolbar items] objectEnumerator]; |
---|
915 | while ((item = [enumerator nextObject])) |
---|
916 | if ([[item itemIdentifier] isEqualToString: [fToolbar selectedItemIdentifier]]) |
---|
917 | { |
---|
918 | [window setTitle: [item label]]; |
---|
919 | break; |
---|
920 | } |
---|
921 | } |
---|
922 | |
---|
923 | //for network view make sure progress indicator hides itself |
---|
924 | if (view == fNetworkView && [fPortStatusImage image]) |
---|
925 | [fPortStatusProgress setDisplayedWhenStopped: NO]; |
---|
926 | } |
---|
927 | |
---|
928 | - (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info |
---|
929 | { |
---|
930 | if (code == NSOKButton) |
---|
931 | { |
---|
932 | [fDownloadFolder release]; |
---|
933 | fDownloadFolder = [[[openPanel filenames] objectAtIndex: 0] retain]; |
---|
934 | |
---|
935 | [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER]; |
---|
936 | [fDefaults setObject: fDownloadFolder forKey: @"DownloadFolder"]; |
---|
937 | [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"]; |
---|
938 | |
---|
939 | [self updatePopUp]; |
---|
940 | } |
---|
941 | else |
---|
942 | { |
---|
943 | //reset if cancelled |
---|
944 | NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"]; |
---|
945 | if ([downloadChoice isEqualToString: @"Constant"]) |
---|
946 | [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER]; |
---|
947 | else if ([downloadChoice isEqualToString: @"Torrent"]) |
---|
948 | [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT]; |
---|
949 | else |
---|
950 | [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK]; |
---|
951 | } |
---|
952 | } |
---|
953 | |
---|
954 | - (void) updatePopUp |
---|
955 | { |
---|
956 | //get and resize the icon |
---|
957 | NSImage * icon = [[NSWorkspace sharedWorkspace] iconForFile: fDownloadFolder]; |
---|
958 | [icon setScalesWhenResized: YES]; |
---|
959 | [icon setSize: NSMakeSize(16.0, 16.0)]; |
---|
960 | |
---|
961 | //update menu item |
---|
962 | NSMenuItem * menuItem = (NSMenuItem *) [fFolderPopUp itemAtIndex: 0]; |
---|
963 | [menuItem setTitle: [fDownloadFolder lastPathComponent]]; |
---|
964 | [menuItem setImage: icon]; |
---|
965 | } |
---|
966 | |
---|
967 | - (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info |
---|
968 | { |
---|
969 | if (code == NSOKButton) |
---|
970 | { |
---|
971 | UKKQueue * sharedQueue = [UKKQueue sharedFileWatcher]; |
---|
972 | [sharedQueue removePathFromQueue: fImportFolder]; |
---|
973 | |
---|
974 | [fImportFolder release]; |
---|
975 | fImportFolder = [[[openPanel filenames] objectAtIndex: 0] retain]; |
---|
976 | |
---|
977 | [fDefaults setObject: fImportFolder forKey: @"AutoImportDirectory"]; |
---|
978 | |
---|
979 | [self updateImportPopUp]; |
---|
980 | |
---|
981 | [sharedQueue addPath: fImportFolder]; |
---|
982 | |
---|
983 | [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self]; |
---|
984 | } |
---|
985 | [fImportFolderPopUp selectItemAtIndex: 0]; |
---|
986 | } |
---|
987 | |
---|
988 | - (void) updateImportPopUp |
---|
989 | { |
---|
990 | //get and resize the icon |
---|
991 | NSImage * icon = [[NSWorkspace sharedWorkspace] iconForFile: fImportFolder]; |
---|
992 | [icon setScalesWhenResized: YES]; |
---|
993 | [icon setSize: NSMakeSize(16.0, 16.0)]; |
---|
994 | |
---|
995 | //update menu item |
---|
996 | NSMenuItem * menuItem = (NSMenuItem *) [fImportFolderPopUp itemAtIndex: 0]; |
---|
997 | [menuItem setTitle: [fImportFolder lastPathComponent]]; |
---|
998 | [menuItem setImage: icon]; |
---|
999 | } |
---|
1000 | |
---|
1001 | @end |
---|