]> granicus.if.org Git - handbrake/commitdiff
MacGui: refactor HBStateFormatter.
authorDamiano Galassi <damiog@gmail.com>
Thu, 13 Dec 2018 12:24:29 +0000 (13:24 +0100)
committerDamiano Galassi <damiog@gmail.com>
Thu, 13 Dec 2018 12:24:29 +0000 (13:24 +0100)
macosx/HBStateFormatter+Private.m [deleted file]
macosx/HBStateFormatter.h
macosx/HBStateFormatter.m
macosx/HandBrake.xcodeproj/project.pbxproj

diff --git a/macosx/HBStateFormatter+Private.m b/macosx/HBStateFormatter+Private.m
deleted file mode 100644 (file)
index f00b4fb..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-//
-//  HBStateFormatter+Private.m
-//  HandBrake
-//
-//  Created by Damiano Galassi on 24/02/16.
-//
-//
-
-#import "HBStateFormatter+Private.h"
-#import "HBLocalizationUtilities.h"
-
-@implementation HBStateFormatter (Private)
-
-- (NSString *)stateToString:(hb_state_t)s
-{
-    NSMutableString *string = [NSMutableString string];
-
-    switch (s.state)
-    {
-#define p s.param.working
-
-        case HB_STATE_SEARCHING:
-        {
-            [string appendFormat:
-             HBKitLocalizedString(@"Searching for start point:  %.2f %%", @"HBStateFormatter -> search pass display name"),
-             100.0 * p.progress];
-
-            if (p.seconds > -1)
-            {
-                [string appendFormat:HBKitLocalizedString(@" (ETA %02dh%02dm%02ds)", @"HBStateFormatter -> search time format"), p.hours, p.minutes, p.seconds];
-            }
-
-            break;
-        }
-
-        case HB_STATE_WORKING:
-        {
-            [string appendFormat:HBKitLocalizedString(@"Encoding %@ ", @"HBStateFormatter -> work pass display name"), self.title];
-
-            if (self.twoLines)
-            {
-                [string appendString:@"\n"];
-            }
-
-            if (self.showPassNumber && p.pass_count > -1)
-            {
-                if (p.pass_id == HB_PASS_SUBTITLE)
-                {
-                    [string appendFormat:
-                     HBKitLocalizedString(@"Pass %d %@ of %d, %.2f %%", @"HBStateFormatter -> work pass number format"),
-                     p.pass,
-                     HBKitLocalizedString(@"(subtitle scan)", @"HBStateFormatter -> work pass type format"),
-                     p.pass_count, 100.0 * p.progress];
-                }
-                else
-                {
-                    [string appendFormat:
-                     HBKitLocalizedString(@"Pass %d of %d, %.2f %%", @"HBStateFormatter -> work pass number format"),
-                     p.pass, p.pass_count, 100.0 * p.progress];
-                }
-            }
-
-            if (p.seconds > -1)
-            {
-                if (p.rate_cur > 0.0)
-                {
-                    [string appendFormat:
-                     HBKitLocalizedString(@" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)", @"HBStateFormatter -> work time format"),
-                     p.rate_cur, p.rate_avg, p.hours, p.minutes, p.seconds];
-                }
-                else
-                {
-                    [string appendFormat:
-                     HBKitLocalizedString(@" (ETA %02dh%02dm%02ds)", @"HBStateFormatter -> work time format"),
-                     p.hours, p.minutes, p.seconds];
-                }
-            }
-
-            break;
-        }
-#undef p
-
-        case HB_STATE_MUXING:
-        {
-            [string appendString:HBKitLocalizedString(@"Muxing…", @"HBStateFormatter -> pass display name")];
-            break;
-        }
-
-        case HB_STATE_PAUSED:
-        {
-            [string appendString:HBKitLocalizedString(@"Paused", @"HBStateFormatter -> pass display name")];
-            break;
-        }
-
-        case HB_STATE_SCANNING:
-        {
-#define p s.param.scanning
-            if (p.preview_cur)
-            {
-                [string appendFormat:
-                 HBKitLocalizedString(@"Scanning title %d of %d, preview %d…", @"HBStateFormatter -> scan pass format"),
-                 p.title_cur, p.title_count,
-                 p.preview_cur];
-            }
-            else
-            {
-                [string appendFormat:
-                 HBKitLocalizedString(@"Scanning title %d of %d…", @"HBStateFormatter -> scan pass format"),
-                 p.title_cur, p.title_count];
-            }
-#undef p
-            break;
-        }
-
-        default:
-            break;
-    }
-
-    return string;
-}
-
-- (float)stateToPercentComplete:(hb_state_t)s
-{
-    float progress = 0;
-
-    switch (s.state)
-    {
-        case HB_STATE_SEARCHING:
-        case HB_STATE_WORKING:
-        case HB_STATE_PAUSED:
-#define p s.param.working
-            progress = (p.progress + p.pass - 1) / p.pass_count;
-#undef p
-
-            break;
-
-        case HB_STATE_SCANNING:
-#define p s.param.scanning
-            progress = p.progress;
-#undef p
-            break;
-
-        case HB_STATE_MUXING:
-            progress = 1;
-            break;
-
-        default:
-            break;
-    }
-
-    if (progress < 0)
-    {
-        progress = 0;
-    }
-    else if (progress > 1)
-    {
-        progress = 1;
-    }
-
-    return progress;
-}
-
-@end
index 49c3599e2986c8b08be26723c03af837032a9e27..665853feac8dc667f4ce99b1d2a3eb0db8a3c05b 100644 (file)
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
  *  The title to show in the output info.
  */
