diff options
author | Damiano Galassi <[email protected]> | 2019-07-20 09:08:25 +0200 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2019-07-20 09:08:25 +0200 |
commit | 61db67faf4bb26ce72cc22884e77269c038678c6 (patch) | |
tree | c575e4602831ebb93922445d3795e3aaa771cd9b /macosx/HBQueueItemWorkingView.m | |
parent | e17eedc1cade5d99be6d85207f32020c19763948 (diff) |
MacGui: add inline progress status and bar in the queue.
Diffstat (limited to 'macosx/HBQueueItemWorkingView.m')
-rw-r--r-- | macosx/HBQueueItemWorkingView.m | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/macosx/HBQueueItemWorkingView.m b/macosx/HBQueueItemWorkingView.m new file mode 100644 index 000000000..94916e2d4 --- /dev/null +++ b/macosx/HBQueueItemWorkingView.m @@ -0,0 +1,56 @@ +/* HBQueueItemWorkingView.m $ + + This file is part of the HandBrake source code. + Homepage: <http://handbrake.fr/>. + It may be used under the terms of the GNU General Public License. */ + +#import "HBQueueItemWorkingView.h" + +#import "HBQueueItem.h" +#import "HBQueue.h" + +@interface HBQueueItemWorkingView () + +@property (nonatomic, weak) IBOutlet NSProgressIndicator *progressBar; +@property (nonatomic, weak) IBOutlet NSTextField *progressField; + +@property (nonatomic) id progressToken; +@property (nonatomic) id completedToken; + +@end + +@implementation HBQueueItemWorkingView + +- (void)setItem:(HBQueueItem *)item +{ + [super setItem:item]; + + if (item.state == HBQueueItemStateWorking) + { + NSNotificationCenter * __weak center = NSNotificationCenter.defaultCenter; + + self.progressToken = [center addObserverForName:HBQueueProgressNotification + object:nil + queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull note) + { + NSString *progressInfo = note.userInfo[HBQueueProgressNotificationInfoKey]; + double progress = [note.userInfo[HBQueueProgressNotificationPercentKey] doubleValue]; + + self.progressField.stringValue = progressInfo; + self.progressBar.doubleValue = progress; + }]; + + self.completedToken = [center addObserverForName:HBQueueDidCompleteItemNotification + object:nil + queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull note) + { + HBQueueItem *completedItem = note.userInfo[HBQueueItemNotificationItemKey]; + if (completedItem == self.item) { + [center removeObserver:self.progressToken]; + [center removeObserver:self.completedToken]; + } + }]; + } +} + +@end |