From 25c30650d667886fb4e25bef7b03d10d6c6e279d Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sun, 31 Aug 2008 20:48:10 +0000 Subject: [PATCH] some more streamlining of the blocklist code --- macosx/BlocklistDownloader.h | 6 +----- macosx/BlocklistDownloader.m | 18 ++++-------------- macosx/BlocklistDownloaderViewController.h | 2 -- macosx/BlocklistDownloaderViewController.m | 6 +++--- macosx/Controller.m | 6 ++++-- macosx/PrefsController.h | 6 ++---- macosx/PrefsController.m | 20 ++++++++++++-------- 7 files changed, 26 insertions(+), 38 deletions(-) diff --git a/macosx/BlocklistDownloader.h b/macosx/BlocklistDownloader.h index efb39f2f2..fe103b162 100644 --- a/macosx/BlocklistDownloader.h +++ b/macosx/BlocklistDownloader.h @@ -23,7 +23,6 @@ *****************************************************************************/ #import -#import @class BlocklistDownloaderViewController; @@ -31,16 +30,13 @@ { NSURLDownload * fDownload; - #warning have to store??? - tr_handle * fHandle; - BlocklistDownloaderViewController * fViewController; NSUInteger fCurrentSize; long long fExpectedSize; } -+ (BlocklistDownloader *) downloader: (tr_handle *) handle; //starts download if not already occuring ++ (BlocklistDownloader *) downloader; //starts download if not already occuring + (BOOL) isRunning; - (void) setViewController: (BlocklistDownloaderViewController *) viewController; diff --git a/macosx/BlocklistDownloader.m b/macosx/BlocklistDownloader.m index 792768f29..8737caf6f 100644 --- a/macosx/BlocklistDownloader.m +++ b/macosx/BlocklistDownloader.m @@ -24,6 +24,7 @@ #import "BlocklistDownloader.h" #import "BlocklistDownloaderViewController.h" +#import "PrefsController.h" #import "NSApplicationAdditions.h" #define LIST_URL @"http://download.m0k.org/transmission/files/level1.gz" @@ -31,7 +32,6 @@ @interface BlocklistDownloader (Private) -- (id) initWithHandle: (tr_handle *) handle; - (void) startDownload; - (void) finishDownloadSuccess; @@ -40,11 +40,11 @@ @implementation BlocklistDownloader BlocklistDownloader * fDownloader = nil; -+ (BlocklistDownloader *) downloader: (tr_handle *) handle ++ (BlocklistDownloader *) downloader { if (!fDownloader) { - fDownloader = [[BlocklistDownloader alloc] initWithHandle: handle]; + fDownloader = [[BlocklistDownloader alloc] init]; [fDownloader startDownload]; } @@ -116,16 +116,6 @@ BlocklistDownloader * fDownloader = nil; @implementation BlocklistDownloader (Private) -- (id) initWithHandle: (tr_handle *) handle -{ - if ((self = [super init])) - { - fHandle = handle; - } - - return self; -} - - (void) startDownload { NSURLRequest * request = [NSURLRequest requestWithURL: [NSURL URLWithString: LIST_URL]]; @@ -141,7 +131,7 @@ BlocklistDownloader * fDownloader = nil; [fViewController setStatusProcessing]; //process data - tr_blocklistSetContent(fHandle, [DESTINATION UTF8String]); + tr_blocklistSetContent([PrefsController handle], [DESTINATION UTF8String]); //delete downloaded file if ([NSApp isOnLeopardOrBetter]) diff --git a/macosx/BlocklistDownloaderViewController.h b/macosx/BlocklistDownloaderViewController.h index b2657d13f..8185b5c01 100644 --- a/macosx/BlocklistDownloaderViewController.h +++ b/macosx/BlocklistDownloaderViewController.h @@ -26,12 +26,10 @@ #import @class PrefsController; -@class BlocklistDownloader; @interface BlocklistDownloaderViewController : NSObject { PrefsController * fPrefsController; - BlocklistDownloader * fDownloader; IBOutlet NSWindow * fStatusWindow; IBOutlet NSProgressIndicator * fProgressBar; diff --git a/macosx/BlocklistDownloaderViewController.m b/macosx/BlocklistDownloaderViewController.m index e0d44f721..674a9df94 100644 --- a/macosx/BlocklistDownloaderViewController.m +++ b/macosx/BlocklistDownloaderViewController.m @@ -59,7 +59,7 @@ - (void) cancelDownload: (id) sender { - [fDownloader cancelDownload]; + [[BlocklistDownloader downloader] cancelDownload]; } - (void) setStatusStarting @@ -142,8 +142,8 @@ [NSBundle loadNibNamed: @"BlocklistStatusWindow" owner: self]; [NSApp beginSheet: fStatusWindow modalForWindow: [fPrefsController window] modalDelegate: nil didEndSelector: nil contextInfo: nil]; - fDownloader = [BlocklistDownloader downloader: [fPrefsController handle]]; - [fDownloader setViewController: self]; + BlocklistDownloader * downloader = [BlocklistDownloader downloader]; + [downloader setViewController: self]; } - (void) failureSheetClosed: (NSAlert *) alert returnCode: (int) code contextInfo: (void *) info diff --git a/macosx/Controller.m b/macosx/Controller.m index 099515604..c82183001 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -241,7 +241,9 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy fMessageController = [[MessageWindowController alloc] init]; fInfoController = [[InfoWindowController alloc] init]; - fPrefsController = [[PrefsController alloc] initWithHandle: fLib]; + + [PrefsController setHandle: fLib]; + fPrefsController = [[PrefsController alloc] init]; fBadger = [[Badger alloc] initWithLib: fLib]; [QuickLookController quickLookControllerInitializeWithController: self infoController: fInfoController]; @@ -562,7 +564,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy { //stop blocklist download if ([BlocklistDownloader isRunning]) - [[BlocklistDownloader downloader: fLib] cancelDownload]; + [[BlocklistDownloader downloader] cancelDownload]; //stop timers and notification checking [[NSNotificationCenter defaultCenter] removeObserver: self]; diff --git a/macosx/PrefsController.h b/macosx/PrefsController.h index 5657e015c..227908b13 100644 --- a/macosx/PrefsController.h +++ b/macosx/PrefsController.h @@ -28,8 +28,6 @@ @interface PrefsController : NSWindowController { - tr_handle * fHandle; - NSUserDefaults * fDefaults; BOOL fHasLoaded; @@ -63,8 +61,8 @@ NSMutableArray * fRPCAccessArray; } -- (id) initWithHandle: (tr_handle *) handle; -- (tr_handle *) handle; ++ (void) setHandle: (tr_handle *) handle; ++ (tr_handle *) handle; - (void) updatePortField; - (void) setPort: (id) sender; diff --git a/macosx/PrefsController.m b/macosx/PrefsController.m index 8f5f98b9e..d3f7a24e3 100644 --- a/macosx/PrefsController.m +++ b/macosx/PrefsController.m @@ -70,12 +70,22 @@ @implementation PrefsController -- (id) initWithHandle: (tr_handle *) handle +tr_handle * fHandle; ++ (void) setHandle: (tr_handle *) handle +{ + fHandle = handle; +} + ++ (tr_handle *) handle +{ + return fHandle; +} + +- (id) init { if ((self = [super initWithWindowNibName: @"PrefsWindow"])) { fDefaults = [NSUserDefaults standardUserDefaults]; - fHandle = handle; //checks for old version speeds of -1 if ([fDefaults integerForKey: @"UploadLimit"] < 0) @@ -127,12 +137,6 @@ return self; } -#warning still needed? make class method? -- (tr_handle *) handle -{ - return fHandle; -} - - (void) dealloc { [[NSNotificationCenter defaultCenter] removeObserver: self];