source: trunk/macosx/PrefsController.m @ 1480

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

Sounds pulldowns only get sounds from the built-in system sound folder. This should avoid an Apple error (and resulting crash) with some wav files on Intel macs.

  • Property svn:keywords set to Date Rev Author Id
File size: 22.0 KB
Line 
1/******************************************************************************
2 * $Id: PrefsController.m 1480 2007-02-09 15:02:25Z 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 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    hasLoaded = 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) updateRatioStopField
344{
345    if (!hasLoaded)
346        return;
347   
348    [fRatioStopField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
349}
350
351- (void) setRatioStop: (id) sender
352{
353    float ratio = [sender floatValue];
354    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%.2f", ratio]] || ratio < 0)
355    {
356        NSBeep();
357        [sender setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
358        return;
359    }
360   
361    [fDefaults setFloat: ratio forKey: @"RatioLimit"];
362}
363
364- (void) updateLimitFields
365{
366    if (!hasLoaded)
367        return;
368   
369    [fUploadField setIntValue: [fDefaults integerForKey: @"UploadLimit"]];
370    [fDownloadField setIntValue: [fDefaults integerForKey: @"DownloadLimit"]];
371}
372
373- (void) setGlobalLimit: (id) sender
374{
375    BOOL upload = sender == fUploadField;
376   
377    int limit = [sender intValue];
378    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0)
379    {
380        NSBeep();
381        [sender setIntValue: [fDefaults integerForKey: upload ? @"UploadLimit" : @"DownloadLimit"]];
382        return;
383    }
384   
385    [fDefaults setInteger: limit forKey: upload ? @"UploadLimit" : @"DownloadLimit"];
386   
387    [self applySpeedSettings: self];
388}
389
390- (void) setSpeedLimit: (id) sender
391{
392    BOOL upload = sender == fSpeedLimitUploadField;
393   
394    int limit = [sender intValue];
395    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]])
396    {
397        NSBeep();
398        [sender setIntValue: [fDefaults integerForKey: upload ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit"]];
399        return;
400    }
401   
402    [fDefaults setInteger: limit forKey: upload ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit"];
403   
404    [self applySpeedSettings: self];
405}
406
407- (void) setAutoSpeedLimit: (id) sender
408{
409    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSpeedLimitChange" object: self];
410}
411
412- (void) setBadge: (id) sender
413{   
414    [[NSNotificationCenter defaultCenter] postNotificationName: @"DockBadgeChange" object: self];
415}
416
417- (void) setSound: (id) sender
418{
419    //play sound when selecting
420    NSSound * sound;
421    if ((sound = [NSSound soundNamed: [sender titleOfSelectedItem]]))
422        [sound play];
423}
424
425- (void) setUpdate: (id) sender
426{
427    int index = [fUpdatePopUp indexOfSelectedItem];
428    NSString * update;
429    NSTimeInterval seconds;
430    if (index == UPDATE_DAILY)
431    {
432        update = @"Daily";
433        seconds = 86400;
434    }
435    else if (index == UPDATE_WEEKLY)
436    {
437        update = @"Weekly";
438        seconds = 604800;
439    }
440    else
441    {
442        update = @"Never";
443        seconds = 0;
444    }
445   
446    [fDefaults setObject: update forKey: @"UpdateCheck"];
447    [fDefaults setInteger: seconds forKey: @"SUScheduledCheckInterval"];
448   
449    if (fUpdater)
450        [fUpdater scheduleCheckWithInterval: seconds];
451}
452
453- (void) setQueue: (id) sender
454{
455    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
456}
457
458- (void) setQueueNumber: (id) sender
459{
460    BOOL download = sender == fQueueDownloadField;
461   
462    int limit = [sender intValue];
463    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0)
464    {
465        NSBeep();
466        [sender setIntValue: [fDefaults integerForKey: download ? @"QueueDownloadNumber" : @"QueueSeedNumber"]];
467        return;
468    }
469   
470    [fDefaults setInteger: limit forKey: download ? @"QueueDownloadNumber" : @"QueueSeedNumber"];
471   
472    [self setQueue: nil];
473}
474
475- (void) setDownloadLocation: (id) sender
476{
477    switch ([fFolderPopUp indexOfSelectedItem])
478    {
479        case DOWNLOAD_FOLDER:
480            [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
481            break;
482        case DOWNLOAD_TORRENT:
483            [fDefaults setObject: @"Torrent" forKey: @"DownloadChoice"];
484            break;
485        case DOWNLOAD_ASK:
486            [fDefaults setObject: @"Ask" forKey: @"DownloadChoice"];
487            break;
488    }
489}
490
491- (void) folderSheetShow: (id) sender
492{
493    NSOpenPanel * panel = [NSOpenPanel openPanel];
494
495    [panel setPrompt: @"Select"];
496    [panel setAllowsMultipleSelection: NO];
497    [panel setCanChooseFiles: NO];
498    [panel setCanChooseDirectories: YES];
499    [panel setCanCreateDirectories: YES];
500
501    [panel beginSheetForDirectory: nil file: nil types: nil
502        modalForWindow: [self window] modalDelegate: self didEndSelector:
503        @selector(folderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
504}
505
506- (void) incompleteFolderSheetShow: (id) sender
507{
508    NSOpenPanel * panel = [NSOpenPanel openPanel];
509
510    [panel setPrompt: @"Select"];
511    [panel setAllowsMultipleSelection: NO];
512    [panel setCanChooseFiles: NO];
513    [panel setCanChooseDirectories: YES];
514    [panel setCanCreateDirectories: YES];
515
516    [panel beginSheetForDirectory: nil file: nil types: nil
517        modalForWindow: [self window] modalDelegate: self didEndSelector:
518        @selector(incompleteFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
519}
520
521- (void) setAutoImport: (id) sender
522{
523    NSString * path = [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath];
524    if ([fDefaults boolForKey: @"AutoImport"])
525        [[UKKQueue sharedFileWatcher] addPath: path];
526    else
527        [[UKKQueue sharedFileWatcher] removePathFromQueue: path];
528   
529    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
530}
531
532- (void) importFolderSheetShow: (id) sender
533{
534    NSOpenPanel * panel = [NSOpenPanel openPanel];
535
536    [panel setPrompt: @"Select"];
537    [panel setAllowsMultipleSelection: NO];
538    [panel setCanChooseFiles: NO];
539    [panel setCanChooseDirectories: YES];
540    [panel setCanCreateDirectories: YES];
541
542    [panel beginSheetForDirectory: nil file: nil types: nil
543        modalForWindow: [self window] modalDelegate: self didEndSelector:
544        @selector(importFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
545}
546
547- (void) setAutoSize: (id) sender
548{
549    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSizeSettingChange" object: self];
550}
551
552- (void) helpForNetwork: (id) sender
553{
554    [[NSHelpManager sharedHelpManager] openHelpAnchor: @"PortForwarding"
555        inBook: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"]];
556}
557
558@end
559
560@implementation PrefsController (Private)
561
562- (void) setPrefView: (id) sender
563{
564    NSView * view = fGeneralView;
565    if (sender)
566    {
567        NSString * identifier = [sender itemIdentifier];
568        if ([identifier isEqualToString: TOOLBAR_TRANSFERS])
569            view = fTransfersView;
570        else if ([identifier isEqualToString: TOOLBAR_BANDWIDTH])
571            view = fBandwidthView;
572        else if ([identifier isEqualToString: TOOLBAR_NETWORK])
573            view = fNetworkView;
574        else;
575    }
576   
577    NSWindow * window = [self window];
578    if ([window contentView] == view)
579        return;
580   
581    NSRect windowRect = [window frame];
582    int difference = [view frame].size.height - [[window contentView] frame].size.height;
583    windowRect.origin.y -= difference;
584    windowRect.size.height += difference;
585   
586    [view setHidden: YES];
587    [window setContentView: view];
588    [window setFrame: windowRect display: YES animate: YES];
589    [view setHidden: NO];
590   
591    //set title label
592    if (sender)
593        [window setTitle: [sender label]];
594    else
595    {
596        NSToolbarItem * item;
597        NSEnumerator * enumerator = [[fToolbar items] objectEnumerator];
598        while ((item = [enumerator nextObject]))
599            if ([[item itemIdentifier] isEqualToString: [fToolbar selectedItemIdentifier]])
600            {
601                [window setTitle: [item label]];
602                break;
603            }
604    }
605   
606    //for network view make sure progress indicator hides itself
607    if (view == fNetworkView && [fPortStatusImage image])
608        [fPortStatusProgress setDisplayedWhenStopped: NO];
609}
610
611- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
612{
613    if (code == NSOKButton)
614    {
615        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
616        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"DownloadFolder"];
617        [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
618    }
619    else
620    {
621        //reset if cancelled
622        NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
623        if ([downloadChoice isEqualToString: @"Constant"])
624            [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
625        else if ([downloadChoice isEqualToString: @"Torrent"])
626            [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
627        else
628            [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
629    }
630}
631
632- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
633{
634    if (code == NSOKButton)
635        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"IncompleteDownloadFolder"];
636    [fIncompleteFolderPopUp selectItemAtIndex: 0];
637}
638
639- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
640{
641    if (code == NSOKButton)
642    {
643        UKKQueue * sharedQueue = [UKKQueue sharedFileWatcher];
644        [sharedQueue removePathFromQueue: [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
645       
646        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"AutoImportDirectory"];
647       
648        [sharedQueue addPath: [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
649       
650        [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
651    }
652    [fImportFolderPopUp selectItemAtIndex: 0];
653}
654
655@end
Note: See TracBrowser for help on using the repository browser.