You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

96 lines
2.8 KiB

  1. /*
  2. Copyright 2017 Virgil Dupras
  3. This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
  4. which should be included with this package. The terms are also available at
  5. http://www.gnu.org/licenses/gpl-3.0.html
  6. */
  7. #import "Utils.h"
  8. #import "NSNotificationAdditions.h"
  9. #import "NSImageAdditions.h"
  10. #import "PyDupeGuru.h"
  11. #import "DetailsPanelPicture.h"
  12. #import "Consts.h"
  13. @implementation DetailsPanelPicture
  14. @synthesize dupeImage;
  15. @synthesize dupeProgressIndicator;
  16. @synthesize refImage;
  17. @synthesize refProgressIndicator;
  18. - (id)initWithApp:(PyDupeGuru *)aApp
  19. {
  20. self = [super initWithPyRef:[aApp detailsPanel]];
  21. pyApp = aApp;
  22. _needsRefresh = YES;
  23. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(imageLoaded:) name:ImageLoadedNotification object:self];
  24. return self;
  25. }
  26. - (NSString *)getWindowNibName
  27. {
  28. return @"DetailsPanelPicture";
  29. }
  30. - (void)loadImageAsync:(NSString *)imagePath
  31. {
  32. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  33. NSImage *image = [[NSImage alloc] initByReferencingFile:imagePath];
  34. NSImage *thumbnail = [image imageByScalingProportionallyToSize:NSMakeSize(512,512)];
  35. [image release];
  36. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  37. [params setValue:imagePath forKey:@"imagePath"];
  38. [params setValue:thumbnail forKey:@"image"];
  39. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:ImageLoadedNotification object:self userInfo:params waitUntilDone:YES];
  40. [pool release];
  41. }
  42. - (void)refreshDetails
  43. {
  44. if (!_needsRefresh)
  45. return;
  46. [detailsTable reloadData];
  47. NSString *refPath = [pyApp getSelectedDupeRefPath];
  48. if (_refPath != nil)
  49. [_refPath autorelease];
  50. _refPath = [refPath retain];
  51. [NSThread detachNewThreadSelector:@selector(loadImageAsync:) toTarget:self withObject:refPath];
  52. NSString *dupePath = [pyApp getSelectedDupePath];
  53. if (_dupePath != nil)
  54. [_dupePath autorelease];
  55. _dupePath = [dupePath retain];
  56. if (![dupePath isEqual: refPath])
  57. [NSThread detachNewThreadSelector:@selector(loadImageAsync:) toTarget:self withObject:dupePath];
  58. [refProgressIndicator startAnimation:nil];
  59. [dupeProgressIndicator startAnimation:nil];
  60. _needsRefresh = NO;
  61. }
  62. /* Notifications */
  63. - (void)imageLoaded:(NSNotification *)aNotification
  64. {
  65. NSString *imagePath = [[aNotification userInfo] valueForKey:@"imagePath"];
  66. NSImage *image = [[aNotification userInfo] valueForKey:@"image"];
  67. if ([imagePath isEqual: _refPath])
  68. {
  69. [refImage setImage:image];
  70. [refProgressIndicator stopAnimation:nil];
  71. }
  72. if ([imagePath isEqual: _dupePath])
  73. {
  74. [dupeImage setImage:image];
  75. [dupeProgressIndicator stopAnimation:nil];
  76. }
  77. }
  78. /* Python --> Cocoa */
  79. - (void)refresh
  80. {
  81. _needsRefresh = YES;
  82. [super refresh];
  83. }
  84. @end