return iterator_;
}
+- (NSArray *) downgrades {
+ NSMutableArray *versions([NSMutableArray arrayWithCapacity:4]);
+
+ for (auto version(iterator_.VersionList()); !version.end(); ++version) {
+ if (version == version_)
+ continue;
+ Package *package([[[Package allocWithZone:NULL] initWithVersion:version withZone:NULL inPool:NULL database:database_] autorelease]);
+ if ([package source] == nil)
+ continue;
+ [versions addObject:package];
+ }
+
+ return versions;
+}
+
- (NSString *) section {
if (section$_ == nil) {
if (section_ == NULL)
resolver->Protect(iterator_);
pkgCacheFile &cache([database_ cache]);
+ cache->SetCandidateVersion(version_);
cache->SetReInstall(iterator_, false);
cache->MarkInstall(iterator_, false);
std::vector<std::pair<_H<NSString>, _H<NSString>>> buttons_;
_H<UIActionSheet> sheet_;
_H<UIBarButtonItem> button_;
+ _H<NSArray> versions_;
}
- (id) initWithDatabase:(Database *)database forPackage:(NSString *)name withReferrer:(NSString *)referrer;
return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@", (id) name_]];
}
+- (void) _clickButtonWithPackage:(Package *)package {
+ [delegate_ installPackage:package];
+}
+
- (void) _clickButtonWithName:(NSString *)name {
if ([name isEqualToString:@"CLEAR"])
- [delegate_ clearPackage:package_];
- else if ([name isEqualToString:@"INSTALL"])
- [delegate_ installPackage:package_];
- else if ([name isEqualToString:@"REINSTALL"])
- [delegate_ installPackage:package_];
+ return [delegate_ clearPackage:package_];
else if ([name isEqualToString:@"REMOVE"])
- [delegate_ removePackage:package_];
- else if ([name isEqualToString:@"UPGRADE"])
- [delegate_ installPackage:package_];
+ return [delegate_ removePackage:package_];
+ else if ([name isEqualToString:@"DOWNGRADE"]) {
+ sheet_ = [[[UIActionSheet alloc]
+ initWithTitle:nil
+ delegate:self
+ cancelButtonTitle:nil
+ destructiveButtonTitle:nil
+ otherButtonTitles:nil
+ ] autorelease];
+
+ for (Package *version in (id) versions_)
+ [sheet_ addButtonWithTitle:[version latest]];
+ [sheet_ setContext:@"version"];
+
+ [delegate_ showActionSheet:sheet_ fromItem:[[self navigationItem] rightBarButtonItem]];
+ return;
+ }
+
+ else if ([name isEqualToString:@"INSTALL"]);
+ else if ([name isEqualToString:@"REINSTALL"]);
+ else if ([name isEqualToString:@"UPGRADE"]);
else _assert(false);
+
+ [delegate_ installPackage:package_];
}
- (void) actionSheet:(UIActionSheet *)sheet clickedButtonAtIndex:(NSInteger)button {
[self _clickButtonWithName:buttons_[button].first];
}
+ [sheet dismissWithClickedButtonIndex:button animated:YES];
+ } else if ([context isEqualToString:@"version"]) {
+ if (button != [sheet cancelButtonIndex]) {
+ Package *version([versions_ objectAtIndex:button]);
+ if (IsWildcat_)
+ [self performSelector:@selector(_clickButtonWithPackage:) withObject:version afterDelay:0];
+ else
+ [self _clickButtonWithPackage:version];
+ }
+
[sheet dismissWithClickedButtonIndex:button animated:YES];
}
}
otherButtonTitles:nil
] autorelease];
- for (NSString *button in buttons) [sheet_ addButtonWithTitle:button];
- if (!IsWildcat_) {
- [sheet_ addButtonWithTitle:UCLocalize("CANCEL")];
- [sheet_ setCancelButtonIndex:[sheet_ numberOfButtons] - 1];
- }
+ for (NSString *button in buttons)
+ [sheet_ addButtonWithTitle:button];
[sheet_ setContext:@"modify"];
[delegate_ showActionSheet:sheet_ fromItem:[[self navigationItem] rightBarButtonItem]];
sheet_ = nil;
package_ = [database_ packageWithName:name_];
+ versions_ = [package_ downgrades];
buttons_.clear();
buttons_.push_back(std::make_pair(@"REINSTALL", UCLocalize("REINSTALL")));
if (![package_ uninstalled])
buttons_.push_back(std::make_pair(@"REMOVE", UCLocalize("REMOVE")));
+ if ([versions_ count] != 0)
+ buttons_.push_back(std::make_pair(@"DOWNGRADE", UCLocalize("DOWNGRADE")));
}
NSString *title;
}
- (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item {
+ if (!IsWildcat_) {
+ [sheet addButtonWithTitle:UCLocalize("CANCEL")];
+ [sheet setCancelButtonIndex:[sheet numberOfButtons] - 1];
+ }
+
if (item != nil && IsWildcat_) {
[sheet showFromBarButtonItem:item animated:YES];
} else {