From 63ad5d8a591cafd660e351d2c670a536b3d4222e Mon Sep 17 00:00:00 2001
From: Damiano Galassi <damiog@gmail.com>
Date: Sun, 28 Jul 2019 07:14:40 +0200
Subject: [PATCH] MacGui: add file size to the statistics. Fix selected text
 color when dark mode is enabled.

---
 .../Base.lproj/HBQueueInfoViewController.xib  | 22 ++++++-------
 .../Base.lproj/HBQueueTableViewController.xib | 20 ++++++++----
 macosx/HBJob+UIAdditions.m                    |  8 +++--
 macosx/HBQueueItem.h                          |  2 ++
 macosx/HBQueueItem.m                          | 31 ++++++++++++++++---
 5 files changed, 59 insertions(+), 24 deletions(-)

diff --git a/macosx/Base.lproj/HBQueueInfoViewController.xib b/macosx/Base.lproj/HBQueueInfoViewController.xib
index d1683793a..d90aea4e7 100644
--- a/macosx/Base.lproj/HBQueueInfoViewController.xib
+++ b/macosx/Base.lproj/HBQueueInfoViewController.xib
@@ -18,11 +18,11 @@
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <customView id="Hz6-mo-xeY">
-            <rect key="frame" x="0.0" y="0.0" width="480" height="335"/>
+            <rect key="frame" x="0.0" y="0.0" width="488" height="335"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
                 <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Z14-gh-hWn">
-                    <rect key="frame" x="402" y="13" width="64" height="32"/>
+                    <rect key="frame" x="410" y="13" width="64" height="32"/>
                     <buttonCell key="cell" type="push" title="Edit" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="erY-5X-50l">
                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                         <font key="font" metaFont="system"/>
@@ -32,7 +32,7 @@
                     </connections>
                 </button>
                 <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="oq4-g0-srt">
-                    <rect key="frame" x="330" y="13" width="75" height="32"/>
+                    <rect key="frame" x="338" y="13" width="75" height="32"/>
                     <buttonCell key="cell" type="push" title="Reset" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="hgl-N3-x4S">
                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                         <font key="font" metaFont="system"/>
@@ -42,16 +42,16 @@
                     </connections>
                 </button>
                 <scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="MXt-Cb-20x">
-                    <rect key="frame" x="0.0" y="49" width="480" height="286"/>
+                    <rect key="frame" x="0.0" y="49" width="488" height="286"/>
                     <clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="kkx-XF-sYr" customClass="HBFlippedClipView">
-                        <rect key="frame" x="0.0" y="0.0" width="480" height="286"/>
+                        <rect key="frame" x="0.0" y="0.0" width="488" height="286"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <view translatesAutoresizingMaskIntoConstraints="NO" id="Akt-r1-6fP">
-                                <rect key="frame" x="0.0" y="188" width="480" height="98"/>
+                                <rect key="frame" x="0.0" y="188" width="488" height="98"/>
                                 <subviews>
                                     <stackView distribution="fill" orientation="vertical" alignment="leading" spacing="4" horizontalStackHuggingPriority="250" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="VVC-g8-nGU">
-                                        <rect key="frame" x="8" y="8" width="464" height="82"/>
+                                        <rect key="frame" x="12" y="8" width="464" height="82"/>
                                         <subviews>
                                             <customView translatesAutoresizingMaskIntoConstraints="NO" id="m2h-yw-mRX" userLabel="Header">
                                                 <rect key="frame" x="0.0" y="64" width="464" height="18"/>
@@ -59,7 +59,7 @@
                                                     <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="OOz-qb-LU4">
                                                         <rect key="frame" x="-2" y="4" width="58" height="14"/>
                                                         <textFieldCell key="cell" lineBreakMode="clipping" title="Statistics" id="aCP-yp-iZy">
-                                                            <font key="font" metaFont="systemBold" size="11"/>
+                                                            <font key="font" metaFont="smallSystemBold"/>
                                                             <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
                                                             <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
                                                         </textFieldCell>
