]> git.saurik.com Git - cydia.git/blobdiff - Cydia.mm
Addons (BossPaper)
[cydia.git] / Cydia.mm
index f94b9de6d7ff6895cbf621e3c721f6b867cdb536..4cb84eb02851cce6062d7711d28bc9e2cf03b504 100644 (file)
--- a/Cydia.mm
+++ b/Cydia.mm
@@ -116,6 +116,8 @@ extern "C" {
 
 #include <ext/hash_map>
 
+#include <notify.h>
+
 #import "UICaboodle/BrowserView.h"
 #import "UICaboodle/ResetView.h"
 
@@ -257,6 +259,15 @@ static _finline NSString *CydiaURL(NSString *path) {
     return [[NSString stringWithUTF8String:page] stringByAppendingString:path];
 }
 
+static _finline void UpdateExternalStatus(uint64_t newStatus) {
+    int notify_token;
+    if (notify_register_check("com.saurik.Cydia.status", &notify_token) == NOTIFY_STATUS_OK) {
+        notify_set_state(notify_token, newStatus);
+        notify_cancel(notify_token);
+    }
+    notify_post("com.saurik.Cydia.status");
+}
+
 /* [NSObject yieldToSelector:(withObject:)] {{{*/
 @interface NSObject (Cydia)
 - (id) yieldToSelector:(SEL)selector withObject:(id)object;
@@ -342,6 +353,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 +374,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 +3910,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @end
 /* }}} */
 
-@interface CYBrowserController : BrowserView {
+@interface CYBrowserController : BrowserController {
     CydiaObject *cydia_;
 }
 
@@ -4010,22 +4031,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [super dealloc];
 }
 
-- (void) actionSheet:(UIActionSheet *)sheet clickedButtonAtIndex:(NSInteger)button {
-    NSString *context([sheet context]);
-
-    if ([context isEqualToString:@"cancel"]) {
-        bool clear;
-
-        if      (button == [sheet cancelButtonIndex])      return;
-        else if (button == [sheet destructiveButtonIndex]) clear = true;
-        else                                               clear = false;
-        
-        [sheet dismissWithClickedButtonIndex:0xDEADBEEF animated:YES];
-        [self dismissModalViewControllerAnimated:YES];
-        [delegate_ cancelAndClear:clear];
-    }
-}
-
 - (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
     NSString *context([alert context]);
 
@@ -4047,11 +4052,19 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     }
 }
 
+- (id) invokeDefaultMethodWithArguments:(NSArray *)args {
+    [self dismissModalViewControllerAnimated:YES];
+    [delegate_ cancelAndClear:NO];
+    
+    return nil;
+}
+
 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
     [super webView:sender didClearWindowObject:window forFrame:frame];
     [window setValue:changes_ forKey:@"changes"];
     [window setValue:issues_ forKey:@"issues"];
     [window setValue:sizes_ forKey:@"sizes"];
+    [window setValue:self forKey:@"queue"];
 }
 
 - (id) initWithDatabase:(Database *)database {
@@ -4142,7 +4155,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"confirm" ofType:@"html"]]];
 
         UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]
-            initWithTitle:[NSString stringWithFormat:UCLocalize("SLASH_DELIMITED"), UCLocalize("CANCEL"), UCLocalize("QUEUE")]
+            initWithTitle:UCLocalize("CANCEL")//[NSString stringWithFormat:UCLocalize("SLASH_DELIMITED"), UCLocalize("CANCEL"), UCLocalize("QUEUE")]
             style:UIBarButtonItemStylePlain
             target:self
             action:@selector(cancelButtonClicked)
@@ -4152,7 +4165,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     } return self;
 }
 
-- (void) didFinishLoading {
+- (void) applyRightButton {
     UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]
         initWithTitle:UCLocalize("CONFIRM")
         style:UIBarButtonItemStylePlain
@@ -4160,27 +4173,17 @@ 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];
 }
 
 - (void) cancelButtonClicked {
-    UIActionSheet *sheet = [[UIActionSheet alloc]
-        initWithTitle:nil
-        delegate:self
-        cancelButtonTitle:nil
-        destructiveButtonTitle:nil
-        otherButtonTitles:nil
-    ];
-
-    [sheet addButtonWithTitle:UCLocalize("CANCEL_CLEAR")];
-    [sheet setDestructiveButtonIndex:[sheet numberOfButtons] - 1];
-    [sheet addButtonWithTitle:UCLocalize("CONTINUE_QUEUING")];
-    [sheet setContext:@"cancel"];
-
-    [delegate_ showActionSheet:[sheet autorelease] fromItem:[[self navigationItem] leftBarButtonItem]];
+    [self dismissModalViewControllerAnimated:YES];
+    [delegate_ cancelAndClear:YES];
 }
 
 #if !AlwaysReload
