source: trunk/macosx/PrefsController.m @ 1034

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

Partial use of bindings in prefs/action menu. This is still experimental and evolving, with the most obvious problem that entering an invalid value causes an annoying error sheet to appear.

  • Property svn:keywords set to Date Rev Author Id
File size: 20.7 KB
Line 
1/******************************************************************************
2 * $Id: PrefsController.m 1034 2006-10-27 19:14:04Z 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) updatePopUp;
48
49- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
50- (void) updateImportPopUp;
51
52@end
53
54@implementation PrefsController
55
56- (id) initWithWindowNibName: (NSString *) name handle: (tr_handle_t *) handle
57{
58    if ((self = [self initWithWindowNibName: name]))
59    {
60        fDefaults = [NSUserDefaults standardUserDefaults];
61        fHandle = handle;
62       
63        //checks for old version upload speed of -1
64        if ([fDefaults integerForKey: @"UploadLimit"] < 0)
65        {
66            [fDefaults setInteger: 20 forKey: @"UploadLimit"];
67            [fDefaults setBool: NO forKey: @"CheckUpload"];
68        }
69       
70        //set auto import
71        if ([fDefaults boolForKey: @"AutoImport"])
72            [[UKKQueue sharedFileWatcher] addPath:
73                [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
74       
75        //set bind port
76        int bindPort = [fDefaults integerForKey: @"BindPort"];
77        tr_setBindPort(fHandle, bindPort);
78       
79        //set NAT
80        if ([fDefaults boolForKey: @"NatTraversal"])
81            tr_natTraversalEnable(fHandle);
82       
83        //actually set bandwidth limits
84        [self applySpeedSettings: nil];
85    }
86    return self;
87}
88
89- (void) dealloc
90{
91    if (fNatStatusTimer)
92        [fNatStatusTimer invalidate];
93   
94    [super dealloc];
95}
96
97- (void) awakeFromNib
98{
99    fToolbar = [[NSToolbar alloc] initWithIdentifier: @"Preferences Toolbar"];
100    [fToolbar setDelegate: self];
101    [fToolbar setAllowsUserCustomization: NO];
102    [[self window] setToolbar: fToolbar];
103    [fToolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
104    [fToolbar setSizeMode: NSToolbarSizeModeRegular];
105
106    [fToolbar setSelectedItemIdentifier: TOOLBAR_GENERAL];
107    [self setPrefView: nil];
108   
109    //set download folder
110    NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
111    if ([downloadChoice isEqualToString: @"Constant"])
112        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
113    else if ([downloadChoice isEqualToString: @"Torrent"])
114        [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
115    else
116        [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
117    [self updatePopUp];
118   
119    //set auto import
120    [self updateImportPopUp];
121   
122    [self updatePortStatus];
123   
124    fNatStatus = -1;
125    [self updateNatStatus];
126    fNatStatusTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0 target: self
127                        selector: @selector(updateNatStatus) userInfo: nil repeats: YES];
128   
129    //set play sound
130    NSMutableArray * sounds = [NSMutableArray array];
131    NSEnumerator * soundEnumerator,
132                * soundDirectoriesEnumerator = [[NSArray arrayWithObjects: @"System/Library/Sounds",
133                        [NSHomeDirectory() stringByAppendingPathComponent: @"Library/Sounds"], nil] objectEnumerator];
134    NSString * soundPath, * sound;
135   
136    //get list of all sounds and sort alphabetically
137    while ((soundPath = [soundDirectoriesEnumerator nextObject]))
138        if (soundEnumerator = [[NSFileManager defaultManager] enumeratorAtPath: soundPath])
139            while ((sound = [soundEnumerator nextObject]))
140            {
141                sound = [sound stringByDeletingPathExtension];
142                if ([NSSound soundNamed: sound])
143                    [sounds addObject: sound];
144            }
145   
146    [sounds sortUsingSelector: @selector(caseInsensitiveCompare:)];
147   
148    //set download sound
149    [fDownloadSoundPopUp removeAllItems];
150    [fDownloadSoundPopUp addItemsWithTitles: sounds];
151   
152    int downloadSoundIndex = [fDownloadSoundPopUp indexOfItemWithTitle: [fDefaults stringForKey: @"DownloadSound"]];
153    if (downloadSoundIndex >= 0)
154        [fDownloadSoundPopUp selectItemAtIndex: downloadSoundIndex];
155    else
156        [fDefaults setObject: [fDownloadSoundPopUp titleOfSelectedItem] forKey: @"DownloadSound"];
157   
158    //set seeding sound
159    [fSeedingSoundPopUp removeAllItems];
160    [fSeedingSoundPopUp addItemsWithTitles: sounds];
161   
162    int seedingSoundIndex = [fDownloadSoundPopUp indexOfItemWithTitle: [fDefaults stringForKey: @"SeedingSound"]];
163    if (seedingSoundIndex >= 0)
164        [fSeedingSoundPopUp selectItemAtIndex: seedingSoundIndex];
165    else
166        [fDefaults setObject: [fSeedingSoundPopUp titleOfSelectedItem] forKey: @"SeedingSound"];
167
168    //set update check
169    NSString * updateCheck = [fDefaults stringForKey: @"UpdateCheck"];
170    if ([updateCheck isEqualToString: @"Weekly"])
171        [fUpdatePopUp selectItemAtIndex: UPDATE_WEEKLY];
172    else if ([updateCheck isEqualToString: @"Never"])
173        [fUpdatePopUp selectItemAtIndex: UPDATE_NEVER];
174    else
175        [fUpdatePopUp selectItemAtIndex: UPDATE_DAILY];
176}
177
178- (void) setUpdater: (SUUpdater *) updater
179{
180    fUpdater = updater;
181}
182
183- (NSToolbarItem *) toolbar: (NSToolbar *) toolbar itemForItemIdentifier: (NSString *) ident
184                    willBeInsertedIntoToolbar: (BOOL) flag
185{
186    NSToolbarItem * item;
187    item = [[NSToolbarItem alloc] initWithItemIdentifier: ident];
188
189    if ([ident isEqualToString: TOOLBAR_GENERAL])
190    {
191        [item setLabel: NSLocalizedString(@"General", "Preferences -> General toolbar item title")];
192        [item setImage: [NSImage imageNamed: @"Preferences.png"]];
193        [item setTarget: self];
194        [item setAction: @selector(setPrefView:)];
195    }
196    else if ([ident isEqualToString: TOOLBAR_TRANSFERS])
197    {
198        [item setLabel: NSLocalizedString(@"Transfers", "Preferences -> Transfers toolbar item title")];
199        [item setImage: [NSImage imageNamed: @"Transfers.png"]];
200        [item setTarget: self];
201        [item setAction: @selector(setPrefView:)];
202    }
203    else if ([ident isEqualToString: TOOLBAR_BANDWIDTH])
204    {
205        [item setLabel: NSLocalizedString(@"Bandwidth", "Preferences -> Bandwidth toolbar item title")];
206        [item setImage: [NSImage imageNamed: @"Bandwidth.png"]];
207        [item setTarget: self];
208        [item setAction: @selector(setPrefView:)];
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    }
217    else
218    {
219        [item release];
220        return nil;
221    }
222
223    return item;
224}
225
226- (NSArray *) toolbarSelectableItemIdentifiers: (NSToolbar *) toolbar
227{
228    return [self toolbarDefaultItemIdentifiers: toolbar];
229}
230
231- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
232{
233    return [self toolbarAllowedItemIdentifiers: toolbar];
234}
235
236- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
237{
238    return [NSArray arrayWithObjects: TOOLBAR_GENERAL, TOOLBAR_TRANSFERS,
239                                        TOOLBAR_BANDWIDTH, TOOLBAR_NETWORK, nil];
240}
241
242- (void) setPort: (id) sender
243{
244    tr_setBindPort(fHandle, [fDefaults integerForKey: @"BindPort"]);
245    [self updateNatStatus];
246    [self updatePortStatus];
247}
248
249- (void) updatePortStatus
250{
251    long sytemVersion;
252    [fPortStatusField setStringValue: @""];
253    [fPortStatusImage setImage: nil];
254   
255    Gestalt('sysv', & sytemVersion);
256    if (sytemVersion >= 0x1040)
257    {
258        //NSXML features are unfortunately only available since Mac OS X v10.4
259        PortChecker * checker = [[PortChecker alloc] initWithDelegate: self];
260
261        [fPortStatusField setStringValue: [NSLocalizedString(@"Checking port status",
262                                            "Preferences -> Network -> port status") stringByAppendingEllipsis]];
263        [fPortStatusProgress startAnimation: self];
264       
265        [checker probePort: [fDefaults integerForKey: @"BindPort"]];
266    }
267}
268
269- (void) portCheckerDidFinishProbing: (PortChecker *) portChecker
270{
271    [fPortStatusProgress stopAnimation: self];
272    switch ([portChecker status])
273    {
274        case PORT_STATUS_OPEN:
275            [fPortStatusField setStringValue: NSLocalizedString(@"Port is open", "Preferences -> Network -> port status")];
276            [fPortStatusImage setImage: [NSImage imageNamed: @"GreenDot.tiff"]];
277            break;
278        case PORT_STATUS_STEALTH:
279            [fPortStatusField setStringValue: NSLocalizedString(@"Port is stealth", "Preferences -> Network -> port status")];
280            [fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]];
281            break;
282        case PORT_STATUS_CLOSED:
283            [fPortStatusField setStringValue: NSLocalizedString(@"Port is closed", "Preferences -> Network -> port status")];
284            [fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]];
285            break;
286        case PORT_STATUS_ERROR:
287            [fPortStatusField setStringValue: NSLocalizedString(@"Unable to check port status",
288                                                "Preferences -> Network -> port status")];
289            [fPortStatusImage setImage: [NSImage imageNamed: @"YellowDot.tiff"]];
290            break;
291    }
292    [portChecker release];
293}
294
295- (void) setNat: (id) sender
296{
297    [fDefaults boolForKey: @"NatTraversal"] ? tr_natTraversalEnable(fHandle) : tr_natTraversalDisable(fHandle);
298    [self updateNatStatus];
299}
300
301- (void) updateNatStatus
302{
303    int status = tr_natTraversalStatus(fHandle);
304    if (fNatStatus == status)
305        return;
306    fNatStatus = status;
307   
308    if (status == 2)
309    {
310        [fNatStatusField setStringValue: NSLocalizedString(@"Port successfully mapped",
311                                            "Preferences -> Network -> port map status")];
312        [fNatStatusImage setImage: [NSImage imageNamed: @"GreenDot.tiff"]];
313    }
314    else if (status == 3 || status == 4)
315    {
316        [fNatStatusField setStringValue: NSLocalizedString(@"Error mapping port",
317                                            "Preferences -> Network -> port map status")];
318        [fNatStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]];
319    }
320    else
321    {
322        [fNatStatusField setStringValue: @""];
323        [fNatStatusImage setImage: nil];
324    }
325   
326    [self updatePortStatus];
327}
328
329- (void) applySpeedSettings: (id) sender
330{
331    if ([fDefaults boolForKey: @"SpeedLimit"])
332    {
333        tr_setUploadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]);
334        tr_setDownloadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]);
335    }
336    else
337    {
338        tr_setUploadLimit(fHandle, [fDefaults boolForKey: @"CheckUpload"]
339                                        ? [fDefaults integerForKey: @"UploadLimit"] : -1);
340        tr_setDownloadLimit(fHandle, [fDefaults boolForKey: @"CheckDownload"]
341                                        ? [fDefaults integerForKey: @"DownloadLimit"] : -1);
342    }
343}
344
345- (void) setAutoSpeedLimitCheck: (id) sender
346{
347    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSpeedLimitChange" object: self];
348}
349
350#warning check if same value
351- (void) setAutoSpeedLimitHour: (id) sender
352{
353    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSpeedLimitChange" object: self];
354}
355
356- (void) setBadge: (id) sender
357{   
358    [[NSNotificationCenter defaultCenter] postNotificationName: @"DockBadgeChange" object: self];
359}
360
361- (void) setSound: (id) sender
362{
363    //play sound when selecting
364    NSString * soundName = [sender titleOfSelectedItem];
365    NSSound * sound;
366    if ((sound = [NSSound soundNamed: soundName]))
367        [sound play];
368
369    #warning use bindings
370    if (sender == fDownloadSoundPopUp)
371        [fDefaults setObject: soundName forKey: @"DownloadSound"];
372    else if (sender == fSeedingSoundPopUp)
373        [fDefaults setObject: soundName forKey: @"SeedingSound"];
374    else;
375}
376
377- (void) setUpdate: (id) sender
378{
379    int index = [fUpdatePopUp indexOfSelectedItem];
380    NSTimeInterval seconds;
381    if (index == UPDATE_DAILY)
382    {
383        [fDefaults setObject: @"Daily" forKey: @"UpdateCheck"];
384        seconds = 86400;
385    }
386    else if (index == UPDATE_WEEKLY)
387    {
388        [fDefaults setObject: @"Weekly" forKey: @"UpdateCheck"];
389        seconds = 604800;
390    }
391    else
392    {
393        [fDefaults setObject: @"Never" forKey: @"UpdateCheck"];
394        seconds = 0;
395    }
396
397    [fDefaults setInteger: seconds forKey: @"SUScheduledCheckInterval"];
398   
399    if (fUpdater)
400        [fUpdater scheduleCheckWithInterval: seconds];
401}
402
403#warning out of range/wrong value
404- (void) setQueueNumber: (id) sender
405{
406    [[NSNotificationCenter defaultCenter] postNotificationName: @"GlobalStartSettingChange" object: self];
407}
408
409- (void) setDownloadLocation: (id) sender
410{
411    //download folder
412    switch ([fFolderPopUp indexOfSelectedItem])
413    {
414        case DOWNLOAD_FOLDER:
415            [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
416            break;
417        case DOWNLOAD_TORRENT:
418            [fDefaults setObject: @"Torrent" forKey: @"DownloadChoice"];
419            break;
420        case DOWNLOAD_ASK:
421            [fDefaults setObject: @"Ask" forKey: @"DownloadChoice"];
422            break;
423    }
424}
425
426- (void) folderSheetShow: (id) sender
427{
428    NSOpenPanel * panel = [NSOpenPanel openPanel];
429
430    [panel setPrompt: @"Select"];
431    [panel setAllowsMultipleSelection: NO];
432    [panel setCanChooseFiles: NO];
433    [panel setCanChooseDirectories: YES];
434    [panel setCanCreateDirectories: YES];
435
436    [panel beginSheetForDirectory: nil file: nil types: nil
437        modalForWindow: [self window] modalDelegate: self didEndSelector:
438        @selector(folderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
439}
440
441- (void) setAutoImport: (id) sender
442{
443    if ([fDefaults boolForKey: @"AutoImport"])
444        [[UKKQueue sharedFileWatcher] addPath:
445            [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
446    else
447        [[UKKQueue sharedFileWatcher] removePathFromQueue:
448            [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
449   
450    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
451}
452
453- (void) importFolderSheetShow: (id) sender
454{
455    NSOpenPanel * panel = [NSOpenPanel openPanel];
456
457    [panel setPrompt: @"Select"];
458    [panel setAllowsMultipleSelection: NO];
459    [panel setCanChooseFiles: NO];
460    [panel setCanChooseDirectories: YES];
461    [panel setCanCreateDirectories: YES];
462
463    [panel beginSheetForDirectory: nil file: nil types: nil
464        modalForWindow: [self window] modalDelegate: self didEndSelector:
465        @selector(importFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
466}
467
468- (void) setAutoSize: (id) sender
469{
470    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSizeSettingChange" object: self];
471}
472
473- (void) helpForNetwork: (id) sender
474{
475    [[NSHelpManager sharedHelpManager] openHelpAnchor: @"PortForwarding"
476        inBook: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"]];
477}
478
479@end
480
481@implementation PrefsController (Private)
482
483- (void) setPrefView: (id) sender
484{
485    NSView * view = fGeneralView;
486    if (sender)
487    {
488        NSString * identifier = [sender itemIdentifier];
489        if ([identifier isEqualToString: TOOLBAR_TRANSFERS])
490            view = fTransfersView;
491        else if ([identifier isEqualToString: TOOLBAR_BANDWIDTH])
492            view = fBandwidthView;
493        else if ([identifier isEqualToString: TOOLBAR_NETWORK])
494            view = fNetworkView;
495        else;
496    }
497   
498    NSWindow * window = [self window];
499    if ([window contentView] == view)
500        return;
501   
502    NSRect windowRect = [window frame];
503    int difference = [view frame].size.height - [[window contentView] frame].size.height;
504    windowRect.origin.y -= difference;
505    windowRect.size.height += difference;
506   
507    [view setHidden: YES];
508    [window setContentView: view];
509    [window setFrame: windowRect display: YES animate: YES];
510    [view setHidden: NO];
511   
512    //set title label
513    if (sender)
514        [window setTitle: [sender label]];
515    else
516    {
517        NSToolbarItem * item;
518        NSEnumerator * enumerator = [[fToolbar items] objectEnumerator];
519        while ((item = [enumerator nextObject]))
520            if ([[item itemIdentifier] isEqualToString: [fToolbar selectedItemIdentifier]])
521            {
522                [window setTitle: [item label]];
523                break;
524            }
525    }
526   
527    //for network view make sure progress indicator hides itself
528    if (view == fNetworkView && [fPortStatusImage image])
529        [fPortStatusProgress setDisplayedWhenStopped: NO];
530}
531
532- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
533{
534    if (code == NSOKButton)
535    {
536        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
537        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"DownloadFolder"];
538        [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
539       
540        [self updatePopUp];
541    }
542    else
543    {
544        //reset if cancelled
545        NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
546        if ([downloadChoice isEqualToString: @"Constant"])
547            [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
548        else if ([downloadChoice isEqualToString: @"Torrent"])
549            [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
550        else
551            [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
552    }
553}
554
555- (void) updatePopUp
556{
557    //get and resize the icon
558    NSImage * icon = [[NSWorkspace sharedWorkspace] iconForFile:
559                        [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath]];
560    [icon setScalesWhenResized: YES];
561    [icon setSize: NSMakeSize(16.0, 16.0)];
562
563    //update menu item
564    NSMenuItem * menuItem = (NSMenuItem *) [fFolderPopUp itemAtIndex: 0];
565    [menuItem setTitle: [[fDefaults stringForKey: @"DownloadFolder"] lastPathComponent]];
566    [menuItem setImage: icon];
567}
568
569- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
570{
571    if (code == NSOKButton)
572    {
573        UKKQueue * sharedQueue = [UKKQueue sharedFileWatcher];
574        [sharedQueue removePathFromQueue: [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
575       
576        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"AutoImportDirectory"];
577       
578        [self updateImportPopUp];
579       
580        [sharedQueue addPath: [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
581       
582        [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
583    }
584    [fImportFolderPopUp selectItemAtIndex: 0];
585}
586
587- (void) updateImportPopUp
588{
589    //get and resize the icon
590    NSImage * icon = [[NSWorkspace sharedWorkspace] iconForFile:
591                        [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
592    [icon setScalesWhenResized: YES];
593    [icon setSize: NSMakeSize(16.0, 16.0)];
594
595    //update menu item
596    NSMenuItem * menuItem = (NSMenuItem *) [fImportFolderPopUp itemAtIndex: 0];
597    [menuItem setTitle: [[fDefaults stringForKey: @"AutoImportDirectory"] lastPathComponent]];
598    [menuItem setImage: icon];
599}
600
601@end
Note: See TracBrowser for help on using the repository browser.