From 27fa4091dc1ba1a8849f45318b52e900aaf74590 Mon Sep 17 00:00:00 2001
From: Mitchell Livingston <livings124@transmissionbt.com>
Date: Tue, 31 May 2011 22:26:04 +0000
Subject: [PATCH] have FileListNodes store their corresponding torrents,
 allowing the removal of this functionality from the file outline view

---
 macosx/FileListNode.h          | 10 ++++++++--
 macosx/FileListNode.m          | 19 +++++++++++++------
 macosx/FileNameCell.m          |  4 ++--
 macosx/FileOutlineController.m |  1 -
 macosx/FileOutlineView.h       |  5 -----
 macosx/FileOutlineView.m       | 11 -----------
 macosx/FilePriorityCell.m      |  7 ++++---
 macosx/Torrent.m               | 10 +++++-----
 8 files changed, 32 insertions(+), 35 deletions(-)

diff --git a/macosx/FileListNode.h b/macosx/FileListNode.h
index 8964efd14..8625280b3 100644
--- a/macosx/FileListNode.h
+++ b/macosx/FileListNode.h
@@ -24,6 +24,8 @@
 
 #import <Cocoa/Cocoa.h>
 
+@class Torrent;
+
 @interface FileListNode : NSObject <NSCopying>
 {
     NSString * fName, * fPath;
@@ -34,10 +36,12 @@
     NSImage * fIcon;
     
     NSMutableArray * fChildren;
+    
+    Torrent * fTorrent;
 }
 
-- (id) initWithFolderName: (NSString *) name path: (NSString *) path;
-- (id) initWithFileName: (NSString *) name path: (NSString *) path size: (uint64_t) size index: (NSUInteger) index;
+- (id) initWithFolderName: (NSString *) name path: (NSString *) path torrent: (Torrent *) torrent;
+- (id) initWithFileName: (NSString *) name path: (NSString *) path size: (uint64_t) size index: (NSUInteger) index torrent: (Torrent *) torrent;
 
 - (void) insertChild: (FileListNode *) child;
 - (void) insertIndex: (NSUInteger) index withSize: (uint64_t) size;
@@ -54,4 +58,6 @@
 
 - (NSMutableArray *) children;
 
+- (Torrent *) torrent;
+
 @end
diff --git a/macosx/FileListNode.m b/macosx/FileListNode.m
index ad0dc81c7..4dc6f9888 100644
--- a/macosx/FileListNode.m
+++ b/macosx/FileListNode.m
@@ -26,15 +26,15 @@
 
 @interface FileListNode (Private)
 
-- (id) initWithFolder: (BOOL) isFolder name: (NSString *) name path: (NSString *) path;
+- (id) initWithFolder: (BOOL) isFolder name: (NSString *) name path: (NSString *) path torrent: (Torrent *) torrent;
 
 @end
 
 @implementation FileListNode
 
