Refactored some code
This commit is contained in:
1 parent
76ce1e5ebb
commit
91fd1c0542
9 files changed
+39
-29
No files matched your search
@@ -6,21 +6,25 @@
|
||||
// Copyright 2011 Douglas Stebila. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "MetadataImporter.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface iTunesStore : MetadataImporter
|
||||
|
||||
#pragma mark iTunes stores
|
||||
+ (NSDictionary *) getStoreFor:(NSString *)aLanguageString;
|
||||
+ (NSDictionary * __nullable) getStoreFor:(NSString *)aLanguageString;
|
||||
|
||||
#pragma mark Quick iTunes search for metadata
|
||||
+ (MP42Metadata *) quickiTunesSearchTV:(NSString *)aSeriesName episodeTitle:(NSString *)aEpisodeTitle;
|
||||
+ (MP42Metadata *) quickiTunesSearchMovie:(NSString *)aMovieName;
|
||||
|
||||
#pragma mark Parse results
|
||||
+ (NSArray *) readPeople:(NSString *)aPeople fromXML:(NSXMLDocument *)aXml;
|
||||
+ (NSArray *) metadataForResults:(NSDictionary *)dict store:(NSDictionary *)store;
|
||||
+ (NSArray<NSString *> *) readPeople:(NSString *)aPeople fromXML:(NSXMLDocument *)aXml;
|
||||
+ (NSArray<MP42Metadata *> *) metadataForResults:(NSDictionary *)dict store:(NSDictionary *)store;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -286,7 +286,7 @@ NSInteger sortMP42Metadata(id ep1, id ep2, void *context)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
return @[];
|
||||
}
|
||||
|
||||
+ (NSArray *) metadataForResults:(NSDictionary *)dict store:(NSDictionary *)store {
|
||||
|
||||
@@ -201,12 +201,18 @@
|
||||
[extension caseInsensitiveCompare: @"mks"] == NSOrderedSame ||
|
||||
[extension caseInsensitiveCompare: @"mov"] == NSOrderedSame) {
|
||||
|
||||
CFRetain(completionHandler);
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSError *outError;
|
||||
|
||||
SBDocument *doc = [self openUntitledDocumentAndDisplay:displayDocument error:&outError];
|
||||
[doc performSelectorOnMainThread:@selector(showImportSheet:) withObject:[NSArray arrayWithObject:url] waitUntilDone:NO];
|
||||
SBDocument *doc = [[self openUntitledDocumentAndDisplay:displayDocument error:&outError] retain];
|
||||
completionHandler(doc, NO, outError);
|
||||
if (doc) {
|
||||
[doc showImportSheet:@[url]];
|
||||
}
|
||||
CFRelease(completionHandler);
|
||||
[doc release];
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -625,7 +625,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
|
||||
[attributes setObject:@YES forKey:MP42GenerateChaptersPreviewTrack];
|
||||
}
|
||||
|
||||
SBQueueItem *item = [SBQueueItem itemWithMP4:self.mp4 url:panel.URL attributes:attributes];
|
||||
SBQueueItem *item = [SBQueueItem itemWithMP4:self.mp4 destinationURL:panel.URL attributes:attributes];
|
||||
[queue addItem:item];
|
||||
|
||||
[attributes release];
|
||||
|
||||
@@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
NSButton *_editButton;
|
||||
NSProgressIndicator *_spinner;
|
||||
|
||||
id _delegate;
|
||||
id<SBItemViewDelegate> _delegate;
|
||||
}
|
||||
|
||||
@property (nonatomic, readonly) SBQueueItem *item;
|
||||
|
||||
+10
-11
@@ -88,7 +88,7 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
_docImg = [[[NSWorkspace sharedWorkspace] iconForFileType:@"public.movie"] retain];
|
||||
[_docImg setSize:NSMakeSize(16, 16)];
|
||||
|
||||
[_tableView registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, SublerBatchTableViewDataType, nil]];
|
||||
[_tableView registerForDraggedTypes:@[NSFilenamesPboardType, SublerBatchTableViewDataType]];
|
||||
|
||||
|
||||
// Observe the changes to SBQueueOptimize
|
||||
@@ -232,7 +232,7 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
|
||||
[self.itemPopover close];
|
||||
|
||||
[self removeItems:[NSArray arrayWithObject:item]];
|
||||
[self removeItems:@[item]];
|
||||
[self updateUI];
|
||||
} else {
|
||||
NSLog(@"%@", error);
|
||||
@@ -292,7 +292,7 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
* Adds a SBQueueItem to the queue
|
||||
*/
|
||||
- (void)addItem:(SBQueueItem *)item {
|
||||
[self addItems:[NSArray arrayWithObject:item] atIndexes:nil];
|
||||
[self addItems:@[item] atIndexes:nil];
|
||||
[self updateUI];
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
* Adds an array of SBQueueItem to the queue.
|
||||
* Implements the undo manager.
|
||||
*/
|
||||
- (void)addItems:(NSArray *)items atIndexes:(NSIndexSet *)indexes; {
|
||||
- (void)addItems:(NSArray<SBQueueItem *> *)items atIndexes:(NSIndexSet *)indexes; {
|
||||
NSMutableIndexSet *mutableIndexes = [indexes mutableCopy];
|
||||
if ([indexes count] == [items count]) {
|
||||
for (id item in [items reverseObjectEnumerator]) {
|
||||
@@ -336,7 +336,7 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
* Removes an array of SBQueueItemfromto the queue.
|
||||
* Implements the undo manager.
|
||||
*/
|
||||
- (void)removeItems:(NSArray *)items {
|
||||
- (void)removeItems:(NSArray<SBQueueItem *> *)items {
|
||||
NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
|
||||
|
||||
for (id item in items) {
|
||||
@@ -534,7 +534,7 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
|
||||
[panel beginSheetModalForWindow:[self window] completionHandler:^(NSInteger result) {
|
||||
if (result == NSFileHandlingPanelOKButton) {
|
||||
NSMutableArray *items = [[NSMutableArray alloc] init];
|
||||
NSMutableArray<SBQueueItem *> *items = [[NSMutableArray alloc] init];
|
||||
|
||||
for (NSURL *url in [panel URLs]) {
|
||||
SBQueueItem *item = [self createItemWithURL:url];
|
||||
@@ -585,7 +585,7 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
[rowIndexes addIndex:clickedRow];
|
||||
}
|
||||
|
||||
NSArray *array = [self.queue itemsAtIndexes:rowIndexes];
|
||||
NSArray<SBQueueItem *> *array = [self.queue itemsAtIndexes:rowIndexes];
|
||||
|
||||
// A item with a status of SBQueueItemStatusWorking can not be removed
|
||||
for (SBQueueItem *item in array)
|
||||
@@ -643,7 +643,7 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard {
|
||||
// Copy the row numbers to the pasteboard.
|
||||
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
|
||||
[pboard declareTypes:[NSArray arrayWithObject:SublerBatchTableViewDataType] owner:self];
|
||||
[pboard declareTypes:@[SublerBatchTableViewDataType] owner:self];
|
||||
[pboard setData:data forType:SublerBatchTableViewDataType];
|
||||
return YES;
|
||||
}
|
||||
@@ -676,7 +676,7 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
NSUInteger i = [rowIndexes countOfIndexesInRange:NSMakeRange(0, row)];
|
||||
row -= i;
|
||||
|
||||
NSArray *objects = [self.queue itemsAtIndexes:rowIndexes];
|
||||
NSArray<SBQueueItem *> *objects = [self.queue itemsAtIndexes:rowIndexes];
|
||||
[self.queue removeItemsAtIndexes:rowIndexes];
|
||||
|
||||
for (id object in [objects reverseObjectEnumerator])
|
||||
@@ -690,8 +690,7 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
return YES;
|
||||
} else { // From other documents
|
||||
if ([[pboard types] containsObject:NSURLPboardType] ) {
|
||||
NSArray *items = [pboard readObjectsForClasses:
|
||||
[NSArray arrayWithObject: [NSURL class]] options: nil];
|
||||
NSArray *items = [pboard readObjectsForClasses:@[[NSURL class]] options: nil];
|
||||
NSMutableArray *queueItems = [[NSMutableArray alloc] init];
|
||||
NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
|
||||
|
||||
|
||||
@@ -28,10 +28,11 @@ typedef enum SBQueueItemStatus : NSInteger {
|
||||
MP42File *_mp4File;
|
||||
NSURL *_fileURL;
|
||||
NSURL *_destURL;
|
||||
NSDictionary *_attributes;
|
||||
NSMutableArray *_actions;
|
||||
|
||||
BOOL _cancelled;
|
||||
NSDictionary<NSString *, id> *_attributes;
|
||||
NSMutableArray<id<SBQueueActionProtocol>> *_actions;
|
||||
|
||||
BOOL _cancelled;
|
||||
|
||||
id _delegate;
|
||||
|
||||
@@ -47,15 +48,15 @@ typedef enum SBQueueItemStatus : NSInteger {
|
||||
@property (nonatomic, readonly) NSURL *URL;
|
||||
@property (nonatomic, copy) NSURL *destURL;
|
||||
|
||||
@property (nonatomic, readonly) NSArray *actions;
|
||||
@property (nonatomic, readonly) NSDictionary *attributes;
|
||||
@property (nonatomic, readonly) NSArray<id<SBQueueActionProtocol>> *actions;
|
||||
@property (nonatomic, readonly) NSDictionary<NSString *, id> *attributes;
|
||||
|
||||
@property (nonatomic, assign, nullable) id delegate;
|
||||
|
||||
+ (instancetype)itemWithURL:(NSURL *)URL;
|
||||
|
||||
+ (instancetype)itemWithMP4:(MP42File *)MP4;
|
||||
+ (instancetype)itemWithMP4:(MP42File *)MP4 url:(NSURL *)URL attributes:(NSDictionary *)dict;
|
||||
+ (instancetype)itemWithMP4:(MP42File *)MP4 destinationURL:(NSURL *)destURL attributes:(NSDictionary *)dict;
|
||||
|
||||
- (void)addAction:(id<SBQueueActionProtocol>)action;
|
||||
- (void)removeAction:(id<SBQueueActionProtocol>)action;
|
||||
|
||||
@@ -116,8 +116,8 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (instancetype)itemWithMP4:(MP42File *)MP4 url:(NSURL *)URL attributes:(NSDictionary *)dict {
|
||||
return [[[SBQueueItem alloc] initWithMP4:MP4 url:URL attributes:dict] autorelease];
|
||||
+ (instancetype)itemWithMP4:(MP42File *)MP4 destinationURL:(NSURL *)destURL attributes:(NSDictionary *)dict {
|
||||
return [[[SBQueueItem alloc] initWithMP4:MP4 url:destURL attributes:dict] autorelease];
|
||||
}
|
||||
|
||||
#pragma mark KVO
|
||||
|
||||
@@ -75,7 +75,7 @@ NSString * const SBQueueSet = @"SBQueueSet";
|
||||
* Save the queue user defaults
|
||||
*/
|
||||
- (void)saveUserDefaults {
|
||||
NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueOptimize,
|
||||
NSArray<NSString *> *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueOptimize,
|
||||
SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage];
|
||||
|
||||
[keys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
|
||||
Reference in new issue
Block a user