- (void) startDownload;
- (void) decompressBlocklist;
-- (void) finishDownloadSuccess;
@end
@implementation BlocklistDownloader
-BlocklistDownloader * fDownloader = nil;
+BlocklistDownloader * fBLDownloader = nil;
+ (BlocklistDownloader *) downloader
{
- if (!fDownloader)
+ if (!fBLDownloader)
{
- fDownloader = [[BlocklistDownloader alloc] init];
- [fDownloader startDownload];
+ fBLDownloader = [[BlocklistDownloader alloc] init];
+ [fBLDownloader startDownload];
}
- return fDownloader;
+ return fBLDownloader;
}
+ (BOOL) isRunning
{
- return fDownloader != nil;
+ return fBLDownloader != nil;
}
- (void) setViewController: (BlocklistDownloaderViewController *) viewController
[[BlocklistScheduler scheduler] updateSchedule];
- fDownloader = nil;
+ fBLDownloader = nil;
[self release];
}
[[NSUserDefaults standardUserDefaults] setObject: [NSDate date] forKey: @"BlocklistNewLastUpdate"];
[[BlocklistScheduler scheduler] updateSchedule];
- fDownloader = nil;
+ fBLDownloader = nil;
[self release];
}
- (void) downloadDidFinish: (NSURLDownload *) download
{
fState = BLOCKLIST_DL_PROCESSING;
- [self performSelectorInBackground: @selector(finishDownloadSuccess) withObject: nil];
+
+ [fViewController setStatusProcessing];
+
+ NSAssert(fDestination != nil, @"the blocklist file destination has not been specified");
+
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ [self decompressBlocklist];
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ const int count = tr_blocklistSetContent([PrefsController handle], [fDestination UTF8String]);
+
+ //delete downloaded file
+ [[NSFileManager defaultManager] removeItemAtPath: fDestination error: NULL];
+
+ 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
+ NSDate * date = [NSDate date];
+ [[NSUserDefaults standardUserDefaults] setObject: date forKey: @"BlocklistNewLastUpdate"];
+ [[NSUserDefaults standardUserDefaults] setObject: date forKey: @"BlocklistNewLastUpdateSuccess"];
+ [[BlocklistScheduler scheduler] updateSchedule];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName: @"BlocklistUpdated" object: nil];
+
+ fBLDownloader = nil;
+ [self release];
+ });
+ });
}
- (BOOL) download: (NSURLDownload *) download shouldDecodeSourceDataOfMIMEType: (NSString *) encodingType
}
}
-
-- (void) finishDownloadSuccess
-{
- @autoreleasepool
- {
- [fViewController setStatusProcessing];
-
- //process data
- NSAssert(fDestination != nil, @"the blocklist file destination has not been specified");
-
- [self decompressBlocklist];
-
- const int count = tr_blocklistSetContent([PrefsController handle], [fDestination UTF8String]);
-
- //delete downloaded file
- [[NSFileManager defaultManager] removeItemAtPath: fDestination error: NULL];
-
- 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
- NSDate * date = [NSDate date];
- [[NSUserDefaults standardUserDefaults] setObject: date forKey: @"BlocklistNewLastUpdate"];
- [[NSUserDefaults standardUserDefaults] setObject: date forKey: @"BlocklistNewLastUpdateSuccess"];
- [[BlocklistScheduler scheduler] updateSchedule];
-
- [[NSNotificationCenter defaultCenter] postNotificationName: @"BlocklistUpdated" object: nil];
- }
-
- fDownloader = nil;
- [self release];
-}
-
@end
@implementation BlocklistDownloaderViewController
+BlocklistDownloaderViewController * fBLViewController = nil;
+ (void) downloadWithPrefsController: (PrefsController *) prefsController
{
- BlocklistDownloaderViewController * downloader = [[BlocklistDownloaderViewController alloc] initWithPrefsController: prefsController];
- [downloader startDownload];
+ if (!fBLViewController)
+ {
+ fBLViewController = [[BlocklistDownloaderViewController alloc] initWithPrefsController: prefsController];
+ [fBLViewController startDownload];
+ }
}
- (void) awakeFromNib
[NSApp endSheet: fStatusWindow];
[fStatusWindow orderOut: self];
+ fBLViewController = nil;
[self release];
}
- (void) failureSheetClosed: (NSAlert *) alert returnCode: (NSInteger) code contextInfo: (void *) info
{
[[alert window] orderOut: self];
+
+ fBLViewController = nil;
[self release];
}
BonjourController * fDefaultController = nil;
+ (BonjourController *) defaultController
{
- if (!fDefaultController)
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
fDefaultController = [[BonjourController alloc] init];
+ });
+
return fDefaultController;
}
NSMutableDictionary * fPendingTorrentDownloads;
NSMutableSet * fAddingTransfers;
+ NSMutableSet * fAddWindows;
BOOL fGlobalPopoverShown;
BOOL fSoundPlaying;
[fTorrents release];
[fDisplayedTorrents release];
+ [fAddWindows release];
[fAddingTransfers release];
[fOverlayWindow release];
lockDestination: lockDestination controller: self torrentFile: torrentPath
deleteTorrent: deleteTorrentFile canToggleDelete: canToggleDelete];
[addController showWindow: self];
+
+ if (!fAddWindows)
+ fAddWindows = [[NSMutableSet alloc] init];
+ [fAddWindows addObject: addController];
+ [addController release];
}
else
{
- (void) askOpenConfirmed: (AddWindowController *) addController add: (BOOL) add
{
Torrent * torrent = [addController torrent];
- [addController autorelease];
if (add)
{
[torrent closeRemoveTorrent: NO];
[torrent release];
}
+
+ [fAddWindows removeObject: addController];
+ if ([fAddWindows count] == 0)
+ {
+ [fAddWindows release];
+ fAddWindows = nil;
+ }
}
- (void) openMagnet: (NSString *) address
AddMagnetWindowController * addController = [[AddMagnetWindowController alloc] initWithTorrent: torrent destination: location
controller: self];
[addController showWindow: self];
+
+ if (!fAddWindows)
+ fAddWindows = [[NSMutableSet alloc] init];
+ [fAddWindows addObject: addController];
+ [addController release];
}
else
{
- (void) askOpenMagnetConfirmed: (AddMagnetWindowController *) addController add: (BOOL) add
{
Torrent * torrent = [addController torrent];
- [addController autorelease];
if (add)
{
[torrent closeRemoveTorrent: NO];
[torrent release];
}
+
+ [fAddWindows removeObject: addController];
+ if ([fAddWindows count] == 0)
+ {
+ [fAddWindows release];
+ fAddWindows = nil;
+ }
}
- (void) openCreatedFile: (NSNotification *) notification
#import "PeerProgressIndicatorCell.h"
#import "NSStringAdditions.h"
-#import "transmission.h" // required by utils.h
-#import "utils.h"
-
@implementation PeerProgressIndicatorCell
- (id) copyWithZone: (NSZone *) zone
NSColor * color3 = [NSColor colorWithCalibratedRed: redComponent * 0.85 green: greenComponent * 0.85 blue: blueComponent * 0.85
alpha: alpha];
- NSGradient * progressGradient = [[NSGradient alloc] initWithColorsAndLocations: baseColor, 0.0, color2, 0.5, color3, 0.5,
- baseColor, 1.0, nil];
- return [progressGradient autorelease];
+ return [[[NSGradient alloc] initWithColorsAndLocations: baseColor, 0.0, color2, 0.5, color3, 0.5, baseColor, 1.0, nil] autorelease];
}
@end