summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2018-12-13 13:24:29 +0100
committerDamiano Galassi <[email protected]>2018-12-13 13:24:29 +0100
commit12c1154c5317aa7cc894c3a9242bfae9d8bb9574 (patch)
tree95bc4697a6d5f7205a871c9f2d4df1ab60afbee1 /macosx
parent4475ff63b6dcf61cc90d8667d070022b18654b6e (diff)
MacGui: refactor HBStateFormatter.
Diffstat (limited to 'macosx')
-rw-r--r--macosx/HBStateFormatter+Private.m163
-rw-r--r--macosx/HBStateFormatter.h2
-rw-r--r--macosx/HBStateFormatter.m153
-rw-r--r--macosx/HandBrake.xcodeproj/project.pbxproj4
4 files changed, 154 insertions, 168 deletions
diff --git a/macosx/HBStateFormatter+Private.m b/macosx/HBStateFormatter+Private.m
deleted file mode 100644
index f00b4fb56..000000000
--- a/macosx/HBStateFormatter+Private.m
+++ /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
diff --git a/macosx/HBStateFormatter.h b/macosx/HBStateFormatter.h
index 49c3599e2..665853fea 100644
--- a/macosx/HBStateFormatter.h
+++ b/macosx/HBStateFormatter.h
@@ -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.
diff --git a/macosx/HBStateFormatter.m b/macosx/HBStateFormatter.m
index 5dadd821d..9d39d29b2 100644
--- a/macosx/HBStateFormatter.m
+++ b/macosx/HBStateFormatter.m
@@ -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
@@ -19,4 +21,155 @@
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
diff --git a/macosx/HandBrake.xcodeproj/project.pbxproj b/macosx/HandBrake.xcodeproj/project.pbxproj
index f0ad8c6d2..abc11e5af 100644
--- a/macosx/HandBrake.xcodeproj/project.pbxproj
+++ b/macosx/HandBrake.xcodeproj/project.pbxproj
@@ -221,7 +221,6 @@
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 */; };
@@ -572,7 +571,6 @@
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>"; };
@@ -1071,7 +1069,6 @@
A93B0DF61C804CF50051A3FA /* NSDictionary+HBAdditions.h */,
A93B0DF71C804CF50051A3FA /* NSDictionary+HBAdditions.m */,
A98F38041C7DCA7E00E469C8 /* HBStateFormatter+Private.h */,
- A98F38051C7DCA7E00E469C8 /* HBStateFormatter+Private.m */,
A91D54851E378ABD006D0997 /* HBSecurityAccessToken.h */,
A91D54861E378ABD006D0997 /* HBSecurityAccessToken.m */,
);
@@ -1744,7 +1741,6 @@
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 */,