Add an uuid property to MP42Image.

This commit is contained in:
Damiano Galassi committed 2014-02-20 10:15:27 +01:00
1 parent d5c56a7a5c
commit 2ece3cabf2
2 files changed
+25 -4

No files matched your search

+2 -1
View File
@@ -23,11 +23,12 @@ typedef enum MP42TagArtworkType_e {
NSURL *_url; NSURL *_url;
NSData *_data; NSData *_data;
NSString *_uuid;
NSInteger _type; NSInteger _type;
} }
- (instancetype)initWithURL:(NSURL *)url type:(NSInteger)type; - (instancetype)initWithURL:(NSURL *)url type:(NSInteger)type;
- (instancetype)initWithImage:(NSImage *)image; - (instancetype)initWithImage:(NSImage *)image;
- (instancetype)initWithData:(NSData *)data type:(NSInteger)type; - (instancetype)initWithData:(NSData *)data type:(NSInteger)type;
- (instancetype)initWithBytes:(const void*)bytes length:(NSUInteger)length type:(NSInteger)type; - (instancetype)initWithBytes:(const void*)bytes length:(NSUInteger)length type:(NSInteger)type;
+23 -3
View File
@@ -9,11 +9,18 @@
#import "MP42Image.h" #import "MP42Image.h"
#import <Quartz/Quartz.h> #import <Quartz/Quartz.h>
@interface MP42Image ()
@property (atomic, readonly) NSString *uuid;
@end
@implementation MP42Image @implementation MP42Image
@synthesize url = _url; @synthesize url = _url;
@synthesize data = _data; @synthesize data = _data;
@synthesize type = _type; @synthesize type = _type;
@synthesize uuid = _uuid;
- (instancetype)initWithURL:(NSURL *)url type:(NSInteger)type - (instancetype)initWithURL:(NSURL *)url type:(NSInteger)type
{ {
@@ -82,9 +89,9 @@
- (NSData *)data { - (NSData *)data {
@synchronized(self) { @synchronized(self) {
if (_data) if (_data) {
return _data; return _data;
else if (_url) { } else if (_url) {
NSError *outError = nil; NSError *outError = nil;
_data = [[NSData dataWithContentsOfURL:_url options:NSDataReadingUncached error:&outError] retain]; _data = [[NSData dataWithContentsOfURL:_url options:NSDataReadingUncached error:&outError] retain];
} }
@@ -111,9 +118,21 @@
return IKImageBrowserNSImageRepresentationType; return IKImageBrowserNSImageRepresentationType;
} }
- (NSString *)uuid
{
@synchronized(self) {
if (_uuid == nil) {
_uuid = [[NSProcessInfo processInfo] globallyUniqueString];
}
}
return _uuid;
}
- (NSString *)imageUID - (NSString *)imageUID
{ {
return [self.image description]; return self.uuid;
} }
- (id)imageRepresentation - (id)imageRepresentation
@@ -147,6 +166,7 @@
{ {
[_image release]; [_image release];
[_data release]; [_data release];
[_uuid release];
[super dealloc]; [super dealloc];
} }