- 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;
-}
-
-- (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) refreshButtonClicked {
- [delegate_ beginUpdate];
- [[self navigationItem] setLeftBarButtonItem:nil animated:YES];
-}
-
-- (void) upgradeButtonClicked {
- [delegate_ distUpgrade];
-}
-
-- (NSString *) title { return UCLocalize("CHANGES"); }
-
-- (id) initWithDatabase:(Database *)database delegate:(id)delegate {
- if ((self = [super init]) != nil) {
- database_ = database;
- [[self navigationItem] setTitle:UCLocalize("CHANGES")];
-
- packages_ = CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL);
-
- sections_ = [[NSMutableArray arrayWithCapacity:16] retain];
-
- list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain];
- [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
- [list_ setRowHeight:73];
- [[self view] addSubview:list_];
-
- [list_ setDataSource:self];
- [list_ setDelegate:self];
-
- delegate_ = delegate;
- } return self;
-}
-
-- (void) _reloadPackages:(NSArray *)packages {
- CFRelease(packages_);
- packages_ = CFArrayCreateMutable(kCFAllocatorDefault, [packages count], NULL);
-
- _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<SKRadixFunction>(&PackageChangesRadix) withContext:NULL];
- _end
- _trace();
-}
-
-- (void) reloadData {
-@synchronized (database_) {
- era_ = [database_ era];
- NSArray *packages = [database_ packages];
-
- [sections_ removeAllObjects];
-
-#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
-
- Section *upgradable = [[[Section alloc] initWithName:UCLocalize("AVAILABLE_UPGRADES") localize:NO] autorelease];
- Section *ignored = nil;
- Section *section = nil;
- time_t last = 0;
-
- upgrades_ = 0;
- bool unseens = false;
-
- CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, Locale_, kCFDateFormatterMediumStyle, kCFDateFormatterMediumStyle));
-
- for (size_t offset = 0, count = CFArrayGetCount(packages_); offset != count; ++offset) {
- Package *package = [self packageAtIndex:offset];
-
- BOOL uae = [package upgradableAndEssential:YES];
-
- if (!uae) {
- unseens = true;
- time_t seen([package seen]);
-
- 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];