-@property (nonatomic, readwrite, copy) NSString *title;
+@property (nonatomic, readwrite, copy, nullable) NSString *title;
 
 /**
  *  Break the output string in two lines.
index 5dadd821d0ed307eca67b8dc2b274a8d123e701a..9d39d29b21d6d7e5cfef87b87498c93f79c02242 100644 (file)
@@ -5,6 +5,8 @@
  It may be used under the terms of the GNU General Public License. */
 
 #import "HBStateFormatter.h"
+#import "HBLocalizationUtilities.h"
+#include "hb.h"
 
 @implementation HBStateFormatter
 
     return self;
 }
 
+- (NSString *)stateToString:(hb_state_t)s
+{
+    NSMutableString *string = [NSMutableString string];
+
+    switch (s.state)
+    {
+#define p s.param.working
+
+        case HB_STATE_SEARCHING:
+        {
+            [string appendFormat:
+             HBKitLocalizedString(@"Searching for start point:  %.2f %%", @"HBStateFormatter -> search pass display name"),
+             100.0 * p.progress];
+
+            if (p.seconds > -1)
+            {
+                [string appendFormat:HBKitLocalizedString(@" (ETA %02dh%02dm%02ds)", @"HBStateFormatter -> search time format"), p.hours, p.minutes, p.seconds];
+            }
+
+            break;
+        }
+
+        case HB_STATE_WORKING:
+        {
+            if (_title)
+            {
+                [string appendFormat:HBKitLocalizedString(@"Encoding %@ ", @"HBStateFormatter -> work pass display name"), _title];
+                if (_twoLines)
+                {
+                    [string appendString:@"\n"];
+                }
+            }
+
+            if (_showPassNumber && p.pass_count > -1)
+            {
+                if (p.pass_id == HB_PASS_SUBTITLE)
+                {
+                    [string appendFormat:
+                     HBKitLocalizedString(@"Pass %d %@ of %d, %.2f %%", @"HBStateFormatter -> work pass number format"),
+                     p.pass,
+                     HBKitLocalizedString(@"(subtitle scan)", @"HBStateFormatter -> work pass type format"),
+                     p.pass_count, 100.0 * p.progress];
+                }
+                else
+                {
+                    [string appendFormat:
+                     HBKitLocalizedString(@"Pass %d of %d, %.2f %%", @"HBStateFormatter -> work pass number format"),
+                     p.pass, p.pass_count, 100.0 * p.progress];
+                }
+            }
+
+            if (p.seconds > -1)
+            {
+                if (p.rate_cur > 0.0)
+                {
+                    [string appendFormat:
+                     HBKitLocalizedString(@" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)", @"HBStateFormatter -> work time format"),
+                     p.rate_cur, p.rate_avg, p.hours, p.minutes, p.seconds];
+                }
+                else
+                {
+                    [string appendFormat:
+                     HBKitLocalizedString(@" (ETA %02dh%02dm%02ds)", @"HBStateFormatter -> work time format"),
+                     p.hours, p.minutes, p.seconds];
+                }
+            }
+
+            break;
+        }
+#undef p
+
+        case HB_STATE_MUXING:
+        {
+            [string appendString:HBKitLocalizedString(@"Muxing…", @"HBStateFormatter -> pass display name")];
+            break;
+        }
+
+        case HB_STATE_PAUSED:
+        {
+            [string appendString:HBKitLocalizedString(@"Paused", @"HBStateFormatter -> pass display name")];
+            break;
+        }
+
+        case HB_STATE_SCANNING:
+        {
+#define p s.param.scanning
+            if (p.preview_cur)
+            {
+                [string appendFormat:
+                 HBKitLocalizedString(@"Scanning title %d of %d, preview %d…", @"HBStateFormatter -> scan pass format"),
+                 p.title_cur, p.title_count,
+                 p.preview_cur];
+            }
+            else
+            {
+                [string appendFormat:
+                 HBKitLocalizedString(@"Scanning title %d of %d…", @"HBStateFormatter -> scan pass format"),
+                 p.title_cur, p.title_count];
+            }
+#undef p
+            break;
+        }
+
+        default:
+            break;
+    }
+
+    return string;
+}
+
+- (float)stateToPercentComplete:(hb_state_t)s
+{
+    float progress = 0;
+
+    switch (s.state)
+    {
+        case HB_STATE_SEARCHING:
+        case HB_STATE_WORKING:
+        case HB_STATE_PAUSED:
+#define p s.param.working
+            progress = (p.progress + p.pass - 1) / p.pass_count;
+#undef p
+
+            break;
+
+        case HB_STATE_SCANNING:
+#define p s.param.scanning
+            progress = p.progress;
+#undef p
+            break;
+
+        case HB_STATE_MUXING:
+            progress = 1;
+            break;
+
+        default:
+            break;
+    }
+
+    if (progress < 0)
+    {
+        progress = 0;
+    }
+    else if (progress > 1)
+    {
+        progress = 1;
+    }
+
+    return progress;
+}
+
 @end
