//
// PSBibleViewController.m
// PocketSword
//
// Created by Nic Carter on 3/11/09.
// Copyright 2009 The CrossWire Bible Society. All rights reserved.
//
#import "PSBibleViewController.h"
//#import "SwordModule.h"
#import "PSModuleController.h"
//#import "ViewController.h"
#import "SwordDictionary.h"
@implementation PSBibleViewController
@synthesize refToShow;
@synthesize jsToShow;
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
- (void) viewDidLoad {
NSString *scrollPosition = [[NSUserDefaults standardUserDefaults] stringForKey: @"bibleScrollPosition"];
if(scrollPosition) {
NSString *script = [NSString stringWithFormat:@"window.scrollTo(0, %@);", scrollPosition];
[bibleWebView stringByEvaluatingJavaScriptFromString: script];
}
}*/
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if(refToShow) {
[moduleManager displayBusyIndicator];
NSString *bText = [moduleManager getBibleChapter:refToShow withExtraJS:[NSString stringWithFormat:@"%@\nstartDetLocPoll();\n", jsToShow]];
[bibleWebView loadHTMLString: bText baseURL: [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];
self.refToShow = nil;
self.jsToShow = nil;
[moduleManager hideBusyIndicator];
}
}
- (void)viewDidAppear:(BOOL)animated {
[bibleWebView stringByEvaluatingJavaScriptFromString:@"startDetLocPoll();"];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[bibleWebView stringByEvaluatingJavaScriptFromString:@"stopDetLocPoll();"];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
BOOL load = YES;
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@":"];
if ([components count] > 1 && [(NSString *)[components objectAtIndex:0] isEqualToString:@"pocketsword"]) {
if([(NSString *)[components objectAtIndex:1] isEqualToString:@"currentverse"]) {
[[NSUserDefaults standardUserDefaults] setObject: [components objectAtIndex:3] forKey: @"bibleScrollPosition"];
[[NSUserDefaults standardUserDefaults] setObject: [components objectAtIndex:2] forKey: @"bibleVersePosition"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSMutableString *ref = [NSMutableString stringWithString:[moduleManager getCurrentBibleRef]];
[ref appendFormat:@":%@", [components objectAtIndex:2]];
[[moduleManager viewController] setTabTitle: [PSModuleController createRefString:ref] ofTab:BibleTab];
}
load = NO;
} else {
//NSLog(@"\nBIBLE: requestString: %@", requestString);
NSDictionary *rData = [PSModuleController dataForLink: [request URL]];
NSString *entry = nil;
if(rData && [[rData objectForKey:ATTRTYPE_ACTION] isEqualToString:@"showStrongs"]) {//@"showStrongs"
//
// Strong's Numbers
//
NSString *mod = [[NSUserDefaults standardUserDefaults] objectForKey:DefaultsStrongsGreekModule];
//NSLog(@"dataType = %@", [rData objectForKey:ATTRTYPE_TYPE]);
BOOL hebrew = NO;
if([[rData objectForKey:ATTRTYPE_TYPE] isEqualToString:@"Hebrew"]) {
mod = [[NSUserDefaults standardUserDefaults] objectForKey:DefaultsStrongsHebrewModule];
hebrew = YES;
}
SwordDictionary *swordDictionary = (SwordDictionary*)[[SwordManager defaultManager] moduleWithName: mod];
if(swordDictionary) {
entry = [swordDictionary entryForKey:[rData objectForKey:ATTRTYPE_VALUE]];
//DLog(@"\n%@ = %@\n", mod, entry);
}
if(!entry) {
if(hebrew)
entry = NSLocalizedString(@"NoHebrewStrongsNumbersModuleInstalled", @"");
else
entry = NSLocalizedString(@"NoGreekStrongsNumbersModuleInstalled", @"");
}
} else if(rData && [[rData objectForKey:ATTRTYPE_ACTION] isEqualToString:@"showMorph"]) {
//
// Morphological Tags
// type hasPrefix: "robinson" for Greek
// type isEqualToString: "Greek" for Greek
// type hasPrefix: "strongMorph" for Hebrew ???
//
// for the time being I'm going to test for "strongMorph" & show an error dialogue or otherwise use Greek.
NSString *mod = [[NSUserDefaults standardUserDefaults] objectForKey:DefaultsMorphGreekModule];
if([[rData objectForKey:ATTRTYPE_TYPE] hasPrefix:@"strongMorph"]) {
entry = NSLocalizedString(@"MorphHebrewNotSupported", @"");
} else {
SwordDictionary *swordDictionary = (SwordDictionary*)[[SwordManager defaultManager] moduleWithName: mod];
if(swordDictionary) {
entry = [swordDictionary entryForKey:[rData objectForKey:ATTRTYPE_VALUE]];
//DLog(@"\n%@ = %@\n", mod, entry);
}
if(!entry) {
entry = NSLocalizedString(@"NoMorphGreekModuleInstalled", @"");
}
}
} else if(rData && [[rData objectForKey:ATTRTYPE_ACTION] isEqualToString:@"showNote"]) {
if([[rData objectForKey:ATTRTYPE_TYPE] isEqualToString:@"n"]) {//footnote
entry = (NSString*)[[moduleManager primaryBible] attributeValueForEntryData:rData];
} else if([[rData objectForKey:ATTRTYPE_TYPE] isEqualToString:@"x"]) {//x-reference
NSArray *array = (NSArray*)[[moduleManager primaryBible] attributeValueForEntryData:rData];
NSMutableString *tmpEntry = [@"" mutableCopy];
for(NSDictionary *dict in array) {
[tmpEntry appendFormat:@"%@: ", [PSModuleController createRefString: [dict objectForKey:SW_OUTPUT_REF_KEY]]];
[tmpEntry appendFormat:@"%@
", [dict objectForKey:SW_OUTPUT_TEXT_KEY]];
}
if(![tmpEntry isEqualToString:@""]) {//"[ ]" appear in the TEXT_KEYs where notes should appear, so we remove them here!
entry = [[tmpEntry stringByReplacingOccurrencesOfString:@"[" withString:@""] stringByReplacingOccurrencesOfString:@"]" withString:@""];
}
[tmpEntry release];
}
}
if(entry) {
[[moduleManager viewController] showInfo: entry];
load = NO;
}
}
[pool release];
return load; // Return YES to make sure regular navigation works as expected.
}
- (void)dealloc {
[super dealloc];
self.refToShow = nil;
self.jsToShow = nil;
}
@end