Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 9e6d250defc1671363b4e61b5eed1cacddf730c1 @dmpatierno dmpatierno committed Dec 13, 2010
Showing with 10,694 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +27 −0 Classes/BGNetRequest.h
  3. +33 −0 Classes/BGNetRequest.m
  4. +32 −0 Classes/CachedImageLoader.h
  5. +196 −0 Classes/CachedImageLoader.m
  6. +29 −0 Classes/DetailViewController.h
  7. +195 −0 Classes/DetailViewController.m
  8. +28 −0 Classes/DiskCache.h
  9. +211 −0 Classes/DiskCache.m
  10. +56 −0 Classes/Guide.h
  11. +55 −0 Classes/Guide.m
  12. +35 −0 Classes/GuideImage.h
  13. +36 −0 Classes/GuideImage.m
  14. +28 −0 Classes/GuideImageViewController.h
  15. +175 −0 Classes/GuideImageViewController.m
  16. +791 −0 Classes/GuideIntroView.xib
  17. +39 −0 Classes/GuideIntroViewController.h
  18. +148 −0 Classes/GuideIntroViewController.m
  19. +27 −0 Classes/GuideStep.h
  20. +42 −0 Classes/GuideStep.m
  21. +26 −0 Classes/GuideStepLine.h
  22. +24 −0 Classes/GuideStepLine.m
  23. +56 −0 Classes/GuideStepViewController.h
  24. +253 −0 Classes/GuideStepViewController.m
  25. +629 −0 Classes/GuideView.xib
  26. +46 −0 Classes/GuideViewController.h
  27. +299 −0 Classes/GuideViewController.m
  28. +72 −0 Classes/JSON/JSON.h
  29. +53 −0 Classes/JSON/NSObject+SBJSON.h
  30. +44 −0 Classes/JSON/NSObject+SBJSON.m
  31. +48 −0 Classes/JSON/NSString+SBJSON.h
  32. +45 −0 Classes/JSON/NSString+SBJSON.m
  33. +86 −0 Classes/JSON/SBJsonBase.h
  34. +78 −0 Classes/JSON/SBJsonBase.m
  35. +86 −0 Classes/JSON/SBJsonParser.h
  36. +516 −0 Classes/JSON/SBJsonParser.m
  37. +127 −0 Classes/JSON/SBJsonWriter.h
  38. +239 −0 Classes/JSON/SBJsonWriter.m
  39. +22 −0 Classes/MTHandler.h
  40. +24 −0 Classes/MTHandler.m
  41. +29 −0 Classes/RootViewController.h
  42. +164 −0 Classes/RootViewController.m
  43. +79 −0 Classes/TapDetectingImageView.h
  44. +96 −0 Classes/TapDetectingImageView.m
  45. +22 −0 Classes/iFixitAPI.h
  46. +103 −0 Classes/iFixitAPI.m
  47. +38 −0 Classes/iFixitAppDelegate.h
  48. +133 −0 Classes/iFixitAppDelegate.m
  49. BIN Default-Landscape.png
  50. BIN Default-Portrait.png
  51. +595 −0 DetailView.xib
  52. +12 −0 Entitlements.plist
  53. +888 −0 GuideStepView.xib
  54. +664 −0 MainWindow.xib
  55. BIN NoImage_300x225.jpg
  56. BIN NoImage_592x444.jpg
  57. +4 −0 README.md
  58. BIN back.png
  59. BIN back@2x.png
  60. BIN backarrow.png
  61. BIN backbutton.psd
  62. BIN forward.png
  63. BIN forward@2x.png
  64. +42 −0 iFixit-Info.plist
  65. +1,434 −0 iFixit.xcodeproj/dmpatierno.mode1v3
  66. +837 −0 iFixit.xcodeproj/dmpatierno.pbxuser
  67. +546 −0 iFixit.xcodeproj/project.pbxproj
  68. +34 −0 iFixit_Prefix.pch
  69. BIN icon114.png
  70. BIN icon512.png
  71. BIN icon57.png
  72. BIN icon72.png
  73. BIN logo_black.png
  74. +17 −0 main.m
