summaryrefslogtreecommitdiff
path: root/MobileCydia.mm
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2011-02-07 17:01:00 -0800
committerJay Freeman (saurik) <saurik@saurik.com>2011-02-07 17:01:00 -0800
commitbea22a677eadd2f5c34fda37b5fa9656dd2dfa36 (patch)
tree2ba82530a521601fd491f6f7ec199b22f3e42ae0 /MobileCydia.mm
parentecb4a6eeb6305276f0762e036a7eee1fa82c7eef (diff)
parent0923b87ee43c7afe083cb513c887b58515ff3413 (diff)
Merge branch 'restructure'
Diffstat (limited to 'MobileCydia.mm')
-rw-r--r--MobileCydia.mm2041
1 files changed, 1032 insertions, 1009 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm
index 6cbb164..4277e57 100644
--- a/MobileCydia.mm
+++ b/MobileCydia.mm
@@ -402,6 +402,7 @@ static const CFStringCompareFlags LaxCompareFlags_ = kCFCompareCaseInsensitive |
#define ShowInternals (0 && !ForRelease)
#define IgnoreInstall (0 && !ForRelease)
#define AlwaysReload (0 && !ForRelease)
+#define TryIndexedCollation (0 && !ForRelease)
#if !TraceLogging
#undef _trace
@@ -1071,7 +1072,7 @@ static _transient NSMutableDictionary *Sources_;
static bool Changed_;
static time_t now_;
-static bool IsWildcat_;
+bool IsWildcat_;
/* }}} */
/* Display Helpers {{{ */
@@ -1179,12 +1180,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 +1199,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
@@ -2736,6 +2735,8 @@ struct PackageNameOrdering :
if (range.location != NSNotFound)
return YES;
+ [self parse];
+
range = [[self shortDescription] rangeOfString:text options:MatchCompareOptions_];
if (range.location != NSNotFound)
return YES;
@@ -3730,23 +3731,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_;
@@ -4047,6 +4031,41 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
@end
/* }}} */
+/* Emulated Loading Controller {{{ */
+@interface CYEmulatedLoadingController : CYViewController {
+ CYLoadingIndicator *indicator_;
+ UITabBar *tabbar_;
+ UINavigationBar *navbar_;
+}
+@end
+
+@implementation CYEmulatedLoadingController
+
+- (CYEmulatedLoadingController *) init {
+ if ((self = [super init])) {
+ [[self view] setBackgroundColor:[UIColor pinStripeColor]];
+
+ indicator_ = [[CYLoadingIndicator alloc] initWithFrame:[[self view] bounds]];
+ [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
+ [[self view] addSubview:indicator_];
+ [indicator_ release];
+
+ 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_];
+ [tabbar_ release];
+
+ 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_];
+ [navbar_ release];
+ } return self;
+}
+
+@end
+/* }}} */
/* Cydia Browser Controller {{{ */
@interface CYBrowserController : BrowserController {
@@ -4070,18 +4089,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 +4157,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;
@@ -4449,7 +4481,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 +4526,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,
@@ -4870,6 +4901,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
@end
/* }}} */
+
/* Package Cell {{{ */
@interface PackageCell : CYTableViewCell <
ContentDelegate
@@ -4960,6 +4992,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
[self setNeedsDisplay];
}
+- (NSString *) accessibilityLabel {
+ return [NSString stringWithFormat:UCLocalize("COLON_DELIMITED"), name_, description_];
+}
+
- (void) setPackage:(Package *)package {
[self clearPackage];
[package parse];
@@ -5188,6 +5224,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_);
@@ -5335,7 +5375,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
@end
/* }}} */
/* Package Controller {{{ */
-@interface PackageController : CYBrowserController <
+@interface CYPackageController : CYBrowserController <
UIActionSheetDelegate
> {
_transient Database *database_;
@@ -5351,7 +5391,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
@end
-@implementation PackageController
+@implementation CYPackageController
- (void) dealloc {
if (package_ != nil)
@@ -5368,8 +5408,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
}
- (void) release {
- if ([self retainCount] == 1)
- [delegate_ setPackageController:self];
[super release];
}
@@ -5470,7 +5508,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
if ((self = [super init]) != nil) {
database_ = database;
buttons_ = [[NSMutableArray alloc] initWithCapacity:4];
- [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"package" ofType:@"html"]]];
+ [self loadURL:[NSURL URLWithString:CydiaURL(@"ui/package/")]];
} return self;
}
@@ -5537,6 +5575,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
@end
/* }}} */
+
/* Package Table {{{ */
@interface PackageTable : UIView <
UITableViewDataSource,
@@ -5583,9 +5622,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
[super dealloc];
}
+#if TryIndexedCollation
+ (BOOL) hasIndexedCollation {
return NO; // XXX: objc_getClass("UILocalizedIndexedCollation") != nil;
}
+#endif
- (NSInteger) numberOfSectionsInTableView:(UITableView *)list {
NSInteger count([sections_ count]);
@@ -5640,9 +5681,11 @@ 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;
}
@@ -5654,9 +5697,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
target_ = target;
action_ = action;
- index_ = [[self class] hasIndexedCollation]
- ? [[[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionIndexTitles] retain]
- : [[NSMutableArray alloc] initWithCapacity:32];
+#if TryIndexedCollation
+ if ([[self class] hasIndexedCollation])
+ index_ = [[[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionIndexTitles] retain]
+ else
+#endif
+ index_ = [[NSMutableArray alloc] initWithCapacity:32];
+
indices_ = [[NSMutableDictionary alloc] initWithCapacity:32];
packages_ = [[NSMutableArray arrayWithCapacity:16] retain];
@@ -5697,6 +5744,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 +5775,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
[section addToCount];
}
_end
- } else {
+ } else
+#endif
+ {
[index_ removeAllObjects];
_profile(PackageTable$reloadData$Section)
@@ -5839,7 +5889,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
@end
/* }}} */
-
/* Filtered Package Controller {{{ */
@interface FilteredPackageController : CYViewController {
_transient Database *database_;
@@ -5866,7 +5915,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
}
- (void) didSelectPackage:(Package *)package {
- PackageController *view([delegate_ packageController]);
+ CYPackageController *view([[[CYPackageController alloc] initWithDatabase:database_] autorelease]);
[view setPackage:package];
[view setDelegate:delegate_];
[[self navigationController] pushViewController:view animated:YES];
@@ -5907,625 +5956,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
/* }}} */
-/* Source Cell {{{ */
-@interface SourceCell : CYTableViewCell <
- ContentDelegate
-> {
- UIImage *icon_;
- NSString *origin_;
- NSString *label_;
-}
-
-- (void) setSource:(Source *)source;
-
-@end
-
-@implementation SourceCell
-
-- (void) clearSource {
- [icon_ release];
- [origin_ release];
- [label_ release];
-
- icon_ = nil;
- origin_ = nil;
- label_ = nil;
-}
-
-- (void) setSource:(Source *)source {
- [self clearSource];
-
- if (icon_ == nil)
- icon_ = [UIImage applicationImageNamed:[NSString stringWithFormat:@"Sources/%@.png", [source host]]];
- if (icon_ == nil)
- icon_ = [UIImage applicationImageNamed:@"unknown.png"];
- icon_ = [icon_ retain];
-
- origin_ = [[source name] retain];
- label_ = [[source uri] retain];
-
- [content_ setNeedsDisplay];
-}
-
-- (void) dealloc {
- [self clearSource];
- [super dealloc];
-}
-
-- (SourceCell *) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
- if ((self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) != nil) {
- UIView *content([self contentView]);
- CGRect bounds([content bounds]);
-
- content_ = [[ContentView alloc] initWithFrame:bounds];
- [content_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
- [content_ setBackgroundColor:[UIColor whiteColor]];
- [content addSubview:content_];
-
- [content_ setDelegate:self];
- [content_ setOpaque:YES];
- } return self;
-}
-
-- (void) drawContentRect:(CGRect)rect {
- bool highlighted(highlighted_);
- float width(rect.size.width);
-
- if (icon_ != nil)
- [icon_ drawInRect:CGRectMake(10, 10, 30, 30)];
-
- if (highlighted)
- UISetColor(White_);
-
- if (!highlighted)
- UISetColor(Black_);
- [origin_ drawAtPoint:CGPointMake(48, 8) forWidth:(width - 80) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation];
-
- if (!highlighted)
- UISetColor(Blue_);
- [label_ drawAtPoint:CGPointMake(58, 29) forWidth:(width - 95) withFont:Font12_ lineBreakMode:UILineBreakModeTailTruncation];
-}
-
-@end
-/* }}} */
-/* Source Table {{{ */
-@interface SourceController : CYViewController <
- UITableViewDataSource,
- UITableViewDelegate
-> {
- _transient Database *database_;
- UITableView *list_;
- NSMutableArray *sources_;
- int offset_;
-
- NSString *href_;
- UIProgressHUD *hud_;
- NSError *error_;
-
- //NSURLConnection *installer_;
- NSURLConnection *trivial_;
- NSURLConnection *trivial_bz2_;
- NSURLConnection *trivial_gz_;
- //NSURLConnection *automatic_;
-
- BOOL cydia_;
-}
-
-- (id) initWithDatabase:(Database *)database;
-
-- (void) updateButtonsForEditingStatus:(BOOL)editing animated:(BOOL)animated;
-
-@end
-
-@implementation SourceController
-
-- (void) _releaseConnection:(NSURLConnection *)connection {
- if (connection != nil) {
- [connection cancel];
- //[connection setDelegate:nil];
- [connection release];
- }
-}
-
-- (void) dealloc {
- if (href_ != nil)
- [href_ release];
- if (hud_ != nil)
- [hud_ release];
- if (error_ != nil)
- [error_ release];
-
- //[self _releaseConnection:installer_];
- [self _releaseConnection:trivial_];
- [self _releaseConnection:trivial_gz_];
- [self _releaseConnection:trivial_bz2_];
- //[self _releaseConnection:automatic_];
-
- [sources_ release];
- [list_ release];
- [super dealloc];
-}
-
-- (void) viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated];
-}
-
-- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
- return offset_ == 0 ? 1 : 2;
-}
-
-- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- switch (section + (offset_ == 0 ? 1 : 0)) {
- case 0: return UCLocalize("ENTERED_BY_USER");
- case 1: return UCLocalize("INSTALLED_BY_PACKAGE");
-
- _nodefault
- }
-}
-
-- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- int count = [sources_ count];
- switch (section) {
- case 0: return (offset_ == 0 ? count : offset_);
- case 1: return count - offset_;
-
- _nodefault
- }
-}
-
-- (Source *) sourceAtIndexPath:(NSIndexPath *)indexPath {
- unsigned idx = 0;
- switch (indexPath.section) {
- case 0: idx = indexPath.row; break;
- case 1: idx = indexPath.row + offset_; break;
-
- _nodefault
- }
- return [sources_ objectAtIndex:idx];
-}
-
-- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *cellIdentifier = @"SourceCell";
-
- SourceCell *cell = (SourceCell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
- if(cell == nil) cell = [[[SourceCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier] autorelease];
- [cell setSource:[self sourceAtIndexPath:indexPath]];
-
- 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]
- initWithDatabase:database_
- title:[source label]
- filter:@selector(isVisibleInSource:)
- with:source
- ] autorelease];
-
- [packages setDelegate:delegate_];
-
- [[self navigationController] pushViewController:packages animated:YES];
-}
-
-- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
- Source *source = [self sourceAtIndexPath:indexPath];
- return [source record] != nil;
-}
-
-- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- Source *source = [self sourceAtIndexPath:indexPath];
- [Sources_ removeObjectForKey:[source key]];
- [delegate_ syncData];
-}
-
-- (void) complete {
- [Sources_ setObject:[NSDictionary dictionaryWithObjectsAndKeys:
- @"deb", @"Type",
- href_, @"URI",
- @"./", @"Distribution",
- nil] forKey:[NSString stringWithFormat:@"deb:%@:./", href_]];
-
- [delegate_ syncData];
-}
-
-- (NSString *) getWarning {
- NSString *href(href_);
- NSRange colon([href rangeOfString:@"://"]);
- if (colon.location != NSNotFound)
- href = [href substringFromIndex:(colon.location + 3)];
- href = [href stringByAddingPercentEscapes];
- href = [CydiaURL(@"api/repotag/") stringByAppendingString:href];
- href = [href stringByCachingURLWithCurrentCDN];
-
- NSURL *url([NSURL URLWithString:href]);
-
- NSStringEncoding encoding;
- NSError *error(nil);
-
- if (NSString *warning = [NSString stringWithContentsOfURL:url usedEncoding:&encoding error:&error])
- return [warning length] == 0 ? nil : warning;
- return nil;
-}
-
-- (void) _endConnection:(NSURLConnection *)connection {
- // XXX: the memory management in this method is horribly awkward
-
- NSURLConnection **field = NULL;
- if (connection == trivial_)
- field = &trivial_;
- else if (connection == trivial_bz2_)
- field = &trivial_bz2_;
- else if (connection == trivial_gz_)
- field = &trivial_gz_;
- _assert(field != NULL);
- [connection release];
- *field = nil;
-
- if (
- trivial_ == nil &&
- trivial_bz2_ == nil &&
- trivial_gz_ == nil
- ) {
- bool defer(false);
-
- if (cydia_) {
- if (NSString *warning = [self yieldToSelector:@selector(getWarning)]) {
- defer = true;
-
- UIAlertView *alert = [[[UIAlertView alloc]
- initWithTitle:UCLocalize("SOURCE_WARNING")
- message:warning
- delegate:self
- cancelButtonTitle:UCLocalize("CANCEL")
- otherButtonTitles:UCLocalize("ADD_ANYWAY"), nil
- ] autorelease];
-
- [alert setContext:@"warning"];
- [alert setNumberOfRows:1];
- [alert show];
- } else
- [self complete];
- } else if (error_ != nil) {
- UIAlertView *alert = [[[UIAlertView alloc]
- initWithTitle:UCLocalize("VERIFICATION_ERROR")
- message:[error_ localizedDescription]
- delegate:self
- cancelButtonTitle:UCLocalize("OK")
- otherButtonTitles:nil
- ] autorelease];
-
- [alert setContext:@"urlerror"];
- [alert show];
- } else {
- UIAlertView *alert = [[[UIAlertView alloc]
- initWithTitle:UCLocalize("NOT_REPOSITORY")
- message:UCLocalize("NOT_REPOSITORY_EX")
- delegate:self
- cancelButtonTitle:UCLocalize("OK")
- otherButtonTitles:nil
- ] autorelease];
-
- [alert setContext:@"trivial"];
- [alert show];
- }
-
- [delegate_ setStatusBarShowsProgress:NO];
- [delegate_ removeProgressHUD:hud_];
-
- [hud_ autorelease];
- hud_ = nil;
-
- if (!defer) {
- [href_ release];
- href_ = nil;
- }
-
- if (error_ != nil) {
- [error_ release];
- error_ = nil;
- }
- }
-}
-
-- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response {
- switch ([response statusCode]) {
- case 200:
- cydia_ = YES;
- }
-}
-
-- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
- lprintf("connection:\"%s\" didFailWithError:\"%s\"", [href_ UTF8String], [[error localizedDescription] UTF8String]);
- if (error_ != nil)
- error_ = [error retain];
- [self _endConnection:connection];
-}
-
-- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
- [self _endConnection:connection];
-}
-
-- (NSString *) title { return UCLocalize("SOURCES"); }
-
-- (NSURLConnection *) _requestHRef:(NSString *)href method:(NSString *)method {
- NSMutableURLRequest *request = [NSMutableURLRequest
- requestWithURL:[NSURL URLWithString:href]
- cachePolicy:NSURLRequestUseProtocolCachePolicy
- timeoutInterval:120.0
- ];
-
- [request setHTTPMethod:method];
-
- if (Machine_ != NULL)
- [request setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"];
- if (UniqueID_ != nil)
- [request setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"];
- if (Role_ != nil)
- [request setValue:Role_ forHTTPHeaderField:@"X-Role"];
-
- return [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
-}
-
-- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
- NSString *context([alert context]);
-
- if ([context isEqualToString:@"source"]) {
- switch (button) {
- case 1: {
- NSString *href = [[alert textField] text];
-
- //installer_ = [[self _requestHRef:href method:@"GET"] retain];
-
- if (![href hasSuffix:@"/"])
- href_ = [href stringByAppendingString:@"/"];
- else
- href_ = href;
- href_ = [href_ retain];
-
- trivial_ = [[self _requestHRef:[href_ stringByAppendingString:@"Packages"] method:@"HEAD"] retain];
- trivial_bz2_ = [[self _requestHRef:[href_ stringByAppendingString:@"Packages.bz2"] method:@"HEAD"] retain];
- trivial_gz_ = [[self _requestHRef:[href_ stringByAppendingString:@"Packages.gz"] method:@"HEAD"] retain];
- //trivial_bz2_ = [[self _requestHRef:[href stringByAppendingString:@"dists/Release"] method:@"HEAD"] retain];
-
- cydia_ = false;
-
- // XXX: this is stupid
- hud_ = [[delegate_ addProgressHUD] retain];
- [hud_ setText:UCLocalize("VERIFYING_URL")];
- } break;
-
- case 0:
- break;
-
- _nodefault
- }
-
- [alert dismissWithClickedButtonIndex:-1 animated:YES];
- } else if ([context isEqualToString:@"trivial"])
- [alert dismissWithClickedButtonIndex:-1 animated:YES];
- else if ([context isEqualToString:@"urlerror"])
- [alert dismissWithClickedButtonIndex:-1 animated:YES];
- else if ([context isEqualToString:@"warning"]) {
- switch (button) {
- case 1:
- [self complete];
- break;
-
- case 0:
- break;
-
- _nodefault
- }
-
- [href_ release];
- href_ = nil;
-
- [alert dismissWithClickedButtonIndex:-1 animated:YES];
- }
-}
-
-- (id) initWithDatabase:(Database *)database {
- if ((self = [super init]) != nil) {
- [[self navigationItem] setTitle:UCLocalize("SOURCES")];
- [self updateButtonsForEditingStatus:NO animated:NO];
-
- database_ = database;
- sources_ = [[NSMutableArray arrayWithCapacity:16] retain];
-
- list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain];
- [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
- [list_ setRowHeight:56];
- [[self view] addSubview:list_];
-
- [list_ setDataSource:self];
- [list_ setDelegate:self];
-
- [self reloadData];
- } return self;
-}
-
-- (void) reloadData {
- pkgSourceList list;
- if (!list.ReadMainList())
- return;
-
- [sources_ removeAllObjects];
- [sources_ addObjectsFromArray:[database_ sources]];
- _trace();
- [sources_ sortUsingSelector:@selector(compareByNameAndType:)];
- _trace();
-
- int count([sources_ count]);
- offset_ = 0;
- for (int i = 0; i != count; i++) {
- if ([[sources_ objectAtIndex:i] record] == nil)
- break;
- offset_++;
- }
-
- [list_ setEditing:NO];
- [self updateButtonsForEditingStatus:NO animated:NO];
- [list_ reloadData];
-}
-
-- (void) addButtonClicked {
- /*[book_ pushPage:[[[AddSourceController alloc]
- initWithBook:book_
- database:database_
- ] autorelease]];*/
-
- UIAlertView *alert = [[[UIAlertView alloc]
- initWithTitle:UCLocalize("ENTER_APT_URL")
- message:nil
- delegate:self
- cancelButtonTitle:UCLocalize("CANCEL")
- otherButtonTitles:UCLocalize("ADD_SOURCE"), nil
- ] autorelease];
-
- [alert setContext:@"source"];
- [alert setTransform:CGAffineTransformTranslate([alert transform], 0.0, 100.0)];
-
- [alert setNumberOfRows:1];
- [alert addTextFieldWithValue:@"http://" label:@""];
-
- UITextInputTraits *traits = [[alert textField] textInputTraits];
- [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
- [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
- [traits setKeyboardType:UIKeyboardTypeURL];
- // XXX: UIReturnKeyDone
- [traits setReturnKeyType:UIReturnKeyNext];
-
- [alert show];
-}
-
-- (void) updateButtonsForEditingStatus:(BOOL)editing animated:(BOOL)animated {
- [[self navigationItem] setLeftBarButtonItem:(editing ? [[[UIBarButtonItem alloc]
- initWithTitle:UCLocalize("ADD")
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(addButtonClicked)
- ] autorelease] : [[self navigationItem] backBarButtonItem]) animated:animated];
-
- [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc]
- initWithTitle:(editing ? UCLocalize("DONE") : UCLocalize("EDIT"))
- style:(editing ? UIBarButtonItemStyleDone : UIBarButtonItemStylePlain)
- target:self
- action:@selector(editButtonClicked)
- ] autorelease] animated:animated];
-
- if (IsWildcat_ && !editing)
- [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
- initWithTitle:UCLocalize("SETTINGS")
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(settingsButtonClicked)
- ] autorelease]];
-}
-
-- (void) settingsButtonClicked {
- [delegate_ showSettings];
-}
-
-- (void) editButtonClicked {
- [list_ setEditing:![list_ isEditing] animated:YES];
-
- [self updateButtonsForEditingStatus:[list_ isEditing] animated:YES];
-}
-
-@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
@@ -6578,6 +6011,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
- (id) init {
if ((self = [super init]) != nil) {
+ [self loadURL:[NSURL URLWithString:CydiaURL(@"ui/home/")]];
+
[[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
initWithTitle:UCLocalize("ABOUT")
style:UIBarButtonItemStylePlain
@@ -6602,6 +6037,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
if ((self = [super init]) != nil) {
[[self navigationItem] setTitle:UCLocalize("MANAGE")];
+ [self loadURL:[NSURL URLWithString:CydiaURL(@"ui/manage/")]];
+
[[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
initWithTitle:UCLocalize("SETTINGS")
style:UIBarButtonItemStylePlain
@@ -6795,15 +6232,14 @@ 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) 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];
}
+
+ [(CYNavigationController *)[self transientViewController] reloadData];
}
- (id) initWithDatabase:(Database *)database {
@@ -6817,10 +6253,6 @@ freeing the view controllers on tab change */
} return self;
}
-- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
- return IsWildcat_ || orientation == UIInterfaceOrientationPortrait;
-}
-
- (void) setUpdate:(NSDate *)date {
[self beginUpdate];
}
@@ -6954,7 +6386,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;
@@ -7042,7 +6474,6 @@ freeing the view controllers on tab change */
@end
/* }}} */
-
/* Cydia Navigation Controller {{{ */
@interface CYNavigationController : UINavigationController {
_transient Database *database_;
@@ -7057,17 +6488,6 @@ 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];
- }
-}
-
- (void) dealloc {
[super dealloc];
}
@@ -7092,6 +6512,7 @@ freeing the view controllers on tab change */
@end
/* }}} */
+
/* Cydia:// Protocol {{{ */
@interface CydiaURLProtocol : NSURLProtocol {
}
@@ -7193,8 +6614,35 @@ freeing the view controllers on tab change */
@end
/* }}} */
+/* Section Controller {{{ */
+@interface SectionController : FilteredPackageController {
+}
+
+- (id) initWithDatabase:(Database *)database section:(NSString *)section;
+
+@end
+
+@implementation SectionController
+
+- (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) {
+ } return self;
+}
+
+@end
+/* }}} */
/* Sections Controller {{{ */
-@interface CYSectionsController : CYViewController <
+@interface SectionsController : CYViewController <
UITableViewDataSource,
UITableViewDelegate
> {
@@ -7202,7 +6650,6 @@ freeing the view controllers on tab change */
NSMutableArray *sections_;
NSMutableArray *filtered_;
UITableView *list_;
- UIView *accessory_;
BOOL editing_;
}
@@ -7214,7 +6661,7 @@ freeing the view controllers on tab change */
@end
-@implementation CYSectionsController
+@implementation SectionsController
- (void) dealloc {
[list_ setDataSource:nil];
@@ -7223,19 +6670,29 @@ freeing the view controllers on tab change */
[sections_ release];
[filtered_ release];
[list_ release];
- [accessory_ release];
[super dealloc];
}
+- (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)];
+ }
+}
+
- (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 {
@@ -7278,37 +6735,16 @@ 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_];
- [table setDelegate:delegate_];
-
- [[self navigationController] pushViewController:table animated:YES];
+ [[self navigationController] pushViewController:controller animated:YES];
}
-- (NSString *) title { return UCLocalize("SECTIONS"); }
-
- (id) initWithDatabase:(Database *)database {
if ((self = [super init]) != nil) {
database_ = database;
@@ -7380,13 +6816,7 @@ 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();
}
@@ -7400,12 +6830,9 @@ freeing the view controllers on tab change */
[self setEditing:!editing_];
}
-- (UIView *) accessoryView {
- return accessory_;
-}
-
@end
/* }}} */
+
/* Changes Controller {{{ */
@interface ChangesController : CYViewController <
UITableViewDataSource,
@@ -7420,8 +6847,7 @@ freeing the view controllers on tab change */
BOOL hasSentFirstLoad_;
}
-- (id) initWithDatabase:(Database *)database delegate:(id)delegate;
-- (void) reloadData;
+- (id) initWithDatabase:(Database *)database;
@end
@@ -7492,7 +6918,7 @@ 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_] autorelease]);
[view setDelegate:delegate_];
[view setPackage:package];
[[self navigationController] pushViewController:view animated:YES];
@@ -7510,13 +6936,12 @@ freeing the view controllers on tab change */
- (NSString *) title { return UCLocalize("CHANGES"); }
-- (id) initWithDatabase:(Database *)database delegate:(id)delegate {
+- (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];
@@ -7526,8 +6951,6 @@ freeing the view controllers on tab change */
[list_ setDataSource:self];
[list_ setDelegate:self];
-
- delegate_ = delegate;
} return self;
}
@@ -7656,6 +7079,7 @@ freeing the view controllers on tab change */
}
- (id) initWithDatabase:(Database *)database;
+- (void) setSearchTerm:(NSString *)term;
- (void) reloadData;
@end
@@ -7667,6 +7091,10 @@ freeing the view controllers on tab change */
[super dealloc];
}
+- (void) setSearchTerm:(NSString *)searchTerm {
+ [search_ setText:searchTerm];
+}
+
- (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[packages_ setObject:[search_ text] forFilter:@selector(isUnfilteredAndSearchedForBy:)];
[search_ resignFirstResponder];
@@ -7678,8 +7106,6 @@ freeing the view controllers on tab change */
[self reloadData];
}
-- (NSString *) title { return nil; }
-
- (id) initWithDatabase:(Database *)database {
return [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:nil];
}
@@ -7722,8 +7148,8 @@ freeing the view controllers on tab change */
@end
/* }}} */
-/* Settings Controller {{{ */
-@interface CYPackageSettingsController : CYViewController <
+/* Package Settings Controller {{{ */
+@interface PackageSettingsController : CYViewController <
UITableViewDataSource,
UITableViewDelegate
> {
@@ -7741,7 +7167,7 @@ freeing the view controllers on tab change */
@end
-@implementation CYPackageSettingsController
+@implementation PackageSettingsController
- (void) dealloc {
[name_ release];
@@ -7770,6 +7196,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");
}
@@ -7820,6 +7250,8 @@ freeing the view controllers on tab change */
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];
subscribedCell_ = [[UITableViewCell alloc] init];
[subscribedCell_ setText:UCLocalize("SHOW_ALL_CHANGES")];
@@ -7891,8 +7323,638 @@ freeing the view controllers on tab change */
@end
/* }}} */
-/* Role Controller {{{ */
-@interface CYSettingsController : CYViewController <
+/* 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
+/* }}} */
+
+/* Source Cell {{{ */
+@interface SourceCell : CYTableViewCell <
+ ContentDelegate
+> {
+ UIImage *icon_;
+ NSString *origin_;
+ NSString *label_;
+}
+
+- (void) setSource:(Source *)source;
+
+@end
+
+@implementation SourceCell
+
+- (void) clearSource {
+ [icon_ release];
+ [origin_ release];
+ [label_ release];
+
+ icon_ = nil;
+ origin_ = nil;
+ label_ = nil;
+}
+
+- (void) setSource:(Source *)source {
+ [self clearSource];
+
+ if (icon_ == nil)
+ icon_ = [UIImage applicationImageNamed:[NSString stringWithFormat:@"Sources/%@.png", [source host]]];
+ if (icon_ == nil)
+ icon_ = [UIImage applicationImageNamed:@"unknown.png"];
+ icon_ = [icon_ retain];
+
+ origin_ = [[source name] retain];
+ label_ = [[source uri] retain];
+
+ [content_ setNeedsDisplay];
+}
+
+- (void) dealloc {
+ [self clearSource];
+ [super dealloc];
+}
+
+- (SourceCell *) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
+ if ((self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) != nil) {
+ UIView *content([self contentView]);
+ CGRect bounds([content bounds]);
+
+ content_ = [[ContentView alloc] initWithFrame:bounds];
+ [content_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
+ [content_ setBackgroundColor:[UIColor whiteColor]];
+ [content addSubview:content_];
+
+ [content_ setDelegate:self];
+ [content_ setOpaque:YES];
+ } return self;
+}
+
+- (NSString *) accessibilityLabel {
+ return label_;
+}
+
+- (void) drawContentRect:(CGRect)rect {
+ bool highlighted(highlighted_);
+ float width(rect.size.width);
+
+ if (icon_ != nil)
+ [icon_ drawInRect:CGRectMake(10, 10, 30, 30)];
+
+ if (highlighted)
+ UISetColor(White_);
+
+ if (!highlighted)
+ UISetColor(Black_);
+ [origin_ drawAtPoint:CGPointMake(48, 8) forWidth:(width - 80) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation];
+
+ if (!highlighted)
+ UISetColor(Blue_);
+ [label_ drawAtPoint:CGPointMake(58, 29) forWidth:(width - 95) withFont:Font12_ lineBreakMode:UILineBreakModeTailTruncation];
+}
+
+@end
+/* }}} */
+/* Source Controller {{{ */
+@interface SourceController : FilteredPackageController {
+}
+
+- (id) initWithDatabase:(Database *)database source:(Source *)source;
+
+@end
+
+@implementation SourceController
+
+- (id) initWithDatabase:(Database *)database 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
+> {
+ _transient Database *database_;
+ UITableView *list_;
+ NSMutableArray *sources_;
+ int offset_;
+
+ NSString *href_;
+ UIProgressHUD *hud_;
+ NSError *error_;
+
+ //NSURLConnection *installer_;
+ NSURLConnection *trivial_;
+ NSURLConnection *trivial_bz2_;
+ NSURLConnection *trivial_gz_;
+ //NSURLConnection *automatic_;
+
+ BOOL cydia_;
+}
+
+- (id) initWithDatabase:(Database *)database;
+
+- (void) updateButtonsForEditingStatus:(BOOL)editing animated:(BOOL)animated;
+
+@end
+
+@implementation SourcesController
+
+- (void) _releaseConnection:(NSURLConnection *)connection {
+ if (connection != nil) {
+ [connection cancel];
+ //[connection setDelegate:nil];
+ [connection release];
+ }
+}
+
+- (void) dealloc {
+ if (href_ != nil)
+ [href_ release];
+ if (hud_ != nil)
+ [hud_ release];
+ if (error_ != nil)
+ [error_ release];
+
+ //[self _releaseConnection:installer_];
+ [self _releaseConnection:trivial_];
+ [self _releaseConnection:trivial_gz_];
+ [self _releaseConnection:trivial_bz2_];
+ //[self _releaseConnection:automatic_];
+
+ [sources_ release];
+ [list_ release];
+ [super dealloc];
+}
+
+- (void) viewDidAppear:(BOOL)animated {
+ [super viewDidAppear:animated];
+ [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated];
+}
+
+- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
+ return offset_ == 0 ? 1 : 2;
+}
+
+- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
+ switch (section + (offset_ == 0 ? 1 : 0)) {
+ case 0: return UCLocalize("ENTERED_BY_USER");
+ case 1: return UCLocalize("INSTALLED_BY_PACKAGE");
+
+ _nodefault
+ }
+}
+
+- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ int count = [sources_ count];
+ switch (section) {
+ case 0: return (offset_ == 0 ? count : offset_);
+ case 1: return count - offset_;
+
+ _nodefault
+ }
+}
+
+- (Source *) sourceAtIndexPath:(NSIndexPath *)indexPath {
+ unsigned idx = 0;
+ switch (indexPath.section) {
+ case 0: idx = indexPath.row; break;
+ case 1: idx = indexPath.row + offset_; break;
+
+ _nodefault
+ }
+ return [sources_ objectAtIndex:idx];
+}
+
+- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+ static NSString *cellIdentifier = @"SourceCell";
+
+ 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;
+}
+
+- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+ Source *source = [self sourceAtIndexPath:indexPath];
+
+ SourceController *controller = [[[SourceController alloc]
+ initWithDatabase:database_
+ source:source
+ ] autorelease];
+
+ [controller setDelegate:delegate_];
+
+ [[self navigationController] pushViewController:controller animated:YES];
+}
+
+- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
+ Source *source = [self sourceAtIndexPath:indexPath];
+ return [source record] != nil;
+}
+
+- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
+ Source *source = [self sourceAtIndexPath:indexPath];
+ [Sources_ removeObjectForKey:[source key]];
+ [delegate_ syncData];
+}
+
+- (void) complete {
+ [Sources_ setObject:[NSDictionary dictionaryWithObjectsAndKeys:
+ @"deb", @"Type",
+ href_, @"URI",
+ @"./", @"Distribution",
+ nil] forKey:[NSString stringWithFormat:@"deb:%@:./", href_]];
+
+ [delegate_ syncData];
+}
+
+- (NSString *) getWarning {
+ NSString *href(href_);
+ NSRange colon([href rangeOfString:@"://"]);
+ if (colon.location != NSNotFound)
+ href = [href substringFromIndex:(colon.location + 3)];
+ href = [href stringByAddingPercentEscapes];
+ href = [CydiaURL(@"api/repotag/") stringByAppendingString:href];
+ href = [href stringByCachingURLWithCurrentCDN];
+
+ NSURL *url([NSURL URLWithString:href]);
+
+ NSStringEncoding encoding;
+ NSError *error(nil);
+
+ if (NSString *warning = [NSString stringWithContentsOfURL:url usedEncoding:&encoding error:&error])
+ return [warning length] == 0 ? nil : warning;
+ return nil;
+}
+
+- (void) _endConnection:(NSURLConnection *)connection {
+ // XXX: the memory management in this method is horribly awkward
+
+ NSURLConnection **field = NULL;
+ if (connection == trivial_)
+ field = &trivial_;
+ else if (connection == trivial_bz2_)
+ field = &trivial_bz2_;
+ else if (connection == trivial_gz_)
+ field = &trivial_gz_;
+ _assert(field != NULL);
+ [connection release];
+ *field = nil;
+
+ if (
+ trivial_ == nil &&
+ trivial_bz2_ == nil &&
+ trivial_gz_ == nil
+ ) {
+ bool defer(false);
+
+ if (cydia_) {
+ if (NSString *warning = [self yieldToSelector:@selector(getWarning)]) {
+ defer = true;
+
+ UIAlertView *alert = [[[UIAlertView alloc]
+ initWithTitle:UCLocalize("SOURCE_WARNING")
+ message:warning
+ delegate:self
+ cancelButtonTitle:UCLocalize("CANCEL")
+ otherButtonTitles:UCLocalize("ADD_ANYWAY"), nil
+ ] autorelease];
+
+ [alert setContext:@"warning"];
+ [alert setNumberOfRows:1];
+ [alert show];
+ } else
+ [self complete];
+ } else if (error_ != nil) {
+ UIAlertView *alert = [[[UIAlertView alloc]
+ initWithTitle:UCLocalize("VERIFICATION_ERROR")
+ message:[error_ localizedDescription]
+ delegate:self
+ cancelButtonTitle:UCLocalize("OK")
+ otherButtonTitles:nil
+ ] autorelease];
+
+ [alert setContext:@"urlerror"];
+ [alert show];
+ } else {
+ UIAlertView *alert = [[[UIAlertView alloc]
+ initWithTitle:UCLocalize("NOT_REPOSITORY")
+ message:UCLocalize("NOT_REPOSITORY_EX")
+ delegate:self
+ cancelButtonTitle:UCLocalize("OK")
+ otherButtonTitles:nil
+ ] autorelease];
+
+ [alert setContext:@"trivial"];
+ [alert show];
+ }
+
+ [delegate_ setStatusBarShowsProgress:NO];
+ [delegate_ removeProgressHUD:hud_];
+
+ [hud_ autorelease];
+ hud_ = nil;
+
+ if (!defer) {
+ [href_ release];
+ href_ = nil;
+ }
+
+ if (error_ != nil) {
+ [error_ release];
+ error_ = nil;
+ }
+ }
+}
+
+- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response {
+ switch ([response statusCode]) {
+ case 200:
+ cydia_ = YES;
+ }
+}
+
+- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
+ lprintf("connection:\"%s\" didFailWithError:\"%s\"", [href_ UTF8String], [[error localizedDescription] UTF8String]);
+ if (error_ != nil)
+ error_ = [error retain];
+ [self _endConnection:connection];
+}
+
+- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
+ [self _endConnection:connection];
+}
+
+- (NSString *) title { return UCLocalize("SOURCES"); }
+
+- (NSURLConnection *) _requestHRef:(NSString *)href method:(NSString *)method {
+ NSMutableURLRequest *request = [NSMutableURLRequest
+ requestWithURL:[NSURL URLWithString:href]
+ cachePolicy:NSURLRequestUseProtocolCachePolicy
+ timeoutInterval:120.0
+ ];
+
+ [request setHTTPMethod:method];
+
+ if (Machine_ != NULL)
+ [request setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"];
+ if (UniqueID_ != nil)
+ [request setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"];
+ if (Role_ != nil)
+ [request setValue:Role_ forHTTPHeaderField:@"X-Role"];
+
+ return [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
+}
+
+- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
+ NSString *context([alert context]);
+
+ if ([context isEqualToString:@"source"]) {
+ switch (button) {
+ case 1: {
+ NSString *href = [[alert textField] text];
+
+ //installer_ = [[self _requestHRef:href method:@"GET"] retain];
+
+ if (![href hasSuffix:@"/"])
+ href_ = [href stringByAppendingString:@"/"];
+ else
+ href_ = href;
+ href_ = [href_ retain];
+
+ trivial_ = [[self _requestHRef:[href_ stringByAppendingString:@"Packages"] method:@"HEAD"] retain];
+ trivial_bz2_ = [[self _requestHRef:[href_ stringByAppendingString:@"Packages.bz2"] method:@"HEAD"] retain];
+ trivial_gz_ = [[self _requestHRef:[href_ stringByAppendingString:@"Packages.gz"] method:@"HEAD"] retain];
+ //trivial_bz2_ = [[self _requestHRef:[href stringByAppendingString:@"dists/Release"] method:@"HEAD"] retain];
+
+ cydia_ = false;
+
+ // XXX: this is stupid
+ hud_ = [[delegate_ addProgressHUD] retain];
+ [hud_ setText:UCLocalize("VERIFYING_URL")];
+ } break;
+
+ case 0:
+ break;
+
+ _nodefault
+ }
+
+ [alert dismissWithClickedButtonIndex:-1 animated:YES];
+ } else if ([context isEqualToString:@"trivial"])
+ [alert dismissWithClickedButtonIndex:-1 animated:YES];
+ else if ([context isEqualToString:@"urlerror"])
+ [alert dismissWithClickedButtonIndex:-1 animated:YES];
+ else if ([context isEqualToString:@"warning"]) {
+ switch (button) {
+ case 1:
+ [self complete];
+ break;
+
+ case 0:
+ break;
+
+ _nodefault
+ }
+
+ [href_ release];
+ href_ = nil;
+
+ [alert dismissWithClickedButtonIndex:-1 animated:YES];
+ }
+}
+
+- (id) initWithDatabase:(Database *)database {
+ if ((self = [super init]) != nil) {
+ [[self navigationItem] setTitle:UCLocalize("SOURCES")];
+ [self updateButtonsForEditingStatus:NO animated:NO];
+
+ database_ = database;
+ sources_ = [[NSMutableArray arrayWithCapacity:16] retain];
+
+ list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain];
+ [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
+ [list_ setRowHeight:56];
+ [[self view] addSubview:list_];
+
+ [list_ setDataSource:self];
+ [list_ setDelegate:self];
+
+ [self reloadData];
+ } return self;
+}
+
+- (void) reloadData {
+ pkgSourceList list;
+ if (!list.ReadMainList())
+ return;
+
+ [sources_ removeAllObjects];
+ [sources_ addObjectsFromArray:[database_ sources]];
+ _trace();
+ [sources_ sortUsingSelector:@selector(compareByNameAndType:)];
+ _trace();
+
+ int count([sources_ count]);
+ offset_ = 0;
+ for (int i = 0; i != count; i++) {
+ if ([[sources_ objectAtIndex:i] record] == nil)
+ break;
+ offset_++;
+ }
+
+ [list_ setEditing:NO];
+ [self updateButtonsForEditingStatus:NO animated:NO];
+ [list_ reloadData];
+}
+
+- (void) showAddSourcePrompt {
+ UIAlertView *alert = [[[UIAlertView alloc]
+ initWithTitle:UCLocalize("ENTER_APT_URL")
+ message:nil
+ delegate:self
+ cancelButtonTitle:UCLocalize("CANCEL")
+ otherButtonTitles:UCLocalize("ADD_SOURCE"), nil
+ ] autorelease];
+
+ [alert setContext:@"source"];
+ [alert setTransform:CGAffineTransformTranslate([alert transform], 0.0, 100.0)];
+
+ [alert setNumberOfRows:1];
+ [alert addTextFieldWithValue:@"http://" label:@""];
+
+ UITextInputTraits *traits = [[alert textField] textInputTraits];
+ [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
+ [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
+ [traits setKeyboardType:UIKeyboardTypeURL];
+ // XXX: UIReturnKeyDone
+ [traits setReturnKeyType:UIReturnKeyNext];
+
+ [alert show];
+}
+
+- (void) addButtonClicked {
+ [self showAddSourcePrompt];
+}
+
+- (void) updateButtonsForEditingStatus:(BOOL)editing animated:(BOOL)animated {
+ [[self navigationItem] setLeftBarButtonItem:(editing ? [[[UIBarButtonItem alloc]
+ initWithTitle:UCLocalize("ADD")
+ style:UIBarButtonItemStylePlain
+ target:self
+ action:@selector(addButtonClicked)
+ ] autorelease] : [[self navigationItem] backBarButtonItem]) animated:animated];
+
+ [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc]
+ initWithTitle:(editing ? UCLocalize("DONE") : UCLocalize("EDIT"))
+ style:(editing ? UIBarButtonItemStyleDone : UIBarButtonItemStylePlain)
+ target:self
+ action:@selector(editButtonClicked)
+ ] autorelease] animated:animated];
+
+ if (IsWildcat_ && !editing)
+ [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
+ initWithTitle:UCLocalize("SETTINGS")
+ style:UIBarButtonItemStylePlain
+ target:self
+ action:@selector(settingsButtonClicked)
+ ] autorelease]];
+}
+
+- (void) settingsButtonClicked {
+ [delegate_ showSettings];
+}
+
+- (void) editButtonClicked {
+ [list_ setEditing:![list_ isEditing] animated:YES];
+
+ [self updateButtonsForEditingStatus:[list_ isEditing] animated:YES];
+}
+
+@end
+/* }}} */
+
+/* Settings Controller {{{ */
+@interface SettingsController : CYViewController <
UITableViewDataSource,
UITableViewDelegate
> {
@@ -7909,7 +7971,7 @@ freeing the view controllers on tab change */
@end
-@implementation CYSettingsController
+@implementation SettingsController
- (void) dealloc {
[table_ release];
[segment_ release];
@@ -8069,7 +8131,7 @@ freeing the view controllers on tab change */
@end
/* }}} */
/* Stash Controller {{{ */
-@interface CYStashController : CYViewController {
+@interface StashController : CYViewController {
// XXX: just delete these things
_transient UIActivityIndicatorView *spinner_;
_transient UILabel *status_;
@@ -8077,7 +8139,7 @@ freeing the view controllers on tab change */
}
@end
-@implementation CYStashController
+@implementation StashController
- (id) init {
if ((self = [super init])) {
[[self view] setBackgroundColor:[UIColor viewFlipsideBackgroundColor]];
@@ -8123,22 +8185,9 @@ freeing the view controllers on tab change */
} return self;
}
-- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
- return IsWildcat_ || orientation == UIInterfaceOrientationPortrait;
-}
@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 +8206,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 {
@@ -8250,42 +8281,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]];
-
- 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_];
+ [tabbar_ reloadData];
- for (CYNavigationController *tab in tabs)
- [tab reloadData];
+ CYNavigationController *navigation = [self queueNavigationController];
- [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 {
@@ -8371,7 +8385,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 +8556,43 @@ 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;
+ CYNavigationController *controller = (CYNavigationController *) viewController;
+
+ if ([[controller viewControllers] count] == 0) {
+ int index = [[tabbar_ viewControllers] indexOfObjectIdenticalTo:controller];
+ CYViewController *root = nil;
+
+ if (index == 0)
+ root = [[[HomeController alloc] init] autorelease];
+ else if (index == 1)
+ root = [[[SectionsController alloc] initWithDatabase:database_] autorelease];
+ else if (index == 2)
+ root = [[[ChangesController alloc] initWithDatabase:database_] autorelease];
+
+ if (IsWildcat_) {
+ if (index == 3)
+ root = [[[InstalledController alloc] initWithDatabase:database_] autorelease];
+ else if (index == 4)
+ root = [[[SourcesController alloc] initWithDatabase:database_] autorelease];
+ else if (index == 5)
+ root = [[[SearchController alloc] initWithDatabase:database_] autorelease];
+ } else {
+ if (index == 3)
+ root = [[[ManageController alloc] init] autorelease];
+ else if (index == 4)
+ root = [[[SearchController alloc] initWithDatabase:database_] autorelease];
+ }
- 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;
+ [root setDelegate:self];
- _nodefault
+ if (root != nil)
+ [controller setViewControllers:[NSArray arrayWithObject:root]];
}
-
- 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 +8609,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) {
@@ -8790,76 +8730,133 @@ static _finline void _setHomePage(Cydia *self) {
- (CYViewController *) pageForPackage:(NSString *)name {
if (Package *package = [database_ packageWithName:name]) {
- PackageController *view([self packageController]);
+ CYPackageController *view = [[[CYPackageController alloc] initWithDatabase:database_] autorelease];
[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]];
+ CYBrowserController *browser = [[[CYBrowserController alloc] init] autorelease];
+ [browser loadURL:url];
+ return browser;
}
}
-- (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] init] autorelease];
+ [(CYBrowserController *)controller loadURL:[NSURL URLWithString:destination]];
+ } else if ([components count] == 1) {
+ 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:@"signature"]) {
+ controller = [[[SignatureController 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_ setTransientViewController:nav];
}
- return !!page;
+ return page != nil;
}
- (void) applicationOpenURL:(NSURL *)url {
@@ -8880,7 +8877,7 @@ static _finline void _setHomePage(Cydia *self) {
- (void) addStashController {
++locked_;
- stash_ = [[CYStashController alloc] init];
+ stash_ = [[StashController alloc] init];
[window_ addSubview:[stash_ view]];
}
@@ -8910,47 +8907,44 @@ 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 = [[CYEmulatedLoadingController alloc] init];
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];
+ [view addSubview:[fake view]];
} else {
- [fake removeFromSuperview];
+ [[fake view] removeFromSuperview];
}
+
+ return fake;
}
- (void) applicationDidFinishLaunching:(id)unused {
@@ -8976,8 +8970,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 +9000,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 +9011,38 @@ _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);
- }
-
- [self showFakeTabBarInView:nil];
-
- [starturl_ release];
- starturl_ = nil;
-
+ [window_ addSubview:[tabbar_ view]];
+ [self showEmulatedLoadingControllerInView:nil];
[window_ setUserInteractionEnabled:YES];
- // XXX: does this actually slow anything down?
- [[tabbar_ view] setBackgroundColor:[UIColor clearColor]];
- [loading removeFromSuperview];
+ // Show the home page.
+ CYNavigationController *navigation = [[tabbar_ viewControllers] objectAtIndex:0];
+ [navigation setViewControllers:[NSArray arrayWithObject:[self pageForURL:[NSURL URLWithString:@"cydia://home"]]]];
+
+ // (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 +9098,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();
@@ -9136,6 +9152,13 @@ int main(int argc, char *argv[]) { _pooled
_UIHardware$_playSystemSound$ = reinterpret_cast<void (*)(Class, SEL, int)>(method_getImplementation(UIHardware$_playSystemSound$));
method_setImplementation(UIHardware$_playSystemSound$, reinterpret_cast<IMP>(&$UIHardware$_playSystemSound$));
}
+
+ $UIApplication = objc_getClass("UIApplication");
+ Method UIApplication$_updateApplicationAccessibility(class_getInstanceMethod($UIApplication, @selector(_updateApplicationAccessibility)));
+ if (UIApplication$_updateApplicationAccessibility != NULL) {
+ _UIApplication$_updateApplicationAccessibility = reinterpret_cast<void (*)(UIApplication *, SEL)>(method_getImplementation(UIApplication$_updateApplicationAccessibility));
+ method_setImplementation(UIApplication$_updateApplicationAccessibility, reinterpret_cast<IMP>(&$UIApplication$_updateApplicationAccessibility));
+ }
/* }}} */
/* Set Locale {{{ */
Locale_ = CFLocaleCopyCurrent();