diff --git a/macosx/Controller.m b/macosx/Controller.m index 54f497874..eb2c485f9 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -311,7 +311,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy { [fTorrents addObject: torrent]; [torrent release]; - NSLog(@"%u", (long)[torrent retainCount]); + NSLog(@"history restore: %u", (long)[torrent retainCount]); } [history release]; @@ -551,9 +551,9 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy [fDisplayedTorrents removeAllObjects]; enumerator = [fTorrents objectEnumerator]; - Torrent * torrent; - while ((torrent = [enumerator nextObject])) - [torrent endTorrent]; + //Torrent * torrent; + /*while ((torrent = [enumerator nextObject])) + [torrent endTorrent];*/ [fTorrents removeAllObjects]; //NSLog(@"%d", (long)[torrent retainCount]); @@ -1124,10 +1124,9 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy currentOrderValue = [torrent orderValue]; if (!lowestOrderValue || [lowestOrderValue compare: currentOrderValue] == NSOrderedDescending) lowestOrderValue = currentOrderValue; - + NSLog(@"before"); [fTorrents removeObject: torrent]; - [fDisplayedTorrents removeObject: torrent]; - [torrent endTorrent]; + [fDisplayedTorrents removeObject: torrent];NSLog(@"after"); } [torrents release]; diff --git a/macosx/FileOutlineView.m b/macosx/FileOutlineView.m index c9df760fa..39e7c6c88 100644 --- a/macosx/FileOutlineView.m +++ b/macosx/FileOutlineView.m @@ -24,6 +24,7 @@ #import "FileOutlineView.h" #import "FileBrowserCell.h" +#import "InfoWindowController.h" #import "Torrent.h" @implementation FileOutlineView @@ -103,7 +104,8 @@ { NSDictionary * item = [self itemAtRow: row]; if ([[item objectForKey: @"IsFolder"] boolValue] - || ![[item objectForKey: @"Torrent"] canChangeDownloadCheckForFiles: [item objectForKey: @"Indexes"]]) + || ![[(InfoWindowController *)[[self window] windowController] selectedTorrent] + canChangeDownloadCheckForFiles: [item objectForKey: @"Indexes"]]) [fNormalColor set]; else { @@ -131,13 +133,14 @@ NSDictionary * item; int i, priority; + Torrent * torrent = [(InfoWindowController *)[[self window] windowController] selectedTorrent]; for (i = 0; i < [self numberOfRows]; i++) { if ([self isRowSelected: i]) { item = [self itemAtRow: i]; if (![[item objectForKey: @"IsFolder"] boolValue] - && [[item objectForKey: @"Torrent"] canChangeDownloadCheckForFiles: [item objectForKey: @"Indexes"]]) + && [torrent canChangeDownloadCheckForFiles: [item objectForKey: @"Indexes"]]) { priority = [[item objectForKey: @"Priority"] intValue]; if (priority == PRIORITY_HIGH) diff --git a/macosx/FilePriorityCell.m b/macosx/FilePriorityCell.m index 02bf4e7ff..d0806219d 100644 --- a/macosx/FilePriorityCell.m +++ b/macosx/FilePriorityCell.m @@ -1,4 +1,5 @@ #import "FilePriorityCell.h" +#import "InfoWindowController.h" #import "Torrent.h" @implementation FilePriorityCell @@ -31,7 +32,7 @@ [super setSelected: flag forSegment: segment]; //only for when clicking manually - Torrent * torrent = [fItem objectForKey: @"Torrent"]; + Torrent * torrent = [[[[self controlView] window] windowController] selectedTorrent]; NSIndexSet * indexes = [fItem objectForKey: @"Indexes"]; if (![torrent canChangeDownloadCheckForFiles: indexes]) return; @@ -50,7 +51,7 @@ - (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView { - Torrent * torrent = [fItem objectForKey: @"Torrent"]; + Torrent * torrent = [(InfoWindowController *)[[[self controlView] window] windowController] selectedTorrent]; NSIndexSet * indexSet = [fItem objectForKey: @"Indexes"]; if (![torrent canChangeDownloadCheckForFiles: indexSet]) diff --git a/macosx/InfoWindowController.h b/macosx/InfoWindowController.h index 59c45ab41..0716c2a74 100644 --- a/macosx/InfoWindowController.h +++ b/macosx/InfoWindowController.h @@ -66,6 +66,7 @@ } - (void) updateInfoForTorrents: (NSArray *) torrents; +- (Torrent *) selectedTorrent; - (void) updateInfoStats; - (void) updateRatioForTorrent: (Torrent *) torrent; diff --git a/macosx/InfoWindowController.m b/macosx/InfoWindowController.m index be3fd9a7d..9dfef5ae0 100644 --- a/macosx/InfoWindowController.m +++ b/macosx/InfoWindowController.m @@ -309,6 +309,11 @@ [fFileOutline reloadData]; } +- (Torrent *) selectedTorrent +{ + return fTorrents && [fTorrents count] > 0 ? [fTorrents objectAtIndex: 0] : nil; +} + - (void) updateInfoStats { NSString * ident = [[fTabView selectedTabViewItem] identifier]; diff --git a/macosx/Torrent.h b/macosx/Torrent.h index 2e2a4425e..7bf14864a 100644 --- a/macosx/Torrent.h +++ b/macosx/Torrent.h @@ -39,7 +39,6 @@ tr_stat_t * fStat; int fID; - BOOL fInitialized; BOOL fResumeOnWake; NSDate * fDateAdded, * fDateCompleted, * fAnnounceDate, @@ -76,8 +75,6 @@ - (NSDictionary *) history; -- (void) endTorrent; - - (void) changeIncompleteDownloadFolder: (NSString *) folder; - (void) changeDownloadFolder: (NSString *) folder; - (NSString *) downloadFolder; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 481e6dc6a..e3220a1d7 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -188,24 +188,13 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 return history; } -#warning need for now :( -- (void) endTorrent -{ - if (fInitialized) - { - tr_torrentClose(fHandle); - fInitialized = NO; - } -} - - (void) dealloc { NSLog(@"Released!"); NSLog(@"%d", (long)[self retainCount]); if (fHandle) { - if (fInitialized) - tr_torrentClose(fHandle); + tr_torrentClose(fHandle); if (fDownloadFolder) [fDownloadFolder release]; @@ -1485,11 +1474,10 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 waitToStart: (NSNumber *) waitToStart orderValue: (NSNumber *) orderValue filesShouldDownload: (NSArray *) filesShouldDownload filePriorities: (NSArray *) filePriorities; { - fInitialized = NO; if (!(self = [super init])) return nil; - NSLog(@"%d", (long)[self retainCount]); + NSLog(@"init %d", (long)[self retainCount]); static_lastid++; fID = static_lastid; @@ -1540,7 +1528,6 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 [self release]; return nil; } - fInitialized = YES; fInfo = tr_torrentInfo(fHandle); @@ -1600,8 +1587,9 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 int i; for (i = 0; i < MAX_PIECES; i++) fPieces[i] = BLANK_PIECE; - + NSLog(@"end1 %d", (long)[self retainCount]); [self update]; + NSLog(@"end2 %d", (long)[self retainCount]); return self; } @@ -1681,7 +1669,6 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 [NSNumber numberWithBool: isFolder], @"IsFolder", currentPath, @"Path", nil]; [siblings addObject: dict]; - [dict setObject: self forKey: @"Torrent"]; if (isFolder) { [dict setObject: [NSMutableArray array] forKey: @"Children"];