]> git.saurik.com Git - cydia.git/blobdiff - Cydia.mm
even more browserview/cydia; fully working now!
[cydia.git] / Cydia.mm
index 10e36da0d82fc5ae8472c2c4d37b720291c91696..f42afe3ecd8bdd5d50d44dabfe419fc6cd0335d9 100644 (file)
--- a/Cydia.mm
+++ b/Cydia.mm
@@ -342,6 +342,18 @@ static _finline NSString *CydiaURL(NSString *path) {
     } return self;
 }
 
+- (void)_updateFrameForDisplay {
+    [super _updateFrameForDisplay];
+    if ([self cancelButtonIndex] == -1) {
+        NSArray *buttons = [self buttons];
+        if ([buttons count]) {
+            UIImage *background = [[buttons objectAtIndex:0] backgroundForState:0];
+            for (UIThreePartButton *button in buttons)
+                [button setBackground:background forState:0];
+        }
+    }
+}
+
 - (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
     button_ = buttonIndex + 1;
 }
@@ -351,11 +363,9 @@ static _finline NSString *CydiaURL(NSString *path) {
 }
 
 - (int) yieldToPopupAlertAnimated:(BOOL)animated {
+    [self setRunsModal:YES];
     button_ = 0;
     [self show];
-    NSRunLoop *loop([NSRunLoop currentRunLoop]);
-    NSDate *future([NSDate distantFuture]);
-    while (button_ == 0 && [loop runMode:NSDefaultRunLoopMode beforeDate:future]);
     return button_;
 }
 
@@ -3889,7 +3899,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @end
 /* }}} */
 
-@interface CYBrowserController : BrowserView {
+@interface CYBrowserController : BrowserController {
     CydiaObject *cydia_;
 }
 
@@ -4152,7 +4162,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     } return self;
 }
 
-- (void) didFinishLoading {
+- (void) applyRightButton {
     UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]
         initWithTitle:UCLocalize("CONFIRM")
         style:UIBarButtonItemStylePlain
@@ -4160,8 +4170,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         action:@selector(confirmButtonClicked)
     ];
 #if !AlwaysReload && !IgnoreInstall
-    if (issues_ == nil) [[self navigationItem] setRightBarButtonItem:rightItem];
-    else [[self navigationItem] setRightBarButtonItem:nil];
+    if (issues_ == nil && ![self isLoading]) [[self navigationItem] setRightBarButtonItem:rightItem];
+    else [super applyRightButton];
+#else
+       [[self navigationItem] setRightBarButtonItem:nil];
 #endif
     [rightItem release];
 }
@@ -5246,11 +5258,18 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) actionButtonClicked {
-    if (commercial_ && [self isLoading])
-        [super _rightButtonClicked];
-    else
+       // Wait until it's done loading.
+    if (![self isLoading])
         [self _actionButtonClicked];
 }
+
+- (void) reloadButtonClicked {
+    // Don't reload a package view by clicking the button.
+}
+
+- (void) applyLoadingTitle {
+    // Don't show "Loading" as the title. Ever.
+}
 #endif
 
 - (id) initWithDatabase:(Database *)database {
@@ -5318,7 +5337,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     }
 }
 
