Diffstat (limited to 'noncore/apps/opie-reader/plucker.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/plucker.cpp | 830 |
1 files changed, 746 insertions, 84 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,104 +1,314 @@ | |||
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" | ||
7 | 17 | ||
8 | CPlucker::CPlucker() : expandedtextbuffer(NULL), compressedtextbuffer(NULL) { /*printf("constructing:%x\n",fin);*/ } | 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);*/ } | ||
9 | 27 | ||
10 | 28 | ||
11 | int CPlucker::openfile(const char *src) | 29 | void CPlucker::Expand(UInt16 reclen, UInt8 type, UInt8* buffer, UInt16 buffersize) |
12 | { | 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 | } | ||
49 | |||
50 | int CPlucker::OpenFile(const char *src) | ||
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; |
82 | fread(&name, 1, sizeof(name), fin); | ||
47 | fread(&id, 1, sizeof(id), fin); | 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 | } | ||
48 | // qDebug("%x", id); | 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 | { |
217 | if (!m_continuous) return EOF; | ||
59 | if (bufferrec >= ntohs(head.recordList.numRecords) - 1) return EOF; | 218 | if (bufferrec >= ntohs(head.recordList.numRecords) - 1) return EOF; |
60 | // qDebug("Passing through %u", currentpos); | 219 | // qDebug("Passing through %u", currentpos); |
61 | if (!expand(bufferrec+1)) return EOF; | 220 | if (!expand(bufferrec+1)) return EOF; |
62 | mystyle.unset(); | 221 | mystyle.unset(); |
222 | ch = 10; | ||
223 | EOPPhase = 4; | ||
63 | } | 224 | } |
64 | 225 | else if (bufferpos == m_nextPara) | |
65 | if (bufferpos == m_nextPara) | 226 | { |
227 | while (bufferpos == m_nextPara) | ||
66 | { | 228 | { |
67 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; | 229 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; |
68 | m_nextParaIndex++; | 230 | m_nextParaIndex++; |
69 | if (m_nextParaIndex == m_nParas) | 231 | if (m_nextParaIndex == m_nParas) |
70 | { | 232 | { |
71 | m_nextPara = -1; | 233 | m_nextPara = -1; |
72 | } | 234 | } |
73 | else | 235 | else |
74 | { | 236 | { |
75 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; | 237 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; |
76 | } | 238 | } |
77 | // qDebug("New paragraph"); | 239 | } |
240 | mystyle.unset(); | ||
241 | if (m_lastBreak == locate()) | ||
242 | { | ||
243 | currentpos++; | ||
244 | ch = expandedtextbuffer[bufferpos++]; | ||
245 | } | ||
246 | else | ||
247 | { | ||
78 | ch = 10; | 248 | ch = 10; |
79 | } | 249 | } |
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 | { |
261 | mystyle.clearPicture(); | ||
262 | |||
263 | |||
264 | if (EOPPhase > 0) | ||
265 | { | ||
266 | int ch = 10; | ||
267 | switch (EOPPhase) | ||
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; | ||
288 | } | ||
289 | |||
290 | |||
90 | int ch = bgetch(); | 291 | int ch = bgetch(); |
91 | while (ch == 0) | 292 | while (ch == 0) |
92 | { | 293 | { |
93 | ch = bgetch(); | 294 | ch = bgetch(); |
94 | // qDebug("Function:%x", ch); | 295 | // qDebug("Function:%x", ch); |
95 | switch (ch) | 296 | switch (ch) |
96 | { | 297 | { |
97 | case 0x38: | 298 | case 0x38: |
299 | // qDebug("Break:%u", locate()); | ||
300 | if (m_lastBreak == locate()) | ||
301 | { | ||
302 | ch = bgetch(); | ||
303 | } | ||
304 | else | ||
305 | { | ||
98 | ch = 10; | 306 | ch = 10; |
307 | } | ||
308 | m_lastBreak = locate(); | ||
99 | break; | 309 | break; |
100 | case 0x0a: | 310 | case 0x0a: |
101 | case 0x0c: | 311 | case 0x0c: |
102 | { | 312 | { |
103 | unsigned long ln = 0; | 313 | unsigned long ln = 0; |
104 | int skip = ch & 7; | 314 | int skip = ch & 7; |
@@ -121,19 +331,38 @@ int CPlucker::getch() | |||
121 | // qDebug("ch:%d, ln:%u", ch, ln); | 331 | // qDebug("ch:%d, ln:%u", ch, ln); |
122 | } | 332 | } |
123 | } | 333 | } |
124 | // qDebug("ln:%u", ln); | 334 | // qDebug("ln:%u", ln); |
125 | mystyle.setLink(true); | 335 | mystyle.setLink(true); |
126 | mystyle.setData(ln); | 336 | mystyle.setData(ln); |
127 | mystyle.setColour(255, 0, 0); | 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 | } | ||
128 | ch = bgetch(); | 355 | ch = bgetch(); |
129 | } | 356 | } |
130 | break; | 357 | break; |
131 | case 0x08: | 358 | case 0x08: |
132 | ch = bgetch(); | 359 | ch = bgetch(); |
133 | mystyle.setColour(0, 0, 0); | 360 | // mystyle.setColour(0, 0, 0); |
361 | mystyle.unsetUnderline(); | ||
362 | mystyle.unsetStrikethru(); | ||
134 | mystyle.setLink(false); | 363 | mystyle.setLink(false); |
135 | mystyle.setData(0); | 364 | mystyle.setData(0); |
136 | break; | 365 | break; |
137 | case 0x40: | 366 | case 0x40: |
138 | mystyle.setItalic(); | 367 | mystyle.setItalic(); |
139 | ch = bgetch(); | 368 | ch = bgetch(); |
@@ -142,53 +371,66 @@ int CPlucker::getch() | |||
142 | mystyle.unsetItalic(); | 371 | mystyle.unsetItalic(); |
143 | ch = bgetch(); | 372 | ch = bgetch(); |
144 | break; | 373 | break; |
145 | case 0x11: | 374 | case 0x11: |
146 | { | 375 | { |
147 | ch = bgetch(); | 376 | ch = bgetch(); |
148 | qDebug("Font:%d",ch); | 377 | // qDebug("Font:%d",ch); |
149 | switch (ch) | 378 | switch (ch) |
150 | { | 379 | { |
151 | case 0: | 380 | case 0: |
381 | mystyle.unsetMono(); | ||
152 | mystyle.unsetBold(); | 382 | mystyle.unsetBold(); |
153 | mystyle.setFontSize(0); | 383 | mystyle.setFontSize(0); |
154 | break; | 384 | break; |
155 | case 1: | 385 | case 1: |
386 | mystyle.unsetMono(); | ||
156 | mystyle.setBold(); | 387 | mystyle.setBold(); |
157 | mystyle.setFontSize(1); | 388 | mystyle.setFontSize(3); |
158 | break; | 389 | break; |
159 | case 2: | 390 | case 2: |
391 | mystyle.unsetMono(); | ||
160 | mystyle.setBold(); | 392 | mystyle.setBold(); |
161 | mystyle.setFontSize(1); | 393 | mystyle.setFontSize(2); |
162 | break; | 394 | break; |
163 | case 3: | 395 | case 3: |
164 | // mystyle.setBold(); | 396 | mystyle.unsetMono(); |
397 | mystyle.setBold(); | ||
398 | // mystyle.unsetBold(); | ||
165 | mystyle.setFontSize(1); | 399 | mystyle.setFontSize(1); |
166 | break; | 400 | break; |
167 | case 4: | 401 | case 4: |
168 | // mystyle.setBold(); | 402 | mystyle.unsetMono(); |
169 | mystyle.setFontSize(1); | 403 | mystyle.setBold(); |
404 | // mystyle.unsetBold(); | ||
405 | mystyle.setFontSize(0); | ||
170 | break; | 406 | break; |
171 | case 5: | 407 | case 5: |
408 | mystyle.unsetMono(); | ||
172 | mystyle.setBold(); | 409 | mystyle.setBold(); |
173 | mystyle.setFontSize(0); | 410 | mystyle.setFontSize(0); |
174 | break; | 411 | break; |
175 | case 6: | 412 | case 6: |
413 | mystyle.unsetMono(); | ||
176 | mystyle.setBold(); | 414 | mystyle.setBold(); |
177 | mystyle.setFontSize(0); | 415 | mystyle.setFontSize(0); |
178 | break; | 416 | break; |
179 | case 7: | 417 | case 7: |
418 | mystyle.unsetMono(); | ||
180 | mystyle.setBold(); | 419 | mystyle.setBold(); |
181 | mystyle.setFontSize(0); | 420 | mystyle.setFontSize(0); |
182 | break; | 421 | break; |
183 | case 8: // should be fixed width | 422 | case 8: // should be fixed width |
423 | qDebug("Trying fixed width"); | ||
184 | mystyle.unsetBold(); | 424 | mystyle.unsetBold(); |
185 | mystyle.setFontSize(0); | 425 | mystyle.setFontSize(0); |
426 | mystyle.setMono(); | ||
186 | break; | 427 | break; |
187 | default: | 428 | default: |
188 | mystyle.unsetBold(); | 429 | mystyle.unsetBold(); |
430 | mystyle.unsetMono(); | ||
189 | mystyle.setFontSize(0); | 431 | mystyle.setFontSize(0); |
190 | break; | 432 | break; |
191 | } | 433 | } |
192 | ch = bgetch(); | 434 | ch = bgetch(); |
193 | } | 435 | } |
194 | break; | 436 | break; |
@@ -223,43 +465,107 @@ int CPlucker::getch() | |||
223 | int b = bgetch(); | 465 | int b = bgetch(); |
224 | mystyle.setColour(r,g,b); | 466 | mystyle.setColour(r,g,b); |
225 | ch = bgetch(); | 467 | ch = bgetch(); |
226 | } | 468 | } |
227 | break; | 469 | break; |
228 | case 0x1a: | 470 | case 0x1a: |
229 | /* | 471 | case 0x5c: |
230 | { | 472 | { |
473 | bool hasalternate = (ch == 0x5c); | ||
231 | UInt16 ir = bgetch(); | 474 | UInt16 ir = bgetch(); |
232 | ir = (ir << 8) + bgetch(); | 475 | ir = (ir << 8) + bgetch(); |
233 | expandimg(ir); | 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 | ||
234 | } | 488 | } |
235 | ch = bgetch(); | 489 | else |
490 | { | ||
491 | mystyle.setPicture(expandimg(ir)); | ||
492 | } | ||
493 | if (mystyle.getLink()) qDebug("Picture link!"); | ||
494 | ch = '#'; | ||
495 | } | ||
496 | // ch = bgetch(); | ||
236 | break; | 497 | break; |
237 | */ | ||
238 | case 0x33: | 498 | case 0x33: |
239 | case 0x22: | 499 | { |
240 | case 0x5c: | 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; | ||
241 | case 0x60: | 515 | case 0x60: |
516 | mystyle.setUnderline(); | ||
517 | ch = bgetch(); | ||
518 | break; | ||
242 | case 0x68: | 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; | ||
243 | case 0x70: | 532 | case 0x70: |
533 | mystyle.setStrikethru(); | ||
534 | ch = bgetch(); | ||
535 | break; | ||
244 | case 0x78: | 536 | case 0x78: |
537 | mystyle.unsetStrikethru(); | ||
538 | ch = bgetch(); | ||
539 | break; | ||
245 | case 0x83: | 540 | case 0x83: |
246 | case 0x85: | 541 | case 0x85: |
247 | default: | 542 | default: |
248 | qDebug("Function:%x NOT IMPLEMENTED", ch); | 543 | qDebug("Function:%x NOT IMPLEMENTED", ch); |
249 | { | 544 | { |
250 | int skip = ch & 7; | 545 | int skip = ch & 7; |
251 | for (int i = 0; i < skip; i++) | 546 | for (int i = 0; i < skip; i++) |
252 | { | 547 | { |
253 | ch = bgetch(); | 548 | ch = bgetch(); |
254 | qDebug("Arg %d, %d", i, ch); | 549 | // qDebug("Arg %d, %d", i, ch); |
255 | } | 550 | } |
256 | ch = bgetch(); | 551 | ch = bgetch(); |
257 | } | 552 | } |
258 | } | 553 | } |
259 | } | 554 | } |
555 | |||
556 | if (m_lastIsBreak && !mystyle.isMono()) | ||
557 | { | ||
558 | while (ch == ' ') | ||
559 | { | ||
560 | ch = getch(); | ||
561 | } | ||
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(); |
@@ -274,13 +580,13 @@ unsigned int CPlucker::locate() | |||
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 | } |
@@ -296,57 +602,255 @@ void CPlucker::locate(unsigned int n) | |||
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++; |
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 | } | ||
329 | gotorecordnumber(thisrec); | 673 | gotorecordnumber(thisrec); |
330 | } | 674 | } |
331 | if (thisHdr.type > 1) | 675 | if (thisHdr.type > 1) |
332 | { | 676 | { |
677 | if (thisHdr.type == 4) | ||
678 | { | ||
333 | QMessageBox::information(NULL, | 679 | QMessageBox::information(NULL, |
334 | QString("OpieReader"), | 680 | PROGNAME, |
335 | QString("External links\nnot yet supported") | 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)") | ||
336 | ); | 692 | ); |
693 | #ifdef LOCALPICTURES | ||
694 | } | ||
695 | else | ||
696 | { | ||
697 | showimg(tuid); | ||
698 | } | ||
699 | #endif | ||
700 | } | ||
337 | return false; | 701 | return false; |
338 | } | 702 | } |
703 | /* | ||
704 | if (thisHdr.type == 2 || thisHdr.type == 3) | ||
705 | { | ||
706 | expandimg(thisrec); | ||
707 | |||
708 | } | ||
709 | */ | ||
339 | else | 710 | else |
340 | { | 711 | { |
341 | expand(thisrec); | 712 | expand(thisrec); |
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); | ||
342 | while (bufferpos < n && bufferpos < buffercontent) getch(); | 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; |
@@ -358,13 +862,13 @@ bool CPlucker::expand(int thisrec) | |||
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); |
@@ -382,31 +886,15 @@ bool CPlucker::expand(int thisrec) | |||
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 | ||
@@ -437,12 +925,14 @@ void CPlucker::UnZip(size_t reclen, UInt8* tgtbuffer, UInt16 bsize) | |||
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) |
@@ -523,57 +1013,229 @@ CList<Bkmk>* CPlucker::getbkmklist() | |||
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); | ||
1050 | |||
1051 | QImage* qimage = Palm2QImage(imgbuffer, imgsize); | ||
1052 | |||
1053 | delete [] imgbuffer; | ||
1054 | |||
1055 | return qimage; | ||
1056 | } | ||
1057 | |||
1058 | #include <qnamespace.h> | ||
551 | 1059 | ||
552 | if (thisHdr.type == 2) | 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); | 1079 | } |
562 | switch (ntohs(hdr0.version)) | 1080 | return ret; |
1081 | } | ||
1082 | |||
1083 | #ifdef _BUFFERPICS | ||
1084 | #include <qmap.h> | ||
1085 | #endif | ||
1086 | |||
1087 | QPixmap* CPlucker::getPicture(unsigned long tgt) | ||
563 | { | 1088 | { |
564 | case 2: | 1089 | #ifdef _BUFFERPICS |
565 | UnZip(reclen, imgbuffer, imgsize); | 1090 | static QMap<unsigned long, QPixmap> pix; |
566 | break; | 1091 | QMap<unsigned long, QPixmap>::Iterator t = pix.find(tgt); |
567 | case 1: | 1092 | if (t == pix.end()) |
568 | UnDoc(reclen, imgbuffer, imgsize); | 1093 | { |
1094 | pix[tgt] = *expandimg(tgt); | ||
1095 | return &pix[tgt]; | ||
1096 | } | ||
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"); | ||
569 | break; | 1190 | break; |
570 | } | 1191 | } |
571 | } | 1192 | } |
572 | FILE* imgfile = fopen("/home/tim/newreader/imagefile.tbmp", "w"); | 1193 | m_nav.putSaveData(src, srclen); |
573 | if (imgfile != NULL) | 1194 | } |
1195 | |||
1196 | unsigned short CPlucker::finduid(unsigned short urlid) | ||
574 | { | 1197 | { |
575 | fwrite(imgbuffer, 1, imgsize, imgfile); | 1198 | // qDebug("Finding %u", urlid); |
576 | fclose(imgfile); | 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; | ||
577 | } | 1211 | } |
578 | delete [] imgbuffer; | 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 | } |