@@ -92,7 +92,7 @@
                                                     <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="8hj-1a-dlb">
                                                         <rect key="frame" x="-2" y="4" width="58" height="14"/>
                                                         <textFieldCell key="cell" lineBreakMode="clipping" title="Summary" id="cx1-rC-AMC">
-                                                            <font key="font" metaFont="systemBold" size="11"/>
+                                                            <font key="font" metaFont="smallSystemBold"/>
                                                             <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
                                                             <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
                                                         </textFieldCell>
@@ -137,8 +137,8 @@
                                 <constraints>
                                     <constraint firstItem="VVC-g8-nGU" firstAttribute="top" secondItem="Akt-r1-6fP" secondAttribute="top" constant="8" id="37f-us-42T"/>
                                     <constraint firstAttribute="bottom" secondItem="VVC-g8-nGU" secondAttribute="bottom" constant="8" id="7lz-sW-xUb"/>
-                                    <constraint firstItem="VVC-g8-nGU" firstAttribute="leading" secondItem="Akt-r1-6fP" secondAttribute="leading" constant="8" id="Ggq-bx-Bfy"/>
-                                    <constraint firstAttribute="trailing" secondItem="VVC-g8-nGU" secondAttribute="trailing" constant="8" id="xlB-d0-saX"/>
+                                    <constraint firstItem="VVC-g8-nGU" firstAttribute="leading" secondItem="Akt-r1-6fP" secondAttribute="leading" constant="12" id="Ggq-bx-Bfy"/>
+                                    <constraint firstAttribute="trailing" secondItem="VVC-g8-nGU" secondAttribute="trailing" constant="12" id="xlB-d0-saX"/>
                                 </constraints>
                             </view>
                         </subviews>
diff --git a/macosx/Base.lproj/HBQueueTableViewController.xib b/macosx/Base.lproj/HBQueueTableViewController.xib
index 1cf0c81f5..1f29c095e 100644
--- a/macosx/Base.lproj/HBQueueTableViewController.xib
+++ b/macosx/Base.lproj/HBQueueTableViewController.xib
@@ -49,7 +49,7 @@
                                                 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                                 <subviews>
                                                     <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ar9-Uk-6sM">
-                                                        <rect key="frame" x="21" y="35" width="494" height="17"/>
+                                                        <rect key="frame" x="23" y="35" width="492" height="17"/>
                                                         <constraints>
                                                             <constraint firstAttribute="height" relation="greaterThanOrEqual" constant="17" id="lzC-jf-dZI"/>
                                                         </constraints>
@@ -71,14 +71,18 @@
                                                         </buttonCell>
                                                     </button>
                                                     <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="7OO-Ut-UrC">
-                                                        <rect key="frame" x="3" y="37" width="14" height="14"/>
+                                                        <rect key="frame" x="3" y="35" width="16" height="16"/>
+                                                        <constraints>
+                                                            <constraint firstAttribute="height" constant="16" id="V3u-Yw-S0G"/>
+                                                            <constraint firstAttribute="width" constant="16" id="dDq-xC-fYL"/>
+                                                        </constraints>
                                                         <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="NSActionTemplate" id="bqz-sk-X31"/>
                                                     </imageView>
                                                     <progressIndicator wantsLayer="YES" maxValue="1" style="bar" translatesAutoresizingMaskIntoConstraints="NO" id="xAK-4F-cCr">
-                                                        <rect key="frame" x="23" y="13" width="490" height="23"/>
+                                                        <rect key="frame" x="25" y="13" width="488" height="23"/>
                                                     </progressIndicator>
                                                     <textField verticalHuggingPriority="750" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fxw-eD-SmJ">
-                                                        <rect key="frame" x="21" y="3" width="494" height="14"/>
+                                                        <rect key="frame" x="23" y="3" width="492" height="14"/>
                                                         <textFieldCell key="cell" lineBreakMode="truncatingTail" enabled="NO" allowsUndo="NO" sendsActionOnEndEditing="YES" title="Encoding status" usesSingleLineMode="YES" id="eEU-Dr-Qh8">
                                                             <font key="font" metaFont="smallSystem"/>
                                                             <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@@ -115,7 +119,7 @@
                                                 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                                 <subviews>
                                                     <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ns0-GA-WCh">