index f0ad8c6d2136e14cbda6cde3fb594a5ae77ffae0..abc11e5afcc8aa403695903c9152740fa7b87c92 100644 (file)
                A98036CD1CCA91DD007661AA /* HBAVPlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = A98036CC1CCA91DD007661AA /* HBAVPlayer.m */; };
                A98B8E241C7DD2A200B810C9 /* HBPresetCoding.h in Headers */ = {isa = PBXBuildFile; fileRef = A997D8EB1A4ABB0900E19B6F /* HBPresetCoding.h */; settings = {ATTRIBUTES = (Public, ); }; };
                A98C29C41977B10600AF5DED /* HBLanguagesSelection.m in Sources */ = {isa = PBXBuildFile; fileRef = A98C29C31977B10600AF5DED /* HBLanguagesSelection.m */; };
-               A98F38071C7DCA7E00E469C8 /* HBStateFormatter+Private.m in Sources */ = {isa = PBXBuildFile; fileRef = A98F38051C7DCA7E00E469C8 /* HBStateFormatter+Private.m */; };
                A9906B2C1A710920001D82D5 /* HBQueueController.m in Sources */ = {isa = PBXBuildFile; fileRef = A9906B2B1A710920001D82D5 /* HBQueueController.m */; };
                A99F40CF1B624E7E00750170 /* HBPictureViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A99F40CD1B624E7E00750170 /* HBPictureViewController.m */; };
                A9A0CBE81CCEA3670045B3DF /* HBPlayerTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = A9A0CBE61CCEA1D10045B3DF /* HBPlayerTrack.m */; };
                A98C29C21977B10600AF5DED /* HBLanguagesSelection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBLanguagesSelection.h; sourceTree = "<group>"; };
                A98C29C31977B10600AF5DED /* HBLanguagesSelection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBLanguagesSelection.m; sourceTree = "<group>"; };
                A98F38041C7DCA7E00E469C8 /* HBStateFormatter+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HBStateFormatter+Private.h"; sourceTree = "<group>"; };
-               A98F38051C7DCA7E00E469C8 /* HBStateFormatter+Private.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "HBStateFormatter+Private.m"; sourceTree = "<group>"; };
                A98FD5941B19C6E400FCC7A5 /* HBTitle+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HBTitle+Private.h"; sourceTree = "<group>"; };
                A9906B2B1A710920001D82D5 /* HBQueueController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBQueueController.m; sourceTree = "<group>"; };
                A990D9051A64562200139032 /* HBJob+HBJobConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HBJob+HBJobConversion.h"; sourceTree = "<group>"; };
                                A93B0DF61C804CF50051A3FA /* NSDictionary+HBAdditions.h */,
                                A93B0DF71C804CF50051A3FA /* NSDictionary+HBAdditions.m */,
                                A98F38041C7DCA7E00E469C8 /* HBStateFormatter+Private.h */,
-                               A98F38051C7DCA7E00E469C8 /* HBStateFormatter+Private.m */,
                                A91D54851E378ABD006D0997 /* HBSecurityAccessToken.h */,
                                A91D54861E378ABD006D0997 /* HBSecurityAccessToken.m */,
                        );
                                A91CE2F61C7DB96D0068F46F /* NSJSONSerialization+HBAdditions.m in Sources */,
                                A91CE2F71C7DB96D0068F46F /* HBPresetsManager.m in Sources */,
                                A91CE2F81C7DB96D0068F46F /* HBPreset.m in Sources */,
-                               A98F38071C7DCA7E00E469C8 /* HBStateFormatter+Private.m in Sources */,
                                A91CE2F91C7DB96D0068F46F /* HBMutablePreset.m in Sources */,
                                A9CE0A921F57EC3400724577 /* HBImageUtilities.m in Sources */,
                                A91CE2FA1C7DB96D0068F46F /* HBTreeNode.m in Sources */,