1 | /****************************************************************************** |
---|
2 | * $Id: FileListNode.m 5926 2008-05-23 22:58:17Z livings124 $ |
---|
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 | fSize = 0; |
---|
41 | } |
---|
42 | |
---|
43 | return self; |
---|
44 | } |
---|
45 | |
---|
46 | - (id) initWithFileName: (NSString *) name path: (NSString *) path size: (uint64_t) size index: (int) index |
---|
47 | { |
---|
48 | if ((self = [self initWithFolder: NO name: name path: path])) |
---|
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 | - (BOOL) isFolder |
---|
92 | { |
---|
93 | return fIsFolder; |
---|
94 | } |
---|
95 | |
---|
96 | - (NSString *) name |
---|
97 | { |
---|
98 | return fName; |
---|
99 | } |
---|
100 | |
---|
101 | - (NSString *) fullPath |
---|
102 | { |
---|
103 | return fPath; |
---|
104 | } |
---|
105 | |
---|
106 | - (NSIndexSet *) indexes |
---|
107 | { |
---|
108 | return fIndexes; |
---|
109 | } |
---|
110 | |
---|
111 | - (uint64_t) size |
---|
112 | { |
---|
113 | return fSize; |
---|
114 | } |
---|
115 | |
---|
116 | - (NSImage *) icon |
---|
117 | { |
---|
118 | if (!fIsFolder && !fIcon) |
---|
119 | { |
---|
120 | fIcon = [[[NSWorkspace sharedWorkspace] iconForFileType: [fName pathExtension]] retain]; |
---|
121 | [fIcon setFlipped: YES]; |
---|
122 | } |
---|
123 | return fIcon; |
---|
124 | } |
---|
125 | |
---|
126 | - (NSArray *) children |
---|
127 | { |
---|
128 | return fChildren; |
---|
129 | } |
---|
130 | |
---|
131 | @end |
---|
132 | |
---|
133 | @implementation FileListNode (Private) |
---|
134 | |
---|
135 | - (id) initWithFolder: (BOOL) isFolder name: (NSString *) name path: (NSString *) path |
---|
136 | { |
---|
137 | if ((self = [super init])) |
---|
138 | { |
---|
139 | fIsFolder = isFolder; |
---|
140 | fName = [name retain]; |
---|
141 | fPath = [[path stringByAppendingPathComponent: name] retain]; |
---|
142 | |
---|
143 | fIndexes = [[NSMutableIndexSet alloc] init]; |
---|
144 | } |
---|
145 | |
---|
146 | return self; |
---|
147 | } |
---|
148 | |
---|
149 | @end |
---|