]> git.saurik.com Git - cydia.git/blobdiff - UICaboodle/BrowserView.mm
more browserview/cydia
[cydia.git] / UICaboodle / BrowserView.mm
index 4523f91b37226c0269db9f31a3605fa95605609f..dbdc8f418045b3de8419e3d427bba7a3711b9eb4 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];
 }
 
@@ -555,7 +560,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 +576,7 @@ static Class $UIWebBrowserView;
         [function_ autorelease];
     function_ = function == nil ? nil : [function retain];
 
-       [self reloadButtons];
+       [self applyRightButton];
 }
 
 - (void) setFinishHook:(id)function {
@@ -645,7 +650,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;
                 }
@@ -914,7 +919,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 +1036,52 @@ static Class $UIWebBrowserView;
         }
     }
 
-       [self reloadButtons];
+       [self _startLoading];
+}
+
+- (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) didFinishLoading { }
+- (void) applyLoadingTitle {
+    [[self navigationItem] setTitle:UCLocalize("LOADING")];
+}
+
+- (void) applyRightButton {
+       if ([self isLoading]) {
+           [[self navigationItem] setRightBarButtonItem:loadingitem_ animated:YES];
+        [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 +1092,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 +1330,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 +1486,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 +1565,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 {