Revision: 23983
          http://sourceforge.net/p/bibdesk/svn/23983
Author:   hofman
Date:     2019-07-09 21:40:52 +0000 (Tue, 09 Jul 2019)
Log Message:
-----------
implement some partial delegate methods in superclass

Modified Paths:
--------------
    trunk/bibdesk/BDSKDownloader.h
    trunk/bibdesk/BDSKDownloader.m
    trunk/bibdesk/BDSKDownloaderDeprecated.m
    trunk/bibdesk/BDSKDownloaderSession.m

Modified: trunk/bibdesk/BDSKDownloader.h
===================================================================
--- trunk/bibdesk/BDSKDownloader.h      2019-07-09 18:04:34 UTC (rev 23982)
+++ trunk/bibdesk/BDSKDownloader.h      2019-07-09 21:40:52 UTC (rev 23983)
@@ -76,6 +76,8 @@
 - (void)cleanupDownload:(BDSKDownload *)download;
 
 - (void)download:(BDSKDownload *)download 
didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge 
completionHandler:(void (^)(BDSKDownloaderAuthChallengeDisposition disposition, 
NSURLCredential *credential))completionHandler;
+- (void)download:(BDSKDownload *)download 
decideDestinationWithSuggestedFilename:(NSString *)suggestedFileName 
completionHandler:(void (^)(NSURL *destinationURL, BOOL 
allowOverwrite))completionHandler;
+- (void)download:(BDSKDownload *)download didReceiveData:(NSData *)data;
 
 @end
 

Modified: trunk/bibdesk/BDSKDownloader.m
===================================================================
--- trunk/bibdesk/BDSKDownloader.m      2019-07-09 18:04:34 UTC (rev 23982)
+++ trunk/bibdesk/BDSKDownloader.m      2019-07-09 21:40:52 UTC (rev 23983)
@@ -40,6 +40,7 @@
 #import "BDSKDownloaderDeprecated.h"
 #import "BDSKDownloaderSession.h"
 #import "BDSKAuthenticationHandler.h"
+#import "NSFileManager_BDSKExtensions.h"
 
 
 @implementation BDSKDownloader
@@ -119,6 +120,28 @@
     }
 }
 
+- (void)download:(BDSKDownload *)download 
decideDestinationWithSuggestedFilename:(NSString *)suggestedFileName 
completionHandler:(void (^)(NSURL *destinationURL, BOOL 
allowOverwrite))completionHandler {
+    id<BDSKDownloaderDelegate> delegate = [download delegate];
+    if ([delegate 
respondsToSelector:@selector(downloader:download:decideDestinationWithSuggestedFilename:completionHandler:)])
 {
+        [delegate downloader:self download:download 
decideDestinationWithSuggestedFilename:suggestedFileName 
completionHandler:completionHandler];
+    } else {
+        NSURL *destinationURL = [[NSFileManager defaultManager] 
temporaryFileURLWithBasename:suggestedFileName];
+        completionHandler(destinationURL, YES);
+    }
+}
+
+- (void)download:(BDSKDownload *)download didReceiveData:(NSData *)data {
+    id<BDSKDownloaderDelegate> delegate = [download delegate];
+    if ([download data] == nil) {
+        [download setData:[NSMutableData dataWithData:data]];
+    } else {
+        [[download data] appendData:data];
+    }
+    if ([delegate 
respondsToSelector:@selector(downloader:download:didReceiveDataOfLength:)]) {
+        [delegate downloader:self download:download 
didReceiveDataOfLength:[data length]];
+    }
+}
+
 @end
 
 #pragma mark -

Modified: trunk/bibdesk/BDSKDownloaderDeprecated.m
===================================================================
--- trunk/bibdesk/BDSKDownloaderDeprecated.m    2019-07-09 18:04:34 UTC (rev 
23982)
+++ trunk/bibdesk/BDSKDownloaderDeprecated.m    2019-07-09 21:40:52 UTC (rev 
23983)
@@ -37,7 +37,6 @@
  */
 
 #import "BDSKDownloaderDeprecated.h"
