Cleaner icon caching

This commit is contained in:
Eric Petit 2006-02-10 06:14:36 +00:00
parent 9b2cbdd166
commit 43696cd5da
2 changed files with 16 additions and 20 deletions

View File

@ -36,8 +36,7 @@
NSString * fTimeString; NSString * fTimeString;
NSString * fPeersString; NSString * fPeersString;
NSMutableArray * fFileTypes; NSMutableDictionary * fIcons;
NSMutableArray * fIcons;
NSImage * fCurrentIcon; NSImage * fCurrentIcon;
} }
- (void) setStat: (tr_stat_t *) stat whiteText: (BOOL) w; - (void) setStat: (tr_stat_t *) stat whiteText: (BOOL) w;

View File

@ -28,34 +28,31 @@
- (id) init - (id) init
{ {
[super init]; if ((self = [super init]))
fIcons = [[NSMutableDictionary alloc] initWithCapacity: 10];
fFileTypes = [[NSMutableArray alloc] initWithCapacity: 10];
fIcons = [[NSMutableArray alloc] initWithCapacity: 10];
return self; return self;
} }
- (NSImage *) iconForFileType: (NSString *) type - (void) dealloc
{ {
unsigned i; [fIcons release];
[super dealloc];
/* See if we have this icon cached */
for( i = 0; i < [fFileTypes count]; i++ )
if( [[fFileTypes objectAtIndex: i] isEqualToString: type] )
break;
if( i == [fFileTypes count] )
{
/* Unknown file type, get its icon and cache it */
NSImage * icon;
icon = [[NSWorkspace sharedWorkspace] iconForFileType: type];
[icon setFlipped: YES];
[fFileTypes addObject: type];
[fIcons addObject: icon];
} }
return [fIcons objectAtIndex: i]; - (NSImage *) iconForFileType: (NSString *) type
{
NSImage * icon;
if (!(icon = [fIcons objectForKey: type]))
{
/* Unknown file type, get its icon and cache it */
icon = [[NSWorkspace sharedWorkspace] iconForFileType: type];
[icon setFlipped: YES];
[fIcons setObject: icon forKey: type];
}
return icon;
} }
- (void) setStat: (tr_stat_t *) stat whiteText: (BOOL) w - (void) setStat: (tr_stat_t *) stat whiteText: (BOOL) w