re-add non-ARC-specific changes from r13248-50, mainly to make re-adding ARC support easier in the future

This commit is contained in:
Mitchell Livingston
2012-03-13 03:20:09 +00:00
parent 3d866c03e6
commit 4252d0ca02
7 changed files with 80 additions and 57 deletions

View File

@@ -31,27 +31,26 @@
- (void) startDownload; - (void) startDownload;
- (void) decompressBlocklist; - (void) decompressBlocklist;
- (void) finishDownloadSuccess;
@end @end
@implementation BlocklistDownloader @implementation BlocklistDownloader
BlocklistDownloader * fDownloader = nil; BlocklistDownloader * fBLDownloader = nil;
+ (BlocklistDownloader *) downloader + (BlocklistDownloader *) downloader
{ {
if (!fDownloader) if (!fBLDownloader)
{ {
fDownloader = [[BlocklistDownloader alloc] init]; fBLDownloader = [[BlocklistDownloader alloc] init];
[fDownloader startDownload]; [fBLDownloader startDownload];
} }
return fDownloader; return fBLDownloader;
} }
+ (BOOL) isRunning + (BOOL) isRunning
{ {
return fDownloader != nil; return fBLDownloader != nil;
} }
- (void) setViewController: (BlocklistDownloaderViewController *) viewController - (void) setViewController: (BlocklistDownloaderViewController *) viewController
@@ -89,7 +88,7 @@ BlocklistDownloader * fDownloader = nil;
[[BlocklistScheduler scheduler] updateSchedule]; [[BlocklistScheduler scheduler] updateSchedule];
fDownloader = nil; fBLDownloader = nil;
[self release]; [self release];
} }
@@ -128,14 +127,45 @@ BlocklistDownloader * fDownloader = nil;
[[NSUserDefaults standardUserDefaults] setObject: [NSDate date] forKey: @"BlocklistNewLastUpdate"]; [[NSUserDefaults standardUserDefaults] setObject: [NSDate date] forKey: @"BlocklistNewLastUpdate"];
[[BlocklistScheduler scheduler] updateSchedule]; [[BlocklistScheduler scheduler] updateSchedule];
fDownloader = nil; fBLDownloader = nil;
[self release]; [self release];
} }
- (void) downloadDidFinish: (NSURLDownload *) download - (void) downloadDidFinish: (NSURLDownload *) download
{ {
fState = BLOCKLIST_DL_PROCESSING; 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 - (BOOL) download: (NSURLDownload *) download shouldDecodeSourceDataOfMIMEType: (NSString *) encodingType
@@ -233,40 +263,4 @@ BlocklistDownloader * fDownloader = nil;
} }
} }
- (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 @end

View File

@@ -37,10 +37,14 @@
@implementation BlocklistDownloaderViewController @implementation BlocklistDownloaderViewController
BlocklistDownloaderViewController * fBLViewController = nil;
+ (void) downloadWithPrefsController: (PrefsController *) prefsController + (void) downloadWithPrefsController: (PrefsController *) prefsController
{ {
BlocklistDownloaderViewController * downloader = [[BlocklistDownloaderViewController alloc] initWithPrefsController: prefsController]; if (!fBLViewController)
[downloader startDownload]; {
fBLViewController = [[BlocklistDownloaderViewController alloc] initWithPrefsController: prefsController];
[fBLViewController startDownload];
}
} }
- (void) awakeFromNib - (void) awakeFromNib
@@ -101,6 +105,7 @@
[NSApp endSheet: fStatusWindow]; [NSApp endSheet: fStatusWindow];
[fStatusWindow orderOut: self]; [fStatusWindow orderOut: self];
fBLViewController = nil;
[self release]; [self release];
} }
@@ -148,6 +153,8 @@
- (void) failureSheetClosed: (NSAlert *) alert returnCode: (NSInteger) code contextInfo: (void *) info - (void) failureSheetClosed: (NSAlert *) alert returnCode: (NSInteger) code contextInfo: (void *) info
{ {
[[alert window] orderOut: self]; [[alert window] orderOut: self];
fBLViewController = nil;
[self release]; [self release];
} }

View File

@@ -29,8 +29,11 @@
BonjourController * fDefaultController = nil; BonjourController * fDefaultController = nil;
+ (BonjourController *) defaultController + (BonjourController *) defaultController
{ {
if (!fDefaultController) static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
fDefaultController = [[BonjourController alloc] init]; fDefaultController = [[BonjourController alloc] init];
});
return fDefaultController; return fDefaultController;
} }

View File

