@end
-@interface BrowserViewActualView : UIView {
+@interface BrowserView : UIView {
@private
UIWebDocumentView *documentView;
}
@property (nonatomic, retain) UIWebDocumentView *documentView;
@end
-@implementation BrowserViewActualView
+@implementation BrowserView
@synthesize documentView;
#define lprintf(args...) fprintf(stderr, args)
-@implementation BrowserView
+@implementation BrowserController
#if ShowInternals
#include "UICaboodle/UCInternal.h"
- (void) dealloc {
#if LogBrowser
- NSLog(@"[BrowserView dealloc]");
+ NSLog(@"[BrowserController dealloc]");
#endif
if (challenge_ != nil)
[sensitive_ release];
if (title_ != nil)
[title_ release];
+ if (reloaditem_ != nil)
+ [reloaditem_ release];
+ if (loadingitem_ != nil)
+ [loadingitem_ release];
+
[super dealloc];
}
if ([request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil)
[self loadRequest:request_];
else {
- UIActionSheet *sheet = [[[UIActionSheet alloc]
+ UIAlertView *alert = [[[UIAlertView alloc]
initWithTitle:UCLocalize("RESUBMIT_FORM")
- buttons:[NSArray arrayWithObjects:UCLocalize("CANCEL"), UCLocalize("SUBMIT"), nil]
- defaultButtonIndex:0
+ message:nil
delegate:self
- context:@"submit"
+ cancelButtonTitle:UCLocalize("CANCEL")
+ otherButtonTitles:UCLocalize("SUBMIT"), nil
] autorelease];
-
- [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
- [sheet setNumberOfRows:1];
- [sheet popupAlertAnimated:YES];
+ [alert setContext:@"submit"];
+ [alert show];
}
}
- (void) _promptForSensitive:(NSMutableArray *)array {
NSString *name([array objectAtIndex:0]);
- UIActionSheet *sheet = [[[UIActionSheet alloc]
+ UIAlertView *alert = [[[UIAlertView alloc]
initWithTitle:nil
- buttons:[NSArray arrayWithObjects:UCLocalize("YES"), UCLocalize("NO"), nil]
- defaultButtonIndex:0
+ message:nil
delegate:indirect_
- context:@"sensitive"
+ cancelButtonTitle:UCLocalize("NO")
+ otherButtonTitles:UCLocalize("YES"), nil
] autorelease];
- [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
NSString *host(@"XXX");
- [sheet setNumberOfRows:1];
- [sheet setBodyText:[NSString stringWithFormat:@"The website at %@ is requesting your phone's %@. This is almost certainly for product licensing purposes. Will you allow this?", host, name]];
- [sheet popupAlertAnimated:YES];
+ [alert setContext:@"sensitive"];
+ [alert setMessage:[NSString stringWithFormat:@"The website at %@ is requesting your phone's %@. This is almost certainly for product licensing purposes. Will you allow this?", host, name]];
+ [alert show];
NSRunLoop *loop([NSRunLoop currentRunLoop]);
NSDate *future([NSDate distantFuture]);
return;
[self retain];
- UIActionSheet *sheet = [[[UIActionSheet alloc]
+ UIAlertView *alert = [[[UIAlertView alloc]
initWithTitle:nil
- buttons:[NSArray arrayWithObjects:UCLocalize("OK"), nil]
- defaultButtonIndex:0
+ message:message
delegate:self
- context:@"alert"
+ cancelButtonTitle:UCLocalize("OK")
+ otherButtonTitles:nil
] autorelease];
-
- [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
- [sheet setBodyText:message];
- [sheet popupAlertAnimated:YES];
+ [alert setContext:@"alert"];
+ [alert show];
}
- (BOOL) webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
return NO;
[self retain];
- UIActionSheet *sheet = [[[UIActionSheet alloc]
+ UIAlertView *alert = [[[UIAlertView alloc]
initWithTitle:nil
- buttons:[NSArray arrayWithObjects:UCLocalize("OK"), UCLocalize("CANCEL"), nil]
- defaultButtonIndex:0
+ message:message
delegate:indirect_
- context:@"confirm"
+ cancelButtonTitle:UCLocalize("CANCEL")
+ otherButtonTitles:UCLocalize("OK"), nil
] autorelease];
- [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
- [sheet setNumberOfRows:1];
- [sheet setBodyText:message];
- [sheet popupAlertAnimated:YES];
+ [alert setContext:@"confirm"];
+ [alert show];
NSRunLoop *loop([NSRunLoop currentRunLoop]);
NSDate *future([NSDate distantFuture]);
[function_ autorelease];
function_ = function == nil ? nil : [function retain];
- [self reloadButtons];
+ [self applyRightButton];
}
- (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
[function_ autorelease];
function_ = function == nil ? nil : [function retain];
- [self reloadButtons];
+ [self applyRightButton];
}
- (void) setFinishHook:(id)function {
if (page == nil) {
/* XXX: call createWebViewWithRequest instead? */
- BrowserView *browser([[[class_ alloc] init] autorelease]);
+ BrowserController *browser([[[class_ alloc] init] autorelease]);
[browser loadURL:url];
page = browser;
}
//lprintf("Status:%s\n", [text UTF8String]);
}
-- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
- NSString *context([sheet context]);
+- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
+ NSString *context([alert context]);
if ([context isEqualToString:@"alert"]) {
[self autorelease];
- [sheet dismiss];
+ [alert dismissWithClickedButtonIndex:-1 animated:YES];
} else if ([context isEqualToString:@"confirm"]) {
switch (button) {
case 1:
break;
}
- [sheet dismiss];
+ [alert dismissWithClickedButtonIndex:-1 animated:YES];
} else if ([context isEqualToString:@"sensitive"]) {
switch (button) {
case 1:
break;
}
- [sheet dismiss];
+ [alert dismissWithClickedButtonIndex:-1 animated:YES];
} else if ([context isEqualToString:@"challenge"]) {
id<NSURLAuthenticationChallengeSender> sender([challenge_ sender]);
switch (button) {
case 1: {
- NSString *username([[sheet textFieldAtIndex:0] text]);
- NSString *password([[sheet textFieldAtIndex:1] text]);
+ NSString *username([[alert textFieldAtIndex:0] text]);
+ NSString *password([[alert textFieldAtIndex:1] text]);
NSURLCredential *credential([NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession]);
[challenge_ release];
challenge_ = nil;
- [sheet dismiss];
+ [alert dismissWithClickedButtonIndex:-1 animated:YES];
} else if ([context isEqualToString:@"submit"]) {
switch (button) {
case 1:
_nodefault
}
- [sheet dismiss];
+ [alert dismissWithClickedButtonIndex:-1 animated:YES];
}
}
if (realm == nil)
realm = @"";
- UIActionSheet *sheet = [[[UIActionSheet alloc]
+ UIAlertView *alert = [[[UIAlertView alloc]
initWithTitle:realm
- buttons:[NSArray arrayWithObjects:UCLocalize("LOGIN"), UCLocalize("CANCEL"), nil]
- defaultButtonIndex:0
+ message:nil
delegate:self
- context:@"challenge"
+ cancelButtonTitle:UCLocalize("CANCEL")
+ otherButtonTitles:UCLocalize("LOGIN"), nil
] autorelease];
- [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+ [alert setContext:@"challenge"];
+ [alert setNumberOfRows:1];
- [sheet setNumberOfRows:1];
+ [alert addTextFieldWithValue:@"" label:UCLocalize("USERNAME")];
+ [alert addTextFieldWithValue:@"" label:UCLocalize("PASSWORD")];
- [sheet addTextFieldWithValue:@"" label:UCLocalize("USERNAME")];
- [sheet addTextFieldWithValue:@"" label:UCLocalize("PASSWORD")];
-
- UITextField *username([sheet textFieldAtIndex:0]); {
+ UITextField *username([alert textFieldAtIndex:0]); {
UITextInputTraits *traits([username textInputTraits]);
[traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[traits setAutocorrectionType:UITextAutocorrectionTypeNo];
[traits setReturnKeyType:UIReturnKeyNext];
}
- UITextField *password([sheet textFieldAtIndex:1]); {
+ UITextField *password([alert textFieldAtIndex:1]); {
UITextInputTraits *traits([password textInputTraits]);
[traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[traits setAutocorrectionType:UITextAutocorrectionTypeNo];
[traits setSecureTextEntry:YES];
}
- [sheet popupAlertAnimated:YES];
+ [alert show];
}
- (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source {
UCNavigationController *navigation(!popup_ ? [self navigationController] : [[[UCNavigationController alloc] init] autorelease]);
/* XXX: deal with cydia:// pages */
- BrowserView *browser([[[class_ alloc] initWithWidth:width] autorelease]);
+ BrowserController *browser([[[class_ alloc] initWithWidth:width] autorelease]);
if (features != nil && popup_) {
[navigation setDelegate:delegate_];
}
}
- [self reloadButtons];
+ [self _startLoading];
}
-- (void) didFinishLoading { }
+- (UINavigationButtonStyle) rightButtonStyle {
+ if (style_ == nil) normal:
+ return UINavigationButtonStyleNormal;
+ else if ([style_ isEqualToString:@"Normal"])
+ return UINavigationButtonStyleNormal;
+ else if ([style_ isEqualToString:@"Back"])
+ return UINavigationButtonStyleBack;
+ else if ([style_ isEqualToString:@"Highlighted"])
+ return UINavigationButtonStyleHighlighted;
+ else if ([style_ isEqualToString:@"Destructive"])
+ return UINavigationButtonStyleDestructive;
+ else goto normal;
+}
+
+- (UIBarButtonItem *) customButton {
+ UIBarButtonItem *customItem = [[UIBarButtonItem alloc]
+ initWithTitle:button_
+ style:[self rightButtonStyle]
+ target:self
+ action:@selector(customButtonClicked)
+ ];
+
+ return [customItem autorelease];
+}
+
+- (void) applyLoadingTitle {
+ [[self navigationItem] setTitle:UCLocalize("LOADING")];
+}
+
+- (void) applyRightButton {
+ if ([self isLoading]) {
+ [[self navigationItem] setRightBarButtonItem:loadingitem_ animated:YES];
+ [[loadingitem_ view] addSubview:indicator_];
+ [self applyLoadingTitle];
+ } else if (button_) {
+ [[self navigationItem] setRightBarButtonItem:[self customButton] animated:YES];
+ } else {
+ [[self navigationItem] setRightBarButtonItem:reloaditem_ animated:YES];
+ }
+}
+
+- (void) _startLoading {
+ [self applyRightButton];
+}
- (void) _finishLoading {
size_t count([loading_ count]);
if (finish_ != nil)
[self callFunction:finish_];
- [self reloadButtons];
+ [self applyRightButton];
+ if (![self isLoading]) [[self navigationItem] setTitle:title_];
}
- (bool) isLoading {
loading_ = [[NSMutableSet alloc] initWithCapacity:3];
popup_ = false;
- BrowserViewActualView *actualView = [[BrowserViewActualView alloc] initWithFrame:CGRectZero];
+ BrowserView *actualView = [[BrowserView alloc] initWithFrame:CGRectZero];
[self setView:actualView];
struct CGRect bounds = [[self view] bounds];
indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(15, 5, indsize.width, indsize.height)];
[indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
[indicator_ startAnimation];
+
+ reloaditem_ = [[UIBarButtonItem alloc]
+ initWithTitle:UCLocalize("RELOAD")
+ style:[self rightButtonStyle]
+ target:self
+ action:@selector(reloadButtonClicked)
+ ];
+
+ loadingitem_ = [[UIBarButtonItem alloc]
+ initWithTitle:@" "
+ style:UIBarButtonItemStylePlain
+ target:self
+ action:@selector(reloadButtonClicked)
+ ];
+ [[loadingitem_ view] addSubview:indicator_];
[scroller_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
[self callFunction:closer_];
}
-- (void) __rightButtonClicked {
+- (void) reloadButtonClicked {
reloading_ = true;
[self reloadURL];
}
-- (void) _rightButtonClicked {
+- (void) customButtonClicked {
#if !AlwaysReload
if (function_ != nil)
[self callFunction:function_];
else
#endif
- [self __rightButtonClicked];
-}
-
-- (UINavigationButtonStyle) rightButtonStyle {
- if (style_ == nil) normal:
- return UINavigationButtonStyleNormal;
- else if ([style_ isEqualToString:@"Normal"])
- return UINavigationButtonStyleNormal;
- else if ([style_ isEqualToString:@"Back"])
- return UINavigationButtonStyleBack;
- else if ([style_ isEqualToString:@"Highlighted"])
- return UINavigationButtonStyleHighlighted;
- else if ([style_ isEqualToString:@"Destructive"])
- return UINavigationButtonStyleDestructive;
- else goto normal;
-}
-
-- (void) reloadButtons {
- if ([self isLoading]) {
- UIBarButtonItem *reloadItem = [[UIBarButtonItem alloc]
- initWithTitle:@" "
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(_rightButtonClicked)
- ];
- [[self navigationItem] setRightBarButtonItem:reloadItem];
- [[reloadItem view] addSubview:indicator_];
- [[self navigationItem] setTitle:UCLocalize("LOADING")];
- [reloadItem release];
- } else {
- UIBarButtonItem *reloadItem = [[UIBarButtonItem alloc]
- initWithTitle:button_ ?: UCLocalize("RELOAD")
- style:[self rightButtonStyle]
- target:self
- action:@selector(_rightButtonClicked)
- ];
- [[self navigationItem] setRightBarButtonItem:reloadItem animated:YES];
- [[self navigationItem] setTitle:title_];
- [reloadItem release];
-
- if (function_ == nil) [self didFinishLoading];
- }
+ [self reloadButtonClicked];
}
- (void) setPageActive:(BOOL)active {