mirror of
https://github.com/transmission/transmission
synced 2024-12-26 09:37:56 +00:00
some more streamlining of the blocklist code
This commit is contained in:
parent
f28d15372d
commit
25c30650d6
7 changed files with 26 additions and 38 deletions
|
@ -23,7 +23,6 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <transmission.h>
|
||||
|
||||
@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;
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -26,12 +26,10 @@
|
|||
#import <transmission.h>
|
||||
|
||||
@class PrefsController;
|
||||
@class BlocklistDownloader;
|
||||
|
||||
@interface BlocklistDownloaderViewController : NSObject
|
||||
{
|
||||
PrefsController * fPrefsController;
|
||||
BlocklistDownloader * fDownloader;
|
||||
|
||||
IBOutlet NSWindow * fStatusWindow;
|
||||
IBOutlet NSProgressIndicator * fProgressBar;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Reference in a new issue