-- (id) initWithFolderName: (NSString *) name path: (NSString *) path
+- (id) initWithFolderName: (NSString *) name path: (NSString *) path torrent: (Torrent *) torrent
 {
-    if ((self = [self initWithFolder: YES name: name path: path]))
+    if ((self = [self initWithFolder: YES name: name path: path torrent: torrent]))
     {
         fChildren = [[NSMutableArray alloc] init];
         fSize = 0;
@@ -43,9 +43,9 @@
     return self;
 }
 
-- (id) initWithFileName: (NSString *) name path: (NSString *) path size: (uint64_t) size index: (NSUInteger) index
+- (id) initWithFileName: (NSString *) name path: (NSString *) path size: (uint64_t) size index: (NSUInteger) index torrent: (Torrent *) torrent
 {
-    if ((self = [self initWithFolder: NO name: name path: path]))
+    if ((self = [self initWithFolder: NO name: name path: path torrent: torrent]))
     {
         fSize = size;
         [fIndexes addIndex: index];
@@ -136,11 +136,16 @@
     return fChildren;
 }
 
+- (Torrent *) torrent
+{
+    return fTorrent;
+}
+
 @end
 
 @implementation FileListNode (Private)
 
-- (id) initWithFolder: (BOOL) isFolder name: (NSString *) name path: (NSString *) path
+- (id) initWithFolder: (BOOL) isFolder name: (NSString *) name path: (NSString *) path torrent: (Torrent *) torrent
 {
     if ((self = [super init]))
     {
@@ -149,6 +154,8 @@
         fPath = [path retain];
         
         fIndexes = [[NSMutableIndexSet alloc] init];
+        
+        fTorrent = torrent;
     }
     
     return self;
diff --git a/macosx/FileNameCell.m b/macosx/FileNameCell.m
index 3ad3162fd..56131d415 100644
--- a/macosx/FileNameCell.m
+++ b/macosx/FileNameCell.m
@@ -129,7 +129,7 @@
     NSColor * titleColor, * statusColor;
     if ([self backgroundStyle] == NSBackgroundStyleDark)
         titleColor = statusColor = [NSColor whiteColor];
-    else if ([[(FileOutlineView *)[self controlView] torrent] checkForFiles: [(FileListNode *)[self objectValue] indexes]] == NSOffState)
+    else if ([[(FileListNode *)[self objectValue] torrent] checkForFiles: [(FileListNode *)[self objectValue] indexes]] == NSOffState)
         titleColor = statusColor = [NSColor disabledControlTextColor];
     else
     {
@@ -207,8 +207,8 @@
 
 - (NSAttributedString *) attributedStatus
 {
-    Torrent * torrent = [(FileOutlineView *)[self controlView] torrent];
     FileListNode * node = (FileListNode *)[self objectValue];
+    Torrent * torrent = [node torrent];
     
     const CGFloat progress = [torrent fileProgress: node];
     NSString * percentString = [NSString percentString: progress longDecimals: YES];
diff --git a/macosx/FileOutlineController.m b/macosx/FileOutlineController.m
index 6fa6d8a06..1c3d2c5a9 100644
--- a/macosx/FileOutlineController.m
+++ b/macosx/FileOutlineController.m
@@ -84,7 +84,6 @@ typedef enum
 - (void) setTorrent: (Torrent *) torrent
 {
     fTorrent = torrent;
-    [fOutline setTorrent: fTorrent];
     
     [fFileList release];
     fFileList = [[fTorrent fileList] retain];
diff --git a/macosx/FileOutlineView.h b/macosx/FileOutlineView.h
index ec1684703..9a9e77421 100644
--- a/macosx/FileOutlineView.h
+++ b/macosx/FileOutlineView.h
@@ -28,14 +28,9 @@
 
 @interface FileOutlineView : NSOutlineView
 {
-    Torrent * fTorrent;
-    
     NSInteger fMouseRow;
 }
 
-- (void) setTorrent: (Torrent *) torrent;
-- (Torrent *) torrent;
-
 - (NSRect) iconRectForRow: (int) row;
 
 - (NSInteger) hoveredRow;
diff --git a/macosx/FileOutlineView.m b/macosx/FileOutlineView.m
index d4e1e0ab3..044d955e3 100644
--- a/macosx/FileOutlineView.m
+++ b/macosx/FileOutlineView.m
@@ -54,17 +54,6 @@
     [super dealloc];
 }
 
-#warning needed?
-- (void) setTorrent: (Torrent *) torrent
-{
-    fTorrent = torrent;
-}
-
-- (Torrent *) torrent
-{
-    return fTorrent;
-}
-
 - (void) mouseDown: (NSEvent *) event
 {
     [[self window] makeKeyWindow];
diff --git a/macosx/FilePriorityCell.m b/macosx/FilePriorityCell.m
index ba26a7edb..38ee2a5e0 100644
--- a/macosx/FilePriorityCell.m
+++ b/macosx/FilePriorityCell.m
@@ -81,9 +81,10 @@
             break;
     }
     
-    FileOutlineView * controlView = (FileOutlineView *)[self controlView];
-    Torrent * torrent = [controlView torrent];
+    Torrent * torrent = [(FileListNode *)[self representedObject] torrent];
     [torrent setFilePriority: priority forIndexes: [(FileListNode *)[self representedObject] indexes]];
+    
+    FileOutlineView * controlView = (FileOutlineView *)[self controlView];
     [controlView reloadData];
 }
 
@@ -110,8 +111,8 @@
 
 - (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
 {
-    Torrent * torrent = [(FileOutlineView *)controlView torrent];
     FileListNode * node = [self representedObject];
+    Torrent * torrent = [node torrent];
     NSSet * priorities = [torrent filePrioritiesForIndexes: [node indexes]];
     
     const NSUInteger count = [priorities count];
diff --git a/macosx/Torrent.m b/macosx/Torrent.m
index 2fee7961a..92096399e 100644
--- a/macosx/Torrent.m
+++ b/macosx/Torrent.m
@@ -1718,7 +1718,7 @@ int trashDataFile(const char * filename)
                 
                 if (!node)
                 {
-                    node = [[FileListNode alloc] initWithFolderName: name path: path];
+                    node = [[FileListNode alloc] initWithFolderName: name path: path torrent: self];
                     [fileList addObject: node];
                     [node release];
                 }
@@ -1731,7 +1731,7 @@ int trashDataFile(const char * filename)
             }
             else
             {
-                FileListNode * node = [[FileListNode alloc] initWithFileName: name path: path size: file->length index: i];
+                FileListNode * node = [[FileListNode alloc] initWithFileName: name path: path size: file->length index: i torrent: self];
                 [fileList addObject: node];
                 [flatFileList addObject: node];
                 [node release];
@@ -1746,7 +1746,7 @@ int trashDataFile(const char * filename)
     }
     else
     {
-        FileListNode * node = [[FileListNode alloc] initWithFileName: [self name] path: @"" size: [self size] index: 0];
+        FileListNode * node = [[FileListNode alloc] initWithFileName: [self name] path: @"" size: [self size] index: 0 torrent: self];
         fFileList = [[NSArray arrayWithObject: node] retain];
         fFlatFileList = [fFileList retain];
         [node release];
@@ -1772,10 +1772,10 @@ int trashDataFile(const char * filename)
     {
         NSString * path = [[parent path] stringByAppendingPathComponent: [parent name]];
         if (isFolder)
-            node = [[FileListNode alloc] initWithFolderName: name path: path];
+            node = [[FileListNode alloc] initWithFolderName: name path: path torrent: self];
         else
         {
-            node = [[FileListNode alloc] initWithFileName: name path: path size: size index: index];
+            node = [[FileListNode alloc] initWithFileName: name path: path size: size index: index torrent: self];
             [flatFileList addObject: node];
         }
         
-- 
2.40.0