source: trunk/macosx/FileListNode.m @ 12483

Last change on this file since 12483 was 12483, checked in by livings124, 11 years ago

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

  • Property svn:keywords set to Date Rev Author Id
File size: 4.0 KB
Line 
1/******************************************************************************
2 * $Id: FileListNode.m 12483 2011-05-31 22:26:04Z livings124 $
3 *
4 * Copyright (c) 2008-2011 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#import "FileListNode.h"
26
27@interface FileListNode (Private)
28
29- (id) initWithFolder: (BOOL) isFolder name: (NSString *) name path: (NSString *) path torrent: (Torrent *) torrent;
30
31@end
32
33@implementation FileListNode
34
35- (id) initWithFolderName: (NSString *) name path: (NSString *) path torrent: (Torrent *) torrent
36{
37    if ((self = [self initWithFolder: YES name: name path: path torrent: torrent]))
38    {
39        fChildren = [[NSMutableArray alloc] init];
40        fSize = 0;
41    }
42   
43    return self;
44}
45
46- (id) initWithFileName: (NSString *) name path: (NSString *) path size: (uint64_t) size index: (NSUInteger) index torrent: (Torrent *) torrent
47{
48    if ((self = [self initWithFolder: NO name: name path: path torrent: torrent]))
49    {
50        fSize = size;
51        [fIndexes addIndex: index];
52    }
53   
54    return self;
55}
56
57- (void) insertChild: (FileListNode *) child
58{
59    NSAssert(fIsFolder, @"method can only be invoked on folders");
60   
61    [fChildren addObject: child];
62}
63
64- (void) insertIndex: (NSUInteger) index withSize: (uint64_t) size
65{
66    NSAssert(fIsFolder, @"method can only be invoked on folders");
67   
68    [fIndexes addIndex: index];
69    fSize += size;
70}
71
72- (id) copyWithZone: (NSZone *) zone
73{
74    //this object is essentially immutable after initial setup
75    return [self retain];
76}
77
78- (void) dealloc
79{
80    [fName release];
81    [fPath release];
82    [fIndexes release];
83   
84    [fIcon release];
85   
86    [fChildren release];
87   
88    [super dealloc];
89}
90
91- (NSString *) description
92{
93    if (!fIsFolder)
94        return [NSString stringWithFormat: @"%@ (%d)", fName, [fIndexes firstIndex]];
95    else
96        return [NSString stringWithFormat: @"%@ (folder: %@)", fName, fIndexes];
97}
98
99- (BOOL) isFolder
100{
101    return fIsFolder;
102}
103
104- (NSString *) name
105{
106    return fName;
107}
108
109- (NSString *) path
110{
111    return fPath;
112}
113
114- (NSIndexSet *) indexes
115{
116    return fIndexes;
117}
118
119- (uint64_t) size
120{
121    return fSize;
122}
123
124- (NSImage *) icon
125{
126    if (!fIcon)
127        fIcon = [[[NSWorkspace sharedWorkspace] iconForFileType: fIsFolder ? NSFileTypeForHFSTypeCode('fldr')
128                                                                            : [fName pathExtension]] retain];
129    return fIcon;
130}
131
132- (NSMutableArray *) children
133{
134    NSAssert(fIsFolder, @"method can only be invoked on folders");
135   
136    return fChildren;
137}
138
139- (Torrent *) torrent
140{
141    return fTorrent;
142}
143
144@end
145
146@implementation FileListNode (Private)
147
148- (id) initWithFolder: (BOOL) isFolder name: (NSString *) name path: (NSString *) path torrent: (Torrent *) torrent
149{
150    if ((self = [super init]))
151    {
152        fIsFolder = isFolder;
153        fName = [name retain];
154        fPath = [path retain];
155       
156        fIndexes = [[NSMutableIndexSet alloc] init];
157       
158        fTorrent = torrent;
159    }
160   
161    return self;
162}
163
164@end
Note: See TracBrowser for help on using the repository browser.