source: trunk/macosx/FileListNode.m @ 5905

Last change on this file since 5905 was 5905, checked in by livings124, 14 years ago

move new files into the macosx directory

File size: 3.4 KB
Line 
1/******************************************************************************
2 * $Id$
3 *
4 * Copyright (c) 2008 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;
30
31@end
32
33@implementation FileListNode
34
35- (id) initWithFolderName: (NSString *) name path: (NSString *) path
36{
37    if ((self = [self initWithFolder: YES name: name path: path]))
38    {
39        fChildren = [[NSMutableArray alloc] init];
40    }
41   
42    return self;
43}
44
45- (id) initWithFileName: (NSString *) name path: (NSString *) path size: (uint64_t) size index: (int) index
46{
47    if ((self = [self initWithFolder: NO name: name path: path]))
48    {
49        fSize = size;
50        [fIndexes addIndex: index];
51    }
52   
53    return self;
54}
55
56- (void) insertChild: (FileListNode *) child
57{
58    [fChildren addObject: child];
59}
60
61- (void) insertIndex: (NSUInteger) index
62{
63    [fIndexes addIndex: index];
64}
65
66- (id) copyWithZone: (NSZone *) zone
67{
68    return [self retain];
69}
70
71- (void) dealloc
72{
73    [fName release];
74    [fPath release];
75    [fIndexes release];
76   
77    [fIcon release];
78   
79    [fChildren release];
80   
81    [super dealloc];
82}
83
84- (BOOL) isFolder
85{
86    return fIsFolder;
87}
88
89- (NSString *) name
90{
91    return fName;
92}
93
94- (NSString *) fullPath
95{
96    return fPath;
97}
98
99- (NSIndexSet *) indexes
100{
101    return fIndexes;
102}
103
104- (uint64_t) size
105{
106    NSAssert(!fIsFolder, @"method can only be invoked on files currently");
107   
108    return fSize;
109}
110
111- (NSImage *) icon
112{
113    NSAssert(!fIsFolder, @"method can only be invoked on files currently");
114   
115    if (!fIcon)
116    {
117        fIcon = [[[NSWorkspace sharedWorkspace] iconForFileType: [fName pathExtension]] retain];
118        [fIcon setFlipped: YES];
119    }
120    return fIcon;
121}
122
123- (NSArray *) children
124{
125    NSAssert(fIsFolder, @"method can only be invoked on folders");
126   
127    return fChildren;
128}
129
130@end
131
132@implementation FileListNode (Private)
133
134- (id) initWithFolder: (BOOL) isFolder name: (NSString *) name path: (NSString *) path
135{
136    if ((self = [super init]))
137    {
138        fIsFolder = isFolder;
139        fName = [name retain];
140        fPath = [[path stringByAppendingPathComponent: name] retain];
141       
142        fIndexes = [[NSMutableIndexSet alloc] init];
143    }
144   
145    return self;
146}
147
148@end
Note: See TracBrowser for help on using the repository browser.