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