summaryrefslogtreecommitdiffstats
path: root/macosx/HBRange.m
diff options
context:
space:
mode:
authorritsuka <[email protected]>2014-12-23 10:23:59 +0000
committerritsuka <[email protected]>2014-12-23 10:23:59 +0000
commita66b692e29674de9c444fd54f0493d03b4900abc (patch)
tree1356eec981d0542ad6ca9087794e7cc52a09c664 /macosx/HBRange.m
parentee10e1fdb417c7f1047406522379c85c47143bfd (diff)
MacGui: move the UI helper methods to new categories. Implement NSCoding in more classes.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6643 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBRange.m')
-rw-r--r--macosx/HBRange.m90
1 files changed, 90 insertions, 0 deletions
diff --git a/macosx/HBRange.m b/macosx/HBRange.m
index be39652ef..731fcebf7 100644
--- a/macosx/HBRange.m
+++ b/macosx/HBRange.m
@@ -5,20 +5,110 @@
It may be used under the terms of the GNU General Public License. */
#import "HBRange.h"
+#import "HBTitle.h"
#import "NSCodingMacro.h"
@implementation HBRange
#pragma mark - NSCoding
+- (instancetype)initWithTitle:(HBTitle *)title
+{
+ self = [super init];
+ if (self)
+ {
+ _title = title;
+
+ _chapterStart = 0;
+ _chapterStop = (int)title.chapters.count - 1;
+
+ _secondsStart = 0;
+ _secondsStop = title.duration;
+
+ _frameStart = 0;
+ _frameStop = title.frames;
+ }
+ return self;
+}
+
+- (NSString *)duration
+{
+ if (self.type == HBRangeTypeChapters)
+ {
+ hb_title_t *title = self.title.hb_title;
+ hb_chapter_t *chapter;
+ int64_t duration = 0;
+
+ for (int i = self.chapterStart; i <= self.chapterStop; i++ )
+ {
+ chapter = (hb_chapter_t *) hb_list_item(title->list_chapter, i);
+ duration += chapter->duration;
+ }
+
+ duration /= 90000; // pts -> seconds
+ return [NSString stringWithFormat: @"%02lld:%02lld:%02lld", duration / 3600, ( duration / 60 ) % 60, duration % 60];
+ }
+ else if (self.type == HBRangeTypeSeconds)
+ {
+ int duration = self.secondsStop - self.secondsStart;
+ return [NSString stringWithFormat:@"%02d:%02d:%02d", duration / 3600, (duration / 60) % 60, duration % 60];
+
+ }
+ else if (self.type == HBRangeTypeFrames)
+ {
+ hb_title_t *title = self.title.hb_title;
+ int duration = (self.frameStop - self.frameStart) / (title->vrate.num / title->vrate.den);
+ return [NSString stringWithFormat: @"%02d:%02d:%02d", duration / 3600, ( duration / 60 ) % 60, duration % 60];
+ }
+
+ return @"00:00:00";
+}
+
++ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key
+{
+ NSSet *retval = nil;
+
+ if ([key isEqualToString:@"duration"])
+ {
+ retval = [NSSet setWithObjects:@"type", @"chapterStart", @"chapterStop", @"frameStart", @"frameStop",
+ @"secondsStart", @"secondsStop",nil];
+ }
+
+ return retval;
+}
+
+#pragma mark - NSCoding
+
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeInt:1 forKey:@"HBRangeVersion"];
+
+ encodeInt(_type);
+
+ encodeInt(_chapterStart);
+ encodeInt(_chapterStop);
+
+ encodeInt(_secondsStart);
+ encodeInt(_secondsStop);
+
+ encodeInt(_frameStart);
+ encodeInt(_frameStop);
}
- (id)initWithCoder:(NSCoder *)decoder
{
self = [super init];
+
+ decodeInt(_type);
+
+ decodeInt(_chapterStart);
+ decodeInt(_chapterStop);
+
+ decodeInt(_secondsStart);
+ decodeInt(_secondsStop);
+
+ decodeInt(_frameStart);
+ decodeInt(_frameStop);
return self;
}