@@ -4385,6 +4388,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (void) closeButtonPushed {
     running_ = NO;
 
+    UpdateExternalStatus(0);
+
     switch (Finish_) {
         case 0:
             [self dismissModalViewControllerAnimated:YES];
@@ -4458,6 +4463,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
     system("su -c /usr/bin/uicache mobile");
 
+    UpdateExternalStatus(Finish_ == 0 ? 2 : 0);
+
     [delegate_ setStatusBarShowsProgress:NO];
 }
 
@@ -4469,6 +4476,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) detachNewThreadSelector:(SEL)selector toTarget:(id)target withObject:(id)object title:(NSString *)title {
+    UpdateExternalStatus(1);
+
     if (title_ != nil)
         [title_ release];
     if (title == nil)
@@ -5055,9 +5064,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     return files_ == nil ? 0 : [files_ count];
 }
 
-- (float) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-    return 24;
-}
+/*- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
+    return 24.0f;
+}*/
 
 - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     static NSString *reuseIdentifier = @"Cell";
@@ -5082,6 +5091,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         files_ = [[NSMutableArray arrayWithCapacity:32] retain];
 
         list_ = [[UITableView alloc] initWithFrame:[[self view] bounds]];
+        [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
+        [list_ setRowHeight:24.0f];
         [[self view] addSubview:list_];
 
         [list_ setDataSource:self];
@@ -5246,11 +5257,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 +5336,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 +5344,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];
 }
 
@@ -5416,10 +5435,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated];
 }
 
-- (CGFloat) tableView:(UITableView *)table heightForRowAtIndexPath:(NSIndexPath *)path {
-    return 73;
+/*- (CGFloat) tableView:(UITableView *)table heightForRowAtIndexPath:(NSIndexPath *)path {
     return [PackageCell heightForPackage:[self packageAtIndexPath:path]];
-}
+}*/
 
 - (NSIndexPath *) tableView:(UITableView *)table willSelectRowAtIndexPath:(NSIndexPath *)path {
     Package *package([self packageAtIndexPath:path]);
@@ -5451,6 +5469,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
         list_ = [[UITableView alloc] initWithFrame:[self bounds] style:UITableViewStylePlain];
         [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
+        [list_ setRowHeight:73.0f];
         [self addSubview:list_];
 
         [list_ setDataSource:self];
@@ -6381,12 +6400,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (void) queueButtonClicked {
     [delegate_ queue];
 }
-#endif
 
-- (void) didFinishLoading {
-    [self queueStatusDidChange];
+- (void) applyLoadingTitle {
+    // No "Loading" title.
 }
 
+- (void) applyRightButton {
+    // No right button.
+}
+#endif
+
 - (void) queueStatusDidChange {
 #if !AlwaysReload
     if (!IsWildcat_ && Queuing_) {
@@ -6742,9 +6765,9 @@ freeing the view controllers on tab change */
     return editing_ ? [sections_ count] : [filtered_ count] + 1;
 }
 
-- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-    return 45;
-}
+/*- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
+    return 45.0f;
+}*/
 
 - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     static NSString *reuseIdentifier = @"SectionCell";
@@ -6800,6 +6823,7 @@ freeing the view controllers on tab change */
 
         list_ = [[UITableView alloc] initWithFrame:[[self view] bounds]];
         [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
+        [list_ setRowHeight:45.0f];
         [[self view] addSubview:list_];
 
         [list_ setDataSource:self];
@@ -6898,7 +6922,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];
@@ -6934,6 +6958,7 @@ freeing the view controllers on tab change */
     NSMutableArray *sections_;
     UITableView *list_;
     unsigned upgrades_;
+    BOOL hasSentFirstLoad_;
 }
 
 - (id) initWithDatabase:(Database *)database delegate:(id)delegate;
@@ -6955,7 +6980,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 {
@@ -6989,10 +7019,9 @@ freeing the view controllers on tab change */
     return cell;
 }
 
-- (CGFloat) tableView:(UITableView *)table heightForRowAtIndexPath:(NSIndexPath *)path {
-    return 73;
+/*- (CGFloat) tableView:(UITableView *)table heightForRowAtIndexPath:(NSIndexPath *)path {
     return [PackageCell heightForPackage:[self packageAtIndexPath:path]];
-}
+}*/
 
 - (NSIndexPath *) tableView:(UITableView *)table willSelectRowAtIndexPath:(NSIndexPath *)path {
     Package *package([self packageAtIndexPath:path]);
@@ -7024,13 +7053,13 @@ freeing the view controllers on tab change */
 
         list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain];
         [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
+        [list_ setRowHeight:73.0f];
         [[self view] addSubview:list_];
 
         [list_ setDataSource:self];
         [list_ setDelegate:self];
 
         delegate_ = delegate;
-        [self reloadData];
     } return self;
 }
 
@@ -7180,14 +7209,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 {
@@ -7201,6 +7237,11 @@ freeing the view controllers on tab change */
     [packages_ resetCursor];
 }
 
+- (void) didSelectPackage:(Package *)package {
+    [search_ resignFirstResponder];
+    [super didSelectPackage:package];
+}
+
 @end
 /* }}} */
 /* Settings Controller {{{ */
@@ -8506,6 +8547,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();
 
@@ -8527,6 +8588,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();