author | llornkcor <llornkcor> | 2002-12-20 01:35:01 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-12-20 01:35:01 (UTC) |
commit | 876e1a4724a7bd75dc642e295de354241096e028 (patch) (unidiff) | |
tree | a37c5dcc9d78e04bb6b859ab89d8cf81e6745087 /noncore/apps/opie-reader/plucker.cpp | |
parent | 5fd6636ba3d94b48dd543887316c47c5388a43c2 (diff) | |
download | opie-876e1a4724a7bd75dc642e295de354241096e028.zip opie-876e1a4724a7bd75dc642e295de354241096e028.tar.gz opie-876e1a4724a7bd75dc642e295de354241096e028.tar.bz2 |
update - sorry it took so long. hope this works correctly
Diffstat (limited to 'noncore/apps/opie-reader/plucker.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/plucker.cpp | 1280 |
1 files changed, 971 insertions, 309 deletions
diff --git a/noncore/apps/opie-reader/plucker.cpp b/noncore/apps/opie-reader/plucker.cpp index ddda4bc..eb039de 100644 --- a/noncore/apps/opie-reader/plucker.cpp +++ b/noncore/apps/opie-reader/plucker.cpp | |||
@@ -1,466 +1,956 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <string.h> | 2 | #include <string.h> |
3 | #include <qmessagebox.h> | 3 | #include <qmessagebox.h> |
4 | #include "plucker.h" | 4 | #include <qpixmap.h> |
5 | #include <qpe/qcopenvelope_qws.h> | ||
6 | #ifdef LOCALPICTURES | ||
7 | #include <qscrollview.h> | ||
8 | #endif | ||
9 | #include <qpe/global.h> | ||
10 | #include <qclipboard.h> | ||
11 | #include <qpe/qpeapplication.h> | ||
5 | 12 | ||
13 | #include "plucker.h" | ||
6 | #include "Aportis.h" | 14 | #include "Aportis.h" |
15 | #include "Palm2QImage.h" | ||
16 | #include "name.h" | ||
17 | |||
18 | CPlucker::CPlucker() : | ||
19 | #ifdef LOCALPICTURES | ||
20 | m_viewer(NULL), | ||
21 | m_picture(NULL), | ||
22 | #endif | ||
23 | expandedtextbuffer(NULL), | ||
24 | compressedtextbuffer(NULL), | ||
25 | urls(NULL) | ||
26 | { /*printf("constructing:%x\n",fin);*/ } | ||
7 | 27 | ||
8 | CPlucker::CPlucker() : expandedtextbuffer(NULL), compressedtextbuffer(NULL) { /*printf("constructing:%x\n",fin);*/ } | ||
9 | 28 | ||
29 | void CPlucker::Expand(UInt16 reclen, UInt8 type, UInt8* buffer, UInt16 buffersize) | ||
30 | { | ||
31 | if (type%2 == 0) | ||
32 | { | ||
33 | fread(buffer, reclen, sizeof(char), fin); | ||
34 | } | ||
35 | else | ||
36 | { | ||
37 | fread(compressedtextbuffer, reclen, sizeof(char), fin); | ||
38 | switch (ntohs(hdr0.version)) | ||
39 | { | ||
40 | case 2: | ||
41 | UnZip(reclen, buffer, buffersize); | ||
42 | break; | ||
43 | case 1: | ||
44 | UnDoc(reclen, buffer, buffersize); | ||
45 | break; | ||
46 | } | ||
47 | } | ||
48 | } | ||
10 | 49 | ||
11 | int CPlucker::openfile(const char *src) | 50 | int CPlucker::OpenFile(const char *src) |
12 | { | 51 | { |
52 | m_lastBreak = 0; | ||
13 | if (!Cpdb::openfile(src)) | 53 | if (!Cpdb::openfile(src)) |
14 | { | 54 | { |
15 | return -1; | 55 | return -1; |
16 | } | 56 | } |
17 | 57 | ||
18 | //printf("Okay %u\n", 4); | 58 | //printf("Okay %u\n", 4); |
19 | 59 | ||
20 | if (memcmp(&head.type, "DataPlkr", 8) != 0) return -1; | 60 | if (memcmp(&head.type, "DataPlkr", 8) != 0) return -1; |
21 | 61 | ||
22 | // qDebug("Cool - this IS plucker"); | 62 | // qDebug("Cool - this IS plucker"); |
23 | 63 | ||
24 | textlength = 0; | 64 | EOPPhase = 0; |
25 | for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | ||
26 | { | ||
27 | CPlucker_dataRecord thisHdr; | ||
28 | gotorecordnumber(recptr); | ||
29 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
30 | if (thisHdr.type < 2) textlength += htons(thisHdr.size); | ||
31 | } | ||
32 | |||
33 | gotorecordnumber(0); | 65 | gotorecordnumber(0); |
34 | fread(&hdr0, 1, sizeof(hdr0), fin); | 66 | fread(&hdr0, 1, sizeof(hdr0), fin); |
35 | //printf("Okay %u\n", 5); | 67 | //printf("Okay %u\n", 5); |
36 | buffersize = 32*1024; | 68 | buffersize = 32*1024; |
37 | compressedtextbuffer = new UInt8[buffersize]; | 69 | compressedtextbuffer = new UInt8[buffersize]; |
38 | expandedtextbuffer = new UInt8[buffersize]; | 70 | expandedtextbuffer = new UInt8[buffersize]; |
39 | 71 | ||
40 | // qDebug("Total number of records:%u", ntohs(head.recordList.numRecords)); | 72 | qDebug("Total number of records:%u", ntohs(head.recordList.numRecords)); |
41 | 73 | ||
42 | unsigned int nrecs = ntohs(hdr0.nRecords); | 74 | unsigned int nrecs = ntohs(hdr0.nRecords); |
43 | // qDebug("Version %u, no. res %u", ntohs(hdr0.version), nrecs); | 75 | qDebug("Version %u, no. recs %u", ntohs(hdr0.version), nrecs); |
44 | for (unsigned int i = 0; i < 4*nrecs; i++) | 76 | UInt16 homerecid = 1; |
77 | UInt16 urlid = 0; | ||
78 | bool urlsfound = false; | ||
79 | for (unsigned int i = 0; i < nrecs; i++) | ||
45 | { | 80 | { |
46 | UInt8 id; | 81 | UInt16 id, name; |
47 | fread(&id, 1, sizeof(id), fin); | 82 | fread(&name, 1, sizeof(name), fin); |
48 | // qDebug("%x", id); | 83 | fread(&id, 1, sizeof(id), fin); |
84 | qDebug("N:%d, I:%d", ntohs(name), ntohs(id)); | ||
85 | if (ntohs(name) == 0) homerecid = ntohs(id); | ||
86 | if (ntohs(name) == 2) | ||
87 | { | ||
88 | urlsfound = true; | ||
89 | urlid = id; | ||
90 | qDebug("Found url index:%d", ntohs(urlid)); | ||
91 | } | ||
92 | //qDebug("%x", id); | ||
49 | } | 93 | } |
94 | |||
95 | textlength = 0; | ||
96 | for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | ||
97 | { | ||
98 | CPlucker_dataRecord thisHdr; | ||
99 | gotorecordnumber(recptr); | ||
100 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
101 | if (ntohs(thisHdr.uid) == homerecid) | ||
102 | { | ||
103 | m_homepos = textlength; | ||
104 | qDebug("Home pos found after %u records", recptr); | ||
105 | break; | ||
106 | } | ||
107 | if (thisHdr.type < 2) textlength += ntohs(thisHdr.size); | ||
108 | } | ||
109 | textlength = 0; | ||
110 | |||
111 | if (urlsfound) | ||
112 | { | ||
113 | unsigned short recptr = finduid(ntohs(urlid)); | ||
114 | if (recptr != 0) | ||
115 | { | ||
116 | CPlucker_dataRecord thisHdr; | ||
117 | gotorecordnumber(recptr); | ||
118 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
119 | fread(&urlid, 1, sizeof(urlid), fin); | ||
120 | fread(&urlid, 1, sizeof(urlid), fin); | ||
121 | qDebug("urls are in %d", ntohs(urlid)); | ||
122 | recptr = finduid(ntohs(urlid)); | ||
123 | if (recptr != 0) | ||
124 | { | ||
125 | gotorecordnumber(recptr); | ||
126 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
127 | qDebug("Found urls:%x",thisHdr.type); | ||
128 | UInt16 reclen = recordlength(recptr) - sizeof(thisHdr); | ||
129 | gotorecordnumber(recptr); | ||
130 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
131 | urlsize = ntohs(thisHdr.size); | ||
132 | urls = new char[urlsize]; | ||
133 | Expand(reclen, thisHdr.type, (UInt8*)urls, urlsize); | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | /* | ||
138 | for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | ||
139 | { | ||
140 | CPlucker_dataRecord thisHdr; | ||
141 | gotorecordnumber(recptr); | ||
142 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
143 | if (thisHdr.uid == urlid) | ||
144 | { | ||
145 | qDebug("Found urls:%x",thisHdr.type); | ||
146 | UInt16 reclen = recordlength(recptr) - sizeof(thisHdr); | ||
147 | gotorecordnumber(recptr); | ||
148 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
149 | urlsize = ntohs(thisHdr.size); | ||
150 | urls = new char[urlsize]; | ||
151 | Expand(reclen, thisHdr.type, (UInt8*)urls, urlsize); | ||
152 | break; | ||
153 | } | ||
154 | } | ||
155 | */ | ||
50 | home(); | 156 | home(); |
157 | #ifdef LOCALPICTURES | ||
158 | if (m_viewer == NULL) | ||
159 | { | ||
160 | m_viewer = new QScrollView(NULL); | ||
161 | m_picture = new QWidget(m_viewer->viewport()); | ||
162 | m_viewer->addChild(m_picture); | ||
163 | } | ||
164 | #endif | ||
51 | return 0; | 165 | return 0; |
166 | |||
167 | } | ||
168 | |||
169 | void CPlucker::sizes(unsigned long& _file, unsigned long& _text) | ||
170 | { | ||
171 | qDebug("Sizes called:%u",textlength); | ||
172 | _file = file_length; | ||
173 | if (textlength == 0) | ||
174 | { | ||
175 | for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | ||
176 | { | ||
177 | CPlucker_dataRecord thisHdr; | ||
178 | gotorecordnumber(recptr); | ||
179 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
180 | if (thisHdr.type < 2) textlength += ntohs(thisHdr.size); | ||
181 | } | ||
182 | } | ||
183 | _text = textlength; | ||
184 | //ntohl(hdr0.size); | ||
185 | } | ||
186 | |||
187 | |||
188 | char* CPlucker::geturl(UInt16 i) | ||
189 | { | ||
190 | if (urls == NULL) return NULL; | ||
191 | char* ptr = urls; | ||
192 | int rn = 1; | ||
193 | while (ptr - urls < urlsize) | ||
194 | { | ||
195 | if (rn == i) return ptr; | ||
196 | ptr += strlen(ptr)+1; | ||
197 | rn++; | ||
198 | } | ||
199 | return NULL; | ||
200 | } | ||
201 | |||
202 | CPlucker::~CPlucker() | ||
203 | { | ||
204 | if (expandedtextbuffer != NULL) delete [] expandedtextbuffer; | ||
205 | if (compressedtextbuffer != NULL) delete [] compressedtextbuffer; | ||
206 | if (urls != NULL) delete [] urls; | ||
207 | #ifdef LOCALPICTURES | ||
208 | if (m_viewer != NULL) delete m_viewer; | ||
209 | #endif | ||
52 | } | 210 | } |
53 | 211 | ||
54 | int CPlucker::bgetch() | 212 | int CPlucker::bgetch() |
55 | { | 213 | { |
56 | int ch = EOF; | 214 | int ch = EOF; |
57 | if (bufferpos >= buffercontent) | 215 | if (bufferpos >= buffercontent) |
58 | { | 216 | { |
59 | if (bufferrec >= ntohs(head.recordList.numRecords) - 1) return EOF; | 217 | if (!m_continuous) return EOF; |
60 | // qDebug("Passing through %u", currentpos); | 218 | if (bufferrec >= ntohs(head.recordList.numRecords) - 1) return EOF; |
61 | if (!expand(bufferrec+1)) return EOF; | 219 | //qDebug("Passing through %u", currentpos); |
62 | mystyle.unset(); | 220 | if (!expand(bufferrec+1)) return EOF; |
221 | mystyle.unset(); | ||
222 | ch = 10; | ||
223 | EOPPhase = 4; | ||
63 | } | 224 | } |
64 | 225 | else if (bufferpos == m_nextPara) | |
65 | if (bufferpos == m_nextPara) | ||
66 | { | 226 | { |
67 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; | 227 | while (bufferpos == m_nextPara) |
68 | m_nextParaIndex++; | 228 | { |
69 | if (m_nextParaIndex == m_nParas) | 229 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; |
70 | { | 230 | m_nextParaIndex++; |
71 | m_nextPara = -1; | 231 | if (m_nextParaIndex == m_nParas) |
72 | } | 232 | { |
73 | else | 233 | m_nextPara = -1; |
74 | { | 234 | } |
75 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; | 235 | else |
76 | } | 236 | { |
77 | // qDebug("New paragraph"); | 237 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; |
78 | ch = 10; | 238 | } |
239 | } | ||
240 | mystyle.unset(); | ||
241 | if (m_lastBreak == locate()) | ||
242 | { | ||
243 | currentpos++; | ||
244 | ch = expandedtextbuffer[bufferpos++]; | ||
245 | } | ||
246 | else | ||
247 | { | ||
248 | ch = 10; | ||
249 | } | ||
79 | } | 250 | } |
80 | else | 251 | else |
81 | { | 252 | { |
82 | currentpos++; | 253 | currentpos++; |
83 | ch = expandedtextbuffer[bufferpos++]; | 254 | ch = expandedtextbuffer[bufferpos++]; |
84 | } | 255 | } |
85 | return ch; | 256 | return ch; |
86 | } | 257 | } |
87 | 258 | ||
88 | int CPlucker::getch() | 259 | int CPlucker::getch() |
89 | { | 260 | { |
90 | int ch = bgetch(); | 261 | mystyle.clearPicture(); |
91 | while (ch == 0) | 262 | |
92 | { | 263 | |
93 | ch = bgetch(); | 264 | if (EOPPhase > 0) |
94 | // qDebug("Function:%x", ch); | ||
95 | switch (ch) | ||
96 | { | ||
97 | case 0x38: | ||
98 | ch = 10; | ||
99 | break; | ||
100 | case 0x0a: | ||
101 | case 0x0c: | ||
102 | { | ||
103 | unsigned long ln = 0; | ||
104 | int skip = ch & 7; | ||
105 | for (int i = 0; i < 2; i++) | ||
106 | { | 265 | { |
107 | int ch = bgetch(); | 266 | int ch = 10; |
108 | ln = (ln << 8) + ch; | 267 | switch (EOPPhase) |
109 | // qDebug("ch:%d, ln:%u", ch, ln); | 268 | { |
269 | case 4: | ||
270 | mystyle.setPicture(hRule(100,5)); | ||
271 | mystyle.setCentreJustify(); | ||
272 | ch = '#'; | ||
273 | break; | ||
274 | case 3: | ||
275 | mystyle.setFontSize(3); | ||
276 | ch = 10; | ||
277 | break; | ||
278 | case 2: | ||
279 | ch = 10; | ||
280 | break; | ||
281 | case 1: | ||
282 | mystyle.unset(); | ||
283 | default: | ||
284 | ch = 10; | ||
285 | } | ||
286 | EOPPhase--; | ||
287 | return ch; | ||
110 | } | 288 | } |
111 | if (skip == 2) | 289 | |
290 | |||
291 | int ch = bgetch(); | ||
292 | while (ch == 0) | ||
112 | { | 293 | { |
113 | ln <<= 16; | 294 | ch = bgetch(); |
295 | //qDebug("Function:%x", ch); | ||
296 | switch (ch) | ||
297 | { | ||
298 | case 0x38: | ||
299 | // qDebug("Break:%u", locate()); | ||
300 | if (m_lastBreak == locate()) | ||
301 | { | ||
302 | ch = bgetch(); | ||
303 | } | ||
304 | else | ||
305 | { | ||
306 | ch = 10; | ||
307 | } | ||
308 | m_lastBreak = locate(); | ||
309 | break; | ||
310 | case 0x0a: | ||
311 | case 0x0c: | ||
312 | { | ||
313 | unsigned long ln = 0; | ||
314 | int skip = ch & 7; | ||
315 | for (int i = 0; i < 2; i++) | ||
316 | { | ||
317 | int ch = bgetch(); | ||
318 | ln = (ln << 8) + ch; | ||
319 | // qDebug("ch:%d, ln:%u", ch, ln); | ||
320 | } | ||
321 | if (skip == 2) | ||
322 | { | ||
323 | ln <<= 16; | ||
324 | } | ||
325 | else | ||
326 | { | ||
327 | for (int i = 0; i < 2; i++) | ||
328 | { | ||
329 | int ch = bgetch(); | ||
330 | ln = (ln << 8) + ch; | ||
331 | // qDebug("ch:%d, ln:%u", ch, ln); | ||
332 | } | ||
333 | } | ||
334 | // qDebug("ln:%u", ln); | ||
335 | mystyle.setLink(true); | ||
336 | mystyle.setData(ln); | ||
337 | // mystyle.setColour(255, 0, 0); | ||
338 | bool hasseen = false; | ||
339 | for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) | ||
340 | { | ||
341 | if (*it == ln) | ||
342 | { | ||
343 | hasseen = true; | ||
344 | break; | ||
345 | } | ||
346 | } | ||
347 | if (hasseen) | ||
348 | { | ||
349 | mystyle.setStrikethru(); | ||
350 | } | ||
351 | else | ||
352 | { | ||
353 | mystyle.setUnderline(); | ||
354 | } | ||
355 | ch = bgetch(); | ||
356 | } | ||
357 | break; | ||
358 | case 0x08: | ||
359 | ch = bgetch(); | ||
360 | // mystyle.setColour(0, 0, 0); | ||
361 | mystyle.unsetUnderline(); | ||
362 | mystyle.unsetStrikethru(); | ||
363 | mystyle.setLink(false); | ||
364 | mystyle.setData(0); | ||
365 | break; | ||
366 | case 0x40: | ||
367 | mystyle.setItalic(); | ||
368 | ch = bgetch(); | ||
369 | break; | ||
370 | case 0x48: | ||
371 | mystyle.unsetItalic(); | ||
372 | ch = bgetch(); | ||
373 | break; | ||
374 | case 0x11: | ||
375 | { | ||
376 | ch = bgetch(); | ||
377 | // qDebug("Font:%d",ch); | ||
378 | switch (ch) | ||
379 | { | ||
380 | case 0: | ||
381 | mystyle.unsetMono(); | ||
382 | mystyle.unsetBold(); | ||
383 | mystyle.setFontSize(0); | ||
384 | break; | ||
385 | case 1: | ||
386 | mystyle.unsetMono(); | ||
387 | mystyle.setBold(); | ||
388 | mystyle.setFontSize(3); | ||
389 | break; | ||
390 | case 2: | ||
391 | mystyle.unsetMono(); | ||
392 | mystyle.setBold(); | ||
393 | mystyle.setFontSize(2); | ||
394 | break; | ||
395 | case 3: | ||
396 | mystyle.unsetMono(); | ||
397 | mystyle.setBold(); | ||
398 | // mystyle.unsetBold(); | ||
399 | mystyle.setFontSize(1); | ||
400 | break; | ||
401 | case 4: | ||
402 | mystyle.unsetMono(); | ||
403 | mystyle.setBold(); | ||
404 | // mystyle.unsetBold(); | ||
405 | mystyle.setFontSize(0); | ||
406 | break; | ||
407 | case 5: | ||
408 | mystyle.unsetMono(); | ||
409 | mystyle.setBold(); | ||
410 | mystyle.setFontSize(0); | ||
411 | break; | ||
412 | case 6: | ||
413 | mystyle.unsetMono(); | ||
414 | mystyle.setBold(); | ||
415 | mystyle.setFontSize(0); | ||
416 | break; | ||
417 | case 7: | ||
418 | mystyle.unsetMono(); | ||
419 | mystyle.setBold(); | ||
420 | mystyle.setFontSize(0); | ||
421 | break; | ||
422 | case 8: // should be fixed width | ||
423 | qDebug("Trying fixed width"); | ||
424 | mystyle.unsetBold(); | ||
425 | mystyle.setFontSize(0); | ||
426 | mystyle.setMono(); | ||
427 | break; | ||
428 | default: | ||
429 | mystyle.unsetBold(); | ||
430 | mystyle.unsetMono(); | ||
431 | mystyle.setFontSize(0); | ||
432 | break; | ||
433 | } | ||
434 | ch = bgetch(); | ||
435 | } | ||
436 | break; | ||
437 | case 0x29: | ||
438 | ch = bgetch(); | ||
439 | switch (ch) | ||
440 | { | ||
441 | case 0: | ||
442 | mystyle.setLeftJustify(); | ||
443 | // qDebug("left"); | ||
444 | break; | ||
445 | case 1: | ||
446 | mystyle.setRightJustify(); | ||
447 | // qDebug("right"); | ||
448 | break; | ||
449 | case 2: | ||
450 | mystyle.setCentreJustify(); | ||
451 | // qDebug("centre"); | ||
452 | break; | ||
453 | case 3: | ||
454 | mystyle.setFullJustify(); | ||
455 | // qDebug("full"); | ||
456 | break; | ||
457 | |||
458 | } | ||
459 | ch = bgetch(); | ||
460 | break; | ||
461 | case 0x53: | ||
462 | { | ||
463 | int r = bgetch(); | ||
464 | int g = bgetch(); | ||
465 | int b = bgetch(); | ||
466 | mystyle.setColour(r,g,b); | ||
467 | ch = bgetch(); | ||
468 | } | ||
469 | break; | ||
470 | case 0x1a: | ||
471 | case 0x5c: | ||
472 | { | ||
473 | bool hasalternate = (ch == 0x5c); | ||
474 | UInt16 ir = bgetch(); | ||
475 | ir = (ir << 8) + bgetch(); | ||
476 | if (hasalternate) | ||
477 | { | ||
478 | qDebug("Alternate image:%x", ir); | ||
479 | UInt16 ir2 = bgetch(); | ||
480 | ir2 = (ir2 << 8) + bgetch(); | ||
481 | mystyle.setPicture(expandimg(ir2, true), true, ir); | ||
482 | #ifdef LOCALPICTURES | ||
483 | UInt32 ln = ir; | ||
484 | ln <<= 16; | ||
485 | mystyle.setLink(true); | ||
486 | mystyle.setData(ln); | ||
487 | #endif | ||
488 | } | ||
489 | else | ||
490 | { | ||
491 | mystyle.setPicture(expandimg(ir)); | ||
492 | } | ||
493 | if (mystyle.getLink()) qDebug("Picture link!"); | ||
494 | ch = '#'; | ||
495 | } | ||
496 | // ch = bgetch(); | ||
497 | break; | ||
498 | case 0x33: | ||
499 | { | ||
500 | UInt8 h = bgetch(); | ||
501 | UInt8 wc = bgetch(); | ||
502 | UInt8 pc = bgetch(); | ||
503 | UInt16 w = wc; | ||
504 | // qDebug("h,w,pc [%u, %u, %u]", h, w, pc); | ||
505 | if (w == 0) | ||
506 | { | ||
507 | w = (240*(unsigned long)pc)/100; | ||
508 | } | ||
509 | if (w == 0) w = 320; | ||
510 | mystyle.setPicture(hRule(w,h,mystyle.Red(),mystyle.Green(),mystyle.Blue())); | ||
511 | // if (mystyle.getLink()) qDebug("hRule link!"); | ||
512 | ch = '#'; | ||
513 | } | ||
514 | break; | ||
515 | case 0x60: | ||
516 | mystyle.setUnderline(); | ||
517 | ch = bgetch(); | ||
518 | break; | ||
519 | case 0x68: | ||
520 | mystyle.unsetUnderline(); | ||
521 | ch = bgetch(); | ||
522 | break; | ||
523 | case 0x22: | ||
524 | ch = bgetch(); | ||
525 | mystyle.setLeftMargin(ch); | ||
526 | // qDebug("Left margin:%d", ch); | ||
527 | ch = bgetch(); | ||
528 | mystyle.setRightMargin(ch); | ||
529 | // qDebug("Right margin:%d", ch); | ||
530 | ch = bgetch(); | ||
531 | break; | ||
532 | case 0x70: | ||
533 | mystyle.setStrikethru(); | ||
534 | ch = bgetch(); | ||
535 | break; | ||
536 | case 0x78: | ||
537 | mystyle.unsetStrikethru(); | ||
538 | ch = bgetch(); | ||
539 | break; | ||
540 | case 0x83: | ||
541 | case 0x85: | ||
542 | default: | ||
543 | qDebug("Function:%x NOT IMPLEMENTED", ch); | ||
544 | { | ||
545 | int skip = ch & 7; | ||
546 | for (int i = 0; i < skip; i++) | ||
547 | { | ||
548 | ch = bgetch(); | ||
549 | // qDebug("Arg %d, %d", i, ch); | ||
550 | } | ||
551 | ch = bgetch(); | ||
552 | } | ||
553 | } | ||
114 | } | 554 | } |
115 | else | 555 | |
556 | if (m_lastIsBreak && !mystyle.isMono()) | ||
116 | { | 557 | { |
117 | for (int i = 0; i < 2; i++) | 558 | while (ch == ' ') |
118 | { | 559 | { |
119 | int ch = bgetch(); | 560 | ch = getch(); |
120 | ln = (ln << 8) + ch; | 561 | } |
121 | // qDebug("ch:%d, ln:%u", ch, ln); | ||
122 | } | ||
123 | } | ||
124 | // qDebug("ln:%u", ln); | ||
125 | mystyle.setLink(true); | ||
126 | mystyle.setData(ln); | ||
127 | mystyle.setColour(255, 0, 0); | ||
128 | ch = bgetch(); | ||
129 | } | ||
130 | break; | ||
131 | case 0x08: | ||
132 | ch = bgetch(); | ||
133 | mystyle.setColour(0, 0, 0); | ||
134 | mystyle.setLink(false); | ||
135 | mystyle.setData(0); | ||
136 | break; | ||
137 | case 0x40: | ||
138 | mystyle.setItalic(); | ||
139 | ch = bgetch(); | ||
140 | break; | ||
141 | case 0x48: | ||
142 | mystyle.unsetItalic(); | ||
143 | ch = bgetch(); | ||
144 | break; | ||
145 | case 0x11: | ||
146 | { | ||
147 | ch = bgetch(); | ||
148 | qDebug("Font:%d",ch); | ||
149 | switch (ch) | ||
150 | { | ||
151 | case 0: | ||
152 | mystyle.unsetBold(); | ||
153 | mystyle.setFontSize(0); | ||
154 | break; | ||
155 | case 1: | ||
156 | mystyle.setBold(); | ||
157 | mystyle.setFontSize(1); | ||
158 | break; | ||
159 | case 2: | ||
160 | mystyle.setBold(); | ||
161 | mystyle.setFontSize(1); | ||
162 | break; | ||
163 | case 3: | ||
164 | // mystyle.setBold(); | ||
165 | mystyle.setFontSize(1); | ||
166 | break; | ||
167 | case 4: | ||
168 | // mystyle.setBold(); | ||
169 | mystyle.setFontSize(1); | ||
170 | break; | ||
171 | case 5: | ||
172 | mystyle.setBold(); | ||
173 | mystyle.setFontSize(0); | ||
174 | break; | ||
175 | case 6: | ||
176 | mystyle.setBold(); | ||
177 | mystyle.setFontSize(0); | ||
178 | break; | ||
179 | case 7: | ||
180 | mystyle.setBold(); | ||
181 | mystyle.setFontSize(0); | ||
182 | break; | ||
183 | case 8: // should be fixed width | ||
184 | mystyle.unsetBold(); | ||
185 | mystyle.setFontSize(0); | ||
186 | break; | ||
187 | default: | ||
188 | mystyle.unsetBold(); | ||
189 | mystyle.setFontSize(0); | ||
190 | break; | ||
191 | } | ||
192 | ch = bgetch(); | ||
193 | } | ||
194 | break; | ||
195 | case 0x29: | ||
196 | ch = bgetch(); | ||
197 | switch (ch) | ||
198 | { | ||
199 | case 0: | ||
200 | mystyle.setLeftJustify(); | ||
201 | // qDebug("left"); | ||
202 | break; | ||
203 | case 1: | ||
204 | mystyle.setRightJustify(); | ||
205 | // qDebug("right"); | ||
206 | break; | ||
207 | case 2: | ||
208 | mystyle.setCentreJustify(); | ||
209 | // qDebug("centre"); | ||
210 | break; | ||
211 | case 3: | ||
212 | mystyle.setFullJustify(); | ||
213 | // qDebug("full"); | ||
214 | break; | ||
215 | |||
216 | } | ||
217 | ch = bgetch(); | ||
218 | break; | ||
219 | case 0x53: | ||
220 | { | ||
221 | int r = bgetch(); | ||
222 | int g = bgetch(); | ||
223 | int b = bgetch(); | ||
224 | mystyle.setColour(r,g,b); | ||
225 | ch = bgetch(); | ||
226 | } | ||
227 | break; | ||
228 | case 0x1a: | ||
229 | /* | ||
230 | { | ||
231 | UInt16 ir = bgetch(); | ||
232 | ir = (ir << 8) + bgetch(); | ||
233 | expandimg(ir); | ||
234 | } | ||
235 | ch = bgetch(); | ||
236 | break; | ||
237 | */ | ||
238 | case 0x33: | ||
239 | case 0x22: | ||
240 | case 0x5c: | ||
241 | case 0x60: | ||
242 | case 0x68: | ||
243 | case 0x70: | ||
244 | case 0x78: | ||
245 | case 0x83: | ||
246 | case 0x85: | ||
247 | default: | ||
248 | qDebug("Function:%x NOT IMPLEMENTED", ch); | ||
249 | { | ||
250 | int skip = ch & 7; | ||
251 | for (int i = 0; i < skip; i++) | ||
252 | { | ||
253 | ch = bgetch(); | ||
254 | qDebug("Arg %d, %d", i, ch); | ||
255 | } | ||
256 | ch = bgetch(); | ||
257 | } | ||
258 | } | ||
259 | } | 562 | } |
563 | |||
564 | m_lastIsBreak = (ch == 10); | ||
565 | |||
260 | return ch; | 566 | return ch; |
261 | } | 567 | } |
262 | 568 | ||
263 | void CPlucker::getch(int& ch, CStyle& sty) | 569 | void CPlucker::getch(int& ch, CStyle& sty) |
264 | { | 570 | { |
265 | ch = getch(); | 571 | ch = getch(); |
266 | sty = mystyle; | 572 | sty = mystyle; |
267 | } | 573 | } |
268 | 574 | ||
269 | unsigned int CPlucker::locate() | 575 | unsigned int CPlucker::locate() |
270 | { | 576 | { |
271 | return currentpos; | 577 | return currentpos; |
272 | /* | 578 | /* |
273 | UInt16 thisrec = 1; | 579 | UInt16 thisrec = 1; |
274 | unsigned long locpos = 0; | 580 | unsigned long locpos = 0; |
275 | gotorecordnumber(thisrec); | 581 | gotorecordnumber(thisrec); |
276 | CPlucker_dataRecord thisHdr; | 582 | CPlucker_dataRecord thisHdr; |
277 | while (thisrec < bufferrec) | 583 | while (thisrec < bufferrec) |
278 | { | 584 | { |
279 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | 585 | fread(&thisHdr, 1, sizeof(thisHdr), fin); |
280 | if (thisHdr.type < 2) locpos += htons(thisHdr.size); | 586 | if (thisHdr.type < 2) locpos += ntohs(thisHdr.size); |
281 | thisrec++; | 587 | thisrec++; |
282 | gotorecordnumber(thisrec); | 588 | gotorecordnumber(thisrec); |
283 | } | 589 | } |
284 | return locpos+bufferpos; | 590 | return locpos+bufferpos; |
285 | */ | 591 | */ |
286 | } | 592 | } |
287 | 593 | ||
288 | void CPlucker::locate(unsigned int n) | 594 | void CPlucker::locate(unsigned int n) |
289 | { | 595 | { |
290 | UInt16 thisrec = 0; | 596 | UInt16 thisrec = 0; |
291 | unsigned long locpos = 0; | 597 | unsigned long locpos = 0; |
292 | unsigned long bs = 0; | 598 | unsigned long bs = 0; |
293 | CPlucker_dataRecord thisHdr; | 599 | CPlucker_dataRecord thisHdr; |
294 | do | 600 | do |
295 | { | 601 | { |
296 | thisrec++; | 602 | thisrec++; |
297 | locpos += bs; | 603 | locpos += bs; |
298 | gotorecordnumber(thisrec); | 604 | gotorecordnumber(thisrec); |
299 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | 605 | fread(&thisHdr, 1, sizeof(thisHdr), fin); |
300 | if (thisHdr.type < 2) | 606 | if (thisHdr.type < 2) |
301 | { | 607 | { |
302 | bs = htons(thisHdr.size); | 608 | bs = ntohs(thisHdr.size); |
303 | } | 609 | } |
304 | else | 610 | else |
305 | { | 611 | { |
306 | bs = 0; | 612 | bs = 0; |
307 | } | 613 | } |
308 | } while (locpos + bs < n); | 614 | } while (locpos + bs <= n); |
309 | currentpos = locpos; | 615 | currentpos = locpos; |
310 | expand(thisrec); | 616 | expand(thisrec); |
617 | #ifdef _FAST | ||
311 | while (currentpos < n && bufferpos < buffercontent) bgetch(); | 618 | while (currentpos < n && bufferpos < buffercontent) bgetch(); |
619 | #else | ||
620 | while (currentpos < n && bufferpos < buffercontent) getch(); | ||
621 | #endif | ||
312 | } | 622 | } |
313 | 623 | ||
314 | bool CPlucker::hyperlink(unsigned int n) | 624 | bool CPlucker::hyperlink(unsigned int n) |
315 | { | 625 | { |
626 | visited.push_front(n); | ||
316 | UInt16 tuid = (n >> 16); | 627 | UInt16 tuid = (n >> 16); |
317 | n &= 0xffff; | 628 | n &= 0xffff; |
629 | // qDebug("Hyper:<%u,%u>", tuid, n); | ||
318 | UInt16 thisrec = 1; | 630 | UInt16 thisrec = 1; |
319 | currentpos = 0; | 631 | currentpos = 0; |
320 | gotorecordnumber(thisrec); | 632 | gotorecordnumber(thisrec); |
321 | CPlucker_dataRecord thisHdr; | 633 | CPlucker_dataRecord thisHdr; |
322 | while (1) | 634 | while (1) |
323 | { | 635 | { |
324 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | 636 | fread(&thisHdr, 1, sizeof(thisHdr), fin); |
325 | if (tuid <= htons(thisHdr.uid)) break; | 637 | if (tuid == ntohs(thisHdr.uid)) break; |
326 | if (thisHdr.type < 2) currentpos += htons(thisHdr.size); | 638 | if (thisHdr.type < 2) currentpos += ntohs(thisHdr.size); |
327 | // qDebug("hyper-cp:%u", currentpos); | 639 | //qDebug("hyper-cp:%u", currentpos); |
328 | thisrec++; | 640 | thisrec++; |
329 | gotorecordnumber(thisrec); | 641 | if (thisrec >= ntohs(head.recordList.numRecords)) |
642 | { | ||
643 | if (urls == NULL) | ||
644 | { | ||
645 | QMessageBox::information(NULL, | ||
646 | PROGNAME, | ||
647 | QString("No external links\nin this pluck") | ||
648 | ); | ||
649 | } | ||
650 | else | ||
651 | { | ||
652 | char *turl = geturl(tuid); | ||
653 | if (turl == NULL) | ||
654 | { | ||
655 | QMessageBox::information(NULL, | ||
656 | PROGNAME, | ||
657 | QString("Couldn't find link") | ||
658 | ); | ||
659 | } | ||
660 | else | ||
661 | { | ||
662 | QString wrd(turl); | ||
663 | QClipboard* cb = QApplication::clipboard(); | ||
664 | cb->setText(wrd); | ||
665 | if (wrd.length() > 10) | ||
666 | { | ||
667 | Global::statusMessage(wrd.left(8) + ".."); | ||
668 | } | ||
669 | } | ||
670 | } | ||
671 | return false; | ||
672 | } | ||
673 | gotorecordnumber(thisrec); | ||
330 | } | 674 | } |
331 | if (thisHdr.type > 1) | 675 | if (thisHdr.type > 1) |
332 | { | 676 | { |
333 | QMessageBox::information(NULL, | 677 | if (thisHdr.type == 4) |
334 | QString("OpieReader"), | 678 | { |
335 | QString("External links\nnot yet supported") | 679 | QMessageBox::information(NULL, |
336 | ); | 680 | PROGNAME, |
337 | return false; | 681 | QString("Mailto links\nnot yet supported (2)")); |
682 | } | ||
683 | else | ||
684 | { | ||
685 | #ifdef LOCALPICTURES | ||
686 | if (thisHdr.type > 3) | ||
687 | { | ||
688 | #endif | ||
689 | QMessageBox::information(NULL, | ||
690 | PROGNAME, | ||
691 | QString("External links\nnot yet supported (2)") | ||
692 | ); | ||
693 | #ifdef LOCALPICTURES | ||
694 | } | ||
695 | else | ||
696 | { | ||
697 | showimg(tuid); | ||
698 | } | ||
699 | #endif | ||
700 | } | ||
701 | return false; | ||
702 | } | ||
703 | /* | ||
704 | if (thisHdr.type == 2 || thisHdr.type == 3) | ||
705 | { | ||
706 | expandimg(thisrec); | ||
707 | |||
338 | } | 708 | } |
709 | */ | ||
339 | else | 710 | else |
340 | { | 711 | { |
341 | expand(thisrec); | 712 | expand(thisrec); |
342 | while (bufferpos < n && bufferpos < buffercontent) getch(); | 713 | if (n != 0) |
714 | { | ||
715 | if (n >= m_nParas) | ||
716 | { | ||
717 | QMessageBox::information(NULL, | ||
718 | PROGNAME, | ||
719 | QString("Error in link\nPara # too big") | ||
720 | ); | ||
721 | return false; | ||
722 | } | ||
723 | unsigned int noff = 0; | ||
724 | for (int i = 0; i < n; i++) noff += m_ParaOffsets[i]; | ||
725 | n = noff; | ||
726 | } | ||
727 | if (n > ntohs(thisHdr.size)) | ||
728 | { | ||
729 | QMessageBox::information(NULL, | ||
730 | PROGNAME, | ||
731 | QString("Error in link\nOffset too big") | ||
732 | ); | ||
733 | return false; | ||
734 | } | ||
735 | qDebug("Hyper:<%u,%u>", tuid, n); | ||
736 | while (bufferpos < n && bufferpos < buffercontent) getch(); | ||
343 | } | 737 | } |
344 | return true; | 738 | return true; |
345 | } | 739 | } |
740 | /* | ||
741 | bool CPlucker::hyperlink(unsigned int n) | ||
742 | { | ||
743 | visited.push_front(n); | ||
744 | UInt16 tuid = (n >> 16); | ||
745 | n &= 0xffff; | ||
746 | // qDebug("Hyper:<%u,%u>", tuid, n); | ||
747 | UInt16 thisrec = finduid(tuid); | ||
748 | if (thisrec == 0) | ||
749 | { | ||
750 | if (urls == NULL) | ||
751 | { | ||
752 | QMessageBox::information(NULL, | ||
753 | PROGNAME, | ||
754 | QString("No external links\nin this pluck") | ||
755 | ); | ||
756 | } | ||
757 | else | ||
758 | { | ||
759 | char *turl = geturl(tuid); | ||
760 | if (turl == NULL) | ||
761 | { | ||
762 | QMessageBox::information(NULL, | ||
763 | PROGNAME, | ||
764 | QString("Couldn't find link") | ||
765 | ); | ||
766 | } | ||
767 | else | ||
768 | { | ||
769 | QString wrd(turl); | ||
770 | QClipboard* cb = QApplication::clipboard(); | ||
771 | cb->setText(wrd); | ||
772 | if (wrd.length() > 10) | ||
773 | { | ||
774 | Global::statusMessage(wrd.left(8) + ".."); | ||
775 | } | ||
776 | } | ||
777 | } | ||
778 | return false; | ||
779 | } | ||
780 | else | ||
781 | { | ||
782 | currentpos = 0; | ||
783 | gotorecordnumber(thisrec); | ||
784 | CPlucker_dataRecord thisHdr; | ||
785 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
346 | 786 | ||
787 | if (thisHdr.type > 1) | ||
788 | { | ||
789 | if (thisHdr.type == 4) | ||
790 | { | ||
791 | QMessageBox::information(NULL, | ||
792 | PROGNAME, | ||
793 | QString("Mailto links\nnot yet supported (2)")); | ||
794 | } | ||
795 | else | ||
796 | { | ||
797 | #ifdef LOCALPICTURES | ||
798 | if (thisHdr.type > 3) | ||
799 | { | ||
800 | #endif | ||
801 | QMessageBox::information(NULL, | ||
802 | PROGNAME, | ||
803 | QString("External links\nnot yet supported (2)") | ||
804 | ); | ||
805 | #ifdef LOCALPICTURES | ||
806 | } | ||
807 | else | ||
808 | { | ||
809 | showimg(tuid); | ||
810 | } | ||
811 | #endif | ||
812 | } | ||
813 | return false; | ||
814 | } | ||
815 | // if (thisHdr.type == 2 || thisHdr.type == 3) | ||
816 | // { | ||
817 | // expandimg(thisrec); | ||
818 | // } | ||
819 | else | ||
820 | { | ||
821 | expand(thisrec); | ||
822 | if (n != 0) | ||
823 | { | ||
824 | if (n >= m_nParas) | ||
825 | { | ||
826 | QMessageBox::information(NULL, | ||
827 | PROGNAME, | ||
828 | QString("Error in link\nPara # too big") | ||
829 | ); | ||
830 | return false; | ||
831 | } | ||
832 | unsigned int noff = 0; | ||
833 | for (int i = 0; i < n; i++) noff += m_ParaOffsets[i]; | ||
834 | n = noff; | ||
835 | } | ||
836 | if (n > ntohs(thisHdr.size)) | ||
837 | { | ||
838 | QMessageBox::information(NULL, | ||
839 | PROGNAME, | ||
840 | QString("Error in link\nOffset too big") | ||
841 | ); | ||
842 | return false; | ||
843 | } | ||
844 | qDebug("Hyper:<%u,%u>", tuid, n); | ||
845 | while (bufferpos < n && bufferpos < buffercontent) getch(); | ||
846 | } | ||
847 | return true; | ||
848 | } | ||
849 | } | ||
850 | */ | ||
347 | bool CPlucker::expand(int thisrec) | 851 | bool CPlucker::expand(int thisrec) |
348 | { | 852 | { |
349 | mystyle.unset(); | 853 | mystyle.unset(); |
350 | size_t reclen = recordlength(thisrec); | 854 | size_t reclen = recordlength(thisrec); |
351 | gotorecordnumber(thisrec); | 855 | gotorecordnumber(thisrec); |
352 | CPlucker_dataRecord thisHdr; | 856 | CPlucker_dataRecord thisHdr; |
353 | while (1) | 857 | while (1) |
354 | { | 858 | { |
355 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | 859 | fread(&thisHdr, 1, sizeof(thisHdr), fin); |
356 | // qDebug("This (%d) type is %d, uid is %u", thisrec, thisHdr.type, ntohs(thisHdr.uid)); | 860 | //qDebug("This (%d) type is %d, uid is %u", thisrec, thisHdr.type, ntohs(thisHdr.uid)); |
357 | if (thisHdr.type < 2) break; | 861 | if (thisHdr.type < 2) break; |
358 | qDebug("Skipping paragraph of type %d", thisHdr.type); | 862 | qDebug("Skipping paragraph of type %d", thisHdr.type); |
359 | if (++thisrec >= ntohs(head.recordList.numRecords) - 1) return false; | 863 | if (++thisrec >= ntohs(head.recordList.numRecords) - 1) return false; |
360 | reclen = recordlength(thisrec); | 864 | reclen = recordlength(thisrec); |
361 | gotorecordnumber(thisrec); | 865 | gotorecordnumber(thisrec); |
362 | } | 866 | } |
363 | m_nParas = ntohs(thisHdr.nParagraphs); | 867 | m_nParas = ntohs(thisHdr.nParagraphs); |
364 | // qDebug("It has %u paragraphs and is %u bytes", htons(thisHdr.nParagraphs), htons(thisHdr.size)); | 868 | //qDebug("It has %u paragraphs and is %u bytes", ntohs(thisHdr.nParagraphs), ntohs(thisHdr.size)); |
365 | uid = ntohs(thisHdr.uid); | 869 | uid = ntohs(thisHdr.uid); |
366 | for (int i = 0; i < m_nParas; i++) | 870 | for (int i = 0; i < m_nParas; i++) |
367 | { | 871 | { |
368 | UInt16 ubytes, attrs; | 872 | UInt16 ubytes, attrs; |
369 | fread(&ubytes, 1, sizeof(ubytes), fin); | 873 | fread(&ubytes, 1, sizeof(ubytes), fin); |
370 | fread(&attrs, 1, sizeof(attrs), fin); | 874 | fread(&attrs, 1, sizeof(attrs), fin); |
371 | m_ParaOffsets[i] = ntohs(ubytes); | 875 | m_ParaOffsets[i] = ntohs(ubytes); |
372 | m_ParaAttrs[i] = ntohs(attrs); | 876 | m_ParaAttrs[i] = ntohs(attrs); |
373 | // qDebug("Bytes %u, Attr %x", ntohs(ubytes), attrs); | 877 | //qDebug("Bytes %u, Attr %x", ntohs(ubytes), attrs); |
374 | } | 878 | } |
375 | if (m_nParas > 0) | 879 | if (m_nParas > 0) |
376 | { | 880 | { |
377 | m_nextPara = m_ParaOffsets[0]; | 881 | m_nextPara = m_ParaOffsets[0]; |
378 | // qDebug("First offset = %u", m_nextPara); | 882 | //qDebug("First offset = %u", m_nextPara); |
379 | m_nextParaIndex = 0; | 883 | m_nextParaIndex = 0; |
380 | } | 884 | } |
381 | else | 885 | else |
382 | { | 886 | { |
383 | m_nextPara = -1; | 887 | m_nextPara = -1; |
384 | } | 888 | } |
385 | 889 | ||
386 | reclen -= sizeof(thisHdr)+4*m_nParas; | 890 | reclen -= sizeof(thisHdr)+4*m_nParas; |
387 | 891 | ||
388 | buffercontent = htons(thisHdr.size); | 892 | buffercontent = ntohs(thisHdr.size); |
389 | 893 | ||
390 | if (thisHdr.type == 0) | 894 | Expand(reclen, thisHdr.type, expandedtextbuffer, buffercontent); |
391 | { | ||
392 | fread(expandedtextbuffer, reclen, sizeof(char), fin); | ||
393 | } | ||
394 | else | ||
395 | { | ||
396 | fread(compressedtextbuffer, reclen, sizeof(char), fin); | ||
397 | switch (ntohs(hdr0.version)) | ||
398 | { | ||
399 | case 2: | ||
400 | UnZip(reclen, expandedtextbuffer, buffercontent); | ||
401 | break; | ||
402 | case 1: | ||
403 | UnDoc(reclen, expandedtextbuffer, buffercontent); | ||
404 | break; | ||
405 | } | ||
406 | } | ||
407 | bufferpos = 0; | 895 | bufferpos = 0; |
408 | bufferrec = thisrec; | 896 | bufferrec = thisrec; |
409 | // qDebug("BC:%u, HS:%u", buffercontent, ntohs(thisHdr.size)); | 897 | // qDebug("BC:%u, HS:%u", buffercontent, ntohs(thisHdr.size)); |
410 | return true; | 898 | return true; |
411 | } | 899 | } |
412 | 900 | ||
413 | void CPlucker::UnZip(size_t reclen, UInt8* tgtbuffer, UInt16 bsize) | 901 | void CPlucker::UnZip(size_t reclen, UInt8* tgtbuffer, UInt16 bsize) |
414 | { | 902 | { |
415 | z_stream zstream; | 903 | z_stream zstream; |
416 | memset(&zstream,sizeof(zstream),0); | 904 | memset(&zstream,sizeof(zstream),0); |
417 | zstream.next_in = compressedtextbuffer; | 905 | zstream.next_in = compressedtextbuffer; |
418 | zstream.next_out = tgtbuffer; | 906 | zstream.next_out = tgtbuffer; |
419 | zstream.avail_out = bsize; | 907 | zstream.avail_out = bsize; |
420 | zstream.avail_in = reclen; | 908 | zstream.avail_in = reclen; |
421 | 909 | ||
422 | int keylen = 0; | 910 | int keylen = 0; |
423 | 911 | ||
424 | zstream.zalloc = Z_NULL; | 912 | zstream.zalloc = Z_NULL; |
425 | zstream.zfree = Z_NULL; | 913 | zstream.zfree = Z_NULL; |
426 | zstream.opaque = Z_NULL; | 914 | zstream.opaque = Z_NULL; |
427 | 915 | ||
428 | // printf("Initialising\n"); | 916 | // printf("Initialising\n"); |
429 | 917 | ||
430 | inflateInit(&zstream); | 918 | inflateInit(&zstream); |
431 | int err = 0; | 919 | int err = 0; |
432 | do { | 920 | do { |
433 | if ( zstream.avail_in == 0 && 0 < keylen ) { | 921 | if ( zstream.avail_in == 0 && 0 < keylen ) { |
434 | zstream.next_in = compressedtextbuffer + keylen; | 922 | zstream.next_in = compressedtextbuffer + keylen; |
435 | zstream.avail_in = reclen - keylen; | 923 | zstream.avail_in = reclen - keylen; |
436 | keylen = 0; | 924 | keylen = 0; |
437 | } | 925 | } |
438 | zstream.next_out = tgtbuffer; | 926 | zstream.next_out = tgtbuffer; |
439 | zstream.avail_out = bsize; | 927 | zstream.avail_out = bsize; |
440 | 928 | ||
441 | err = inflate( &zstream, Z_SYNC_FLUSH ); | 929 | err = inflate( &zstream, Z_SYNC_FLUSH ); |
442 | 930 | ||
931 | //qDebug("err:%d - %u", err, zstream.avail_in); | ||
932 | |||
443 | } while ( err == Z_OK ); | 933 | } while ( err == Z_OK ); |
444 | 934 | ||
445 | inflateEnd(&zstream); | 935 | inflateEnd(&zstream); |
446 | } | 936 | } |
447 | 937 | ||
448 | void CPlucker::UnDoc(size_t reclen, UInt8* tgtbuffer, UInt16 bsize) | 938 | void CPlucker::UnDoc(size_t reclen, UInt8* tgtbuffer, UInt16 bsize) |
449 | { | 939 | { |
450 | // UInt16 headerSize; | 940 | // UInt16 headerSize; |
451 | UInt16 docSize; | 941 | UInt16 docSize; |
452 | UInt16 i; | 942 | UInt16 i; |
453 | UInt16 j; | 943 | UInt16 j; |
454 | UInt16 k; | 944 | UInt16 k; |
455 | 945 | ||
456 | UInt8 *inBuf = compressedtextbuffer; | 946 | UInt8 *inBuf = compressedtextbuffer; |
457 | UInt8 *outBuf = tgtbuffer; | 947 | UInt8 *outBuf = tgtbuffer; |
458 | 948 | ||
459 | // headerSize = sizeof( Header ) + record->paragraphs * sizeof( Paragraph ); | 949 | // headerSize = sizeof( Header ) + record->paragraphs * sizeof( Paragraph ); |
460 | docSize = reclen; | 950 | docSize = reclen; |
461 | 951 | ||
462 | j = 0; | 952 | j = 0; |
463 | k = 0; | 953 | k = 0; |
464 | while ( j < docSize ) { | 954 | while ( j < docSize ) { |
465 | i = 0; | 955 | i = 0; |
466 | while ( i < bsize && j < docSize ) { | 956 | while ( i < bsize && j < docSize ) { |
@@ -490,90 +980,262 @@ void CPlucker::UnDoc(size_t reclen, UInt8* tgtbuffer, UInt16 bsize) | |||
490 | 980 | ||
491 | do { | 981 | do { |
492 | outBuf[ i ] = outBuf[ i - m ]; | 982 | outBuf[ i ] = outBuf[ i - m ]; |
493 | i++; | 983 | i++; |
494 | } while ( 0 < n-- ); | 984 | } while ( 0 < n-- ); |
495 | } | 985 | } |
496 | } | 986 | } |
497 | k += bsize; | 987 | k += bsize; |
498 | } | 988 | } |
499 | } | 989 | } |
500 | 990 | ||
501 | void CPlucker::home() | 991 | void CPlucker::home() |
502 | { | 992 | { |
503 | currentpos = 0; | 993 | currentpos = 0; |
504 | expand(1); | 994 | expand(1); |
505 | } | 995 | } |
506 | 996 | ||
507 | CList<Bkmk>* CPlucker::getbkmklist() | 997 | CList<Bkmk>* CPlucker::getbkmklist() |
508 | { | 998 | { |
509 | /* | 999 | /* |
510 | CPlucker_dataRecord thisHdr; | 1000 | CPlucker_dataRecord thisHdr; |
511 | 1001 | ||
512 | for (int i = 1; i < ntohs(head.recordList.numRecords); i++) | 1002 | for (int i = 1; i < ntohs(head.recordList.numRecords); i++) |
513 | { | 1003 | { |
514 | gotorecordnumber(i); | 1004 | gotorecordnumber(i); |
515 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | 1005 | fread(&thisHdr, 1, sizeof(thisHdr), fin); |
516 | if (thisHdr.type == 8) | 1006 | if (thisHdr.type == 8) |
517 | { | 1007 | { |
518 | UInt16 n; | 1008 | UInt16 n; |
519 | fread(&n, 1, sizeof(n), fin); | 1009 | fread(&n, 1, sizeof(n), fin); |
520 | n = ntohs(n); | 1010 | n = ntohs(n); |
521 | qDebug("Found %u bookmarks", n); | 1011 | qDebug("Found %u bookmarks", n); |
522 | } | 1012 | } |
523 | qDebug("Found:%d, %u", i , thisHdr.type); | 1013 | qDebug("Found:%d, %u", i , thisHdr.type); |
524 | } | 1014 | } |
525 | */ | 1015 | */ |
526 | return NULL; | 1016 | return NULL; |
527 | } | 1017 | } |
528 | 1018 | ||
529 | void CPlucker::expandimg(UInt16 tgt) | 1019 | QImage* CPlucker::getimg(UInt16 tgt) |
530 | { | 1020 | { |
531 | qDebug("Image:%u", tgt); | 1021 | // static int imageno; |
1022 | // char* file = "tmp1"; | ||
1023 | // sprintf(file, "image%04u.tbmp", imageno++); | ||
1024 | // qDebug("Image:%u", tgt); | ||
532 | CPlucker_dataRecord thisHdr; | 1025 | CPlucker_dataRecord thisHdr; |
533 | size_t reclen; | 1026 | size_t reclen; |
1027 | UInt16 thisrec = finduid(tgt); | ||
1028 | reclen = recordlength(thisrec); | ||
1029 | gotorecordnumber(thisrec); | ||
1030 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
1031 | /* | ||
534 | UInt16 thisrec = 0; | 1032 | UInt16 thisrec = 0; |
535 | do | 1033 | do |
536 | { | 1034 | { |
537 | thisrec++; | 1035 | hthisrec++; |
538 | reclen = recordlength(thisrec); | 1036 | reclen = recordlength(thisrec); |
539 | gotorecordnumber(thisrec); | 1037 | gotorecordnumber(thisrec); |
540 | qDebug("thisrec:%u.%u", ftell(fin),thisrec); | 1038 | //qDebug("thisrec:%u.%u", ftell(fin),thisrec); |
541 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | 1039 | fread(&thisHdr, 1, sizeof(thisHdr), fin); |
542 | } | 1040 | } |
543 | while (ntohs(thisHdr.uid) != tgt); | 1041 | while (ntohs(thisHdr.uid) != tgt); |
544 | 1042 | */ | |
545 | reclen -= sizeof(thisHdr); | 1043 | reclen -= sizeof(thisHdr); |
546 | 1044 | ||
547 | UInt16 imgsize = htons(thisHdr.size); | 1045 | UInt16 imgsize = ntohs(thisHdr.size); |
548 | UInt8* imgbuffer = new UInt8[imgsize]; | 1046 | UInt8* imgbuffer = new UInt8[imgsize]; |
549 | 1047 | ||
550 | qDebug("type:%u", thisHdr.type); | 1048 | // qDebug("type:%u", thisHdr.type); |
1049 | Expand(reclen, thisHdr.type, imgbuffer, imgsize); | ||
551 | 1050 | ||
552 | if (thisHdr.type == 2) | 1051 | QImage* qimage = Palm2QImage(imgbuffer, imgsize); |
1052 | |||
1053 | delete [] imgbuffer; | ||
1054 | |||
1055 | return qimage; | ||
1056 | } | ||
1057 | |||
1058 | #include <qnamespace.h> | ||
1059 | |||
1060 | QPixmap* CPlucker::expandimg(UInt16 tgt, bool border) | ||
1061 | { | ||
1062 | QImage* qimage = getimg(tgt); | ||
1063 | if (qimage == NULL) return NULL; | ||
1064 | QPixmap* image = new QPixmap(0,0); | ||
1065 | QPixmap* ret; | ||
1066 | // qDebug("New image"); | ||
1067 | image->convertFromImage(*qimage); | ||
1068 | delete qimage; | ||
1069 | if (border) | ||
553 | { | 1070 | { |
554 | qDebug("Not compressed:%u.%u", ftell(fin),reclen); | 1071 | ret = new QPixmap(image->width()+4, image->height()+4); |
555 | fread(imgbuffer, reclen, sizeof(char), fin); | 1072 | ret->fill(Qt::red); |
556 | qDebug("Not compressed:%u.%u", ftell(fin),reclen); | 1073 | bitBlt(ret, 2, 2, image, 0, 0, -1, -1);//, Qt::RasterOp::CopyROP); |
1074 | delete image; | ||
557 | } | 1075 | } |
558 | else | 1076 | else |
559 | { | 1077 | { |
560 | qDebug("Compressed"); | 1078 | ret = image; |
561 | fread(compressedtextbuffer, reclen, sizeof(char), fin); | ||
562 | switch (ntohs(hdr0.version)) | ||
563 | { | ||
564 | case 2: | ||
565 | UnZip(reclen, imgbuffer, imgsize); | ||
566 | break; | ||
567 | case 1: | ||
568 | UnDoc(reclen, imgbuffer, imgsize); | ||
569 | break; | ||
570 | } | ||
571 | } | 1079 | } |
572 | FILE* imgfile = fopen("/home/tim/newreader/imagefile.tbmp", "w"); | 1080 | return ret; |
573 | if (imgfile != NULL) | 1081 | } |
1082 | |||
1083 | #ifdef _BUFFERPICS | ||
1084 | #include <qmap.h> | ||
1085 | #endif | ||
1086 | |||
1087 | QPixmap* CPlucker::getPicture(unsigned long tgt) | ||
1088 | { | ||
1089 | #ifdef _BUFFERPICS | ||
1090 | static QMap<unsigned long, QPixmap> pix; | ||
1091 | QMap<unsigned long, QPixmap>::Iterator t = pix.find(tgt); | ||
1092 | if (t == pix.end()) | ||
574 | { | 1093 | { |
575 | fwrite(imgbuffer, 1, imgsize, imgfile); | 1094 | pix[tgt] = *expandimg(tgt); |
576 | fclose(imgfile); | 1095 | return &pix[tgt]; |
577 | } | 1096 | } |
578 | delete [] imgbuffer; | 1097 | else |
1098 | return &(t.data()); | ||
1099 | #else | ||
1100 | return expandimg(tgt); | ||
1101 | #endif | ||
1102 | } | ||
1103 | |||
1104 | #ifdef LOCALPICTURES | ||
1105 | #include <unistd.h> | ||
1106 | #include <qpe/global.h> | ||
1107 | void CPlucker::showimg(UInt16 tgt) | ||
1108 | { | ||
1109 | qDebug("Crassssssh!"); | ||
1110 | QPixmap* qimage = expandimg(tgt); | ||
1111 | m_picture->setFixedSize(qimage->size()); | ||
1112 | m_picture->setBackgroundPixmap(*qimage); | ||
1113 | delete qimage; | ||
1114 | m_viewer->show(); | ||
1115 | |||
1116 | /* | ||
1117 | char tmp[] = "uqtreader.XXXXXX"; | ||
1118 | QImage* qimage = getimg(tgt); | ||
1119 | QPixmap* image = new QPixmap(0,0); | ||
1120 | // qDebug("New image"); | ||
1121 | image->convertFromImage(*qimage); | ||
1122 | delete qimage; | ||
1123 | char tmpfile[sizeof(tmp)+1]; | ||
1124 | strcpy(tmpfile,tmp); | ||
1125 | int f = mkstemp(tmpfile); | ||
1126 | close(f); | ||
1127 | qDebug("TMPFILE:%s", tmpfile); | ||
1128 | if (image->save(tmpfile,"PNG")) | ||
1129 | { | ||
1130 | QCopEnvelope e("QPE/Application/showimg", "setDocument(QString)"); | ||
1131 | e << QString(tmpfile); | ||
1132 | } | ||
1133 | Global::statusMessage("Opening image"); | ||
1134 | sleep(5); | ||
1135 | delete image; | ||
1136 | unlink(tmpfile); | ||
1137 | */ | ||
1138 | } | ||
1139 | |||
1140 | #endif | ||
1141 | |||
1142 | void CPlucker::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) | ||
1143 | { | ||
1144 | unsigned short sz = 0; | ||
1145 | for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) | ||
1146 | { | ||
1147 | sz++; | ||
1148 | } | ||
1149 | size_t newlen = srclen+sizeof(sz)+sz*sizeof(unsigned long); | ||
1150 | unsigned char* newdata = new unsigned char[newlen]; | ||
1151 | unsigned char* pdata = newdata; | ||
1152 | memcpy(newdata, src, srclen); | ||
1153 | newdata += srclen; | ||
1154 | memcpy(newdata, &sz, sizeof(sz)); | ||
1155 | newdata += sizeof(sz); | ||
1156 | for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) | ||
1157 | { | ||
1158 | unsigned long t = *it; | ||
1159 | qDebug("[%u]", t); | ||
1160 | memcpy(newdata, &t, sizeof(t)); | ||
1161 | newdata += sizeof(t); | ||
1162 | } | ||
1163 | m_nav.setSaveData(data, len, pdata, newlen); | ||
1164 | delete [] pdata; | ||
1165 | } | ||
1166 | |||
1167 | void CPlucker::putSaveData(unsigned char*& src, unsigned short& srclen) | ||
1168 | { | ||
1169 | unsigned short sz; | ||
1170 | if (srclen >= sizeof(sz)) | ||
1171 | { | ||
1172 | memcpy(&sz, src, sizeof(sz)); | ||
1173 | src += sizeof(sz); | ||
1174 | srclen -= sizeof(sz); | ||
1175 | } | ||
1176 | for (int i = 0; i < sz; i++) | ||
1177 | { | ||
1178 | unsigned long t; | ||
1179 | if (srclen >= sizeof(t)) | ||
1180 | { | ||
1181 | memcpy(&t, src, sizeof(t)); | ||
1182 | qDebug("[%u]", t); | ||
1183 | visited.push_front(t); | ||
1184 | src += sizeof(t); | ||
1185 | srclen -= sizeof(t); | ||
1186 | } | ||
1187 | else | ||
1188 | { | ||
1189 | QMessageBox::warning(NULL, PROGNAME, "File data mismatch\nMight fix itself"); | ||
1190 | break; | ||
1191 | } | ||
1192 | } | ||
1193 | m_nav.putSaveData(src, srclen); | ||
1194 | } | ||
1195 | |||
1196 | unsigned short CPlucker::finduid(unsigned short urlid) | ||
1197 | { | ||
1198 | // qDebug("Finding %u", urlid); | ||
1199 | unsigned short jmin = 1, jmax = ntohs(head.recordList.numRecords); | ||
1200 | unsigned short jmid = (jmin+jmax) >> 1; | ||
1201 | while (jmax - jmin > 1) | ||
1202 | { | ||
1203 | CPlucker_dataRecord thisHdr; | ||
1204 | gotorecordnumber(jmid); | ||
1205 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
1206 | unsigned short luid = ntohs(thisHdr.uid); | ||
1207 | //qDebug("%u %u %u : %u", jmin, jmid, jmax, urlid); | ||
1208 | if (luid == urlid) | ||
1209 | { | ||
1210 | return jmid; | ||
1211 | } | ||
1212 | if (luid < urlid) | ||
1213 | { | ||
1214 | jmin = jmid; | ||
1215 | } | ||
1216 | else | ||
1217 | { | ||
1218 | jmax = jmid; | ||
1219 | } | ||
1220 | jmid = (jmin+jmax) >> 1; | ||
1221 | } | ||
1222 | CPlucker_dataRecord thisHdr; | ||
1223 | gotorecordnumber(jmin); | ||
1224 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
1225 | unsigned short luid = ntohs(thisHdr.uid); | ||
1226 | qDebug("jmin at end:%u,%u", jmin, luid); | ||
1227 | if (luid == urlid) | ||
1228 | { | ||
1229 | return jmin; | ||
1230 | } | ||
1231 | gotorecordnumber(jmax); | ||
1232 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
1233 | luid = ntohs(thisHdr.uid); | ||
1234 | qDebug("jmax at end:%u,%u", jmax, luid); | ||
1235 | if (luid == urlid) | ||
1236 | { | ||
1237 | return jmax; | ||
1238 | } | ||
1239 | qDebug("Couldn't find %u", urlid); | ||
1240 | return 0; // Not found! | ||
579 | } | 1241 | } |