summaryrefslogtreecommitdiffstats
path: root/macosx/HBCore.m
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2018-11-11 11:56:53 +0100
committerDamiano Galassi <[email protected]>2018-11-11 11:56:53 +0100
commit32ee37822392081e96f1192197063bce54a27ba4 (patch)
treee02f5119d1c042007124d2436b595cef8fc572d6 /macosx/HBCore.m
parenta38719df5cbc8ebc7636f2a4b3e0ac69d4f8adad (diff)
MacGui: show a progress bar on the encoded file in Finder.
Diffstat (limited to 'macosx/HBCore.m')
-rw-r--r--macosx/HBCore.m34
1 files changed, 33 insertions, 1 deletions
diff --git a/macosx/HBCore.m b/macosx/HBCore.m
index de9a26941..81cc6c3e3 100644
--- a/macosx/HBCore.m
+++ b/macosx/HBCore.m
@@ -61,6 +61,9 @@ typedef void (^HBCoreCleanupHandler)(void);
/// Cleanup handle, used for internal HBCore cleanup.
@property (nonatomic, readwrite, copy) HBCoreCleanupHandler cleanupHandler;
+/// Progress
+@property (nonatomic, readwrite) NSProgress *progress;
+
@end
@implementation HBCore
@@ -429,7 +432,7 @@ typedef void (^HBCoreCleanupHandler)(void);
hb_job_close(&hb_job);
[self preventAutoSleep];
-
+ [self startProgressReporting:job.completeOutputURL];
hb_start(_hb_handle);
// Start the timer to handle libhb state changes
@@ -446,6 +449,8 @@ typedef void (^HBCoreCleanupHandler)(void);
- (HBCoreResult)workDone
{
+ [self stopProgressReporting];
+
// HB_STATE_WORKDONE happpens as a result of libhb finishing all its jobs
// or someone calling hb_stop. In the latter case, hb_stop does not clear
// out the remaining passes/jobs in the queue. We'll do that here.
@@ -494,6 +499,28 @@ typedef void (^HBCoreCleanupHandler)(void);
[self preventAutoSleep];
}
+#pragma mark - Progress
+
+- (void)startProgressReporting:(NSURL *)fileURL
+{
+ NSDictionary *userInfo = @{NSProgressFileURLKey : fileURL};
+
+ self.progress = [[NSProgress alloc] initWithParent:nil userInfo:userInfo];
+ self.progress.totalUnitCount = 100;
+ self.progress.kind = NSProgressKindFile;
+ self.progress.pausable = NO;
+ self.progress.cancellable = NO;
+
+ [self.progress publish];
+}
+
+- (void)stopProgressReporting
+{
+ self.progress.completedUnitCount = 100;
+ [self.progress unpublish];
+ self.progress = nil;
+}
+
#pragma mark - State updates
/**
@@ -585,6 +612,11 @@ typedef void (^HBCoreCleanupHandler)(void);
NSString *info = [self.stateFormatter stateToString:state];
self.progressHandler(self.state, progress, info);
+
+ if (self.progress.completedUnitCount < progress.percent * 100)
+ {
+ self.progress.completedUnitCount = progress.percent * 100;
+ }
}
}