source: trunk/macosx/PrefsController.m @ 1305

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

remove bindings from the rest of the text fields, added back glue code

  • Property svn:keywords set to Date Rev Author Id
File size: 22.9 KB
Line 
1/******************************************************************************
2 * $Id: PrefsController.m 1305 2006-12-31 23:24:23Z livings124 $
3 *
4 * Copyright (c) 2005-2006 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#import "PrefsController.h"
26#import "StringAdditions.h"
27#import "UKKQueue.h"
28
29#define DOWNLOAD_FOLDER     0
30#define DOWNLOAD_TORRENT    2
31#define DOWNLOAD_ASK        3
32
33#define UPDATE_DAILY    0
34#define UPDATE_WEEKLY   1
35#define UPDATE_NEVER    2
36
37#define TOOLBAR_GENERAL     @"TOOLBAR_GENERAL"
38#define TOOLBAR_TRANSFERS   @"TOOLBAR_TRANSFERS"
39#define TOOLBAR_BANDWIDTH   @"TOOLBAR_BANDWIDTH"
40#define TOOLBAR_NETWORK     @"TOOLBAR_NETWORK"
41
42@interface PrefsController (Private)
43
44- (void) setPrefView: (id) sender;
45
46- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
47- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
48- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
49
50@end
51
52@implementation PrefsController
53
54- (id) initWithWindowNibName: (NSString *) name handle: (tr_handle_t *) handle
55{
56    if ((self = [self initWithWindowNibName: name]))
57    {
58        fDefaults = [NSUserDefaults standardUserDefaults];
59        fHandle = handle;
60       
61        //checks for old version upload speed of -1
62        if ([fDefaults integerForKey: @"UploadLimit"] < 0)
63        {
64            [fDefaults setInteger: 20 forKey: @"UploadLimit"];
65            [fDefaults setBool: NO forKey: @"CheckUpload"];
66        }
67       
68        //set auto import
69        if ([fDefaults boolForKey: @"AutoImport"])
70            [[UKKQueue sharedFileWatcher] addPath:
71                [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
72       
73        //set bind port
74        int bindPort = [fDefaults integerForKey: @"BindPort"];
75        tr_setBindPort(fHandle, bindPort);
76       
77        //set NAT
78        if ([fDefaults boolForKey: @"NatTraversal"])
79            tr_natTraversalEnable(fHandle);
80       
81        //actually set bandwidth limits
82        [self applySpeedSettings: nil];
83       
84        //set play sound
85        NSMutableArray * sounds = [NSMutableArray array];
86        NSEnumerator * soundEnumerator,
87                    * soundDirectoriesEnumerator = [[NSArray arrayWithObjects: @"System/Library/Sounds",
88                            [NSHomeDirectory() stringByAppendingPathComponent: @"Library/Sounds"], nil] objectEnumerator];
89        NSString * soundPath, * sound;
90       
91        //get list of all sounds and sort alphabetically
92        while ((soundPath = [soundDirectoriesEnumerator nextObject]))
93            if (soundEnumerator = [[NSFileManager defaultManager] enumeratorAtPath: soundPath])
94                while ((sound = [soundEnumerator nextObject]))
95                {
96                    sound = [sound stringByDeletingPathExtension];
97                    if ([NSSound soundNamed: sound])
98                        [sounds addObject: sound];
99                }
100       
101        fSounds = [[sounds sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)] retain];
102    }
103    return self;
104}
105
106- (void) dealloc
107{
108    if (fNatStatusTimer)
109        [fNatStatusTimer invalidate];
110    [fSounds release];
111   
112    [super dealloc];
113}
114
115- (void) awakeFromNib
116{
117    hasLoaded = YES;
118   
119    fToolbar = [[NSToolbar alloc] initWithIdentifier: @"Preferences Toolbar"];
120    [fToolbar setDelegate: self];
121    [fToolbar setAllowsUserCustomization: NO];
122    [[self window] setToolbar: fToolbar];
123    [fToolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
124    [fToolbar setSizeMode: NSToolbarSizeModeRegular];
125
126    [fToolbar setSelectedItemIdentifier: TOOLBAR_GENERAL];
127    [self setPrefView: nil];
128   
129    //set download folder
130    NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
131    if ([downloadChoice isEqualToString: @"Constant"])
132        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
133    else if ([downloadChoice isEqualToString: @"Torrent"])
134        [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
135    else
136        [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
137   
138    //set stop ratio
139    [self updateRatioStopField];
140   
141    //set limits
142    [self updateLimitFields];
143   
144    //set torrent limits
145    [fUploadTorrentField setIntValue: [fDefaults integerForKey: @"UploadLimitTorrent"]];
146    [fDownloadTorrentField setIntValue: [fDefaults integerForKey: @"DownloadLimitTorrent"]];
147   
148    //set speed limit
149    [fSpeedLimitUploadField setIntValue: [fDefaults integerForKey: @"SpeedLimitUploadLimit"]];
150    [fSpeedLimitDownloadField setIntValue: [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]];
151   
152    //set port
153    [fPortField setIntValue: [fDefaults integerForKey: @"BindPort"]];
154   
155    [self updatePortStatus];
156   
157    fNatStatus = -1;
158    [self updateNatStatus];
159    fNatStatusTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0 target: self
160                        selector: @selector(updateNatStatus) userInfo: nil repeats: YES];
161   
162    //set queue values
163    [fQueueField setIntValue: [fDefaults integerForKey: @"QueueDownloadNumber"]];
164   
165    //set update check
166    NSString * updateCheck = [fDefaults stringForKey: @"UpdateCheck"];
167    if ([updateCheck isEqualToString: @"Weekly"])
168        [fUpdatePopUp selectItemAtIndex: UPDATE_WEEKLY];
169    else if ([updateCheck isEqualToString: @"Never"])
170        [fUpdatePopUp selectItemAtIndex: UPDATE_NEVER];
171    else
172        [fUpdatePopUp selectItemAtIndex: UPDATE_DAILY];
173}
174
175- (void) setUpdater: (SUUpdater *) updater
176{
177    fUpdater = updater;
178}
179
180- (NSToolbarItem *) toolbar: (NSToolbar *) toolbar itemForItemIdentifier: (NSString *) ident
181                    willBeInsertedIntoToolbar: (BOOL) flag
182{
183    NSToolbarItem * item;
184    item = [[NSToolbarItem alloc] initWithItemIdentifier: ident];
185
186    if ([ident isEqualToString: TOOLBAR_GENERAL])
187    {
188        [item setLabel: NSLocalizedString(@"General", "Preferences -> General toolbar item title")];
189        [item setImage: [NSImage imageNamed: @"Preferences.png"]];
190        [item setTarget: self];
191        [item setAction: @selector(setPrefView:)];
192        [item setAutovalidates: NO];
193    }
194    else if ([ident isEqualToString: TOOLBAR_TRANSFERS])
195    {
196        [item setLabel: NSLocalizedString(@"Transfers", "Preferences -> Transfers toolbar item title")];
197        [item setImage: [NSImage imageNamed: @"Transfers.png"]];
198        [item setTarget: self];
199        [item setAction: @selector(setPrefView:)];
200        [item setAutovalidates: NO];
201    }
202    else if ([ident isEqualToString: TOOLBAR_BANDWIDTH])
203    {
204        [item setLabel: NSLocalizedString(@"Bandwidth", "Preferences -> Bandwidth toolbar item title")];
205        [item setImage: [NSImage imageNamed: @"Bandwidth.png"]];
206        [item setTarget: self];
207        [item setAction: @selector(setPrefView:)];
208        [item setAutovalidates: NO];
209    }
210    else if ([ident isEqualToString: TOOLBAR_NETWORK])
211    {
212        [item setLabel: NSLocalizedString(@"Network", "Preferences -> Network toolbar item title")];
213        [item setImage: [NSImage imageNamed: @"Network.png"]];
214        [item setTarget: self];
215        [item setAction: @selector(setPrefView:)];
216        [item setAutovalidates: NO];
217    }
218    else
219    {
220        [item release];
221        return nil;
222    }
223
224    return item;
225}
226
227- (NSArray *) toolbarSelectableItemIdentifiers: (NSToolbar *) toolbar
228{
229    return [self toolbarDefaultItemIdentifiers: toolbar];
230}
231
232- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
233{
234    return [self toolbarAllowedItemIdentifiers: toolbar];
235}
236
237- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
238{
239    return [NSArray arrayWithObjects: TOOLBAR_GENERAL, TOOLBAR_TRANSFERS,
240                                        TOOLBAR_BANDWIDTH, TOOLBAR_NETWORK, nil];
241}
242
243- (void) setPort: (id) sender
244{
245    int port = [sender intValue];
246    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", port]])
247    {
248        NSBeep();
249        [sender setIntValue: [fDefaults integerForKey: @"BindPort"]];
250        return;
251    }
252   
253    [fDefaults setInteger: port forKey: @"BindPort"];
254   
255    tr_setBindPort(fHandle, [fDefaults integerForKey: @"BindPort"]);
256    [self updateNatStatus];
257    [self updatePortStatus];
258}
259
260- (void) updatePortStatus
261{
262    PortChecker * portChecker = [[PortChecker alloc] initWithDelegate: self];
263
264    [fPortStatusField setStringValue: [NSLocalizedString(@"Checking port status",
265                                        "Preferences -> Network -> port status") stringByAppendingEllipsis]];
266    [fPortStatusImage setImage: nil];
267    [fPortStatusProgress startAnimation: self];
268       
269    [portChecker probePort: [fDefaults integerForKey: @"BindPort"]];
270}
271
272- (void) portCheckerDidFinishProbing: (PortChecker *) portChecker
273{
274    [fPortStatusProgress stopAnimation: self];
275    switch ([portChecker status])
276    {
277        case PORT_STATUS_OPEN:
278            [fPortStatusField setStringValue: NSLocalizedString(@"Port is open", "Preferences -> Network -> port status")];
279            [fPortStatusImage setImage: [NSImage imageNamed: @"GreenDot.tiff"]];
280            break;
281        case PORT_STATUS_STEALTH:
282            [fPortStatusField setStringValue: NSLocalizedString(@"Port is stealth", "Preferences -> Network -> port status")];
283            [fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]];
284            break;
285        case PORT_STATUS_CLOSED:
286            [fPortStatusField setStringValue: NSLocalizedString(@"Port is closed", "Preferences -> Network -> port status")];
287            [fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]];
288            break;
289        case PORT_STATUS_ERROR:
290            [fPortStatusField setStringValue: NSLocalizedString(@"Unable to check port status",
291                                                "Preferences -> Network -> port status")];
292            [fPortStatusImage setImage: [NSImage imageNamed: @"YellowDot.tiff"]];
293            break;
294    }
295    [portChecker release];
296}
297
298- (void) setNat: (id) sender
299{
300    [fDefaults boolForKey: @"NatTraversal"] ? tr_natTraversalEnable(fHandle) : tr_natTraversalDisable(fHandle);
301    [self updateNatStatus];
302}
303
304- (void) updateNatStatus
305{
306    int status = tr_natTraversalStatus(fHandle);
307    if (fNatStatus == status)
308        return;
309    fNatStatus = status;
310   
311    if (status == 2)
312    {
313        [fNatStatusField setStringValue: NSLocalizedString(@"Port successfully mapped",
314                                            "Preferences -> Network -> port map status")];
315        [fNatStatusImage setImage: [NSImage imageNamed: @"GreenDot.tiff"]];
316    }
317    else if (status == 3 || status == 4)
318    {
319        [fNatStatusField setStringValue: NSLocalizedString(@"Error mapping port",
320                                            "Preferences -> Network -> port map status")];
321        [fNatStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]];
322    }
323    else
324    {
325        [fNatStatusField setStringValue: @""];
326        [fNatStatusImage setImage: nil];
327    }
328   
329    [self updatePortStatus];
330}
331
332- (void) applySpeedSettings: (id) sender
333{
334    if ([fDefaults boolForKey: @"SpeedLimit"])
335    {
336        tr_setGlobalUploadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]);
337        tr_setGlobalDownloadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]);
338    }
339    else
340    {
341        tr_setGlobalUploadLimit(fHandle, [fDefaults boolForKey: @"CheckUpload"]
342                                        ? [fDefaults integerForKey: @"UploadLimit"] : -1);
343        tr_setGlobalDownloadLimit(fHandle, [fDefaults boolForKey: @"CheckDownload"]
344                                        ? [fDefaults integerForKey: @"DownloadLimit"] : -1);
345    }
346}
347
348- (void) updateRatioStopField
349{
350    if (!hasLoaded)
351        return;
352   
353    [fRatioStopField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
354}
355
356- (void) setRatioStop: (id) sender
357{
358    float ratio = [sender floatValue];
359    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%.2f", ratio]] || ratio < 0)
360    {
361        NSBeep();
362        [sender setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
363        return;
364    }
365   
366    [fDefaults setFloat: ratio forKey: @"RatioLimit"];
367}
368
369- (void) updateLimitFields
370{
371    if (!hasLoaded)
372        return;
373   
374    [fUploadField setIntValue: [fDefaults integerForKey: @"UploadLimit"]];
375    [fDownloadField setIntValue: [fDefaults integerForKey: @"DownloadLimit"]];
376}
377
378- (void) setGlobalLimit: (id) sender
379{
380    BOOL upload = sender == fUploadField;
381   
382    int limit = [sender intValue];
383    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0)
384    {
385        NSBeep();
386        [sender setIntValue: [fDefaults integerForKey: upload ? @"UploadLimit" : @"DownloadLimit"]];
387        return;
388    }
389   
390    [fDefaults setInteger: limit forKey: upload ? @"UploadLimit" : @"DownloadLimit"];
391   
392    [self applySpeedSettings: self];
393}
394
395- (void) applyTorrentLimitSetting: (id) sender
396{
397    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateSpeedSetting" object: self];
398}
399
400- (void) setTorrentLimit: (id) sender
401{
402    BOOL upload = sender == fUploadTorrentField;
403   
404    int limit = [sender intValue];
405    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0)
406    {
407        NSBeep();
408        [sender setIntValue: [fDefaults integerForKey: upload ? @"UploadLimitTorrent" : @"DownloadLimitTorrent"]];
409        return;
410    }
411   
412    [fDefaults setInteger: limit forKey: upload ? @"UploadLimitTorrent" : @"DownloadLimitTorrent"];
413   
414    [self applyTorrentLimitSetting: self];
415}
416
417- (void) setSpeedLimit: (id) sender
418{
419    BOOL upload = sender == fSpeedLimitUploadField;
420   
421    int limit = [sender intValue];
422    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]])
423    {
424        NSBeep();
425        [sender setIntValue: [fDefaults integerForKey: upload ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit"]];
426        return;
427    }
428   
429    [fDefaults setInteger: limit forKey: upload ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit"];
430   
431    [self applySpeedSettings: self];
432}
433
434- (void) setAutoSpeedLimit: (id) sender
435{
436    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSpeedLimitChange" object: self];
437}
438
439- (void) setBadge: (id) sender
440{   
441    [[NSNotificationCenter defaultCenter] postNotificationName: @"DockBadgeChange" object: self];
442}
443
444- (void) setSound: (id) sender
445{
446    //play sound when selecting
447    NSString * soundName = [sender titleOfSelectedItem];
448    NSSound * sound;
449    if ((sound = [NSSound soundNamed: soundName]))
450        [sound play];
451}
452
453- (void) setUpdate: (id) sender
454{
455    int index = [fUpdatePopUp indexOfSelectedItem];
456    NSTimeInterval seconds;
457    if (index == UPDATE_DAILY)
458    {
459        [fDefaults setObject: @"Daily" forKey: @"UpdateCheck"];
460        seconds = 86400;
461    }
462    else if (index == UPDATE_WEEKLY)
463    {
464        [fDefaults setObject: @"Weekly" forKey: @"UpdateCheck"];
465        seconds = 604800;
466    }
467    else
468    {
469        [fDefaults setObject: @"Never" forKey: @"UpdateCheck"];
470        seconds = 0;
471    }
472
473    [fDefaults setInteger: seconds forKey: @"SUScheduledCheckInterval"];
474   
475    if (fUpdater)
476        [fUpdater scheduleCheckWithInterval: seconds];
477}
478
479- (void) setQueueNumber: (id) sender
480{
481    int limit = [sender intValue];
482    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0)
483    {
484        NSBeep();
485        [sender setIntValue: [fDefaults integerForKey: @"QueueDownloadNumber"]];
486        return;
487    }
488   
489    [fDefaults setInteger: limit forKey: @"QueueDownloadNumber"];
490   
491    [[NSNotificationCenter defaultCenter] postNotificationName: @"GlobalStartSettingChange" object: self];
492}
493
494- (void) setDownloadLocation: (id) sender
495{
496    //download folder
497    switch ([fFolderPopUp indexOfSelectedItem])
498    {
499        case DOWNLOAD_FOLDER:
500            [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
501            break;
502        case DOWNLOAD_TORRENT:
503            [fDefaults setObject: @"Torrent" forKey: @"DownloadChoice"];
504            break;
505        case DOWNLOAD_ASK:
506            [fDefaults setObject: @"Ask" forKey: @"DownloadChoice"];
507            break;
508    }
509}
510
511- (void) folderSheetShow: (id) sender
512{
513    NSOpenPanel * panel = [NSOpenPanel openPanel];
514
515    [panel setPrompt: @"Select"];
516    [panel setAllowsMultipleSelection: NO];
517    [panel setCanChooseFiles: NO];
518    [panel setCanChooseDirectories: YES];
519    [panel setCanCreateDirectories: YES];
520
521    [panel beginSheetForDirectory: nil file: nil types: nil
522        modalForWindow: [self window] modalDelegate: self didEndSelector:
523        @selector(folderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
524}
525
526- (void) incompleteFolderSheetShow: (id) sender
527{
528    NSOpenPanel * panel = [NSOpenPanel openPanel];
529
530    [panel setPrompt: @"Select"];
531    [panel setAllowsMultipleSelection: NO];
532    [panel setCanChooseFiles: NO];
533    [panel setCanChooseDirectories: YES];
534    [panel setCanCreateDirectories: YES];
535
536    [panel beginSheetForDirectory: nil file: nil types: nil
537        modalForWindow: [self window] modalDelegate: self didEndSelector:
538        @selector(incompleteFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
539}
540
541- (void) setAutoImport: (id) sender
542{
543    NSString * path = [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath];
544    if ([fDefaults boolForKey: @"AutoImport"])
545        [[UKKQueue sharedFileWatcher] addPath: path];
546    else
547        [[UKKQueue sharedFileWatcher] removePathFromQueue: path];
548   
549    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
550}
551
552- (void) importFolderSheetShow: (id) sender
553{
554    NSOpenPanel * panel = [NSOpenPanel openPanel];
555
556    [panel setPrompt: @"Select"];
557    [panel setAllowsMultipleSelection: NO];
558    [panel setCanChooseFiles: NO];
559    [panel setCanChooseDirectories: YES];
560    [panel setCanCreateDirectories: YES];
561
562    [panel beginSheetForDirectory: nil file: nil types: nil
563        modalForWindow: [self window] modalDelegate: self didEndSelector:
564        @selector(importFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
565}
566
567- (void) setAutoSize: (id) sender
568{
569    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSizeSettingChange" object: self];
570}
571
572- (void) helpForNetwork: (id) sender
573{
574    [[NSHelpManager sharedHelpManager] openHelpAnchor: @"PortForwarding"
575        inBook: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"]];
576}
577
578@end
579
580@implementation PrefsController (Private)
581
582- (void) setPrefView: (id) sender
583{
584    NSView * view = fGeneralView;
585    if (sender)
586    {
587        NSString * identifier = [sender itemIdentifier];
588        if ([identifier isEqualToString: TOOLBAR_TRANSFERS])
589            view = fTransfersView;
590        else if ([identifier isEqualToString: TOOLBAR_BANDWIDTH])
591            view = fBandwidthView;
592        else if ([identifier isEqualToString: TOOLBAR_NETWORK])
593            view = fNetworkView;
594        else;
595    }
596   
597    NSWindow * window = [self window];
598    if ([window contentView] == view)
599        return;
600   
601    NSRect windowRect = [window frame];
602    int difference = [view frame].size.height - [[window contentView] frame].size.height;
603    windowRect.origin.y -= difference;
604    windowRect.size.height += difference;
605   
606    [view setHidden: YES];
607    [window setContentView: view];
608    [window setFrame: windowRect display: YES animate: YES];
609    [view setHidden: NO];
610   
611    //set title label
612    if (sender)
613        [window setTitle: [sender label]];
614    else
615    {
616        NSToolbarItem * item;
617        NSEnumerator * enumerator = [[fToolbar items] objectEnumerator];
618        while ((item = [enumerator nextObject]))
619            if ([[item itemIdentifier] isEqualToString: [fToolbar selectedItemIdentifier]])
620            {
621                [window setTitle: [item label]];
622                break;
623            }
624    }
625   
626    //for network view make sure progress indicator hides itself
627    if (view == fNetworkView && [fPortStatusImage image])
628        [fPortStatusProgress setDisplayedWhenStopped: NO];
629}
630
631- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
632{
633    if (code == NSOKButton)
634    {
635        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
636        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"DownloadFolder"];
637        [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
638    }
639    else
640    {
641        //reset if cancelled
642        NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
643        if ([downloadChoice isEqualToString: @"Constant"])
644            [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
645        else if ([downloadChoice isEqualToString: @"Torrent"])
646            [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
647        else
648            [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
649    }
650}
651
652- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
653{
654    if (code == NSOKButton)
655        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"IncompleteDownloadFolder"];
656    [fIncompleteFolderPopUp selectItemAtIndex: 0];
657}
658
659- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
660{
661    if (code == NSOKButton)
662    {
663        UKKQueue * sharedQueue = [UKKQueue sharedFileWatcher];
664        [sharedQueue removePathFromQueue: [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
665       
666        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"AutoImportDirectory"];
667       
668        [sharedQueue addPath: [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
669       
670        [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
671    }
672    [fImportFolderPopUp selectItemAtIndex: 0];
673}
674
675@end
Note: See TracBrowser for help on using the repository browser.