Changeset 3101

Show
Ignore:
Timestamp:
07/09/05 23:01:41 (3 years ago)
Author:
morris
Message:

Add a zip handler based on FHFileHandler

Files:

Legend:

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

    r3037 r3101  
    193193                url = [ZAURL URLWithString:[FHSettings objectForKey:FHOpenURL]]; 
    194194 
    195                 if([url isFileURL] && ![[NSFileManager defaultManager] directoryExistsAtPath:[url path]]) 
     195                if([url isFileURL] && ![[NSFileManager defaultManager] fileExistsAtPath:[url path]]) 
    196196                        url = [ZAURL fileURLWithPath:NSHomeDirectory()]; 
    197197 
     
    212212        if(url) 
    213213                [FHSettings setObject:[url string] forKey:FHOpenURL]; 
     214         
     215        [_handler release]; 
    214216} 
    215217 
     
    224226- (BOOL)application:(NSApplication *)application openFile:(NSString *)path { 
    225227        NSString        *file; 
    226          
    227         if([[NSFileManager defaultManager] directoryExistsAtPath:path]) { 
    228                 [self loadURL:[ZAURL fileURLWithPath:path]]; 
     228        ZAURL           *url; 
     229         
     230        url = [ZAURL fileURLWithPath:path]; 
     231         
     232        if([FHHandler handlesURLAsDirectory:url]) { 
     233                [self loadURL:url]; 
    229234        } else { 
    230235                file = [path lastPathComponent]; 
    231236                path = [path stringByDeletingLastPathComponent]; 
    232237                 
    233                 [self loadURL:[ZAURL fileURLWithPath:path] selectFile:file]; 
    234         } 
     238                [self loadURL:url selectFile:file]; 
     239        } 
     240         
     241        _openLastURL = NO; 
    235242 
    236243        return YES; 
     
    808815 
    809816- (void)loadURL:(ZAURL *)url selectRow:(int)row file:(NSString *)file { 
     817        NSArray                 *files; 
    810818        FHHandler               *handler; 
    811819        unsigned int    i, count; 
     
    831839        _handler = handler; 
    832840        [_handler setDelegate:self]; 
    833         [_handler files]; 
     841        files = [_handler files]; 
    834842         
    835843        [self updateLeftStatus]; 
     
    838846         
    839847        if(file) { 
    840                 for(i = 0, count = [[_handler files] count]; i < count; i++) { 
    841                         if([[[[_handler files] objectAtIndex:i] name] isEqualToString:file]) { 
     848                for(i = 0, count = [files count]; i < count; i++) { 
     849                        if([[[files objectAtIndex:i] name] isEqualToString:file]) { 
    842850                                row = i; 
    843851                                 
  • Footagehead/trunk/FHFileHandler.h

    r920 r3101  
    1 /* $Id: FHFileHandler.h,v 1.5 2005/01/08 22:55:46 morris Exp $ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    2929#import "FHHandler.h" 
    3030 
    31 @interface FHFileHandler : FHHandler 
     31@interface FHFileHandler : FHHandler { 
     32        NSString                                *_rootPath; 
     33
     34 
     35 
     36+ (NSArray *)handledFileTypes; 
     37 
     38- (id)initHandlerWithURL:(ZAURL *)url rootPath:(NSString *)rootPath; 
    3239 
    3340@end 
  • Footagehead/trunk/FHFileHandler.m

    r2957 r3101  
    3030#import "FHFile.h" 
    3131#import "FHFileHandler.h" 
     32#import "FHZipHandler.h" 
    3233 
    33 static NSComparisonResult compareFile(id, id, void *); 
     34static NSMutableArray                   *FHFileHandlerFileTypes; 
     35 
     36@implementation FHFileHandler 
     37 
     38+ (void)initialize { 
     39        if([self isEqual:[FHFileHandler class]]) { 
     40                FHFileHandlerFileTypes = [[NSMutableArray alloc] init]; 
     41                [FHFileHandlerFileTypes addObjectsFromArray:[FHZipHandler handledFileTypes]]; 
     42        } 
     43
    3444 
    3545 
    36 @implementation FHFileHandler 
     46 
     47#pragma mark - 
    3748 
    3849+ (BOOL)handlesURL:(ZAURL *)url isPrimary:(BOOL)primary { 
     
    4354         
    4455        return NO; 
     56} 
     57 
     58 
     59 
     60+ (BOOL)handlesURLAsDirectory:(ZAURL *)url { 
     61        if(![url isFileURL]) 
     62                return NO; 
     63         
     64        if([[NSFileManager defaultManager] directoryExistsAtPath:[url path]]) 
     65                return YES; 
     66 
     67        return [FHFileHandlerFileTypes containsObject:[url pathExtension]]; 
     68} 
     69 
     70 
     71 
     72+ (NSArray *)handledFileTypes { 
     73        return [NSImage FHImageFileTypes]; 
     74} 
     75 
     76 
     77 
     78#pragma mark - 
     79 
     80- (id)initHandlerWithURL:(ZAURL *)url { 
     81        return [self initHandlerWithURL:url rootPath:[url path]]; 
     82} 
     83 
     84 
     85 
     86- (id)initHandlerWithURL:(ZAURL *)url rootPath:(NSString *)rootPath { 
     87        self = [super initHandlerWithURL:url]; 
     88         
     89        _rootPath = [rootPath retain]; 
     90         
     91        return self; 
     92} 
     93 
     94 
     95 
     96- (void)dealloc { 
     97        [_rootPath release]; 
     98         
     99        [super dealloc]; 
    45100} 
    46101 
     
    59114- (NSArray *)files { 
    60115        NSArray                         *types, *files; 
    61         NSString                        *name, *root, *path
     116        NSString                        *name, *path, *extension
    62117        FHFile                          *file; 
    63118        ZAURL                           *url; 
     
    68123 
    69124        if(!_files) { 
    70                 root    = [[self URL] path]; 
    71                 files   = [[NSFileManager defaultManager] directoryContentsWithFileAtPath:root]; 
     125                files   = [[NSFileManager defaultManager] directoryContentsWithFileAtPath:_rootPath]; 
    72126                files   = [files sortedArrayUsingFunction:compareFile context:NULL]; 
    73127                count   = [files count]; 
    74                 types   = [NSImage FHImageFileTypes]; 
    75                  
     128                types   = [FHFileHandler handledFileTypes]; 
    76129                _files  = [[NSMutableArray alloc] initWithCapacity:count]; 
    77130                 
    78131                for(i = index = 0; i < count; i++) { 
    79132                        name = [files objectAtIndex:i]; 
    80                         path = [root stringByAppendingPathComponent:name]; 
     133                        path = [_rootPath stringByAppendingPathComponent:name]; 
    81134                         
    82135                        if([name hasPrefix:@"."] ) 
     
    95148 
    96149                        if(!isDirectory) { 
    97                                 if(![types containsObject:[path pathExtension]]) 
    98                                         continue; 
     150                                extension = [path pathExtension]; 
     151                                 
     152                                if(![types containsObject:extension]) { 
     153                                        if([FHFileHandlerFileTypes containsObject:extension]) 
     154                                                isDirectory = YES; 
     155                                        else 
     156                                                continue; 
     157                                } 
    99158                        } 
    100159 
  • Footagehead/trunk/FHHandler.h

    r3024 r3101  
    4343 
    4444+ (BOOL)handlesURL:(ZAURL *)url isPrimary:(BOOL)primary; 
     45+ (BOOL)handlesURLAsDirectory:(ZAURL *)url; 
    4546 
    4647- (id)initHandlerWithURL:(ZAURL *)url; 
  • Footagehead/trunk/FHHandler.m

    r2935 r3101  
    3535#import "FHSpotlightHandler.h" 
    3636#import "FHURLHandler.h" 
     37#import "FHZipHandler.h" 
    3738 
    3839static NSArray                                  *FHHandlerClasses; 
     
    4748                        [FHSpotlightHandler class], 
    4849                        [FHURLHandler class], 
     50                        [FHZipHandler class], 
    4951                        NULL]; 
    5052        } 
     
    5557+ (BOOL)handlesURL:(ZAURL *)url isPrimary:(BOOL)primary { 
    5658        [self doesNotRecognizeSelector:_cmd]; 
     59        return NO; 
     60} 
     61 
     62 
     63 
     64+ (BOOL)handlesURLAsDirectory:(ZAURL *)url { 
    5765        return NO; 
    5866} 
  • Footagehead/trunk/Footagehead.xcodeproj/project.pbxproj

    r2967 r3101  
    149149                A5B1FB9F067CB90400111D0A /* FHCache.m in Sources */ = {isa = PBXBuildFile; fileRef = A5B1FB9D067CB90400111D0A /* FHCache.m */; }; 
    150150                A5B1FBC6067D01C200111D0A /* FHImageHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = A5B1FBC4067D01C200111D0A /* FHImageHandler.m */; }; 
     151                A5B44F98087F9A2D003B1DA1 /* FHZipHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = A5B44F96087F9A2D003B1DA1 /* FHZipHandler.m */; }; 
    151152                A5DE34860567F307003E7FE9 /* URL.tiff in Resources */ = {isa = PBXBuildFile; fileRef = A5DE34850567F307003E7FE9 /* URL.tiff */; }; 
    152153                A5DEB67005CBEFD30074DA63 /* Fullscreen.tiff in Resources */ = {isa = PBXBuildFile; fileRef = A5DEB66F05CBEFD30074DA63 /* Fullscreen.tiff */; }; 
     
    385386                A5B1FBC4067D01C200111D0A /* FHImageHandler.m */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.objc; path = FHImageHandler.m; sourceTree = "<group>"; }; 
    386387                A5B1FBC5067D01C200111D0A /* FHImageHandler.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = FHImageHandler.h; sourceTree = "<group>"; }; 
     388                A5B44F95087F9A2D003B1DA1 /* FHZipHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FHZipHandler.h; sourceTree = "<group>"; }; 
     389                A5B44F96087F9A2D003B1DA1 /* FHZipHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FHZipHandler.m; sourceTree = "<group>"; }; 
    387390                A5DE34850567F307003E7FE9 /* URL.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = URL.tiff; sourceTree = "<group>"; }; 
    388391                A5DEB66F05CBEFD30074DA63 /* Fullscreen.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = Fullscreen.tiff; sourceTree = "<group>"; }; 
     
    631634                                A5B1F616067B3B7900111D0A /* FHFileHandler.m */, 
    632635                                A5B1F614067B3B6F00111D0A /* FHFileHandler.h */, 
     636                                A5B44FA4087F9CAB003B1DA1 /* File Handlers */, 
    633637                                A5B1F9BF067BDF2300111D0A /* FHRangeHandler.m */, 
    634638                                A5B1F9C0067BDF2300111D0A /* FHRangeHandler.h */, 
     
    655659                        ); 
    656660                        name = Data; 
     661                        sourceTree = "<group>"; 
     662                }; 
     663                A5B44FA4087F9CAB003B1DA1 /* File Handlers */ = { 
     664                        isa = PBXGroup; 
     665                        children = ( 
     666                                A5B44F96087F9A2D003B1DA1 /* FHZipHandler.m */, 
     667                                A5B44F95087F9A2D003B1DA1 /* FHZipHandler.h */, 
     668                        ); 
     669                        name = "File Handlers"; 
    657670                        sourceTree = "<group>"; 
    658671                }; 
     
    957970                                8D11072D0486CEB800E47090 /* main.m in Sources */, 
    958971                                770EBFC5083C94CE0094BD6C /* NSBitmapImageRep-FHAdditions.m in Sources */, 
     972                                A570FD9F0863661300317D0F /* NSData-FHAdditions.m in Sources */, 
    959973                                775BA4F2075F70ED00F0941E /* NSImage-FHAdditions.m in Sources */, 
    960974                                A5B1FB9F067CB90400111D0A /* FHCache.m in Sources */, 
     
    964978                                A599A110075F94F400A03BA5 /* FHFileCell.m in Sources */, 
    965979                                A5B1F617067B3B7900111D0A /* FHFileHandler.m in Sources */, 
     980                                77EAC0D5084C6D1F006C9F69 /* FHFlickrHandler.m in Sources */, 
    966981                                A5B1F611067B3AA100111D0A /* FHHandler.m in Sources */, 
    967982                                A5B1F9AC067BCF0200111D0A /* FHHTMLHandler.m in Sources */, 
    968983                                77EABF11084C61FF006C9F69 /* FHHTMLParser.m in Sources */, 
     984                                77494704085A57F600BA0915 /* FHImage.m in Sources */, 
    969985                                A5B1FBC6067D01C200111D0A /* FHImageHandler.m in Sources */, 
    970986                                77CDB023083B6B85003BE654 /* FHImageView.m in Sources */, 
     
    975991                                77BD99520760B7380007D034 /* FHTableView.m in Sources */, 
    976992                                77EAADDA084B546D006C9F69 /* FHURLHandler.m in Sources */, 
    977                                 77EAC0D5084C6D1F006C9F69 /* FHFlickrHandler.m in Sources */, 
    978                                 77494704085A57F600BA0915 /* FHImage.m in Sources */, 
    979                                 A570FD9F0863661300317D0F /* NSData-FHAdditions.m in Sources */, 
     993                                A5B44F98087F9A2D003B1DA1 /* FHZipHandler.m in Sources */, 
    980994                        ); 
    981995                        runOnlyForDeploymentPostprocessing = 0; 
  • Footagehead/trunk/Info.plist

    r2844 r3101  
    145145                        <string>Viewer</string> 
    146146                </dict> 
     147                <dict> 
     148                        <key>CFBundleTypeExtensions</key> 
     149                        <array> 
     150                                <string>cbz</string> 
     151                        </array> 
     152                        <key>CFBundleTypeName</key> 
     153                        <string>Comic Book Zip File</string> 
     154                        <key>CFBundleTypeRole</key> 
     155                        <string>Viewer</string> 
     156                </dict> 
    147157        </array> 
    148158        <key>CFBundleExecutable</key>