diff options
author | Damiano Galassi <[email protected]> | 2019-07-27 16:39:06 +0200 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2019-07-27 16:39:06 +0200 |
commit | 87d08603b7521dbdd16d7fbae92679b56f90ad83 (patch) | |
tree | 4a547da2a39bd518aebc8b2e542433e07904630b /macosx/HBQueueItem.m | |
parent | f82a8597f2800a5ca147679ad5660ef9fab5a85d (diff) |
MacGui: show statistics for completed jobs.
Diffstat (limited to 'macosx/HBQueueItem.m')
-rw-r--r-- | macosx/HBQueueItem.m | 90 |
1 files changed, 79 insertions, 11 deletions
diff --git a/macosx/HBQueueItem.m b/macosx/HBQueueItem.m index f3279790e..ff1893866 100644 --- a/macosx/HBQueueItem.m +++ b/macosx/HBQueueItem.m @@ -7,21 +7,52 @@ #import "HBQueueItem.h" #import "HBCodingUtilities.h" +#import "HBAttributedStringAdditions.h" + +static NSDateFormatter *_dateFormatter = nil; + +static NSDictionary *detailAttr; +static NSDictionary *detailBoldAttr; +static NSDictionary *shortHeightAttr; @interface HBQueueItem () @property (nonatomic, nullable) NSDate *pausedDate; @property (nonatomic, nullable) NSDate *resumedDate; +@property (nonatomic, readwrite, nullable) NSAttributedString *attributedStatistics; + @end @implementation HBQueueItem ++ (void)initialize +{ + if (self == [HBQueueItem class]) { + _dateFormatter = [[NSDateFormatter alloc] init]; + [_dateFormatter setDateStyle:NSDateFormatterLongStyle]; + [_dateFormatter setTimeStyle:NSDateFormatterLongStyle]; + + // Attributes + NSMutableParagraphStyle *ps = [NSParagraphStyle.defaultParagraphStyle mutableCopy]; + ps.headIndent = 88.0; + ps.paragraphSpacing = 1.0; + ps.tabStops = @[[[NSTextTab alloc] initWithType:NSRightTabStopType location:88], + [[NSTextTab alloc] initWithType:NSLeftTabStopType location:90]]; + + detailAttr = @{NSFontAttributeName: [NSFont systemFontOfSize:NSFont.smallSystemFontSize], + NSParagraphStyleAttributeName: ps}; + + detailBoldAttr = @{NSFontAttributeName: [NSFont systemFontOfSize:NSFont.smallSystemFontSize], + NSParagraphStyleAttributeName: ps}; + + shortHeightAttr = @{NSFontAttributeName: [NSFont systemFontOfSize:2.0]}; + } +} + @synthesize job = _job; -@synthesize attributedTitleDescription = _attributedTitleDescription; @synthesize attributedDescription = _attributedDescription; - @synthesize uuid = _uuid; - (instancetype)initWithJob:(HBJob *)job @@ -66,14 +97,6 @@ return _job.completeOutputURL; } -- (NSAttributedString *)attributedTitleDescription -{ - if (_attributedTitleDescription == nil) { - _attributedTitleDescription = _job.attributedTitleDescription; - } - return _attributedTitleDescription; -} - - (NSAttributedString *)attributedDescription { if (_attributedDescription == nil) { @@ -82,6 +105,45 @@ return _attributedDescription; } +- (NSAttributedString *)attributedStatistics +{ + if (self.endedDate == nil) + { + return nil; + } + + if (_attributedStatistics == nil) + { + NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] init]; + + [attrString appendString:@"\t" withAttributes:detailAttr]; + [attrString appendString:NSLocalizedString(@"Started at:", @"Job statistics") withAttributes:detailBoldAttr]; + [attrString appendString:@" \t" withAttributes:detailAttr]; + [attrString appendString:[_dateFormatter stringFromDate:self.startedDate] withAttributes:detailAttr]; + [attrString appendString:@"\n\t" withAttributes:detailAttr]; + [attrString appendString:NSLocalizedString(@"Ended at:", @"Job statistics") withAttributes:detailBoldAttr]; + [attrString appendString:@" \t" withAttributes:detailAttr]; + [attrString appendString:[_dateFormatter stringFromDate:self.endedDate] withAttributes:detailAttr]; + [attrString appendString:@"\n\n" withAttributes:shortHeightAttr]; + [attrString appendString:@"\t" withAttributes:detailAttr]; + + [attrString appendString:NSLocalizedString(@"Run time:", @"Job statistics") withAttributes:detailBoldAttr]; + [attrString appendString:@" \t" withAttributes:detailAttr]; + uint64_t encodeDuration = (uint64_t)self.encodeDuration; + [attrString appendString:[NSString stringWithFormat:@"%02lld:%02lld:%02lld", encodeDuration / 3600, (encodeDuration/ 60) % 60, encodeDuration % 60] withAttributes:detailAttr]; + [attrString appendString:@"\n\t" withAttributes:detailAttr]; + [attrString appendString:NSLocalizedString(@"Paused time:", @"Job statistics") withAttributes:detailBoldAttr]; + [attrString appendString:@" \t" withAttributes:detailAttr]; + uint64_t pauseDuration = (uint64_t)self.pauseDuration; + [attrString appendString:[NSString stringWithFormat:@"%02lld:%02lld:%02lld", pauseDuration / 3600, (pauseDuration/ 60) % 60, pauseDuration % 60] withAttributes:detailAttr]; + [attrString appendString:@"\n" withAttributes:detailAttr]; + + _attributedStatistics = attrString; + } + + return _attributedStatistics; +} + #pragma mark - Statistics - (void)resetStatistics @@ -92,6 +154,7 @@ self.endedDate = nil; self.encodeDuration = 0; self.pauseDuration = 0; + self.attributedStatistics = nil; } - (void)pausedAtDate:(NSDate *)date @@ -103,12 +166,17 @@ { self.resumedDate = date; self.pauseDuration += [self.resumedDate timeIntervalSinceDate:self.pausedDate]; + self.pausedDate = nil; } - (void)setEndedDate:(NSDate *)endedDate { _endedDate = endedDate; - self.encodeDuration = [self.startedDate timeIntervalSinceDate:self.endedDate]; + if (endedDate && self.pausedDate) + { + [self resumedAtDate:endedDate]; + } + self.encodeDuration = [self.endedDate timeIntervalSinceDate:self.startedDate]; self.encodeDuration -= self.pauseDuration; } |