// // ChildBrowserViewController.m // // Created by Jesse MacFadyen on 21/07/09. // Copyright 2009 Nitobi. All rights reserved. // #import "ChildBrowserViewController.h" @implementation ChildBrowserViewController @synthesize imageURL; @synthesize supportedOrientations; @synthesize isImage; @synthesize delegate; /* // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization } return self; } */ - (ChildBrowserViewController*)initWithScale:(BOOL)enabled { self = [super init]; scaleEnabled = enabled; return self; } // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; webView.delegate = self; webView.scalesPageToFit = TRUE; webView.backgroundColor = [UIColor whiteColor]; NSLog(@"View did load",@""); } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; NSLog(@"View did UN-load",@""); } - (void)dealloc { webView.delegate = nil; [webView release]; [closeBtn release]; [refreshBtn release]; [addressLabel release]; [backBtn release]; [fwdBtn release]; [safariBtn release]; [spinner release]; [ supportedOrientations release]; [super dealloc]; } -(void)closeBrowser { if(delegate != NULL) { [delegate onClose]; } [ [super parentViewController] dismissModalViewControllerAnimated:YES]; } -(IBAction) onDoneButtonPress:(id)sender { [ self closeBrowser]; } -(IBAction) onSafariButtonPress:(id)sender { if(delegate != NULL) { [delegate onOpenInSafari]; } if(isImage) { NSURL* pURL = [ [NSURL alloc] initWithString:imageURL ]; [ [ UIApplication sharedApplication ] openURL:pURL ]; } else { NSURLRequest *request = webView.request; [[UIApplication sharedApplication] openURL:request.URL]; } } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { BOOL autoRotate = [self.supportedOrientations count] > 1; // autorotate if only more than 1 orientation supported if (autoRotate) { if ([self.supportedOrientations containsObject: [NSNumber numberWithInt:interfaceOrientation]]) { return YES; } } return NO; } - (void)loadURL:(NSString*)url { NSLog(@"Opening Url : %@",url); if( [url hasSuffix:@".png" ] || [url hasSuffix:@".jpg" ] || [url hasSuffix:@".jpeg" ] || [url hasSuffix:@".bmp" ] || [url hasSuffix:@".gif" ] ) { [ imageURL release ]; imageURL = [url copy]; isImage = YES; NSString* htmlText = @"