2009-08-05 08:59:46 +00:00
|
|
|
/*
|
2015-01-03 21:30:57 +00:00
|
|
|
Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
|
2015-01-03 21:33:16 +00:00
|
|
|
This software is licensed under the "GPLv3" 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
|
2015-01-03 21:33:16 +00:00
|
|
|
http://www.gnu.org/licenses/gpl-3.0.html
|
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"
|
2012-07-29 15:57:46 +00:00
|
|
|
#import "DetailsPanel.h"
|
2009-06-01 09:55:11 +00:00
|
|
|
#import "Consts.h"
|
2012-07-29 15:57:46 +00:00
|
|
|
#import "DetailsPanel_UI.h"
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2012-07-29 15:57:46 +00:00
|
|
|
@implementation DetailsPanel
|
2012-07-21 20:13:16 +00:00
|
|
|
|
|
|
|
@synthesize dupeImage;
|
|
|
|
@synthesize dupeProgressIndicator;
|
|
|
|
@synthesize refImage;
|
|
|
|
@synthesize refProgressIndicator;
|
|
|
|
|
2012-01-16 15:30:45 +00:00
|
|
|
- (id)initWithApp:(PyDupeGuru *)aApp
|
2009-06-01 09:55:11 +00:00
|
|
|
{
|
2012-01-16 15:30:45 +00:00
|
|
|
self = [super initWithPyRef:[aApp detailsPanel]];
|
|
|
|
pyApp = aApp;
|
2009-06-01 09:55:11 +00:00
|
|
|
_needsRefresh = YES;
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(imageLoaded:) name:ImageLoadedNotification object:self];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-07-29 15:57:46 +00:00
|
|
|
- (NSWindow *)createWindow
|
|
|
|
{
|
|
|
|
return createDetailsPanel_UI(self);
|
|
|
|
}
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
- (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];
|
|
|
|
|
2012-01-16 15:30:45 +00:00
|
|
|
NSString *refPath = [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];
|
2012-01-16 15:30:45 +00:00
|
|
|
NSString *dupePath = [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
|