From f6e1356137e494e0746becbfda851c8858de1c98 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Thu, 30 Dec 2010 01:52:12 -0800 Subject: Switch to native UITabBarController handling, and rewrite URL subsystem. Also make a number of changes, creating and renaming classes for the different pages dispalyed in Cydia. Incomplete; -urlForPage methods are not implemented or used and CYSearchController does not yet exist. --- MobileCydia.app/package.js | 4 +- MobileCydia.mm | 546 +++++++++++++++++++++++---------------------- UICaboodle/BrowserView.h | 2 +- UICaboodle/BrowserView.mm | 6 +- 4 files changed, 285 insertions(+), 273 deletions(-) diff --git a/MobileCydia.app/package.js b/MobileCydia.app/package.js index 07f9588..2eaeb4a 100644 --- a/MobileCydia.app/package.js +++ b/MobileCydia.app/package.js @@ -117,7 +117,7 @@ $(function () { } }); - $("#settings").href("cydia://package-settings/" + idc); + $("#settings").href("cydia://package/" + idc + "/settings"); var mode = package.mode; if (mode == null) @@ -275,7 +275,7 @@ $(function () { $("#source-name").html($.xml(source.name)); if (source.trusted) - $("#trusted").href("cydia://package-signature/" + idc); + $("#trusted").href("cydia://package/" + idc + "/signature"); else $(".trusted").addClass("deleted"); diff --git a/MobileCydia.mm b/MobileCydia.mm index 18fbe49..57643ee 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -1179,12 +1179,12 @@ bool isSectionVisible(NSString *section) { - (void) setConfigurationData:(NSString *)data; @end -@class PackageController; +@class CYPackageController; @protocol CydiaDelegate - (void) retainNetworkActivityIndicator; - (void) releaseNetworkActivityIndicator; -- (void) setPackageController:(PackageController *)view; +- (void) setPackageController:(CYPackageController *)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 @@ -3997,6 +3996,43 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ +@interface CYEmulatedLoadingController : UIViewController { + 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; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { + return (IsWildcat_ || orientation == UIInterfaceOrientationPortrait); +} + +@end /* Cydia Browser Controller {{{ */ @interface CYBrowserController : BrowserController { @@ -5290,7 +5326,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Package Controller {{{ */ -@interface PackageController : CYBrowserController < +@interface CYPackageController : CYBrowserController < UIActionSheetDelegate > { _transient Database *database_; @@ -5306,7 +5342,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end -@implementation PackageController +@implementation CYPackageController - (void) dealloc { if (package_ != nil) @@ -5825,7 +5861,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]; @@ -5956,7 +5992,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Source Table {{{ */ -@interface SourceController : CYViewController < +@interface CYSourcesController : CYViewController < UITableViewDataSource, UITableViewDelegate > { @@ -5984,7 +6020,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end -@implementation SourceController +@implementation CYSourcesController - (void) _releaseConnection:(NSURLConnection *)connection { if (connection != nil) { @@ -6346,8 +6382,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [list_ reloadData]; } -- (void) addButtonClicked { - /*[book_ pushPage:[[[AddSourceController alloc] +- (void) showAddSourcePrompt { + /*[book_ pushPage:[[[AddCYSourcesController alloc] initWithBook:book_ database:database_ ] autorelease]];*/ @@ -6376,6 +6412,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [alert show]; } +- (void) addButtonClicked { + [self showAddSourcePrompt]; +} + - (void) updateButtonsForEditingStatus:(BOOL)editing animated:(BOOL)animated { [[self navigationItem] setLeftBarButtonItem:(editing ? [[[UIBarButtonItem alloc] initWithTitle:UCLocalize("ADD") @@ -6414,7 +6454,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* Installed Controller {{{ */ -@interface InstalledController : FilteredPackageController { +@interface CYInstalledController : FilteredPackageController { BOOL expert_; } @@ -6425,7 +6465,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end -@implementation InstalledController +@implementation CYInstalledController - (void) dealloc { [super dealloc]; @@ -6490,16 +6530,56 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [packages_ setDelegate:delegate]; } +@end +/* }}} */ +/* Section Controller {{{ */ +@interface CYSectionController : FilteredPackageController { +} + +- (id) initWithDatabase:(Database *)database section:(NSString *)section; + +@end + +@implementation CYSectionController + +- (void) dealloc { + [super dealloc]; +} + +- (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; +} + +- (void) reloadData { + [packages_ reloadData]; +} + +- (void) setDelegate:(id)delegate { + [super setDelegate:delegate]; + [packages_ setDelegate:delegate]; +} + @end /* }}} */ /* Home Controller {{{ */ -@interface HomeController : CYBrowserController { +@interface CYHomeController : CYBrowserController { } @end -@implementation HomeController +@implementation CYHomeController + (BOOL)shouldHideNavigationBar { return NO; @@ -6549,6 +6629,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (id) init { if ((self = [super init]) != nil) { + [self loadURL:[NSURL URLWithString:CydiaURL(@"")]]; + [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:UCLocalize("ABOUT") style:UIBarButtonItemStylePlain @@ -6561,18 +6643,20 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Manage Controller {{{ */ -@interface ManageController : CYBrowserController { +@interface CYManageController : CYBrowserController { } - (void) queueStatusDidChange; @end -@implementation ManageController +@implementation CYManageController - (id) init { if ((self = [super init]) != nil) { [[self navigationItem] setTitle:UCLocalize("MANAGE")]; + [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"manage" ofType:@"html"]]]; + [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:UCLocalize("SETTINGS") style:UIBarButtonItemStylePlain @@ -6766,9 +6850,6 @@ 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) { @@ -7249,37 +7330,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] + CYSectionController *controller = [[[CYSectionController 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; @@ -7378,7 +7438,7 @@ freeing the view controllers on tab change */ @end /* }}} */ /* Changes Controller {{{ */ -@interface ChangesController : CYViewController < +@interface CYChangesController : CYViewController < UITableViewDataSource, UITableViewDelegate > { @@ -7396,7 +7456,7 @@ freeing the view controllers on tab change */ @end -@implementation ChangesController +@implementation CYChangesController - (void) dealloc { [list_ setDelegate:nil]; @@ -7464,7 +7524,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]; @@ -7558,7 +7618,7 @@ freeing the view controllers on tab change */ name = (NSString *) CFDateFormatterCreateStringWithDate(NULL, formatter, (CFDateRef) [NSDate dateWithTimeIntervalSince1970:seen]); [name autorelease]; - _profile(ChangesController$reloadData$Allocate) + _profile(CYChangesController$reloadData$Allocate) name = [NSString stringWithFormat:UCLocalize("NEW_AT"), name]; section = [[[Section alloc] initWithName:name row:offset localize:NO] autorelease]; [sections_ addObject:section]; @@ -7614,24 +7674,29 @@ freeing the view controllers on tab change */ @end /* }}} */ /* Search Controller {{{ */ -@interface SearchController : FilteredPackageController < +@interface CYSearchController : FilteredPackageController < UISearchBarDelegate > { UISearchBar *search_; } +- (void) setSearchTerm:(NSString *)searchTerm; - (id) initWithDatabase:(Database *)database; - (void) reloadData; @end -@implementation SearchController +@implementation CYSearchController - (void) dealloc { [search_ release]; [super dealloc]; } +- (void) setSearchTerm:(NSString *)searchTerm { + [search_ setText:searchTerm]; +} + - (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar { [packages_ setObject:[search_ text] forFilter:@selector(isUnfilteredAndSearchedForBy:)]; [search_ resignFirstResponder]; @@ -7673,7 +7738,7 @@ freeing the view controllers on tab change */ } - (void) reloadData { - _profile(SearchController$reloadData) + _profile(CYSearchController$reloadData) [packages_ reloadData]; _end PrintTimes(); @@ -7735,6 +7800,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"); } @@ -7785,6 +7854,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")]; @@ -8093,13 +8164,13 @@ freeing the view controllers on tab change */ /* }}} */ typedef enum { - kCydiaTag = 0, - kSectionsTag = 1, - kChangesTag = 2, - kManageTag = 3, - kInstalledTag = 4, - kSourcesTag = 5, - kSearchTag = 6 + kCydiaTag, + kSectionsTag, + kChangesTag, + kManageTag, + kInstalledTag, + kSourcesTag, + kSearchTag } CYTabTag; @interface Cydia : UIApplication < @@ -8120,17 +8191,10 @@ 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_; @@ -8138,7 +8202,6 @@ typedef enum { bool loaded_; } -- (CYViewController *) _pageForURL:(NSURL *)url withClass:(Class)_class; - (void) setPage:(CYViewController *)page; - (void) loadData; @@ -8147,10 +8210,6 @@ typedef enum { @end -static _finline void _setHomePage(Cydia *self) { - [self setPage:[self _pageForURL:[NSURL URLWithString:CydiaURL(@"")] withClass:[HomeController class]]]; -} - @implementation Cydia - (void) beginUpdate { @@ -8216,25 +8275,7 @@ static _finline void _setHomePage(Cydia *self) { - (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_]; - - for (CYNavigationController *tab in tabs) - [tab reloadData]; + [tabbar_ reloadData]; [queueDelegate_ queueStatusDidChange]; [[[self queueBadgeController] tabBarItem] setBadgeValue:(Queuing_ ? UCLocalize("Q_D") : nil)]; @@ -8510,85 +8551,7 @@ static _finline void _setHomePage(Cydia *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; + NSLog(@"page: %@ nav: %@", page, navController); } - (void) showSettings { @@ -8609,20 +8572,12 @@ static _finline void _setHomePage(Cydia *self) { [self setNetworkActivityIndicatorVisible:NO]; } -- (void) setPackageController:(PackageController *)view { +- (void) setPackageController:(CYPackageController *)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]; @@ -8753,59 +8708,126 @@ 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] && [[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]); + + if ([components count] == 1) { + if ([base isEqualToString:@"storage"]) { + CYBrowserController *browser = [[[CYBrowserController alloc] init] autorelease]; + [browser loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"storage" ofType:@"html"]]]; + return browser; + } + + if ([base isEqualToString:@"sources"]) { + CYSourcesController *source = [[[CYSourcesController alloc] initWithDatabase:database_] autorelease]; + return source; + } + + if ([base isEqualToString:@"home"]) { + CYHomeController *home = [[[CYHomeController alloc] init] autorelease]; + return home; + } + + if ([base isEqualToString:@"sections"]) { + CYSectionsController *sections = [[[CYSectionsController alloc] initWithDatabase:database_] autorelease]; + return sections; + } + + if ([base isEqualToString:@"search"]) { + CYSearchController *search = [[[CYSearchController alloc] initWithDatabase:database_] autorelease]; + return search; + } + + if ([base isEqualToString:@"changes"]) { + CYChangesController *changes = [[[CYChangesController alloc] initWithDatabase:database_ delegate:self] autorelease]; + return changes; + } + + if ([base isEqualToString:@"installed"]) { + CYInstalledController *installed = [[[CYInstalledController alloc] initWithDatabase:database_] autorelease]; + return installed; + } + } else if ([components count] == 2) { + NSString *argument = [components objectAtIndex:1]; + + if ([base isEqualToString:@"package"]) { + CYViewController *package = [self pageForPackage:argument]; + return package; + } + + if ([base isEqualToString:@"search"]) { + CYSearchController *search = [[[CYSearchController alloc] initWithDatabase:database_] autorelease]; + [search setSearchTerm:argument]; + return search; + } + + if ([base isEqualToString:@"sections"]) { + if ([argument isEqualToString:@"all"]) + argument = nil; + CYSectionController *section = [[[CYSectionController alloc] initWithDatabase:database_ section:argument] autorelease]; + [section setDelegate:self]; + return section; + } + + if ([base isEqualToString:@"sources"]) { + if ([argument isEqualToString:@"add"]) { + CYSourcesController *source = [[[CYSourcesController alloc] initWithDatabase:database_] autorelease]; + [source showAddSourcePrompt]; + return source; + } else { + // XXX: Create page of the source specfified. + } + } + + if ([base isEqualToString:@"url"]) { + CYBrowserController *browser = [[[CYBrowserController alloc] init] autorelease]; + [browser loadURL:[NSURL URLWithString:argument]]; + return browser; + } + + if ([base isEqualToString:@"launch"]) { + [self launchApplicationWithIdentifier:argument suspended:NO]; + } + } else if ([components count] == 3) { + NSString *arg1 = [components objectAtIndex:1]; + NSString *arg2 = [components objectAtIndex:2]; + + if ([base isEqualToString:@"package"]) { + if ([arg2 isEqualToString:@"settings"]) { + return [[[CYPackageSettingsController alloc] initWithDatabase:database_ package:arg1] autorelease]; + } else if ([arg2 isEqualToString:@"signature"]) { + return [[[SignatureController alloc] initWithDatabase:database_ package:arg1] autorelease]; + } else if ([arg2 isEqualToString:@"files"]) { + if (Package *package = [database_ packageWithName:arg1]) { + FileTable *files = [[[FileTable alloc] initWithDatabase:database_] autorelease]; + [files setPackage:package]; + return files; + } + } } } @@ -8813,16 +8835,12 @@ static _finline void _setHomePage(Cydia *self) { } - (BOOL) openCydiaURL:(NSURL *)url { - CYViewController *page = nil; - int tag = 0; + CYViewController *page([self pageForURL:url]); - if ((page = [self pageForURL:url hasTag:&tag])) { + if (page != nil) [self setPage:page]; - tag_ = tag; - [tabbar_ setSelectedViewController:(tag_ == -1 ? nil : [[tabbar_ viewControllers] objectAtIndex:tag_])]; - } - return !!page; + return page != nil; } - (void) applicationOpenURL:(NSURL *)url { @@ -8873,7 +8891,7 @@ static _finline void _setHomePage(Cydia *self) { } } -- (void) setupTabBarController { +- (void) setupViewControllers { tabbar_ = [[CYTabBarController alloc] initWithDatabase:database_]; [tabbar_ setDelegate:self]; @@ -8884,35 +8902,49 @@ static _finline void _setHomePage(Cydia *self) { [[[UITabBarItem alloc] initWithTitle:UCLocalize("SEARCH") image:[UIImage applicationImageNamed:@"search.png"] tag:kSearchTag] autorelease], nil]); + NSMutableArray *pages([NSMutableArray arrayWithObjects: + [[[CYHomeController alloc] init] autorelease], + [[[CYSectionsController alloc] initWithDatabase:database_] autorelease], + [[[CYChangesController alloc] initWithDatabase:database_ delegate:self] autorelease], + [[[CYSearchController alloc] initWithDatabase:database_] 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]; + [pages insertObject:[[[CYSourcesController alloc] initWithDatabase:database_] autorelease] atIndex:3]; + [pages insertObject:[[[CYInstalledController alloc] initWithDatabase:database_] autorelease] atIndex:3]; + queueDelegate_ = [pages objectAtIndex:3]; } else { [items insertObject:[[[UITabBarItem alloc] initWithTitle:UCLocalize("MANAGE") image:[UIImage applicationImageNamed:@"manage.png"] tag:kManageTag] autorelease] atIndex:3]; + [pages insertObject:[[[CYManageController alloc] init] autorelease] atIndex:3]; + queueDelegate_ = [pages objectAtIndex:3]; } NSMutableArray *controllers([NSMutableArray array]); - for (UITabBarItem *item in items) { + for (unsigned int i = 0; i < [pages count]; i++) { + UITabBarItem *item = [items objectAtIndex:i]; + CYViewController *page = [pages objectAtIndex:i]; + [page setDelegate:self]; + CYNavigationController *controller([[[CYNavigationController alloc] initWithDatabase:database_] autorelease]); + [controller setViewControllers:[NSArray arrayWithObject:page]]; [controller setTabBarItem:item]; [controllers addObject:controller]; } [tabbar_ setViewControllers:controllers]; + [tabbar_ setUpdateDelegate:self]; + [window_ addSubview:[tabbar_ view]]; } -- (void)showFakeTabBarInView:(UIView *)view { - static UITabBar *fake = [[UITabBar alloc] initWithFrame:CGRectMake(0, 0, 0, 49.0f)]; +- (void)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]; } } @@ -8936,8 +8968,6 @@ _trace(); Font18Bold_ = [[UIFont boldSystemFontOfSize:18] retain]; Font22Bold_ = [[UIFont boldSystemFontOfSize:22] retain]; - tag_ = 0; - essential_ = [[NSMutableArray alloc] initWithCapacity:4]; broken_ = [[NSMutableArray alloc] initWithCapacity:4]; @@ -8968,13 +8998,7 @@ _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]]; + [self showEmulatedLoadingControllerInView:window_]; [self performSelector:@selector(loadData) withObject:nil afterDelay:0]; _trace(); @@ -8987,33 +9011,23 @@ _trace(); return; } - 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_ setUserInteractionEnabled:YES]; + [self setupViewControllers]; + [tabbar_ setSelectedIndex:0]; + [self showEmulatedLoadingControllerInView:nil]; // XXX: does this actually slow anything down? [[tabbar_ view] setBackgroundColor:[UIColor clearColor]]; - [loading removeFromSuperview]; + + // Show the initial page + if (starturl_ != nil) { + [self openCydiaURL:starturl_]; + [starturl_ release]; + starturl_ = nil; + } } - (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item { diff --git a/UICaboodle/BrowserView.h b/UICaboodle/BrowserView.h index f224326..efc1e6c 100644 --- a/UICaboodle/BrowserView.h +++ b/UICaboodle/BrowserView.h @@ -52,7 +52,7 @@ @protocol BrowserControllerDelegate - (void) retainNetworkActivityIndicator; - (void) releaseNetworkActivityIndicator; -- (CYViewController *) pageForURL:(NSURL *)url hasTag:(int *)tag; +- (CYViewController *) pageForURL:(NSURL *)url; @end @interface BrowserController : CYViewController < diff --git a/UICaboodle/BrowserView.mm b/UICaboodle/BrowserView.mm index 168cff1..921e6aa 100644 --- a/UICaboodle/BrowserView.mm +++ b/UICaboodle/BrowserView.mm @@ -638,7 +638,7 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se if ([scheme isEqualToString:@"mailto"]) [self _openMailToURL:url]; - CYViewController *page([delegate_ pageForURL:url hasTag:NULL]); + CYViewController *page([delegate_ pageForURL:url]); if (page == nil) { BrowserController *browser([[[class_ alloc] init] autorelease]); @@ -653,13 +653,11 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se [[self navigationController] pushViewController:page animated:YES]; } else { - UCNavigationController *navigation([[[UCNavigationController alloc] init] autorelease]); + UCNavigationController *navigation([[[UCNavigationController alloc] initWithRootViewController:page] autorelease]); [navigation setHook:indirect_]; [navigation setDelegate:delegate_]; - [navigation setViewControllers:[NSArray arrayWithObject:page]]; - [[page navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:UCLocalize("CLOSE") style:UIBarButtonItemStylePlain -- cgit v1.2.3 From d90a4cd63517689533389dd82aca7b2b07297eda Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Mon, 3 Jan 2011 19:44:37 -0800 Subject: Began reworking of URL handling system; renamed a few classes to remove unnecessary CY prefix. --- MobileCydia.app/package.js | 4 +- MobileCydia.mm | 253 +++++++++++++++++++++++++++++++-------------- 2 files changed, 178 insertions(+), 79 deletions(-) diff --git a/MobileCydia.app/package.js b/MobileCydia.app/package.js index 07f9588..2eaeb4a 100644 --- a/MobileCydia.app/package.js +++ b/MobileCydia.app/package.js @@ -117,7 +117,7 @@ $(function () { } }); - $("#settings").href("cydia://package-settings/" + idc); + $("#settings").href("cydia://package/" + idc + "/settings"); var mode = package.mode; if (mode == null) @@ -275,7 +275,7 @@ $(function () { $("#source-name").html($.xml(source.name)); if (source.trusted) - $("#trusted").href("cydia://package-signature/" + idc); + $("#trusted").href("cydia://package/" + idc + "/signature"); else $(".trusted").addClass("deleted"); diff --git a/MobileCydia.mm b/MobileCydia.mm index 8b596a1..1a246bc 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -6006,7 +6006,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Source Table {{{ */ -@interface SourceController : CYViewController < +@interface SourcesController : CYViewController < UITableViewDataSource, UITableViewDelegate > { @@ -6034,7 +6034,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end -@implementation SourceController +@implementation SourcesController - (void) _releaseConnection:(NSURLConnection *)connection { if (connection != nil) { @@ -6396,12 +6396,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [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 @@ -6426,6 +6421,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [alert show]; } +- (void) addButtonClicked { + /*[book_ pushPage:[[[AddSourcesController alloc] + initWithBook:book_ + database:database_ + ] autorelease]];*/ + + [self showAddSourcePrompt]; +} + - (void) updateButtonsForEditingStatus:(BOOL)editing animated:(BOOL)animated { [[self navigationItem] setLeftBarButtonItem:(editing ? [[[UIBarButtonItem alloc] initWithTitle:UCLocalize("ADD") @@ -7214,8 +7218,48 @@ freeing the view controllers on tab change */ @end /* }}} */ +/* Section Controller {{{ */ +@interface SectionController : FilteredPackageController { +} + +- (id) initWithDatabase:(Database *)database section:(NSString *)section; + +@end + +@implementation SectionController + +- (void) dealloc { + [super dealloc]; +} + +- (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; +} + +- (void) reloadData { + [packages_ reloadData]; +} + +- (void) setDelegate:(id)delegate { + [super setDelegate:delegate]; + [packages_ setDelegate:delegate]; +} + +@end +/* }}} */ /* Sections Controller {{{ */ -@interface CYSectionsController : CYViewController < +@interface SectionsController : CYViewController < UITableViewDataSource, UITableViewDelegate > { @@ -7235,7 +7279,7 @@ freeing the view controllers on tab change */ @end -@implementation CYSectionsController +@implementation SectionsController - (void) dealloc { [list_ setDataSource:nil]; @@ -7299,33 +7343,14 @@ 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"); } @@ -7427,6 +7452,7 @@ freeing the view controllers on tab change */ @end /* }}} */ + /* Changes Controller {{{ */ @interface ChangesController : CYViewController < UITableViewDataSource, @@ -7681,6 +7707,7 @@ freeing the view controllers on tab change */ } - (id) initWithDatabase:(Database *)database; +- (void) setSearchTerm:(NSString *)term; - (void) reloadData; @end @@ -7703,6 +7730,10 @@ freeing the view controllers on tab change */ [self reloadData]; } +- (void) setSearchTerm:(NSString *)term { + [search_ setText:term]; +} + - (NSString *) title { return nil; } - (id) initWithDatabase:(Database *)database { @@ -7748,7 +7779,7 @@ freeing the view controllers on tab change */ @end /* }}} */ /* Settings Controller {{{ */ -@interface CYPackageSettingsController : CYViewController < +@interface PackageSettingsController : CYViewController < UITableViewDataSource, UITableViewDelegate > { @@ -7766,7 +7797,7 @@ freeing the view controllers on tab change */ @end -@implementation CYPackageSettingsController +@implementation PackageSettingsController - (void) dealloc { [name_ release]; @@ -8185,11 +8216,11 @@ typedef enum { unsigned locked_; unsigned activity_; - CYSectionsController *sections_; + SectionsController *sections_; ChangesController *changes_; ManageController *manage_; SearchController *search_; - SourceController *sources_; + SourcesController *sources_; InstalledController *installed_; id queueDelegate_; @@ -8581,9 +8612,9 @@ static _finline void _setHomePage(Cydia *self) { return browser; } -- (CYSectionsController *) sectionsController { +- (SectionsController *) sectionsController { if (sections_ == nil) - sections_ = [[CYSectionsController alloc] initWithDatabase:database_]; + sections_ = [[SectionsController alloc] initWithDatabase:database_]; return sections_; } @@ -8611,9 +8642,9 @@ static _finline void _setHomePage(Cydia *self) { return search_; } -- (SourceController *) sourcesController { +- (SourcesController *) sourcesController { if (sources_ == nil) - sources_ = [[SourceController alloc] initWithDatabase:database_]; + sources_ = [[SourcesController alloc] initWithDatabase:database_]; return sources_; } @@ -8827,45 +8858,113 @@ static _finline void _setHomePage(Cydia *self) { if (tag != NULL) *tag = -1; - NSString *href([url absoluteString]); - if ([href hasPrefix:@"apptapp://package/"]) - return [self pageForPackage:[href substringFromIndex:18]]; - 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] && [[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]); + + if ([components count] == 1) { + if ([base isEqualToString:@"storage"]) { + CYBrowserController *browser = [[[CYBrowserController alloc] init] autorelease]; + [browser loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"storage" ofType:@"html"]]]; + return browser; + } + + if ([base isEqualToString:@"sources"]) { + SourcesController *source = [[[SourcesController alloc] initWithDatabase:database_] autorelease]; + return source; + } + + if ([base isEqualToString:@"home"]) { + HomeController *home = [[[HomeController alloc] init] autorelease]; + return home; + } + + if ([base isEqualToString:@"sections"]) { + SectionsController *sections = [[[SectionsController alloc] initWithDatabase:database_] autorelease]; + return sections; + } + + if ([base isEqualToString:@"search"]) { + SearchController *search = [[[SearchController alloc] initWithDatabase:database_] autorelease]; + return search; + } + + if ([base isEqualToString:@"changes"]) { + ChangesController *changes = [[[ChangesController alloc] initWithDatabase:database_ delegate:self] autorelease]; + return changes; + } + + if ([base isEqualToString:@"installed"]) { + InstalledController *installed = [[[InstalledController alloc] initWithDatabase:database_] autorelease]; + return installed; + } + } else if ([components count] == 2) { + NSString *argument = [components objectAtIndex:1]; + + if ([base isEqualToString:@"package"]) { + CYViewController *package = [self pageForPackage:argument]; + return package; + } + + if ([base isEqualToString:@"search"]) { + SearchController *search = [[[SearchController alloc] initWithDatabase:database_] autorelease]; + [search setSearchTerm:argument]; + return search; + } + + if ([base isEqualToString:@"sections"]) { + if ([argument isEqualToString:@"all"]) + argument = nil; + SectionController *section = [[[SectionController alloc] initWithDatabase:database_ section:argument] autorelease]; + [section setDelegate:self]; + return section; + } + + if ([base isEqualToString:@"sources"]) { + if ([argument isEqualToString:@"add"]) { + SourcesController *source = [[[SourcesController alloc] initWithDatabase:database_] autorelease]; + [source showAddSourcePrompt]; + return source; + } else { + // XXX: Create page of the source specfified. + } + } + + if ([base isEqualToString:@"url"]) { + CYBrowserController *browser = [[[CYBrowserController alloc] init] autorelease]; + [browser loadURL:[NSURL URLWithString:argument]]; + return browser; + } + + if ([base isEqualToString:@"launch"]) { + [self launchApplicationWithIdentifier:argument suspended:NO]; + } + } else if ([components count] == 3) { + NSString *arg1 = [components objectAtIndex:1]; + NSString *arg2 = [components objectAtIndex:2]; + + if ([base isEqualToString:@"package"]) { + if ([arg2 isEqualToString:@"settings"]) { + return [[[PackageSettingsController alloc] initWithDatabase:database_ package:arg1] autorelease]; + } else if ([arg2 isEqualToString:@"signature"]) { + return [[[SignatureController alloc] initWithDatabase:database_ package:arg1] autorelease]; + } else if ([arg2 isEqualToString:@"files"]) { + if (Package *package = [database_ packageWithName:arg1]) { + FileTable *files = [[[FileTable alloc] initWithDatabase:database_] autorelease]; + [files setPackage:package]; + return files; + } + } } } -- cgit v1.2.3 From be45a8cfd12aacd4d9d841044ff45177a8b4ab3e Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Mon, 3 Jan 2011 20:49:35 -0800 Subject: Add CYEmulatedLoadingController, because there is no reason not to fake the whole thing, and plenty of reasons to do so. --- MobileCydia.mm | 68 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 1a246bc..5d52a60 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -4045,6 +4045,45 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (UILabel *)label { return label_; } - (UIActivityIndicatorView *)activityIndicatorView { return spinner_; } +@end +/* }}} */ +/* Emulated Loading Controller {{{ */ +@interface CYEmulatedLoadingController : UIViewController { + 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; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { + return (IsWildcat_ || orientation == UIInterfaceOrientationPortrait); +} + @end /* }}} */ @@ -9061,17 +9100,12 @@ static _finline void _setHomePage(Cydia *self) { [tabbar_ setViewControllers:controllers]; } -- (void)showFakeTabBarInView:(UIView *)view { - static UITabBar *fake = [[UITabBar alloc] initWithFrame:CGRectMake(0, 0, 0, 49.0f)]; +- (void)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]; } } @@ -9134,9 +9168,7 @@ _trace(); [tabbar_ setUpdateDelegate:self]; [window_ addSubview:[tabbar_ view]]; - // Show pinstripes while loading data. - [[tabbar_ view] setBackgroundColor:[UIColor pinStripeColor]]; - [self showFakeTabBarInView:[tabbar_ tabBar]]; + [self showEmulatedLoadingControllerInView:window_]; [self performSelector:@selector(loadData) withObject:nil afterDelay:0]; _trace(); @@ -9149,12 +9181,6 @@ _trace(); return; } - 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]; @@ -9166,16 +9192,12 @@ _trace(); _setHomePage(self); } - [self showFakeTabBarInView:nil]; - [starturl_ release]; starturl_ = nil; [window_ setUserInteractionEnabled:YES]; - // XXX: does this actually slow anything down? - [[tabbar_ view] setBackgroundColor:[UIColor clearColor]]; - [loading removeFromSuperview]; + [self showEmulatedLoadingControllerInView:nil]; } - (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item { -- cgit v1.2.3 From acf268596fe5c872a3630c674b4b3d40fc5de47b Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Mon, 3 Jan 2011 20:54:38 -0800 Subject: Removed obsolete reference to AddSourceController. --- MobileCydia.mm | 5 ----- 1 file changed, 5 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 5d52a60..efea8a9 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -6461,11 +6461,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) addButtonClicked { - /*[book_ pushPage:[[[AddSourcesController alloc] - initWithBook:book_ - database:database_ - ] autorelease]];*/ - [self showAddSourcePrompt]; } -- cgit v1.2.3 From 89571a5b947a38866a7834e3071e51eb4fa4f1d2 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Mon, 3 Jan 2011 22:59:48 -0800 Subject: [LARGE COMMIT] Switch to lazy-loaded SDK-style tab management. Remove the tags on the tab bar items, and remove a significant chunk of code. Also, fix a few internal pages (and the BrowserView) to work with the new URL schemes. --- MobileCydia.app/manage.html | 2 +- MobileCydia.mm | 250 ++++++++++++++------------------------------ UICaboodle/BrowserView.h | 2 +- UICaboodle/BrowserView.mm | 2 +- 4 files changed, 80 insertions(+), 176 deletions(-) diff --git a/MobileCydia.app/manage.html b/MobileCydia.app/manage.html index bba3762..e240b54 100644 --- a/MobileCydia.app/manage.html +++ b/MobileCydia.app/manage.html @@ -71,7 +71,7 @@
- +
diff --git a/MobileCydia.mm b/MobileCydia.mm index efea8a9..ccb5f82 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -6637,6 +6637,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (id) init { if ((self = [super init]) != nil) { + [self loadURL:[NSURL URLWithString:CydiaURL(@"")]]; + [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:UCLocalize("ABOUT") style:UIBarButtonItemStylePlain @@ -6661,6 +6663,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if ((self = [super init]) != nil) { [[self navigationItem] setTitle:UCLocalize("MANAGE")]; + [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"manage" ofType:@"html"]]]; + [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:UCLocalize("SETTINGS") style:UIBarButtonItemStylePlain @@ -8217,16 +8221,6 @@ freeing the view controllers on tab change */ @end /* }}} */ -typedef enum { - kCydiaTag = 0, - kSectionsTag = 1, - kChangesTag = 2, - kManageTag = 3, - kInstalledTag = 4, - kSourcesTag = 5, - kSearchTag = 6 -} CYTabTag; - @interface Cydia : UIApplication < ConfirmationControllerDelegate, ProgressControllerDelegate, @@ -8245,37 +8239,20 @@ typedef enum { Database *database_; NSURL *starturl_; - int tag_; unsigned locked_; unsigned activity_; - SectionsController *sections_; - ChangesController *changes_; - ManageController *manage_; - SearchController *search_; - SourcesController *sources_; - InstalledController *installed_; - id queueDelegate_; - CYStashController *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 { @@ -8338,42 +8315,26 @@ 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_]; - - for (CYNavigationController *tab in tabs) - [tab reloadData]; + for (CYNavigationController *controller in [tabbar_ viewControllers]) + [controller reloadData]; - [queueDelegate_ queueStatusDidChange]; - [[[self queueBadgeController] tabBarItem] setBadgeValue:(Queuing_ ? UCLocalize("Q_D") : nil)]; -} + CYNavigationController *navigation = [self queueNavigationController]; + id queuedelegate = nil; -- (int)indexOfTabWithTag:(int)tag { - int i = 0; - for (UINavigationController *controller in [tabbar_ viewControllers]) { - if ([[controller tabBarItem] tag] == tag) - return i; - i += 1; - } + if ([[navigation viewControllers] count] > 0) + queuedelegate = [[navigation viewControllers] objectAtIndex:0]; - return -1; + [queuedelegate queueStatusDidChange]; + [[navigation tabBarItem] setBadgeValue:(Queuing_ ? UCLocalize("Q_D") : nil)]; } - (void) _refreshIfPossible { @@ -8459,7 +8420,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]); @@ -8640,80 +8601,39 @@ static _finline void _setHomePage(Cydia *self) { [page setViewControllers:nil]; } -- (CYViewController *) _pageForURL:(NSURL *)url withClass:(Class)_class { - CYBrowserController *browser = [[[_class alloc] init] autorelease]; - [browser loadURL:url]; - return browser; -} - -- (SectionsController *) sectionsController { - if (sections_ == nil) - sections_ = [[SectionsController 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_; -} - -- (SourcesController *) sourcesController { - if (sources_ == nil) - sources_ = [[SourcesController 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_ selectedIndex]; + 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_ delegate:self] 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 { @@ -8748,15 +8668,6 @@ static _finline void _setHomePage(Cydia *self) { 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) { @@ -8884,14 +8795,13 @@ static _finline void _setHomePage(Cydia *self) { } 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 *controller = [[[CYBrowserController alloc] init] autorelease]; + [controller loadURL:url]; + return controller; } } -- (CYViewController *) pageForURL:(NSURL *)url hasTag:(int *)tag { - if (tag != NULL) - *tag = -1; - +- (CYViewController *) pageForURL:(NSURL *)url { NSString *scheme([[url scheme] lowercaseString]); if ([[url absoluteString] length] <= [scheme length] + 3) return nil; @@ -9007,13 +8917,9 @@ static _finline void _setHomePage(Cydia *self) { - (BOOL) openCydiaURL:(NSURL *)url { CYViewController *page = nil; - int tag = 0; - if ((page = [self pageForURL:url hasTag:&tag])) { + if ((page = [self pageForURL:url])) [self setPage:page]; - tag_ = tag; - [tabbar_ setSelectedViewController:(tag_ == -1 ? nil : [[tabbar_ viewControllers] objectAtIndex:tag_])]; - } return !!page; } @@ -9066,22 +8972,22 @@ 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]); @@ -9093,6 +8999,9 @@ static _finline void _setHomePage(Cydia *self) { } [tabbar_ setViewControllers:controllers]; + [tabbar_ setUpdateDelegate:self]; + [window_ addSubview:[tabbar_ view]]; + } - (void)showEmulatedLoadingControllerInView:(UIView *)view { @@ -9127,8 +9036,6 @@ _trace(); Font18Bold_ = [[UIFont boldSystemFontOfSize:18] retain]; Font22Bold_ = [[UIFont boldSystemFontOfSize:22] retain]; - tag_ = 0; - essential_ = [[NSMutableArray alloc] initWithCapacity:4]; broken_ = [[NSMutableArray alloc] initWithCapacity:4]; @@ -9159,10 +9066,7 @@ _trace(); database_ = [Database sharedInstance]; - [self setupTabBarController]; - [tabbar_ setUpdateDelegate:self]; - [window_ addSubview:[tabbar_ view]]; - + [window_ setUserInteractionEnabled:NO]; [self showEmulatedLoadingControllerInView:window_]; [self performSelector:@selector(loadData) withObject:nil afterDelay:0]; @@ -9176,23 +9080,23 @@ _trace(); return; } - [window_ setUserInteractionEnabled:NO]; - [self reloadData]; PrintTimes(); - // Show the initial page - if (starturl_ == nil || ![self openCydiaURL:starturl_]) { - [tabbar_ setSelectedIndex:0]; - _setHomePage(self); - } - - [starturl_ release]; - starturl_ = nil; - + [self setupViewControllers]; + [self showEmulatedLoadingControllerInView:nil]; [window_ setUserInteractionEnabled:YES]; - [self showEmulatedLoadingControllerInView:nil]; + // Show the home page. + CYNavigationController *navigation = [[tabbar_ viewControllers] objectAtIndex:0]; + [navigation setViewControllers:[NSArray arrayWithObject:[[[HomeController alloc] init] autorelease]]]; + + // (Try to) show the startup URL. + if (starturl_ != nil) { + [self openCydiaURL:starturl_]; + [starturl_ release]; + starturl_ = nil; + } } - (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item { diff --git a/UICaboodle/BrowserView.h b/UICaboodle/BrowserView.h index f224326..efc1e6c 100644 --- a/UICaboodle/BrowserView.h +++ b/UICaboodle/BrowserView.h @@ -52,7 +52,7 @@ @protocol BrowserControllerDelegate - (void) retainNetworkActivityIndicator; - (void) releaseNetworkActivityIndicator; -- (CYViewController *) pageForURL:(NSURL *)url hasTag:(int *)tag; +- (CYViewController *) pageForURL:(NSURL *)url; @end @interface BrowserController : CYViewController < diff --git a/UICaboodle/BrowserView.mm b/UICaboodle/BrowserView.mm index 1017496..2a88537 100644 --- a/UICaboodle/BrowserView.mm +++ b/UICaboodle/BrowserView.mm @@ -638,7 +638,7 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se if ([scheme isEqualToString:@"mailto"]) [self _openMailToURL:url]; - CYViewController *page([delegate_ pageForURL:url hasTag:NULL]); + CYViewController *page([delegate_ pageForURL:url]); if (page == nil) { BrowserController *browser([[[class_ alloc] init] autorelease]); -- cgit v1.2.3 From 650e9e360c5c07185b3a10adf646669aadac7d24 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Mon, 3 Jan 2011 23:05:26 -0800 Subject: Until the ignored toggle saves state, disallow modifying the state. --- MobileCydia.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MobileCydia.mm b/MobileCydia.mm index ccb5f82..2b64440 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -7924,6 +7924,8 @@ freeing the view controllers on tab change */ [ignoredCell_ setText:UCLocalize("IGNORE_UPGRADES")]; [ignoredCell_ setAccessoryView:ignoredSwitch_]; [ignoredCell_ setSelectionStyle:UITableViewCellSelectionStyleNone]; + // FIXME: Ignored state is not saved. + [ignoredCell_ setUserInteractionEnabled:NO]; [table_ setDataSource:self]; [table_ setDelegate:self]; -- cgit v1.2.3 From 0b91a8743d785866006c01457b45bfe279cbc11c Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Sat, 22 Jan 2011 15:48:14 -0800 Subject: fixed a few outdated cydia:// URLs --- MobileCydia.app/manage.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MobileCydia.app/manage.html b/MobileCydia.app/manage.html index bba3762..55e7462 100644 --- a/MobileCydia.app/manage.html +++ b/MobileCydia.app/manage.html @@ -71,7 +71,7 @@
- +
-- cgit v1.2.3 From 5829aea2aa4f13edbf151d3c2d15cd1dd15c5bd5 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Sat, 22 Jan 2011 16:31:03 -0800 Subject: Moved code around and deleted duplicated and unused code. - Moved down SourceCell and SourceController to match master. - Moved down InstalledController to be in a sane location. - Merged DepSubstrate() in with Confirmation Controller's section to avoid a useless and mis-named section. - Removed CY prefix on a number of classes where it does not belong. - Changed a few folding markers to have more descriptive and accurate names. - Probably more. --- MobileCydia.mm | 3031 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 1495 insertions(+), 1536 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 44b2c1c..e548e9b 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -3729,23 +3729,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_; @@ -4178,7 +4161,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; @@ -4908,6 +4906,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ + /* Package Cell {{{ */ @interface PackageCell : CYTableViewCell < ContentDelegate @@ -5575,6 +5574,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ + /* Package Table {{{ */ @interface PackageTable : UIView < UITableViewDataSource, @@ -5877,7 +5877,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ - /* Filtered Package Controller {{{ */ @interface FilteredPackageController : CYViewController { _transient Database *database_; @@ -5945,2060 +5944,2020 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ -/* Source Cell {{{ */ -@interface SourceCell : CYTableViewCell < - ContentDelegate -> { - UIImage *icon_; - NSString *origin_; - NSString *label_; +/* Home Controller {{{ */ +@interface HomeController : CYBrowserController { } - -- (void) setSource:(Source *)source; - @end -@implementation SourceCell - -- (void) clearSource { - [icon_ release]; - [origin_ release]; - [label_ release]; +@implementation HomeController - icon_ = nil; - origin_ = nil; - label_ = nil; ++ (BOOL)shouldHideNavigationBar { + return NO; } -- (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]; +- (void) _setMoreHeaders:(NSMutableURLRequest *)request { + [super _setMoreHeaders:request]; - [content_ setNeedsDisplay]; + if (ChipID_ != nil) + [request setValue:ChipID_ forHTTPHeaderField:@"X-Chip-ID"]; + if (UniqueID_ != nil) + [request setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"]; + if (PLMN_ != nil) + [request setValue:PLMN_ forHTTPHeaderField:@"X-Carrier-ID"]; } -- (void) dealloc { - [self clearSource]; - [super dealloc]; -} +- (void) aboutButtonClicked { + UIAlertView *alert([[[UIAlertView alloc] init] autorelease]); -- (SourceCell *) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier { - if ((self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) != nil) { - UIView *content([self contentView]); - CGRect bounds([content bounds]); + [alert setTitle:UCLocalize("ABOUT_CYDIA")]; + [alert addButtonWithTitle:UCLocalize("CLOSE")]; + [alert setCancelButtonIndex:0]; - content_ = [[ContentView alloc] initWithFrame:bounds]; - [content_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [content_ setBackgroundColor:[UIColor whiteColor]]; - [content addSubview:content_]; + [alert setMessage: + @"Copyright (C) 2008-2010\n" + "Jay Freeman (saurik)\n" + "saurik@saurik.com\n" + "http://www.saurik.com/" + ]; - [content_ setDelegate:self]; - [content_ setOpaque:YES]; - } return self; + [alert show]; } -- (void) drawContentRect:(CGRect)rect { - bool highlighted(highlighted_); - float width(rect.size.width); +- (void) viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; - if (icon_ != nil) - [icon_ drawInRect:CGRectMake(10, 10, 30, 30)]; + if ([[self class] shouldHideNavigationBar]) + [[self navigationController] setNavigationBarHidden:YES animated:animated]; +} - if (highlighted) - UISetColor(White_); +- (void) viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; - if (!highlighted) - UISetColor(Black_); - [origin_ drawAtPoint:CGPointMake(48, 8) forWidth:(width - 80) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation]; + if ([[self class] shouldHideNavigationBar]) + [[self navigationController] setNavigationBarHidden:NO animated:animated]; +} - if (!highlighted) - UISetColor(Blue_); - [label_ drawAtPoint:CGPointMake(58, 29) forWidth:(width - 95) withFont:Font12_ lineBreakMode:UILineBreakModeTailTruncation]; +- (id) init { + if ((self = [super init]) != nil) { + [self loadURL:[NSURL URLWithString:CydiaURL(@"")]]; + + [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] + initWithTitle:UCLocalize("ABOUT") + style:UIBarButtonItemStylePlain + target:self + action:@selector(aboutButtonClicked) + ] autorelease]]; + } return self; } @end /* }}} */ -/* Source Table {{{ */ -@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_; +/* Manage Controller {{{ */ +@interface ManageController : CYBrowserController { } -- (id) initWithDatabase:(Database *)database; - -- (void) updateButtonsForEditingStatus:(BOOL)editing animated:(BOOL)animated; - +- (void) queueStatusDidChange; @end -@implementation SourcesController +@implementation ManageController -- (void) _releaseConnection:(NSURLConnection *)connection { - if (connection != nil) { - [connection cancel]; - //[connection setDelegate:nil]; - [connection release]; - } -} +- (id) init { + if ((self = [super init]) != nil) { + [[self navigationItem] setTitle:UCLocalize("MANAGE")]; -- (void) dealloc { - if (href_ != nil) - [href_ release]; - if (hud_ != nil) - [hud_ release]; - if (error_ != nil) - [error_ release]; + [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"manage" ofType:@"html"]]]; - //[self _releaseConnection:installer_]; - [self _releaseConnection:trivial_]; - [self _releaseConnection:trivial_gz_]; - [self _releaseConnection:trivial_bz2_]; - //[self _releaseConnection:automatic_]; + [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] + initWithTitle:UCLocalize("SETTINGS") + style:UIBarButtonItemStylePlain + target:self + action:@selector(settingsButtonClicked) + ] autorelease]]; - [sources_ release]; - [list_ release]; - [super dealloc]; + [self queueStatusDidChange]; + } return self; } -- (void) viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; - [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated]; +- (void) settingsButtonClicked { + [delegate_ showSettings]; } -- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { - return offset_ == 0 ? 1 : 2; +#if !AlwaysReload +- (void) queueButtonClicked { + [delegate_ queue]; } -- (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 - } +- (void) applyLoadingTitle { + // No "Loading" title. } -- (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 - } +- (void) applyRightButton { + // No right button. } +#endif -- (Source *) sourceAtIndexPath:(NSIndexPath *)indexPath { - unsigned idx = 0; - switch (indexPath.section) { - case 0: idx = indexPath.row; break; - case 1: idx = indexPath.row + offset_; break; - - _nodefault +- (void) queueStatusDidChange { +#if !AlwaysReload + if (!IsWildcat_ && Queuing_) { + [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] + initWithTitle:UCLocalize("QUEUE") + style:UIBarButtonItemStyleDone + target:self + action:@selector(queueButtonClicked) + ] autorelease]]; + } else { + [[self navigationItem] setRightBarButtonItem:nil]; } - return [sources_ objectAtIndex:idx]; +#endif } -- (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; +- (bool) isLoading { + return false; } -- (UITableViewCellAccessoryType) tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath { - return UITableViewCellAccessoryDisclosureIndicator; -} +@end +/* }}} */ -- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - Source *source = [self sourceAtIndexPath:indexPath]; +/* Refresh Bar {{{ */ +@interface RefreshBar : UINavigationBar { + UIProgressIndicator *indicator_; + UITextLabel *prompt_; + UIProgressBar *progress_; + UINavigationButton *cancel_; +} - FilteredPackageController *packages = [[[FilteredPackageController alloc] - initWithDatabase:database_ - title:[source label] - filter:@selector(isVisibleInSource:) - with:source - ] autorelease]; +@end - [packages setDelegate:delegate_]; +@implementation RefreshBar - [[self navigationController] pushViewController:packages animated:YES]; +- (void) dealloc { + [indicator_ release]; + [prompt_ release]; + [progress_ release]; + [cancel_ release]; + [super dealloc]; } -- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { - Source *source = [self sourceAtIndexPath:indexPath]; - return [source record] != nil; -} +- (void) positionViews { + CGRect frame = [cancel_ frame]; + frame.size = [cancel_ sizeThatFits:frame.size]; + frame.origin.x = [self frame].size.width - frame.size.width - 5; + frame.origin.y = ([self frame].size.height - frame.size.height) / 2; + [cancel_ setFrame:frame]; -- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { - Source *source = [self sourceAtIndexPath:indexPath]; - [Sources_ removeObjectForKey:[source key]]; - [delegate_ syncData]; -} + CGSize prgsize = {75, 100}; + CGRect prgrect = {{ + [self frame].size.width - prgsize.width - 10, + ([self frame].size.height - prgsize.height) / 2 + } , prgsize}; + [progress_ setFrame:prgrect]; -- (void) complete { - [Sources_ setObject:[NSDictionary dictionaryWithObjectsAndKeys: - @"deb", @"Type", - href_, @"URI", - @"./", @"Distribution", - nil] forKey:[NSString stringWithFormat:@"deb:%@:./", href_]]; + CGSize indsize([UIProgressIndicator defaultSizeForStyle:[indicator_ activityIndicatorViewStyle]]); + unsigned indoffset = ([self frame].size.height - indsize.height) / 2; + CGRect indrect = {{indoffset, indoffset}, indsize}; + [indicator_ setFrame:indrect]; - [delegate_ syncData]; + CGSize prmsize = {215, indsize.height + 4}; + CGRect prmrect = {{ + indoffset * 2 + indsize.width, + unsigned([self frame].size.height - prmsize.height) / 2 - 1 + }, prmsize}; + [prompt_ setFrame:prmrect]; } -- (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); +- (void)setFrame:(CGRect)frame { + [super setFrame:frame]; - if (NSString *warning = [NSString stringWithContentsOfURL:url usedEncoding:&encoding error:&error]) - return [warning length] == 0 ? nil : warning; - return nil; + [self positionViews]; } -- (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; +- (id) initWithFrame:(CGRect)frame delegate:(id)delegate { + if ((self = [super initWithFrame:frame])) { + [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; - if ( - trivial_ == nil && - trivial_bz2_ == nil && - trivial_gz_ == nil - ) { - bool defer(false); + [self setBarStyle:UIBarStyleBlack]; - if (cydia_) { - if (NSString *warning = [self yieldToSelector:@selector(getWarning)]) { - defer = true; + UIBarStyle barstyle([self _barStyle:NO]); + bool ugly(barstyle == UIBarStyleDefault); - UIAlertView *alert = [[[UIAlertView alloc] - initWithTitle:UCLocalize("SOURCE_WARNING") - message:warning - delegate:self - cancelButtonTitle:UCLocalize("CANCEL") - otherButtonTitles:UCLocalize("ADD_ANYWAY"), nil - ] autorelease]; + UIProgressIndicatorStyle style = ugly ? + UIProgressIndicatorStyleMediumBrown : + UIProgressIndicatorStyleMediumWhite; - [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]; + indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectZero]; + [indicator_ setStyle:style]; + [indicator_ startAnimation]; + [self addSubview:indicator_]; - [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]; + prompt_ = [[UITextLabel alloc] initWithFrame:CGRectZero]; + [prompt_ setColor:[UIColor colorWithCGColor:(ugly ? Blueish_ : Off_)]]; + [prompt_ setBackgroundColor:[UIColor clearColor]]; + [prompt_ setFont:[UIFont systemFontOfSize:15]]; + [self addSubview:prompt_]; - [alert setContext:@"trivial"]; - [alert show]; - } + progress_ = [[UIProgressBar alloc] initWithFrame:CGRectZero]; + [progress_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin]; + [progress_ setStyle:0]; + [self addSubview:progress_]; - [delegate_ setStatusBarShowsProgress:NO]; - [delegate_ removeProgressHUD:hud_]; + cancel_ = [[UINavigationButton alloc] initWithTitle:UCLocalize("CANCEL") style:UINavigationButtonStyleHighlighted]; + [cancel_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; + [cancel_ addTarget:delegate action:@selector(cancelPressed) forControlEvents:UIControlEventTouchUpInside]; + [cancel_ setBarStyle:barstyle]; - [hud_ autorelease]; - hud_ = nil; + [self positionViews]; + } return self; +} - if (!defer) { - [href_ release]; - href_ = nil; - } +- (void) cancel { + [cancel_ removeFromSuperview]; +} - if (error_ != nil) { - [error_ release]; - error_ = nil; - } - } +- (void) start { + [prompt_ setText:UCLocalize("UPDATING_DATABASE")]; + [progress_ setProgress:0]; + [self addSubview:cancel_]; } -- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response { - switch ([response statusCode]) { - case 200: - cydia_ = YES; - } +- (void) stop { + [cancel_ removeFromSuperview]; } -- (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) setPrompt:(NSString *)prompt { + [prompt_ setText:prompt]; } -- (void) connectionDidFinishLoading:(NSURLConnection *)connection { - [self _endConnection:connection]; +- (void) setProgress:(float)progress { + [progress_ setProgress:progress]; } -- (NSString *) title { return UCLocalize("SOURCES"); } +@end +/* }}} */ -- (NSURLConnection *) _requestHRef:(NSString *)href method:(NSString *)method { - NSMutableURLRequest *request = [NSMutableURLRequest - requestWithURL:[NSURL URLWithString:href] - cachePolicy:NSURLRequestUseProtocolCachePolicy - timeoutInterval:120.0 - ]; +@class CYNavigationController; - [request setHTTPMethod:method]; +/* Cydia Tab Bar Controller {{{ */ +@interface CYTabBarController : UITabBarController < + ProgressDelegate +> { + _transient Database *database_; + RefreshBar *refreshbar_; - 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"]; + bool dropped_; + bool updating_; + // XXX: ok, "updatedelegate_"?... + _transient NSObject *updatedelegate_; - return [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease]; + id root_; } -- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button { - NSString *context([alert context]); +- (void) dropBar:(BOOL)animated; +- (void) beginUpdate; +- (void) raiseBar:(BOOL)animated; +- (BOOL) updating; - 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 - } +@end - [href_ release]; - href_ = nil; +@implementation CYTabBarController - [alert dismissWithClickedButtonIndex:-1 animated:YES]; +- (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]; } } - (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 view] setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameChanged:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil]; - [self reloadData]; + refreshbar_ = [[RefreshBar alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, [UINavigationBar defaultSize].height) delegate:self]; } 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]; +- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { + return IsWildcat_ || orientation == UIInterfaceOrientationPortrait; } -- (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)]; +- (void) setUpdate:(NSDate *)date { + [self beginUpdate]; +} - [alert setNumberOfRows:1]; - [alert addTextFieldWithValue:@"http://" label:@""]; +- (void) beginUpdate { + [refreshbar_ start]; + [self dropBar:YES]; - UITextInputTraits *traits = [[alert textField] textInputTraits]; - [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone]; - [traits setAutocorrectionType:UITextAutocorrectionTypeNo]; - [traits setKeyboardType:UIKeyboardTypeURL]; - // XXX: UIReturnKeyDone - [traits setReturnKeyType:UIReturnKeyNext]; + [updatedelegate_ retainNetworkActivityIndicator]; + updating_ = true; - [alert show]; + [NSThread + detachNewThreadSelector:@selector(performUpdate) + toTarget:self + withObject:nil + ]; } -- (void) addButtonClicked { - [self showAddSourcePrompt]; +- (void) performUpdate { _pooled + Status status; + status.setDelegate(self); + [database_ updateWithStatus:status]; + + [self + performSelectorOnMainThread:@selector(completeUpdate) + withObject:nil + waitUntilDone:NO + ]; } -- (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]; +- (void) stopUpdateWithSelector:(SEL)selector { + updating_ = false; + [updatedelegate_ releaseNetworkActivityIndicator]; - [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:(editing ? UCLocalize("DONE") : UCLocalize("EDIT")) - style:(editing ? UIBarButtonItemStyleDone : UIBarButtonItemStylePlain) - target:self - action:@selector(editButtonClicked) - ] autorelease] animated:animated]; + [self raiseBar:YES]; + [refreshbar_ stop]; - if (IsWildcat_ && !editing) - [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:UCLocalize("SETTINGS") - style:UIBarButtonItemStylePlain - target:self - action:@selector(settingsButtonClicked) - ] autorelease]]; + [updatedelegate_ performSelector:selector withObject:nil afterDelay:0]; } -- (void) settingsButtonClicked { - [delegate_ showSettings]; +- (void) completeUpdate { + if (!updating_) + return; + [self stopUpdateWithSelector:@selector(reloadData)]; } -- (void) editButtonClicked { - [list_ setEditing:![list_ isEditing] animated:YES]; - - [self updateButtonsForEditingStatus:[list_ isEditing] animated:YES]; +- (void) cancelUpdate { + [self stopUpdateWithSelector:@selector(updateData)]; } -@end -/* }}} */ +- (void) cancelPressed { + [self cancelUpdate]; +} -/* Installed Controller {{{ */ -@interface InstalledController : FilteredPackageController { - BOOL expert_; +- (BOOL) updating { + return updating_; } -- (id) initWithDatabase:(Database *)database; +- (void) setProgressError:(NSString *)error withTitle:(NSString *)title { + [refreshbar_ setPrompt:[NSString stringWithFormat:UCLocalize("COLON_DELIMITED"), UCLocalize("ERROR"), error]]; +} -- (void) updateRoleButton; -- (void) queueStatusDidChange; +- (void) startProgress { +} -@end +- (void) setProgressTitle:(NSString *)title { + [self + performSelectorOnMainThread:@selector(_setProgressTitle:) + withObject:title + waitUntilDone:YES + ]; +} -@implementation InstalledController +- (bool) isCancelling:(size_t)received { + return !updating_; +} -- (void) dealloc { - [super dealloc]; +- (void) setProgressPercent:(float)percent { + [self + performSelectorOnMainThread:@selector(_setProgressPercent:) + withObject:[NSNumber numberWithFloat:percent] + waitUntilDone:YES + ]; } -- (NSString *) title { return UCLocalize("INSTALLED"); } +- (void) addProgressOutput:(NSString *)output { + [self + performSelectorOnMainThread:@selector(_addProgressOutput:) + withObject:output + waitUntilDone:YES + ]; +} -- (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) _setProgressTitle:(NSString *)title { + [refreshbar_ setPrompt:title]; } -#if !AlwaysReload -- (void) queueButtonClicked { - [delegate_ queue]; +- (void) _setProgressPercent:(NSNumber *)percent { + [refreshbar_ setProgress:[percent floatValue]]; } -#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) _addProgressOutput:(NSString *)output { } -- (void) reloadData { - [packages_ reloadData]; +- (void) setUpdateDelegate:(id)delegate { + updatedelegate_ = delegate; } -- (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]]; +- (CGFloat) statusBarHeight { + if (UIInterfaceOrientationIsPortrait([self interfaceOrientation])) { + return [[UIApplication sharedApplication] statusBarFrame].size.height; + } else { + return [[UIApplication sharedApplication] statusBarFrame].size.width; + } } -- (void) roleButtonClicked { - [packages_ setObject:[NSNumber numberWithBool:expert_]]; - [packages_ reloadData]; - expert_ = !expert_; - - [self updateRoleButton]; +- (UIView *) transitionView { + if ([self respondsToSelector:@selector(_transitionView)]) + return [self _transitionView]; + else + return MSHookIvar(self, "_viewControllerTransitionView"); } -- (void) setDelegate:(id)delegate { - [super setDelegate:delegate]; - [packages_ setDelegate:delegate]; -} +- (void) dropBar:(BOOL)animated { + if (dropped_) + return; + dropped_ = true; -@end -/* }}} */ -/* Section Controller {{{ */ -@interface CYSectionController : FilteredPackageController { -} + UIView *transition([self transitionView]); + [[self view] addSubview:refreshbar_]; -- (id) initWithDatabase:(Database *)database section:(NSString *)section; + CGRect barframe([refreshbar_ frame]); -@end + if (false) // XXX: _UIApplicationLinkedOnOrAfter(4) + barframe.origin.y = [self statusBarHeight]; + else + barframe.origin.y = 0; -@implementation CYSectionController + [refreshbar_ setFrame:barframe]; -- (void) dealloc { - [super dealloc]; -} + if (animated) + [UIView beginAnimations:nil context:NULL]; -- (id) initWithDatabase:(Database *)database section:(NSString *)name { - NSString *title; + CGRect viewframe = [transition frame]; + viewframe.origin.y += barframe.size.height; + viewframe.size.height -= barframe.size.height; + [transition setFrame:viewframe]; - 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 (animated) + [UIView commitAnimations]; - if ((self = [super initWithDatabase:database title:title filter:@selector(isVisibleInSection:) with:name]) != nil) { - } return self; -} + // Ensure bar has the proper width for our view, it might have changed + barframe.size.width = viewframe.size.width; + [refreshbar_ setFrame:barframe]; -- (void) reloadData { - [packages_ reloadData]; + // XXX: fix Apple's layout bug + [[root_ selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation]; } -- (void) setDelegate:(id)delegate { - [super setDelegate:delegate]; - [packages_ setDelegate:delegate]; -} +- (void) raiseBar:(BOOL)animated { + if (!dropped_) + return; + dropped_ = false; -@end -/* }}} */ + UIView *transition([self transitionView]); + [refreshbar_ removeFromSuperview]; -/* Home Controller {{{ */ -@interface HomeController : CYBrowserController { -} -@end + CGRect barframe([refreshbar_ frame]); -@implementation HomeController + if (animated) + [UIView beginAnimations:nil context:NULL]; -+ (BOOL)shouldHideNavigationBar { - return NO; -} + CGRect viewframe = [transition frame]; + viewframe.origin.y -= barframe.size.height; + viewframe.size.height += barframe.size.height; + [transition setFrame:viewframe]; -- (void) _setMoreHeaders:(NSMutableURLRequest *)request { - [super _setMoreHeaders:request]; + if (animated) + [UIView commitAnimations]; - if (ChipID_ != nil) - [request setValue:ChipID_ forHTTPHeaderField:@"X-Chip-ID"]; - if (UniqueID_ != nil) - [request setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"]; - if (PLMN_ != nil) - [request setValue:PLMN_ forHTTPHeaderField:@"X-Carrier-ID"]; + // XXX: fix Apple's layout bug + // SRK [[self selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation]; } -- (void) aboutButtonClicked { - UIAlertView *alert([[[UIAlertView alloc] init] autorelease]); +#if 0 +- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { + // XXX: fix Apple's layout bug + // SRK [[self selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation]; +} +#endif - [alert setTitle:UCLocalize("ABOUT_CYDIA")]; - [alert addButtonWithTitle:UCLocalize("CLOSE")]; - [alert setCancelButtonIndex:0]; +- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { + bool dropped(dropped_); - [alert setMessage: - @"Copyright (C) 2008-2010\n" - "Jay Freeman (saurik)\n" - "saurik@saurik.com\n" - "http://www.saurik.com/" - ]; + if (dropped) + [self raiseBar:NO]; - [alert show]; -} + [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; -- (void) viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; + if (dropped) + [self dropBar:NO]; - if ([[self class] shouldHideNavigationBar]) - [[self navigationController] setNavigationBarHidden:YES animated:animated]; + // XXX: fix Apple's layout bug + // SRK [[self selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation]; } -- (void) viewWillDisappear:(BOOL)animated { - [super viewWillDisappear:animated]; - - if ([[self class] shouldHideNavigationBar]) - [[self navigationController] setNavigationBarHidden:NO animated:animated]; +- (void) statusBarFrameChanged:(NSNotification *)notification { + if (dropped_) { + [self raiseBar:NO]; + [self dropBar:NO]; + } } -- (id) init { - if ((self = [super init]) != nil) { - [self loadURL:[NSURL URLWithString:CydiaURL(@"")]]; - - [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:UCLocalize("ABOUT") - style:UIBarButtonItemStylePlain - target:self - action:@selector(aboutButtonClicked) - ] autorelease]]; - } return self; +- (void) dealloc { + [refreshbar_ release]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [super dealloc]; } @end /* }}} */ -/* Manage Controller {{{ */ -@interface ManageController : CYBrowserController { +/* Cydia Navigation Controller {{{ */ +@interface CYNavigationController : UINavigationController { + _transient Database *database_; + _transient id delegate_; } -- (void) queueStatusDidChange; -@end - -@implementation ManageController +- (id) initWithDatabase:(Database *)database; +- (void) reloadData; -- (id) init { - if ((self = [super init]) != nil) { - [[self navigationItem] setTitle:UCLocalize("MANAGE")]; +@end - [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"manage" ofType:@"html"]]]; - [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:UCLocalize("SETTINGS") - style:UIBarButtonItemStylePlain - target:self - action:@selector(settingsButtonClicked) - ] autorelease]]; +@implementation CYNavigationController - [self queueStatusDidChange]; - } return self; +- (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) settingsButtonClicked { - [delegate_ showSettings]; +- (void) dealloc { + [super dealloc]; } -#if !AlwaysReload -- (void) queueButtonClicked { - [delegate_ queue]; +- (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]; + } } -- (void) applyLoadingTitle { - // No "Loading" title. +- (void) setDelegate:(id)delegate { + delegate_ = delegate; } -- (void) applyRightButton { - // No right button. +- (id) initWithDatabase:(Database *)database { + if ((self = [super init]) != nil) { + database_ = database; + } return self; } -#endif -- (void) queueStatusDidChange { -#if !AlwaysReload - if (!IsWildcat_ && Queuing_) { - [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:UCLocalize("QUEUE") - style:UIBarButtonItemStyleDone - target:self - action:@selector(queueButtonClicked) - ] autorelease]]; - } else { - [[self navigationItem] setRightBarButtonItem:nil]; - } -#endif -} +@end +/* }}} */ -- (bool) isLoading { - return false; +/* Cydia:// Protocol {{{ */ +@interface CydiaURLProtocol : NSURLProtocol { } @end -/* }}} */ -/* Refresh Bar {{{ */ -@interface RefreshBar : UINavigationBar { - UIProgressIndicator *indicator_; - UITextLabel *prompt_; - UIProgressBar *progress_; - UINavigationButton *cancel_; +@implementation CydiaURLProtocol + ++ (BOOL) canInitWithRequest:(NSURLRequest *)request { + NSURL *url([request URL]); + if (url == nil) + return NO; + NSString *scheme([[url scheme] lowercaseString]); + if (scheme == nil || ![scheme isEqualToString:@"cydia"]) + return NO; + return YES; } -@end ++ (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request { + return request; +} -@implementation RefreshBar +- (void) _returnPNGWithImage:(UIImage *)icon forRequest:(NSURLRequest *)request { + id client([self client]); + if (icon == nil) + [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]]; + else { + NSData *data(UIImagePNGRepresentation(icon)); -- (void) dealloc { - [indicator_ release]; - [prompt_ release]; - [progress_ release]; - [cancel_ release]; - [super dealloc]; + NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/png" expectedContentLength:-1 textEncodingName:nil] autorelease]); + [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed]; + [client URLProtocol:self didLoadData:data]; + [client URLProtocolDidFinishLoading:self]; + } } -- (void) positionViews { - CGRect frame = [cancel_ frame]; - frame.size = [cancel_ sizeThatFits:frame.size]; - frame.origin.x = [self frame].size.width - frame.size.width - 5; - frame.origin.y = ([self frame].size.height - frame.size.height) / 2; - [cancel_ setFrame:frame]; +- (void) startLoading { + id client([self client]); + NSURLRequest *request([self request]); - CGSize prgsize = {75, 100}; - CGRect prgrect = {{ - [self frame].size.width - prgsize.width - 10, - ([self frame].size.height - prgsize.height) / 2 - } , prgsize}; - [progress_ setFrame:prgrect]; + NSURL *url([request URL]); + NSString *href([url absoluteString]); - CGSize indsize([UIProgressIndicator defaultSizeForStyle:[indicator_ activityIndicatorViewStyle]]); - unsigned indoffset = ([self frame].size.height - indsize.height) / 2; - CGRect indrect = {{indoffset, indoffset}, indsize}; - [indicator_ setFrame:indrect]; + NSString *path([href substringFromIndex:8]); + NSRange slash([path rangeOfString:@"/"]); - CGSize prmsize = {215, indsize.height + 4}; - CGRect prmrect = {{ - indoffset * 2 + indsize.width, - unsigned([self frame].size.height - prmsize.height) / 2 - 1 - }, prmsize}; - [prompt_ setFrame:prmrect]; -} + NSString *command; + if (slash.location == NSNotFound) { + command = path; + path = nil; + } else { + command = [path substringToIndex:slash.location]; + path = [path substringFromIndex:(slash.location + 1)]; + } -- (void)setFrame:(CGRect)frame { - [super setFrame:frame]; + Database *database([Database sharedInstance]); - [self positionViews]; + if ([command isEqualToString:@"package-icon"]) { + if (path == nil) + goto fail; + path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + Package *package([database packageWithName:path]); + if (package == nil) + goto fail; + UIImage *icon([package icon]); + [self _returnPNGWithImage:icon forRequest:request]; + } else if ([command isEqualToString:@"source-icon"]) { + if (path == nil) + goto fail; + path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + NSString *source(Simplify(path)); + UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sources/%@.png", App_, source]]); + if (icon == nil) + icon = [UIImage applicationImageNamed:@"unknown.png"]; + [self _returnPNGWithImage:icon forRequest:request]; + } else if ([command isEqualToString:@"uikit-image"]) { + if (path == nil) + goto fail; + path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + UIImage *icon(_UIImageWithName(path)); + [self _returnPNGWithImage:icon forRequest:request]; + } else if ([command isEqualToString:@"section-icon"]) { + if (path == nil) + goto fail; + path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + NSString *section(Simplify(path)); + UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, section]]); + if (icon == nil) + icon = [UIImage applicationImageNamed:@"unknown.png"]; + [self _returnPNGWithImage:icon forRequest:request]; + } else fail: { + [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]]; + } } -- (id) initWithFrame:(CGRect)frame delegate:(id)delegate { - if ((self = [super initWithFrame:frame])) { - [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; - - [self setBarStyle:UIBarStyleBlack]; - - UIBarStyle barstyle([self _barStyle:NO]); - bool ugly(barstyle == UIBarStyleDefault); +- (void) stopLoading { +} - UIProgressIndicatorStyle style = ugly ? - UIProgressIndicatorStyleMediumBrown : - UIProgressIndicatorStyleMediumWhite; +@end +/* }}} */ - indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectZero]; - [indicator_ setStyle:style]; - [indicator_ startAnimation]; - [self addSubview:indicator_]; +/* Section Controller {{{ */ +@interface SectionController : FilteredPackageController { +} - prompt_ = [[UITextLabel alloc] initWithFrame:CGRectZero]; - [prompt_ setColor:[UIColor colorWithCGColor:(ugly ? Blueish_ : Off_)]]; - [prompt_ setBackgroundColor:[UIColor clearColor]]; - [prompt_ setFont:[UIFont systemFontOfSize:15]]; - [self addSubview:prompt_]; +- (id) initWithDatabase:(Database *)database section:(NSString *)section; - progress_ = [[UIProgressBar alloc] initWithFrame:CGRectZero]; - [progress_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin]; - [progress_ setStyle:0]; - [self addSubview:progress_]; +@end - cancel_ = [[UINavigationButton alloc] initWithTitle:UCLocalize("CANCEL") style:UINavigationButtonStyleHighlighted]; - [cancel_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; - [cancel_ addTarget:delegate action:@selector(cancelPressed) forControlEvents:UIControlEventTouchUpInside]; - [cancel_ setBarStyle:barstyle]; +@implementation SectionController - [self positionViews]; - } return self; +- (void) dealloc { + [super dealloc]; } -- (void) cancel { - [cancel_ removeFromSuperview]; -} +- (id) initWithDatabase:(Database *)database section:(NSString *)name { + NSString *title; -- (void) start { - [prompt_ setText:UCLocalize("UPDATING_DATABASE")]; - [progress_ setProgress:0]; - [self addSubview:cancel_]; -} + 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"); + } -- (void) stop { - [cancel_ removeFromSuperview]; + if ((self = [super initWithDatabase:database title:title filter:@selector(isVisibleInSection:) with:name]) != nil) { + } return self; } -- (void) setPrompt:(NSString *)prompt { - [prompt_ setText:prompt]; +- (void) reloadData { + [packages_ reloadData]; } -- (void) setProgress:(float)progress { - [progress_ setProgress:progress]; +- (void) setDelegate:(id)delegate { + [super setDelegate:delegate]; + [packages_ setDelegate:delegate]; } @end /* }}} */ - -@class CYNavigationController; - -/* Cydia Tab Bar Controller {{{ */ -@interface CYTabBarController : UITabBarController < - ProgressDelegate +/* Sections Controller {{{ */ +@interface SectionsController : CYViewController < + UITableViewDataSource, + UITableViewDelegate > { _transient Database *database_; - RefreshBar *refreshbar_; - - bool dropped_; - bool updating_; - // XXX: ok, "updatedelegate_"?... - _transient NSObject *updatedelegate_; - - id root_; + NSMutableArray *sections_; + NSMutableArray *filtered_; + UITableView *list_; + UIView *accessory_; + BOOL editing_; } -- (void) dropBar:(BOOL)animated; -- (void) beginUpdate; -- (void) raiseBar:(BOOL)animated; -- (BOOL) updating; +- (id) initWithDatabase:(Database *)database; +- (void) reloadData; +- (void) resetView; + +- (void) editButtonClicked; @end -@implementation CYTabBarController +@implementation SectionsController -- (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]; - } -} +- (void) dealloc { + [list_ setDataSource:nil]; + [list_ setDelegate:nil]; -- (id) initWithDatabase:(Database *)database { - if ((self = [super init]) != nil) { - database_ = database; + [sections_ release]; + [filtered_ release]; + [list_ release]; + [accessory_ release]; + [super dealloc]; +} - [[self view] setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameChanged:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil]; +- (void) setEditing:(BOOL)editing { + if ((editing_ = editing)) + [list_ reloadData]; + else + [delegate_ updateData]; - refreshbar_ = [[RefreshBar alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, [UINavigationBar defaultSize].height) delegate:self]; - } return self; + [[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]; } -- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { - return IsWildcat_ || orientation == UIInterfaceOrientationPortrait; +- (void) viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; + [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated]; } -- (void) setUpdate:(NSDate *)date { - [self beginUpdate]; +- (void) viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + if (editing_) [self setEditing:NO]; } -- (void) beginUpdate { - [refreshbar_ start]; - [self dropBar:YES]; - - [updatedelegate_ retainNetworkActivityIndicator]; - updating_ = true; +- (Section *) sectionAtIndexPath:(NSIndexPath *)indexPath { + Section *section = (editing_ ? [sections_ objectAtIndex:[indexPath row]] : ([indexPath row] == 0 ? nil : [filtered_ objectAtIndex:([indexPath row] - 1)])); + return section; +} - [NSThread - detachNewThreadSelector:@selector(performUpdate) - toTarget:self - withObject:nil - ]; +- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return editing_ ? [sections_ count] : [filtered_ count] + 1; } -- (void) performUpdate { _pooled - Status status; - status.setDelegate(self); - [database_ updateWithStatus:status]; +/*- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { + return 45.0f; +}*/ - [self - performSelectorOnMainThread:@selector(completeUpdate) - withObject:nil - waitUntilDone:NO - ]; -} +- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + static NSString *reuseIdentifier = @"SectionCell"; -- (void) stopUpdateWithSelector:(SEL)selector { - updating_ = false; - [updatedelegate_ releaseNetworkActivityIndicator]; + SectionCell *cell = (SectionCell *) [tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; + if (cell == nil) + cell = [[[SectionCell alloc] initWithFrame:CGRectZero reuseIdentifier:reuseIdentifier] autorelease]; - [self raiseBar:YES]; - [refreshbar_ stop]; + [cell setSection:[self sectionAtIndexPath:indexPath] editing:editing_]; - [updatedelegate_ performSelector:selector withObject:nil afterDelay:0]; + return cell; } -- (void) completeUpdate { - if (!updating_) +- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + if (editing_) return; - [self stopUpdateWithSelector:@selector(reloadData)]; -} -- (void) cancelUpdate { - [self stopUpdateWithSelector:@selector(updateData)]; -} + Section *section = [self sectionAtIndexPath:indexPath]; -- (void) cancelPressed { - [self cancelUpdate]; -} + SectionController *controller = [[[SectionController alloc] + initWithDatabase:database_ + section:[section name] + ] autorelease]; + [controller setDelegate:delegate_]; -- (BOOL) updating { - return updating_; + [[self navigationController] pushViewController:controller animated:YES]; } -- (void) setProgressError:(NSString *)error withTitle:(NSString *)title { - [refreshbar_ setPrompt:[NSString stringWithFormat:UCLocalize("COLON_DELIMITED"), UCLocalize("ERROR"), error]]; -} +- (id) initWithDatabase:(Database *)database { + if ((self = [super init]) != nil) { + database_ = database; -- (void) startProgress { -} + [[self navigationItem] setTitle:UCLocalize("SECTIONS")]; -- (void) setProgressTitle:(NSString *)title { - [self - performSelectorOnMainThread:@selector(_setProgressTitle:) - withObject:title - waitUntilDone:YES - ]; -} + sections_ = [[NSMutableArray arrayWithCapacity:16] retain]; + filtered_ = [[NSMutableArray arrayWithCapacity:16] retain]; -- (bool) isCancelling:(size_t)received { - return !updating_; -} + list_ = [[UITableView alloc] initWithFrame:[[self view] bounds]]; + [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [list_ setRowHeight:45.0f]; + [[self view] addSubview:list_]; -- (void) setProgressPercent:(float)percent { - [self - performSelectorOnMainThread:@selector(_setProgressPercent:) - withObject:[NSNumber numberWithFloat:percent] - waitUntilDone:YES - ]; -} + [list_ setDataSource:self]; + [list_ setDelegate:self]; -- (void) addProgressOutput:(NSString *)output { - [self - performSelectorOnMainThread:@selector(_addProgressOutput:) - withObject:output - waitUntilDone:YES - ]; + [self reloadData]; + } return self; } -- (void) _setProgressTitle:(NSString *)title { - [refreshbar_ setPrompt:title]; -} +- (void) reloadData { + NSArray *packages = [database_ packages]; -- (void) _setProgressPercent:(NSNumber *)percent { - [refreshbar_ setProgress:[percent floatValue]]; -} + [sections_ removeAllObjects]; + [filtered_ removeAllObjects]; -- (void) _addProgressOutput:(NSString *)output { -} + NSMutableDictionary *sections([NSMutableDictionary dictionaryWithCapacity:32]); -- (void) setUpdateDelegate:(id)delegate { - updatedelegate_ = delegate; -} + _trace(); + for (Package *package in packages) { + NSString *name([package section]); + NSString *key(name == nil ? @"" : name); -- (CGFloat) statusBarHeight { - if (UIInterfaceOrientationIsPortrait([self interfaceOrientation])) { - return [[UIApplication sharedApplication] statusBarFrame].size.height; - } else { - return [[UIApplication sharedApplication] statusBarFrame].size.width; - } -} + Section *section; -- (UIView *) transitionView { - if ([self respondsToSelector:@selector(_transitionView)]) - return [self _transitionView]; - else - return MSHookIvar(self, "_viewControllerTransitionView"); -} + _profile(SectionsView$reloadData$Section) + section = [sections objectForKey:key]; + if (section == nil) { + _profile(SectionsView$reloadData$Section$Allocate) + section = [[[Section alloc] initWithName:name localize:YES] autorelease]; + [sections setObject:section forKey:key]; + _end + } + _end -- (void) dropBar:(BOOL)animated { - if (dropped_) - return; - dropped_ = true; + [section addToCount]; - UIView *transition([self transitionView]); - [[self view] addSubview:refreshbar_]; + _profile(SectionsView$reloadData$Filter) + if (![package valid] || ![package visible]) + continue; + _end - CGRect barframe([refreshbar_ frame]); + [section addToRow]; + } + _trace(); - if (false) // XXX: _UIApplicationLinkedOnOrAfter(4) - barframe.origin.y = [self statusBarHeight]; - else - barframe.origin.y = 0; + [sections_ addObjectsFromArray:[sections allValues]]; - [refreshbar_ setFrame:barframe]; + [sections_ sortUsingSelector:@selector(compareByLocalized:)]; - if (animated) - [UIView beginAnimations:nil context:NULL]; + for (Section *section in sections_) { + size_t count([section row]); + if (count == 0) + continue; - CGRect viewframe = [transition frame]; - viewframe.origin.y += barframe.size.height; - viewframe.size.height -= barframe.size.height; - [transition setFrame:viewframe]; + section = [[[Section alloc] initWithName:[section name] localized:[section localized]] autorelease]; + [section setCount:count]; + [filtered_ addObject:section]; + } - if (animated) - [UIView commitAnimations]; + [[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)]; - // Ensure bar has the proper width for our view, it might have changed - barframe.size.width = viewframe.size.width; - [refreshbar_ setFrame:barframe]; + [list_ reloadData]; + _trace(); +} - // XXX: fix Apple's layout bug - [[root_ selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation]; +- (void) resetView { + if (editing_) + [self editButtonClicked]; } -- (void) raiseBar:(BOOL)animated { - if (!dropped_) - return; - dropped_ = false; +- (void)editButtonClicked { + [self setEditing:!editing_]; +} - UIView *transition([self transitionView]); - [refreshbar_ removeFromSuperview]; +- (UIView *) accessoryView { + return accessory_; +} - CGRect barframe([refreshbar_ frame]); +@end +/* }}} */ - if (animated) - [UIView beginAnimations:nil context:NULL]; +/* Changes Controller {{{ */ +@interface ChangesController : CYViewController < + UITableViewDataSource, + UITableViewDelegate +> { + _transient Database *database_; + unsigned era_; + CFMutableArrayRef packages_; + NSMutableArray *sections_; + UITableView *list_; + unsigned upgrades_; + BOOL hasSentFirstLoad_; +} - CGRect viewframe = [transition frame]; - viewframe.origin.y -= barframe.size.height; - viewframe.size.height += barframe.size.height; - [transition setFrame:viewframe]; +- (id) initWithDatabase:(Database *)database delegate:(id)delegate; +- (void) reloadData; - if (animated) - [UIView commitAnimations]; +@end - // XXX: fix Apple's layout bug - // SRK [[self selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation]; -} +@implementation ChangesController -#if 0 -- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { - // XXX: fix Apple's layout bug - // SRK [[self selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation]; -} -#endif - -- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { - bool dropped(dropped_); - - if (dropped) - [self raiseBar:NO]; - - [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; +- (void) dealloc { + [list_ setDelegate:nil]; + [list_ setDataSource:nil]; - if (dropped) - [self dropBar:NO]; + CFRelease(packages_); - // XXX: fix Apple's layout bug - // SRK [[self selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation]; + [sections_ release]; + [list_ release]; + [super dealloc]; } -- (void) statusBarFrameChanged:(NSNotification *)notification { - if (dropped_) { - [self raiseBar:NO]; - [self dropBar:NO]; +- (void) viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; + if (!hasSentFirstLoad_) { + hasSentFirstLoad_ = YES; + [self performSelector:@selector(reloadData) withObject:nil afterDelay:0.0]; + } else { + [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated]; } } -- (void) dealloc { - [refreshbar_ release]; - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [super dealloc]; +- (NSInteger) numberOfSectionsInTableView:(UITableView *)list { + NSInteger count([sections_ count]); + return count == 0 ? 1 : count; } -@end -/* }}} */ - -/* Cydia Navigation Controller {{{ */ -@interface CYNavigationController : UINavigationController { - _transient Database *database_; - _transient id delegate_; +- (NSString *) tableView:(UITableView *)list titleForHeaderInSection:(NSInteger)section { + if ([sections_ count] == 0) + return nil; + return [[sections_ objectAtIndex:section] name]; } -- (id) initWithDatabase:(Database *)database; -- (void) reloadData; +- (NSInteger) tableView:(UITableView *)list numberOfRowsInSection:(NSInteger)section { + if ([sections_ count] == 0) + return 0; + return [[sections_ objectAtIndex:section] count]; +} -@end +- (Package *) packageAtIndex:(NSUInteger)index { + return (Package *) CFArrayGetValueAtIndex(packages_, index); +} +- (Package *) packageAtIndexPath:(NSIndexPath *)path { +@synchronized (database_) { + if ([database_ era] != era_) + return nil; -@implementation CYNavigationController + NSUInteger sectionIndex([path section]); + if (sectionIndex >= [sections_ count]) + return nil; + Section *section([sections_ objectAtIndex:sectionIndex]); + NSInteger row([path row]); + return [[[self packageAtIndex:([section row] + row)] retain] autorelease]; +} } -- (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]; - } +- (UITableViewCell *) tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path { + PackageCell *cell((PackageCell *) [table dequeueReusableCellWithIdentifier:@"Package"]); + if (cell == nil) + cell = [[[PackageCell alloc] init] autorelease]; + [cell setPackage:[self packageAtIndexPath:path]]; + return cell; } -- (void) dealloc { - [super dealloc]; +- (NSIndexPath *) tableView:(UITableView *)table willSelectRowAtIndexPath:(NSIndexPath *)path { + Package *package([self packageAtIndexPath:path]); + CYPackageController *view([[[CYPackageController alloc] initWithDatabase:database_] autorelease]); + [view setDelegate:delegate_]; + [view setPackage:package]; + [[self navigationController] pushViewController:view animated:YES]; + return path; } -- (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]; - } +- (void) refreshButtonClicked { + [delegate_ beginUpdate]; + [[self navigationItem] setLeftBarButtonItem:nil animated:YES]; } -- (void) setDelegate:(id)delegate { - delegate_ = delegate; +- (void) upgradeButtonClicked { + [delegate_ distUpgrade]; } -- (id) initWithDatabase:(Database *)database { +- (NSString *) title { return UCLocalize("CHANGES"); } + +- (id) initWithDatabase:(Database *)database delegate:(id)delegate { if ((self = [super init]) != nil) { database_ = database; - } return self; -} + [[self navigationItem] setTitle:UCLocalize("CHANGES")]; -@end -/* }}} */ -/* Cydia:// Protocol {{{ */ -@interface CydiaURLProtocol : NSURLProtocol { -} + packages_ = CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL); -@end + sections_ = [[NSMutableArray arrayWithCapacity:16] retain]; -@implementation CydiaURLProtocol + list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain]; + [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [list_ setRowHeight:73]; + [[self view] addSubview:list_]; -+ (BOOL) canInitWithRequest:(NSURLRequest *)request { - NSURL *url([request URL]); - if (url == nil) - return NO; - NSString *scheme([[url scheme] lowercaseString]); - if (scheme == nil || ![scheme isEqualToString:@"cydia"]) - return NO; - return YES; -} + [list_ setDataSource:self]; + [list_ setDelegate:self]; -+ (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request { - return request; + delegate_ = delegate; + } return self; } -- (void) _returnPNGWithImage:(UIImage *)icon forRequest:(NSURLRequest *)request { - id client([self client]); - if (icon == nil) - [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]]; - else { - NSData *data(UIImagePNGRepresentation(icon)); +- (void) _reloadPackages:(NSArray *)packages { + CFRelease(packages_); + packages_ = CFArrayCreateMutable(kCFAllocatorDefault, [packages count], NULL); - NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/png" expectedContentLength:-1 textEncodingName:nil] autorelease]); - [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed]; - [client URLProtocol:self didLoadData:data]; - [client URLProtocolDidFinishLoading:self]; - } + _trace(); + _profile(ChangesController$_reloadPackages$Filter) + for (Package *package in packages) + if ([package upgradableAndEssential:YES] || [package visible]) + CFArrayAppendValue(packages_, package); + _end + _trace(); + _profile(ChangesController$_reloadPackages$radixSort) + [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackageChangesRadix) withContext:NULL]; + _end + _trace(); } -- (void) startLoading { - id client([self client]); - NSURLRequest *request([self request]); +- (void) reloadData { +@synchronized (database_) { + era_ = [database_ era]; + NSArray *packages = [database_ packages]; - NSURL *url([request URL]); - NSString *href([url absoluteString]); + [sections_ removeAllObjects]; - NSString *path([href substringFromIndex:8]); - NSRange slash([path rangeOfString:@"/"]); +#if 1 + UIProgressHUD *hud([delegate_ addProgressHUD]); + [hud setText:UCLocalize("LOADING")]; + //NSLog(@"HUD:%@::%@", delegate_, hud); + [self yieldToSelector:@selector(_reloadPackages:) withObject:packages]; + [delegate_ removeProgressHUD:hud]; +#else + [self _reloadPackages:packages]; +#endif - NSString *command; - if (slash.location == NSNotFound) { - command = path; - path = nil; - } else { - command = [path substringToIndex:slash.location]; - path = [path substringFromIndex:(slash.location + 1)]; - } + Section *upgradable = [[[Section alloc] initWithName:UCLocalize("AVAILABLE_UPGRADES") localize:NO] autorelease]; + Section *ignored = nil; + Section *section = nil; + time_t last = 0; - Database *database([Database sharedInstance]); + upgrades_ = 0; + bool unseens = false; - if ([command isEqualToString:@"package-icon"]) { - if (path == nil) - goto fail; - path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - Package *package([database packageWithName:path]); - if (package == nil) - goto fail; - UIImage *icon([package icon]); - [self _returnPNGWithImage:icon forRequest:request]; - } else if ([command isEqualToString:@"source-icon"]) { - if (path == nil) - goto fail; - path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - NSString *source(Simplify(path)); - UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sources/%@.png", App_, source]]); - if (icon == nil) - icon = [UIImage applicationImageNamed:@"unknown.png"]; - [self _returnPNGWithImage:icon forRequest:request]; - } else if ([command isEqualToString:@"uikit-image"]) { - if (path == nil) - goto fail; - path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - UIImage *icon(_UIImageWithName(path)); - [self _returnPNGWithImage:icon forRequest:request]; - } else if ([command isEqualToString:@"section-icon"]) { - if (path == nil) - goto fail; - path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - NSString *section(Simplify(path)); - UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, section]]); - if (icon == nil) - icon = [UIImage applicationImageNamed:@"unknown.png"]; - [self _returnPNGWithImage:icon forRequest:request]; - } else fail: { - [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]]; - } -} + CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, Locale_, kCFDateFormatterMediumStyle, kCFDateFormatterMediumStyle)); -- (void) stopLoading { -} + for (size_t offset = 0, count = CFArrayGetCount(packages_); offset != count; ++offset) { + Package *package = [self packageAtIndex:offset]; -@end -/* }}} */ + BOOL uae = [package upgradableAndEssential:YES]; -/* Section Controller {{{ */ -@interface SectionController : FilteredPackageController { -} + if (!uae) { + unseens = true; + time_t seen([package seen]); -- (id) initWithDatabase:(Database *)database section:(NSString *)section; + if (section == nil || last != seen) { + last = seen; + + NSString *name; + name = (NSString *) CFDateFormatterCreateStringWithDate(NULL, formatter, (CFDateRef) [NSDate dateWithTimeIntervalSince1970:seen]); + [name autorelease]; + + _profile(ChangesController$reloadData$Allocate) + name = [NSString stringWithFormat:UCLocalize("NEW_AT"), name]; + section = [[[Section alloc] initWithName:name row:offset localize:NO] autorelease]; + [sections_ addObject:section]; + _end + } + + [section addToCount]; + } else if ([package ignored]) { + if (ignored == nil) { + ignored = [[[Section alloc] initWithName:UCLocalize("IGNORED_UPGRADES") row:offset localize:NO] autorelease]; + } + [ignored addToCount]; + } else { + ++upgrades_; + [upgradable addToCount]; + } + } + _trace(); + + CFRelease(formatter); + + if (unseens) { + Section *last = [sections_ lastObject]; + size_t count = [last count]; + CFArrayReplaceValues(packages_, CFRangeMake(CFArrayGetCount(packages_) - count, count), NULL, 0); + [sections_ removeLastObject]; + } + + if ([ignored count] != 0) + [sections_ insertObject:ignored atIndex:0]; + if (upgrades_ != 0) + [sections_ insertObject:upgradable atIndex:0]; + + [list_ reloadData]; + + if (upgrades_ > 0) + [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] + initWithTitle:[NSString stringWithFormat:UCLocalize("PARENTHETICAL"), UCLocalize("UPGRADE"), [NSString stringWithFormat:@"%u", upgrades_]] + style:UIBarButtonItemStylePlain + target:self + action:@selector(upgradeButtonClicked) + ] autorelease]]; + + if (![delegate_ updating]) + [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] + initWithTitle:UCLocalize("REFRESH") + style:UIBarButtonItemStylePlain + target:self + action:@selector(refreshButtonClicked) + ] autorelease]]; + + PrintTimes(); +} } + +@end +/* }}} */ +/* Search Controller {{{ */ +@interface SearchController : FilteredPackageController < + UISearchBarDelegate +> { + UISearchBar *search_; +} + +- (id) initWithDatabase:(Database *)database; +- (void) setSearchTerm:(NSString *)term; +- (void) reloadData; @end -@implementation SectionController +@implementation SearchController - (void) dealloc { + [search_ release]; [super dealloc]; } -- (id) initWithDatabase:(Database *)database section:(NSString *)name { - NSString *title; +- (void) setSearchTerm:(NSString *)searchTerm { + [search_ setText:searchTerm]; +} - 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"); +- (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar { + [packages_ setObject:[search_ text] forFilter:@selector(isUnfilteredAndSearchedForBy:)]; + [search_ resignFirstResponder]; + [self reloadData]; +} + +- (void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)text { + [packages_ setObject:text forFilter:@selector(isUnfilteredAndSelectedForBy:)]; + [self reloadData]; +} + +- (id) initWithDatabase:(Database *)database { + return [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:nil]; +} + +- (void)viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; + if (!search_) { + search_ = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, [[self view] bounds].size.width, 44.0f)]; + [search_ layoutSubviews]; + [search_ setPlaceholder:UCLocalize("SEARCH_EX")]; + + UITextField *textField; + if ([search_ respondsToSelector:@selector(searchField)]) + textField = [search_ searchField]; + else + textField = MSHookIvar(search_, "_searchField"); + + [textField setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin]; + [search_ setDelegate:self]; + [textField setEnablesReturnKeyAutomatically:NO]; + [[self navigationItem] setTitleView:textField]; } +} - if ((self = [super initWithDatabase:database title:title filter:@selector(isVisibleInSection:) with:name]) != nil) { - } return self; +- (void) _reloadData { } - (void) reloadData { - [packages_ reloadData]; + _profile(SearchController$reloadData) + [packages_ reloadData]; + _end + PrintTimes(); + [packages_ resetCursor]; } -- (void) setDelegate:(id)delegate { - [super setDelegate:delegate]; - [packages_ setDelegate:delegate]; +- (void) didSelectPackage:(Package *)package { + [search_ resignFirstResponder]; + [super didSelectPackage:package]; } @end /* }}} */ -/* Sections Controller {{{ */ -@interface SectionsController : CYViewController < +/* Package Settings Controller {{{ */ +@interface PackageSettingsController : CYViewController < UITableViewDataSource, UITableViewDelegate > { _transient Database *database_; - NSMutableArray *sections_; - NSMutableArray *filtered_; - UITableView *list_; - UIView *accessory_; - BOOL editing_; + NSString *name_; + Package *package_; + UITableView *table_; + UISwitch *subscribedSwitch_; + UISwitch *ignoredSwitch_; + UITableViewCell *subscribedCell_; + UITableViewCell *ignoredCell_; } -- (id) initWithDatabase:(Database *)database; -- (void) reloadData; -- (void) resetView; - -- (void) editButtonClicked; +- (id) initWithDatabase:(Database *)database package:(NSString *)package; @end -@implementation SectionsController +@implementation PackageSettingsController - (void) dealloc { - [list_ setDataSource:nil]; - [list_ setDelegate:nil]; + [name_ release]; + if (package_ != nil) + [package_ release]; + [table_ release]; + [subscribedSwitch_ release]; + [ignoredSwitch_ release]; + [subscribedCell_ release]; + [ignoredCell_ release]; - [sections_ release]; - [filtered_ release]; - [list_ release]; - [accessory_ release]; [super dealloc]; } -- (void) setEditing:(BOOL)editing { - if ((editing_ = editing)) - [list_ reloadData]; - else - [delegate_ updateData]; +- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { + if (package_ == nil) + return 0; - [[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]; + return 1; } -- (void) viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; - [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated]; +- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + if (package_ == nil) + return 0; + + return 2; } -- (void) viewWillDisappear:(BOOL)animated { - [super viewWillDisappear:animated]; - if (editing_) [self setEditing:NO]; +- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { + return UCLocalize("CHANGE_PACKAGE_SETTINGS"); } -- (Section *) sectionAtIndexPath:(NSIndexPath *)indexPath { - Section *section = (editing_ ? [sections_ objectAtIndex:[indexPath row]] : ([indexPath row] == 0 ? nil : [filtered_ objectAtIndex:([indexPath row] - 1)])); - return section; +- (NSString *) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { + return UCLocalize("SHOW_ALL_CHANGES_EX"); } -- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return editing_ ? [sections_ count] : [filtered_ count] + 1; +- (void) onSubscribed:(id)control { + bool value([control isOn]); + if (package_ == nil) + return; + if ([package_ setSubscribed:value]) + [delegate_ updateData]; } -/*- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - return 45.0f; -}*/ +- (void) onIgnored:(id)control { + // TODO: set Held state - possibly call out to dpkg, etc. +} - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - static NSString *reuseIdentifier = @"SectionCell"; + if (package_ == nil) + return nil; - SectionCell *cell = (SectionCell *) [tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; - if (cell == nil) - cell = [[[SectionCell alloc] initWithFrame:CGRectZero reuseIdentifier:reuseIdentifier] autorelease]; + switch ([indexPath row]) { + case 0: return subscribedCell_; + case 1: return ignoredCell_; - [cell setSection:[self sectionAtIndexPath:indexPath] editing:editing_]; + _nodefault + } - return cell; + return nil; } -- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - if (editing_) - return; - - Section *section = [self sectionAtIndexPath:indexPath]; - - SectionController *controller = [[[SectionController alloc] - initWithDatabase:database_ - section:[section name] - ] autorelease]; - [controller setDelegate:delegate_]; - - [[self navigationController] pushViewController:controller animated:YES]; -} +- (NSString *) title { return UCLocalize("SETTINGS"); } -- (id) initWithDatabase:(Database *)database { - if ((self = [super init]) != nil) { +- (id) initWithDatabase:(Database *)database package:(NSString *)package { + if ((self = [super init])) { database_ = database; + name_ = [package retain]; - [[self navigationItem] setTitle:UCLocalize("SECTIONS")]; - - sections_ = [[NSMutableArray arrayWithCapacity:16] retain]; - filtered_ = [[NSMutableArray arrayWithCapacity:16] retain]; + [[self navigationItem] setTitle:UCLocalize("SETTINGS")]; - list_ = [[UITableView alloc] initWithFrame:[[self view] bounds]]; - [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [list_ setRowHeight:45.0f]; - [[self view] addSubview:list_]; + table_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped]; + [table_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [[self view] addSubview:table_]; - [list_ setDataSource:self]; - [list_ setDelegate:self]; + subscribedSwitch_ = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 50, 20)]; + [subscribedSwitch_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; + [subscribedSwitch_ addTarget:self action:@selector(onSubscribed:) forEvents:UIControlEventValueChanged]; + + 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")]; + [subscribedCell_ setAccessoryView:subscribedSwitch_]; + [subscribedCell_ setSelectionStyle:UITableViewCellSelectionStyleNone]; + + ignoredCell_ = [[UITableViewCell alloc] init]; + [ignoredCell_ setText:UCLocalize("IGNORE_UPGRADES")]; + [ignoredCell_ setAccessoryView:ignoredSwitch_]; + [ignoredCell_ setSelectionStyle:UITableViewCellSelectionStyleNone]; + // FIXME: Ignored state is not saved. + [ignoredCell_ setUserInteractionEnabled:NO]; + [table_ setDataSource:self]; + [table_ setDelegate:self]; [self reloadData]; } return self; } - (void) reloadData { - NSArray *packages = [database_ packages]; - - [sections_ removeAllObjects]; - [filtered_ removeAllObjects]; - - NSMutableDictionary *sections([NSMutableDictionary dictionaryWithCapacity:32]); - - _trace(); - for (Package *package in packages) { - NSString *name([package section]); - NSString *key(name == nil ? @"" : name); - - Section *section; - - _profile(SectionsView$reloadData$Section) - section = [sections objectForKey:key]; - if (section == nil) { - _profile(SectionsView$reloadData$Section$Allocate) - section = [[[Section alloc] initWithName:name localize:YES] autorelease]; - [sections setObject:section forKey:key]; - _end - } - _end - - [section addToCount]; - - _profile(SectionsView$reloadData$Filter) - if (![package valid] || ![package visible]) - continue; - _end - - [section addToRow]; + if (package_ != nil) + [package_ autorelease]; + package_ = [database_ packageWithName:name_]; + if (package_ != nil) { + [package_ retain]; + [subscribedSwitch_ setOn:([package_ subscribed] ? 1 : 0) animated:NO]; + [ignoredSwitch_ setOn:([package_ ignored] ? 1 : 0) animated:NO]; } - _trace(); - [sections_ addObjectsFromArray:[sections allValues]]; + [table_ reloadData]; +} - [sections_ sortUsingSelector:@selector(compareByLocalized:)]; +@end +/* }}} */ +/* Signature Controller {{{ */ +@interface SignatureController : CYBrowserController { + _transient Database *database_; + NSString *package_; +} - for (Section *section in sections_) { - size_t count([section row]); - if (count == 0) - continue; +- (id) initWithDatabase:(Database *)database package:(NSString *)package; - section = [[[Section alloc] initWithName:[section name] localized:[section localized]] autorelease]; - [section setCount:count]; - [filtered_ addObject:section]; - } +@end - [[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)]; +@implementation SignatureController - [list_ reloadData]; - _trace(); +- (void) dealloc { + [package_ release]; + [super dealloc]; } -- (void) resetView { - if (editing_) - [self editButtonClicked]; +- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { + // XXX: dude! + [super webView:view didClearWindowObject:window forFrame:frame]; } -- (void)editButtonClicked { - [self setEditing:!editing_]; +- (id) initWithDatabase:(Database *)database package:(NSString *)package { + if ((self = [super init]) != nil) { + database_ = database; + package_ = [package retain]; + [self reloadData]; + } return self; } -- (UIView *) accessoryView { - return accessory_; +- (void) reloadData { + [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"signature" ofType:@"html"]]]; } @end /* }}} */ -/* Changes Controller {{{ */ -@interface ChangesController : CYViewController < - UITableViewDataSource, - UITableViewDelegate -> { - _transient Database *database_; - unsigned era_; - CFMutableArrayRef packages_; - NSMutableArray *sections_; - UITableView *list_; - unsigned upgrades_; - BOOL hasSentFirstLoad_; +/* Installed Controller {{{ */ +@interface InstalledController : FilteredPackageController { + BOOL expert_; } -- (id) initWithDatabase:(Database *)database delegate:(id)delegate; -- (void) reloadData; +- (id) initWithDatabase:(Database *)database; + +- (void) updateRoleButton; +- (void) queueStatusDidChange; @end -@implementation ChangesController +@implementation InstalledController - (void) dealloc { - [list_ setDelegate:nil]; - [list_ setDataSource:nil]; - - CFRelease(packages_); - - [sections_ release]; - [list_ release]; [super dealloc]; } -- (void) viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; - if (!hasSentFirstLoad_) { - hasSentFirstLoad_ = YES; - [self performSelector:@selector(reloadData) withObject:nil afterDelay:0.0]; - } else { - [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated]; - } -} +- (NSString *) title { return UCLocalize("INSTALLED"); } -- (NSInteger) numberOfSectionsInTableView:(UITableView *)list { - NSInteger count([sections_ count]); - return count == 0 ? 1 : count; +- (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; } -- (NSString *) tableView:(UITableView *)list titleForHeaderInSection:(NSInteger)section { - if ([sections_ count] == 0) - return nil; - return [[sections_ objectAtIndex:section] name]; +#if !AlwaysReload +- (void) queueButtonClicked { + [delegate_ queue]; } +#endif -- (NSInteger) tableView:(UITableView *)list numberOfRowsInSection:(NSInteger)section { - if ([sections_ count] == 0) - return 0; - return [[sections_ objectAtIndex:section] count]; +- (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 } -- (Package *) packageAtIndex:(NSUInteger)index { - return (Package *) CFArrayGetValueAtIndex(packages_, index); +- (void) reloadData { + [packages_ reloadData]; } -- (Package *) packageAtIndexPath:(NSIndexPath *)path { -@synchronized (database_) { - if ([database_ era] != era_) - return nil; - - NSUInteger sectionIndex([path section]); - if (sectionIndex >= [sections_ count]) - return nil; - Section *section([sections_ objectAtIndex:sectionIndex]); - NSInteger row([path row]); - return [[[self packageAtIndex:([section row] + row)] retain] autorelease]; -} } - -- (UITableViewCell *) tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path { - PackageCell *cell((PackageCell *) [table dequeueReusableCellWithIdentifier:@"Package"]); - if (cell == nil) - cell = [[[PackageCell alloc] init] autorelease]; - [cell setPackage:[self packageAtIndexPath:path]]; - return cell; +- (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]]; } -- (NSIndexPath *) tableView:(UITableView *)table willSelectRowAtIndexPath:(NSIndexPath *)path { - Package *package([self packageAtIndexPath:path]); - CYPackageController *view([[[CYPackageController alloc] initWithDatabase:database_] autorelease]); - [view setDelegate:delegate_]; - [view setPackage:package]; - [[self navigationController] pushViewController:view animated:YES]; - return path; -} +- (void) roleButtonClicked { + [packages_ setObject:[NSNumber numberWithBool:expert_]]; + [packages_ reloadData]; + expert_ = !expert_; -- (void) refreshButtonClicked { - [delegate_ beginUpdate]; - [[self navigationItem] setLeftBarButtonItem:nil animated:YES]; + [self updateRoleButton]; } -- (void) upgradeButtonClicked { - [delegate_ distUpgrade]; +- (void) setDelegate:(id)delegate { + [super setDelegate:delegate]; + [packages_ setDelegate:delegate]; } -- (NSString *) title { return UCLocalize("CHANGES"); } +@end +/* }}} */ -- (id) initWithDatabase:(Database *)database delegate:(id)delegate { - if ((self = [super init]) != nil) { - database_ = database; - [[self navigationItem] setTitle:UCLocalize("CHANGES")]; +/* Source Cell {{{ */ +@interface SourceCell : CYTableViewCell < + ContentDelegate +> { + UIImage *icon_; + NSString *origin_; + NSString *label_; +} - packages_ = CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL); +- (void) setSource:(Source *)source; - sections_ = [[NSMutableArray arrayWithCapacity:16] retain]; +@end - list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain]; - [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [list_ setRowHeight:73]; - [[self view] addSubview:list_]; +@implementation SourceCell - [list_ setDataSource:self]; - [list_ setDelegate:self]; +- (void) clearSource { + [icon_ release]; + [origin_ release]; + [label_ release]; - delegate_ = delegate; - } return self; + icon_ = nil; + origin_ = nil; + label_ = nil; } -- (void) _reloadPackages:(NSArray *)packages { - CFRelease(packages_); - packages_ = CFArrayCreateMutable(kCFAllocatorDefault, [packages count], NULL); +- (void) setSource:(Source *)source { + [self clearSource]; - _trace(); - _profile(ChangesController$_reloadPackages$Filter) - for (Package *package in packages) - if ([package upgradableAndEssential:YES] || [package visible]) - CFArrayAppendValue(packages_, package); - _end - _trace(); - _profile(ChangesController$_reloadPackages$radixSort) - [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackageChangesRadix) withContext:NULL]; - _end - _trace(); + 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) reloadData { -@synchronized (database_) { - era_ = [database_ era]; - NSArray *packages = [database_ packages]; +- (void) dealloc { + [self clearSource]; + [super dealloc]; +} - [sections_ removeAllObjects]; +- (SourceCell *) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier { + if ((self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) != nil) { + UIView *content([self contentView]); + CGRect bounds([content bounds]); -#if 1 - UIProgressHUD *hud([delegate_ addProgressHUD]); - [hud setText:UCLocalize("LOADING")]; - //NSLog(@"HUD:%@::%@", delegate_, hud); - [self yieldToSelector:@selector(_reloadPackages:) withObject:packages]; - [delegate_ removeProgressHUD:hud]; -#else - [self _reloadPackages:packages]; -#endif + content_ = [[ContentView alloc] initWithFrame:bounds]; + [content_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [content_ setBackgroundColor:[UIColor whiteColor]]; + [content addSubview:content_]; - Section *upgradable = [[[Section alloc] initWithName:UCLocalize("AVAILABLE_UPGRADES") localize:NO] autorelease]; - Section *ignored = nil; - Section *section = nil; - time_t last = 0; + [content_ setDelegate:self]; + [content_ setOpaque:YES]; + } return self; +} - upgrades_ = 0; - bool unseens = false; +- (void) drawContentRect:(CGRect)rect { + bool highlighted(highlighted_); + float width(rect.size.width); - CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, Locale_, kCFDateFormatterMediumStyle, kCFDateFormatterMediumStyle)); + if (icon_ != nil) + [icon_ drawInRect:CGRectMake(10, 10, 30, 30)]; - for (size_t offset = 0, count = CFArrayGetCount(packages_); offset != count; ++offset) { - Package *package = [self packageAtIndex:offset]; + if (highlighted) + UISetColor(White_); - BOOL uae = [package upgradableAndEssential:YES]; + if (!highlighted) + UISetColor(Black_); + [origin_ drawAtPoint:CGPointMake(48, 8) forWidth:(width - 80) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation]; - if (!uae) { - unseens = true; - time_t seen([package seen]); + if (!highlighted) + UISetColor(Blue_); + [label_ drawAtPoint:CGPointMake(58, 29) forWidth:(width - 95) withFont:Font12_ lineBreakMode:UILineBreakModeTailTruncation]; +} - if (section == nil || last != seen) { - last = seen; +@end +/* }}} */ +/* Source Table {{{ */ +@interface SourcesController : CYViewController < + UITableViewDataSource, + UITableViewDelegate +> { + _transient Database *database_; + UITableView *list_; + NSMutableArray *sources_; + int offset_; - NSString *name; - name = (NSString *) CFDateFormatterCreateStringWithDate(NULL, formatter, (CFDateRef) [NSDate dateWithTimeIntervalSince1970:seen]); - [name autorelease]; + NSString *href_; + UIProgressHUD *hud_; + NSError *error_; - _profile(ChangesController$reloadData$Allocate) - name = [NSString stringWithFormat:UCLocalize("NEW_AT"), name]; - section = [[[Section alloc] initWithName:name row:offset localize:NO] autorelease]; - [sections_ addObject:section]; - _end - } + //NSURLConnection *installer_; + NSURLConnection *trivial_; + NSURLConnection *trivial_bz2_; + NSURLConnection *trivial_gz_; + //NSURLConnection *automatic_; - [section addToCount]; - } else if ([package ignored]) { - if (ignored == nil) { - ignored = [[[Section alloc] initWithName:UCLocalize("IGNORED_UPGRADES") row:offset localize:NO] autorelease]; - } - [ignored addToCount]; - } else { - ++upgrades_; - [upgradable addToCount]; - } - } - _trace(); + BOOL cydia_; +} - CFRelease(formatter); +- (id) initWithDatabase:(Database *)database; - if (unseens) { - Section *last = [sections_ lastObject]; - size_t count = [last count]; - CFArrayReplaceValues(packages_, CFRangeMake(CFArrayGetCount(packages_) - count, count), NULL, 0); - [sections_ removeLastObject]; +- (void) updateButtonsForEditingStatus:(BOOL)editing animated:(BOOL)animated; + +@end + +@implementation SourcesController + +- (void) _releaseConnection:(NSURLConnection *)connection { + if (connection != nil) { + [connection cancel]; + //[connection setDelegate:nil]; + [connection release]; } +} - if ([ignored count] != 0) - [sections_ insertObject:ignored atIndex:0]; - if (upgrades_ != 0) - [sections_ insertObject:upgradable atIndex:0]; +- (void) dealloc { + if (href_ != nil) + [href_ release]; + if (hud_ != nil) + [hud_ release]; + if (error_ != nil) + [error_ release]; - [list_ reloadData]; + //[self _releaseConnection:installer_]; + [self _releaseConnection:trivial_]; + [self _releaseConnection:trivial_gz_]; + [self _releaseConnection:trivial_bz2_]; + //[self _releaseConnection:automatic_]; - if (upgrades_ > 0) - [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:[NSString stringWithFormat:UCLocalize("PARENTHETICAL"), UCLocalize("UPGRADE"), [NSString stringWithFormat:@"%u", upgrades_]] - style:UIBarButtonItemStylePlain - target:self - action:@selector(upgradeButtonClicked) - ] autorelease]]; + [sources_ release]; + [list_ release]; + [super dealloc]; +} - if (![delegate_ updating]) - [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:UCLocalize("REFRESH") - style:UIBarButtonItemStylePlain - target:self - action:@selector(refreshButtonClicked) - ] autorelease]]; +- (void) viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; + [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated]; +} - PrintTimes(); -} } +- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { + return offset_ == 0 ? 1 : 2; +} -@end -/* }}} */ -/* Search Controller {{{ */ -@interface SearchController : FilteredPackageController < - UISearchBarDelegate -> { - UISearchBar *search_; +- (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 + } } -- (id) initWithDatabase:(Database *)database; -- (void) setSearchTerm:(NSString *)term; -- (void) reloadData; +- (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_; -@end + _nodefault + } +} -@implementation SearchController +- (Source *) sourceAtIndexPath:(NSIndexPath *)indexPath { + unsigned idx = 0; + switch (indexPath.section) { + case 0: idx = indexPath.row; break; + case 1: idx = indexPath.row + offset_; break; -- (void) dealloc { - [search_ release]; - [super dealloc]; + _nodefault + } + return [sources_ objectAtIndex:idx]; } -- (void) setSearchTerm:(NSString *)searchTerm { - [search_ setText:searchTerm]; +- (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; } -- (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar { - [packages_ setObject:[search_ text] forFilter:@selector(isUnfilteredAndSearchedForBy:)]; - [search_ resignFirstResponder]; - [self reloadData]; +- (UITableViewCellAccessoryType) tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath { + return UITableViewCellAccessoryDisclosureIndicator; } -- (void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)text { - [packages_ setObject:text forFilter:@selector(isUnfilteredAndSelectedForBy:)]; - [self reloadData]; +- (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]; } -- (id) initWithDatabase:(Database *)database { - return [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:nil]; +- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { + Source *source = [self sourceAtIndexPath:indexPath]; + return [source record] != nil; } -- (void)viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; - if (!search_) { - search_ = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, [[self view] bounds].size.width, 44.0f)]; - [search_ layoutSubviews]; - [search_ setPlaceholder:UCLocalize("SEARCH_EX")]; +- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { + Source *source = [self sourceAtIndexPath:indexPath]; + [Sources_ removeObjectForKey:[source key]]; + [delegate_ syncData]; +} - UITextField *textField; - if ([search_ respondsToSelector:@selector(searchField)]) - textField = [search_ searchField]; - else - textField = MSHookIvar(search_, "_searchField"); +- (void) complete { + [Sources_ setObject:[NSDictionary dictionaryWithObjectsAndKeys: + @"deb", @"Type", + href_, @"URI", + @"./", @"Distribution", + nil] forKey:[NSString stringWithFormat:@"deb:%@:./", href_]]; - [textField setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin]; - [search_ setDelegate:self]; - [textField setEnablesReturnKeyAutomatically:NO]; - [[self navigationItem] setTitleView:textField]; - } + [delegate_ syncData]; } -- (void) _reloadData { +- (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) reloadData { - _profile(SearchController$reloadData) - [packages_ reloadData]; - _end - PrintTimes(); - [packages_ resetCursor]; +- (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) didSelectPackage:(Package *)package { - [search_ resignFirstResponder]; - [super didSelectPackage:package]; +- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response { + switch ([response statusCode]) { + case 200: + cydia_ = YES; + } } -@end -/* }}} */ -/* Settings Controller {{{ */ -@interface PackageSettingsController : CYViewController < - UITableViewDataSource, - UITableViewDelegate -> { - _transient Database *database_; - NSString *name_; - Package *package_; - UITableView *table_; - UISwitch *subscribedSwitch_; - UISwitch *ignoredSwitch_; - UITableViewCell *subscribedCell_; - UITableViewCell *ignoredCell_; +- (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]; } -- (id) initWithDatabase:(Database *)database package:(NSString *)package; - -@end +- (void) connectionDidFinishLoading:(NSURLConnection *)connection { + [self _endConnection:connection]; +} -@implementation PackageSettingsController +- (NSString *) title { return UCLocalize("SOURCES"); } -- (void) dealloc { - [name_ release]; - if (package_ != nil) - [package_ release]; - [table_ release]; - [subscribedSwitch_ release]; - [ignoredSwitch_ release]; - [subscribedCell_ release]; - [ignoredCell_ release]; +- (NSURLConnection *) _requestHRef:(NSString *)href method:(NSString *)method { + NSMutableURLRequest *request = [NSMutableURLRequest + requestWithURL:[NSURL URLWithString:href] + cachePolicy:NSURLRequestUseProtocolCachePolicy + timeoutInterval:120.0 + ]; - [super dealloc]; -} + [request setHTTPMethod:method]; -- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { - if (package_ == nil) - return 0; + 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 1; + return [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease]; } -- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - if (package_ == nil) - return 0; +- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button { + NSString *context([alert context]); - return 2; -} + if ([context isEqualToString:@"source"]) { + switch (button) { + case 1: { + NSString *href = [[alert textField] text]; -- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { - return UCLocalize("CHANGE_PACKAGE_SETTINGS"); -} + //installer_ = [[self _requestHRef:href method:@"GET"] retain]; -- (NSString *) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { - return UCLocalize("SHOW_ALL_CHANGES_EX"); -} + if (![href hasSuffix:@"/"]) + href_ = [href stringByAppendingString:@"/"]; + else + href_ = href; + href_ = [href_ retain]; -- (void) onSubscribed:(id)control { - bool value([control isOn]); - if (package_ == nil) - return; - if ([package_ setSubscribed:value]) - [delegate_ updateData]; -} + 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]; -- (void) onIgnored:(id)control { - // TODO: set Held state - possibly call out to dpkg, etc. -} + cydia_ = false; -- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - if (package_ == nil) - return nil; + // XXX: this is stupid + hud_ = [[delegate_ addProgressHUD] retain]; + [hud_ setText:UCLocalize("VERIFYING_URL")]; + } break; - switch ([indexPath row]) { - case 0: return subscribedCell_; - case 1: return ignoredCell_; + case 0: + break; - _nodefault - } + _nodefault + } - return nil; -} + [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; -- (NSString *) title { return UCLocalize("SETTINGS"); } + case 0: + break; -- (id) initWithDatabase:(Database *)database package:(NSString *)package { - if ((self = [super init])) { - database_ = database; - name_ = [package retain]; + _nodefault + } - [[self navigationItem] setTitle:UCLocalize("SETTINGS")]; + [href_ release]; + href_ = nil; - table_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped]; - [table_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [[self view] addSubview:table_]; + [alert dismissWithClickedButtonIndex:-1 animated:YES]; + } +} - subscribedSwitch_ = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 50, 20)]; - [subscribedSwitch_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; - [subscribedSwitch_ addTarget:self action:@selector(onSubscribed:) forEvents:UIControlEventValueChanged]; +- (id) initWithDatabase:(Database *)database { + if ((self = [super init]) != nil) { + [[self navigationItem] setTitle:UCLocalize("SOURCES")]; + [self updateButtonsForEditingStatus:NO animated:NO]; - 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]; + database_ = database; + sources_ = [[NSMutableArray arrayWithCapacity:16] retain]; - subscribedCell_ = [[UITableViewCell alloc] init]; - [subscribedCell_ setText:UCLocalize("SHOW_ALL_CHANGES")]; - [subscribedCell_ setAccessoryView:subscribedSwitch_]; - [subscribedCell_ setSelectionStyle:UITableViewCellSelectionStyleNone]; + list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain]; + [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [list_ setRowHeight:56]; + [[self view] addSubview:list_]; - ignoredCell_ = [[UITableViewCell alloc] init]; - [ignoredCell_ setText:UCLocalize("IGNORE_UPGRADES")]; - [ignoredCell_ setAccessoryView:ignoredSwitch_]; - [ignoredCell_ setSelectionStyle:UITableViewCellSelectionStyleNone]; - // FIXME: Ignored state is not saved. - [ignoredCell_ setUserInteractionEnabled:NO]; + [list_ setDataSource:self]; + [list_ setDelegate:self]; - [table_ setDataSource:self]; - [table_ setDelegate:self]; [self reloadData]; } return self; } - (void) reloadData { - if (package_ != nil) - [package_ autorelease]; - package_ = [database_ packageWithName:name_]; - if (package_ != nil) { - [package_ retain]; - [subscribedSwitch_ setOn:([package_ subscribed] ? 1 : 0) animated:NO]; - [ignoredSwitch_ setOn:([package_ ignored] ? 1 : 0) animated:NO]; + 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_++; } - [table_ reloadData]; + [list_ setEditing:NO]; + [self updateButtonsForEditingStatus:NO animated:NO]; + [list_ reloadData]; } -@end -/* }}} */ -/* Signature Controller {{{ */ -@interface SignatureController : CYBrowserController { - _transient Database *database_; - NSString *package_; -} +- (void) showAddSourcePrompt { + UIAlertView *alert = [[[UIAlertView alloc] + initWithTitle:UCLocalize("ENTER_APT_URL") + message:nil + delegate:self + cancelButtonTitle:UCLocalize("CANCEL") + otherButtonTitles:UCLocalize("ADD_SOURCE"), nil + ] autorelease]; -- (id) initWithDatabase:(Database *)database package:(NSString *)package; + [alert setContext:@"source"]; + [alert setTransform:CGAffineTransformTranslate([alert transform], 0.0, 100.0)]; -@end + [alert setNumberOfRows:1]; + [alert addTextFieldWithValue:@"http://" label:@""]; -@implementation SignatureController + UITextInputTraits *traits = [[alert textField] textInputTraits]; + [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone]; + [traits setAutocorrectionType:UITextAutocorrectionTypeNo]; + [traits setKeyboardType:UIKeyboardTypeURL]; + // XXX: UIReturnKeyDone + [traits setReturnKeyType:UIReturnKeyNext]; -- (void) dealloc { - [package_ release]; - [super dealloc]; + [alert show]; } -- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { - // XXX: dude! - [super webView:view didClearWindowObject:window forFrame:frame]; +- (void) addButtonClicked { + [self showAddSourcePrompt]; } -- (id) initWithDatabase:(Database *)database package:(NSString *)package { - if ((self = [super init]) != nil) { - database_ = database; - package_ = [package retain]; - [self reloadData]; - } return self; +- (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) reloadData { - [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"signature" ofType:@"html"]]]; +- (void) settingsButtonClicked { + [delegate_ showSettings]; +} + +- (void) editButtonClicked { + [list_ setEditing:![list_ isEditing] animated:YES]; + + [self updateButtonsForEditingStatus:[list_ isEditing] animated:YES]; } @end /* }}} */ -/* Role Controller {{{ */ -@interface CYSettingsController : CYViewController < +/* Settings Controller {{{ */ +@interface SettingsController : CYViewController < UITableViewDataSource, UITableViewDelegate > { @@ -8015,7 +7974,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end -@implementation CYSettingsController +@implementation SettingsController - (void) dealloc { [table_ release]; [segment_ release]; @@ -8175,7 +8134,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Stash Controller {{{ */ -@interface CYStashController : CYViewController { +@interface StashController : CYViewController { // XXX: just delete these things _transient UIActivityIndicatorView *spinner_; _transient UILabel *status_; @@ -8183,7 +8142,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } @end -@implementation CYStashController +@implementation StashController - (id) init { if ((self = [super init])) { [[self view] setBackgroundColor:[UIColor viewFlipsideBackgroundColor]]; @@ -8257,7 +8216,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { unsigned locked_; unsigned activity_; - CYStashController *stash_; + StashController *stash_; bool loaded_; } @@ -8650,7 +8609,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (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]; @@ -8947,7 +8906,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) addStashController { ++locked_; - stash_ = [[CYStashController alloc] init]; + stash_ = [[StashController alloc] init]; [window_ addSubview:[stash_ view]]; } -- cgit v1.2.3 From 0be165c8572ed2963e0503c174f0c0b67ec521c0 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Sat, 22 Jan 2011 16:57:18 -0800 Subject: Fix changes badge on first refresh. --- MobileCydia.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index e548e9b..9bcfd68 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -9029,6 +9029,7 @@ _trace(); database_ = [Database sharedInstance]; [window_ setUserInteractionEnabled:NO]; + [self setupViewControllers]; [self showEmulatedLoadingControllerInView:window_]; [self performSelector:@selector(loadData) withObject:nil afterDelay:0]; @@ -9045,7 +9046,6 @@ _trace(); [self reloadData]; PrintTimes(); - [self setupViewControllers]; [self showEmulatedLoadingControllerInView:nil]; [window_ setUserInteractionEnabled:YES]; -- cgit v1.2.3 From 8bacb67f37c8d04eb614fd1bb401bd489cb8253f Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Sat, 22 Jan 2011 22:05:04 -0800 Subject: Fix -setPage: to not pop all the other tabs to the root controller. --- MobileCydia.mm | 3 --- 1 file changed, 3 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 9bcfd68..dd2a6ff 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -8568,9 +8568,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { CYNavigationController *navController = (CYNavigationController *) [tabbar_ selectedViewController]; [navController setViewControllers:[NSArray arrayWithObject:page]]; - for (CYNavigationController *page in [tabbar_ viewControllers]) - if (page != navController) - [page setViewControllers:nil]; } - (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { -- cgit v1.2.3 From c713af59c5ade19907804670a8c98381124aca6d Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Sat, 22 Jan 2011 22:35:52 -0800 Subject: Finish cydia:// URLs using the private "transient view controller" methods on UITabBarController. This allows for no tab to appear selected when on a page using a cydia:// URL. --- MobileCydia.mm | 17 +++++++---------- iPhonePrivate.h | 3 +++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index dd2a6ff..7a7a6a7 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -6226,6 +6226,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { CYNavigationController *page([[self viewControllers] objectAtIndex:(count - i - 1)]); [page reloadData]; } + + [(CYNavigationController *) [self transientViewController] reloadData]; } - (id) initWithDatabase:(Database *)database { @@ -8221,7 +8223,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { bool loaded_; } -- (void) setPage:(CYViewController *)page; - (void) loadData; @end @@ -8563,13 +8564,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [self complete]; } -- (void) setPage:(CYViewController *)page { - [page setDelegate:self]; - - CYNavigationController *navController = (CYNavigationController *) [tabbar_ selectedViewController]; - [navController setViewControllers:[NSArray arrayWithObject:page]]; -} - - (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { CYNavigationController *controller = (CYNavigationController *) viewController; @@ -8879,8 +8873,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (BOOL) openCydiaURL:(NSURL *)url { CYViewController *page([self pageForURL:url]); - if (page != nil) - [self setPage:page]; + if (page != nil) { + CYNavigationController *nav = [[[CYNavigationController alloc] init] autorelease]; + [nav setViewControllers:[NSArray arrayWithObject:page]]; + [tabbar_ setTransientViewController:nav]; + } return page != nil; } diff --git a/iPhonePrivate.h b/iPhonePrivate.h index 149fdc8..818dae3 100644 --- a/iPhonePrivate.h +++ b/iPhonePrivate.h @@ -237,6 +237,9 @@ typedef enum { @interface UITabBarController (Apple) - (UITransitionView *) _transitionView; +- (UIViewController *) transientViewController; +- (void) setTransientViewController:(UIViewController *)controller; +- (void) setTransientViewController:(UIViewController *)controller animated:(BOOL)animated; @end @interface UITabBarItem (Apple) -- cgit v1.2.3 From f5a1751757734cc1e62f5182cea0edc08c32f956 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Sun, 23 Jan 2011 12:38:17 -0800 Subject: Controllers need their delegete set when launched from URLs. Also, use cydia://home when creating the home page, to avoid a *third* duplication of that code. (Setting the selected index to zero is not possible due to UITabBarController changes between 2.x and 3.x+ that make behavior uncertain in that case with regard to calling delegate methods.) --- MobileCydia.mm | 64 +++++++++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 7a7a6a7..5600c6c 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -8763,7 +8763,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { NSString *path([[url absoluteString] substringFromIndex:[scheme length] + 3]); NSArray *components([path pathComponents]); - if ([scheme isEqualToString:@"apptapp"] && [components count] && [[components objectAtIndex:0] isEqualToString:@"package"]) + 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"]) @@ -8771,82 +8771,72 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { NSString *base([components objectAtIndex:0]); + CYViewController *controller = nil; + if ([components count] == 1) { if ([base isEqualToString:@"storage"]) { - CYBrowserController *browser = [[[CYBrowserController alloc] init] autorelease]; - [browser loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"storage" ofType:@"html"]]]; - return browser; + controller = [[[CYBrowserController alloc] init] autorelease]; + [(CYBrowserController *)controller loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"storage" ofType:@"html"]]]; } if ([base isEqualToString:@"sources"]) { - SourcesController *source = [[[SourcesController alloc] initWithDatabase:database_] autorelease]; - return source; + controller = [[[SourcesController alloc] initWithDatabase:database_] autorelease]; } if ([base isEqualToString:@"home"]) { - HomeController *home = [[[HomeController alloc] init] autorelease]; - return home; + controller = [[[HomeController alloc] init] autorelease]; } if ([base isEqualToString:@"sections"]) { - SectionsController *sections = [[[SectionsController alloc] initWithDatabase:database_] autorelease]; - return sections; + controller = [[[SectionsController alloc] initWithDatabase:database_] autorelease]; } if ([base isEqualToString:@"search"]) { - SearchController *search = [[[SearchController alloc] initWithDatabase:database_] autorelease]; - return search; + controller = [[[SearchController alloc] initWithDatabase:database_] autorelease]; } if ([base isEqualToString:@"changes"]) { - ChangesController *changes = [[[ChangesController alloc] initWithDatabase:database_ delegate:self] autorelease]; - return changes; + controller = [[[ChangesController alloc] initWithDatabase:database_ delegate:self] autorelease]; } if ([base isEqualToString:@"installed"]) { - InstalledController *installed = [[[InstalledController alloc] initWithDatabase:database_] autorelease]; - return installed; + controller = [[[InstalledController alloc] initWithDatabase:database_] autorelease]; } } else if ([components count] == 2) { NSString *argument = [components objectAtIndex:1]; if ([base isEqualToString:@"package"]) { - CYViewController *package = [self pageForPackage:argument]; - return package; + controller = [self pageForPackage:argument]; } if ([base isEqualToString:@"search"]) { - SearchController *search = [[[SearchController alloc] initWithDatabase:database_] autorelease]; - [search setSearchTerm:argument]; - return search; + controller = [[[SearchController alloc] initWithDatabase:database_] autorelease]; + [(SearchController *)controller setSearchTerm:argument]; } if ([base isEqualToString:@"sections"]) { if ([argument isEqualToString:@"all"]) argument = nil; - SectionController *section = [[[SectionController alloc] initWithDatabase:database_ section:argument] autorelease]; - [section setDelegate:self]; - return section; + controller = [[[SectionController alloc] initWithDatabase:database_ section:argument] autorelease]; } if ([base isEqualToString:@"sources"]) { if ([argument isEqualToString:@"add"]) { - SourcesController *source = [[[SourcesController alloc] initWithDatabase:database_] autorelease]; - [source showAddSourcePrompt]; - return source; + controller = [[[SourcesController alloc] initWithDatabase:database_] autorelease]; + [(SourcesController *)controller showAddSourcePrompt]; } else { // XXX: Create page of the source specfified. } } if ([base isEqualToString:@"url"]) { - CYBrowserController *browser = [[[CYBrowserController alloc] init] autorelease]; - [browser loadURL:[NSURL URLWithString:argument]]; - return browser; + controller = [[[CYBrowserController alloc] init] autorelease]; + [(CYBrowserController *)controller loadURL:[NSURL URLWithString:argument]]; } if ([base isEqualToString:@"launch"]) { [self launchApplicationWithIdentifier:argument suspended:NO]; + return nil; } } else if ([components count] == 3) { NSString *arg1 = [components objectAtIndex:1]; @@ -8854,20 +8844,20 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if ([base isEqualToString:@"package"]) { if ([arg2 isEqualToString:@"settings"]) { - return [[[PackageSettingsController alloc] initWithDatabase:database_ package:arg1] autorelease]; + controller = [[[PackageSettingsController alloc] initWithDatabase:database_ package:arg1] autorelease]; } else if ([arg2 isEqualToString:@"signature"]) { - return [[[SignatureController alloc] initWithDatabase:database_ package:arg1] autorelease]; + controller = [[[SignatureController alloc] initWithDatabase:database_ package:arg1] autorelease]; } else if ([arg2 isEqualToString:@"files"]) { if (Package *package = [database_ packageWithName:arg1]) { - FileTable *files = [[[FileTable alloc] initWithDatabase:database_] autorelease]; - [files setPackage:package]; - return files; + controller = [[[FileTable alloc] initWithDatabase:database_] autorelease]; + [(FileTable *)controller setPackage:package]; } } } } - return nil; + [controller setDelegate:self]; + return controller; } - (BOOL) openCydiaURL:(NSURL *)url { @@ -9045,7 +9035,7 @@ _trace(); // Show the home page. CYNavigationController *navigation = [[tabbar_ viewControllers] objectAtIndex:0]; - [navigation setViewControllers:[NSArray arrayWithObject:[[[HomeController alloc] init] autorelease]]]; + [navigation setViewControllers:[NSArray arrayWithObject:[self pageForURL:[NSURL URLWithString:@"cydia://home"]]]]; // (Try to) show the startup URL. if (starturl_ != nil) { -- cgit v1.2.3 From ea3bb538405a55030753b8345bdf230896ffaed9 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Wed, 26 Jan 2011 18:44:41 -0800 Subject: Make ChangesController more like any other controller, i.e., use -initWithDatabase: and -setDelegate: instead of the unique -initWithDatabase:delegate:. --- MobileCydia.mm | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 5600c6c..e3c9d9c 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -6864,8 +6864,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { BOOL hasSentFirstLoad_; } -- (id) initWithDatabase:(Database *)database delegate:(id)delegate; -- (void) reloadData; +- (id) initWithDatabase:(Database *)database; @end @@ -6954,13 +6953,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (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]; @@ -6970,8 +6968,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [list_ setDataSource:self]; [list_ setDelegate:self]; - - delegate_ = delegate; } return self; } @@ -8576,7 +8572,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { else if (index == 1) root = [[[SectionsController alloc] initWithDatabase:database_] autorelease]; else if (index == 2) - root = [[[ChangesController alloc] initWithDatabase:database_ delegate:self] autorelease]; + root = [[[ChangesController alloc] initWithDatabase:database_] autorelease]; if (IsWildcat_) { if (index == 3) @@ -8796,7 +8792,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } if ([base isEqualToString:@"changes"]) { - controller = [[[ChangesController alloc] initWithDatabase:database_ delegate:self] autorelease]; + controller = [[[ChangesController alloc] initWithDatabase:database_] autorelease]; } if ([base isEqualToString:@"installed"]) { -- cgit v1.2.3 From b89fa270de1a17bf2505ed8bca773c52537a8061 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Wed, 26 Jan 2011 19:13:30 -0800 Subject: Fix a runtime syslog warning from UIKit by using the -tableView:accessoryTypeForRowWithIndexPath: in SourceController. --- MobileCydia.mm | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index e3c9d9c..2079a6a 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -7604,14 +7604,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { 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]; -- cgit v1.2.3 From 5e565049e26ac6541df632c31981bacde7bf980c Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Thu, 27 Jan 2011 17:44:39 -0800 Subject: Sanity in rotation handling: centralize in CYViewController, as it should be. --- MobileCydia.mm | 24 +----------------------- UICaboodle/RVPage.mm | 6 +----- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 2079a6a..4421211 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -4030,7 +4030,7 @@ static NSString *Warning_; @end /* }}} */ /* Emulated Loading Controller {{{ */ -@interface CYEmulatedLoadingController : UIViewController { +@interface CYEmulatedLoadingController : CYViewController { CYLoadingIndicator *indicator_; UITabBar *tabbar_; UINavigationBar *navbar_; @@ -4062,10 +4062,6 @@ static NSString *Warning_; } return self; } -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { - return (IsWildcat_ || orientation == UIInterfaceOrientationPortrait); -} - @end /* }}} */ @@ -6241,10 +6237,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } return self; } -- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { - return IsWildcat_ || orientation == UIInterfaceOrientationPortrait; -} - - (void) setUpdate:(NSDate *)date { [self beginUpdate]; } @@ -6480,17 +6472,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @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]; } @@ -8183,9 +8164,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } return self; } -- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { - return IsWildcat_ || orientation == UIInterfaceOrientationPortrait; -} @end /* }}} */ diff --git a/UICaboodle/RVPage.mm b/UICaboodle/RVPage.mm index 4a8ea5d..a28e37c 100644 --- a/UICaboodle/RVPage.mm +++ b/UICaboodle/RVPage.mm @@ -12,10 +12,6 @@ - (void) reloadData { } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { - if ([self parentViewController]) { - return [[self parentViewController] shouldAutorotateToInterfaceOrientation:orientation]; - } else { - return [super shouldAutorotateToInterfaceOrientation:orientation]; - } + return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad || orientation == UIInterfaceOrientationPortrait); } @end -- cgit v1.2.3 From 27afbbfcd7a2ba506ea0f95c562dea58904680b6 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Thu, 27 Jan 2011 18:00:55 -0800 Subject: Small formatting fixes. --- UICaboodle/RVPage.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UICaboodle/RVPage.mm b/UICaboodle/RVPage.mm index a28e37c..81c8739 100644 --- a/UICaboodle/RVPage.mm +++ b/UICaboodle/RVPage.mm @@ -6,12 +6,12 @@ #import "RVBook.h" @implementation CYViewController -- (void)setDelegate:(id)delegate { +- (void) setDelegate:(id)delegate { delegate_ = delegate; } - (void) reloadData { } -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { +- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad || orientation == UIInterfaceOrientationPortrait); } @end -- cgit v1.2.3 From 293c95d6e064c4ac092f5510e6015e637add11ae Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Thu, 27 Jan 2011 18:01:03 -0800 Subject: Fix loading screen rotation. --- MobileCydia.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 4421211..849d3db 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -8918,7 +8918,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [tabbar_ setViewControllers:controllers]; [tabbar_ setUpdateDelegate:self]; - [window_ addSubview:[tabbar_ view]]; } - (void)showEmulatedLoadingControllerInView:(UIView *)view { @@ -9001,6 +9000,7 @@ _trace(); [self reloadData]; PrintTimes(); + [window_ addSubview:[tabbar_ view]]; [self showEmulatedLoadingControllerInView:nil]; [window_ setUserInteractionEnabled:YES]; -- cgit v1.2.3 From a23207d2b4e9986a5f0ef23dafb9ef31cd080319 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Sat, 29 Jan 2011 16:28:11 -0800 Subject: Fix refreshing bar on iOS 3.0+ by using the CoreFoundation version to check versioning at runtime. --- MobileCydia.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 849d3db..0076c42 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -6370,7 +6370,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { 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; -- cgit v1.2.3 From 20fd0049ccbe0fba9fee79b4a546bd71ffb55107 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Sat, 29 Jan 2011 17:32:01 -0800 Subject: Update section mapping to correctly redirect Themes (Video). --- MobileCydia.app/Sections.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MobileCydia.app/Sections.plist b/MobileCydia.app/Sections.plist index fb8f880..b160632 100644 --- a/MobileCydia.app/Sections.plist +++ b/MobileCydia.app/Sections.plist @@ -40,7 +40,7 @@ Themes (LockScreen) Themes (Video) - Themes (Videos) + Themes (Apps) Utilites Utilities -- cgit v1.2.3 From f70ea8991859d6fe70cc14696fa5e0dfc512ed66 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Sun, 30 Jan 2011 23:31:59 -0800 Subject: Fix cydia://url/ links when they include a slash. --- MobileCydia.mm | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 0076c42..1596c38 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -8744,7 +8744,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { CYViewController *controller = nil; - if ([components count] == 1) { + if ([base isEqualToString:@"url"]) { + controller = [[[CYBrowserController alloc] init] autorelease]; + NSArray *arguments([components subarrayWithRange:NSMakeRange(1, [components count] - 1)]); + [(CYBrowserController *)controller loadURL:[NSURL URLWithString:[arguments componentsJoinedByString:@""]]]; + } else if ([components count] == 1) { if ([base isEqualToString:@"storage"]) { controller = [[[CYBrowserController alloc] init] autorelease]; [(CYBrowserController *)controller loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"storage" ofType:@"html"]]]; @@ -8800,11 +8804,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } } - if ([base isEqualToString:@"url"]) { - controller = [[[CYBrowserController alloc] init] autorelease]; - [(CYBrowserController *)controller loadURL:[NSURL URLWithString:argument]]; - } - if ([base isEqualToString:@"launch"]) { [self launchApplicationWithIdentifier:argument suspended:NO]; return nil; -- cgit v1.2.3 From 106d645f5846b972245285e9d075b11be88f8de8 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Sun, 30 Jan 2011 23:42:16 -0800 Subject: Fix stupidness introduced by last commit; correctly fix cydia://url/* URLs. --- MobileCydia.mm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 1596c38..2e7abad 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -8745,9 +8745,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { 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]; - NSArray *arguments([components subarrayWithRange:NSMakeRange(1, [components count] - 1)]); - [(CYBrowserController *)controller loadURL:[NSURL URLWithString:[arguments componentsJoinedByString:@""]]]; + [(CYBrowserController *)controller loadURL:[NSURL URLWithString:destination]]; } else if ([components count] == 1) { if ([base isEqualToString:@"storage"]) { controller = [[[CYBrowserController alloc] init] autorelease]; -- cgit v1.2.3 From d544eabd7ecfac01ec20121d868c78360b3d2dc3 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Tue, 1 Feb 2011 09:54:00 -0800 Subject: Removed unused "accessory_" ivar of SectionsController. --- MobileCydia.mm | 6 ------ 1 file changed, 6 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 2e7abad..023284a 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -6647,7 +6647,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { NSMutableArray *sections_; NSMutableArray *filtered_; UITableView *list_; - UIView *accessory_; BOOL editing_; } @@ -6668,7 +6667,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [sections_ release]; [filtered_ release]; [list_ release]; - [accessory_ release]; [super dealloc]; } @@ -6824,10 +6822,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [self setEditing:!editing_]; } -- (UIView *) accessoryView { - return accessory_; -} - @end /* }}} */ -- cgit v1.2.3 From a784d0a4a6a8457296ba2c6128e9da29cdd1fcfd Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Tue, 1 Feb 2011 11:00:09 -0800 Subject: Refactor edit button in SectionsController; use system provided UIBarButtonItems. --- MobileCydia.mm | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 023284a..392c173 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -6670,15 +6670,26 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [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 { @@ -6802,13 +6813,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [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(); } -- cgit v1.2.3 From dbf1327cec2722cfbc5895f3092c92fc933b29c0 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Tue, 1 Feb 2011 14:49:39 -0800 Subject: Formatting changes. --- MobileCydia.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 392c173..42d9dc3 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -6223,7 +6223,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [page reloadData]; } - [(CYNavigationController *) [self transientViewController] reloadData]; + [(CYNavigationController *)[self transientViewController] reloadData]; } - (id) initWithDatabase:(Database *)database { @@ -8538,7 +8538,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { CYNavigationController *controller = (CYNavigationController *) viewController; if ([[controller viewControllers] count] == 0) { - int index = [tabbar_ selectedIndex]; + int index = [[tabbar_ viewControllers] indexOfObjectIdenticalTo:controller]; CYViewController *root = nil; if (index == 0) -- cgit v1.2.3 From 3f8edf70826f85ab3f0c5b47c4ab2a586068b43a Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Tue, 1 Feb 2011 17:57:30 -0800 Subject: Refactor out SourceController; add cydia://source/ to open it from outside the app. --- MobileCydia.mm | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 42d9dc3..0c9634b 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -6608,10 +6608,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @implementation SectionController -- (void) dealloc { - [super dealloc]; -} - - (id) initWithDatabase:(Database *)database section:(NSString *)name { NSString *title; @@ -6627,15 +6623,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } return self; } -- (void) reloadData { - [packages_ reloadData]; -} - -- (void) setDelegate:(id)delegate { - [super setDelegate:delegate]; - [packages_ setDelegate:delegate]; -} - @end /* }}} */ /* Sections Controller {{{ */ @@ -7481,7 +7468,24 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ -/* Source Table {{{ */ +/* 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 @@ -7592,16 +7596,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (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 { @@ -8800,7 +8802,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { controller = [[[SourcesController alloc] initWithDatabase:database_] autorelease]; [(SourcesController *)controller showAddSourcePrompt]; } else { - // XXX: Create page of the source specfified. + NSArray *sources = [database_ sources]; + for (Source *source in sources) { + if ([[source name] caseInsensitiveCompare:argument] == NSOrderedSame) { + controller = [[[SourceController alloc] initWithDatabase:database_ source:source] autorelease]; + break; + } + } } } -- cgit v1.2.3 From 0c1cb67a559b2077dddedf7eab3251a3e4cc0812 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Wed, 2 Feb 2011 00:30:38 -0800 Subject: Workaround to fix the Settings Controller popup on initial launch. --- MobileCydia.mm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 0c9634b..5a5afed 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -8927,13 +8927,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [tabbar_ setUpdateDelegate:self]; } -- (void)showEmulatedLoadingControllerInView:(UIView *)view { +- (CYEmulatedLoadingController *)showEmulatedLoadingControllerInView:(UIView *)view { static CYEmulatedLoadingController *fake = [[CYEmulatedLoadingController alloc] init]; if (view != nil) { [view addSubview:[fake view]]; } else { [[fake view] removeFromSuperview]; } + + return fake; } - (void) applicationDidFinishLaunching:(id)unused { @@ -9000,8 +9002,19 @@ _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]; } [self reloadData]; -- cgit v1.2.3 From 79b42fd1b46eab09474ab4530e6959a52676b079 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Thu, 3 Feb 2011 15:40:19 -0800 Subject: Fix VoiceOver (at least on 4.x). Does not cause issues on other firmwares, since if the fix does not work it will just bail out (checks all methods, etc). --- MobileCydia.mm | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/MobileCydia.mm b/MobileCydia.mm index 5a5afed..ee88c00 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -9089,6 +9089,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(); @@ -9116,6 +9143,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(); -- cgit v1.2.3 From 003fc610c40f29f5e9195a890b198e48aad14c49 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Thu, 3 Feb 2011 15:59:51 -0800 Subject: Make PackageCell, SourceCell, and SectionCell have reasonable VoiceOver labels. --- MobileCydia.mm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/MobileCydia.mm b/MobileCydia.mm index ee88c00..cc00590 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -4993,6 +4993,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]; @@ -5221,6 +5225,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_); @@ -7447,6 +7455,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } return self; } +- (NSString *) accessibilityLabel { + return label_; +} + - (void) drawContentRect:(CGRect)rect { bool highlighted(highlighted_); float width(rect.size.width); -- cgit v1.2.3 From afcc9400f543602df4f2e25f7ffc94ea1637836e Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Sat, 5 Feb 2011 00:39:15 -0800 Subject: Avoid flashing empty package view as it loads the package details. --- MobileCydia.app/package.html | 6 +++++- MobileCydia.app/package.js | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/MobileCydia.app/package.html b/MobileCydia.app/package.html index c91b52c..985b207 100644 --- a/MobileCydia.app/package.html +++ b/MobileCydia.app/package.html @@ -196,8 +196,12 @@ height: 1px; width: 320px; } + + .invisible * { + visibility: hidden; + } - +