source: trunk/macosx/PrefsController.m @ 493

Last change on this file since 493 was 493, checked in by livings124, 16 years ago

Opening multiple torrents will once again respect the auto-start setting.

  • Property svn:keywords set to Date Rev Author Id
File size: 20.9 KB
Line 
1/******************************************************************************
2 * $Id: PrefsController.m 493 2006-07-01 00:55:41Z 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
28#define MIN_PORT    1
29#define MAX_PORT    65535
30
31#define DOWNLOAD_FOLDER     0
32#define DOWNLOAD_TORRENT    2
33#define DOWNLOAD_ASK    3
34
35#define START_YES_CHECK_TAG     0
36#define START_WAIT_CHECK_TAG    1
37#define START_NO_CHECK_TAG      2
38
39#define UPDATE_DAILY    0
40#define UPDATE_WEEKLY   1
41#define UPDATE_NEVER    2
42
43#define TOOLBAR_GENERAL     @"General"
44#define TOOLBAR_TRANSFERS   @"Transfers"
45#define TOOLBAR_BANDWIDTH   @"Bandwidth"
46#define TOOLBAR_NETWORK     @"Network"
47
48@interface PrefsController (Private)
49
50- (void) showGeneralPref: (id) sender;
51- (void) showTransfersPref: (id) sender;
52- (void) showBandwidthPref: (id) sender;
53- (void) showNetworkPref: (id) sender;
54
55- (void) setPrefView: (NSView *) view;
56
57- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
58- (void) updatePopUp;
59
60@end
61
62@implementation PrefsController
63
64+ (void) initialize
65{
66    [[NSUserDefaults standardUserDefaults] registerDefaults:
67        [NSDictionary dictionaryWithContentsOfFile:
68        [[NSBundle mainBundle] pathForResource: @"Defaults" ofType: @"plist"]]];
69}
70
71- (void) dealloc
72{
73    [fDownloadFolder release];
74    [super dealloc];
75}
76
77- (void) setPrefs: (tr_handle_t *) handle
78{
79    fToolbar = [[NSToolbar alloc] initWithIdentifier: @"Preferences Toolbar"];
80    [fToolbar setDelegate: self];
81    [fToolbar setAllowsUserCustomization: NO];
82    [[self window] setToolbar: fToolbar];
83    [fToolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
84    [fToolbar setSizeMode: NSToolbarSizeModeRegular];
85
86    [fToolbar setSelectedItemIdentifier: TOOLBAR_GENERAL];
87    [self showGeneralPref: nil];
88
89    fDefaults = [NSUserDefaults standardUserDefaults];
90    fHandle = handle;
91   
92    //set download folder
93    NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
94    fDownloadFolder = [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath];
95    [fDownloadFolder retain];
96
97    if ([downloadChoice isEqualToString: @"Constant"])
98        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
99    else if ([downloadChoice isEqualToString: @"Torrent"])
100        [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
101    else
102        [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
103    [self updatePopUp];
104
105    //set bind port
106    int bindPort = [fDefaults integerForKey: @"BindPort"];
107    [fPortField setIntValue: bindPort];
108    tr_setBindPort(fHandle, bindPort);
109   
110    //checks for old version upload speed of -1
111    if ([fDefaults integerForKey: @"UploadLimit"] < 0)
112    {
113        [fDefaults setInteger: 20 forKey: @"UploadLimit"];
114        [fDefaults setBool: NO forKey: @"CheckUpload"];
115    }
116   
117    //set upload limit
118    BOOL checkUpload = [fDefaults boolForKey: @"CheckUpload"];
119    int uploadLimit = [fDefaults integerForKey: @"UploadLimit"];
120   
121    [fUploadCheck setState: checkUpload];
122    [fUploadField setIntValue: uploadLimit];
123    [fUploadField setEnabled: checkUpload];
124
125        //set download limit
126    BOOL checkDownload = [fDefaults boolForKey: @"CheckDownload"];
127    int downloadLimit = [fDefaults integerForKey: @"DownloadLimit"];
128   
129    [fDownloadCheck setState: checkDownload];
130    [fDownloadField setIntValue: downloadLimit];
131    [fDownloadField setEnabled: checkDownload];
132   
133    //set speed limit
134    int speedLimitUploadLimit = [fDefaults integerForKey: @"SpeedLimitUploadLimit"];
135    [fSpeedLimitUploadField setIntValue: speedLimitUploadLimit];
136   
137    int speedLimitDownloadLimit = [fDefaults integerForKey: @"SpeedLimitDownloadLimit"];
138    [fSpeedLimitDownloadField setIntValue: speedLimitDownloadLimit];
139   
140    //actually set bandwidth limits
141    if ([fDefaults boolForKey: @"SpeedLimit"])
142    {
143        tr_setUploadLimit(fHandle, speedLimitUploadLimit);
144        tr_setDownloadLimit(fHandle, speedLimitDownloadLimit);
145    }
146    else
147    {
148        tr_setUploadLimit(fHandle, checkUpload ? uploadLimit : -1);
149        tr_setDownloadLimit(fHandle, checkDownload ? downloadLimit : -1);
150    }
151   
152    //set ratio limit
153    BOOL ratioCheck = [fDefaults boolForKey: @"RatioCheck"];
154    [fRatioCheck setState: ratioCheck];
155    [fRatioField setEnabled: ratioCheck];
156    [fRatioField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
157   
158    //set remove and quit prompts
159    BOOL isQuitCheck = [fDefaults boolForKey: @"CheckQuit"],
160        isRemoveCheck = [fDefaults boolForKey: @"CheckRemove"];
161   
162    [fQuitCheck setState: isQuitCheck];
163    [fRemoveCheck setState: isRemoveCheck];
164   
165    [fQuitDownloadingCheck setState: [fDefaults boolForKey: @"CheckQuitDownloading"]];
166    [fQuitDownloadingCheck setEnabled: isQuitCheck];
167    [fRemoveDownloadingCheck setState: [fDefaults boolForKey: @"CheckRemoveDownloading"]];
168    [fRemoveDownloadingCheck setEnabled: isRemoveCheck];
169
170    //set dock badging
171    [fBadgeDownloadRateCheck setState: [fDefaults boolForKey: @"BadgeDownloadRate"]];
172    [fBadgeUploadRateCheck setState: [fDefaults boolForKey: @"BadgeUploadRate"]];
173   
174    //set start setting
175    NSString * startSetting = [fDefaults stringForKey: @"StartSetting"];
176    int tag;
177    if ([startSetting isEqualToString: @"Start"])
178        tag = START_YES_CHECK_TAG;
179    else if ([startSetting isEqualToString: @"Wait"])
180        tag = START_WAIT_CHECK_TAG;
181    else
182        tag = START_NO_CHECK_TAG;
183   
184    [fStartMatrix selectCellWithTag: tag];
185    [fWaitToStartField setEnabled: tag == START_WAIT_CHECK_TAG];
186    [fWaitToStartField setIntValue: [fDefaults integerForKey: @"WaitToStartNumber"]];
187   
188    //set private torrents
189    BOOL copyTorrents = [fDefaults boolForKey: @"SavePrivateTorrent"];
190    [fCopyTorrentCheck setState: copyTorrents];
191   
192    [fDeleteOriginalTorrentCheck setEnabled: copyTorrents];
193    [fDeleteOriginalTorrentCheck setState: [fDefaults boolForKey: @"DeleteOriginalTorrent"]];
194
195    //set update check
196    NSString * updateCheck = [fDefaults stringForKey: @"UpdateCheck"];
197    if ([updateCheck isEqualToString: @"Weekly"])
198        [fUpdatePopUp selectItemAtIndex: UPDATE_WEEKLY];
199    else if ([updateCheck isEqualToString: @"Never"])
200        [fUpdatePopUp selectItemAtIndex: UPDATE_NEVER];
201    else
202        [fUpdatePopUp selectItemAtIndex: UPDATE_DAILY];
203}
204
205- (NSToolbarItem *) toolbar: (NSToolbar *) t itemForItemIdentifier:
206    (NSString *) ident willBeInsertedIntoToolbar: (BOOL) flag
207{
208    NSToolbarItem * item;
209    item = [[NSToolbarItem alloc] initWithItemIdentifier: ident];
210
211    if ([ident isEqualToString: TOOLBAR_GENERAL])
212    {
213        [item setLabel: TOOLBAR_GENERAL];
214        [item setImage: [NSImage imageNamed: @"Preferences.png"]];
215        [item setTarget: self];
216        [item setAction: @selector( showGeneralPref: )];
217    }
218    else if ([ident isEqualToString: TOOLBAR_TRANSFERS])
219    {
220        [item setLabel: TOOLBAR_TRANSFERS];
221        [item setImage: [NSImage imageNamed: @"Transfers.png"]];
222        [item setTarget: self];
223        [item setAction: @selector( showTransfersPref: )];
224    }
225    else if ([ident isEqualToString: TOOLBAR_BANDWIDTH])
226    {
227        [item setLabel: TOOLBAR_BANDWIDTH];
228        [item setImage: [NSImage imageNamed: @"Bandwidth.png"]];
229        [item setTarget: self];
230        [item setAction: @selector( showBandwidthPref: )];
231    }
232    else if ([ident isEqualToString: TOOLBAR_NETWORK])
233    {
234        [item setLabel: TOOLBAR_NETWORK];
235        [item setImage: [NSImage imageNamed: @"Network.png"]];
236        [item setTarget: self];
237        [item setAction: @selector( showNetworkPref: )];
238    }
239    else
240    {
241        [item release];
242        return nil;
243    }
244
245    return item;
246}
247
248- (NSArray *) toolbarSelectableItemIdentifiers: (NSToolbar *) toolbar
249{
250    return [self toolbarDefaultItemIdentifiers: toolbar];
251}
252
253- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
254{
255    return [self toolbarAllowedItemIdentifiers: toolbar];
256}
257
258- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
259{
260    return [NSArray arrayWithObjects:
261            TOOLBAR_GENERAL, TOOLBAR_TRANSFERS,
262            TOOLBAR_BANDWIDTH, TOOLBAR_NETWORK, nil];
263}
264
265- (void) setPort: (id) sender
266{
267    int bindPort = [sender intValue];
268    if (![[NSString stringWithInt: bindPort] isEqualToString: [sender stringValue]]
269            || bindPort < MIN_PORT || bindPort > MAX_PORT)
270    {
271        NSBeep();
272        bindPort = [fDefaults integerForKey: @"BindPort"];
273        [sender setIntValue: bindPort];
274    }
275    else
276    {
277        tr_setBindPort( fHandle, bindPort );
278        [fDefaults setInteger: bindPort forKey: @"BindPort"];
279    }
280}
281
282- (void) setLimit: (id) sender
283{
284    NSString * key;
285    NSButton * check;
286    NSString * type;
287    if (sender == fUploadField)
288    {
289        key = @"UploadLimit";
290        check = fUploadCheck;
291        type = @"Upload";
292    }
293    else
294    {
295        key = @"DownloadLimit";
296        check = fDownloadCheck;
297        type = @"Download";
298    }
299
300    int limit = [sender intValue];
301    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0)
302    {
303        NSBeep();
304        limit = [fDefaults integerForKey: key];
305        [sender setIntValue: limit];
306    }
307    else
308    {
309        if (![fDefaults boolForKey: @"SpeedLimit"])
310        {
311            if (sender == fUploadField)
312                tr_setUploadLimit(fHandle, [fUploadCheck state] ? limit : -1);
313            else
314                tr_setDownloadLimit(fHandle, [fDownloadCheck state] ? limit : -1);
315        }
316       
317        [fDefaults setInteger: limit forKey: key];
318    }
319   
320    NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys:
321                                    [NSNumber numberWithBool: [check state]], @"Enable",
322                                    [NSNumber numberWithInt: limit], @"Limit",
323                                    type, @"Type", nil];
324    [[NSNotificationCenter defaultCenter] postNotificationName: @"LimitGlobalChange" object: dict];
325}
326
327- (void) setLimitCheck: (id) sender
328{
329    NSString * key;
330    NSTextField * field;
331    if (sender == fUploadCheck)
332    {
333        key = @"CheckUpload";
334        field = fUploadField;
335    }
336    else
337    {
338        key = @"CheckDownload";
339        field = fDownloadField;
340    }
341   
342    BOOL check = [sender state] == NSOnState;
343    [self setLimit: field];
344    [field setEnabled: check];
345   
346    [fDefaults setBool: check forKey: key];
347}
348
349- (void) setLimitEnabled: (BOOL) enable type: (NSString *) type
350{
351    NSButton * check = [type isEqualToString: @"Upload"] ? fUploadCheck : fDownloadCheck;
352    [check setState: enable ? NSOnState : NSOffState];
353    [self setLimitCheck: check];
354}
355
356- (void) setQuickLimit: (int) limit type: (NSString *) type
357{
358    NSButton * check;
359    if ([type isEqualToString: @"Upload"])
360    {
361        [fUploadField setIntValue: limit];
362        check = fUploadCheck;
363    }
364    else
365    {
366        [fDownloadField setIntValue: limit];
367        check = fDownloadCheck;
368    }
369    [check setState: NSOnState];
370    [self setLimitCheck: check];
371}
372
373- (void) enableSpeedLimit: (BOOL) enable
374{
375    if ([fDefaults boolForKey: @"SpeedLimit"] != enable)
376    {
377        [fDefaults setBool: enable forKey: @"SpeedLimit"];
378       
379        if (enable)
380        {
381            tr_setUploadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]);
382            tr_setDownloadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]);
383        }
384        else
385        {
386            tr_setUploadLimit(fHandle, [fUploadCheck state] ? [fDefaults integerForKey: @"UploadLimit"] : -1);
387            tr_setDownloadLimit(fHandle, [fDownloadCheck state] ? [fDefaults integerForKey: @"DownloadLimit"] : -1);
388        }
389    }
390}
391
392- (void) setSpeedLimit: (id) sender
393{
394    NSString * key = sender == fSpeedLimitUploadField ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit";
395
396    int limit = [sender intValue];
397    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0)
398    {
399        NSBeep();
400        limit = [fDefaults integerForKey: key];
401        [sender setIntValue: limit];
402    }
403    else
404    {
405        if ([fDefaults boolForKey: @"SpeedLimit"])
406        {
407            if (sender == fSpeedLimitUploadField)
408                tr_setUploadLimit(fHandle, limit);
409            else
410                tr_setDownloadLimit(fHandle, limit);
411        }
412       
413        [fDefaults setInteger: limit forKey: key];
414    }
415}
416
417- (void) setRatio: (id) sender
418{
419    float ratioLimit = [sender floatValue];
420    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%.2f", ratioLimit]]
421            || ratioLimit < 0)
422    {
423        NSBeep();
424        ratioLimit = [fDefaults floatForKey: @"RatioLimit"];
425        [sender setFloatValue: ratioLimit];
426    }
427    else
428        [fDefaults setFloat: ratioLimit forKey: @"RatioLimit"];
429   
430    NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys:
431                                [NSNumber numberWithBool: [fRatioCheck state]], @"Enable",
432                                [NSNumber numberWithFloat: ratioLimit], @"Ratio", nil];
433    [[NSNotificationCenter defaultCenter] postNotificationName: @"RatioGlobalChange" object: dict];
434}
435
436- (void) setRatioCheck: (id) sender
437{
438    BOOL check = [sender state] == NSOnState;
439    [self setRatio: fRatioField];
440    [fRatioField setEnabled: check];
441   
442    [fDefaults setBool: check forKey: @"RatioCheck"];
443}
444
445- (void) setRatioEnabled: (BOOL) enable
446{
447    int state = enable ? NSOnState : NSOffState;
448   
449    [fRatioCheck setState: state];
450    [self setRatioCheck: fRatioCheck];
451}
452
453- (void) setQuickRatio: (float) ratioLimit
454{
455    [fRatioField setFloatValue: ratioLimit];
456   
457    [fRatioCheck setState: NSOnState];
458    [self setRatioCheck: fRatioCheck];
459}
460
461- (void) setShowMessage: (id) sender
462{
463    BOOL state = [sender state];
464
465    if (sender == fQuitCheck)
466    {
467        [fDefaults setBool: state forKey: @"CheckQuit"];
468        [fQuitDownloadingCheck setEnabled: state];
469    }
470    else if (sender == fRemoveCheck)
471    {
472        [fDefaults setBool: state forKey: @"CheckRemove"];
473        [fRemoveDownloadingCheck setEnabled: state];
474    }
475    if (sender == fQuitDownloadingCheck)
476        [fDefaults setBool: state forKey: @"CheckQuitDownloading"];
477    else if (sender == fRemoveDownloadingCheck)
478        [fDefaults setBool: state forKey: @"CheckRemoveDownloading"];
479    else;
480}
481
482- (void) setBadge: (id) sender
483{   
484    if (sender == fBadgeDownloadRateCheck)
485        [fDefaults setBool: [sender state] forKey: @"BadgeDownloadRate"];
486    else if (sender == fBadgeUploadRateCheck)
487        [fDefaults setBool: [sender state] forKey: @"BadgeUploadRate"];
488    else;
489}
490
491- (void) setUpdate: (id) sender
492{
493    int index = [fUpdatePopUp indexOfSelectedItem];
494    NSTimeInterval seconds;
495    if (index == UPDATE_DAILY)
496    {
497        [fDefaults setObject: @"Daily" forKey: @"UpdateCheck"];
498        seconds = 86400;
499    }
500    else if (index == UPDATE_WEEKLY)
501    {
502        [fDefaults setObject: @"Weekly" forKey: @"UpdateCheck"];
503        seconds = 604800;
504    }
505    else
506    {
507        [fDefaults setObject: @"Never" forKey: @"UpdateCheck"];
508        seconds = 0;
509    }
510
511    [fDefaults setInteger: seconds forKey: @"SUScheduledCheckInterval"];
512    [fUpdater scheduleCheckWithInterval: seconds];
513}
514
515- (void) setStartSetting: (id) sender
516{
517    NSString * startSetting;
518
519    int tag = [[fStartMatrix selectedCell] tag];
520    if (tag == START_YES_CHECK_TAG)
521        startSetting = @"Start";
522    else if (tag == START_WAIT_CHECK_TAG)
523        startSetting = @"Wait";
524    else
525        startSetting = @"Manual";
526   
527    [fDefaults setObject: startSetting forKey: @"StartSetting"];
528   
529    [self setWaitToStart: fWaitToStartField];
530    [fWaitToStartField setEnabled: tag == START_WAIT_CHECK_TAG];
531}
532
533- (void) setWaitToStart: (id) sender
534{
535    int waitNumber = [sender intValue];
536    if (![[sender stringValue] isEqualToString: [NSString stringWithInt: waitNumber]] || waitNumber < 1)
537    {
538        NSBeep();
539        waitNumber = [fDefaults floatForKey: @"WaitToStartNumber"];
540        [sender setIntValue: waitNumber];
541    }
542    else
543        [fDefaults setInteger: waitNumber forKey: @"WaitToStartNumber"];
544   
545    [[NSNotificationCenter defaultCenter] postNotificationName: @"GlobalStartSettingChange" object: self];
546}
547
548- (void) setMoveTorrent: (id) sender
549{
550    int state = [sender state];
551    if (sender == fCopyTorrentCheck)
552    {
553        [fDefaults setBool: state forKey: @"SavePrivateTorrent"];
554       
555        [fDeleteOriginalTorrentCheck setEnabled: state];
556        if (state == NSOffState)
557        {
558            [fDeleteOriginalTorrentCheck setState: NSOffState];
559            [fDefaults setBool: NO forKey: @"DeleteOriginalTorrent"];
560        }
561    }
562    else
563        [fDefaults setBool: state forKey: @"DeleteOriginalTorrent"];
564}
565
566- (void) setDownloadLocation: (id) sender
567{
568    //Download folder
569    switch ([fFolderPopUp indexOfSelectedItem])
570    {
571        case DOWNLOAD_FOLDER:
572            [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
573            break;
574        case DOWNLOAD_TORRENT:
575            [fDefaults setObject: @"Torrent" forKey: @"DownloadChoice"];
576            break;
577        case DOWNLOAD_ASK:
578            [fDefaults setObject: @"Ask" forKey: @"DownloadChoice"];
579            break;
580    }
581}
582
583- (void) checkUpdate
584{
585    [fUpdater checkForUpdates: nil];
586}
587
588- (void) folderSheetShow: (id) sender
589{
590    NSOpenPanel * panel = [NSOpenPanel openPanel];
591
592    [panel setPrompt: @"Select"];
593    [panel setAllowsMultipleSelection: NO];
594    [panel setCanChooseFiles: NO];
595    [panel setCanChooseDirectories: YES];
596    [panel setCanCreateDirectories: YES];
597
598    [panel beginSheetForDirectory: nil file: nil types: nil
599        modalForWindow: [self window] modalDelegate: self didEndSelector:
600        @selector( folderSheetClosed:returnCode:contextInfo: )
601        contextInfo: nil];
602}
603
604@end
605
606@implementation PrefsController (Private)
607
608- (void) showGeneralPref: (id) sender
609{
610    [self setPrefView: fGeneralView];
611}
612
613- (void) showTransfersPref: (id) sender
614{
615    [self setPrefView: fTransfersView];
616}
617
618- (void) showBandwidthPref: (id) sender
619{
620    [self setPrefView: fBandwidthView];
621}
622
623- (void) showNetworkPref: (id) sender
624{
625    [self setPrefView: fNetworkView];
626}
627
628- (void) setPrefView: (NSView *) view
629{
630    NSWindow * window = [self window];
631   
632    NSRect windowRect = [window frame];
633    int difference = [view frame].size.height - [[window contentView] frame].size.height;
634    windowRect.origin.y -= difference;
635    windowRect.size.height += difference;
636
637    [window setTitle: [fToolbar selectedItemIdentifier]];
638   
639    [window setContentView: view];
640    [view setHidden: YES];
641    [window setFrame: windowRect display: YES animate: YES];
642    [view setHidden: NO];
643}
644
645- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
646{
647   if (code == NSOKButton)
648   {
649       [fDownloadFolder release];
650       fDownloadFolder = [[openPanel filenames] objectAtIndex: 0];
651       [fDownloadFolder retain];
652
653       [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
654       [fDefaults setObject: fDownloadFolder forKey: @"DownloadFolder"];
655       [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
656
657       [self updatePopUp];
658   }
659   else
660   {
661       //reset if cancelled
662       NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
663       if ([downloadChoice isEqualToString: @"Constant"])
664           [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
665       else if ([downloadChoice isEqualToString: @"Torrent"])
666           [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
667       else
668           [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
669   }
670}
671
672- (void) updatePopUp
673{
674    //get and resize the icon
675    NSImage * icon = [[NSWorkspace sharedWorkspace] iconForFile: fDownloadFolder];
676    [icon setScalesWhenResized: YES];
677    [icon setSize: NSMakeSize(16.0, 16.0)];
678
679    //update menu item
680    NSMenuItem * menuItem = (NSMenuItem *) [fFolderPopUp itemAtIndex: 0];
681    [menuItem setTitle: [fDownloadFolder lastPathComponent]];
682    [menuItem setImage: icon];
683}
684
685@end
Note: See TracBrowser for help on using the repository browser.