BathyScapheで画像のインラインプレビューを可能にするプラグイン
修訂 | 308f3a19d0af4a2444d7bbe35dc1a600bffbbaeb (tree) |
---|---|
時間 | 2012-05-18 20:46:22 |
作者 | masakih <masakih@user...> |
Commiter | masakih |
[Mod] サムネイルをキャッシュするように変更
@@ -441,7 +441,7 @@ const NSUInteger alreadyPreviewed = NSNotFound - 1; | ||
441 | 441 | - (NSImage *)downloadImageURL:(NSURL *)imageURL |
442 | 442 | { |
443 | 443 | NSImage *cachedImage = [cache objectForKey:[self cacheKeyForURL:imageURL]]; |
444 | - if(cachedImage) return [self fitImage:cachedImage toSize:[self previewSize]];; | |
444 | + if(cachedImage) return cachedImage; | |
445 | 445 | |
446 | 446 | NSURLRequest *req; |
447 | 447 |
@@ -457,24 +457,27 @@ const NSUInteger alreadyPreviewed = NSNotFound - 1; | ||
457 | 457 | error:&err]; |
458 | 458 | if(err) { |
459 | 459 | NSLog(@"Fail download. reason(%@)", [err localizedDescription]); |
460 | - return [self notFoundImage]; | |
460 | + goto notFound; | |
461 | 461 | } |
462 | 462 | if(res) { |
463 | 463 | if(![[res MIMEType] hasPrefix:@"image/"]) { |
464 | 464 | NSLog(@"Fail download. reason(target type is %@)", [res MIMEType]); |
465 | - return [self notFoundImage]; | |
465 | + goto notFound; | |
466 | 466 | } |
467 | 467 | } |
468 | 468 | |
469 | 469 | NSImage *image = [[[NSImage alloc] initWithData:imageData] autorelease]; |
470 | 470 | if(!image) { |
471 | 471 | NSLog(@"Can not create image."); |
472 | - return [self notFoundImage]; | |
472 | + goto notFound; | |
473 | 473 | } |
474 | 474 | |
475 | - [cache setObject:image forKey:[self cacheKeyForURL:imageURL]]; | |
476 | - | |
477 | - return [self fitImage:image toSize:[self previewSize]]; | |
475 | + cachedImage = [self fitImage:image toSize:[self previewSize]]; | |
476 | + [cache setObject:cachedImage forKey:[self cacheKeyForURL:imageURL]]; | |
477 | + return cachedImage; | |
478 | +notFound: | |
479 | + [cache setObject:[self notFoundImage] forKey:[self cacheKeyForURL:imageURL]]; | |
480 | + return [self notFoundImage]; | |
478 | 481 | } |
479 | 482 | |
480 | 483 | @end |