@@ -0,0 +1 @@
+build
@@ -0,0 +1,27 @@
+//
+// BGNetRequest.h
+// iFixit
+//
+// Created by David Patierno on 8/6/10.
+// Copyright 2010 iFixit. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "MTHandler.h"
+
+@interface BGNetRequest : NSObject {
+
+ NSString *url;
+ NSMutableArray *handlers;
+ NSString *data;
+
+}
+
+@property (nonatomic, retain) NSString *url;
+@property (nonatomic, retain) NSString *data;
+@property (nonatomic, retain) NSMutableArray *handlers;
+
++ (BGNetRequest *)initWithUrl:(NSString *)url;
+- (void)pushHandler:(MTHandler *)handler;
+- (MTHandler *)popHandler;
+@end
@@ -0,0 +1,33 @@
+//
+// BGNetRequest.m
+// iFixit
+//
+// Created by David Patierno on 8/6/10.
+// Copyright 2010 iFixit. All rights reserved.
+//
+
+#import "BGNetRequest.h"
+
+
+@implementation BGNetRequest
+
+@synthesize url, data, handlers;
+
++ (BGNetRequest *)initWithUrl:(NSString *)url {
+ BGNetRequest *bgnr = [[BGNetRequest alloc] init];
+ bgnr.url = url;
+ bgnr.handlers = [NSMutableArray array];
+ return [bgnr autorelease];
+}
+
+- (void)pushHandler:(MTHandler *)handler {
+ [handlers addObject:handler];
+}
+
+- (MTHandler *)popHandler {
+ MTHandler *handler = [[handlers lastObject] retain];
+ [handlers removeObject:handler];
+ return [handler autorelease];
+}
+
+@end
@@ -0,0 +1,32 @@
+//
+// CachedImageLoader.h
+// happyhours
+//
+// Created by David Golightly on 2/16/09.
+// Copyright 2009 __MyCompanyName__. All rights reserved.
+//
+
+@protocol ImageConsumer <NSObject>
+- (NSURLRequest *)request;
+- (void)renderImage:(UIImage *)image;
+@end
+
+
+@interface CachedImageLoader : NSObject {
+@private
+ NSOperationQueue *_imageDownloadQueue;
+}
+
+
++ (CachedImageLoader *)sharedImageLoader;
+
+
+- (void)addClientToDownloadQueue:(id<ImageConsumer>)client;
+- (UIImage *)cachedImageForClient:(id<ImageConsumer>)client;
+
+- (void)suspendImageDownloads;
+- (void)resumeImageDownloads;
+- (void)cancelImageDownloads;
+
+
+@end
@@ -0,0 +1,196 @@
+//
+// CachedImageLoader.m
+// happyhours
+//
+// Created by David Golightly on 2/16/09.
+// Copyright 2009 __MyCompanyName__. All rights reserved.
+//
+
+#import "CachedImageLoader.h"
+#import "DiskCache.h"
+
+const NSInteger kMaxDownloadConnections = 1;
+
+static CachedImageLoader *sharedInstance;
+
+
+@interface CachedImageLoader (Privates)
+- (void)loadImageForClient:(id<ImageConsumer>)client;
+- (BOOL)loadImageRemotelyForClient:(id<ImageConsumer>)request;
+@end
+
+
+@implementation CachedImageLoader
+
+- (void)dealloc {
+ [_imageDownloadQueue cancelAllOperations];
+ [_imageDownloadQueue release];
+
+ [super dealloc];
+}
+
+
+- (id)init {
+ if (self = [super init]) {
+ _imageDownloadQueue = [[NSOperationQueue alloc] init];
+ [_imageDownloadQueue setMaxConcurrentOperationCount:kMaxDownloadConnections];
+ }
+ return self;
+}
+
+
+- (void)addClientToDownloadQueue:(id<ImageConsumer>)client {
+ [_imageDownloadQueue setSuspended:NO];
+ NSOperation *imageDownloadOp = [[[NSInvocationOperation alloc] initWithTarget:self
+ selector:@selector(loadImageForClient:)
+ object:client] autorelease];
+ [_imageDownloadQueue addOperation:imageDownloadOp];
+}
+
+- (void)loadImageForClient:(id<ImageConsumer>)client {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ UIImage *cachedImage = [self cachedImageForClient:client];
+
+ if (cachedImage) {
+ [client renderImage:cachedImage];
+
+ } else if (![self loadImageRemotelyForClient:client]) {
+ // DLog(@"image download failed, trying again: %@", client);
+ [self addClientToDownloadQueue:client];
+ }
+
+ [pool release];
+}
+
+
+- (void)suspendImageDownloads {
+ [_imageDownloadQueue setSuspended:YES];
+}
+
+
+- (void)resumeImageDownloads {
+ [_imageDownloadQueue setSuspended:NO];
+}
+
+
+- (void)cancelImageDownloads {
+ [_imageDownloadQueue cancelAllOperations];
+}
+
+
+- (UIImage *)cachedImageForClient:(id<ImageConsumer>)client {
+ NSData *imageData = nil;
+ UIImage *image = nil;
+
+ NSURLRequest *request = [client request];
+ NSCachedURLResponse *cachedResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:request];
+
+ if (cachedResponse) {
+ // DLog(@"found cached image data for %@", [request URL]);
+ imageData = [cachedResponse data];
+ image = [UIImage imageWithData:imageData];
+ }
+
+ if (image == nil &&
+ (imageData = [[DiskCache sharedCache] imageDataInCacheForURLString:[[request URL] absoluteString]])) {
+ NSURLResponse *response = [[[NSURLResponse alloc] initWithURL:[request URL]
+ MIMEType:@"image/jpeg"
+ expectedContentLength:[imageData length]
+ textEncodingName:nil]
+ autorelease];
+ [[DiskCache sharedCache] cacheImageData:imageData
+ request:request
+ response:response];
+ image = [UIImage imageWithData:imageData];
+ }
+
+ // if (image == nil) {
+ // DLog(@"unable to find image data in cache: %@", request);
+ // }
+
+ return image;
+}
+
+
+- (BOOL)loadImageRemotelyForClient:(id<ImageConsumer>)client {
+ // DLog(@"loading image data remotely for %@", [self imageURL]);
+ NSURLResponse *response = nil;
+ NSError *error = nil;
+
+
+ NSURLRequest *request = [client request];
+ if (!request)
+ return YES;
+
+ NSData *imageData = [NSURLConnection sendSynchronousRequest:request
+ returningResponse:&response
+ error:&error];
+
+ if (error != nil) {
+ DLog(@"ERROR RETRIEVING IMAGE at %@: %@", request, error);
+ DLog(@"User info: %@", [error userInfo]);
+ if ([[error userInfo] objectForKey:NSUnderlyingErrorKey]) {
+ DLog(@"underlying error info: %@", [[[error userInfo] objectForKey:NSUnderlyingErrorKey] userInfo]);
+ }
+
+ NSInteger code = [error code];
+ if (code == NSURLErrorUnsupportedURL ||
+ code == NSURLErrorBadURL ||
+ code == NSURLErrorBadServerResponse ||
+ code == NSURLErrorRedirectToNonExistentLocation ||
+ code == NSURLErrorFileDoesNotExist ||
+ code == NSURLErrorFileIsDirectory ||
+ code == NSURLErrorRedirectToNonExistentLocation) {
+ // the above status codes are permanent fatal errors;
+ // don't retry
+ return YES;
+ }
+ [error autorelease];
+
+ } else if (imageData != nil && response != nil) {
+ [[DiskCache sharedCache] cacheImageData:imageData
+ request:request
+ response:response];
+
+ UIImage *image = [UIImage imageWithData:imageData];
+ if (image == nil) {
+ // DLog(@"removing image data for: %@", [client request]);
+ [[DiskCache sharedCache] clearCachedDataForRequest:[client request]];
+ } else {
+ [client renderImage:image];
+ return YES;
+ }
+
+ } else {
+ DLog(@"Unknown error retrieving image %@ (response is null)", request);
+ }
+ return NO;
+}
+
+
+#pragma mark
+#pragma mark ---- singleton implementation ----
+
++ (CachedImageLoader *)sharedImageLoader {
+ @synchronized(self) {
+ if (sharedInstance == nil) {
+ [[self alloc] init]; // assignment not done here
+ }
+ }
+ return sharedInstance;
+}
+
+
++ (id)allocWithZone:(NSZone *)zone {
+ @synchronized(self) {
+ if (sharedInstance == nil) {
+ sharedInstance = [super allocWithZone:zone];
+ return sharedInstance; // assignment and return on first allocation
+ }
+ }
+ return nil; // on subsequent allocation attempts return nil
+}
+
+
+@end
@@ -0,0 +1,29 @@
+//
+// DetailViewController.h
+// iFixit
+//
+// Created by David Patierno on 8/6/10.
+// Copyright iFixit 2010. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "GuideViewController.h"
+
+@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate, UIWebViewDelegate> {
+ UIPopoverController *popoverController;
+ UIToolbar *toolbar;
+
+ UIWebView *webView;
+ UIBarButtonItem *backButton;
+ UIBarButtonItem *fwdButton;
+}
+
+@property (nonatomic, retain) IBOutlet UIToolbar *toolbar;
+@property (nonatomic, retain) IBOutlet UIWebView *webView;
+@property (nonatomic, retain) IBOutlet UIBarButtonItem *backButton;
+@property (nonatomic, retain) IBOutlet UIBarButtonItem *fwdButton;
+@property (nonatomic, retain) UIPopoverController *popoverController;
+
+- (NSInteger)parseGuideURL:(NSString *)url;
+
+@end
Oops, something went wrong.

0 comments on commit 9e6d250

Please sign in to comment.