From 134108035e7ecdee5eb7b9c910acec680e9bf225 Mon Sep 17 00:00:00 2001 From: masakih Date: Tue, 23 Dec 2014 01:49:27 +0900 Subject: [PATCH] =?utf8?q?HMScreenshotInformation=E3=82=AF=E3=83=A9?= =?utf8?q?=E3=82=B9=E3=82=92Swift=E3=81=A6=E3=82=99=E6=9B=B8=E3=81=8D?= =?utf8?q?=E6=8F=9B=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- KCD.xcodeproj/project.pbxproj | 10 ++- KCD/HMScreenshotInformation.h | 17 ----- KCD/HMScreenshotInformation.m | 111 --------------------------------- KCD/HMScreenshotInformation.swift | 80 ++++++++++++++++++++++++ KCD/HMScreenshotListWindowController.m | 5 +- 5 files changed, 88 insertions(+), 135 deletions(-) delete mode 100644 KCD/HMScreenshotInformation.h delete mode 100644 KCD/HMScreenshotInformation.m create mode 100644 KCD/HMScreenshotInformation.swift diff --git a/KCD.xcodeproj/project.pbxproj b/KCD.xcodeproj/project.pbxproj index 1a4a5075..d03b51ea 100644 --- a/KCD.xcodeproj/project.pbxproj +++ b/KCD.xcodeproj/project.pbxproj @@ -46,6 +46,7 @@ F4551BDE1A46C23100BB0235 /* HMTimerCountFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4551BDD1A46C23100BB0235 /* HMTimerCountFormatter.swift */; }; F4551BE21A47044A00BB0235 /* HMExternalBrowserWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4551BE11A47044A00BB0235 /* HMExternalBrowserWindowController.swift */; }; F4551BE41A48379F00BB0235 /* HMDeckViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4551BE31A48379F00BB0235 /* HMDeckViewController.swift */; }; + F4551BE61A48711D00BB0235 /* HMScreenshotInformation.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4551BE51A48711D00BB0235 /* HMScreenshotInformation.swift */; }; F46F103618A7CE310063E503 /* HMJSONViewCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F46F103518A7CE310063E503 /* HMJSONViewCommand.m */; }; F46F104118A9B85E0063E503 /* HMJSONNode.m in Sources */ = {isa = PBXBuildFile; fileRef = F46F104018A9B85E0063E503 /* HMJSONNode.m */; }; F46F104518AA50730063E503 /* HMBroserWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = F46F104318AA50730063E503 /* HMBroserWindowController.m */; }; @@ -61,7 +62,6 @@ F4A2AF521A074DCF0024BD9E /* HMScreenshotListWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = F4A2AF501A074DCF0024BD9E /* HMScreenshotListWindowController.m */; }; F4A2AF541A074DE40024BD9E /* HMScreenshotListWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4A2AF561A074DE40024BD9E /* HMScreenshotListWindowController.xib */; }; F4A2AF581A0930160024BD9E /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4A2AF571A0930160024BD9E /* Quartz.framework */; }; - F4A2AF5B1A0F9B490024BD9E /* HMScreenshotInformation.m in Sources */ = {isa = PBXBuildFile; fileRef = F4A2AF5A1A0F9B490024BD9E /* HMScreenshotInformation.m */; }; F4A3AD82199F529700FDBF80 /* HMCombinedBattleCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4A3AD81199F529700FDBF80 /* HMCombinedBattleCommand.m */; }; F4A3AD8819B6149D00FDBF80 /* HMNyukyoStartCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4A3AD8719B6149D00FDBF80 /* HMNyukyoStartCommand.m */; }; F4A3AD8B19B9BE7A00FDBF80 /* HMMaskSelectView.m in Sources */ = {isa = PBXBuildFile; fileRef = F4A3AD8A19B9BE7A00FDBF80 /* HMMaskSelectView.m */; }; @@ -230,6 +230,7 @@ F4551BDD1A46C23100BB0235 /* HMTimerCountFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMTimerCountFormatter.swift; sourceTree = ""; }; F4551BE11A47044A00BB0235 /* HMExternalBrowserWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMExternalBrowserWindowController.swift; sourceTree = ""; }; F4551BE31A48379F00BB0235 /* HMDeckViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMDeckViewController.swift; sourceTree = ""; }; + F4551BE51A48711D00BB0235 /* HMScreenshotInformation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMScreenshotInformation.swift; sourceTree = ""; }; F46F103418A7CE310063E503 /* HMJSONViewCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMJSONViewCommand.h; sourceTree = ""; }; F46F103518A7CE310063E503 /* HMJSONViewCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMJSONViewCommand.m; sourceTree = ""; }; F46F103F18A9B85E0063E503 /* HMJSONNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMJSONNode.h; sourceTree = ""; }; @@ -259,8 +260,6 @@ F4A2AF501A074DCF0024BD9E /* HMScreenshotListWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMScreenshotListWindowController.m; sourceTree = ""; }; F4A2AF551A074DE40024BD9E /* ja */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = ja; path = ja.lproj/HMScreenshotListWindowController.xib; sourceTree = ""; }; F4A2AF571A0930160024BD9E /* Quartz.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quartz.framework; path = System/Library/Frameworks/Quartz.framework; sourceTree = SDKROOT; }; - F4A2AF591A0F9B490024BD9E /* HMScreenshotInformation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMScreenshotInformation.h; sourceTree = ""; }; - F4A2AF5A1A0F9B490024BD9E /* HMScreenshotInformation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMScreenshotInformation.m; sourceTree = ""; }; F4A3AD80199F529700FDBF80 /* HMCombinedBattleCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMCombinedBattleCommand.h; sourceTree = ""; }; F4A3AD81199F529700FDBF80 /* HMCombinedBattleCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMCombinedBattleCommand.m; sourceTree = ""; }; F4A3AD8619B6149D00FDBF80 /* HMNyukyoStartCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMNyukyoStartCommand.h; sourceTree = ""; }; @@ -634,11 +633,10 @@ F4A3AD9619BDDE5500FDBF80 /* HMPreferencePanelController.xib */, F4B30CF51A45BABE008E3D79 /* HMUpgradableShipsWindowController.swift */, F4B37F0119FC8DCC002F371A /* HMUpgradableShipsWindowController.xib */, + F4551BE51A48711D00BB0235 /* HMScreenshotInformation.swift */, F4A2AF4F1A074DCF0024BD9E /* HMScreenshotListWindowController.h */, F4A2AF501A074DCF0024BD9E /* HMScreenshotListWindowController.m */, F4A2AF561A074DE40024BD9E /* HMScreenshotListWindowController.xib */, - F4A2AF591A0F9B490024BD9E /* HMScreenshotInformation.h */, - F4A2AF5A1A0F9B490024BD9E /* HMScreenshotInformation.m */, F4551BE11A47044A00BB0235 /* HMExternalBrowserWindowController.swift */, F4B2A08E1A1F9C2100D2EF12 /* HMExternalBrowserWindowController.xib */, ); @@ -917,7 +915,6 @@ F4B3DC2A18DF31400011B4FC /* HMCreateShipCommand.m in Sources */, F46F103618A7CE310063E503 /* HMJSONViewCommand.m in Sources */, F4B3DC1E18DEB8C70011B4FC /* HMKenzoHistory.m in Sources */, - F4A2AF5B1A0F9B490024BD9E /* HMScreenshotInformation.m in Sources */, F4B3DC5218F150CD0011B4FC /* HMScreenshotWindowController.m in Sources */, F426802E194D0FFD00B2C27F /* HMMemberShip3Command.m in Sources */, F4B37EF319FBBBED002F371A /* HMRemodelSlotCommand.m in Sources */, @@ -953,6 +950,7 @@ F4B30CFC1A4687E7008E3D79 /* HMIgnoreZeroTransformer.swift in Sources */, F43F3D4C1A34AC8000D6DAF7 /* HMKCMasterShipObject.m in Sources */, F4268031194D1B1A00B2C27F /* HMChangeHenseiCommand.m in Sources */, + F4551BE61A48711D00BB0235 /* HMScreenshotInformation.swift in Sources */, F4513EE418B635EA00073552 /* HMDocksViewController.m in Sources */, F494DC6D18CC054800AE97E4 /* HMNyukyoDockStatus.m in Sources */, F43BA4A1197BE22200CFF788 /* HMDestroyShipCommand.m in Sources */, diff --git a/KCD/HMScreenshotInformation.h b/KCD/HMScreenshotInformation.h deleted file mode 100644 index 4f95e7a0..00000000 --- a/KCD/HMScreenshotInformation.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// HMScreenshotInformation.h -// KCD -// -// Created by Hori,Masaki on 2014/11/09. -// Copyright (c) 2014å¹´ Hori,Masaki. All rights reserved. -// - -#import - -@interface HMScreenshotInformation : NSObject -@property (strong) NSString *path; -@property (readonly) NSString *name; -@property (strong) NSDate *creationDate; -@property NSUInteger version; -@property (nonatomic, strong) NSArray *tags; -@end diff --git a/KCD/HMScreenshotInformation.m b/KCD/HMScreenshotInformation.m deleted file mode 100644 index fba60c89..00000000 --- a/KCD/HMScreenshotInformation.m +++ /dev/null @@ -1,111 +0,0 @@ -// -// HMScreenshotInformation.m -// KCD -// -// Created by Hori,Masaki on 2014/11/09. -// Copyright (c) 2014å¹´ Hori,Masaki. All rights reserved. -// - -#import "HMScreenshotInformation.h" - -#import - - -static NSDateFormatter *formatter = nil; - -@interface HMScreenshotInformation () -@property (nonatomic, strong) NSURL *url; -@end - -@implementation HMScreenshotInformation -@synthesize creationDate = _creationDate; -@synthesize url = _url; - -+ (void)initialize -{ - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - formatter = [NSDateFormatter new]; - formatter.dateStyle = NSDateFormatterShortStyle; - formatter.timeStyle = NSDateFormatterShortStyle; - formatter.doesRelativeDateFormatting = YES; - }); -} -- (NSString *)imageUID -{ - return self.path; -} -- (NSString *)imageRepresentationType -{ - return IKImageBrowserQuickLookPathRepresentationType; -} -- (id)imageRepresentation -{ - return self.path; -} -- (NSString *)imageTitle -{ - return self.path.lastPathComponent.stringByDeletingPathExtension; -} -- (NSString *)imageSubtitle -{ - return [formatter stringFromDate:self.creationDate]; -} -- (NSUInteger)imageVersion -{ - return self.version; -} - -- (NSDate *)creationDate -{ - if(!_creationDate) { - NSFileManager *fm = [NSFileManager defaultManager]; - NSDictionary *fileAttr = [fm attributesOfItemAtPath:self.path error:NULL]; - _creationDate = [fileAttr fileCreationDate]; - } - return _creationDate; -} -- (void)setCreationDate:(NSDate *)creationDate -{ - _creationDate = creationDate; -} -- (NSURL *)url -{ - if(_url) return _url; - _url = [NSURL fileURLWithPath:self.path]; - return _url; -} - -- (NSArray *)tags -{ - NSError *error = nil; - NSArray *tags; - if(![self.url getResourceValue:&tags forKey:NSURLTagNamesKey error:&error]) { - if(error) { - NSLog(@"get tags error -> %@", error); - return @[]; - } - } - return tags; -} -- (void)setTags:(NSArray *)tags -{ - NSError *error = nil; - [self.url setResourceValue:tags forKey:NSURLTagNamesKey error:&error]; - if(error) { - NSLog(@"set tags error -> %@", error); - } -} - - -- (NSUInteger)hash -{ - return [self.path hash]; -} -- (BOOL)isEqual:(id)object -{ - return [self.path isEqual:object]; -} - - -@end diff --git a/KCD/HMScreenshotInformation.swift b/KCD/HMScreenshotInformation.swift new file mode 100644 index 00000000..bea2d35c --- /dev/null +++ b/KCD/HMScreenshotInformation.swift @@ -0,0 +1,80 @@ +// +// HMScreenshotInformation.swift +// KCD +// +// Created by Hori,Masaki on 2014/12/23. +// Copyright (c) 2014å¹´ Hori,Masaki. All rights reserved. +// + +import Cocoa +import Quartz + +var formatter: NSDateFormatter? + +class HMScreenshotInformation: NSObject +{ + override class func initialize() { + formatter = NSDateFormatter() + formatter?.dateStyle = .ShortStyle + formatter?.timeStyle = .ShortStyle + formatter?.doesRelativeDateFormatting = true + } + + var path: String? + var version: UInt = 0 + + var url: NSURL { + return NSURL.fileURLWithPath(path!)! + } + var creationDate: NSDate { + let fm = NSFileManager.defaultManager() + let fileAttr: NSDictionary = fm.attributesOfItemAtPath(path!, error: nil)! + return fileAttr.fileCreationDate()! + } + + var imageUID: String { + return path! + } + var imageRepresentationType: String = IKImageBrowserQuickLookPathRepresentationType + var imageRepresentation: AnyObject { + return path! + } + var imageTitle: String { + return path!.lastPathComponent.stringByDeletingPathExtension + } + var imageSubtitle: String { + return formatter!.stringFromDate(creationDate) + } + var imageVersion: UInt { + return version + } + + var tags: [String]? { + get { + var error: NSError? = nil + var resource: AnyObject? = nil + if !url.getResourceValue(&resource, forKey: NSURLTagNamesKey, error: &error) { + if error != nil { + println("get tags error -> \(error)") + } + return [] + } + + return resource as? [String] + } + set { + var error: NSError? = nil + url.setResourceValue(newValue, forKey: NSURLTagNamesKey, error: &error) + if error != nil { + println("set tags error -> \(error)") + } + } + } + + override var hash: Int { + return path!.hash + } + override func isEqual(object: AnyObject?) -> Bool { + return path!.isEqual(object) + } +} diff --git a/KCD/HMScreenshotListWindowController.m b/KCD/HMScreenshotListWindowController.m index 1b443976..263d40b7 100644 --- a/KCD/HMScreenshotListWindowController.m +++ b/KCD/HMScreenshotListWindowController.m @@ -7,7 +7,7 @@ // #import "HMScreenshotListWindowController.h" -#import "HMScreenshotInformation.h" +//#import "HMScreenshotInformation.h" #import "HMMaskSelectView.h" #import @@ -18,6 +18,9 @@ #import #import +#import "KCD-Swift.h" + + @interface NSFileManager (KCDExtension) - (NSString *)_web_pathWithUniqueFilenameForPath:(NSString *)path; @end -- 2.11.0