Refactored some code

This commit is contained in:
Damiano Galassi committed 2015-08-20 13:09:09 +02:00
1 parent 76ce1e5ebb
commit 91fd1c0542
9 files changed
+39 -29

No files matched your search

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