2008-05-22 18:39:49 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2011-01-01 20:42:14 +00:00
|
|
|
* Copyright (c) 2008-2011 Transmission authors and contributors
|
2008-05-22 18:39:49 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#import "FileListNode.h"
|
|
|
|
|
|
|
|
@interface FileListNode (Private)
|
|
|
|
|
2011-05-31 22:26:04 +00:00
|
|
|
- (id) initWithFolder: (BOOL) isFolder name: (NSString *) name path: (NSString *) path torrent: (Torrent *) torrent;
|
2008-05-22 18:39:49 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation FileListNode
|
|
|
|
|
2011-05-31 22:26:04 +00:00
|
|
|
- (id) initWithFolderName: (NSString *) name path: (NSString *) path torrent: (Torrent *) torrent
|
2008-05-22 18:39:49 +00:00
|
|
|
{
|
2011-05-31 22:26:04 +00:00
|
|
|
if ((self = [self initWithFolder: YES name: name path: path torrent: torrent]))
|
2008-05-22 18:39:49 +00:00
|
|
|
{
|
|
|
|
fChildren = [[NSMutableArray alloc] init];
|
2008-05-22 21:06:56 +00:00
|
|
|
fSize = 0;
|
2008-05-22 18:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2011-05-31 22:26:04 +00:00
|
|
|
- (id) initWithFileName: (NSString *) name path: (NSString *) path size: (uint64_t) size index: (NSUInteger) index torrent: (Torrent *) torrent
|
2008-05-22 18:39:49 +00:00
|
|
|
{
|
2011-05-31 22:26:04 +00:00
|
|
|
if ((self = [self initWithFolder: NO name: name path: path torrent: torrent]))
|
2008-05-22 18:39:49 +00:00
|
|
|
{
|
|
|
|
fSize = size;
|
|
|
|
[fIndexes addIndex: index];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) insertChild: (FileListNode *) child
|
|
|
|
{
|
2008-05-23 22:58:17 +00:00
|
|
|
NSAssert(fIsFolder, @"method can only be invoked on folders");
|
2008-05-22 21:06:56 +00:00
|
|
|
|
2008-05-22 18:39:49 +00:00
|
|
|
[fChildren addObject: child];
|
|
|
|
}
|
|
|
|
|
2008-05-22 21:06:56 +00:00
|
|
|
- (void) insertIndex: (NSUInteger) index withSize: (uint64_t) size
|
2008-05-22 18:39:49 +00:00
|
|
|
{
|
2008-05-23 22:58:17 +00:00
|
|
|
NSAssert(fIsFolder, @"method can only be invoked on folders");
|
2008-05-22 21:06:56 +00:00
|
|
|
|
2008-05-22 18:39:49 +00:00
|
|
|
[fIndexes addIndex: index];
|
2008-05-22 21:06:56 +00:00
|
|
|
fSize += size;
|
2008-05-22 18:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) copyWithZone: (NSZone *) zone
|
|
|
|
{
|
2008-05-22 21:06:56 +00:00
|
|
|
//this object is essentially immutable after initial setup
|
2008-05-22 18:39:49 +00:00
|
|
|
return [self retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[fName release];
|
|
|
|
[fPath release];
|
|
|
|
[fIndexes release];
|
|
|
|
|
|
|
|
[fIcon release];
|
|
|
|
|
|
|
|
[fChildren release];
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2011-05-21 18:29:35 +00:00
|
|
|
- (NSString *) description
|
|
|
|
{
|
|
|
|
if (!fIsFolder)
|
|
|
|
return [NSString stringWithFormat: @"%@ (%d)", fName, [fIndexes firstIndex]];
|
|
|
|
else
|
|
|
|
return [NSString stringWithFormat: @"%@ (folder: %@)", fName, fIndexes];
|
|
|
|
}
|
|
|
|
|
2008-05-22 18:39:49 +00:00
|
|
|
- (BOOL) isFolder
|
|
|
|
{
|
|
|
|
return fIsFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) name
|
|
|
|
{
|
|
|
|
return fName;
|
|
|
|
}
|
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
- (NSString *) path
|
2008-05-22 18:39:49 +00:00
|
|
|
{
|
|
|
|
return fPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSIndexSet *) indexes
|
|
|
|
{
|
|
|
|
return fIndexes;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (uint64_t) size
|
|
|
|
{
|
|
|
|
return fSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSImage *) icon
|
|
|
|
{
|
2009-12-27 19:30:20 +00:00
|
|
|
if (!fIcon)
|
|
|
|
fIcon = [[[NSWorkspace sharedWorkspace] iconForFileType: fIsFolder ? NSFileTypeForHFSTypeCode('fldr')
|
|
|
|
: [fName pathExtension]] retain];
|
2008-05-22 18:39:49 +00:00
|
|
|
return fIcon;
|
|
|
|
}
|
|
|
|
|
2010-10-23 20:20:31 +00:00
|
|
|
- (NSMutableArray *) children
|
2008-05-22 18:39:49 +00:00
|
|
|
{
|
2009-10-19 01:38:13 +00:00
|
|
|
NSAssert(fIsFolder, @"method can only be invoked on folders");
|
|
|
|
|
2008-05-22 18:39:49 +00:00
|
|
|
return fChildren;
|
|
|
|
}
|
|
|
|
|
2011-05-31 22:26:04 +00:00
|
|
|
- (Torrent *) torrent
|
|
|
|
{
|
|
|
|
return fTorrent;
|
|
|
|
}
|
|
|
|
|
2008-05-22 18:39:49 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation FileListNode (Private)
|
|
|
|
|
2011-05-31 22:26:04 +00:00
|
|
|
- (id) initWithFolder: (BOOL) isFolder name: (NSString *) name path: (NSString *) path torrent: (Torrent *) torrent
|
2008-05-22 18:39:49 +00:00
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
fIsFolder = isFolder;
|
|
|
|
fName = [name retain];
|
2009-10-21 13:01:14 +00:00
|
|
|
fPath = [path retain];
|
2008-05-22 18:39:49 +00:00
|
|
|
|
|
|
|
fIndexes = [[NSMutableIndexSet alloc] init];
|
2011-05-31 22:26:04 +00:00
|
|
|
|
|
|
|
fTorrent = torrent;
|
2008-05-22 18:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|