-- (void) didFinishLoading {
+- (void) applyRightButton {
     int count = [buttons_ count];
     UIBarButtonItem *actionItem = [[UIBarButtonItem alloc]
         initWithTitle:count == 0 ? nil : count != 1 ? UCLocalize("MODIFY") : [buttons_ objectAtIndex:0]
@@ -5326,7 +5345,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         target:self
         action:@selector(actionButtonClicked)
     ];
-    [[self navigationItem] setRightBarButtonItem:actionItem];
+    if (![self isLoading]) [[self navigationItem] setRightBarButtonItem:actionItem];
+       else [super applyRightButton];
     [actionItem release];
 }
 
@@ -6424,6 +6444,38 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 @implementation RefreshBar
 
+- (void) positionViews {
+    CGRect frame = [cancel_ frame];
+    frame.origin.x = [self frame].size.width - frame.size.width - 5;
+    frame.origin.y = ([self frame].size.height - frame.size.height) / 2;
+    [cancel_ setFrame:frame];
+    
+    CGSize prgsize = {75, 100};
+    CGRect prgrect = {{
+        [self frame].size.width - prgsize.width - 10,
+        ([self frame].size.height - prgsize.height) / 2
+    } , prgsize};
+    [progress_ setFrame:prgrect];
+    
+    CGSize indsize([UIProgressIndicator defaultSizeForStyle:[indicator_ activityIndicatorViewStyle]]);
+    unsigned indoffset = ([self frame].size.height - indsize.height) / 2;
+    CGRect indrect = {{indoffset, indoffset}, indsize};
+    [indicator_ setFrame:indrect];
+    
+    CGSize prmsize = {215, indsize.height + 4};
+    CGRect prmrect = {{
+        indoffset * 2 + indsize.width,
+        unsigned([self frame].size.height - prmsize.height) / 2 - 1
+    }, prmsize};
+    [prompt_ setFrame:prmrect];
+}
+
+- (void)setFrame:(CGRect)frame {
+    [super setFrame:frame];
+    
+    [self positionViews];
+}
+
 - (id) initWithFrame:(CGRect)frame delegate:(id)delegate {
     if ((self = [super initWithFrame:frame])) {
         [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
@@ -6438,57 +6490,28 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
             UIProgressIndicatorStyleMediumBrown :
             UIProgressIndicatorStyleMediumWhite;
 
-        CGSize indsize([UIProgressIndicator defaultSizeForStyle:style]);
-        unsigned indoffset = ([self frame].size.height - indsize.height) / 2;
-        CGRect indrect = {{indoffset, indoffset}, indsize};
-
-        indicator_ = [[UIProgressIndicator alloc] initWithFrame:indrect];
+        indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectZero];
         [indicator_ setStyle:style];
+        [indicator_ startAnimation];
         [self addSubview:indicator_];
 
-        CGSize prmsize = {215, indsize.height + 4};
-
-        CGRect prmrect = {{
-            indoffset * 2 + indsize.width,
-            unsigned([self frame].size.height - prmsize.height) / 2 - 1
-        }, prmsize};
-
-        UIFont *font([UIFont systemFontOfSize:15]);
-
-        prompt_ = [[UITextLabel alloc] initWithFrame:prmrect];
-
+        prompt_ = [[UITextLabel alloc] initWithFrame:CGRectZero];
         [prompt_ setColor:[UIColor colorWithCGColor:(ugly ? Blueish_ : Off_)]];
         [prompt_ setBackgroundColor:[UIColor clearColor]];
-        [prompt_ setFont:font];
-
+        [prompt_ setFont:[UIFont systemFontOfSize:15]];
         [self addSubview:prompt_];
 
-        CGSize prgsize = {75, 100};
-
-        CGRect prgrect = {{
-            [self frame].size.width - prgsize.width - 10,
-            ([self frame].size.height - prgsize.height) / 2
-        } , prgsize};
-
-        progress_ = [[UIProgressBar alloc] initWithFrame:prgrect];
-        [progress_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
-        [self addSubview:progress_];
-
+        progress_ = [[UIProgressBar alloc] initWithFrame:CGRectZero];
+        [progress_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin];
         [progress_ setStyle:0];
-
+        [self addSubview:progress_];
+        
         cancel_ = [[UINavigationButton alloc] initWithTitle:UCLocalize("CANCEL") style:UINavigationButtonStyleHighlighted];
-        [progress_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
         [cancel_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
         [cancel_ addTarget:delegate action:@selector(cancelPressed) forControlEvents:UIControlEventTouchUpInside];
-
-        CGRect frame = [cancel_ frame];
-        frame.origin.x = [self frame].size.width - frame.size.width - 5;
-        frame.origin.y = ([self frame].size.height - frame.size.height) / 2;
-        [cancel_ setFrame:frame];
-
-        [cancel_ setBarStyle:barstyle];    
-
-        [indicator_ startAnimation];
+        [cancel_ setBarStyle:barstyle];
+        
+        [self positionViews];
     } return self;
 }
 
@@ -6895,7 +6918,7 @@ freeing the view controllers on tab change */
         target:self
         action:@selector(editButtonClicked)
     ];
-    [[self navigationItem] setRightBarButtonItem:rightItem];
+    [[self navigationItem] setRightBarButtonItem:rightItem animated:[[self navigationItem] rightBarButtonItem] != nil];
     [rightItem release];
 
     [list_ reloadData];
@@ -6931,6 +6954,7 @@ freeing the view controllers on tab change */
     NSMutableArray *sections_;
     UITableView *list_;
     unsigned upgrades_;
+    BOOL hasSentFirstLoad_;
 }
 
 - (id) initWithDatabase:(Database *)database delegate:(id)delegate;
@@ -6952,7 +6976,12 @@ freeing the view controllers on tab change */
 
 - (void) viewDidAppear:(BOOL)animated {
     [super viewDidAppear:animated];
-    [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated];
+    if (!hasSentFirstLoad_) {
+        hasSentFirstLoad_ = YES;
+        [self performSelector:@selector(reloadData) withObject:nil afterDelay:0.0];
+    } else {
+        [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated];
+    }
 }
 
 - (NSInteger) numberOfSectionsInTableView:(UITableView *)list {
@@ -7027,7 +7056,6 @@ freeing the view controllers on tab change */
         [list_ setDelegate:self];
 
         delegate_ = delegate;
-        [self reloadData];
     } return self;
 }
 
@@ -7177,14 +7205,21 @@ freeing the view controllers on tab change */
 - (id) title { return nil; }
 
 - (id) initWithDatabase:(Database *)database {
-    if ((self = [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:nil]) != nil) {
-        search_ = [[objc_getClass("UISearchBar") alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, 44.0f)];
+    return [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:nil];
+}
+
+- (void)viewDidAppear:(BOOL)animated {
+       [super viewDidAppear:animated];
+       if (!search_) {
+        search_ = [[objc_getClass("UISearchBar") alloc] initWithFrame:CGRectMake(0, 0, [[self view] bounds].size.width, 44.0f)];
+        [search_ layoutSubviews];
         [search_ setPlaceholder:UCLocalize("SEARCH_EX")];
-        [search_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
+        UITextField *textField = [search_ searchField];
+        [textField setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
         [search_ setDelegate:self];
-        [[search_ searchField] setEnablesReturnKeyAutomatically:NO];
-        [[self navigationItem] setTitleView:search_];
-    } return self;
+        [textField setEnablesReturnKeyAutomatically:NO];
+        [[self navigationItem] setTitleView:textField];
+    }
 }
 
 - (void) _reloadData {
@@ -7198,6 +7233,11 @@ freeing the view controllers on tab change */
     [packages_ resetCursor];
 }
 
+- (void) didSelectPackage:(Package *)package {
+    [search_ resignFirstResponder];
+    [super didSelectPackage:package];
+}
+
 @end
 /* }}} */
 /* Settings Controller {{{ */
@@ -7582,8 +7622,8 @@ freeing the view controllers on tab change */
     if (animated) [UIView beginAnimations:nil context:NULL];
     CGRect barframe = [refreshbar_ frame];
     CGRect viewframe = [[root_ view] frame];
-    viewframe.origin.y += barframe.size.height;
-    viewframe.size.height -= barframe.size.height;
+    viewframe.origin.y += barframe.size.height + 20.0f;
+    viewframe.size.height -= barframe.size.height + 20.0f;
     [[root_ view] setFrame:viewframe];
     if (animated) [UIView commitAnimations];
 
@@ -7604,8 +7644,8 @@ freeing the view controllers on tab change */
     if (animated) [UIView beginAnimations:nil context:NULL];
     CGRect barframe = [refreshbar_ frame];
     CGRect viewframe = [[root_ view] frame];
-    viewframe.origin.y -= barframe.size.height;
-    viewframe.size.height += barframe.size.height;
+    viewframe.origin.y -= barframe.size.height + 20.0f;
+    viewframe.size.height += barframe.size.height + 20.0f;
     [[root_ view] setFrame:viewframe];
     if (animated) [UIView commitAnimations];
 
@@ -7613,6 +7653,12 @@ freeing the view controllers on tab change */
     [[root_ selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation];
 }
 
+- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
+{
+    // XXX: fix Apple's layout bug
+    [[root_ selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation];
+}
+
 - (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
     if (dropped_) {
         [self raiseBar:NO];
@@ -7621,11 +7667,6 @@ freeing the view controllers on tab change */
     
     // XXX: fix Apple's layout bug
     [[root_ selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation];
-
-    // Resize refresh bar to fit the new size
-    CGRect barframe = [refreshbar_ frame];
-    barframe.size.width = [[self view] frame].size.width;
-    [refreshbar_ setFrame:barframe];
 }
 
 - (void) dealloc {
@@ -8012,7 +8053,7 @@ static _finline void _setHomePage(Cydia *self) {
     ];
 }
 
-- (void) progressViewIsComplete:(ProgressController *)progress {
+- (void) progressControllerIsComplete:(ProgressController *)progress {
     [self complete];
 }
 
@@ -8252,6 +8293,8 @@ static _finline void _setHomePage(Cydia *self) {
 }
 
 - (void) applicationSuspend:(__GSEvent *)event {
+    // FIXME: This needs to be fixed, but we no longer have a progress_.
+    //        What's the best solution?
     if (hud_ == nil)// && ![progress_ isRunning])
         [super applicationSuspend:event];
 }
@@ -8272,7 +8315,7 @@ static _finline void _setHomePage(Cydia *self) {
 
     [window_ setUserInteractionEnabled:NO];
     [hud show:YES];
-    [window_ addSubview:hud];
+    [[container_ view] addSubview:hud];
     return hud;
 }
 
@@ -8448,10 +8491,10 @@ static _finline void _setHomePage(Cydia *self) {
     [tabbar_ setSelectedIndex:0];
 
     container_ = [[CYContainer alloc] initWithDatabase:database_];
-    [[container_ view] setFrame:[window_ bounds]];
     [container_ setUpdateDelegate:self];
     [container_ setRootController:tabbar_];
     [window_ addSubview:[container_ view]];
+    [[tabbar_ view] setFrame:CGRectMake(0, -20.0f, [window_ bounds].size.width, [window_ bounds].size.height)];
 
     [UIKeyboard initImplementationNow];
 
@@ -8500,6 +8543,26 @@ MSHook(void, UIWebDocumentView$_setUIKitDelegate$, UIWebDocumentView *self, SEL
     return _UIWebDocumentView$_setUIKitDelegate$(self, _cmd, delegate);
 }
 
+static NSNumber *shouldPlayKeyboardSounds;
+
+Class $UIHardware;
+
+MSHook(void, UIHardware$_playSystemSound$, Class self, SEL _cmd, int soundIndex) {
+    switch (soundIndex) {
+        case 1104: // Keyboard Button Clicked
+        case 1105: // Keyboard Delete Repeated
+            if (!shouldPlayKeyboardSounds) {
+                NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.preferences.sounds.plist"];
+                shouldPlayKeyboardSounds = [[dict objectForKey:@"keyboard"] ?: (id)kCFBooleanTrue retain];
+                [dict release];
+            }
+            if (![shouldPlayKeyboardSounds boolValue])
+                break;
+        default:
+            _UIHardware$_playSystemSound$(self, _cmd, soundIndex);
+    }
+}
+
 int main(int argc, char *argv[]) { _pooled
     _trace();
 
@@ -8521,6 +8584,13 @@ int main(int argc, char *argv[]) { _pooled
         _UIWebDocumentView$_setUIKitDelegate$ = reinterpret_cast<void (*)(UIWebDocumentView *, SEL, id)>(method_getImplementation(UIWebDocumentView$_setUIKitDelegate$));
         method_setImplementation(UIWebDocumentView$_setUIKitDelegate$, reinterpret_cast<IMP>(&$UIWebDocumentView$_setUIKitDelegate$));
     }
+
+    $UIHardware = objc_getClass("UIHardware");
+    Method UIHardware$_playSystemSound$(class_getClassMethod($UIHardware, @selector(_playSystemSound:)));
+    if (UIHardware$_playSystemSound$ != NULL) {
+        _UIHardware$_playSystemSound$ = reinterpret_cast<void (*)(Class, SEL, int)>(method_getImplementation(UIHardware$_playSystemSound$));
+        method_setImplementation(UIHardware$_playSystemSound$, reinterpret_cast<IMP>(&$UIHardware$_playSystemSound$));
+    }
     /* }}} */
     /* Set Locale {{{ */
     Locale_ = CFLocaleCopyCurrent();