X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/f99f86e24e844ab573ab88d3100da00b7772ae36..ae22446dad54f9c244d804e40febdb828caae0b0:/Cydia.mm diff --git a/Cydia.mm b/Cydia.mm index c28f93d9..c8e2c1bc 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -375,7 +375,7 @@ static const CFStringCompareFlags LaxCompareFlags_ = kCFCompareCaseInsensitive | #define lprintf(args...) fprintf(stderr, args) -#define ForRelease 0 +#define ForRelease 1 #define TraceLogging (1 && !ForRelease) #define HistogramInsertionSort (0 && !ForRelease) #define ProfileTimes (0 && !ForRelease) @@ -1209,6 +1209,7 @@ bool isSectionVisible(NSString *section) { - (void) beginUpdate; - (BOOL) updating; - (void) distUpgrade; +- (void) loadData; - (void) updateData; - (void) syncData; - (void) showSettings; @@ -1216,6 +1217,7 @@ bool isSectionVisible(NSString *section) { - (void) removeProgressHUD:(UIProgressHUD *)hud; - (UCViewController *) pageForPackage:(NSString *)name; - (PackageController *) packageController; +- (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item; @end /* }}} */ @@ -2480,11 +2482,13 @@ struct PackageNameOrdering : UIImage *icon(nil); if (!icon_.empty()) if ([icon_ hasPrefix:@"file:///"]) + // XXX: correct escaping icon = [UIImage imageAtPath:[icon_ substringFromIndex:7]]; if (icon == nil) if (section != nil) icon = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, section]]; if (icon == nil) if (source_ != nil) if (NSString *dicon = [source_ defaultIcon]) if ([dicon hasPrefix:@"file:///"]) + // XXX: correct escaping icon = [UIImage imageAtPath:[dicon substringFromIndex:7]]; if (icon == nil) icon = [UIImage applicationImageNamed:@"unknown.png"]; @@ -3867,7 +3871,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @implementation CYViewController @end /* }}} */ - +/* Cydia Browser Controller {{{ */ @interface CYBrowserController : BrowserController { CydiaObject *cydia_; } @@ -3957,7 +3961,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } @end +/* }}} */ +/* Confirmation {{{ */ @protocol ConfirmationControllerDelegate - (void) cancelAndClear:(bool)clear; - (void) confirmWithNavigationController:(UINavigationController *)navigation; @@ -5121,7 +5127,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Package Controller {{{ */ -@interface PackageController : CYBrowserController { +@interface PackageController : CYBrowserController < + UIActionSheetDelegate +> { _transient Database *database_; Package *package_; NSString *name_; @@ -5193,7 +5201,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } #if !AlwaysReload -- (void) _actionButtonClicked { +- (void) _customButtonClicked { int count([buttons_ count]); if (count == 0) return; @@ -5223,10 +5231,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } } -- (void) actionButtonClicked { - // Wait until it's done loading. - if (![self isLoading]) - [self _actionButtonClicked]; +// We don't want to allow non-commercial packages to do custom things to the install button, +// so it must call customButtonClicked with a custom commercial_ == 1 fallthrough. +- (void) customButtonClicked { + if (commercial_) + [super customButtonClicked]; + else + [self _customButtonClicked]; } - (void) reloadButtonClicked { @@ -5236,6 +5247,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) applyLoadingTitle { // Don't show "Loading" as the title. Ever. } + +- (UIBarButtonItem *) rightButton { + int count = [buttons_ count]; + return [[[UIBarButtonItem alloc] + initWithTitle:count == 0 ? nil : count != 1 ? UCLocalize("MODIFY") : [buttons_ objectAtIndex:0] + style:UIBarButtonItemStylePlain + target:self + action:@selector(customButtonClicked) + ] autorelease]; +} #endif - (id) initWithDatabase:(Database *)database { @@ -5303,19 +5324,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } } -- (void) applyRightButton { - int count = [buttons_ count]; - UIBarButtonItem *actionItem = [[UIBarButtonItem alloc] - initWithTitle:count == 0 ? nil : count != 1 ? UCLocalize("MODIFY") : [buttons_ objectAtIndex:0] - style:UIBarButtonItemStylePlain - target:self - action:@selector(actionButtonClicked) - ]; - if (![self isLoading]) [[self navigationItem] setRightBarButtonItem:actionItem]; - else [super applyRightButton]; - [actionItem release]; -} - - (bool) isLoading { return commercial_ ? [super isLoading] : false; } @@ -6560,7 +6568,7 @@ freeing the view controllers on tab change */ } } -- (id) initWithDatabase: (Database *)database { +- (id) initWithDatabase:(Database *)database { if ((self = [super init]) != nil) { database_ = database; } return self; @@ -7513,7 +7521,7 @@ freeing the view controllers on tab change */ } - (void) save { - NSString *role = nil; + NSString *role(nil); switch ([segment_ selectedSegmentIndex]) { case 0: role = @"User"; break; @@ -7524,6 +7532,7 @@ freeing the view controllers on tab change */ } if (![role isEqualToString:Role_]) { + bool rolling(Role_ == nil); Role_ = role; Settings_ = [NSMutableDictionary dictionaryWithObjectsAndKeys: @@ -7534,7 +7543,10 @@ freeing the view controllers on tab change */ Changed_ = true; - [roledelegate_ updateData]; + if (rolling) + [roledelegate_ loadData]; + else + [roledelegate_ updateData]; } } @@ -7642,7 +7654,7 @@ freeing the view controllers on tab change */ } - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { - return YES; /* XXX: return YES; */ + return IsWildcat_; } - (void) setTabBarController:(UITabBarController *)controller { @@ -7759,8 +7771,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 + 20.0f; - viewframe.size.height -= barframe.size.height + 20.0f; + viewframe.origin.y += barframe.size.height; + viewframe.size.height -= barframe.size.height; [[root_ view] setFrame:viewframe]; if (animated) [UIView commitAnimations]; @@ -7781,8 +7793,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 + 20.0f; - viewframe.size.height += barframe.size.height + 20.0f; + viewframe.origin.y -= barframe.size.height; + viewframe.size.height += barframe.size.height; [[root_ view] setFrame:viewframe]; if (animated) [UIView commitAnimations]; @@ -7870,6 +7882,7 @@ typedef enum { - (UCViewController *) _pageForURL:(NSURL *)url withClass:(Class)_class; - (void) setPage:(UCViewController *)page; +- (void) loadData; @end @@ -7994,8 +8007,6 @@ static _finline void _setHomePage(Cydia *self) { } - (void) _reloadData { - UIView *block(); - UIProgressHUD *hud([self addProgressHUD]); [hud setText:(loaded_ ? UCLocalize("RELOADING_DATA") : UCLocalize("LOADING_DATA"))]; @@ -8568,26 +8579,14 @@ static _finline void _setHomePage(Cydia *self) { return; } - if (Role_ == nil) - [self showSettings]; - _trace(); - NSMutableArray *controllers = [NSMutableArray array]; - [controllers addObject:[[CYNavigationController alloc] initWithDatabase:database_]]; - [controllers addObject:[[CYNavigationController alloc] initWithDatabase:database_]]; - [controllers addObject:[[CYNavigationController alloc] initWithDatabase:database_]]; - if (IsWildcat_) [controllers addObject:[[CYNavigationController alloc] initWithDatabase:database_]]; - [controllers addObject:[[CYNavigationController alloc] initWithDatabase:database_]]; - [controllers addObject:[[CYNavigationController alloc] initWithDatabase:database_]]; - - NSMutableArray *items = [NSMutableArray arrayWithObjects: + NSMutableArray *items([NSMutableArray arrayWithObjects: [[[UITabBarItem alloc] initWithTitle:@"Cydia" image:[UIImage applicationImageNamed:@"home.png"] tag:kCydiaTag] autorelease], [[[UITabBarItem alloc] initWithTitle:UCLocalize("SECTIONS") image:[UIImage applicationImageNamed:@"install.png"] tag:kSectionsTag] autorelease], [[[UITabBarItem alloc] initWithTitle:UCLocalize("CHANGES") image:[UIImage applicationImageNamed:@"changes.png"] tag:kChangesTag] autorelease], [[[UITabBarItem alloc] initWithTitle:UCLocalize("SEARCH") image:[UIImage applicationImageNamed:@"search.png"] tag:kSearchTag] autorelease], - nil - ]; + nil]); if (IsWildcat_) { [items insertObject:[[[UITabBarItem alloc] initWithTitle:UCLocalize("SOURCES") image:[UIImage applicationImageNamed:@"source.png"] tag:kSourcesTag] autorelease] atIndex:3]; @@ -8596,8 +8595,13 @@ static _finline void _setHomePage(Cydia *self) { [items insertObject:[[[UITabBarItem alloc] initWithTitle:UCLocalize("MANAGE") image:[UIImage applicationImageNamed:@"manage.png"] tag:kManageTag] autorelease] atIndex:3]; } - for (size_t i(0); i != [items count]; i++) - [[controllers objectAtIndex:i] setTabBarItem:[items objectAtIndex:i]]; + NSMutableArray *controllers([NSMutableArray array]); + + for (UITabBarItem *item in items) { + CYNavigationController *controller([[[CYNavigationController alloc] initWithDatabase:database_] autorelease]); + [controller setTabBarItem:item]; + [controllers addObject:controller]; + } tabbar_ = [[CYTabBarController alloc] initWithDatabase:database_]; [tabbar_ setViewControllers:controllers]; @@ -8608,7 +8612,15 @@ static _finline void _setHomePage(Cydia *self) { [container_ setUpdateDelegate:self]; [container_ setTabBarController:tabbar_]; [window_ addSubview:[container_ view]]; - [[tabbar_ view] setFrame:CGRectMake(0, -20.0f, [window_ bounds].size.width, [window_ bounds].size.height)]; + + [self performSelector:@selector(loadData) withObject:nil afterDelay:0]; +} + +- (void) loadData { + if (Role_ == nil) { + [self showSettings]; + return; + } [UIKeyboard initImplementationNow]; @@ -8661,19 +8673,20 @@ static NSNumber *shouldPlayKeyboardSounds; Class $UIHardware; -MSHook(void, UIHardware$_playSystemSound$, Class self, SEL _cmd, int soundIndex) { - switch (soundIndex) { +MSHook(void, UIHardware$_playSystemSound$, Class self, SEL _cmd, int sound) { + switch (sound) { 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 == nil) { + NSDictionary *dict([[[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.preferences.sounds.plist"] autorelease]); + shouldPlayKeyboardSounds = [([dict objectForKey:@"keyboard"] ?: (id) kCFBooleanTrue) retain]; } + if (![shouldPlayKeyboardSounds boolValue]) break; + default: - _UIHardware$_playSystemSound$(self, _cmd, soundIndex); + _UIHardware$_playSystemSound$(self, _cmd, sound); } } @@ -8941,7 +8954,7 @@ int main(int argc, char *argv[]) { _pooled Warning_ = UCLocalize("WARNING"); _trace(); - int value = UIApplicationMain(argc, argv, @"Cydia", @"Cydia"); + int value(UIApplicationMain(argc, argv, @"Cydia", @"Cydia")); CGColorSpaceRelease(space_); CFRelease(Locale_);