2 // HMScreenshotInformation.m
5 // Created by Hori,Masaki on 2014/11/09.
6 // Copyright (c) 2014年 Hori,Masaki. All rights reserved.
9 #import "HMScreenshotInformation.h"
11 #import <Quartz/Quartz.h>
14 static NSDateFormatter *formatter = nil;
16 @interface HMScreenshotInformation ()
17 @property (nonatomic, strong) NSURL *url;
20 @implementation HMScreenshotInformation
21 @synthesize creationDate = _creationDate;
22 @synthesize url = _url;
26 static dispatch_once_t onceToken;
27 dispatch_once(&onceToken, ^{
28 formatter = [NSDateFormatter new];
29 formatter.dateStyle = NSDateFormatterShortStyle;
30 formatter.timeStyle = NSDateFormatterShortStyle;
31 formatter.doesRelativeDateFormatting = YES;
34 - (NSString *)imageUID
38 - (NSString *)imageRepresentationType
40 return IKImageBrowserQuickLookPathRepresentationType;
42 - (id)imageRepresentation
46 - (NSString *)imageTitle
48 return self.path.lastPathComponent.stringByDeletingPathExtension;
50 - (NSString *)imageSubtitle
52 return [formatter stringFromDate:self.creationDate];
54 - (NSUInteger)imageVersion
59 - (NSDate *)creationDate
62 NSFileManager *fm = [NSFileManager defaultManager];
63 NSDictionary *fileAttr = [fm attributesOfItemAtPath:self.path error:NULL];
64 _creationDate = [fileAttr fileCreationDate];
68 - (void)setCreationDate:(NSDate *)creationDate
70 _creationDate = creationDate;
75 _url = [NSURL fileURLWithPath:self.path];
83 if(![self.url getResourceValue:&tags forKey:NSURLTagNamesKey error:&error]) {
85 NSLog(@"get tags error -> %@", error);
91 - (void)setTags:(NSArray *)tags
94 [self.url setResourceValue:tags forKey:NSURLTagNamesKey error:&error];
96 NSLog(@"set tags error -> %@", error);
103 return [self.path hash];
105 - (BOOL)isEqual:(id)object
107 if(![object isMemberOfClass:[self class]]) return NO;
109 HMScreenshotInformation *obj = object;
110 return [self.path isEqual:obj.path];
113 #pragma mark - NSCoding
114 - (void)encodeWithCoder:(NSCoder *)aCoder
116 [aCoder encodeObject:self.path forKey:@"HMScreenshotInformationPathKey"];
117 [aCoder encodeDouble:self.creationDate.timeIntervalSince1970 forKey:@"HMScreenshotInformationCreationDateKey"];
118 [aCoder encodeInt64:self.version forKey:@"HMScreenshotInformationVersionKey"];
120 - (id)initWithCoder:(NSCoder *)aDecoder
124 _path = [aDecoder decodeObjectForKey:@"HMScreenshotInformationPathKey"];
125 NSTimeInterval t = [aDecoder decodeDoubleForKey:@"HMScreenshotInformationCreationDateKey"];
126 _creationDate = [NSDate dateWithTimeIntervalSince1970:t];
127 _version = [aDecoder decodeInt64ForKey:@"HMScreenshotInformationVersionKey"];