Connect SBQueueController to the new SBQueue instance.

This commit is contained in:
Damiano Galassi committed 2014-03-11 20:57:57 +01:00
1 parent dab25ea4b8
commit f1dab1fe48
5 files changed
+451 -2061

No files matched your search

+5
View File
@@ -21,6 +21,11 @@ typedef NS_ENUM(NSUInteger, SBQueueStatus) {
SBQueueStatusCancelled, SBQueueStatusCancelled,
}; };
extern NSString *SBQueueWorkingNotification;
extern NSString *SBQueueCompletedNotification;
extern NSString *SBQueueFailedNotification;
extern NSString *SBQueueCancelledNotification;
@interface SBQueue : NSObject { @interface SBQueue : NSObject {
@private @private
dispatch_queue_t _queue; dispatch_queue_t _queue;
+54 -20
View File
@@ -18,6 +18,11 @@
static NSString *fileType = @"mp4"; static NSString *fileType = @"mp4";
NSString *SBQueueWorkingNotification = @"SBQueueWorkingNotification";
NSString *SBQueueCompletedNotification = @"SBQueueCompletedNotification";
NSString *SBQueueFailedNotification = @"SBQueueFailedNotification";
NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
@interface SBQueue () <MP42FileDelegate> @interface SBQueue () <MP42FileDelegate>
@property (atomic) SBQueueStatus status; @property (atomic) SBQueueStatus status;
@@ -39,7 +44,6 @@ static NSString *fileType = @"mp4";
self = [super init]; self = [super init];
if (self) { if (self) {
_queue = dispatch_queue_create("org.subler.Queue", NULL); _queue = dispatch_queue_create("org.subler.Queue", NULL);
_URL = [queueURL copy]; _URL = [queueURL copy];
if ([[NSFileManager defaultManager] fileExistsAtPath:[queueURL path]]) { if ([[NSFileManager defaultManager] fileExistsAtPath:[queueURL path]]) {
@@ -80,8 +84,7 @@ static NSString *fileType = @"mp4";
#pragma mark - item management #pragma mark - item management
- (void)addItem:(SBQueueItem *)item - (void)addItem:(SBQueueItem *)item {
{
[self.items addObject:item]; [self.items addObject:item];
} }
@@ -94,6 +97,7 @@ static NSString *fileType = @"mp4";
for (SBQueueItem *item in self.items) for (SBQueueItem *item in self.items)
if ([item status] != SBQueueItemStatusCompleted) if ([item status] != SBQueueItemStatusCompleted)
count++; count++;
return count; return count;
} }
@@ -135,8 +139,7 @@ static NSString *fileType = @"mp4";
#pragma mark - item preprocessing #pragma mark - item preprocessing
- (NSArray *)loadSubtitles:(NSURL *)url - (NSArray *)loadSubtitles:(NSURL *)url {
{
NSError *outError; NSError *outError;
NSMutableArray *tracksArray = [[NSMutableArray alloc] init]; NSMutableArray *tracksArray = [[NSMutableArray alloc] init];
NSArray *directory = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:[url URLByDeletingLastPathComponent] NSArray *directory = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:[url URLByDeletingLastPathComponent]
@@ -171,8 +174,7 @@ static NSString *fileType = @"mp4";
return [tracksArray autorelease]; return [tracksArray autorelease];
} }
- (MP42Image *)loadArtwork:(NSURL *)url - (MP42Image *)loadArtwork:(NSURL *)url {
{
NSData *artworkData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy]; NSData *artworkData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
if (artworkData && [artworkData length]) { if (artworkData && [artworkData length]) {
MP42Image *artwork = [[MP42Image alloc] initWithData:artworkData type:MP42_ART_JPEG]; MP42Image *artwork = [[MP42Image alloc] initWithData:artworkData type:MP42_ART_JPEG];
@@ -184,8 +186,7 @@ static NSString *fileType = @"mp4";
return nil; return nil;
} }
- (MP42Metadata *)searchMetadataForFile:(NSURL *)url - (MP42Metadata *)searchMetadataForFile:(NSURL *)url {
{
id currentSearcher = nil; id currentSearcher = nil;
MP42Metadata *metadata = nil; MP42Metadata *metadata = nil;
@@ -350,6 +351,7 @@ static NSString *fileType = @"mp4";
break; break;
} }
[self handleSBStatusWorking];
noErr = [self processItem:item error:&outError]; noErr = [self processItem:item error:&outError];
// Check results // Check results
@@ -387,13 +389,21 @@ static NSString *fileType = @"mp4";
} }
} }
// Save to disk
[self saveQueueToDisk];
// Disable sleep assertion // Disable sleep assertion
[self enableSleep]; [self enableSleep];
[self handleSBStatusCompleted];
}); });
} }
- (BOOL)processItem:(SBQueueItem *)item error:(NSError **)outError{
/**
* Processes a SBQueueItem.
*/
- (BOOL)processItem:(SBQueueItem *)item error:(NSError **)outError {
NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init]; NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"chaptersPreviewTrack"] boolValue]) if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"chaptersPreviewTrack"] boolValue])
[attributes setObject:@YES forKey:MP42GenerateChaptersPreviewTrack]; [attributes setObject:@YES forKey:MP42GenerateChaptersPreviewTrack];
@@ -408,14 +418,6 @@ static NSString *fileType = @"mp4";
_currentMP4 = [item mp4File]; _currentMP4 = [item mp4File];
[_currentMP4 setDelegate:self]; [_currentMP4 setDelegate:self];
// Update the UI
dispatch_async(dispatch_get_main_queue(), ^{
/*NSInteger itemIndex = [filesArray indexOfObject:item];
[countLabel setStringValue:[NSString stringWithFormat:@"Processing file %ld of %lu.",(long)itemIndex + 1, (unsigned long)[filesArray count]]];
[[NSApp dockTile] setBadgeLabel:[NSString stringWithFormat:@"%lu", (unsigned long)[filesArray count] - itemIndex]];
[tableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] columnIndexes:[NSIndexSet indexSetWithIndex:0]];*/
});
// Set the destination url // Set the destination url
if (![item destURL]) { if (![item destURL]) {
if (!_currentMP4 && self.destination /*&& customDestination*/) { if (!_currentMP4 && self.destination /*&& customDestination*/) {
@@ -426,8 +428,9 @@ static NSString *fileType = @"mp4";
} }
// The file has been added directly to the queue // The file has been added directly to the queue
if (!_currentMP4 && item.URL) if (!_currentMP4 && item.URL) {
_currentMP4 = [self prepareQueueItem:item.URL error:outError]; _currentMP4 = [self prepareQueueItem:item.URL error:outError];
}
NSDictionary *dict = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[_currentMP4.URL path] error:NULL]; NSDictionary *dict = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[_currentMP4.URL path] error:NULL];
NSNumber *freeSpace = [dict objectForKey:NSFileSystemFreeSize]; NSNumber *freeSpace = [dict objectForKey:NSFileSystemFreeSize];
@@ -458,9 +461,40 @@ static NSString *fileType = @"mp4";
} }
- (void)stop { - (void)stop {
_cancelled = YES;
} }
/**
* Processes SBQueueStatusWorking state information. Current implementation just
* sends SBQueueWorkingNotification.
*/
- (void)handleSBStatusWorking {
[[NSNotificationCenter defaultCenter] postNotificationName:SBQueueWorkingNotification object:self];
}
/**
* Processes SBQueueStatusCompleted state information. Current implementation just
* sends SBQueueCompletedNotification.
*/
- (void)handleSBStatusCompleted {
[[NSNotificationCenter defaultCenter] postNotificationName:SBQueueCompletedNotification object:self];
}
/**
* Processes SBQueueStatusFailed state information. Current implementation just
* sends SBQueueFailedNotification.
*/
- (void)handleSBStatusFailed {
[[NSNotificationCenter defaultCenter] postNotificationName:SBQueueFailedNotification object:self];
}
/**
* Processes SBQueueStatusCancelled state information. Current implementation just
* sends SBQueueCancelledNotification.
*/
- (void)handleSBStatusCancelled {
[[NSNotificationCenter defaultCenter] postNotificationName:SBQueueCancelledNotification object:self];
}
- (void)dealloc { - (void)dealloc {
dispatch_release(_queue); dispatch_release(_queue);
+16 -28
View File
@@ -9,49 +9,37 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import <IOKit/pwr_mgt/IOPMLib.h> #import <IOKit/pwr_mgt/IOPMLib.h>
#import "SBQueue.h"
@class SBQueueItem; @class SBQueueItem;
@class SBTableView; @class SBTableView;
@class MP42File; @class MP42File;
typedef enum SBQueueStatus : NSUInteger {
SBQueueStatusUnknown = 0,
SBQueueStatusWorking,
SBQueueStatusCompleted,
SBQueueStatusFailed,
SBQueueStatusCancelled,
} SBQueueStatus;
@interface SBQueueController : NSWindowController { @interface SBQueueController : NSWindowController {
IBOutlet NSButton *start; IBOutlet NSButton *_start;
IBOutlet NSButton *open; IBOutlet NSButton *_open;
IBOutlet NSTextField *countLabel; IBOutlet NSTextField *_countLabel;
IBOutlet NSProgressIndicator *progressIndicator; IBOutlet NSProgressIndicator *_progressIndicator;
IBOutlet NSButton *OptimizeOption; IBOutlet NSButton *_optimizeOption;
IBOutlet NSButton *MetadataOption; IBOutlet NSButton *_metadataOption;
IBOutlet NSButton *ITunesGroupsOption; IBOutlet NSButton *_organizeGroupsOption;
IBOutlet NSButton *AutoStartOption; IBOutlet NSButton *_autoStartOption;
IBOutlet NSBox *optionsBox; IBOutlet NSBox *_optionsBox;
BOOL optionsStatus; BOOL _optionsStatus;
IBOutlet NSScrollView *tableScrollView; IBOutlet NSScrollView *tableScrollView;
IBOutlet SBTableView *tableView; IBOutlet SBTableView *tableView;
NSURL *destination;
BOOL customDestination;
IBOutlet NSPopUpButton *destButton; IBOutlet NSPopUpButton *destButton;
NSImage *docImg; NSImage *docImg;
dispatch_queue_t queue; NSURL *destination;
MP42File *_currentMP4; BOOL customDestination;
NSMutableArray *filesArray; SBQueue *_queue;
SBQueueStatus status;
IOPMAssertionID _assertionID;
BOOL _cancelled;
} }
@property(readonly) SBQueueStatus status; @property(readonly) SBQueueStatus status;
@@ -61,7 +49,7 @@ typedef enum SBQueueStatus : NSUInteger {
- (void)start:(id)sender; - (void)start:(id)sender;
- (void)stop:(id)sender; - (void)stop:(id)sender;
- (void)addItem:(SBQueueItem*)item; - (void)addItem:(SBQueueItem *)item;
- (BOOL)saveQueueToDisk; - (BOOL)saveQueueToDisk;
+102 -452
View File
@@ -12,18 +12,16 @@
#import "SBTableView.h" #import "SBTableView.h"
#import "MetadataImporter.h" #import "MetadataImporter.h"
#import <MP42Foundation/MP42File.h>
#import <MP42Foundation/MP42FileImporter.h>
#import <MP42Foundation/MP42Image.h>
#import <MP42Foundation/MP42Utilities.h> #import <MP42Foundation/MP42Utilities.h>
#define SublerBatchTableViewDataType @"SublerBatchTableViewDataType" #define SublerBatchTableViewDataType @"SublerBatchTableViewDataType"
#define kOptionsPanelHeight 88 #define kOptionsPanelHeight 88
static NSString *fileType = @"mp4"; @interface SBQueueController () <NSTableViewDelegate, NSTableViewDataSource, SBTableViewDelegate>
@property (readonly) SBQueue *queue;
@interface SBQueueController () <NSTableViewDelegate, NSTableViewDataSource, SBTableViewDelegate, MP42FileDelegate>
- (void)updateUI; - (void)updateUI;
- (void)updateDockTile; - (void)updateDockTile;
- (NSURL *)queueURL; - (NSURL *)queueURL;
@@ -32,13 +30,13 @@ static NSString *fileType = @"mp4";
- (void)addItems:(NSArray *)items atIndexes:(NSIndexSet *)indexes; - (void)addItems:(NSArray *)items atIndexes:(NSIndexSet *)indexes;
- (void)removeItems:(NSArray *)items; - (void)removeItems:(NSArray *)items;
@end @end
@implementation SBQueueController @implementation SBQueueController
@synthesize status; @synthesize queue = _queue;
+ (SBQueueController *)sharedManager + (SBQueueController *)sharedManager
{ {
@@ -51,30 +49,9 @@ static NSString *fileType = @"mp4";
- (id)init - (id)init
{ {
if (self = [super initWithWindowNibName:@"Queue"]) if (self = [super initWithWindowNibName:@"Queue"]) {
{ _queue = [[SBQueue alloc] initWithURL:[self queueURL]];
queue = dispatch_queue_create("org.subler.Queue", NULL); [self removeCompletedItems:self];
NSURL *queueURL = [self queueURL];
if ([[NSFileManager defaultManager] fileExistsAtPath:[queueURL path]]) {
@try {
filesArray = [[NSKeyedUnarchiver unarchiveObjectWithFile:[queueURL path]] retain];
}
@catch (NSException *exception) {
[[NSFileManager defaultManager] removeItemAtURL:queueURL error:nil];
filesArray = nil;
}
for (SBQueueItem *item in filesArray)
if ([item status] == SBQueueItemStatusWorking)
[item setStatus:SBQueueItemStatusFailed];
}
if (!filesArray)
filesArray = [[NSMutableArray alloc] init];
[self updateDockTile]; [self updateDockTile];
} }
@@ -83,8 +60,8 @@ static NSString *fileType = @"mp4";
- (void)awakeFromNib - (void)awakeFromNib
{ {
[progressIndicator setHidden:YES]; [_progressIndicator setHidden:YES];
[countLabel setStringValue:@"Empty"]; [_countLabel setStringValue:@"Empty"];
NSRect frame = [[self window] frame]; NSRect frame = [[self window] frame];
frame.size.height += kOptionsPanelHeight; frame.size.height += kOptionsPanelHeight;
@@ -97,47 +74,65 @@ static NSString *fileType = @"mp4";
frame.origin.y += kOptionsPanelHeight; frame.origin.y += kOptionsPanelHeight;
[tableScrollView setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin]; [tableScrollView setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
[optionsBox setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin]; [_optionsBox setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
[[self window] setFrame:frame display:YES animate:NO]; [[self window] setFrame:frame display:YES animate:NO];
[tableScrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [tableScrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[optionsBox setAutoresizingMask:NSViewWidthSizable | NSViewMaxYMargin]; [_optionsBox setAutoresizingMask:NSViewWidthSizable | NSViewMaxYMargin];
docImg = [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode('MOOV')] retain]; docImg = [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode('MOOV')] retain];
[docImg setSize:NSMakeSize(16, 16)]; [docImg setSize:NSMakeSize(16, 16)];
[self prepareDestPopup]; [self prepareDestPopup];
[self updateUI];
} }
- (void)windowDidLoad - (void)windowDidLoad
{ {
[super windowDidLoad]; [super windowDidLoad];
[self removeCompletedItems:self];
[tableView registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, SublerBatchTableViewDataType, nil]]; [tableView registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, SublerBatchTableViewDataType, nil]];
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
[[NSNotificationCenter defaultCenter] addObserverForName:SBQueueWorkingNotification object:nil queue:mainQueue usingBlock:^(NSNotification *note) {
[_countLabel setStringValue:@"Working"];
}];
[[NSNotificationCenter defaultCenter] addObserverForName:SBQueueCompletedNotification object:nil queue:mainQueue usingBlock:^(NSNotification *note) {
[_progressIndicator setHidden:YES];
[_progressIndicator stopAnimation:self];
[_progressIndicator setDoubleValue:0];
[_start setTitle:@"Start"];
[_countLabel setStringValue:@"Done"];
[self updateDockTile];
[self updateUI];
}];
[self updateUI];
} }
- (NSURL*)queueURL - (NSURL *)queueURL
{ {
NSURL *appSupportURL = nil; NSURL *appSupportURL = nil;
NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory,
NSUserDomainMask, NSUserDomainMask,
YES); YES);
if ([allPaths count]) { if ([allPaths count]) {
appSupportURL = [NSURL fileURLWithPath:[[[allPaths lastObject] stringByAppendingPathComponent:@"Subler"] stringByAppendingPathComponent:@"queue.sbqueue"] isDirectory:YES]; appSupportURL = [NSURL fileURLWithPath:[[[allPaths lastObject] stringByAppendingPathComponent:@"Subler"] stringByAppendingPathComponent:@"queue.sbqueue"] isDirectory:YES];
return appSupportURL; return appSupportURL;
} } else {
else
return nil; return nil;
}
} }
- (BOOL)saveQueueToDisk - (SBQueueStatus)status {
{ return self.queue.status;
return [NSKeyedArchiver archiveRootObject:filesArray toFile:[[self queueURL] path]]; }
- (BOOL)saveQueueToDisk {
return [self.queue saveQueueToDisk];
} }
- (NSMenuItem *)prepareDestPopupItem:(NSURL*) dest - (NSMenuItem *)prepareDestPopupItem:(NSURL*) dest
@@ -145,7 +140,7 @@ static NSString *fileType = @"mp4";
NSMenuItem *folderItem = [[NSMenuItem alloc] initWithTitle:[dest lastPathComponent] action:@selector(destination:) keyEquivalent:@""]; NSMenuItem *folderItem = [[NSMenuItem alloc] initWithTitle:[dest lastPathComponent] action:@selector(destination:) keyEquivalent:@""];
[folderItem setTag:10]; [folderItem setTag:10];
NSImage* menuItemIcon = [[NSWorkspace sharedWorkspace] iconForFile:[dest path]]; NSImage *menuItemIcon = [[NSWorkspace sharedWorkspace] iconForFile:[dest path]];
[menuItemIcon setSize:NSMakeSize(16, 16)]; [menuItemIcon setSize:NSMakeSize(16, 16)];
[folderItem setImage:menuItemIcon]; [folderItem setImage:menuItemIcon];
@@ -203,8 +198,7 @@ static NSString *fileType = @"mp4";
if ([sender tag] == 10) { if ([sender tag] == 10) {
customDestination = YES; customDestination = YES;
[[NSUserDefaults standardUserDefaults] setValue:@"YES" forKey:@"SBQueueDestinationSelected"]; [[NSUserDefaults standardUserDefaults] setValue:@"YES" forKey:@"SBQueueDestinationSelected"];
} } else {
else {
customDestination = NO; customDestination = NO;
[[NSUserDefaults standardUserDefaults] setValue:nil forKey:@"SBQueueDestinationSelected"]; [[NSUserDefaults standardUserDefaults] setValue:nil forKey:@"SBQueueDestinationSelected"];
} }
@@ -212,10 +206,7 @@ static NSString *fileType = @"mp4";
- (void)updateDockTile - (void)updateDockTile
{ {
int count = 0; NSUInteger count = [self.queue readyCount];
for (SBQueueItem *item in filesArray)
if ([item status] != SBQueueItemStatusCompleted)
count++;
if (count) if (count)
[[NSApp dockTile] setBadgeLabel:[NSString stringWithFormat:@"%d", count]]; [[NSApp dockTile] setBadgeLabel:[NSString stringWithFormat:@"%d", count]];
@@ -226,369 +217,42 @@ static NSString *fileType = @"mp4";
- (void)updateUI - (void)updateUI
{ {
[tableView reloadData]; [tableView reloadData];
if (status != SBQueueStatusWorking) { if (self.queue.status != SBQueueStatusWorking) {
[countLabel setStringValue:[NSString stringWithFormat:@"%lu files in queue.", (unsigned long)[filesArray count]]]; [_countLabel setStringValue:[NSString stringWithFormat:@"%lu files in queue.", (unsigned long)[self.queue count]]];
[self updateDockTile]; [self updateDockTile];
} }
} }
- (NSArray *)loadSubtitles:(NSURL*)url
{
NSError *outError;
NSMutableArray *tracksArray = [[NSMutableArray alloc] init];
NSArray *directory = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:[url URLByDeletingLastPathComponent]
includingPropertiesForKeys:nil
options:NSDirectoryEnumerationSkipsSubdirectoryDescendants |
NSDirectoryEnumerationSkipsHiddenFiles |
NSDirectoryEnumerationSkipsPackageDescendants
error:nil];
for (NSURL *dirUrl in directory) {
if ([[dirUrl pathExtension] isEqualToString:@"srt"]) {
NSComparisonResult result;
NSString *movieFilename = [[url URLByDeletingPathExtension] lastPathComponent];
NSString *subtitleFilename = [[dirUrl URLByDeletingPathExtension] lastPathComponent];
NSRange range = { 0, [movieFilename length] };
if ([movieFilename length] <= [subtitleFilename length]) {
result = [subtitleFilename compare:movieFilename options:NSCaseInsensitiveSearch range:range];
if (result == NSOrderedSame) {
MP42FileImporter *fileImporter = [[[MP42FileImporter alloc] initWithURL:dirUrl
error:&outError] autorelease];
for (MP42Track *track in fileImporter.tracks) {
[tracksArray addObject:track];
}
}
}
}
}
return [tracksArray autorelease];
}
- (MP42Image *)loadArtwork:(NSURL*)url
{
NSData *artworkData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
if (artworkData && [artworkData length]) {
MP42Image *artwork = [[MP42Image alloc] initWithData:artworkData type:MP42_ART_JPEG];
if (artwork != nil) {
return [artwork autorelease];
}
}
return nil;
}
- (MP42Metadata *)searchMetadataForFile:(NSURL*) url
{
id currentSearcher = nil;
MP42Metadata *metadata = nil;
// Parse FileName and search for metadata
NSDictionary *parsed = [MetadataImporter parseFilename:[url lastPathComponent]];
NSString *type = (NSString *)[parsed valueForKey:@"type"];
if ([@"movie" isEqualToString:type]) {
currentSearcher = [MetadataImporter defaultMovieProvider];
NSString *language = [MetadataImporter defaultMovieLanguage];
NSArray *results = [currentSearcher searchMovie:[parsed valueForKey:@"title"] language:language];
if ([results count])
metadata = [currentSearcher loadMovieMetadata:[results objectAtIndex:0] language:language];
} else if ([@"tv" isEqualToString:type]) {
currentSearcher = [MetadataImporter defaultTVProvider];
NSString *language = [MetadataImporter defaultTVLanguage];
NSArray *results = [currentSearcher searchTVSeries:[parsed valueForKey:@"seriesName"]
language:language seasonNum:[parsed valueForKey:@"seasonNum"]
episodeNum:[parsed valueForKey:@"episodeNum"]];
if ([results count])
metadata = [currentSearcher loadTVMetadata:[results objectAtIndex:0] language:language];
}
if (metadata.artworkThumbURLs && [metadata.artworkThumbURLs count]) {
NSURL *artworkURL = nil;
if ([type isEqualToString:@"movie"]) {
artworkURL = [metadata.artworkFullsizeURLs objectAtIndex:0];
} else if ([type isEqualToString:@"tv"]) {
if ([metadata.artworkFullsizeURLs count] > 1) {
int i = 0;
for (NSString *artworkProviderName in metadata.artworkProviderNames) {
NSArray *a = [artworkProviderName componentsSeparatedByString:@"|"];
if ([a count] > 1 && ![[a objectAtIndex:1] isEqualToString:@"episode"]) {
artworkURL = [metadata.artworkFullsizeURLs objectAtIndex:i];
break;
}
i++;
}
} else {
artworkURL = [metadata.artworkFullsizeURLs objectAtIndex:0];
}
}
MP42Image *artwork = [self loadArtwork:artworkURL];
if (artwork)
[metadata.artworks addObject:artwork];
}
return metadata;
}
- (MP42File *)prepareQueueItem:(NSURL*)url error:(NSError**)outError {
NSString *type;
MP42File *mp4File = nil;
[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"]) {
mp4File = [[MP42File alloc] initWithExistingFile:url andDelegate:self];
} else {
mp4File = [[MP42File alloc] initWithDelegate:self];
MP42FileImporter *fileImporter = [[MP42FileImporter alloc] initWithURL:url
error:outError];
for (MP42Track *track in fileImporter.tracks) {
if ([track.format isEqualToString:MP42AudioFormatAC3]) {
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"SBAudioConvertAC3"] boolValue]) {
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"SBAudioKeepAC3"] boolValue] ||
![(MP42AudioTrack *)track fallbackTrack]) {
MP42AudioTrack *copy = [track copy];
[copy setNeedConversion:YES];
[copy setMixdownType:SBDolbyPlIIMixdown];
[(MP42AudioTrack *)track setFallbackTrack:copy];
[mp4File addTrack:copy];
[copy release];
}
else
track.needConversion = YES;
}
}
if ([track.format isEqualToString:MP42AudioFormatDTS] ||
([track.format isEqualToString:MP42SubtitleFormatVobSub] && [[[NSUserDefaults standardUserDefaults] valueForKey:@"SBSubtitleConvertBitmap"] boolValue]))
track.needConversion = YES;
if (isTrackMuxable(track.format) || trackNeedConversion(track.format))
[mp4File addTrack:track];
}
[fileImporter release];
}
// Search for external subtitles files
NSArray *subtitles = [self loadSubtitles:url];
for (MP42SubtitleTrack *subTrack in subtitles) {
[mp4File addTrack:subTrack];
}
// Search for metadata
if ([MetadataOption state]) {
MP42Metadata *metadata = [self searchMetadataForFile:url];
for (MP42Track *track in mp4File.tracks)
if ([track isKindOfClass:[MP42VideoTrack class]]) {
int hdVideo = isHdVideo([((MP42VideoTrack *) track) trackWidth], [((MP42VideoTrack *) track) trackHeight]);
if (hdVideo)
[mp4File.metadata setTag:@(hdVideo) forKey:@"HD Video"];
}
[[mp4File metadata] mergeMetadata:metadata];
}
if ([ITunesGroupsOption state])
[mp4File organizeAlternateGroups];
return [mp4File autorelease];
}
- (SBQueueItem *)firstItemInQueue
{
for (SBQueueItem *item in filesArray)
if (([item status] != SBQueueItemStatusCompleted) && ([item status] != SBQueueItemStatusFailed))
return item;
return nil;
}
- (void)start:(id)sender - (void)start:(id)sender
{ {
if (status == SBQueueStatusWorking) if (self.queue.status == SBQueueStatusWorking)
return; return;
status = SBQueueStatusWorking; [_start setTitle:@"Stop"];
[_countLabel setStringValue:@"Working."];
[_progressIndicator setHidden:NO];
[_progressIndicator startAnimation:self];
[start setTitle:@"Stop"]; [self.queue start];
[countLabel setStringValue:@"Working."];
[progressIndicator setHidden:NO];
[progressIndicator startAnimation:self];
NSMutableDictionary * attributes = [[NSMutableDictionary alloc] init];
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"chaptersPreviewTrack"] boolValue])
[attributes setObject:@YES forKey:MP42GenerateChaptersPreviewTrack];
// Enable sleep assertion
CFStringRef reasonForActivity= CFSTR("Subler Queue Started");
IOReturn io_success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
kIOPMAssertionLevelOn, reasonForActivity, &_assertionID);
dispatch_async(queue, ^{
NSError *outError = nil;
BOOL success = NO;
#ifdef SB_SANDBOX
if([destination respondsToSelector:@selector(startAccessingSecurityScopedResource)])
[destination startAccessingSecurityScopedResource];
#endif
for (;;) {
@autoreleasepool {
__block SBQueueItem *item = nil;
// Get the first item available in the queue
dispatch_sync(dispatch_get_main_queue(), ^{
item = [self firstItemInQueue];
[item retain];
[item setStatus:SBQueueItemStatusWorking];
});
if (item == nil)
break;
_currentMP4 = [item mp4File];
[_currentMP4 setDelegate:self];
// Update the UI
dispatch_async(dispatch_get_main_queue(), ^{
NSInteger itemIndex = [filesArray indexOfObject:item];
[countLabel setStringValue:[NSString stringWithFormat:@"Processing file %ld of %lu.",(long)itemIndex + 1, (unsigned long)[filesArray count]]];
[[NSApp dockTile] setBadgeLabel:[NSString stringWithFormat:@"%lu", (unsigned long)[filesArray count] - itemIndex]];
[tableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] columnIndexes:[NSIndexSet indexSetWithIndex:0]];
});
// Set the destination url
if (![item destURL]) {
if (!_currentMP4 && destination && customDestination)
item.destURL = [[[destination URLByAppendingPathComponent:[item.URL lastPathComponent]] URLByDeletingPathExtension] URLByAppendingPathExtension:fileType];
else
item.destURL = [[item.URL URLByDeletingPathExtension] URLByAppendingPathExtension:fileType];
}
// The file has been added directly to the queue
if (!_currentMP4 && item.URL)
_currentMP4 = [self prepareQueueItem:item.URL error:&outError];
// We have an existing mp4 file, update it
if (!_cancelled) {
if ([_currentMP4 hasFileRepresentation])
success = [_currentMP4 updateMP4FileWithAttributes:attributes error:&outError];
// Write the new file to disk
else if (_currentMP4 && item.destURL) {
[attributes addEntriesFromDictionary:[item attributes]];
success = [_currentMP4 writeToUrl:[item destURL]
withAttributes:attributes
error:&outError];
}
}
// Check results
if (_cancelled) {
[item setStatus:SBQueueItemStatusCancelled];
status = SBQueueStatusCancelled;
}
else if (success) {
if ([OptimizeOption state]) {
// Update the UI
dispatch_async(dispatch_get_main_queue(), ^{
NSInteger itemIndex = [filesArray indexOfObject:item];
[countLabel setStringValue:[NSString stringWithFormat:@"Optimizing file %ld of %lu.",(long)itemIndex + 1, (unsigned long)[filesArray count]]];
});
success = [_currentMP4 optimize];
}
}
if (success)
[item setStatus:SBQueueItemStatusCompleted];
else {
[item setStatus:SBQueueItemStatusFailed];
if (outError) {
dispatch_async(dispatch_get_main_queue(), ^{
[NSApp presentError:outError];
});
}
}
// Update the UI
dispatch_async(dispatch_get_main_queue(), ^{
NSInteger itemIndex = [filesArray indexOfObject:item];
[tableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] columnIndexes:[NSIndexSet indexSetWithIndex:0]];
[self saveQueueToDisk];
});
[item release];
}
if (status == SBQueueStatusCancelled)
break;
}
#ifdef SB_SANDBOX
if([destination respondsToSelector:@selector(stopAccessingSecurityScopedResource)])
[destination stopAccessingSecurityScopedResource];
#endif
// Disable sleep assertion
if (io_success == kIOReturnSuccess)
IOPMAssertionRelease(_assertionID);
dispatch_async(dispatch_get_main_queue(), ^{
_currentMP4 = nil;
if (status == SBQueueStatusCancelled) {
[countLabel setStringValue:@"Cancelled."];
status = SBQueueStatusCancelled;
_cancelled = NO;
}
else {
[countLabel setStringValue:@"Done."];
status = SBQueueStatusCompleted;
}
[progressIndicator setHidden:YES];
[progressIndicator stopAnimation:self];
[progressIndicator setDoubleValue:0];
[start setTitle:@"Start"];
[self updateDockTile];
[self saveQueueToDisk];
});
});
[attributes release];
} }
- (void)progressStatus: (CGFloat)progress { - (void)progressStatus: (CGFloat)progress {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[progressIndicator setIndeterminate:NO]; [_progressIndicator setIndeterminate:NO];
[progressIndicator setDoubleValue:progress]; [_progressIndicator setDoubleValue:progress];
}); });
} }
- (void)stop:(id)sender - (void)stop:(id)sender
{ {
_cancelled = YES; [self.queue stop];
[_currentMP4 cancel];
} }
- (IBAction)toggleStartStop:(id)sender - (IBAction)toggleStartStop:(id)sender
{ {
if (status == SBQueueStatusWorking) { if (self.queue.status == SBQueueStatusWorking) {
[self stop:sender]; [self stop:sender];
} } else {
else {
[self start:sender]; [self start:sender];
} }
} }
@@ -596,13 +260,13 @@ static NSString *fileType = @"mp4";
- (IBAction)toggleOptions:(id)sender - (IBAction)toggleOptions:(id)sender
{ {
NSInteger value = 0; NSInteger value = 0;
if (optionsStatus) { if (_optionsStatus) {
value = -kOptionsPanelHeight; value = -kOptionsPanelHeight;
optionsStatus = NO; _optionsStatus = NO;
} }
else { else {
value = kOptionsPanelHeight; value = kOptionsPanelHeight;
optionsStatus = YES; _optionsStatus = YES;
} }
NSRect frame = [[self window] frame]; NSRect frame = [[self window] frame];
@@ -610,12 +274,12 @@ static NSString *fileType = @"mp4";
frame.origin.y -= value; frame.origin.y -= value;
[tableScrollView setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin]; [tableScrollView setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
[optionsBox setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin]; [_optionsBox setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
[[self window] setFrame:frame display:YES animate:YES]; [[self window] setFrame:frame display:YES animate:YES];
[tableScrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [tableScrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[optionsBox setAutoresizingMask:NSViewWidthSizable | NSViewMaxYMargin]; [_optionsBox setAutoresizingMask:NSViewWidthSizable | NSViewMaxYMargin];
} }
#pragma mark Open methods #pragma mark Open methods
@@ -640,7 +304,7 @@ static NSString *fileType = @"mp4";
[self updateUI]; [self updateUI];
if ([AutoStartOption state]) if ([_autoStartOption state])
[self start:self]; [self start:self];
} }
}]; }];
@@ -693,16 +357,16 @@ static NSString *fileType = @"mp4";
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{ {
return [filesArray count]; return [self.queue count];
} }
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{ {
if ([aTableColumn.identifier isEqualToString:@"nameColumn"]) if ([aTableColumn.identifier isEqualToString:@"nameColumn"])
return [[[filesArray objectAtIndex:rowIndex] URL] lastPathComponent]; return [[[self.queue itemAtIndex:rowIndex] URL] lastPathComponent];
if ([aTableColumn.identifier isEqualToString:@"statusColumn"]) { if ([aTableColumn.identifier isEqualToString:@"statusColumn"]) {
SBQueueItemStatus batchStatus = [(SBQueueItem *)[filesArray objectAtIndex:rowIndex] status]; SBQueueItemStatus batchStatus = [[self.queue itemAtIndex:rowIndex] status];
if (batchStatus == SBQueueItemStatusCompleted) if (batchStatus == SBQueueItemStatusCompleted)
return [NSImage imageNamed:@"EncodeComplete"]; return [NSImage imageNamed:@"EncodeComplete"];
else if (batchStatus == SBQueueItemStatusWorking) else if (batchStatus == SBQueueItemStatusWorking)
@@ -719,22 +383,22 @@ static NSString *fileType = @"mp4";
- (void)_deleteSelectionFromTableView:(NSTableView *)aTableView - (void)_deleteSelectionFromTableView:(NSTableView *)aTableView
{ {
NSMutableIndexSet *rowIndexes = [[aTableView selectedRowIndexes] mutableCopy]; NSMutableIndexSet *rowIndexes = [[aTableView selectedRowIndexes] mutableCopy];
NSInteger clickedRow = [aTableView clickedRow];
NSUInteger selectedIndex = -1; NSUInteger selectedIndex = -1;
if ([rowIndexes count]) if ([rowIndexes count])
selectedIndex = [rowIndexes firstIndex]; selectedIndex = [rowIndexes firstIndex];
NSInteger clickedRow = [aTableView clickedRow];
if (clickedRow != -1 && ![rowIndexes containsIndex:clickedRow]) { if (clickedRow != -1 && ![rowIndexes containsIndex:clickedRow]) {
[rowIndexes removeAllIndexes]; [rowIndexes removeAllIndexes];
[rowIndexes addIndex:clickedRow]; [rowIndexes addIndex:clickedRow];
} }
NSArray *array = [filesArray objectsAtIndexes:rowIndexes]; NSArray *array = [self.queue itemsAtIndexes:rowIndexes];
// A item with a status of SBQueueItemStatusWorking can not be removed // A item with a status of SBQueueItemStatusWorking can not be removed
for (SBQueueItem *item in array) for (SBQueueItem *item in array)
if ([item status] == SBQueueItemStatusWorking) if ([item status] == SBQueueItemStatusWorking)
[rowIndexes removeIndex:[filesArray indexOfObject:item]]; [rowIndexes removeIndex:[self.queue indexOfItem:item]];
if ([rowIndexes count]) { if ([rowIndexes count]) {
if ([NSTableView instancesRespondToSelector:@selector(beginUpdates)]) { if ([NSTableView instancesRespondToSelector:@selector(beginUpdates)]) {
@@ -752,8 +416,8 @@ static NSString *fileType = @"mp4";
[aTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedIndex] byExtendingSelection:NO]; [aTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedIndex] byExtendingSelection:NO];
} }
if (status != SBQueueStatusWorking) { if (self.queue.status != SBQueueStatusWorking) {
[countLabel setStringValue:[NSString stringWithFormat:@"%lu files in queue.", (unsigned long)[filesArray count]]]; [_countLabel setStringValue:[NSString stringWithFormat:@"%lu files in queue.", (unsigned long)[self.queue count]]];
[self updateDockTile]; [self updateDockTile];
} }
} }
@@ -762,7 +426,7 @@ static NSString *fileType = @"mp4";
- (IBAction)edit:(id)sender - (IBAction)edit:(id)sender
{ {
SBQueueItem *item = [[filesArray objectAtIndex:[tableView clickedRow]] retain]; /*SBQueueItem *item = [[self.queue itemAtIndex:[tableView clickedRow]] retain];
[self removeItems:[NSArray arrayWithObject:item]]; [self removeItems:[NSArray arrayWithObject:item]];
[self updateUI]; [self updateUI];
@@ -775,12 +439,12 @@ static NSString *fileType = @"mp4";
SBDocument *doc = [[NSDocumentController sharedDocumentController] openUntitledDocumentAndDisplay:YES error:NULL]; SBDocument *doc = [[NSDocumentController sharedDocumentController] openUntitledDocumentAndDisplay:YES error:NULL];
[doc setMp4File:mp4]; [doc setMp4File:mp4];
[item release]; [item release];*/
} }
- (IBAction)showInFinder:(id)sender - (IBAction)showInFinder:(id)sender
{ {
SBQueueItem *item = [filesArray objectAtIndex:[tableView clickedRow]]; SBQueueItem *item = [self.queue itemAtIndex:[tableView clickedRow]];
[[NSWorkspace sharedWorkspace] selectFile:[item.destURL path] inFileViewerRootedAtPath:nil]; [[NSWorkspace sharedWorkspace] selectFile:[item.destURL path] inFileViewerRootedAtPath:nil];
} }
@@ -791,35 +455,24 @@ static NSString *fileType = @"mp4";
- (IBAction)removeCompletedItems:(id)sender - (IBAction)removeCompletedItems:(id)sender
{ {
NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init]; NSIndexSet *indexes = [self.queue removeCompletedItems];
for (SBQueueItem *item in filesArray)
if ([item status] == SBQueueItemStatusCompleted)
[indexes addIndex:[filesArray indexOfObject:item]];
if ([indexes count]) { if ([indexes count]) {
if ([NSTableView instancesRespondToSelector:@selector(beginUpdates)]) { if ([NSTableView instancesRespondToSelector:@selector(beginUpdates)]) {
#if __MAC_OS_X_VERSION_MAX_ALLOWED > 1060 #if __MAC_OS_X_VERSION_MAX_ALLOWED > 1060
[tableView beginUpdates]; [tableView beginUpdates];
[tableView removeRowsAtIndexes:indexes withAnimation:NSTableViewAnimationEffectFade]; [tableView removeRowsAtIndexes:indexes withAnimation:NSTableViewAnimationEffectFade];
NSArray* items = [filesArray objectsAtIndexes:indexes];
[self removeItems:items];
[tableView endUpdates]; [tableView endUpdates];
#endif #endif
} } else {
else {
NSArray *items = [filesArray objectsAtIndexes:indexes];
[self removeItems:items];
[tableView reloadData]; [tableView reloadData];
} }
if (status != SBQueueStatusWorking) { if (self.queue.status != SBQueueStatusWorking) {
[countLabel setStringValue:[NSString stringWithFormat:@"%lu files in queue.", (unsigned long)[filesArray count]]]; [_countLabel setStringValue:[NSString stringWithFormat:@"%lu files in queue.", (unsigned long)[self.queue count]]];
[self updateDockTile]; [self updateDockTile];
} }
} }
[indexes release];
} }
- (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem - (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem
@@ -832,7 +485,7 @@ static NSString *fileType = @"mp4";
if (action == @selector(showInFinder:)) { if (action == @selector(showInFinder:)) {
if ([tableView clickedRow] != -1) { if ([tableView clickedRow] != -1) {
SBQueueItem *item = [filesArray objectAtIndex:[tableView clickedRow]]; SBQueueItem *item = [self.queue itemAtIndex:[tableView clickedRow]];
if ([item status] == SBQueueItemStatusCompleted) if ([item status] == SBQueueItemStatusCompleted)
return YES; return YES;
} }
@@ -872,12 +525,11 @@ static NSString *fileType = @"mp4";
if (nil == [info draggingSource]) { // From other application if (nil == [info draggingSource]) { // From other application
[view setDropRow: row dropOperation: NSTableViewDropAbove]; [view setDropRow: row dropOperation: NSTableViewDropAbove];
return NSDragOperationCopy; return NSDragOperationCopy;
} } else if (view == [info draggingSource] && operation == NSTableViewDropAbove) { // From self
else if (view == [info draggingSource] && operation == NSTableViewDropAbove) { // From self
return NSDragOperationEvery; return NSDragOperationEvery;
} } else {
else
return NSDragOperationNone; return NSDragOperationNone;
}
} }
- (BOOL)tableView:(NSTableView *)view - (BOOL)tableView:(NSTableView *)view
@@ -888,16 +540,16 @@ static NSString *fileType = @"mp4";
NSPasteboard *pboard = [info draggingPasteboard]; NSPasteboard *pboard = [info draggingPasteboard];
if (tableView == [info draggingSource]) { // From self if (tableView == [info draggingSource]) { // From self
NSData* rowData = [pboard dataForType:SublerBatchTableViewDataType]; NSData *rowData = [pboard dataForType:SublerBatchTableViewDataType];
NSIndexSet* rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData]; NSIndexSet *rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData];
NSUInteger i = [rowIndexes countOfIndexesInRange:NSMakeRange(0, row)]; NSUInteger i = [rowIndexes countOfIndexesInRange:NSMakeRange(0, row)];
row -= i; row -= i;
NSArray *objects = [filesArray objectsAtIndexes:rowIndexes]; NSArray *objects = [self.queue itemsAtIndexes:rowIndexes];
[filesArray removeObjectsAtIndexes:rowIndexes]; [self.queue removeItemsAtIndexes:rowIndexes];
for (id object in [objects reverseObjectEnumerator]) for (id object in [objects reverseObjectEnumerator])
[filesArray insertObject:object atIndex:row]; [self.queue insertItem:object atIndex:row];
NSIndexSet *selectionSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(row, [rowIndexes count])]; NSIndexSet *selectionSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(row, [rowIndexes count])];
@@ -905,15 +557,14 @@ static NSString *fileType = @"mp4";
[view selectRowIndexes:selectionSet byExtendingSelection:NO]; [view selectRowIndexes:selectionSet byExtendingSelection:NO];
return YES; return YES;
} } else { // From other documents
else { // From other documents if ([[pboard types] containsObject:NSURLPboardType] ) {
if ( [[pboard types] containsObject:NSURLPboardType] ) { NSArray *items = [pboard readObjectsForClasses:
NSArray * items = [pboard readObjectsForClasses:
[NSArray arrayWithObject: [NSURL class]] options: nil]; [NSArray arrayWithObject: [NSURL class]] options: nil];
NSMutableArray *queueItems = [[NSMutableArray alloc] init]; NSMutableArray *queueItems = [[NSMutableArray alloc] init];
NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init]; NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
for (NSURL * url in items) { for (NSURL *url in items) {
[queueItems addObject:[SBQueueItem itemWithURL:url]]; [queueItems addObject:[SBQueueItem itemWithURL:url]];
[indexes addIndex:row]; [indexes addIndex:row];
} }
@@ -924,7 +575,7 @@ static NSString *fileType = @"mp4";
[indexes release]; [indexes release];
[self updateUI]; [self updateUI];
if ([AutoStartOption state]) if ([_autoStartOption state])
[self start:self]; [self start:self];
return YES; return YES;
@@ -937,29 +588,28 @@ static NSString *fileType = @"mp4";
- (void)addItem:(SBQueueItem *)item - (void)addItem:(SBQueueItem *)item
{ {
[self addItems:[NSArray arrayWithObject:item] atIndexes:nil]; [self addItems:[NSArray arrayWithObject:item] atIndexes:nil];
[self updateUI]; [self updateUI];
if ([AutoStartOption state]) if ([_autoStartOption state])
[self start:self]; [self start:self];
} }
- (void)addItems:(NSArray *)items atIndexes:(NSIndexSet *)indexes; - (void)addItems:(NSArray *)items atIndexes:(NSIndexSet *)indexes;
{ {
NSMutableIndexSet *mutableIndexes = [indexes mutableCopy]; NSMutableIndexSet *mutableIndexes = [indexes mutableCopy];
if ([indexes count] == [items count]) if ([indexes count] == [items count]) {
for (id item in [items reverseObjectEnumerator]) { for (id item in [items reverseObjectEnumerator]) {
[filesArray insertObject:item atIndex:[mutableIndexes firstIndex]]; [self.queue insertItem:item atIndex:[mutableIndexes firstIndex]];
[mutableIndexes removeIndexesInRange:NSMakeRange(0, 1)]; [mutableIndexes removeIndexesInRange:NSMakeRange(0, 1)];
} }
else if ([indexes count] == 1) { } else if ([indexes count] == 1) {
for (id item in [items reverseObjectEnumerator]) { for (id item in [items reverseObjectEnumerator]) {
[filesArray insertObject:item atIndex:[mutableIndexes firstIndex]]; [self.queue insertItem:item atIndex:[mutableIndexes firstIndex]];
} }
} } else {
else
for (id item in [items reverseObjectEnumerator]) { for (id item in [items reverseObjectEnumerator]) {
[filesArray addObject:item]; [self.queue addItem:item];
}
} }
NSUndoManager *undo = [[self window] undoManager]; NSUndoManager *undo = [[self window] undoManager];
@@ -971,7 +621,7 @@ static NSString *fileType = @"mp4";
if ([undo isUndoing] || [undo isRedoing]) if ([undo isUndoing] || [undo isRedoing])
[self updateUI]; [self updateUI];
if ([AutoStartOption state]) if ([_autoStartOption state])
[self start:self]; [self start:self];
[mutableIndexes release]; [mutableIndexes release];
@@ -982,8 +632,8 @@ static NSString *fileType = @"mp4";
NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init]; NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
for (id item in items) { for (id item in items) {
[indexes addIndex:[filesArray indexOfObject:item]]; [indexes addIndex:[self.queue indexOfItem:item]];
[filesArray removeObject:item]; [self.queue removeItem:item];
} }
NSUndoManager *undo = [[self window] undoManager]; NSUndoManager *undo = [[self window] undoManager];
+274 -1561
View File
File diff suppressed because it is too large. Load diff