From 5c52e252def1d72d072adc4cfdb2137a35705186 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Thu, 7 Feb 2019 19:11:51 +0100 Subject: MacGui: refactor some queue related properties out of HBJob to a new HBQueueItem class. --- macosx/Base.lproj/Queue.xib | 65 +++- macosx/Base.lproj/Subtitles.xib | 4 +- macosx/HBAutoNamer.m | 2 + macosx/HBJob+UIAdditions.h | 2 +- macosx/HBJob.h | 18 +- macosx/HBJob.m | 21 +- macosx/HBQueueController.m | 381 ++++++++++----------- macosx/HBQueueItem.h | 55 +++ macosx/HBQueueItem.m | 99 ++++++ macosx/HBQueueItemView.h | 10 +- macosx/HBQueueItemView.m | 49 ++- macosx/HandBrake.xcodeproj/project.pbxproj | 20 +- .../xcschemes/HandBrake-Release-Sandbox.xcscheme | 11 +- macosx/HandBrakeKit/HandBrakeKit.h | 1 - 14 files changed, 465 insertions(+), 273 deletions(-) create mode 100644 macosx/HBQueueItem.h create mode 100644 macosx/HBQueueItem.m diff --git a/macosx/Base.lproj/Queue.xib b/macosx/Base.lproj/Queue.xib index d2a4b3359..bb379a101 100644 --- a/macosx/Base.lproj/Queue.xib +++ b/macosx/Base.lproj/Queue.xib @@ -74,9 +74,66 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + @@ -216,7 +273,7 @@ - + diff --git a/macosx/Base.lproj/Subtitles.xib b/macosx/Base.lproj/Subtitles.xib index 2a69366e5..9b76c25c7 100644 --- a/macosx/Base.lproj/Subtitles.xib +++ b/macosx/Base.lproj/Subtitles.xib @@ -30,7 +30,7 @@ diff --git a/macosx/HBAutoNamer.m b/macosx/HBAutoNamer.m index 2fced6239..642706f7b 100644 --- a/macosx/HBAutoNamer.m +++ b/macosx/HBAutoNamer.m @@ -6,6 +6,8 @@ #import "HBAutoNamer.h" +#import + #import "HBJob.h" #import "HBUtilities.h" diff --git a/macosx/HBJob+UIAdditions.h b/macosx/HBJob+UIAdditions.h index 2125c5e2a..73a09d8a7 100644 --- a/macosx/HBJob+UIAdditions.h +++ b/macosx/HBJob+UIAdditions.h @@ -4,7 +4,7 @@ Homepage: . It may be used under the terms of the GNU General Public License. */ -#import +#import #import "HBJob.h" @interface HBJob (UIAdditions) diff --git a/macosx/HBJob.h b/macosx/HBJob.h index e77dd346e..c5325f1b3 100644 --- a/macosx/HBJob.h +++ b/macosx/HBJob.h @@ -19,36 +19,20 @@ #import "HBSubtitles.h" #import "HBChapter.h" -#import "HBDistributedArray.h" - NS_ASSUME_NONNULL_BEGIN extern NSString *HBContainerChangedNotification; extern NSString *HBChaptersChangedNotification; -/** - * A flag to indicate the job's state - */ -typedef NS_ENUM(NSUInteger, HBJobState){ - HBJobStateReady, - HBJobStateWorking, - HBJobStateCompleted, - HBJobStateCanceled, - HBJobStateFailed -}; - /** * HBJob */ -@interface HBJob : NSObject +@interface HBJob : NSObject - (instancetype)initWithTitle:(HBTitle *)title andPreset:(HBPreset *)preset; - (void)applyPreset:(HBPreset *)preset; -/// Current state of the job. -@property (nonatomic, readwrite) HBJobState state; - @property (nonatomic, readwrite, weak, nullable) HBTitle *title; @property (nonatomic, readonly) int titleIdx; diff --git a/macosx/HBJob.m b/macosx/HBJob.m index beb7e5875..ebd8df594 100644 --- a/macosx/HBJob.m +++ b/macosx/HBJob.m @@ -45,8 +45,6 @@ NSString *HBChaptersChangedNotification = @"HBChaptersChangedNotification"; @implementation HBJob -@synthesize uuid = _uuid; - - (instancetype)initWithTitle:(HBTitle *)title andPreset:(HBPreset *)preset { self = [super init]; @@ -73,11 +71,6 @@ NSString *HBChaptersChangedNotification = @"HBChaptersChangedNotification"; _chapterTitles = [title.chapters copy]; - CFUUIDRef theUUID = CFUUIDCreate(NULL); - CFStringRef string = CFUUIDCreateString(NULL, theUUID); - CFRelease(theUUID); - _uuid = CFBridgingRelease(string); - [self applyPreset:preset]; } @@ -312,16 +305,10 @@ NSString *HBChaptersChangedNotification = @"HBChaptersChangedNotification"; if (copy) { - copy->_state = HBJobStateReady; copy->_name = [_name copy]; copy->_presetName = [_presetName copy]; copy->_titleIdx = _titleIdx; - CFUUIDRef theUUID = CFUUIDCreate(NULL); - CFStringRef string = CFUUIDCreateString(NULL, theUUID); - CFRelease(theUUID); - copy->_uuid = CFBridgingRelease(string); - copy->_fileURLBookmark = [_fileURLBookmark copy]; copy->_outputURLFolderBookmark = [_outputURLFolderBookmark copy]; @@ -363,13 +350,11 @@ NSString *HBChaptersChangedNotification = @"HBChaptersChangedNotification"; - (void)encodeWithCoder:(NSCoder *)coder { - [coder encodeInt:3 forKey:@"HBJobVersion"]; + [coder encodeInt:4 forKey:@"HBJobVersion"]; - encodeInt(_state); encodeObject(_name); encodeObject(_presetName); encodeInt(_titleIdx); - encodeObject(_uuid); #ifdef __SANDBOX_ENABLED__ if (!_fileURLBookmark) @@ -418,13 +403,11 @@ NSString *HBChaptersChangedNotification = @"HBChaptersChangedNotification"; { int version = [decoder decodeIntForKey:@"HBJobVersion"]; - if (version == 3 && (self = [super init])) + if (version == 4 && (self = [super init])) { - decodeInt(_state); decodeObjectOrFail(_name, NSString); decodeObjectOrFail(_presetName, NSString); decodeInt(_titleIdx); - decodeObjectOrFail(_uuid, NSString); #ifdef __SANDBOX_ENABLED__ _fileURLBookmark = [decoder decodeObjectOfClass:[NSData class] forKey:@"_fileURLBookmark"]; diff --git a/macosx/HBQueueController.m b/macosx/HBQueueController.m index d227ffd24..fe603d5ea 100644 --- a/macosx/HBQueueController.m +++ b/macosx/HBQueueController.m @@ -6,6 +6,8 @@ #import "HBQueueController.h" +#import "HBQueueItem.h" + #import "HBController.h" #import "HBAppDelegate.h" @@ -50,21 +52,20 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; @property (nonatomic) IBOutlet NSToolbarItem *ripToolbarItem; @property (nonatomic) IBOutlet NSToolbarItem *pauseToolbarItem; -@property (nonatomic, readonly) NSMutableDictionary *expanded; @property (nonatomic) NSTableCellView *dummyCell; @property (nonatomic) NSLayoutConstraint *dummyCellWidth; +@property (nonatomic, readonly) HBDistributedArray *items; -@property (nonatomic, readonly) HBDistributedArray *jobs; -@property (nonatomic) HBJob *currentJob; -@property (nonatomic) HBJobOutputFileWriter *currentLog; +@property (nonatomic) HBQueueItem *currentItem; +@property (nonatomic) HBJobOutputFileWriter *currentLog; @property (nonatomic, readwrite) BOOL stop; @property (nonatomic, readwrite) NSUInteger pendingItemsCount; @property (nonatomic, readwrite) NSUInteger completedItemsCount; -@property (nonatomic) NSArray *dragNodesArray; +@property (nonatomic) NSArray *dragNodesArray; @end @@ -81,9 +82,6 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; if (self = [super initWithWindowNibName:@"Queue"]) { - // Cached queue items expanded state - _expanded = [[NSMutableDictionary alloc] init]; - // Load the dockTile and instiante initial text fields _dockTile = [[HBDockTile alloc] initWithDockTile:[[NSApplication sharedApplication] dockTile] image:[[NSApplication sharedApplication] applicationIconImage]]; @@ -98,8 +96,8 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; _progressInfo = @""; // Load the queue from disk. - _jobs = [[HBDistributedArray alloc] initWithURL:queueURL class:[HBJob class]]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadQueue) name:HBDistributedArrayChanged object:_jobs]; + _items = [[HBDistributedArray alloc] initWithURL:queueURL class:[HBQueueItem class]]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadQueue) name:HBDistributedArrayChanged object:_items]; [NSUserNotificationCenter defaultUserNotificationCenter].delegate = self; } @@ -228,7 +226,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; if (action == @selector(clearAll:)) { - return self.jobs.count > 0; + return self.items.count > 0; } if (action == @selector(clearCompleted:)) @@ -284,12 +282,18 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; [self addJobsFromArray:@[item]]; } -- (void)addJobsFromArray:(NSArray *)items; +- (void)addJobsFromArray:(NSArray *)jobs; { - NSParameterAssert(items); - if (items.count) + NSParameterAssert(jobs); + NSMutableArray *itemsToAdd = [NSMutableArray array]; + for (HBJob *job in jobs) + { + HBQueueItem *item = [[HBQueueItem alloc] initWithJob:job]; + [itemsToAdd addObject:item]; + } + if (itemsToAdd.count) { - [self addQueueItems:items]; + [self addQueueItems:itemsToAdd]; } } @@ -297,9 +301,9 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; { NSParameterAssert(url); - for (HBJob *item in self.jobs) + for (HBQueueItem *item in self.items) { - if ((item.state == HBJobStateReady || item.state == HBJobStateWorking) + if ((item.state == HBQueueItemStateReady || item.state == HBQueueItemStateWorking) && [item.completeOutputURL isEqualTo:url]) { return YES; @@ -310,7 +314,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; - (NSUInteger)count { - return self.jobs.count; + return self.items.count; } /** @@ -319,12 +323,12 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; */ - (void)removeCompletedJobs { - [self.jobs beginTransaction]; - NSIndexSet *indexes = [self.jobs indexesOfObjectsUsingBlock:^BOOL(HBJob *item) { - return (item.state == HBJobStateCompleted || item.state == HBJobStateCanceled); + [self.items beginTransaction]; + NSIndexSet *indexes = [self.items indexesOfObjectsUsingBlock:^BOOL(HBQueueItem *item) { + return (item.state == HBQueueItemStateCompleted || item.state == HBQueueItemStateCanceled); }]; [self removeQueueItemsAtIndexes:indexes]; - [self.jobs commit]; + [self.items commit]; } /** @@ -332,9 +336,9 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; */ - (void)removeAllJobs { - [self.jobs beginTransaction]; - [self removeQueueItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.jobs.count)]]; - [self.jobs commit]; + [self.items beginTransaction]; + [self removeQueueItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.items.count)]]; + [self.items commit]; } /** @@ -343,22 +347,22 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; */ - (void)setEncodingJobsAsPending { - [self.jobs beginTransaction]; + [self.items beginTransaction]; NSMutableIndexSet *indexes = [NSMutableIndexSet indexSet]; NSUInteger idx = 0; - for (HBJob *job in self.jobs) + for (HBQueueItem *item in self.items) { // We want to keep any queue item that is pending or was previously being encoded - if (job.state == HBJobStateWorking) + if (item.state == HBQueueItemStateWorking) { - job.state = HBJobStateReady; + item.state = HBQueueItemStateReady; [indexes addIndex:idx]; } idx++; } [self reloadQueueItemsAtIndexes:indexes]; - [self.jobs commit]; + [self.items commit]; } #pragma mark - Private queue editing methods @@ -386,10 +390,10 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; [self updateQueueStats]; } -- (void)addQueueItems:(NSArray *)items +- (void)addQueueItems:(NSArray *)items { NSParameterAssert(items); - NSIndexSet *indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(self.jobs.count, items.count)]; + NSIndexSet *indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(self.items.count, items.count)]; [self addQueueItems:items atIndexes:indexes]; } @@ -397,7 +401,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; { NSParameterAssert(items); NSParameterAssert(indexes); - [self.jobs beginTransaction]; + [self.items beginTransaction]; [self.tableView beginUpdates]; // Forward @@ -405,7 +409,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; NSUInteger currentObjectIndex = 0; while (currentIndex != NSNotFound) { - [self.jobs insertObject:items[currentObjectIndex] atIndex:currentIndex]; + [self.items insertObject:items[currentObjectIndex] atIndex:currentIndex]; currentIndex = [indexes indexGreaterThanIndex:currentIndex]; currentObjectIndex++; } @@ -430,7 +434,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; [self.tableView endUpdates]; [self updateQueueStats]; - [self.jobs commit]; + [self.items commit]; } - (void)removeQueueItemAtIndex:(NSUInteger)index @@ -447,26 +451,21 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; return; } - [self.jobs beginTransaction]; + [self.items beginTransaction]; [self.tableView beginUpdates]; - NSArray *removeJobs = [self.jobs objectsAtIndexes:indexes]; + NSArray *removeItems = [self.items objectsAtIndexes:indexes]; - if (self.jobs.count > indexes.lastIndex) + if (self.items.count > indexes.lastIndex) { - [self.jobs removeObjectsAtIndexes:indexes]; - } - - for (HBJob *job in removeJobs) - { - [self.expanded removeObjectForKey:job.uuid]; + [self.items removeObjectsAtIndexes:indexes]; } [self.tableView removeRowsAtIndexes:indexes withAnimation:NSTableViewAnimationSlideUp]; [self.tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:indexes.firstIndex] byExtendingSelection:NO]; NSUndoManager *undo = self.window.undoManager; - [[undo prepareWithInvocationTarget:self] addQueueItems:removeJobs atIndexes:indexes]; + [[undo prepareWithInvocationTarget:self] addQueueItems:removeItems atIndexes:indexes]; if (!undo.isUndoing) { @@ -482,12 +481,12 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; [self.tableView endUpdates]; [self updateQueueStats]; - [self.jobs commit]; + [self.items commit]; } - (void)moveQueueItems:(NSArray *)items toIndex:(NSUInteger)index { - [self.jobs beginTransaction]; + [self.items beginTransaction]; [self.tableView beginUpdates]; NSMutableArray *source = [NSMutableArray array]; @@ -495,8 +494,8 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; for (id object in items.reverseObjectEnumerator) { - NSUInteger sourceIndex = [self.jobs indexOfObject:object]; - [self.jobs removeObjectAtIndex:sourceIndex]; + NSUInteger sourceIndex = [self.items indexOfObject:object]; + [self.items removeObjectAtIndex:sourceIndex]; if (sourceIndex < index) @@ -504,7 +503,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; index--; } - [self.jobs insertObject:object atIndex:index]; + [self.items insertObject:object atIndex:index]; [source addObject:@(index)]; [dest addObject:@(sourceIndex)]; @@ -528,12 +527,12 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; } [self.tableView endUpdates]; - [self.jobs commit]; + [self.items commit]; } - (void)moveQueueItemsAtIndexes:(NSArray *)source toIndexes:(NSArray *)dest { - [self.jobs beginTransaction]; + [self.items beginTransaction]; [self.tableView beginUpdates]; NSMutableArray *newSource = [NSMutableArray array]; @@ -547,9 +546,9 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; [newSource addObject:@(destIndex)]; [newDest addObject:@(sourceIndex)]; - id obj = [self.jobs objectAtIndex:sourceIndex]; - [self.jobs removeObjectAtIndex:sourceIndex]; - [self.jobs insertObject:obj atIndex:destIndex]; + id obj = [self.items objectAtIndex:sourceIndex]; + [self.items removeObjectAtIndex:sourceIndex]; + [self.items insertObject:obj atIndex:destIndex]; [self.tableView moveRowAtIndex:sourceIndex toIndex:destIndex]; } @@ -570,7 +569,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; } [self.tableView endUpdates]; - [self.jobs commit]; + [self.items commit]; } - (void)windowDidChangeOcclusionState:(NSNotification *)notification @@ -605,13 +604,13 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; NSUInteger pendingCount = 0; NSUInteger completedCount = 0; - for (HBJob *job in self.jobs) + for (HBQueueItem *item in self.items) { - if (job.state == HBJobStateReady) + if (item.state == HBQueueItemStateReady) { pendingCount++; } - if (job.state == HBJobStateCompleted) + if (item.state == HBQueueItemStateCompleted) { completedCount++; } @@ -670,13 +669,13 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; /** * Used to get the next pending queue item and return it if found */ -- (HBJob *)getNextPendingQueueItem +- (HBQueueItem *)getNextPendingQueueItem { - for (HBJob *job in self.jobs) + for (HBQueueItem *item in self.items) { - if (job.state == HBJobStateReady) + if (item.state == HBQueueItemStateReady) { - return job; + return item; } } return nil; @@ -687,8 +686,8 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; */ - (void)encodeNextQueueItem { - [self.jobs beginTransaction]; - self.currentJob = nil; + [self.items beginTransaction]; + self.currentItem = nil; // since we have completed an encode, we go to the next if (self.stop) @@ -701,9 +700,9 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; else { // Check to see if there are any more pending items in the queue - HBJob *nextJob = [self getNextPendingQueueItem]; + HBQueueItem *nextItem = [self getNextPendingQueueItem]; - if (nextJob && [self _isDiskSpaceLowAtURL:nextJob.outputURL]) + if (nextItem && [self _isDiskSpaceLowAtURL:nextItem.outputURL]) { // Disk space is low, show an alert [HBUtilities writeToActivityLog:"Queue Stopped, low space on destination disk"]; @@ -711,24 +710,24 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; [self queueLowDiskSpaceAlert]; } // If we still have more pending items in our queue, lets go to the next one - else if (nextJob) + else if (nextItem) { // now we mark the queue item as working so another instance can not come along and try to scan it while we are scanning - nextJob.state = HBJobStateWorking; + nextItem.state = HBQueueItemStateWorking; // Tell HB to output a new activity log file for this encode - self.currentLog = [[HBJobOutputFileWriter alloc] initWithJob:nextJob]; + self.currentLog = [[HBJobOutputFileWriter alloc] initWithJob:nextItem.job]; if (self.currentLog) { [[HBOutputRedirect stderrRedirect] addListener:self.currentLog]; [[HBOutputRedirect stdoutRedirect] addListener:self.currentLog]; } - self.currentJob = nextJob; - [self reloadQueueItemAtIndex:[self.jobs indexOfObject:nextJob]]; + self.currentItem = nextItem; + [self reloadQueueItemAtIndex:[self.items indexOfObject:nextItem]]; // now we can go ahead and scan the new pending queue item - [self encodeJob:nextJob]; + [self encodeItem:nextItem]; // erase undo manager history [self.window.undoManager removeAllActions]; @@ -744,13 +743,13 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; [self.core allowSleep]; } } - [self.jobs commit]; + [self.items commit]; } -- (void)completedJob:(HBJob *)job result:(HBCoreResult)result; +- (void)completedItem:(HBQueueItem *)item result:(HBCoreResult)result; { - NSParameterAssert(job); - [self.jobs beginTransaction]; + NSParameterAssert(item); + [self.items beginTransaction]; // Since we are done with this encode, tell output to stop writing to the // individual encode log. @@ -764,42 +763,42 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; if (result != HBCoreResultCanceled) { // Send to tagger - [self sendToExternalApp:job]; + [self sendToExternalApp:item]; } // Mark the encode just finished switch (result) { case HBCoreResultDone: - job.state = HBJobStateCompleted; + item.state = HBQueueItemStateCompleted; break; case HBCoreResultCanceled: - job.state = HBJobStateCanceled; + item.state = HBQueueItemStateCanceled; break; default: - job.state = HBJobStateFailed; + item.state = HBQueueItemStateFailed; break; } - if ([self.jobs containsObject:job]) + if ([self.items containsObject:item]) { - [self reloadQueueItemAtIndex:[self.jobs indexOfObject:job]]; + [self reloadQueueItemAtIndex:[self.items indexOfObject:item]]; } [self.window.toolbar validateVisibleItems]; - [self.jobs commit]; + [self.items commit]; // Update UI NSString *info = nil; switch (result) { case HBCoreResultDone: info = NSLocalizedString(@"Encode Finished.", @"Queue status"); - [self jobCompletedAlerts:job result:result]; + [self itemCompletedAlerts:item result:result]; break; case HBCoreResultCanceled: info = NSLocalizedString(@"Encode Canceled.", @"Queue status"); break; default: info = NSLocalizedString(@"Encode Failed.", @"Queue status"); - [self jobCompletedAlerts:job result:result]; + [self itemCompletedAlerts:item result:result]; break; } [self updateProgress:info progress:1.0 hidden:YES]; @@ -812,9 +811,9 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; /** * Here we actually tell hb_scan to perform the source scan, using the path to source and title number */ -- (void)encodeJob:(HBJob *)job +- (void)encodeItem:(HBQueueItem *)item { - NSParameterAssert(job); + NSParameterAssert(item); // Progress handler void (^progressHandler)(HBState state, HBProgress progress, NSString *info) = ^(HBState state, HBProgress progress, NSString *info) @@ -827,19 +826,19 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; { if (result == HBCoreResultDone) { - [self realEncodeJob:job]; + [self realEncodeItem:item]; } else { - [self completedJob:job result:result]; + [self completedItem:item result:result]; [self encodeNextQueueItem]; } }; // Only scan 10 previews before an encode - additional previews are // only useful for autocrop and static previews, which are already taken care of at this point - [self.core scanURL:job.fileURL - titleIndex:job.titleIdx + [self.core scanURL:item.fileURL + titleIndex:item.job.titleIdx previews:10 minDuration:0 progressHandler:progressHandler @@ -849,9 +848,11 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; /** * This assumes that we have re-scanned and loaded up a new queue item to send to libhb */ -- (void)realEncodeJob:(HBJob *)job +- (void)realEncodeItem:(HBQueueItem *)item { - NSParameterAssert(job); + NSParameterAssert(item); + + HBJob *job = item.job; // Reset the title in the job. job.title = self.core.titles.firstObject; @@ -886,7 +887,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; // Completion handler void (^completionHandler)(HBCoreResult result) = ^(HBCoreResult result) { - [self completedJob:job result:result]; + [self completedItem:item result:result]; [self encodeNextQueueItem]; }; @@ -900,7 +901,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; /** * Cancels the current job */ -- (void)doCancelCurrentJob +- (void)doCancelCurrentItem { if (self.core.state == HBStateScanning) { @@ -915,18 +916,18 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; /** * Cancels the current job and starts processing the next in queue. */ -- (void)cancelCurrentJobAndContinue +- (void)cancelCurrentItemAndContinue { - [self doCancelCurrentJob]; + [self doCancelCurrentItem]; } /** * Cancels the current job and stops libhb from processing the remaining encodes. */ -- (void)cancelCurrentJobAndStop +- (void)cancelCurrentItemAndStop { self.stop = YES; - [self doCancelCurrentJob]; + [self doCancelCurrentItem]; } /** @@ -968,13 +969,13 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; * * @param job the job of the file to send */ -- (void)sendToExternalApp:(HBJob *)job +- (void)sendToExternalApp:(HBQueueItem *)item { // This end of encode action is called as each encode rolls off of the queue if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HBSendToAppEnabled"] == YES) { #ifdef __SANDBOX_ENABLED__ - BOOL accessingSecurityScopedResource = [job.outputURL startAccessingSecurityScopedResource]; + BOOL accessingSecurityScopedResource = [item.outputURL startAccessingSecurityScopedResource]; #endif NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; @@ -982,7 +983,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; if (app) { - if (![workspace openFile:job.completeOutputURL.path withApplication:app]) + if (![workspace openFile:item.completeOutputURL.path withApplication:app]) { [HBUtilities writeToActivityLog:"Failed to send file to: %s", app]; } @@ -995,7 +996,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; #ifdef __SANDBOX_ENABLED__ if (accessingSecurityScopedResource) { - [job.outputURL stopAccessingSecurityScopedResource]; + [item.outputURL stopAccessingSecurityScopedResource]; } #endif } @@ -1004,7 +1005,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; /** * Runs the alert for a single job */ -- (void)jobCompletedAlerts:(HBJob *)job result:(HBCoreResult)result +- (void)itemCompletedAlerts:(HBQueueItem *)item result:(HBCoreResult)result { // Both the Notification and Sending to tagger can be done as encodes roll off the queue if ([[NSUserDefaults standardUserDefaults] integerForKey:@"HBAlertWhenDone"] == HBDoneActionNotification || @@ -1019,19 +1020,19 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; { title = NSLocalizedString(@"Put down that cocktailā€¦", @"Queue notification alert message"); description = [NSString stringWithFormat:NSLocalizedString(@"Your encode %@ is done!", @"Queue done notification message"), - job.outputFileName]; + item.outputFileName]; } else { title = NSLocalizedString(@"Encode failed", @"Queue done notification failed message"); description = [NSString stringWithFormat:NSLocalizedString(@"Your encode %@ couldn't be completed.", @"Queue done notification message"), - job.outputFileName]; + item.outputFileName]; } [self showNotificationWithTitle:title description:description - url:job.completeOutputURL + url:item.completeOutputURL playSound:playSound]; } } @@ -1095,10 +1096,10 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; */ - (IBAction)removeSelectedQueueItem:(id)sender { - if ([self.jobs beginTransaction] == HBDistributedArrayContentReload) + if ([self.items beginTransaction] == HBDistributedArrayContentReload) { // Do not execture the action if the array changed. - [self.jobs commit]; + [self.items commit]; return; } @@ -1109,18 +1110,18 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; // if this is a currently encoding job, we need to be sure to alert the user, // to let them decide to cancel it first, then if they do, we can come back and // remove it - NSIndexSet *workingIndexes = [self.jobs indexesOfObjectsUsingBlock:^BOOL(HBJob *item) { - return item.state == HBJobStateWorking; + NSIndexSet *workingIndexes = [self.items indexesOfObjectsUsingBlock:^BOOL(HBQueueItem *item) { + return item.state == HBQueueItemStateWorking; }]; if ([targetedRows containsIndexes:workingIndexes]) { [targetedRows removeIndexes:workingIndexes]; - NSArray *workingJobs = [self.jobs filteredArrayUsingBlock:^BOOL(HBJob *item) { - return item.state == HBJobStateWorking; + NSArray *workingItems = [self.items filteredArrayUsingBlock:^BOOL(HBQueueItem *item) { + return item.state == HBQueueItemStateWorking; }]; - if ([workingJobs containsObject:self.currentJob]) + if ([workingItems containsObject:self.currentItem]) { NSString *alertTitle = [NSString stringWithFormat:NSLocalizedString(@"Stop This Encode and Remove It?", @"Queue Stop Alert -> stop and remove message")]; @@ -1141,13 +1142,13 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; [alert beginSheetModalForWindow:targetWindow completionHandler:^(NSModalResponse returnCode) { if (returnCode == NSAlertSecondButtonReturn) { - [self.jobs beginTransaction]; + [self.items beginTransaction]; - NSInteger index = [self.jobs indexOfObject:self.currentJob]; - [self cancelCurrentJobAndContinue]; + NSInteger index = [self.items indexOfObject:self.currentItem]; + [self cancelCurrentItemAndContinue]; [self removeQueueItemAtIndex:index]; - [self.jobs commit]; + [self.items commit]; } }]; } @@ -1156,7 +1157,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; // remove the non working items immediately [self removeQueueItemsAtIndexes:targetedRows]; } - [self.jobs commit]; + [self.items commit]; } /** @@ -1169,7 +1170,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; NSUInteger currentIndex = [targetedRows firstIndex]; while (currentIndex != NSNotFound) { - NSURL *url = [[self.jobs objectAtIndex:currentIndex] completeOutputURL]; + NSURL *url = [[self.items objectAtIndex:currentIndex] completeOutputURL]; [urls addObject:url]; currentIndex = [targetedRows indexGreaterThanIndex:currentIndex]; } @@ -1184,7 +1185,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; NSUInteger currentIndex = [targetedRows firstIndex]; while (currentIndex != NSNotFound) { - NSURL *url = [[self.jobs objectAtIndex:currentIndex] fileURL]; + NSURL *url = [[self.items objectAtIndex:currentIndex] fileURL]; [urls addObject:url]; currentIndex = [targetedRows indexGreaterThanIndex:currentIndex]; } @@ -1242,7 +1243,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; { [self cancelRip:sender]; } - // If there are pending jobs in the queue, then this is a rip the queue + // If there are pending items in the queue, then this is a rip the queue else if (self.pendingItemsCount > 0) { // We check to see if we need to warn the user that the computer will go to sleep @@ -1255,9 +1256,9 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; } /** - * Displays an alert asking user if the want to cancel encoding of current job. + * Displays an alert asking user if the want to cancel encoding of current item. * Cancel: returns immediately after posting the alert. Later, when the user - * acknowledges the alert, doCancelCurrentJob is called. + * acknowledges the alert, doCancelCurrentItem is called. */ - (IBAction)cancelRip:(id)sender { @@ -1280,7 +1281,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; [alert beginSheetModalForWindow:window completionHandler:^(NSModalResponse returnCode) { if (returnCode == NSAlertSecondButtonReturn) { - [self cancelCurrentJobAndContinue]; + [self cancelCurrentItemAndContinue]; } else if (returnCode == NSAlertThirdButtonReturn) { @@ -1288,13 +1289,13 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; } else if (returnCode == NSAlertThirdButtonReturn + 1) { - [self cancelCurrentJobAndStop]; + [self cancelCurrentItemAndStop]; } }]; } /** - * Starts or cancels the processing of jobs depending on the current state + * Starts or cancels the processing of items depending on the current state */ - (IBAction)toggleStartCancel:(id)sender { @@ -1328,14 +1329,14 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; } /** - * Resets the job state to ready. + * Resets the item state to ready. */ - (IBAction)resetJobState:(id)sender { - if ([self.jobs beginTransaction] == HBDistributedArrayContentReload) + if ([self.items beginTransaction] == HBDistributedArrayContentReload) { // Do not execture the action if the array changed. - [self.jobs commit]; + [self.items commit]; return; } @@ -1344,47 +1345,47 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; NSUInteger currentIndex = [targetedRows firstIndex]; while (currentIndex != NSNotFound) { - HBJob *job = self.jobs[currentIndex]; + HBQueueItem *item = self.items[currentIndex]; - if (job.state == HBJobStateCanceled || job.state == HBJobStateCompleted || job.state == HBJobStateFailed) + if (item.state == HBQueueItemStateCanceled || item.state == HBQueueItemStateCompleted || item.state == HBQueueItemStateFailed) { - job.state = HBJobStateReady; + item.state = HBQueueItemStateReady; [updatedIndexes addIndex:currentIndex]; } currentIndex = [targetedRows indexGreaterThanIndex:currentIndex]; } [self reloadQueueItemsAtIndexes:updatedIndexes]; - [self.jobs commit]; + [self.items commit]; } -- (void)editQueueItem:(HBJob *)job +- (void)editQueueItem:(HBQueueItem *)item { - NSParameterAssert(job); - [self.jobs beginTransaction]; + NSParameterAssert(item); + [self.items beginTransaction]; - if (job != self.currentJob) + if (item != self.currentItem) { - job.state = HBJobStateWorking; + item.state = HBQueueItemStateWorking; - NSUInteger row = [self.jobs indexOfObject:job]; + NSUInteger row = [self.items indexOfObject:item]; [self reloadQueueItemAtIndex:row]; - [self.controller openJob:[job copy] completionHandler:^(BOOL result) { - [self.jobs beginTransaction]; + [self.controller openJob:[item.job copy] completionHandler:^(BOOL result) { + [self.items beginTransaction]; if (result) { // Now that source is loaded and settings applied, delete the queue item from the queue - NSInteger index = [self.jobs indexOfObject:job]; - job.state = HBJobStateReady; + NSInteger index = [self.items indexOfObject:item]; + item.state = HBQueueItemStateReady; [self removeQueueItemAtIndex:index]; } else { - job.state = HBJobStateFailed; + item.state = HBQueueItemStateFailed; NSBeep(); } - [self.jobs commit]; + [self.items commit]; }]; } else @@ -1392,7 +1393,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; NSBeep(); } - [self.jobs commit]; + [self.items commit]; } /** @@ -1400,21 +1401,21 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; */ - (IBAction)editSelectedQueueItem:(id)sender { - if ([self.jobs beginTransaction] == HBDistributedArrayContentReload) + if ([self.items beginTransaction] == HBDistributedArrayContentReload) { // Do not execture the action if the array changed. - [self.jobs commit]; + [self.items commit]; return; } NSInteger row = self.tableView.clickedRow; if (row != NSNotFound) { - // if this is a currently encoding job, we need to be sure to alert the user, + // if this is a currently encoding item, we need to be sure to alert the user, // to let them decide to cancel it first, then if they do, we can come back and // remove it - HBJob *job = self.jobs[row]; - if (job == self.currentJob) + HBQueueItem *item = self.items[row]; + if (item == self.currentItem) { NSString *alertTitle = [NSString stringWithFormat:NSLocalizedString(@"Stop This Encode and Edit It?", @"Queue Edit Alert -> stop and edit message")]; @@ -1435,37 +1436,37 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; [alert beginSheetModalForWindow:docWindow completionHandler:^(NSModalResponse returnCode) { if (returnCode == NSAlertSecondButtonReturn) { - [self editQueueItem:job]; + [self editQueueItem:item]; } }]; } - else if (job.state != HBJobStateWorking) + else if (item.state != HBQueueItemStateWorking) { - [self editQueueItem:job]; + [self editQueueItem:item]; } } - [self.jobs commit]; + [self.items commit]; } - (IBAction)clearAll:(id)sender { - [self.jobs beginTransaction]; - NSIndexSet *indexes = [self.jobs indexesOfObjectsUsingBlock:^BOOL(HBJob *item) { - return (item.state != HBJobStateWorking); + [self.items beginTransaction]; + NSIndexSet *indexes = [self.items indexesOfObjectsUsingBlock:^BOOL(HBQueueItem *item) { + return (item.state != HBQueueItemStateWorking); }]; [self removeQueueItemsAtIndexes:indexes]; - [self.jobs commit]; + [self.items commit]; } - (IBAction)clearCompleted:(id)sender { - [self.jobs beginTransaction]; - NSIndexSet *indexes = [self.jobs indexesOfObjectsUsingBlock:^BOOL(HBJob *item) { - return (item.state == HBJobStateCompleted); + [self.items beginTransaction]; + NSIndexSet *indexes = [self.items indexesOfObjectsUsingBlock:^BOOL(HBQueueItem *item) { + return (item.state == HBQueueItemStateCompleted); }]; [self removeQueueItemsAtIndexes:indexes]; - [self.jobs commit]; + [self.items commit]; } #pragma mark - NSTableView data source @@ -1475,25 +1476,23 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; row:(NSInteger)row { HBQueueItemView *view = [tableView makeViewWithIdentifier:@"MainCell" owner:self]; - HBJob *job = self.jobs[row]; + HBQueueItem *item = self.items[row]; - view.expanded = [self.expanded[job.uuid] boolValue]; view.delegate = self; - - view.job = job; + view.item = item; return view; } - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { - return self.jobs.count; + return self.items.count; } - (NSTableCellView *)dummyCell { if (!_dummyCell) { - _dummyCell = [self.tableView makeViewWithIdentifier:@"MainCell" owner: self]; + _dummyCell = [self.tableView makeViewWithIdentifier:@"MainCellForSizing" owner: self]; _dummyCellWidth = [NSLayoutConstraint constraintWithItem:_dummyCell attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual @@ -1508,15 +1507,14 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row { - HBJob *job = self.jobs[row]; - BOOL expanded = [self.expanded[job.uuid] boolValue]; + HBQueueItem *item = self.items[row]; - if (expanded) + if (item.expanded) { CGFloat width = tableView.frame.size.width; self.dummyCellWidth.constant = width; - self.dummyCell.textField.preferredMaxLayoutWidth = width; - self.dummyCell.textField.attributedStringValue = job.attributedDescription; + self.dummyCell.textField.preferredMaxLayoutWidth = width - 60; + self.dummyCell.textField.attributedStringValue = item.attributedDescription; CGFloat height = self.dummyCell.fittingSize.height; return height; @@ -1531,11 +1529,11 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; { NSMutableIndexSet *rowsToExpand = [NSMutableIndexSet indexSet]; [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger index, BOOL *stop) { - HBJob *job = self.jobs[index]; - BOOL expanded = [self.expanded[job.uuid] boolValue]; + HBQueueItem *item = self.items[index]; + BOOL expanded = item.expanded; if (expanded != expand) { - self.expanded[job.uuid] = @(!expanded); + item.expanded = !expanded; [rowsToExpand addIndex:index]; } @@ -1554,22 +1552,21 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; #pragma mark NSQueueItemView delegate -- (void)removeQueueItem:(nonnull HBJob *)job +- (void)removeQueueItem:(nonnull HBQueueItem *)item { - NSUInteger index = [self.jobs indexOfObject:job]; + NSUInteger index = [self.items indexOfObject:item]; [self removeQueueItemAtIndex:index]; } -- (void)revealQueueItem:(nonnull HBJob *)job +- (void)revealQueueItem:(nonnull HBQueueItem *)item { - [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[job.completeOutputURL]]; + [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[item.completeOutputURL]]; } -- (void)toggleQueueItemHeight:(nonnull HBJob *)job +- (void)toggleQueueItemHeight:(nonnull HBQueueItem *)item { - NSInteger row = [self.jobs indexOfObject:job]; - BOOL expanded = [self.expanded[job.uuid] boolValue]; - [self toggleRowsAtIndexes:[NSIndexSet indexSetWithIndex:row] expand:!expanded]; + NSInteger row = [self.items indexOfObject:item]; + [self toggleRowsAtIndexes:[NSIndexSet indexSetWithIndex:row] expand:!item.expanded]; } #pragma mark NSTableView delegate @@ -1593,9 +1590,9 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; - (BOOL)tableView:(NSTableView *)tableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard; { - NSArray *items = [self.jobs objectsAtIndexes:rowIndexes]; + NSArray *items = [self.items objectsAtIndexes:rowIndexes]; // Dragging is only allowed of the pending items. - if ([items[0] state] != HBJobStateReady) + if (items[0].state != HBQueueItemStateReady) { return NO; } @@ -1620,9 +1617,9 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; return NSDragOperationNone; } - // We do not let the user drop a pending job before or *above* - // already finished or currently encoding jobs. - NSInteger encodingRow = [self.jobs indexOfObject:self.currentJob]; + // We do not let the user drop a pending item before or *above* + // already finished or currently encoding items. + NSInteger encodingRow = [self.items indexOfObject:self.currentItem]; if (encodingRow != NSNotFound && row <= encodingRow) { return NSDragOperationNone; diff --git a/macosx/HBQueueItem.h b/macosx/HBQueueItem.h new file mode 100644 index 000000000..d62eee5fa --- /dev/null +++ b/macosx/HBQueueItem.h @@ -0,0 +1,55 @@ +// +// HBQueueItem.h +// HandBrake +// +// Created by Damiano Galassi on 07/02/2019. +// + +#import +#import "HBDistributedArray.h" + +@import HandBrakeKit; + +NS_ASSUME_NONNULL_BEGIN + +/** + * A flag to indicate the item's state + */ +typedef NS_ENUM(NSUInteger, HBQueueItemState){ + HBQueueItemStateReady, + HBQueueItemStateWorking, + HBQueueItemStateCompleted, + HBQueueItemStateCanceled, + HBQueueItemStateFailed +}; + +@interface HBQueueItem : NSObject + +- (instancetype)init NS_UNAVAILABLE; +- (instancetype)initWithJob:(HBJob *)job; + +/// Current state of the job. +@property (nonatomic, readwrite) HBQueueItemState state; + +/// The file URL of the source. +@property (nonatomic, readonly) NSURL *fileURL; + +/// The file URL at which the new file will be created. +@property (nonatomic, readwrite, copy, nullable) NSURL *outputURL; + +/// The name of the new file that will be created. +@property (nonatomic, readwrite, copy, nullable) NSString *outputFileName; + +/// The file URL at which the new file will be created. +@property (nonatomic, readwrite, copy, nullable) NSURL *completeOutputURL; + +@property (nonatomic, readonly) NSAttributedString *attributedTitleDescription; +@property (nonatomic, readonly) NSAttributedString *attributedDescription; + +@property (nonatomic, readwrite) BOOL expanded; + +@property (nonatomic, readonly) HBJob *job; + +@end + +NS_ASSUME_NONNULL_END diff --git a/macosx/HBQueueItem.m b/macosx/HBQueueItem.m new file mode 100644 index 000000000..3e993281f --- /dev/null +++ b/macosx/HBQueueItem.m @@ -0,0 +1,99 @@ +// +// HBQueueItem.m +// HandBrake +// +// Created by Damiano Galassi on 07/02/2019. +// + +#import "HBQueueItem.h" + +#import "HBCodingUtilities.h" + +@implementation HBQueueItem + +@synthesize job = _job; +@synthesize attributedDescription = _attributedDescription; +@synthesize attributedTitleDescription = _attributedTitleDescription; + +@synthesize uuid = _uuid; + +- (instancetype)initWithJob:(HBJob *)job +{ + self = [super init]; + if (self) + { + _job = job; + _uuid = [NSUUID UUID].UUIDString; + } + return self; +} + +#pragma mark - Properties + +- (NSURL *)fileURL +{ + return _job.fileURL; +} + +- (NSString *)outputFileName +{ + return _job.outputFileName; +} + +- (NSURL *)outputURL +{ + return _job.outputURL; +} + +- (NSURL *)completeOutputURL +{ + return _job.completeOutputURL; +} + +- (NSAttributedString *)attributedDescription +{ + if (_attributedDescription == nil) { + _attributedDescription = _job.attributedDescription; + } + return _attributedDescription; +} + +- (NSAttributedString *)attributedTitleDescription +{ + if (_attributedTitleDescription == nil) { + _attributedTitleDescription = _job.attributedTitleDescription; + } + return _attributedTitleDescription; +} + +#pragma mark - NSSecureCoding + ++ (BOOL)supportsSecureCoding +{ + return YES; +} + +static NSString *versionKey = @"HBQueueItemVersion"; + +- (void)encodeWithCoder:(nonnull NSCoder *)coder +{ + [coder encodeInt:1 forKey:versionKey]; + encodeObject(_job); + encodeObject(_uuid); +} + +- (nullable instancetype)initWithCoder:(nonnull NSCoder *)decoder +{ + int version = [decoder decodeIntForKey:versionKey]; + + if (version == 1 && (self = [super init])) + { + decodeObjectOrFail(_job, HBJob); + decodeObjectOrFail(_uuid, NSString); + return self; + } +fail: + return nil; +} + +@end diff --git a/macosx/HBQueueItemView.h b/macosx/HBQueueItemView.h index 1146ae294..907108f47 100644 --- a/macosx/HBQueueItemView.h +++ b/macosx/HBQueueItemView.h @@ -6,21 +6,21 @@ #import -@class HBJob; +@class HBQueueItem; NS_ASSUME_NONNULL_BEGIN @protocol HBQueueItemViewDelegate -- (void)revealQueueItem:(HBJob *)job; -- (void)removeQueueItem:(HBJob *)job; -- (void)toggleQueueItemHeight:(HBJob *)job; +- (void)revealQueueItem:(HBQueueItem *)job; +- (void)removeQueueItem:(HBQueueItem *)job; +- (void)toggleQueueItemHeight:(HBQueueItem *)job; @end @interface HBQueueItemView : NSTableCellView -@property (nonatomic, weak, nullable) HBJob *job; +@property (nonatomic, weak, nullable) HBQueueItem *item; @property (nonatomic, weak, nullable) id delegate; @property (nonatomic) BOOL expanded; diff --git a/macosx/HBQueueItemView.m b/macosx/HBQueueItemView.m index c5547124a..b6b8b80b1 100644 --- a/macosx/HBQueueItemView.m +++ b/macosx/HBQueueItemView.m @@ -5,8 +5,7 @@ It may be used under the terms of the GNU General Public License. */ #import "HBQueueItemView.h" -#import "HBJob.h" -#import "HBJob+UIAdditions.h" +#import "HBQueueItem.h" @interface HBQueueItemView () @@ -17,9 +16,9 @@ @implementation HBQueueItemView -- (void)setJob:(HBJob *)job +- (void)setItem:(HBQueueItem *)item { - _job = job; + _item = item; [self reload]; } @@ -38,12 +37,12 @@ { if (_expanded) { - self.textField.attributedStringValue = self.job.attributedDescription; + self.textField.attributedStringValue = self.item.attributedDescription; self.expandButton.state = NSOnState; } else { - self.textField.attributedStringValue = self.job.attributedTitleDescription; + self.textField.attributedStringValue = self.item.attributedTitleDescription; self.expandButton.state = NSOffState; } } @@ -51,17 +50,17 @@ - (void)HB_updateState { NSImage *state = nil; - switch (self.job.state) { - case HBJobStateCompleted: + switch (self.item.state) { + case HBQueueItemStateCompleted: state = [NSImage imageNamed:@"EncodeComplete"]; break; - case HBJobStateWorking: + case HBQueueItemStateWorking: state = [NSImage imageNamed:@"EncodeWorking0"]; break; - case HBJobStateCanceled: + case HBQueueItemStateCanceled: state = [NSImage imageNamed:@"EncodeCanceled"]; break; - case HBJobStateFailed: + case HBQueueItemStateFailed: state = [NSImage imageNamed:@"EncodeFailed"]; break; default: @@ -74,7 +73,14 @@ - (void)HB_updateRightButton { - if (self.job.state == HBJobStateCompleted) + BOOL darkAqua = NO; + + if (@available(macOS 10.14, *)) + { + darkAqua = [self.effectiveAppearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameDarkAqua]] == NSAppearanceNameDarkAqua ? YES : NO; + } + + if (self.item.state == HBQueueItemStateCompleted) { [_removeButton setAction: @selector(revealQueueItem:)]; if (self.backgroundStyle == NSBackgroundStyleEmphasized) @@ -84,7 +90,7 @@ } else { - [_removeButton setImage:[NSImage imageNamed:@"Reveal"]]; + [_removeButton setImage:[NSImage imageNamed:darkAqua ? @"RevealHighlight" : @"Reveal"]]; } } else @@ -97,7 +103,7 @@ } else { - [_removeButton setImage:[NSImage imageNamed:@"Delete"]]; + [_removeButton setImage:[NSImage imageNamed:darkAqua ? @"DeleteHighlight" : @"Delete"]]; } } } @@ -112,14 +118,14 @@ { self.expandButton.state = NSOnState; self.expanded = YES; - self.textField.attributedStringValue = self.job.attributedDescription; + self.textField.attributedStringValue = self.item.attributedDescription; } - (void)collapse { self.expandButton.state = NSOffState; self.expanded = NO; - self.textField.attributedStringValue = self.job.attributedTitleDescription; + self.textField.attributedStringValue = self.item.attributedTitleDescription; } - (BOOL)isFlipped @@ -127,19 +133,24 @@ return YES; } +- (void)viewDidChangeEffectiveAppearance +{ + [self HB_updateRightButton]; +} + - (IBAction)revealQueueItem:(id)sender { - [self.delegate revealQueueItem:self.job]; + [self.delegate revealQueueItem:self.item]; } - (IBAction)removeQueueItem:(id)sender { - [self.delegate removeQueueItem:self.job]; + [self.delegate removeQueueItem:self.item]; } - (IBAction)toggleHeight:(id)sender { - [self.delegate toggleQueueItemHeight:self.job]; + [self.delegate toggleQueueItemHeight:self.item]; } @end diff --git a/macosx/HandBrake.xcodeproj/project.pbxproj b/macosx/HandBrake.xcodeproj/project.pbxproj index d656fb130..f19a4e4fc 100644 --- a/macosx/HandBrake.xcodeproj/project.pbxproj +++ b/macosx/HandBrake.xcodeproj/project.pbxproj @@ -83,8 +83,6 @@ A91119A21C7DD58B001C463C /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273F203B14ADBC210021BE6D /* Cocoa.framework */; }; A91119A31C7DD591001C463C /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273F202214ADB8650021BE6D /* IOKit.framework */; }; A91119A41C7DD614001C463C /* HBSubtitlesDefaults.h in Headers */ = {isa = PBXBuildFile; fileRef = A9F4728B1976BAA70009EC65 /* HBSubtitlesDefaults.h */; settings = {ATTRIBUTES = (Public, ); }; }; - A91119A51C7DD644001C463C /* HBDistributedArray.h in Headers */ = {isa = PBXBuildFile; fileRef = A9E66D6E1A67A2A8007B641D /* HBDistributedArray.h */; settings = {ATTRIBUTES = (Public, ); }; }; - A91119A61C7DD64A001C463C /* HBDistributedArray.m in Sources */ = {isa = PBXBuildFile; fileRef = A9E66D6F1A67A2A8007B641D /* HBDistributedArray.m */; }; A91485FE1F61296100374C12 /* HBFiltersViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A91485FD1F61296100374C12 /* HBFiltersViewController.m */; }; A914BCB31BC441C700157917 /* HBPreviewView.m in Sources */ = {isa = PBXBuildFile; fileRef = A914BCB21BC441C700157917 /* HBPreviewView.m */; }; A916180E1C845161000556C6 /* NSDictionary+HBAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = A93B0DF71C804CF50051A3FA /* NSDictionary+HBAdditions.m */; }; @@ -201,6 +199,8 @@ A95121E61B5F7BE700FD773D /* NSArray+HBAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = A95121E51B5F7BE700FD773D /* NSArray+HBAdditions.m */; }; A955128B1A320B02001BFC6F /* libjansson.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A95512881A320A12001BFC6F /* libjansson.a */; }; A957EBCD218DBE5900007988 /* HBAutoNamer.m in Sources */ = {isa = PBXBuildFile; fileRef = A957EBCC218DBE5900007988 /* HBAutoNamer.m */; }; + A95BA15D220C968500A2F9F9 /* HBQueueItem.m in Sources */ = {isa = PBXBuildFile; fileRef = A95BA15C220C968500A2F9F9 /* HBQueueItem.m */; }; + A95BA161220CA5DB00A2F9F9 /* HBDistributedArray.m in Sources */ = {isa = PBXBuildFile; fileRef = A95BA160220CA5DB00A2F9F9 /* HBDistributedArray.m */; }; A95BC1E71CD2548A008D6A33 /* volHighTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = A95BC1E51CD2548A008D6A33 /* volHighTemplate.pdf */; }; A95BC1E81CD2548A008D6A33 /* volLowTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = A95BC1E61CD2548A008D6A33 /* volLowTemplate.pdf */; }; A96664B01CCE45BF00DA4A57 /* HBPlayerHUDController.m in Sources */ = {isa = PBXBuildFile; fileRef = A96664AE1CCE45BF00DA4A57 /* HBPlayerHUDController.m */; }; @@ -506,6 +506,10 @@ A957EBCC218DBE5900007988 /* HBAutoNamer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HBAutoNamer.m; sourceTree = ""; }; A9597A281A49749D00007771 /* HBRange+UIAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HBRange+UIAdditions.h"; sourceTree = ""; }; A9597A291A49749D00007771 /* HBRange+UIAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "HBRange+UIAdditions.m"; sourceTree = ""; }; + A95BA15B220C968500A2F9F9 /* HBQueueItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HBQueueItem.h; sourceTree = ""; }; + A95BA15C220C968500A2F9F9 /* HBQueueItem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HBQueueItem.m; sourceTree = ""; }; + A95BA15F220CA5DB00A2F9F9 /* HBDistributedArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBDistributedArray.h; sourceTree = ""; }; + A95BA160220CA5DB00A2F9F9 /* HBDistributedArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBDistributedArray.m; sourceTree = ""; }; A95BC1E51CD2548A008D6A33 /* volHighTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = volHighTemplate.pdf; sourceTree = ""; }; A95BC1E61CD2548A008D6A33 /* volLowTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = volLowTemplate.pdf; sourceTree = ""; }; A95CB2FB217B6D07001E9F51 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; @@ -657,8 +661,6 @@ A9E2FD241A21BC4A000E8D3F /* HBAddPresetController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBAddPresetController.h; sourceTree = ""; }; A9E2FD251A21BC4A000E8D3F /* HBAddPresetController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBAddPresetController.m; sourceTree = ""; }; A9E52CD7218DD52A00E17B86 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/ExceptionAlert.xib; sourceTree = ""; }; - A9E66D6E1A67A2A8007B641D /* HBDistributedArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HBDistributedArray.h; path = ../HBDistributedArray.h; sourceTree = ""; }; - A9E66D6F1A67A2A8007B641D /* HBDistributedArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HBDistributedArray.m; path = ../HBDistributedArray.m; sourceTree = ""; }; A9EA43661A2210C400785E95 /* HBTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBTableView.h; sourceTree = ""; }; A9EA43671A2210C400785E95 /* HBTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBTableView.m; sourceTree = ""; }; A9F217E41E2F897D00C10C6E /* HandBrake.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HandBrake.entitlements; sourceTree = ""; }; @@ -1019,6 +1021,8 @@ A901C2401BC7CFDC00D77735 /* Queue */ = { isa = PBXGroup; children = ( + A95BA15B220C968500A2F9F9 /* HBQueueItem.h */, + A95BA15C220C968500A2F9F9 /* HBQueueItem.m */, A9D3634F2209C08500D8EFEA /* HBQueueItemView.h */, A9D363502209C08500D8EFEA /* HBQueueItemView.m */, A9EA43661A2210C400785E95 /* HBTableView.h */, @@ -1077,6 +1081,8 @@ children = ( A9706CB21AC1436F00BAEAA8 /* HBApplication.h */, A9706CB31AC1436F00BAEAA8 /* HBApplication.m */, + A95BA15F220CA5DB00A2F9F9 /* HBDistributedArray.h */, + A95BA160220CA5DB00A2F9F9 /* HBDistributedArray.m */, A9706CB51AC1437800BAEAA8 /* HBExceptionAlertController.h */, A9706CB61AC1437800BAEAA8 /* HBExceptionAlertController.m */, A9E52CD6218DD52A00E17B86 /* ExceptionAlert.xib */, @@ -1162,8 +1168,6 @@ children = ( A98C29C51977C00000AF5DED /* Core */, A952392E199A647F00588AEF /* Presets */, - A9E66D6E1A67A2A8007B641D /* HBDistributedArray.h */, - A9E66D6F1A67A2A8007B641D /* HBDistributedArray.m */, A9AA44781970664A00D7DEFC /* HBUtilities.h */, A9AA44791970664A00D7DEFC /* HBUtilities.m */, A9736F041C7DA5FE008F1D18 /* HandBrakeKit.h */, @@ -1383,7 +1387,6 @@ A91CE2DB1C7DAEEE0068F46F /* HBVideo.h in Headers */, A91CE2DC1C7DAEEE0068F46F /* HBPicture.h in Headers */, A91CE2DD1C7DAEEE0068F46F /* HBFilters.h in Headers */, - A91119A51C7DD644001C463C /* HBDistributedArray.h in Headers */, A91CE2DE1C7DAEEE0068F46F /* HBChapter.h in Headers */, A91CE2DF1C7DAEEE0068F46F /* HBAudio.h in Headers */, A91CE2E01C7DAEEE0068F46F /* HBAudioTrack.h in Headers */, @@ -1669,6 +1672,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + A95BA161220CA5DB00A2F9F9 /* HBDistributedArray.m in Sources */, A916C99B1C844A0800C7B560 /* HBTableView.m in Sources */, A916C9991C8449E200C7B560 /* main.mm in Sources */, A973E10C216E74E900D498EC /* HBThumbnailItemView.m in Sources */, @@ -1707,6 +1711,7 @@ 273F20B214ADBE670021BE6D /* HBImageAndTextCell.m in Sources */, 273F20B314ADBE670021BE6D /* HBOutputPanelController.m in Sources */, 273F20B414ADBE670021BE6D /* HBOutputRedirect.m in Sources */, + A95BA15D220C968500A2F9F9 /* HBQueueItem.m in Sources */, A9D0FA771C1C284D0003F2A9 /* HBFocusRingView.m in Sources */, A9D0FA7A1C1C36820003F2A9 /* HBTabView.m in Sources */, A91AFD0C1A948827009BECED /* HBOutputFileWriter.m in Sources */, @@ -1757,7 +1762,6 @@ A91CE2A21C7DA7320068F46F /* HBVideo+UIAdditions.m in Sources */, A91CE2A41C7DA7320068F46F /* HBPicture+UIAdditions.m in Sources */, A91D54881E378ABD006D0997 /* HBSecurityAccessToken.m in Sources */, - A91119A61C7DD64A001C463C /* HBDistributedArray.m in Sources */, A91CE2A61C7DA7320068F46F /* HBFilters+UIAdditions.m in Sources */, A91CE2A81C7DA7320068F46F /* HBDVDDetector.m in Sources */, A91CE2AD1C7DA7320068F46F /* HBStateFormatter.m in Sources */, diff --git a/macosx/HandBrake.xcodeproj/xcshareddata/xcschemes/HandBrake-Release-Sandbox.xcscheme b/macosx/HandBrake.xcodeproj/xcshareddata/xcschemes/HandBrake-Release-Sandbox.xcscheme index a3433f97b..1e04e9b67 100644 --- a/macosx/HandBrake.xcodeproj/xcshareddata/xcschemes/HandBrake-Release-Sandbox.xcscheme +++ b/macosx/HandBrake.xcodeproj/xcshareddata/xcschemes/HandBrake-Release-Sandbox.xcscheme @@ -109,15 +109,16 @@ savedToolIdentifier = "" useCustomWorkingDirectory = "NO" debugDocumentVersioning = "YES"> - + - + diff --git a/macosx/HandBrakeKit/HandBrakeKit.h b/macosx/HandBrakeKit/HandBrakeKit.h index d5a684d34..3e388855c 100644 --- a/macosx/HandBrakeKit/HandBrakeKit.h +++ b/macosx/HandBrakeKit/HandBrakeKit.h @@ -36,7 +36,6 @@ FOUNDATION_EXPORT const unsigned char HandBrakeKitVersionString[]; #import #import -#import #import #import -- cgit v1.2.3