Changeset 2959

Show
Ignore:
Timestamp:
06/17/05 22:27:46 (3 years ago)
Author:
morris
Message:

Add NSData convenience method for loading using NSURLConnection

Specify parent directory as referer when loading from the web

Files:

Legend:

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

    r2948 r2959  
    2727 */ 
    2828 
     29#import "NSData-FHAdditions.h" 
    2930#import "NSImage-FHAdditions.h" 
    3031#import "FHImage.h" 
     
    3233@interface FHImage(Private) 
    3334 
     35- (BOOL)_initImageWithData:(NSData *)data; 
     36 
     37         
    3438static BOOL                             FHImageUseCGImage = YES; 
    3539 
     
    5559 
    5660- (id)initImageWithURL:(ZAURL *)url { 
     61        NSData          *data; 
     62         
     63        self = [super init]; 
     64         
     65        data = [NSData dataWithContentsOfURL:url returningResponse:NULL]; 
     66         
     67        if(!data) { 
     68                [self release]; 
     69                 
     70                return NULL; 
     71        } 
     72         
     73        if(![self _initImageWithData:data]) { 
     74                [self release]; 
     75                 
     76                return NULL; 
     77        } 
     78         
     79        return self; 
     80} 
     81 
     82 
     83 
     84- (id)initImageWithURL:(ZAURL *)url preferredSize:(NSSize)size { 
    5785        self = [super init]; 
    5886         
     
    6896                } 
    6997                 
    70                 _CGImage = FHImageLoadCGImageFromSource(imageSource); 
     98                _CGImage = FHImageLoadCGImageThumbnailFromSource(imageSource, size.width); 
    7199                 
    72100                if(!_CGImage) { 
     
    81109                CFRelease(imageSource); 
    82110        } else { 
    83                 _NSImage = [[NSImage alloc] initWithContentsOfURL:[url URL]]; 
     111                _NSImage = [[NSImage alloc] initWithJPEGFile:[url path] preferredSize:size]; 
    84112                 
    85113                if(!_NSImage) { 
     
    97125 
    98126 
    99 - (id)initImageWithURL:(ZAURL *)url preferredSize:(NSSize)size { 
    100         self = [super init]; 
    101          
    102         if(FHImageUseCGImage && CGImageSourceCreateWithURL != NULL) { 
    103                 CGImageSourceRef        imageSource; 
    104                  
    105                 imageSource = CGImageSourceCreateWithURL((CFURLRef) [url URL], NULL); 
    106                  
    107                 if(!imageSource) { 
    108                         [self release]; 
    109                          
    110                         return NULL; 
    111                 } 
    112                  
    113                 _CGImage = FHImageLoadCGImageThumbnailFromSource(imageSource, size.width); 
    114                  
    115                 if(!_CGImage) { 
    116                         [self release]; 
    117                         CFRelease(imageSource); 
    118                          
    119                         return NULL; 
    120                 } 
    121                  
    122                 _size = NSMakeSize(CGImageGetWidth(_CGImage), CGImageGetHeight(_CGImage)); 
    123                  
    124                 CFRelease(imageSource); 
    125         } else { 
    126                 _NSImage = [[NSImage alloc] initWithJPEGFile:[url path] preferredSize:size]; 
    127                  
    128                 if(!_NSImage) { 
    129                         [self release]; 
    130                          
    131                         return NULL; 
    132                 } 
    133                  
    134                 _size = [_NSImage size]; 
    135         } 
    136          
    137         return self; 
    138 } 
    139  
    140  
    141  
    142127- (id)initImageWithData:(NSData *)data { 
    143128        self = [super init]; 
    144129         
     130        if(![self _initImageWithData:data]) { 
     131                [self release]; 
     132                 
     133                return NULL; 
     134        } 
     135         
     136        return self; 
     137} 
     138 
     139 
     140 
     141- (BOOL)_initImageWithData:(NSData *)data { 
    145142        if(FHImageUseCGImage && CGImageSourceCreateWithData != NULL) { 
    146143                CGImageSourceRef        imageSource; 
     
    148145                imageSource = CGImageSourceCreateWithData((CFDataRef) data, NULL); 
    149146                 
    150                 if(!imageSource) { 
    151                         [self release]; 
    152                          
    153                         return NULL; 
    154                 } 
    155                  
     147                if(!imageSource) 
     148                        return NO; 
     149 
    156150                _CGImage = FHImageLoadCGImageFromSource(imageSource); 
    157151                 
    158152                if(!_CGImage) { 
    159                         [self release]; 
    160153                        CFRelease(imageSource); 
    161154                         
    162                         return NULL
     155                        return NO
    163156                } 
    164157                 
     
    169162                _NSImage = [[NSImage alloc] initWithData:data]; 
    170163                 
    171                 if(!_NSImage) { 
    172                         [self release]; 
    173                          
    174                         return NULL; 
    175                 } 
     164                if(!_NSImage) 
     165                        return NO; 
    176166                 
    177167                _size = [_NSImage size]; 
    178168        } 
    179169         
    180         return self
     170        return YES
    181171} 
    182172 
  • Footagehead/trunk/FHURLHandler.m

    r2948 r2959  
    2727 */ 
    2828 
     29#import "NSData-FHAdditions.h" 
    2930#import "FHURLHandler.h" 
    3031#import "FHFeedHandler.h" 
     
    6667 
    6768- (id)initHandlerWithURL:(ZAURL *)url { 
    68         NSURLRequest    *request; 
    6969        NSURLResponse   *response; 
    7070        NSData                  *data; 
     
    8080        } 
    8181 
    82         request = [NSURLRequest requestWithURL:[url URL]]; 
    83         data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:NULL]; 
     82        data = [NSData dataWithContentsOfURL:url returningResponse:&response]; 
     83         
     84        if(!data) 
     85                return NULL; 
     86 
    8487        mime = [response MIMEType]; 
    8588         
  • Footagehead/trunk/Footagehead.xcodeproj/project.pbxproj

    r2955 r2959  
    134134                A53901F40596A3E7000FBFD6 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A53901F30596A3E7000FBFD6 /* Carbon.framework */; }; 
    135135                A54BD5420566834700E3ACBC /* FHFullscreenWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = A54BD5400566834700E3ACBC /* FHFullscreenWindow.m */; }; 
     136                A570FD9F0863661300317D0F /* NSData-FHAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = A570FD9D0863661300317D0F /* NSData-FHAdditions.m */; }; 
    136137                A583338E069E30D100D6A96D /* Reload.tiff in Resources */ = {isa = PBXBuildFile; fileRef = A583338D069E30D100D6A96D /* Reload.tiff */; }; 
    137138                A587DF71055AA3C4005D2097 /* Delete.tiff in Resources */ = {isa = PBXBuildFile; fileRef = A587DF6E055AA3C4005D2097 /* Delete.tiff */; }; 
     
    204205                        containerPortal = 77396B390857A18300058AF5 /* ZankaAdditions.xcodeproj */; 
    205206                        proxyType = 2; 
    206                         remoteGlobalIDString = 8DC2EF5B0486A6940098B216 /* ZankaAdditions.framework */
     207                        remoteGlobalIDString = 8DC2EF5B0486A6940098B216
    207208                        remoteInfo = "Zanka Additions"; 
    208209                }; 
     
    211212                        containerPortal = 77396B390857A18300058AF5 /* ZankaAdditions.xcodeproj */; 
    212213                        proxyType = 2; 
    213                         remoteGlobalIDString = A5E4B39E07A9797200BD6812 /* ZAAutoreleasePool Test.app */
     214                        remoteGlobalIDString = A5E4B39E07A9797200BD6812
    214215                        remoteInfo = "ZAAutoreleasePool Test"; 
    215216                }; 
     
    218219                        containerPortal = 77396B390857A18300058AF5 /* ZankaAdditions.xcodeproj */; 
    219220                        proxyType = 2; 
    220                         remoteGlobalIDString = A553B5E007AAF56E005EE3E5 /* ZANotificationCenter Test.app */
     221                        remoteGlobalIDString = A553B5E007AAF56E005EE3E5
    221222                        remoteInfo = "ZANotificationCenter Test"; 
    222223                }; 
     
    225226                        containerPortal = 77396B390857A18300058AF5 /* ZankaAdditions.xcodeproj */; 
    226227                        proxyType = 2; 
    227                         remoteGlobalIDString = A5E4B55207A98AEE00BD6812 /* ZAObject Test.app */
     228                        remoteGlobalIDString = A5E4B55207A98AEE00BD6812
    228229                        remoteInfo = "ZAObject Test"; 
    229230                }; 
     
    232233                        containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */; 
    233234                        proxyType = 1; 
    234                         remoteGlobalIDString = 77512CE50862CF78002757A8 /* Zanka Additions */
     235                        remoteGlobalIDString = 77512CE50862CF78002757A8
    235236                        remoteInfo = "Zanka Additions"; 
    236237                }; 
     
    239240                        containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */; 
    240241                        proxyType = 1; 
    241                         remoteGlobalIDString = 77512F3C0862D69D002757A8 /* libjpeg */
     242                        remoteGlobalIDString = 77512F3C0862D69D002757A8
    242243                        remoteInfo = libjpeg; 
    243244                }; 
     
    358359                A54BD5410566834700E3ACBC /* FHFullscreenWindow.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = FHFullscreenWindow.h; sourceTree = "<group>"; }; 
    359360                A54D2E8D076214FC00227EBE /* ZankaAdditions.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ZankaAdditions.framework; path = ../ZankaAdditions/build/ZankaAdditions.framework; sourceTree = SOURCE_ROOT; }; 
     361                A570FD9C0863661300317D0F /* NSData-FHAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData-FHAdditions.h"; sourceTree = "<group>"; }; 
     362                A570FD9D0863661300317D0F /* NSData-FHAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData-FHAdditions.m"; sourceTree = "<group>"; }; 
    360363                A583338D069E30D100D6A96D /* Reload.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = Reload.tiff; sourceTree = "<group>"; }; 
    361364                A587DF6E055AA3C4005D2097 /* Delete.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = Delete.tiff; sourceTree = "<group>"; }; 
     
    661664                                770EBFC3083C94CE0094BD6C /* NSBitmapImageRep-FHAdditions.m */, 
    662665                                770EBFC2083C94CE0094BD6C /* NSBitmapImageRep-FHAdditions.h */, 
     666                                A570FD9D0863661300317D0F /* NSData-FHAdditions.m */, 
     667                                A570FD9C0863661300317D0F /* NSData-FHAdditions.h */, 
    663668                                775BA4F0075F70ED00F0941E /* NSImage-FHAdditions.m */, 
    664669                                775BA4EF075F70ED00F0941E /* NSImage-FHAdditions.h */, 
     
    974979                                77EAC0D5084C6D1F006C9F69 /* FHFlickrHandler.m in Sources */, 
    975980                                77494704085A57F600BA0915 /* FHImage.m in Sources */, 
     981                                A570FD9F0863661300317D0F /* NSData-FHAdditions.m in Sources */, 
    976982                        ); 
    977983                        runOnlyForDeploymentPostprocessing = 0; 
     
    10501056                                COPY_PHASE_STRIP = NO; 
    10511057                                GCC_GENERATE_DEBUGGING_SYMBOLS = YES; 
    1052                                 OPTIMIZATION_CFLAGS = ""; 
     1058                                OPTIMIZATION_CFLAGS = "-O0"; 
    10531059                                OTHER_CFLAGS = ""; 
    10541060                                OTHER_LDFLAGS = ""; 
     
    10671073                        isa = XCBuildConfiguration; 
    10681074                        buildSettings = { 
    1069                                 OPTIMIZATION_CFLAGS = ""; 
     1075                                OPTIMIZATION_CFLAGS = "-O0"; 
    10701076                                OTHER_CFLAGS = ""; 
    10711077                                OTHER_LDFLAGS = ""; 
     
    10861092                                COPY_PHASE_STRIP = YES; 
    10871093                                GCC_GENERATE_DEBUGGING_SYMBOLS = NO; 
    1088                                 OPTIMIZATION_CFLAGS = ""; 
     1094                                OPTIMIZATION_CFLAGS = "-O0"; 
    10891095                                OTHER_CFLAGS = ""; 
    10901096                                OTHER_LDFLAGS = "";