Diffstat (limited to 'noncore/apps/opie-reader/CHM.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/CHM.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/noncore/apps/opie-reader/CHM.cpp b/noncore/apps/opie-reader/CHM.cpp index 88d53bf..ace5abc 100644 --- a/noncore/apps/opie-reader/CHM.cpp +++ b/noncore/apps/opie-reader/CHM.cpp | |||
@@ -1,23 +1,26 @@ | |||
1 | #include "CHM.h" | 1 | #include "CHM.h" |
2 | #include "chm_lib.h" | 2 | #include "chm_lib.h" |
3 | #include <qstring.h> | 3 | #include <qstring.h> |
4 | #include <qstringlist.h> | 4 | #include <qstringlist.h> |
5 | #include <stdio.h> | 5 | #include <stdio.h> |
6 | #include <qimage.h> | 6 | #include <qimage.h> |
7 | #include <qpixmap.h> | 7 | #include <qpixmap.h> |
8 | #ifdef USEQPE | ||
9 | #include <qpe/global.h> | ||
10 | #endif | ||
8 | 11 | ||
9 | #ifndef __STATIC | 12 | #ifndef __STATIC |
10 | extern "C" | 13 | extern "C" |
11 | { | 14 | { |
12 | CExpander* newcodec() { return new CHM; } | 15 | CExpander* newcodec() { return new CHM; } |
13 | } | 16 | } |
14 | #endif | 17 | #endif |
15 | 18 | ||
16 | static int _print_ui_index(struct chmFile *h, struct chmUnitInfo *ui, | 19 | static int _print_ui_index(struct chmFile *h, struct chmUnitInfo *ui, |
17 | void *context) | 20 | void *context) |
18 | { | 21 | { |
19 | CHM *chm = (CHM *)context; | 22 | CHM *chm = (CHM *)context; |
20 | QString temp = "<tr>"; | 23 | QString temp = "<tr>"; |
21 | char buff[1024]; | 24 | char buff[1024]; |
22 | sprintf( buff,"<td align=right>%8d\n</td><td><a href=\"%s\">%s</a></td></tr>",(int)ui->length, ui->path, ui->path); | 25 | sprintf( buff,"<td align=right>%8d\n</td><td><a href=\"%s\">%s</a></td></tr>",(int)ui->length, ui->path, ui->path); |
23 | temp += buff; | 26 | temp += buff; |
@@ -53,52 +56,57 @@ void CHM::suspend() { | |||
53 | #ifdef USEQPE | 56 | #ifdef USEQPE |
54 | bSuspended = true; | 57 | bSuspended = true; |
55 | //suspos = gztell(file); | 58 | //suspos = gztell(file); |
56 | chm_close(chmFile); | 59 | chm_close(chmFile); |
57 | chmFile = NULL; | 60 | chmFile = NULL; |
58 | sustime = time(NULL); | 61 | sustime = time(NULL); |
59 | #endif | 62 | #endif |
60 | } | 63 | } |
61 | 64 | ||
62 | void CHM::unsuspend() { | 65 | void CHM::unsuspend() { |
63 | #ifdef USEQPE | 66 | #ifdef USEQPE |
64 | if (bSuspended) | 67 | if (bSuspended) |
65 | { | 68 | { |
66 | bSuspended = false; | 69 | bSuspended = false; |
67 | int delay = time(NULL) - sustime; | 70 | int delay = time(NULL) - sustime; |
68 | if (delay < 10) | 71 | if (delay < 10) |
72 | { | ||
73 | Global::statusMessage("Stalling"); | ||
69 | sleep(10-delay); | 74 | sleep(10-delay); |
75 | } | ||
70 | chmFile = chm_open(fname); | 76 | chmFile = chm_open(fname); |
71 | for (int i = 0; chmFile == NULL && i < 5; i++) { | 77 | for (int i = 0; chmFile == NULL && i < 5; i++) { |
78 | Global::statusMessage("Stalling"); | ||
72 | sleep(5); | 79 | sleep(5); |
73 | chmFile = chm_open(fname); | 80 | chmFile = chm_open(fname); |
74 | } | 81 | } |
75 | if (chmFile == NULL) { | 82 | if (chmFile == NULL) { |
76 | QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file"); | 83 | QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file"); |
77 | exit(0); | 84 | exit(0); |
78 | } | 85 | } |
79 | //suspos = gzseek(file, suspos, SEEK_SET); | 86 | //suspos = gzseek(file, suspos, SEEK_SET); |
80 | } | 87 | } |
81 | #endif | 88 | #endif |
82 | } | 89 | } |
83 | 90 | ||
84 | void CHM::addContent(QString content) { | 91 | void CHM::addContent(QString content) { |
85 | chmBuffer += content; | 92 | chmBuffer += content; |
86 | } | 93 | } |
87 | 94 | ||
88 | void CHM::FillHomeContent() { | 95 | void CHM::FillHomeContent() { |
96 | unsuspend(); | ||
89 | if (chmHHCPath != "") { | 97 | if (chmHHCPath != "") { |
90 | const char *ext; | 98 | const char *ext; |
91 | char buffer[65536]; | 99 | char buffer[65536]; |
92 | unsigned int swath, offset; | 100 | unsigned int swath, offset; |
93 | QString tmp=""; | 101 | QString tmp=""; |
94 | QString HTML=""; | 102 | QString HTML=""; |
95 | /* try to find the file */ | 103 | /* try to find the file */ |
96 | const char *filename = (const char *)chmHHCPath; | 104 | const char *filename = (const char *)chmHHCPath; |
97 | if (chm_resolve_object(chmFile, filename, &m_ui) != CHM_RESOLVE_SUCCESS) | 105 | if (chm_resolve_object(chmFile, filename, &m_ui) != CHM_RESOLVE_SUCCESS) |
98 | { | 106 | { |
99 | chmBuffer = "HELP"; | 107 | chmBuffer = "HELP"; |
100 | fsize = chmBuffer.length(); | 108 | fsize = chmBuffer.length(); |
101 | return; | 109 | return; |
102 | } | 110 | } |
103 | m_homestart = m_ui.start; | 111 | m_homestart = m_ui.start; |
104 | m_homeend = m_homestart + m_ui.length; | 112 | m_homeend = m_homestart + m_ui.length; |
@@ -149,32 +157,33 @@ void CHM::FillHomeContent() { | |||
149 | } | 157 | } |
150 | } | 158 | } |
151 | } | 159 | } |
152 | HTML +="</h3>"; | 160 | HTML +="</h3>"; |
153 | HTML +="</BODY>\r\n"; | 161 | HTML +="</BODY>\r\n"; |
154 | HTML +="</HTML>\r\n"; | 162 | HTML +="</HTML>\r\n"; |
155 | chmHomeBuffer = HTML; | 163 | chmHomeBuffer = HTML; |
156 | chmBuffer = HTML; | 164 | chmBuffer = HTML; |
157 | fsize = chmBuffer.length(); | 165 | fsize = chmBuffer.length(); |
158 | m_currentstart = m_ui.start; | 166 | m_currentstart = m_ui.start; |
159 | m_currentend = m_currentstart+chmBuffer.length(); | 167 | m_currentend = m_currentstart+chmBuffer.length(); |
160 | } | 168 | } |
161 | } | 169 | } |
162 | 170 | ||
163 | bool CHM::FillBuffer() | 171 | bool CHM::FillBuffer() |
164 | { | 172 | { |
173 | unsuspend(); | ||
165 | bool bRetVal = false; | 174 | bool bRetVal = false; |
166 | char buffer[65536]; | 175 | char buffer[65536]; |
167 | int swath, offset; | 176 | int swath, offset; |
168 | chmBuffer = ""; | 177 | chmBuffer = ""; |
169 | swath = 65536; | 178 | swath = 65536; |
170 | offset = 0; | 179 | offset = 0; |
171 | fsize = m_ui.length; | 180 | fsize = m_ui.length; |
172 | while (offset < m_ui.length) | 181 | while (offset < m_ui.length) |
173 | { | 182 | { |
174 | if ((m_ui.length - offset) < 65536) | 183 | if ((m_ui.length - offset) < 65536) |
175 | swath = m_ui.length - offset; | 184 | swath = m_ui.length - offset; |
176 | else | 185 | else |
177 | swath = 65536; | 186 | swath = 65536; |
178 | swath = (int)chm_retrieve_object(chmFile, &m_ui, (unsigned char *) buffer, offset, swath); | 187 | swath = (int)chm_retrieve_object(chmFile, &m_ui, (unsigned char *) buffer, offset, swath); |
179 | chmBuffer += buffer; | 188 | chmBuffer += buffer; |
180 | offset += swath; | 189 | offset += swath; |
@@ -183,32 +192,33 @@ bool CHM::FillBuffer() | |||
183 | QString temp = chmBuffer.lower(); | 192 | QString temp = chmBuffer.lower(); |
184 | int lpos = temp.find("</html"); | 193 | int lpos = temp.find("</html"); |
185 | if (lpos > -1) { | 194 | if (lpos > -1) { |
186 | chmBuffer.truncate(lpos); | 195 | chmBuffer.truncate(lpos); |
187 | chmBuffer = chmBuffer+"</HTML>"; | 196 | chmBuffer = chmBuffer+"</HTML>"; |
188 | } | 197 | } |
189 | fsize = chmBuffer.length(); | 198 | fsize = chmBuffer.length(); |
190 | 199 | ||
191 | bufpos = 0; | 200 | bufpos = 0; |
192 | bRetVal = true; | 201 | bRetVal = true; |
193 | m_currentstart = m_ui.start; | 202 | m_currentstart = m_ui.start; |
194 | m_currentend = m_currentstart+chmBuffer.length(); | 203 | m_currentend = m_currentstart+chmBuffer.length(); |
195 | return bRetVal; | 204 | return bRetVal; |
196 | } | 205 | } |
197 | 206 | ||
198 | bool CHM::FillContent() { | 207 | bool CHM::FillContent() { |
208 | unsuspend(); | ||
199 | bool bRetVal = false; | 209 | bool bRetVal = false; |
200 | if (chmPath != "") { | 210 | if (chmPath != "") { |
201 | /* try to find the file */ | 211 | /* try to find the file */ |
202 | const char *filename = (const char *)chmPath; | 212 | const char *filename = (const char *)chmPath; |
203 | if (chm_resolve_object(chmFile, filename, &m_ui) != CHM_RESOLVE_SUCCESS) | 213 | if (chm_resolve_object(chmFile, filename, &m_ui) != CHM_RESOLVE_SUCCESS) |
204 | { | 214 | { |
205 | fsize = chmBuffer.length(); | 215 | fsize = chmBuffer.length(); |
206 | return bRetVal; | 216 | return bRetVal; |
207 | } | 217 | } |
208 | 218 | ||
209 | char buffer[65536]; | 219 | char buffer[65536]; |
210 | int swath, offset; | 220 | int swath, offset; |
211 | chmBuffer = ""; | 221 | chmBuffer = ""; |
212 | swath = 65536; | 222 | swath = 65536; |
213 | offset = 0; | 223 | offset = 0; |
214 | fsize = m_ui.length; | 224 | fsize = m_ui.length; |
@@ -226,33 +236,34 @@ bool CHM::FillContent() { | |||
226 | QString temp = chmBuffer.lower(); | 236 | QString temp = chmBuffer.lower(); |
227 | int lpos = temp.find("</html"); | 237 | int lpos = temp.find("</html"); |
228 | if (lpos > -1) { | 238 | if (lpos > -1) { |
229 | chmBuffer.truncate(lpos); | 239 | chmBuffer.truncate(lpos); |
230 | chmBuffer = chmBuffer+"</HTML>"; | 240 | chmBuffer = chmBuffer+"</HTML>"; |
231 | } | 241 | } |
232 | fsize = chmBuffer.length(); | 242 | fsize = chmBuffer.length(); |
233 | 243 | ||
234 | bufpos = 0; | 244 | bufpos = 0; |
235 | m_currentstart = m_ui.start; | 245 | m_currentstart = m_ui.start; |
236 | m_currentend = m_currentstart+chmBuffer.length(); | 246 | m_currentend = m_currentstart+chmBuffer.length(); |
237 | bRetVal = true; | 247 | bRetVal = true; |
238 | } | 248 | } |
239 | return bRetVal; | 249 | return bRetVal; |
240 | } | 250 | } |
241 | 251 | ||
242 | bool CHM::getFile(const QString& href) { | 252 | bool CHM::getFile(const QString& _href, const QString& ) { |
253 | QString href = "/" + _href; | ||
243 | qDebug("Got:%s", (const char*)href); | 254 | qDebug("Got:%s", (const char*)href); |
244 | bool bRetVal = false; | 255 | bool bRetVal = false; |
245 | QString temp = chmPath; | 256 | QString temp = chmPath; |
246 | chmPath = href; | 257 | chmPath = href; |
247 | if (FillContent()) { | 258 | if (FillContent()) { |
248 | qDebug("Got it"); | 259 | qDebug("Got it"); |
249 | bRetVal = true; | 260 | bRetVal = true; |
250 | } else { | 261 | } else { |
251 | qDebug("Missed"); | 262 | qDebug("Missed"); |
252 | chmPath = temp; | 263 | chmPath = temp; |
253 | FillContent(); | 264 | FillContent(); |
254 | } | 265 | } |
255 | return bRetVal; | 266 | return bRetVal; |
256 | } | 267 | } |
257 | 268 | ||
258 | QImage *CHM::getPicture(const QString& href) { | 269 | QImage *CHM::getPicture(const QString& href) { |