- 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];
- }
- _trace();
-
- [sections_ addObjectsFromArray:[sections allValues]];
-
- [sections_ sortUsingSelector:@selector(compareByLocalized:)];
-
- for (Section *section in sections_) {
- size_t count([section row]);
- if (count == 0)
- continue;
-
- section = [[[Section alloc] initWithName:[section name] localized:[section localized]] autorelease];
- [section setCount:count];
- [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)];
-
- [list_ reloadData];
- _trace();
-}
-
-- (void) resetView {
- if (editing_)
- [self editButtonClicked];
-}
-
-- (void) editButtonClicked {
- 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];
-}
-
-- (UIView *) accessoryView {
- return accessory_;
-}
-
-@end
-/* }}} */
-/* Changes Controller {{{ */
-@interface ChangesController : CYViewController <
- UITableViewDataSource,
- UITableViewDelegate
-> {
- _transient Database *database_;
- CFMutableArrayRef packages_;
- NSMutableArray *sections_;
- UITableView *list_;
- unsigned upgrades_;
- BOOL hasSentFirstLoad_;
-}
-
-- (id) initWithDatabase:(Database *)database delegate:(id)delegate;
-- (void) reloadData;
-
-@end
-
-@implementation ChangesController
-
-- (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];
- }
-}
-
-- (NSInteger) numberOfSectionsInTableView:(UITableView *)list {
- NSInteger count([sections_ count]);
- return count == 0 ? 1 : count;
-}
-
-- (NSString *) tableView:(UITableView *)list titleForHeaderInSection:(NSInteger)section {
- if ([sections_ count] == 0)
- return nil;
- return [[sections_ objectAtIndex:section] name];
-}
-
-- (NSInteger) tableView:(UITableView *)list numberOfRowsInSection:(NSInteger)section {
- if ([sections_ count] == 0)
- return 0;
- return [[sections_ objectAtIndex:section] count];
-}
-
-- (Package *) packageAtIndex:(NSUInteger)index {
- return (Package *) CFArrayGetValueAtIndex(packages_, index);
-}
-
-- (Package *) packageAtIndexPath:(NSIndexPath *)path {
- Section *section([sections_ objectAtIndex:[path section]]);
- NSInteger row([path row]);
- return [self packageAtIndex:([section row] + row)];
-}
-
-- (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;
-}
-
-/*- (CGFloat) tableView:(UITableView *)table heightForRowAtIndexPath:(NSIndexPath *)path {
- return [PackageCell heightForPackage:[self packageAtIndexPath:path]];
-}*/
-
-- (NSIndexPath *) tableView:(UITableView *)table willSelectRowAtIndexPath:(NSIndexPath *)path {
- Package *package([self packageAtIndexPath:path]);
- PackageController *view([delegate_ packageController]);
- [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.0f];
- [[self view] addSubview:list_];
-
- [list_ setDataSource:self];
- [list_ setDelegate:self];
-
- delegate_ = delegate;
- } return self;
-}
-
-- (void) _reloadPackages:(NSArray *)packages {
- _trace();
- for (Package *package in packages)
- if ([package upgradableAndEssential:YES] || [package visible])
- CFArrayAppendValue(packages_, package);
-
- _trace();
- [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast<SKRadixFunction>(&PackageChangesRadix) withContext:NULL];
- _trace();
-}
-
-- (void) reloadData {
- NSArray *packages = [database_ packages];
-
- CFArrayRemoveAllValues(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;