X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/bf50bdfae66349ce234174c713f1237185e80a19..d7a235a65e829223521738d675148c64a7de577e:/Cydia.mm diff --git a/Cydia.mm b/Cydia.mm index 87f28993..090823dd 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -59,6 +59,8 @@ #include #include +#include + #include #include "iPhonePrivate.h" @@ -119,12 +121,8 @@ extern "C" { #include #include "UICaboodle/BrowserView.h" -#include "UICaboodle/ResetView.h" #include "substrate.h" - -// Apple's sample Reachability code, ASPL licensed. -#include "Reachability.h" /* }}} */ /* Profiler {{{ */ @@ -375,7 +373,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,12 +1207,13 @@ bool isSectionVisible(NSString *section) { - (void) beginUpdate; - (BOOL) updating; - (void) distUpgrade; +- (void) loadData; - (void) updateData; - (void) syncData; - (void) showSettings; - (UIProgressHUD *) addProgressHUD; - (void) removeProgressHUD:(UIProgressHUD *)hud; -- (UCViewController *) pageForPackage:(NSString *)name; +- (CYViewController *) pageForPackage:(NSString *)name; - (PackageController *) packageController; - (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item; @end @@ -2481,11 +2480,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"]; @@ -3861,14 +3862,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ -/* Cydia View Controller {{{ */ -@interface CYViewController : UCViewController { } -@end - -@implementation CYViewController -@end -/* }}} */ - +/* Cydia Browser Controller {{{ */ @interface CYBrowserController : BrowserController { CydiaObject *cydia_; } @@ -3958,7 +3952,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } @end +/* }}} */ +/* Confirmation {{{ */ @protocol ConfirmationControllerDelegate - (void) cancelAndClear:(bool)clear; - (void) confirmWithNavigationController:(UINavigationController *)navigation; @@ -5226,9 +5222,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } } +// 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 { - // Wait until it's done loading. - if (![self isLoading]) + if (commercial_) + [super customButtonClicked]; + else [self _customButtonClicked]; } @@ -5239,6 +5238,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 { @@ -5306,19 +5315,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(customButtonClicked) - ]; - if (![self isLoading]) [[self navigationItem] setRightBarButtonItem:actionItem]; - else [super applyRightButton]; - [actionItem release]; -} - - (bool) isLoading { return commercial_ ? [super isLoading] : false; } @@ -6563,7 +6559,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; @@ -7516,7 +7512,7 @@ freeing the view controllers on tab change */ } - (void) save { - NSString *role = nil; + NSString *role(nil); switch ([segment_ selectedSegmentIndex]) { case 0: role = @"User"; break; @@ -7527,6 +7523,7 @@ freeing the view controllers on tab change */ } if (![role isEqualToString:Role_]) { + bool rolling(Role_ == nil); Role_ = role; Settings_ = [NSMutableDictionary dictionaryWithObjectsAndKeys: @@ -7537,7 +7534,10 @@ freeing the view controllers on tab change */ Changed_ = true; - [roledelegate_ updateData]; + if (rolling) + [roledelegate_ loadData]; + else + [roledelegate_ updateData]; } } @@ -7645,7 +7645,7 @@ freeing the view controllers on tab change */ } - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { - return YES; /* XXX: return YES; */ + return IsWildcat_; } - (void) setTabBarController:(UITabBarController *)controller { @@ -7762,8 +7762,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]; @@ -7784,8 +7784,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]; @@ -7871,8 +7871,9 @@ typedef enum { bool loaded_; } -- (UCViewController *) _pageForURL:(NSURL *)url withClass:(Class)_class; -- (void) setPage:(UCViewController *)page; +- (CYViewController *) _pageForURL:(NSURL *)url withClass:(Class)_class; +- (void) setPage:(CYViewController *)page; +- (void) loadData; @end @@ -7970,10 +7971,25 @@ static _finline void _setHomePage(Cydia *self) { - (void) _refreshIfPossible { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - Reachability* reachability = [Reachability reachabilityWithHostName:@"cydia.saurik.com"]; - NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus]; + SCNetworkReachabilityFlags flags; { + SCNetworkReachabilityRef reachability(SCNetworkReachabilityCreateWithName(NULL, "cydia.saurik.com")); + SCNetworkReachabilityGetFlags(reachability, &flags); + CFRelease(reachability); + } + + // XXX: this elaborate mess is what Apple is using to determine this? :( + // XXX: do we care if the user has to intervene? maybe that's ok? + bool reachable( + (flags & kSCNetworkReachabilityFlagsReachable) != 0 && ( + (flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0 || ( + (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) != 0 || + (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0 + ) && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0 || + (flags & kSCNetworkReachabilityFlagsIsWWAN) != 0 + ) + ); - if (loaded_ || ManualRefresh || remoteHostStatus == NotReachable) loaded: + if (loaded_ || ManualRefresh || !reachable) loaded: [self performSelectorOnMainThread:@selector(_loaded) withObject:nil waitUntilDone:NO]; else { loaded_ = true; @@ -7997,8 +8013,6 @@ static _finline void _setHomePage(Cydia *self) { } - (void) _reloadData { - UIView *block(); - UIProgressHUD *hud([self addProgressHUD]); [hud setText:(loaded_ ? UCLocalize("RELOADING_DATA") : UCLocalize("LOADING_DATA"))]; @@ -8196,7 +8210,7 @@ static _finline void _setHomePage(Cydia *self) { [self complete]; } -- (void) setPage:(UCViewController *)page { +- (void) setPage:(CYViewController *)page { [page setDelegate:self]; CYNavigationController *navController = (CYNavigationController *) [tabbar_ selectedViewController]; @@ -8206,7 +8220,7 @@ static _finline void _setHomePage(Cydia *self) { } } -- (UCViewController *) _pageForURL:(NSURL *)url withClass:(Class)_class { +- (CYViewController *) _pageForURL:(NSURL *)url withClass:(Class)_class { CYBrowserController *browser = [[[_class alloc] init] autorelease]; [browser loadURL:url]; return browser; @@ -8435,7 +8449,7 @@ static _finline void _setHomePage(Cydia *self) { [window_ setUserInteractionEnabled:YES]; } -- (UCViewController *) pageForPackage:(NSString *)name { +- (CYViewController *) pageForPackage:(NSString *)name { if (Package *package = [database_ packageWithName:name]) { PackageController *view([self packageController]); [view setPackage:package]; @@ -8447,7 +8461,7 @@ static _finline void _setHomePage(Cydia *self) { } } -- (UCViewController *) pageForURL:(NSURL *)url hasTag:(int *)tag { +- (CYViewController *) pageForURL:(NSURL *)url hasTag:(int *)tag { if (tag != NULL) *tag = -1; @@ -8499,7 +8513,7 @@ static _finline void _setHomePage(Cydia *self) { - (void) applicationOpenURL:(NSURL *)url { [super applicationOpenURL:url]; int tag; - if (UCViewController *page = [self pageForURL:url hasTag:&tag]) { + if (CYViewController *page = [self pageForURL:url hasTag:&tag]) { [self setPage:page]; tag_ = tag; [tabbar_ setSelectedViewController:(tag_ == -1 ? nil : [[tabbar_ viewControllers] objectAtIndex:tag_])]; @@ -8571,26 +8585,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]; @@ -8599,8 +8601,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]; @@ -8612,6 +8619,15 @@ static _finline void _setHomePage(Cydia *self) { [container_ setTabBarController:tabbar_]; [window_ addSubview:[container_ view]]; + [self performSelector:@selector(loadData) withObject:nil afterDelay:0]; +} + +- (void) loadData { + if (Role_ == nil) { + [self showSettings]; + return; + } + [UIKeyboard initImplementationNow]; [self reloadData];