@@ -105,6 +105,7 @@ typedef enum
NSMutableDictionary * fPendingTorrentDownloads; NSMutableDictionary * fPendingTorrentDownloads;
NSMutableSet * fAddingTransfers; NSMutableSet * fAddingTransfers;
NSMutableSet * fAddWindows;
BOOL fGlobalPopoverShown; BOOL fGlobalPopoverShown;
BOOL fSoundPlaying; BOOL fSoundPlaying;

View File

@@ -714,6 +714,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
[fTorrents release]; [fTorrents release];
[fDisplayedTorrents release]; [fDisplayedTorrents release];
[fAddWindows release];
[fAddingTransfers release]; [fAddingTransfers release];
[fOverlayWindow release]; [fOverlayWindow release];
@@ -901,6 +902,11 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
lockDestination: lockDestination controller: self torrentFile: torrentPath lockDestination: lockDestination controller: self torrentFile: torrentPath
deleteTorrent: deleteTorrentFile canToggleDelete: canToggleDelete]; deleteTorrent: deleteTorrentFile canToggleDelete: canToggleDelete];
[addController showWindow: self]; [addController showWindow: self];
if (!fAddWindows)
fAddWindows = [[NSMutableSet alloc] init];
[fAddWindows addObject: addController];
[addController release];
} }
else else
{ {
@@ -923,7 +929,6 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
- (void) askOpenConfirmed: (AddWindowController *) addController add: (BOOL) add - (void) askOpenConfirmed: (AddWindowController *) addController add: (BOOL) add
{ {
Torrent * torrent = [addController torrent]; Torrent * torrent = [addController torrent];
[addController autorelease];
if (add) if (add)
{ {
@@ -944,6 +949,13 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
[torrent closeRemoveTorrent: NO]; [torrent closeRemoveTorrent: NO];
[torrent release]; [torrent release];
} }
[fAddWindows removeObject: addController];
if ([fAddWindows count] == 0)
{
[fAddWindows release];
fAddWindows = nil;
}
} }
- (void) openMagnet: (NSString *) address - (void) openMagnet: (NSString *) address
@@ -981,6 +993,11 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
AddMagnetWindowController * addController = [[AddMagnetWindowController alloc] initWithTorrent: torrent destination: location AddMagnetWindowController * addController = [[AddMagnetWindowController alloc] initWithTorrent: torrent destination: location
controller: self]; controller: self];
[addController showWindow: self]; [addController showWindow: self];
if (!fAddWindows)
fAddWindows = [[NSMutableSet alloc] init];
[fAddWindows addObject: addController];
[addController release];
} }
else else
{ {
@@ -1002,7 +1019,6 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
- (void) askOpenMagnetConfirmed: (AddMagnetWindowController *) addController add: (BOOL) add - (void) askOpenMagnetConfirmed: (AddMagnetWindowController *) addController add: (BOOL) add
{ {
Torrent * torrent = [addController torrent]; Torrent * torrent = [addController torrent];
[addController autorelease];
if (add) if (add)
{ {
@@ -1023,6 +1039,13 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
[torrent closeRemoveTorrent: NO]; [torrent closeRemoveTorrent: NO];
[torrent release]; [torrent release];
} }
[fAddWindows removeObject: addController];
if ([fAddWindows count] == 0)
{
[fAddWindows release];
fAddWindows = nil;
}
} }
- (void) openCreatedFile: (NSNotification *) notification - (void) openCreatedFile: (NSNotification *) notification

View File

@@ -25,9 +25,6 @@
#import "PeerProgressIndicatorCell.h" #import "PeerProgressIndicatorCell.h"
#import "NSStringAdditions.h" #import "NSStringAdditions.h"
#import "transmission.h" // required by utils.h
#import "utils.h"
@implementation PeerProgressIndicatorCell @implementation PeerProgressIndicatorCell
- (id) copyWithZone: (NSZone *) zone - (id) copyWithZone: (NSZone *) zone

View File

@@ -38,9 +38,7 @@
NSColor * color3 = [NSColor colorWithCalibratedRed: redComponent * 0.85 green: greenComponent * 0.85 blue: blueComponent * 0.85 NSColor * color3 = [NSColor colorWithCalibratedRed: redComponent * 0.85 green: greenComponent * 0.85 blue: blueComponent * 0.85
alpha: alpha]; alpha: alpha];
NSGradient * progressGradient = [[NSGradient alloc] initWithColorsAndLocations: baseColor, 0.0, color2, 0.5, color3, 0.5, return [[[NSGradient alloc] initWithColorsAndLocations: baseColor, 0.0, color2, 0.5, color3, 0.5, baseColor, 1.0, nil] autorelease];
baseColor, 1.0, nil];
return [progressGradient autorelease];
} }
@end @end