source: trunk/macosx/PrefsController.m @ 2239

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

add an option in the duplicate alert to not prompt again

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