}
- (int) yieldToPopupAlertAnimated:(BOOL)animated;
+
@end
@implementation CYAlertView
- (id) initWithTitle:(NSString *)title buttons:(NSArray *)buttons defaultButtonIndex:(int)index {
- if ((self = [super init])) {
+ if ((self = [super init]) != nil) {
[self setTitle:title];
[self setDelegate:self];
for (NSString *button in buttons) [self addButtonWithTitle:button];
+ (Address *) addressWithString:(NSString *)string;
- (Address *) initWithString:(NSString *)string;
+
@end
@implementation Address
}
+ (NSArray *) _attributeKeys {
- return [NSArray arrayWithObjects:@"address", @"name", nil];
+ return [NSArray arrayWithObjects:
+ @"address",
+ @"name",
+ nil];
}
- (NSArray *) attributeKeys {
- (pkgSourceList &) list;
- (NSArray *) packages;
- (NSArray *) sources;
+- (Source *) sourceWithKey:(NSString *)key;
- (void) reloadData;
- (void) configure;
}
+ (NSArray *) _attributeKeys {
- return [NSArray arrayWithObjects:@"description", @"distribution", @"host", @"key", @"label", @"name", @"origin", @"trusted", @"type", @"uri", @"version", nil];
+ return [NSArray arrayWithObjects:
+ @"description",
+ @"distribution",
+ @"host",
+ @"key",
+ @"label",
+ @"name",
+ @"origin",
+ @"trusted",
+ @"type",
+ @"uri",
+ @"version",
+ nil];
}
- (NSArray *) attributeKeys {
@end
/* }}} */
-/* Relationship Class {{{ */
-@interface Relationship : NSObject {
- NSString *type_;
- NSString *id_;
+/* CydiaOperation Class {{{ */
+@interface CydiaOperation : NSObject {
+ NSString *operator_;
+ NSString *value_;
}
-- (NSString *) type;
-- (NSString *) id;
-- (NSString *) name;
+- (NSString *) operator;
+- (NSString *) value;
@end
-@implementation Relationship
+@implementation CydiaOperation
- (void) dealloc {
- [type_ release];
- [id_ release];
+ [operator_ release];
+ [value_ release];
[super dealloc];
}
-- (NSString *) type {
- return type_;
+- (id) initWithOperator:(const char *)_operator value:(const char *)value {
+ if ((self = [super init]) != nil) {
+ operator_ = [[NSString alloc] initWithUTF8String:_operator];
+ value_ = [[NSString alloc] initWithUTF8String:value];
+ } return self;
}
-- (NSString *) id {
- return id_;
++ (NSArray *) _attributeKeys {
+ return [NSArray arrayWithObjects:
+ @"operator",
+ @"value",
+ nil];
}
-- (NSString *) name {
- _assert(false);
- return nil;
+- (NSArray *) attributeKeys {
+ return [[self class] _attributeKeys];
+}
+
++ (BOOL) isKeyExcludedFromWebScript:(const char *)name {
+ return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
+}
+
+- (NSString *) operator {
+ return operator_;
+}
+
+- (NSString *) value {
+ return value_;
+}
+
+@end
+/* }}} */
+/* CydiaRelation Class {{{ */
+@interface CydiaRelation : NSObject {
+ NSString *relationship_;
+ NSString *package_;
+ CydiaOperation *version_;
+}
+
+- (NSString *) relationship;
+- (NSString *) package;
+- (CydiaOperation *) version;
+
+@end
+
+@implementation CydiaRelation
+
+- (void) dealloc {
+ [relationship_ release];
+ [package_ release];
+ [version_ release];
+ [super dealloc];
+}
+
+- (id) initWithIterator:(pkgCache::DepIterator &)dep {
+ if ((self = [super init]) != nil) {
+ relationship_ = [[NSString alloc] initWithUTF8String:dep.DepType()];
+ package_ = [[NSString alloc] initWithUTF8String:dep.TargetPkg().Name()];
+
+ if (const char *version = dep.TargetVer())
+ version_ = [[CydiaOperation alloc] initWithOperator:dep.CompType() value:version];
+ else
+ version_ = [[NSNull null] retain];
+ } return self;
+}
+
++ (NSArray *) _attributeKeys {
+ return [NSArray arrayWithObjects:
+ @"package",
+ @"relationship",
+ @"version",
+ nil];
+}
+
+- (NSArray *) attributeKeys {
+ return [[self class] _attributeKeys];
+}
+
++ (BOOL) isKeyExcludedFromWebScript:(const char *)name {
+ return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
+}
+
+- (NSString *) relationship {
+ return relationship_;
+}
+
+- (NSString *) package {
+ return package_;
+}
+
+- (CydiaOperation *) version {
+ return version_;
}
@end
}
+ (NSString *) webScriptNameForSelector:(SEL)selector {
- if (selector == @selector(hasTag:))
+ if (false);
+ else if (selector == @selector(clear))
+ return @"clear";
+ else if (selector == @selector(hasTag:))
return @"hasTag";
+ else if (selector == @selector(install))
+ return @"install";
+ else if (selector == @selector(remove))
+ return @"remove";
else
return nil;
}
}
+ (NSArray *) _attributeKeys {
- return [NSArray arrayWithObjects:@"applications", @"author", @"depiction", @"longDescription", @"essential", @"homepage", @"icon", @"id", @"installed", @"latest", @"longSection", @"maintainer", @"mode", @"name", @"purposes", @"section", @"shortDescription", @"shortSection", @"simpleSection", @"size", @"source", @"sponsor", @"support", @"warnings", nil];
+ return [NSArray arrayWithObjects:
+ @"applications",
+ @"author",
+ @"depiction",
+ @"essential",
+ @"homepage",
+ @"icon",
+ @"id",
+ @"installed",
+ @"latest",
+ @"longDescription",
+ @"longSection",
+ @"maintainer",
+ @"mode",
+ @"name",
+ @"purposes",
+ @"relations",
+ @"section",
+ @"shortDescription",
+ @"shortSection",
+ @"simpleSection",
+ @"size",
+ @"source",
+ @"sponsor",
+ @"support",
+ @"warnings",
+ nil];
}
- (NSArray *) attributeKeys {
return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
}
+- (NSArray *) relations {
+@synchronized (database_) {
+ NSMutableArray *relations([NSMutableArray arrayWithCapacity:16]);
+
+ for (pkgCache::DepIterator dep(version_.DependsList()); !dep.end(); ++dep) {
+ pkgCache::DepIterator start;
+ pkgCache::DepIterator end;
+ dep.GlobOr(start, end); // ++dep
+
+ NSMutableArray *ors([NSMutableArray arrayWithCapacity:2]);
+ [relations addObject:ors];
+
+ _forever {
+ [ors addObject:[[[CydiaRelation alloc] initWithIterator:start] autorelease]];
+
+ // yes, seriously. (wtf?)
+ if (start == end)
+ break;
+ ++start;
+ }
+ }
+
+ return relations;
+} }
+
- (void) parse {
if (parsed_ != NULL)
return;
// XXX: actually implement this thing
_assert(false);
if (deadSources_)
- CFRelease(deadSources_);
+ CFRelease(deadSources_);
[self releasePackages];
apr_pool_destroy(pool_);
NSRecycleZone(zone_);
return sources;
}
+- (Source *) sourceWithKey:(NSString *)key {
+ for (Source *source in [self sources]) {
+ if ([[source key] isEqualToString:key])
+ return source;
+ } return nil;
+}
+
- (bool) popErrorWithTitle:(NSString *)title {
bool fatal(false);
std::string message;
}
- (id) initWithDelegate:(IndirectDelegate *)indirect;
+
@end
@implementation CydiaObject
}
+ (NSArray *) _attributeKeys {
- return [NSArray arrayWithObjects:@"device", @"firewire", @"imei", @"mac", @"serial", nil];
+ return [NSArray arrayWithObjects:
+ @"device",
+ @"firewire",
+ @"imei",
+ @"mac",
+ @"serial",
+ nil];
}
- (NSArray *) attributeKeys {
#endif
+ (NSString *) webScriptNameForSelector:(SEL)selector {
- if (selector == @selector(close))
+ if (false);
+ else if (selector == @selector(close))
return @"close";
+ else if (selector == @selector(du:))
+ return @"du";
+ else if (selector == @selector(stringWithFormat:arguments:))
+ return @"format";
else if (selector == @selector(getInstalledPackages))
return @"getInstalledPackages";
else if (selector == @selector(getPackageById:))
return @"getPackageById";
else if (selector == @selector(installPackages:))
return @"installPackages";
+ else if (selector == @selector(localizedStringForKey:value:table:))
+ return @"localize";
else if (selector == @selector(setButtonImage:withStyle:toFunction:))
return @"setButtonImage";
else if (selector == @selector(setButtonTitle:withStyle:toFunction:))
return @"setToken";
else if (selector == @selector(setViewportWidth:))
return @"setViewportWidth";
- else if (selector == @selector(supports:))
- return @"supports";
- else if (selector == @selector(stringWithFormat:arguments:))
- return @"format";
- else if (selector == @selector(localizedStringForKey:value:table:))
- return @"localize";
- else if (selector == @selector(du:))
- return @"du";
else if (selector == @selector(statfs:))
return @"statfs";
+ else if (selector == @selector(supports:))
+ return @"supports";
else
return nil;
}
@implementation CYLoadingIndicator
-- (id)initWithFrame:(CGRect)frame {
- if ((self = [super initWithFrame:frame])) {
+- (id) initWithFrame:(CGRect)frame {
+ if ((self = [super initWithFrame:frame]) != nil) {
container_ = [[[UIView alloc] init] autorelease];
[container_ setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin];
[spinner_ setFrame:spinrect];
[label_ setFrame:textrect];
[self addSubview:container_];
- }
+ } return self;
+}
- return self;
+- (UILabel *) label {
+ return label_;
}
-- (UILabel *)label { return label_; }
-- (UIActivityIndicatorView *)activityIndicatorView { return spinner_; }
+- (UIActivityIndicatorView *) activityIndicatorView {
+ return spinner_;
+}
@end
/* }}} */
UITabBar *tabbar_;
UINavigationBar *navbar_;
}
+
@end
@implementation CYEmulatedLoadingController
}
- (id) initWithDatabase:(Database *)database {
- if ((self = [super init])) {
+ if ((self = [super init]) != nil) {
database_ = database;
[database_ setDelegate:self];
} return self;
- (SEL) selector;
- (id) target;
- (id) object;
+
@end
@implementation ProgressData
[self positionViews];
}
-- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
+- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[self positionViews];
}
/* Home Controller {{{ */
@interface HomeController : CYBrowserController {
}
+
@end
@implementation HomeController
}
- (void) queueStatusDidChange;
+
@end
@implementation ManageController
[prompt_ setFrame:prmrect];
}
-- (void)setFrame:(CGRect)frame {
+- (void) setFrame:(CGRect)frame {
[super setFrame:frame];
-
[self positionViews];
}
- (id) initWithFrame:(CGRect)frame delegate:(id)delegate {
- if ((self = [super initWithFrame:frame])) {
+ if ((self = [super initWithFrame:frame]) != nil) {
[self setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[self setBarStyle:UIBarStyleBlack];
_trace();
}
-- (void)editButtonClicked {
- [self setEditing:!editing_];
+- (void) editButtonClicked {
+ [self setEditing:(!editing_)];
}
@end
} return self;
}
-- (void)viewDidAppear:(BOOL)animated {
+- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (!searchloaded_) {
}
- (id) initWithDatabase:(Database *)database package:(NSString *)package {
- if ((self = [super init])) {
+ if ((self = [super init]) != nil) {
database_ = database;
name_ = [package retain];
} return self;
/* Source Controller {{{ */
@interface SourceController : FilteredPackageListController {
_transient Source *source_;
- NSString *uri_;
+ NSString *key_;
}
- (id) initWithDatabase:(Database *)database source:(Source *)source;
}
- (id) initWithDatabase:(Database *)database source:(Source *)source {
- source_ = source;
- uri_ = [source uri];
-
if ((self = [super initWithDatabase:database title:[source label] filter:@selector(isVisibleInSource:) with:source]) != nil) {
+ source_ = source;
+ key_ = [[source key] retain];
} return self;
}
- (void) reloadData {
- NSArray *sources = [database_ sources];
- for (Source *source in sources) {
- if ([[source uri] isEqual:uri_]) {
- source_ = source;
- uri_ = [source uri];
- break;
- }
- }
-
+ source_ = [database_ sourceWithKey:key_];
+ [key_ release];
+ key_ = [[source_ key] retain];
[self setObject:source_];
+ [[self navigationItem] setTitle:[source_ label]];
[super reloadData];
}
[[self navigationController] pushViewController:controller animated:YES];
}
-- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
+- (BOOL) tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
Source *source = [self sourceAtIndexPath:indexPath];
return [source record] != nil;
}
-- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
+- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
Source *source = [self sourceAtIndexPath:indexPath];
[Sources_ removeObjectForKey:[source key]];
[delegate_ syncData];
return [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
}
-- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
+- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
NSString *context([alert context]);
if ([context isEqualToString:@"source"]) {
}
- (id) initWithDatabase:(Database *)database delegate:(id)delegate {
- if ((self = [super init])) {
+ if ((self = [super init]) != nil) {
database_ = database;
roledelegate_ = delegate;
} return self;
return 0; // :(
}
-- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return nil; // This method is required by the protocol.
}
UILabel *status_;
UILabel *caption_;
}
+
@end
@implementation StashController
return [[[CYPackageController alloc] initWithDatabase:database_ forPackage:name] autorelease];
}
-- (CYViewController *) pageForURL:(NSURL *)url {
+- (CYViewController *) pageForURL:(NSURL *)url forExternal:(BOOL)external {
NSString *scheme([[url scheme] lowercaseString]);
if ([[url absoluteString] length] <= [scheme length] + 3)
return nil;
// This kind of URL can contain slashes in the argument, so we can't parse them below.
NSString *destination = [[url absoluteString] substringFromIndex:([scheme length] + [@"://" length] + [base length] + [@"/" length])];
controller = [[[CYBrowserController alloc] initWithURL:[NSURL URLWithString:destination]] autorelease];
- } else if ([components count] == 1) {
+ } else if (!external && [components count] == 1) {
if ([base isEqualToString:@"manage"]) {
controller = [[[ManageController alloc] init] autorelease];
}
controller = [self pageForPackage:argument];
}
- if ([base isEqualToString:@"search"]) {
+ if (!external && [base isEqualToString:@"search"]) {
controller = [[[SearchController alloc] initWithDatabase:database_] autorelease];
[(SearchController *)controller setSearchTerm:argument];
}
- if ([base isEqualToString:@"sections"]) {
+ if (!external && [base isEqualToString:@"sections"]) {
if ([argument isEqualToString:@"all"])
argument = nil;
controller = [[[SectionController alloc] initWithDatabase:database_ section:argument] autorelease];
}
- if ([base isEqualToString:@"sources"]) {
+ if (!external && [base isEqualToString:@"sources"]) {
if ([argument isEqualToString:@"add"]) {
controller = [[[SourcesController alloc] initWithDatabase:database_] autorelease];
[(SourcesController *)controller showAddSourcePrompt];
} else {
- NSArray *sources = [database_ sources];
- for (Source *source in sources) {
- if ([[source name] caseInsensitiveCompare:argument] == NSOrderedSame) {
- controller = [[[SourceController alloc] initWithDatabase:database_ source:source] autorelease];
- break;
- }
- }
+ Source *source = [database_ sourceWithKey:argument];
+ controller = [[[SourceController alloc] initWithDatabase:database_ source:source] autorelease];
}
}
- if ([base isEqualToString:@"launch"]) {
+ if (!external && [base isEqualToString:@"launch"]) {
[self launchApplicationWithIdentifier:argument suspended:NO];
return nil;
}
- } else if ([components count] == 3) {
+ } else if (!external && [components count] == 3) {
NSString *arg1 = [components objectAtIndex:1];
NSString *arg2 = [components objectAtIndex:2];
return controller;
}
-- (BOOL) openCydiaURL:(NSURL *)url {
- CYViewController *page([self pageForURL:url]);
+- (BOOL) openCydiaURL:(NSURL *)url forExternal:(BOOL)external {
+ CYViewController *page([self pageForURL:url forExternal:external]);
if (page != nil) {
CYNavigationController *nav = [[[CYNavigationController alloc] init] autorelease];
[super applicationOpenURL:url];
if (!loaded_) starturl_ = [url retain];
- else [self openCydiaURL:url];
+ else [self openCydiaURL:url forExternal:YES];
}
- (void) applicationWillResignActive:(UIApplication *)application {
[tabbar_ setUpdateDelegate:self];
}
-- (CYEmulatedLoadingController *)showEmulatedLoadingControllerInView:(UIView *)view {
+- (CYEmulatedLoadingController *) showEmulatedLoadingControllerInView:(UIView *)view {
static CYEmulatedLoadingController *fake = nil;
if (view != nil) {
for (unsigned int nav = 0; nav < [stack count]; nav++) {
NSString *addr = [stack objectAtIndex:nav];
NSURL *url = [NSURL URLWithString:addr];
- CYViewController *page = [self pageForURL:url];
+ CYViewController *page = [self pageForURL:url forExternal:NO];
if (page != nil)
[current addObject:page];
}
// (Try to) show the startup URL.
if (starturl_ != nil) {
- [self openCydiaURL:starturl_];
+ [self openCydiaURL:starturl_ forExternal:NO];
[starturl_ release];
starturl_ = nil;
}