-                                                        <rect key="frame" x="21" y="3" width="494" height="17"/>
+                                                        <rect key="frame" x="23" y="3" width="492" height="17"/>
                                                         <constraints>
                                                             <constraint firstAttribute="height" relation="greaterThanOrEqual" constant="17" id="5Tc-Oy-HWg"/>
                                                         </constraints>
@@ -137,7 +141,11 @@
                                                         </buttonCell>
                                                     </button>
                                                     <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="kNw-fy-iYB">
-                                                        <rect key="frame" x="3" y="5" width="14" height="14"/>
+                                                        <rect key="frame" x="3" y="3" width="16" height="16"/>
+                                                        <constraints>
+                                                            <constraint firstAttribute="width" constant="16" id="Sg7-eg-u2l"/>
+                                                            <constraint firstAttribute="height" constant="16" id="udI-Cr-8CG"/>
+                                                        </constraints>
                                                         <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="NSActionTemplate" id="ofG-k5-PfV"/>
                                                     </imageView>
                                                 </subviews>
diff --git a/macosx/HBJob+UIAdditions.m b/macosx/HBJob+UIAdditions.m
index 7bc90090b..061d5fb6c 100644
--- a/macosx/HBJob+UIAdditions.m
+++ b/macosx/HBJob+UIAdditions.m
@@ -104,12 +104,14 @@ static NSDictionary            *shortHeightAttr;
                         [[NSTextTab alloc] initWithType:NSLeftTabStopType location:90]];
 
         detailAttr = @{NSFontAttributeName: [NSFont systemFontOfSize:NSFont.smallSystemFontSize],
-                       NSParagraphStyleAttributeName: ps};
+                       NSParagraphStyleAttributeName: ps,
+                       NSForegroundColorAttributeName: NSColor.labelColor};
 
         detailBoldAttr = @{NSFontAttributeName: [NSFont systemFontOfSize:NSFont.smallSystemFontSize],
-                           NSParagraphStyleAttributeName: ps};
+                           NSParagraphStyleAttributeName: ps,
+                           NSForegroundColorAttributeName: NSColor.labelColor};
 
-        shortHeightAttr = @{NSFontAttributeName: [NSFont systemFontOfSize:8.0]};
+        shortHeightAttr = @{NSFontAttributeName: [NSFont systemFontOfSize:6.0]};
     }
 }
 
