source: trunk/macosx/PrefsController.m @ 1777

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

get error messages working again

  • Property svn:keywords set to Date Rev Author Id
File size: 22.2 KB
Line 
1/******************************************************************************
2 * $Id: PrefsController.m 1777 2007-04-23 18:49:28Z 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    fNatStatus = -1;
149   
150    [self updatePortStatus];
151    fNatStatusTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0 target: self
152                        selector: @selector(updatePortStatus) userInfo: nil repeats: YES];
153   
154    //set queue values
155    [fQueueDownloadField setIntValue: [fDefaults integerForKey: @"QueueDownloadNumber"]];
156    [fQueueSeedField setIntValue: [fDefaults integerForKey: @"QueueSeedNumber"]];
157   
158    //set update check
159    NSString * updateCheck = [fDefaults stringForKey: @"UpdateCheck"];
160    if ([updateCheck isEqualToString: @"Weekly"])
161        [fUpdatePopUp selectItemAtIndex: UPDATE_WEEKLY];
162    else if ([updateCheck isEqualToString: @"Never"])
163        [fUpdatePopUp selectItemAtIndex: UPDATE_NEVER];
164    else
165        [fUpdatePopUp selectItemAtIndex: UPDATE_DAILY];
166}
167
168- (void) setUpdater: (SUUpdater *) updater
169{
170    fUpdater = updater;
171}
172
173- (NSToolbarItem *) toolbar: (NSToolbar *) toolbar itemForItemIdentifier: (NSString *) ident
174                    willBeInsertedIntoToolbar: (BOOL) flag
175{
176    NSToolbarItem * item;
177    item = [[NSToolbarItem alloc] initWithItemIdentifier: ident];
178
179    if ([ident isEqualToString: TOOLBAR_GENERAL])
180    {
181        [item setLabel: NSLocalizedString(@"General", "Preferences -> General toolbar item title")];
182        [item setImage: [NSImage imageNamed: @"Preferences.png"]];
183        [item setTarget: self];
184        [item setAction: @selector(setPrefView:)];
185        [item setAutovalidates: NO];
186    }
187    else if ([ident isEqualToString: TOOLBAR_TRANSFERS])
188    {
189        [item setLabel: NSLocalizedString(@"Transfers", "Preferences -> Transfers toolbar item title")];
190        [item setImage: [NSImage imageNamed: @"Transfers.png"]];
191        [item setTarget: self];
192        [item setAction: @selector(setPrefView:)];
193        [item setAutovalidates: NO];
194    }
195    else if ([ident isEqualToString: TOOLBAR_BANDWIDTH])
196    {
197        [item setLabel: NSLocalizedString(@"Bandwidth", "Preferences -> Bandwidth toolbar item title")];
198        [item setImage: [NSImage imageNamed: @"Bandwidth.png"]];
199        [item setTarget: self];
200        [item setAction: @selector(setPrefView:)];
201        [item setAutovalidates: NO];
202    }
203    else if ([ident isEqualToString: TOOLBAR_NETWORK])
204    {
205        [item setLabel: NSLocalizedString(@"Network", "Preferences -> Network toolbar item title")];
206        [item setImage: [NSImage imageNamed: @"Network.png"]];
207        [item setTarget: self];
208        [item setAction: @selector(setPrefView:)];
209        [item setAutovalidates: NO];
210    }
211    else
212    {
213        [item release];
214        return nil;
215    }
216
217    return item;
218}
219
220- (NSArray *) toolbarSelectableItemIdentifiers: (NSToolbar *) toolbar
221{
222    return [self toolbarDefaultItemIdentifiers: toolbar];
223}
224
225- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
226{
227    return [self toolbarAllowedItemIdentifiers: toolbar];
228}
229
230- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
231{
232    return [NSArray arrayWithObjects: TOOLBAR_GENERAL, TOOLBAR_TRANSFERS,
233                                        TOOLBAR_BANDWIDTH, TOOLBAR_NETWORK, nil];
234}
235
236- (void) setPort: (id) sender
237{
238    int port = [sender intValue];
239    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", port]])
240    {
241        NSBeep();
242        [sender setIntValue: [fDefaults integerForKey: @"BindPort"]];
243        return;
244    }
245   
246    [fDefaults setInteger: fPublicPort forKey: @"BindPort"];
247   
248    tr_setBindPort(fHandle, port);
249   
250    fPublicPort = -1;
251    [self updatePortStatus];
252}
253
254- (void) setNat: (id) sender
255{
256    tr_natTraversalEnable(fHandle, [fDefaults boolForKey: @"NatTraversal"]);
257    [self updatePortStatus];
258}
259
260- (void) updatePortStatus
261{
262    tr_handle_status_t * stat = tr_handleStatus(fHandle);
263   
264    BOOL change;
265    if (change = (fNatStatus != stat->natTraversalStatus))
266    {
267        fNatStatus = stat->natTraversalStatus;
268       
269        if (fNatStatus == TR_NAT_TRAVERSAL_MAPPED)
270        {
271            [fNatStatusField setStringValue: NSLocalizedString(@"Port successfully mapped",
272                                                "Preferences -> Network -> port map status")];
273            [fNatStatusImage setImage: [NSImage imageNamed: @"GreenDot.tiff"]];
274        }
275        else if (fNatStatus == TR_NAT_TRAVERSAL_NOTFOUND || fNatStatus == TR_NAT_TRAVERSAL_ERROR)
276        {
277            [fNatStatusField setStringValue: NSLocalizedString(@"Error mapping port",
278                                                "Preferences -> Network -> port map status")];
279            [fNatStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]];
280        }
281        else
282        {
283            [fNatStatusField setStringValue: @""];
284            [fNatStatusImage setImage: nil];
285        }
286    }
287   
288    if (change || fPublicPort != stat->publicPort)
289    {
290        fPublicPort = stat->publicPort;
291       
292        [fPortStatusField setStringValue: [NSLocalizedString(@"Checking port status",
293                                            "Preferences -> Network -> port status") stringByAppendingEllipsis]];
294        [fPortStatusImage setImage: nil];
295        [fPortStatusProgress startAnimation: self];
296       
297        PortChecker * portChecker = [[PortChecker alloc] initWithDelegate: self];
298        [portChecker probePort: fPublicPort];
299    }
300}
301
302- (void) portCheckerDidFinishProbing: (PortChecker *) portChecker
303{
304    [fPortStatusProgress stopAnimation: self];
305    switch ([portChecker status])
306    {
307        case PORT_STATUS_OPEN:
308            [fPortStatusField setStringValue: NSLocalizedString(@"Port is open", "Preferences -> Network -> port status")];
309            [fPortStatusImage setImage: [NSImage imageNamed: @"GreenDot.tiff"]];
310            break;
311        case PORT_STATUS_STEALTH:
312            [fPortStatusField setStringValue: NSLocalizedString(@"Port is stealth", "Preferences -> Network -> port status")];
313            [fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]];
314            break;
315        case PORT_STATUS_CLOSED:
316            [fPortStatusField setStringValue: NSLocalizedString(@"Port is closed", "Preferences -> Network -> port status")];
317            [fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]];
318            break;
319        case PORT_STATUS_ERROR:
320            [fPortStatusField setStringValue: NSLocalizedString(@"Unable to check port status",
321                                                "Preferences -> Network -> port status")];
322            [fPortStatusImage setImage: [NSImage imageNamed: @"YellowDot.tiff"]];
323            break;
324    }
325    [portChecker release];
326}
327
328- (void) applySpeedSettings: (id) sender
329{
330    if ([fDefaults boolForKey: @"SpeedLimit"])
331    {
332        tr_setGlobalUploadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]);
333        tr_setGlobalDownloadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]);
334    }
335    else
336    {
337        tr_setGlobalUploadLimit(fHandle, [fDefaults boolForKey: @"CheckUpload"]
338                                        ? [fDefaults integerForKey: @"UploadLimit"] : -1);
339        tr_setGlobalDownloadLimit(fHandle, [fDefaults boolForKey: @"CheckDownload"]
340                                        ? [fDefaults integerForKey: @"DownloadLimit"] : -1);
341    }
342}
343
344- (void) applyRatioSetting: (id) sender
345{
346    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
347}
348
349- (void) updateRatioStopField
350{
351    if (!fHasLoaded)
352        return;
353   
354    [fRatioStopField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
355   
356    [self applyRatioSetting: nil];
357}
358
359- (void) setRatioStop: (id) sender
360{
361    float ratio = [sender floatValue];
362    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%.2f", ratio]] || ratio < 0)
363    {
364        NSBeep();
365        [sender setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
366        return;
367    }
368   
369    [fDefaults setFloat: ratio forKey: @"RatioLimit"];
370   
371    [self applyRatioSetting: nil];
372}
373
374- (void) updateLimitFields
375{
376    if (!fHasLoaded)
377        return;
378   
379    [fUploadField setIntValue: [fDefaults integerForKey: @"UploadLimit"]];
380    [fDownloadField setIntValue: [fDefaults integerForKey: @"DownloadLimit"]];
381}
382
383- (void) setGlobalLimit: (id) sender
384{
385    BOOL upload = sender == fUploadField;
386   
387    int limit = [sender intValue];
388    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0)
389    {
390        NSBeep();
391        [sender setIntValue: [fDefaults integerForKey: upload ? @"UploadLimit" : @"DownloadLimit"]];
392        return;
393    }
394   
395    [fDefaults setInteger: limit forKey: upload ? @"UploadLimit" : @"DownloadLimit"];
396   
397    [self applySpeedSettings: self];
398}
399
400- (void) setSpeedLimit: (id) sender
401{
402    BOOL upload = sender == fSpeedLimitUploadField;
403   
404    int limit = [sender intValue];
405    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]])
406    {
407        NSBeep();
408        [sender setIntValue: [fDefaults integerForKey: upload ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit"]];
409        return;
410    }
411   
412    [fDefaults setInteger: limit forKey: upload ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit"];
413   
414    [self applySpeedSettings: self];
415}
416
417- (void) setAutoSpeedLimit: (id) sender
418{
419    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSpeedLimitChange" object: self];
420}
421
422- (void) setBadge: (id) sender
423{   
424    [[NSNotificationCenter defaultCenter] postNotificationName: @"DockBadgeChange" object: self];
425}
426
427- (void) setSound: (id) sender
428{
429    //play sound when selecting
430    NSSound * sound;
431    if ((sound = [NSSound soundNamed: [sender titleOfSelectedItem]]))
432        [sound play];
433}
434
435- (void) setUpdate: (id) sender
436{
437    int index = [fUpdatePopUp indexOfSelectedItem];
438    NSString * update;
439    NSTimeInterval seconds;
440    if (index == UPDATE_DAILY)
441    {
442        update = @"Daily";
443        seconds = 86400;
444    }
445    else if (index == UPDATE_WEEKLY)
446    {
447        update = @"Weekly";
448        seconds = 604800;
449    }
450    else
451    {
452        update = @"Never";
453        seconds = 0;
454    }
455   
456    [fDefaults setObject: update forKey: @"UpdateCheck"];
457    [fDefaults setInteger: seconds forKey: @"SUScheduledCheckInterval"];
458   
459    if (fUpdater)
460        [fUpdater scheduleCheckWithInterval: seconds];
461}
462
463- (void) setQueue: (id) sender
464{
465    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
466}
467
468- (void) setQueueNumber: (id) sender
469{
470    BOOL download = sender == fQueueDownloadField;
471   
472    int limit = [sender intValue];
473    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0)
474    {
475        NSBeep();
476        [sender setIntValue: [fDefaults integerForKey: download ? @"QueueDownloadNumber" : @"QueueSeedNumber"]];
477        return;
478    }
479   
480    [fDefaults setInteger: limit forKey: download ? @"QueueDownloadNumber" : @"QueueSeedNumber"];
481   
482    [self setQueue: nil];
483}
484
485- (void) setDownloadLocation: (id) sender
486{
487    switch ([fFolderPopUp indexOfSelectedItem])
488    {
489        case DOWNLOAD_FOLDER:
490            [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
491            break;
492        case DOWNLOAD_TORRENT:
493            [fDefaults setObject: @"Torrent" forKey: @"DownloadChoice"];
494            break;
495        case DOWNLOAD_ASK:
496            [fDefaults setObject: @"Ask" forKey: @"DownloadChoice"];
497            break;
498    }
499}
500
501- (void) folderSheetShow: (id) sender
502{
503    NSOpenPanel * panel = [NSOpenPanel openPanel];
504
505    [panel setPrompt: @"Select"];
506    [panel setAllowsMultipleSelection: NO];
507    [panel setCanChooseFiles: NO];
508    [panel setCanChooseDirectories: YES];
509    [panel setCanCreateDirectories: YES];
510
511    [panel beginSheetForDirectory: nil file: nil types: nil
512        modalForWindow: [self window] modalDelegate: self didEndSelector:
513        @selector(folderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
514}
515
516- (void) incompleteFolderSheetShow: (id) sender
517{
518    NSOpenPanel * panel = [NSOpenPanel openPanel];
519
520    [panel setPrompt: @"Select"];
521    [panel setAllowsMultipleSelection: NO];
522    [panel setCanChooseFiles: NO];
523    [panel setCanChooseDirectories: YES];
524    [panel setCanCreateDirectories: YES];
525
526    [panel beginSheetForDirectory: nil file: nil types: nil
527        modalForWindow: [self window] modalDelegate: self didEndSelector:
528        @selector(incompleteFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
529}
530
531- (void) setAutoImport: (id) sender
532{
533    NSString * path = [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath];
534    if ([fDefaults boolForKey: @"AutoImport"])
535        [[UKKQueue sharedFileWatcher] addPath: path];
536    else
537        [[UKKQueue sharedFileWatcher] removePathFromQueue: path];
538   
539    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
540}
541
542- (void) importFolderSheetShow: (id) sender
543{
544    NSOpenPanel * panel = [NSOpenPanel openPanel];
545
546    [panel setPrompt: @"Select"];
547    [panel setAllowsMultipleSelection: NO];
548    [panel setCanChooseFiles: NO];
549    [panel setCanChooseDirectories: YES];
550    [panel setCanCreateDirectories: YES];
551
552    [panel beginSheetForDirectory: nil file: nil types: nil
553        modalForWindow: [self window] modalDelegate: self didEndSelector:
554        @selector(importFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
555}
556
557- (void) setAutoSize: (id) sender
558{
559    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSizeSettingChange" object: self];
560}
561
562- (void) helpForNetwork: (id) sender
563{
564    [[NSHelpManager sharedHelpManager] openHelpAnchor: @"PortForwarding"
565        inBook: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"]];
566}
567
568@end
569
570@implementation PrefsController (Private)
571
572- (void) setPrefView: (id) sender
573{
574    NSView * view = fGeneralView;
575    if (sender)
576    {
577        NSString * identifier = [sender itemIdentifier];
578        if ([identifier isEqualToString: TOOLBAR_TRANSFERS])
579            view = fTransfersView;
580        else if ([identifier isEqualToString: TOOLBAR_BANDWIDTH])
581            view = fBandwidthView;
582        else if ([identifier isEqualToString: TOOLBAR_NETWORK])
583            view = fNetworkView;
584        else;
585    }
586   
587    NSWindow * window = [self window];
588    if ([window contentView] == view)
589        return;
590   
591    NSRect windowRect = [window frame];
592    float difference = [view frame].size.height - [[window contentView] frame].size.height;
593    windowRect.origin.y -= difference;
594    windowRect.size.height += difference;
595   
596    [view setHidden: YES];
597    [window setContentView: view];
598    [window setFrame: windowRect display: YES animate: YES];
599    [view setHidden: NO];
600   
601    //set title label
602    if (sender)
603        [window setTitle: [sender label]];
604    else
605    {
606        NSToolbarItem * item;
607        NSEnumerator * enumerator = [[fToolbar items] objectEnumerator];
608        while ((item = [enumerator nextObject]))
609            if ([[item itemIdentifier] isEqualToString: [fToolbar selectedItemIdentifier]])
610            {
611                [window setTitle: [item label]];
612                break;
613            }
614    }
615   
616    //for network view make sure progress indicator hides itself
617    if (view == fNetworkView && [fPortStatusImage image])
618        [fPortStatusProgress setDisplayedWhenStopped: NO];
619}
620
621- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
622{
623    if (code == NSOKButton)
624    {
625        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
626        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"DownloadFolder"];
627        [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
628    }
629    else
630    {
631        //reset if cancelled
632        NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
633        if ([downloadChoice isEqualToString: @"Constant"])
634            [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
635        else if ([downloadChoice isEqualToString: @"Torrent"])
636            [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
637        else
638            [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
639    }
640}
641
642- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
643{
644    if (code == NSOKButton)
645        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"IncompleteDownloadFolder"];
646    [fIncompleteFolderPopUp selectItemAtIndex: 0];
647}
648
649- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
650{
651    if (code == NSOKButton)
652    {
653        UKKQueue * sharedQueue = [UKKQueue sharedFileWatcher];
654        [sharedQueue removePathFromQueue: [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
655       
656        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"AutoImportDirectory"];
657       
658        [sharedQueue addPath: [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
659       
660        [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
661    }
662    [fImportFolderPopUp selectItemAtIndex: 0];
663}
664
665@end
Note: See TracBrowser for help on using the repository browser.