source: trunk/macosx/PrefsController.m @ 4205

Last change on this file since 4205 was 4205, checked in by livings124, 15 years ago

ensure that a single portchecker can be used for only a single check

  • Property svn:keywords set to Date Rev Author Id
File size: 21.6 KB
Line 
1/******************************************************************************
2 * $Id: PrefsController.m 4205 2007-12-18 20:10:23Z 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 "NSApplicationAdditions.h"
27#import "NSStringAdditions.h"
28#import "UKKQueue.h"
29
30#define DOWNLOAD_FOLDER     0
31#define DOWNLOAD_TORRENT    2
32#define DOWNLOAD_ASK        3
33
34#define UPDATE_SECONDS 86400
35
36#define TOOLBAR_GENERAL     @"TOOLBAR_GENERAL"
37#define TOOLBAR_TRANSFERS   @"TOOLBAR_TRANSFERS"
38#define TOOLBAR_BANDWIDTH   @"TOOLBAR_BANDWIDTH"
39#define TOOLBAR_ADVANCED    @"TOOLBAR_ADVANCED"
40
41@interface PrefsController (Private)
42
43- (void) setPrefView: (id) sender;
44
45- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
46- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
47- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
48
49@end
50
51@implementation PrefsController
52
53- (id) initWithHandle: (tr_handle *) handle
54{
55    if ((self = [super initWithWindowNibName: @"PrefsWindow"]))
56    {
57        fDefaults = [NSUserDefaults standardUserDefaults];
58        fHandle = handle;
59       
60        //checks for old version upload speed of -1
61        if ([fDefaults integerForKey: @"UploadLimit"] < 0)
62        {
63            [fDefaults setInteger: 20 forKey: @"UploadLimit"];
64            [fDefaults setBool: NO forKey: @"CheckUpload"];
65        }
66       
67        //set check for update to right value
68        [self setCheckForUpdate: nil];
69       
70        //set auto import
71        NSString * autoPath;
72        if ([fDefaults boolForKey: @"AutoImport"] && (autoPath = [fDefaults stringForKey: @"AutoImportDirectory"]))
73            [[UKKQueue sharedFileWatcher] addPath: [autoPath stringByExpandingTildeInPath]];
74       
75        //set bind port
76        tr_setBindPort(fHandle, [fDefaults integerForKey: @"BindPort"]);
77       
78        //set NAT
79        tr_natTraversalEnable(fHandle, [fDefaults boolForKey: @"NatTraversal"]);
80       
81        //set encryption
82        [self setEncryptionMode: nil];
83       
84        //actually set bandwidth limits
85        [self applySpeedSettings: nil];
86    }
87   
88    return self;
89}
90
91- (void) dealloc
92{
93    if (fPortStatusTimer)
94        [fPortStatusTimer invalidate];
95   
96    [super dealloc];
97}
98
99- (void) awakeFromNib
100{
101    fHasLoaded = YES;
102   
103    NSToolbar * toolbar = [[NSToolbar alloc] initWithIdentifier: @"Preferences Toolbar"];
104    [toolbar setDelegate: self];
105    [toolbar setAllowsUserCustomization: NO];
106    [toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
107    [toolbar setSizeMode: NSToolbarSizeModeRegular];
108    [toolbar setSelectedItemIdentifier: TOOLBAR_GENERAL];
109    [[self window] setToolbar: toolbar];
110    [toolbar release];
111   
112    [self setPrefView: nil];
113   
114    //set download folder
115    NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
116    if ([downloadChoice isEqualToString: @"Constant"])
117        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
118    else if ([downloadChoice isEqualToString: @"Torrent"])
119        [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
120    else
121        [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
122   
123    //set stop ratio
124    [self updateRatioStopField];
125   
126    //set limits
127    [self updateLimitFields];
128   
129    //set speed limit
130    [fSpeedLimitUploadField setIntValue: [fDefaults integerForKey: @"SpeedLimitUploadLimit"]];
131    [fSpeedLimitDownloadField setIntValue: [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]];
132   
133    //set port
134    [fPortField setIntValue: [fDefaults integerForKey: @"BindPort"]];
135    fNatStatus = -1;
136   
137    [self updatePortStatus];
138    fPortStatusTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0 target: self
139                        selector: @selector(updatePortStatus) userInfo: nil repeats: YES];
140   
141    //set queue values
142    [fQueueDownloadField setIntValue: [fDefaults integerForKey: @"QueueDownloadNumber"]];
143    [fQueueSeedField setIntValue: [fDefaults integerForKey: @"QueueSeedNumber"]];
144    [fStalledField setIntValue: [fDefaults integerForKey: @"StalledMinutes"]];
145}
146
147- (void) setUpdater: (SUUpdater *) updater
148{
149    fUpdater = updater;
150}
151
152- (NSToolbarItem *) toolbar: (NSToolbar *) toolbar itemForItemIdentifier: (NSString *) ident willBeInsertedIntoToolbar: (BOOL) flag
153{
154    NSToolbarItem * item;
155    item = [[NSToolbarItem alloc] initWithItemIdentifier: ident];
156
157    if ([ident isEqualToString: TOOLBAR_GENERAL])
158    {
159        [item setLabel: NSLocalizedString(@"General", "Preferences -> General toolbar item title")];
160        [item setImage: [NSImage imageNamed: [NSApp isOnLeopardOrBetter] ? NSImageNamePreferencesGeneral : @"Preferences.png"]];
161        [item setTarget: self];
162        [item setAction: @selector(setPrefView:)];
163        [item setAutovalidates: NO];
164    }
165    else if ([ident isEqualToString: TOOLBAR_TRANSFERS])
166    {
167        [item setLabel: NSLocalizedString(@"Transfers", "Preferences -> Transfers toolbar item title")];
168        [item setImage: [NSImage imageNamed: @"Transfers.png"]];
169        [item setTarget: self];
170        [item setAction: @selector(setPrefView:)];
171        [item setAutovalidates: NO];
172    }
173    else if ([ident isEqualToString: TOOLBAR_BANDWIDTH])
174    {
175        [item setLabel: NSLocalizedString(@"Bandwidth", "Preferences -> Bandwidth toolbar item title")];
176        [item setImage: [NSImage imageNamed: @"Bandwidth.png"]];
177        [item setTarget: self];
178        [item setAction: @selector(setPrefView:)];
179        [item setAutovalidates: NO];
180    }
181    else if ([ident isEqualToString: TOOLBAR_ADVANCED])
182    {
183        [item setLabel: NSLocalizedString(@"Advanced", "Preferences -> Advanced toolbar item title")];
184        [item setImage: [NSImage imageNamed: [NSApp isOnLeopardOrBetter] ? NSImageNameAdvanced : @"Advanced.png"]];
185        [item setTarget: self];
186        [item setAction: @selector(setPrefView:)];
187        [item setAutovalidates: NO];
188    }
189    else
190    {
191        [item release];
192        return nil;
193    }
194
195    return [item autorelease];
196}
197
198- (NSArray *) toolbarSelectableItemIdentifiers: (NSToolbar *) toolbar
199{
200    return [self toolbarDefaultItemIdentifiers: toolbar];
201}
202
203- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
204{
205    return [self toolbarAllowedItemIdentifiers: toolbar];
206}
207
208- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
209{
210    return [NSArray arrayWithObjects: TOOLBAR_GENERAL, TOOLBAR_TRANSFERS, TOOLBAR_BANDWIDTH, TOOLBAR_ADVANCED, nil];
211}
212
213- (void) setPort: (id) sender
214{
215    int port = [sender intValue];
216    [fDefaults setInteger: port forKey: @"BindPort"];
217    tr_setBindPort(fHandle, port);
218   
219    fPublicPort = -1;
220    [self updatePortStatus];
221}
222
223- (void) setNat: (id) sender
224{
225    tr_natTraversalEnable(fHandle, [fDefaults boolForKey: @"NatTraversal"]);
226    [self updatePortStatus];
227}
228
229- (void) updatePortStatus
230{
231#warning look into
232    tr_handle_status * stat = tr_handleStatus(fHandle);
233    if (fNatStatus != stat->natTraversalStatus || fPublicPort != stat->publicPort)
234    {
235        fNatStatus = stat->natTraversalStatus;
236        fPublicPort = stat->publicPort;
237       
238        [fPortStatusField setStringValue: [NSLocalizedString(@"Checking port status",
239                                            "Preferences -> Advanced -> port status") stringByAppendingEllipsis]];
240        [fPortStatusImage setImage: nil];
241        [fPortStatusProgress startAnimation: self];
242       
243        if (fPortChecker)
244        {
245            [fPortChecker endProbe];
246            [fPortChecker release];
247        }
248        fPortChecker = [[PortChecker alloc] initForPort: fPublicPort withDelegate: self];
249    }
250}
251
252- (void) portCheckerDidFinishProbing: (PortChecker *) portChecker
253{
254    [fPortStatusProgress stopAnimation: self];
255    switch ([portChecker status])
256    {
257        case PORT_STATUS_OPEN:
258            [fPortStatusField setStringValue: NSLocalizedString(@"Port is open", "Preferences -> Advanced -> port status")];
259            [fPortStatusImage setImage: [NSImage imageNamed: @"GreenDot.png"]];
260            break;
261        case PORT_STATUS_CLOSED:
262            [fPortStatusField setStringValue: NSLocalizedString(@"Port is closed", "Preferences -> Advanced -> port status")];
263            [fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.png"]];
264            break;
265        case PORT_STATUS_ERROR:
266            [fPortStatusField setStringValue: NSLocalizedString(@"Unable to check port status",
267                                                "Preferences -> Advanced -> port status")];
268            [fPortStatusImage setImage: [NSImage imageNamed: @"YellowDot.png"]];
269            break;
270    }
271    [fPortChecker release];
272    fPortChecker = nil;
273}
274
275- (NSArray *) sounds
276{
277    NSMutableArray * sounds = [NSMutableArray array];
278   
279    //until Apple can fix soundNamed to not crash on invalid sound files, don't use custom sounds
280    NSArray * directories = [NSArray arrayWithObjects: @"/System/Library/Sounds", @"/Library/Sounds",
281                                /*[NSHomeDirectory() stringByAppendingPathComponent: @"Library/Sounds"],*/ nil];
282    BOOL isDirectory;
283    NSEnumerator * soundEnumerator;
284    NSString * sound;
285   
286    NSString * directory;
287    NSEnumerator * enumerator = [directories objectEnumerator];
288    while ((directory = [enumerator nextObject]))
289        if ([[NSFileManager defaultManager] fileExistsAtPath: directory isDirectory: &isDirectory] && isDirectory)
290        {
291                soundEnumerator = [[[NSFileManager defaultManager] directoryContentsAtPath: directory] objectEnumerator];
292                while ((sound = [soundEnumerator nextObject]))
293                {
294                    sound = [sound stringByDeletingPathExtension];
295                    if ([NSSound soundNamed: sound])
296                        [sounds addObject: sound];
297                }
298        }
299   
300    return sounds;
301}
302
303- (void) setSound: (id) sender
304{
305    //play sound when selecting
306    NSSound * sound;
307    if ((sound = [NSSound soundNamed: [sender titleOfSelectedItem]]))
308        [sound play];
309}
310
311- (void) setEncryptionMode: (id) sender
312{
313    tr_setEncryptionMode(fHandle, [fDefaults boolForKey: @"EncryptionPrefer"] ?
314        ([fDefaults boolForKey: @"EncryptionRequire"] ? TR_ENCRYPTION_REQUIRED : TR_ENCRYPTION_PREFERRED) : TR_PLAINTEXT_PREFERRED);
315}
316
317- (void) applySpeedSettings: (id) sender
318{
319    if ([fDefaults boolForKey: @"SpeedLimit"])
320    {
321        tr_setUseGlobalSpeedLimit(fHandle, TR_UP, 1);
322        tr_setGlobalSpeedLimit(fHandle, TR_UP, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]);
323       
324        tr_setUseGlobalSpeedLimit(fHandle, TR_DOWN, 1);
325        tr_setGlobalSpeedLimit(fHandle, TR_DOWN, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]);
326    }
327    else
328    {
329        tr_setUseGlobalSpeedLimit(fHandle, TR_UP, [fDefaults boolForKey: @"CheckUpload"]);
330        tr_setGlobalSpeedLimit(fHandle, TR_UP, [fDefaults integerForKey: @"UploadLimit"]);
331       
332        tr_setUseGlobalSpeedLimit(fHandle, TR_DOWN, [fDefaults boolForKey: @"CheckDownload"]);
333        tr_setGlobalSpeedLimit(fHandle, TR_DOWN, [fDefaults integerForKey: @"DownloadLimit"]);
334    }
335}
336
337- (void) applyRatioSetting: (id) sender
338{
339    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
340}
341
342- (void) updateRatioStopField
343{
344    if (!fHasLoaded)
345        return;
346   
347    [fRatioStopField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
348   
349    [self applyRatioSetting: nil];
350}
351
352- (void) setRatioStop: (id) sender
353{
354    [fDefaults setFloat: [sender floatValue] forKey: @"RatioLimit"];
355    [self applyRatioSetting: nil];
356}
357
358- (void) updateLimitFields
359{
360    if (!fHasLoaded)
361        return;
362   
363    [fUploadField setIntValue: [fDefaults integerForKey: @"UploadLimit"]];
364    [fDownloadField setIntValue: [fDefaults integerForKey: @"DownloadLimit"]];
365}
366
367- (void) setGlobalLimit: (id) sender
368{
369    [fDefaults setInteger: [sender intValue] forKey: sender == fUploadField ? @"UploadLimit" : @"DownloadLimit"];
370    [self applySpeedSettings: self];
371}
372
373- (void) setSpeedLimit: (id) sender
374{
375    [fDefaults setInteger: [sender intValue] forKey: sender == fSpeedLimitUploadField
376                                                        ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit"];
377    [self applySpeedSettings: self];
378}
379
380- (void) setAutoSpeedLimit: (id) sender
381{
382    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSpeedLimitChange" object: self];
383}
384
385- (BOOL) control: (NSControl *) control textShouldBeginEditing: (NSText *) fieldEditor
386{
387    [fInitialString release];
388    fInitialString = [[control stringValue] retain];
389   
390    return YES;
391}
392
393- (BOOL) control: (NSControl *) control didFailToFormatString: (NSString *) string errorDescription: (NSString *) error
394{
395    NSBeep();
396    if (fInitialString)
397    {
398        [control setStringValue: fInitialString];
399        [fInitialString release];
400        fInitialString = nil;
401    }
402    return NO;
403}
404
405- (void) setBadge: (id) sender
406{   
407    [[NSNotificationCenter defaultCenter] postNotificationName: @"DockBadgeChange" object: self];
408}
409
410- (void) resetWarnings: (id) sender
411{
412    [fDefaults setBool: YES forKey: @"WarningDuplicate"];
413    [fDefaults setBool: YES forKey: @"WarningRemainingSpace"];
414}
415
416- (void) setCheckForUpdate: (id) sender
417{
418    NSTimeInterval seconds = [fDefaults boolForKey: @"CheckForUpdates"] ? UPDATE_SECONDS : 0;
419    [fDefaults setInteger: seconds forKey: @"SUScheduledCheckInterval"];
420    if (fUpdater)
421        [fUpdater scheduleCheckWithInterval: seconds];
422}
423
424- (void) setQueue: (id) sender
425{
426    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
427}
428
429- (void) setQueueNumber: (id) sender
430{
431    [fDefaults setInteger: [sender intValue] forKey: sender == fQueueDownloadField ? @"QueueDownloadNumber" : @"QueueSeedNumber"];
432    [self setQueue: nil];
433}
434
435- (void) setStalled: (id) sender
436{
437    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: self];
438}
439
440- (void) setStalledMinutes: (id) sender
441{
442    [fDefaults setInteger: [sender intValue] forKey: @"StalledMinutes"];
443    [self setStalled: nil];
444}
445
446- (void) setDownloadLocation: (id) sender
447{
448    switch ([fFolderPopUp indexOfSelectedItem])
449    {
450        case DOWNLOAD_FOLDER:
451            [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
452            break;
453        case DOWNLOAD_TORRENT:
454            [fDefaults setObject: @"Torrent" forKey: @"DownloadChoice"];
455            break;
456        case DOWNLOAD_ASK:
457            [fDefaults setObject: @"Ask" forKey: @"DownloadChoice"];
458            break;
459    }
460}
461
462- (void) folderSheetShow: (id) sender
463{
464    NSOpenPanel * panel = [NSOpenPanel openPanel];
465
466    [panel setPrompt: @"Select"];
467    [panel setAllowsMultipleSelection: NO];
468    [panel setCanChooseFiles: NO];
469    [panel setCanChooseDirectories: YES];
470    [panel setCanCreateDirectories: YES];
471
472    [panel beginSheetForDirectory: nil file: nil types: nil
473        modalForWindow: [self window] modalDelegate: self didEndSelector:
474        @selector(folderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
475}
476
477- (void) incompleteFolderSheetShow: (id) sender
478{
479    NSOpenPanel * panel = [NSOpenPanel openPanel];
480
481    [panel setPrompt: @"Select"];
482    [panel setAllowsMultipleSelection: NO];
483    [panel setCanChooseFiles: NO];
484    [panel setCanChooseDirectories: YES];
485    [panel setCanCreateDirectories: YES];
486
487    [panel beginSheetForDirectory: nil file: nil types: nil
488        modalForWindow: [self window] modalDelegate: self didEndSelector:
489        @selector(incompleteFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
490}
491
492- (void) setAutoImport: (id) sender
493{
494    NSString * path;
495    if ((path = [fDefaults stringForKey: @"AutoImportDirectory"]))
496    {
497        path = [path stringByExpandingTildeInPath];
498        if ([fDefaults boolForKey: @"AutoImport"])
499            [[UKKQueue sharedFileWatcher] addPath: path];
500        else
501            [[UKKQueue sharedFileWatcher] removePathFromQueue: path];
502       
503        [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
504    }
505    else
506        [self importFolderSheetShow: nil];
507}
508
509- (void) importFolderSheetShow: (id) sender
510{
511    NSOpenPanel * panel = [NSOpenPanel openPanel];
512
513    [panel setPrompt: @"Select"];
514    [panel setAllowsMultipleSelection: NO];
515    [panel setCanChooseFiles: NO];
516    [panel setCanChooseDirectories: YES];
517    [panel setCanCreateDirectories: YES];
518
519    [panel beginSheetForDirectory: nil file: nil types: nil
520        modalForWindow: [self window] modalDelegate: self didEndSelector:
521        @selector(importFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
522}
523
524- (void) setAutoSize: (id) sender
525{
526    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSizeSettingChange" object: self];
527}
528
529- (void) helpForNetwork: (id) sender
530{
531    [[NSHelpManager sharedHelpManager] openHelpAnchor: @"PortForwarding"
532        inBook: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"]];
533}
534
535@end
536
537@implementation PrefsController (Private)
538
539- (void) setPrefView: (id) sender
540{
541    NSView * view = fGeneralView;
542    if (sender)
543    {
544        NSString * identifier = [sender itemIdentifier];
545        if ([identifier isEqualToString: TOOLBAR_TRANSFERS])
546            view = fTransfersView;
547        else if ([identifier isEqualToString: TOOLBAR_BANDWIDTH])
548            view = fBandwidthView;
549        else if ([identifier isEqualToString: TOOLBAR_ADVANCED])
550            view = fAdvancedView;
551        else;
552    }
553   
554    NSWindow * window = [self window];
555    if ([window contentView] == view)
556        return;
557   
558    NSRect windowRect = [window frame];
559    float difference = ([view frame].size.height - [[window contentView] frame].size.height) * [window userSpaceScaleFactor];
560    windowRect.origin.y -= difference;
561    windowRect.size.height += difference;
562   
563    [view setHidden: YES];
564    [window setContentView: view];
565    [window setFrame: windowRect display: YES animate: YES];
566    [view setHidden: NO];
567   
568    //set title label
569    if (sender)
570        [window setTitle: [sender label]];
571    else
572    {
573        NSToolbar * toolbar = [window toolbar];
574        NSString * itemIdentifier = [toolbar selectedItemIdentifier];
575        NSEnumerator * enumerator = [[toolbar items] objectEnumerator];
576        NSToolbarItem * item;
577        while ((item = [enumerator nextObject]))
578            if ([[item itemIdentifier] isEqualToString: itemIdentifier])
579            {
580                [window setTitle: [item label]];
581                break;
582            }
583    }
584   
585    //for advanced view make sure progress indicator hides itself
586    if (view == fAdvancedView && [fPortStatusImage image])
587        [fPortStatusProgress setDisplayedWhenStopped: NO];
588}
589
590- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
591{
592    if (code == NSOKButton)
593    {
594        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
595        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"DownloadFolder"];
596        [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
597    }
598    else
599    {
600        //reset if cancelled
601        NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
602        if ([downloadChoice isEqualToString: @"Constant"])
603            [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
604        else if ([downloadChoice isEqualToString: @"Torrent"])
605            [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
606        else
607            [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
608    }
609}
610
611- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
612{
613    if (code == NSOKButton)
614        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"IncompleteDownloadFolder"];
615    [fIncompleteFolderPopUp selectItemAtIndex: 0];
616}
617
618- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
619{
620    NSString * path = [fDefaults stringForKey: @"AutoImportDirectory"];
621    if (code == NSOKButton)
622    {
623        UKKQueue * sharedQueue = [UKKQueue sharedFileWatcher];
624        if (path)
625            [sharedQueue removePathFromQueue: [path stringByExpandingTildeInPath]];
626       
627        path = [[openPanel filenames] objectAtIndex: 0];
628        [fDefaults setObject: path forKey: @"AutoImportDirectory"];
629        [sharedQueue addPath: [path stringByExpandingTildeInPath]];
630       
631        [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
632    }
633    else if (!path)
634        [fDefaults setBool: NO forKey: @"AutoImport"];
635   
636    [fImportFolderPopUp selectItemAtIndex: 0];
637}
638
639@end
Note: See TracBrowser for help on using the repository browser.