Ignore:
Timestamp:
Mar 10, 2012, 3:38:58 AM (10 years ago)
Author:
livings124
Message:

#4822 Enable Automatic Reference Counting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r13240 r13248  
    140140    NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: [[NSNumber alloc] initWithBool: active], @"Active",
    141141                                [[NSNumber alloc] initWithBool: byUser], @"ByUser", nil];
    142     [(Controller *)controller performSelectorOnMainThread: @selector(altSpeedToggledCallbackIsLimited:)
     142    [(__bridge Controller *)controller performSelectorOnMainThread: @selector(altSpeedToggledCallbackIsLimited:)
    143143        withObject: dict waitUntilDone: NO];
    144144}
     
    147147                                            void * controller)
    148148{
    149     [(Controller *)controller rpcCallback: type forTorrentStruct: torrentStruct];
     149    [(__bridge Controller *)controller rpcCallback: type forTorrentStruct: torrentStruct];
    150150    return TR_RPC_NOREMOVE; //we'll do the remove manually
    151151}
     
    153153static void sleepCallback(void * controller, io_service_t y, natural_t messageType, void * messageArgument)
    154154{
    155     [(Controller *)controller sleepCallback: messageType argument: messageArgument];
     155    [(__bridge Controller *)controller sleepCallback: messageType argument: messageArgument];
    156156}
    157157
     
    173173       
    174174        [alert runModal];
    175         [alert release];
    176175       
    177176        //kill ourselves right away
     
    183182   
    184183    //set custom value transformers
    185     ExpandedPathToPathTransformer * pathTransformer = [[[ExpandedPathToPathTransformer alloc] init] autorelease];
     184    ExpandedPathToPathTransformer * pathTransformer = [[ExpandedPathToPathTransformer alloc] init];
    186185    [NSValueTransformer setValueTransformer: pathTransformer forName: @"ExpandedPathToPathTransformer"];
    187186   
    188     ExpandedPathToIconTransformer * iconTransformer = [[[ExpandedPathToIconTransformer alloc] init] autorelease];
     187    ExpandedPathToIconTransformer * iconTransformer = [[ExpandedPathToIconTransformer alloc] init];
    189188    [NSValueTransformer setValueTransformer: iconTransformer forName: @"ExpandedPathToIconTransformer"];
    190189   
     
    204203        if ([alert runModal] == NSAlertSecondButtonReturn)
    205204            exit(0);
    206         [alert release];
    207205       
    208206        [[NSUserDefaults standardUserDefaults] setBool: NO forKey: @"WarningLegal"];
     
    343341        fSoundPlaying = NO;
    344342       
    345         tr_sessionSetAltSpeedFunc(fLib, altSpeedToggledCallback, self);
     343        tr_sessionSetAltSpeedFunc(fLib, altSpeedToggledCallback, (__bridge void *)(self));
    346344        if (usesSpeedLimitSched)
    347345            [fDefaults setBool: tr_sessionUsesAltSpeed(fLib) forKey: @"SpeedLimit"];
    348346       
    349         tr_sessionSetRPCCallback(fLib, rpcCallback, self);
     347        tr_sessionSetRPCCallback(fLib, rpcCallback, (__bridge void *)(self));
    350348       
    351349        [GrowlApplicationBridge setGrowlDelegate: self];
     
    369367    [toolbar setDisplayMode: NSToolbarDisplayModeIconOnly];
    370368    [fWindow setToolbar: toolbar];
    371     [toolbar release];
    372369   
    373370    [fWindow setDelegate: self]; //do manually to avoid placement issue
     
    439436    IONotificationPortRef notify;
    440437    io_object_t iterator;
    441     if ((fRootPort = IORegisterForSystemPower(self, & notify, sleepCallback, &iterator)))
     438    if ((fRootPort = IORegisterForSystemPower((__bridge void *)(self), & notify, sleepCallback, &iterator)))
    442439        CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notify), kCFRunLoopCommonModes);
    443440    else
     
    469466                    [waitToStartTorrents addObject: torrent];
    470467               
    471                 [torrent release];
    472468            }
    473469        }
     
    600596                [fDefaults setBool: ([[alert suppressionButton] state] != NSOnState) forKey: @"WarningDonate"];
    601597           
    602             [alert release];
    603598        }
    604599    }
     
    671666        if ([fAutoImportTimer isValid])
    672667            [fAutoImportTimer invalidate];
    673         [fAutoImportTimer release];
    674668    }
    675669   
     
    683677            NSURLDownload * download = [downloadDict objectForKey: @"Download"];
    684678            [download cancel];
    685             [download release];
    686         }
    687         [fPendingTorrentDownloads release];
     679        }
    688680    }
    689681   
     
    704696    [fTableView saveCollapsedGroups];
    705697   
    706     //remaining calls the same as dealloc
    707     [fInfoController release];
    708     [fMessageController release];
    709     [fPrefsController release];
    710    
    711     [fStatusBar release];
    712     [fFilterBar release];
    713    
    714     [fTorrents release];
    715     [fDisplayedTorrents release];
    716    
    717     [fAddingTransfers release];
    718    
    719     [fOverlayWindow release];
    720     [fBadger release];
    721    
    722     [fAutoImportedNames release];
    723    
    724     [fPreviewPanel release];
    725    
    726698    //complete cleanup
    727699    tr_sessionClose(fLib);
     
    751723    {
    752724        [download cancel];
     725       
     726        [fPendingTorrentDownloads removeObjectForKey: [[download request] URL]];
     727        if ([fPendingTorrentDownloads count] == 0)
     728            fPendingTorrentDownloads = nil;
    753729       
    754730        NSRunAlertPanel(NSLocalizedString(@"Torrent download failed", "Download not a torrent -> title"),
     
    757733            [[[[download request] URL] absoluteString] stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding]],
    758734            NSLocalizedString(@"OK", "Download not a torrent -> button"), nil, nil);
    759        
    760         [download release];
    761735    }
    762736    else
     
    767741-(void) download: (NSURLDownload *) download didCreateDestination: (NSString *) path
    768742{
    769     if (!fPendingTorrentDownloads)
    770         fPendingTorrentDownloads = [[NSMutableDictionary alloc] init];
    771    
    772     [fPendingTorrentDownloads setObject: [NSDictionary dictionaryWithObjectsAndKeys:
    773                     path, @"Path", download, @"Download", nil] forKey: [[download request] URL]];
     743    [(NSMutableDictionary *)[fPendingTorrentDownloads objectForKey: [[download request] URL]] setObject: path forKey: @"Path"];
    774744}
    775745
     
    784754    [fPendingTorrentDownloads removeObjectForKey: [[download request] URL]];
    785755    if ([fPendingTorrentDownloads count] == 0)
    786     {
    787         [fPendingTorrentDownloads release];
    788756        fPendingTorrentDownloads = nil;
    789     }
    790    
    791     [download release];
    792757}
    793758
     
    803768    [fPendingTorrentDownloads removeObjectForKey: [[download request] URL]];
    804769    if ([fPendingTorrentDownloads count] == 0)
    805     {
    806         [fPendingTorrentDownloads release];
    807770        fPendingTorrentDownloads = nil;
    808     }
    809    
    810     [download release];
    811771}
    812772
     
    902862                                                    deleteTorrent: deleteTorrentFile canToggleDelete: canToggleDelete];
    903863            [addController showWindow: self];
     864           
     865            if (!fAddWindows)
     866                fAddWindows = [NSMutableSet set];
     867            [fAddWindows addObject: addController];
    904868        }
    905869        else
     
    910874            [torrent update];
    911875            [fTorrents addObject: torrent];
    912             [torrent release];
    913876           
    914877            if (!fAddingTransfers)
     
    924887{
    925888    Torrent * torrent = [addController torrent];
    926     [addController autorelease];
    927889   
    928890    if (add)
     
    932894        [torrent update];
    933895        [fTorrents addObject: torrent];
    934         [torrent release];
    935896       
    936897        if (!fAddingTransfers)
     
    943904    {
    944905        [torrent closeRemoveTorrent: NO];
    945         [torrent release];
    946     }
     906    }
     907   
     908    [fAddWindows removeObject: addController];
     909    if ([fAddWindows count] == 0)
     910        fAddWindows = nil;
    947911}
    948912
     
    982946                                                        controller: self];
    983947        [addController showWindow: self];
     948       
     949        if (!fAddWindows)
     950            fAddWindows = [NSMutableSet set];
     951        [fAddWindows addObject: addController];
    984952    }
    985953    else
     
    990958        [torrent update];
    991959        [fTorrents addObject: torrent];
    992         [torrent release];
    993960       
    994961        if (!fAddingTransfers)
     
    1003970{
    1004971    Torrent * torrent = [addController torrent];
    1005     [addController autorelease];
    1006972   
    1007973    if (add)
     
    1011977        [torrent update];
    1012978        [fTorrents addObject: torrent];
    1013         [torrent release];
    1014979       
    1015980        if (!fAddingTransfers)
     
    1022987    {
    1023988        [torrent closeRemoveTorrent: NO];
    1024         [torrent release];
    1025     }
     989    }
     990   
     991    [fAddWindows removeObject: addController];
     992    if ([fAddWindows count] == 0)
     993        fAddWindows = nil;
    1026994}
    1027995
     
    1029997{
    1030998    NSDictionary * dict = [notification userInfo];
    1031     [self openFiles: [NSArray arrayWithObject: [dict objectForKey: @"File"]] addType: ADD_CREATED
    1032                         forcePath: [dict objectForKey: @"Path"]];
    1033     [dict release];
     999    [self openFiles: [NSArray arrayWithObject: [dict objectForKey: @"File"]] addType: ADD_CREATED forcePath: [dict objectForKey: @"Path"]];
    10341000}
    10351001
     
    10371003{
    10381004    [self openFiles: [dictionary objectForKey: @"Filenames"] addType: [[dictionary objectForKey: @"AddType"] intValue] forcePath: nil];
    1039    
    1040     [dictionary release];
    10411005}
    10421006
     
    10901054    if ([[alert suppressionButton] state] == NSOnState)
    10911055        [fDefaults setBool: NO forKey: @"WarningInvalidOpen"];
    1092     [alert release];
    10931056}
    10941057
     
    11081071    if ([[alert suppressionButton] state] == NSOnState)
    11091072        [fDefaults setBool: NO forKey: @"WarningInvalidOpen"];
    1110     [alert release];
    11111073}
    11121074
     
    11291091    if ([[alert suppressionButton] state])
    11301092        [fDefaults setBool: NO forKey: @"WarningDuplicate"];
    1131     [alert release];
    11321093}
    11331094
     
    11541115    if ([[alert suppressionButton] state])
    11551116        [fDefaults setBool: NO forKey: @"WarningDuplicate"];
    1156     [alert release];
    11571117}
    11581118
     
    11811141        NSURLRequest * request = [NSURLRequest requestWithURL: [NSURL URLWithString: urlString]
    11821142                                    cachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval: 60];
    1183         [[NSURLDownload alloc] initWithRequest: request delegate: self];
     1143       
     1144        if ([fPendingTorrentDownloads objectForKey: [request URL]])
     1145        {
     1146            NSLog(@"Already downloading %@", [request URL]);
     1147            return;
     1148        }
     1149       
     1150        NSURLDownload * download = [[NSURLDownload alloc] initWithRequest: request delegate: self];
     1151       
     1152        if (!fPendingTorrentDownloads)
     1153            fPendingTorrentDownloads = [[NSMutableDictionary alloc] init];
     1154       
     1155        [fPendingTorrentDownloads setObject: [NSMutableDictionary dictionaryWithObject: download forKey: @"Download"] forKey: [request URL]];
    11841156    }
    11851157}
     
    11871159- (void) openURLShowSheet: (id) sender
    11881160{
    1189     [[[URLSheetWindowController alloc] initWithController: self] beginSheetForWindow: fWindow];
    1190 }
    1191 
    1192 - (void) urlSheetDidEnd: (URLSheetWindowController *) controller url: (NSString *) urlString returnCode: (NSInteger) returnCode
     1161    if (!fUrlSheetController)
     1162    {
     1163        fUrlSheetController = [[URLSheetWindowController alloc] initWithController: self];
     1164       
     1165        [NSApp beginSheet: [fUrlSheetController window] modalForWindow: fWindow modalDelegate: self didEndSelector: @selector(urlSheetDidEnd:returnCode:contextInfo:) contextInfo: nil];
     1166    }
     1167}
     1168
     1169- (void) urlSheetDidEnd: (NSWindow *) sheet returnCode: (NSInteger) returnCode contextInfo: (void *) contextInfo
    11931170{
    11941171    if (returnCode == 1)
     1172    {
     1173        NSString * urlString = [fUrlSheetController urlString];
    11951174        [self performSelectorOnMainThread: @selector(openURL:) withObject: urlString waitUntilDone: NO];
    1196    
    1197     [controller release];
     1175    }
     1176   
     1177    fUrlSheetController = nil;
    11981178}
    11991179
     
    12771257- (void) removeTorrents: (NSArray *) torrents deleteData: (BOOL) deleteData
    12781258{
    1279     [torrents retain];
    12801259
    12811260    if ([fDefaults boolForKey: @"CheckRemove"])
     
    13401319            NSBeginAlertSheet(title, NSLocalizedString(@"Remove", "Removal confirm panel -> button"),
    13411320                NSLocalizedString(@"Cancel", "Removal confirm panel -> button"), nil, fWindow, self,
    1342                 nil, @selector(removeSheetDidEnd:returnCode:contextInfo:), dict, message);
     1321                nil, @selector(removeSheetDidEnd:returnCode:contextInfo:), (__bridge void *)dict, message);
    13431322            return;
    13441323        }
     
    13531332    if (returnCode == NSAlertDefaultReturn)
    13541333        [self confirmRemoveTorrents: torrents deleteData: [[dict objectForKey: @"DeleteData"] boolValue]];
    1355     else
    1356         [torrents release];
    1357    
    1358     [dict release];
    13591334}
    13601335
     
    14441419   
    14451420    [self fullUpdateUI];
    1446    
    1447     #warning why do we need them retained?
    1448     [torrents autorelease];
    14491421}
    14501422
     
    14881460        }
    14891461       
    1490         NSAlert * alert = [[[NSAlert alloc] init] autorelease];
     1462        NSAlert * alert = [[NSAlert alloc] init];
    14911463        [alert setMessageText: message];
    14921464        [alert setInformativeText: info];
     
    15021474        if (returnCode != NSAlertFirstButtonReturn)
    15031475        {
    1504             [torrents release];
    15051476            return;
    15061477        }
     
    15501521    if ([torrents count] == 0)
    15511522    {
    1552         [torrents release];
    15531523        return;
    15541524    }
     
    15871557           
    15881558            [alert runModal];
    1589             [alert release];
    15901559        }
    15911560       
     
    23012270                        if (!newGroup)
    23022271                        {
    2303                             newGroup = [[[TorrentGroup alloc] initWithGroup: groupValue] autorelease];
     2272                            newGroup = [[TorrentGroup alloc] initWithGroup: groupValue];
    23042273                            [groupsByIndex setObject: newGroup forKey: [NSNumber numberWithInteger: groupValue]];
    23052274                            [fDisplayedTorrents addObject: newGroup];
     
    23472316            if (!group)
    23482317            {
    2349                 group = [[[TorrentGroup alloc] initWithGroup: groupValue] autorelease];
     2318                group = [[TorrentGroup alloc] initWithGroup: groupValue];
    23502319                [groupsByIndex setObject: group forKey: [NSNumber numberWithInteger: groupValue]];
    23512320                [fDisplayedTorrents addObject: group];
     
    24102379                if (!group)
    24112380                {
    2412                     group = [[[TorrentGroup alloc] initWithGroup: groupValue] autorelease];
     2381                    group = [[TorrentGroup alloc] initWithGroup: groupValue];
    24132382                    [groupsByIndex setObject: group forKey: [NSNumber numberWithInteger: groupValue]];
    24142383                }
     
    24782447    if (fAddingTransfers)
    24792448    {
    2480         [fAddingTransfers release];
    24812449        fAddingTransfers = nil;
    24822450    }
     
    25032471        [popover showRelativeToRect: [sender frame] ofView: sender preferredEdge: NSMaxYEdge];
    25042472       
    2505         [viewController release];
    2506         [popover release];
    25072473    }
    25082474    else
     
    25402506        for (NSInteger i = 0; i < groupMenuCount; i++)
    25412507        {
    2542             NSMenuItem * item = [[groupMenu itemAtIndex: 0] retain];
     2508            NSMenuItem * item = [groupMenu itemAtIndex: 0];
    25432509            [groupMenu removeItemAtIndex: 0];
    25442510            [menu addItem: item];
    2545             [item release];
    25462511        }
    25472512    }
     
    25622527            [item setRepresentedObject: [NSNumber numberWithInt: speedLimitActionValue[i]]];
    25632528            [menu addItem: item];
    2564             [item release];
    25652529        }
    25662530    }
     
    25802544            [item setRepresentedObject: [NSNumber numberWithFloat: ratioLimitActionValue[i]]];
    25812545            [menu addItem: item];
    2582             [item release];
    25832546        }
    25842547    }
     
    26272590            notificationName: GROWL_AUTO_SPEED_LIMIT iconData: nil priority: 0 isSticky: NO clickContext: nil];
    26282591   
    2629     [dict release];
    26302592}
    26312593
     
    26792641            if ([fAutoImportTimer isValid])
    26802642                [fAutoImportTimer invalidate];
    2681             [fAutoImportTimer release];
    26822643            fAutoImportTimer = nil;
    26832644        }
    26842645       
    26852646        //check again in 10 seconds in case torrent file wasn't complete
    2686         fAutoImportTimer = [[NSTimer scheduledTimerWithTimeInterval: 10.0 target: self
    2687             selector: @selector(checkAutoImportDirectory) userInfo: nil repeats: NO] retain];
     2647        fAutoImportTimer = [NSTimer scheduledTimerWithTimeInterval: 10.0 target: self
     2648            selector: @selector(checkAutoImportDirectory) userInfo: nil repeats: NO];
    26882649       
    26892650        [self checkAutoImportDirectory];
     
    26972658        if ([fAutoImportTimer isValid])
    26982659            [fAutoImportTimer invalidate];
    2699         [fAutoImportTimer release];
    27002660        fAutoImportTimer = nil;
    27012661    }
    27022662   
    2703     if (fAutoImportedNames)
    2704     {
    2705         [fAutoImportedNames release];
    2706         fAutoImportedNames = nil;
    2707     }
     2663    fAutoImportedNames = nil;
    27082664   
    27092665    [self checkAutoImportDirectory];
     
    27662722    }
    27672723   
    2768     [newNames release];
    27692724}
    27702725
     
    33043259    {
    33053260        [[fStatusBar view] removeFromSuperviewWithoutNeedingDisplay];
    3306         [fStatusBar release];
    33073261        fStatusBar = nil;
    33083262    }
     
    34023356    {
    34033357        [[fFilterBar view] removeFromSuperviewWithoutNeedingDisplay];
    3404         [fFilterBar release];
    34053358        fFilterBar = nil;
    34063359    }
     
    34313384- (void) beginPreviewPanelControl: (QLPreviewPanel *) panel
    34323385{
    3433     fPreviewPanel = [panel retain];
     3386    fPreviewPanel = panel;
    34343387    [fPreviewPanel setDelegate: self];
    34353388    [fPreviewPanel setDataSource: self];
     
    34383391- (void) endPreviewPanelControl: (QLPreviewPanel *) panel
    34393392{
    3440     [fPreviewPanel release];
    34413393    fPreviewPanel = nil;
    34423394}
     
    35153467   
    35163468    [item setView: button];
    3517     [button release];
    35183469   
    35193470    const NSSize buttonSize = NSMakeSize(36.0, 25.0);
     
    35213472    [item setMaxSize: buttonSize];
    35223473   
    3523     return [item autorelease];
     3474    return item;
    35243475}
    35253476
     
    36013552       
    36023553        NSSegmentedControl * segmentedControl = [[NSSegmentedControl alloc] initWithFrame: NSZeroRect];
    3603         [segmentedControl setCell: [[[ToolbarSegmentedCell alloc] init] autorelease]];
     3554        [segmentedControl setCell: [[ToolbarSegmentedCell alloc] init]];
    36043555        [groupItem setView: segmentedControl];
    36053556        NSSegmentedCell * segmentedCell = (NSSegmentedCell *)[segmentedControl cell];
     
    36323583                                        NSLocalizedString(@"Resume All", "All toolbar item -> label"), nil]];
    36333584       
    3634         [segmentedControl release];
    36353585       
    36363586        [groupItem setVisibilityPriority: NSToolbarItemVisibilityPriorityHigh];
    36373587       
    3638         return [groupItem autorelease];
     3588        return groupItem;
    36393589    }
    36403590    else if ([ident isEqualToString: TOOLBAR_PAUSE_RESUME_SELECTED])
     
    36433593       
    36443594        NSSegmentedControl * segmentedControl = [[NSSegmentedControl alloc] initWithFrame: NSZeroRect];
    3645         [segmentedControl setCell: [[[ToolbarSegmentedCell alloc] init] autorelease]];
     3595        [segmentedControl setCell: [[ToolbarSegmentedCell alloc] init]];
    36463596        [groupItem setView: segmentedControl];
    36473597        NSSegmentedCell * segmentedCell = (NSSegmentedCell *)[segmentedControl cell];
     
    36743624                                        NSLocalizedString(@"Resume Selected", "Selected toolbar item -> label"), nil]];
    36753625       
    3676         [segmentedControl release];
    36773626       
    36783627        [groupItem setVisibilityPriority: NSToolbarItemVisibilityPriorityHigh];
    36793628       
    3680         return [groupItem autorelease];
     3629        return groupItem;
    36813630    }
    36823631    else if ([ident isEqualToString: TOOLBAR_FILTER])
     
    42764225    [menu addItemWithTitle: NSLocalizedString(@"Speed Limit", "Dock item") action: @selector(toggleSpeedLimit:) keyEquivalent: @""];
    42774226   
    4278     return [menu autorelease];
     4227    return menu;
    42794228}
    42804229
     
    44394388                if (torrentStruct == [torrent torrentStruct])
    44404389                {
    4441                     [torrent retain];
    44424390                    break;
    44434391                }
     
    44544402            case TR_RPC_TORRENT_ADDED:
    44554403                [self performSelectorOnMainThread: @selector(rpcAddTorrentStruct:) withObject:
    4456                     [[NSValue valueWithPointer: torrentStruct] retain] waitUntilDone: NO];
     4404                    [NSValue valueWithPointer: torrentStruct] waitUntilDone: NO];
    44574405                break;
    44584406           
     
    44934441            default:
    44944442                NSAssert1(NO, @"Unknown RPC command received: %d", type);
    4495                 [torrent release];
    44964443        }
    44974444    }
     
    45014448{
    45024449    tr_torrent * torrentStruct = (tr_torrent *)[torrentStructPtr pointerValue];
    4503     [torrentStructPtr release];
    45044450   
    45054451    NSString * location = nil;
     
    45184464    [torrent update];
    45194465    [fTorrents addObject: torrent];
    4520     [torrent release];
    45214466   
    45224467    if (!fAddingTransfers)
     
    45294474- (void) rpcRemoveTorrent: (Torrent *) torrent
    45304475{
    4531     [self confirmRemoveTorrents: [[NSArray arrayWithObject: torrent] retain] deleteData: NO];
    4532     [torrent release];
     4476    [self confirmRemoveTorrents: [NSArray arrayWithObject: torrent] deleteData: NO];
    45334477}
    45344478
    45354479- (void) rpcRemoveTorrentDeleteData: (Torrent *) torrent
    45364480{
    4537     [self confirmRemoveTorrents: [[NSArray arrayWithObject: torrent] retain] deleteData: YES];
    4538     [torrent release];
     4481    [self confirmRemoveTorrents: [NSArray arrayWithObject: torrent] deleteData: YES];
    45394482}
    45404483
     
    45424485{
    45434486    [torrent update];
    4544     [torrent release];
    45454487   
    45464488    [self updateUI];
     
    45594501    }
    45604502   
    4561     [torrent release];
    45624503}
    45634504
     
    45704511        [fInfoController updateInfoStats];
    45714512   
    4572     [torrent release];
    45734513}
    45744514
Note: See TracChangeset for help on using the changeset viewer.