1 |
|
---|
2 | #import <Foundation/Foundation.h>
|
---|
3 |
|
---|
4 | #import <UIKit/CDStructures.h>
|
---|
5 | #import <UIKit/UIKit.h>
|
---|
6 | #import <UIKit/UITable.h>
|
---|
7 | #import <UIKit/UIProgressIndicator.h>
|
---|
8 |
|
---|
9 | #import "GreenstoneApplication.h"
|
---|
10 | #import "GreenstoneAPI.h"
|
---|
11 | //#import "SimpleWebView.h"
|
---|
12 | #import "GSResultItem.h"
|
---|
13 |
|
---|
14 | #import "BrowseCascadeView.h"
|
---|
15 |
|
---|
16 | // ***** think about coding for orientation of iPod!!!!
|
---|
17 |
|
---|
18 | @implementation BrowseCascadeView
|
---|
19 |
|
---|
20 |
|
---|
21 | -(UIView*) directEntry:(int)rowId
|
---|
22 | {
|
---|
23 | return self;
|
---|
24 | }
|
---|
25 |
|
---|
26 |
|
---|
27 | -(void) browseListToMenuItems:(NSMutableArray*)browseList withCollection:(NSString*)collection withGID:(NSString*)gid
|
---|
28 | {
|
---|
29 | GreenstoneAPI* greenstoneAPI = [GreenstoneApplication greenstoneAPI];
|
---|
30 |
|
---|
31 | NSEnumerator* browselist_enumerator = [browseList objectEnumerator];
|
---|
32 | NSString* childname;
|
---|
33 | while (childname = [browselist_enumerator nextObject]) {
|
---|
34 | NSString* childGID = [NSString alloc];
|
---|
35 |
|
---|
36 | if (gid==nil) {
|
---|
37 | childGID = [childGID initWithString:childname];
|
---|
38 | }
|
---|
39 | else if ([childname hasPrefix:@"."]==NO) {
|
---|
40 | childGID = [childGID initWithString:childname];
|
---|
41 | }
|
---|
42 | else {
|
---|
43 | childGID = [childGID initWithFormat:@"%@%@",gid,childname];
|
---|
44 | }
|
---|
45 |
|
---|
46 | GreenstoneApplication* toplevelApp = [GreenstoneApplication toplevelApp];
|
---|
47 | NSString* lang = [toplevelApp languagePref];
|
---|
48 | //greenstoneAPI->setLanguage(lang); // *****
|
---|
49 | greenstoneAPI->setLanguage("en");
|
---|
50 |
|
---|
51 | // look up Title metadata for child's GID, and use that to display on menu
|
---|
52 | NSString* textTitle = nil;
|
---|
53 | if ([childGID hasPrefix:@"CL"]==YES) {
|
---|
54 | textTitle = greenstoneAPI->getMetadataFirst(collection,childGID,@"Title");
|
---|
55 | }
|
---|
56 | else {
|
---|
57 | // Try for dc.Title first as generally better quality than ex.Title
|
---|
58 | textTitle = greenstoneAPI->getMetadataFirst(collection,childGID,@"dc.Title");
|
---|
59 | if (textTitle == nil) {
|
---|
60 | textTitle = greenstoneAPI->getMetadataFirst(collection,childGID,@"Title");
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | [(BrowseCascadeView*)_childMenu appendMenuItem:self withItem:textTitle withGID:childGID];
|
---|
65 |
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | -(void) createChildMenu:(NSString*)collection withTitle:(NSString*)title withGID:(NSString*)gid
|
---|
70 | withBrowseList:(NSMutableArray*) browseList
|
---|
71 | {
|
---|
72 | CGRect rect = [GreenstoneApplication workAreaRect];
|
---|
73 |
|
---|
74 | // The following check isn't strictly necessary, if _childMenu is released and set to nil
|
---|
75 | // when you transition back to the parent
|
---|
76 | if (_childMenu != nil) {
|
---|
77 | // [_childMenu release]; // *****
|
---|
78 | }
|
---|
79 |
|
---|
80 | _childMenu = [BrowseCascadeView alloc];
|
---|
81 | _childMenu = [(BrowseCascadeView*)_childMenu initWithFrame:rect withParent:self withCollection:collection withTitle:title withGID:gid];
|
---|
82 |
|
---|
83 | [self browseListToMenuItems:browseList withCollection:collection withGID:gid];
|
---|
84 | }
|
---|
85 |
|
---|
86 |
|
---|
87 |
|
---|
88 | -(void) tableRowSelected:(NSNotification*)notification
|
---|
89 | {
|
---|
90 | UITable* table = [notification object];
|
---|
91 | int rowId = [table selectedRow];
|
---|
92 |
|
---|
93 | UITableCell* cell = [table cellAtRow:rowId column:0];
|
---|
94 | [cell setSelected:FALSE withFade:TRUE];
|
---|
95 |
|
---|
96 |
|
---|
97 | GreenstoneAPI* greenstoneAPI = [GreenstoneApplication greenstoneAPI];
|
---|
98 | NSString* childTitle = [[_oidItem objectAtIndex:rowId] title];
|
---|
99 | int transStyle = UITransitionBothShiftLeft;
|
---|
100 |
|
---|
101 | GreenstoneApplication* toplevelApp = [GreenstoneApplication toplevelApp];
|
---|
102 | NSString* lang = [toplevelApp languagePref];
|
---|
103 | //greenstoneAPI->setLanguage(lang); // ***** make it a param (with default) to calling fns
|
---|
104 | greenstoneAPI->setLanguage("en");
|
---|
105 |
|
---|
106 | // Initialise with child menu
|
---|
107 |
|
---|
108 | if (_collection == nil) {
|
---|
109 | // Root node to Browse Greenstone collections
|
---|
110 | NSString* childGID = [[_oidItem objectAtIndex:rowId] oid];
|
---|
111 |
|
---|
112 | NSString* chosenCollection = [[NSString alloc] initWithString:childGID];
|
---|
113 |
|
---|
114 | NSMutableArray* classifierList = greenstoneAPI->browseToplevelList(chosenCollection);
|
---|
115 | [self createChildMenu:chosenCollection withTitle:childTitle withGID:nil withBrowseList:classifierList];
|
---|
116 | [classifierList release];
|
---|
117 |
|
---|
118 | [GreenstoneApplication setInCollection:chosenCollection];
|
---|
119 | [GreenstoneApplication transitionView:transStyle fromView:self toView:_childMenu];
|
---|
120 | }
|
---|
121 | else {
|
---|
122 | NSString* childGID = [[_oidItem objectAtIndex:rowId] oid];
|
---|
123 |
|
---|
124 | if ([childGID hasPrefix:@"CL"]==YES) {
|
---|
125 | // Note this test is potentially flawed if a document ID starts CL...
|
---|
126 | // Allow this for now, since default is for it to be HASH
|
---|
127 |
|
---|
128 | NSMutableArray* classifierList = greenstoneAPI->browseClassifierList(_collection,childGID);
|
---|
129 |
|
---|
130 | NSString* chosenCollection = [[NSString alloc] initWithString:_collection];
|
---|
131 | [self createChildMenu:chosenCollection withTitle:childTitle withGID:childGID withBrowseList:classifierList];
|
---|
132 | [classifierList release];
|
---|
133 |
|
---|
134 | [GreenstoneApplication transitionView:transStyle fromView:self toView:_childMenu];
|
---|
135 | }
|
---|
136 | else {
|
---|
137 | NSString* childGID = [[_oidItem objectAtIndex:rowId] oid];
|
---|
138 |
|
---|
139 | NSString* srcurl = greenstoneAPI->getSrcUrlMetadata(_collection,childGID);
|
---|
140 | NSURL* url = [NSURL alloc];
|
---|
141 |
|
---|
142 | if (srcurl == nil) {
|
---|
143 |
|
---|
144 | NSTimer *timer = [ NSTimer scheduledTimerWithTimeInterval: 1.0 // used to be 0.3, then 0.5
|
---|
145 | target: self
|
---|
146 | selector: @selector(asynchronousLoad:)
|
---|
147 | userInfo: childGID
|
---|
148 | repeats: NO ];
|
---|
149 |
|
---|
150 | url = [url initWithString:@"file:///var/code/gs2-runtime-svn/ext/iOS3.x/loading.html"]; // **** make it use proper gsdlhome
|
---|
151 |
|
---|
152 | }
|
---|
153 | else {
|
---|
154 | NSString* fullurlstr = [[NSString alloc] initWithFormat:@"file://%@",srcurl];
|
---|
155 |
|
---|
156 | url = [url initWithString:fullurlstr];
|
---|
157 | NSLog(@"** opening src URL= %@",fullurlstr);
|
---|
158 |
|
---|
159 | }
|
---|
160 | [GreenstoneApplication showWebView:transStyle fromView:self withURL:url];
|
---|
161 |
|
---|
162 | }
|
---|
163 | }
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 |
|
---|
168 |
|
---|
169 | -(void) asynchronousLoad:(NSTimer*)timer
|
---|
170 | {
|
---|
171 | NSString* childGID = [timer userInfo];
|
---|
172 |
|
---|
173 | [GreenstoneApplication startWebViewBusy];
|
---|
174 |
|
---|
175 | GreenstoneAPI* greenstoneAPI = [GreenstoneApplication greenstoneAPI];
|
---|
176 | GreenstoneApplication* toplevelApp = [GreenstoneApplication toplevelApp];
|
---|
177 | NSString* lang = [toplevelApp languagePref];
|
---|
178 | //greenstoneAPI->setLanguage(lang); // ***** make param
|
---|
179 | greenstoneAPI->setLanguage("en");
|
---|
180 |
|
---|
181 | NSString* doctext = greenstoneAPI->getResolvedDocument(_collection,childGID);
|
---|
182 |
|
---|
183 | [doctext writeToFile:@"/tmp/gsdoc.html" atomically:NO encoding:NSUTF8StringEncoding error:nil];
|
---|
184 | NSURL* url = [[NSURL alloc] initWithString:@"file:///tmp/gsdoc.html"];
|
---|
185 | system("chmod a+rw /tmp/gsdoc.html");
|
---|
186 |
|
---|
187 | [GreenstoneApplication loadURL:url];
|
---|
188 | // [GreenstoneApplication showWebView:0 fromView:self withURL:url]; // ****
|
---|
189 |
|
---|
190 | [GreenstoneApplication stopWebViewBusy];
|
---|
191 | }
|
---|
192 |
|
---|
193 |
|
---|
194 | -(void) navigationBar:(UINavigationBar*)navbar buttonClicked:(int)button
|
---|
195 | {
|
---|
196 | NSLog(@"_gid = %@",_gid);
|
---|
197 |
|
---|
198 | switch (button)
|
---|
199 | {
|
---|
200 | case 1: // left button (back)
|
---|
201 | // if ([_gid hasPrefix:@"CL"]==YES) { // ****
|
---|
202 | if (_gid == nil) {
|
---|
203 | [GreenstoneApplication setInCollection:nil];
|
---|
204 | }
|
---|
205 | break;
|
---|
206 | }
|
---|
207 |
|
---|
208 | [super navigationBar:navbar buttonClicked:button];
|
---|
209 | }
|
---|
210 | @end
|
---|