Show
Ignore:
Timestamp:
04/26/07 13:11:32 (2 years ago)
Author:
morris
Message:

Add a progress indicator for asynchronously loading files off the net

Extract thumbnail data from loaded files off the net

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Footagehead/trunk/FHCache.m

    r4723 r4725  
    7979#pragma mark - 
    8080 
    81 - (void)setFileIcon:(NSImage *)icon forURL:(WIURL *)url { 
    82         if([_fileIcons count] > 1000) 
    83                 [_fileIcons removeObjectForKey:[[_fileIcons allKeys] objectAtIndex:0]]; 
    84          
    85         [_fileIcons setObject:icon forKey:[url string]]; 
    86 } 
    87  
    88  
    89  
    9081- (NSImage *)fileIconForURL:(WIURL *)url { 
    91         return [_fileIcons objectForKey:[url string]]; 
     82        NSImage         *image; 
     83        WIURL           *faviconURL; 
     84         
     85        image = [_fileIcons objectForKey:[url string]]; 
     86         
     87        if(!image) { 
     88                if([url isFileURL]) { 
     89                        image = [[NSWorkspace sharedWorkspace] iconForFile:[url path]]; 
     90                } else { 
     91                        faviconURL = [[url copy] autorelease]; 
     92                        [faviconURL setPath:@"/favicon.ico"]; 
     93                         
     94                        image = [[[NSImage alloc] initWithContentsOfURL:[faviconURL URL]] autorelease]; 
     95                         
     96                        if(!image) 
     97                                image = [NSImage imageNamed:@"URL"]; 
     98                } 
     99                 
     100                if(image) { 
     101                        if([_fileIcons count] > 1000) 
     102                                [_fileIcons removeObjectForKey:[[_fileIcons allKeys] objectAtIndex:0]]; 
     103                         
     104                        [_fileIcons setObject:image forKey:[url string]]; 
     105                } 
     106        } 
     107                 
     108        return image; 
     109
     110 
     111 
     112 
     113- (NSImage *)largeFileIconForExtension:(NSString *)extension { 
     114        NSImage         *image; 
     115         
     116        image = [_largeFileIcons objectForKey:extension]; 
     117                 
     118        if(!image) { 
     119                image = [[NSWorkspace sharedWorkspace] iconForFileType:extension]; 
     120                 
     121                if(image) { 
     122                        [image setSize:NSMakeSize(128.0, 128.0)]; 
     123                 
     124                        if([_largeFileIcons count] > 1000) 
     125                                [_largeFileIcons removeObjectForKey:[[_largeFileIcons allKeys] objectAtIndex:0]]; 
     126                         
     127                        [_largeFileIcons setObject:image forKey:extension]; 
     128                } 
     129        } 
     130         
     131        return image; 
     132
     133 
     134 
     135 
     136- (NSImage *)largeFileIconForURL:(WIURL *)url { 
     137        NSImage         *image; 
     138         
     139        image = [_largeFileIcons objectForKey:[url string]]; 
     140                         
     141        if(!image) { 
     142                image = [[NSWorkspace sharedWorkspace] iconForFile:[url path]]; 
     143                 
     144                if(image) { 
     145                        [image setSize:NSMakeSize(128.0, 128.0)]; 
     146                 
     147                        if([_largeFileIcons count] > 1000) 
     148                                [_largeFileIcons removeObjectForKey:[[_largeFileIcons allKeys] objectAtIndex:0]]; 
     149                         
     150                        [_largeFileIcons setObject:image forKey:[url string]]; 
     151                } 
     152        } 
     153         
     154        return image; 
    92155} 
    93156 
     
    96159#pragma mark - 
    97160 
    98 - (void)setLargeFileIcon:(NSImage *)icon forExtension:(NSString *)extension { 
    99         if([_largeFileIcons count] > 1000) 
    100                 [_largeFileIcons removeObjectForKey:[[_largeFileIcons allKeys] objectAtIndex:0]]; 
    101          
    102         [_largeFileIcons setObject:icon forKey:extension]; 
    103 } 
    104  
    105  
    106  
    107 - (NSImage *)largeFileIconForExtension:(NSString *)extension { 
    108         return [_largeFileIcons objectForKey:extension]; 
    109 } 
    110  
    111  
    112  
    113 #pragma mark - 
    114  
    115 - (void)setLargeFileIcon:(NSImage *)icon forURL:(WIURL *)url { 
    116         if([_largeFileIcons count] > 1000) 
    117                 [_largeFileIcons removeObjectForKey:[[_largeFileIcons allKeys] objectAtIndex:0]]; 
    118          
    119         [_largeFileIcons setObject:icon forKey:[url string]]; 
    120 } 
    121  
    122  
    123  
    124 - (NSImage *)largeFileIconForURL:(WIURL *)url { 
    125         return [_largeFileIcons objectForKey:[url string]]; 
    126 } 
    127  
    128  
    129  
    130 #pragma mark - 
    131  
    132 - (void)setThumbnail:(FHImage *)image forURL:(WIURL *)url { 
    133         if([_thumbnails count] > 500) 
    134                 [_thumbnails removeObjectForKey:[[_thumbnails allKeys] objectAtIndex:0]]; 
    135          
    136         [_thumbnails setObject:image forKey:[url string]]; 
    137 } 
    138  
    139  
    140  
    141161- (FHImage *)thumbnailForURL:(WIURL *)url { 
    142         return [_thumbnails objectForKey:[url string]]; 
     162        return [self thumbnailForURL:url withData:NULL]; 
     163
     164 
     165 
     166 
     167- (FHImage *)thumbnailForURL:(WIURL *)url withData:(NSData *)data { 
     168        FHImage         *image; 
     169         
     170        image = [_thumbnails objectForKey:[url string]]; 
     171 
     172        if(!image) { 
     173                if(data) 
     174                        image = [[[FHImage alloc] initThumbnailWithData:data preferredSize:NSMakeSize(128.0, 128.0)] autorelease]; 
     175                else 
     176                        image = [[[FHImage alloc] initThumbnailWithURL:url preferredSize:NSMakeSize(128.0, 128.0)] autorelease]; 
     177                         
     178                if(image) { 
     179                        if([_thumbnails count] > 500) 
     180                                [_thumbnails removeObjectForKey:[[_thumbnails allKeys] objectAtIndex:0]]; 
     181                         
     182                        [_thumbnails setObject:image forKey:[url string]]; 
     183                } 
     184        } 
     185         
     186        return image; 
    143187} 
    144188