- description_ = [[UITextLabel alloc] initWithFrame:CGRectMake(12, 46, 280, 20)];
- [description_ setBackgroundColor:clear];
- [description_ setFont:small];
-
- source_ = [[UITextLabel alloc] initWithFrame:CGRectMake(12, 72, 225, 20)];
- [source_ setBackgroundColor:clear];
- [source_ setFont:large];
-
- version_ = [[UIRightTextLabel alloc] initWithFrame:CGRectMake(286, 69, 70, 25)];
- [version_ setBackgroundColor:clear];
- [version_ setFont:large];
-
- //trusted_ = [[UIImageView alloc] initWithFrame:CGRectMake(278, 7, 16, 16)];
- trusted_ = [[UIImageView alloc] initWithFrame:CGRectMake(30, 30, 16, 16)];
- [trusted_ setImage:[UIImage applicationImageNamed:@"trusted.png"]];
-
- [self addSubview:icon_];
- [self addSubview:name_];
- [self addSubview:description_];
- [self addSubview:source_];
- [self addSubview:version_];
-
- CGColorSpaceRelease(space);
-
- CFRelease(small);
- CFRelease(large);
- CFRelease(bold);
- } return self;
-}
-
-- (void) setPackage:(Package *)package {
- Source *source = [package source];
-
- UIImage *image = nil;
- if (NSString *icon = [package icon])
- image = [UIImage imageAtPath:[icon substringFromIndex:6]];
- if (image == nil) if (NSString *icon = [source defaultIcon])
- image = [UIImage imageAtPath:[icon substringFromIndex:6]];
- if (image == nil)
- image = [UIImage applicationImageNamed:@"unknown.png"];
-
- [icon_ setImage:image];
- [icon_ zoomToScale:0.5f];
- [icon_ setFrame:CGRectMake(10, 10, 30, 30)];
-
- [name_ setText:[package name]];
- [version_ setText:[package latest]];
- [description_ setText:[package tagline]];
-
- NSString *label;
- bool trusted;
-
- if (source != nil) {
- label = [source label];
- trusted = [source trusted];
- } else if ([[package id] isEqualToString:@"firmware"]) {
- label = @"Apple";
- trusted = false;
- } else {
- label = @"Unknown/Local";
- trusted = false;
- }
-
- [source_ setText:[NSString stringWithFormat:@"from %@", label]];
-
- [trusted_ removeFromSuperview];
- if (trusted)
- [self addSubview:trusted_];
-}
-
-- (void) _setSelected:(float)fraction {
- CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
-
- CGColor black(space,
- interpolate(0.0, 1.0, fraction),
- interpolate(0.0, 1.0, fraction),
- interpolate(0.0, 1.0, fraction),
- 1.0);
-
- CGColor blue(space,
- interpolate(0.2, 1.0, fraction),
- interpolate(0.2, 1.0, fraction),
- interpolate(1.0, 1.0, fraction),
- 1.0);
-
- CGColor gray(space,
- interpolate(0.4, 1.0, fraction),
- interpolate(0.4, 1.0, fraction),
- interpolate(0.4, 1.0, fraction),
- 1.0);
-
- [name_ setColor:black];
- [description_ setColor:gray];
- [source_ setColor:black];
- [version_ setColor:blue];
-
- CGColorSpaceRelease(space);
-}
-
-- (void) setSelected:(BOOL)selected {
- [self _setSelected:(selected ? 1.0 : 0.0)];
- [super setSelected:selected];
-}
-
-- (void) setSelected:(BOOL)selected withFade:(BOOL)fade {
- if (!fade)
- [self _setSelected:(selected ? 1.0 : 0.0)];
- [super setSelected:selected withFade:fade];
-}
-
-- (void) _setSelectionFadeFraction:(float)fraction {
- [self _setSelected:fraction];
- [super _setSelectionFadeFraction:fraction];
-}
-
-@end
-/* }}} */
-
-/* Database Implementation {{{ */
-@implementation Database
-
-- (void) dealloc {
- _assert(false);
- [super dealloc];
-}
-
-- (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;
-
- const char *error;
- int offset;
- pcre *code = pcre_compile("^([^:]*):([^:]*):([^:]*):(.*)$", 0, &error, &offset, NULL);
-
- pcre_extra *study = NULL;
- int capture;
- pcre_fullinfo(code, study, PCRE_INFO_CAPTURECOUNT, &capture);
- int matches[(capture + 1) * 3];
-
- while (std::getline(is, line)) {
- const char *data(line.c_str());
-
- _assert(pcre_exec(code, study, data, line.size(), 0, 0, matches, sizeof(matches) / sizeof(matches[0])) >= 0);
-
- std::istringstream buffer(line.substr(matches[6], matches[7] - matches[6]));
- float percent;
- buffer >> percent;
- [delegate_ setPercent:(percent / 100)];
-
- NSString *string = [NSString stringWithCString:(data + matches[8]) length:(matches[9] - matches[8])];
- std::string type(line.substr(matches[2], matches[3] - matches[2]));
-
- if (type == "pmerror")
- [delegate_ setError:string];
- else if (type == "pmstatus")
- [delegate_ setTitle:string];
- else if (type == "pmconffile")
- ;
- 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))
- [delegate_ addOutput:[NSString stringWithCString:line.c_str()]];
-
- [pool release];
- _assert(false);
-}
-
-- (Package *) packageWithName:(NSString *)name {
- pkgCache::PkgIterator iterator(cache_->FindPkg([name cString]));
- return iterator.end() ? nil : [Package packageWithIterator:iterator database:self];
-}
-
-- (Database *) init {
- if ((self = [super init]) != nil) {
- records_ = NULL;
- resolver_ = NULL;
- fetcher_ = NULL;
- lock_ = NULL;
-
- sources_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
-
- int fds[2];