From cd83b1dec32bd807f032fbe33528837051778b4f Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Mon, 15 Aug 2011 03:12:14 +0200 Subject: [PATCH] Refactor QTTime shortening --- Medianno.xcodeproj/project.pbxproj | 6 +++ Medianno/MAAnno.h | 3 -- Medianno/MAAnno.mm | 38 ---------------- Medianno/MAShortenQTTime.h | 13 ++++++ Medianno/MAShortenQTTime.mm | 50 ++++++++++++++++++++++ Medianno/en.lproj/MADocument.xib | 69 +++++++++++++++++------------- 6 files changed, 108 insertions(+), 71 deletions(-) create mode 100644 Medianno/MAShortenQTTime.h create mode 100644 Medianno/MAShortenQTTime.mm diff --git a/Medianno.xcodeproj/project.pbxproj b/Medianno.xcodeproj/project.pbxproj index b0a6a75..93b33a6 100644 --- a/Medianno.xcodeproj/project.pbxproj +++ b/Medianno.xcodeproj/project.pbxproj @@ -29,6 +29,7 @@ 95B3748713F87B17009BB79A /* MATokenFieldCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = 95B3748613F87B17009BB79A /* MATokenFieldCell.mm */; }; 95BCFA2113F76A04000F650F /* app.icns in Resources */ = {isa = PBXBuildFile; fileRef = 95BCFA1F13F76A04000F650F /* app.icns */; }; 95BCFA2213F76A04000F650F /* doc.icns in Resources */ = {isa = PBXBuildFile; fileRef = 95BCFA2013F76A04000F650F /* doc.icns */; }; + 95BCFA2E13F8A3AD000F650F /* MAShortenQTTime.mm in Sources */ = {isa = PBXBuildFile; fileRef = 95BCFA2D13F8A3AD000F650F /* MAShortenQTTime.mm */; }; 95C534E013F732A200A07932 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 95C534DE13F732A200A07932 /* Localizable.strings */; }; /* End PBXBuildFile section */ @@ -68,6 +69,8 @@ 95B3748613F87B17009BB79A /* MATokenFieldCell.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MATokenFieldCell.mm; sourceTree = ""; }; 95BCFA1F13F76A04000F650F /* app.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = app.icns; path = Resources/app.icns; sourceTree = ""; }; 95BCFA2013F76A04000F650F /* doc.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = doc.icns; path = Resources/doc.icns; sourceTree = ""; }; + 95BCFA2C13F8A3AD000F650F /* MAShortenQTTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MAShortenQTTime.h; sourceTree = ""; }; + 95BCFA2D13F8A3AD000F650F /* MAShortenQTTime.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MAShortenQTTime.mm; sourceTree = ""; }; 95C534DF13F732A200A07932 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; /* End PBXFileReference section */ @@ -180,6 +183,8 @@ 950BB78513F2D95500D8E669 /* MADocWindow.mm */, 95B3748513F87B17009BB79A /* MATokenFieldCell.h */, 95B3748613F87B17009BB79A /* MATokenFieldCell.mm */, + 95BCFA2C13F8A3AD000F650F /* MAShortenQTTime.h */, + 95BCFA2D13F8A3AD000F650F /* MAShortenQTTime.mm */, ); name = Classes; sourceTree = ""; @@ -264,6 +269,7 @@ 950BB7AA13F46BAF00D8E669 /* MAAddMediaSheet.mm in Sources */, 950BB7AD13F46ECF00D8E669 /* MAAppController.mm in Sources */, 95B3748713F87B17009BB79A /* MATokenFieldCell.mm in Sources */, + 95BCFA2E13F8A3AD000F650F /* MAShortenQTTime.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Medianno/MAAnno.h b/Medianno/MAAnno.h index 59430d3..833ee34 100644 --- a/Medianno/MAAnno.h +++ b/Medianno/MAAnno.h @@ -20,10 +20,7 @@ @property (nonatomic, retain) NSSet *tags; @property (nonatomic, retain) NSManagedObject *media; -- (NSString *)shortLocation; -+ (NSSet *)keyPathsForValuesAffectingShortLocation; - (QTTime)qtLocation; -+ (NSSet *)keyPathsForValuesAffectingQtLocation; /* * Tags are never manipulated through the tag objects, but always through diff --git a/Medianno/MAAnno.mm b/Medianno/MAAnno.mm index 3ed957c..a5f7a7a 100644 --- a/Medianno/MAAnno.mm +++ b/Medianno/MAAnno.mm @@ -18,49 +18,11 @@ @dynamic tags; @dynamic media; -- (NSString *)shortLocation -{ - NSString * location = self.location; - NSRange rangeToUse = {0,0}; - // - // Trim leading zeros, up to a point - // - while (rangeToUse.location < 6) { - switch ([location characterAtIndex:rangeToUse.location]) { - case '0': - case ':': - ++rangeToUse.location; - continue; - } - break; - } - // - // Trim fractions of seconds - // - for (rangeToUse.length = [location length]-rangeToUse.location; rangeToUse.length-- > 0; ) - if ([location characterAtIndex:rangeToUse.location+rangeToUse.length] == '.') - break; - if (!rangeToUse.length) - rangeToUse.length = [location length]-rangeToUse.location; - - return [location substringWithRange:rangeToUse]; -} - -+ (NSSet *)keyPathsForValuesAffectingShortLocation -{ - return [NSSet setWithObject:@"location"]; -} - - (QTTime)qtLocation { return QTTimeFromString(self.location); } -+ (NSSet *)keyPathsForValuesAffectingQtLocation -{ - return [NSSet setWithObject:@"location"]; -} - - (NSArray *)tagDescriptions { NSSet * tags = self.tags; diff --git a/Medianno/MAShortenQTTime.h b/Medianno/MAShortenQTTime.h new file mode 100644 index 0000000..a03b52c --- /dev/null +++ b/Medianno/MAShortenQTTime.h @@ -0,0 +1,13 @@ +// +// MAShortenQTTime.h +// Medianno +// +// Created by Matthias Neeracher on 8/15/11. +// Copyright 2011 Matthias Neeracher. All rights reserved. +// + +#import + +@interface MAShortenQTTime : NSValueTransformer + +@end diff --git a/Medianno/MAShortenQTTime.mm b/Medianno/MAShortenQTTime.mm new file mode 100644 index 0000000..6349626 --- /dev/null +++ b/Medianno/MAShortenQTTime.mm @@ -0,0 +1,50 @@ +// +// MAShortenQTTime.mm +// Medianno +// +// Created by Matthias Neeracher on 8/15/11. +// Copyright 2011 Matthias Neeracher. All rights reserved. +// + +#import "MAShortenQTTime.h" + +@implementation MAShortenQTTime + ++ (Class)transformedValueClass +{ + return [NSString class]; +} + ++ (BOOL)allowsReverseTransformation +{ + return NO; +} + +- (id)transformedValue:(id)value { + NSString * fullTime = value; + NSRange rangeToUse = {0,0}; + // + // Trim leading zeros, up to a point + // + while (rangeToUse.location < 6) { + switch ([fullTime characterAtIndex:rangeToUse.location]) { + case '0': + case ':': + ++rangeToUse.location; + continue; + } + break; + } + // + // Trim fractions of seconds + // + for (rangeToUse.length = [fullTime length]-rangeToUse.location; rangeToUse.length-- > 0; ) + if ([fullTime characterAtIndex:rangeToUse.location+rangeToUse.length] == '.') + break; + if (!rangeToUse.length) + rangeToUse.length = [fullTime length]-rangeToUse.location; + + return [fullTime substringWithRange:rangeToUse]; +} + +@end diff --git a/Medianno/en.lproj/MADocument.xib b/Medianno/en.lproj/MADocument.xib index 3bc7503..79a1f8d 100644 --- a/Medianno/en.lproj/MADocument.xib +++ b/Medianno/en.lproj/MADocument.xib @@ -924,35 +924,6 @@ 100156 - - - value: arrangedObjects.shortLocation - - - - - - value: arrangedObjects.shortLocation - value - arrangedObjects.shortLocation - - YES - - YES - NSConditionallySetsEditable - NSCreatesSortDescriptor - - - YES - - - - - 2 - - - 100158 - value: arrangedObjects.notes @@ -1085,6 +1056,37 @@ 100181 + + + value: arrangedObjects.location + + + + + + value: arrangedObjects.location + value + arrangedObjects.location + + YES + + YES + NSConditionallySetsEditable + NSCreatesSortDescriptor + NSValueTransformerName + + + YES + + + MAShortenQTTime + + + 2 + + + 100183 + @@ -1476,7 +1478,7 @@ - 100181 + 100183 @@ -1490,6 +1492,7 @@ YES addAnnotation: addMediaFiles: + exportMedia: mediaSkipBackward: mediaSkipForward: toggleMediaPlay: @@ -1501,6 +1504,7 @@ id id id + id @@ -1509,6 +1513,7 @@ YES addAnnotation: addMediaFiles: + exportMedia: mediaSkipBackward: mediaSkipForward: toggleMediaPlay: @@ -1523,6 +1528,10 @@ addMediaFiles: id + + exportMedia: + id + mediaSkipBackward: id