-#import "NSFileManager_BDSKExtensions.h"
 
 @interface BDSKDownloadDeprecated : BDSKDownload {
     NSURLResponse *response;
@@ -100,15 +99,9 @@
 
 - (void)download:(NSURLDownload *)task 
decideDestinationWithSuggestedFilename:(NSString *)suggestedFileName {
     BDSKDownload *download = [[[self downloadForTask:task] retain] 
autorelease];
-    id<BDSKDownloaderDelegate> delegate = [download delegate];
-    if ([delegate 
respondsToSelector:@selector(downloader:download:decideDestinationWithSuggestedFilename:completionHandler:)])
 {
-        [delegate downloader:self download:download 
decideDestinationWithSuggestedFilename:suggestedFileName 
completionHandler:^(NSURL *destinationURL, BOOL allowOverwrite){
-            [task setDestination:[destinationURL path] allowOverwrite:YES];
-        }];
-    } else {
-        NSURL *destination =[[NSFileManager defaultManager] 
temporaryFileURLWithBasename:suggestedFileName];
-        [task setDestination:[destination path] allowOverwrite:YES];
-    }
+    [self download:download 
decideDestinationWithSuggestedFilename:suggestedFileName 
completionHandler:^(NSURL *destinationURL, BOOL allowOverwrite){
+        [task setDestination:[destinationURL path] 
allowOverwrite:allowOverwrite];
+    }];
 }
 
 - (void)download:(NSURLDownload *)task didCreateDestination:(NSString *)path {
@@ -168,16 +161,8 @@
 }
 
 - (void)connection:(NSURLConnection *)task didReceiveData:(NSData *)data {
-    BDSKDownloadDeprecated *download = (BDSKDownloadDeprecated *)[[[self 
downloadForTask:task] retain] autorelease];
-    id<BDSKDownloaderDelegate> delegate = [download delegate];
-    if ([download data] == nil) {
-        [download setData:[NSMutableData dataWithData:data]];
-    } else {
-        [[download data] appendData:data];
-    }
-    if ([delegate 
respondsToSelector:@selector(downloader:download:didReceiveDataOfLength:)]) {
-        [delegate downloader:self download:download 
didReceiveDataOfLength:[data length]];
-    }
+    BDSKDownload *download = [[[self downloadForTask:task] retain] 
autorelease];
+    [self download:download didReceiveData:data];
 }
 
 - (void)connectionDidFinishLoading:(NSURLConnection *)task {

Modified: trunk/bibdesk/BDSKDownloaderSession.m
===================================================================
--- trunk/bibdesk/BDSKDownloaderSession.m       2019-07-09 18:04:34 UTC (rev 
23982)
+++ trunk/bibdesk/BDSKDownloaderSession.m       2019-07-09 21:40:52 UTC (rev 
23983)
@@ -127,7 +127,7 @@
     id<BDSKDownloaderDelegate> delegate = [download delegate];
     NSString *suggestedFileName = [[task response] suggestedFilename] ?: 
[location lastPathComponent];
     
-    void (^completionHandler)(NSURL *, BOOL) = ^(NSURL *destinationURL, BOOL 
allowOverwrite){
+    [self download:download 
decideDestinationWithSuggestedFilename:suggestedFileName 
completionHandler:^(NSURL *destinationURL, BOOL allowOverwrite){
         NSError *error = nil;
         NSFileManager *fm = [NSFileManager defaultManager];
         if ([destinationURL checkResourceIsReachableAndReturnError:NULL]) {
@@ -148,14 +148,7 @@
             [delegate downloader:self download:download 
didFailWithError:error];
             [self cleanupDownload:download];
         }
-    };
-    
-    if ([delegate 
respondsToSelector:@selector(downloader:download:decideDestinationWithSuggestedFilename:completionHandler:)])
 {
-        [delegate downloader:self download:download 
decideDestinationWithSuggestedFilename:suggestedFileName 
completionHandler:completionHandler];
-    } else {
-        NSURL *destinationURL = [[NSFileManager defaultManager] 
temporaryFileURLWithBasename:suggestedFileName];
-        completionHandler(destinationURL, YES);
-    }
+    }];
 }
 
 - (void)URLSession:(NSURLSession *)aSession 
downloadTask:(NSURLSessionDownloadTask *)task 
didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten 
totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
@@ -188,15 +181,7 @@
 
 - (void)URLSession:(NSURLSession *)aSession dataTask:(NSURLSessionDataTask 
*)task didReceiveData:(NSData *)data {
     BDSKDownload *download = [[[self downloadForTask:task] retain] 
autorelease];
-    id<BDSKDownloaderDelegate> delegate = [download delegate];
-    if ([download data] == nil) {
-        [download setData:[NSMutableData dataWithData:data]];
-    } else {
-        [[download data] appendData:data];
-    }
-    if ([delegate 
respondsToSelector:@selector(downloader:download:didReceiveDataOfLength:)]) {
-        [delegate downloader:self download:download 
didReceiveDataOfLength:[data length]];
-    }
+    [self download:download didReceiveData:data];
 }
 
 #pragma mark NSURLSessionTaskDelegate

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to