+ if (!version_.end())
+ file_ = version_.FileList();
+ else {
+ pkgCache &cache([database_ cache]);
+ file_ = pkgCache::VerFileIterator(cache, cache.VerFileP);
+ }
+
+ pkgCache::VerIterator current = iterator_.CurrentVer();
+ installed_ = current.end() ? nil : [StripVersion([NSString stringWithUTF8String:current.VerStr()]) retain];
+
+ id_ = [[[NSString stringWithUTF8String:iterator_.Name()] lowercaseString] retain];
+
+ if (!file_.end()) {
+ pkgRecords::Parser *parser = &[database_ records]->Lookup(file_);
+
+ const char *begin, *end;
+ parser->GetRec(begin, end);
+
+ name_ = Scour("Name", begin, end);
+ if (name_ != nil)
+ name_ = [name_ retain];
+ tagline_ = [[NSString stringWithUTF8String:parser->ShortDesc().c_str()] retain];
+ icon_ = Scour("Icon", begin, end);
+ if (icon_ != nil)
+ icon_ = [icon_ retain];
+ website_ = Scour("Homepage", begin, end);
+ if (website_ == nil)
+ website_ = Scour("Website", begin, end);
+ if (website_ != nil)
+ website_ = [website_ retain];
+ NSString *sponsor = Scour("Sponsor", begin, end);
+ if (sponsor != nil)
+ sponsor_ = [[Address addressWithString:sponsor] retain];
+ NSString *author = Scour("Author", begin, end);
+ if (author != nil)
+ author_ = [[Address addressWithString:author] retain];
+ }
+
+ NSMutableDictionary *metadata = [Packages_ objectForKey:id_];
+ if (metadata == nil || [metadata count] == 0) {
+ metadata = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ now_, @"FirstSeen",
+ nil];
+
+ [Packages_ setObject:metadata forKey:id_];
+ Changed_ = true;
+ }
+ } return self;
+}
+
++ (Package *) packageWithIterator:(pkgCache::PkgIterator)iterator database:(Database *)database {
+ return [[[Package alloc]
+ initWithIterator:iterator
+ database:database
+ ] autorelease];
+}
+
+- (pkgCache::PkgIterator) iterator {
+ return iterator_;
+}
+
+- (NSString *) section {
+ const char *section = iterator_.Section();
+ return section == NULL ? nil : [[NSString stringWithUTF8String:section] stringByReplacingCharacter:'_' withCharacter:' '];
+}
+
+- (Address *) maintainer {
+ if (file_.end())
+ return nil;
+ pkgRecords::Parser *parser = &[database_ records]->Lookup(file_);
+ return [Address addressWithString:[NSString stringWithUTF8String:parser->Maintainer().c_str()]];
+}
+
+- (size_t) size {
+ return version_.end() ? 0 : version_->InstalledSize;
+}
+
+- (NSString *) description {
+ if (file_.end())
+ return nil;
+ pkgRecords::Parser *parser = &[database_ records]->Lookup(file_);
+ NSString *description([NSString stringWithUTF8String:parser->LongDesc().c_str()]);
+
+ NSArray *lines = [description componentsSeparatedByString:@"\n"];
+ NSMutableArray *trimmed = [NSMutableArray arrayWithCapacity:([lines count] - 1)];
+ if ([lines count] < 2)
+ return nil;
+
+ NSCharacterSet *whitespace = [NSCharacterSet whitespaceCharacterSet];
+ for (size_t i(1); i != [lines count]; ++i) {
+ NSString *trim = [[lines objectAtIndex:i] stringByTrimmingCharactersInSet:whitespace];
+ [trimmed addObject:trim];
+ }
+
+ return [trimmed componentsJoinedByString:@"\n"];
+}
+
+- (NSString *) index {
+ NSString *index = [[[self name] substringToIndex:1] uppercaseString];
+ return [index length] != 0 && isalpha([index characterAtIndex:0]) ? index : @"123";
+}
+
+- (NSDate *) seen {
+ return [[Packages_ objectForKey:id_] objectForKey:@"FirstSeen"];
+}
+
+- (NSString *) latest {
+ return latest_;
+}
+
+- (NSString *) installed {
+ return installed_;
+}
+
+- (BOOL) valid {
+ return !version_.end();
+}
+
+- (BOOL) upgradableAndEssential:(BOOL)essential {
+ pkgCache::VerIterator current = iterator_.CurrentVer();
+
+ if (current.end())
+ return essential && [self essential];
+ else {
+ pkgCache::VerIterator candidate = [database_ policy]->GetCandidateVer(iterator_);
+ return !candidate.end() && candidate != current;
+ }
+}
+
+- (BOOL) essential {
+ return (iterator_->Flags & pkgCache::Flag::Essential) == 0 ? NO : YES;
+}
+
+- (BOOL) broken {
+ return [database_ cache][iterator_].InstBroken();
+}
+
+- (BOOL) half {
+ unsigned char current = iterator_->CurrentState;
+ return current == pkgCache::State::HalfConfigured || current == pkgCache::State::HalfInstalled;
+}
+
+- (BOOL) halfConfigured {
+ return iterator_->CurrentState == pkgCache::State::HalfConfigured;
+}
+
+- (BOOL) halfInstalled {
+ return iterator_->CurrentState == pkgCache::State::HalfInstalled;
+}
+
+- (BOOL) hasMode {
+ pkgDepCache::StateCache &state([database_ cache][iterator_]);
+ return state.Mode != pkgDepCache::ModeKeep;
+}
+
+- (NSString *) mode {
+ pkgDepCache::StateCache &state([database_ cache][iterator_]);
+
+ switch (state.Mode) {
+ case pkgDepCache::ModeDelete:
+ if ((state.iFlags & pkgDepCache::Purge) != 0)
+ return @"Purge";
+ else
+ return @"Remove";
+ _assert(false);
+ case pkgDepCache::ModeKeep:
+ if ((state.iFlags & pkgDepCache::AutoKept) != 0)
+ return nil;
+ else
+ return nil;
+ _assert(false);
+ case pkgDepCache::ModeInstall:
+ if ((state.iFlags & pkgDepCache::ReInstall) != 0)
+ return @"Reinstall";
+ else switch (state.Status) {
+ case -1:
+ return @"Downgrade";
+ case 0:
+ return @"Install";
+ case 1:
+ return @"Upgrade";
+ case 2:
+ return @"New Install";
+ default:
+ _assert(false);
+ }
+ default:
+ _assert(false);
+ }
+}
+
+- (NSString *) id {
+ return id_;
+}
+
+- (NSString *) name {
+ return name_ == nil ? id_ : name_;
+}
+
+- (NSString *) tagline {
+ return tagline_;
+}
+
+- (NSString *) icon {
+ return icon_;
+}
+
+- (NSString *) website {
+ return website_;
+}
+
+- (Address *) sponsor {
+ return sponsor_;
+}
+
+- (Address *) author {
+ return author_;
+}
+
+- (NSArray *) relationships {
+ return relationships_;
+}
+
+- (Source *) source {
+ if (!cached_) {
+ source_ = file_.end() ? nil : [[database_ getSource:file_.File()] retain];
+ cached_ = true;
+ }
+
+ return source_;
+}
+
+- (BOOL) matches:(NSString *)text {
+ if (text == nil)
+ return NO;
+
+ NSRange range;
+
+ range = [[self id] rangeOfString:text options:NSCaseInsensitiveSearch];
+ if (range.location != NSNotFound)
+ return YES;
+
+ range = [[self name] rangeOfString:text options:NSCaseInsensitiveSearch];
+ if (range.location != NSNotFound)
+ return YES;
+
+ range = [[self tagline] rangeOfString:text options:NSCaseInsensitiveSearch];
+ if (range.location != NSNotFound)
+ return YES;
+
+ return NO;
+}
+
+- (NSComparisonResult) compareByName:(Package *)package {
+ NSString *lhs = [self name];
+ NSString *rhs = [package name];
+
+ if ([lhs length] != 0 && [rhs length] != 0) {
+ unichar lhc = [lhs characterAtIndex:0];
+ unichar rhc = [rhs characterAtIndex:0];
+
+ if (isalpha(lhc) && !isalpha(rhc))
+ return NSOrderedAscending;
+ else if (!isalpha(lhc) && isalpha(rhc))
+ return NSOrderedDescending;
+ }
+
+ return [lhs caseInsensitiveCompare:rhs];
+}
+
+- (NSComparisonResult) compareBySection:(Package *)package {
+ NSString *lhs = [self section];
+ NSString *rhs = [package section];
+
+ if (lhs == NULL && rhs != NULL)
+ return NSOrderedAscending;
+ else if (lhs != NULL && rhs == NULL)
+ return NSOrderedDescending;
+ else if (lhs != NULL && rhs != NULL) {
+ NSComparisonResult result = [lhs caseInsensitiveCompare:rhs];
+ if (result != NSOrderedSame)
+ return result;
+ }
+
+ return NSOrderedSame;
+}
+
+- (NSComparisonResult) compareBySectionAndName:(Package *)package {
+ NSString *lhs = [self section];
+ NSString *rhs = [package section];
+
+ if (lhs == NULL && rhs != NULL)
+ return NSOrderedAscending;
+ else if (lhs != NULL && rhs == NULL)
+ return NSOrderedDescending;
+ else if (lhs != NULL && rhs != NULL) {
+ NSComparisonResult result = [lhs compare:rhs];
+ if (result != NSOrderedSame)
+ return result;
+ }
+
+ return [self compareByName:package];
+}
+
+- (NSComparisonResult) compareForChanges:(Package *)package {
+ BOOL lhs = [self upgradableAndEssential:YES];
+ BOOL rhs = [package upgradableAndEssential:YES];
+
+ if (lhs != rhs)
+ return lhs ? NSOrderedAscending : NSOrderedDescending;
+ else if (!lhs) {
+ switch ([[self seen] compare:[package seen]]) {
+ case NSOrderedAscending:
+ return NSOrderedDescending;
+ case NSOrderedSame:
+ break;
+ case NSOrderedDescending:
+ return NSOrderedAscending;
+ default:
+ _assert(false);
+ }
+ }
+
+ return [self compareByName:package];
+}
+
+- (void) install {
+ pkgProblemResolver *resolver = [database_ resolver];
+ resolver->Clear(iterator_);
+ resolver->Protect(iterator_);
+ pkgCacheFile &cache([database_ cache]);
+ cache->MarkInstall(iterator_, false);
+ pkgDepCache::StateCache &state((*cache)[iterator_]);
+ if (!state.Install())
+ cache->SetReInstall(iterator_, true);
+}
+
+- (void) remove {
+ pkgProblemResolver *resolver = [database_ resolver];
+ resolver->Clear(iterator_);
+ resolver->Protect(iterator_);
+ resolver->Remove(iterator_);
+ [database_ cache]->MarkDelete(iterator_, true);
+}
+
+- (NSNumber *) isSearchedForBy:(NSString *)search {
+ return [NSNumber numberWithBool:([self valid] && [self matches:search])];
+}
+
+- (NSNumber *) isInstalledInSection:(NSString *)section {
+ return [NSNumber numberWithBool:([self installed] != nil && (section == nil || [section isEqualToString:[self section]]))];
+}
+
+- (NSNumber *) isUninstalledInSection:(NSString *)name {
+ NSString *section = [self section];
+
+ return [NSNumber numberWithBool:([self valid] && [self installed] == nil && (
+ (name == nil ||
+ section == nil && [name length] == 0 ||
+ [name isEqualToString:section])
+ ))];
+}
+
+@end
+/* }}} */
+/* Section Class {{{ */
+@interface Section : NSObject {
+ NSString *name_;
+ size_t row_;
+ size_t count_;
+}
+
+- (Section *) initWithName:(NSString *)name row:(size_t)row;
+- (NSString *) name;
+- (size_t) row;
+- (size_t) count;
+- (void) addToCount;
+
+@end
+
+@implementation Section
+
+- (void) dealloc {
+ [name_ release];
+ [super dealloc];
+}
+
+- (Section *) initWithName:(NSString *)name row:(size_t)row {
+ if ((self = [super init]) != nil) {
+ name_ = [name retain];
+ row_ = row;
+ } return self;
+}
+
+- (NSString *) name {
+ return name_;
+}
+
+- (size_t) row {
+ return row_;
+}
+
+- (size_t) count {
+ return count_;
+}
+
+- (void) addToCount {
+ ++count_;
+}
+
+@end
+/* }}} */
+
+/* Database Implementation {{{ */
+@implementation Database
+
+- (void) dealloc {
+ _assert(false);
+ [super dealloc];
+}
+
+- (void) _readCydia:(NSNumber *)fd {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ __gnu_cxx::stdio_filebuf<char> ib([fd intValue], std::ios::in);
+ std::istream is(&ib);
+ std::string line;
+
+ while (std::getline(is, line)) {
+ const char *data(line.c_str());
+ //size_t size = line.size();
+ fprintf(stderr, "C:%s\n", data);
+ }
+
+ [pool release];
+ _assert(false);
+}
+
+- (void) _readStatus:(NSNumber *)fd {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ __gnu_cxx::stdio_filebuf<char> ib([fd intValue], std::ios::in);
+ std::istream is(&ib);
+ std::string line;
+
+ Pcre conffile_r("^status: [^ ]* : conffile-prompt : (.*?) *$");
+ Pcre pmstatus_r("^([^:]*):([^:]*):([^:]*):(.*)$");
+
+ while (std::getline(is, line)) {
+ const char *data(line.c_str());
+ size_t size = line.size();
+ fprintf(stderr, "S:%s\n", data);
+
+ if (conffile_r(data, size)) {
+ [delegate_ setConfigurationData:conffile_r[1]];
+ } else if (strncmp(data, "status: ", 8) == 0) {
+ NSString *string = [NSString stringWithUTF8String:(data + 8)];
+ [delegate_ setProgressTitle:string];
+ } else if (pmstatus_r(data, size)) {
+ std::string type([pmstatus_r[1] UTF8String]);
+ NSString *id = pmstatus_r[2];
+
+ float percent([pmstatus_r[3] floatValue]);
+ [delegate_ setProgressPercent:(percent / 100)];
+
+ NSString *string = pmstatus_r[4];
+
+ if (type == "pmerror")
+ [delegate_ performSelectorOnMainThread:@selector(_setProgressError:)
+ withObject:[NSArray arrayWithObjects:string, id, nil]
+ waitUntilDone:YES
+ ];
+ else if (type == "pmstatus")
+ [delegate_ setProgressTitle:string];
+ else if (type == "pmconffile")
+ [delegate_ setConfigurationData:string];
+ else _assert(false);
+ } else _assert(false);
+ }
+
+ [pool release];
+ _assert(false);
+}
+
+- (void) _readOutput:(NSNumber *)fd {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ __gnu_cxx::stdio_filebuf<char> ib([fd intValue], std::ios::in);
+ std::istream is(&ib);
+ std::string line;
+
+ while (std::getline(is, line)) {
+ fprintf(stderr, "O:%s\n", line.c_str());
+ [delegate_ addProgressOutput:[NSString stringWithUTF8String:line.c_str()]];
+ }
+
+ [pool release];
+ _assert(false);
+}
+
+- (FILE *) input {
+ return input_;
+}
+
+- (Package *) packageWithName:(NSString *)name {
+ if (static_cast<pkgDepCache *>(cache_) == NULL)
+ return nil;
+ pkgCache::PkgIterator iterator(cache_->FindPkg([name UTF8String]));
+ return iterator.end() ? nil : [Package packageWithIterator:iterator database:self];
+}
+
+- (Database *) init {
+ if ((self = [super init]) != nil) {
+ policy_ = NULL;
+ records_ = NULL;
+ resolver_ = NULL;
+ fetcher_ = NULL;
+ lock_ = NULL;
+
+ sources_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
+ packages_ = [[NSMutableArray arrayWithCapacity:16] retain];
+
+ int fds[2];
+
+ _assert(pipe(fds) != -1);
+ cydiafd_ = fds[1];
+
+ _config->Set("APT::Keep-Fds::", cydiafd_);
+ setenv("CYDIA", [[[[NSNumber numberWithInt:cydiafd_] stringValue] stringByAppendingString:@" 0"] UTF8String], _not(int));
+
+ [NSThread
+ detachNewThreadSelector:@selector(_readCydia:)
+ toTarget:self
+ withObject:[[NSNumber numberWithInt:fds[0]] retain]
+ ];
+
+ _assert(pipe(fds) != -1);
+ statusfd_ = fds[1];
+
+ [NSThread
+ detachNewThreadSelector:@selector(_readStatus:)
+ toTarget:self
+ withObject:[[NSNumber numberWithInt:fds[0]] retain]
+ ];
+
+ _assert(pipe(fds) != -1);
+ _assert(dup2(fds[0], 0) != -1);
+ _assert(close(fds[0]) != -1);
+
+ input_ = fdopen(fds[1], "a");
+
+ _assert(pipe(fds) != -1);
+ _assert(dup2(fds[1], 1) != -1);
+ _assert(close(fds[1]) != -1);
+
+ [NSThread
+ detachNewThreadSelector:@selector(_readOutput:)
+ toTarget:self
+ withObject:[[NSNumber numberWithInt:fds[0]] retain]
+ ];
+ } return self;
+}
+
+- (pkgCacheFile &) cache {
+ return cache_;
+}
+
+- (pkgDepCache::Policy *) policy {
+ return policy_;
+}
+
+- (pkgRecords *) records {
+ return records_;
+}
+
+- (pkgProblemResolver *) resolver {
+ return resolver_;
+}
+
+- (pkgAcquire &) fetcher {
+ return *fetcher_;
+}
+
+- (NSArray *) packages {
+ return packages_;
+}
+
+- (void) reloadData {
+ _error->Discard();
+
+ delete list_;
+ list_ = NULL;
+ manager_ = NULL;
+ delete lock_;
+ lock_ = NULL;
+ delete fetcher_;
+ fetcher_ = NULL;
+ delete resolver_;
+ resolver_ = NULL;
+ delete records_;
+ records_ = NULL;
+ delete policy_;
+ policy_ = NULL;
+
+ cache_.Close();
+
+ if (!cache_.Open(progress_, true)) {
+ std::string error;
+ if (!_error->PopMessage(error))
+ _assert(false);
+ _error->Discard();
+ fprintf(stderr, "cache_.Open():[%s]\n", error.c_str());
+
+ if (error == "dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the problem. ")
+ [delegate_ repairWithSelector:@selector(configure)];
+ else if (error == "The package lists or status file could not be parsed or opened.")
+ [delegate_ repairWithSelector:@selector(update)];
+ // else if (error == "Could not open lock file /var/lib/dpkg/lock - open (13 Permission denied)")
+ // else if (error == "Could not get lock /var/lib/dpkg/lock - open (35 Resource temporarily unavailable)")
+ // else if (error == "The list of sources could not be read.")
+ else _assert(false);
+
+ return;
+ }
+
+ now_ = [[NSDate date] retain];
+
+ policy_ = new pkgDepCache::Policy();
+ records_ = new pkgRecords(cache_);
+ resolver_ = new pkgProblemResolver(cache_);
+ fetcher_ = new pkgAcquire(&status_);
+ lock_ = NULL;
+
+ list_ = new pkgSourceList();
+ _assert(list_->ReadMainList());
+
+ _assert(cache_->DelCount() == 0 && cache_->InstCount() == 0);
+ _assert(pkgApplyStatus(cache_));
+
+ if (cache_->BrokenCount() != 0) {
+ _assert(pkgFixBroken(cache_));
+ _assert(cache_->BrokenCount() == 0);
+ _assert(pkgMinimizeUpgrade(cache_));
+ }
+
+ [sources_ removeAllObjects];
+ for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source) {
+ std::vector<pkgIndexFile *> *indices = (*source)->GetIndexFiles();
+ for (std::vector<pkgIndexFile *>::const_iterator index = indices->begin(); index != indices->end(); ++index)
+ [sources_
+ setObject:[[[Source alloc] initWithMetaIndex:*source] autorelease]
+ forKey:[NSNumber numberWithLong:reinterpret_cast<uintptr_t>(*index)]
+ ];
+ }
+
+ [packages_ removeAllObjects];
+ for (pkgCache::PkgIterator iterator = cache_->PkgBegin(); !iterator.end(); ++iterator)
+ if (Package *package = [Package packageWithIterator:iterator database:self])
+ [packages_ addObject:package];
+
+ [packages_ sortUsingSelector:@selector(compareByName:)];
+}
+
+- (void) configure {
+ NSString *dpkg = [NSString stringWithFormat:@"dpkg --configure -a --status-fd %u", statusfd_];
+ system([dpkg UTF8String]);
+}
+
+- (void) clean {
+ if (lock_ != NULL)
+ return;
+
+ FileFd Lock;
+ Lock.Fd(GetLock(_config->FindDir("Dir::Cache::Archives") + "lock"));
+ _assert(!_error->PendingError());
+
+ pkgAcquire fetcher;
+ fetcher.Clean(_config->FindDir("Dir::Cache::Archives"));
+
+ class LogCleaner :
+ public pkgArchiveCleaner
+ {
+ protected:
+ virtual void Erase(const char *File, std::string Pkg, std::string Ver, struct stat &St) {
+ unlink(File);
+ }
+ } cleaner;
+
+ if (!cleaner.Go(_config->FindDir("Dir::Cache::Archives") + "partial/", cache_)) {
+ std::string error;
+ while (_error->PopMessage(error))
+ fprintf(stderr, "ArchiveCleaner: %s\n", error.c_str());
+ }
+}
+
+- (void) prepare {
+ pkgRecords records(cache_);
+
+ lock_ = new FileFd();
+ lock_->Fd(GetLock(_config->FindDir("Dir::Cache::Archives") + "lock"));
+ _assert(!_error->PendingError());
+
+ pkgSourceList list;
+ // XXX: explain this with an error message
+ _assert(list.ReadMainList());
+
+ manager_ = (_system->CreatePM(cache_));
+ _assert(manager_->GetArchives(fetcher_, &list, &records));
+ _assert(!_error->PendingError());
+}
+
+- (void) perform {
+ NSMutableArray *before = [NSMutableArray arrayWithCapacity:16]; {
+ pkgSourceList list;
+ _assert(list.ReadMainList());
+ for (pkgSourceList::const_iterator source = list.begin(); source != list.end(); ++source)
+ [before addObject:[NSString stringWithUTF8String:(*source)->GetURI().c_str()]];
+ }
+
+ if (fetcher_->Run(PulseInterval_) != pkgAcquire::Continue)
+ return;
+
+ _system->UnLock();
+ pkgPackageManager::OrderResult result = manager_->DoInstall(statusfd_);
+
+ if (result == pkgPackageManager::Failed)
+ return;
+ if (_error->PendingError())
+ return;
+ if (result != pkgPackageManager::Completed)
+ return;
+
+ NSMutableArray *after = [NSMutableArray arrayWithCapacity:16]; {
+ pkgSourceList list;
+ _assert(list.ReadMainList());
+ for (pkgSourceList::const_iterator source = list.begin(); source != list.end(); ++source)
+ [after addObject:[NSString stringWithUTF8String:(*source)->GetURI().c_str()]];
+ }
+
+ if (![before isEqualToArray:after])
+ [self update];
+}
+
+- (void) upgrade {
+ _assert(pkgDistUpgrade(cache_));
+}
+
+- (void) update {
+ [self updateWithStatus:status_];
+}
+
+- (void) updateWithStatus:(Status &)status {
+ pkgSourceList list;
+ _assert(list.ReadMainList());
+
+ FileFd lock;
+ lock.Fd(GetLock(_config->FindDir("Dir::State::Lists") + "lock"));
+ _assert(!_error->PendingError());
+
+ pkgAcquire fetcher(&status);
+ _assert(list.GetIndexes(&fetcher));
+
+ if (fetcher.Run(PulseInterval_) != pkgAcquire::Failed) {
+ bool failed = false;
+ for (pkgAcquire::ItemIterator item = fetcher.ItemsBegin(); item != fetcher.ItemsEnd(); item++)
+ if ((*item)->Status != pkgAcquire::Item::StatDone) {
+ (*item)->Finished();
+ failed = true;
+ }
+
+ if (!failed && _config->FindB("APT::Get::List-Cleanup", true) == true) {
+ _assert(fetcher.Clean(_config->FindDir("Dir::State::lists")));
+ _assert(fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/"));
+ }
+
+ [Metadata_ setObject:[NSDate date] forKey:@"LastUpdate"];
+ Changed_ = true;
+ }
+}
+
+- (void) setDelegate:(id)delegate {
+ delegate_ = delegate;
+ status_.setDelegate(delegate);
+ progress_.setDelegate(delegate);
+}
+
+- (Source *) getSource:(const pkgCache::PkgFileIterator &)file {
+ pkgIndexFile *index(NULL);
+ list_->FindIndex(file, index);
+ return [sources_ objectForKey:[NSNumber numberWithLong:reinterpret_cast<uintptr_t>(index)]];
+}
+
+@end
+/* }}} */
+
+/* Confirmation View {{{ */
+void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString *key) {
+ if ([packages count] == 0)
+ return;
+
+ UITextView *text = GetTextView([packages count] == 0 ? @"n/a" : [packages componentsJoinedByString:@", "], 120, false);
+ [fields setObject:text forKey:key];
+
+ CGColor blue(space_, 0, 0, 0.4, 1);
+ [text setTextColor:blue];
+}
+
+@protocol ConfirmationViewDelegate
+- (void) cancel;
+- (void) confirm;
+@end
+
+@interface ConfirmationView : UIView {
+ Database *database_;
+ id delegate_;
+ UITransitionView *transition_;
+ UIView *overlay_;
+ UINavigationBar *navbar_;
+ UIPreferencesTable *table_;
+ NSMutableDictionary *fields_;
+ UIAlertSheet *essential_;
+}
+
+- (void) cancel;
+
+- (id) initWithView:(UIView *)view database:(Database *)database delegate:(id)delegate;
+
+@end
+
+@implementation ConfirmationView
+
+- (void) dealloc {
+ [navbar_ setDelegate:nil];
+ [transition_ setDelegate:nil];
+ [table_ setDataSource:nil];
+
+ [transition_ release];
+ [overlay_ release];
+ [navbar_ release];
+ [table_ release];
+ [fields_ release];
+ if (essential_ != nil)
+ [essential_ release];
+ [super dealloc];
+}
+
+- (void) cancel {
+ [transition_ transition:7 toView:nil];
+ [delegate_ cancel];
+}
+
+- (void) transitionViewDidComplete:(UITransitionView*)view fromView:(UIView*)from toView:(UIView*)to {
+ if (from != nil && to == nil)
+ [self removeFromSuperview];
+}
+
+- (void) navigationBar:(UINavigationBar *)navbar buttonClicked:(int)button {
+ switch (button) {
+ case 0:
+ if (essential_ != nil)
+ [essential_ popupAlertAnimated:YES];
+ else
+ [delegate_ confirm];