| 1 |
/* $Id$ */ |
|---|
| 2 |
|
|---|
| 3 |
/* |
|---|
| 4 |
* Copyright (c) 2003-2007 Axel Andersson |
|---|
| 5 |
* All rights reserved. |
|---|
| 6 |
* |
|---|
| 7 |
* Redistribution and use in source and binary forms, with or without |
|---|
| 8 |
* modification, are permitted provided that the following conditions |
|---|
| 9 |
* are met: |
|---|
| 10 |
* 1. Redistributions of source code must retain the above copyright |
|---|
| 11 |
* notice, this list of conditions and the following disclaimer. |
|---|
| 12 |
* 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 13 |
* notice, this list of conditions and the following disclaimer in the |
|---|
| 14 |
* documentation and/or other materials provided with the distribution. |
|---|
| 15 |
* |
|---|
| 16 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|---|
| 17 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|---|
| 18 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|---|
| 19 |
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
|---|
| 20 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|---|
| 21 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|---|
| 22 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|---|
| 23 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|---|
| 24 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|---|
| 25 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|---|
| 26 |
* POSSIBILITY OF SUCH DAMAGE. |
|---|
| 27 |
*/ |
|---|
| 28 |
|
|---|
| 29 |
#import "FHCache.h" |
|---|
| 30 |
#import "FHFile.h" |
|---|
| 31 |
#import "FHImage.h" |
|---|
| 32 |
|
|---|
| 33 |
@implementation FHFile |
|---|
| 34 |
|
|---|
| 35 |
+ (id)fileWithURL:(WIURL *)url isDirectory:(BOOL)isDirectory { |
|---|
| 36 |
return [[[self alloc] initWithURL:url isDirectory:isDirectory] autorelease]; |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
+ (id)fileWithURL:(WIURL *)url name:(NSString *)name isDirectory:(BOOL)isDirectory { |
|---|
| 42 |
return [[[self alloc] initWithURL:url name:name isDirectory:isDirectory] autorelease]; |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
- (id)initWithURL:(WIURL *)url isDirectory:(BOOL)isDirectory { |
|---|
| 48 |
return [self initWithURL:url name:NULL isDirectory:isDirectory]; |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
- (id)initWithURL:(WIURL *)url name:(NSString *)name isDirectory:(BOOL)isDirectory { |
|---|
| 54 |
NSImage *icon; |
|---|
| 55 |
|
|---|
| 56 |
self = [super init]; |
|---|
| 57 |
|
|---|
| 58 |
_url = [url retain]; |
|---|
| 59 |
_path = [[_url path] retain]; |
|---|
| 60 |
_name = name ? [name retain] : [[_path lastPathComponent] retain]; |
|---|
| 61 |
_extension = [[[self path] pathExtension] retain]; |
|---|
| 62 |
_directory = isDirectory; |
|---|
| 63 |
|
|---|
| 64 |
if(!_directory) { |
|---|
| 65 |
icon = [[FHCache cache] largeFileIconForExtension:_extension]; |
|---|
| 66 |
|
|---|
| 67 |
_icon = [[FHImage alloc] initImageWithImage:icon]; |
|---|
| 68 |
} else { |
|---|
| 69 |
if(![_url isFileURL]) |
|---|
| 70 |
icon = [[FHCache cache] directoryIcon]; |
|---|
| 71 |
else |
|---|
| 72 |
icon = [[FHCache cache] largeFileIconForURL:url]; |
|---|
| 73 |
|
|---|
| 74 |
_icon = [[FHImage alloc] initImageWithImage:icon]; |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
return self; |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
- (void)dealloc { |
|---|
| 83 |
[_url release]; |
|---|
| 84 |
[_path release]; |
|---|
| 85 |
[_extension release]; |
|---|
| 86 |
[_name release]; |
|---|
| 87 |
[_image release]; |
|---|
| 88 |
[_icon release]; |
|---|
| 89 |
|
|---|
| 90 |
[super dealloc]; |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
#pragma mark - |
|---|
| 96 |
|
|---|
| 97 |
- (NSString *)description { |
|---|
| 98 |
return [self name]; |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
- (NSComparisonResult)compareName:(FHFile *)file { |
|---|
| 104 |
return [[self name] compare:[file name] options:NSCaseInsensitiveSearch | NSNumericSearch]; |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
#pragma mark - |
|---|
| 110 |
|
|---|
| 111 |
- (void)setImage:(FHImage *)image { |
|---|
| 112 |
[image retain]; |
|---|
| 113 |
[_image release]; |
|---|
| 114 |
|
|---|
| 115 |
_image = image; |
|---|
| 116 |
} |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
- (FHImage *)image { |
|---|
| 121 |
return _image; |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
- (void)setThumbnail:(FHImage *)thumbnail { |
|---|
| 127 |
[thumbnail retain]; |
|---|
| 128 |
[_thumbnail release]; |
|---|
| 129 |
|
|---|
| 130 |
_thumbnail = thumbnail; |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
- (FHImage *)thumbnail { |
|---|
| 136 |
return _thumbnail; |
|---|
| 137 |
} |
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
- (void)setData:(NSData *)data { |
|---|
| 142 |
[data retain]; |
|---|
| 143 |
[_data release]; |
|---|
| 144 |
|
|---|
| 145 |
_data = data; |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
- (NSData *)data { |
|---|
| 151 |
return _data; |
|---|
| 152 |
} |
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
- (void)setLoaded:(BOOL)loaded { |
|---|
| 157 |
_loaded = loaded; |
|---|
| 158 |
} |
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
- (BOOL)isLoaded { |
|---|
| 163 |
return _loaded; |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
- (void)setPercentReceived:(double)percentReceived { |
|---|
| 169 |
_percentReceived = percentReceived; |
|---|
| 170 |
} |
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
- (double)percentReceived { |
|---|
| 175 |
return _percentReceived; |
|---|
| 176 |
} |
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
#pragma mark - |
|---|
| 181 |
|
|---|
| 182 |
- (NSString *)name { |
|---|
| 183 |
return _name; |
|---|
| 184 |
} |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
- (WIURL *)URL { |
|---|
| 189 |
return _url; |
|---|
| 190 |
} |
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
- (NSString *)path { |
|---|
| 195 |
return _path; |
|---|
| 196 |
} |
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
- (NSString *)extension { |
|---|
| 201 |
return _extension; |
|---|
| 202 |
} |
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
- (FHImage *)icon { |
|---|
| 207 |
return _icon; |
|---|
| 208 |
} |
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
- (BOOL)isDirectory { |
|---|
| 213 |
return _directory; |
|---|
| 214 |
} |
|---|
| 215 |
|
|---|
| 216 |
@end |
|---|