]> git.saurik.com Git - cydia.git/blobdiff - UICaboodle/BrowserView.mm
self isn't even initialized, why are we trying to get our own view?
[cydia.git] / UICaboodle / BrowserView.mm
index 4523f91b37226c0269db9f31a3605fa95605609f..5fa21e169094275ad80ee2a04a9ccfe85c5d9dfa 100644 (file)
@@ -148,14 +148,14 @@ static Class $UIWebBrowserView;
 
 @end
 
-@interface BrowserViewActualView : UIView {
+@interface BrowserView : UIView {
 @private
     UIWebDocumentView *documentView;
 }
 @property (nonatomic, retain) UIWebDocumentView *documentView;
 @end
 
-@implementation BrowserViewActualView
+@implementation BrowserView
 
 @synthesize documentView;
 
@@ -177,7 +177,7 @@ static Class $UIWebBrowserView;
 
 #define lprintf(args...) fprintf(stderr, args)
 
-@implementation BrowserView
+@implementation BrowserController
 
 #if ShowInternals
 #include "UICaboodle/UCInternal.h"
@@ -207,7 +207,7 @@ static Class $UIWebBrowserView;
 
 - (void) dealloc {
 #if LogBrowser
-    NSLog(@"[BrowserView dealloc]");
+    NSLog(@"[BrowserController dealloc]");
 #endif
 
     if (challenge_ != nil)
@@ -279,6 +279,11 @@ static Class $UIWebBrowserView;
         [sensitive_ release];
     if (title_ != nil)
         [title_ release];
+    if (reloaditem_ != nil)
+        [reloaditem_ release];
+    if (loadingitem_ != nil)
+        [loadingitem_ release];
+        
     [super dealloc];
 }
 
@@ -310,18 +315,15 @@ static Class $UIWebBrowserView;
     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];
     }
 }
 
@@ -443,21 +445,19 @@ static Class $UIWebBrowserView;
 - (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]);
@@ -487,18 +487,15 @@ static Class $UIWebBrowserView;
         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 {
@@ -506,19 +503,16 @@ static Class $UIWebBrowserView;
         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]);
@@ -555,7 +549,7 @@ static Class $UIWebBrowserView;
         [function_ autorelease];
     function_ = function == nil ? nil : [function retain];
 
-       [self reloadButtons];
+       [self applyRightButton];
 }
 
 - (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
@@ -571,7 +565,7 @@ static Class $UIWebBrowserView;
         [function_ autorelease];
     function_ = function == nil ? nil : [function retain];
 
-       [self reloadButtons];
+       [self applyRightButton];
 }
 
 - (void) setFinishHook:(id)function {
@@ -645,7 +639,7 @@ static Class $UIWebBrowserView;
                 if (page == nil) {
                     /* XXX: call createWebViewWithRequest instead? */
 
-                    BrowserView *browser([[[class_ alloc] init] autorelease]);
+                    BrowserController *browser([[[class_ alloc] init] autorelease]);
                     [browser loadURL:url];
                     page = browser;
                 }
@@ -779,12 +773,12 @@ static Class $UIWebBrowserView;
     //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:
@@ -796,7 +790,7 @@ static Class $UIWebBrowserView;
             break;
         }
 
-        [sheet dismiss];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
     } else if ([context isEqualToString:@"sensitive"]) {
         switch (button) {
             case 1:
@@ -808,14 +802,14 @@ static Class $UIWebBrowserView;
             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]);
 
@@ -832,7 +826,7 @@ static Class $UIWebBrowserView;
         [challenge_ release];
         challenge_ = nil;
 
-        [sheet dismiss];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
     } else if ([context isEqualToString:@"submit"]) {
         switch (button) {
             case 1:
@@ -849,7 +843,7 @@ static Class $UIWebBrowserView;
             _nodefault
         }
 
-        [sheet dismiss];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
     }
 }
 
@@ -861,22 +855,21 @@ static Class $UIWebBrowserView;
     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];
@@ -884,7 +877,7 @@ static Class $UIWebBrowserView;
         [traits setReturnKeyType:UIReturnKeyNext];
     }
 
-    UITextField *password([sheet textFieldAtIndex:1]); {
+    UITextField *password([alert textFieldAtIndex:1]); {
         UITextInputTraits *traits([password textInputTraits]);
         [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
         [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
@@ -894,7 +887,7 @@ static Class $UIWebBrowserView;
         [traits setSecureTextEntry:YES];
     }
 
-    [sheet popupAlertAnimated:YES];
+    [alert show];
 }
 
 - (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source {
@@ -914,7 +907,7 @@ static Class $UIWebBrowserView;
     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_];
@@ -1031,10 +1024,53 @@ static Class $UIWebBrowserView;
         }
     }
 
-       [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]);
@@ -1045,7 +1081,8 @@ static Class $UIWebBrowserView;
     if (finish_ != nil)
         [self callFunction:finish_];
 
-       [self reloadButtons];
+       [self applyRightButton];
+       if (![self isLoading]) [[self navigationItem] setTitle:title_];
 }
 
 - (bool) isLoading {
@@ -1282,7 +1319,7 @@ static Class $UIWebBrowserView;
         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];
@@ -1438,6 +1475,21 @@ static Class $UIWebBrowserView;
         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];
@@ -1502,59 +1554,18 @@ static Class $UIWebBrowserView;
         [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 {