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"
@interface SBChapterDB ()
@property (nonatomic, readwrite) NSURLSessionTask *task;
@end
@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]]];
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
options:0
error:NULL];
NSMutableArray<SBChapterResult *> *resultsArray = [[NSMutableArray alloc] init];
NSMutableArray<SBChapterResult *> *resultsArray = [[NSMutableArray alloc] init];
if (xml) {
NSArray<NSXMLNode *> *children = [xml nodesForXPath:@"//*:chapterInfo" error:nil];
if (xml) {
NSArray<NSXMLNode *> *children = [xml nodesForXPath:@"//*:chapterInfo" error:nil];
for (NSXMLNode *child in children) {
SBChapterResult *result = [self parseResult:child];
if (result) {
[resultsArray addObject:result];
for (NSXMLNode *child in children) {
SBChapterResult *result = [self parseResult:child];
if (result) {
[resultsArray addObject:result];
}
}
}
}
if (duration > 0) {
NSArray<SBChapterResult *> *filteredArray = [self filterArray:resultsArray byDuration:duration delta:10000];
if (filteredArray.count) {
return filteredArray;
if (duration > 0) {
NSArray<SBChapterResult *> *filteredArray = [self filterArray:resultsArray byDuration:duration delta:10000];
if (filteredArray.count) {
handler(filteredArray);
return;
}
}
}
handler(resultsArray);
return resultsArray;
}];
[self.task resume];
}
- (void)cancel;
{
[self.task cancel];
}
/**
@@ -13,20 +13,16 @@
NS_ASSUME_NONNULL_BEGIN
@interface SBChapterImporter : NSObject {
@private
BOOL _isCancelled;
}
@interface SBChapterImporter : NSObject
+ (NSString *)defaultProvider;
+ (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
- (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
+3 -21
View File
@@ -11,16 +11,8 @@
#import "SBChapterDB.h"
@interface SBChapterImporter ()
@property (atomic, readwrite) BOOL isCancelled;
@end
@implementation SBChapterImporter
@synthesize isCancelled = _isCancelled;
+ (NSString *)defaultProvider
{
return @"ChapterDB";
@@ -36,22 +28,12 @@
- (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), ^{
NSArray *results = [self searchTitle:title language:language duration:duration];
dispatch_async(dispatch_get_main_queue(), ^{
if (!self.isCancelled) {
handler(results);
}
});
});
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
userInfo:nil];
}
- (void)cancel
{
self.isCancelled = YES;
}
- (NSArray<SBChapterResult *> *)searchTitle:(NSString *)title language:(nullable NSString *)language duration:(NSUInteger)duration
{
@throw [NSException exceptionWithName:NSInternalInconsistencyException
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;
+ (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
+17 -24
View File
@@ -121,14 +121,7 @@
}
+ (NSString *)urlEncoded:(NSString *)string {
string = string.precomposedStringWithCompatibilityMapping;
CFStringRef urlString = CFURLCreateStringByAddingPercentEscapes(
NULL,
(CFStringRef) string,
NULL,
(CFStringRef) @"!*'\"();:@&=+$,/?%#[]% ",
kCFStringEncodingUTF8);
return CFAutorelease(urlString);
return [string.precomposedStringWithCompatibilityMapping stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
}
+ (NSString *)md5String:(NSString *)s {
@@ -189,7 +182,7 @@
}
#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
cachePolicy:NSURLRequestUseProtocolCachePolicy
@@ -202,24 +195,24 @@
}
}
NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
NSURLSession *defaultSession = [NSURLSession sharedSession];
NSURLSessionTask *task = [defaultSession dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (data) {
NSUInteger statusCode = 0;
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
statusCode = (long)((NSHTTPURLResponse *)response).statusCode;
}
if (data) {
NSUInteger statusCode = 0;
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
statusCode = (long)((NSHTTPURLResponse *)response).statusCode;
if (statusCode == 200) {
completionHandler(data);
}
else {
completionHandler(nil);
}
}
if (statusCode == 200) {
return data;
}
}
return nil;
}];
return task;
}
@end
@@ -348,9 +348,9 @@
</scroller>
</scrollView>
<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>
<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"/>
</constraints>
<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>
</button>
<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>
<constraint firstAttribute="width" constant="24" id="FBv-tK-Tdv"/>
<constraint firstAttribute="width" constant="25" id="FBv-tK-Tdv"/>
</constraints>
<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"/>
@@ -390,12 +390,12 @@
<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="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="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="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="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 firstAttribute="trailing" secondItem="214" secondAttribute="trailing" constant="17" id="zZm-R8-SeH"/>
</constraints>
@@ -25,7 +25,7 @@
NSMutableParagraphStyle *ps = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
ps.headIndent = -10.0;
ps.alignment = NSRightTextAlignment;
ps.alignment = NSTextAlignmentRight;
if ([[NSFont class] respondsToSelector:@selector(monospacedDigitSystemFontOfSize:weight:)]) {
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 addButtonWithTitle:NSLocalizedString(@"Quit", @"Quit alert default action.")];
[alert addButtonWithTitle:NSLocalizedString(@"Don't Quit", @"Quit alert cancel action.")];
alert.alertStyle = NSCriticalAlertStyle;
alert.alertStyle = NSAlertStyleCritical;
NSInteger result = [alert runModal];
@@ -124,7 +124,7 @@
" If you enjoy using it, please consider showing your appreciation with a donation.", "Donation -> message")];
[alert setInformativeText:donateMessage];
[alert setAlertStyle: NSInformationalAlertStyle];
[alert setAlertStyle: NSAlertStyleInformational];
[alert addButtonWithTitle: NSLocalizedString(@"Donate", "Donation -> button")];
NSButton *noDonateButton = [alert addButtonWithTitle: NSLocalizedString(@"Nope", "Donation -> button")];
+3 -2
View File
@@ -156,9 +156,10 @@
language:nil
duration:_searchDuration
completionHandler:^(NSArray<SBChapterResult *> *results) {
[self searchForResultsDone:results];
dispatch_async(dispatch_get_main_queue(), ^{
[self searchForResultsDone:results];
});
}];
}
else {
// Nothing to search, reset the table view
+1 -1
View File
@@ -1031,7 +1031,7 @@ static NSDictionary *_detailMonospacedAttr;
alert.informativeText = [NSString stringWithFormat:
NSLocalizedString(@"There was a problem creating the file \"%@\".",
"Export alert panel -> message"), panel.URL.lastPathComponent];
alert.alertStyle = NSWarningAlertStyle;
alert.alertStyle = NSAlertStyleWarning;
[alert runModal];
}
+2 -2
View File
@@ -200,7 +200,7 @@
if ([tableColumn.identifier isEqualToString:@"check"]) {
NSButtonCell *buttonCell = [[NSButtonCell alloc] init];
[buttonCell setButtonType:NSSwitchButton];
buttonCell.controlSize = NSSmallControlSize;
buttonCell.controlSize = NSControlSizeSmall;
buttonCell.title = @"";
buttonCell.enabled = (isTrackMuxable(track.format) || trackNeedConversion(track.format)) ? YES : NO;
@@ -212,7 +212,7 @@
NSPopUpButtonCell *actionCell = [[NSPopUpButtonCell alloc] init];
[actionCell setAutoenablesItems:NO];
actionCell.font = [NSFont systemFontOfSize:11];
actionCell.controlSize = NSSmallControlSize;
actionCell.controlSize = NSControlSizeSmall;
[actionCell setBordered:NO];
if ([track isMemberOfClass:[MP42VideoTrack class]]) {
+1 -1
View File
@@ -76,7 +76,7 @@
NSMutableParagraphStyle * ps = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
ps.headIndent = -10.0;
ps.alignment = NSRightTextAlignment;
ps.alignment = NSTextAlignmentRight;
detailBoldAttr = @{NSFontAttributeName: [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]],
NSParagraphStyleAttributeName: ps,
NSForegroundColorAttributeName: [NSColor grayColor]};