Connect SBQueueController to the new SBQueue instance.
This commit is contained in:
1 parent
dab25ea4b8
commit
f1dab1fe48
5 files changed
+454
-2064
No files matched your search
@@ -21,6 +21,11 @@ typedef NS_ENUM(NSUInteger, SBQueueStatus) {
|
||||
SBQueueStatusCancelled,
|
||||
};
|
||||
|
||||
extern NSString *SBQueueWorkingNotification;
|
||||
extern NSString *SBQueueCompletedNotification;
|
||||
extern NSString *SBQueueFailedNotification;
|
||||
extern NSString *SBQueueCancelledNotification;
|
||||
|
||||
@interface SBQueue : NSObject {
|
||||
@private
|
||||
dispatch_queue_t _queue;
|
||||
|
||||
+54
-20
@@ -18,6 +18,11 @@
|
||||
|
||||
static NSString *fileType = @"mp4";
|
||||
|
||||
NSString *SBQueueWorkingNotification = @"SBQueueWorkingNotification";
|
||||
NSString *SBQueueCompletedNotification = @"SBQueueCompletedNotification";
|
||||
NSString *SBQueueFailedNotification = @"SBQueueFailedNotification";
|
||||
NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
|
||||
@interface SBQueue () <MP42FileDelegate>
|
||||
|
||||
@property (atomic) SBQueueStatus status;
|
||||
@@ -39,7 +44,6 @@ static NSString *fileType = @"mp4";
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_queue = dispatch_queue_create("org.subler.Queue", NULL);
|
||||
|
||||
_URL = [queueURL copy];
|
||||
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:[queueURL path]]) {
|
||||
@@ -80,8 +84,7 @@ static NSString *fileType = @"mp4";
|
||||
|
||||
#pragma mark - item management
|
||||
|
||||
- (void)addItem:(SBQueueItem *)item
|
||||
{
|
||||
- (void)addItem:(SBQueueItem *)item {
|
||||
[self.items addObject:item];
|
||||
}
|
||||
|
||||
@@ -94,6 +97,7 @@ static NSString *fileType = @"mp4";
|
||||
for (SBQueueItem *item in self.items)
|
||||
if ([item status] != SBQueueItemStatusCompleted)
|
||||
count++;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -135,8 +139,7 @@ static NSString *fileType = @"mp4";
|
||||
|
||||
#pragma mark - item preprocessing
|
||||
|
||||
- (NSArray *)loadSubtitles:(NSURL *)url
|
||||
{
|
||||
- (NSArray *)loadSubtitles:(NSURL *)url {
|
||||
NSError *outError;
|
||||
NSMutableArray *tracksArray = [[NSMutableArray alloc] init];
|
||||
NSArray *directory = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:[url URLByDeletingLastPathComponent]
|
||||
@@ -171,8 +174,7 @@ static NSString *fileType = @"mp4";
|
||||
return [tracksArray autorelease];
|
||||
}
|
||||
|
||||
- (MP42Image *)loadArtwork:(NSURL *)url
|
||||
{
|
||||
- (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];
|
||||
@@ -184,8 +186,7 @@ static NSString *fileType = @"mp4";
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (MP42Metadata *)searchMetadataForFile:(NSURL *)url
|
||||
{
|
||||
- (MP42Metadata *)searchMetadataForFile:(NSURL *)url {
|
||||
id currentSearcher = nil;
|
||||
MP42Metadata *metadata = nil;
|
||||
|
||||
@@ -350,6 +351,7 @@ static NSString *fileType = @"mp4";
|
||||
break;
|
||||
}
|
||||
|
||||
[self handleSBStatusWorking];
|
||||
noErr = [self processItem:item error:&outError];
|
||||
|
||||
// Check results
|
||||
@@ -387,13 +389,21 @@ static NSString *fileType = @"mp4";
|
||||
}
|
||||
}
|
||||
|
||||
// Save to disk
|
||||
[self saveQueueToDisk];
|
||||
|
||||
// Disable sleep assertion
|
||||
[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];
|
||||
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"chaptersPreviewTrack"] boolValue])
|
||||
[attributes setObject:@YES forKey:MP42GenerateChaptersPreviewTrack];
|
||||
@@ -408,14 +418,6 @@ static NSString *fileType = @"mp4";
|
||||
_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 && self.destination /*&& customDestination*/) {
|
||||
@@ -426,8 +428,9 @@ static NSString *fileType = @"mp4";
|
||||
}
|
||||
|
||||
// The file has been added directly to the queue
|
||||
if (!_currentMP4 && item.URL)
|
||||
if (!_currentMP4 && item.URL) {
|
||||
_currentMP4 = [self prepareQueueItem:item.URL error:outError];
|
||||
}
|
||||
|
||||
NSDictionary *dict = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[_currentMP4.URL path] error:NULL];
|
||||
NSNumber *freeSpace = [dict objectForKey:NSFileSystemFreeSize];
|
||||
@@ -458,9 +461,40 @@ static NSString *fileType = @"mp4";
|
||||
}
|
||||
|
||||
- (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 {
|
||||
dispatch_release(_queue);
|
||||
|
||||
+16
-28
@@ -9,49 +9,37 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <IOKit/pwr_mgt/IOPMLib.h>
|
||||
|
||||
#import "SBQueue.h"
|
||||
|
||||
@class SBQueueItem;
|
||||
@class SBTableView;
|
||||
@class MP42File;
|
||||
|
||||
typedef enum SBQueueStatus : NSUInteger {
|
||||
SBQueueStatusUnknown = 0,
|
||||
SBQueueStatusWorking,
|
||||
SBQueueStatusCompleted,
|
||||
SBQueueStatusFailed,
|
||||
SBQueueStatusCancelled,
|
||||
} SBQueueStatus;
|
||||
|
||||
@interface SBQueueController : NSWindowController {
|
||||
IBOutlet NSButton *start;
|
||||
IBOutlet NSButton *open;
|
||||
IBOutlet NSButton *_start;
|
||||
IBOutlet NSButton *_open;
|
||||
|
||||
IBOutlet NSTextField *countLabel;
|
||||
IBOutlet NSProgressIndicator *progressIndicator;
|
||||
IBOutlet NSTextField *_countLabel;
|
||||
IBOutlet NSProgressIndicator *_progressIndicator;
|
||||
|
||||
IBOutlet NSButton *OptimizeOption;
|
||||
IBOutlet NSButton *MetadataOption;
|
||||
IBOutlet NSButton *ITunesGroupsOption;
|
||||
IBOutlet NSButton *AutoStartOption;
|
||||
IBOutlet NSBox *optionsBox;
|
||||
BOOL optionsStatus;
|
||||
IBOutlet NSButton *_optimizeOption;
|
||||
IBOutlet NSButton *_metadataOption;
|
||||
IBOutlet NSButton *_organizeGroupsOption;
|
||||
IBOutlet NSButton *_autoStartOption;
|
||||
IBOutlet NSBox *_optionsBox;
|
||||
BOOL _optionsStatus;
|
||||
|
||||
IBOutlet NSScrollView *tableScrollView;
|
||||
IBOutlet SBTableView *tableView;
|
||||
|
||||
NSURL *destination;
|
||||
BOOL customDestination;
|
||||
IBOutlet NSPopUpButton *destButton;
|
||||
|
||||
NSImage *docImg;
|
||||
|
||||
dispatch_queue_t queue;
|
||||
MP42File *_currentMP4;
|
||||
NSURL *destination;
|
||||
BOOL customDestination;
|
||||
|
||||
NSMutableArray *filesArray;
|
||||
SBQueueStatus status;
|
||||
|
||||
IOPMAssertionID _assertionID;
|
||||
BOOL _cancelled;
|
||||
SBQueue *_queue;
|
||||
}
|
||||
|
||||
@property(readonly) SBQueueStatus status;
|
||||
@@ -61,7 +49,7 @@ typedef enum SBQueueStatus : NSUInteger {
|
||||
- (void)start:(id)sender;
|
||||
- (void)stop:(id)sender;
|
||||
|
||||
- (void)addItem:(SBQueueItem*)item;
|
||||
- (void)addItem:(SBQueueItem *)item;
|
||||
|
||||
- (BOOL)saveQueueToDisk;
|
||||
|
||||
|
||||
+105
-455
@@ -12,18 +12,16 @@
|
||||
#import "SBTableView.h"
|
||||
#import "MetadataImporter.h"
|
||||
|
||||
#import <MP42Foundation/MP42File.h>
|
||||
#import <MP42Foundation/MP42FileImporter.h>
|
||||
#import <MP42Foundation/MP42Image.h>
|
||||
#import <MP42Foundation/MP42Utilities.h>
|
||||
|
||||
|
||||
#define SublerBatchTableViewDataType @"SublerBatchTableViewDataType"
|
||||
#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)updateDockTile;
|
||||
- (NSURL *)queueURL;
|
||||
@@ -32,49 +30,28 @@ static NSString *fileType = @"mp4";
|
||||
|
||||
- (void)addItems:(NSArray *)items atIndexes:(NSIndexSet *)indexes;
|
||||
- (void)removeItems:(NSArray *)items;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation SBQueueController
|
||||
|
||||
@synthesize status;
|
||||
|
||||
@synthesize queue = _queue;
|
||||
|
||||
+ (SBQueueController *)sharedManager
|
||||
{
|
||||
static dispatch_once_t pred;
|
||||
static SBQueueController *sharedManager = nil;
|
||||
|
||||
|
||||
dispatch_once(&pred, ^{ sharedManager = [[self alloc] init]; });
|
||||
return sharedManager;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
if (self = [super initWithWindowNibName:@"Queue"])
|
||||
{
|
||||
queue = dispatch_queue_create("org.subler.Queue", NULL);
|
||||
|
||||
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];
|
||||
|
||||
if (self = [super initWithWindowNibName:@"Queue"]) {
|
||||
_queue = [[SBQueue alloc] initWithURL:[self queueURL]];
|
||||
[self removeCompletedItems:self];
|
||||
[self updateDockTile];
|
||||
}
|
||||
|
||||
@@ -83,8 +60,8 @@ static NSString *fileType = @"mp4";
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
[progressIndicator setHidden:YES];
|
||||
[countLabel setStringValue:@"Empty"];
|
||||
[_progressIndicator setHidden:YES];
|
||||
[_countLabel setStringValue:@"Empty"];
|
||||
|
||||
NSRect frame = [[self window] frame];
|
||||
frame.size.height += kOptionsPanelHeight;
|
||||
@@ -97,47 +74,65 @@ static NSString *fileType = @"mp4";
|
||||
frame.origin.y += kOptionsPanelHeight;
|
||||
|
||||
[tableScrollView setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
|
||||
[optionsBox setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
|
||||
[_optionsBox setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
|
||||
|
||||
[[self window] setFrame:frame display:YES animate:NO];
|
||||
|
||||
[tableScrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||
[optionsBox setAutoresizingMask:NSViewWidthSizable | NSViewMaxYMargin];
|
||||
[_optionsBox setAutoresizingMask:NSViewWidthSizable | NSViewMaxYMargin];
|
||||
|
||||
docImg = [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode('MOOV')] retain];
|
||||
[docImg setSize:NSMakeSize(16, 16)];
|
||||
|
||||
[self prepareDestPopup];
|
||||
[self updateUI];
|
||||
}
|
||||
|
||||
- (void)windowDidLoad
|
||||
{
|
||||
[super windowDidLoad];
|
||||
[self removeCompletedItems:self];
|
||||
|
||||
[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;
|
||||
|
||||
NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory,
|
||||
NSUserDomainMask,
|
||||
YES);
|
||||
if ([allPaths count]) {
|
||||
appSupportURL = [NSURL fileURLWithPath:[[[allPaths lastObject] stringByAppendingPathComponent:@"Subler"] stringByAppendingPathComponent:@"queue.sbqueue"] isDirectory:YES];
|
||||
|
||||
return appSupportURL;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)saveQueueToDisk
|
||||
{
|
||||
return [NSKeyedArchiver archiveRootObject:filesArray toFile:[[self queueURL] path]];
|
||||
- (SBQueueStatus)status {
|
||||
return self.queue.status;
|
||||
}
|
||||
|
||||
- (BOOL)saveQueueToDisk {
|
||||
return [self.queue saveQueueToDisk];
|
||||
}
|
||||
|
||||
- (NSMenuItem *)prepareDestPopupItem:(NSURL*) dest
|
||||
@@ -145,7 +140,7 @@ static NSString *fileType = @"mp4";
|
||||
NSMenuItem *folderItem = [[NSMenuItem alloc] initWithTitle:[dest lastPathComponent] action:@selector(destination:) keyEquivalent:@""];
|
||||
[folderItem setTag:10];
|
||||
|
||||
NSImage* menuItemIcon = [[NSWorkspace sharedWorkspace] iconForFile:[dest path]];
|
||||
NSImage *menuItemIcon = [[NSWorkspace sharedWorkspace] iconForFile:[dest path]];
|
||||
[menuItemIcon setSize:NSMakeSize(16, 16)];
|
||||
|
||||
[folderItem setImage:menuItemIcon];
|
||||
@@ -203,8 +198,7 @@ static NSString *fileType = @"mp4";
|
||||
if ([sender tag] == 10) {
|
||||
customDestination = YES;
|
||||
[[NSUserDefaults standardUserDefaults] setValue:@"YES" forKey:@"SBQueueDestinationSelected"];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
customDestination = NO;
|
||||
[[NSUserDefaults standardUserDefaults] setValue:nil forKey:@"SBQueueDestinationSelected"];
|
||||
}
|
||||
@@ -212,10 +206,7 @@ static NSString *fileType = @"mp4";
|
||||
|
||||
- (void)updateDockTile
|
||||
{
|
||||
int count = 0;
|
||||
for (SBQueueItem *item in filesArray)
|
||||
if ([item status] != SBQueueItemStatusCompleted)
|
||||
count++;
|
||||
NSUInteger count = [self.queue readyCount];
|
||||
|
||||
if (count)
|
||||
[[NSApp dockTile] setBadgeLabel:[NSString stringWithFormat:@"%d", count]];
|
||||
@@ -226,369 +217,42 @@ static NSString *fileType = @"mp4";
|
||||
- (void)updateUI
|
||||
{
|
||||
[tableView reloadData];
|
||||
if (status != SBQueueStatusWorking) {
|
||||
[countLabel setStringValue:[NSString stringWithFormat:@"%lu files in queue.", (unsigned long)[filesArray count]]];
|
||||
if (self.queue.status != SBQueueStatusWorking) {
|
||||
[_countLabel setStringValue:[NSString stringWithFormat:@"%lu files in queue.", (unsigned long)[self.queue count]]];
|
||||
[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
|
||||
{
|
||||
if (status == SBQueueStatusWorking)
|
||||
if (self.queue.status == SBQueueStatusWorking)
|
||||
return;
|
||||
|
||||
status = SBQueueStatusWorking;
|
||||
[_start setTitle:@"Stop"];
|
||||
[_countLabel setStringValue:@"Working."];
|
||||
[_progressIndicator setHidden:NO];
|
||||
[_progressIndicator startAnimation:self];
|
||||
|
||||
[start setTitle:@"Stop"];
|
||||
[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];
|
||||
[self.queue start];
|
||||
}
|
||||
|
||||
- (void)progressStatus: (CGFloat)progress {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[progressIndicator setIndeterminate:NO];
|
||||
[progressIndicator setDoubleValue:progress];
|
||||
[_progressIndicator setIndeterminate:NO];
|
||||
[_progressIndicator setDoubleValue:progress];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)stop:(id)sender
|
||||
{
|
||||
_cancelled = YES;
|
||||
[_currentMP4 cancel];
|
||||
[self.queue stop];
|
||||
}
|
||||
|
||||
- (IBAction)toggleStartStop:(id)sender
|
||||
{
|
||||
if (status == SBQueueStatusWorking) {
|
||||
if (self.queue.status == SBQueueStatusWorking) {
|
||||
[self stop:sender];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
[self start:sender];
|
||||
}
|
||||
}
|
||||
@@ -596,13 +260,13 @@ static NSString *fileType = @"mp4";
|
||||
- (IBAction)toggleOptions:(id)sender
|
||||
{
|
||||
NSInteger value = 0;
|
||||
if (optionsStatus) {
|
||||
if (_optionsStatus) {
|
||||
value = -kOptionsPanelHeight;
|
||||
optionsStatus = NO;
|
||||
_optionsStatus = NO;
|
||||
}
|
||||
else {
|
||||
value = kOptionsPanelHeight;
|
||||
optionsStatus = YES;
|
||||
_optionsStatus = YES;
|
||||
}
|
||||
|
||||
NSRect frame = [[self window] frame];
|
||||
@@ -610,12 +274,12 @@ static NSString *fileType = @"mp4";
|
||||
frame.origin.y -= value;
|
||||
|
||||
[tableScrollView setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
|
||||
[optionsBox setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
|
||||
[_optionsBox setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
|
||||
|
||||
[[self window] setFrame:frame display:YES animate:YES];
|
||||
|
||||
[tableScrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||
[optionsBox setAutoresizingMask:NSViewWidthSizable | NSViewMaxYMargin];
|
||||
[_optionsBox setAutoresizingMask:NSViewWidthSizable | NSViewMaxYMargin];
|
||||
}
|
||||
|
||||
#pragma mark Open methods
|
||||
@@ -640,7 +304,7 @@ static NSString *fileType = @"mp4";
|
||||
|
||||
[self updateUI];
|
||||
|
||||
if ([AutoStartOption state])
|
||||
if ([_autoStartOption state])
|
||||
[self start:self];
|
||||
}
|
||||
}];
|
||||
@@ -693,16 +357,16 @@ static NSString *fileType = @"mp4";
|
||||
|
||||
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
|
||||
{
|
||||
return [filesArray count];
|
||||
return [self.queue count];
|
||||
}
|
||||
|
||||
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
|
||||
{
|
||||
if ([aTableColumn.identifier isEqualToString:@"nameColumn"])
|
||||
return [[[filesArray objectAtIndex:rowIndex] URL] lastPathComponent];
|
||||
return [[[self.queue itemAtIndex:rowIndex] URL] lastPathComponent];
|
||||
|
||||
if ([aTableColumn.identifier isEqualToString:@"statusColumn"]) {
|
||||
SBQueueItemStatus batchStatus = [(SBQueueItem *)[filesArray objectAtIndex:rowIndex] status];
|
||||
SBQueueItemStatus batchStatus = [[self.queue itemAtIndex:rowIndex] status];
|
||||
if (batchStatus == SBQueueItemStatusCompleted)
|
||||
return [NSImage imageNamed:@"EncodeComplete"];
|
||||
else if (batchStatus == SBQueueItemStatusWorking)
|
||||
@@ -719,22 +383,22 @@ static NSString *fileType = @"mp4";
|
||||
- (void)_deleteSelectionFromTableView:(NSTableView *)aTableView
|
||||
{
|
||||
NSMutableIndexSet *rowIndexes = [[aTableView selectedRowIndexes] mutableCopy];
|
||||
NSInteger clickedRow = [aTableView clickedRow];
|
||||
NSUInteger selectedIndex = -1;
|
||||
if ([rowIndexes count])
|
||||
selectedIndex = [rowIndexes firstIndex];
|
||||
NSInteger clickedRow = [aTableView clickedRow];
|
||||
|
||||
if (clickedRow != -1 && ![rowIndexes containsIndex:clickedRow]) {
|
||||
[rowIndexes removeAllIndexes];
|
||||
[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
|
||||
for (SBQueueItem *item in array)
|
||||
if ([item status] == SBQueueItemStatusWorking)
|
||||
[rowIndexes removeIndex:[filesArray indexOfObject:item]];
|
||||
[rowIndexes removeIndex:[self.queue indexOfItem:item]];
|
||||
|
||||
if ([rowIndexes count]) {
|
||||
if ([NSTableView instancesRespondToSelector:@selector(beginUpdates)]) {
|
||||
@@ -752,8 +416,8 @@ static NSString *fileType = @"mp4";
|
||||
[aTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedIndex] byExtendingSelection:NO];
|
||||
}
|
||||
|
||||
if (status != SBQueueStatusWorking) {
|
||||
[countLabel setStringValue:[NSString stringWithFormat:@"%lu files in queue.", (unsigned long)[filesArray count]]];
|
||||
if (self.queue.status != SBQueueStatusWorking) {
|
||||
[_countLabel setStringValue:[NSString stringWithFormat:@"%lu files in queue.", (unsigned long)[self.queue count]]];
|
||||
[self updateDockTile];
|
||||
}
|
||||
}
|
||||
@@ -762,7 +426,7 @@ static NSString *fileType = @"mp4";
|
||||
|
||||
- (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 updateUI];
|
||||
@@ -775,12 +439,12 @@ static NSString *fileType = @"mp4";
|
||||
|
||||
SBDocument *doc = [[NSDocumentController sharedDocumentController] openUntitledDocumentAndDisplay:YES error:NULL];
|
||||
[doc setMp4File:mp4];
|
||||
[item release];
|
||||
[item release];*/
|
||||
}
|
||||
|
||||
- (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];
|
||||
}
|
||||
|
||||
@@ -791,35 +455,24 @@ static NSString *fileType = @"mp4";
|
||||
|
||||
- (IBAction)removeCompletedItems:(id)sender
|
||||
{
|
||||
NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
|
||||
|
||||
for (SBQueueItem *item in filesArray)
|
||||
if ([item status] == SBQueueItemStatusCompleted)
|
||||
[indexes addIndex:[filesArray indexOfObject:item]];
|
||||
NSIndexSet *indexes = [self.queue removeCompletedItems];
|
||||
|
||||
if ([indexes count]) {
|
||||
if ([NSTableView instancesRespondToSelector:@selector(beginUpdates)]) {
|
||||
#if __MAC_OS_X_VERSION_MAX_ALLOWED > 1060
|
||||
[tableView beginUpdates];
|
||||
[tableView removeRowsAtIndexes:indexes withAnimation:NSTableViewAnimationEffectFade];
|
||||
NSArray* items = [filesArray objectsAtIndexes:indexes];
|
||||
[self removeItems:items];
|
||||
[tableView endUpdates];
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
NSArray *items = [filesArray objectsAtIndexes:indexes];
|
||||
[self removeItems:items];
|
||||
} else {
|
||||
[tableView reloadData];
|
||||
}
|
||||
|
||||
if (status != SBQueueStatusWorking) {
|
||||
[countLabel setStringValue:[NSString stringWithFormat:@"%lu files in queue.", (unsigned long)[filesArray count]]];
|
||||
if (self.queue.status != SBQueueStatusWorking) {
|
||||
[_countLabel setStringValue:[NSString stringWithFormat:@"%lu files in queue.", (unsigned long)[self.queue count]]];
|
||||
[self updateDockTile];
|
||||
}
|
||||
}
|
||||
|
||||
[indexes release];
|
||||
}
|
||||
|
||||
- (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem
|
||||
@@ -832,7 +485,7 @@ static NSString *fileType = @"mp4";
|
||||
|
||||
if (action == @selector(showInFinder:)) {
|
||||
if ([tableView clickedRow] != -1) {
|
||||
SBQueueItem *item = [filesArray objectAtIndex:[tableView clickedRow]];
|
||||
SBQueueItem *item = [self.queue itemAtIndex:[tableView clickedRow]];
|
||||
if ([item status] == SBQueueItemStatusCompleted)
|
||||
return YES;
|
||||
}
|
||||
@@ -872,12 +525,11 @@ static NSString *fileType = @"mp4";
|
||||
if (nil == [info draggingSource]) { // From other application
|
||||
[view setDropRow: row dropOperation: NSTableViewDropAbove];
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
else if (view == [info draggingSource] && operation == NSTableViewDropAbove) { // From self
|
||||
} else if (view == [info draggingSource] && operation == NSTableViewDropAbove) { // From self
|
||||
return NSDragOperationEvery;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)tableView:(NSTableView *)view
|
||||
@@ -888,16 +540,16 @@ static NSString *fileType = @"mp4";
|
||||
NSPasteboard *pboard = [info draggingPasteboard];
|
||||
|
||||
if (tableView == [info draggingSource]) { // From self
|
||||
NSData* rowData = [pboard dataForType:SublerBatchTableViewDataType];
|
||||
NSIndexSet* rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData];
|
||||
NSData *rowData = [pboard dataForType:SublerBatchTableViewDataType];
|
||||
NSIndexSet *rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData];
|
||||
NSUInteger i = [rowIndexes countOfIndexesInRange:NSMakeRange(0, row)];
|
||||
row -= i;
|
||||
|
||||
NSArray *objects = [filesArray objectsAtIndexes:rowIndexes];
|
||||
[filesArray removeObjectsAtIndexes:rowIndexes];
|
||||
NSArray *objects = [self.queue itemsAtIndexes:rowIndexes];
|
||||
[self.queue removeItemsAtIndexes:rowIndexes];
|
||||
|
||||
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])];
|
||||
|
||||
@@ -905,15 +557,14 @@ static NSString *fileType = @"mp4";
|
||||
[view selectRowIndexes:selectionSet byExtendingSelection:NO];
|
||||
|
||||
return YES;
|
||||
}
|
||||
else { // From other documents
|
||||
if ( [[pboard types] containsObject:NSURLPboardType] ) {
|
||||
NSArray * items = [pboard readObjectsForClasses:
|
||||
} else { // From other documents
|
||||
if ([[pboard types] containsObject:NSURLPboardType] ) {
|
||||
NSArray *items = [pboard readObjectsForClasses:
|
||||
[NSArray arrayWithObject: [NSURL class]] options: nil];
|
||||
NSMutableArray *queueItems = [[NSMutableArray alloc] init];
|
||||
NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
|
||||
|
||||
for (NSURL * url in items) {
|
||||
for (NSURL *url in items) {
|
||||
[queueItems addObject:[SBQueueItem itemWithURL:url]];
|
||||
[indexes addIndex:row];
|
||||
}
|
||||
@@ -924,7 +575,7 @@ static NSString *fileType = @"mp4";
|
||||
[indexes release];
|
||||
[self updateUI];
|
||||
|
||||
if ([AutoStartOption state])
|
||||
if ([_autoStartOption state])
|
||||
[self start:self];
|
||||
|
||||
return YES;
|
||||
@@ -937,30 +588,29 @@ static NSString *fileType = @"mp4";
|
||||
- (void)addItem:(SBQueueItem *)item
|
||||
{
|
||||
[self addItems:[NSArray arrayWithObject:item] atIndexes:nil];
|
||||
|
||||
[self updateUI];
|
||||
|
||||
if ([AutoStartOption state])
|
||||
if ([_autoStartOption state])
|
||||
[self start:self];
|
||||
}
|
||||
|
||||
- (void)addItems:(NSArray *)items atIndexes:(NSIndexSet *)indexes;
|
||||
{
|
||||
NSMutableIndexSet *mutableIndexes = [indexes mutableCopy];
|
||||
if ([indexes count] == [items count])
|
||||
if ([indexes count] == [items count]) {
|
||||
for (id item in [items reverseObjectEnumerator]) {
|
||||
[filesArray insertObject:item atIndex:[mutableIndexes firstIndex]];
|
||||
[self.queue insertItem:item atIndex:[mutableIndexes firstIndex]];
|
||||
[mutableIndexes removeIndexesInRange:NSMakeRange(0, 1)];
|
||||
}
|
||||
else if ([indexes count] == 1) {
|
||||
} else if ([indexes count] == 1) {
|
||||
for (id item in [items reverseObjectEnumerator]) {
|
||||
[filesArray insertObject:item atIndex:[mutableIndexes firstIndex]];
|
||||
[self.queue insertItem:item atIndex:[mutableIndexes firstIndex]];
|
||||
}
|
||||
} else {
|
||||
for (id item in [items reverseObjectEnumerator]) {
|
||||
[self.queue addItem:item];
|
||||
}
|
||||
}
|
||||
else
|
||||
for (id item in [items reverseObjectEnumerator]) {
|
||||
[filesArray addObject:item];
|
||||
}
|
||||
|
||||
NSUndoManager *undo = [[self window] undoManager];
|
||||
[[undo prepareWithInvocationTarget:self] removeItems:items];
|
||||
@@ -971,7 +621,7 @@ static NSString *fileType = @"mp4";
|
||||
if ([undo isUndoing] || [undo isRedoing])
|
||||
[self updateUI];
|
||||
|
||||
if ([AutoStartOption state])
|
||||
if ([_autoStartOption state])
|
||||
[self start:self];
|
||||
|
||||
[mutableIndexes release];
|
||||
@@ -982,8 +632,8 @@ static NSString *fileType = @"mp4";
|
||||
NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
|
||||
|
||||
for (id item in items) {
|
||||
[indexes addIndex:[filesArray indexOfObject:item]];
|
||||
[filesArray removeObject:item];
|
||||
[indexes addIndex:[self.queue indexOfItem:item]];
|
||||
[self.queue removeItem:item];
|
||||
}
|
||||
|
||||
NSUndoManager *undo = [[self window] undoManager];
|
||||
|
||||
+274
-1561
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user