Added back the progress info in the queue, and refactored the SBQueueItem creation method. Added an edit contextual menu item.
This commit is contained in:
1 parent
49954c92f7
commit
494f2f537e
6 files changed
+89
-65
No files matched your search
+1
-3
@@ -32,9 +32,9 @@ extern NSString *SBQueueCancelledNotification;
|
||||
SBQueueStatus _status;
|
||||
|
||||
MP42File *_currentMP4;
|
||||
NSUInteger _currentIndex;
|
||||
NSMutableArray *_items;
|
||||
NSURL *_URL;
|
||||
NSURL *_destination;
|
||||
|
||||
IOPMAssertionID _assertionID;
|
||||
IOReturn _io_success;
|
||||
@@ -44,8 +44,6 @@ extern NSString *SBQueueCancelledNotification;
|
||||
}
|
||||
|
||||
@property (atomic, readonly) SBQueueStatus status;
|
||||
|
||||
@property (atomic, copy) NSURL *destination;
|
||||
@property (atomic) BOOL optimize;
|
||||
|
||||
- (instancetype)initWithURL:(NSURL *)queueURL;
|
||||
|
||||
+41
-41
@@ -16,8 +16,6 @@
|
||||
#import <MP42Foundation/MP42Image.h>
|
||||
#import <MP42Foundation/MP42Utilities.h>
|
||||
|
||||
static NSString *fileType = @"mp4";
|
||||
|
||||
NSString *SBQueueWorkingNotification = @"SBQueueWorkingNotification";
|
||||
NSString *SBQueueCompletedNotification = @"SBQueueCompletedNotification";
|
||||
NSString *SBQueueFailedNotification = @"SBQueueFailedNotification";
|
||||
@@ -30,14 +28,18 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
@property (nonatomic, copy) NSURL *URL;
|
||||
@property (nonatomic, retain) NSMutableArray *items;
|
||||
|
||||
@property (atomic, retain) MP42File *currentMP4;
|
||||
@property (nonatomic) NSUInteger currentIndex;
|
||||
|
||||
@property (nonatomic) dispatch_queue_t queue;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SBQueue
|
||||
|
||||
@synthesize status = _status, destination = _destination;
|
||||
@synthesize status = _status;
|
||||
@synthesize optimize = _optimize;
|
||||
@synthesize currentMP4 = _currentMP4, currentIndex = _currentIndex;
|
||||
@synthesize items = _items, URL = _URL, queue = _queue;
|
||||
|
||||
- (instancetype)initWithURL:(NSURL *)queueURL {
|
||||
@@ -151,6 +153,9 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Starts the queue.
|
||||
*/
|
||||
- (void)start {
|
||||
if (self.status == SBQueueStatusWorking) {
|
||||
return;
|
||||
@@ -169,6 +174,11 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
@autoreleasepool {
|
||||
__block SBQueueItem *item = nil;
|
||||
|
||||
// Save the queue
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self saveQueueToDisk];
|
||||
});
|
||||
|
||||
// Get the first item available in the queue
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
item = [[self firstItemInQueue] retain];
|
||||
@@ -179,7 +189,7 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
break;
|
||||
}
|
||||
|
||||
[self handleSBStatusWorking];
|
||||
[self handleSBStatusWorking:0];
|
||||
noErr = [self processItem:item error:&outError];
|
||||
|
||||
// Check results
|
||||
@@ -190,7 +200,7 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
break;
|
||||
} else if (noErr) {
|
||||
if (self.optimize) {
|
||||
noErr = [_currentMP4 optimize];
|
||||
noErr = [self.currentMP4 optimize];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,18 +208,9 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
item.status = SBQueueItemStatusCompleted;
|
||||
} else {
|
||||
item.status = SBQueueItemStatusFailed;
|
||||
if (outError) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[NSApp presentError:outError];
|
||||
});
|
||||
}
|
||||
[self handleSBStatusFailed:outError];
|
||||
}
|
||||
|
||||
// Save the queue
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self saveQueueToDisk];
|
||||
});
|
||||
|
||||
[item release];
|
||||
}
|
||||
|
||||
@@ -242,40 +243,33 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
|
||||
BOOL noErr = YES;
|
||||
|
||||
_currentMP4 = [item mp4File];
|
||||
[_currentMP4 setDelegate:self];
|
||||
|
||||
// Set the destination url
|
||||
if (![item destURL]) {
|
||||
if (!_currentMP4 && self.destination /*&& customDestination*/) {
|
||||
item.destURL = [[[self.destination URLByAppendingPathComponent:[item.URL lastPathComponent]] URLByDeletingPathExtension] URLByAppendingPathExtension:fileType];
|
||||
} else {
|
||||
item.destURL = [[item.URL URLByDeletingPathExtension] URLByAppendingPathExtension:fileType];
|
||||
}
|
||||
}
|
||||
self.currentMP4 = [item mp4File];
|
||||
self.currentIndex = [self.items indexOfObject:item];
|
||||
|
||||
// The file has been added directly to the queue
|
||||
if (!_currentMP4 && item.URL) {
|
||||
[item prepareItem:outError];
|
||||
_currentMP4 = item.mp4File;
|
||||
self.currentMP4 = item.mp4File;
|
||||
}
|
||||
|
||||
self.currentMP4.delegate = self;
|
||||
|
||||
NSDictionary *dict = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[_currentMP4.URL path] error:NULL];
|
||||
NSNumber *freeSpace = [dict objectForKey:NSFileSystemFreeSize];
|
||||
if (freeSpace && [_currentMP4 dataSize] > [freeSpace longLongValue]) {
|
||||
NSLog(@"Not enough disk space");
|
||||
}
|
||||
|
||||
// We have an existing mp4 file, update it
|
||||
if (!_cancelled) {
|
||||
if ([_currentMP4 hasFileRepresentation])
|
||||
noErr = [_currentMP4 updateMP4FileWithAttributes:attributes error:outError];
|
||||
// Write the new file to disk
|
||||
else if (_currentMP4 && item.destURL) {
|
||||
[attributes addEntriesFromDictionary:[item attributes]];
|
||||
noErr = [_currentMP4 writeToUrl:[item destURL]
|
||||
withAttributes:attributes
|
||||
error:outError];
|
||||
if ([self.currentMP4 hasFileRepresentation]) {
|
||||
// We have an existing mp4 file, update it
|
||||
noErr = [self.currentMP4 updateMP4FileWithAttributes:attributes error:outError];
|
||||
} else if (self.currentMP4 && item.destURL) {
|
||||
// Write the new file to disk
|
||||
[attributes addEntriesFromDictionary:item.attributes];
|
||||
noErr = [self.currentMP4 writeToUrl:item.destURL
|
||||
withAttributes:attributes
|
||||
error:outError];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,20 +282,26 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
return noErr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the queue and abort the current work.
|
||||
*/
|
||||
- (void)stop {
|
||||
_cancelled = YES;
|
||||
[self.currentMP4 cancel];
|
||||
}
|
||||
|
||||
- (void)progressStatus:(CGFloat)progress {
|
||||
NSLog(@"%f", progress);
|
||||
[self handleSBStatusWorking:progress];
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes SBQueueStatusWorking state information. Current implementation just
|
||||
* sends SBQueueWorkingNotification.
|
||||
*/
|
||||
- (void)handleSBStatusWorking {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SBQueueWorkingNotification object:self];
|
||||
- (void)handleSBStatusWorking:(CGFloat)progress {
|
||||
NSString *info = [NSString stringWithFormat:@"Processing file %ld of %lu.",(long)self.currentIndex + 1, (unsigned long)[self.items count]];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SBQueueWorkingNotification object:self userInfo:@{@"ProgressString": info,
|
||||
@"Progress": @(progress)}];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -317,9 +317,9 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
* Processes SBQueueStatusFailed state information. Current implementation just
|
||||
* sends SBQueueFailedNotification.
|
||||
*/
|
||||
- (void)handleSBStatusFailed {
|
||||
- (void)handleSBStatusFailed:(NSError *)error {
|
||||
self.status = SBQueueStatusFailed;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SBQueueFailedNotification object:self];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SBQueueFailedNotification object:self userInfo:@{@"Error" : error}];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,9 +46,6 @@
|
||||
|
||||
+ (SBQueueController *)sharedManager;
|
||||
|
||||
- (void)start:(id)sender;
|
||||
- (void)stop:(id)sender;
|
||||
|
||||
- (void)addItem:(SBQueueItem *)item;
|
||||
|
||||
- (BOOL)saveQueueToDisk;
|
||||
|
||||
+38
-17
@@ -13,6 +13,7 @@
|
||||
|
||||
#import <MP42Foundation/MP42Utilities.h>
|
||||
|
||||
static NSString *fileType = @"mp4";
|
||||
|
||||
#define SublerBatchTableViewDataType @"SublerBatchTableViewDataType"
|
||||
#define kOptionsPanelHeight 88
|
||||
@@ -21,6 +22,9 @@
|
||||
|
||||
@property (readonly) SBQueue *queue;
|
||||
|
||||
- (void)start:(id)sender;
|
||||
- (void)stop:(id)sender;
|
||||
|
||||
- (void)updateUI;
|
||||
- (void)updateDockTile;
|
||||
- (NSURL *)queueURL;
|
||||
@@ -86,16 +90,21 @@
|
||||
|
||||
[_tableView registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, SublerBatchTableViewDataType, nil]];
|
||||
|
||||
// Register to the queue notifications
|
||||
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserverForName:SBQueueWorkingNotification object:nil queue:mainQueue usingBlock:^(NSNotification *note) {
|
||||
[_countLabel setStringValue:@"Working"];
|
||||
NSDictionary *info = [note userInfo];
|
||||
[_countLabel setStringValue:[info valueForKey:@"ProgressString"]];
|
||||
[_progressIndicator setIndeterminate:NO];
|
||||
[_progressIndicator setDoubleValue:[[info valueForKey:@"Progress"] doubleValue]];
|
||||
}];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserverForName:SBQueueCompletedNotification object:nil queue:mainQueue usingBlock:^(NSNotification *note) {
|
||||
[_progressIndicator setHidden:YES];
|
||||
[_progressIndicator stopAnimation:self];
|
||||
[_progressIndicator setDoubleValue:0];
|
||||
[_progressIndicator setIndeterminate:YES];
|
||||
[_start setTitle:@"Start"];
|
||||
[_countLabel setStringValue:@"Done"];
|
||||
|
||||
@@ -103,6 +112,11 @@
|
||||
[self updateUI];
|
||||
}];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserverForName:SBQueueFailedNotification object:nil queue:mainQueue usingBlock:^(NSNotification *note) {
|
||||
NSDictionary *info = [note userInfo];
|
||||
[NSApp presentError:[info valueForKey:@"Error"]];
|
||||
}];
|
||||
|
||||
[self updateUI];
|
||||
}
|
||||
|
||||
@@ -278,15 +292,7 @@
|
||||
NSMutableArray *items = [[NSMutableArray alloc] init];
|
||||
|
||||
for (NSURL *url in [panel URLs]) {
|
||||
SBQueueItem *item = [SBQueueItem itemWithURL:url];
|
||||
if ([_metadataOption state] == NSOnState) {
|
||||
[item addAction:[[[SBQueueMetadataAction alloc] init] autorelease]];
|
||||
[item addAction:[[[SBQueueSubtitlesAction alloc] init] autorelease]];
|
||||
}
|
||||
if ([_organizeGroupsOption state] == NSOnState) {
|
||||
[item addAction:[[[SBQueueOrganizeGroupsAction alloc] init] autorelease]];
|
||||
}
|
||||
|
||||
SBQueueItem *item = [self createItemWithURL:url];
|
||||
[items addObject:item];
|
||||
}
|
||||
|
||||
@@ -412,20 +418,19 @@
|
||||
}
|
||||
|
||||
- (IBAction)edit:(id)sender {
|
||||
/*SBQueueItem *item = [[self.queue itemAtIndex:[tableView clickedRow]] retain];
|
||||
SBQueueItem *item = [[self.queue itemAtIndex:[_tableView clickedRow]] retain];
|
||||
|
||||
[self removeItems:[NSArray arrayWithObject:item]];
|
||||
[self updateUI];
|
||||
|
||||
MP42File *mp4;
|
||||
if (!item.mp4File)
|
||||
mp4 = [self prepareQueueItem:item.URL error:NULL];
|
||||
else
|
||||
mp4 = item.mp4File;
|
||||
[item prepareItem:NULL];
|
||||
|
||||
MP42File *mp4 = item.mp4File;
|
||||
|
||||
SBDocument *doc = [[NSDocumentController sharedDocumentController] openUntitledDocumentAndDisplay:YES error:NULL];
|
||||
[doc setMp4File:mp4];
|
||||
[item release];*/
|
||||
[item release];
|
||||
}
|
||||
|
||||
- (IBAction)showInFinder:(id)sender {
|
||||
@@ -546,7 +551,7 @@
|
||||
NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
|
||||
|
||||
for (NSURL *url in items) {
|
||||
[queueItems addObject:[SBQueueItem itemWithURL:url]];
|
||||
[queueItems addObject:[self createItemWithURL:url]];
|
||||
[indexes addIndex:row];
|
||||
}
|
||||
|
||||
@@ -566,6 +571,22 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (SBQueueItem *)createItemWithURL:(NSURL *)url {
|
||||
SBQueueItem *item = [SBQueueItem itemWithURL:url];
|
||||
|
||||
if ([_metadataOption state] == NSOnState) {
|
||||
[item addAction:[[[SBQueueMetadataAction alloc] init] autorelease]];
|
||||
[item addAction:[[[SBQueueSubtitlesAction alloc] init] autorelease]];
|
||||
}
|
||||
if ([_organizeGroupsOption state] == NSOnState) {
|
||||
[item addAction:[[[SBQueueOrganizeGroupsAction alloc] init] autorelease]];
|
||||
}
|
||||
|
||||
item.destURL = [[[_destination URLByAppendingPathComponent:[url lastPathComponent]] URLByDeletingPathExtension] URLByAppendingPathExtension:fileType];
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
- (void)addItem:(SBQueueItem *)item {
|
||||
[self addItems:[NSArray arrayWithObject:item] atIndexes:nil];
|
||||
[self updateUI];
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
typedef enum SBQueueItemStatus : NSInteger {
|
||||
SBQueueItemtatusUnknown = 0,
|
||||
SBQueueItemStatusReady,
|
||||
SBQueueItemStatusEditing,
|
||||
SBQueueItemStatusWorking,
|
||||
SBQueueItemStatusCompleted,
|
||||
SBQueueItemStatusFailed,
|
||||
@@ -34,7 +35,7 @@ typedef enum SBQueueItemStatus : NSInteger {
|
||||
@property (nonatomic, readonly) MP42File *mp4File;
|
||||
@property (nonatomic, readonly) NSDictionary *attributes;
|
||||
@property (nonatomic, readonly) NSURL *URL;
|
||||
@property (nonatomic, retain, readwrite) NSURL *destURL;
|
||||
@property (nonatomic, copy, readwrite) NSURL *destURL;
|
||||
|
||||
@property (nonatomic, readwrite) SBQueueItemStatus status;
|
||||
|
||||
|
||||
@@ -256,6 +256,13 @@
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="U9H-ZG-j7u"/>
|
||||
<menuItem title="Edit…" id="qHz-Zh-l5L">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="edit:" target="-2" id="4Pr-Wx-RXw"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="NnU-9u-KGQ"/>
|
||||
<menuItem title="Reveal in Finder" id="8gi-57-i6u">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
|
||||
Reference in new issue
Block a user