1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-04 10:38:13 +00:00

have FileListNodes store their corresponding torrents, allowing the removal of this functionality from the file outline view

This commit is contained in:
Mitchell Livingston 2011-05-31 22:26:04 +00:00
parent 764f513c4e
commit 27fa4091dc
8 changed files with 32 additions and 35 deletions

View file

@ -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

View file

@ -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;

View file

@ -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];

View file

@ -84,7 +84,6 @@ typedef enum
- (void) setTorrent: (Torrent *) torrent
{
fTorrent = torrent;
[fOutline setTorrent: fTorrent];
[fFileList release];
fFileList = [[fTorrent fileList] retain];

View file

@ -28,14 +28,9 @@
@interface FileOutlineView : NSOutlineView
{
Torrent * fTorrent;
NSInteger fMouseRow;
}
- (void) setTorrent: (Torrent *) torrent;
- (Torrent *) torrent;
- (NSRect) iconRectForRow: (int) row;
- (NSInteger) hoveredRow;

View file

@ -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];

View file

@ -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];

View file

@ -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];
}