Revision: 7634 http://skim-app.svn.sourceforge.net/skim-app/?rev=7634&view=rev Author: hofman Date: 2012-01-24 11:24:47 +0000 (Tue, 24 Jan 2012) Log Message: ----------- No need for a download delegate, we already observe the status
Modified Paths: -------------- trunk/SKDownload.h trunk/SKDownload.m trunk/SKDownloadController.h trunk/SKDownloadController.m Modified: trunk/SKDownload.h =================================================================== --- trunk/SKDownload.h 2012-01-24 11:16:26 UTC (rev 7633) +++ trunk/SKDownload.h 2012-01-24 11:24:47 UTC (rev 7634) @@ -53,8 +53,6 @@ }; typedef NSInteger SKDownloadStatus; -@protocol SKDownloadDelegate; - @interface SKDownload : NSObject { NSURL *URL; NSURLDownload *URLDownload; @@ -64,11 +62,8 @@ NSImage *fileIcon; NSProgressIndicator *progressIndicator; SKDownloadStatus status; - id <SKDownloadDelegate> delegate; } -@property (nonatomic, assign) id <SKDownloadDelegate> delegate; - @property (nonatomic, readonly) SKDownloadStatus status; @property (nonatomic, readonly) NSURL *URL; @@ -99,10 +94,3 @@ - (void)removeProgressIndicatorFromSuperview; @end - - -@protocol SKDownloadDelegate <NSObject> - -- (void)downloadDidEnd:(SKDownload *)download; - -@end Modified: trunk/SKDownload.m =================================================================== --- trunk/SKDownload.m 2012-01-24 11:16:26 UTC (rev 7633) +++ trunk/SKDownload.m 2012-01-24 11:24:47 UTC (rev 7634) @@ -64,7 +64,7 @@ @implementation SKDownload -@synthesize URL, filePath, fileIcon, expectedContentLength, receivedContentLength, status, delegate; +@synthesize URL, filePath, fileIcon, expectedContentLength, receivedContentLength, status; @dynamic fileName, fileURL, info, canCancel, canRemove, canResume, scriptingURL, scriptingStatus; static NSSet *keysAffectedByFilePath = nil; @@ -104,7 +104,6 @@ receivedContentLength = 0; progressIndicator = nil; status = SKDownloadStatusUndefined; - delegate = nil; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleApplicationWillTerminateNotification:) name:NSApplicationWillTerminateNotification object:NSApp]; @@ -278,7 +277,6 @@ [URLDownload cancel]; [self setStatus:SKDownloadStatusCanceled]; - [delegate downloadDidEnd:self]; } } @@ -376,7 +374,6 @@ if (expectedContentLength > 0) [progressIndicator setDoubleValue:(double)expectedContentLength]; [self setStatus:SKDownloadStatusFinished]; - [delegate downloadDidEnd:self]; } - (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error { @@ -384,7 +381,6 @@ [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL]; [self setFilePath:nil]; [self setStatus:SKDownloadStatusFailed]; - [delegate downloadDidEnd:self]; } @end Modified: trunk/SKDownloadController.h =================================================================== --- trunk/SKDownloadController.h 2012-01-24 11:16:26 UTC (rev 7633) +++ trunk/SKDownloadController.h 2012-01-24 11:24:47 UTC (rev 7634) @@ -39,12 +39,11 @@ #import <Cocoa/Cocoa.h> #import "SKWindowController.h" #import "SKTableView.h" -#import "SKDownload.h" -@class SKTableView; +@class SKDownload; -@interface SKDownloadController : SKWindowController <SKTableViewDelegate, NSTableViewDataSource, SKDownloadDelegate> { +@interface SKDownloadController : SKWindowController <SKTableViewDelegate, NSTableViewDataSource> { NSArrayController *arrayController; SKTableView *tableView; NSButton *clearButton; Modified: trunk/SKDownloadController.m =================================================================== --- trunk/SKDownloadController.m 2012-01-24 11:16:26 UTC (rev 7633) +++ trunk/SKDownloadController.m 2012-01-24 11:24:47 UTC (rev 7634) @@ -133,6 +133,29 @@ return [self addDownloadForURL:aURL showWindow:[[NSUserDefaults standardUserDefaults] boolForKey:SKAutoOpenDownloadsWindowKey]]; } +- (void)openDownload:(SKDownload *)download { + if ([download status] == SKDownloadStatusFinished) { + NSURL *URL = [download fileURL]; + NSString *fragment = [[download URL] fragment]; + if ([fragment length] > 0) + URL = [NSURL URLWithString:[[URL absoluteString] stringByAppendingFormat:@"#%@", fragment]]; + + NSError *error = nil; + id document = [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:URL display:YES error:&error]; + if (document == nil && [error isUserCancelledError] == NO) + [NSApp presentError:error]; + + if ([[NSUserDefaults standardUserDefaults] boolForKey:SKAutoRemoveFinishedDownloadsKey]) { + [[download retain] autorelease]; + [[self mutableArrayValueForKey:DOWNLOADS_KEY] removeObject:download]; + // for the document to note that the file has been deleted + [document setFileURL:[download fileURL]]; + if ([self countOfDownloads] == 0 && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoCloseDownloadsWindowKey]) + [[self window] close]; + } + } +} + #pragma mark Images + (NSImage *)cancelImage { @@ -201,7 +224,6 @@ } - (void)insertObject:(SKDownload *)download inDownloadsAtIndex:(NSUInteger)anIndex { - [download setDelegate:self]; [downloads insertObject:download atIndex:anIndex]; [self startObservingDownloads:[NSArray arrayWithObject:download]]; [download start]; @@ -212,7 +234,6 @@ - (void)removeObjectFromDownloadsAtIndex:(NSUInteger)anIndex { SKDownload *download = [downloads objectAtIndex:anIndex]; [self endObservingDownloads:[NSArray arrayWithObject:download]]; - [download setDelegate:nil]; [download cancel]; [downloads removeObjectAtIndex:anIndex]; [downloads makeObjectsPerformSelector:@selector(removeProgressIndicatorFromSuperview)]; @@ -331,31 +352,6 @@ return YES; } -#pragma mark SKDownloadDelegate - -- (void)downloadDidEnd:(SKDownload *)download { - if ([download status] == SKDownloadStatusFinished) { - NSURL *URL = [download fileURL]; - NSString *fragment = [[download URL] fragment]; - if ([fragment length] > 0) - URL = [NSURL URLWithString:[[URL absoluteString] stringByAppendingFormat:@"#%@", fragment]]; - - NSError *error = nil; - id document = [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:URL display:YES error:&error]; - if (document == nil && [error isUserCancelledError] == NO) - [NSApp presentError:error]; - - if ([[NSUserDefaults standardUserDefaults] boolForKey:SKAutoRemoveFinishedDownloadsKey]) { - [[download retain] autorelease]; - [[self mutableArrayValueForKey:DOWNLOADS_KEY] removeObject:download]; - // for the document to note that the file has been deleted - [document setFileURL:[download fileURL]]; - if ([self countOfDownloads] == 0 && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoCloseDownloadsWindowKey]) - [[self window] close]; - } - } -} - #pragma mark NSTableViewDataSource - (NSInteger)numberOfRowsInTableView:(NSTableView *)tv { return 0; } @@ -520,6 +516,8 @@ NSUInteger row = [downloads indexOfObject:object]; if (row != NSNotFound) [tableView setNeedsDisplayInRect:NSUnionRect([tableView frameOfCellAtColumn:RESUME_COLUMN row:row], [tableView frameOfCellAtColumn:CANCEL_COLUMN row:row])]; + if ([object status] == SKDownloadStatusFinished) + [self openDownload:object]; } } else { [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d _______________________________________________ Skim-app-commit mailing list Skim-app-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-commit