From 4252d0ca024ca3b3b6c6a0e6b22d5d25f02b4ca0 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Tue, 13 Mar 2012 03:20:09 +0000 Subject: [PATCH] re-add non-ARC-specific changes from r13248-50, mainly to make re-adding ARC support easier in the future --- macosx/BlocklistDownloader.m | 86 ++++++++++------------ macosx/BlocklistDownloaderViewController.m | 11 ++- macosx/BonjourController.m | 5 +- macosx/Controller.h | 1 + macosx/Controller.m | 27 ++++++- macosx/PeerProgressIndicatorCell.m | 3 - macosx/ProgressGradients.m | 4 +- 7 files changed, 80 insertions(+), 57 deletions(-) diff --git a/macosx/BlocklistDownloader.m b/macosx/BlocklistDownloader.m index 385478405..9d61ef4c1 100644 --- a/macosx/BlocklistDownloader.m +++ b/macosx/BlocklistDownloader.m @@ -31,27 +31,26 @@ - (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 @@ -89,7 +88,7 @@ BlocklistDownloader * fDownloader = nil; [[BlocklistScheduler scheduler] updateSchedule]; - fDownloader = nil; + fBLDownloader = nil; [self release]; } @@ -128,14 +127,45 @@ BlocklistDownloader * fDownloader = nil; [[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 @@ -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 diff --git a/macosx/BlocklistDownloaderViewController.m b/macosx/BlocklistDownloaderViewController.m index d3705198c..dd87f7fe0 100644 --- a/macosx/BlocklistDownloaderViewController.m +++ b/macosx/BlocklistDownloaderViewController.m @@ -37,10 +37,14 @@ @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 @@ -101,6 +105,7 @@ [NSApp endSheet: fStatusWindow]; [fStatusWindow orderOut: self]; + fBLViewController = nil; [self release]; } @@ -148,6 +153,8 @@ - (void) failureSheetClosed: (NSAlert *) alert returnCode: (NSInteger) code contextInfo: (void *) info { [[alert window] orderOut: self]; + + fBLViewController = nil; [self release]; } diff --git a/macosx/BonjourController.m b/macosx/BonjourController.m index bece2ed41..38b71a8b6 100644 --- a/macosx/BonjourController.m +++ b/macosx/BonjourController.m @@ -29,8 +29,11 @@ BonjourController * fDefaultController = nil; + (BonjourController *) defaultController { - if (!fDefaultController) + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ fDefaultController = [[BonjourController alloc] init]; + }); + return fDefaultController; } diff --git a/macosx/Controller.h b/macosx/Controller.h index 273bad030..6b03d8edc 100644 --- a/macosx/Controller.h +++ b/macosx/Controller.h @@ -105,6 +105,7 @@ typedef enum NSMutableDictionary * fPendingTorrentDownloads; NSMutableSet * fAddingTransfers; + NSMutableSet * fAddWindows; BOOL fGlobalPopoverShown; BOOL fSoundPlaying; diff --git a/macosx/Controller.m b/macosx/Controller.m index f6924f8a9..130580e02 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -714,6 +714,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy [fTorrents release]; [fDisplayedTorrents release]; + [fAddWindows release]; [fAddingTransfers 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 deleteTorrent: deleteTorrentFile canToggleDelete: canToggleDelete]; [addController showWindow: self]; + + if (!fAddWindows) + fAddWindows = [[NSMutableSet alloc] init]; + [fAddWindows addObject: addController]; + [addController release]; } else { @@ -923,7 +929,6 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy - (void) askOpenConfirmed: (AddWindowController *) addController add: (BOOL) add { Torrent * torrent = [addController torrent]; - [addController autorelease]; if (add) { @@ -944,6 +949,13 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy [torrent closeRemoveTorrent: NO]; [torrent release]; } + + [fAddWindows removeObject: addController]; + if ([fAddWindows count] == 0) + { + [fAddWindows release]; + fAddWindows = nil; + } } - (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 controller: self]; [addController showWindow: self]; + + if (!fAddWindows) + fAddWindows = [[NSMutableSet alloc] init]; + [fAddWindows addObject: addController]; + [addController release]; } else { @@ -1002,7 +1019,6 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy - (void) askOpenMagnetConfirmed: (AddMagnetWindowController *) addController add: (BOOL) add { Torrent * torrent = [addController torrent]; - [addController autorelease]; if (add) { @@ -1023,6 +1039,13 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy [torrent closeRemoveTorrent: NO]; [torrent release]; } + + [fAddWindows removeObject: addController]; + if ([fAddWindows count] == 0) + { + [fAddWindows release]; + fAddWindows = nil; + } } - (void) openCreatedFile: (NSNotification *) notification diff --git a/macosx/PeerProgressIndicatorCell.m b/macosx/PeerProgressIndicatorCell.m index 47a52fdf2..b37fa88ff 100644 --- a/macosx/PeerProgressIndicatorCell.m +++ b/macosx/PeerProgressIndicatorCell.m @@ -25,9 +25,6 @@ #import "PeerProgressIndicatorCell.h" #import "NSStringAdditions.h" -#import "transmission.h" // required by utils.h -#import "utils.h" - @implementation PeerProgressIndicatorCell - (id) copyWithZone: (NSZone *) zone diff --git a/macosx/ProgressGradients.m b/macosx/ProgressGradients.m index 0c783b7cf..ac709bc9f 100644 --- a/macosx/ProgressGradients.m +++ b/macosx/ProgressGradients.m @@ -38,9 +38,7 @@ 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 -- 2.40.0