Changeset 4868

Show
Ignore:
Timestamp:
08/21/07 17:38:21 (1 year ago)
Author:
morris
Message:

Add support for saving a directory full of images to somewhere

Update the status bar when we delete an image to reflect correct count

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Footagehead/trunk/English.lproj/Browser.nib/classes.nib

    r4725 r4868  
    22    IBClasses = ( 
    33        { 
    4             ACTIONS = { 
    5                 autoSwitch = id;  
    6                 firstFile = id;  
    7                 lastFile = id;  
    8                 nextImage = id;  
    9                 nextPage = id;  
    10                 openDirectory = id;  
    11                 openFile = id;  
    12                 openParent = id;  
    13                 previousImage = id;  
    14                 previousPage = id;  
    15             };  
     4            ACTIONS = {autoSwitch = id; };  
    165            CLASS = FHBrowserController;  
    176            LANGUAGE = ObjC;  
     
    2817                "_rightStatusTextField" = NSTextField;  
    2918                "_rightView" = NSView;  
     19                "_saveProgressIndicator" = NSProgressIndicator;  
     20                "_saveProgressPanel" = NSPanel;  
     21                "_saveProgressTextField" = NSTextField;  
    3022                "_screenAutoSwitchButton" = NSButton;  
    3123                "_screenAutoSwitchTextField" = NSTextField;  
  • Footagehead/trunk/English.lproj/Browser.nib/info.nib

    r4727 r4868  
    44<dict> 
    55        <key>IBDocumentLocation</key> 
    6         <string>1075 123 403 407 0 0 1920 1178 </string> 
     6        <string>816 72 403 407 0 0 1920 1178 </string> 
    77        <key>IBFramework Version</key> 
    88        <string>446.1</string> 
    99        <key>IBOpenObjects</key> 
    1010        <array> 
     11                <integer>7</integer> 
    1112                <integer>65</integer> 
    1213                <integer>52</integer> 
    13                 <integer>7</integer> 
     14                <integer>160</integer> 
    1415                <integer>82</integer> 
    1516        </array> 
    1617        <key>IBSystem Version</key> 
    17         <string>8P135</string> 
     18        <string>8R218</string> 
    1819</dict> 
    1920</plist> 
  • Footagehead/trunk/English.lproj/MainMenu.nib/info.nib

    r4733 r4868  
    88        <dict> 
    99                <key>29</key> 
    10                 <string>433 614 400 44 0 0 1280 778 </string> 
     10                <string>748 949 400 44 0 0 1920 1178 </string> 
    1111        </dict> 
    1212        <key>IBFramework Version</key> 
     
    1919        </array> 
    2020        <key>IBSystem Version</key> 
    21         <string>8P2137</string> 
     21        <string>8R218</string> 
    2222</dict> 
    2323</plist> 
  • Footagehead/trunk/FHBrowserController.h

    r4726 r4868  
    5151        IBOutlet NSPanel                                *_openSpotlightPanel; 
    5252        IBOutlet NSTextView                             *_openSpotlightTextView; 
     53         
     54        IBOutlet NSPanel                                *_saveProgressPanel; 
     55        IBOutlet NSProgressIndicator    *_saveProgressIndicator; 
     56        IBOutlet NSTextField                    *_saveProgressTextField; 
    5357 
    5458        IBOutlet NSPanel                                *_screenPanel; 
     
    6973        BOOL                                                    _switchingURL; 
    7074        NSInteger                                               _previousRow; 
     75        NSUInteger                                              _savedFiles; 
    7176} 
    7277 
     
    7479#define FHBrowserControllerDidLoadHandler       @"FHBrowserControllerDidLoadHandler" 
    7580 
    76  
    77 - (IBAction)openParent:(id)sender; 
    78 - (IBAction)openFile:(id)sender; 
    79 - (IBAction)openDirectory:(id)sender; 
    8081 
    8182- (IBAction)autoSwitch:(id)sender; 
  • Footagehead/trunk/FHBrowserController.m

    r4858 r4868  
    429429        imageLoader = [[FHImageLoader alloc] init]; 
    430430        [self setImageLoader:imageLoader]; 
    431          
     431 
     432        [[_imageLoader notificationCenter] 
     433                addObserver:self 
     434                   selector:@selector(imageLoaderWillLoadFile:) 
     435                           name:FHImageLoaderWillLoadFile]; 
     436         
     437        [[_imageLoader notificationCenter] 
     438                addObserver:self 
     439                   selector:@selector(imageLoaderReceivedFileData:) 
     440                           name:FHImageLoaderReceivedFileData]; 
     441 
    432442        [[_imageLoader notificationCenter] 
    433443                addObserver:self 
    434444                   selector:@selector(imageLoaderDidLoadThumbnail:) 
    435445                           name:FHImageLoaderDidLoadThumbnail]; 
     446         
     447        [[_imageLoader notificationCenter] 
     448                addObserver:self 
     449                   selector:@selector(imageLoaderDidLoadAllFiles:) 
     450                           name:FHImageLoaderDidLoadAllFiles]; 
    436451 
    437452        [imageLoader release]; 
     
    447462        [_handler release]; 
    448463         
    449         [_imageLoader stopLoading]; 
     464        [_imageLoader stopLoadingImagesAndThumbnails]; 
    450465         
    451466        [_toolbarItems release]; 
     
    604619 
    605620 
     621- (void)imageLoaderWillLoadFile:(NSNotification *)notification { 
     622        FHFile  *file; 
     623         
     624        file = [notification object]; 
     625         
     626        _savedFiles++; 
     627         
     628        [_saveProgressIndicator setIndeterminate:YES]; 
     629        [_saveProgressTextField setStringValue:[NSSWF:NSLS(@"%@, %u/%u%C", @"Save status (name, this file, remaining files, '...'"), 
     630                [file name], _savedFiles, [_handler numberOfFiles], 0x2026]]; 
     631} 
     632 
     633 
     634 
     635- (void)imageLoaderReceivedFileData:(NSNotification *)notification { 
     636        FHFile  *file; 
     637         
     638        file = [notification object]; 
     639         
     640        [_saveProgressIndicator setIndeterminate:NO]; 
     641        [_saveProgressIndicator setDoubleValue:[file percentReceived]]; 
     642        [_saveProgressIndicator animate:self]; 
     643} 
     644 
     645 
     646 
    606647- (void)imageLoaderDidLoadThumbnail:(NSNotification *)notification { 
    607648        [_tableView reloadData]; 
     649} 
     650 
     651 
     652 
     653- (void)imageLoaderDidLoadAllFiles:(NSNotification *)notification { 
     654        [NSApp endSheet:_saveProgressPanel returnCode:NSAlertDefaultReturn]; 
    608655} 
    609656 
     
    852899 
    853900 
    854 - (IBAction)openURL:(id)sender { 
     901- (void)openURL:(id)sender { 
    855902        [_openURLTextView setSelectedRange:NSMakeRange(0, [[_openURLTextView string] length])]; 
    856903 
     
    903950 
    904951 
    905 #pragma mark - 
    906  
    907 - (IBAction)openParent:(id)sender { 
    908         NSString        *name; 
    909         WIURL           *url; 
    910          
    911         if([_handler hasParent]) { 
    912                 url = [_handler parentURL]; 
    913                  
    914                 if(![url isEqual:[_handler URL]]) { 
    915                         name = [[[_handler URL] path] lastPathComponent]; 
     952- (void)saveDocument:(id)sender { 
     953        NSOpenPanel             *openPanel; 
     954        NSString                *path; 
     955         
     956        openPanel = [NSOpenPanel openPanel]; 
     957        [openPanel setTitle:NSLS(@"Select Directory", @"Save panel title")]; 
     958        [openPanel setPrompt:NSLS(@"Select", @"Save panel button")]; 
     959        [openPanel setCanChooseFiles:NO]; 
     960        [openPanel setCanChooseDirectories:YES]; 
     961        [openPanel setCanCreateDirectories:YES]; 
     962         
     963        if([openPanel runModalForTypes:nil] == NSFileHandlingPanelOKButton) { 
     964                path = [openPanel filename]; 
     965                 
     966                [_imageLoader stopLoadingImagesAndThumbnails]; 
     967                [_imageLoader startLoadingData]; 
     968 
     969                [_saveProgressIndicator setDoubleValue:0.0]; 
     970                [_saveProgressTextField setStringValue:@""]; 
     971                 
     972                _savedFiles = 0; 
     973                 
     974                [NSApp beginSheet:_saveProgressPanel 
     975                   modalForWindow:[self window] 
     976                        modalDelegate:self 
     977                   didEndSelector:@selector(saveProgressPanelDidEnd:returnCode:contextInfo:) 
     978                          contextInfo:[path retain]]; 
     979        } 
     980
     981 
     982 
     983 
     984- (void)saveProgressPanelDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo { 
     985        NSArray                 *files; 
     986        NSString                *path = contextInfo; 
     987        FHFile                  *file; 
     988        NSUInteger              i, count; 
     989         
     990        [_saveProgressPanel close]; 
     991         
     992        if(returnCode == NSAlertDefaultReturn) { 
     993                files = [[self imageLoader] files]; 
     994                count = [files count]; 
     995                 
     996                for(i = 0; i < count; i++) { 
     997                        file = [files objectAtIndex:i]; 
    916998                         
    917                         [self _loadURL:url selectName:name]; 
     999                        if([file data]) { 
     1000                                [[file data] writeToFile:[path stringByAppendingPathComponent:[[file path] lastPathComponent]] 
     1001                                                          atomically:YES]; 
     1002                                 
     1003                                [file setData:NULL]; 
     1004                        } 
    9181005                } 
    919         } 
    920 
    921  
    922  
    923  
    924 - (IBAction)openFile:(id)sender { 
    925         FHFile  *file; 
    926          
    927         file = [self selectedFile]; 
    928          
    929         if([file isDirectory]) 
    930                 [self _loadURL:[file URL]]; 
    931         else 
    932                 [[NSWorkspace sharedWorkspace] openURL:[[file URL] URL]]; 
    933 
    934  
    935  
    936  
    937 - (IBAction)openDirectory:(id)sender { 
    938         FHFile  *file; 
    939          
    940         file = [self selectedFile]; 
    941          
    942         if([file isDirectory]) 
    943                 [self _loadURL:[file URL]]; 
     1006        } else { 
     1007                [_imageLoader stopLoadingData]; 
     1008        } 
     1009 
     1010        [_imageLoader startLoadingImages]; 
     1011        [_imageLoader startLoadingThumbnails]; 
     1012         
     1013        [path release]; 
    9441014} 
    9451015 
     
    10021072 
    10031073                [self showFile:[self selectedFile]]; 
     1074                 
     1075                [self _updateLeftStatus]; 
    10041076        } 
    10051077} 
     
    10961168#pragma mark - 
    10971169 
     1170- (void)openParent:(id)sender { 
     1171        NSString        *name; 
     1172        WIURL           *url; 
     1173         
     1174        if([_handler hasParent]) { 
     1175                url = [_handler parentURL]; 
     1176                 
     1177                if(![url isEqual:[_handler URL]]) { 
     1178                        name = [[[_handler URL] path] lastPathComponent]; 
     1179                         
     1180                        [self _loadURL:url selectName:name]; 
     1181                } 
     1182        } 
     1183} 
     1184 
     1185 
     1186 
     1187- (void)openFile:(id)sender { 
     1188        FHFile  *file; 
     1189         
     1190        file = [self selectedFile]; 
     1191         
     1192        if([file isDirectory]) 
     1193                [self _loadURL:[file URL]]; 
     1194        else 
     1195                [[NSWorkspace sharedWorkspace] openURL:[[file URL] URL]]; 
     1196} 
     1197 
     1198 
     1199 
     1200- (void)openDirectory:(id)sender { 
     1201        FHFile  *file; 
     1202         
     1203        file = [self selectedFile]; 
     1204         
     1205        if([file isDirectory]) 
     1206                [self _loadURL:[file URL]]; 
     1207} 
     1208 
     1209 
     1210 
     1211#pragma mark - 
     1212 
    10981213- (void)loadURL:(WIURL *)url { 
    10991214        NSString        *name; 
  • Footagehead/trunk/FHFile.h

    r4726 r4868  
    3737        FHImage                                 *_icon; 
    3838        FHImage                                 *_thumbnail; 
     39        NSData                                  *_data; 
    3940        BOOL                                    _loaded; 
    4041        double                                  _percentReceived; 
     
    5354- (void)setThumbnail:(FHImage *)thumbnail; 
    5455- (FHImage *)thumbnail; 
     56- (void)setData:(NSData *)data; 
     57- (NSData *)data; 
    5558- (void)setLoaded:(BOOL)loaded; 
    5659- (BOOL)isLoaded; 
  • Footagehead/trunk/FHFile.m

    r4726 r4868  
    125125 
    126126 
     127- (void)setData:(NSData *)data { 
     128        [data retain]; 
     129        [_data release]; 
     130         
     131        _data = data; 
     132} 
     133 
     134 
     135 
     136- (NSData *)data { 
     137        return _data; 
     138} 
     139 
     140 
     141 
    127142- (void)setLoaded:(BOOL)loaded { 
    128143        _loaded = loaded; 
  • Footagehead/trunk/FHImageLoader.h

    r4726 r4868  
    3434        NSConditionLock                 *_imageLock; 
    3535        NSConditionLock                 *_thumbnailLock; 
     36        NSConditionLock                 *_dataLock; 
    3637 
    3738        NSUInteger                              _imageCounter; 
    3839        NSUInteger                              _thumbnailCounter; 
    39          
    40         NSMutableData                   *_asynchronousData; 
    41         FHFile                                  *_asynchronousFile; 
    42         long long                               _asynchronousLength; 
    43         BOOL                                    _asynchronousDone; 
     40        NSUInteger                              _dataCounter; 
    4441         
    4542        BOOL                                    _imageStop; 
    4643        BOOL                                    _thumbnailStop; 
     44        BOOL                                    _dataStop; 
     45         
     46        NSLock                                  *_asynchronousLock; 
     47        NSMutableData                   *_asynchronousData; 
     48        FHFile                                  *_asynchronousFile; 
     49        NSMutableURLRequest             *_asynchronousRequest; 
     50        long long                               _asynchronousLength; 
     51        BOOL                                    _asynchronousImages; 
     52        BOOL                                    _asynchronousDone; 
    4753         
    4854        NSArray                                 *_files; 
     
    5359 
    5460 
     61#define FHImageLoaderWillLoadImage                                      @"FHImageLoaderWillLoadImage" 
     62#define FHImageLoaderWillLoadFile                                       @"FHImageLoaderWillLoadFile" 
     63 
    5564#define FHImageLoaderReceivedImageData                          @"FHImageLoaderReceivedImageData" 
     65#define FHImageLoaderReceivedFileData                           @"FHImageLoaderReceivedFileData" 
    5666 
    5767#define FHImageLoaderDidLoadImage                                       @"FHImageLoaderDidLoadImage" 
    5868#define FHImageLoaderDidLoadThumbnail                           @"FHImageLoaderDidLoadThumbnail" 
     69#define FHImageLoaderDidLoadFile                                        @"FHImageLoaderDidLoadFile" 
     70#define FHImageLoaderDidLoadAllFiles                            @"FHImageLoaderDidLoadAllFiles" 
    5971 
    6072 
     
    6779- (void)startLoadingImages; 
    6880- (void)startLoadingThumbnails; 
    69 - (void)stopLoading; 
     81- (void)stopLoadingImagesAndThumbnails; 
     82- (void)startLoadingData; 
     83- (void)stopLoadingData; 
    7084 
    7185@end 
  • Footagehead/trunk/FHImageLoader.m

    r4732 r4868  
    3434#define FHImagesToKeepBehind                    2 
    3535 
     36@interface FHImageLoader(Private) 
     37 
     38- (void)_asynchronouslyLoadDataForFile:(FHFile *)file; 
     39- (void)_loadDataForFile:(FHFile *)file; 
     40- (void)_loadImageForFile:(FHFile *)file; 
     41 
     42@end 
     43 
     44 
     45@implementation FHImageLoader(Private) 
     46 
     47- (void)_asynchronouslyLoadDataForFile:(FHFile *)file { 
     48        NSURLConnection *connection; 
     49        WIURL                   *url; 
     50         
     51        url = [file URL]; 
     52         
     53        [_asynchronousRequest setURL:[url URL]]; 
     54        [_asynchronousRequest setValue:[[url URLByDeletingLastPathComponent] string] forHTTPHeaderField:@"Referer"]; 
     55         
     56        connection = [NSURLConnection connectionWithRequest:_asynchronousRequest delegate:self]; 
     57 
     58        _asynchronousDone = NO; 
     59        _asynchronousFile = file; 
     60        [_asynchronousData setLength:0]; 
     61         
     62        do { 
     63                [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode 
     64                                                                 beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.2]]; 
     65        } while(!_asynchronousDone); 
     66} 
     67 
     68 
     69 
     70- (void)_loadDataForFile:(FHFile *)file { 
     71        NSData          *data; 
     72        WIURL           *url; 
     73         
     74        [_notificationCenter mainThreadPostNotificationName:FHImageLoaderWillLoadFile object:file]; 
     75 
     76        url = [file URL]; 
     77 
     78        if([url isFileURL]) { 
     79                data = [[NSData alloc] initWithContentsOfFile:[url path]]; 
     80                [file setData:data]; 
     81                [data release]; 
     82        } else { 
     83                [_asynchronousLock lock]; 
     84                 
     85                _asynchronousImages = NO; 
     86 
     87                [self _asynchronouslyLoadDataForFile:file]; 
     88                 
     89                [file setData:_asynchronousData]; 
     90                 
     91                [_asynchronousData release]; 
     92                _asynchronousData = [[NSMutableData alloc] init]; 
     93                 
     94                [_asynchronousLock unlock]; 
     95        } 
     96         
     97        [_notificationCenter mainThreadPostNotificationName:FHImageLoaderDidLoadFile object:file]; 
     98} 
     99 
     100 
     101 
     102- (void)_loadImageForFile:(FHFile *)file { 
     103        NSData          *data; 
     104        WIURL           *url; 
     105        FHImage         *image, *thumbnail; 
     106         
     107        [_notificationCenter mainThreadPostNotificationName:FHImageLoaderWillLoadImage object:file]; 
     108 
     109        url = [file URL]; 
     110 
     111        if([url isFileURL]) { 
     112                data = [[NSData alloc] initWithContentsOfFile:[url path]]; 
     113                image = [[FHImage alloc] initImageWithData:data]; 
     114                thumbnail = NULL; 
     115                [data release]; 
     116        } else { 
     117                [_asynchronousLock lock]; 
     118                 
     119                _asynchronousImages = YES; 
     120                 
     121                [self _asynchronouslyLoadDataForFile:file]; 
     122                 
     123                image = [[FHImage alloc] initImageWithData:_asynchronousData]; 
     124                thumbnail = [[FHCache cache] thumbnailForURL:url withData:_asynchronousData]; 
     125 
     126                [_asynchronousData setLength:0]; 
     127                [_asynchronousLock unlock]; 
     128        } 
     129         
     130        [file setImage:image]; 
     131        [file setLoaded:YES]; 
     132        _pixels += [image pixels]; 
     133        [image release]; 
     134         
     135        [_notificationCenter mainThreadPostNotificationName:FHImageLoaderDidLoadImage object:file]; 
     136         
     137        if(thumbnail) { 
     138                [file setThumbnail:thumbnail]; 
     139 
     140                [_notificationCenter mainThreadPostNotificationName:FHImageLoaderDidLoadThumbnail object:file]; 
     141        } 
     142} 
     143 
     144@end 
     145 
     146 
     147 
    36148@implementation FHImageLoader 
    37149 
     
    39151        self = [super init]; 
    40152         
    41         _notificationCenter     = [[NSNotificationCenter alloc] init]; 
    42          
    43         _imageLock                      = [[NSConditionLock alloc] initWithCondition:0]; 
    44         _thumbnailLock          = [[NSConditionLock alloc] initWithCondition:0]; 
    45  
    46         _asynchronousData       = [[NSMutableData alloc] init]; 
    47  
    48         _maxPixels                      = ((double) [[NSProcessInfo processInfo] amountOfMemory] / 10) / 5; 
     153        _notificationCenter             = [[NSNotificationCenter alloc] init]; 
     154         
     155        _imageLock                              = [[NSConditionLock alloc] initWithCondition:0]; 
     156        _thumbnailLock                  = [[NSConditionLock alloc] initWithCondition:0]; 
     157        _dataLock                               = [[NSConditionLock alloc] initWithCondition:0]; 
     158 
     159        _asynchronousLock               = [[NSLock alloc] init]; 
     160        _asynchronousData               = [[NSMutableData alloc] init]; 
     161         
     162        _asynchronousRequest    = [[NSMutableURLRequest alloc] init]; 
     163 
     164#ifdef DEBUG 
     165        [_asynchronousRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData]; 
     166#endif 
     167 
     168        _maxPixels                              = ((double) [[NSProcessInfo processInfo] amountOfMemory] / 10) / 5; 
    49169         
    50170        [NSThread detachNewThreadSelector:@selector(imageThread:) toTarget:self withObject:NULL]; 
    51171        [NSThread detachNewThreadSelector:@selector(thumbnailsThread:) toTarget:self withObject:NULL]; 
     172        [NSThread detachNewThreadSelector:@selector(dataThread:) toTarget:self withObject:NULL]; 
    52173 
    53174        [NSThread setThreadPriority:0.75]; 
     
    63184        [_imageLock release]; 
    64185        [_thumbnailLock release]; 
     186        [_dataLock release]; 
    65187         
    66188        [_asynchronousData release]; 
     189        [_asynchronousLock release]; 
    67190         
    68191        [super dealloc]; 
     
    80203 
    81204- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 
     205        NSString        *notification; 
    82206        double          percent; 
    83207         
     
    90214                        [_asynchronousFile setPercentReceived:percent]; 
    91215         
    92                         [_notificationCenter mainThreadPostNotificationName:FHImageLoaderReceivedImageData 
    93                                                                                                                  object:_asynchronousFile]; 
     216                        notification = _asynchronousImages ? FHImageLoaderReceivedImageData : FHImageLoaderReceivedFileData; 
     217                         
     218                        [_notificationCenter mainThreadPostNotificationName:notification object:_asynchronousFile]; 
    94219                } 
    95220        } 
     
    115240        NSAutoreleasePool               *pool; 
    116241        NSArray                                 *files; 
    117         NSData                                  *data; 
    118         NSURLConnection                 *connection; 
    119         NSMutableURLRequest             *request; 
    120         WIURL                                   *url; 
    121         FHImage                                 *image; 
    122242        FHFile                                  *file; 
    123243        NSUInteger                              i, count, index; 
     
    128248         
    129249        pool = [[NSAutoreleasePool alloc] init]; 
    130         request = [[NSMutableURLRequest alloc] init]; 
    131250 
    132251        while(YES) { 
     
    170289                                file = [files objectAtIndex:i]; 
    171290                                 
    172                                 if([file isDirectory]) 
    173                                         goto next; 
    174                                  
    175                                 if([file image]) 
    176                                         goto next; 
    177                          
    178                                 if(i > index + 1 && _pixels >= _maxPixels) 
    179                                         break; 
    180                                  
    181                                 url = [file URL]; 
    182                                  
    183                                 if([url isFileURL]) { 
    184                                         data = [NSData dataWithContentsOfFile:[url path]]; 
    185                                 } else { 
    186                                         [request setURL:[url URL]]; 
    187                                         [request setValue:[[url URLByDeletingLastPathComponent] string] forHTTPHeaderField:@"Referer"]; 
    188  
    189                                         connection = [NSURLConnection connectionWithRequest:request delegate:self]; 
    190                                          
    191                                         _asynchronousDone = NO; 
    192                                         _asynchronousFile = file; 
    193                                         [_asynchronousData setLength:0]; 
    194  
    195                                         do { 
    196                                                 [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode 
    197                                                                                                  beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.2]]; 
    198                                         } while(!_asynchronousDone); 
    199                                          
    200                                         data = _asynchronousData; 
     291                                if(![file isDirectory] && ![file image]) { 
     292                                        if(i > index + 1 && _pixels >= _maxPixels) 
     293                                                break; 
     294                                         
     295                                        [self _loadImageForFile:file]; 
    201296                                } 
    202                                  
    203                                 image = [[FHImage alloc] initImageWithData:data]; 
    204                                 [file setImage:image]; 
    205                                 [file setLoaded:YES]; 
    206                                 _pixels += [image pixels]; 
    207                                 [image release]; 
    208  
    209                                 [_notificationCenter mainThreadPostNotificationName:FHImageLoaderDidLoadImage object:file]; 
    210                                  
    211                                 if([_asynchronousData length] > 0) { 
    212                                         image = [[FHCache cache] thumbnailForURL:url withData:data]; 
    213                                          
    214                                         if(image) { 
    215                                                 [file setThumbnail:image]; 
    216                                                  
    217                                                 [_notificationCenter mainThreadPostNotificationName:FHImageLoaderDidLoadThumbnail object:file]; 
    218                                         } 
    219  
    220                                         [_asynchronousData setLength:0]; 
    221                                 } 
    222  
    223 next: 
     297 
    224298                                [_imageLock lock]; 
    225299                                if(counter != _imageCounter) 
     
    242316        } 
    243317         
    244         [request release]; 
    245318        [pool release]; 
    246319} 
     
    275348                for(i = images = 0; i < count; i++) { 
    276349                        file = [files objectAtIndex:i]; 
    277                          
    278                         if([file isDirectory] || [file thumbnail]) 
    279                                 goto next; 
    280                          
    281350                        url = [file URL]; 
    282351                         
    283                         if(![url isFileURL]) 
    284                                 goto next; 
    285                          
    286                         image = [[FHCache cache] thumbnailForURL:url]; 
    287                          
    288                         if(image) { 
    289                                 [file setThumbnail:image]; 
    290                          
    291                                 [_notificationCenter mainThreadPostNotificationName:FHImageLoaderDidLoadThumbnail object:file]; 
     352                        if(![file isDirectory] && ![file thumbnail] && [url isFileURL]) { 
     353                                image = [[FHCache cache] thumbnailForURL:url]; 
     354                                 
     355                                if(image) { 
     356                                        [file setThumbnail:image]; 
     357                                         
     358                                        [_notificationCenter mainThreadPostNotificationName:FHImageLoaderDidLoadThumbnail object:file]; 
     359                                } 
    292360                        } 
    293                          
    294 next: 
     361                                 
    295362                        if(++images % 5 == 0) { 
    296363                                [_thumbnailLock lock]; 
     
    317384 
    318385 
     386- (void)dataThread:(id)sender { 
     387        NSAutoreleasePool               *pool; 
     388        NSArray                                 *files; 
     389        FHFile                                  *file; 
     390        NSUInteger                              i, count; 
     391        NSUInteger                              counter, lastCounter = 0; 
     392        BOOL                                    stop; 
     393         
     394        [NSThread setThreadPriority:0.5]; 
     395         
     396        pool = [[NSAutoreleasePool alloc] init]; 
     397 
     398        while(YES) { 
     399                if(!pool) 
     400                        pool = [[NSAutoreleasePool alloc] init]; 
     401 
     402                [_dataLock lockWhenCondition:1]; 
     403                files = [[_files retain] autorelease]; 
     404                counter = _dataCounter; 
     405                stop = _dataStop; 
     406                [_dataLock unlockWithCondition:0]; 
     407                 
     408                if(stop) 
     409                        break; 
     410                 
     411                if(counter != lastCounter) { 
     412                        count = [files count]; 
     413                         
     414                        for(i = 0; i < count; i++) { 
     415                                file = [files objectAtIndex:i]; 
     416                                 
     417                                if(![file isDirectory] && ![file data]) 
     418                                        [self _loadDataForFile:file]; 
     419                                 
     420                                [_dataLock lock]; 
     421                                if(counter != _dataCounter) 
     422                                        i = count; 
     423                                stop = _dataStop; 
     424                                [_dataLock unlockWithCondition:counter == _dataCounter ? 0 : 1]; 
     425                                 
     426                                if(stop) 
     427                                        break; 
     428                        } 
     429                         
     430                        lastCounter = counter; 
     431 
     432                        [_notificationCenter mainThreadPostNotificationName:FHImageLoaderDidLoadAllFiles]; 
     433                } 
     434 
     435                [pool release]; 
     436                pool = NULL; 
     437                 
     438                if(stop) 
     439                        break; 
     440        } 
     441         
     442        [pool release]; 
     443} 
     444 
     445 
     446 
    319447#pragma mark - 
    320448 
     
    373501 
    374502 
    375 - (void)stopLoading
     503- (void)stopLoadingImagesAndThumbnails
    376504        [_imageLock lock]; 
    377505        _imageStop = YES; 
     
    383511} 
    384512 
     513 
     514 
     515- (void)startLoadingData { 
     516        [_dataLock lock]; 
     517        _dataCounter++; 
     518        [_dataLock unlockWithCondition:1]; 
     519} 
     520 
     521 
     522 
     523- (void)stopLoadingData { 
     524        [_dataLock lock]; 
     525        _dataStop = YES; 
     526        [_dataLock unlockWithCondition:1]; 
     527} 
     528 
    385529@end