X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/1b1d445bc087b7d185fb0ec63c8c96d17704c954..c9132db418f017e9f72d31b1aeb9ef31bd6e0de8:/MobileCydia.mm diff --git a/MobileCydia.mm b/MobileCydia.mm index afd02875..2b6bd1e0 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -1,5 +1,5 @@ /* Cydia - iPhone UIKit Front-End for Debian APT - * Copyright (C) 2008-2010 Jay Freeman (saurik) + * Copyright (C) 2008-2011 Jay Freeman (saurik) */ /* Modified BSD License {{{ */ @@ -217,14 +217,6 @@ union SplitHash { static const NSUInteger UIViewAutoresizingFlexibleBoth(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); -void NSLogPoint(const char *fix, const CGPoint &point) { - NSLog(@"%s(%g,%g)", fix, point.x, point.y); -} - -void NSLogRect(const char *fix, const CGRect &rect) { - NSLog(@"%s(%g,%g)+(%g,%g)", fix, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); -} - static _finline NSString *CydiaURL(NSString *path) { char page[25]; page[0] = 'h'; page[1] = 't'; page[2] = 't'; page[3] = 'p'; page[4] = ':'; @@ -309,15 +301,15 @@ static _finline void UpdateExternalStatus(uint64_t newStatus) { @end /* }}} */ -/* Cydia Action Sheet {{{ */ -@interface CYActionSheet : UIAlertView { +/* Cydia Alert View {{{ */ +@interface CYAlertView : UIAlertView { unsigned button_; } - (int) yieldToPopupAlertAnimated:(BOOL)animated; @end -@implementation CYActionSheet +@implementation CYAlertView - (id) initWithTitle:(NSString *)title buttons:(NSArray *)buttons defaultButtonIndex:(int)index { if ((self = [super init])) { @@ -363,32 +355,6 @@ static const NSStringCompareOptions MatchCompareOptions_ = NSLiteralSearch | NSC static const NSStringCompareOptions LaxCompareOptions_ = NSNumericSearch | NSDiacriticInsensitiveSearch | NSWidthInsensitiveSearch | NSCaseInsensitiveSearch; static const CFStringCompareFlags LaxCompareFlags_ = kCFCompareCaseInsensitive | kCFCompareNonliteral | kCFCompareLocalized | kCFCompareNumerically | kCFCompareWidthInsensitive | kCFCompareForcedOrdering; -/* Information Dictionaries {{{ */ -@interface NSMutableArray (Cydia) -- (void) addInfoDictionary:(NSDictionary *)info; -@end - -@implementation NSMutableArray (Cydia) - -- (void) addInfoDictionary:(NSDictionary *)info { - [self addObject:info]; -} - -@end - -@interface NSMutableDictionary (Cydia) -- (void) addInfoDictionary:(NSDictionary *)info; -@end - -@implementation NSMutableDictionary (Cydia) - -- (void) addInfoDictionary:(NSDictionary *)info { - [self setObject:info forKey:[info objectForKey:@"CFBundleIdentifier"]]; -} - -@end -/* }}} */ - #define lprintf(args...) fprintf(stderr, args) #define ForRelease 1 @@ -400,8 +366,8 @@ static const CFStringCompareFlags LaxCompareFlags_ = kCFCompareCaseInsensitive | #define TrackResize (0 && !ForRelease) #define ManualRefresh (1 && !ForRelease) #define ShowInternals (0 && !ForRelease) -#define IgnoreInstall (0 && !ForRelease) #define AlwaysReload (0 && !ForRelease) +#define TryIndexedCollation (0 && !ForRelease) #if !TraceLogging #undef _trace @@ -1013,6 +979,8 @@ class CYColor { /* Random Global Variables {{{ */ static const int PulseInterval_ = 50000; +static const NSString *UI_; + static int Finish_; static NSArray *Finishes_; @@ -1071,7 +1039,8 @@ static _transient NSMutableDictionary *Sources_; static bool Changed_; static time_t now_; -static bool IsWildcat_; +bool IsWildcat_; +static CGFloat ScreenScale_; /* }}} */ /* Display Helpers {{{ */ @@ -1179,12 +1148,11 @@ bool isSectionVisible(NSString *section) { - (void) setConfigurationData:(NSString *)data; @end -@class PackageController; +@class CYPackageController; @protocol CydiaDelegate - (void) retainNetworkActivityIndicator; - (void) releaseNetworkActivityIndicator; -- (void) setPackageController:(PackageController *)view; - (void) clearPackage:(Package *)package; - (void) installPackage:(Package *)package; - (void) installPackages:(NSArray *)packages; @@ -1199,7 +1167,6 @@ bool isSectionVisible(NSString *section) { - (UIProgressHUD *) addProgressHUD; - (void) removeProgressHUD:(UIProgressHUD *)hud; - (CYViewController *) pageForPackage:(NSString *)name; -- (PackageController *) packageController; - (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item; @end @@ -1462,7 +1429,7 @@ struct MetaValue : static Cytore::File MetaFile_; // }}} // Cytore Helper Functions {{{ -static PackageValue *PackageFind(const char *name, size_t length) { +static PackageValue *PackageFind(const char *name, size_t length, bool *fail = NULL) { SplitHash nhash = { hashlittle(name, length) }; PackageValue *metadata; @@ -1472,6 +1439,14 @@ static PackageValue *PackageFind(const char *name, size_t length) { *offset = MetaFile_.New(length + 1); metadata = &MetaFile_.Get(*offset); + if (metadata == NULL) { + if (fail != NULL) + *fail = true; + + metadata = new PackageValue(); + memset(metadata, 0, sizeof(*metadata)); + } + memcpy(metadata->name_, name, length + 1); metadata->nhash_ = nhash.u16[1]; } else { @@ -1487,13 +1462,15 @@ static PackageValue *PackageFind(const char *name, size_t length) { } static void PackageImport(const void *key, const void *value, void *context) { + bool &fail(*reinterpret_cast(context)); + char buffer[1024]; if (!CFStringGetCString((CFStringRef) key, buffer, sizeof(buffer), kCFStringEncodingUTF8)) { NSLog(@"failed to import package %@", key); return; } - PackageValue *metadata(PackageFind(buffer, strlen(buffer))); + PackageValue *metadata(PackageFind(buffer, strlen(buffer), &fail)); NSDictionary *package((NSDictionary *) value); if (NSNumber *subscribed = [package objectForKey:@"IsSubscribed"]) @@ -2736,6 +2713,8 @@ struct PackageNameOrdering : if (range.location != NSNotFound) return YES; + [self parse]; + range = [[self shortDescription] rangeOfString:text options:MatchCompareOptions_]; if (range.location != NSNotFound) return YES; @@ -3376,7 +3355,7 @@ static NSString *Warning_; NSString *title(UCLocalize("DATABASE")); _trace(); - if (!cache_.Open(progress_, true)) { pop: + while (!cache_.Open(progress_, true)) { pop: std::string error; bool warning(!_error->PopMessage(error)); lprintf("cache_.Open():[%s]\n", error.c_str()); @@ -3386,15 +3365,17 @@ static NSString *Warning_; else if (error == "The package lists or status file could not be parsed or opened.") [delegate_ repairWithSelector:@selector(update)]; // else if (error == "Could not open lock file /var/lib/dpkg/lock - open (13 Permission denied)") - // else if (error == "Could not get lock /var/lib/dpkg/lock - open (35 Resource temporarily unavailable)") + else if (error == "Could not get lock /var/lib/dpkg/lock - open (35 Resource temporarily unavailable)") + [delegate_ _setProgressError:[NSString stringWithUTF8String:error.c_str()] withTitle:[NSString stringWithFormat:Colon_, Error_, title]]; // else if (error == "The list of sources could not be read.") - else + else { [delegate_ _setProgressError:[NSString stringWithUTF8String:error.c_str()] withTitle:[NSString stringWithFormat:Colon_, warning ? Warning_ : Error_, title]]; + return; + } if (warning) goto pop; _error->Discard(); - return; } _trace(); @@ -3730,23 +3711,6 @@ static NSString *Warning_; @end /* }}} */ -/* Confirmation Controller {{{ */ -bool DepSubstrate(const pkgCache::VerIterator &iterator) { - if (!iterator.end()) - for (pkgCache::DepIterator dep(iterator.DependsList()); !dep.end(); ++dep) { - if (dep->Type != pkgCache::Dep::Depends && dep->Type != pkgCache::Dep::PreDepends) - continue; - pkgCache::PkgIterator package(dep.TargetPkg()); - if (package.end()) - continue; - if (strcmp(package.Name(), "mobilesubstrate") == 0) - return true; - } - - return false; -} -/* }}} */ - /* Web Scripting {{{ */ @interface CydiaObject : NSObject { id indirect_; @@ -3969,7 +3933,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { id values[count]; for (unsigned i(0); i != count; ++i) values[i] = [arguments objectAtIndex:i]; - return [[[NSString alloc] initWithFormat:format arguments:*(reinterpret_cast(&values))] autorelease]; + return [[[NSString alloc] initWithFormat:format arguments:reinterpret_cast(values)] autorelease]; } - (NSString *) localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)table { @@ -4045,6 +4009,92 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (UILabel *)label { return label_; } - (UIActivityIndicatorView *)activityIndicatorView { return spinner_; } +@end +/* }}} */ +/* Emulated Loading Controller {{{ */ +@interface CYEmulatedLoadingController : CYViewController < + ProgressDelegate, + ConfigurationDelegate +> { + _transient Database *database_; + CYLoadingIndicator *indicator_; + UITabBar *tabbar_; + UINavigationBar *navbar_; +} +@end + +@implementation CYEmulatedLoadingController + +- (void) dealloc { + [self releaseSubviews]; + [database_ setDelegate:nil]; + + [super dealloc]; +} + +- (void) setProgressError:(NSString *)error withTitle:(NSString *)title { + CYAlertView *sheet([[[CYAlertView alloc] + initWithTitle:title + buttons:[NSArray arrayWithObjects:UCLocalize("OKAY"), nil] + defaultButtonIndex:0 + ] autorelease]); + + [sheet setMessage:error]; + [sheet yieldToPopupAlertAnimated:YES]; + [sheet dismiss]; +} + +- (void) setProgressTitle:(NSString *)title { } +- (void) setProgressPercent:(float)percent { } +- (void) startProgress { } +- (void) addProgressOutput:(NSString *)output { } +- (bool) isCancelling:(size_t)received { return NO; } +- (void) setConfigurationData:(NSString *)data { } + +- (void) repairWithSelector:(SEL)selector { + [[indicator_ label] performSelectorOnMainThread:@selector(setText:) withObject:[NSString stringWithFormat:Elision_, UCLocalize("REPAIRING"), nil] waitUntilDone:YES]; + [database_ performSelector:selector]; + sleep(10); + [[indicator_ label] performSelectorOnMainThread:@selector(setText:) withObject:[NSString stringWithFormat:Elision_, UCLocalize("LOADING"), nil] waitUntilDone:YES]; +} + +- (id) initWithDatabase:(Database *)database { + if ((self = [super init])) { + database_ = database; + [database_ setDelegate:self]; + } return self; +} + +- (void) loadView { + [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; + [[self view] setBackgroundColor:[UIColor pinStripeColor]]; + + indicator_ = [[CYLoadingIndicator alloc] initWithFrame:[[self view] bounds]]; + [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [[self view] addSubview:indicator_]; + + tabbar_ = [[UITabBar alloc] initWithFrame:CGRectMake(0, 0, 0, 49.0f)]; + [tabbar_ setFrame:CGRectMake(0.0f, [[self view] bounds].size.height - [tabbar_ bounds].size.height, [[self view] bounds].size.width, [tabbar_ bounds].size.height)]; + [tabbar_ setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth]; + [[self view] addSubview:tabbar_]; + + navbar_ = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 0, 44.0f)]; + [navbar_ setFrame:CGRectMake(0.0f, 0.0f, [[self view] bounds].size.width, [navbar_ bounds].size.height)]; + [navbar_ setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth]; + [[self view] addSubview:navbar_]; +} + +- (void) releaseSubviews { + [indicator_ release]; + indicator_ = nil; + + [tabbar_ release]; + tabbar_ = nil; + + [navbar_ release]; + navbar_ = nil; +} + @end /* }}} */ @@ -4062,6 +4112,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [super dealloc]; } +- (NSURL *) navigationURL { + return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://url/%@", [[[webview_ request] URL] absoluteString]]]; +} + - (void) setHeaders:(NSDictionary *)headers forHost:(NSString *)host { } @@ -4070,18 +4124,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { WebDataSource *source([frame dataSource]); NSURLResponse *response([source response]); + NSURL *url([response URL]); NSString *scheme([url scheme]); - - NSHTTPURLResponse *http; - if (scheme != nil && ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"])) - http = (NSHTTPURLResponse *) response; - else - http = nil; - - NSDictionary *headers([http allHeaderFields]); NSString *host([url host]); - [self setHeaders:headers forHost:host]; + + if ([response isKindOfClass:[NSHTTPURLResponse class]]) { + NSHTTPURLResponse *http((NSHTTPURLResponse *) response); + NSDictionary *headers([http allHeaderFields]); + [self setHeaders:headers forHost:host]; + } if ( [host isEqualToString:@"cydia.saurik.com"] || @@ -4140,7 +4192,22 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ -/* Confirmation {{{ */ +/* Confirmation Controller {{{ */ +bool DepSubstrate(const pkgCache::VerIterator &iterator) { + if (!iterator.end()) + for (pkgCache::DepIterator dep(iterator.DependsList()); !dep.end(); ++dep) { + if (dep->Type != pkgCache::Dep::Depends && dep->Type != pkgCache::Dep::PreDepends) + continue; + pkgCache::PkgIterator package(dep.TargetPkg()); + if (package.end()) + continue; + if (strcmp(package.Name(), "mobilesubstrate") == 0) + return true; + } + + return false; +} + @protocol ConfirmationControllerDelegate - (void) cancelAndClear:(bool)clear; - (void) confirmWithNavigationController:(UINavigationController *)navigation; @@ -4215,8 +4282,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if ((self = [super init]) != nil) { database_ = database; - [[self navigationItem] setTitle:UCLocalize("CONFIRM")]; - NSMutableArray *installing = [NSMutableArray arrayWithCapacity:16]; NSMutableArray *reinstalling = [NSMutableArray arrayWithCapacity:16]; NSMutableArray *upgrading = [NSMutableArray arrayWithCapacity:16]; @@ -4263,7 +4328,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { message:UCLocalize("REMOVING_ESSENTIALS_EX") delegate:self cancelButtonTitle:[NSString stringWithFormat:parenthetical, UCLocalize("CANCEL_OPERATION"), UCLocalize("SAFE")] - otherButtonTitles:[NSString stringWithFormat:parenthetical, UCLocalize("FORCE_REMOVAL"), UCLocalize("UNSAFE")], nil + otherButtonTitles: + [NSString stringWithFormat:parenthetical, UCLocalize("FORCE_REMOVAL"), UCLocalize("UNSAFE")], + nil ]; [essential_ setContext:@"remove"]; @@ -4296,11 +4363,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { SizeString([database_ fetcher].PartialPresent()), nil]; - [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"confirm" ofType:@"html"]]]; + [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/confirm/", UI_]]]; [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:UCLocalize("CANCEL") - // OLD: [NSString stringWithFormat:UCLocalize("SLASH_DELIMITED"), UCLocalize("CANCEL"), UCLocalize("QUEUE")] style:UIBarButtonItemStylePlain target:self action:@selector(cancelButtonClicked) @@ -4309,11 +4375,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) applyRightButton { -#if !AlwaysReload && !IgnoreInstall +#if !AlwaysReload if (issues_ == nil && ![self isLoading]) [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:UCLocalize("CONFIRM") - style:UIBarButtonItemStylePlain + style:UIBarButtonItemStyleDone target:self action:@selector(confirmButtonClicked) ] autorelease]]; @@ -4331,9 +4397,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { #if !AlwaysReload - (void) confirmButtonClicked { -#if IgnoreInstall - return; -#endif if (essential_ != nil) [essential_ show]; else { @@ -4449,7 +4512,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { //[status_ setFont:font]; output_ = [[UITextView alloc] init]; - [output_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; //[output_ setTextFont:@"Courier New"]; [output_ setFont:[[output_ font] fontWithSize:12]]; @@ -4495,7 +4557,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { 10, 20, bounds.size.width - 20, - bounds.size.height - 62 + bounds.size.height - 96 )]; [close_ setFrame:CGRectMake( (bounds.size.width - closewidth) / 2, @@ -4705,7 +4767,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) setProgressError:(NSString *)error withTitle:(NSString *)title { - CYActionSheet *sheet([[[CYActionSheet alloc] + CYAlertView *sheet([[[CYAlertView alloc] initWithTitle:title buttons:[NSArray arrayWithObjects:UCLocalize("OKAY"), nil] defaultButtonIndex:0 @@ -4763,8 +4825,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { message:[NSString stringWithFormat:@"%@\n\n%@", UCLocalize("CONFIGURATION_UPGRADE_EX"), ofile] delegate:self cancelButtonTitle:UCLocalize("KEEP_OLD_COPY") - otherButtonTitles:UCLocalize("ACCEPT_NEW_COPY"), - // XXX: UCLocalize("SEE_WHAT_CHANGED"), + otherButtonTitles: + UCLocalize("ACCEPT_NEW_COPY"), + // XXX: UCLocalize("SEE_WHAT_CHANGED"), nil ] autorelease]; @@ -4870,6 +4933,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ + /* Package Cell {{{ */ @interface PackageCell : CYTableViewCell < ContentDelegate @@ -4948,16 +5012,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } return self; } -- (void) _setBackgroundColor { - UIColor *color; - if (NSString *mode = [package_ mode]) { - bool remove([mode isEqualToString:@"REMOVE"] || [mode isEqualToString:@"PURGE"]); - color = remove ? RemovingColor_ : InstallingColor_; - } else - color = [UIColor whiteColor]; - - [content_ setBackgroundColor:color]; - [self setNeedsDisplay]; +- (NSString *) accessibilityLabel { + return [NSString stringWithFormat:UCLocalize("COLON_DELIMITED"), name_, description_]; } - (void) setPackage:(Package *)package { @@ -5006,11 +5062,36 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if ((badge_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Purposes/%@.png", App_, purpose]]) != nil) badge_ = [badge_ retain]; - if ([package installed] != nil) - if ((placard_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/installed.png", App_]]) != nil) + UIColor *color; + NSString *placard; + + if (NSString *mode = [package_ mode]) { + if ([mode isEqualToString:@"REMOVE"] || [mode isEqualToString:@"PURGE"]) { + color = RemovingColor_; + //placard = @"removing"; + } else { + color = InstallingColor_; + //placard = @"installing"; + } + + // XXX: the removing/installing placards are not @2x + placard = nil; + } else { + color = [UIColor whiteColor]; + + if ([package installed] != nil) + placard = @"installed"; + else + placard = nil; + } + + [content_ setBackgroundColor:color]; + + if (placard != nil) + if ((placard_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/%@.png", App_, placard]]) != nil) placard_ = [placard_ retain]; - [self _setBackgroundColor]; + [self setNeedsDisplay]; [content_ setNeedsDisplay]; } @@ -5188,6 +5269,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [switch_ setFrame:CGRectMake(frame.size.width - 102, 9, rect.size.width, rect.size.height)]; } +- (NSString *) accessibilityLabel { + return name_; +} + - (void) drawContentRect:(CGRect)rect { bool highlighted(highlighted_ && !editing_); @@ -5234,12 +5319,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @implementation FileTable - (void) dealloc { - if (package_ != nil) - [package_ release]; - if (name_ != nil) - [name_ release]; + [self releaseSubviews]; + + [package_ release]; + [name_ release]; [files_ release]; - [list_ release]; + [super dealloc]; } @@ -5265,21 +5350,35 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return cell; } +- (NSURL *) navigationURL { + return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@/files", [package_ id]]]; +} + +- (void) loadView { + [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; + + list_ = [[UITableView alloc] initWithFrame:[[self view] bounds]]; + [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [list_ setRowHeight:24.0f]; + [list_ setDataSource:self]; + [list_ setDelegate:self]; + [[self view] addSubview:list_]; +} + +- (void) viewDidLoad { + [[self navigationItem] setTitle:UCLocalize("INSTALLED_FILES")]; +} + +- (void) releaseSubviews { + [list_ release]; + list_ = nil; +} + - (id) initWithDatabase:(Database *)database { if ((self = [super init]) != nil) { database_ = database; - [[self navigationItem] setTitle:UCLocalize("INSTALLED_FILES")]; - 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]; - [list_ setDelegate:self]; } return self; } @@ -5329,13 +5428,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) reloadData { + [super reloadData]; + [self setPackage:[database_ packageWithName:name_]]; } @end /* }}} */ /* Package Controller {{{ */ -@interface PackageController : CYBrowserController < +@interface CYPackageController : CYBrowserController < UIActionSheetDelegate > { _transient Database *database_; @@ -5346,12 +5447,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { UIBarButtonItem *button_; } -- (id) initWithDatabase:(Database *)database; -- (void) setPackage:(Package *)package; +- (id) initWithDatabase:(Database *)database forPackage:(NSString *)name; @end -@implementation PackageController +@implementation CYPackageController - (void) dealloc { if (package_ != nil) @@ -5367,10 +5467,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [super dealloc]; } -- (void) release { - if ([self retainCount] == 1) - [delegate_ setPackageController:self]; - [super release]; +- (NSURL *) navigationURL { + return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@", name_]]; } /* XXX: this is not safe at all... localization of /fail/ */ @@ -5401,11 +5499,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } } -- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { - [super webView:view didClearWindowObject:window forFrame:frame]; - [window setValue:package_ forKey:@"package"]; -} - - (bool) _allowJavaScriptPanel { return commercial_; } @@ -5466,33 +5559,28 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } #endif -- (id) initWithDatabase:(Database *)database { +- (id) initWithDatabase:(Database *)database forPackage:(NSString *)name { if ((self = [super init]) != nil) { database_ = database; buttons_ = [[NSMutableArray alloc] initWithCapacity:4]; - [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"package" ofType:@"html"]]]; + name_ = [[NSString alloc] initWithString:name]; } return self; } -- (void) setPackage:(Package *)package { - if (package_ != nil) { - [package_ autorelease]; - package_ = nil; - } +- (void) reloadData { + [super reloadData]; - if (name_ != nil) { - [name_ release]; - name_ = nil; - } + if (package_ != nil) + [package_ autorelease]; + package_ = [database_ packageWithName:name_]; [buttons_ removeAllObjects]; - if (package != nil) { - [package parse]; + if (package_ != nil) { + [package_ parse]; - package_ = [package retain]; - name_ = [[package id] retain]; - commercial_ = [package isCommercial]; + package_ = [package_ retain]; + commercial_ = [package_ isCommercial]; if ([package_ mode] != nil) [buttons_ addObject:UCLocalize("CLEAR")]; @@ -5524,21 +5612,18 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { action:@selector(customButtonClicked) ]; - [self reloadURL]; + [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/package/#!/%@", UI_, name_]]]; } - (bool) isLoading { return commercial_ ? [super isLoading] : false; } -- (void) reloadData { - [self setPackage:[database_ packageWithName:name_]]; -} - @end /* }}} */ -/* Package Table {{{ */ -@interface PackageTable : UIView < + +/* Package List Controller {{{ */ +@interface PackageListController : CYViewController < UITableViewDataSource, UITableViewDelegate > { @@ -5549,29 +5634,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { UITableView *list_; NSMutableArray *index_; NSMutableDictionary *indices_; - // XXX: this target_ seems to be delegate_. :( - _transient id target_; - SEL action_; - // XXX: why do we even have this delegate_? - _transient id delegate_; + NSString *title_; } -- (id) initWithFrame:(CGRect)frame database:(Database *)database target:(id)target action:(SEL)action; - +- (id) initWithDatabase:(Database *)database title:(NSString *)title; - (void) setDelegate:(id)delegate; - -- (void) reloadData; - (void) resetCursor; -- (UITableView *) list; - -- (void) setShouldHideHeaderInShortLists:(BOOL)hide; - -- (void) deselectWithAnimation:(BOOL)animated; - @end -@implementation PackageTable +@implementation PackageListController - (void) dealloc { [packages_ release]; @@ -5579,13 +5651,97 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [list_ release]; [index_ release]; [indices_ release]; + [title_ release]; [super dealloc]; } +- (void) deselectWithAnimation:(BOOL)animated { + [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated]; +} + +- (void) resizeForKeyboardBounds:(CGRect)bounds duration:(NSTimeInterval)duration curve:(UIViewAnimationCurve)curve { + CGRect base = [[self view] bounds]; + base.size.height -= bounds.size.height; + base.origin = [list_ frame].origin; + + [UIView beginAnimations:nil context:NULL]; + [UIView setAnimationBeginsFromCurrentState:YES]; + [UIView setAnimationCurve:curve]; + [UIView setAnimationDuration:duration]; + [list_ setFrame:base]; + [UIView commitAnimations]; +} + +- (void) resizeForKeyboardBounds:(CGRect)bounds duration:(NSTimeInterval)duration { + [self resizeForKeyboardBounds:bounds duration:duration curve:UIViewAnimationCurveLinear]; +} + +- (void) resizeForKeyboardBounds:(CGRect)bounds { + [self resizeForKeyboardBounds:bounds duration:0]; +} + +- (void) keyboardWillShow:(NSNotification *)notification { + CGRect bounds; + CGPoint center; + NSTimeInterval duration; + UIViewAnimationCurve curve; + [[[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey] getValue:&bounds]; + [[[notification userInfo] objectForKey:UIKeyboardCenterEndUserInfoKey] getValue:¢er]; + [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&curve]; + [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&duration]; + + CGRect kbframe = CGRectMake(round(center.x - bounds.size.width / 2.0), round(center.y - bounds.size.height / 2.0), bounds.size.width, bounds.size.height); + UIViewController *base = self; + while ([base parentViewController] != nil) + base = [base parentViewController]; + CGRect viewframe = [[base view] convertRect:[list_ frame] fromView:[list_ superview]]; + CGRect intersection = CGRectIntersection(viewframe, kbframe); + + [self resizeForKeyboardBounds:intersection duration:duration curve:curve]; +} + +- (void) keyboardWillHide:(NSNotification *)notification { + NSTimeInterval duration; + UIViewAnimationCurve curve; + [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&curve]; + [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&duration]; + + [self resizeForKeyboardBounds:CGRectZero duration:duration curve:curve]; +} + +- (void) viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + + [self resizeForKeyboardBounds:CGRectZero]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; +} + +- (void) viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + + [self resizeForKeyboardBounds:CGRectZero]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; +} + +- (void) viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; + [self deselectWithAnimation:animated]; +} + +- (void) didSelectPackage:(Package *)package { + CYPackageController *view([[[CYPackageController alloc] initWithDatabase:database_ forPackage:[package id]] autorelease]); + [view setDelegate:delegate_]; + [[self navigationController] pushViewController:view animated:YES]; +} + +#if TryIndexedCollation + (BOOL) hasIndexedCollation { return NO; // XXX: objc_getClass("UILocalizedIndexedCollation") != nil; } +#endif - (NSInteger) numberOfSectionsInTableView:(UITableView *)list { NSInteger count([sections_ count]); @@ -5623,15 +5779,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return cell; } -- (void) deselectWithAnimation:(BOOL)animated { - [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated]; -} - -- (NSIndexPath *) tableView:(UITableView *)table willSelectRowAtIndexPath:(NSIndexPath *)path { +- (void) tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path { Package *package([self packageAtIndexPath:path]); package = [database_ packageWithName:[package id]]; - [target_ performSelector:action_ withObject:package]; - return path; + [self didSelectPackage:package]; } - (NSArray *) sectionIndexTitlesForTableView:(UITableView *)tableView { @@ -5640,32 +5791,37 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { +#if TryIndexedCollation if ([[self class] hasIndexedCollation]) { return [[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionForSectionIndexTitleAtIndex:index]; } +#endif return index; } -- (id) initWithFrame:(CGRect)frame database:(Database *)database target:(id)target action:(SEL)action { - if ((self = [super initWithFrame:frame]) != nil) { +- (id) initWithDatabase:(Database *)database title:(NSString *)title { + if ((self = [super init]) != nil) { database_ = database; + title_ = [title copy]; + [[self navigationItem] setTitle:title_]; - target_ = target; - action_ = action; +#if TryIndexedCollation + if ([[self class] hasIndexedCollation]) + index_ = [[[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionIndexTitles] retain] + else +#endif + index_ = [[NSMutableArray alloc] initWithCapacity:32]; - index_ = [[self class] hasIndexedCollation] - ? [[[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionIndexTitles] retain] - : [[NSMutableArray alloc] initWithCapacity:32]; indices_ = [[NSMutableDictionary alloc] initWithCapacity:32]; packages_ = [[NSMutableArray arrayWithCapacity:16] retain]; sections_ = [[NSMutableArray arrayWithCapacity:16] retain]; - list_ = [[UITableView alloc] initWithFrame:[self bounds] style:UITableViewStylePlain]; + list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain]; [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; [list_ setRowHeight:73]; - [self addSubview:list_]; + [[self view] addSubview:list_]; [list_ setDataSource:self]; [list_ setDelegate:self]; @@ -5681,6 +5837,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) reloadData { + [super reloadData]; + era_ = [database_ era]; NSArray *packages = [database_ packages]; @@ -5697,6 +5855,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { Section *section = nil; +#if TryIndexedCollation if ([[self class] hasIndexedCollation]) { id collation = [objc_getClass("UILocalizedIndexedCollation") currentCollation]; NSArray *titles = [collation sectionIndexTitles]; @@ -5727,7 +5886,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [section addToCount]; } _end - } else { + } else +#endif + { [index_ removeAllObjects]; _profile(PackageTable$reloadData$Section) @@ -5767,18 +5928,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [list_ scrollRectToVisible:CGRectMake(0, 0, 0, 0) animated:NO]; } -- (UITableView *) list { - return list_; -} - -- (void) setShouldHideHeaderInShortLists:(BOOL)hide { - //XXX:[list_ setShouldHideHeaderInShortLists:hide]; -} - @end /* }}} */ -/* Filtered Package Table {{{ */ -@interface FilteredPackageTable : PackageTable { +/* Filtered Package List Controller {{{ */ +@interface FilteredPackageListController : PackageListController { SEL filter_; IMP imp_; id object_; @@ -5787,11 +5940,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) setObject:(id)object; - (void) setObject:(id)object forFilter:(SEL)filter; -- (id) initWithFrame:(CGRect)frame database:(Database *)database target:(id)target action:(SEL)action filter:(SEL)filter with:(id)object; +- (id) initWithDatabase:(Database *)database title:(NSString *)title filter:(SEL)filter with:(id)object; @end -@implementation FilteredPackageTable +@implementation FilteredPackageListController - (void) dealloc { if (object_ != nil) @@ -5829,10 +5982,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { _end } -- (id) initWithFrame:(CGRect)frame database:(Database *)database target:(id)target action:(SEL)action filter:(SEL)filter with:(id)object { - if ((self = [super initWithFrame:frame database:database target:target action:action]) != nil) { +- (id) initWithDatabase:(Database *)database title:(NSString *)title filter:(SEL)filter with:(id)object { + if ((self = [super initWithDatabase:database title:title]) != nil) { [self setFilter:filter]; - object_ = [object retain]; + [self setObject:object]; [self reloadData]; } return self; } @@ -5840,165 +5993,21 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ -/* Filtered Package Controller {{{ */ -@interface FilteredPackageController : CYViewController { - _transient Database *database_; - FilteredPackageTable *packages_; - NSString *title_; -} - -- (id) initWithDatabase:(Database *)database title:(NSString *)title filter:(SEL)filter with:(id)object; - -@end - -@implementation FilteredPackageController - -- (void) dealloc { - [packages_ release]; - [title_ release]; - - [super dealloc]; -} - -- (void) viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; - [packages_ deselectWithAnimation:animated]; -} - -- (void) didSelectPackage:(Package *)package { - PackageController *view([delegate_ packageController]); - [view setPackage:package]; - [view setDelegate:delegate_]; - [[self navigationController] pushViewController:view animated:YES]; -} - -- (NSString *) title { return title_; } - -- (id) initWithDatabase:(Database *)database title:(NSString *)title filter:(SEL)filter with:(id)object { - if ((self = [super init]) != nil) { - database_ = database; - title_ = [title copy]; - [[self navigationItem] setTitle:title_]; - - packages_ = [[FilteredPackageTable alloc] - initWithFrame:[[self view] bounds] - database:database - target:self - action:@selector(didSelectPackage:) - filter:filter - with:object - ]; - - [packages_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [[self view] addSubview:packages_]; - } return self; -} - -- (void) reloadData { - [packages_ reloadData]; -} - -- (void) setDelegate:(id)delegate { - [super setDelegate:delegate]; - [packages_ setDelegate:delegate]; -} - -@end - -/* }}} */ - -/* Installed Controller {{{ */ -@interface InstalledController : FilteredPackageController { - BOOL expert_; -} - -- (id) initWithDatabase:(Database *)database; - -- (void) updateRoleButton; -- (void) queueStatusDidChange; - -@end - -@implementation InstalledController - -- (void) dealloc { - [super dealloc]; -} - -- (NSString *) title { return UCLocalize("INSTALLED"); } - -- (id) initWithDatabase:(Database *)database { - if ((self = [super initWithDatabase:database title:UCLocalize("INSTALLED") filter:@selector(isInstalledAndUnfiltered:) with:[NSNumber numberWithBool:YES]]) != nil) { - [self updateRoleButton]; - [self queueStatusDidChange]; - } return self; -} - -#if !AlwaysReload -- (void) queueButtonClicked { - [delegate_ queue]; -} -#endif - -- (void) queueStatusDidChange { -#if !AlwaysReload - if (IsWildcat_) { - if (Queuing_) { - [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:UCLocalize("QUEUE") - style:UIBarButtonItemStyleDone - target:self - action:@selector(queueButtonClicked) - ] autorelease]]; - } else { - [[self navigationItem] setLeftBarButtonItem:nil]; - } - } -#endif -} - -- (void) reloadData { - [packages_ reloadData]; -} - -- (void) updateRoleButton { - if (Role_ != nil && ![Role_ isEqualToString:@"Developer"]) - [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:(expert_ ? UCLocalize("EXPERT") : UCLocalize("SIMPLE")) - style:(expert_ ? UIBarButtonItemStyleDone : UIBarButtonItemStylePlain) - target:self - action:@selector(roleButtonClicked) - ] autorelease]]; -} - -- (void) roleButtonClicked { - [packages_ setObject:[NSNumber numberWithBool:expert_]]; - [packages_ reloadData]; - expert_ = !expert_; - - [self updateRoleButton]; -} - -- (void) setDelegate:(id)delegate { - [super setDelegate:delegate]; - [packages_ setDelegate:delegate]; -} - -@end -/* }}} */ - /* Home Controller {{{ */ @interface HomeController : CYBrowserController { } - @end @implementation HomeController -+ (BOOL)shouldHideNavigationBar { ++ (BOOL) shouldHideNavigationBar { return NO; } +- (NSURL *) navigationURL { + return [NSURL URLWithString:@"cydia://home"]; +} + - (void) _setMoreHeaders:(NSMutableURLRequest *)request { [super _setMoreHeaders:request]; @@ -6018,7 +6027,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [alert setCancelButtonIndex:0]; [alert setMessage: - @"Copyright (C) 2008-2010\n" + @"Copyright (C) 2008-2011\n" "Jay Freeman (saurik)\n" "saurik@saurik.com\n" "http://www.saurik.com/" @@ -6027,29 +6036,30 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [alert show]; } -- (void) viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; +- (void) viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; if ([[self class] shouldHideNavigationBar]) - [[self navigationController] setNavigationBarHidden:YES animated:animated]; + [[self navigationController] setNavigationBarHidden:NO animated:animated]; } -- (void) viewWillDisappear:(BOOL)animated { - [super viewWillDisappear:animated]; +- (void) viewWillAppear:(BOOL)animated { + if (![self hasLoaded]) + [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/home/", UI_]]]; + + [super viewWillAppear:animated]; if ([[self class] shouldHideNavigationBar]) - [[self navigationController] setNavigationBarHidden:NO animated:animated]; + [[self navigationController] setNavigationBarHidden:YES animated:animated]; } -- (id) init { - if ((self = [super init]) != nil) { - [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:UCLocalize("ABOUT") - style:UIBarButtonItemStylePlain - target:self - action:@selector(aboutButtonClicked) - ] autorelease]]; - } return self; +- (void) viewDidLoad { + [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] + initWithTitle:UCLocalize("ABOUT") + style:UIBarButtonItemStylePlain + target:self + action:@selector(aboutButtonClicked) + ] autorelease]]; } @end @@ -6063,19 +6073,26 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @implementation ManageController -- (id) init { - if ((self = [super init]) != nil) { - [[self navigationItem] setTitle:UCLocalize("MANAGE")]; +- (NSURL *) navigationURL { + return [NSURL URLWithString:@"cydia://manage"]; +} - [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:UCLocalize("SETTINGS") - style:UIBarButtonItemStylePlain - target:self - action:@selector(settingsButtonClicked) - ] autorelease]]; +- (void) viewWillAppear:(BOOL)animated { + if (![self hasLoaded]) + [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/manage/", UI_]]]; - [self queueStatusDidChange]; - } return self; + [super viewWillAppear:animated]; +} + +- (void) viewDidLoad { + [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] + initWithTitle:UCLocalize("SETTINGS") + style:UIBarButtonItemStylePlain + target:self + action:@selector(settingsButtonClicked) + ] autorelease]]; + + [self queueStatusDidChange]; } - (void) settingsButtonClicked { @@ -6088,11 +6105,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) applyLoadingTitle { - // No "Loading" title. + // Disable "Loading" title. } - (void) applyRightButton { - // No right button. + // Disable right button. } #endif @@ -6112,6 +6129,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (bool) isLoading { + // Never show as loading. return false; } @@ -6238,6 +6256,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* Cydia Tab Bar Controller {{{ */ @interface CYTabBarController : UITabBarController < + UITabBarControllerDelegate, ProgressDelegate > { _transient Database *database_; @@ -6249,8 +6268,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { _transient NSObject *updatedelegate_; id root_; + UIViewController *remembered_; + _transient UIViewController *transient_; } +- (NSArray *) navigationURLCollection; - (void) dropBar:(BOOL)animated; - (void) beginUpdate; - (void) raiseBar:(BOOL)animated; @@ -6260,20 +6282,68 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @implementation CYTabBarController -/* XXX: some logic should probably go here related to -freeing the view controllers on tab change */ +- (void) setUnselectedViewController:(UIViewController *)transient { + NSMutableArray *controllers = [[self viewControllers] mutableCopy]; + if (transient != nil) { + if (transient_ == nil) + remembered_ = [[controllers objectAtIndex:0] retain]; + transient_ = transient; + [transient_ setTabBarItem:[remembered_ tabBarItem]]; + [controllers replaceObjectAtIndex:0 withObject:transient_]; + [self setSelectedIndex:0]; + [self setViewControllers:controllers]; + [self concealTabBarSelection]; + } else if (remembered_ != nil) { + [remembered_ setTabBarItem:[transient_ tabBarItem]]; + transient_ = transient; + [controllers replaceObjectAtIndex:0 withObject:remembered_]; + [remembered_ release]; + remembered_ = nil; + [self setViewControllers:controllers]; + [self revealTabBarSelection]; + } +} -- (void) reloadData { - size_t count([[self viewControllers] count]); - for (size_t i(0); i != count; ++i) { - CYNavigationController *page([[self viewControllers] objectAtIndex:(count - i - 1)]); - [page reloadData]; +- (UIViewController *) unselectedViewController { + return transient_; +} + +- (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { + if ([self unselectedViewController]) + [self setUnselectedViewController:nil]; +} + +- (NSArray *) navigationURLCollection { + NSMutableArray *items([NSMutableArray array]); + + // XXX: Should this deal with transient view controllers? + for (id navigation in [self viewControllers]) { + NSArray *stack = [navigation performSelector:@selector(navigationURLCollection)]; + if (stack != nil) + [items addObject:stack]; } + + return items; +} + +- (void) reloadData { + for (CYViewController *controller in [self viewControllers]) + [controller reloadData]; + + [(CYNavigationController *)[self unselectedViewController] reloadData]; +} + +- (void) dealloc { + [refreshbar_ release]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; + + [super dealloc]; } - (id) initWithDatabase:(Database *)database { if ((self = [super init]) != nil) { database_ = database; + [self setDelegate:self]; [[self view] setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameChanged:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil]; @@ -6282,10 +6352,6 @@ freeing the view controllers on tab change */ } return self; } -- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { - return IsWildcat_ || orientation == UIInterfaceOrientationPortrait; -} - - (void) setUpdate:(NSDate *)date { [self beginUpdate]; } @@ -6419,7 +6485,7 @@ freeing the view controllers on tab change */ CGRect barframe([refreshbar_ frame]); - if (false) // XXX: _UIApplicationLinkedOnOrAfter(4) + if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: _UIApplicationLinkedOnOrAfter(4) barframe.origin.y = [self statusBarHeight]; else barframe.origin.y = 0; @@ -6499,21 +6565,15 @@ freeing the view controllers on tab change */ } } -- (void) dealloc { - [refreshbar_ release]; - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [super dealloc]; -} - @end /* }}} */ - /* Cydia Navigation Controller {{{ */ @interface CYNavigationController : UINavigationController { _transient Database *database_; _transient id delegate_; } +- (NSArray *) navigationURLCollection; - (id) initWithDatabase:(Database *)database; - (void) reloadData; @@ -6522,26 +6582,25 @@ freeing the view controllers on tab change */ @implementation CYNavigationController -- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { - // Inherit autorotation settings for modal parents. - if ([self parentViewController] && [[self parentViewController] modalViewController] == self) { - return [[self parentViewController] shouldAutorotateToInterfaceOrientation:orientation]; - } else if ([self parentViewController]) { - return [[self parentViewController] shouldAutorotateToInterfaceOrientation:orientation]; - } else { - return [super shouldAutorotateToInterfaceOrientation:orientation]; +- (NSArray *) navigationURLCollection { + NSMutableArray *stack([NSMutableArray array]); + + for (CYViewController *controller in [self viewControllers]) { + NSString *url = [[controller navigationURL] absoluteString]; + if (url != nil) + [stack addObject:url]; } -} -- (void) dealloc { - [super dealloc]; + return stack; } - (void) reloadData { - size_t count([[self viewControllers] count]); - for (size_t i(0); i != count; ++i) { - CYViewController *page([[self viewControllers] objectAtIndex:(count - i - 1)]); - [page reloadData]; + for (CYViewController *page in [self viewControllers]) { + // Only reload controllers that have already loaded. + // This prevents a page from accidentally loading too + // early if it hasn't been shown on the screen yet. + if ([page hasLoaded]) + [page reloadData]; } } @@ -6557,6 +6616,7 @@ freeing the view controllers on tab change */ @end /* }}} */ + /* Cydia:// Protocol {{{ */ @interface CydiaURLProtocol : NSURLProtocol { } @@ -6658,8 +6718,43 @@ freeing the view controllers on tab change */ @end /* }}} */ +/* Section Controller {{{ */ +@interface SectionController : FilteredPackageListController { + NSString *section_; +} + +- (id) initWithDatabase:(Database *)database section:(NSString *)section; + +@end + +@implementation SectionController + +- (NSURL *) navigationURL { + NSString *name = section_; + if (name == nil) + name = @"all"; + + return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://sections/%@", name]]; +} + +- (id) initWithDatabase:(Database *)database section:(NSString *)name { + NSString *title; + if (name == nil) + title = UCLocalize("ALL_PACKAGES"); + else if (![name isEqual:@""]) + title = [[NSBundle mainBundle] localizedStringForKey:Simplify(name) value:nil table:@"Sections"]; + else + title = UCLocalize("NO_SECTION"); + + if ((self = [super initWithDatabase:database title:title filter:@selector(isVisibleInSection:) with:name]) != nil) { + section_ = name; + } return self; +} + +@end +/* }}} */ /* Sections Controller {{{ */ -@interface CYSectionsController : CYViewController < +@interface SectionsController : CYViewController < UITableViewDataSource, UITableViewDelegate > { @@ -6667,40 +6762,52 @@ freeing the view controllers on tab change */ NSMutableArray *sections_; NSMutableArray *filtered_; UITableView *list_; - UIView *accessory_; BOOL editing_; } - (id) initWithDatabase:(Database *)database; -- (void) reloadData; -- (void) resetView; - - (void) editButtonClicked; @end -@implementation CYSectionsController +@implementation SectionsController - (void) dealloc { - [list_ setDataSource:nil]; - [list_ setDelegate:nil]; - + [self releaseSubviews]; [sections_ release]; [filtered_ release]; - [list_ release]; - [accessory_ release]; + [super dealloc]; } +- (NSURL *) navigationURL { + return [NSURL URLWithString:@"cydia://sections"]; +} + +- (void) updateNavigationItem { + [[self navigationItem] setTitle:editing_ ? UCLocalize("SECTION_VISIBILITY") : UCLocalize("SECTIONS")]; + if ([sections_ count] == 0) { + [[self navigationItem] setRightBarButtonItem:nil]; + } else { + [[self navigationItem] setRightBarButtonItem:[[UIBarButtonItem alloc] + initWithBarButtonSystemItem:(editing_ ? UIBarButtonSystemItemDone : UIBarButtonSystemItemEdit) + target:self + action:@selector(editButtonClicked) + ] animated:([[self navigationItem] rightBarButtonItem] != nil)]; + } +} + +- (BOOL) isEditing { + return editing_; +} + - (void) setEditing:(BOOL)editing { if ((editing_ = editing)) [list_ reloadData]; else [delegate_ updateData]; - [[self navigationItem] setTitle:editing_ ? UCLocalize("SECTION_VISIBILITY") : UCLocalize("SECTIONS")]; - [[[self navigationItem] rightBarButtonItem] setTitle:[sections_ count] == 0 ? nil : editing_ ? UCLocalize("DONE") : UCLocalize("EDIT")]; - [[[self navigationItem] rightBarButtonItem] setStyle:editing_ ? UIBarButtonItemStyleDone : UIBarButtonItemStylePlain]; + [self updateNavigationItem]; } - (void) viewDidAppear:(BOOL)animated { @@ -6729,7 +6836,7 @@ freeing the view controllers on tab change */ - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *reuseIdentifier = @"SectionCell"; - SectionCell *cell = (SectionCell *) [tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; + SectionCell *cell = (SectionCell *)[tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; if (cell == nil) cell = [[[SectionCell alloc] initWithFrame:CGRectZero reuseIdentifier:reuseIdentifier] autorelease]; @@ -6743,59 +6850,48 @@ freeing the view controllers on tab change */ return; Section *section = [self sectionAtIndexPath:indexPath]; - NSString *name = [section name]; - NSString *title; - - if ([indexPath row] == 0) { - section = nil; - name = nil; - title = UCLocalize("ALL_PACKAGES"); - } else { - if (name != nil) { - name = [NSString stringWithString:name]; - title = [[NSBundle mainBundle] localizedStringForKey:Simplify(name) value:nil table:@"Sections"]; - } else { - name = @""; - title = UCLocalize("NO_SECTION"); - } - } - FilteredPackageController *table = [[[FilteredPackageController alloc] + SectionController *controller = [[[SectionController alloc] initWithDatabase:database_ - title:title - filter:@selector(isVisibleInSection:) - with:name + section:[section name] ] autorelease]; + [controller setDelegate:delegate_]; + + [[self navigationController] pushViewController:controller animated:YES]; +} - [table setDelegate:delegate_]; +- (void) loadView { + [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; - [[self navigationController] pushViewController:table animated:YES]; + list_ = [[UITableView alloc] initWithFrame:[[self view] bounds]]; + [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [list_ setRowHeight:45.0f]; + [list_ setDataSource:self]; + [list_ setDelegate:self]; + [[self view] addSubview:list_]; } -- (NSString *) title { return UCLocalize("SECTIONS"); } +- (void) viewDidLoad { + [[self navigationItem] setTitle:UCLocalize("SECTIONS")]; +} + +- (void) releaseSubviews { + [list_ release]; + list_ = nil; +} - (id) initWithDatabase:(Database *)database { if ((self = [super init]) != nil) { database_ = database; - [[self navigationItem] setTitle:UCLocalize("SECTIONS")]; - sections_ = [[NSMutableArray arrayWithCapacity:16] retain]; filtered_ = [[NSMutableArray arrayWithCapacity:16] retain]; - - list_ = [[UITableView alloc] initWithFrame:[[self view] bounds]]; - [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [list_ setRowHeight:45.0f]; - [[self view] addSubview:list_]; - - [list_ setDataSource:self]; - [list_ setDelegate:self]; - - [self reloadData]; } return self; } - (void) reloadData { + [super reloadData]; + NSArray *packages = [database_ packages]; [sections_ removeAllObjects]; @@ -6814,7 +6910,7 @@ freeing the view controllers on tab change */ section = [sections objectForKey:key]; if (section == nil) { _profile(SectionsView$reloadData$Section$Allocate) - section = [[[Section alloc] initWithName:name localize:YES] autorelease]; + section = [[[Section alloc] initWithName:key localize:YES] autorelease]; [sections setObject:section forKey:key]; _end } @@ -6845,32 +6941,18 @@ freeing the view controllers on tab change */ [filtered_ addObject:section]; } - [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:([sections_ count] == 0 ? nil : UCLocalize("EDIT")) - style:UIBarButtonItemStylePlain - target:self - action:@selector(editButtonClicked) - ] autorelease] animated:([[self navigationItem] rightBarButtonItem] != nil)]; - + [self updateNavigationItem]; [list_ reloadData]; _trace(); } -- (void) resetView { - if (editing_) - [self editButtonClicked]; -} - - (void)editButtonClicked { [self setEditing:!editing_]; } -- (UIView *) accessoryView { - return accessory_; -} - @end /* }}} */ + /* Changes Controller {{{ */ @interface ChangesController : CYViewController < UITableViewDataSource, @@ -6885,26 +6967,33 @@ freeing the view controllers on tab change */ BOOL hasSentFirstLoad_; } -- (id) initWithDatabase:(Database *)database delegate:(id)delegate; -- (void) reloadData; +- (id) initWithDatabase:(Database *)database; @end @implementation ChangesController - (void) dealloc { - [list_ setDelegate:nil]; - [list_ setDataSource:nil]; - + [self releaseSubviews]; CFRelease(packages_); - [sections_ release]; - [list_ release]; + [super dealloc]; } +- (NSURL *) navigationURL { + return [NSURL URLWithString:@"cydia://changes"]; +} + +- (void) viewWillAppear:(BOOL)animated { + // Loads after it appears, so don't load beforehand. + loaded_ = YES; + [super viewWillAppear:animated]; +} + - (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; + if (!hasSentFirstLoad_) { hasSentFirstLoad_ = YES; [self performSelector:@selector(reloadData) withObject:nil afterDelay:0.0]; @@ -6957,9 +7046,8 @@ freeing the view controllers on tab change */ - (NSIndexPath *) tableView:(UITableView *)table willSelectRowAtIndexPath:(NSIndexPath *)path { Package *package([self packageAtIndexPath:path]); - PackageController *view([delegate_ packageController]); + CYPackageController *view([[[CYPackageController alloc] initWithDatabase:database_ forPackage:[package id]] autorelease]); [view setDelegate:delegate_]; - [view setPackage:package]; [[self navigationController] pushViewController:view animated:YES]; return path; } @@ -6973,26 +7061,32 @@ freeing the view controllers on tab change */ [delegate_ distUpgrade]; } -- (NSString *) title { return UCLocalize("CHANGES"); } +- (void) loadView { + [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; -- (id) initWithDatabase:(Database *)database delegate:(id)delegate { + list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain]; + [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [list_ setRowHeight:73]; + [list_ setDataSource:self]; + [list_ setDelegate:self]; + [[self view] addSubview:list_]; +} + +- (void) viewDidLoad { + [[self navigationItem] setTitle:UCLocalize("CHANGES")]; +} + +- (void) releaseSubviews { + [list_ release]; + list_ = nil; +} + +- (id) initWithDatabase:(Database *)database { if ((self = [super init]) != nil) { database_ = database; - [[self navigationItem] setTitle:UCLocalize("CHANGES")]; packages_ = CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL); - sections_ = [[NSMutableArray arrayWithCapacity:16] retain]; - - list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain]; - [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [list_ setRowHeight:73]; - [[self view] addSubview:list_]; - - [list_ setDataSource:self]; - [list_ setDelegate:self]; - - delegate_ = delegate; } return self; } @@ -7114,13 +7208,15 @@ freeing the view controllers on tab change */ @end /* }}} */ /* Search Controller {{{ */ -@interface SearchController : FilteredPackageController < +@interface SearchController : FilteredPackageListController < UISearchBarDelegate > { UISearchBar *search_; + BOOL searchloaded_; } - (id) initWithDatabase:(Database *)database; +- (void) setSearchTerm:(NSString *)term; - (void) reloadData; @end @@ -7132,27 +7228,41 @@ freeing the view controllers on tab change */ [super dealloc]; } +- (NSURL *) navigationURL { + if ([search_ text] == nil || [[search_ text] isEqualToString:@""]) + return [NSURL URLWithString:@"cydia://search"]; + else + return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://search/%@", [search_ text]]]; +} + +- (void) setSearchTerm:(NSString *)searchTerm { + [search_ setText:searchTerm]; + [self reloadData]; +} + - (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar { - [packages_ setObject:[search_ text] forFilter:@selector(isUnfilteredAndSearchedForBy:)]; + [self setObject:[search_ text] forFilter:@selector(isUnfilteredAndSearchedForBy:)]; [search_ resignFirstResponder]; [self reloadData]; } - (void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)text { - [packages_ setObject:text forFilter:@selector(isUnfilteredAndSelectedForBy:)]; + [self setObject:text forFilter:@selector(isUnfilteredAndSelectedForBy:)]; [self reloadData]; } -- (NSString *) title { return nil; } - - (id) initWithDatabase:(Database *)database { - return [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:nil]; + if ((self = [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:nil])) { + search_ = [[UISearchBar alloc] init]; + } return self; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; - if (!search_) { - search_ = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, [[self view] bounds].size.width, 44.0f)]; + + if (!searchloaded_) { + searchloaded_ = YES; + [search_ setFrame:CGRectMake(0, 0, [[self view] bounds].size.width, 44.0f)]; [search_ layoutSubviews]; [search_ setPlaceholder:UCLocalize("SEARCH_EX")]; @@ -7169,15 +7279,10 @@ freeing the view controllers on tab change */ } } -- (void) _reloadData { -} - - (void) reloadData { - _profile(SearchController$reloadData) - [packages_ reloadData]; - _end - PrintTimes(); - [packages_ resetCursor]; + [self setObject:[search_ text]]; + [super reloadData]; + [self resetCursor]; } - (void) didSelectPackage:(Package *)package { @@ -7187,8 +7292,8 @@ freeing the view controllers on tab change */ @end /* }}} */ -/* Settings Controller {{{ */ -@interface CYPackageSettingsController : CYViewController < +/* Package Settings Controller {{{ */ +@interface PackageSettingsController : CYViewController < UITableViewDataSource, UITableViewDelegate > { @@ -7206,21 +7311,20 @@ freeing the view controllers on tab change */ @end -@implementation CYPackageSettingsController +@implementation PackageSettingsController - (void) dealloc { + [self releaseSubviews]; [name_ release]; - if (package_ != nil) - [package_ release]; - [table_ release]; - [subscribedSwitch_ release]; - [ignoredSwitch_ release]; - [subscribedCell_ release]; - [ignoredCell_ release]; + [package_ release]; [super dealloc]; } +- (NSURL *) navigationURL { + return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@/settings", [package_ id]]]; +} + - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { if (package_ == nil) return 0; @@ -7235,6 +7339,10 @@ freeing the view controllers on tab change */ return 2; } +- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { + return UCLocalize("CHANGE_PACKAGE_SETTINGS"); +} + - (NSString *) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { return UCLocalize("SHOW_ALL_CHANGES_EX"); } @@ -7265,46 +7373,69 @@ freeing the view controllers on tab change */ return nil; } -- (NSString *) title { return UCLocalize("SETTINGS"); } +- (void) loadView { + [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; -- (id) initWithDatabase:(Database *)database package:(NSString *)package { - if ((self = [super init])) { - database_ = database; - name_ = [package retain]; + table_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped]; + [table_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [table_ setDataSource:self]; + [table_ setDelegate:self]; + [[self view] addSubview:table_]; - [[self navigationItem] setTitle:UCLocalize("SETTINGS")]; + subscribedSwitch_ = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 50, 20)]; + [subscribedSwitch_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; + [subscribedSwitch_ addTarget:self action:@selector(onSubscribed:) forEvents:UIControlEventValueChanged]; - table_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped]; - [table_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [[self view] addSubview:table_]; + ignoredSwitch_ = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 50, 20)]; + [ignoredSwitch_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; + [ignoredSwitch_ addTarget:self action:@selector(onIgnored:) forEvents:UIControlEventValueChanged]; + // Disable this switch, since it only reflects (not modifies) the ignored state. + [ignoredSwitch_ setUserInteractionEnabled:NO]; - subscribedSwitch_ = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 50, 20)]; - [subscribedSwitch_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; - [subscribedSwitch_ addTarget:self action:@selector(onSubscribed:) forEvents:UIControlEventValueChanged]; + subscribedCell_ = [[UITableViewCell alloc] init]; + [subscribedCell_ setText:UCLocalize("SHOW_ALL_CHANGES")]; + [subscribedCell_ setAccessoryView:subscribedSwitch_]; + [subscribedCell_ setSelectionStyle:UITableViewCellSelectionStyleNone]; - ignoredSwitch_ = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 50, 20)]; - [ignoredSwitch_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; - [ignoredSwitch_ addTarget:self action:@selector(onIgnored:) forEvents:UIControlEventValueChanged]; + ignoredCell_ = [[UITableViewCell alloc] init]; + [ignoredCell_ setText:UCLocalize("IGNORE_UPGRADES")]; + [ignoredCell_ setAccessoryView:ignoredSwitch_]; + [ignoredCell_ setSelectionStyle:UITableViewCellSelectionStyleNone]; + // FIXME: Ignored state is not saved. + [ignoredCell_ setUserInteractionEnabled:NO]; +} - subscribedCell_ = [[UITableViewCell alloc] init]; - [subscribedCell_ setText:UCLocalize("SHOW_ALL_CHANGES")]; - [subscribedCell_ setAccessoryView:subscribedSwitch_]; - [subscribedCell_ setSelectionStyle:UITableViewCellSelectionStyleNone]; +- (void) viewDidLoad { + [[self navigationItem] setTitle:UCLocalize("SETTINGS")]; +} - ignoredCell_ = [[UITableViewCell alloc] init]; - [ignoredCell_ setText:UCLocalize("IGNORE_UPGRADES")]; - [ignoredCell_ setAccessoryView:ignoredSwitch_]; - [ignoredCell_ setSelectionStyle:UITableViewCellSelectionStyleNone]; - // FIXME: Ignored state is not saved. - [ignoredCell_ setUserInteractionEnabled:NO]; +- (void) releaseSubviews { + [ignoredCell_ release]; + ignoredCell_ = nil; - [table_ setDataSource:self]; - [table_ setDelegate:self]; - [self reloadData]; + [subscribedCell_ release]; + subscribedCell_ = nil; + + [table_ release]; + table_ = nil; + + [ignoredSwitch_ release]; + ignoredSwitch_ = nil; + + [subscribedSwitch_ release]; + subscribedSwitch_ = nil; +} + +- (id) initWithDatabase:(Database *)database package:(NSString *)package { + if ((self = [super init])) { + database_ = database; + name_ = [package retain]; } return self; } - (void) reloadData { + [super reloadData]; + if (package_ != nil) [package_ autorelease]; package_ = [database_ packageWithName:name_]; @@ -7319,38 +7450,75 @@ freeing the view controllers on tab change */ @end /* }}} */ -/* Signature Controller {{{ */ -@interface SignatureController : CYBrowserController { - _transient Database *database_; - NSString *package_; + +/* Installed Controller {{{ */ +@interface InstalledController : FilteredPackageListController { + BOOL expert_; } -- (id) initWithDatabase:(Database *)database package:(NSString *)package; +- (id) initWithDatabase:(Database *)database; + +- (void) updateRoleButton; +- (void) queueStatusDidChange; @end -@implementation SignatureController +@implementation InstalledController - (void) dealloc { - [package_ release]; [super dealloc]; } -- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { - // XXX: dude! - [super webView:view didClearWindowObject:window forFrame:frame]; +- (NSURL *) navigationURL { + return [NSURL URLWithString:@"cydia://installed"]; } -- (id) initWithDatabase:(Database *)database package:(NSString *)package { - if ((self = [super init]) != nil) { - database_ = database; - package_ = [package retain]; - [self reloadData]; +- (id) initWithDatabase:(Database *)database { + if ((self = [super initWithDatabase:database title:UCLocalize("INSTALLED") filter:@selector(isInstalledAndUnfiltered:) with:[NSNumber numberWithBool:YES]]) != nil) { + [self updateRoleButton]; + [self queueStatusDidChange]; } return self; } -- (void) reloadData { - [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"signature" ofType:@"html"]]]; +#if !AlwaysReload +- (void) queueButtonClicked { + [delegate_ queue]; +} +#endif + +- (void) queueStatusDidChange { +#if !AlwaysReload + if (IsWildcat_) { + if (Queuing_) { + [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] + initWithTitle:UCLocalize("QUEUE") + style:UIBarButtonItemStyleDone + target:self + action:@selector(queueButtonClicked) + ] autorelease]]; + } else { + [[self navigationItem] setLeftBarButtonItem:nil]; + } + } +#endif +} + +- (void) updateRoleButton { + if (Role_ != nil && ![Role_ isEqualToString:@"Developer"]) + [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] + initWithTitle:(expert_ ? UCLocalize("EXPERT") : UCLocalize("SIMPLE")) + style:(expert_ ? UIBarButtonItemStyleDone : UIBarButtonItemStylePlain) + target:self + action:@selector(roleButtonClicked) + ] autorelease]]; +} + +- (void) roleButtonClicked { + [self setObject:[NSNumber numberWithBool:expert_]]; + [self reloadData]; + expert_ = !expert_; + + [self updateRoleButton]; } @end @@ -7416,6 +7584,10 @@ freeing the view controllers on tab change */ } return self; } +- (NSString *) accessibilityLabel { + return label_; +} + - (void) drawContentRect:(CGRect)rect { bool highlighted(highlighted_); float width(rect.size.width); @@ -7437,8 +7609,32 @@ freeing the view controllers on tab change */ @end /* }}} */ -/* Source Table {{{ */ -@interface SourceController : CYViewController < +/* Source Controller {{{ */ +@interface SourceController : FilteredPackageListController { + Source *source_; +} + +- (id) initWithDatabase:(Database *)database source:(Source *)source; + +@end + +@implementation SourceController + +- (NSURL *) navigationURL { + return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://sources/%@", [source_ name]]]; +} + +- (id) initWithDatabase:(Database *)database source:(Source *)source { + source_ = source; + + if ((self = [super initWithDatabase:database title:[source label] filter:@selector(isVisibleInSource:) with:source]) != nil) { + } return self; +} + +@end +/* }}} */ +/* Sources Controller {{{ */ +@interface SourcesController : CYViewController < UITableViewDataSource, UITableViewDelegate > { @@ -7461,12 +7657,11 @@ freeing the view controllers on tab change */ } - (id) initWithDatabase:(Database *)database; - - (void) updateButtonsForEditingStatus:(BOOL)editing animated:(BOOL)animated; @end -@implementation SourceController +@implementation SourcesController - (void) _releaseConnection:(NSURLConnection *)connection { if (connection != nil) { @@ -7477,12 +7672,11 @@ freeing the view controllers on tab change */ } - (void) dealloc { - if (href_ != nil) - [href_ release]; - if (hud_ != nil) - [hud_ release]; - if (error_ != nil) - [error_ release]; + [self releaseSubviews]; + + [href_ release]; + [hud_ release]; + [error_ release]; //[self _releaseConnection:installer_]; [self _releaseConnection:trivial_]; @@ -7491,10 +7685,13 @@ freeing the view controllers on tab change */ //[self _releaseConnection:automatic_]; [sources_ release]; - [list_ release]; [super dealloc]; } +- (NSURL *) navigationURL { + return [NSURL URLWithString:@"cydia://sources"]; +} + - (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated]; @@ -7540,27 +7737,22 @@ freeing the view controllers on tab change */ SourceCell *cell = (SourceCell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if(cell == nil) cell = [[[SourceCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier] autorelease]; [cell setSource:[self sourceAtIndexPath:indexPath]]; + [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; return cell; } -- (UITableViewCellAccessoryType) tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath { - return UITableViewCellAccessoryDisclosureIndicator; -} - - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Source *source = [self sourceAtIndexPath:indexPath]; - FilteredPackageController *packages = [[[FilteredPackageController alloc] + SourceController *controller = [[[SourceController alloc] initWithDatabase:database_ - title:[source label] - filter:@selector(isVisibleInSource:) - with:source + source:source ] autorelease]; - [packages setDelegate:delegate_]; + [controller setDelegate:delegate_]; - [[self navigationController] pushViewController:packages animated:YES]; + [[self navigationController] pushViewController:controller animated:YES]; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { @@ -7633,7 +7825,9 @@ freeing the view controllers on tab change */ message:warning delegate:self cancelButtonTitle:UCLocalize("CANCEL") - otherButtonTitles:UCLocalize("ADD_ANYWAY"), nil + otherButtonTitles: + UCLocalize("ADD_ANYWAY"), + nil ] autorelease]; [alert setContext:@"warning"]; @@ -7701,8 +7895,6 @@ freeing the view controllers on tab change */ [self _endConnection:connection]; } -- (NSString *) title { return UCLocalize("SOURCES"); } - - (NSURLConnection *) _requestHRef:(NSString *)href method:(NSString *)method { NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:href] @@ -7780,27 +7972,37 @@ freeing the view controllers on tab change */ } } -- (id) initWithDatabase:(Database *)database { - if ((self = [super init]) != nil) { - [[self navigationItem] setTitle:UCLocalize("SOURCES")]; - [self updateButtonsForEditingStatus:NO animated:NO]; +- (void) loadView { + [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; - database_ = database; - sources_ = [[NSMutableArray arrayWithCapacity:16] retain]; + list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain]; + [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [list_ setRowHeight:56]; + [list_ setDataSource:self]; + [list_ setDelegate:self]; + [[self view] addSubview:list_]; +} - list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain]; - [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [list_ setRowHeight:56]; - [[self view] addSubview:list_]; +- (void) viewDidLoad { + [[self navigationItem] setTitle:UCLocalize("SOURCES")]; + [self updateButtonsForEditingStatus:NO animated:NO]; +} - [list_ setDataSource:self]; - [list_ setDelegate:self]; +- (void) releaseSubviews { + [list_ release]; + list_ = nil; +} - [self reloadData]; +- (id) initWithDatabase:(Database *)database { + if ((self = [super init]) != nil) { + database_ = database; + sources_ = [[NSMutableArray arrayWithCapacity:16] retain]; } return self; } - (void) reloadData { + [super reloadData]; + pkgSourceList list; if (!list.ReadMainList()) return; @@ -7824,18 +8026,15 @@ freeing the view controllers on tab change */ [list_ reloadData]; } -- (void) addButtonClicked { - /*[book_ pushPage:[[[AddSourceController alloc] - initWithBook:book_ - database:database_ - ] autorelease]];*/ - +- (void) showAddSourcePrompt { UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:UCLocalize("ENTER_APT_URL") message:nil delegate:self cancelButtonTitle:UCLocalize("CANCEL") - otherButtonTitles:UCLocalize("ADD_SOURCE"), nil + otherButtonTitles: + UCLocalize("ADD_SOURCE"), + nil ] autorelease]; [alert setContext:@"source"]; @@ -7854,6 +8053,10 @@ freeing the view controllers on tab change */ [alert show]; } +- (void) addButtonClicked { + [self showAddSourcePrompt]; +} + - (void) updateButtonsForEditingStatus:(BOOL)editing animated:(BOOL)animated { [[self navigationItem] setLeftBarButtonItem:(editing ? [[[UIBarButtonItem alloc] initWithTitle:UCLocalize("ADD") @@ -7891,8 +8094,8 @@ freeing the view controllers on tab change */ @end /* }}} */ -/* Role Controller {{{ */ -@interface CYSettingsController : CYViewController < +/* Settings Controller {{{ */ +@interface SettingsController : CYViewController < UITableViewDataSource, UITableViewDelegate > { @@ -7909,49 +8112,64 @@ freeing the view controllers on tab change */ @end -@implementation CYSettingsController +@implementation SettingsController + - (void) dealloc { + [self releaseSubviews]; + + [super dealloc]; +} + +- (void) loadView { + [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; + + table_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped]; + [table_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [table_ setDelegate:self]; + [table_ setDataSource:self]; + [[self view] addSubview:table_]; + + NSArray *items = [NSArray arrayWithObjects: + UCLocalize("USER"), + UCLocalize("HACKER"), + UCLocalize("DEVELOPER"), + nil]; + segment_ = [[UISegmentedControl alloc] initWithItems:items]; + container_ = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, 44.0f)]; + [container_ addSubview:segment_]; +} + +- (void) viewDidLoad { + [[self navigationItem] setTitle:UCLocalize("WHO_ARE_YOU")]; + + int index = -1; + if ([Role_ isEqualToString:@"User"]) index = 0; + if ([Role_ isEqualToString:@"Hacker"]) index = 1; + if ([Role_ isEqualToString:@"Developer"]) index = 2; + if (index != -1) { + [segment_ setSelectedSegmentIndex:index]; + [self showDoneButton]; + } + + [segment_ addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged]; + [self resizeSegmentedControl]; +} + +- (void) releaseSubviews { [table_ release]; + table_ = nil; + [segment_ release]; - [container_ release]; + segment_ = nil; - [super dealloc]; + [container_ release]; + container_ = nil; } - (id) initWithDatabase:(Database *)database delegate:(id)delegate { if ((self = [super init])) { database_ = database; roledelegate_ = delegate; - - [[self navigationItem] setTitle:UCLocalize("WHO_ARE_YOU")]; - - NSArray *items = [NSArray arrayWithObjects: - UCLocalize("USER"), - UCLocalize("HACKER"), - UCLocalize("DEVELOPER"), - nil]; - segment_ = [[UISegmentedControl alloc] initWithItems:items]; - container_ = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, 44.0f)]; - [container_ addSubview:segment_]; - - int index = -1; - if ([Role_ isEqualToString:@"User"]) index = 0; - if ([Role_ isEqualToString:@"Hacker"]) index = 1; - if ([Role_ isEqualToString:@"Developer"]) index = 2; - if (index != -1) { - [segment_ setSelectedSegmentIndex:index]; - [self showDoneButton]; - } - - [segment_ addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged]; - [self resizeSegmentedControl]; - - table_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped]; - [table_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [table_ setDelegate:self]; - [table_ setDataSource:self]; - [[self view] addSubview:table_]; - [table_ reloadData]; } return self; } @@ -8066,79 +8284,87 @@ freeing the view controllers on tab change */ return section == 3 ? container_ : nil; } +- (void) reloadData { + [super reloadData]; + [table_ reloadData]; +} + @end /* }}} */ /* Stash Controller {{{ */ -@interface CYStashController : CYViewController { - // XXX: just delete these things - _transient UIActivityIndicatorView *spinner_; - _transient UILabel *status_; - _transient UILabel *caption_; +@interface StashController : CYViewController { + UIActivityIndicatorView *spinner_; + UILabel *status_; + UILabel *caption_; } @end -@implementation CYStashController -- (id) init { - if ((self = [super init])) { - [[self view] setBackgroundColor:[UIColor viewFlipsideBackgroundColor]]; +@implementation StashController - spinner_ = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease]; - CGRect spinrect = [spinner_ frame]; - spinrect.origin.x = ([[self view] frame].size.width / 2) - (spinrect.size.width / 2); - spinrect.origin.y = [[self view] frame].size.height - 80.0f; - [spinner_ setFrame:spinrect]; - [spinner_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin]; - [[self view] addSubview:spinner_]; - [spinner_ startAnimating]; +- (void) dealloc { + [self releaseSubviews]; - CGRect captrect; - captrect.size.width = [[self view] frame].size.width; - captrect.size.height = 40.0f; - captrect.origin.x = 0; - captrect.origin.y = ([[self view] frame].size.height / 2) - (captrect.size.height * 2); - caption_ = [[[UILabel alloc] initWithFrame:captrect] autorelease]; - [caption_ setText:UCLocalize("PREPARING_FILESYSTEM")]; - [caption_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin]; - [caption_ setFont:[UIFont boldSystemFontOfSize:28.0f]]; - [caption_ setTextColor:[UIColor whiteColor]]; - [caption_ setBackgroundColor:[UIColor clearColor]]; - [caption_ setShadowColor:[UIColor blackColor]]; - [caption_ setTextAlignment:UITextAlignmentCenter]; - [[self view] addSubview:caption_]; - - CGRect statusrect; - statusrect.size.width = [[self view] frame].size.width; - statusrect.size.height = 30.0f; - statusrect.origin.x = 0; - statusrect.origin.y = ([[self view] frame].size.height / 2) - statusrect.size.height; - status_ = [[[UILabel alloc] initWithFrame:statusrect] autorelease]; - [status_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin]; - [status_ setText:UCLocalize("EXIT_WHEN_COMPLETE")]; - [status_ setFont:[UIFont systemFontOfSize:16.0f]]; - [status_ setTextColor:[UIColor whiteColor]]; - [status_ setBackgroundColor:[UIColor clearColor]]; - [status_ setShadowColor:[UIColor blackColor]]; - [status_ setTextAlignment:UITextAlignmentCenter]; - [[self view] addSubview:status_]; - } return self; + [super dealloc]; +} + +- (void) loadView { + [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; + [[self view] setBackgroundColor:[UIColor viewFlipsideBackgroundColor]]; + + spinner_ = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease]; + CGRect spinrect = [spinner_ frame]; + spinrect.origin.x = ([[self view] frame].size.width / 2) - (spinrect.size.width / 2); + spinrect.origin.y = [[self view] frame].size.height - 80.0f; + [spinner_ setFrame:spinrect]; + [spinner_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin]; + [[self view] addSubview:spinner_]; + [spinner_ startAnimating]; + + CGRect captrect; + captrect.size.width = [[self view] frame].size.width; + captrect.size.height = 40.0f; + captrect.origin.x = 0; + captrect.origin.y = ([[self view] frame].size.height / 2) - (captrect.size.height * 2); + caption_ = [[[UILabel alloc] initWithFrame:captrect] autorelease]; + [caption_ setText:UCLocalize("PREPARING_FILESYSTEM")]; + [caption_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin]; + [caption_ setFont:[UIFont boldSystemFontOfSize:28.0f]]; + [caption_ setTextColor:[UIColor whiteColor]]; + [caption_ setBackgroundColor:[UIColor clearColor]]; + [caption_ setShadowColor:[UIColor blackColor]]; + [caption_ setTextAlignment:UITextAlignmentCenter]; + [[self view] addSubview:caption_]; + + CGRect statusrect; + statusrect.size.width = [[self view] frame].size.width; + statusrect.size.height = 30.0f; + statusrect.origin.x = 0; + statusrect.origin.y = ([[self view] frame].size.height / 2) - statusrect.size.height; + status_ = [[[UILabel alloc] initWithFrame:statusrect] autorelease]; + [status_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin]; + [status_ setText:UCLocalize("EXIT_WHEN_COMPLETE")]; + [status_ setFont:[UIFont systemFontOfSize:16.0f]]; + [status_ setTextColor:[UIColor whiteColor]]; + [status_ setBackgroundColor:[UIColor clearColor]]; + [status_ setShadowColor:[UIColor blackColor]]; + [status_ setTextAlignment:UITextAlignmentCenter]; + [[self view] addSubview:status_]; } -- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { - return IsWildcat_ || orientation == UIInterfaceOrientationPortrait; +- (void) releaseSubviews { + [spinner_ release]; + spinner_ = nil; + + [status_ release]; + status_ = nil; + + [caption_ release]; + caption_ = nil; } + @end /* }}} */ -typedef enum { - kCydiaTag = 0, - kSectionsTag = 1, - kChangesTag = 2, - kManageTag = 3, - kInstalledTag = 4, - kSourcesTag = 5, - kSearchTag = 6 -} CYTabTag; - @interface Cydia : UIApplication < ConfirmationControllerDelegate, ProgressControllerDelegate, @@ -8157,37 +8383,19 @@ typedef enum { Database *database_; NSURL *starturl_; - int tag_; unsigned locked_; unsigned activity_; - CYSectionsController *sections_; - ChangesController *changes_; - ManageController *manage_; - SearchController *search_; - SourceController *sources_; - InstalledController *installed_; - id queueDelegate_; - - CYStashController *stash_; + StashController *stash_; bool loaded_; } -- (CYViewController *) _pageForURL:(NSURL *)url withClass:(Class)_class; -- (void) setPage:(CYViewController *)page; - (void) loadData; -// XXX: I hate prototypes -- (id) queueBadgeController; - @end -static _finline void _setHomePage(Cydia *self) { - [self setPage:[self _pageForURL:[NSURL URLWithString:CydiaURL(@"")] withClass:[HomeController class]]]; -} - @implementation Cydia - (void) beginUpdate { @@ -8207,7 +8415,9 @@ static _finline void _setHomePage(Cydia *self) { message:UCLocalize("HALFINSTALLED_PACKAGE_EX") delegate:self cancelButtonTitle:UCLocalize("FORCIBLY_CLEAR") - otherButtonTitles:UCLocalize("TEMPORARY_IGNORE"), nil + otherButtonTitles: + UCLocalize("TEMPORARY_IGNORE"), + nil ] autorelease]; [alert setContext:@"fixhalf"]; @@ -8220,7 +8430,10 @@ static _finline void _setHomePage(Cydia *self) { message:UCLocalize("ESSENTIAL_UPGRADE_EX") delegate:self cancelButtonTitle:UCLocalize("TEMPORARY_IGNORE") - otherButtonTitles:UCLocalize("UPGRADE_ESSENTIAL"), UCLocalize("COMPLETE_UPGRADE"), nil + otherButtonTitles: + UCLocalize("UPGRADE_ESSENTIAL"), + UCLocalize("COMPLETE_UPGRADE"), + nil ] autorelease]; [alert setContext:@"upgrade"]; @@ -8250,42 +8463,25 @@ static _finline void _setHomePage(Cydia *self) { } } +// Navigation controller for the queuing badge. +- (CYNavigationController *) queueNavigationController { + NSArray *controllers = [tabbar_ viewControllers]; + return [controllers objectAtIndex:3]; +} + - (void) _updateData { [self _saveConfig]; - NSMutableSet *tabs([[[NSMutableSet alloc] initWithCapacity:10] autorelease]); - - [tabs addObject:[tabbar_ selectedViewController]]; + [tabbar_ reloadData]; - if (sections_ != nil) - [tabs addObject:sections_]; - if (changes_ != nil) - [tabs addObject:changes_]; - if (manage_ != nil) - [tabs addObject:manage_]; - if (search_ != nil) - [tabs addObject:search_]; - if (sources_ != nil) - [tabs addObject:sources_]; - if (installed_ != nil) - [tabs addObject:installed_]; + CYNavigationController *navigation = [self queueNavigationController]; - for (CYNavigationController *tab in tabs) - [tab reloadData]; - - [queueDelegate_ queueStatusDidChange]; - [[[self queueBadgeController] tabBarItem] setBadgeValue:(Queuing_ ? UCLocalize("Q_D") : nil)]; -} - -- (int)indexOfTabWithTag:(int)tag { - int i = 0; - for (UINavigationController *controller in [tabbar_ viewControllers]) { - if ([[controller tabBarItem] tag] == tag) - return i; - i += 1; - } + id queuedelegate = nil; + if ([[navigation viewControllers] count] > 0) + queuedelegate = [[navigation viewControllers] objectAtIndex:0]; - return -1; + [queuedelegate queueStatusDidChange]; + [[navigation tabBarItem] setBadgeValue:(Queuing_ ? UCLocalize("Q_D") : nil)]; } - (void) _refreshIfPossible { @@ -8306,8 +8502,7 @@ static _finline void _setHomePage(Cydia *self) { if (recently || loaded_ || ManualRefresh) { [self performSelectorOnMainThread:@selector(_loaded) withObject:nil waitUntilDone:NO]; - // If we are cancelling due to ManualRefresh or a recent refresh - // we need to make sure it knows it's already loaded. + // If we are cancelling, we need to make sure it knows it's already loaded. loaded_ = true; return; } else { @@ -8371,7 +8566,7 @@ static _finline void _setHomePage(Cydia *self) { NSLog(@"changes:#%u", changes); - UITabBarItem *changesItem = [[[tabbar_ viewControllers] objectAtIndex:[self indexOfTabWithTag:kChangesTag]] tabBarItem]; + UITabBarItem *changesItem = [[[tabbar_ viewControllers] objectAtIndex:2] tabBarItem]; if (changes != 0) { _trace(); NSString *badge([[NSNumber numberWithInt:changes] stringValue]); @@ -8542,94 +8737,8 @@ static _finline void _setHomePage(Cydia *self) { [self complete]; } -- (void) setPage:(CYViewController *)page { - [page setDelegate:self]; - - CYNavigationController *navController = (CYNavigationController *) [tabbar_ selectedViewController]; - [navController setViewControllers:[NSArray arrayWithObject:page]]; - for (CYNavigationController *page in [tabbar_ viewControllers]) - if (page != navController) - [page setViewControllers:nil]; -} - -- (CYViewController *) _pageForURL:(NSURL *)url withClass:(Class)_class { - CYBrowserController *browser = [[[_class alloc] init] autorelease]; - [browser loadURL:url]; - return browser; -} - -- (CYSectionsController *) sectionsController { - if (sections_ == nil) - sections_ = [[CYSectionsController alloc] initWithDatabase:database_]; - return sections_; -} - -- (ChangesController *) changesController { - if (changes_ == nil) - changes_ = [[ChangesController alloc] initWithDatabase:database_ delegate:self]; - return changes_; -} - -- (ManageController *) manageController { - if (manage_ == nil) { - manage_ = (ManageController *) [[self - _pageForURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"manage" ofType:@"html"]] - withClass:[ManageController class] - ] retain]; - if (!IsWildcat_) - queueDelegate_ = manage_; - } - return manage_; -} - -- (SearchController *) searchController { - if (search_ == nil) - search_ = [[SearchController alloc] initWithDatabase:database_]; - return search_; -} - -- (SourceController *) sourcesController { - if (sources_ == nil) - sources_ = [[SourceController alloc] initWithDatabase:database_]; - return sources_; -} - -- (InstalledController *) installedController { - if (installed_ == nil) { - installed_ = [[InstalledController alloc] initWithDatabase:database_]; - if (IsWildcat_) - queueDelegate_ = installed_; - } - return installed_; -} - -- (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { - int tag = [[viewController tabBarItem] tag]; - if (tag == tag_) { - [(CYNavigationController *)[tabbar_ selectedViewController] popToRootViewControllerAnimated:YES]; - return; - } else if (tag_ == 1) { - [[self sectionsController] resetView]; - } - - switch (tag) { - case kCydiaTag: _setHomePage(self); break; - - case kSectionsTag: [self setPage:[self sectionsController]]; break; - case kChangesTag: [self setPage:[self changesController]]; break; - case kManageTag: [self setPage:[self manageController]]; break; - case kInstalledTag: [self setPage:[self installedController]]; break; - case kSourcesTag: [self setPage:[self sourcesController]]; break; - case kSearchTag: [self setPage:[self searchController]]; break; - - _nodefault - } - - tag_ = tag; -} - - (void) showSettings { - CYSettingsController *role = [[[CYSettingsController alloc] initWithDatabase:database_ delegate:self] autorelease]; + SettingsController *role = [[[SettingsController alloc] initWithDatabase:database_ delegate:self] autorelease]; CYNavigationController *nav = [[[CYNavigationController alloc] initWithRootViewController:role] autorelease]; if (IsWildcat_) [nav setModalPresentationStyle:UIModalPresentationFormSheet]; @@ -8646,29 +8755,6 @@ static _finline void _setHomePage(Cydia *self) { [self setNetworkActivityIndicatorVisible:NO]; } -- (void) setPackageController:(PackageController *)view { - WebThreadLock(); - [view setPackage:nil]; - WebThreadUnlock(); -} - -- (PackageController *) _packageController { - return [[[PackageController alloc] initWithDatabase:database_] autorelease]; -} - -- (PackageController *) packageController { - return [self _packageController]; -} - -// Returns the navigation controller for the queuing badge. -- (id) queueBadgeController { - int index = [self indexOfTabWithTag:kManageTag]; - if (index == -1) - index = [self indexOfTabWithTag:kInstalledTag]; - - return [[tabbar_ viewControllers] objectAtIndex:index]; -} - - (void) cancelAndClear:(bool)clear { @synchronized (self) { if (clear) { @@ -8686,7 +8772,7 @@ static _finline void _setHomePage(Cydia *self) { NSString *context([alert context]); if ([context isEqualToString:@"fixhalf"]) { - if (button == [alert firstOtherButtonIndex]) { + if (button == [alert cancelButtonIndex]) { @synchronized (self) { for (Package *broken in broken_) { [broken remove]; @@ -8701,7 +8787,7 @@ static _finline void _setHomePage(Cydia *self) { [self resolve]; [self perform]; } - } else if (button == [alert cancelButtonIndex]) { + } else if (button == [alert firstOtherButtonIndex]) { [broken_ removeAllObjects]; [self _loaded]; } @@ -8789,77 +8875,125 @@ static _finline void _setHomePage(Cydia *self) { } - (CYViewController *) pageForPackage:(NSString *)name { - if (Package *package = [database_ packageWithName:name]) { - PackageController *view([self packageController]); - [view setPackage:package]; - return view; - } else { - NSURL *url([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"unknown" ofType:@"html"]]); - url = [NSURL URLWithString:[[url absoluteString] stringByAppendingString:[NSString stringWithFormat:@"?%@", name]]]; - return [self _pageForURL:url withClass:[CYBrowserController class]]; - } + return [[[CYPackageController alloc] initWithDatabase:database_ forPackage:name] autorelease]; } -- (CYViewController *) pageForURL:(NSURL *)url hasTag:(int *)tag { - if (tag != NULL) - *tag = -1; - - NSString *href([url absoluteString]); - if ([href hasPrefix:@"apptapp://package/"]) - return [self pageForPackage:[href substringFromIndex:18]]; - +- (CYViewController *) pageForURL:(NSURL *)url { NSString *scheme([[url scheme] lowercaseString]); - if (![scheme isEqualToString:@"cydia"]) + if ([[url absoluteString] length] <= [scheme length] + 3) return nil; - NSString *path([url absoluteString]); - if ([path length] < 8) + NSString *path([[url absoluteString] substringFromIndex:[scheme length] + 3]); + NSArray *components([path pathComponents]); + + if ([scheme isEqualToString:@"apptapp"] && [components count] > 0 && [[components objectAtIndex:0] isEqualToString:@"package"]) + return [self pageForPackage:[components objectAtIndex:1]]; + + if ([components count] < 1 || ![scheme isEqualToString:@"cydia"]) return nil; - path = [path substringFromIndex:8]; - if (![path hasPrefix:@"/"]) - path = [@"/" stringByAppendingString:path]; - - if ([path isEqualToString:@"/storage"]) - return [self _pageForURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"storage" ofType:@"html"]] withClass:[CYBrowserController class]]; - /*else if ([path isEqualToString:@"/add-source"]) - return [[[AddSourceController alloc] initWithDatabase:database_] autorelease];*/ - else if ([path isEqualToString:@"/sources"]) - return [[[SourceController alloc] initWithDatabase:database_] autorelease]; - else if ([path isEqualToString:@"/packages"]) - return [[[InstalledController alloc] initWithDatabase:database_] autorelease]; - else if ([path hasPrefix:@"/url/"]) - return [self _pageForURL:[NSURL URLWithString:[path substringFromIndex:5]] withClass:[CYBrowserController class]]; - else if ([path hasPrefix:@"/launch/"]) - [self launchApplicationWithIdentifier:[path substringFromIndex:8] suspended:NO]; - else if ([path hasPrefix:@"/package-settings/"]) - return [[[CYPackageSettingsController alloc] initWithDatabase:database_ package:[path substringFromIndex:18]] autorelease]; - else if ([path hasPrefix:@"/package-signature/"]) - return [[[SignatureController alloc] initWithDatabase:database_ package:[path substringFromIndex:19]] autorelease]; - else if ([path hasPrefix:@"/package/"]) - return [self pageForPackage:[path substringFromIndex:9]]; - else if ([path hasPrefix:@"/files/"]) { - NSString *name = [path substringFromIndex:7]; - - if (Package *package = [database_ packageWithName:name]) { - FileTable *files = [[[FileTable alloc] initWithDatabase:database_] autorelease]; - [files setPackage:package]; - return files; + + NSString *base([components objectAtIndex:0]); + + CYViewController *controller = nil; + + if ([base isEqualToString:@"url"]) { + // This kind of URL can contain slashes in the argument, so we can't parse them below. + NSString *destination = [[url absoluteString] substringFromIndex:([scheme length] + [@"://" length] + [base length] + [@"/" length])]; + controller = [[[CYBrowserController alloc] initWithURL:[NSURL URLWithString:destination]] autorelease]; + } else if ([components count] == 1) { + if ([base isEqualToString:@"manage"]) { + controller = [[[ManageController alloc] init] autorelease]; + } + + if ([base isEqualToString:@"sources"]) { + controller = [[[SourcesController alloc] initWithDatabase:database_] autorelease]; + } + + if ([base isEqualToString:@"home"]) { + controller = [[[HomeController alloc] init] autorelease]; + } + + if ([base isEqualToString:@"sections"]) { + controller = [[[SectionsController alloc] initWithDatabase:database_] autorelease]; + } + + if ([base isEqualToString:@"search"]) { + controller = [[[SearchController alloc] initWithDatabase:database_] autorelease]; + } + + if ([base isEqualToString:@"changes"]) { + controller = [[[ChangesController alloc] initWithDatabase:database_] autorelease]; + } + + if ([base isEqualToString:@"installed"]) { + controller = [[[InstalledController alloc] initWithDatabase:database_] autorelease]; + } + } else if ([components count] == 2) { + NSString *argument = [components objectAtIndex:1]; + + if ([base isEqualToString:@"package"]) { + controller = [self pageForPackage:argument]; + } + + if ([base isEqualToString:@"search"]) { + controller = [[[SearchController alloc] initWithDatabase:database_] autorelease]; + [(SearchController *)controller setSearchTerm:argument]; + } + + if ([base isEqualToString:@"sections"]) { + if ([argument isEqualToString:@"all"]) + argument = nil; + controller = [[[SectionController alloc] initWithDatabase:database_ section:argument] autorelease]; + } + + if ([base isEqualToString:@"sources"]) { + if ([argument isEqualToString:@"add"]) { + controller = [[[SourcesController alloc] initWithDatabase:database_] autorelease]; + [(SourcesController *)controller showAddSourcePrompt]; + } else { + NSArray *sources = [database_ sources]; + for (Source *source in sources) { + if ([[source name] caseInsensitiveCompare:argument] == NSOrderedSame) { + controller = [[[SourceController alloc] initWithDatabase:database_ source:source] autorelease]; + break; + } + } + } + } + + if ([base isEqualToString:@"launch"]) { + [self launchApplicationWithIdentifier:argument suspended:NO]; + return nil; + } + } else if ([components count] == 3) { + NSString *arg1 = [components objectAtIndex:1]; + NSString *arg2 = [components objectAtIndex:2]; + + if ([base isEqualToString:@"package"]) { + if ([arg2 isEqualToString:@"settings"]) { + controller = [[[PackageSettingsController alloc] initWithDatabase:database_ package:arg1] autorelease]; + } else if ([arg2 isEqualToString:@"files"]) { + if (Package *package = [database_ packageWithName:arg1]) { + controller = [[[FileTable alloc] initWithDatabase:database_] autorelease]; + [(FileTable *)controller setPackage:package]; + } + } } } - return nil; + [controller setDelegate:self]; + return controller; } - (BOOL) openCydiaURL:(NSURL *)url { - CYViewController *page = nil; - int tag = 0; + CYViewController *page([self pageForURL:url]); - if ((page = [self pageForURL:url hasTag:&tag])) { - [self setPage:page]; - tag_ = tag; - [tabbar_ setSelectedViewController:(tag_ == -1 ? nil : [[tabbar_ viewControllers] objectAtIndex:tag_])]; + if (page != nil) { + CYNavigationController *nav = [[[CYNavigationController alloc] init] autorelease]; + [nav setViewControllers:[NSArray arrayWithObject:page]]; + [tabbar_ setUnselectedViewController:nav]; } - return !!page; + return page != nil; } - (void) applicationOpenURL:(NSURL *)url { @@ -8878,9 +9012,18 @@ static _finline void _setHomePage(Cydia *self) { [super applicationWillResignActive:application]; } +- (void) applicationWillTerminate:(UIApplication *)application { + Changed_ = true; + [Metadata_ setObject:[tabbar_ navigationURLCollection] forKey:@"InterfaceState"]; + [Metadata_ setObject:[NSDate date] forKey:@"LastClosed"]; + [Metadata_ setObject:[NSNumber numberWithInt:[tabbar_ selectedIndex]] forKey:@"InterfaceIndex"]; + + [self _saveConfig]; +} + - (void) addStashController { ++locked_; - stash_ = [[CYStashController alloc] init]; + stash_ = [[StashController alloc] init]; [window_ addSubview:[stash_ view]]; } @@ -8910,47 +9053,48 @@ static _finline void _setHomePage(Cydia *self) { } } -- (void) setupTabBarController { +- (void) setupViewControllers { tabbar_ = [[CYTabBarController alloc] initWithDatabase:database_]; - [tabbar_ setDelegate:self]; 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], + [[[UITabBarItem alloc] initWithTitle:@"Cydia" image:[UIImage applicationImageNamed:@"home.png"] tag:0] autorelease], + [[[UITabBarItem alloc] initWithTitle:UCLocalize("SECTIONS") image:[UIImage applicationImageNamed:@"install.png"] tag:0] autorelease], + [[[UITabBarItem alloc] initWithTitle:UCLocalize("CHANGES") image:[UIImage applicationImageNamed:@"changes.png"] tag:0] autorelease], + [[[UITabBarItem alloc] initWithTitle:UCLocalize("SEARCH") image:[UIImage applicationImageNamed:@"search.png"] tag:0] autorelease], nil]); if (IsWildcat_) { - [items insertObject:[[[UITabBarItem alloc] initWithTitle:UCLocalize("SOURCES") image:[UIImage applicationImageNamed:@"source.png"] tag:kSourcesTag] autorelease] atIndex:3]; - [items insertObject:[[[UITabBarItem alloc] initWithTitle:UCLocalize("INSTALLED") image:[UIImage applicationImageNamed:@"manage.png"] tag:kInstalledTag] autorelease] atIndex:3]; + [items insertObject:[[[UITabBarItem alloc] initWithTitle:UCLocalize("SOURCES") image:[UIImage applicationImageNamed:@"source.png"] tag:0] autorelease] atIndex:3]; + [items insertObject:[[[UITabBarItem alloc] initWithTitle:UCLocalize("INSTALLED") image:[UIImage applicationImageNamed:@"manage.png"] tag:0] autorelease] atIndex:3]; } else { - [items insertObject:[[[UITabBarItem alloc] initWithTitle:UCLocalize("MANAGE") image:[UIImage applicationImageNamed:@"manage.png"] tag:kManageTag] autorelease] atIndex:3]; + [items insertObject:[[[UITabBarItem alloc] initWithTitle:UCLocalize("MANAGE") image:[UIImage applicationImageNamed:@"manage.png"] tag:0] autorelease] atIndex:3]; } NSMutableArray *controllers([NSMutableArray array]); - for (UITabBarItem *item in items) { CYNavigationController *controller([[[CYNavigationController alloc] initWithDatabase:database_] autorelease]); [controller setTabBarItem:item]; [controllers addObject:controller]; } - [tabbar_ setViewControllers:controllers]; + + [tabbar_ setUpdateDelegate:self]; } -- (void)showFakeTabBarInView:(UIView *)view { - static UITabBar *fake = [[UITabBar alloc] initWithFrame:CGRectMake(0, 0, 0, 49.0f)]; +- (CYEmulatedLoadingController *)showEmulatedLoadingControllerInView:(UIView *)view { + static CYEmulatedLoadingController *fake = nil; + if (view != nil) { - CGRect frame = [fake frame]; - frame.origin.y = [view frame].size.height - frame.size.height; - frame.size.width = [view frame].size.width; - [fake setFrame:frame]; - [fake setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin]; - [view addSubview:fake]; + if (fake == nil) + fake = [[CYEmulatedLoadingController alloc] initWithDatabase:database_]; + [view addSubview:[fake view]]; } else { - [fake removeFromSuperview]; + [[fake view] removeFromSuperview]; + [fake release]; + fake = nil; } + + return fake; } - (void) applicationDidFinishLaunching:(id)unused { @@ -8976,8 +9120,6 @@ _trace(); Font18Bold_ = [[UIFont boldSystemFontOfSize:18] retain]; Font22Bold_ = [[UIFont boldSystemFontOfSize:22] retain]; - tag_ = 0; - essential_ = [[NSMutableArray alloc] initWithCapacity:4]; broken_ = [[NSMutableArray alloc] initWithCapacity:4]; @@ -9008,13 +9150,9 @@ _trace(); database_ = [Database sharedInstance]; - [self setupTabBarController]; - [tabbar_ setUpdateDelegate:self]; - [window_ addSubview:[tabbar_ view]]; - - // Show pinstripes while loading data. - [[tabbar_ view] setBackgroundColor:[UIColor pinStripeColor]]; - [self showFakeTabBarInView:[tabbar_ tabBar]]; + [window_ setUserInteractionEnabled:NO]; + [self setupViewControllers]; + [self showEmulatedLoadingControllerInView:window_]; [self performSelector:@selector(loadData) withObject:nil afterDelay:0]; _trace(); @@ -9023,37 +9161,86 @@ _trace(); - (void) loadData { _trace(); if (Role_ == nil) { - [self showSettings]; + [window_ setUserInteractionEnabled:YES]; + + SettingsController *role = [[[SettingsController alloc] initWithDatabase:database_ delegate:self] autorelease]; + CYNavigationController *nav = [[[CYNavigationController alloc] initWithRootViewController:role] autorelease]; + if (IsWildcat_) + [nav setModalPresentationStyle:UIModalPresentationFormSheet]; + [[self showEmulatedLoadingControllerInView:window_] presentModalViewController:nav animated:YES]; + return; + } else { + if ([[self showEmulatedLoadingControllerInView:window_] modalViewController] != nil) + [[self showEmulatedLoadingControllerInView:window_] dismissModalViewControllerAnimated:YES]; + [window_ setUserInteractionEnabled:NO]; } - CGRect fixframe = [[tabbar_ view] frame]; - if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) - fixframe.size = CGSizeMake(fixframe.size.height, fixframe.size.width); - CYLoadingIndicator *loading = [[[CYLoadingIndicator alloc] initWithFrame:fixframe] autorelease]; - [loading setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [[tabbar_ view] addSubview:loading]; - [window_ setUserInteractionEnabled:NO]; - [self reloadData]; PrintTimes(); - // Show the initial page - if (starturl_ == nil || ![self openCydiaURL:starturl_]) { - [tabbar_ setSelectedIndex:0]; - _setHomePage(self); + [window_ addSubview:[tabbar_ view]]; + [self showEmulatedLoadingControllerInView:nil]; + [window_ setUserInteractionEnabled:YES]; + + int selectedIndex = 0; + NSMutableArray *items = nil; + + bool recently = false; + NSDate *closed([Metadata_ objectForKey:@"LastClosed"]); + if (closed != nil) { + NSTimeInterval interval([closed timeIntervalSinceNow]); + // XXX: Is 15 minutes the optimal time here? + if (interval <= 0 && interval > -(15*60)) + recently = true; } - [self showFakeTabBarInView:nil]; + items = [[Metadata_ objectForKey:@"InterfaceState"] mutableCopy]; + selectedIndex = [[Metadata_ objectForKey:@"InterfaceIndex"] intValue]; - [starturl_ release]; - starturl_ = nil; + BOOL enough = YES; + for (NSArray *entry in items) + if ([entry count] <= 0) + enough = NO; - [window_ setUserInteractionEnabled:YES]; + if (!recently || !items || !enough) { + selectedIndex = 0; + items = [NSMutableArray array]; + [items addObject:[NSArray arrayWithObject:@"cydia://home"]]; + [items addObject:[NSArray arrayWithObject:@"cydia://sections"]]; + [items addObject:[NSArray arrayWithObject:@"cydia://changes"]]; + if (!IsWildcat_) { + [items addObject:[NSArray arrayWithObject:@"cydia://manage"]]; + } else { + [items addObject:[NSArray arrayWithObject:@"cydia://installed"]]; + [items addObject:[NSArray arrayWithObject:@"cydia://sources"]]; + } + [items addObject:[NSArray arrayWithObject:@"cydia://search"]]; + } + + [tabbar_ setSelectedIndex:selectedIndex]; + for (unsigned int tab = 0; tab < [[tabbar_ viewControllers] count]; tab++) { + NSArray *stack = [items objectAtIndex:tab]; + CYNavigationController *navigation = [[tabbar_ viewControllers] objectAtIndex:tab]; + NSMutableArray *current = [NSMutableArray array]; + + for (unsigned int nav = 0; nav < [stack count]; nav++) { + NSString *addr = [stack objectAtIndex:nav]; + NSURL *url = [NSURL URLWithString:addr]; + CYViewController *page = [self pageForURL:url]; + if (page != nil) + [current addObject:page]; + } - // XXX: does this actually slow anything down? - [[tabbar_ view] setBackgroundColor:[UIColor clearColor]]; - [loading removeFromSuperview]; + [navigation setViewControllers:current]; + } + + // (Try to) show the startup URL. + if (starturl_ != nil) { + [self openCydiaURL:starturl_]; + [starturl_ release]; + starturl_ = nil; + } } - (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item { @@ -9109,6 +9296,33 @@ MSHook(void, UIHardware$_playSystemSound$, Class self, SEL _cmd, int sound) { } } +Class $UIApplication; + +MSHook(void, UIApplication$_updateApplicationAccessibility, UIApplication *self, SEL _cmd) { + static BOOL initialized = NO; + static BOOL started = NO; + + NSDictionary *dict([[[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.Accessibility.plist"] autorelease]); + BOOL enabled = [[dict objectForKey:@"VoiceOverTouchEnabled"] boolValue] || [[dict objectForKey:@"VoiceOverTouchEnabledByiTunes"] boolValue]; + + if ([self respondsToSelector:@selector(_accessibilityBundlePrincipalClass)]) { + id bundle = [self performSelector:@selector(_accessibilityBundlePrincipalClass)]; + if (![bundle respondsToSelector:@selector(_accessibilityStopServer)]) return; + if (![bundle respondsToSelector:@selector(_accessibilityStartServer)]) return; + + if (initialized && !enabled) { + initialized = NO; + [bundle performSelector:@selector(_accessibilityStopServer)]; + } else if (enabled) { + initialized = YES; + if (!started) { + started = YES; + [bundle performSelector:@selector(_accessibilityStartServer)]; + } + } + } +} + int main(int argc, char *argv[]) { _pooled _trace(); @@ -9118,6 +9332,18 @@ int main(int argc, char *argv[]) { _pooled } else IsWildcat_ = false; + UIScreen *screen([UIScreen mainScreen]); + if ([screen respondsToSelector:@selector(scale)]) + ScreenScale_ = [screen scale]; + else + ScreenScale_ = 1; + + NSMutableArray *parts([NSMutableArray arrayWithCapacity:2]); + if (ScreenScale_ > 1) + [parts addObject:@"@2x"]; + [parts addObject:(IsWildcat_ ? @"~ipad" : @"~iphone")]; + UI_ = CydiaURL([NSString stringWithFormat:@"ui/ios%@", [parts componentsJoinedByString:@""]]); + PackageName = reinterpret_cast(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname)))); /* Library Hacks {{{ */ @@ -9136,6 +9362,13 @@ int main(int argc, char *argv[]) { _pooled _UIHardware$_playSystemSound$ = reinterpret_cast(method_getImplementation(UIHardware$_playSystemSound$)); method_setImplementation(UIHardware$_playSystemSound$, reinterpret_cast(&$UIHardware$_playSystemSound$)); } + + $UIApplication = objc_getClass("UIApplication"); + Method UIApplication$_updateApplicationAccessibility(class_getInstanceMethod($UIApplication, @selector(_updateApplicationAccessibility))); + if (UIApplication$_updateApplicationAccessibility != NULL) { + _UIApplication$_updateApplicationAccessibility = reinterpret_cast(method_getImplementation(UIApplication$_updateApplicationAccessibility)); + method_setImplementation(UIApplication$_updateApplicationAccessibility, reinterpret_cast(&$UIApplication$_updateApplicationAccessibility)); + } /* }}} */ /* Set Locale {{{ */ Locale_ = CFLocaleCopyCurrent(); @@ -9309,11 +9542,15 @@ int main(int argc, char *argv[]) { _pooled _trace(); if (Packages_ != nil) { - CFDictionaryApplyFunction((CFDictionaryRef) Packages_, &PackageImport, NULL); + bool fail(false); + CFDictionaryApplyFunction((CFDictionaryRef) Packages_, &PackageImport, &fail); _trace(); - [Metadata_ removeObjectForKey:@"Packages"]; - Packages_ = nil; - Changed_ = true; + + if (!fail) { + [Metadata_ removeObjectForKey:@"Packages"]; + Packages_ = nil; + Changed_ = true; + } } Finishes_ = [NSArray arrayWithObjects:@"return", @"reopen", @"restart", @"reload", @"reboot", nil];