source: trunk/macosx/PrefsController.m @ 1970

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

make stalled check work for minutes, not seconds

  • Property svn:keywords set to Date Rev Author Id
File size: 23.3 KB
Line 
1/******************************************************************************
2 * $Id: PrefsController.m 1970 2007-05-28 16:40:56Z 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: @"WarningRemainingSpace"];
442}
443
444- (void) setUpdate: (id) sender
445{
446    int index = [fUpdatePopUp indexOfSelectedItem];
447    NSString * update;
448    NSTimeInterval seconds;
449    if (index == UPDATE_DAILY)
450    {
451        update = @"Daily";
452        seconds = 86400;
453    }
454    else if (index == UPDATE_WEEKLY)
455    {
456        update = @"Weekly";
457        seconds = 604800;
458    }
459    else
460    {
461        update = @"Never";
462        seconds = 0;
463    }
464   
465    [fDefaults setObject: update forKey: @"UpdateCheck"];
466    [fDefaults setInteger: seconds forKey: @"SUScheduledCheckInterval"];
467   
468    if (fUpdater)
469        [fUpdater scheduleCheckWithInterval: seconds];
470}
471
472- (void) setQueue: (id) sender
473{
474    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
475}
476
477- (void) setQueueNumber: (id) sender
478{
479    BOOL download = sender == fQueueDownloadField;
480   
481    int limit = [sender intValue];
482    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 1)
483    {
484        NSBeep();
485        [sender setIntValue: [fDefaults integerForKey: download ? @"QueueDownloadNumber" : @"QueueSeedNumber"]];
486        return;
487    }
488   
489    [fDefaults setInteger: limit forKey: download ? @"QueueDownloadNumber" : @"QueueSeedNumber"];
490    [self setQueue: nil];
491}
492
493- (void) setStalled: (id) sender
494{
495    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: self];
496}
497
498- (void) setStalledMinutes: (id) sender
499{
500    int minutes = [sender intValue];
501    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", minutes]] || minutes < 1)
502    {
503        NSBeep();
504        [sender setIntValue: [fDefaults integerForKey: @"StalledMinutes"]];
505        return;
506    }
507   
508    [fDefaults setInteger: minutes forKey: @"StalledMinutes"];
509    [self setStalled: nil];
510}
511
512- (void) setDownloadLocation: (id) sender
513{
514    switch ([fFolderPopUp indexOfSelectedItem])
515    {
516        case DOWNLOAD_FOLDER:
517            [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
518            break;
519        case DOWNLOAD_TORRENT:
520            [fDefaults setObject: @"Torrent" forKey: @"DownloadChoice"];
521            break;
522        case DOWNLOAD_ASK:
523            [fDefaults setObject: @"Ask" forKey: @"DownloadChoice"];
524            break;
525    }
526}
527
528- (void) folderSheetShow: (id) sender
529{
530    NSOpenPanel * panel = [NSOpenPanel openPanel];
531
532    [panel setPrompt: @"Select"];
533    [panel setAllowsMultipleSelection: NO];
534    [panel setCanChooseFiles: NO];
535    [panel setCanChooseDirectories: YES];
536    [panel setCanCreateDirectories: YES];
537
538    [panel beginSheetForDirectory: nil file: nil types: nil
539        modalForWindow: [self window] modalDelegate: self didEndSelector:
540        @selector(folderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
541}
542
543- (void) incompleteFolderSheetShow: (id) sender
544{
545    NSOpenPanel * panel = [NSOpenPanel openPanel];
546
547    [panel setPrompt: @"Select"];
548    [panel setAllowsMultipleSelection: NO];
549    [panel setCanChooseFiles: NO];
550    [panel setCanChooseDirectories: YES];
551    [panel setCanCreateDirectories: YES];
552
553    [panel beginSheetForDirectory: nil file: nil types: nil
554        modalForWindow: [self window] modalDelegate: self didEndSelector:
555        @selector(incompleteFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
556}
557
558- (void) setAutoImport: (id) sender
559{
560    NSString * path;
561    if ((path = [fDefaults stringForKey: @"AutoImportDirectory"]))
562    {
563        path = [path stringByExpandingTildeInPath];
564        if ([fDefaults boolForKey: @"AutoImport"])
565            [[UKKQueue sharedFileWatcher] addPath: path];
566        else
567            [[UKKQueue sharedFileWatcher] removePathFromQueue: path];
568       
569        [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
570    }
571    else
572        [self importFolderSheetShow: nil];
573}
574
575- (void) importFolderSheetShow: (id) sender
576{
577    NSOpenPanel * panel = [NSOpenPanel openPanel];
578
579    [panel setPrompt: @"Select"];
580    [panel setAllowsMultipleSelection: NO];
581    [panel setCanChooseFiles: NO];
582    [panel setCanChooseDirectories: YES];
583    [panel setCanCreateDirectories: YES];
584
585    [panel beginSheetForDirectory: nil file: nil types: nil
586        modalForWindow: [self window] modalDelegate: self didEndSelector:
587        @selector(importFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
588}
589
590- (void) setAutoSize: (id) sender
591{
592    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSizeSettingChange" object: self];
593}
594
595- (void) helpForNetwork: (id) sender
596{
597    [[NSHelpManager sharedHelpManager] openHelpAnchor: @"PortForwarding"
598        inBook: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"]];
599}
600
601@end
602
603@implementation PrefsController (Private)
604
605- (void) setPrefView: (id) sender
606{
607    NSView * view = fGeneralView;
608    if (sender)
609    {
610        NSString * identifier = [sender itemIdentifier];
611        if ([identifier isEqualToString: TOOLBAR_TRANSFERS])
612            view = fTransfersView;
613        else if ([identifier isEqualToString: TOOLBAR_BANDWIDTH])
614            view = fBandwidthView;
615        else if ([identifier isEqualToString: TOOLBAR_NETWORK])
616            view = fNetworkView;
617        else;
618    }
619   
620    NSWindow * window = [self window];
621    if ([window contentView] == view)
622        return;
623   
624    NSRect windowRect = [window frame];
625    float difference = [view frame].size.height - [[window contentView] frame].size.height;
626    windowRect.origin.y -= difference;
627    windowRect.size.height += difference;
628   
629    [view setHidden: YES];
630    [window setContentView: view];
631    [window setFrame: windowRect display: YES animate: YES];
632    [view setHidden: NO];
633   
634    //set title label
635    if (sender)
636        [window setTitle: [sender label]];
637    else
638    {
639        NSToolbarItem * item;
640        NSEnumerator * enumerator = [[fToolbar items] objectEnumerator];
641        while ((item = [enumerator nextObject]))
642            if ([[item itemIdentifier] isEqualToString: [fToolbar selectedItemIdentifier]])
643            {
644                [window setTitle: [item label]];
645                break;
646            }
647    }
648   
649    //for network view make sure progress indicator hides itself
650    if (view == fNetworkView && [fPortStatusImage image])
651        [fPortStatusProgress setDisplayedWhenStopped: NO];
652}
653
654- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
655{
656    if (code == NSOKButton)
657    {
658        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
659        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"DownloadFolder"];
660        [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
661    }
662    else
663    {
664        //reset if cancelled
665        NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
666        if ([downloadChoice isEqualToString: @"Constant"])
667            [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
668        else if ([downloadChoice isEqualToString: @"Torrent"])
669            [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
670        else
671            [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
672    }
673}
674
675- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
676{
677    if (code == NSOKButton)
678        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"IncompleteDownloadFolder"];
679    [fIncompleteFolderPopUp selectItemAtIndex: 0];
680}
681
682- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
683{
684    NSString * path = [fDefaults stringForKey: @"AutoImportDirectory"];
685    if (code == NSOKButton)
686    {
687        UKKQueue * sharedQueue = [UKKQueue sharedFileWatcher];
688        if (path)
689            [sharedQueue removePathFromQueue: [path stringByExpandingTildeInPath]];
690       
691        path = [[openPanel filenames] objectAtIndex: 0];
692        [fDefaults setObject: path forKey: @"AutoImportDirectory"];
693        [sharedQueue addPath: [path stringByExpandingTildeInPath]];
694       
695        [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
696    }
697    else if (!path)
698        [fDefaults setBool: NO forKey: @"AutoImport"];
699   
700    [fImportFolderPopUp selectItemAtIndex: 0];
701}
702
703@end
Note: See TracBrowser for help on using the repository browser.