#3697 make blocklist URL configurable in the Mac UI

This commit is contained in:
Mitchell Livingston 2010-10-31 19:05:46 +00:00
parent 92620b72b0
commit 317349c13c
8 changed files with 304 additions and 179 deletions

View File

@ -27,8 +27,7 @@
#import "BlocklistScheduler.h"
#import "PrefsController.h"
#define LIST_URL @"http://update.transmissionbt.com/level1.gz"
#define FILE_NAME @"level1.gz"
#define FILE_NAME @"blocklist.tmp"
@interface BlocklistDownloader (Private)
@ -142,7 +141,11 @@ BlocklistDownloader * fDownloader = nil;
[[BlocklistScheduler scheduler] cancelSchedule];
NSURLRequest * request = [NSURLRequest requestWithURL: [NSURL URLWithString: LIST_URL]];
NSString * urlString = [[NSUserDefaults standardUserDefaults] stringForKey: @"BlocklistURL"];
if (!urlString)
urlString = @"";
NSURLRequest * request = [NSURLRequest requestWithURL: [NSURL URLWithString: urlString]];
fDownload = [[NSURLDownload alloc] initWithRequest: request delegate: self];
[fDownload setDestination: [NSTemporaryDirectory() stringByAppendingPathComponent: FILE_NAME] allowOverwrite: YES];
@ -156,12 +159,16 @@ BlocklistDownloader * fDownloader = nil;
//process data
NSAssert(fDestination != nil, @"the blocklist file destination has not been specified");
tr_blocklistSetContent([PrefsController handle], [fDestination UTF8String]);
const int count = tr_blocklistSetContent([PrefsController handle], [fDestination UTF8String]);
//delete downloaded file
[[NSFileManager defaultManager] removeItemAtPath: fDestination error: NULL];
[fViewController setFinished];
if (count > 0)
[fViewController setFinished];
else
[fViewController setFailed: NSLocalizedString(@"The specified blocklist file did not contain any valid rules.",
"blocklist fail message")];
//update last updated date for schedule
[[NSUserDefaults standardUserDefaults] setObject: [NSDate date] forKey: @"BlocklistLastUpdate"];

View File

@ -55,7 +55,7 @@ BlocklistScheduler * fScheduler = nil;
[self cancelSchedule];
if (![[NSUserDefaults standardUserDefaults] boolForKey: @"Blocklist"]
if (![[NSUserDefaults standardUserDefaults] boolForKey: @"BlocklistNew"]
|| ![[NSUserDefaults standardUserDefaults] boolForKey: @"BlocklistAutoUpdate"])
return;

View File

@ -295,7 +295,8 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
if ([fDefaults objectForKey: @"BindAddressIPv6"])
tr_bencDictAddStr(&settings, TR_PREFS_KEY_BIND_ADDRESS_IPV6, [[fDefaults stringForKey: @"BindAddressIPv6"] UTF8String]);
tr_bencDictAddBool(&settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, [fDefaults boolForKey: @"Blocklist"]);
tr_bencDictAddBool(&settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, [fDefaults boolForKey: @"BlocklistNew"]);
tr_bencDictAddBool(&settings, TR_PREFS_KEY_BLOCKLIST_URL, [[fDefaults stringForKey: @"BlocklistURL"] UTF8String]);
tr_bencDictAddBool(&settings, TR_PREFS_KEY_DHT_ENABLED, [fDefaults boolForKey: @"DHTGlobal"]);
tr_bencDictAddStr(&settings, TR_PREFS_KEY_DOWNLOAD_DIR, [[[fDefaults stringForKey: @"DownloadFolder"]
stringByExpandingTildeInPath] UTF8String]);

View File

@ -16,7 +16,7 @@
<true/>
<key>BindPort</key>
<integer>51413</integer>
<key>Blocklist</key>
<key>BlocklistNew</key>
<false/>
<key>BlocklistAutoUpdate</key>
<false/>

View File

@ -43,8 +43,8 @@
* fSpeedLimitUploadField, * fSpeedLimitDownloadField;
IBOutlet NSPopUpButton * fAutoSpeedDayTypePopUp;
IBOutlet NSTextField * fPeersGlobalField, * fPeersTorrentField, * fBlocklistMessageField, * fBlocklistDateField;
IBOutlet NSButton * fBlocklistEnableCheck;
IBOutlet NSTextField * fPeersGlobalField, * fPeersTorrentField,
* fBlocklistURLField, * fBlocklistMessageField, * fBlocklistDateField;
PortChecker * fPortChecker;
IBOutlet NSTextField * fPortField, * fPortStatusField;
@ -86,6 +86,7 @@
- (void) setEncryptionMode: (id) sender;
- (void) setBlocklistEnabled: (id) sender;
- (void) setBlocklistURL: (id) sender;
- (void) updateBlocklist: (id) sender;
- (void) setBlocklistAutoUpdate: (id) sender;
- (void) updateBlocklistFields;

View File

@ -462,13 +462,16 @@ tr_session * fHandle;
- (void) setBlocklistEnabled: (id) sender
{
const BOOL enable = [sender state] == NSOnState;
[fDefaults setBool: enable forKey: @"Blocklist"];
tr_blocklistSetEnabled(fHandle, enable);
tr_blocklistSetEnabled(fHandle, [fDefaults boolForKey: @"BlocklistNew"]);
[[BlocklistScheduler scheduler] updateSchedule];
}
- (void) setBlocklistURL: (id) sender
{
tr_blocklistSetURL(fHandle, [[fDefaults stringForKey: @"BlocklistURL"] UTF8String]);
}
- (void) updateBlocklist: (id) sender
{
[BlocklistDownloaderViewController downloadWithPrefsController: self];
@ -498,9 +501,6 @@ tr_session * fHandle;
[fBlocklistMessageField setStringValue: NSLocalizedString(@"A blocklist must first be downloaded",
"Prefs -> blocklist -> message")];
[fBlocklistEnableCheck setEnabled: exists];
[fBlocklistEnableCheck setState: exists && [fDefaults boolForKey: @"Blocklist"]];
NSString * updatedDateString;
if (exists)
{
@ -1095,7 +1095,7 @@ tr_session * fHandle;
//blocklist
const BOOL blocklist = tr_blocklistIsEnabled(fHandle);
[fDefaults setBool: blocklist forKey: @"Blocklist"];
[fDefaults setBool: blocklist forKey: @"BlocklistNew"];
//seed ratio
const BOOL ratioLimited = tr_sessionIsRatioLimited(fHandle);

View File

@ -12,8 +12,8 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="1480"/>
<integer value="2"/>
<integer value="1480"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -156,7 +156,7 @@
<int key="NSfFlags">3100</int>
</object>
<reference key="NSControlView" ref="673219624"/>
<int key="NSButtonFlags">-934526721</int>
<int key="NSButtonFlags">-935051009</int>
<int key="NSButtonFlags2">160</int>
<object class="NSCustomResource" key="NSNormalImage">
<string key="NSClassName">NSImage</string>
@ -176,7 +176,7 @@
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="696487414">
<int key="NSCellFlags">67239488</int>
<int key="NSCellFlags2">138544128</int>
<int key="NSCellFlags2">138549248</int>
<string key="NSContents">999 of 999 transfers</string>
<object class="NSFont" key="NSSupport" id="660654866">
<string key="NSName">LucidaGrande</string>

File diff suppressed because it is too large Load Diff