]> granicus.if.org Git - transmission/commitdiff
re-add non-ARC-specific changes from r13248-50, mainly to make re-adding ARC support...
authorMitchell Livingston <livings124@transmissionbt.com>
Tue, 13 Mar 2012 03:20:09 +0000 (03:20 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Tue, 13 Mar 2012 03:20:09 +0000 (03:20 +0000)
macosx/BlocklistDownloader.m
macosx/BlocklistDownloaderViewController.m
macosx/BonjourController.m
macosx/Controller.h
macosx/Controller.m
macosx/PeerProgressIndicatorCell.m
macosx/ProgressGradients.m

index 3854784059fa98e2ab35ade44c9c758c5318861c..9d61ef4c18666fe59ad3246f3c9497e3e6305627 100644 (file)
 
 - (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
index d3705198cd683cb5c9341608eaa328848ca436b9..dd87f7fe0f3a25d94dc915416e87469ad4d281b6 100644 (file)
 
 @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];
 }
 
index bece2ed41eb9717e08bad965aef9d4b9cded579f..38b71a8b66f325e28d79789ea338dbad33bc8d9d 100644 (file)
 BonjourController * fDefaultController = nil;
 + (BonjourController *) defaultController
 {
-    if (!fDefaultController)
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
         fDefaultController = [[BonjourController alloc] init];
+    });
+    
     return fDefaultController;
 }
 
index 273bad03001cf9bbf6477dd0fdcb9fbf32987fb3..6b03d8edc99f43f4ed90ca88a99eab29b819ab4a 100644 (file)
@@ -105,6 +105,7 @@ typedef enum
     NSMutableDictionary             * fPendingTorrentDownloads;
     
     NSMutableSet                    * fAddingTransfers;
+    NSMutableSet                    * fAddWindows;
     
     BOOL                            fGlobalPopoverShown;
     BOOL                            fSoundPlaying;
index f6924f8a93f725b6415f8ec398dc6c41c80035bb..130580e020eb0f83347f57f74bc176cfba5524b6 100644 (file)
@@ -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
index 47a52fdf2f064d833309fec21bbbbf964ca34ee8..b37fa88ffe8021904f991699c1378697d98aaca7 100644 (file)
@@ -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
index 0c783b7cf566405bbfedaaf73601e5f908a70452..ac709bc9fdae488b3ca72a772609a36335587327 100644 (file)
@@ -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