- path = [path substringFromIndex:8];
- if (![path hasPrefix:@"/"])
- path = [@"/" stringByAppendingString:path];
-
- if ([path isEqualToString:@"/storage"])
- return [self _pageForURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"storage" ofType:@"html"]] withClass:[CYBrowserController class]];
- /*else if ([path isEqualToString:@"/add-source"])
- return [[[AddSourceController alloc] initWithDatabase:database_] autorelease];*/
- else if ([path isEqualToString:@"/sources"])
- return [[[SourceController alloc] initWithDatabase:database_] autorelease];
- else if ([path isEqualToString:@"/packages"])
- return [[[InstalledController alloc] initWithDatabase:database_] autorelease];
- else if ([path hasPrefix:@"/url/"])
- return [self _pageForURL:[NSURL URLWithString:[path substringFromIndex:5]] withClass:[CYBrowserController class]];
- else if ([path hasPrefix:@"/launch/"])
- [self launchApplicationWithIdentifier:[path substringFromIndex:8] suspended:NO];
- else if ([path hasPrefix:@"/package-settings/"])
- return [[[CYPackageSettingsController alloc] initWithDatabase:database_ package:[path substringFromIndex:18]] autorelease];
- else if ([path hasPrefix:@"/package-signature/"])
- return [[[SignatureController alloc] initWithDatabase:database_ package:[path substringFromIndex:19]] autorelease];
- else if ([path hasPrefix:@"/package/"])
- return [self pageForPackage:[path substringFromIndex:9]];
- else if ([path hasPrefix:@"/files/"]) {
- NSString *name = [path substringFromIndex:7];
-
- if (Package *package = [database_ packageWithName:name]) {
- FileTable *files = [[[FileTable alloc] initWithDatabase:database_] autorelease];
- [files setPackage:package];
- return files;
+
+ NSString *base([components objectAtIndex:0]);
+
+ if ([components count] == 1) {
+ if ([base isEqualToString:@"storage"]) {
+ CYBrowserController *browser = [[[CYBrowserController alloc] init] autorelease];
+ [browser loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"storage" ofType:@"html"]]];
+ return browser;
+ }
+
+ if ([base isEqualToString:@"sources"]) {
+ CYSourcesController *source = [[[CYSourcesController alloc] initWithDatabase:database_] autorelease];
+ return source;
+ }
+
+ if ([base isEqualToString:@"home"]) {
+ CYHomeController *home = [[[CYHomeController alloc] init] autorelease];
+ return home;
+ }
+
+ if ([base isEqualToString:@"sections"]) {
+ CYSectionsController *sections = [[[CYSectionsController alloc] initWithDatabase:database_] autorelease];
+ return sections;
+ }
+
+ if ([base isEqualToString:@"search"]) {
+ CYSearchController *search = [[[CYSearchController alloc] initWithDatabase:database_] autorelease];
+ return search;
+ }
+
+ if ([base isEqualToString:@"changes"]) {
+ CYChangesController *changes = [[[CYChangesController alloc] initWithDatabase:database_ delegate:self] autorelease];
+ return changes;
+ }
+
+ if ([base isEqualToString:@"installed"]) {
+ CYInstalledController *installed = [[[CYInstalledController alloc] initWithDatabase:database_] autorelease];
+ return installed;
+ }
+ } else if ([components count] == 2) {
+ NSString *argument = [components objectAtIndex:1];
+
+ if ([base isEqualToString:@"package"]) {
+ CYViewController *package = [self pageForPackage:argument];
+ return package;
+ }
+
+ if ([base isEqualToString:@"search"]) {
+ CYSearchController *search = [[[CYSearchController alloc] initWithDatabase:database_] autorelease];
+ [search setSearchTerm:argument];
+ return search;
+ }
+
+ if ([base isEqualToString:@"sections"]) {
+ if ([argument isEqualToString:@"all"])
+ argument = nil;
+ CYSectionController *section = [[[CYSectionController alloc] initWithDatabase:database_ section:argument] autorelease];
+ [section setDelegate:self];
+ return section;
+ }
+
+ if ([base isEqualToString:@"sources"]) {
+ if ([argument isEqualToString:@"add"]) {
+ CYSourcesController *source = [[[CYSourcesController alloc] initWithDatabase:database_] autorelease];
+ [source showAddSourcePrompt];
+ return source;
+ } else {
+ // XXX: Create page of the source specfified.
+ }
+ }
+
+ if ([base isEqualToString:@"url"]) {
+ CYBrowserController *browser = [[[CYBrowserController alloc] init] autorelease];
+ [browser loadURL:[NSURL URLWithString:argument]];
+ return browser;
+ }
+
+ if ([base isEqualToString:@"launch"]) {
+ [self launchApplicationWithIdentifier:argument suspended:NO];
+ }
+ } else if ([components count] == 3) {
+ NSString *arg1 = [components objectAtIndex:1];
+ NSString *arg2 = [components objectAtIndex:2];
+
+ if ([base isEqualToString:@"package"]) {
+ if ([arg2 isEqualToString:@"settings"]) {
+ return [[[CYPackageSettingsController alloc] initWithDatabase:database_ package:arg1] autorelease];
+ } else if ([arg2 isEqualToString:@"signature"]) {
+ return [[[SignatureController alloc] initWithDatabase:database_ package:arg1] autorelease];
+ } else if ([arg2 isEqualToString:@"files"]) {
+ if (Package *package = [database_ packageWithName:arg1]) {
+ FileTable *files = [[[FileTable alloc] initWithDatabase:database_] autorelease];
+ [files setPackage:package];
+ return files;
+ }
+ }