Reworked things to use a progress block for MP42File progress

This commit is contained in:
Damiano Galassi committed 2015-09-07 11:46:10 +02:00
1 parent f6b0962970
commit be3481e2bc
4 files changed
+24 -22

No files matched your search

+15 -14
View File
@@ -26,7 +26,7 @@
#define SublerTableViewDataType @"SublerTableViewDataType" #define SublerTableViewDataType @"SublerTableViewDataType"
@interface SBDocument () <NSTableViewDelegate, MP42FileDelegate, SBFileImportDelegate, SBMetadataSearchControllerDelegate> @interface SBDocument () <NSTableViewDelegate, SBFileImportDelegate, SBMetadataSearchControllerDelegate>
@property (nonatomic, retain) MP42File *mp4; @property (nonatomic, retain) MP42File *mp4;
@@ -75,7 +75,7 @@
- (instancetype)initWithType:(NSString *)typeName error:(NSError **)outError - (instancetype)initWithType:(NSString *)typeName error:(NSError **)outError
{ {
if (self = [super initWithType:typeName error:outError]) { if (self = [super initWithType:typeName error:outError]) {
self.mp4 = [[[MP42File alloc] initWithDelegate:self] autorelease]; self.mp4 = [[[MP42File alloc] init] autorelease];
} }
return self; return self;
@@ -96,7 +96,7 @@
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError - (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
{ {
self.mp4 = [[[MP42File alloc] initWithURL:absoluteURL delegate:self] autorelease]; self.mp4 = [[[MP42File alloc] initWithURL:absoluteURL] autorelease];
if (outError != NULL && !self.mp4) { if (outError != NULL && !self.mp4) {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL]; *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
@@ -109,7 +109,7 @@
- (BOOL)revertToContentsOfURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError - (BOOL)revertToContentsOfURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
{ {
self.mp4 = [[[MP42File alloc] initWithURL:absoluteURL delegate:self] autorelease]; self.mp4 = [[[MP42File alloc] initWithURL:absoluteURL] autorelease];
[fileTracksTable reloadData]; [fileTracksTable reloadData];
[self reloadPropertyView]; [self reloadPropertyView];
@@ -174,6 +174,13 @@
BOOL result = NO; BOOL result = NO;
NSDictionary<NSString *, NSNumber *> *attributes = [self saveAttributes]; NSDictionary<NSString *, NSNumber *> *attributes = [self saveAttributes];
self.mp4.progressHandler = ^(double progress){
dispatch_async(dispatch_get_main_queue(), ^{
[optBar setIndeterminate:NO];
[optBar setDoubleValue:progress];
});
};
switch (saveOperation) { switch (saveOperation) {
case NSSaveOperation: case NSSaveOperation:
// movie file already exists, so we'll just update // movie file already exists, so we'll just update
@@ -199,6 +206,8 @@
_optimize = NO; _optimize = NO;
} }
self.mp4.progressHandler = nil;
if (io_success == kIOReturnSuccess) { if (io_success == kIOReturnSuccess) {
IOPMAssertionRelease(assertionID); IOPMAssertionRelease(assertionID);
} }
@@ -207,7 +216,7 @@
MP42File *reloadedFile = nil; MP42File *reloadedFile = nil;
if (result == YES) { if (result == YES) {
reloadedFile = [[MP42File alloc] initWithURL:[NSURL fileURLWithPath:url.path] delegate:self]; reloadedFile = [[MP42File alloc] initWithURL:[NSURL fileURLWithPath:url.path]];
} }
dispatch_sync(dispatch_get_main_queue(), ^{ dispatch_sync(dispatch_get_main_queue(), ^{
@@ -324,14 +333,6 @@
#pragma mark - Interface validation #pragma mark - Interface validation
- (void)progressStatus:(CGFloat)progress
{
dispatch_async(dispatch_get_main_queue(), ^{
[optBar setIndeterminate:NO];
[optBar setDoubleValue:progress];
});
}
- (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem - (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem
{ {
SEL action = [anItem action]; SEL action = [anItem action];
@@ -816,7 +817,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
} }
else { else {
MP42File *file = nil; MP42File *file = nil;
if ((file = [[MP42File alloc] initWithURL:URL delegate:self])) { if ((file = [[MP42File alloc] initWithURL:URL])) {
[self.mp4.metadata mergeMetadata:file.metadata]; [self.mp4.metadata mergeMetadata:file.metadata];
[file release]; [file release];
} }
+1 -1
View File
@@ -240,7 +240,7 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
[self.currentItem cancel]; [self.currentItem cancel];
} }
- (void)progressStatus:(CGFloat)progress { - (void)progressStatus:(double)progress {
[self handleSBStatusWorking:progress index:-1]; [self handleSBStatusWorking:progress index:-1];
} }
+7 -6
View File
@@ -15,7 +15,7 @@
#define ALMOST_4GiB 4000000000 #define ALMOST_4GiB 4000000000
@interface SBQueueItem () <MP42FileDelegate> @interface SBQueueItem ()
@property (nonatomic, readwrite) NSString *localizedWorkingDescription; @property (nonatomic, readwrite) NSString *localizedWorkingDescription;
@@ -179,7 +179,7 @@
[self.URL getResourceValue:&type forKey:NSURLTypeIdentifierKey error:outError]; [self.URL getResourceValue:&type forKey:NSURLTypeIdentifierKey error:outError];
if ([type isEqualToString:@"com.apple.m4a-audio"] || [type isEqualToString:@"com.apple.m4v-video"] || [type isEqualToString:@"public.mpeg-4"]) { if ([type isEqualToString:@"com.apple.m4a-audio"] || [type isEqualToString:@"com.apple.m4v-video"] || [type isEqualToString:@"public.mpeg-4"]) {
self.mp4File = [[[MP42File alloc] initWithURL:self.URL delegate:nil] autorelease]; self.mp4File = [[[MP42File alloc] initWithURL:self.URL] autorelease];
} else { } else {
self.mp4File = [[[MP42File alloc] init] autorelease]; self.mp4File = [[[MP42File alloc] init] autorelease];
MP42FileImporter *fileImporter = [[MP42FileImporter alloc] initWithURL:self.URL error:outError]; MP42FileImporter *fileImporter = [[MP42FileImporter alloc] initWithURL:self.URL error:outError];
@@ -261,7 +261,7 @@
for (id<SBQueueActionProtocol> action in self.actions) { for (id<SBQueueActionProtocol> action in self.actions) {
self.localizedWorkingDescription = action.localizedDescription; self.localizedWorkingDescription = action.localizedDescription;
[self progressStatus:0]; [self.delegate progressStatus:0];
[action runAction:self]; [action runAction:self];
} }
@@ -285,7 +285,9 @@
if (!noErr) { goto bail; } if (!noErr) { goto bail; }
self.mp4File.delegate = self; self.mp4File.progressHandler = ^(double progress){
[self.delegate progressStatus:progress];
};
// Check if there is enough space on the destination disk // Check if there is enough space on the destination disk
if (![self.URL isEqualTo:self.destURL]) { if (![self.URL isEqualTo:self.destURL]) {
@@ -341,6 +343,7 @@
} }
bail: bail:
self.mp4File.progressHandler = nil;
self.mp4File = nil; self.mp4File = nil;
[self willChangeValueForKey:@"actions"]; [self willChangeValueForKey:@"actions"];
@@ -360,8 +363,6 @@ bail:
[self.mp4File cancel]; [self.mp4File cancel];
} }
#pragma mark MP42File delegate
- (void)progressStatus:(CGFloat)progress { - (void)progressStatus:(CGFloat)progress {
[self.delegate progressStatus:progress]; [self.delegate progressStatus:progress];
} }