Changeset 4717

Show
Ignore:
Timestamp:
04/24/07 16:50:54 (1 year ago)
Author:
morris
Message:

Share the image loader between browser and slideshow

Bring back auto switching

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Footagehead/trunk/FHBrowserController.h

    r4716 r4717  
    3030 
    3131@class FHTableView; 
     32@class FHHandler; 
    3233 
    3334@interface FHBrowserController : FHWindowController { 
     
    6061        IBOutlet NSTextField                    *_screenAutoSwitchTextField; 
    6162 
     63        FHHandler                                               *_handler; 
     64 
    6265        NSMutableDictionary                             *_toolbarItems; 
    6366 
  • Footagehead/trunk/FHBrowserController.m

    r4716 r4717  
    419419        self = [super initWithWindowNibName:@"Browser"]; 
    420420         
     421        _imageLoader = [[FHImageLoader alloc] init]; 
     422         
     423        [[_imageLoader notificationCenter] 
     424                addObserver:self 
     425                   selector:@selector(imageLoaderDidLoadImage:) 
     426                           name:FHImageLoaderDidLoadImage]; 
     427         
     428        [[_imageLoader notificationCenter] 
     429                addObserver:self 
     430                   selector:@selector(imageLoaderDidLoadThumbnail:) 
     431                           name:FHImageLoaderDidLoadThumbnail]; 
     432 
    421433        [self window]; 
    422434         
     
    427439 
    428440- (void)dealloc { 
     441        [_handler release]; 
     442         
     443        [_imageLoader stopLoading]; 
     444         
    429445        [_toolbarItems release]; 
    430446         
     
    550566 
    551567 
    552 - (void)imageLoaderDidLoadImageForFile:(FHFile *)file { 
     568- (void)imageLoaderDidLoadImage:(NSNotification *)notification { 
     569        FHFile          *file; 
     570         
     571        file = [notification object]; 
     572         
    553573        if(file == [self selectedFile]) 
    554574                [self showFile:file]; 
     
    557577 
    558578 
    559 - (void)imageLoaderDidLoadThumbnailForFile:(FHFile *)file
     579- (void)imageLoaderDidLoadThumbnail:(NSNotification *)notification
    560580        [_tableView reloadData]; 
    561581} 
     
    699719#pragma mark - 
    700720 
     721- (NSArray *)files { 
     722        return [_handler files]; 
     723} 
     724 
     725 
     726 
    701727- (NSUInteger)selectedIndex { 
    702728        NSInteger       row; 
     
    10051031                [FHSettings setInt:[_screenAutoSwitchTextField intValue] forKey:FHFullscreenAutoSwitchTime]; 
    10061032                 
    1007                 controller = [[FHSlideshowController alloc] initWithHandler:_handler index:[self selectedIndex]]; 
     1033                controller = [[FHSlideshowController alloc] initWithImageLoader:_imageLoader 
     1034                                                                                                                                  index:[self selectedIndex] 
     1035                                                                                                                                 images:[_handler numberOfImages]]; 
    10081036                [controller showSlideshowWindow:self]; 
    10091037                [controller release]; 
  • Footagehead/trunk/FHImageLoader.h

    r4716 r4717  
    2929@class FHFile; 
    3030 
    31 @interface FHImageLoader : NSObject { 
    32         id                                                             _delegate
     31@interface FHImageLoader : WIObject { 
     32        NSNotificationCenter   *_notificationCenter
    3333         
    34         NSConditionLock                                *_imageLock; 
    35         NSConditionLock                                *_thumbnailLock; 
     34        NSConditionLock                 *_imageLock; 
     35        NSConditionLock                 *_thumbnailLock; 
    3636 
    37         NSUInteger                                             _imageCounter; 
    38         NSUInteger                                             _thumbnailCounter; 
     37        NSUInteger                              _imageCounter; 
     38        NSUInteger                              _thumbnailCounter; 
    3939         
    40         BOOL                                                   _imageStop; 
    41         BOOL                                                   _thumbnailStop; 
     40        BOOL                                    _imageStop; 
     41        BOOL                                    _thumbnailStop; 
    4242         
    43         NSArray                                                *_files; 
    44         NSUInteger                                             _index; 
    45         NSUInteger                                             _pixels, _maxPixels; 
     43        NSArray                                 *_files; 
     44        NSUInteger                              _index; 
     45        NSUInteger                              _pixels, _maxPixels; 
    4646} 
    4747 
    48 - (void)setDelegate:(id)delegate; 
    49 - (id)delegate; 
     48 
     49#define FHImageLoaderDidLoadImage               @"FHImageLoaderDidLoadImage" 
     50#define FHImageLoaderDidLoadThumbnail   @"FHImageLoaderDidLoadThumbnail" 
     51 
     52 
     53- (NSNotificationCenter *)notificationCenter; 
     54 
    5055- (void)setFiles:(NSArray *)files; 
    5156- (NSArray *)files; 
     
    5762 
    5863@end 
    59  
    60  
    61 @interface NSObject(FHImageLoaderDelegate) 
    62  
    63 - (void)imageLoaderDidLoadImageForFile:(FHFile *)file; 
    64 - (void)imageLoaderDidLoadThumbnailForFile:(FHFile *)file; 
    65  
    66 @end 
  • Footagehead/trunk/FHImageLoader.m

    r4716 r4717  
    3939        self = [super init]; 
    4040         
     41        _notificationCenter     = [[NSNotificationCenter alloc] init]; 
     42         
    4143        _imageLock                      = [[NSConditionLock alloc] initWithCondition:0]; 
    4244        _thumbnailLock          = [[NSConditionLock alloc] initWithCondition:0]; 
     
    5557 
    5658- (void)dealloc { 
     59        [_notificationCenter release]; 
     60         
    5761        [_imageLock release]; 
    5862        [_thumbnailLock release]; 
     
    130134                                [image release]; 
    131135 
    132                                 [_delegate performSelectorOnMainThread:@selector(imageLoaderDidLoadImageForFile:) 
    133                                                                                         withObject:file 
    134                                                                                  waitUntilDone:YES]; 
     136                                [_notificationCenter mainThreadPostNotificationName:FHImageLoaderDidLoadImage object:file]; 
    135137 
    136138next: 
     
    196198                                goto next; 
    197199                         
    198                         image = [[FHCache cache] thumbnailForURL:url]; 
     200                        image = [[[FHCache cache] thumbnailForURL:url] retain]; 
    199201                         
    200202                        if(!image) { 
     
    209211                                [image release]; 
    210212                         
    211                                 [_delegate performSelectorOnMainThread:@selector(imageLoaderDidLoadThumbnailForFile:) 
    212                                                                                         withObject:file 
    213                                                                                  waitUntilDone:YES]; 
     213                                [_notificationCenter mainThreadPostNotificationName:FHImageLoaderDidLoadThumbnail object:file]; 
    214214                        } 
    215215                         
     
    241241#pragma mark - 
    242242 
    243 - (void)setDelegate:(id)delegate { 
    244         _delegate = delegate; 
    245 
    246  
    247  
    248  
    249 - (id)delegate { 
    250         return _delegate; 
     243- (NSNotificationCenter *)notificationCenter { 
     244        return _notificationCenter; 
    251245} 
    252246 
  • Footagehead/trunk/FHSlideshowController.h

    r4716 r4717  
    3434        FHSlideshowWindow               *_slideshowWindow; 
    3535         
     36        NSTimer                                 *_timer; 
     37         
    3638        NSUInteger                              _index; 
     39        NSUInteger                              _images; 
    3740} 
    3841 
    3942 
    40 - (id)initWithHandler:(FHHandler *)handler index:(NSUInteger)index
     43- (id)initWithImageLoader:(FHImageLoader *)imageLoader index:(NSUInteger)index images:(NSUInteger)images
    4144 
    4245- (void)showSlideshowWindow:(id)sender; 
  • Footagehead/trunk/FHSlideshowController.m

    r4716 r4717  
    3434#import "FHSettings.h" 
    3535 
    36 @interface FHSlideshowController(Private) 
    37  
    38  
    39 @end 
    40  
    41  
    42 @implementation FHSlideshowController(Private) 
    43  
    44 /* 
    45  - (void)_loadFileTimer:(NSTimer *)timer { 
    46         NSArray         *files; 
    47         int                     i, count; 
    48         BOOL            next = NO; 
    49          
    50 //      [self nextImage:self]; 
    51          
    52         i = [_tableView selectedRow]; 
    53         files = [_handler files]; 
    54         count = [files count]; 
    55          
    56         while(i < count - 1) { 
    57                 if(![[files objectAtIndex:i] isDirectory]) { 
    58                         next = YES; 
    59                          
    60                         break; 
    61                 } 
    62         } 
    63          
    64         if(!next) 
    65                 [timer invalidate]; 
    66 } 
    67 */ 
    68  
    69 @end 
    70  
    71  
    72  
    7336@implementation FHSlideshowController 
    7437 
    75 - (id)initWithHandler:(FHHandler *)handler index:(NSUInteger)index
     38- (id)initWithImageLoader:(FHImageLoader *)imageLoader index:(NSUInteger)index images:(NSUInteger)images
    7639        self = [super initWithWindowNibName:@"Slideshow"]; 
    7740         
    78         _handler = [handler retain]; 
     41        _imageLoader = [imageLoader retain]; 
    7942        _index = index; 
    80          
    81         [_imageLoader setFiles:[_handler files]]; 
    82  
     43        _images = images; 
     44 
     45        [[_imageLoader notificationCenter] 
     46                addObserver:self 
     47                   selector:@selector(imageLoaderDidLoadImage:) 
     48                           name:FHImageLoaderDidLoadImage]; 
     49         
    8350        [self retain]; 
    8451        [self window]; 
     
    9158- (void)dealloc { 
    9259        [_slideshowWindow release]; 
     60        [_timer release]; 
    9361 
    9462        [super dealloc]; 
     
    9967#pragma mark - 
    10068 
    101 - (void)imageLoaderDidLoadImageForFile:(FHFile *)file { 
     69- (void)imageLoaderDidLoadImage:(NSNotification *)notification { 
     70        FHFile          *file; 
     71         
     72        file = [notification object]; 
     73         
    10274        if(file == [self selectedFile]) 
    10375                [self showFile:file]; 
     
    145117        [_imageView setBackgroundColor:color]; 
    146118         
    147         [_imageLoader startLoadingImages]; 
    148          
    149         /* 
    150                         // --- get screen 
    151                 screenNumber = [FHSettings intForKey:FHFullscreenScreen]; 
    152                  
    153                 if((unsigned int) screenNumber > [[NSScreen screens] count]) 
    154                         screenNumber = 0; 
    155                  
    156                 screen = [[NSScreen screens] objectAtIndex:screenNumber]; 
    157                 screenRect = [screen frame]; 
    158                 screenRect.origin.x = screenRect.origin.y = 0; 
    159                  
    160                 // --- create fullscreen window 
    161                 _fullscreenWindow = [[FHSlideshowWindow alloc] 
    162                         initWithContentRect:screenRect 
    163                                           styleMask:NSBorderlessWindowMask 
    164                                                 backing:NSBackingStoreBuffered 
    165                                                   defer:YES 
    166                                                  screen:screen]; 
    167                  
    168                 [_fullscreenWindow setLevel:NSScreenSaverWindowLevel]; 
    169                 [_fullscreenWindow setDelegate:self]; 
    170                 [_fullscreenWindow setReleasedWhenClosed:YES]; 
    171                 [_fullscreenWindow setTitle:[[self window] title]]; 
    172           
    173                 [_fullscreenImageView setBackgroundColor:[_screenBackgroundPopUpButton representedObjectOfSelectedItem]]; 
    174                 [_fullscreenImageView setImageScaling:[FHSettings intForKey:FHFullscreenImageScalingMethod]]; 
    175                 [_fullscreenImageView setImageRotation:[_imageView imageRotation]]; 
    176  
    177                 [_fullscreenPanel setFrame:screenRect display:NO]; 
    178                 [_fullscreenWindow setContentView:[[_fullscreenPanel contentView] retain]]; 
    179                 [[self window] orderOut:self]; 
    180                 [_fullscreenWindow makeKeyAndOrderFront:self]; 
    181                 [self _updateImage]; 
    182  
    183                 if([FHSettings boolForKey:FHFullscreenAutoSwitch]) { 
    184                         _loadImageTimer = [[NSTimer scheduledTimerWithTimeInterval:[FHSettings intForKey:FHFullscreenAutoSwitchTime] 
    185                                                                                                                                 target:self 
    186                                                                                                                           selector:@selector(_loadFileTimer:) 
    187                                                                                                                           userInfo:NULL 
    188                                                                                                                            repeats:YES] retain]; 
    189 */ 
     119        [_imageLoader startLoadingImageAtIndex:[self selectedIndex]]; 
     120         
     121        if([FHSettings boolForKey:FHFullscreenAutoSwitch]) { 
     122                _timer = [[NSTimer scheduledTimerWithTimeInterval:[FHSettings intForKey:FHFullscreenAutoSwitchTime] 
     123                                                                                                   target:self 
     124                                                                                                 selector:@selector(switchTimer:) 
     125                                                                                                 userInfo:NULL 
     126                                                                                                  repeats:YES] retain]; 
     127        } 
    190128         
    191129        [self showFile:[self selectedFile]]; 
     
    195133 
    196134- (void)windowWillClose:(NSNotification *)notification { 
     135        [_timer invalidate]; 
     136         
    197137        [self autorelease]; 
    198138} 
     
    210150#pragma mark - 
    211151 
     152- (NSArray *)files { 
     153        return [_imageLoader files]; 
     154} 
     155 
     156 
     157 
    212158- (NSUInteger)selectedIndex { 
    213159        return _index; 
     
    219165        _index = index; 
    220166 
     167        [_timer setFireDate:[NSDate distantFuture]]; 
     168 
    221169        [self showFile:[self selectedFile]]; 
     170 
     171        [_imageLoader startLoadingImageAtIndex:_index]; 
     172} 
     173 
     174 
     175 
     176- (void)showFile:(FHFile *)file { 
     177        [super showFile:file]; 
     178         
     179        [_timer setFireDate:[NSDate dateWithTimeIntervalSinceNow: 
     180                [FHSettings intForKey:FHFullscreenAutoSwitchTime]]]; 
    222181} 
    223182 
     
    230189         
    231190        file = [self selectedFile]; 
    232         files = [_handler files]; 
     191        files = [self files]; 
    233192        count = [files count]; 
    234193 
     
    245204                0x2014, 
    246205                index, 
    247                 [_handler numberOfImages]]]; 
     206                _images]]; 
     207
     208 
     209 
     210 
     211#pragma mark - 
     212 
     213- (void)switchTimer:(NSTimer *)timer { 
     214        NSArray         *files; 
     215        NSUInteger      i, count; 
     216        BOOL            next = NO; 
     217         
     218        [self nextImage:self]; 
     219         
     220        i = [self selectedIndex]; 
     221        files = [self files]; 
     222        count = [files count]; 
     223         
     224        while(i < count - 1) { 
     225                if(![[files objectAtIndex:i] isDirectory]) { 
     226                        next = YES; 
     227                         
     228                        break; 
     229                } 
     230        } 
     231         
     232        if(!next) 
     233                [timer invalidate]; 
    248234} 
    249235 
  • Footagehead/trunk/FHWindowController.h

    r4716 r4717  
    2828 
    2929@class FHImageView; 
    30 @class FHImageLoader, FHHandler, FHFile; 
     30@class FHImageLoader, FHFile; 
    3131 
    3232@interface FHWindowController : WIWindowController { 
     
    3434 
    3535        FHImageLoader                                   *_imageLoader; 
    36         FHHandler                                               *_handler; 
    3736} 
    3837 
    3938 
     39- (NSArray *)files; 
    4040- (FHFile *)fileAtIndex:(NSUInteger)index; 
    4141- (FHFile *)selectedFile; 
  • Footagehead/trunk/FHWindowController.m

    r4716 r4717  
    3535@implementation FHWindowController 
    3636 
    37 - (id)initWithWindowNibName:(NSString *)nibName { 
    38         self = [super initWithWindowNibName:nibName]; 
    39          
    40         _imageLoader = [[FHImageLoader alloc] init]; 
    41         [_imageLoader setDelegate:self]; 
    42          
    43         return self; 
    44 } 
    45  
    46  
    47  
    4837- (void)dealloc { 
    49         [_imageLoader stopLoading]; 
    50         [_imageLoader release]; 
    51  
    52         [_handler release]; 
    53          
     38        [[_imageLoader notificationCenter] removeObserver:self]; 
     39 
    5440        [super dealloc]; 
    5541} 
     
    5945#pragma mark - 
    6046 
     47- (NSArray *)files { 
     48        return NULL; 
     49} 
     50 
     51 
     52 
    6153- (FHFile *)fileAtIndex:(NSUInteger)index { 
    62         return [[_handler files] objectAtIndex:index]; 
     54        return [[self files] objectAtIndex:index]; 
    6355} 
    6456 
     
    118110 
    119111- (void)firstFile:(id)sender { 
    120         if([[_handler files] count] == 0) 
     112        if([[self files] count] == 0) 
    121113                return; 
    122114         
     
    129121        NSUInteger              count; 
    130122 
    131         count = [[_handler files] count]; 
     123        count = [[self files] count]; 
    132124         
    133125        if(count == 0) 
     
    148140                return; 
    149141         
    150         files = [_handler files]; 
     142        files = [self files]; 
    151143        count = [files count]; 
    152144        newIndex = NSNotFound; 
     
    177169                return; 
    178170         
    179         files = [_handler files]; 
     171        files = [self files]; 
    180172        count = [files count]; 
    181173         
     
    210202                return; 
    211203         
    212         files = [_handler files]; 
     204        files = [self files]; 
    213205        count = [files count]; 
    214206        newIndex = 0; 
     
    242234                return; 
    243235         
    244         files = [_handler files]; 
     236        files = [self files]; 
    245237        count = [files count]; 
    246238