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)
{
}
- (void) upgrade;
- (void) update;
-- (void) updateWithStatus:(Status &)status;
+- (NSString *) updateWithStatus:(Status &)status;
- (void) setDelegate:(id)delegate;
- (Source *) getSource:(pkgCache::PkgFileIterator)file;
debReleaseIndex *dindex(dynamic_cast<debReleaseIndex *>(index));
if (dindex != NULL) {
- FileFd fd(dindex->MetaIndexFile("Release"), FileFd::ReadOnly);
- pkgTagFile tags(&fd);
+ FileFd fd;
+ if (!fd.Open(dindex->MetaIndexFile("Release"), FileFd::ReadOnly))
+ _error->Discard();
+ else {
+ pkgTagFile tags(&fd);
- pkgTagSection section;
- tags.Step(section);
+ 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;
+ 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);
+ if (section.Find(names[i].name_, start, end)) {
+ CYString &value(*names[i].value_);
+ value.set(pool, start, end - start);
+ }
}
}
}
}
- (NSString *) longSection {
- return LocalizeSection(section_);
+ return LocalizeSection([self section]);
}
- (NSString *) shortSection {
[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];
}