2009-08-05 08:59:46 +00:00
|
|
|
/*
|
2010-01-01 20:11:34 +00:00
|
|
|
Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
|
2010-09-30 10:17:41 +00:00
|
|
|
This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
2009-08-05 08:59:46 +00:00
|
|
|
which should be included with this package. The terms are also available at
|
2010-09-30 10:17:41 +00:00
|
|
|
http://www.hardcoded.net/licenses/bsd_license
|
2009-08-05 08:59:46 +00:00
|
|
|
*/
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
#import "Utils.h"
|
|
|
|
#import "NSNotificationAdditions.h"
|
|
|
|
#import "NSImageAdditions.h"
|
|
|
|
#import "PyDupeGuru.h"
|
|
|
|
#import "DetailsPanel.h"
|
|
|
|
#import "Consts.h"
|
|
|
|
|
2010-02-05 16:15:45 +00:00
|
|
|
@implementation DetailsPanelPE
|
2009-06-01 09:55:11 +00:00
|
|
|
- (id)initWithPy:(PyApp *)aPy
|
|
|
|
{
|
2009-06-15 12:45:08 +00:00
|
|
|
self = [super initWithPy:aPy];
|
2010-02-05 19:10:54 +00:00
|
|
|
pyApp = aPy;
|
2009-06-01 09:55:11 +00:00
|
|
|
_needsRefresh = YES;
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(imageLoaded:) name:ImageLoadedNotification object:self];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)loadImageAsync:(NSString *)imagePath
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
NSImage *image = [[NSImage alloc] initByReferencingFile:imagePath];
|
|
|
|
NSImage *thumbnail = [image imageByScalingProportionallyToSize:NSMakeSize(512,512)];
|
|
|
|
[image release];
|
|
|
|
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
|
|
|
[params setValue:imagePath forKey:@"imagePath"];
|
|
|
|
[params setValue:thumbnail forKey:@"image"];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:ImageLoadedNotification object:self userInfo:params waitUntilDone:YES];
|
|
|
|
[pool release];
|
|
|
|
}
|
|
|
|
|
2010-02-05 19:10:54 +00:00
|
|
|
- (void)refreshDetails
|
2009-06-01 09:55:11 +00:00
|
|
|
{
|
|
|
|
if (!_needsRefresh)
|
|
|
|
return;
|
|
|
|
[detailsTable reloadData];
|
|
|
|
|
2010-02-05 19:10:54 +00:00
|
|
|
NSString *refPath = [(PyDupeGuru *)pyApp getSelectedDupeRefPath];
|
2009-06-01 09:55:11 +00:00
|
|
|
if (_refPath != nil)
|
|
|
|
[_refPath autorelease];
|
|
|
|
_refPath = [refPath retain];
|
|
|
|
[NSThread detachNewThreadSelector:@selector(loadImageAsync:) toTarget:self withObject:refPath];
|
2010-02-05 19:10:54 +00:00
|
|
|
NSString *dupePath = [(PyDupeGuru *)pyApp getSelectedDupePath];
|
2009-06-01 09:55:11 +00:00
|
|
|
if (_dupePath != nil)
|
|
|
|
[_dupePath autorelease];
|
|
|
|
_dupePath = [dupePath retain];
|
|
|
|
if (![dupePath isEqual: refPath])
|
|
|
|
[NSThread detachNewThreadSelector:@selector(loadImageAsync:) toTarget:self withObject:dupePath];
|
|
|
|
[refProgressIndicator startAnimation:nil];
|
|
|
|
[dupeProgressIndicator startAnimation:nil];
|
|
|
|
_needsRefresh = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Notifications */
|
|
|
|
- (void)imageLoaded:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
NSString *imagePath = [[aNotification userInfo] valueForKey:@"imagePath"];
|
|
|
|
NSImage *image = [[aNotification userInfo] valueForKey:@"image"];
|
|
|
|
if ([imagePath isEqual: _refPath])
|
|
|
|
{
|
|
|
|
[refImage setImage:image];
|
|
|
|
[refProgressIndicator stopAnimation:nil];
|
|
|
|
}
|
|
|
|
if ([imagePath isEqual: _dupePath])
|
|
|
|
{
|
|
|
|
[dupeImage setImage:image];
|
|
|
|
[dupeProgressIndicator stopAnimation:nil];
|
|
|
|
}
|
|
|
|
}
|
2010-02-05 19:10:54 +00:00
|
|
|
|
|
|
|
/* Python --> Cocoa */
|
|
|
|
- (void)refresh
|
|
|
|
{
|
|
|
|
_needsRefresh = YES;
|
|
|
|
[super refresh];
|
|
|
|
}
|
2009-06-01 09:55:11 +00:00
|
|
|
@end
|