#include <apt-pkg/sourcelist.h>
#include <apt-pkg/sptr.h>
#include <apt-pkg/strutl.h>
+#include <apt-pkg/tagfile.h>
#include <apr-1/apr_pools.h>
#define ForRelease 0
#define TraceLogging (1 && !ForRelease)
#define HistogramInsertionSort (0 && !ForRelease)
-#define ProfileTimes (1 && !ForRelease)
+#define ProfileTimes (0 && !ForRelease)
#define ForSaurik (0 && !ForRelease)
-#define LogBrowser (0 && !ForRelease)
+#define LogBrowser (1 && !ForRelease)
#define TrackResize (0 && !ForRelease)
#define ManualRefresh (1 && !ForRelease)
#define ShowInternals (0 && !ForRelease)
CFStringRef cache_;
_finline void clear_() {
- if (cache_ != nil)
+ if (cache_ != NULL) {
CFRelease(cache_);
+ cache_ = NULL;
+ }
}
public:
_finline CYString() :
data_(0),
size_(0),
- cache_(nil)
+ cache_(NULL)
{
}
return [NSString stringWithFormat:@"%s%.1f %s", (negative ? "-" : ""), size, powers_[power]];
}
+static _finline CFStringRef CFCString(const char *value) {
+ return CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast<const uint8_t *>(value), strlen(value), kCFStringEncodingUTF8, NO, kCFAllocatorNull);
+}
+
CFStringRef StripVersion(const char *version) {
const char *colon(strchr(version, ':'));
if (colon != NULL)
version = colon + 1;
- return CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast<const uint8_t *>(version), strlen(version), kCFStringEncodingUTF8, NO, kCFAllocatorNull);
+ return CFCString(version);
}
NSString *LocalizeSection(NSString *section) {
- (void) upgrade;
- (void) update;
-- (void) updateWithStatus:(Status &)status;
+- (NSString *) updateWithStatus:(Status &)status;
- (void) setDelegate:(id)delegate;
- (Source *) getSource:(pkgCache::PkgFileIterator)file;
/* Source Class {{{ */
@interface Source : NSObject {
- NSString *description_;
- NSString *label_;
- NSString *origin_;
- NSString *support_;
+ CYString description_;
+ CYString label_;
+ CYString origin_;
+ CYString support_;
- NSString *uri_;
- NSString *distribution_;
- NSString *type_;
- NSString *version_;
+ CYString uri_;
+ CYString distribution_;
+ CYString type_;
+ CYString version_;
+
+ NSString *host_;
- NSString *defaultIcon_;
+ CYString defaultIcon_;
NSDictionary *record_;
BOOL trusted_;
}
-- (Source *) initWithMetaIndex:(metaIndex *)index;
+- (Source *) initWithMetaIndex:(metaIndex *)index inPool:(apr_pool_t *)pool;
- (NSComparisonResult) compareByNameAndType:(Source *)source;
@implementation Source
-#define _clear(field) \
- if (field != nil) \
- [field release]; \
- field = nil;
-
- (void) _clear {
- _clear(uri_)
- _clear(distribution_)
- _clear(type_)
+ uri_.clear();
+ distribution_.clear();
+ type_.clear();
+
+ description_.clear();
+ label_.clear();
+ origin_.clear();
+ support_.clear();
+ version_.clear();
+ defaultIcon_.clear();
- _clear(description_)
- _clear(label_)
- _clear(origin_)
- _clear(support_)
- _clear(version_)
- _clear(defaultIcon_)
- _clear(record_)
+ if (record_ != nil) {
+ [record_ release];
+ record_ = nil;
+ }
+
+ if (host_ != nil) {
+ [host_ release];
+ host_ = nil;
+ }
}
- (void) dealloc {
return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
}
-- (void) setMetaIndex:(metaIndex *)index {
+- (void) setMetaIndex:(metaIndex *)index inPool:(apr_pool_t *)pool {
[self _clear];
trusted_ = index->IsTrusted();
- uri_ = [[NSString stringWithUTF8String:index->GetURI().c_str()] retain];
- distribution_ = [[NSString stringWithUTF8String:index->GetDist().c_str()] retain];
- type_ = [[NSString stringWithUTF8String:index->GetType()] retain];
+ uri_.set(pool, index->GetURI());
+ distribution_.set(pool, index->GetDist());
+ type_.set(pool, index->GetType());
debReleaseIndex *dindex(dynamic_cast<debReleaseIndex *>(index));
if (dindex != NULL) {
- std::ifstream release(dindex->MetaIndexFile("Release").c_str());
- std::string line;
- while (std::getline(release, line)) {
- std::string::size_type colon(line.find(':'));
- if (colon == std::string::npos)
- continue;
+ FileFd fd;
+ if (!fd.Open(dindex->MetaIndexFile("Release"), FileFd::ReadOnly))
+ _error->Discard();
+ else {
+ pkgTagFile tags(&fd);
- std::string name(line.substr(0, colon));
- std::string value(line.substr(colon + 1));
- while (!value.empty() && value[0] == ' ')
- value = value.substr(1);
-
- if (name == "Default-Icon")
- defaultIcon_ = [[NSString stringWithUTF8String:value.c_str()] retain];
- else if (name == "Description")
- description_ = [[NSString stringWithUTF8String:value.c_str()] retain];
- else if (name == "Label")
- label_ = [[NSString stringWithUTF8String:value.c_str()] retain];
- else if (name == "Origin")
- origin_ = [[NSString stringWithUTF8String:value.c_str()] retain];
- else if (name == "Support")
- support_ = [[NSString stringWithUTF8String:value.c_str()] retain];
- else if (name == "Version")
- version_ = [[NSString stringWithUTF8String:value.c_str()] retain];
+ pkgTagSection section;
+ tags.Step(section);
+
+ struct {
+ const char *name_;
+ CYString *value_;
+ } names[] = {
+ {"default-icon", &defaultIcon_},
+ {"description", &description_},
+ {"label", &label_},
+ {"origin", &origin_},
+ {"support", &support_},
+ {"version", &version_},
+ };
+
+ for (size_t i(0); i != sizeof(names) / sizeof(names[0]); ++i) {
+ const char *start, *end;
+
+ if (section.Find(names[i].name_, start, end)) {
+ CYString &value(*names[i].value_);
+ value.set(pool, start, end - start);
+ }
+ }
}
}
record_ = [Sources_ objectForKey:[self key]];
if (record_ != nil)
record_ = [record_ retain];
+
+ host_ = [[[[NSURL URLWithString:uri_] host] lowercaseString] retain];
}
-- (Source *) initWithMetaIndex:(metaIndex *)index {
+- (Source *) initWithMetaIndex:(metaIndex *)index inPool:(apr_pool_t *)pool {
if ((self = [super init]) != nil) {
- [self setMetaIndex:index];
+ [self setMetaIndex:index inPool:pool];
} return self;
}
}
- (NSString *) supportForPackage:(NSString *)package {
- return support_ == nil ? nil : [support_ stringByReplacingOccurrencesOfString:@"*" withString:package];
+ return support_.empty() ? nil : [support_ stringByReplacingOccurrencesOfString:@"*" withString:package];
}
- (NSDictionary *) record {
}
- (NSString *) key {
- return [NSString stringWithFormat:@"%@:%@:%@", type_, uri_, distribution_];
+ return [NSString stringWithFormat:@"%@:%@:%@", (NSString *) type_, (NSString *) uri_, (NSString *) distribution_];
}
- (NSString *) host {
- return [[[NSURL URLWithString:[self uri]] host] lowercaseString];
+ return host_;
}
- (NSString *) name {
- return origin_ == nil ? [self host] : origin_;
+ return origin_.empty() ? host_ : origin_;
}
- (NSString *) description {
}
- (NSString *) label {
- return label_ == nil ? [self host] : label_;
+ return label_.empty() ? host_ : label_;
}
- (NSString *) origin {
Address *author$_;
CYString support_;
- NSArray *tags_;
+ NSMutableArray *tags_;
NSString *role_;
NSArray *relationships_;
_profile(Package$parse$Tagline)
const char *start, *end;
- if (parser->Find("Description", start, end)) {
+ if (parser->ShortDesc(start, end)) {
const char *stop(reinterpret_cast<const char *>(memchr(start, '\n', end - start)));
if (stop == NULL)
stop = end;
_profile(Package$initWithVersion$Name)
id_.set(pool_, iterator_.Name());
+ name_.set(pool, iterator_.Display());
_end
if (!file_.end()) {
_end
}
- /* XXX: get the damned Name */
-
_profile(Package$initWithVersion$Tags)
- if (tags_ != nil)
- for (NSString *tag in tags_)
- if ([tag hasPrefix:@"role::"]) {
- role_ = [[tag substringFromIndex:6] retain];
- break;
- }
+ pkgCache::TagIterator tag(iterator_.TagList());
+ if (!tag.end()) {
+ tags_ = [[NSMutableArray alloc] initWithCapacity:8];
+ do {
+ const char *name(tag.Name());
+ [tags_ addObject:(NSString *)CFCString(name)];
+ if (role_ == nil && strncmp(name, "role::", 6) == 0)
+ role_ = (NSString *) CFCString(name + 6);
+ ++tag;
+ } while (!tag.end());
+ }
_end
bool changed(false);
}
- (NSString *) longSection {
- return LocalizeSection(section_);
+ return LocalizeSection([self section]);
}
- (NSString *) shortSection {
if (dynamic_cast<debPackagesIndex *>(*index) != NULL) {
pkgCache::PkgFileIterator cached((*index)->FindInCache(cache_));
if (!cached.end())
- sources_[cached->ID] = [[[Source alloc] initWithMetaIndex:*source] autorelease];
+ sources_[cached->ID] = [[[Source alloc] initWithMetaIndex:*source inPool:pool_] autorelease];
}
}
[self updateWithStatus:status_];
}
-- (void) updateWithStatus:(Status &)status {
+- (NSString *) updateWithStatus:(Status &)status {
pkgSourceList list;
_assert(list.ReadMainList());
FileFd lock;
lock.Fd(GetLock(_config->FindDir("Dir::State::Lists") + "lock"));
- _assert(!_error->PendingError());
+
+ if (_error->PendingError()) {
+ std::string error;
+ if (!_error->PopMessage(error))
+ _assert(false);
+ _error->Discard();
+ return [NSString stringWithUTF8String:error.c_str()];
+ }
pkgAcquire fetcher(&status);
_assert(list.GetIndexes(&fetcher));
[Metadata_ setObject:[NSDate date] forKey:@"LastUpdate"];
Changed_ = true;
}
+
+ return nil;
}
- (void) setDelegate:(id)delegate {
];
}
-- (void) _update_ {
+- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
+ NSString *context([sheet context]);
+
+ if ([context isEqualToString:@"refresh"])
+ [sheet dismiss];
+}
+
+- (void) _update_:(NSString *)error {
updating_ = false;
[indicator_ stopAnimation];
[UIView commitAnimations];
- [delegate_ performSelector:@selector(reloadData) withObject:nil afterDelay:0];
+ if (error == nil)
+ [delegate_ performSelector:@selector(reloadData) withObject:nil afterDelay:0];
+ else {
+ UIActionSheet *sheet = [[[UIActionSheet alloc]
+ initWithTitle:[NSString stringWithFormat:CYLocalize("COLON_DELIMITED"), CYLocalize("ERROR"), CYLocalize("REFRESH")]
+ buttons:[NSArray arrayWithObjects:
+ CYLocalize("OK"),
+ nil]
+ defaultButtonIndex:0
+ delegate:self
+ context:@"refresh"
+ ] autorelease];
+
+ [sheet setBodyText:error];
+ [sheet popupAlertAnimated:YES];
+
+ [self reloadButtons];
+ }
}
- (id) initWithFrame:(CGRect)frame database:(Database *)database {
Status status;
status.setDelegate(self);
- [database_ updateWithStatus:status];
+ NSString *error([database_ updateWithStatus:status]);
[self
- performSelectorOnMainThread:@selector(_update_)
- withObject:nil
+ performSelectorOnMainThread:@selector(_update_:)
+ withObject:error
waitUntilDone:NO
];
}
return !updating_;
}
-- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
- [sheet dismiss];
-}
-
- (void) _setProgressTitle:(NSString *)title {
[prompt_ setText:title];
}
ManageView *manage_;
SearchView *search_;
- PackageView *package_;
+ NSMutableArray *details_;
}
@end
}
- (void) setPackageView:(PackageView *)view {
- if (package_ == nil)
- package_ = [view retain];
+ WebThreadLock();
+ [view setPackage:nil];
+ if ([details_ count] < 3)
+ [details_ addObject:view];
+ WebThreadUnlock();
+}
+
+- (PackageView *) _packageView {
+ return [[[PackageView alloc] initWithBook:book_ database:database_] autorelease];
}
- (PackageView *) packageView {
PackageView *view;
+ size_t count([details_ count]);
- if (package_ == nil)
- view = [[[PackageView alloc] initWithBook:book_ database:database_] autorelease];
- else {
- return package_;
- view = [package_ autorelease];
- package_ = nil;
+ if (count == 0) {
+ view = [self _packageView];
+ renew:
+ [details_ addObject:[self _packageView]];
+ } else {
+ view = [[[details_ lastObject] retain] autorelease];
+ [details_ removeLastObject];
+ if (count == 1)
+ goto renew;
}
return view;
withClass:[ManageView class]
] retain];
- [self setPackageView:[self packageView]];
+ details_ = [[NSMutableArray alloc] initWithCapacity:4];
+ [details_ addObject:[self _packageView]];
+ [details_ addObject:[self _packageView]];
PrintTimes();