From 61db67faf4bb26ce72cc22884e77269c038678c6 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Sat, 20 Jul 2019 09:08:25 +0200 Subject: MacGui: add inline progress status and bar in the queue. --- macosx/Base.lproj/HBQueueTableViewController.xib | 72 +++++++++++++++++++++++- macosx/HBController.m | 17 ++++-- macosx/HBQueue.h | 3 +- macosx/HBQueue.m | 14 +++-- macosx/HBQueueController.m | 7 ++- macosx/HBQueueItemView.h | 1 - macosx/HBQueueItemView.m | 6 -- macosx/HBQueueItemWorkingView.h | 15 +++++ macosx/HBQueueItemWorkingView.m | 56 ++++++++++++++++++ macosx/HBQueueTableViewController.m | 46 ++++----------- macosx/HandBrake.xcodeproj/project.pbxproj | 6 ++ 11 files changed, 185 insertions(+), 58 deletions(-) create mode 100644 macosx/HBQueueItemWorkingView.h create mode 100644 macosx/HBQueueItemWorkingView.m (limited to 'macosx') diff --git a/macosx/Base.lproj/HBQueueTableViewController.xib b/macosx/Base.lproj/HBQueueTableViewController.xib index 8eb989790..875c9a879 100644 --- a/macosx/Base.lproj/HBQueueTableViewController.xib +++ b/macosx/Base.lproj/HBQueueTableViewController.xib @@ -24,7 +24,7 @@ - + @@ -44,8 +44,74 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/macosx/HBController.m b/macosx/HBController.m index 40b42ff9b..21f08570c 100644 --- a/macosx/HBController.m +++ b/macosx/HBController.m @@ -81,7 +81,6 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; // Bottom IBOutlet NSTextField * fStatusField; IBOutlet NSProgressIndicator * fRipIndicator; - BOOL fRipIndicatorShown; // User Preset HBPresetsManager * presetManager; @@ -291,18 +290,28 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; [NSNotificationCenter.defaultCenter addObserverForName:HBQueueDidStartNotification object:_queue queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull note) { self.bottomConstrain.animator.constant = 0; - self->fRipIndicatorShown = YES; self->fRipIndicator.hidden = NO; }]; [NSNotificationCenter.defaultCenter addObserverForName:HBQueueDidCompleteNotification object:_queue queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull note) { self.bottomConstrain.animator.constant = -WINDOW_HEIGHT_OFFSET; self->fRipIndicator.hidden = YES; - self->fRipIndicatorShown = NO; }]; [NSNotificationCenter.defaultCenter addObserverForName:HBQueueProgressNotification object:_queue queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull note) { - self.progressInfo = note.userInfo[HBQueueProgressNotificationInfoKey]; + HBQueueItem *item = self.queue.currentItem; + NSString *info; + if (item) + { + info = [NSString stringWithFormat:NSLocalizedString(@"Encoding %@\n%@", @""), + self.queue.currentItem.outputFileName, + note.userInfo[HBQueueProgressNotificationInfoKey]]; + } + else + { + info = note.userInfo[HBQueueProgressNotificationInfoKey]; + } + self.progressInfo = [[NSAttributedString alloc] initWithString:info]; self.progress = [note.userInfo[HBQueueProgressNotificationPercentKey] doubleValue]; if (self->_visible) diff --git a/macosx/HBQueue.h b/macosx/HBQueue.h index 0e176292b..4a85c47ef 100644 --- a/macosx/HBQueue.h +++ b/macosx/HBQueue.h @@ -33,8 +33,9 @@ extern NSString * const HBQueueProgressNotificationInfoKey; // NSString extern NSString * const HBQueueDidStartNotification; extern NSString * const HBQueueDidCompleteNotification; +extern NSString * const HBQueueDidStartItemNotification; extern NSString * const HBQueueDidCompleteItemNotification; -extern NSString * const HBQueueDidCompleteItemNotificationItemKey; // HBQueueItem +extern NSString * const HBQueueItemNotificationItemKey; // HBQueueItem @interface HBQueue : NSObject diff --git a/macosx/HBQueue.m b/macosx/HBQueue.m index 6aee92452..3c9c20a2b 100644 --- a/macosx/HBQueue.m +++ b/macosx/HBQueue.m @@ -28,8 +28,9 @@ NSString * const HBQueueProgressNotificationInfoKey = @"HBQueueProgressNotificat NSString * const HBQueueDidStartNotification = @"HBQueueDidStartNotification"; NSString * const HBQueueDidCompleteNotification = @"HBQueueDidCompleteNotification"; +NSString * const HBQueueDidStartItemNotification = @"HBQueueDidStartItemNotification"; NSString * const HBQueueDidCompleteItemNotification = @"HBQueueDidCompleteItemNotification"; -NSString * const HBQueueDidCompleteItemNotificationItemKey = @"HBQueueDidCompleteItemNotificationItemKey"; +NSString * const HBQueueItemNotificationItemKey = @"HBQueueItemNotificationItemKey"; @interface HBQueue () @@ -520,7 +521,6 @@ NSString * const HBQueueDidCompleteItemNotificationItemKey = @"HBQueueDidComplet - (void)encodeNextQueueItem { [self.items beginTransaction]; - self.currentItem = nil; // since we have completed an encode, we go to the next if (self.stop) @@ -562,7 +562,9 @@ NSString * const HBQueueDidCompleteItemNotificationItemKey = @"HBQueueDidComplet self.currentItem = nextItem; NSIndexSet *indexes = [NSIndexSet indexSetWithIndex:[self.items indexOfObject:nextItem]]; - [NSNotificationCenter.defaultCenter postNotificationName:HBQueueDidChangeItemNotification object:self userInfo:@{HBQueueItemNotificationIndexesKey: indexes}]; + + [NSNotificationCenter.defaultCenter postNotificationName:HBQueueDidStartItemNotification object:self userInfo:@{HBQueueItemNotificationItemKey: nextItem, + HBQueueItemNotificationIndexesKey: indexes}]; [self updateStats]; @@ -622,12 +624,14 @@ NSString * const HBQueueDidCompleteItemNotificationItemKey = @"HBQueueDidComplet break; } + self.currentItem = nil; + [NSNotificationCenter.defaultCenter postNotificationName:HBQueueProgressNotification object:self userInfo:@{HBQueueProgressNotificationPercentKey: @1.0, HBQueueProgressNotificationInfoKey: info}]; NSInteger index = [self.items indexOfObject:item]; NSIndexSet *indexes = index > -1 ? [NSIndexSet indexSetWithIndex:index] : [NSIndexSet indexSet]; - [NSNotificationCenter.defaultCenter postNotificationName:HBQueueDidCompleteItemNotification object:self userInfo:@{HBQueueDidCompleteItemNotificationItemKey: item, + [NSNotificationCenter.defaultCenter postNotificationName:HBQueueDidCompleteItemNotification object:self userInfo:@{HBQueueItemNotificationItemKey: item, HBQueueItemNotificationIndexesKey: indexes}]; [self.items commit]; @@ -686,7 +690,7 @@ NSString * const HBQueueDidCompleteItemNotificationItemKey = @"HBQueueDidComplet NSParameterAssert(job); HBStateFormatter *formatter = [[HBStateFormatter alloc] init]; - formatter.title = job.outputFileName; + formatter.twoLines = NO; self.core.stateFormatter = formatter; // Progress handler diff --git a/macosx/HBQueueController.m b/macosx/HBQueueController.m index 40ae17334..e5621db6d 100644 --- a/macosx/HBQueueController.m +++ b/macosx/HBQueueController.m @@ -79,8 +79,6 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; _splitViewController.splitView = _splitView; _splitViewController.view.wantsLayer = YES; _splitViewController.splitView.vertical = YES; - _splitViewController.splitView.autosaveName = @"HBQueueSplitViewAutosave"; - _splitViewController.splitView.identifier = @"HBQueueSplitViewIdentifier"; _tableViewController = [[HBQueueTableViewController alloc] initWithQueue:self.queue delegate:self]; _detailsViewController = [[HBQueueDetailsViewController alloc] initWithDelegate:self]; @@ -96,6 +94,9 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; [_splitViewController addSplitViewItem:detailsItem]; + _splitViewController.splitView.autosaveName = @"HBQueueSplitViewAutosave"; + _splitViewController.splitView.identifier = @"HBQueueSplitViewIdentifier"; + self.window.contentViewController = _splitViewController; self.window.frameAutosaveName = @"HBQueueWindowFrameAutosave"; @@ -141,7 +142,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; self.dockIconProgress = 0; // Run the per item notification and actions - HBQueueItem *item = note.userInfo[HBQueueDidCompleteItemNotificationItemKey]; + HBQueueItem *item = note.userInfo[HBQueueItemNotificationItemKey]; if (item.state == HBQueueItemStateCompleted) { [self sendToExternalApp:item]; diff --git a/macosx/HBQueueItemView.h b/macosx/HBQueueItemView.h index e79ee51c8..43235e30f 100644 --- a/macosx/HBQueueItemView.h +++ b/macosx/HBQueueItemView.h @@ -14,7 +14,6 @@ NS_ASSUME_NONNULL_BEGIN - (void)revealQueueItem:(HBQueueItem *)job; - (void)removeQueueItem:(HBQueueItem *)job; -- (void)toggleQueueItemHeight:(HBQueueItem *)job; @end diff --git a/macosx/HBQueueItemView.m b/macosx/HBQueueItemView.m index 39fbdf4ce..243c52938 100644 --- a/macosx/HBQueueItemView.m +++ b/macosx/HBQueueItemView.m @@ -10,7 +10,6 @@ @interface HBQueueItemView () @property (nonatomic, weak) IBOutlet NSButton *removeButton; -@property (nonatomic, weak) IBOutlet NSButton *expandButton; @end @@ -123,9 +122,4 @@ [self.delegate removeQueueItem:_item]; } -- (IBAction)toggleHeight:(id)sender -{ - [self.delegate toggleQueueItemHeight:_item]; -} - @end diff --git a/macosx/HBQueueItemWorkingView.h b/macosx/HBQueueItemWorkingView.h new file mode 100644 index 000000000..4223829b6 --- /dev/null +++ b/macosx/HBQueueItemWorkingView.h @@ -0,0 +1,15 @@ +/* HBQueueItemWorkingView.h $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#import "HBQueueItemView.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface HBQueueItemWorkingView : HBQueueItemView + +@end + +NS_ASSUME_NONNULL_END 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: . + 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 diff --git a/macosx/HBQueueTableViewController.m b/macosx/HBQueueTableViewController.m index d0b4753cb..309d6d48a 100644 --- a/macosx/HBQueueTableViewController.m +++ b/macosx/HBQueueTableViewController.m @@ -84,14 +84,19 @@ [self.tableView reloadDataForRowIndexes:indexes columnIndexes:columnIndexes]; }]; - [NSNotificationCenter.defaultCenter addObserverForName:HBQueueDidCompleteItemNotification object:_queue queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull note) { + typedef void (^HBUpdateHeight)(NSNotification *note); + HBUpdateHeight updateHeight = ^void(NSNotification *note) { NSIndexSet *indexes = note.userInfo[HBQueueItemNotificationIndexesKey]; NSIndexSet *columnIndexes = [NSIndexSet indexSetWithIndex:0]; if (indexes.count) { [self.tableView reloadDataForRowIndexes:indexes columnIndexes:columnIndexes]; + [self.tableView noteHeightOfRowsWithIndexesChanged:indexes]; } - }]; + }; + + [NSNotificationCenter.defaultCenter addObserverForName:HBQueueDidStartItemNotification object:_queue queue:NSOperationQueue.mainQueue usingBlock:updateHeight]; + [NSNotificationCenter.defaultCenter addObserverForName:HBQueueDidCompleteItemNotification object:_queue queue:NSOperationQueue.mainQueue usingBlock:updateHeight]; } #pragma mark - UI Actions @@ -212,9 +217,10 @@ viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { - HBQueueItemView *view = [tableView makeViewWithIdentifier:@"MainSimpleCell" owner:self]; HBQueueItem *item = self.queue.items[row]; + HBQueueItemView *view = item.state == HBQueueItemStateWorking ? [tableView makeViewWithIdentifier:@"MainWorkingCell" owner:self] : [tableView makeViewWithIdentifier:@"MainCell" owner:self]; + view.delegate = self; view.item = item; @@ -228,32 +234,8 @@ - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row { - return 22; -} - -- (void)toggleRowsAtIndexes:(NSIndexSet *)rowIndexes expand:(BOOL)expand -{ - NSMutableIndexSet *rowsToExpand = [NSMutableIndexSet indexSet]; - [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger index, BOOL *stop) { - HBQueueItem *item = self.queue.items[index]; - BOOL expanded = item.expanded; - if (expanded != expand) - { - item.expanded = !expanded; - [rowsToExpand addIndex:index]; - } - - //HBQueueItemView *itemView = (HBQueueItemView *)[self.tableView viewAtColumn:0 row:index makeIfNecessary:NO]; - //if (expand) - //{ - //[itemView expand]; - //} - //else - //{ - //[itemView collapse]; - //} - }]; - [self.tableView noteHeightOfRowsWithIndexesChanged:rowsToExpand]; + HBQueueItem *item = self.queue.items[row]; + return item.state == HBQueueItemStateWorking ? 56 : 22; } #pragma mark NSQueueItemView delegate @@ -269,12 +251,6 @@ [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[item.completeOutputURL]]; } -- (void)toggleQueueItemHeight:(nonnull HBQueueItem *)item -{ - NSInteger row = [self.queue.items indexOfObject:item]; - [self toggleRowsAtIndexes:[NSIndexSet indexSetWithIndex:row] expand:!item.expanded]; -} - #pragma mark NSTableView delegate - (void)tableViewSelectionDidChange:(NSNotification *)notification diff --git a/macosx/HandBrake.xcodeproj/project.pbxproj b/macosx/HandBrake.xcodeproj/project.pbxproj index f63eec1bf..ecdb0c0e9 100644 --- a/macosx/HandBrake.xcodeproj/project.pbxproj +++ b/macosx/HandBrake.xcodeproj/project.pbxproj @@ -259,6 +259,7 @@ A9ABD1A71E2A0F7500EC8B65 /* CoreText.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9ABD1A51E2A0F0700EC8B65 /* CoreText.framework */; }; A9ABD1A91E2A0F8200EC8B65 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9ABD1A81E2A0F8200EC8B65 /* CoreGraphics.framework */; }; A9ABD1AA1E2A0F8F00EC8B65 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9ABD1A81E2A0F8200EC8B65 /* CoreGraphics.framework */; }; + A9B3B63922E2EA58001CEB9A /* HBQueueItemWorkingView.m in Sources */ = {isa = PBXBuildFile; fileRef = A9B3B63822E2EA58001CEB9A /* HBQueueItemWorkingView.m */; }; A9B6B9EE217B38D200B957AE /* HBLocalizationUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = A9B6B9ED217B38D200B957AE /* HBLocalizationUtilities.h */; }; A9B6B9F1217B408E00B957AE /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = A9B6B9EF217B408E00B957AE /* InfoPlist.strings */; }; A9B6B9F4217B408E00B957AE /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = A9B6B9F2217B408E00B957AE /* Localizable.strings */; }; @@ -667,6 +668,8 @@ A9ABD1A51E2A0F0700EC8B65 /* CoreText.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreText.framework; path = System/Library/Frameworks/CoreText.framework; sourceTree = SDKROOT; }; A9ABD1A81E2A0F8200EC8B65 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; A9B34D74197696FE00871B7D /* DiskArbitration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DiskArbitration.framework; path = System/Library/Frameworks/DiskArbitration.framework; sourceTree = SDKROOT; }; + A9B3B63722E2EA58001CEB9A /* HBQueueItemWorkingView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HBQueueItemWorkingView.h; sourceTree = ""; }; + A9B3B63822E2EA58001CEB9A /* HBQueueItemWorkingView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HBQueueItemWorkingView.m; sourceTree = ""; }; A9B6B9ED217B38D200B957AE /* HBLocalizationUtilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HBLocalizationUtilities.h; sourceTree = ""; }; A9B6B9F0217B408E00B957AE /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/InfoPlist.strings; sourceTree = ""; }; A9B6B9F3217B408E00B957AE /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Localizable.strings; sourceTree = ""; }; @@ -1098,6 +1101,8 @@ A9A96BD220CAD63000A39AFB /* Queue.xib */, A9D3634F2209C08500D8EFEA /* HBQueueItemView.h */, A9D363502209C08500D8EFEA /* HBQueueItemView.m */, + A9B3B63722E2EA58001CEB9A /* HBQueueItemWorkingView.h */, + A9B3B63822E2EA58001CEB9A /* HBQueueItemWorkingView.m */, A96127E122E09ADD0086E6DC /* HBQueueTableViewController.h */, A96127E222E09ADD0086E6DC /* HBQueueTableViewController.m */, A958EAC422E24D6400D83AF4 /* HBQueueTableViewController.xib */, @@ -1812,6 +1817,7 @@ A96127DF22E0994E0086E6DC /* HBQueueDetailsViewController.m in Sources */, A97ECB8222E1D85500570935 /* HBQueue.m in Sources */, A92B148220CA9F7700146FD8 /* HBHUDView.m in Sources */, + A9B3B63922E2EA58001CEB9A /* HBQueueItemWorkingView.m in Sources */, A914BCB31BC441C700157917 /* HBPreviewView.m in Sources */, 273F20B714ADBE670021BE6D /* HBPreviewController.m in Sources */, A9D1E41718262364002F6424 /* HBPreviewGenerator.m in Sources */, -- cgit v1.2.3