diff --git a/macosx/HBQueueItem.h b/macosx/HBQueueItem.h
index 54a4f82a9..ddcf1b6a5 100644
--- a/macosx/HBQueueItem.h
+++ b/macosx/HBQueueItem.h
@@ -53,6 +53,8 @@ typedef NS_ENUM(NSUInteger, HBQueueItemState) {
 - (void)pausedAtDate:(NSDate *)date;
 - (void)resumedAtDate:(NSDate *)date;
 
+@property (nonatomic, readonly) NSUInteger fileSize;
+
 @property (nonatomic, readonly) NSAttributedString *attributedDescription;
 
 @property (nonatomic, readonly, nullable) NSAttributedString *attributedStatistics;
diff --git a/macosx/HBQueueItem.m b/macosx/HBQueueItem.m
index ff1893866..a655409c5 100644
--- a/macosx/HBQueueItem.m
+++ b/macosx/HBQueueItem.m
@@ -10,6 +10,7 @@
 #import "HBAttributedStringAdditions.h"
 
 static NSDateFormatter *_dateFormatter = nil;
+static NSByteCountFormatter *_byteFormatter = nil;
 
 static NSDictionary     *detailAttr;
 static NSDictionary     *detailBoldAttr;
@@ -20,6 +21,8 @@ static NSDictionary     *shortHeightAttr;
 @property (nonatomic, nullable) NSDate *pausedDate;
 @property (nonatomic, nullable) NSDate *resumedDate;
 
+@property (nonatomic) NSUInteger fileSize;
+
 @property (nonatomic, readwrite, nullable) NSAttributedString *attributedStatistics;
 
 @end
@@ -33,6 +36,8 @@ static NSDictionary     *shortHeightAttr;
         [_dateFormatter setDateStyle:NSDateFormatterLongStyle];
         [_dateFormatter setTimeStyle:NSDateFormatterLongStyle];
 
+        _byteFormatter = [[NSByteCountFormatter alloc] init];
+
         // Attributes
         NSMutableParagraphStyle *ps = [NSParagraphStyle.defaultParagraphStyle mutableCopy];
         ps.headIndent = 88.0;
@@ -41,12 +46,14 @@ static NSDictionary     *shortHeightAttr;
                         [[NSTextTab alloc] initWithType:NSLeftTabStopType location:90]];
 
         detailAttr = @{NSFontAttributeName: [NSFont systemFontOfSize:NSFont.smallSystemFontSize],
-                       NSParagraphStyleAttributeName: ps};
+                       NSParagraphStyleAttributeName: ps,
+                       NSForegroundColorAttributeName: NSColor.labelColor};
 
         detailBoldAttr = @{NSFontAttributeName: [NSFont systemFontOfSize:NSFont.smallSystemFontSize],
-                           NSParagraphStyleAttributeName: ps};
+                           NSParagraphStyleAttributeName: ps,
+                           NSForegroundColorAttributeName: NSColor.labelColor};
 
-        shortHeightAttr = @{NSFontAttributeName: [NSFont systemFontOfSize:2.0]};
+        shortHeightAttr = @{NSFontAttributeName: [NSFont systemFontOfSize:6.0]};
     }
 }
 
@@ -136,7 +143,13 @@ static NSDictionary     *shortHeightAttr;
         [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];
+
+        [attrString appendString:@"\n\n" withAttributes:shortHeightAttr];
+        [attrString appendString:@"\t" withAttributes:detailAttr];
+
+        [attrString appendString:NSLocalizedString(@"Size:", @"Job statistics") withAttributes:detailBoldAttr];
+        [attrString appendString:@" \t" withAttributes:detailAttr];
+        [attrString appendString:[_byteFormatter stringFromByteCount:self.fileSize] withAttributes:detailAttr];
 
         _attributedStatistics = attrString;
     }
@@ -154,6 +167,7 @@ static NSDictionary     *shortHeightAttr;
     self.endedDate = nil;
     self.encodeDuration = 0;
     self.pauseDuration = 0;
+    self.fileSize = 0;
     self.attributedStatistics = nil;
 }
 
@@ -178,6 +192,11 @@ static NSDictionary     *shortHeightAttr;
     }
     self.encodeDuration = [self.endedDate timeIntervalSinceDate:self.startedDate];
     self.encodeDuration -= self.pauseDuration;
+
+    [self.completeOutputURL removeCachedResourceValueForKey:NSURLFileSizeKey];
+    NSDictionary<NSURLResourceKey, id> *values = [self.completeOutputURL resourceValuesForKeys:@[NSURLFileSizeKey] error:NULL];
+
+    self.fileSize = [values[NSURLFileSizeKey] integerValue];
 }
 
 #pragma mark - NSSecureCoding
@@ -201,6 +220,8 @@ static NSString *versionKey = @"HBQueueItemVersion";
 
     encodeObject(_startedDate);
     encodeObject(_endedDate);
+
+    encodeInteger(_fileSize);
 }
 
 - (nullable instancetype)initWithCoder:(nonnull NSCoder *)decoder
@@ -219,6 +240,8 @@ static NSString *versionKey = @"HBQueueItemVersion";
         decodeObject(_startedDate, NSDate);
         decodeObject(_endedDate, NSDate);
 
+        decodeInteger(_fileSize);
+
         return self;
     }
 fail:
-- 
2.40.0