Fixed some deprecated api warnings.

This commit is contained in:
Damiano Galassi committed 2016-10-13 10:54:17 +02:00
1 parent 7dcf857660
commit 5083abe3ed
12 files changed
+74 -88

No files matched your search

+35 -21
View File
@@ -14,41 +14,55 @@
#define API_KEY @"ETET7TXFJH45YNYW0I4A" #define API_KEY @"ETET7TXFJH45YNYW0I4A"
@interface SBChapterDB ()
@property (nonatomic, readwrite) NSURLSessionTask *task;
@end
@implementation SBChapterDB @implementation SBChapterDB
- (NSArray<SBChapterResult *> *)searchTitle:(NSString *)title language:(nullable NSString *)language duration:(NSUInteger)duration - (void)searchTitle:(NSString *)title language:(nullable NSString *)language duration:(NSUInteger)duration completionHandler:(void(^)(NSArray<SBChapterResult *> *results))handler
{ {
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.chapterdb.org/chapters/search?title=%@", [SBMetadataHelper urlEncoded:title]]]; NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.chapterdb.org/chapters/search?title=%@", [SBMetadataHelper urlEncoded:title]]];
NSDictionary *headerOptions = @{@"ApiKey" : API_KEY}; NSDictionary *headerOptions = @{@"ApiKey" : API_KEY};
NSData *xmlData = xmlData = [SBMetadataHelper dataFromUrl:url withHTTPMethod:@"GET" headerOptions:headerOptions error:nil]; self.task = [SBMetadataHelper sessionTaskFromUrl:url withHTTPMethod:@"GET" headerOptions:headerOptions completionHandler:^(NSData * _Nullable data) {
NSXMLDocument *xml = [[NSXMLDocument alloc] initWithData:data
options:0
error:NULL];
NSXMLDocument *xml = [[NSXMLDocument alloc] initWithData:xmlData NSMutableArray<SBChapterResult *> *resultsArray = [[NSMutableArray alloc] init];
options:0
error:NULL];
NSMutableArray<SBChapterResult *> *resultsArray = [[NSMutableArray alloc] init]; if (xml) {
NSArray<NSXMLNode *> *children = [xml nodesForXPath:@"//*:chapterInfo" error:nil];
if (xml) { for (NSXMLNode *child in children) {
NSArray<NSXMLNode *> *children = [xml nodesForXPath:@"//*:chapterInfo" error:nil]; SBChapterResult *result = [self parseResult:child];
if (result) {
for (NSXMLNode *child in children) { [resultsArray addObject:result];
SBChapterResult *result = [self parseResult:child]; }
if (result) {
[resultsArray addObject:result];
} }
} }
}
if (duration > 0) {
if (duration > 0) { NSArray<SBChapterResult *> *filteredArray = [self filterArray:resultsArray byDuration:duration delta:10000];
NSArray<SBChapterResult *> *filteredArray = [self filterArray:resultsArray byDuration:duration delta:10000]; if (filteredArray.count) {
if (filteredArray.count) { handler(filteredArray);
return filteredArray; return;
}
} }
}
handler(resultsArray);
return resultsArray; }];
[self.task resume];
}
- (void)cancel;
{
[self.task cancel];
} }
/** /**
@@ -13,20 +13,16 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface SBChapterImporter : NSObject { @interface SBChapterImporter : NSObject
@private
BOOL _isCancelled;
}
+ (NSString *)defaultProvider; + (NSString *)defaultProvider;
+ (nullable instancetype)importerForProvider:(NSString *)providerName; + (nullable instancetype)importerForProvider:(NSString *)providerName;
- (void) searchTitle:(NSString *)title language:(nullable NSString *)language duration:(NSUInteger)duration completionHandler:(void(^)(NSArray<SBChapterResult *> *results))handler;
- (void) cancel;
#pragma mark Methods to be overridden #pragma mark Methods to be overridden
- (NSArray<SBChapterResult *> *)searchTitle:(NSString *)title language:(nullable NSString *)language duration:(NSUInteger)duration; - (void)searchTitle:(NSString *)title language:(nullable NSString *)language duration:(NSUInteger)duration completionHandler:(void(^)(NSArray<SBChapterResult *> *results))handler;
- (void)cancel;
@end @end
+3 -21
View File
@@ -11,16 +11,8 @@
#import "SBChapterDB.h" #import "SBChapterDB.h"
@interface SBChapterImporter ()
@property (atomic, readwrite) BOOL isCancelled;
@end
@implementation SBChapterImporter @implementation SBChapterImporter
@synthesize isCancelled = _isCancelled;
+ (NSString *)defaultProvider + (NSString *)defaultProvider
{ {
return @"ChapterDB"; return @"ChapterDB";
@@ -36,22 +28,12 @@
- (void)searchTitle:(NSString *)title language:(nullable NSString *)language duration:(NSUInteger)duration completionHandler:(void(^)(NSArray<SBChapterResult *> *results))handler - (void)searchTitle:(NSString *)title language:(nullable NSString *)language duration:(NSUInteger)duration completionHandler:(void(^)(NSArray<SBChapterResult *> *results))handler
{ {
dispatch_async(dispatch_get_global_queue(0, 0), ^{ @throw [NSException exceptionWithName:NSInternalInconsistencyException
NSArray *results = [self searchTitle:title language:language duration:duration]; reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
dispatch_async(dispatch_get_main_queue(), ^{ userInfo:nil];
if (!self.isCancelled) {
handler(results);
}
});
});
} }
- (void)cancel - (void)cancel
{
self.isCancelled = YES;
}
- (NSArray<SBChapterResult *> *)searchTitle:(NSString *)title language:(nullable NSString *)language duration:(NSUInteger)duration
{ {
@throw [NSException exceptionWithName:NSInternalInconsistencyException @throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
+1 -1
View File
@@ -23,7 +23,7 @@ typedef NS_ENUM(NSUInteger, SBCachePolicy) {
+ (NSString *)urlEncoded:(NSString *)string; + (NSString *)urlEncoded:(NSString *)string;
+ (nullable NSData *)downloadDataFromURL:(NSURL *)url withCachePolicy:(SBCachePolicy)policy; + (nullable NSData *)downloadDataFromURL:(NSURL *)url withCachePolicy:(SBCachePolicy)policy;
+ (nullable NSData *)dataFromUrl:(NSURL *)url withHTTPMethod:(NSString *)method headerOptions:(nullable NSDictionary *)header error:(NSError **)outError; + (NSURLSessionTask *)sessionTaskFromUrl:(NSURL *)url withHTTPMethod:(NSString *)method headerOptions:(nullable NSDictionary *)header completionHandler:(void(^)(NSData * _Nullable data))completionHandler;
@end @end
+17 -24
View File
@@ -121,14 +121,7 @@
} }
+ (NSString *)urlEncoded:(NSString *)string { + (NSString *)urlEncoded:(NSString *)string {
string = string.precomposedStringWithCompatibilityMapping; return [string.precomposedStringWithCompatibilityMapping stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
CFStringRef urlString = CFURLCreateStringByAddingPercentEscapes(
NULL,
(CFStringRef) string,
NULL,
(CFStringRef) @"!*'\"();:@&=+$,/?%#[]% ",
kCFStringEncodingUTF8);
return CFAutorelease(urlString);
} }
+ (NSString *)md5String:(NSString *)s { + (NSString *)md5String:(NSString *)s {
@@ -189,7 +182,7 @@
} }
#pragma mark NSURLRequest #pragma mark NSURLRequest
+ (nullable NSData *)dataFromUrl:(NSURL *)url withHTTPMethod:(NSString *)method headerOptions:(nullable NSDictionary *)header error:(NSError * __autoreleasing *)outError + (NSURLSessionTask *)sessionTaskFromUrl:(NSURL *)url withHTTPMethod:(NSString *)method headerOptions:(nullable NSDictionary *)header completionHandler:(void(^)(NSData * _Nullable data))completionHandler
{ {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy cachePolicy:NSURLRequestUseProtocolCachePolicy
@@ -202,24 +195,24 @@
} }
} }
NSURLResponse *response = nil; NSURLSession *defaultSession = [NSURLSession sharedSession];
NSError *error = nil; NSURLSessionTask *task = [defaultSession dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSData *data = [NSURLConnection sendSynchronousRequest:request if (data) {
returningResponse:&response NSUInteger statusCode = 0;
error:&error]; if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
statusCode = (long)((NSHTTPURLResponse *)response).statusCode;
}
if (data) { if (statusCode == 200) {
NSUInteger statusCode = 0; completionHandler(data);
if ([response isKindOfClass:[NSHTTPURLResponse class]]) { }
statusCode = (long)((NSHTTPURLResponse *)response).statusCode; else {
completionHandler(nil);
}
} }
if (statusCode == 200) { }];
return data; return task;
}
}
return nil;
} }
@end @end
@@ -348,9 +348,9 @@
</scroller> </scroller>
</scrollView> </scrollView>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="223"> <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="223">
<rect key="frame" x="17" y="7" width="24" height="22"/> <rect key="frame" x="17" y="7" width="25" height="22"/>
<constraints> <constraints>
<constraint firstAttribute="width" constant="24" id="PQ5-Tu-VFK"/> <constraint firstAttribute="width" constant="25" id="PQ5-Tu-VFK"/>
<constraint firstAttribute="height" constant="20" id="nbn-sF-RRs"/> <constraint firstAttribute="height" constant="20" id="nbn-sF-RRs"/>
</constraints> </constraints>
<buttonCell key="cell" type="smallSquare" bezelStyle="smallSquare" image="NSAddTemplate" imagePosition="overlaps" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="224"> <buttonCell key="cell" type="smallSquare" bezelStyle="smallSquare" image="NSAddTemplate" imagePosition="overlaps" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="224">
@@ -362,9 +362,9 @@
</connections> </connections>
</button> </button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="226"> <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="226">
<rect key="frame" x="40" y="7" width="24" height="22"/> <rect key="frame" x="41" y="7" width="25" height="22"/>
<constraints> <constraints>
<constraint firstAttribute="width" constant="24" id="FBv-tK-Tdv"/> <constraint firstAttribute="width" constant="25" id="FBv-tK-Tdv"/>
</constraints> </constraints>
<buttonCell key="cell" type="smallSquare" bezelStyle="smallSquare" image="NSRemoveTemplate" imagePosition="overlaps" alignment="center" enabled="NO" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="227"> <buttonCell key="cell" type="smallSquare" bezelStyle="smallSquare" image="NSRemoveTemplate" imagePosition="overlaps" alignment="center" enabled="NO" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="227">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -390,12 +390,12 @@
<constraint firstAttribute="bottom" secondItem="223" secondAttribute="bottom" constant="8" id="2rH-o3-DfM"/> <constraint firstAttribute="bottom" secondItem="223" secondAttribute="bottom" constant="8" id="2rH-o3-DfM"/>
<constraint firstItem="235" firstAttribute="top" secondItem="214" secondAttribute="bottom" constant="11" id="3GL-7W-Gde"/> <constraint firstItem="235" firstAttribute="top" secondItem="214" secondAttribute="bottom" constant="11" id="3GL-7W-Gde"/>
<constraint firstItem="214" firstAttribute="leading" secondItem="16" secondAttribute="leading" constant="17" id="4FA-0p-Olg"/> <constraint firstItem="214" firstAttribute="leading" secondItem="16" secondAttribute="leading" constant="17" id="4FA-0p-Olg"/>
<constraint firstItem="226" firstAttribute="leading" secondItem="16" secondAttribute="leading" constant="40" id="H85-kJ-Lp3"/>
<constraint firstItem="226" firstAttribute="centerY" secondItem="235" secondAttribute="centerY" constant="0.5" id="IHP-mq-pja"/> <constraint firstItem="226" firstAttribute="centerY" secondItem="235" secondAttribute="centerY" constant="0.5" id="IHP-mq-pja"/>
<constraint firstItem="223" firstAttribute="top" secondItem="214" secondAttribute="bottom" constant="8" symbolic="YES" id="Omx-Vr-JKg"/> <constraint firstItem="223" firstAttribute="top" secondItem="214" secondAttribute="bottom" constant="8" symbolic="YES" id="Omx-Vr-JKg"/>
<constraint firstItem="214" firstAttribute="top" secondItem="16" secondAttribute="top" constant="6" id="Pfx-al-MJd"/> <constraint firstItem="214" firstAttribute="top" secondItem="16" secondAttribute="top" constant="6" id="Pfx-al-MJd"/>
<constraint firstItem="214" firstAttribute="leading" secondItem="223" secondAttribute="leading" id="Xbu-J3-MGE"/> <constraint firstItem="214" firstAttribute="leading" secondItem="223" secondAttribute="leading" id="Xbu-J3-MGE"/>
<constraint firstItem="226" firstAttribute="height" secondItem="223" secondAttribute="height" id="bRk-bc-DiM"/> <constraint firstItem="226" firstAttribute="height" secondItem="223" secondAttribute="height" id="bRk-bc-DiM"/>
<constraint firstItem="226" firstAttribute="leading" secondItem="223" secondAttribute="trailing" constant="-1" id="mSU-ml-jzw"/>
<constraint firstItem="214" firstAttribute="trailing" secondItem="235" secondAttribute="trailing" id="uWI-rx-Mmh"/> <constraint firstItem="214" firstAttribute="trailing" secondItem="235" secondAttribute="trailing" id="uWI-rx-Mmh"/>
<constraint firstAttribute="trailing" secondItem="214" secondAttribute="trailing" constant="17" id="zZm-R8-SeH"/> <constraint firstAttribute="trailing" secondItem="214" secondAttribute="trailing" constant="17" id="zZm-R8-SeH"/>
</constraints> </constraints>
@@ -25,7 +25,7 @@
NSMutableParagraphStyle *ps = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; NSMutableParagraphStyle *ps = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
ps.headIndent = -10.0; ps.headIndent = -10.0;
ps.alignment = NSRightTextAlignment; ps.alignment = NSTextAlignmentRight;
if ([[NSFont class] respondsToSelector:@selector(monospacedDigitSystemFontOfSize:weight:)]) { if ([[NSFont class] respondsToSelector:@selector(monospacedDigitSystemFontOfSize:weight:)]) {
detailBoldAttr = @{ NSFontAttributeName: [NSFont monospacedDigitSystemFontOfSize:[NSFont smallSystemFontSize] weight:NSFontWeightBold], detailBoldAttr = @{ NSFontAttributeName: [NSFont monospacedDigitSystemFontOfSize:[NSFont smallSystemFontSize] weight:NSFontWeightBold],
+2 -2
View File
@@ -86,7 +86,7 @@
alert.informativeText = NSLocalizedString(@"Your current queue will be lost. Do you want to quit anyway?", @"Quit alert description."); alert.informativeText = NSLocalizedString(@"Your current queue will be lost. Do you want to quit anyway?", @"Quit alert description.");
[alert addButtonWithTitle:NSLocalizedString(@"Quit", @"Quit alert default action.")]; [alert addButtonWithTitle:NSLocalizedString(@"Quit", @"Quit alert default action.")];
[alert addButtonWithTitle:NSLocalizedString(@"Don't Quit", @"Quit alert cancel action.")]; [alert addButtonWithTitle:NSLocalizedString(@"Don't Quit", @"Quit alert cancel action.")];
alert.alertStyle = NSCriticalAlertStyle; alert.alertStyle = NSAlertStyleCritical;
NSInteger result = [alert runModal]; NSInteger result = [alert runModal];
@@ -124,7 +124,7 @@
" If you enjoy using it, please consider showing your appreciation with a donation.", "Donation -> message")]; " If you enjoy using it, please consider showing your appreciation with a donation.", "Donation -> message")];
[alert setInformativeText:donateMessage]; [alert setInformativeText:donateMessage];
[alert setAlertStyle: NSInformationalAlertStyle]; [alert setAlertStyle: NSAlertStyleInformational];
[alert addButtonWithTitle: NSLocalizedString(@"Donate", "Donation -> button")]; [alert addButtonWithTitle: NSLocalizedString(@"Donate", "Donation -> button")];
NSButton *noDonateButton = [alert addButtonWithTitle: NSLocalizedString(@"Nope", "Donation -> button")]; NSButton *noDonateButton = [alert addButtonWithTitle: NSLocalizedString(@"Nope", "Donation -> button")];
+3 -2
View File
@@ -156,9 +156,10 @@
language:nil language:nil
duration:_searchDuration duration:_searchDuration
completionHandler:^(NSArray<SBChapterResult *> *results) { completionHandler:^(NSArray<SBChapterResult *> *results) {
[self searchForResultsDone:results]; dispatch_async(dispatch_get_main_queue(), ^{
[self searchForResultsDone:results];
});
}]; }];
} }
else { else {
// Nothing to search, reset the table view // Nothing to search, reset the table view
+1 -1
View File
@@ -1031,7 +1031,7 @@ static NSDictionary *_detailMonospacedAttr;
alert.informativeText = [NSString stringWithFormat: alert.informativeText = [NSString stringWithFormat:
NSLocalizedString(@"There was a problem creating the file \"%@\".", NSLocalizedString(@"There was a problem creating the file \"%@\".",
"Export alert panel -> message"), panel.URL.lastPathComponent]; "Export alert panel -> message"), panel.URL.lastPathComponent];
alert.alertStyle = NSWarningAlertStyle; alert.alertStyle = NSAlertStyleWarning;
[alert runModal]; [alert runModal];
} }
+2 -2
View File
@@ -200,7 +200,7 @@
if ([tableColumn.identifier isEqualToString:@"check"]) { if ([tableColumn.identifier isEqualToString:@"check"]) {
NSButtonCell *buttonCell = [[NSButtonCell alloc] init]; NSButtonCell *buttonCell = [[NSButtonCell alloc] init];
[buttonCell setButtonType:NSSwitchButton]; [buttonCell setButtonType:NSSwitchButton];
buttonCell.controlSize = NSSmallControlSize; buttonCell.controlSize = NSControlSizeSmall;
buttonCell.title = @""; buttonCell.title = @"";
buttonCell.enabled = (isTrackMuxable(track.format) || trackNeedConversion(track.format)) ? YES : NO; buttonCell.enabled = (isTrackMuxable(track.format) || trackNeedConversion(track.format)) ? YES : NO;
@@ -212,7 +212,7 @@
NSPopUpButtonCell *actionCell = [[NSPopUpButtonCell alloc] init]; NSPopUpButtonCell *actionCell = [[NSPopUpButtonCell alloc] init];
[actionCell setAutoenablesItems:NO]; [actionCell setAutoenablesItems:NO];
actionCell.font = [NSFont systemFontOfSize:11]; actionCell.font = [NSFont systemFontOfSize:11];
actionCell.controlSize = NSSmallControlSize; actionCell.controlSize = NSControlSizeSmall;
[actionCell setBordered:NO]; [actionCell setBordered:NO];
if ([track isMemberOfClass:[MP42VideoTrack class]]) { if ([track isMemberOfClass:[MP42VideoTrack class]]) {
+1 -1
View File
@@ -76,7 +76,7 @@
NSMutableParagraphStyle * ps = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; NSMutableParagraphStyle * ps = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
ps.headIndent = -10.0; ps.headIndent = -10.0;
ps.alignment = NSRightTextAlignment; ps.alignment = NSTextAlignmentRight;
detailBoldAttr = @{NSFontAttributeName: [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]], detailBoldAttr = @{NSFontAttributeName: [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]],
NSParagraphStyleAttributeName: ps, NSParagraphStyleAttributeName: ps,
NSForegroundColorAttributeName: [NSColor grayColor]}; NSForegroundColorAttributeName: [NSColor grayColor]};