Refactor QTTime shortening

This commit is contained in:
Matthias Neeracher 2011-08-15 03:12:14 +02:00
parent 61cb6c09e2
commit cd83b1dec3
6 changed files with 108 additions and 71 deletions

View File

@ -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 = "<group>"; };
95BCFA1F13F76A04000F650F /* app.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = app.icns; path = Resources/app.icns; sourceTree = "<group>"; };
95BCFA2013F76A04000F650F /* doc.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = doc.icns; path = Resources/doc.icns; sourceTree = "<group>"; };
95BCFA2C13F8A3AD000F650F /* MAShortenQTTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MAShortenQTTime.h; sourceTree = "<group>"; };
95BCFA2D13F8A3AD000F650F /* MAShortenQTTime.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MAShortenQTTime.mm; sourceTree = "<group>"; };
95C534DF13F732A200A07932 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
/* 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 = "<group>";
@ -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;
};

View File

@ -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

View File

@ -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;

View File

@ -0,0 +1,13 @@
//
// MAShortenQTTime.h
// Medianno
//
// Created by Matthias Neeracher on 8/15/11.
// Copyright 2011 Matthias Neeracher. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface MAShortenQTTime : NSValueTransformer
@end

View File

@ -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

View File

@ -924,35 +924,6 @@
</object>
<int key="connectionID">100156</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">value: arrangedObjects.shortLocation</string>
<reference key="source" ref="971688616"/>
<reference key="destination" ref="603895450"/>
<object class="NSNibBindingConnector" key="connector">
<reference key="NSSource" ref="971688616"/>
<reference key="NSDestination" ref="603895450"/>
<string key="NSLabel">value: arrangedObjects.shortLocation</string>
<string key="NSBinding">value</string>
<string key="NSKeyPath">arrangedObjects.shortLocation</string>
<object class="NSDictionary" key="NSOptions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSConditionallySetsEditable</string>
<string>NSCreatesSortDescriptor</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<boolean value="YES"/>
<boolean value="NO"/>
</object>
</object>
<int key="NSNibBindingConnectorVersion">2</int>
</object>
</object>
<int key="connectionID">100158</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">value: arrangedObjects.notes</string>
@ -1085,6 +1056,37 @@
</object>
<int key="connectionID">100181</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">value: arrangedObjects.location</string>
<reference key="source" ref="971688616"/>
<reference key="destination" ref="603895450"/>
<object class="NSNibBindingConnector" key="connector">
<reference key="NSSource" ref="971688616"/>
<reference key="NSDestination" ref="603895450"/>
<string key="NSLabel">value: arrangedObjects.location</string>
<string key="NSBinding">value</string>
<string key="NSKeyPath">arrangedObjects.location</string>
<object class="NSDictionary" key="NSOptions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSConditionallySetsEditable</string>
<string>NSCreatesSortDescriptor</string>
<string>NSValueTransformerName</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<boolean value="YES"/>
<boolean value="NO"/>
<string>MAShortenQTTime</string>
</object>
</object>
<int key="NSNibBindingConnectorVersion">2</int>
</object>
</object>
<int key="connectionID">100183</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@ -1476,7 +1478,7 @@
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
<int key="maxID">100181</int>
<int key="maxID">100183</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@ -1490,6 +1492,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<string>addAnnotation:</string>
<string>addMediaFiles:</string>
<string>exportMedia:</string>
<string>mediaSkipBackward:</string>
<string>mediaSkipForward:</string>
<string>toggleMediaPlay:</string>
@ -1501,6 +1504,7 @@
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
@ -1509,6 +1513,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<string>addAnnotation:</string>
<string>addMediaFiles:</string>
<string>exportMedia:</string>
<string>mediaSkipBackward:</string>
<string>mediaSkipForward:</string>
<string>toggleMediaPlay:</string>
@ -1523,6 +1528,10 @@
<string key="name">addMediaFiles:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">exportMedia:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">mediaSkipBackward:</string>
<string key="candidateClassName">id</string>