source: trunk/macosx/PrefsController.m @ 1801

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

new option in general prefs to reset all warnings (replaces option for enabling file size check)

  • Property svn:keywords set to Date Rev Author Id
File size: 22.4 KB
Line 
1/******************************************************************************
2 * $Id: PrefsController.m 1801 2007-04-25 03:16:25Z livings124 $
3 *
4 * Copyright (c) 2005-2007 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#import "PrefsController.h"
26#import "StringAdditions.h"
27#import "UKKQueue.h"
28
29#define DOWNLOAD_FOLDER     0
30#define DOWNLOAD_TORRENT    2
31#define DOWNLOAD_ASK        3
32
33#define UPDATE_DAILY    0
34#define UPDATE_WEEKLY   1
35#define UPDATE_NEVER    2
36
37#define TOOLBAR_GENERAL     @"TOOLBAR_GENERAL"
38#define TOOLBAR_TRANSFERS   @"TOOLBAR_TRANSFERS"
39#define TOOLBAR_BANDWIDTH   @"TOOLBAR_BANDWIDTH"
40#define TOOLBAR_NETWORK     @"TOOLBAR_NETWORK"
41
42@interface PrefsController (Private)
43
44- (void) setPrefView: (id) sender;
45
46- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
47- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
48- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
49
50@end
51
52@implementation PrefsController
53
54- (id) initWithWindowNibName: (NSString *) name handle: (tr_handle_t *) handle
55{
56    if ((self = [self initWithWindowNibName: name]))
57    {
58        fDefaults = [NSUserDefaults standardUserDefaults];
59        fHandle = handle;
60       
61        //checks for old version upload speed of -1
62        if ([fDefaults integerForKey: @"UploadLimit"] < 0)
63        {
64            [fDefaults setInteger: 20 forKey: @"UploadLimit"];
65            [fDefaults setBool: NO forKey: @"CheckUpload"];
66        }
67       
68        //set auto import
69        if ([fDefaults boolForKey: @"AutoImport"])
70            [[UKKQueue sharedFileWatcher] addPath:
71                [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
72       
73        //set bind port
74        int bindPort = [fDefaults integerForKey: @"BindPort"];
75        tr_setBindPort(fHandle, bindPort);
76       
77        //set NAT
78        tr_natTraversalEnable(fHandle, [fDefaults boolForKey: @"NatTraversal"]);
79       
80        //actually set bandwidth limits
81        [self applySpeedSettings: nil];
82       
83        //set play sound
84        NSMutableArray * sounds = [NSMutableArray array];
85        NSEnumerator * soundEnumerator;
86       
87        //get list of all sounds and sort alphabetically
88        if (soundEnumerator = [[NSFileManager defaultManager] enumeratorAtPath: @"System/Library/Sounds"])
89        {
90            NSString * sound;
91            while ((sound = [soundEnumerator nextObject]))
92            {
93                sound = [sound stringByDeletingPathExtension];
94                if ([NSSound soundNamed: sound])
95                    [sounds addObject: sound];
96            }
97        }
98       
99        fSounds = [[sounds sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)] retain];
100    }
101    return self;
102}
103
104- (void) dealloc
105{
106    if (fNatStatusTimer)
107        [fNatStatusTimer invalidate];
108    [fSounds release];
109   
110    [super dealloc];
111}
112
113- (void) awakeFromNib
114{
115    fHasLoaded = YES;
116   
117    fToolbar = [[NSToolbar alloc] initWithIdentifier: @"Preferences Toolbar"];
118    [fToolbar setDelegate: self];
119    [fToolbar setAllowsUserCustomization: NO];
120    [[self window] setToolbar: fToolbar];
121    [fToolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
122    [fToolbar setSizeMode: NSToolbarSizeModeRegular];
123
124    [fToolbar setSelectedItemIdentifier: TOOLBAR_GENERAL];
125    [self setPrefView: nil];
126   
127    //set download folder
128    NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
129    if ([downloadChoice isEqualToString: @"Constant"])
130        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
131    else if ([downloadChoice isEqualToString: @"Torrent"])
132        [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
133    else
134        [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
135   
136    //set stop ratio
137    [self updateRatioStopField];
138   
139    //set limits
140    [self updateLimitFields];
141   
142    //set speed limit
143    [fSpeedLimitUploadField setIntValue: [fDefaults integerForKey: @"SpeedLimitUploadLimit"]];
144    [fSpeedLimitDownloadField setIntValue: [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]];
145   
146    //set port
147    [fPortField setIntValue: [fDefaults integerForKey: @"BindPort"]];
148    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) resetWarnings: (id) sender
436{
437    [fDefaults setBool: YES forKey: @"WarningDebug"];
438    [fDefaults setBool: YES forKey: @"WarningRemainingSpace"];
439}
440
441- (void) setUpdate: (id) sender
442{
443    int index = [fUpdatePopUp indexOfSelectedItem];
444    NSString * update;
445    NSTimeInterval seconds;
446    if (index == UPDATE_DAILY)
447    {
448        update = @"Daily";
449        seconds = 86400;
450    }
451    else if (index == UPDATE_WEEKLY)
452    {
453        update = @"Weekly";
454        seconds = 604800;
455    }
456    else
457    {
458        update = @"Never";
459        seconds = 0;
460    }
461   
462    [fDefaults setObject: update forKey: @"UpdateCheck"];
463    [fDefaults setInteger: seconds forKey: @"SUScheduledCheckInterval"];
464   
465    if (fUpdater)
466        [fUpdater scheduleCheckWithInterval: seconds];
467}
468
469- (void) setQueue: (id) sender
470{
471    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
472}
473
474- (void) setQueueNumber: (id) sender
475{
476    BOOL download = sender == fQueueDownloadField;
477   
478    int limit = [sender intValue];
479    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0)
480    {
481        NSBeep();
482        [sender setIntValue: [fDefaults integerForKey: download ? @"QueueDownloadNumber" : @"QueueSeedNumber"]];
483        return;
484    }
485   
486    [fDefaults setInteger: limit forKey: download ? @"QueueDownloadNumber" : @"QueueSeedNumber"];
487   
488    [self setQueue: nil];
489}
490
491- (void) setDownloadLocation: (id) sender
492{
493    switch ([fFolderPopUp indexOfSelectedItem])
494    {
495        case DOWNLOAD_FOLDER:
496            [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
497            break;
498        case DOWNLOAD_TORRENT:
499            [fDefaults setObject: @"Torrent" forKey: @"DownloadChoice"];
500            break;
501        case DOWNLOAD_ASK:
502            [fDefaults setObject: @"Ask" forKey: @"DownloadChoice"];
503            break;
504    }
505}
506
507- (void) folderSheetShow: (id) sender
508{
509    NSOpenPanel * panel = [NSOpenPanel openPanel];
510
511    [panel setPrompt: @"Select"];
512    [panel setAllowsMultipleSelection: NO];
513    [panel setCanChooseFiles: NO];
514    [panel setCanChooseDirectories: YES];
515    [panel setCanCreateDirectories: YES];
516
517    [panel beginSheetForDirectory: nil file: nil types: nil
518        modalForWindow: [self window] modalDelegate: self didEndSelector:
519        @selector(folderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
520}
521
522- (void) incompleteFolderSheetShow: (id) sender
523{
524    NSOpenPanel * panel = [NSOpenPanel openPanel];
525
526    [panel setPrompt: @"Select"];
527    [panel setAllowsMultipleSelection: NO];
528    [panel setCanChooseFiles: NO];
529    [panel setCanChooseDirectories: YES];
530    [panel setCanCreateDirectories: YES];
531
532    [panel beginSheetForDirectory: nil file: nil types: nil
533        modalForWindow: [self window] modalDelegate: self didEndSelector:
534        @selector(incompleteFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
535}
536
537- (void) setAutoImport: (id) sender
538{
539    NSString * path = [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath];
540    if ([fDefaults boolForKey: @"AutoImport"])
541        [[UKKQueue sharedFileWatcher] addPath: path];
542    else
543        [[UKKQueue sharedFileWatcher] removePathFromQueue: path];
544   
545    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
546}
547
548- (void) importFolderSheetShow: (id) sender
549{
550    NSOpenPanel * panel = [NSOpenPanel openPanel];
551
552    [panel setPrompt: @"Select"];
553    [panel setAllowsMultipleSelection: NO];
554    [panel setCanChooseFiles: NO];
555    [panel setCanChooseDirectories: YES];
556    [panel setCanCreateDirectories: YES];
557
558    [panel beginSheetForDirectory: nil file: nil types: nil
559        modalForWindow: [self window] modalDelegate: self didEndSelector:
560        @selector(importFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
561}
562
563- (void) setAutoSize: (id) sender
564{
565    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSizeSettingChange" object: self];
566}
567
568- (void) helpForNetwork: (id) sender
569{
570    [[NSHelpManager sharedHelpManager] openHelpAnchor: @"PortForwarding"
571        inBook: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"]];
572}
573
574@end
575
576@implementation PrefsController (Private)
577
578- (void) setPrefView: (id) sender
579{
580    NSView * view = fGeneralView;
581    if (sender)
582    {
583        NSString * identifier = [sender itemIdentifier];
584        if ([identifier isEqualToString: TOOLBAR_TRANSFERS])
585            view = fTransfersView;
586        else if ([identifier isEqualToString: TOOLBAR_BANDWIDTH])
587            view = fBandwidthView;
588        else if ([identifier isEqualToString: TOOLBAR_NETWORK])
589            view = fNetworkView;
590        else;
591    }
592   
593    NSWindow * window = [self window];
594    if ([window contentView] == view)
595        return;
596   
597    NSRect windowRect = [window frame];
598    float difference = [view frame].size.height - [[window contentView] frame].size.height;
599    windowRect.origin.y -= difference;
600    windowRect.size.height += difference;
601   
602    [view setHidden: YES];
603    [window setContentView: view];
604    [window setFrame: windowRect display: YES animate: YES];
605    [view setHidden: NO];
606   
607    //set title label
608    if (sender)
609        [window setTitle: [sender label]];
610    else
611    {
612        NSToolbarItem * item;
613        NSEnumerator * enumerator = [[fToolbar items] objectEnumerator];
614        while ((item = [enumerator nextObject]))
615            if ([[item itemIdentifier] isEqualToString: [fToolbar selectedItemIdentifier]])
616            {
617                [window setTitle: [item label]];
618                break;
619            }
620    }
621   
622    //for network view make sure progress indicator hides itself
623    if (view == fNetworkView && [fPortStatusImage image])
624        [fPortStatusProgress setDisplayedWhenStopped: NO];
625}
626
627- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
628{
629    if (code == NSOKButton)
630    {
631        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
632        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"DownloadFolder"];
633        [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
634    }
635    else
636    {
637        //reset if cancelled
638        NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
639        if ([downloadChoice isEqualToString: @"Constant"])
640            [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
641        else if ([downloadChoice isEqualToString: @"Torrent"])
642            [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
643        else
644            [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
645    }
646}
647
648- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
649{
650    if (code == NSOKButton)
651        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"IncompleteDownloadFolder"];
652    [fIncompleteFolderPopUp selectItemAtIndex: 0];
653}
654
655- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
656{
657    if (code == NSOKButton)
658    {
659        UKKQueue * sharedQueue = [UKKQueue sharedFileWatcher];
660        [sharedQueue removePathFromQueue: [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
661       
662        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"AutoImportDirectory"];
663       
664        [sharedQueue addPath: [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
665       
666        [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
667    }
668    [fImportFolderPopUp selectItemAtIndex: 0];
669}
670
671@end
Note: See TracBrowser for help on using the repository browser.