mirror of
https://github.com/transmission/transmission
synced 2025-02-07 06:54:40 +00:00
Cleaner icon caching
This commit is contained in:
parent
9b2cbdd166
commit
43696cd5da
2 changed files with 16 additions and 20 deletions
|
@ -36,9 +36,8 @@
|
||||||
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;
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
[fIcons release];
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
- (NSImage *) iconForFileType: (NSString *) type
|
- (NSImage *) iconForFileType: (NSString *) type
|
||||||
{
|
{
|
||||||
unsigned i;
|
NSImage * icon;
|
||||||
|
if (!(icon = [fIcons objectForKey: type]))
|
||||||
/* 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 */
|
/* Unknown file type, get its icon and cache it */
|
||||||
NSImage * icon;
|
|
||||||
icon = [[NSWorkspace sharedWorkspace] iconForFileType: type];
|
icon = [[NSWorkspace sharedWorkspace] iconForFileType: type];
|
||||||
[icon setFlipped: YES];
|
[icon setFlipped: YES];
|
||||||
[fFileTypes addObject: type];
|
|
||||||
[fIcons addObject: icon];
|
[fIcons setObject: icon forKey: type];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [fIcons objectAtIndex: i];
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setStat: (tr_stat_t *) stat whiteText: (BOOL) w
|
- (void) setStat: (tr_stat_t *) stat whiteText: (BOOL) w
|
||||||
|
@ -136,7 +133,7 @@
|
||||||
float cellWidth = cellFrame.size.width;
|
float cellWidth = cellFrame.size.width;
|
||||||
|
|
||||||
pen.x += 5;
|
pen.x += 5;
|
||||||
pen.y += 5;
|
pen.y += 5;
|
||||||
[fCurrentIcon drawAtPoint: pen fromRect:
|
[fCurrentIcon drawAtPoint: pen fromRect:
|
||||||
NSMakeRect(0,0,[fCurrentIcon size].width,[fCurrentIcon size].height)
|
NSMakeRect(0,0,[fCurrentIcon size].width,[fCurrentIcon size].height)
|
||||||
operation: NSCompositeSourceOver fraction: 1.0];
|
operation: NSCompositeSourceOver fraction: 1.0];
|
||||||
|
|
Loading…
Reference in a new issue