summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/Aportis.cpp2
-rw-r--r--noncore/apps/opie-reader/Aportis.h10
-rw-r--r--noncore/apps/opie-reader/Bkmks.cpp310
-rw-r--r--noncore/apps/opie-reader/Bkmks.h37
-rw-r--r--noncore/apps/opie-reader/BuffDoc.cpp248
-rw-r--r--noncore/apps/opie-reader/BuffDoc.h30
-rw-r--r--noncore/apps/opie-reader/CBuffer.cpp4
-rw-r--r--noncore/apps/opie-reader/CDrawBuffer.cpp264
-rw-r--r--noncore/apps/opie-reader/CDrawBuffer.h27
-rw-r--r--noncore/apps/opie-reader/CExpander.h87
-rw-r--r--noncore/apps/opie-reader/CFilter.cpp127
-rw-r--r--noncore/apps/opie-reader/CFilter.h18
-rw-r--r--noncore/apps/opie-reader/Filedata.h51
-rw-r--r--noncore/apps/opie-reader/FontControl.cpp37
-rw-r--r--noncore/apps/opie-reader/FontControl.h47
-rw-r--r--noncore/apps/opie-reader/GraphicWin.h65
-rw-r--r--noncore/apps/opie-reader/Navigation.cpp98
-rw-r--r--noncore/apps/opie-reader/Navigation.h16
-rw-r--r--noncore/apps/opie-reader/Palm2QImage.cpp290
-rw-r--r--noncore/apps/opie-reader/Palm2QImage.h7
-rw-r--r--noncore/apps/opie-reader/QTReader.cpp540
-rw-r--r--noncore/apps/opie-reader/QTReader.h56
-rw-r--r--noncore/apps/opie-reader/QTReaderApp.cpp1693
-rw-r--r--noncore/apps/opie-reader/QTReaderApp.h50
-rw-r--r--noncore/apps/opie-reader/StateData.h32
-rw-r--r--noncore/apps/opie-reader/StyleConsts.cpp99
-rw-r--r--noncore/apps/opie-reader/StyleConsts.h192
-rw-r--r--noncore/apps/opie-reader/Text.h28
-rw-r--r--noncore/apps/opie-reader/ZText.h35
-rw-r--r--noncore/apps/opie-reader/cbkmkselector.h4
-rw-r--r--noncore/apps/opie-reader/config.h4
-rw-r--r--noncore/apps/opie-reader/fileBrowser.cpp3
-rw-r--r--noncore/apps/opie-reader/infowin.cpp5
-rw-r--r--noncore/apps/opie-reader/main.cpp6
-rw-r--r--noncore/apps/opie-reader/name.h8
-rw-r--r--noncore/apps/opie-reader/opie-reader.pro129
-rw-r--r--noncore/apps/opie-reader/opie.h6
-rw-r--r--noncore/apps/opie-reader/pdb.cpp12
-rw-r--r--noncore/apps/opie-reader/plucker.cpp1280
-rw-r--r--noncore/apps/opie-reader/plucker.h73
-rw-r--r--noncore/apps/opie-reader/ppm_expander.cpp2
-rw-r--r--noncore/apps/opie-reader/ppm_expander.h12
-rw-r--r--noncore/apps/opie-reader/ustring.h12
-rw-r--r--noncore/apps/opie-reader/version.h2
-rw-r--r--noncore/apps/opie-reader/ztxt.cpp2
-rw-r--r--noncore/apps/opie-reader/ztxt.h42
46 files changed, 4580 insertions, 1522 deletions
diff --git a/noncore/apps/opie-reader/Aportis.cpp b/noncore/apps/opie-reader/Aportis.cpp
index 1327ff8..b4988da 100644
--- a/noncore/apps/opie-reader/Aportis.cpp
+++ b/noncore/apps/opie-reader/Aportis.cpp
@@ -1,374 +1,374 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <string.h> 2#include <string.h>
3#include "Aportis.h" 3#include "Aportis.h"
4#include "my_list.h" 4#include "my_list.h"
5#include "Bkmks.h" 5#include "Bkmks.h"
6 6
7Aportis::Aportis() : peanutfile(false) { /*printf("constructing:%x\n",fin);*/ } 7Aportis::Aportis() : peanutfile(false) { /*printf("constructing:%x\n",fin);*/ }
8 8
9void Aportis::dePeanut(int& ch) 9void Aportis::dePeanut(int& ch)
10{ 10{
11 if (peanutfile && ch != EOF) 11 if (peanutfile && ch != EOF)
12 { 12 {
13 unsigned char c = ch; 13 unsigned char c = ch;
14 if (peanutfile) c ^= 0xa5; 14 if (peanutfile) c ^= 0xa5;
15 ch = c; 15 ch = c;
16 } 16 }
17} 17}
18 18
19CList<Bkmk>* Aportis::getbkmklist() 19CList<Bkmk>* Aportis::getbkmklist()
20{ 20{
21/* 21/*
22 if (peanutfile) 22 if (peanutfile)
23 { 23 {
24 if (nRecs2 > nRecs) 24 if (nRecs2 > nRecs)
25 { 25 {
26 CList<Bkmk>* t = new CList<Bkmk>; 26 CList<Bkmk>* t = new CList<Bkmk>;
27 for (int i = nRecs; i < nRecs2; i++) 27 for (int i = nRecs; i < nRecs2; i++)
28 { 28 {
29 char name[17]; 29 char name[17];
30 name[16] = '\0'; 30 name[16] = '\0';
31 qDebug("Record:%d, Length:%u",i,recordlength(i)); 31 qDebug("Record:%d, Length:%u",i,recordlength(i));
32 gotorecordnumber(i); 32 gotorecordnumber(i);
33 fread(name,1,16,fin); 33 fread(name,1,16,fin);
34 unsigned long lcn; 34 unsigned long lcn;
35 fread(&lcn,sizeof(lcn),1,fin); 35 fread(&lcn,sizeof(lcn),1,fin);
36 lcn ^= 0xa5a5a5a5; 36 lcn ^= 0xa5a5a5a5;
37 lcn = SwapLong(lcn); 37 lcn = SwapLong(lcn);
38 qDebug("Bookmark:%s:%u", name,lcn); 38 qDebug("Bookmark:%s:%u", name,lcn);
39 tchar tname[17]; 39 tchar tname[17];
40 memset(tname, 0, sizeof(tname)); 40 memset(tname, 0, sizeof(tname));
41 for (int i = 0; name[i] != 0; i++) 41 for (int i = 0; name[i] != 0; i++)
42 { 42 {
43 tname[i] = name[i] ^ 0xa5; 43 tname[i] = name[i] ^ 0xa5;
44 } 44 }
45 t->push_back(Bkmk(tname, NULL, lcn)); 45 t->push_back(Bkmk(tname, NULL, lcn));
46 } 46 }
47 return t; 47 return t;
48 } 48 }
49 else 49 else
50 { 50 {
51 return NULL; 51 return NULL;
52 } 52 }
53 } 53 }
54*/ 54*/
55 if (bCompressed != 4) return NULL; 55 if (bCompressed != 4) return NULL;
56 CList<Bkmk>* t = new CList<Bkmk>; 56 CList<Bkmk>* t = new CList<Bkmk>;
57 size_t cur = ftell(fin); 57 size_t cur = ftell(fin);
58 for (int i = 0; i < nRecs2; i++) 58 for (int i = 0; i < nRecs2; i++)
59 { 59 {
60 DWORD dwPos; 60 DWORD dwPos;
61 fseek(fin, 0x56 + 8*i, SEEK_SET); 61 fseek(fin, 0x56 + 8*i, SEEK_SET);
62 fread(&dwPos, 4, 1, fin); 62 fread(&dwPos, 4, 1, fin);
63 dwPos = SwapLong(dwPos); 63 dwPos = SwapLong(dwPos);
64 fseek(fin,dwPos,SEEK_SET); 64 fseek(fin,dwPos,SEEK_SET);
65 unsigned char ch; 65 unsigned char ch;
66 fread(&ch,1,1,fin); 66 fread(&ch,1,1,fin);
67 if (ch != 241) 67 if (ch != 241)
68 { 68 {
69 char name[17]; 69 char name[17];
70 name[16] = '\0'; 70 name[16] = '\0';
71 fseek(fin,dwPos,SEEK_SET); 71 fseek(fin,dwPos,SEEK_SET);
72 fread(name,1,16,fin); 72 fread(name,1,16,fin);
73 unsigned long lcn; 73 unsigned long lcn;
74 fread(&lcn,sizeof(lcn),1,fin); 74 fread(&lcn,sizeof(lcn),1,fin);
75 lcn = SwapLong(lcn); 75 lcn = SwapLong(lcn);
76#ifdef _UNICODE 76#ifdef _UNICODE
77 tchar tname[17]; 77 tchar tname[17];
78 memset(tname, 0, sizeof(tname)); 78 memset(tname, 0, sizeof(tname));
79 for (int i = 0; name[i] != 0; i++) 79 for (int i = 0; name[i] != 0; i++)
80 { 80 {
81 tname[i] = name[i]; 81 tname[i] = name[i];
82 } 82 }
83 t->push_back(Bkmk(tname, NULL, lcn)); 83 t->push_back(Bkmk(tname, NULL, lcn));
84#else 84#else
85 t->push_back(Bkmk(name,lcn)); 85 t->push_back(Bkmk(name,lcn));
86#endif 86#endif
87 } 87 }
88 } 88 }
89 fseek(fin, cur, SEEK_SET); 89 fseek(fin, cur, SEEK_SET);
90 return t; 90 return t;
91} 91}
92 92
93int Aportis::openfile(const char *src) 93int Aportis::OpenFile(const char *src)
94{ 94{
95 // printf("In openfile\n"); 95 // printf("In openfile\n");
96 int ret = 0; 96 int ret = 0;
97 97
98 if (!Cpdb::openfile(src)) return -1; 98 if (!Cpdb::openfile(src)) return -1;
99 99
100 if (head.creator != 0x64414552 // 'dAER' 100 if (head.creator != 0x64414552 // 'dAER'
101 || head.type != 0x74584554) // 'tXET') 101 || head.type != 0x74584554) // 'tXET')
102 { 102 {
103 103
104 if (memcmp(&head.creator, "PPrs", 4) == 0 && memcmp(&head.type, "PNRd", 4) == 0) 104 if (memcmp(&head.creator, "PPrs", 4) == 0 && memcmp(&head.type, "PNRd", 4) == 0)
105 { 105 {
106 peanutfile = true; 106 peanutfile = true;
107 } 107 }
108 else 108 else
109 { 109 {
110 return -2; 110 return -2;
111 } 111 }
112 } 112 }
113 113
114 nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1; 114 nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1;
115 fseek(fin,0,SEEK_END); 115 fseek(fin,0,SEEK_END);
116 dwLen = ftell(fin); 116 dwLen = ftell(fin);
117 117
118 if (peanutfile) 118 if (peanutfile)
119 { 119 {
120 120
121 PeanutHeader hdr0; 121 PeanutHeader hdr0;
122 gotorecordnumber(0); 122 gotorecordnumber(0);
123 fread(&hdr0, sizeof(hdr0), 1, fin); 123 fread(&hdr0, sizeof(hdr0), 1, fin);
124 qDebug("Version:%x", ntohs(hdr0.Version)); 124 qDebug("Version:%x", ntohs(hdr0.Version));
125 if (hdr0.Version && 0x0200) 125 if (hdr0.Version && 0x0200)
126 { 126 {
127 bCompressed = 2; 127 bCompressed = 2;
128 } 128 }
129 else 129 else
130 { 130 {
131 bCompressed = 1; 131 bCompressed = 1;
132 } 132 }
133 BlockSize = 4096; 133 BlockSize = 4096;
134 nRecs = SwapWord(hdr0.Records)-1; 134 nRecs = SwapWord(hdr0.Records)-1;
135 dwTLen = nRecs*BlockSize; 135 dwTLen = nRecs*BlockSize;
136 } 136 }
137 else 137 else
138 { 138 {
139 gotorecordnumber(0); 139 gotorecordnumber(0);
140 tDocRecord0 hdr0; 140 tDocRecord0 hdr0;
141 fread(&hdr0, sizeof(hdr0), 1, fin); 141 fread(&hdr0, sizeof(hdr0), 1, fin);
142 bCompressed = SwapWord(hdr0.wVersion); 142 bCompressed = SwapWord(hdr0.wVersion);
143 if (bCompressed!=1 && bCompressed!=2 && bCompressed != 4) { 143 if (bCompressed!=1 && bCompressed!=2 && bCompressed != 4) {
144 ret = bCompressed; 144 ret = bCompressed;
145 bCompressed = 2; 145 bCompressed = 2;
146 } 146 }
147 switch (bCompressed) 147 switch (bCompressed)
148 { 148 {
149 case 4: 149 case 4:
150 { 150 {
151 dwTLen = 0; 151 dwTLen = 0;
152 int i; 152 int i;
153 for (i = 0; i < nRecs; i++) 153 for (i = 0; i < nRecs; i++)
154 { 154 {
155 unsigned int bs = GetBS(i); 155 unsigned int bs = GetBS(i);
156 if (bs == 0) break; 156 if (bs == 0) break;
157 else dwTLen += bs; 157 else dwTLen += bs;
158 } 158 }
159 nRecs = i; 159 nRecs = i;
160 BlockSize = 0; 160 BlockSize = 0;
161 } 161 }
162 break; 162 break;
163 case 1: 163 case 1:
164 case 2: 164 case 2:
165 default: 165 default:
166 nRecs = SwapWord(hdr0.wNumRecs); 166 nRecs = SwapWord(hdr0.wNumRecs);
167 dwTLen = SwapLong(hdr0.dwStoryLen); 167 dwTLen = SwapLong(hdr0.dwStoryLen);
168 BlockSize = SwapWord(hdr0.wRecSize); 168 BlockSize = SwapWord(hdr0.wRecSize);
169 if (BlockSize == 0) 169 if (BlockSize == 0)
170 { 170 {
171 BlockSize = 4096; 171 BlockSize = 4096;
172 printf("WARNING: Blocksize not set in source file\n"); 172 printf("WARNING: Blocksize not set in source file\n");
173 } 173 }
174 } 174 }
175 } 175 }
176 176
177 177
178 178
179 // this is the main record buffer 179 // this is the main record buffer
180 // it knows how to stretch to accomodate the decompress 180 // it knows how to stretch to accomodate the decompress
181 currentrec = 0; 181 currentrec = 0;
182 cbptr = 0; 182 cbptr = 0;
183 outptr = 0; 183 outptr = 0;
184 refreshbuffer(); 184 refreshbuffer();
185 qDebug("Number of records:[%u,%u]", nRecs, nRecs2); 185 qDebug("Number of records:[%u,%u]", nRecs, nRecs2);
186 return ret; 186 return ret;
187} 187}
188 188
189int Aportis::getch() 189int Aportis::getch()
190{ 190{
191 if (bCompressed == 1) 191 if (bCompressed == 1)
192 { 192 {
193 if ((dwRecLen == 0) && !refreshbuffer()) return EOF; 193 if ((dwRecLen == 0) && !refreshbuffer()) return EOF;
194 else 194 else
195 { 195 {
196 int c = getc(fin); 196 int c = getc(fin);
197 dePeanut(c); 197 dePeanut(c);
198 dwRecLen--; 198 dwRecLen--;
199 currentpos++; 199 currentpos++;
200 return c; 200 return c;
201 } 201 }
202 } 202 }
203 if (outptr != cbptr) 203 if (outptr != cbptr)
204 { 204 {
205 currentpos++; 205 currentpos++;
206 return (circbuf[outptr = (outptr + 1) % 2048]); 206 return (circbuf[outptr = (outptr + 1) % 2048]);
207 } 207 }
208 if ((dwRecLen == 0) && !refreshbuffer()) return EOF; 208 if ((dwRecLen == 0) && !refreshbuffer()) return EOF;
209 currentpos++; 209 currentpos++;
210 int c; 210 int c;
211 211
212 // take a char from the input buffer 212 // take a char from the input buffer
213 c = getc(fin); 213 c = getc(fin);
214 dePeanut(c); 214 dePeanut(c);
215 dwRecLen--; 215 dwRecLen--;
216 // separate the char into zones: 0, 1...8, 9...0x7F, 0x80...0xBF, 0xC0...0xFF 216 // separate the char into zones: 0, 1...8, 9...0x7F, 0x80...0xBF, 0xC0...0xFF
217 217
218 // codes 1...8 mean copy that many chars; for accented chars & binary 218 // codes 1...8 mean copy that many chars; for accented chars & binary
219 if (c == 0) 219 if (c == 0)
220 { 220 {
221 circbuf[outptr = cbptr = (cbptr+1)%2048] = c; 221 circbuf[outptr = cbptr = (cbptr+1)%2048] = c;
222 return c; 222 return c;
223 } 223 }
224 else if (c >= 0x09 && c <= 0x7F) 224 else if (c >= 0x09 && c <= 0x7F)
225 { 225 {
226 circbuf[outptr = cbptr = (cbptr+1)%2048] = c; 226 circbuf[outptr = cbptr = (cbptr+1)%2048] = c;
227 return c; 227 return c;
228 } 228 }
229 else if (c >= 0x01 && c <= 0x08) 229 else if (c >= 0x01 && c <= 0x08)
230 { 230 {
231 dwRecLen -= c; 231 dwRecLen -= c;
232 while(c--) 232 while(c--)
233 { 233 {
234 int c = getc(fin); 234 int c = getc(fin);
235 dePeanut(c); 235 dePeanut(c);
236 circbuf[cbptr = (cbptr+1)%2048] = c; 236 circbuf[cbptr = (cbptr+1)%2048] = c;
237 } 237 }
238 return circbuf[outptr = (outptr+1)%2048]; 238 return circbuf[outptr = (outptr+1)%2048];
239 } 239 }
240 else if (c >= 0x80 && c <= 0xBF) 240 else if (c >= 0x80 && c <= 0xBF)
241 { 241 {
242 int m,n; 242 int m,n;
243 c <<= 8; 243 c <<= 8;
244 int c1 = getc(fin); 244 int c1 = getc(fin);
245 dePeanut(c1); 245 dePeanut(c1);
246 c += c1; 246 c += c1;
247 dwRecLen--; 247 dwRecLen--;
248 m = (c & 0x3FFF) >> COUNT_BITS; 248 m = (c & 0x3FFF) >> COUNT_BITS;
249 n = c & ((1<<COUNT_BITS) - 1); 249 n = c & ((1<<COUNT_BITS) - 1);
250 n += 3; 250 n += 3;
251 while (n--) 251 while (n--)
252 { 252 {
253 cbptr = (cbptr+1)%2048; 253 cbptr = (cbptr+1)%2048;
254 circbuf[cbptr] = circbuf[(cbptr+2048-m)%2048]; 254 circbuf[cbptr] = circbuf[(cbptr+2048-m)%2048];
255 } 255 }
256 return circbuf[outptr = (outptr+1)%2048]; 256 return circbuf[outptr = (outptr+1)%2048];
257 } 257 }
258 else if (c >= 0xC0 && c <= 0xFF) 258 else if (c >= 0xC0 && c <= 0xFF)
259 { 259 {
260 circbuf[cbptr = (cbptr+1)%2048] = ' '; 260 circbuf[cbptr = (cbptr+1)%2048] = ' ';
261 circbuf[cbptr = (cbptr+1)%2048] = c^0x80; 261 circbuf[cbptr = (cbptr+1)%2048] = c^0x80;
262 return circbuf[outptr = (outptr+1)%2048]; 262 return circbuf[outptr = (outptr+1)%2048];
263 } 263 }
264} 264}
265 265
266unsigned int Aportis::GetBS(unsigned int bn) 266unsigned int Aportis::GetBS(unsigned int bn)
267{ 267{
268 DWORD dwPos; 268 DWORD dwPos;
269 WORD fs; 269 WORD fs;
270 270
271 fseek(fin, 0x56 + 8*bn, SEEK_SET); 271 fseek(fin, 0x56 + 8*bn, SEEK_SET);
272 fread(&dwPos, 4, 1, fin); 272 fread(&dwPos, 4, 1, fin);
273 dwPos = SwapLong(dwPos); 273 dwPos = SwapLong(dwPos);
274 fseek(fin,dwPos,SEEK_SET); 274 fseek(fin,dwPos,SEEK_SET);
275 275
276// gotorecordnumber(bn+1); 276// gotorecordnumber(bn+1);
277 unsigned char ch; 277 unsigned char ch;
278 fread(&ch,1,1,fin); 278 fread(&ch,1,1,fin);
279 if (ch == 241) 279 if (ch == 241)
280 { 280 {
281 fread(&fs,sizeof(fs),1,fin); 281 fread(&fs,sizeof(fs),1,fin);
282 fs = SwapWord(fs); 282 fs = SwapWord(fs);
283 } 283 }
284 else 284 else
285 fs = 0; 285 fs = 0;
286 return fs; 286 return fs;
287} 287}
288 288
289unsigned int Aportis::locate() 289unsigned int Aportis::locate()
290{ 290{
291 if (bCompressed == 4) 291 if (bCompressed == 4)
292 { 292 {
293 size_t cur = ftell(fin); 293 size_t cur = ftell(fin);
294 unsigned int clen = 0; 294 unsigned int clen = 0;
295 for (unsigned int i = 0; i < currentrec-1; i++) 295 for (unsigned int i = 0; i < currentrec-1; i++)
296 { 296 {
297 unsigned int bs = GetBS(i); 297 unsigned int bs = GetBS(i);
298 if (bs == 0) break; 298 if (bs == 0) break;
299 clen += bs; 299 clen += bs;
300 } 300 }
301 fseek(fin,cur,SEEK_SET); 301 fseek(fin,cur,SEEK_SET);
302 return clen+currentpos; 302 return clen+currentpos;
303 } 303 }
304 else 304 else
305 return (currentrec-1)*BlockSize+currentpos; 305 return (currentrec-1)*BlockSize+currentpos;
306} 306}
307 307
308void Aportis::locate(unsigned int n) 308void Aportis::locate(unsigned int n)
309{ 309{
310 unsigned int offset; 310 unsigned int offset;
311 // currentrec = (n >> OFFBITS); 311 // currentrec = (n >> OFFBITS);
312 switch (bCompressed) 312 switch (bCompressed)
313 { 313 {
314 case 4: 314 case 4:
315 { 315 {
316 DWORD clen = 0; 316 DWORD clen = 0;
317 offset = n; 317 offset = n;
318 unsigned int i; 318 unsigned int i;
319 for (i = 0; i < nRecs; i++) 319 for (i = 0; i < nRecs; i++)
320 { 320 {
321 unsigned int bs = GetBS(i); 321 unsigned int bs = GetBS(i);
322 if (bs == 0) break; 322 if (bs == 0) break;
323 clen += bs; 323 clen += bs;
324 if (clen > n) break; 324 if (clen > n) break;
325 offset = n - clen; 325 offset = n - clen;
326 } 326 }
327 currentrec = i; 327 currentrec = i;
328 } 328 }
329 break; 329 break;
330 case 1: 330 case 1:
331 case 2: 331 case 2:
332 default: 332 default:
333 currentrec = n / BlockSize; 333 currentrec = n / BlockSize;
334 offset = n % BlockSize; 334 offset = n % BlockSize;
335 } 335 }
336 336
337 outptr = cbptr; 337 outptr = cbptr;
338 refreshbuffer(); 338 refreshbuffer();
339 while (currentpos < offset && getch() != EOF); 339 while (currentpos < offset && getch() != EOF);
340} 340}
341 341
342bool Aportis::refreshbuffer() 342bool Aportis::refreshbuffer()
343{ 343{
344 if (currentrec < nRecs) 344 if (currentrec < nRecs)
345 { 345 {
346 dwRecLen = recordlength(currentrec+1); 346 dwRecLen = recordlength(currentrec+1);
347 gotorecordnumber(currentrec+1); 347 gotorecordnumber(currentrec+1);
348 if (bCompressed == 4) 348 if (bCompressed == 4)
349 { 349 {
350 unsigned char t[3]; 350 unsigned char t[3];
351 fread(t,1,3,fin); 351 fread(t,1,3,fin);
352 if (t[0] != 241) 352 if (t[0] != 241)
353 { 353 {
354 printf("You shouldn't be here!\n"); 354 printf("You shouldn't be here!\n");
355 return false; 355 return false;
356 } 356 }
357 dwRecLen -= 3; 357 dwRecLen -= 3;
358 } 358 }
359 /* 359 /*
360 int n = fread(t.buf, 1, dwRecLen, fin); 360 int n = fread(t.buf, 1, dwRecLen, fin);
361 t.len = n; 361 t.len = n;
362 // if(bCompressed) 362 // if(bCompressed)
363 t.Decompress(); 363 t.Decompress();
364 364
365 t.buf[t.Len()] = '\0'; 365 t.buf[t.Len()] = '\0';
366 */ 366 */
367 currentpos = 0; 367 currentpos = 0;
368 currentrec++; 368 currentrec++;
369 return true; 369 return true;
370 } 370 }
371 else { 371 else {
372 return false; 372 return false;
373 } 373 }
374} 374}
diff --git a/noncore/apps/opie-reader/Aportis.h b/noncore/apps/opie-reader/Aportis.h
index 1ca5e73..af1fd3b 100644
--- a/noncore/apps/opie-reader/Aportis.h
+++ b/noncore/apps/opie-reader/Aportis.h
@@ -1,100 +1,108 @@
1/* 1/*
2 Derived from makedoc9 by Pat Beirne 2 Derived from makedoc9 by Pat Beirne
3*/ 3*/
4 4
5#ifndef __Aportis_h 5#ifndef __Aportis_h
6#define __Aportis_h 6#define __Aportis_h
7 7
8#include "CExpander.h" 8#include "CExpander.h"
9#include "pdb.h" 9#include "pdb.h"
10 10
11typedef UInt32 DWORD; 11typedef UInt32 DWORD;
12typedef UInt16 WORD; 12typedef UInt16 WORD;
13 13
14#define DISP_BITS 11 14#define DISP_BITS 11
15#define COUNT_BITS 3 15#define COUNT_BITS 3
16/* 16/*
17// all numbers in these structs are big-endian, MAC format 17// all numbers in these structs are big-endian, MAC format
18struct tDocHeader { 18struct tDocHeader {
19 char sName[32]; 19 char sName[32];
20 DWORD dwUnknown1; 20 DWORD dwUnknown1;
21 DWORD dwTime1; 21 DWORD dwTime1;
22 DWORD dwTime2; 22 DWORD dwTime2;
23 DWORD dwTime3; 23 DWORD dwTime3;
24 DWORD dwLastSync; 24 DWORD dwLastSync;
25 DWORD ofsSort; 25 DWORD ofsSort;
26 DWORD ofsCatagories; 26 DWORD ofsCatagories;
27 DWORD dwCreator; 27 DWORD dwCreator;
28 DWORD dwType; 28 DWORD dwType;
29 DWORD dwUnknown2; 29 DWORD dwUnknown2;
30 DWORD dwUnknown3; 30 DWORD dwUnknown3;
31 WORD wNumRecs; 31 WORD wNumRecs;
32}; 32};
33*/ 33*/
34struct tDocRecord0 { 34struct tDocRecord0 {
35 WORD wVersion;// 1=plain text, 2=compressed 35 WORD wVersion;// 1=plain text, 2=compressed
36 WORD wSpare; 36 WORD wSpare;
37 DWORD dwStoryLen; // in chars, when decompressed 37 DWORD dwStoryLen; // in chars, when decompressed
38 WORD wNumRecs; // text records only; equals tDocHeader.wNumRecs-1 38 WORD wNumRecs; // text records only; equals tDocHeader.wNumRecs-1
39 WORD wRecSize; // usually 0x1000 39 WORD wRecSize; // usually 0x1000
40 DWORD dwSpare2; 40 DWORD dwSpare2;
41}; 41};
42 42
43struct PeanutHeader 43struct PeanutHeader
44{ 44{
45 UInt16 Version; 45 UInt16 Version;
46 UInt8 Junk1[6]; 46 UInt8 Junk1[6];
47 UInt16 Records; 47 UInt16 Records;
48 UInt8 Junk2[106]; 48 UInt8 Junk2[106];
49}; 49};
50 50
51////////////// utilities ////////////////////////////////////// 51////////////// utilities //////////////////////////////////////
52 52
53inline WORD SwapWord(WORD r) 53inline WORD SwapWord(WORD r)
54{ 54{
55 return (r>>8) + (r<<8); 55 return (r>>8) + (r<<8);
56} 56}
57 57
58inline DWORD SwapLong(DWORD r) 58inline DWORD SwapLong(DWORD r)
59{ 59{
60 return ((r>>24) & 0xFF) + (r<<24) + ((r>>8) & 0xFF00) + ((r<<8) & 0xFF0000); 60 return ((r>>24) & 0xFF) + (r<<24) + ((r>>8) & 0xFF00) + ((r<<8) & 0xFF0000);
61} 61}
62 62
63class Aportis : public CExpander, Cpdb { 63class Aportis : public CExpander, Cpdb {
64 bool peanutfile; 64 bool peanutfile;
65 void dePeanut(int&); 65 void dePeanut(int&);
66 DWORD dwLen; 66 DWORD dwLen;
67 WORD nRecs2; 67 WORD nRecs2;
68 DWORD dwTLen; 68 DWORD dwTLen;
69 WORD nRecs; 69 WORD nRecs;
70 WORD BlockSize; 70 WORD BlockSize;
71 DWORD dwRecLen; 71 DWORD dwRecLen;
72 int currentrec, currentpos; 72 int currentrec, currentpos;
73 unsigned int cbptr; 73 unsigned int cbptr;
74 unsigned int outptr; 74 unsigned int outptr;
75 unsigned char circbuf[2048]; 75 unsigned char circbuf[2048];
76 char bCompressed; 76 char bCompressed;
77public: 77public:
78 virtual void suspend()
79 {
80 CExpander::suspend(fin);
81 }
82 virtual void unsuspend()
83 {
84 CExpander::unsuspend(fin);
85 }
78 virtual void sizes(unsigned long& _file, unsigned long& _text) 86 virtual void sizes(unsigned long& _file, unsigned long& _text)
79 { 87 {
80 _file = dwLen; 88 _file = dwLen;
81 _text = dwTLen; 89 _text = dwTLen;
82 } 90 }
83 virtual bool hasrandomaccess() { return true; } 91 virtual bool hasrandomaccess() { return true; }
84 virtual ~Aportis() {} 92 virtual ~Aportis() {}
85 Aportis(); 93 Aportis();
86 virtual int openfile(const char *src); 94 virtual int OpenFile(const char *src);
87 virtual int getch(); 95 virtual int getch();
88 virtual unsigned int locate(); 96 virtual unsigned int locate();
89 virtual void locate(unsigned int n); 97 virtual void locate(unsigned int n);
90 virtual CList<Bkmk>* getbkmklist(); 98 virtual CList<Bkmk>* getbkmklist();
91 virtual MarkupType PreferredMarkup() 99 virtual MarkupType PreferredMarkup()
92 { 100 {
93 return (peanutfile) ? cPML : cTEXT; 101 return (peanutfile) ? cPML : cTEXT;
94 } 102 }
95private: 103private:
96 bool refreshbuffer(); 104 bool refreshbuffer();
97 unsigned int GetBS(unsigned int bn); 105 unsigned int GetBS(unsigned int bn);
98}; 106};
99 107
100#endif 108#endif
diff --git a/noncore/apps/opie-reader/Bkmks.cpp b/noncore/apps/opie-reader/Bkmks.cpp
index 30d2881..998601a 100644
--- a/noncore/apps/opie-reader/Bkmks.cpp
+++ b/noncore/apps/opie-reader/Bkmks.cpp
@@ -1,240 +1,322 @@
1#include "name.h"
1#include <qmessagebox.h> 2#include <qmessagebox.h>
2 3
3#include "Bkmks.h" 4#include "Bkmks.h"
4 5
5#include "StyleConsts.h" 6#include "StyleConsts.h"
6#include "Markups.h" 7#include "Markups.h"
7#include "my_list.h" 8#include "my_list.h"
8#include "version.h" 9#include "version.h"
9 10
10const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE); 11const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE);
11 12
13Bkmk::Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p) : m_position(_p)
14{
15 init(_nm, _nmlen, _anno, _annolen, _p);
16}
17
18Bkmk::Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short annolen, unsigned int _p) : m_position(_p)
19{
20 init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, annolen, _p);
21}
12 22
13Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p) 23Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p)
14{ 24{
15 int len = ustrlen(_nm)+1;
16 m_name = new tchar[len];
17 for (int i = 0; i < len; i++) m_name[i] = _nm[i];
18 25
19 if (_anno == NULL) 26 if (_anno == NULL)
20 { 27 {
21 m_anno = new tchar[1]; 28 tchar t = 0;
22 m_anno[0] = 0; 29 init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), &t, sizeof(t), _p);
23 } 30 }
24 else 31 else
25 { 32 {
26 len = ustrlen(_anno)+1; 33 init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, sizeof(tchar)*(ustrlen(_anno)+1), _p);
27 m_anno = new tchar[len];
28 for (int i = 0; i < len; i++) m_anno[i] = _anno[i];
29 } 34 }
30} 35}
31 36
37void Bkmk::init(const void* _nm, unsigned short _nmlen, const void* _anno, unsigned short _annolen, unsigned int _p)
38{
39 m_namelen = _nmlen;
40 if (m_namelen > 0)
41 {
42 m_name = new unsigned char[m_namelen];
43 memcpy(m_name, _nm, m_namelen);
44 }
45 else
46 {
47 m_name = NULL;
48 }
49
50 m_annolen = _annolen;
51 if (m_annolen > 0)
52 {
53 m_anno = new unsigned char[m_annolen];
54 memcpy(m_anno, _anno, m_annolen);
55 }
56 else
57 {
58 m_anno = NULL;
59 }
60 m_position = _p;
61}
62
32Bkmk::~Bkmk() 63Bkmk::~Bkmk()
33{ 64{
34 if (m_name != NULL) delete [] m_name; 65 if (m_name != NULL) delete [] m_name;
35 m_name = NULL; 66 m_name = NULL;
36 if (m_anno != NULL) delete [] m_anno; 67 if (m_anno != NULL) delete [] m_anno;
37 m_anno = NULL; 68 m_anno = NULL;
38} 69}
39 70
40Bkmk& Bkmk::operator=(const Bkmk& rhs) 71Bkmk& Bkmk::operator=(const Bkmk& rhs)
41{ 72{
42 if (m_name != NULL) 73 if (m_name != NULL)
43 { 74 {
44 delete [] m_name; 75 delete [] m_name;
45 m_name = NULL; 76 m_name = NULL;
46 } 77 }
47 if (m_anno != NULL) 78 if (m_anno != NULL)
48 { 79 {
49 delete [] m_anno; 80 delete [] m_anno;
50 m_anno = NULL; 81 m_anno = NULL;
51 } 82 }
52 if (rhs.m_name != NULL) 83 if (rhs.m_name != NULL)
53 { 84 {
54 int len = ustrlen(rhs.m_name)+1; 85 m_namelen = rhs.m_namelen;
55 m_name = new tchar[len]; 86 m_name = new unsigned char[m_namelen];
56 for (int i = 0; i < len; i++) m_name[i] = rhs.m_name[i]; 87 memcpy(m_name, rhs.m_name, m_namelen);
57 } 88 }
58 else 89 else
59 m_name = NULL; 90 m_name = NULL;
60 if (rhs.m_anno != NULL) 91 if (rhs.m_anno != NULL)
61 { 92 {
62 int len = ustrlen(rhs.m_anno)+1; 93 m_annolen = rhs.m_annolen;
63 m_anno = new tchar[len]; 94 m_anno = new unsigned char[m_annolen];
64 for (int i = 0; i < len; i++) m_anno[i] = rhs.m_anno[i]; 95 memcpy(m_anno, rhs.m_anno, m_annolen);
65 } 96 }
66 else 97 else
67 m_anno = NULL; 98 m_anno = NULL;
68 m_position = rhs.m_position; 99 m_position = rhs.m_position;
69 return *this; 100 return *this;
70} 101}
71 102
72bool Bkmk::operator==(const Bkmk& rhs) 103bool Bkmk::operator==(const Bkmk& rhs)
73{ 104{
74 return (m_position == rhs.m_position && ustrcmp(m_name,rhs.m_name) == 0); 105 return (m_position == rhs.m_position && (rhs.m_namelen == m_namelen) && memcmp(m_name,rhs.m_name,m_namelen) == 0);
106}
107
108void Bkmk::setAnno(unsigned char* t, unsigned short len)
109{
110 if (m_anno != NULL)
111 {
112 delete [] m_anno;
113 m_anno = NULL;
114 }
115 if (t != NULL)
116 {
117 m_annolen = len;
118 m_anno = new unsigned char[m_annolen];
119 memcpy(m_anno, t, m_annolen);
120 }
121 else
122 {
123 m_annolen = sizeof(tchar);
124 m_anno = new unsigned char[m_annolen];
125 *((tchar*)m_anno) = 0;
126 }
75} 127}
76 128
77void Bkmk::setAnno(tchar* t) 129void Bkmk::setAnno(tchar* t)
78{ 130{
79 if (m_anno != NULL) 131 if (m_anno != NULL)
80 { 132 {
81 delete [] m_anno; 133 delete [] m_anno;
82 m_anno = NULL; 134 m_anno = NULL;
83 } 135 }
84 if (t != NULL) 136 if (t != NULL)
85 { 137 {
86 int len = ustrlen(t)+1; 138 unsigned short len = ustrlen(t)+1;
87 m_anno = new tchar[len]; 139 m_annolen = sizeof(tchar)*len;
88 for (int i = 0; i < len; i++) m_anno[i] = t[i]; 140 m_anno = new unsigned char[m_annolen];
141 memcpy(m_anno, t, m_annolen);
89 } 142 }
90 else 143 else
91 m_anno = NULL; 144 {
145 m_annolen = sizeof(tchar);
146 m_anno = new unsigned char[m_annolen];
147 *((tchar*)m_anno) = 0;
148 }
92} 149}
93 150
94BkmkFile::BkmkFile(const char *fnm, bool w ) 151BkmkFile::BkmkFile(const char *fnm, bool w = false)
95 : 152 :
96 wt(w), isUpgraded(false) 153 wt(w), isUpgraded(false)
97{ 154{
98 if (w) 155 if (w)
99 { 156 {
100 f = fopen(fnm, "wb"); 157 f = fopen(fnm, "wb");
101 } 158 }
102 else 159 else
103 { 160 {
104 f = fopen(fnm, "rb"); 161 f = fopen(fnm, "rb");
105 } 162 }
106} 163}
107 164
108BkmkFile::~BkmkFile() 165BkmkFile::~BkmkFile()
109{ 166{
110 if (f != NULL) fclose(f); 167 if (f != NULL) fclose(f);
111} 168}
112 169
113void BkmkFile::write(tchar* nm, tchar* an, const unsigned int& pos) 170void BkmkFile::write(const Bkmk& b)
114{ 171{
115 if (f != NULL) 172 if (f != NULL)
116 { 173 {
117 unsigned short ln = ustrlen(nm); 174 fwrite(&b.m_namelen, sizeof(b.m_namelen),1,f);
118 fwrite(&ln,sizeof(ln),1,f); 175 fwrite(b.m_name,1,b.m_namelen,f);
119 fwrite(nm,sizeof(tchar),ln,f); 176 fwrite(&b.m_annolen, sizeof(b.m_annolen),1,f);
120 ln = ustrlen(an); 177 fwrite(b.m_anno,1,b.m_annolen,f);
121 fwrite(&ln,sizeof(ln),1,f); 178 fwrite(&b.m_position,sizeof(b.m_position),1,f);
122 if (ln > 0) fwrite(an,sizeof(tchar),ln,f);
123 fwrite(&pos,sizeof(pos),1,f);
124 } 179 }
125} 180}
126 181
127void BkmkFile::write(const Bkmk& b) { write(b.name(), b.anno(), b.value()); }
128
129void BkmkFile::write(CList<Bkmk>& bl) 182void BkmkFile::write(CList<Bkmk>& bl)
130{ 183{
131 if (f != NULL) 184 if (f != NULL)
132 { 185 {
133 fwrite(&magic, sizeof(magic), 1, f); 186 fwrite(&magic, sizeof(magic), 1, f);
134 for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++) 187 for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++)
135 { 188 {
136 write(*i); 189 write(*i);
137 } 190 }
138 }
139}
140
141Bkmk* BkmkFile::read()
142{
143 Bkmk* b = NULL;
144 if (f != NULL)
145 {
146 unsigned short ln;
147 if (fread(&ln,sizeof(ln),1,f) == 1)
148 {
149 b = new Bkmk;
150 b->m_name = new tchar[ln+1];
151 fread(b->m_name,sizeof(tchar),ln,f);
152 b->m_name[ln] = 0;
153
154 fread(&ln,sizeof(ln),1,f);
155 b->m_anno = new tchar[ln+1];
156 if (ln > 0) fread(b->m_anno,sizeof(tchar),ln,f);
157 b->m_anno[ln] = 0;
158 fread(&b->m_position,sizeof(b->m_position),1,f);
159 }
160 } 191 }
161 return b;
162} 192}
163 193
164CList<Bkmk>* BkmkFile::readall() 194CList<Bkmk>* BkmkFile::readall()
165{ 195{
166 CList<Bkmk>* bl = NULL; 196 CList<Bkmk>* bl = NULL;
167 if (f != NULL) 197 if (f != NULL)
168 { 198 {
169 unsigned long newmagic; 199 unsigned long newmagic;
170 fread(&newmagic, sizeof(newmagic), 1, f); 200 fread(&newmagic, sizeof(newmagic), 1, f);
171 if (newmagic != magic) 201 if ((newmagic & 0xffffff00) != (magic & 0xffffff00))
172 { 202 {
173 if (QMessageBox::warning(NULL, "Old bookmark file!", "Which version of OpieReader\ndid you upgrade from?", "0_4*", "Any other version") == 0) 203 if (QMessageBox::warning(NULL, "Old bookmark file!", "Which version of " PROGNAME "\ndid you upgrade from?", "0_4*", "Any other version") == 0)
174 { 204 {
175 fseek(f,0,SEEK_SET); 205 fseek(f,0,SEEK_SET);
176 bl = readall04(); 206 bl = readall00(&read05);
177 } 207 }
178 else 208 else
179 { 209 {
180 fseek(f,0,SEEK_SET); 210 fseek(f,0,SEEK_SET);
181 bl = readall03(); 211 bl = readall00(&read03);
182 } 212 }
183 isUpgraded = true; 213 isUpgraded = true;
184 } 214 }
185 else 215 else
186 { 216 {
187 bl = readall04(); 217 switch(newmagic & 0xff)
188 } 218 {
219 case 6:
220 isUpgraded = false;
221 bl = readall00(read06);
222 qDebug("Correct version!");
223 break;
224 case 5:
225 isUpgraded = true;
226 bl = readall00(read05);
227 qDebug("Known version!");
228 break;
229 default:
230 qDebug("Unknown version!");
231 isUpgraded = true;
232 bl = readall00(read05);
233 }
234 }
189 } 235 }
190 return bl; 236 return bl;
191} 237}
192 238
193CList<Bkmk>* BkmkFile::readall04() 239CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(FILE*))
194{ 240{
195 CList<Bkmk>* bl = new CList<Bkmk>; 241 CList<Bkmk>* bl = new CList<Bkmk>;
196 while (1) 242 while (1)
197 { 243 {
198 Bkmk* b = read(); 244 Bkmk* b = (*readfn)(f);
199 if (b == NULL) break; 245 if (b == NULL) break;
200 bl->push_back(*b); 246 bl->push_back(*b);
201 delete b; 247 delete b;
202 } 248 }
203 return bl; 249 return bl;
204} 250}
205 251
206CList<Bkmk>* BkmkFile::readall03() 252Bkmk* BkmkFile::read03(FILE* f)
207{ 253{
208 CList<Bkmk>* bl = new CList<Bkmk>; 254 Bkmk* b = NULL;
209 while (1) 255 if (f != NULL)
210 { 256 {
211 Bkmk* b = read03(); 257 unsigned short ln;
212 if (b == NULL) break; 258 if (fread(&ln,sizeof(ln),1,f) == 1)
213 bl->push_back(*b); 259 {
214 delete b; 260 tchar* name = new tchar[ln+1];
261 fread(name,sizeof(tchar),ln,f);
262 name[ln] = 0;
263
264 ln = 0;
265 tchar* anno = new tchar[ln+1];
266 anno[ln] = 0;
267
268 unsigned int pos;
269 fread(&pos,sizeof(pos),1,f);
270 b = new Bkmk(name,anno,pos);
271 }
215 } 272 }
216 return bl; 273 return b;
217} 274}
218 275
219Bkmk* BkmkFile::read03() 276Bkmk* BkmkFile::read05(FILE* f)
220{ 277{
221 Bkmk* b = NULL; 278 Bkmk* b = NULL;
222 if (f != NULL) 279 if (f != NULL)
223 { 280 {
224 unsigned short ln; 281 unsigned short ln;
225 if (fread(&ln,sizeof(ln),1,f) == 1) 282 if (fread(&ln,sizeof(ln),1,f) == 1)
226 { 283 {
227 b = new Bkmk; 284 tchar* nm = new tchar[ln+1];
228 b->m_name = new tchar[ln+1]; 285 fread(nm,sizeof(tchar),ln,f);
229 fread(b->m_name,sizeof(tchar),ln,f); 286 nm[ln] = 0;
230 b->m_name[ln] = 0; 287 fread(&ln,sizeof(ln),1,f);
288 tchar* anno = new tchar[ln+1];
289 if (ln > 0) fread(anno,sizeof(tchar),ln,f);
290 anno[ln] = 0;
291 unsigned int pos;
292 fread(&pos,sizeof(pos),1,f);
293 b = new Bkmk(nm,anno,pos);
294 }
295 }
296 return b;
297}
231 298
232 ln = 0; 299Bkmk* BkmkFile::read06(FILE* f)
233 b->m_anno = new tchar[ln+1]; 300{
234 b->m_anno[ln] = 0; 301 Bkmk* b = NULL;
302 if (f != NULL)
303 {
304 unsigned short ln;
305 if (fread(&ln,sizeof(ln),1,f) == 1)
306 {
307 b = new Bkmk;
308 b->m_namelen = ln;
309 b->m_name = new unsigned char[b->m_namelen];
310 fread(b->m_name,1,b->m_namelen,f);
235 311
236 fread(&b->m_position,sizeof(b->m_position),1,f); 312 fread(&(b->m_annolen),sizeof(b->m_annolen),1,f);
237 } 313 if (b->m_annolen > 0)
314 {
315 b->m_anno = new unsigned char[b->m_annolen];
316 fread(b->m_anno,1,b->m_annolen,f);
317 }
318 fread(&(b->m_position),sizeof(b->m_position),1,f);
319 }
238 } 320 }
239 return b; 321 return b;
240} 322}
diff --git a/noncore/apps/opie-reader/Bkmks.h b/noncore/apps/opie-reader/Bkmks.h
index b38184a..ee528e4 100644
--- a/noncore/apps/opie-reader/Bkmks.h
+++ b/noncore/apps/opie-reader/Bkmks.h
@@ -1,53 +1,70 @@
1#ifndef __Bkmks_h 1#ifndef __Bkmks_h
2#define __Bkmks_h 2#define __Bkmks_h
3 3
4#include "config.h" 4#include "config.h"
5#include "Filedata.h"
5#include <stdio.h> 6#include <stdio.h>
6 7
7template<class T> 8template<class T>
8class CList; 9class CList;
9 10
10class Bkmk 11class Bkmk
11{ 12{
12 friend class BkmkFile; 13 friend class BkmkFile;
13 tchar* m_name; 14 unsigned char* m_name;
14 tchar* m_anno; 15 unsigned short m_namelen;
16 unsigned char* m_anno;
17 unsigned short m_annolen;
15 unsigned int m_position; 18 unsigned int m_position;
19 void init(const void*, unsigned short, const void*, unsigned short, unsigned int);
16 public: 20 public:
17 Bkmk() : m_name(NULL), m_anno(NULL), m_position(0) {}; 21 Bkmk() : m_name(NULL), m_namelen(0), m_anno(NULL), m_annolen(0), m_position(0) {};
22 Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p);
23 Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short _annolen, unsigned int _p);
18 Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p); 24 Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p);
19 Bkmk(const Bkmk& rhs) : m_name(NULL), m_anno(NULL) 25 Bkmk(const Bkmk& rhs) : m_name(NULL), m_anno(NULL)
20 { 26 {
21 *this = rhs; 27 *this = rhs;
22 } 28 }
23 ~Bkmk(); 29 ~Bkmk();
24 unsigned int value() const { return m_position; } 30 unsigned int value() const { return m_position; }
25 tchar *name() const { return m_name; } 31 void value(unsigned int _v) { m_position = _v; }
26 tchar *anno() const { return m_anno; } 32 tchar *name() const { return (tchar*)m_name; }
33 tchar *anno() const { return (tchar*)m_anno; }
27 bool operator<(const Bkmk& rhs) { return (m_position < rhs.m_position); } 34 bool operator<(const Bkmk& rhs) { return (m_position < rhs.m_position); }
28 Bkmk& operator=(const Bkmk& rhs); 35 Bkmk& operator=(const Bkmk& rhs);
29 bool operator==(const Bkmk& rhs); 36 bool operator==(const Bkmk& rhs);
30 void setAnno(tchar* t); 37 void setAnno(tchar* t);
38 void setAnno(unsigned char* t, unsigned short len);
39 unsigned char* filedata()
40 {
41 CFiledata fd(anno());
42 return m_anno+fd.length();
43 }
44 unsigned short filedatalen()
45 {
46 CFiledata fd(anno());
47 return m_annolen - fd.length();
48 }
31}; 49};
32 50
33class BkmkFile 51class BkmkFile
34{ 52{
35 FILE* f; 53 FILE* f;
36 bool wt; 54 bool wt;
37 bool isUpgraded; 55 bool isUpgraded;
38 static const unsigned long magic; 56 static const unsigned long magic;
39 private: 57 private:
40 Bkmk* read(); 58 static Bkmk* read06(FILE*);
41 Bkmk* read03(); 59 static Bkmk* read05(FILE*);
42 CList<Bkmk>* readall03(); 60 static Bkmk* read03(FILE*);
43 CList<Bkmk>* readall04(); 61 CList<Bkmk>* readall00(Bkmk*(*fn)(FILE*));
44 void write(tchar* nm, tchar* an, const unsigned int& pos);
45 void write(const Bkmk& b); 62 void write(const Bkmk& b);
46 public: 63 public:
47 bool upgraded() { return isUpgraded; } 64 bool upgraded() { return isUpgraded; }
48 BkmkFile(const char *fnm, bool w = false); 65 BkmkFile(const char *fnm, bool w = false);
49 ~BkmkFile(); 66 ~BkmkFile();
50 void write(CList<Bkmk>& bl); 67 void write(CList<Bkmk>& bl);
51 CList<Bkmk>* readall(); 68 CList<Bkmk>* readall();
52}; 69};
53#endif 70#endif
diff --git a/noncore/apps/opie-reader/BuffDoc.cpp b/noncore/apps/opie-reader/BuffDoc.cpp
index d4541ea..1123960 100644
--- a/noncore/apps/opie-reader/BuffDoc.cpp
+++ b/noncore/apps/opie-reader/BuffDoc.cpp
@@ -1,224 +1,356 @@
1#include "name.h"
2
1#include "BuffDoc.h" 3#include "BuffDoc.h"
2//#include <FL/fl_draw.h> 4//#include <FL/fl_draw.h>
3#include "config.h" 5#include "config.h"
4#include "CDrawBuffer.h" 6#include "CDrawBuffer.h"
5#include "plucker.h" 7#include "plucker.h"
6 8
7 9
8bool BuffDoc::hyperlink(unsigned int n) 10bool BuffDoc::hyperlink(unsigned int n)
9{ 11{
10 bool bRet = false; 12 bool bRet = false;
11 lastword.empty(); 13 lastword.empty();
12 lastsizes[0] = laststartline = n; 14 lastsizes[0] = laststartline = n;
13 lastispara = false; 15 lastispara = false;
14 if (exp != NULL) 16 if (exp != NULL)
15 { 17 {
16 bRet = exp->hyperlink(n); 18 bRet = exp->hyperlink(n);
17 lastsizes[0] = laststartline = exp->locate(); 19 lastsizes[0] = laststartline = exp->locate();
18 } 20 }
19 return bRet; 21 return bRet;
20} 22}
21 23
22void BuffDoc::locate(unsigned int n) 24void BuffDoc::locate(unsigned int n)
23{ 25{
24 // qDebug("BuffDoc:locating:%u",n); 26 // qDebug("BuffDoc:locating:%u",n);
25 lastword.empty(); 27 lastword.empty();
26 lastsizes[0] = laststartline = n; 28 lastsizes[0] = laststartline = n;
27 lastispara = false; 29 lastispara = false;
28 // tchar linebuf[1024]; 30 // tchar linebuf[1024];
29 if (exp != NULL) exp->locate(n); 31 if (exp != NULL) exp->locate(n);
30 // qDebug("BuffDoc:Located"); 32 // qDebug("BuffDoc:Located");
31} 33}
32 34
33bool BuffDoc::getline(CDrawBuffer* buff, int w) 35#define NEWLINEBREAK
36#ifdef NEWLINEBREAK
37bool BuffDoc::getline(CDrawBuffer* buff, int wth)
34{ 38{
39 bool moreleft = true;
40 bool margindone = false;
41 int w = wth-2*BORDER;
35 tchar ch = 32; 42 tchar ch = 32;
36 CStyle cs; 43 CStyle cs;
37 buff->empty(); 44 buff->empty();
38 if (exp == NULL) 45 if (exp == NULL)
39 { 46 {
40// (*buff)[0] = '\0'; 47 buff->empty();
41 buff->empty(); 48 buff->setEof();
42 return false; 49 return false;
50 }
51 int len = 0;
52 if (lastword.length() > 0)
53 {
54 *buff = lastword;
55 cs = lastword.laststyle();
56 w -= buff->leftMargin() + buff->rightMargin();
57 margindone = true;
58 len = lastword.length();
59 }
60 else buff->empty();
61 lastword.empty();
62 unsigned int slen = buff->width(len);
63 lastispara = false;
64 while (1)
65 {
66 lastsizes[len] = exp->locate();
67 getch(ch, cs);
68 if (ch == UEOF)
69 {
70 lastword.empty();
71 if (len == 0)
72 {
73 buff->setEof();
74 moreleft = false;
75 }
76 laststartline = exp->locate();
77 break;
78 }
79 if (ch == 10)
80 {
81 lastword.empty();
82 lastispara = true;
83 laststartline = exp->locate();
84 break;
85 }
86 buff->addch(ch, cs);
87 len++;
88 if (!margindone)
89 {
90 w -= buff->leftMargin() + buff->rightMargin();
91 margindone = true;
92 }
93 if ((slen = buff->width(len)) > w)
94 {
95 if (ch == ' ' || len == 1)
96 {
97 lastword.empty();
98 laststartline = exp->locate();
99 break;
100 }
101 else // should do a backward search for spaces, first.
102 {
103 for (int i = len-1; i > 0; i--)
104 {
105 if ((*buff)[i] == ' ')
106 {
107 (*buff)[len] = 0;
108 lastword.setright(*buff, i+1);
109 buff->truncate(i);
110 (*buff)[i] = '\0';
111 laststartline = lastsizes[i+1];
112 buff->resize();
113 for (int j = 0; j < lastword.length(); j++)
114 {
115 lastsizes[j] = lastsizes[j+i+1];
116 }
117 return true;
118 }
119 }
120 laststartline = lastsizes[len-1];
121 lastword.setright(*buff, len - 1);
122 buff->truncate(len-1);
123 buff->addch('-', cs);
124 for (int j = 0; j < lastword.length(); j++)
125 {
126 lastsizes[j] = lastsizes[j+len];
127 }
128 break;
129 }
130 }
131 }
132 (*buff)[len] = '\0';
133 buff->resize();
134 return moreleft;
135}
136#else
137bool BuffDoc::getline(CDrawBuffer* buff, int wth)
138{
139 bool margindone = false;
140 int w = wth-2*BORDER;
141 tchar ch = 32;
142 CStyle cs;
143 buff->empty();
144 if (exp == NULL)
145 {
146 //(*buff)[0] = '\0';
147 buff->empty();
148 return false;
43 } 149 }
44 int len = 0, lastcheck = 0; 150 int len = 0, lastcheck = 0;
45 if (lastword.length() > 0) 151 if (lastword.length() > 0)
46 { 152 {
47 *buff = lastword; 153 *buff = lastword;
48 cs = lastword.laststyle(); 154 cs = lastword.laststyle();
155 w -= buff->leftMargin() + buff->rightMargin();
156 margindone = true;
49 } 157 }
50 else buff->empty(); 158 else buff->empty();
51// qDebug("Buff:%s Lastword:%s", (const char*)toQString(buff->data()), (const char*)toQString(lastword.data())); 159// qDebug("Buff:%s Lastword:%s", (const char*)toQString(buff->data()), (const char*)toQString(lastword.data()));
52 lastcheck = len = buff->length(); 160 lastcheck = len = buff->length();
53 unsigned int slen = buff->width(len); 161 unsigned int slen = buff->width(len);
54 if (slen > w) 162 if (slen > w)
55 { 163 {
56 for ( ; len > 0; len--) 164 for ( ; len > 1; len--)
57 { 165 {
58 if (buff->width(len) < w) break; 166 if (buff->width(len) < w) break;
59 } 167 }
60// lastword = buff->data() + len - 1; 168// lastword = buff->data() + len - 1;
61 laststartline = lastsizes[len-1]; 169 laststartline = lastsizes[len-1];
62 lastword.setright(*buff, len - 1);
63 for (int i = 0; i < buff->length(); i++) lastsizes[i] = lastsizes[i+len-1]; 170 for (int i = 0; i < buff->length(); i++) lastsizes[i] = lastsizes[i+len-1];
64// (*buff)[len-1] = '-'; 171// (*buff)[len-1] = '-';
65 buff->truncate(len-1); 172 if (len > 2)
66 buff->addch('-', cs); 173 {
67 (*buff)[len] = '\0'; 174 lastword.setright(*buff, len - 1);
175 buff->truncate(len-1);
176 buff->addch('-', cs);
177 (*buff)[len] = '\0';
178 }
179
180 else
181 {
182 lastword.empty();
183 (*buff)[len] = '\0';
184 }
185 buff->resize();
68 return true; 186 return true;
69 } 187 }
70 if (lastispara) 188 if (lastispara)
71 { 189 {
72 lastispara = false; 190 lastispara = false;
73// lastword[0] = '\0'; 191// lastword[0] = '\0';
74 lastword.empty(); 192 lastword.empty();
75 len = buff->length(); 193 len = buff->length();
76 while (buff->width(len) > w) len--; 194 while (buff->width(len) > w) len--;
77// (*buff)[len] = '\0'; 195// (*buff)[len] = '\0';
78 buff->truncate(len); 196 buff->truncate(len);
79 laststartline = exp->locate(); 197 laststartline = exp->locate();
198 buff->resize();
80 return true; 199 return true;
81 } 200 }
82 lastispara = false; 201 lastispara = false;
83 for (int i = 0; i < len; i++) allsizes[i] = lastsizes[i]; 202 for (int i = 0; i < len; i++) allsizes[i] = lastsizes[i];
84 while (slen < w) 203 while (slen < w)
85 { 204 {
86 lastcheck = len; 205 lastcheck = len;
87 allsizes[len] = exp->locate(); 206 allsizes[len] = exp->locate();
88 getch(ch, cs); 207 getch(ch, cs);
89 while (ch != ' ' && ch != '\012' && ch != UEOF && len < 128) 208 while (ch != ' ' && ch != '\012' && ch != UEOF && len < 128)
90 { 209 {
91 len++; 210 len++;
92 buff->addch(ch,cs); 211 buff->addch(ch,cs);
93 allsizes[len] = exp->locate(); 212 allsizes[len] = exp->locate();
94 getch(ch, cs); 213 getch(ch, cs);
95 } 214 }
96 (*buff)[len] = 0; 215 (*buff)[len] = 0;
97 slen = buff->width(len); 216 slen = buff->width(len);
98 len++; 217 len++;
99 buff->addch(' ', cs); 218 buff->addch(' ', cs);
219 if (!margindone)
220 {
221 w -= buff->leftMargin() + buff->rightMargin();
222 margindone = true;
223 }
100 allsizes[len] = exp->locate(); 224 allsizes[len] = exp->locate();
101 if (slen < w && ch != ' ') 225 if (slen < w && ch != ' ')
102 { 226 {
103 lastcheck = len; 227 lastcheck = len;
104 break; 228 break;
105 } 229 }
106 lastispara = (ch == '\012'); 230 lastispara = (ch == '\012');
107 } 231 }
108 (*buff)[len] = '\0'; 232 (*buff)[len] = '\0';
109// lastword = buff->data()+lastcheck; 233// lastword = buff->data()+lastcheck;
110 lastword.setright(*buff, lastcheck); 234#ifdef WINDOWS
235 lastword.setright(*buff, (lastcheck > 0) ? lastcheck : 1);
236 {
237 int i;
238 for (i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck];
239 }
240#else
241 lastword.setright(*buff, (lastcheck > 0) ? lastcheck : 1);
111 for (int i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck]; 242 for (int i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck];
243#endif
112 if (lastcheck > 0) 244 if (lastcheck > 0)
113 { 245 {
114 laststartline = allsizes[lastcheck]; 246 laststartline = allsizes[lastcheck];
115// (*buff)[lastcheck-1] = '\0'; 247// (*buff)[lastcheck-1] = '\0';
116 buff->truncate(lastcheck-1); 248 buff->truncate(lastcheck-1);
117 } 249 }
118 else 250 else
119 { 251 {
120 laststartline = (lastcheck == len) ? exp->locate() : allsizes[lastcheck+1]; 252 laststartline = (lastcheck == len) ? exp->locate() : allsizes[lastcheck+1];
121// (*buff)[lastcheck] = '\0'; 253// (*buff)[lastcheck] = '\0';
122 buff->truncate(lastcheck); 254 buff->truncate(lastcheck);
123 } 255 }
124// buff->frig(); 256// buff->frig();
125 return (ch != UEOF); 257 buff->resize();
258 if (ch == UEOF && buff->length() == 0)
259 {
260 buff->setEof();
261 return false;
262 }
263 return true;
126} 264}
265#endif
127 266
128bool BuffDoc::getline(CDrawBuffer* buff, int w, int cw) 267bool BuffDoc::getline(CDrawBuffer* buff, int wth, int cw)
129{ 268{
269 int w = wth-2*BORDER;
130 buff->empty(); 270 buff->empty();
131 if (exp == NULL) 271 if (exp == NULL)
132 { 272 {
133 return false; 273 return false;
134 } 274 }
135 tchar ch; 275 tchar ch;
136 CStyle cs; 276 CStyle cs;
137 int i = 0; 277 int i = 0;
138 while (i*cw < w) 278 while (i*cw < w)
139 { 279 {
140 getch(ch, cs); 280 getch(ch, cs);
141 if (ch == '\12' || ch == UEOF) break; 281 if (ch == '\12' || ch == UEOF) break;
142 buff->addch(ch,cs); 282 buff->addch(ch,cs);
143 i++; 283 i++;
144 } 284 }
145 buff->truncate(i); 285 buff->truncate(i);
146 laststartline = exp->locate(); 286 laststartline = exp->locate();
287 buff->resize();
147 return (ch != UEOF); 288 return (ch != UEOF);
148} 289}
149 290
150int BuffDoc::openfile(QWidget* _parent, const char *src) 291int BuffDoc::openfile(QWidget* _parent, const char *src)
151{ 292{
152 // qDebug("BuffDoc:Openfile:%s", src); 293 // qDebug("BuffDoc:Openfile:%s", src);
153 // qDebug("Trying aportis %x",exp); 294 // qDebug("Trying aportis %x",exp);
154 if (exp != NULL) delete exp; 295 if (exp != NULL) delete exp;
155 lastword.empty(); 296 lastword.empty();
156 lastsizes[0] = laststartline = 0; 297 lastsizes[0] = laststartline = 0;
157 lastispara = false; 298 lastispara = false;
158 /* 299 /*
159 exp = new Text; 300 exp = new Text;
160 int ret = exp->openfile(src); 301 int ret = exp->openfile(src);
161 */ 302 */
162 303
163 exp = new Aportis; 304 exp = new Aportis;
164 int ret = exp->openfile(src); 305 int ret = exp->openfile(src);
165 if (ret == -1) 306 if (ret == -1)
166 { 307 {
167 delete exp; 308 delete exp;
168 exp = NULL; 309 exp = NULL;
169 return ret; 310 return ret;
170 } 311 }
171 if (ret == -2) 312 if (ret == -2)
172 { 313 {
173 314
174 delete exp; 315 delete exp;
175 exp = new ztxt; 316 exp = new ztxt;
176 ret = exp->openfile(src); 317 ret = exp->openfile(src);
177 } 318 }
178 if (ret != 0) 319 if (ret != 0)
179 { 320 {
180 321
181 delete exp; 322 delete exp;
182 exp = new CPlucker; 323 exp = new CPlucker;
183 ret = exp->openfile(src); 324 ret = exp->openfile(src);
184 } 325 }
185#ifndef SMALL
186 if (ret != 0) 326 if (ret != 0)
187 { 327 {
188 delete exp; 328 delete exp;
189 qDebug("Trying ppms"); 329 qDebug("Trying ppms");
190 exp = new ppm_expander; 330 exp = new ppm_expander;
191 ret = exp->openfile(src); 331 ret = exp->openfile(src);
192 } 332 }
193
194 if (ret != 0) 333 if (ret != 0)
195 { 334 {
196 delete exp; 335 delete exp;
197 exp = new Text; 336 exp = new Text;
198// qDebug("Trying text"); 337 // qDebug("Trying text");
199 ret = exp->openfile(src); 338 ret = exp->openfile(src);
200 } 339 }
201#else 340
202 if (ret != 0)
203 {
204 delete exp;
205 exp = new Text;
206 ret = exp->openfile(src);
207 }
208#endif
209 if (ret != 0) 341 if (ret != 0)
210 { 342 {
211 delete exp; 343 delete exp;
212 QMessageBox::information(_parent, "OpieReader", "Unknown file compression type","Try another file"); 344 QMessageBox::information(_parent, PROGNAME, "Unknown file compression type","Try another file");
213 return ret; 345 return ret;
214 } 346 }
215 // qDebug("Doing final open:%x:%x",exp,filt); 347 // qDebug("Doing final open:%x:%x",exp,filt);
216 348
217 lastword.empty(); 349 lastword.empty();
218 lastsizes[0] = laststartline = 0; 350 lastsizes[0] = laststartline = 0;
219 lastispara = false; 351 lastispara = false;
220 exp->locate(0); 352 exp->locate(0);
221 filt->setsource(exp); 353 filt->setsource(exp);
222 // qDebug("BuffDoc:file opened"); 354 // qDebug("BuffDoc:file opened");
223 return 0; 355 return 0;
224} 356}
diff --git a/noncore/apps/opie-reader/BuffDoc.h b/noncore/apps/opie-reader/BuffDoc.h
index 1aac817..78d8457 100644
--- a/noncore/apps/opie-reader/BuffDoc.h
+++ b/noncore/apps/opie-reader/BuffDoc.h
@@ -1,84 +1,114 @@
1#ifndef __BuffDoc_h 1#ifndef __BuffDoc_h
2#define __BuffDoc_h 2#define __BuffDoc_h
3 3
4#include "ZText.h" 4#include "ZText.h"
5#include "Aportis.h" 5#include "Aportis.h"
6#include "ztxt.h" 6#include "ztxt.h"
7#include "ppm_expander.h" 7#include "ppm_expander.h"
8#include "CDrawBuffer.h" 8#include "CDrawBuffer.h"
9#include "CFilter.h" 9#include "CFilter.h"
10#include <qfontmetrics.h> 10#include <qfontmetrics.h>
11#include <qmessagebox.h> 11#include <qmessagebox.h>
12 12
13class BuffDoc 13class BuffDoc
14{ 14{
15 CDrawBuffer lastword; 15 CDrawBuffer lastword;
16 CSizeBuffer lastsizes, allsizes; 16 CSizeBuffer lastsizes, allsizes;
17 size_t laststartline; 17 size_t laststartline;
18 bool lastispara; 18 bool lastispara;
19 CExpander* exp; 19 CExpander* exp;
20 CFilterChain* filt; 20 CFilterChain* filt;
21 public: 21 public:
22 void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
23 {
24 if (exp == NULL)
25 {
26 data = NULL;
27 len = 0;
28 }
29 else
30 {
31 exp->setSaveData(data, len, src, srclen);
32 }
33 }
34 void putSaveData(unsigned char*& src, unsigned short& srclen)
35 {
36 if (exp != NULL)
37 {
38 exp->putSaveData(src, srclen);
39 }
40 }
41 void suspend() { if (exp != NULL) exp->suspend(); }
42 void unsuspend() { if (exp != NULL) exp->unsuspend(); }
22 ~BuffDoc() 43 ~BuffDoc()
23 { 44 {
24 delete filt; 45 delete filt;
25 delete exp; 46 delete exp;
26 } 47 }
27 BuffDoc() 48 BuffDoc()
28 { 49 {
29 exp = NULL; 50 exp = NULL;
30 filt = NULL; 51 filt = NULL;
31 lastword.empty(); 52 lastword.empty();
32 // qDebug("Buffdoc created"); 53 // qDebug("Buffdoc created");
33 } 54 }
34 bool empty() { return (exp == NULL); } 55 bool empty() { return (exp == NULL); }
35 void setfilter(CFilterChain* _f) 56 void setfilter(CFilterChain* _f)
36 { 57 {
37 if (filt != NULL) delete filt; 58 if (filt != NULL) delete filt;
38 filt = _f; 59 filt = _f;
39 filt->setsource(exp); 60 filt->setsource(exp);
40 } 61 }
41 CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); } 62 CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); }
42 bool hasrandomaccess() { return (exp == NULL) ? false : exp->hasrandomaccess(); } 63 bool hasrandomaccess() { return (exp == NULL) ? false : exp->hasrandomaccess(); }
43 bool iseol() { return (lastword[0] == '\0'); } 64 bool iseol() { return (lastword[0] == '\0'); }
44 int openfile(QWidget* _parent, const char *src); 65 int openfile(QWidget* _parent, const char *src);
45 tchar getch() 66 tchar getch()
46 { 67 {
47 tchar ch = UEOF; 68 tchar ch = UEOF;
48 CStyle sty; 69 CStyle sty;
49 if (exp != NULL) 70 if (exp != NULL)
50 { 71 {
51 filt->getch(ch, sty); 72 filt->getch(ch, sty);
52 } 73 }
53 return ch; 74 return ch;
54 } 75 }
55 void getch(tchar& ch, CStyle& sty) 76 void getch(tchar& ch, CStyle& sty)
56 { 77 {
57 if (exp != NULL) 78 if (exp != NULL)
58 { 79 {
59 filt->getch(ch, sty); 80 filt->getch(ch, sty);
60 } 81 }
61 else 82 else
62 ch = UEOF; 83 ch = UEOF;
63 } 84 }
85 QPixmap* getPicture(unsigned long tgt) { return (exp == NULL) ? NULL : exp->getPicture(tgt); }
86 unsigned int startSection() { return (exp == NULL) ? 0 : exp->startSection(); }
87 unsigned int endSection() { return (exp == NULL) ? 0 : exp->endSection(); }
64 unsigned int locate() { return (exp == NULL) ? 0 : laststartline; } 88 unsigned int locate() { return (exp == NULL) ? 0 : laststartline; }
65 unsigned int explocate() { return (exp == NULL) ? 0 : exp->locate(); } 89 unsigned int explocate() { return (exp == NULL) ? 0 : exp->locate(); }
90 void setContinuous(bool _b) { if (exp != NULL) exp->setContinuous(_b); }
66 MarkupType PreferredMarkup() { return (exp == NULL) ? cTEXT : exp->PreferredMarkup(); } 91 MarkupType PreferredMarkup() { return (exp == NULL) ? cTEXT : exp->PreferredMarkup(); }
67 bool hyperlink(unsigned int n); 92 bool hyperlink(unsigned int n);
93 size_t getHome() { return ((exp != NULL) ? exp->getHome() : 0); }
68 void locate(unsigned int n); 94 void locate(unsigned int n);
69 bool getline(CDrawBuffer* buff, int w); 95 bool getline(CDrawBuffer* buff, int w);
70 bool getline(CDrawBuffer* buff, int w, int cw); 96 bool getline(CDrawBuffer* buff, int w, int cw);
71 void sizes(unsigned long& fs, unsigned long& ts) { exp->sizes(fs,ts); } 97 void sizes(unsigned long& fs, unsigned long& ts) { exp->sizes(fs,ts); }
72 int getpara(CBuffer& buff) 98 int getpara(CBuffer& buff)
73 { 99 {
74 tchar ch; 100 tchar ch;
75 int i = 0; 101 int i = 0;
76 while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch; 102 while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch;
77 buff[i] = '\0'; 103 buff[i] = '\0';
78 if (i == 0 && ch == UEOF) i = -1; 104 if (i == 0 && ch == UEOF) i = -1;
79 laststartline = exp->locate(); 105 laststartline = exp->locate();
80 return i; 106 return i;
81 } 107 }
108 void saveposn(size_t posn) { exp->saveposn(posn); }
109 bool forward(size_t& loc) { return exp->forward(loc); }
110 bool back(size_t& loc) { return exp->back(loc); }
111 bool hasnavigation() { return exp->hasnavigation(); }
82}; 112};
83 113
84#endif 114#endif
diff --git a/noncore/apps/opie-reader/CBuffer.cpp b/noncore/apps/opie-reader/CBuffer.cpp
index 0780a88..526b25f 100644
--- a/noncore/apps/opie-reader/CBuffer.cpp
+++ b/noncore/apps/opie-reader/CBuffer.cpp
@@ -1,46 +1,46 @@
1#include "CBuffer.h" 1#include "CBuffer.h"
2 2
3CBufferBase& CBufferBase::assign(const void* sztmp, size_t ms) 3CBufferBase& CBufferBase::assign(const void* sztmp, size_t ms)
4{ 4{
5 if (ms*membersize > len) 5 if (ms*membersize > len)
6 { 6 {
7 delete [] buffer; 7 delete [] buffer;
8 buffer = new unsigned char[len = ms*membersize]; 8 buffer = new unsigned char[len = ms*membersize];
9 } 9 }
10 memcpy(buffer, sztmp, ms*membersize); 10 memcpy(buffer, sztmp, ms*membersize);
11 return *this; 11 return *this;
12} 12}
13 13
14CBufferBase::CBufferBase(size_t ms, size_t n) : len(n), membersize(ms) 14CBufferBase::CBufferBase(size_t ms, size_t n = 16) : len(n), membersize(ms)
15{ 15{
16 buffer = new unsigned char[len*membersize]; 16 buffer = new unsigned char[len*membersize];
17 memset(buffer, 0, len*membersize); 17 memset(buffer, 0, len*membersize);
18} 18}
19 19
20void* CBufferBase::operator[](int i) 20void* CBufferBase::operator[](int i)
21{ 21{
22 if ((i+1)*membersize > len) 22 if ((i+1)*membersize > len)
23 { 23 {
24 unsigned char* oldbuffer = buffer; 24 unsigned char* oldbuffer = buffer;
25 buffer = new unsigned char[(i+1)*membersize]; 25 buffer = new unsigned char[(i+1)*membersize];
26 memcpy(buffer, oldbuffer, len); 26 memcpy(buffer, oldbuffer, len);
27 memset(buffer+len, 0, (i+1)*membersize-len); 27 memset(buffer+len, 0, (i+1)*membersize-len);
28 len = (i+1)*membersize; 28 len = (i+1)*membersize;
29 delete [] oldbuffer; 29 delete [] oldbuffer;
30 } 30 }
31 return buffer+i*membersize; 31 return buffer+i*membersize;
32} 32}
33 33
34size_t CBufferBase::bstrlen(unsigned char* _buffer) 34size_t CBufferBase::bstrlen(unsigned char* _buffer = NULL)
35{ 35{
36 if (_buffer == NULL) _buffer = buffer; 36 if (_buffer == NULL) _buffer = buffer;
37 unsigned char* zero = new unsigned char[membersize]; 37 unsigned char* zero = new unsigned char[membersize];
38 memset(zero,0,membersize); 38 memset(zero,0,membersize);
39 unsigned char* element = _buffer; 39 unsigned char* element = _buffer;
40 while (memcmp(element, zero, membersize) != 0) 40 while (memcmp(element, zero, membersize) != 0)
41 { 41 {
42 element += membersize; 42 element += membersize;
43 } 43 }
44 delete [] zero; 44 delete [] zero;
45 return (element - _buffer)/membersize; 45 return (element - _buffer)/membersize;
46} 46}
diff --git a/noncore/apps/opie-reader/CDrawBuffer.cpp b/noncore/apps/opie-reader/CDrawBuffer.cpp
index 892456f..ca220e6 100644
--- a/noncore/apps/opie-reader/CDrawBuffer.cpp
+++ b/noncore/apps/opie-reader/CDrawBuffer.cpp
@@ -1,211 +1,379 @@
1
2#include "CDrawBuffer.h" 1#include "CDrawBuffer.h"
3#include "FontControl.h" 2#include "FontControl.h"
4#include <qfontmetrics.h> 3#include <qfontmetrics.h>
5#include <qpainter.h> 4#include <qpainter.h>
5#include <qpixmap.h>
6#include "opie.h"
7
8CDrawBuffer::~CDrawBuffer()
9{
10 while (!segs.isEmpty()) segs.erase(0);
11}
6 12
7void CDrawBuffer::setright(CDrawBuffer& rhs, int f) 13void CDrawBuffer::setright(CDrawBuffer& rhs, int f)
8{ 14{
9 int i; 15 int i;
10// qDebug("Trying 1:%d:%s", f, (const char*)toQString(rhs.data()));
11 len = rhs.len; 16 len = rhs.len;
12 m_maxstyle = rhs.m_maxstyle; 17 fc = rhs.fc;
13 m_ascent = rhs.m_ascent; 18 m_maxstyle = m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0;
14 m_descent = rhs.m_descent; 19 while (!segs.isEmpty())
15 m_lineSpacing = rhs.m_lineSpacing; 20 {
16 while (!segs.isEmpty()) segs.erase(0); 21 segs.erase(0);
22 }
17 for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); ) 23 for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); )
18 { 24 {
19 CList<textsegment>::iterator next = iter; 25 CList<textsegment>::iterator next = iter;
20 iter++; 26 iter++;
21 if (iter == rhs.segs.end() || iter->start > f) 27 if (iter == rhs.segs.end() || iter->start > f)
22 { 28 {
23 int st = next->start-f; 29 int st = next->start-f;
24 if (st < 0) st = 0; 30 if (st < 0) st = 0;
31
32 CStyle _style = next->style;
33
25 segs.push_back(textsegment(st,next->style)); 34 segs.push_back(textsegment(st,next->style));
26 } 35 }
27 } 36 }
28 for (i = f; rhs[i] != '\0'; i++) (*this)[i-f] = rhs[i]; 37 for (i = f; rhs[i] != '\0'; i++) (*this)[i-f] = rhs[i];
29 (*this)[i-f] = '\0'; 38 (*this)[i-f] = '\0';
30 len = i; 39 len = i;
31// qDebug("Tried 1");
32} 40}
33 41
34CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs) 42CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs)
35{ 43{
36 int i; 44 int i;
37// qDebug("Trying 2"); 45// qDebug("Trying 2");
38 len = rhs.len; 46 len = rhs.len;
39 m_maxstyle = rhs.m_maxstyle; 47 m_maxstyle = rhs.m_maxstyle;
40 m_ascent = rhs.m_ascent; 48 m_ascent = rhs.m_ascent;
41 m_descent = rhs.m_descent; 49 m_descent = rhs.m_descent;
42 m_lineSpacing = rhs.m_lineSpacing; 50 m_lineSpacing = rhs.m_lineSpacing;
43 while (!segs.isEmpty()) segs.erase(0); 51 m_lineExtraSpacing = rhs.m_lineExtraSpacing;
52 while (!segs.isEmpty())
53 {
54 segs.erase(0);
55 }
44 for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); iter++) 56 for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); iter++)
45 { 57 {
46 segs.push_back(*iter); 58 segs.push_back(*iter);
47 } 59 }
48 for (i = 0; rhs[i] != '\0'; i++) (*this)[i] = rhs[i]; 60 for (i = 0; rhs[i] != '\0'; i++) (*this)[i] = rhs[i];
49 (*this)[i] = '\0'; 61 (*this)[i] = '\0';
50 len = i; 62 len = i;
51// qDebug("Tried 2"); 63// qDebug("Tried 2");
52 return *this; 64 return *this;
53} 65}
54 66
55CDrawBuffer& CDrawBuffer::operator=(const tchar*sztmp) 67CDrawBuffer& CDrawBuffer::operator=(const tchar*sztmp)
56{ 68{
57 int i; 69 int i;
58 while (!segs.isEmpty()) segs.erase(0); 70 while (!segs.isEmpty())
71 {
72 segs.erase(0);
73 }
59 segs.push_back(textsegment(0, CStyle())); 74 segs.push_back(textsegment(0, CStyle()));
60 for (i = 0; sztmp[i] != '\0'; i++) (*this)[i] = sztmp[i]; 75 for (i = 0; sztmp[i] != '\0'; i++) (*this)[i] = sztmp[i];
61 (*this)[i] = '\0'; 76 (*this)[i] = '\0';
62 len = i; 77 len = i;
63 return *this; 78 return *this;
64} 79}
65 80
66void CDrawBuffer::empty() 81void CDrawBuffer::empty()
67{ 82{
68 len = 0; 83 len = 0;
69 (*this)[0] = 0; 84 (*this)[0] = 0;
70 while (!segs.isEmpty()) segs.erase(0); 85 while (!segs.isEmpty())
86 {
87 segs.erase(0);
88 }
71 segs.push_back(textsegment(0,CStyle())); 89 segs.push_back(textsegment(0,CStyle()));
72 m_maxstyle = m_ascent = m_descent = m_lineSpacing = 0; 90 m_maxstyle = m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0;
91 m_bEof = false;
73} 92}
74 93
75void CDrawBuffer::addch(tchar ch, CStyle _style/* = ucFontBase*/) 94void CDrawBuffer::addch(tchar ch, CStyle _style/* = ucFontBase*/)
76{ 95{
77 if (len == 0) 96 if (len == 0)
78 { 97 {
79 int thissize = fc->getsize(_style);
80 m_maxstyle = thissize;
81 m_ascent = fc->ascent(_style);
82 m_descent = fc->descent(_style);
83 m_lineSpacing = fc->lineSpacing(_style);
84 segs.first().start = 0; 98 segs.first().start = 0;
85 segs.first().style = _style; 99 segs.first().style = _style;
86 } 100 }
87 else if (_style != segs.last().style) 101 else if (_style != segs.last().style)
88 { 102 {
89 int thissize = fc->getsize(_style);
90 if (thissize > m_maxstyle)
91 {
92 m_maxstyle = thissize;
93 m_ascent = fc->ascent(_style);
94 m_descent = fc->descent(_style);
95 m_lineSpacing = fc->lineSpacing(_style);
96 }
97 segs.push_back(textsegment(len, _style)); 103 segs.push_back(textsegment(len, _style));
98 } 104 }
99 (*this)[len++] = ch; 105 (*this)[len++] = ch;
100} 106}
101 107
102void CDrawBuffer::truncate(int n) 108void CDrawBuffer::truncate(int n)
103{ 109{
104 len = n; 110 len = n;
105 (*this)[n] = 0; 111 (*this)[n] = 0;
106} 112}
107 113
108int CDrawBuffer::width(int numchars) 114int CDrawBuffer::width(int numchars)
109{ 115{
110 int currentx = 0, end = 0; 116 int currentx = 0, end = 0;
111 QString text = toQString(data()); 117 QString text = toQString(data());
112 CList<textsegment>::iterator textstart = segs.begin(); 118 CList<textsegment>::iterator textstart = segs.begin();
113 CList<textsegment>::iterator textend = textstart; 119 CList<textsegment>::iterator textend = textstart;
114 do 120 do
115 { 121 {
116 textend++; 122 textend++;
117 end = (textend != segs.end()) ? textend->start : length(); 123 end = (textend != segs.end()) ? textend->start : length();
118 if (numchars >= 0 && end > numchars) 124 if (numchars >= 0 && end > numchars)
119 { 125 {
120 end = numchars; 126 end = numchars;
121 } 127 }
122 CStyle currentstyle = textstart->style; 128 CStyle currentstyle = textstart->style;
123 QFont f(fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); 129 if (currentstyle.isPicture())
124 QString str = text.mid(textstart->start, end-textstart->start); 130 {
125 QFontMetrics fm(f); 131 currentx += currentstyle.getPicture()->width();
126 currentx += fm.width(str); 132 }
133 else
134 {
135 if (currentstyle.isMono() && !fc->hasCourier())
136 {
137 int cw = (7*fc->getsize(currentstyle))/10;
138 currentx += cw*(end-textstart->start);
139 }
140 else
141 {
142 QFont f(currentstyle.isMono() ? QString("courier") : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) );
143 // f.setUnderline(currentstyle.isUnderline());
144 QString str = text.mid(textstart->start, end-textstart->start);
145 QFontMetrics fm(f);
146 currentx += fm.width(str);
147 }
148 }
127 textstart = textend; 149 textstart = textend;
128 } 150 }
129 while (textend != segs.end() && end != numchars); 151 while (textend != segs.end() && end != numchars);
130 return currentx; 152 return currentx;
131} 153}
132 154
155int CDrawBuffer::leftMargin()
156{
157 return (segs.begin()->style.getLeftMargin()*fc->getsize(segs.begin()->style))/6;
158}
159
160int CDrawBuffer::rightMargin()
161{
162 return (segs.begin()->style.getRightMargin()*fc->getsize(segs.begin()->style))/6;
163}
164
165int CDrawBuffer::offset(int scwidth)
166{
167 int currentx = BORDER;
168 switch(segs.begin()->style.getJustify())
169 {
170 case m_AlignRight:
171 {
172 currentx = scwidth - BORDER - rightMargin() - width();
173 }
174 break;
175 case m_AlignCentre:
176 {
177 currentx = (
178 scwidth +
179 leftMargin() - rightMargin()
180 - width())/2;
181 }
182 break;
183 case m_AlignJustify:
184 case m_AlignLeft:
185 currentx = BORDER + leftMargin();
186 break;
187 }
188 return currentx;
189}
190
133void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scwidth) 191void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scwidth)
134{ 192{
135 int currentx = 0; 193 int currentx = offset(scwidth);
136 QString text = toQString(data()); 194 QString text = toQString(data());
137 CList<textsegment>::iterator textstart = segs.begin(); 195 CList<textsegment>::iterator textstart = segs.begin();
196/*
138 StyleType align = textstart->style.getJustify(); 197 StyleType align = textstart->style.getJustify();
139 switch (align) 198 switch (align)
140 { 199 {
141 case CStyle::m_AlignRight: 200 case CStyle::m_AlignRight:
142 { 201 {
143 // int linelength = width(); 202 currentx = scwidth - width() - 2*BORDER;
144 currentx = scwidth - width();
145 } 203 }
146 break; 204 break;
147 case CStyle::m_AlignCentre: 205 case CStyle::m_AlignCentre:
148 { 206 {
149 // int linelength = width(); 207 currentx = (scwidth - width())/2 - BORDER;
150 currentx = (scwidth - width())/2;
151 } 208 }
152 break; 209 break;
153 case CStyle::m_AlignJustify: 210 case CStyle::m_AlignJustify:
154 case CStyle::m_AlignLeft: 211 case CStyle::m_AlignLeft:
155 break; 212 break;
156 } 213 }
214*/
157 CList<textsegment>::iterator textend = textstart; 215 CList<textsegment>::iterator textend = textstart;
158 do 216 do
159 { 217 {
160 textend++; 218 textend++;
161 int end = (textend != segs.end()) ? textend->start : length(); 219 int end = (textend != segs.end()) ? textend->start : length();
162 CStyle currentstyle = textstart->style; 220 CStyle currentstyle = textstart->style;
163 QFont f(fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); 221 QFont f((currentstyle.isMono() && fc->hasCourier()) ? QString("courier") : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) );
222 //f.setUnderline(currentstyle.isUnderline());
223 //if (currentstyle.isUnderline()) qDebug("UNDERLINE");
164 _p->setFont(f); 224 _p->setFont(f);
165 QString str = text.mid(textstart->start, end-textstart->start); 225 QString str = text.mid(textstart->start, end-textstart->start);
166 _p->setPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue())); 226#ifdef OPIE
227 _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/100));
228#else
229 _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/10));
230#endif
167 if (_bMono) 231 if (_bMono)
168 { 232 {
233 if (currentstyle.isUnderline())
234 {
235 _p->drawLine( currentx, _y, currentx + str.length()*_charWidth, _y);
236 }
237 if (currentstyle.isStrikethru())
238 {
239 int ascent = fc->ascent(currentstyle)/3;
240 _p->drawLine( currentx, _y-ascent, currentx + str.length()*_charWidth, _y-ascent);
241 }
169 for (int i = 0; i < str.length(); i++) 242 for (int i = 0; i < str.length(); i++)
170 { 243 {
171 _p->drawText( currentx + i*_charWidth, _y, QString(str[i])); 244 _p->drawText( currentx + i*_charWidth, _y, QString(str[i]));
172 } 245 }
173 currentx += str.length()*_charWidth; 246 currentx += str.length()*_charWidth;
174 } 247 }
175 else 248 else
176 { 249 {
177 _p->drawText( currentx, _y, str); 250 if (currentstyle.isPicture())
178 QFontMetrics fm(f); 251 {
179 currentx += fm.width(str); 252 int ascent = fc->ascent(currentstyle)/2;
253 int yoffset = currentstyle.getPicture()->height()/2 + ascent;
254 _p->drawPixmap( currentx, _y-yoffset, *(currentstyle.getPicture()));
255 currentx += currentstyle.getPicture()->width();
256 }
257 else
258 {
259 if (currentstyle.isMono() && !fc->hasCourier())
260 {
261 int cw = (7*fc->getsize(currentstyle))/10;
262 int w = cw*(end-textstart->start);
263 if (currentstyle.isUnderline())
264 {
265 _p->drawLine( currentx, _y, currentx + w, _y);
266 }
267 if (currentstyle.isStrikethru())
268 {
269 int ascent = fc->ascent(currentstyle)/3;
270 _p->drawLine( currentx, _y-ascent, currentx + w, _y-ascent);
271 }
272 QString str = text.mid(textstart->start, end-textstart->start);
273
274 for (int i = 0; i < str.length(); i++)
275 {
276 _p->drawText( currentx, _y, QString(str[i]));
277 currentx += cw;
278 }
279 }
280 else
281 {
282 QFontMetrics fm(f);
283 int w = fm.width(str);
284 if (currentstyle.isUnderline())
285 {
286 _p->drawLine( currentx, _y, currentx + w, _y);
287 }
288 if (currentstyle.isStrikethru())
289 {
290 int ascent = fc->ascent(currentstyle)/3;
291 _p->drawLine( currentx, _y-ascent, currentx + w, _y-ascent);
292 }
293 _p->drawText( currentx, _y, str);
294 currentx += w;
295 }
296 }
180 } 297 }
181 textstart = textend; 298 textstart = textend;
182 } 299 }
183 while (textend != segs.end()); 300 while (textend != segs.end() && textstart->start < length()-1);
184} 301}
185 302
186CStyle CDrawBuffer::laststyle() 303CStyle CDrawBuffer::laststyle()
187{ 304{
188 return segs.last().style; 305 return segs.last().style;
189} 306}
190 307
191bool CDrawBuffer::isLink(int numchars, size_t& tgt) 308linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt)
192{ 309{
193 int end = 0; 310 int end = 0;
194 CStyle currentstyle; 311 CStyle currentstyle;
195 CList<textsegment>::iterator textstart = segs.begin(); 312 CList<textsegment>::iterator textstart = segs.begin();
196 CList<textsegment>::iterator textend = textstart; 313 CList<textsegment>::iterator textend = textstart;
197 do 314 do
198 { 315 {
199 textend++; 316 textend++;
200 end = (textend != segs.end()) ? textend->start : length(); 317 end = (textend != segs.end()) ? textend->start : length();
201 if (numchars >= 0 && end > numchars)
202 {
203 end = numchars;
204 }
205 currentstyle = textstart->style; 318 currentstyle = textstart->style;
319/*
320 if (currentstyle.isPicture()) qDebug("Passed thru picture");
321 if (currentstyle.getLink()) qDebug("Passed thru link");
322 qDebug("islink:%d - %d", numchars, end);
323*/
206 textstart = textend; 324 textstart = textend;
207 } 325 }
208 while (textend != segs.end() && end != numchars); 326 while (textend != segs.end() && end <= numchars);
209 tgt = currentstyle.getData(); 327// if (currentstyle.isPicture()) qDebug("Clicked on picture");
210 return currentstyle.getLink(); 328 if (currentstyle.getPictureLink())
329 {
330 tgt = currentstyle.getPictureLinkData();
331 return ePicture;
332 }
333 if (currentstyle.getLink())
334 {
335 tgt = currentstyle.getData();
336 return eLink;
337 }
338 return eNone;
339}
340
341void CDrawBuffer::resize()
342{
343 int i;
344 m_maxstyle = m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0;
345 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= length(); )
346 {
347 CList<textsegment>::iterator next = iter;
348 iter++;
349 int st = next->start;
350 if (st < 0) st = 0;
351
352 CStyle _style = next->style;
353
354 int linespacing, ascent, descent, extra;
355
356 ascent = fc->ascent(_style);
357 descent = fc->descent(_style);
358 linespacing = fc->lineSpacing(_style);
359 extra = linespacing - ascent - descent;
360 if (_style.isPicture())
361 {
362 descent = (_style.getPicture()->height()-ascent)/2;
363 ascent = (_style.getPicture()->height()+ascent)/2;
364 }
365/*
366 else if (fc != NULL)
367 {
368 ascent = fc->ascent(_style);
369 descent = fc->descent(_style);
370 linespacing = fc->lineSpacing(_style);
371 extra = linespacing - ascent - descent;
372 }
373*/
374 if (ascent > m_ascent) m_ascent = ascent;
375 if (descent > m_descent) m_descent = descent;
376 if (extra > m_lineExtraSpacing) m_lineExtraSpacing = extra;
377 m_lineSpacing = m_ascent+m_descent+m_lineExtraSpacing;
378 }
211} 379}
diff --git a/noncore/apps/opie-reader/CDrawBuffer.h b/noncore/apps/opie-reader/CDrawBuffer.h
index 4d3696e..0d8968c 100644
--- a/noncore/apps/opie-reader/CDrawBuffer.h
+++ b/noncore/apps/opie-reader/CDrawBuffer.h
@@ -1,59 +1,76 @@
1#ifndef __CDRAWBUFFER_H 1#ifndef __CDRAWBUFFER_H
2#define __CDRAWBUFFER_H 2#define __CDRAWBUFFER_H
3 3
4#include "StyleConsts.h" 4#include "StyleConsts.h"
5#include "CBuffer.h" 5#include "CBuffer.h"
6#include "my_list.h" 6#include "my_list.h"
7 7
8class QPainter; 8class QPainter;
9 9
10enum linkType
11{
12 eNone,
13 eLink,
14 ePicture
15};
16
10struct textsegment 17struct textsegment
11{ 18{
12 int start; 19 int start;
13 CStyle style; 20 CStyle style;
14 textsegment(int _start, CStyle _style) 21 textsegment(int _start, const CStyle& _style)
15 : 22 :
16 start(_start), style(_style) 23 start(_start), style(_style)
17 {} 24 {}
18}; 25};
19 26
20class FontControl; 27class FontControl;
21 28
22class CDrawBuffer : public CBuffer 29class CDrawBuffer : public CBuffer
23{ 30{
24 CList<textsegment> segs; 31 CList<textsegment> segs;
25 int len; 32 int len;
26 FontControl* fc; 33 FontControl* fc;
27 int m_maxstyle, m_ascent, m_descent, m_lineSpacing; 34 int m_maxstyle, m_ascent, m_descent, m_lineSpacing, m_lineExtraSpacing;
35 bool m_bEof;
36 CDrawBuffer(const CDrawBuffer&);
37 CDrawBuffer& operator=(const tchar*sztmp);
28 public: 38 public:
39 int leftMargin();
40 int rightMargin();
41 void setEof() { m_bEof = true; }
42 bool eof() { return m_bEof; }
43 CDrawBuffer& operator=(CDrawBuffer&);
29 CDrawBuffer(FontControl* _fs = NULL) 44 CDrawBuffer(FontControl* _fs = NULL)
30 : 45 :
31 fc(_fs) 46 fc(_fs)
32 { 47 {
33 empty(); 48 empty();
34 } 49 }
50 ~CDrawBuffer();
35/* 51/*
36 CDrawBuffer() 52 CDrawBuffer()
37 : 53 :
38 size(0) 54 size(0)
39 { 55 {
40 empty(); 56 empty();
41 } 57 }
42*/ 58*/
43 int width(int numchars = -1); 59 int width(int numchars = -1);
60 int offset(int);
44 void render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scw); 61 void render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scw);
45 CDrawBuffer& operator=(const tchar*sztmp);
46 CDrawBuffer& operator=(CDrawBuffer&);
47 void empty(); 62 void empty();
48 void addch(tchar ch, CStyle _style); 63 void addch(tchar ch, CStyle _style);
49 void truncate(int); 64 void truncate(int);
50 void setright(CDrawBuffer&, int); 65 void setright(CDrawBuffer&, int);
51 CStyle laststyle(); 66 CStyle laststyle();
52 int ascent() { return m_ascent; } 67 int ascent() { return m_ascent; }
53 int descent() { return m_descent; } 68 int descent() { return m_descent; }
54 int lineSpacing() { return m_lineSpacing; } 69 int lineSpacing() { return m_lineSpacing; }
70 int lineExtraSpacing() { return m_lineExtraSpacing; }
55 71
56// void frig(); 72// void frig();
57 bool isLink(int numchars, size_t& tgt); 73 linkType getLinkType(int numchars, size_t& tgt);
74 void resize();
58}; 75};
59#endif 76#endif
diff --git a/noncore/apps/opie-reader/CExpander.h b/noncore/apps/opie-reader/CExpander.h
index b1147a6..c281398 100644
--- a/noncore/apps/opie-reader/CExpander.h
+++ b/noncore/apps/opie-reader/CExpander.h
@@ -1,43 +1,124 @@
1#ifndef __CExpander_h 1#ifndef __CExpander_h
2#define __CExpander_h 2#define __CExpander_h
3 3
4#include <unistd.h>
5#include <stdio.h>
6#include <time.h>
7#include <qmessagebox.h>
4#include "config.h" 8#include "config.h"
5#include "StyleConsts.h" 9#include "StyleConsts.h"
6#include "Markups.h" 10#include "Markups.h"
11#include "name.h"
7 12
13class QPixmap;
8class Bkmk; 14class Bkmk;
9 15
10template<class T> 16template<class T>
11class CList; 17class CList;
12 18
13class CCharacterSource 19class CCharacterSource
14{ 20{
15 public: 21 public:
16 virtual void getch(tchar&, CStyle&) = 0; 22 virtual void getch(tchar&, CStyle&) = 0;
17}; 23};
18 24
19class CExpander 25class CExpander
20{ 26{
27 protected:
28 size_t m_homepos;
29 bool m_continuous;
30 char* fname;
31 bool bSuspended;
32 size_t suspos;
33 time_t sustime;
21 public: 34 public:
22 CExpander() {}; 35 virtual void suspend() = 0;
23 virtual ~CExpander() {}; 36 virtual void unsuspend() = 0;
24 virtual int openfile(const char *src) = 0; 37 size_t getHome() { return m_homepos; }
38 CExpander() : m_homepos(0), fname(NULL) {};
39 virtual ~CExpander() { if (fname != NULL) delete [] fname; };
40 int openfile(const char *src)
41 {
42 bSuspended = false;
43 fname = strdup(src);
44 return OpenFile(src);
45 }
46 virtual int OpenFile(const char *src) = 0;
25 virtual unsigned int locate() = 0; 47 virtual unsigned int locate() = 0;
26 virtual void locate(unsigned int n) = 0; 48 virtual void locate(unsigned int n) = 0;
27 virtual bool hasrandomaccess() = 0; 49 virtual bool hasrandomaccess() = 0;
28 virtual void sizes(unsigned long& file, unsigned long& text) = 0; 50 virtual void sizes(unsigned long& file, unsigned long& text) = 0;
29 virtual CList<Bkmk>* getbkmklist() { return NULL; } 51 virtual CList<Bkmk>* getbkmklist() { return NULL; }
30 virtual void getch(int& ch, CStyle& sty) 52 virtual void getch(int& ch, CStyle& sty)
31 { 53 {
32 ch = getch(); 54 ch = getch();
33 sty.unset(); 55 sty.unset();
34 } 56 }
35 virtual int getch() = 0; 57 virtual int getch() = 0;
36 virtual bool hyperlink(unsigned int n) 58 virtual bool hyperlink(unsigned int n)
37 { 59 {
38 locate(n); 60 locate(n);
39 return true; 61 return true;
40 } 62 }
41 virtual MarkupType PreferredMarkup() = 0; 63 virtual MarkupType PreferredMarkup() = 0;
64 virtual void saveposn(size_t posn) {}
65 virtual bool forward(size_t& loc) {}
66 virtual bool back(size_t& loc) {}
67 virtual bool hasnavigation() { return false; }
68 virtual unsigned long startSection()
69 {
70 return 0;
71 }
72 virtual unsigned long endSection()
73 {
74 unsigned long file, text;
75 sizes(file, text);
76 return text;
77 }
78 virtual QPixmap* getPicture(unsigned long tgt) { return NULL; }
79 void setContinuous(bool _b) { m_continuous = _b; }
80
81 virtual void suspend(FILE*& fin)
82 {
83 bSuspended = true;
84 suspos = ftell(fin);
85 fclose(fin);
86 fin = NULL;
87 sustime = time(NULL);
88 }
89 virtual void unsuspend(FILE*& fin)
90 {
91 if (bSuspended)
92 {
93 bSuspended = false;
94 int delay = time(NULL) - sustime;
95 if (delay < 10) sleep(10-delay);
96 fin = fopen(fname, "rb");
97 for (int i = 0; fin == NULL && i < 5; i++)
98 {
99 sleep(5);
100 fin = fopen(fname, "rb");
101 }
102 if (fin == NULL)
103 {
104 QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file");
105 exit(0);
106 }
107 suspos = fseek(fin, suspos, SEEK_SET);
108 }
109 }
110 virtual void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
111 {
112 len = srclen;
113 data = new unsigned char[len];
114 memcpy(data, src, len);
115 }
116 virtual void putSaveData(unsigned char*& src, unsigned short& srclen)
117 {
118 if (srclen != 0)
119 {
120 qDebug("Don't know what to do with non-zero save data");
121 }
122 }
42}; 123};
43#endif 124#endif
diff --git a/noncore/apps/opie-reader/CFilter.cpp b/noncore/apps/opie-reader/CFilter.cpp
index c17cf61..d5e3116 100644
--- a/noncore/apps/opie-reader/CFilter.cpp
+++ b/noncore/apps/opie-reader/CFilter.cpp
@@ -1,561 +1,684 @@
1#include "CDrawBuffer.h" 1#include "CDrawBuffer.h"
2#include "CFilter.h" 2#include "CFilter.h"
3 3
4unsigned short striphtml::skip_ws() 4unsigned short striphtml::skip_ws()
5{ 5{
6 tchar ch; 6 tchar ch;
7 CStyle sty; 7 CStyle sty;
8 do 8 do
9 { 9 {
10 parent->getch(ch, sty); 10 parent->getch(ch, sty);
11 } 11 }
12 while (ch < 33); 12 while (ch < 33);
13 return ch; 13 return ch;
14} 14}
15 15
16unsigned short striphtml::skip_ws_end() 16unsigned short striphtml::skip_ws_end()
17{ 17{
18 tchar ch; 18 tchar ch;
19 CStyle sty; 19 CStyle sty;
20 parent->getch(ch, sty); 20 parent->getch(ch, sty);
21 if (ch == ' ') 21 if (ch == ' ')
22 { 22 {
23 do 23 do
24 { 24 {
25 parent->getch(ch, sty); 25 parent->getch(ch, sty);
26 } 26 }
27 while (ch != '>'); 27 while (ch != '>');
28 } 28 }
29 return ch; 29 return ch;
30} 30}
31 31
32unsigned short striphtml::parse_m() 32unsigned short striphtml::parse_m()
33{ 33{
34 tchar ch; 34 tchar ch;
35 CStyle sty; 35 CStyle sty;
36 parent->getch(ch, sty); 36 parent->getch(ch, sty);
37 if (ch == 'm' || ch == 'M') 37 if (ch == 'm' || ch == 'M')
38 { 38 {
39 ch = skip_ws_end(); 39 ch = skip_ws_end();
40 if (ch == '>') 40 if (ch == '>')
41 { 41 {
42 return 0; 42 return 0;
43 } 43 }
44 } 44 }
45 return ch; 45 return ch;
46} 46}
47 47
48void striphtml::mygetch(tchar& ch, CStyle& sty) 48void striphtml::mygetch(tchar& ch, CStyle& sty)
49{ 49{
50 parent->getch(ch, sty); 50 parent->getch(ch, sty);
51 if (ch == 10) ch = ' '; 51 if (ch == 10) ch = ' ';
52} 52}
53 53
54void striphtml::getch(tchar& ch, CStyle& sty) 54void striphtml::getch(tchar& ch, CStyle& sty)
55{ 55{
56 CStyle dummy; 56 CStyle dummy;
57 mygetch(ch, dummy); 57 mygetch(ch, dummy);
58 if (ch == 10) ch = ' '; 58 if (ch == 10) ch = ' ';
59 while (ch == '<') 59 while (ch == '<')
60 { 60 {
61 ch = skip_ws(); 61 ch = skip_ws();
62 62
63 switch (ch) 63 switch (ch)
64 { 64 {
65 case 'p': 65 case 'p':
66 case 'P': 66 case 'P':
67 ch = skip_ws_end(); 67 ch = skip_ws_end();
68 if (ch == '>') 68 if (ch == '>')
69 { 69 {
70 ch = 10; 70 ch = 10;
71 continue; 71 continue;
72 } 72 }
73 break; 73 break;
74 case 'b': 74 case 'b':
75 case 'B': 75 case 'B':
76 ch = skip_ws_end(); 76 ch = skip_ws_end();
77 if (ch == '>') 77 if (ch == '>')
78 { 78 {
79 currentstyle.setBold(); 79 currentstyle.setBold();
80 mygetch(ch, dummy); 80 mygetch(ch, dummy);
81 continue; 81 continue;
82 } 82 }
83 else if (ch == 'r' || ch == 'R') 83 else if (ch == 'r' || ch == 'R')
84 { 84 {
85 ch = skip_ws_end(); 85 ch = skip_ws_end();
86 if (ch == '>') 86 if (ch == '>')
87 { 87 {
88 ch = 10; 88 ch = 10;
89 continue; 89 continue;
90 } 90 }
91 } 91 }
92 break; 92 break;
93 case 'i': 93 case 'i':
94 case 'I': 94 case 'I':
95 ch = skip_ws_end(); 95 ch = skip_ws_end();
96 if (ch == '>') 96 if (ch == '>')
97 { 97 {
98 currentstyle.setItalic(); 98 currentstyle.setItalic();
99 mygetch(ch, dummy); 99 mygetch(ch, dummy);
100 continue; 100 continue;
101 } 101 }
102 break; 102 break;
103 case 'e': 103 case 'e':
104 case 'E': 104 case 'E':
105 if ((ch = parse_m()) == 0) 105 if ((ch = parse_m()) == 0)
106 { 106 {
107 currentstyle.setItalic(); 107 currentstyle.setItalic();
108 mygetch(ch, dummy); 108 mygetch(ch, dummy);
109 continue; 109 continue;
110 } 110 }
111 break; 111 break;
112 case 'h': 112 case 'h':
113 case 'H': 113 case 'H':
114 mygetch(ch, dummy); 114 mygetch(ch, dummy);
115 if ('0' < ch && ch <= '9') 115 if ('0' < ch && ch <= '9')
116 { 116 {
117 tchar hs = ch; 117 tchar hs = ch;
118 ch = skip_ws_end(); 118 ch = skip_ws_end();
119 if (ch == '>') 119 if (ch == '>')
120 { 120 {
121 switch (hs) 121 switch (hs)
122 { 122 {
123 case '1': 123 case '1':
124 // currentstyle = ucBold | ucFontBase+2 | (ucAlignCentre << ucAlignShift); 124 // currentstyle = ucBold | ucFontBase+2 | (ucAlignCentre << ucAlignShift);
125 currentstyle.unset(); 125 currentstyle.unset();
126 currentstyle.setFontSize(2); 126 currentstyle.setFontSize(2);
127 currentstyle.setBold(); 127 currentstyle.setBold();
128 currentstyle.setCentreJustify(); 128 currentstyle.setCentreJustify();
129 break; 129 break;
130 case '2': 130 case '2':
131 // currentstyle = ucBold | ucFontBase+1; 131 // currentstyle = ucBold | ucFontBase+1;
132 currentstyle.unset(); 132 currentstyle.unset();
133 currentstyle.setFontSize(1); 133 currentstyle.setFontSize(1);
134 currentstyle.setBold(); 134 currentstyle.setBold();
135 break; 135 break;
136 default: 136 default:
137 // currentstyle = ucBold | ucFontBase; 137 // currentstyle = ucBold | ucFontBase;
138 currentstyle.unset(); 138 currentstyle.unset();
139 currentstyle.setBold(); 139 currentstyle.setBold();
140 } 140 }
141 ch = 10; 141 ch = 10;
142 // mygetch(ch, dummy); 142 // mygetch(ch, dummy);
143 continue; 143 continue;
144 } 144 }
145 } 145 }
146 break; 146 break;
147 case '/': 147 case '/':
148 mygetch(ch, dummy); 148 mygetch(ch, dummy);
149 switch (ch) 149 switch (ch)
150 { 150 {
151 case 'b': 151 case 'b':
152 case 'B': 152 case 'B':
153 ch = skip_ws_end(); 153 ch = skip_ws_end();
154 if (ch == '>') 154 if (ch == '>')
155 { 155 {
156 currentstyle.unsetBold(); 156 currentstyle.unsetBold();
157 mygetch(ch, dummy); 157 mygetch(ch, dummy);
158 continue; 158 continue;
159 } 159 }
160 break; 160 break;
161 case 'i': 161 case 'i':
162 case 'I': 162 case 'I':
163 ch = skip_ws_end(); 163 ch = skip_ws_end();
164 if (ch == '>') 164 if (ch == '>')
165 { 165 {
166 currentstyle.unsetItalic(); 166 currentstyle.unsetItalic();
167 mygetch(ch, dummy); 167 mygetch(ch, dummy);
168 continue; 168 continue;
169 } 169 }
170 break; 170 break;
171 case 'e': 171 case 'e':
172 case 'E': 172 case 'E':
173 if ((ch = parse_m()) == 0) 173 if ((ch = parse_m()) == 0)
174 { 174 {
175 currentstyle.unsetItalic(); 175 currentstyle.unsetItalic();
176 mygetch(ch, dummy); 176 mygetch(ch, dummy);
177 continue; 177 continue;
178 } 178 }
179 break; 179 break;
180 case 'h': 180 case 'h':
181 case 'H': 181 case 'H':
182 mygetch(ch, dummy); 182 mygetch(ch, dummy);
183 if ('0' < ch && ch <= '9') 183 if ('0' < ch && ch <= '9')
184 { 184 {
185 ch = skip_ws_end(); 185 ch = skip_ws_end();
186 if (ch == '>') 186 if (ch == '>')
187 { 187 {
188 currentstyle.unset(); 188 currentstyle.unset();
189 //mygetch(ch, dummy); 189 //mygetch(ch, dummy);
190 ch = 10; 190 ch = 10;
191 continue; 191 continue;
192 } 192 }
193 } 193 }
194 break; 194 break;
195 default: 195 default:
196 break; 196 break;
197 } 197 }
198 break; 198 break;
199 default: 199 default:
200 break; 200 break;
201 } 201 }
202 while (ch != '>' && ch != UEOF) 202 while (ch != '>' && ch != UEOF)
203 { 203 {
204 mygetch(ch, dummy); 204 mygetch(ch, dummy);
205 } 205 }
206 mygetch(ch, dummy); 206 mygetch(ch, dummy);
207 } 207 }
208 if (ch == '&') 208 if (ch == '&')
209 { 209 {
210 mygetch(ch, dummy); 210 mygetch(ch, dummy);
211 if (ch == '#') 211 if (ch == '#')
212 { 212 {
213 int id = 0; 213 int id = 0;
214 mygetch(ch, dummy); 214 mygetch(ch, dummy);
215 while (ch != ';' && ch != UEOF) 215 while (ch != ';' && ch != UEOF)
216 { 216 {
217 id = 10*id+ch-'0'; 217 id = 10*id+ch-'0';
218 mygetch(ch, dummy); 218 mygetch(ch, dummy);
219 } 219 }
220 ch = id; 220 ch = id;
221 } 221 }
222 } 222 }
223// sty = (dummy == ucFontBase) ? currentstyle : dummy; 223// sty = (dummy == ucFontBase) ? currentstyle : dummy;
224 sty = currentstyle; 224 sty = currentstyle;
225 return; 225 return;
226} 226}
227 227
228 228
229void textfmt::mygetch(tchar& ch, CStyle& sty) 229void textfmt::mygetch(tchar& ch, CStyle& sty)
230{ 230{
231 if (uselast) 231 if (uselast)
232 { 232 {
233 ch = lastchar; 233 ch = lastchar;
234 uselast = false; 234 uselast = false;
235 } 235 }
236 else 236 else
237 { 237 {
238 parent->getch(ch, sty); 238 parent->getch(ch, sty);
239 } 239 }
240} 240}
241 241
242void textfmt::getch(tchar& ch, CStyle& sty) 242void textfmt::getch(tchar& ch, CStyle& sty)
243{ 243{
244 mygetch(ch, sty); 244 mygetch(ch, sty);
245 do 245 do
246 { 246 {
247 sty = currentstyle; 247 sty = currentstyle;
248 switch (ch) 248 switch (ch)
249 { 249 {
250 case 10: 250 case 10:
251 currentstyle.unset(); 251 currentstyle.unset();
252 sty = currentstyle; 252 sty = currentstyle;
253 break; 253 break;
254// Use this if you want to replace -- by em-dash 254// Use this if you want to replace -- by em-dash
255 case '-': 255 case '-':
256 // parent->getch(ch, sty); 256 // parent->getch(ch, sty);
257 mygetch(ch, sty); 257 mygetch(ch, sty);
258 if (ch == '-') 258 if (ch == '-')
259 { 259 {
260 ch = 0x2014; 260 ch = 0x2014;
261 } 261 }
262 else 262 else
263 { 263 {
264 lastchar = ch; 264 lastchar = ch;
265 uselast = true; 265 uselast = true;
266 ch = '-'; 266 ch = '-';
267 } 267 }
268 break; 268 break;
269 case '*': 269 case '*':
270 if (currentstyle.isBold()) 270 if (currentstyle.isBold())
271 { 271 {
272// Already bold - time to turn it off? 272// Already bold - time to turn it off?
273// The next two lines ensure that * follows a character but it works better without 273// The next two lines ensure that * follows a character but it works better without
274 // QChar c(lastchar); 274 // QChar c(lastchar);
275 // if ((lastchar != '*') && (c.isPunct() || c.isLetterOrNumber())) 275 // if ((lastchar != '*') && (c.isPunct() || c.isLetterOrNumber()))
276 if (lastchar != '*') 276 if (lastchar != '*')
277 { 277 {
278 currentstyle.unsetBold(); 278 currentstyle.unsetBold();
279 CStyle dummy; 279 CStyle dummy;
280 // parent->getch(ch, dummy); 280 // parent->getch(ch, dummy);
281 mygetch(ch, dummy); 281 mygetch(ch, dummy);
282 } 282 }
283 } 283 }
284 else 284 else
285 { 285 {
286// not bold - time to turn it on? 286// not bold - time to turn it on?
287 CStyle dummy; 287 CStyle dummy;
288 // parent->getch(ch, dummy); 288 // parent->getch(ch, dummy);
289 mygetch(ch, dummy); 289 mygetch(ch, dummy);
290 QChar c(ch); 290 QChar c(ch);
291 if ((ch != '*') && (c.isPunct() || c.isLetterOrNumber())) 291 if ((ch != '*') && (c.isPunct() || c.isLetterOrNumber()))
292 { 292 {
293 currentstyle.setBold(); 293 currentstyle.setBold();
294 } 294 }
295 else 295 else
296 { 296 {
297 lastchar = ch; 297 lastchar = ch;
298 uselast = true; 298 uselast = true;
299 ch = '*'; 299 ch = '*';
300 } 300 }
301 301
302 } 302 }
303 break; 303 break;
304 case '_': 304 case '_':
305 if (currentstyle.isItalic()) 305 if (currentstyle.isItalic())
306 { 306 {
307// Already bold - time to turn it off? 307// Already bold - time to turn it off?
308// The next two lines ensure that * follows a character but it works better without 308// The next two lines ensure that * follows a character but it works better without
309 // QChar c(lastchar); 309 // QChar c(lastchar);
310 // if ((lastchar != '_') && (c.isPunct() || c.isLetterOrNumber())) 310 // if ((lastchar != '_') && (c.isPunct() || c.isLetterOrNumber()))
311 if (lastchar != '_') 311 if (lastchar != '_')
312 { 312 {
313 currentstyle.unsetItalic(); 313 currentstyle.unsetItalic();
314 CStyle dummy; 314 CStyle dummy;
315 // parent->getch(ch, dummy); 315 // parent->getch(ch, dummy);
316 mygetch(ch, dummy); 316 mygetch(ch, dummy);
317 } 317 }
318 } 318 }
319 else 319 else
320 { 320 {
321// not bold - time to turn it on? 321// not bold - time to turn it on?
322 CStyle dummy; 322 CStyle dummy;
323 // parent->getch(ch, dummy); 323 // parent->getch(ch, dummy);
324 mygetch(ch, dummy); 324 mygetch(ch, dummy);
325 QChar c(ch); 325 QChar c(ch);
326 if ((ch != '_') && (c.isPunct() || c.isLetterOrNumber())) 326 if ((ch != '_') && (c.isPunct() || c.isLetterOrNumber()))
327 { 327 {
328 currentstyle.setItalic(); 328 currentstyle.setItalic();
329 } 329 }
330 else 330 else
331 { 331 {
332 lastchar = ch; 332 lastchar = ch;
333 uselast = true; 333 uselast = true;
334 ch = '_'; 334 ch = '_';
335 } 335 }
336 336
337 } 337 }
338 break; 338 break;
339 } 339 }
340 } 340 }
341 while (sty != currentstyle); 341 while (sty != currentstyle);
342 if (!uselast) lastchar = ch; 342 if (!uselast) lastchar = ch;
343 return; 343 return;
344} 344}
345 345
346void remap::getch(tchar& ch, CStyle& sty) 346void remap::getch(tchar& ch, CStyle& sty)
347{ 347{
348 if (q[offset] != 0) 348 if (q[offset] != 0)
349 { 349 {
350 q[offset++]; 350 q[offset++];
351 sty = currentstyle; 351 sty = currentstyle;
352 return; 352 return;
353 } 353 }
354 parent->getch(ch, sty); 354 parent->getch(ch, sty);
355 switch (ch) 355 switch (ch)
356 { 356 {
357 case 0x201a: 357 case 0x201a:
358 ch = '\''; 358 ch = '\'';
359 break; 359 break;
360 case 0x0192: 360 case 0x0192:
361 ch = 'f'; 361 ch = 'f';
362 break; 362 break;
363 case 0x201e: 363 case 0x201e:
364 ch = '"'; 364 ch = '"';
365 break; 365 break;
366 case 0x2026: 366 case 0x2026:
367 offset = 0; 367 offset = 0;
368 q[0] = '.'; 368 q[0] = '.';
369 q[1] = '.'; 369 q[1] = '.';
370 q[2] = 0; 370 q[2] = 0;
371 ch = '.'; // should be ... 371 ch = '.'; // should be ...
372 break; 372 break;
373 case 0x0160: 373 case 0x0160:
374 ch = 'S'; 374 ch = 'S';
375 break; 375 break;
376 case 0x2039: 376 case 0x2039:
377 ch = '<'; 377 ch = '<';
378 break; 378 break;
379 case 0x0152: 379 case 0x0152:
380 offset = 0; 380 offset = 0;
381 q[0] = 'E'; 381 q[0] = 'E';
382 q[1] = 0; 382 q[1] = 0;
383 ch = 'O'; 383 ch = 'O';
384 break; 384 break;
385 case 0x017d: 385 case 0x017d:
386 ch = 'Z'; 386 ch = 'Z';
387 break; 387 break;
388 case 0x2018: 388 case 0x2018:
389 ch = '\''; 389 ch = '\'';
390 break; 390 break;
391 case 0x2019: 391 case 0x2019:
392 ch = '\''; 392 ch = '\'';
393 break; 393 break;
394 case 0x201c: 394 case 0x201c:
395 ch = '"'; 395 ch = '"';
396 break; 396 break;
397 case 0x201d: 397 case 0x201d:
398 ch = '"'; 398 ch = '"';
399 break; 399 break;
400 case 0x2022: 400 case 0x2022:
401 ch = '>'; 401 ch = '>';
402 break; 402 break;
403 case 0x2013: 403 case 0x2013:
404 ch = '-'; 404 ch = '-';
405 break; 405 break;
406 case 0x2014: 406 case 0x2014:
407 offset = 0; 407 offset = 0;
408 q[0] = '-'; 408 q[0] = '-';
409 q[1] = 0; 409 q[1] = 0;
410 ch = '-'; // should be -- 410 ch = '-'; // should be --
411 break; 411 break;
412 case 0x02dc: 412 case 0x02dc:
413 ch = '~'; 413 ch = '~';
414 break; 414 break;
415 case 0x0161: 415 case 0x0161:
416 ch = 's'; 416 ch = 's';
417 break; 417 break;
418 case 0x203a: 418 case 0x203a:
419 ch = '>'; 419 ch = '>';
420 break; 420 break;
421 case 0x0153: 421 case 0x0153:
422 offset = 0; 422 offset = 0;
423 q[0] = 'e'; 423 q[0] = 'e';
424 q[1] = 0; 424 q[1] = 0;
425 ch = 'o';// should be oe 425 ch = 'o';// should be oe
426 break; 426 break;
427 case 0x017e: 427 case 0x017e:
428 ch = 'z'; 428 ch = 'z';
429 break; 429 break;
430 case 0x0178: 430 case 0x0178:
431 ch = 'Y'; 431 ch = 'Y';
432 break; 432 break;
433 } 433 }
434 currentstyle = sty; 434 currentstyle = sty;
435} 435}
436 436
437void PeanutFormatter::getch(tchar& ch, CStyle& sty) 437void PeanutFormatter::getch(tchar& ch, CStyle& sty)
438{ 438{
439 CStyle dummy; 439 CStyle dummy;
440 currentstyle.setColour(0,0,0); 440 currentstyle.setColour(0,0,0);
441 parent->getch(ch, dummy); 441 parent->getch(ch, dummy);
442 while (ch == '\\') 442 while (ch == '\\')
443 { 443 {
444 parent->getch(ch, dummy); 444 parent->getch(ch, dummy);
445 if (ch == '\\') break; 445 if (ch == '\\') break;
446 switch(ch) 446 switch(ch)
447 { 447 {
448 case 'a': 448 case 'a':
449 { 449 {
450 int code = 0; 450 int code = 0;
451 for (int i = 0; i < 3; i++) 451 for (int i = 0; i < 3; i++)
452 { 452 {
453 parent->getch(ch, dummy); 453 parent->getch(ch, dummy);
454 code = 10*code + ch - '0'; 454 code = 10*code + ch - '0';
455 } 455 }
456 ch = code; 456 ch = code;
457 } 457 }
458 break; 458 break;
459 case 'v': 459 case 'v':
460 { 460 {
461 while (1) 461 while (1)
462 { 462 {
463 parent->getch(ch, dummy); 463 parent->getch(ch, dummy);
464 if (ch == '\\') 464 if (ch == '\\')
465 { 465 {
466 parent->getch(ch, dummy); 466 parent->getch(ch, dummy);
467 if (ch == 'v') 467 if (ch == 'v')
468 { 468 {
469 parent->getch(ch, dummy); 469 parent->getch(ch, dummy);
470 break; 470 break;
471 } 471 }
472 } 472 }
473 } 473 }
474 } 474 }
475 break; 475 break;
476 case 's': 476 case 's':
477 case 'n': 477 case 'n':
478 currentstyle.setFontSize(0); 478 currentstyle.setFontSize(0);
479 parent->getch(ch,dummy); 479 parent->getch(ch,dummy);
480 break; 480 break;
481 case 'p': 481 case 'p':
482 currentstyle.unset(); 482 currentstyle.unset();
483 // parent->getch(ch,dummy); 483 // parent->getch(ch,dummy);
484 ch = 10; 484 ch = 10;
485 break; 485 break;
486 case 'l': 486 case 'l':
487 if (currentstyle.getFontSize() == 1) 487 if (currentstyle.getFontSize() == 1)
488 { 488 {
489 currentstyle.setFontSize(0); 489 currentstyle.setFontSize(0);
490 } 490 }
491 else 491 else
492 { 492 {
493 currentstyle.setFontSize(1); 493 currentstyle.setFontSize(1);
494 } 494 }
495 parent->getch(ch, dummy); 495 parent->getch(ch, dummy);
496 break; 496 break;
497 case 'x': 497 case 'x':
498 if (currentstyle.getFontSize() == 0) 498 if (currentstyle.getFontSize() == 0)
499 { 499 {
500 // currentstyle.unset(); 500 // currentstyle.unset();
501 // currentstyle.setBold(); 501 // currentstyle.setBold();
502 currentstyle.setFontSize(1); 502 currentstyle.setFontSize(1);
503 } 503 }
504 else 504 else
505 { 505 {
506 currentstyle.unset(); 506 currentstyle.unset();
507 } 507 }
508 // parent->getch(ch, dummy); 508 // parent->getch(ch, dummy);
509 ch = 10; 509 ch = 10;
510 break; 510 break;
511 case 'i': 511 case 'i':
512 if (currentstyle.isItalic()) 512 if (currentstyle.isItalic())
513 { 513 {
514 currentstyle.unsetItalic(); 514 currentstyle.unsetItalic();
515 } 515 }
516 else 516 else
517 { 517 {
518 currentstyle.setItalic(); 518 currentstyle.setItalic();
519 } 519 }
520 parent->getch(ch, dummy); 520 parent->getch(ch, dummy);
521 break; 521 break;
522 case 'b': 522 case 'b':
523 case 'B': 523 case 'B':
524 if (currentstyle.isBold()) 524 if (currentstyle.isBold())
525 { 525 {
526 currentstyle.unsetBold(); 526 currentstyle.unsetBold();
527 } 527 }
528 else 528 else
529 { 529 {
530 currentstyle.setBold(); 530 currentstyle.setBold();
531 } 531 }
532 parent->getch(ch, dummy); 532 parent->getch(ch, dummy);
533 break; 533 break;
534 case 'c': 534 case 'c':
535 if (currentstyle.getJustify() == CStyle::m_AlignCentre) 535 if (currentstyle.getJustify() == m_AlignCentre)
536 { 536 {
537 currentstyle.setLeftJustify(); 537 currentstyle.setLeftJustify();
538 } 538 }
539 else 539 else
540 { 540 {
541 currentstyle.setCentreJustify(); 541 currentstyle.setCentreJustify();
542 } 542 }
543 parent->getch(ch, dummy); 543 parent->getch(ch, dummy);
544 break; 544 break;
545 case 'r': 545 case 'r':
546 if (currentstyle.getJustify() == CStyle::m_AlignRight) 546 if (currentstyle.getJustify() == m_AlignRight)
547 { 547 {
548 currentstyle.setLeftJustify(); 548 currentstyle.setLeftJustify();
549 } 549 }
550 else 550 else
551 { 551 {
552 currentstyle.setRightJustify(); 552 currentstyle.setRightJustify();
553 } 553 }
554 parent->getch(ch, dummy); 554 parent->getch(ch, dummy);
555 break; 555 break;
556 default: 556 default:
557 currentstyle.setColour(255,0,0); 557 currentstyle.setColour(255,0,0);
558 } 558 }
559 } 559 }
560 sty = currentstyle; 560 sty = currentstyle;
561} 561}
562
563void OnePara::getch(tchar& ch, CStyle& sty)
564{
565 parent->getch(ch, sty);
566 if (m_lastchar == 10)
567 {
568 while (ch == 10) parent->getch(ch, sty);
569 }
570 m_lastchar = ch;
571}
572
573#ifdef REPALM
574void repalm::getch(tchar& ch, CStyle& sty)
575{
576 parent->getch(ch, sty);
577 switch (ch)
578 {
579 case 0x80:
580 ch = 0x20ac;
581 break;
582 case 0x82:
583 ch = 0x201a;
584 break;
585 case 0x83:
586 ch = 0x0192;
587 break;
588 case 0x84:
589 ch = 0x201e;
590 break;
591 case 0x85:
592 ch = 0x2026;
593 break;
594 case 0x86:
595 ch = 0x2020;
596 break;
597 case 0x87:
598 ch = 0x2021;
599 break;
600 case 0x88:
601 ch = 0x02c6;
602 break;
603 case 0x89:
604 ch = 0x2030;
605 break;
606 case 0x8a:
607 ch = 0x0160;
608 break;
609 case 0x8b:
610 ch = 0x2039;
611 break;
612 case 0x8c:
613 ch = 0x0152;
614 break;
615/*
616 case 0x8e:
617 ch = 0x017d;
618 break;
619*/
620 case 0x91:
621 ch = 0x2018;
622 break;
623 case 0x92:
624 ch = 0x2019;
625 break;
626 case 0x93:
627 ch = 0x201c;
628 break;
629 case 0x94:
630 ch = 0x201d;
631 break;
632 case 0x95:
633 ch = 0x2022;
634 break;
635 case 0x96:
636 ch = 0x2013;
637 break;
638 case 0x97:
639 ch = 0x2014;
640 break;
641 case 0x98:
642 ch = 0x02dc;
643 break;
644 case 0x99:
645 ch = 0x2122;
646 break;
647 case 0x9a:
648 ch = 0x0161;
649 break;
650 case 0x9b:
651 ch = 0x203a;
652 break;
653 case 0x9c:
654 ch = 0x0153;
655 break;
656 case 0x9e:
657 ch = 0x017e;
658 break;
659 case 0x9f:
660 ch = 0x0178;
661 break;
662 case 0x18:
663 ch = 0x2026;
664 break;
665 case 0x19:
666 ch = 0x2007;
667 break;
668 case 0x8d:
669 ch = 0x2662;
670 break;
671 case 0x8e:
672 ch = 0x2663;
673 break;
674 case 0x8f:
675 ch = 0x2661;
676 break;
677 case 0x90:
678 ch = 0x2660;
679 break;
680 default:
681 break;
682 }
683}
684#endif
diff --git a/noncore/apps/opie-reader/CFilter.h b/noncore/apps/opie-reader/CFilter.h
index 8cfd7eb..2d0c30f 100644
--- a/noncore/apps/opie-reader/CFilter.h
+++ b/noncore/apps/opie-reader/CFilter.h
@@ -1,269 +1,287 @@
1#ifndef __CFILTER_H 1#ifndef __CFILTER_H
2#define __CFILTER_H 2#define __CFILTER_H
3 3
4#include "CExpander.h" 4#include "CExpander.h"
5#include "CEncoding.h" 5#include "CEncoding.h"
6 6
7class CFilter : public CCharacterSource 7class CFilter : public CCharacterSource
8{ 8{
9 friend class CFilterChain; 9 friend class CFilterChain;
10 protected: 10 protected:
11 CCharacterSource* parent; 11 CCharacterSource* parent;
12 public: 12 public:
13 CFilter() : parent(NULL) {} 13 CFilter() : parent(NULL) {}
14 void setparent(CCharacterSource* p) { parent = p; } 14 void setparent(CCharacterSource* p) { parent = p; }
15 virtual ~CFilter() {}; 15 virtual ~CFilter() {};
16}; 16};
17 17
18class CFilterChain 18class CFilterChain
19{ 19{
20 CExpander* expander; 20 CExpander* expander;
21 CEncoding* encoder; 21 CEncoding* encoder;
22 CFilter* first; 22 CFilter* first;
23 CCharacterSource* front; 23 CCharacterSource* front;
24 public: 24 public:
25 CFilterChain(CEncoding* _e) : encoder(_e), first(NULL), front(_e) {}; 25 CFilterChain(CEncoding* _e) : encoder(_e), first(NULL), front(_e) {};
26 ~CFilterChain() 26 ~CFilterChain()
27 { 27 {
28 CCharacterSource* p = front; 28 CCharacterSource* p = front;
29 while (p != encoder) 29 while (p != encoder)
30 { 30 {
31 CFilter* pnext = (CFilter*)p; 31 CFilter* pnext = (CFilter*)p;
32 p = ((CFilter*)p)->parent; 32 p = ((CFilter*)p)->parent;
33 delete pnext; 33 delete pnext;
34 } 34 }
35 delete encoder; 35 delete encoder;
36 } 36 }
37 void getch(tchar& ch, CStyle& sty) 37 void getch(tchar& ch, CStyle& sty)
38 { 38 {
39 front->getch(ch, sty); 39 front->getch(ch, sty);
40 } 40 }
41 void addfilter(CFilter* p) 41 void addfilter(CFilter* p)
42 { 42 {
43 if (first == NULL) 43 if (first == NULL)
44 { 44 {
45 front = first = p; 45 front = first = p;
46 p->setparent(encoder); 46 p->setparent(encoder);
47 } 47 }
48 else 48 else
49 { 49 {
50 p->setparent(front); 50 p->setparent(front);
51 front = p; 51 front = p;
52 } 52 }
53 } 53 }
54 void setsource(CExpander* p) 54 void setsource(CExpander* p)
55 { 55 {
56 expander = p; 56 expander = p;
57 encoder->setparent(p); 57 encoder->setparent(p);
58 } 58 }
59 void setencoder(CEncoding* p) 59 void setencoder(CEncoding* p)
60 { 60 {
61 delete encoder; 61 delete encoder;
62 encoder = p; 62 encoder = p;
63 first->setparent(p); 63 first->setparent(p);
64 encoder->setparent(expander); 64 encoder->setparent(expander);
65 } 65 }
66}; 66};
67 67
68class stripcr : public CFilter 68class stripcr : public CFilter
69{ 69{
70 public: 70 public:
71 stripcr() {} 71 stripcr() {}
72 virtual ~stripcr() {} 72 virtual ~stripcr() {}
73 virtual void getch(tchar& ch, CStyle& sty) 73 virtual void getch(tchar& ch, CStyle& sty)
74 { 74 {
75 do 75 do
76 { 76 {
77 parent->getch(ch, sty); 77 parent->getch(ch, sty);
78 } 78 }
79 while (ch == 13); 79 while (ch == 13);
80 } 80 }
81}; 81};
82 82
83class dehyphen : public CFilter 83class dehyphen : public CFilter
84{ 84{
85 bool m_bCharWaiting; 85 bool m_bCharWaiting;
86 tchar m_nextChar; 86 tchar m_nextChar;
87 CStyle m_nextSty; 87 CStyle m_nextSty;
88 public: 88 public:
89 dehyphen() : m_bCharWaiting(false) {} 89 dehyphen() : m_bCharWaiting(false) {}
90 virtual ~dehyphen() {} 90 virtual ~dehyphen() {}
91 virtual void getch(tchar& ch, CStyle& sty) 91 virtual void getch(tchar& ch, CStyle& sty)
92 { 92 {
93 if (m_bCharWaiting) 93 if (m_bCharWaiting)
94 { 94 {
95 m_bCharWaiting = false; 95 m_bCharWaiting = false;
96 ch = m_nextChar; 96 ch = m_nextChar;
97 sty = m_nextSty; 97 sty = m_nextSty;
98 return; 98 return;
99 } 99 }
100 parent->getch(ch, sty); 100 parent->getch(ch, sty);
101 if (ch != '-') return; 101 if (ch != '-') return;
102 parent->getch(m_nextChar, m_nextSty); 102 parent->getch(m_nextChar, m_nextSty);
103 if (m_nextChar != 10) 103 if (m_nextChar != 10)
104 { 104 {
105 m_bCharWaiting = true; 105 m_bCharWaiting = true;
106 ch = '-'; 106 ch = '-';
107 return; 107 return;
108 } 108 }
109 parent->getch(ch, sty); 109 parent->getch(ch, sty);
110 } 110 }
111}; 111};
112 112
113class striphtml : public CFilter 113class striphtml : public CFilter
114{ 114{
115 CStyle currentstyle; 115 CStyle currentstyle;
116 unsigned short skip_ws(); 116 unsigned short skip_ws();
117 unsigned short skip_ws_end(); 117 unsigned short skip_ws_end();
118 unsigned short parse_m(); 118 unsigned short parse_m();
119 void mygetch(tchar& ch, CStyle& sty); 119 void mygetch(tchar& ch, CStyle& sty);
120 public: 120 public:
121 striphtml() {} 121 striphtml() {}
122 virtual ~striphtml() {} 122 virtual ~striphtml() {}
123 virtual void getch(tchar& ch, CStyle& sty); 123 virtual void getch(tchar& ch, CStyle& sty);
124}; 124};
125 125
126class unindent : public CFilter 126class unindent : public CFilter
127{ 127{
128 tchar lc; 128 tchar lc;
129 public: 129 public:
130 unindent() : lc(0) {} 130 unindent() : lc(0) {}
131 virtual ~unindent() {} 131 virtual ~unindent() {}
132 virtual void getch(tchar& ch, CStyle& sty) 132 virtual void getch(tchar& ch, CStyle& sty)
133 { 133 {
134 if (lc == 10) 134 if (lc == 10)
135 { 135 {
136 do 136 do
137 { 137 {
138 parent->getch(ch, sty); 138 parent->getch(ch, sty);
139 } 139 }
140 while (ch == ' '); 140 while (ch == ' ');
141 } 141 }
142 else parent->getch(ch, sty); 142 else parent->getch(ch, sty);
143 lc = ch; 143 lc = ch;
144 return; 144 return;
145 } 145 }
146}; 146};
147 147
148class repara : public CFilter 148class repara : public CFilter
149{ 149{
150 tchar tch; 150 tchar tch;
151 public: 151 public:
152 repara() : tch(0) {} 152 repara() : tch(0) {}
153 virtual ~repara() {} 153 virtual ~repara() {}
154 virtual void getch(tchar& ch, CStyle& sty) 154 virtual void getch(tchar& ch, CStyle& sty)
155 { 155 {
156 parent->getch(ch, sty); 156 parent->getch(ch, sty);
157 if (ch == 10) 157 if (ch == 10)
158 { 158 {
159 if (tch == 10) 159 if (tch == 10)
160 { 160 {
161 return; 161 return;
162 } 162 }
163 else 163 else
164 { 164 {
165 tch = ch; 165 tch = ch;
166 ch = ' '; 166 ch = ' ';
167 return; 167 return;
168 } 168 }
169 } 169 }
170 tch = ch; 170 tch = ch;
171 return; 171 return;
172 } 172 }
173}; 173};
174 174
175class indenter : public CFilter 175class indenter : public CFilter
176{ 176{
177 int amnt; 177 int amnt;
178 int indent; 178 int indent;
179 CStyle lsty; 179 CStyle lsty;
180 public: 180 public:
181 indenter(int _a=5) : amnt(_a), indent(0) {} 181 indenter(int _a=5) : amnt(_a), indent(0) {}
182 virtual ~indenter() {} 182 virtual ~indenter() {}
183 virtual void getch(tchar& ch, CStyle& sty) 183 virtual void getch(tchar& ch, CStyle& sty)
184 { 184 {
185 if (indent > 0) 185 if (indent > 0)
186 { 186 {
187 indent--; 187 indent--;
188 ch = ' '; 188 ch = ' ';
189 sty = lsty; 189 sty = lsty;
190 return; 190 return;
191 } 191 }
192 parent->getch(ch, sty); 192 parent->getch(ch, sty);
193 if (ch == 10) 193 if (ch == 10)
194 { 194 {
195 indent = amnt; 195 indent = amnt;
196 lsty = sty; 196 lsty = sty;
197 } 197 }
198 return; 198 return;
199 } 199 }
200}; 200};
201 201
202class dblspce : public CFilter 202class dblspce : public CFilter
203{ 203{
204 bool lastlf; 204 bool lastlf;
205 CStyle lsty; 205 CStyle lsty;
206 public: 206 public:
207 dblspce() : lastlf(false) {} 207 dblspce() : lastlf(false) {}
208 virtual ~dblspce() {} 208 virtual ~dblspce() {}
209 virtual void getch(tchar& ch, CStyle& sty) 209 virtual void getch(tchar& ch, CStyle& sty)
210 { 210 {
211 if (lastlf) 211 if (lastlf)
212 { 212 {
213 lastlf = false; 213 lastlf = false;
214 ch = 10; 214 ch = 10;
215 sty = lsty; 215 sty = lsty;
216 return; 216 return;
217 } 217 }
218 parent->getch(ch, sty); 218 parent->getch(ch, sty);
219 if (lastlf = (ch == 10)) 219 if (lastlf = (ch == 10))
220 { 220 {
221 lsty = sty; 221 lsty = sty;
222 } 222 }
223 return; 223 return;
224 } 224 }
225}; 225};
226 226
227class textfmt : public CFilter 227class textfmt : public CFilter
228{ 228{
229 CStyle currentstyle; 229 CStyle currentstyle;
230 tchar lastchar; 230 tchar lastchar;
231 bool uselast; 231 bool uselast;
232 void mygetch(tchar&, CStyle&); 232 void mygetch(tchar&, CStyle&);
233 public: 233 public:
234 textfmt() : lastchar(0), uselast(false) {} 234 textfmt() : lastchar(0), uselast(false) {}
235 virtual ~textfmt() {} 235 virtual ~textfmt() {}
236 virtual void getch(tchar& ch, CStyle& sty); 236 virtual void getch(tchar& ch, CStyle& sty);
237}; 237};
238 238
239class embolden : public CFilter 239class embolden : public CFilter
240{ 240{
241 public: 241 public:
242 embolden() {} 242 embolden() {}
243 virtual ~embolden() {} 243 virtual ~embolden() {}
244 virtual void getch(tchar& ch, CStyle& sty) 244 virtual void getch(tchar& ch, CStyle& sty)
245 { 245 {
246 parent->getch(ch, sty); 246 parent->getch(ch, sty);
247 sty.setBold(); 247 sty.setBold();
248 } 248 }
249}; 249};
250 250
251class remap : public CFilter 251class remap : public CFilter
252{ 252{
253 tchar q[3]; 253 tchar q[3];
254 int offset; 254 int offset;
255 CStyle currentstyle; 255 CStyle currentstyle;
256 public: 256 public:
257 remap() : offset(0) { q[0] = 0; } 257 remap() : offset(0) { q[0] = 0; }
258 virtual ~remap() {} 258 virtual ~remap() {}
259 virtual void getch(tchar& ch, CStyle& sty); 259 virtual void getch(tchar& ch, CStyle& sty);
260}; 260};
261 261
262class PeanutFormatter : public CFilter 262class PeanutFormatter : public CFilter
263{ 263{
264 CStyle currentstyle; 264 CStyle currentstyle;
265 public: 265 public:
266 virtual ~PeanutFormatter() {} 266 virtual ~PeanutFormatter() {}
267 virtual void getch(tchar& ch, CStyle& sty); 267 virtual void getch(tchar& ch, CStyle& sty);
268}; 268};
269
270class OnePara : public CFilter
271{
272 tchar m_lastchar;
273 public:
274 OnePara() : m_lastchar(0) {}
275 virtual ~OnePara() {}
276 virtual void getch(tchar& ch, CStyle& sty);
277};
278
279#ifdef REPALM
280class repalm : public CFilter
281{
282 public:
283 virtual ~repalm() {}
284 virtual void getch(tchar& ch, CStyle& sty);
285};
286#endif
269#endif 287#endif
diff --git a/noncore/apps/opie-reader/Filedata.h b/noncore/apps/opie-reader/Filedata.h
new file mode 100644
index 0000000..f920238
--- a/dev/null
+++ b/noncore/apps/opie-reader/Filedata.h
@@ -0,0 +1,51 @@
1#ifndef __FILEDATA_H
2#define __FILEDATA_H
3
4#include <time.h>
5
6class CFiledata
7{
8 unsigned char* data;
9 bool m_own;
10 public:
11 CFiledata(tchar* d)
12 {
13 data = (unsigned char*)d;
14 m_own = false;
15 }
16 CFiledata(time_t dt, tchar* nm)
17 {
18 int nlen = ustrlen(nm)+1;
19 data = new unsigned char[sizeof(time_t)+sizeof(tchar)*nlen];
20 *((time_t *)data) = dt;
21 memcpy(data+sizeof(time_t), nm, sizeof(tchar)*nlen);
22 m_own = true;
23 }
24 ~CFiledata()
25 {
26 if (m_own && data != NULL)
27 {
28 delete [] data;
29 qDebug("~Filedata: deleting");
30 }
31 else
32 {
33 qDebug("~Filedata: not deleting");
34 }
35 }
36 tchar* name() const { return (tchar*)(data+sizeof(time_t)); }
37 time_t date() { return *((time_t *)data); }
38 void setdate(time_t _t) { *((time_t *)data) = _t; }
39 unsigned char* content() { return data; }
40 size_t length() const { return sizeof(time_t)+sizeof(tchar)*(ustrlen(name())+1); }
41 bool operator==(const CFiledata& rhs)
42 {
43 return ((length() == rhs.length()) && (memcmp(data, rhs.data, length()) == 0));
44 }
45 bool samename(const CFiledata& rhs)
46 {
47 return (ustrcmp((tchar *)(data+sizeof(time_t)),(tchar *)(rhs.data+sizeof(time_t))) == 0);
48 }
49};
50
51#endif
diff --git a/noncore/apps/opie-reader/FontControl.cpp b/noncore/apps/opie-reader/FontControl.cpp
new file mode 100644
index 0000000..f0ed98b
--- a/dev/null
+++ b/noncore/apps/opie-reader/FontControl.cpp
@@ -0,0 +1,37 @@
1#include "opie.h"
2#include "FontControl.h"
3
4bool FontControl::ChangeFont(QString& n, int tgt)
5{
6 QValueList<int>::Iterator it;
7 QFontDatabase fdb;
8 QValueList<int> sizes = fdb.pointSizes(n);
9 if (sizes.count() == 0)
10 {
11 return false;
12 }
13 else
14 {
15 m_fontname = n;
16 m_maxsize = sizes.count();
17 if (m_fontsizes != NULL) delete [] m_fontsizes;
18 m_fontsizes = new int[m_maxsize];
19 uint i = 0;
20 uint best = 0;
21 for (it = sizes.begin(); it != sizes.end(); it++)
22 {
23#ifdef OPIE
24 m_fontsizes[i] = (*it);
25#else
26 m_fontsizes[i] = (*it)/10;
27#endif
28 if (abs(tgt-m_fontsizes[i]) < abs(tgt-m_fontsizes[best]))
29 {
30 best = i;
31 }
32 i++;
33 }
34 m_size = best;
35 }
36 return true;
37}
diff --git a/noncore/apps/opie-reader/FontControl.h b/noncore/apps/opie-reader/FontControl.h
index d427680..02049d0 100644
--- a/noncore/apps/opie-reader/FontControl.h
+++ b/noncore/apps/opie-reader/FontControl.h
@@ -1,121 +1,104 @@
1#ifndef __FONTCONTROL_H 1#ifndef __FONTCONTROL_H
2#define __FONTCONTROL_H 2#define __FONTCONTROL_H
3 3
4#include <qfontdatabase.h> 4#include <qfontdatabase.h>
5#include <qfontmetrics.h> 5#include <qfontmetrics.h>
6#include "StyleConsts.h" 6#include "StyleConsts.h"
7 7
8class FontControl 8class FontControl
9{ 9{
10 int * m_fontsizes; 10 int * m_fontsizes;
11 int m_size; 11 int m_size;
12 QString m_fontname; 12 QString m_fontname;
13 int m_maxsize; 13 int m_maxsize;
14 bool m_hasCourier;
14 public: 15 public:
15 FontControl(QString n = "helvetica", int size = 10) 16 FontControl(QString n = "helvetica", int size = 10)
16 : 17 :
17 m_fontsizes(NULL) 18 m_fontsizes(NULL), m_hasCourier(false)
18 { 19 {
19 ChangeFont(n, size); 20 ChangeFont(n, size);
20 } 21 }
21 ~FontControl() 22 ~FontControl()
22 { 23 {
23 if (m_fontsizes != NULL) delete [] m_fontsizes; 24 if (m_fontsizes != NULL) delete [] m_fontsizes;
24 } 25 }
26 void hasCourier(bool _b) { m_hasCourier = _b; }
27 bool hasCourier() { return m_hasCourier; }
25 QString name() { return m_fontname; } 28 QString name() { return m_fontname; }
26 int currentsize() { return m_fontsizes[m_size]; } 29 int currentsize() { return m_fontsizes[m_size]; }
27 int getsize(CStyle size) 30 int getsize(CStyle size)
28 { 31 {
29 return m_fontsizes[m_size+size.getFontSize()]; 32 int tgt = m_size+size.getFontSize();
33 if (tgt < 0)
34 {
35 tgt = 0;
36 }
37 if (tgt >= m_maxsize)
38 {
39 tgt = m_maxsize - 1;
40 }
41 return m_fontsizes[tgt];
30 } 42 }
31 int ascent() 43 int ascent()
32 { 44 {
33 QFont f(name(), currentsize()); 45 QFont f(name(), currentsize());
34 QFontMetrics fm(f); 46 QFontMetrics fm(f);
35 return fm.ascent(); 47 return fm.ascent();
36 } 48 }
37 int ascent(CStyle ch) 49 int ascent(CStyle ch)
38 { 50 {
39 QFont f(name(), getsize(ch)); 51 QFont f(name(), getsize(ch));
40 QFontMetrics fm(f); 52 QFontMetrics fm(f);
41 return fm.ascent(); 53 return fm.ascent();
42 } 54 }
43 int descent() 55 int descent()
44 { 56 {
45 QFont f(name(), currentsize()); 57 QFont f(name(), currentsize());
46 QFontMetrics fm(f); 58 QFontMetrics fm(f);
47 return fm.descent(); 59 return fm.descent();
48 } 60 }
49 int descent(CStyle ch) 61 int descent(CStyle ch)
50 { 62 {
51 QFont f(name(), getsize(ch)); 63 QFont f(name(), getsize(ch));
52 QFontMetrics fm(f); 64 QFontMetrics fm(f);
53 return fm.descent(); 65 return fm.descent();
54 } 66 }
55 int lineSpacing() 67 int lineSpacing()
56 { 68 {
57 QFont f(name(), currentsize()); 69 QFont f(name(), currentsize());
58 QFontMetrics fm(f); 70 QFontMetrics fm(f);
59 return fm.lineSpacing(); 71 return fm.lineSpacing();
60 } 72 }
61 int lineSpacing(CStyle ch) 73 int lineSpacing(CStyle ch)
62 { 74 {
63 QFont f(name(), getsize(ch)); 75 QFont f(name(), getsize(ch));
64 QFontMetrics fm(f); 76 QFontMetrics fm(f);
65 return fm.lineSpacing(); 77 return fm.lineSpacing();
66 } 78 }
67 bool decreasesize() 79 bool decreasesize()
68 { 80 {
69 if (--m_size < 0) 81 if (--m_size < 0)
70 { 82 {
71 m_size = 0; 83 m_size = 0;
72 return false; 84 return false;
73 } 85 }
74 else return true; 86 else return true;
75 } 87 }
76 bool increasesize() 88 bool increasesize()
77 { 89 {
78 if (++m_size >= m_maxsize) 90 if (++m_size >= m_maxsize)
79 { 91 {
80 m_size = m_maxsize - 1; 92 m_size = m_maxsize - 1;
81 return false; 93 return false;
82 } 94 }
83 else return true; 95 else return true;
84 } 96 }
85 bool ChangeFont(QString& n) 97 bool ChangeFont(QString& n)
86 { 98 {
87 return ChangeFont(n, currentsize()); 99 return ChangeFont(n, currentsize());
88 } 100 }
89 bool ChangeFont(QString& n, int tgt) 101 bool ChangeFont(QString& n, int tgt);
90 {
91 QValueList<int>::Iterator it;
92 QFontDatabase fdb;
93 QValueList<int> sizes = fdb.pointSizes(n);
94 if (sizes.count() == 0)
95 {
96 return false;
97 }
98 else
99 {
100 m_fontname = n;
101 m_maxsize = sizes.count();
102 if (m_fontsizes != NULL) delete [] m_fontsizes;
103 m_fontsizes = new int[m_maxsize];
104 uint i = 0;
105 uint best = 0;
106 for (it = sizes.begin(); it != sizes.end(); it++)
107 {
108 m_fontsizes[i] = (*it);
109 if (abs(tgt-m_fontsizes[i]) < abs(tgt-m_fontsizes[best]))
110 {
111 best = i;
112 }
113 i++;
114 }
115 m_size = best;
116 }
117 return true;
118 }
119}; 102};
120 103
121#endif 104#endif
diff --git a/noncore/apps/opie-reader/GraphicWin.h b/noncore/apps/opie-reader/GraphicWin.h
new file mode 100644
index 0000000..31811d2
--- a/dev/null
+++ b/noncore/apps/opie-reader/GraphicWin.h
@@ -0,0 +1,65 @@
1#ifndef __GRAPHICWIN_H
2#define __GRAPHICWIN_H
3
4#include <qscrollview.h>
5#include <qpixmap.h>
6#include <qpushbutton.h>
7#include <qlayout.h>
8
9class GraphicScroll : public QScrollView
10{
11 Q_OBJECT
12 QWidget* m_picture;
13 protected:
14 void hideEvent( QHideEvent * p)
15 {
16 m_picture->setFixedSize(1,1);
17 }
18 public:
19 GraphicScroll( QWidget *parent=0, const char *name=0, WFlags f = 0)
20 : QScrollView(parent, name, f)
21 {
22 m_picture = new QWidget(viewport());
23 addChild(m_picture);
24 }
25 void setPixmap(QPixmap& pm)
26 {
27 m_picture->setFixedSize(pm.size());
28 m_picture->setBackgroundPixmap(pm);
29 }
30/*
31 private slots:
32 void graphicClose() { emit Close(); }
33 signals:
34 void Close();
35*/
36
37};
38
39
40class GraphicWin : public QWidget
41{
42 Q_OBJECT
43
44 GraphicScroll* m_scroll;
45 signals:
46 void Closed();
47 private slots:
48 void slotClosed() { emit Closed(); }
49
50 public:
51
52 void setPixmap(QPixmap& pm) { m_scroll->setPixmap(pm); }
53 GraphicWin( QWidget *parent=0, const char *name=0, WFlags f = 0)
54 : QWidget(parent, name, f)
55 {
56 QVBoxLayout* grid = new QVBoxLayout(this);
57 m_scroll = new GraphicScroll(this);
58 QPushButton* exitButton = new QPushButton("Close", this);
59 connect(exitButton, SIGNAL( released() ), this, SLOT( slotClosed() ) );
60 grid->addWidget(m_scroll,1);
61 grid->addWidget(exitButton);
62 }
63};
64
65#endif
diff --git a/noncore/apps/opie-reader/Navigation.cpp b/noncore/apps/opie-reader/Navigation.cpp
new file mode 100644
index 0000000..7b392ba
--- a/dev/null
+++ b/noncore/apps/opie-reader/Navigation.cpp
@@ -0,0 +1,98 @@
1#include "Navigation.h"
2
3void CNavigation::saveposn(size_t posn)
4{
5// qDebug("Saved:%u [%u,%u,%u]", posn, historystart, historycurrent, historyend);
6 historycurrent = historyend = (historycurrent+1)%NAVIGATION_HISTORY_SIZE;
7 history[historycurrent] = posn;
8 if (historystart == historyend) historystart = (historystart+1)%NAVIGATION_HISTORY_SIZE;
9// qDebug("Saved:%u [%u,%u,%u]", posn, historystart, historycurrent, historyend);
10}
11
12bool CNavigation::forward(size_t& loc)
13{
14 if (historycurrent != historyend)
15 {
16 historycurrent = (historycurrent + 1)%NAVIGATION_HISTORY_SIZE;
17 loc = history[historycurrent];
18 //qDebug("Forward:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend);
19 return true;
20 }
21 else
22 {
23 return false;
24 }
25}
26
27bool CNavigation::back(size_t& loc)
28{
29 if (historyend != historystart)
30 {
31 //qDebug("Back:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend);
32 if (historycurrent == historyend && history[historycurrent] != loc)
33 {
34 historyend = (historyend+1) % NAVIGATION_HISTORY_SIZE;
35 history[historyend] = loc;
36 }
37 else
38 {
39 size_t sv = historycurrent;
40 historycurrent = (historycurrent + NAVIGATION_HISTORY_SIZE - 1) % NAVIGATION_HISTORY_SIZE;
41 if (historycurrent == historystart)
42 {
43 historycurrent = sv;
44 return false;
45 }
46 }
47 loc = history[historycurrent];
48 //qDebug("Back:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend);
49 return true;
50 }
51 else
52 {
53 return false;
54 }
55}
56
57#include <stdio.h>
58
59void CNavigation::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
60{
61 len = srclen+sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE);
62 data = new unsigned char[len];
63 unsigned char* p = data;
64 memcpy(p, src, srclen);
65 p += srclen;
66 memcpy(p, &historystart, sizeof(size_t));
67 p += sizeof(size_t);
68 memcpy(p, &historyend, sizeof(size_t));
69 p += sizeof(size_t);
70 memcpy(p, &historycurrent, sizeof(size_t));
71 p += sizeof(size_t);
72 memcpy(p, history, sizeof(size_t)*NAVIGATION_HISTORY_SIZE);
73 printf("<%u,%u,%u>\n", historystart, historyend, historycurrent);
74 for (int i = historystart; i <= historyend; i++)
75 printf("<%u> ", history[i]);
76 printf("\n");
77}
78
79void CNavigation::putSaveData(unsigned char*& src, unsigned short& srclen)
80{
81 if (srclen >= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE))
82 {
83 unsigned char* p = src;
84 memcpy(&historystart, p, sizeof(size_t));
85 p += sizeof(size_t);
86 memcpy(&historyend, p, sizeof(size_t));
87 p += sizeof(size_t);
88 memcpy(&historycurrent, p, sizeof(size_t));
89 p += sizeof(size_t);
90 memcpy(history, p, sizeof(size_t)*NAVIGATION_HISTORY_SIZE);
91 src = p + sizeof(size_t)*NAVIGATION_HISTORY_SIZE;
92 srclen -= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE);
93 }
94 printf("<%u,%u,%u>\n", historystart, historyend, historycurrent);
95 for (int i = historystart; i <= historyend; i++)
96 printf("<%u> ", history[i]);
97 printf("\n");
98}
diff --git a/noncore/apps/opie-reader/Navigation.h b/noncore/apps/opie-reader/Navigation.h
new file mode 100644
index 0000000..57fb006
--- a/dev/null
+++ b/noncore/apps/opie-reader/Navigation.h
@@ -0,0 +1,16 @@
1#include <stdlib.h>
2
3const size_t NAVIGATION_HISTORY_SIZE = 32;
4
5class CNavigation
6{
7 size_t history[NAVIGATION_HISTORY_SIZE];
8 size_t historystart, historyend, historycurrent;
9 public:
10 CNavigation() : historystart(0),historyend(0),historycurrent(0) {}
11 void saveposn(size_t posn);
12 bool forward(size_t& loc);
13 bool back(size_t& loc);
14 void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen);
15 void putSaveData(unsigned char*& src, unsigned short& srclen);
16};
diff --git a/noncore/apps/opie-reader/Palm2QImage.cpp b/noncore/apps/opie-reader/Palm2QImage.cpp
new file mode 100644
index 0000000..ef88cc5
--- a/dev/null
+++ b/noncore/apps/opie-reader/Palm2QImage.cpp
@@ -0,0 +1,290 @@
1/* -*- mode: c; indent-tabs-mode: nil; -*- */
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <unistd.h> /* for link */
6#include <sys/types.h>
7#include <sys/stat.h>
8#include <stdarg.h>
9
10#include <qimage.h>
11
12/***********************************************************************/
13/***********************************************************************/
14/***** *****/
15/***** Code to decode the Palm image format to JPEG *****/
16/***** *****/
17/***********************************************************************/
18/***********************************************************************/
19
20#define READ_BIGENDIAN_SHORT(p) (((p)[0] << 8)|((p)[1]))
21#define READ_BIGENDIAN_LONG(p) (((p)[0] << 24)|((p)[1] << 16)|((p)[2] << 8)|((p)[3]))
22
23#define PALM_IS_COMPRESSED_FLAG 0x8000
24#define PALM_HAS_COLORMAP_FLAG 0x4000
25#define PALM_HAS_TRANSPARENCY_FLAG 0x2000
26#define PALM_DIRECT_COLOR_FLAG 0x0400
27#define PALM_4_BYTE_FIELD_FLAG 0x0200
28
29#define PALM_COMPRESSION_SCANLINE 0x00
30#define PALM_COMPRESSION_RLE 0x01
31#define PALM_COMPRESSION_PACKBITS 0x02
32#define PALM_COMPRESSION_NONE 0xFF
33
34#define PALM_COLORMAP_SIZE 232
35
36typedef struct {
37 unsigned char red;
38 unsigned char green;
39 unsigned char blue;
40} ColorMapEntry;
41
42static ColorMapEntry Palm8BitColormap[] = {
43 { 255, 255, 255 }, { 255, 204, 255 }, { 255, 153, 255 }, { 255, 102, 255 },
44 { 255, 51, 255 }, { 255, 0, 255 }, { 255, 255, 204 }, { 255, 204, 204 },
45 { 255, 153, 204 }, { 255, 102, 204 }, { 255, 51, 204 }, { 255, 0, 204 },
46 { 255, 255, 153 }, { 255, 204, 153 }, { 255, 153, 153 }, { 255, 102, 153 },
47 { 255, 51, 153 }, { 255, 0, 153 }, { 204, 255, 255 }, { 204, 204, 255 },
48 { 204, 153, 255 }, { 204, 102, 255 }, { 204, 51, 255 }, { 204, 0, 255 },
49 { 204, 255, 204 }, { 204, 204, 204 }, { 204, 153, 204 }, { 204, 102, 204 },
50 { 204, 51, 204 }, { 204, 0, 204 }, { 204, 255, 153 }, { 204, 204, 153 },
51 { 204, 153, 153 }, { 204, 102, 153 }, { 204, 51, 153 }, { 204, 0, 153 },
52 { 153, 255, 255 }, { 153, 204, 255 }, { 153, 153, 255 }, { 153, 102, 255 },
53 { 153, 51, 255 }, { 153, 0, 255 }, { 153, 255, 204 }, { 153, 204, 204 },
54 { 153, 153, 204 }, { 153, 102, 204 }, { 153, 51, 204 }, { 153, 0, 204 },
55 { 153, 255, 153 }, { 153, 204, 153 }, { 153, 153, 153 }, { 153, 102, 153 },
56 { 153, 51, 153 }, { 153, 0, 153 }, { 102, 255, 255 }, { 102, 204, 255 },
57 { 102, 153, 255 }, { 102, 102, 255 }, { 102, 51, 255 }, { 102, 0, 255 },
58 { 102, 255, 204 }, { 102, 204, 204 }, { 102, 153, 204 }, { 102, 102, 204 },
59 { 102, 51, 204 }, { 102, 0, 204 }, { 102, 255, 153 }, { 102, 204, 153 },
60 { 102, 153, 153 }, { 102, 102, 153 }, { 102, 51, 153 }, { 102, 0, 153 },
61 { 51, 255, 255 }, { 51, 204, 255 }, { 51, 153, 255 }, { 51, 102, 255 },
62 { 51, 51, 255 }, { 51, 0, 255 }, { 51, 255, 204 }, { 51, 204, 204 },
63 { 51, 153, 204 }, { 51, 102, 204 }, { 51, 51, 204 }, { 51, 0, 204 },
64 { 51, 255, 153 }, { 51, 204, 153 }, { 51, 153, 153 }, { 51, 102, 153 },
65 { 51, 51, 153 }, { 51, 0, 153 }, { 0, 255, 255 }, { 0, 204, 255 },
66 { 0, 153, 255 }, { 0, 102, 255 }, { 0, 51, 255 }, { 0, 0, 255 },
67 { 0, 255, 204 }, { 0, 204, 204 }, { 0, 153, 204 }, { 0, 102, 204 },
68 { 0, 51, 204 }, { 0, 0, 204 }, { 0, 255, 153 }, { 0, 204, 153 },
69 { 0, 153, 153 }, { 0, 102, 153 }, { 0, 51, 153 }, { 0, 0, 153 },
70 { 255, 255, 102 }, { 255, 204, 102 }, { 255, 153, 102 }, { 255, 102, 102 },
71 { 255, 51, 102 }, { 255, 0, 102 }, { 255, 255, 51 }, { 255, 204, 51 },
72 { 255, 153, 51 }, { 255, 102, 51 }, { 255, 51, 51 }, { 255, 0, 51 },
73 { 255, 255, 0 }, { 255, 204, 0 }, { 255, 153, 0 }, { 255, 102, 0 },
74 { 255, 51, 0 }, { 255, 0, 0 }, { 204, 255, 102 }, { 204, 204, 102 },
75 { 204, 153, 102 }, { 204, 102, 102 }, { 204, 51, 102 }, { 204, 0, 102 },
76 { 204, 255, 51 }, { 204, 204, 51 }, { 204, 153, 51 }, { 204, 102, 51 },
77 { 204, 51, 51 }, { 204, 0, 51 }, { 204, 255, 0 }, { 204, 204, 0 },
78 { 204, 153, 0 }, { 204, 102, 0 }, { 204, 51, 0 }, { 204, 0, 0 },
79 { 153, 255, 102 }, { 153, 204, 102 }, { 153, 153, 102 }, { 153, 102, 102 },
80 { 153, 51, 102 }, { 153, 0, 102 }, { 153, 255, 51 }, { 153, 204, 51 },
81 { 153, 153, 51 }, { 153, 102, 51 }, { 153, 51, 51 }, { 153, 0, 51 },
82 { 153, 255, 0 }, { 153, 204, 0 }, { 153, 153, 0 }, { 153, 102, 0 },
83 { 153, 51, 0 }, { 153, 0, 0 }, { 102, 255, 102 }, { 102, 204, 102 },
84 { 102, 153, 102 }, { 102, 102, 102 }, { 102, 51, 102 }, { 102, 0, 102 },
85 { 102, 255, 51 }, { 102, 204, 51 }, { 102, 153, 51 }, { 102, 102, 51 },
86 { 102, 51, 51 }, { 102, 0, 51 }, { 102, 255, 0 }, { 102, 204, 0 },
87 { 102, 153, 0 }, { 102, 102, 0 }, { 102, 51, 0 }, { 102, 0, 0 },
88 { 51, 255, 102 }, { 51, 204, 102 }, { 51, 153, 102 }, { 51, 102, 102 },
89 { 51, 51, 102 }, { 51, 0, 102 }, { 51, 255, 51 }, { 51, 204, 51 },
90 { 51, 153, 51 }, { 51, 102, 51 }, { 51, 51, 51 }, { 51, 0, 51 },
91 { 51, 255, 0 }, { 51, 204, 0 }, { 51, 153, 0 }, { 51, 102, 0 },
92 { 51, 51, 0 }, { 51, 0, 0 }, { 0, 255, 102 }, { 0, 204, 102 },
93 { 0, 153, 102 }, { 0, 102, 102 }, { 0, 51, 102 }, { 0, 0, 102 },
94 { 0, 255, 51 }, { 0, 204, 51 }, { 0, 153, 51 }, { 0, 102, 51 },
95 { 0, 51, 51 }, { 0, 0, 51 }, { 0, 255, 0 }, { 0, 204, 0 },
96 { 0, 153, 0 }, { 0, 102, 0 }, { 0, 51, 0 }, { 17, 17, 17 },
97 { 34, 34, 34 }, { 68, 68, 68 }, { 85, 85, 85 }, { 119, 119, 119 },
98 { 136, 136, 136 }, { 170, 170, 170 }, { 187, 187, 187 }, { 221, 221, 221 },
99 { 238, 238, 238 }, { 192, 192, 192 }, { 128, 0, 0 }, { 128, 0, 128 },
100 { 0, 128, 0 }, { 0, 128, 128 }, { 0, 0, 0 }, { 0, 0, 0 },
101 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
102 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
103 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
104 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
105 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
106 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }};
107
108static ColorMapEntry Palm1BitColormap[] = {{ 255, 255, 255 }, { 0, 0, 0 }};
109
110static ColorMapEntry Palm2BitColormap[] = {
111 { 255, 255, 255 }, { 192, 192, 192 }, { 128, 128, 128 }, { 0, 0, 0 }};
112
113static ColorMapEntry Palm4BitColormap[] = {
114 { 255, 255, 255 }, { 238, 238, 238 }, { 221, 221, 221 }, { 204, 204, 204 },
115 { 187, 187, 187 }, { 170, 170, 170 }, { 153, 153, 153 }, { 136, 136, 136 },
116 { 119, 119, 119 }, { 102, 102, 102 }, { 85, 85, 85 }, { 68, 68, 68 },
117 { 51, 51, 51 }, { 34, 34, 34 }, { 17, 17, 17 }, { 0, 0, 0 }};
118
119QImage* Palm2QImage
120 (unsigned char *image_bytes_in, int byte_count_in)
121{
122 unsigned int width, height, bytes_per_row, flags, next_depth_offset;
123 unsigned int bits_per_pixel, version, transparent_index, compression_type, i, j, inval, inbit, mask, incount;
124 unsigned int palm_red_bits, palm_green_bits, palm_blue_bits;
125 unsigned char *palm_ptr, *x_ptr, *imagedata, *inbyte, *rowbuf, *lastrow,
126 *imagedatastart, *palmimage;
127 ColorMapEntry *colormap;
128
129 palmimage = image_bytes_in;
130 width = READ_BIGENDIAN_SHORT(palmimage + 0);
131 height = READ_BIGENDIAN_SHORT(palmimage + 2);
132 bytes_per_row = READ_BIGENDIAN_SHORT(palmimage + 4);
133 flags = READ_BIGENDIAN_SHORT(palmimage + 6);
134 bits_per_pixel = palmimage[8];
135 version = palmimage[9];
136 next_depth_offset = READ_BIGENDIAN_SHORT(palmimage + 10);
137 transparent_index = palmimage[12];
138 compression_type = palmimage[13];
139 /* bytes 14 and 15 are reserved by Palm and always 0 */
140
141#if 0
142 qDebug ("Palm image is %dx%d, %d bpp, version %d, flags 0x%x, compression %d",
143 width, height, bits_per_pixel, version, flags, compression_type);
144#endif
145
146 if (compression_type == PALM_COMPRESSION_PACKBITS) {
147 qDebug ("Image uses packbits compression; not yet supported");
148 return NULL;
149 } else if ((compression_type != PALM_COMPRESSION_NONE) &&
150 (compression_type != PALM_COMPRESSION_RLE) &&
151 (compression_type != PALM_COMPRESSION_SCANLINE)) {
152 qDebug ("Image uses unknown compression, code 0x%x", compression_type);
153 return NULL;
154 }
155
156 /* as of PalmOS 4.0, there are 6 different kinds of Palm pixmaps:
157
158 1, 2, or 4 bit grayscale
159 8-bit StaticColor using the Palm standard colormap
160 8-bit PseudoColor using a user-specified colormap
161 16-bit DirectColor using 5 bits for red, 6 for green, and 5 for blue
162
163 Each of these can be compressed with one of four compression schemes,
164 "RLE", "Scanline", "PackBits", or none.
165
166 We begin by constructing the colormap.
167 */
168
169 if (flags & PALM_HAS_COLORMAP_FLAG) {
170 qDebug("Palm images with custom colormaps are not currently supported.\n");
171 return NULL;
172 } else if (bits_per_pixel == 1) {
173 colormap = Palm1BitColormap;
174 imagedatastart = palmimage + 16;
175 } else if (bits_per_pixel == 2) {
176 colormap = Palm2BitColormap;
177 imagedatastart = palmimage + 16;
178 } else if (bits_per_pixel == 4) {
179 colormap = Palm4BitColormap;
180 imagedatastart = palmimage + 16;
181 } else if (bits_per_pixel == 8) {
182 colormap = Palm8BitColormap;
183 imagedatastart = palmimage + 16;
184 } else if (bits_per_pixel == 16 && (flags & PALM_DIRECT_COLOR_FLAG)) {
185 colormap = NULL;
186 palm_red_bits = palmimage[16];
187 palm_green_bits = palmimage[17];
188 palm_blue_bits = palmimage[18];
189 if (palm_blue_bits > 8 || palm_green_bits > 8 || palm_red_bits > 8) {
190 qDebug("Can't handle this format DirectColor image -- too wide in some color (%d:%d:%d)\n",
191 palm_red_bits, palm_green_bits, palm_blue_bits);
192 return NULL;
193 }
194 if (bits_per_pixel > (8 * sizeof(unsigned long))) {
195 qDebug ("Can't handle this format DirectColor image -- too many bits per pixel (%d)\n",
196 bits_per_pixel);
197 return NULL;
198 }
199 imagedatastart = palmimage + 24;
200 } else {
201 qDebug("Unknown bits-per-pixel of %d encountered.\n", bits_per_pixel);
202 return NULL;
203 }
204
205 QImage* qimage = new QImage(width, height, 16);
206
207 /* row by row, uncompress the Palm image and copy it to the JPEG buffer */
208 rowbuf = new unsigned char[bytes_per_row * width];
209 lastrow = new unsigned char[bytes_per_row * width];
210
211 for (i=0, palm_ptr = imagedatastart , x_ptr = imagedata; i < height; ++i) {
212
213 /* first, uncompress the Palm image */
214 if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) {
215 for (j = 0; j < bytes_per_row; ) {
216 incount = *palm_ptr++;
217 inval = *palm_ptr++;
218 memset(rowbuf + j, inval, incount);
219 j += incount;
220 }
221 } else if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_SCANLINE)) {
222 for (j = 0; j < bytes_per_row; j += 8) {
223 incount = *palm_ptr++;
224 inval = ((bytes_per_row - j) < 8) ? (bytes_per_row - j) : 8;
225 for (inbit = 0; inbit < inval; inbit += 1) {
226 if (incount & (1 << (7 - inbit)))
227 rowbuf[j + inbit] = *palm_ptr++;
228 else
229 rowbuf[j + inbit] = lastrow[j + inbit];
230 }
231 }
232 memcpy (lastrow, rowbuf, bytes_per_row);
233 } else if (((flags & PALM_IS_COMPRESSED_FLAG) &&
234 (compression_type == PALM_COMPRESSION_NONE)) ||
235 (flags && PALM_IS_COMPRESSED_FLAG) == 0) {
236 memcpy (rowbuf, palm_ptr, bytes_per_row);
237 palm_ptr += bytes_per_row;
238 }
239
240 /* next, write it to the GDK bitmap */
241 if (colormap) {
242 mask = (1 << bits_per_pixel) - 1;
243 for (inbit = 8 - bits_per_pixel, inbyte = rowbuf, j = 0; j < width; ++j) {
244 inval = ((*inbyte) & (mask << inbit)) >> inbit;
245 /* correct for oddity of the 8-bit color Palm pixmap... */
246 if ((bits_per_pixel == 8) && (inval == 0xFF)) inval = 231;
247 /* now lookup the correct color and set the pixel in the GTK bitmap */
248 QRgb colour = qRgb(colormap[inval].red, colormap[inval].green, colormap[inval].blue);
249 qimage->setPixel(j, i, colour);
250 if (!inbit) {
251 ++inbyte;
252 inbit = 8 - bits_per_pixel;
253 } else {
254 inbit -= bits_per_pixel;
255 }
256 }
257 } else if (!colormap &&
258 bits_per_pixel == 16) {
259 for (inbyte = rowbuf, j = 0; j < width; ++j) {
260 inval = (inbyte[0] << 8) | inbyte[1];
261#if 0
262 qDebug ("pixel is %d,%d (%02x:%02x:%02x)",
263 j, i,
264 (inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1),
265 (inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1),
266 (inval >> 0) & ((1 << palm_blue_bits) - 1));
267#endif
268 QRgb colour = qRgb(
269 (inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1),
270 (inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1),
271 (inval >> 0) & ((1 << palm_blue_bits) - 1));
272 qimage->setPixel(j, i, colour);
273 inbyte += 2;
274 }
275 }
276 }
277
278 delete [] rowbuf;
279 delete [] lastrow;
280
281 return qimage;
282}
283
284QPixmap* hRule(int w, int h, unsigned char r, unsigned char g, unsigned char b)
285{
286// qDebug("hrule [%d, %d]", w, h);
287 QPixmap* qimage = new QPixmap(w, h);
288 qimage->fill(QColor(r,g,b));
289 return qimage;
290}
diff --git a/noncore/apps/opie-reader/Palm2QImage.h b/noncore/apps/opie-reader/Palm2QImage.h
new file mode 100644
index 0000000..3ac2d19
--- a/dev/null
+++ b/noncore/apps/opie-reader/Palm2QImage.h
@@ -0,0 +1,7 @@
1#include <qimage.h>
2#include <qpixmap.h>
3
4QImage* Palm2QImage
5(unsigned char *image_bytes_in, int byte_count_in);
6
7QPixmap* hRule(int w, int h, unsigned char r=0, unsigned char g=0, unsigned char b=0);
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp
index 7cf08e5..3995ee7 100644
--- a/noncore/apps/opie-reader/QTReader.cpp
+++ b/noncore/apps/opie-reader/QTReader.cpp
@@ -1,1109 +1,1327 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
5** 5**
6** This file is part of an example program for Qt. This example 6** This file is part of an example program for Qt. This example
7** program may be used, distributed and modified without limitation. 7** program may be used, distributed and modified without limitation.
8** 8**
9*****************************************************************************/ 9*****************************************************************************/
10 10
11#include <qpainter.h> 11#include <qpainter.h>
12#include "config.h" 12#include "config.h"
13#include "QTReader.h" 13#include "QTReader.h"
14#include "QTReaderApp.h" 14#include "QTReaderApp.h"
15#include "CDrawBuffer.h" 15#include "CDrawBuffer.h"
16#include <qpe/qpeapplication.h> 16#include <qpe/qpeapplication.h>
17#include <math.h> 17#include <math.h>
18#include <ctype.h> 18#include <ctype.h>
19#include <stdio.h> //for sprintf 19#include <stdio.h> //for sprintf
20#include <qpe/config.h> 20#include <qpe/config.h>
21#include <qpe/applnk.h> 21#include <qpe/applnk.h>
22#include <qfontdatabase.h> 22#include <qfontdatabase.h>
23#include <qpe/global.h> 23#include <qpe/global.h>
24#include <qpe/qcopenvelope_qws.h> 24#include <qpe/qcopenvelope_qws.h>
25#include "StateData.h"
25 26
26#ifdef _UNICODE 27#ifdef _UNICODE
27const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 }; 28const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 };
28#else 29#else
29const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 }; 30const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 };
30#endif 31#endif
31//const int QTReader::fontsizes[] = { 8, 10, 12, 14, 18, 24, 30, 40, 50, 60, 70, 80, 90, 100, 0 }; 32//const int QTReader::fontsizes[] = { 8, 10, 12, 14, 18, 24, 30, 40, 50, 60, 70, 80, 90, 100, 0 };
32 33
33//const tchar *QTReader::fonts[] = { "unifont", "fixed", "micro", "smoothtimes", "Courier", "Times", 0 }; 34//const tchar *QTReader::fonts[] = { "unifont", "fixed", "micro", "smoothtimes", "Courier", "Times", 0 };
34//const int QTReader::fontsizes[] = {10,16,17,22,0}; 35//const int QTReader::fontsizes[] = {10,16,17,22,0};
35//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 }; 36//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 };
36//const int QTReader::fontsizes[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0}; 37//const int QTReader::fontsizes[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0};
37 38
38QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : 39QTReader::QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0) :
39 QWidget(parent, name, f), 40 QWidget(parent, name, f),
40 m_delay(100), 41 m_delay(100),
41 m_scrolldy1(0), 42 m_scrolldy1(0),
42 m_scrolldy2(0), 43 m_scrolldy2(0),
43 m_autoScroll(false), 44 m_autoScroll(false),
44 //textarray(NULL), 45 //textarray(NULL),
45 //locnarray(NULL), 46 //locnarray(NULL),
46 numlines(0), 47 numlines(0),
47 m_fontname("unifont"), 48 m_fontname("unifont"),
48 m_fm(NULL), 49 m_fm(NULL),
49 mouseUpOn(true), 50 mouseUpOn(true),
50 m_twotouch(true), 51 m_twotouch(true),
51 m_touchone(true) 52 m_touchone(true),
53 bDoUpdates(false),
54 m_navkeys(true)
52{ 55{
53 m_overlap = 1; 56 m_overlap = 1;
54// init(); 57// init();
55} 58}
56/* 59/*
57QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) : 60QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) :
58 QWidget(parent, name, f), 61 QWidget(parent, name, f),
59 m_textfont(0), 62 m_textfont(0),
60 m_textsize(1), 63 m_textsize(1),
61 textarray(NULL), 64 textarray(NULL),
62 numlines(0), 65 numlines(0),
63 bstripcr(true), 66 bstripcr(true),
64 bunindent(false), 67 bunindent(false),
65 brepara(false), 68 brepara(false),
66 bdblspce(false), 69 bdblspce(false),
67 btight(false), 70 btight(false),
68 bindenter(0), 71 bindenter(0),
69 m_fm(NULL) 72 m_fm(NULL)
70{ 73{
71 init(); 74 init();
72 // qDebug("Load_file(1)"); 75 // qDebug("Load_file(1)");
73 load_file((const tchar*)filename); 76 load_file((const tchar*)filename);
74} 77}
75*/ 78*/
76 79
77long QTReader::real_delay() 80long QTReader::real_delay()
78{ 81{
79 return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing ); 82 return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing );
80} 83}
81 84
82void QTReader::mousePressEvent( QMouseEvent* _e ) 85void QTReader::mousePressEvent( QMouseEvent* _e )
83{ 86{
87 buffdoc.unsuspend();
84 if (_e->button() == RightButton) 88 if (_e->button() == RightButton)
85 { 89 {
86 mouseUpOn = false; 90 mouseUpOn = false;
87 if (_e->y() > height()/2) 91 if (buffdoc.hasnavigation())
88 { 92 {
89 goDown(); 93 if (_e->y() > (2*height())/3)
94 {
95 goDown();
96 }
97 else if (_e->y() < height()/3)
98 {
99 goUp();
100 }
101 else
102 {
103 if (_e->x() < width()/3)
104 {
105 size_t target = pagelocate();
106 if (buffdoc.back(target))
107 {
108 locate(target);
109 }
110 }
111 else if (_e->x() > (2*width())/3)
112 {
113 size_t target = pagelocate();
114 if (buffdoc.forward(target))
115 {
116 locate(target);
117 }
118 }
119 else
120 {
121 buffdoc.saveposn(pagelocate());
122 locate(buffdoc.getHome());
123 }
124 }
90 } 125 }
91 else 126 else
92 { 127 {
93 goUp(); 128 if (_e->y() > height()/2)
129 {
130 goDown();
131 }
132 else
133 {
134 goUp();
135 }
94 } 136 }
95 } 137 }
96} 138}
97 139
98bool QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt) 140linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt)
99{ 141{
100 int lineno = 0; 142 int lineno = 0;
101 int ht = textarray[0]->lineSpacing(); 143 int ht = textarray[0]->lineSpacing();
102 while ((ht < y) && (lineno < numlines)) 144 while ((ht < y) && (lineno < numlines))
103 { 145 {
104 ht += textarray[++lineno]->lineSpacing(); 146 ht += textarray[++lineno]->lineSpacing();
105 } 147 }
106 start = locnarray[lineno]; 148 start = locnarray[lineno];
107 if (m_bMonoSpaced) 149 if (m_bMonoSpaced)
108 { 150 {
109 offset = x/m_charWidth; 151 offset = x/m_charWidth;
110 } 152 }
111 else 153 else
112 { 154 {
113 int i; 155 int i;
114 CDrawBuffer* t = textarray[lineno]; 156 CDrawBuffer* t = textarray[lineno];
115 for (i = t->length(); t->width(i) > x; i--); 157 x = x - t->offset(width());
158 for (i = t->length(); i >= 0 && t->width(i) > x; i--);
116 offset = i; 159 offset = i;
117 } 160 }
118 return textarray[lineno]->isLink(offset, tgt); 161 return textarray[lineno]->getLinkType(offset, tgt);
119} 162}
120 163
121void QTReader::setTwoTouch(bool _b) 164void QTReader::setTwoTouch(bool _b)
122{ 165{
123 setBackgroundColor( white ); 166 setBackgroundColor( white );
124 m_twotouch = m_touchone = _b; 167 m_twotouch = m_touchone = _b;
125} 168}
126 169
170void QTReader::setContinuous(bool _b)
171{
172 buffdoc.unsuspend();
173 buffdoc.setContinuous(m_continuousDocument = _b);
174}
175
127void QTReader::mouseReleaseEvent( QMouseEvent* _e ) 176void QTReader::mouseReleaseEvent( QMouseEvent* _e )
128{ 177{
178 buffdoc.unsuspend();
129 if (_e->button() == LeftButton) 179 if (_e->button() == LeftButton)
130 { 180 {
131 if (mouseUpOn) 181 if (mouseUpOn)
132 { 182 {
133 if (textarray[0] != NULL) 183 if (textarray[0] != NULL)
134 { 184 {
135 QString wrd, line; 185 QString wrd, line;
136 // int lineno = _e->y()/m_linespacing; 186 // int lineno = _e->y()/m_linespacing;
137 int lineno = 0; 187 int lineno = 0;
138 int ht = textarray[0]->lineSpacing(); 188 int ht = textarray[0]->lineSpacing();
139 while ((ht < _e->y()) && (lineno < numlines)) 189 while ((ht < _e->y()) && (lineno < numlines))
140 { 190 {
141 ht += textarray[++lineno]->lineSpacing(); 191 ht += textarray[++lineno]->lineSpacing();
142 } 192 }
143 size_t startpos, startoffset, tgt; 193 size_t startpos, startoffset, tgt;
144 if (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt)) 194 switch (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt))
145 { 195 {
146 if (buffdoc.hyperlink(tgt)) 196 case eLink:
147 { 197 {
148 fillbuffer(); 198 size_t saveposn = pagelocate();
149 update(); 199 if (buffdoc.hyperlink(tgt))
200 {
201 buffdoc.saveposn(saveposn);
202 fillbuffer();
203 update();
204 }
205 else
206 {
207 locate(pagelocate());
208 }
209 return;
150 } 210 }
151 else 211 case ePicture:
152 { 212 {
153 locate(pagelocate()); 213 qDebug("Picture:%x", tgt);
214 QPixmap* pm = buffdoc.getPicture(tgt);
215 if (pm != NULL)
216 {
217 emit OnShowPicture(*pm);
218 delete pm;
219 }
220 else
221 {
222 locate(pagelocate());
223 }
224 return;
154 } 225 }
155 return; 226 case eNone:
227 break;
228 default:
229 qDebug("Unknown linktype");
230 return;
156 } 231 }
157 if (m_twotouch) 232 if (m_twotouch)
158 { 233 {
159 if (m_touchone) 234 if (m_touchone)
160 { 235 {
161 m_touchone = false; 236 m_touchone = false;
162 m_startpos = startpos; 237 m_startpos = startpos;
163 m_startoffset = startoffset; 238 m_startoffset = startoffset;
164 setBackgroundColor( lightGray ); 239 setBackgroundColor( lightGray );
165 } 240 }
166 else 241 else
167 { 242 {
168 m_touchone = true; 243 m_touchone = true;
169 setBackgroundColor( white ); 244 setBackgroundColor( white );
170 size_t endpos, endoffset; 245 size_t endpos, endoffset;
171 endpos = startpos; 246 endpos = startpos;
172 endoffset = startoffset; 247 endoffset = startoffset;
173 size_t currentpos = locate(); 248 size_t currentpos = locate();
174 if (endpos >= m_startpos) 249 if (endpos >= m_startpos)
175 { 250 {
176 jumpto(m_startpos); 251 jumpto(m_startpos);
177 for (int i = 0; i < m_startoffset; i++) 252 for (int i = 0; i < m_startoffset; i++)
178 { 253 {
179 getch(); 254 getch();
180 } 255 }
181 if (m_startpos == endpos) 256 if (m_startpos == endpos)
182 { 257 {
183 for (int i = m_startoffset; i <= endoffset; i++) 258 for (int i = m_startoffset; i <= endoffset; i++)
184 { 259 {
185 wrd += QChar(getch()); 260 wrd += QChar(getch());
186 } 261 }
187 } 262 }
188 else 263 else
189 { 264 {
190 while (buffdoc.explocate() <= endpos) 265 while (buffdoc.explocate() <= endpos)
191 { 266 {
192 wrd += QChar(getch()); 267 wrd += QChar(getch());
193 } 268 }
194 for (int i = 0; i < endoffset; i++) 269 for (int i = 0; i < endoffset; i++)
195 { 270 {
196 wrd += QChar(getch()); 271 wrd += QChar(getch());
197 } 272 }
198 } 273 }
199 jumpto(currentpos); 274 jumpto(currentpos);
200 } 275 }
201 } 276 }
202 } 277 }
203 else if (m_bMonoSpaced) 278 else if (m_bMonoSpaced)
204 { 279 {
205 int chno = _e->x()/m_charWidth; 280 int chno = _e->x()/m_charWidth;
206 if (chno < ustrlen(textarray[lineno]->data())) 281 if (chno < ustrlen(textarray[lineno]->data()))
207 { 282 {
208 wrd[0] = textarray[lineno]->data()[chno]; 283 wrd[0] = textarray[lineno]->data()[chno];
209 } 284 }
210 } 285 }
211 else 286 else
212 { 287 {
213 CDrawBuffer* t = textarray[lineno]; 288 CDrawBuffer* t = textarray[lineno];
214 int first = 0; 289 int first = 0;
290 int tgt = _e->x() - t->offset(width());
215 while (1) 291 while (1)
216 { 292 {
217 int i = first+1; 293 int i = first+1;
218 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; 294 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
219 if (t->width(i) > _e->x()) 295 if (t->width(i) > tgt)
220 { 296 {
221 wrd = toQString(t->data()+first, i - first); 297 wrd = toQString(t->data()+first, i - first);
222 break; 298 break;
223 } 299 }
224 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; 300 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
225 if ((*t)[i] == 0) break; 301 if ((*t)[i] == 0) break;
226 first = i; 302 first = i;
227 } 303 }
228 } 304 }
229 if (!wrd.isEmpty()) 305 if (!wrd.isEmpty())
230 { 306 {
231 emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data())); 307 emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data()));
232 } 308 }
233 } 309 }
234 } 310 }
235 else 311 else
236 { 312 {
237 mouseUpOn = true; 313 mouseUpOn = true;
238 } 314 }
239 } 315 }
240} 316}
241 317
242void QTReader::focusInEvent(QFocusEvent* e) 318void QTReader::focusInEvent(QFocusEvent* e)
243{ 319{
244 if (m_autoScroll) timer->start(real_delay(), false); 320 if (m_autoScroll) timer->start(real_delay(), false);
245 update(); 321 update();
246} 322}
247 323
248void QTReader::focusOutEvent(QFocusEvent* e) 324void QTReader::focusOutEvent(QFocusEvent* e)
249{ 325{
250 if (m_autoScroll) 326 if (m_autoScroll)
251 { 327 {
252 timer->stop(); 328 timer->stop();
253 m_scrolldy1 = m_scrolldy2 = 0; 329 m_scrolldy1 = m_scrolldy2 = 0;
254 } 330 }
255} 331}
256 332
257#include <qapplication.h> 333#include <qapplication.h>
258#include <qdrawutil.h> 334#include <qdrawutil.h>
259#include <unistd.h> 335#include <unistd.h>
260 336
261void QTReader::goDown() 337void QTReader::goDown()
262{ 338{
263 if (m_bpagemode) 339 if (m_bpagemode)
264 { 340 {
265 dopagedn(); 341 dopagedn();
266 } 342 }
267 else 343 else
268 { 344 {
269 lineDown(); 345 lineDown();
270 } 346 }
271} 347}
272 348
273void QTReader::goUp() 349void QTReader::goUp()
274{ 350{
275 if (m_bpagemode) 351 if (m_bpagemode)
276 { 352 {
277 dopageup(); 353 dopageup();
278 } 354 }
279 else 355 else
280 { 356 {
281 lineUp(); 357 lineUp();
282 } 358 }
283} 359}
284 360
361void QTReader::NavUp()
362{
363 buffdoc.unsuspend();
364 if (buffdoc.hasnavigation())
365 {
366/*
367 size_t target = pagelocate();
368 if (buffdoc.back(target))
369 {
370 locate(target);
371 }
372*/
373 locate(buffdoc.startSection());
374 }
375 else
376 {
377 goUp();
378 }
379}
380
381void QTReader::NavDown()
382{
383 buffdoc.unsuspend();
384 if (buffdoc.hasnavigation())
385 {
386/*
387 size_t target = pagelocate();
388 if (buffdoc.forward(target))
389 {
390 locate(target);
391 }
392*/
393 dopageup(buffdoc.endSection());
394 }
395 else
396 {
397 goDown();
398 }
399}
400
401void QTReader::zoomin()
402{
403 if (m_fontControl.increasesize())
404 {
405 bool sc = m_autoScroll;
406 setfont();
407 m_autoScroll = false;
408 locate(pagelocate());
409 update();
410 m_autoScroll = sc;
411 if (m_autoScroll) autoscroll();
412 }
413}
414
415void QTReader::zoomout()
416{
417 if (m_fontControl.decreasesize())
418 {
419 bool sc = m_autoScroll;
420 m_autoScroll = false;
421 setfont();
422 locate(pagelocate());
423 update();
424 m_autoScroll = sc;
425 if (m_autoScroll) autoscroll();
426 }
427}
428
285void QTReader::keyPressEvent(QKeyEvent* e) 429void QTReader::keyPressEvent(QKeyEvent* e)
286{ 430{
431 buffdoc.unsuspend();
287 switch (e->key()) 432 switch (e->key())
288 { 433 {
289 case Key_Down: 434 case Key_Down:
290 { 435 {
291 e->accept(); 436 e->accept();
292 if (m_autoScroll) 437 if (m_autoScroll)
293 { 438 {
294 if (m_delay < 59049) 439 if (m_delay < 59049)
295 { 440 {
296 m_delay = (3*m_delay)/2; 441 m_delay = (3*m_delay)/2;
297 timer->changeInterval(real_delay()); 442 timer->changeInterval(real_delay());
298 } 443 }
299 else 444 else
300 { 445 {
301 m_delay = 59049; 446 m_delay = 59049;
302 } 447 }
303 } 448 }
304 else 449 else
305 { 450 {
306 goDown(); 451 goDown();
307 } 452 }
308 } 453 }
309 break; 454 break;
310 case Key_Up: 455 case Key_Up:
311 { 456 {
312 e->accept(); 457 e->accept();
313 if (m_autoScroll) 458 if (m_autoScroll)
314 { 459 {
315 if (m_delay > 1024) 460 if (m_delay > 1024)
316 { 461 {
317 m_delay = (2*m_delay)/3; 462 m_delay = (2*m_delay)/3;
318 timer->changeInterval(real_delay()); 463 timer->changeInterval(real_delay());
319 } 464 }
320 else 465 else
321 { 466 {
322 m_delay = 1024; 467 m_delay = 1024;
323 } 468 }
324 } 469 }
325 else 470 else
326 { 471 {
327 goUp(); 472 goUp();
328 } 473 }
329 } 474 }
330 break; 475 break;
331 /* 476 /*
332 case Key_Left: 477 case Key_Left:
333 { 478 {
334 e->accept(); 479 e->accept();
335 if (m_textfont > 0) 480 if (m_textfont > 0)
336 { 481 {
337 m_textfont--; 482 m_textfont--;
338 setfont(NULL); 483 setfont(NULL);
339 locate(pagelocate()); 484 locate(pagelocate());
340 update(); 485 update();
341 } 486 }
342 } 487 }
343 break; 488 break;
344 case Key_Right: 489 case Key_Right:
345 { 490 {
346 e->accept(); 491 e->accept();
347 if (fonts[++m_textfont] == 0) 492 if (fonts[++m_textfont] == 0)
348 { 493 {
349 m_textfont--; 494 m_textfont--;
350 } 495 }
351 else 496 else
352 { 497 {
353 setfont(NULL); 498 setfont(NULL);
354 locate(pagelocate()); 499 locate(pagelocate());
355 update(); 500 update();
356 } 501 }
357 } 502 }
358 break; 503 break;
359 */ 504 */
360 case Key_Right: 505 case Key_Right:
361 { 506 {
362 e->accept(); 507 e->accept();
363 if (m_fontControl.increasesize()) 508 if (m_navkeys && buffdoc.hasnavigation())
364 { 509 {
365 bool sc = m_autoScroll; 510 size_t target = pagelocate();
366 setfont(); 511 if (buffdoc.forward(target))
367 m_autoScroll = false; 512 {
368 locate(pagelocate()); 513 locate(target);
369 update(); 514 }
370 m_autoScroll = sc; 515 }
371 if (m_autoScroll) autoscroll(); 516 else zoomin();
372 }
373 } 517 }
374 break; 518 break;
375 case Key_Left: 519 case Key_Left:
376 { 520 {
377 e->accept(); 521 e->accept();
378 if (m_fontControl.decreasesize()) 522 if (m_navkeys && buffdoc.hasnavigation())
379 { 523 {
380 bool sc = m_autoScroll; 524 size_t target = pagelocate();
381 m_autoScroll = false; 525 if (buffdoc.back(target))
382 setfont(); 526 {
383 locate(pagelocate()); 527 locate(target);
384 update(); 528 }
385 m_autoScroll = sc; 529 }
386 if (m_autoScroll) autoscroll(); 530 else zoomout();
387 }
388 } 531 }
389 break; 532 break;
390 case Key_Space: 533 case Key_Space:
391 case Key_Return: 534 case Key_Return:
392 { 535 {
393 e->accept(); 536 e->accept();
394 emit OnActionPressed(); 537 emit OnActionPressed();
395 } 538 }
396 break; 539 break;
397 default: 540 default:
398 e->ignore(); 541 e->ignore();
399 } 542 }
400} 543}
401 544
402void QTReader::setautoscroll(bool _sc) 545void QTReader::setautoscroll(bool _sc)
403{ 546{
404 if (_sc == m_autoScroll) return; 547 if (_sc == m_autoScroll) return;
405 if (m_autoScroll) 548 if (m_autoScroll)
406 { 549 {
407 m_autoScroll = false; 550 m_autoScroll = false;
408 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 551 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
409 } 552 }
410 else 553 else
411 { 554 {
555 CDrawBuffer* reusebuffer = textarray[numlines];
556 if (reusebuffer == NULL || reusebuffer->eof()) return;
412 m_autoScroll = true; 557 m_autoScroll = true;
413 autoscroll(); 558 autoscroll();
414 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed 559 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed
415 } 560 }
416} 561}
417 562
418bool QTReader::getline(CDrawBuffer *buff) 563bool QTReader::getline(CDrawBuffer *buff)
419{ 564{
565 buffdoc.unsuspend();
420 if (m_bMonoSpaced) 566 if (m_bMonoSpaced)
421 { 567 {
422 return buffdoc.getline(buff ,width(), m_charWidth); 568 return buffdoc.getline(buff ,width(), m_charWidth);
423 } 569 }
424 else 570 else
425 { 571 {
426 return buffdoc.getline(buff, width()); 572 return buffdoc.getline(buff, width());
427 } 573 }
428} 574}
429 575
430void QTReader::doscroll() 576void QTReader::doscroll()
431{ 577{
432 if (!m_autoScroll) 578 if (!m_autoScroll)
433 { 579 {
434 timer->stop(); 580 timer->stop();
435 return; 581 return;
436 } 582 }
437// timer->changeInterval(real_delay()); 583// timer->changeInterval(real_delay());
438 QPainter p( this ); 584 QPainter p( this );
439 QBrush b( white); 585 QBrush b( white);
440 bitBlt(this,0,0,this,0,1,width(),-1); 586 bitBlt(this,0,0,this,0,1,width(),-1);
441 qDrawPlainRect(&p,0,height() - 2,width(),2,white,1,&b); 587 qDrawPlainRect(&p,0,height() - 2,width(),2,white,1,&b);
442 588
443 if (++m_scrolldy1 == textarray[0]->lineSpacing()) 589 if (++m_scrolldy1 == textarray[0]->lineSpacing())
444 { 590 {
445 CDrawBuffer* buff = textarray[0]; 591 CDrawBuffer* buff = textarray[0];
446 for (int i = 1; i <= numlines; i++) 592 for (int i = 1; i <= numlines; i++)
447 { 593 {
448 textarray[i-1] = textarray[i]; 594 textarray[i-1] = textarray[i];
449 locnarray[i-1] = locnarray[i]; 595 locnarray[i-1] = locnarray[i];
450 } 596 }
451 textarray[numlines] = buff; 597 textarray[numlines] = buff;
452 --numlines; 598 --numlines;
453 m_scrolldy1 = 0; 599 m_scrolldy1 = 0;
454 } 600 }
455 if (++m_scrolldy2 == textarray[numlines]->lineSpacing()) 601 if (++m_scrolldy2 == textarray[numlines]->lineSpacing())
456 { 602 {
457 m_scrolldy2 = 0; 603 m_scrolldy2 = 0;
458 numlines++; 604 numlines++;
459 605
460 if (textarray[numlines] == NULL) 606 if (textarray[numlines] == NULL)
461 { 607 {
462 textarray[numlines] = new CDrawBuffer; 608 textarray[numlines] = new CDrawBuffer(&m_fontControl);
463 } 609 }
464 locnarray[numlines] = locate(); 610 locnarray[numlines] = locate();
465 int ch = getline(textarray[numlines]); 611 int ch = getline(textarray[numlines]);
466 textarray[numlines-1]->render(&p, height() - textarray[numlines]->descent() - 2, m_bMonoSpaced, m_charWidth, width()); 612 textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2, m_bMonoSpaced, m_charWidth, width());
467 mylastpos = locate(); 613 mylastpos = locate();
468 if (!ch) 614 if (!ch)
469 { 615 {
470 m_autoScroll = false; 616 m_autoScroll = false;
471 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); 617 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
472 emit OnRedraw();
473 } 618 }
474 emit OnRedraw(); 619 emit OnRedraw();
475 } 620 }
476} 621}
477 622
478void QTReader::autoscroll() 623void QTReader::autoscroll()
479{ 624{
480 timer->start(real_delay(), false); 625 timer->start(real_delay(), false);
481} 626}
482 627
483void QTReader::setfont() 628void QTReader::setfont()
484{ 629{
485// m_fontControl.Change 630// m_fontControl.Change
486 m_charWidth = (m_charpc*m_fontControl.currentsize())/100; 631 m_charWidth = (m_charpc*m_fontControl.currentsize())/100;
487 if (m_charWidth <= 0) m_charWidth = 1; 632 if (m_charWidth <= 0) m_charWidth = 1;
488 m_ascent = m_fontControl.ascent(); 633 m_ascent = m_fontControl.ascent();
489 m_descent = m_fontControl.descent(); 634 m_descent = m_fontControl.descent();
490 m_linespacing = m_fontControl.lineSpacing(); 635 m_linespacing = m_fontControl.lineSpacing();
491} 636}
492 637
493void QTReader::drawFonts( QPainter *p ) 638void QTReader::drawFonts( QPainter *p )
494{ 639{
495 setfont(); 640 if (bDoUpdates)
496 if (m_lastwidth != width() || m_lastheight != height()) 641 {
497 { 642 qDebug("How refreshing...");
498 m_lastwidth = width(); 643 if (buffdoc.empty()) return;
499 m_lastheight = height(); 644 setfont();
500 locate(pagelocate()); 645 if (m_lastwidth != width())
501 } 646 {
502 else 647 qDebug("Not Optimised %d", m_lastwidth);
503 { 648 m_lastwidth = width();
504 649 m_lastheight = height();
505/* 650 locate(pagelocate());
506 int sl = screenlines(); 651 qDebug("Not Optimised %d", m_lastwidth);
507 if (sl < numlines) 652 }
508 { 653 else
509 //qDebug("df:<%u,%u>",sl,numlines); 654 {
510 655 if (m_lastheight > height())
511 size_t newpos = locnarray[sl]; 656 {
512 CDrawBuffer** nta = new CDrawBuffer*[sl]; 657 qDebug("Optimised < %d", numlines);
513 size_t* nla = new size_t[sl]; 658 int ypos = 0;
514 for (int i = 0; i < sl; i++) 659 for (int i = 0; i < numlines; i++)
515 { 660 {
516 nta[i] = textarray[i]; 661 if ((ypos += textarray[i]->lineSpacing()) > height())
517 nla[i] = locnarray[i]; 662 {
518 } 663 numlines = i;
519 for (int i = sl; i < numlines; i++) delete textarray[i]; 664 jumpto(locnarray[i+1]);
520 delete [] locnarray; 665 break;
521 delete [] textarray; 666 }
522 textarray = nta; 667 }
523 locnarray = nla; 668 qDebug("Optimised < %d", numlines);
524 numlines = sl; 669 m_lastheight = height();
525 jumpto(mylastpos = newpos); 670 }
526 } 671 else if (m_lastheight < height())
527 if (sl > numlines) 672 {
528 { 673 qDebug("Optimised > %d", numlines);
529 //qDebug("df:<%u,%u>",sl,numlines); 674 int ypos = 0;
530 CDrawBuffer** nta = new CDrawBuffer*[sl]; 675 for (int i = 0; i <= numlines; i++)
531 size_t* nla = new size_t[sl]; 676 {
532 for (int i = 0; i < numlines; i++) 677 ypos += textarray[i]->lineSpacing();
533 { 678 }
534 nta[i] = textarray[i]; 679 fillbuffer(numlines+1, ypos);
535 nla[i] = locnarray[i]; 680 qDebug("Optimised > %d", numlines);
536 } 681 m_lastheight = height();
537 if (locate() != mylastpos) jumpto(mylastpos); 682 }
538 for (int i = numlines; i < sl; i++) 683 if (numlines > 0)
539 { 684 {
540 nta[i] = new CDrawBuffer(&m_fontControl); 685 int ypos = textarray[0]->ascent();
541 nla[i] = locate(); 686 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
542 getline(nta[i]); 687 for (int i = 1; i < numlines; i++)
543 } 688 {
544 mylastpos = locate(); 689 // ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2;
545 delete [] locnarray; 690 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
546 delete [] textarray; 691 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
547 textarray = nta; 692 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
548 locnarray = nla; 693 }
549 numlines = sl;
550 }
551*/
552 if (numlines > 0)
553 {
554 int ypos = textarray[0]->ascent();
555 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
556 for (int i = 1; i < numlines; i++)
557 {
558 ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2;
559 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
560
561 }
562// mylastpos = locate(); 694// mylastpos = locate();
563 } 695 }
564 } 696 }
565 m_scrolldy1 = m_scrolldy2 = 0; 697 m_scrolldy1 = m_scrolldy2 = 0;
566 emit OnRedraw(); 698 emit OnRedraw();
699 }
700 else
701 {
702 qDebug("Not so refreshing...");
703 }
567} 704}
568 705
569QString QTReader::firstword() 706QString QTReader::firstword()
570{ 707{
571 if (m_bMonoSpaced) 708 if (m_bMonoSpaced)
572 { 709 {
573 return toQString(textarray[0]->data()); 710 return toQString(textarray[0]->data());
574 } 711 }
575 else 712 else
576 { 713 {
577 int start, end, len, j; 714 int start, end, len, j;
578 for (j = 0; j < numlines; j++) 715 for (j = 0; j < numlines; j++)
579 { 716 {
580 len = textarray[j]->length(); 717 len = textarray[j]->length();
581 for (start = 0; start < len && !isalpha((*textarray[j])[start]); start++); 718 for (start = 0; start < len && !isalpha((*textarray[j])[start]); start++);
582 if (start < len) break; 719 if (start < len) break;
583 } 720 }
584 if (j < numlines) 721 if (j < numlines)
585 { 722 {
586 QString ret = ""; 723 QString ret = "";
587 for (end = start; end < len && isalpha((*textarray[j])[end]); end++) 724 for (end = start; end < len && isalpha((*textarray[j])[end]); end++)
588 ret += (*textarray[j])[end]; 725 ret += (*textarray[j])[end];
589 if (ret.isEmpty()) ret = "Current position"; 726 if (ret.isEmpty()) ret = "Current position";
590 return ret; 727 return ret;
591 } 728 }
592 else 729 else
593 return "Current position"; 730 return "Current position";
594 } 731 }
595} 732}
596 733
597// 734//
598// Construct the QTReader with buttons. 735// Construct the QTReader with buttons.
599// 736//
600 737
601bool QTReader::ChangeFont(int tgt) 738bool QTReader::ChangeFont(int tgt)
602{ 739{
603 return m_fontControl.ChangeFont(m_fontname, tgt); 740 return m_fontControl.ChangeFont(m_fontname, tgt);
604} 741}
605 742
606void QTReader::init() 743void QTReader::init()
607{ 744{
608 // setCaption( "Qt Draw Demo Application" ); 745 // setCaption( "Qt Draw Demo Application" );
609 746
747 buffdoc.unsuspend();
610 setBackgroundColor( white ); 748 setBackgroundColor( white );
611// QPainter p(this); 749// QPainter p(this);
612// p.setBackgroundMode( Qt::OpaqueMode ); 750// p.setBackgroundMode( Qt::OpaqueMode );
613 buffdoc.setfilter(getfilter()); 751 buffdoc.setfilter(getfilter());
614 ChangeFont(m_textsize); 752 ChangeFont(m_textsize);
615 setFocusPolicy(QWidget::StrongFocus); 753 setFocusPolicy(QWidget::StrongFocus);
616 // resize( 240, 320 ); 754 // resize( 240, 320 );
617 //setFocus(); 755 //setFocus();
618 timer = new QTimer(this); 756 timer = new QTimer(this);
619 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll())); 757 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll()));
620// QMessageBox::information(this, "init", m_lastfile, 1); 758// QMessageBox::information(this, "init", m_lastfile, 1);
621 m_lastwidth = width();
622 m_lastheight = height();
623 setfont(); 759 setfont();
760/*
624 if (!m_lastfile.isEmpty()) 761 if (!m_lastfile.isEmpty())
625 { 762 {
626 m_string = DocLnk(m_lastfile).name(); 763 m_string = DocLnk(m_lastfile).name();
627 load_file(m_lastfile); 764 load_file(m_lastfile);
628 } 765 }
766*/
629} 767}
630 768
631// 769//
632// Clean up 770// Clean up
633// 771//
634QTReader::~QTReader() 772QTReader::~QTReader()
635{ 773{
636} 774}
637 775
638// 776//
639// Calls the drawing function as specified by the radio buttons. 777// Calls the drawing function as specified by the radio buttons.
640// 778//
641 779
642void QTReader::drawIt( QPainter *p ) 780void QTReader::drawIt( QPainter *p )
643{ 781{
644 drawFonts(p); 782 drawFonts(p);
645} 783}
646 784
647// 785//
648// Called when the print button is clicked. 786// Called when the print button is clicked.
649// 787//
650/* 788/*
651void QTReader::printIt() 789void QTReader::printIt()
652{ 790{
653#ifndef QT_NO_PRINTER 791#ifndef QT_NO_PRINTER
654 if ( printer->setup( this ) ) { 792 if ( printer->setup( this ) ) {
655 QPainter paint; 793 QPainter paint;
656 if ( !paint.begin( printer ) ) 794 if ( !paint.begin( printer ) )
657 return; 795 return;
658 drawIt( &paint ); 796 drawIt( &paint );
659 } 797 }
660#endif 798#endif
661} 799}
662*/ 800*/
663// 801//
664// Called when the widget needs to be updated. 802// Called when the widget needs to be updated.
665// 803//
666 804
667void QTReader::paintEvent( QPaintEvent * ) 805void QTReader::paintEvent( QPaintEvent * )
668{ 806{
669 QPainter paint( this ); 807 QPainter paint( this );
670 drawIt( &paint ); 808 drawIt( &paint );
671} 809}
672 810
673// 811//
674// Called when the widget has been resized. 812// Called when the widget has been resized.
675// Moves the button group to the upper right corner 813// Moves the button group to the upper right corner
676// of the widget. 814// of the widget.
677 815
678/* 816/*
679void QTReader::resizeEvent( QResizeEvent * ) 817void QTReader::resizeEvent( QResizeEvent * )
680{ 818{
681 // qDebug("resize:(%u,%u)", width(), height()); 819 // qDebug("resize:(%u,%u)", width(), height());
682 // bgroup->move( width()-bgroup->width(), 0 ); 820 // bgroup->move( width()-bgroup->width(), 0 );
683} 821}
684*/ 822*/
685 823
686// 824//
687// Create and display our widget. 825// Create and display our widget.
688// 826//
689/* 827/*
690int main( int argc, tchar **argv ) 828int main( int argc, tchar **argv )
691{ 829{
692 QApplication app( argc, argv ); 830 QApplication app( argc, argv );
693 QTReader draw; 831 QTReader draw;
694 app.setMainWidget( &draw ); 832 app.setMainWidget( &draw );
695 draw.setCaption("Qt Example - Drawdemo"); 833 draw.setCaption("Qt Example - Drawdemo");
696 draw.show(); 834 draw.show();
697 return app.exec(); 835 return app.exec();
698} 836}
699*/ 837*/
700 838
701 839
702bool QTReader::locate(unsigned long n) { 840bool QTReader::locate(unsigned long n) {
703 //printf("Locate\n"); 841 //printf("Locate\n");
842 buffdoc.unsuspend();
704 buffdoc.locate(n); 843 buffdoc.locate(n);
705 // qDebug("&buffdoc.located"); 844 // qDebug("&buffdoc.located");
706 fillbuffer(); 845 fillbuffer();
707 // qDebug("&Buffer filled"); 846 // qDebug("&Buffer filled");
708 update(); 847 update();
709 // qDebug("&Located"); 848 // qDebug("&Located");
710 return true; 849 return true;
711} 850}
712 851
713unsigned int QTReader::screenlines() 852unsigned int QTReader::screenlines()
714{ 853{
715 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent; 854 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent;
716 // return (height()-m_descent)/(m_linespacing); 855 // return (height()-m_descent)/(m_linespacing);
717 return (height()-2)/(m_linespacing); 856 return (height()-2)/(m_linespacing);
718}; 857};
719 858
720bool QTReader::fillbuffer(int reuse, int ht) 859bool QTReader::fillbuffer(int reuse, int ht)
721{ 860{
861 buffdoc.unsuspend();
722 if (buffdoc.empty()) return false; 862 if (buffdoc.empty()) return false;
723 m_scrolldy1 = m_scrolldy2 = 0; 863 m_scrolldy1 = m_scrolldy2 = 0;
724 int ch; 864 int ch;
725 bool ret = false; 865 bool ret = false;
726 unsigned int oldpagepos = locnarray[reuse]; 866 unsigned int oldpagepos = locnarray[reuse];
727 int ypos = ht; 867 int ypos = ht;
728 numlines = reuse; 868 numlines = reuse;
729 while (ypos < height()) 869 while (ypos < height() || numlines < 2)
730 { 870 {
731 if (textarray[numlines] == NULL) 871 if (textarray[numlines] == NULL)
732 { 872 {
733 textarray[numlines] = new CDrawBuffer(&m_fontControl); 873 textarray[numlines] = new CDrawBuffer(&m_fontControl);
734 } 874 }
735 locnarray[numlines] = locate(); 875 locnarray[numlines] = locate();
736 int ch = getline(textarray[numlines]); 876 int ch = getline(textarray[numlines]);
737 ypos += textarray[numlines]->lineSpacing(); 877 ypos += textarray[numlines]->lineSpacing();
738 numlines++; 878 numlines++;
739 if (!ch) 879 if (!ch)
740 { 880 {
741 if (numlines - reuse == 1/* && locnarray[0] == buffdoc.locate()*/) 881 if (numlines - reuse == 1 /*&& locnarray[numlines] == buffdoc.locate()*/)
742 { 882 {
743 locate(oldpagepos); 883 locate(oldpagepos);
744 return false; 884 return false;
745 } 885 }
746 else 886 else
747 { 887 {
748 --numlines; 888 --numlines;
749 mylastpos = locate(); 889 mylastpos = locate();
750 return true; 890 return true;
751 } 891 }
752 } 892 }
753 } 893 }
754 894
755 --numlines; 895 --numlines;
756 mylastpos = locate(); 896 mylastpos = locate();
757 897
758 return true; 898 return true;
759} 899}
760 900
761 901
762void QTReader::dopagedn() 902void QTReader::dopagedn()
763{ 903{
904 buffdoc.unsuspend();
764 int skip = 0, ypos = 0; 905 int skip = 0, ypos = 0;
765 if (locate() != mylastpos) 906 if (locate() != mylastpos)
766 { 907 {
767 //qDebug("Jumping to %u", mylastpos); 908 //qDebug("Jumping to %u", mylastpos);
768 jumpto(mylastpos); 909 jumpto(mylastpos);
769 } 910 }
770 CDrawBuffer* reusebuffer = textarray[numlines]; 911 CDrawBuffer* reusebuffer = textarray[numlines];
912 if (reusebuffer != NULL && reusebuffer->eof()) return;
771 if (reusebuffer != NULL) 913 if (reusebuffer != NULL)
772 { 914 {
773 for (int i = 0; i <= m_overlap; i++) 915 for (int i = 0; i <= m_overlap; i++)
774 { 916 {
775 int offset = numlines - m_overlap + i; 917 int offset = numlines - m_overlap + i;
776 reusebuffer = textarray[offset]; 918 reusebuffer = textarray[offset];
777 size_t reuselocn = locnarray[offset]; 919 size_t reuselocn = locnarray[offset];
778 textarray[offset] = textarray[i]; 920 textarray[offset] = textarray[i];
779 textarray[i] = reusebuffer; 921 textarray[i] = reusebuffer;
922 // reusebuffer->empty();
780 locnarray[offset] = locnarray[i]; 923 locnarray[offset] = locnarray[i];
781 locnarray[i] = reuselocn; 924 locnarray[i] = reuselocn;
782 ypos += textarray[i]->lineSpacing(); 925 ypos += textarray[i]->lineSpacing();
783 skip++; 926 skip++;
784 } 927 }
785 } 928 }
786 if (fillbuffer(skip, ypos)) 929 if (fillbuffer(skip, ypos))
787 { 930 {
788 update(); 931 update();
789 } 932 }
790} 933}
791 934
792void QTReader::dopageup() 935void QTReader::dopageup()
793{ 936{
937 buffdoc.unsuspend();
938 dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]);
939}
940
941void QTReader::dopageup(unsigned int target)
942{
943 buffdoc.unsuspend();
794 CBufferFace<CDrawBuffer*> buff; 944 CBufferFace<CDrawBuffer*> buff;
795 CBufferFace<size_t> loc; 945 CBufferFace<size_t> loc;
796 unsigned int target = locnarray[(m_overlap < numlines) ? m_overlap : numlines/2];
797 946
798 size_t delta; 947 size_t delta, guess = 2048;
799 if (target < 2048) 948 bool ch = true;
800 { 949 int nbfl, ypos = 0;
801 delta = target;
802 jumpto(0);
803 }
804 else
805 {
806 delta = 2048;
807 950
808 jumpto(target - delta); 951 while (1)
809 952 {
810 buff[0] = new CDrawBuffer(&m_fontControl); 953 ch = true;
811 954 nbfl = 0;
812 do 955 if (target < guess)
956 {
957 delta = 0; // 0 is a flag to say don't guess any more
958 jumpto( (m_continuousDocument) ? 0 : buffdoc.startSection() );
959 }
960 else if (!m_continuousDocument && (target - guess < buffdoc.startSection()))
961 {
962 delta = 0; // 0 is a flag to say don't guess any more
963 jumpto(buffdoc.startSection());
964 }
965 else
813 { 966 {
967 delta = guess;
814 968
815 if (!getline(buff[0])) break; 969 jumpto(target - delta);
816 970
817 if (locate() > target) continue; 971 buff[0] = new CDrawBuffer(&m_fontControl);
972
973 do
974 {
975
976 if (!getline(buff[0])) break;
977
978 if (locate() > target) break;
979 }
980 while (!buffdoc.iseol());
818 } 981 }
819 while (!buffdoc.iseol()); 982
820 } 983 ypos = 0;
821 int nbfl = 0; 984 while (locate() < target)
822 985 {
823 bool ch = true; 986 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
824 int ypos = 0; 987 loc[nbfl] = locate();
825 while (locate() < target) 988 ch = getline(buff[nbfl]);
826 { 989 ypos += buff[nbfl]->lineSpacing();
827 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl); 990 nbfl++;
828 loc[nbfl] = locate(); 991 if (!ch) break;
829 ch = getline(buff[nbfl]); 992 }
830 ypos += buff[nbfl]->lineSpacing(); 993 if (ypos < height() && (delta != 0))
831 nbfl++; 994 {
832 if (!ch) break; 995 for (int i = 0; i < nbfl; i++)
833 } 996 {
834 if (ypos < height()) 997 delete buff[i];
835 { 998 buff[i] = NULL;
836 locate(0); 999 }
837 return; 1000 guess <<= 1;
1001 continue;
1002 }
1003 break;
838 } 1004 }
839 if (ch) 1005 if (ch)
840 { 1006 {
841 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl); 1007 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
842 loc[nbfl] = locate(); 1008 loc[nbfl] = locate();
843 int ch = getline(buff[nbfl]); 1009 int ch = getline(buff[nbfl]);
844 nbfl++; 1010 nbfl++;
845 } 1011 }
846 ypos = 0; 1012 ypos = 0;
847 numlines = 0; 1013 numlines = 0;
848 while (ypos < height() && numlines <= nbfl-2) 1014 while (ypos < height() && numlines <= nbfl-1)
849 { 1015 {
850 ypos += buff[nbfl - numlines - 2]->lineSpacing(); 1016 ypos += buff[nbfl - numlines - 1]->lineSpacing();
851 numlines++; 1017 numlines++;
852 } 1018 }
853 --numlines; 1019 --numlines;
854 int offset = nbfl; 1020 int offset = nbfl-1;
855 offset -= numlines+1; 1021 offset -= numlines;
1022 ypos = 0;
856 for (int i = 0; i <= numlines; i++) 1023 for (int i = 0; i <= numlines; i++)
857 { 1024 {
858 delete textarray[i]; 1025 delete textarray[i];
859 textarray[i] = buff[offset+i]; 1026 textarray[i] = buff[offset+i];
860 locnarray[i] = loc[offset + i]; 1027 locnarray[i] = loc[offset + i];
1028 ypos += textarray[i]->lineSpacing();
861 } 1029 }
862 for (int i = 0; i < nbfl - numlines - 1; i++) 1030 for (int i = 0; i < nbfl - numlines - 1; i++)
863 { 1031 {
864 delete buff[i]; 1032 delete buff[i];
865 } 1033 }
866 1034
867// --numlines; 1035 while (ypos < height())
1036 {
1037 numlines++;
1038 locnarray[numlines] = locate();
1039 if (textarray[numlines] == NULL) textarray[numlines] = new CDrawBuffer(&m_fontControl);
1040 if (!getline(textarray[numlines])) break;
1041 ypos += textarray[numlines]->lineSpacing();
1042 }
1043
868 mylastpos = locate(); 1044 mylastpos = locate();
869 1045
870 update(); 1046 update();
871} 1047}
872 1048
873bool QTReader::load_file(const char *newfile, unsigned int _lcn) 1049bool QTReader::load_file(const char *newfile, unsigned int _lcn)
874{ 1050{
875// QMessageBox::information(this, "Name", name, 1); 1051// QMessageBox::information(this, "Name", name, 1);
876// QMessageBox::information(this, "load_file", newfile, 1); 1052// QMessageBox::information(this, "load_file", newfile, 1);
877 1053
878 bool bRC = false; 1054 bool bRC = false;
879 unsigned int lcn = _lcn; 1055 unsigned int lcn = _lcn;
880 if (m_lastfile == newfile) 1056 if (m_lastfile == newfile)
881 { 1057 {
882 lcn = m_lastposn; 1058 lcn = m_lastposn;
883 } 1059 }
884 m_lastfile = newfile; 1060 m_lastfile = newfile;
885 // QMessageBox::information(0, "Opening...", newfile); 1061 // QMessageBox::information(0, "Opening...", newfile);
1062 m_lastwidth = width();
1063 m_lastheight = height();
886 if (buffdoc.openfile(this,newfile) == 0) 1064 if (buffdoc.openfile(this,newfile) == 0)
887 { 1065 {
888 bRC = true; 1066 bRC = true;
1067 buffdoc.setContinuous(m_continuousDocument);
889 // qDebug("buffdoc.openfile done"); 1068 // qDebug("buffdoc.openfile done");
890 locate(lcn); 1069 locate(lcn);
891 // qDebug("buffdoc.locate done"); 1070 // qDebug("buffdoc.locate done");
892 } 1071 }
893 setfilter(getfilter()); 1072 setfilter(getfilter());
894 update(); 1073 update();
895 // qDebug("Updated"); 1074 // qDebug("Updated");
896 return bRC; 1075 return bRC;
897} 1076}
898 1077
899void QTReader::lineDown() 1078void QTReader::lineDown()
900{ 1079{
901 int ypos = 0; 1080 int ypos = 0;
902 int offset = numlines; 1081 int offset = numlines;
903 1082
904 for (int i = 0; i <= numlines; i++) 1083 for (int i = 0; i <= numlines; i++)
905 { 1084 {
906 if ((ypos += textarray[numlines-i]->lineSpacing()) > height()) 1085 if ((ypos += textarray[numlines-i]->lineSpacing()) > height())
907 { 1086 {
908 offset = i-1; 1087 offset = i-1;
909 break; 1088 break;
910 } 1089 }
911 } 1090 }
912 offset = numlines - offset; 1091 offset = numlines - offset;
913 for (int i = offset; i <= numlines; i++) 1092 for (int i = offset; i <= numlines; i++)
914 { 1093 {
915 CDrawBuffer* buff = textarray[i-offset]; 1094 CDrawBuffer* buff = textarray[i-offset];
916 textarray[i-offset] = textarray[i]; 1095 textarray[i-offset] = textarray[i];
917 locnarray[i-offset] = locnarray[i]; 1096 locnarray[i-offset] = locnarray[i];
918 textarray[i] = buff; 1097 textarray[i] = buff;
919 } 1098 }
920 numlines = numlines - offset + 1; 1099 numlines = numlines - offset + 1;
921 locnarray[numlines] = locate(); 1100 locnarray[numlines] = locate();
922 if (textarray[numlines] == NULL) 1101 if (textarray[numlines] == NULL)
923 { 1102 {
924 textarray[numlines] = new CDrawBuffer(&m_fontControl); 1103 textarray[numlines] = new CDrawBuffer(&m_fontControl);
925 } 1104 }
926 getline(textarray[numlines]); 1105 getline(textarray[numlines]);
927 mylastpos = locate(); 1106 mylastpos = locate();
928 update(); 1107 update();
929} 1108}
930/* 1109/*
931void QTReader::lineUp() 1110void QTReader::lineUp()
932{ 1111{
933 CBuffer** buff = textarray; 1112 CBuffer** buff = textarray;
934 unsigned int *loc = new unsigned int[numlines]; 1113 unsigned int *loc = new unsigned int[numlines];
935 int cbptr = 0; 1114 int cbptr = 0;
936 if (locate() != mylastpos) jumpto(mylastpos); 1115 if (locate() != mylastpos) jumpto(mylastpos);
937 unsigned int target = locnarray[numlines-1]; 1116 unsigned int target = locnarray[numlines-1];
938 if (buffdoc.hasrandomaccess()) 1117 if (buffdoc.hasrandomaccess())
939 { 1118 {
940 unsigned int delta = locate()-pagelocate(); 1119 unsigned int delta = locate()-pagelocate();
941 if (delta < 64) delta = 64; 1120 if (delta < 64) delta = 64;
942 do 1121 do
943 { 1122 {
944 delta <<= 1; 1123 delta <<= 1;
945 if (delta >= target) 1124 if (delta >= target)
946 { 1125 {
947 delta = target; 1126 delta = target;
948 jumpto(0); 1127 jumpto(0);
949 for (int i = 0; i < numlines; i++) 1128 for (int i = 0; i < numlines; i++)
950 { 1129 {
951 loc[i] = locate(); 1130 loc[i] = locate();
952 getline(buff[i]); 1131 getline(buff[i]);
953 } 1132 }
954 break; 1133 break;
955 } 1134 }
956 jumpto(target-delta); 1135 jumpto(target-delta);
957 do 1136 do
958 { 1137 {
959 buffdoc.getline(buff[0],width()); 1138 buffdoc.getline(buff[0],width());
960#ifdef WS 1139#ifdef WS
961 //printf("Trying:%s\n",buff[0]); 1140 //printf("Trying:%s\n",buff[0]);
962#endif 1141#endif
963 if (locate() > target) continue; 1142 if (locate() > target) continue;
964 } 1143 }
965 while (!buffdoc.iseol()); 1144 while (!buffdoc.iseol());
966 for (int i = 0; i < numlines; i++) 1145 for (int i = 0; i < numlines; i++)
967 { 1146 {
968 loc[i] = locate(); 1147 loc[i] = locate();
969 buffdoc.getline(buff[i],width()); 1148 buffdoc.getline(buff[i],width());
970#ifdef WS 1149#ifdef WS
971 //printf("Filling:%s\n",buff[i]); 1150 //printf("Filling:%s\n",buff[i]);
972#endif 1151#endif
973 } 1152 }
974 } 1153 }
975 while (locate() >= target && delta < 4096); 1154 while (locate() >= target && delta < 4096);
976#ifdef WS 1155#ifdef WS
977 //printf("Delta:%u\n",delta); 1156 //printf("Delta:%u\n",delta);
978#endif 1157#endif
979 } 1158 }
980 else 1159 else
981 { 1160 {
982 jumpto(0); 1161 jumpto(0);
983 for (int i = 0; i < numlines; i++) 1162 for (int i = 0; i < numlines; i++)
984 { 1163 {
985 loc[i] = locate(); 1164 loc[i] = locate();
986 buffdoc.getline(buff[i],width()); 1165 buffdoc.getline(buff[i],width());
987 } 1166 }
988 } 1167 }
989 cbptr = 0; 1168 cbptr = 0;
990 while (locate() < target) 1169 while (locate() < target)
991 { 1170 {
992 loc[cbptr] = locate(); 1171 loc[cbptr] = locate();
993 buffdoc.getline(buff[cbptr], width()); 1172 buffdoc.getline(buff[cbptr], width());
994#ifdef WS 1173#ifdef WS
995 //printf("Adding:%s\n",buff[cbptr]->data()); 1174 //printf("Adding:%s\n",buff[cbptr]->data());
996#endif 1175#endif
997 cbptr = (cbptr+1) % numlines; 1176 cbptr = (cbptr+1) % numlines;
998 } 1177 }
999 pagepos = loc[cbptr]; 1178 pagepos = loc[cbptr];
1000 textarray = new CBuffer*[numlines]; 1179 textarray = new CBuffer*[numlines];
1001 for (int i = 0; i < numlines; i++) 1180 for (int i = 0; i < numlines; i++)
1002 { 1181 {
1003 int j = (cbptr+i)%numlines; 1182 int j = (cbptr+i)%numlines;
1004 textarray[i] = buff[j]; 1183 textarray[i] = buff[j];
1005 locnarray[i] = loc[j]; 1184 locnarray[i] = loc[j];
1006 } 1185 }
1007 delete [] buff; 1186 delete [] buff;
1008 delete [] loc; 1187 delete [] loc;
1009 mylastpos = locate(); 1188 mylastpos = locate();
1010 update(); 1189 update();
1011} 1190}
1012*/ 1191*/
1013void QTReader::lineUp() 1192void QTReader::lineUp()
1014{ 1193{
1194 buffdoc.unsuspend();
1015 CDrawBuffer* buff = textarray[numlines]; 1195 CDrawBuffer* buff = textarray[numlines];
1016 unsigned int loc; 1196 unsigned int loc;
1017 unsigned int end = locnarray[numlines]; 1197 unsigned int end = locnarray[numlines];
1018 int cbptr = 0; 1198 int cbptr = 0;
1019 if (locate() != mylastpos) jumpto(mylastpos); 1199 if (locate() != mylastpos) jumpto(mylastpos);
1020 unsigned int target = locnarray[0]; 1200 unsigned int target = locnarray[0];
1021 if (target == 0) return; 1201 if (target == 0) return;
1202 if (!m_continuousDocument && (target == buffdoc.startSection())) return;
1022 if (buffdoc.hasrandomaccess()) 1203 if (buffdoc.hasrandomaccess())
1023 { 1204 {
1024 unsigned int delta = locate()-pagelocate(); 1205 unsigned int delta = locate()-pagelocate();
1025 if (delta < 64) delta = 64; 1206 if (delta < 64) delta = 64;
1026 do 1207 do
1027 { 1208 {
1028 delta <<= 1; 1209 delta <<= 1;
1029 if (delta >= target) 1210 if (delta >= target)
1030 { 1211 {
1031 delta = target; 1212 delta = target;
1032 jumpto(0); 1213 jumpto(0);
1033 loc = locate(); 1214 loc = locate();
1034 getline(buff); 1215 getline(buff);
1035 break; 1216 break;
1036 } 1217 }
1218 else if (!m_continuousDocument && (target - delta < buffdoc.startSection()))
1219 {
1220 delta = target-buffdoc.startSection();
1221 jumpto(buffdoc.startSection());
1222 loc = locate();
1223 getline(buff);
1224 break;
1225 }
1037 jumpto(target-delta); 1226 jumpto(target-delta);
1038 do 1227 do
1039 { 1228 {
1040 getline(buff); 1229 getline(buff);
1041#ifdef WS 1230#ifdef WS
1042 //printf("Trying:%s\n",buff[0]); 1231 //printf("Trying:%s\n",buff[0]);
1043#endif 1232#endif
1044 if (locate() > target) continue; 1233 if (locate() > target) continue;
1045 } 1234 }
1046 while (!buffdoc.iseol()); 1235 while (!buffdoc.iseol());
1047 loc = locate(); 1236 loc = locate();
1048 getline(buff); 1237 getline(buff);
1049 } 1238 }
1050 while (locate() >= target && delta < 4096); 1239 while (locate() >= target && delta < 4096);
1051 } 1240 }
1052 else 1241 else
1053 { 1242 {
1054 jumpto(0); 1243 jumpto(0);
1055 loc = locate(); 1244 loc = locate();
1056 getline(buff); 1245 getline(buff);
1057 } 1246 }
1058 cbptr = 0; 1247 cbptr = 0;
1059 while (locate() < target) 1248 while (locate() < target)
1060 { 1249 {
1061 loc = locate(); 1250 loc = locate();
1062 getline(buff); 1251 getline(buff);
1063 } 1252 }
1064 for (int i = numlines; i > 0; i--) 1253 for (int i = numlines; i > 0; i--)
1065 { 1254 {
1066 textarray[i] = textarray[i-1]; 1255 textarray[i] = textarray[i-1];
1067 locnarray[i] = locnarray[i-1]; 1256 locnarray[i] = locnarray[i-1];
1068 } 1257 }
1069 textarray[0] = buff; 1258 textarray[0] = buff;
1070 locnarray[0] = loc; 1259 locnarray[0] = loc;
1071 int start = numlines; 1260 int start = numlines;
1072 int ypos = 0; 1261 int ypos = 0;
1073 for (int i = 0; i <= numlines; i++) 1262 for (int i = 0; i <= numlines; i++)
1074 { 1263 {
1075 ypos += textarray[i]->lineSpacing(); 1264 ypos += textarray[i]->lineSpacing();
1076 if (ypos > height()) 1265 if (ypos > height())
1077 { 1266 {
1078 start = i; 1267 start = i;
1079 ypos -= textarray[i]->lineSpacing(); 1268 ypos -= textarray[i]->lineSpacing();
1080 break; 1269 break;
1081 } 1270 }
1082 } 1271 }
1083 jumpto(locnarray[start]); 1272 jumpto(locnarray[start]);
1084 fillbuffer(start, ypos); 1273 fillbuffer(start, ypos);
1085 update(); 1274 update();
1086} 1275}
1087 1276
1088bool QTReader::empty() 1277bool QTReader::empty()
1089{ 1278{
1090 return buffdoc.empty(); 1279 return buffdoc.empty();
1091} 1280}
1092 1281
1093MarkupType QTReader::PreferredMarkup() 1282MarkupType QTReader::PreferredMarkup()
1094{ 1283{
1095 MarkupType m = buffdoc.PreferredMarkup(); 1284 MarkupType m = buffdoc.PreferredMarkup();
1096 if (m == cTEXT) 1285 if (m == cTEXT)
1097 { 1286 {
1098 int ext = m_lastfile.findRev('.'); 1287 int ext = m_lastfile.findRev('.');
1099 if (ext >= 0) 1288 if (ext >= 0)
1100 { 1289 {
1101 QString ft = m_lastfile.right(m_lastfile.length()-ext-1).upper(); 1290 QString ft = m_lastfile.right(m_lastfile.length()-ext-1).upper();
1102 if (ft.left(3) == "HTM") 1291 if (ft.left(3) == "HTM")
1103 { 1292 {
1104 m = cHTML; 1293 m = cHTML;
1105 } 1294 }
1106 } 1295 }
1107 } 1296 }
1108 return m; 1297 return m;
1109} 1298}
1299
1300void QTReader::setstate(const statedata& sd)
1301{
1302 bstripcr = sd.bstripcr;
1303 btextfmt = sd.btextfmt;
1304 bautofmt = sd.bautofmt;
1305 bstriphtml = sd.bstriphtml;
1306 bpeanut = sd.bpeanut;
1307 bdehyphen = sd.bdehyphen;
1308 bonespace = sd.bonespace;
1309 bunindent = sd.bunindent;
1310 brepara = sd.brepara;
1311 bdblspce = sd.bdblspce;
1312 m_bpagemode = sd.m_bpagemode;
1313 m_navkeys = sd.m_navkeys;
1314 m_bMonoSpaced = sd.m_bMonoSpaced;
1315 bremap = sd.bremap;
1316 bmakebold = sd.bmakebold;
1317 m_continuousDocument = sd.Continuous;
1318#ifdef REPALM
1319 brepalm = sd.brepalm;
1320#endif
1321 bindenter = sd.bindenter;
1322 m_encd = sd.m_charpc;
1323 m_fontname = sd.m_fontname;
1324 setContinuous(sd.Continuous);
1325 ChangeFont(sd.m_textsize);
1326 refresh();
1327}
diff --git a/noncore/apps/opie-reader/QTReader.h b/noncore/apps/opie-reader/QTReader.h
index 78230b4..3d5f57d 100644
--- a/noncore/apps/opie-reader/QTReader.h
+++ b/noncore/apps/opie-reader/QTReader.h
@@ -1,272 +1,312 @@
1#ifndef __QTREADER_H 1#ifndef __QTREADER_H
2#define __QTREADER_H 2#define __QTREADER_H
3 3
4#include <qwidget.h> 4#include <qwidget.h>
5//#include <qpainter.h> 5//#include <qpainter.h>
6#include "my_list.h" 6#include "my_list.h"
7#include "BuffDoc.h" 7#include "BuffDoc.h"
8#include "FontControl.h" 8#include "FontControl.h"
9 9
10//#include <qtimer.h> 10//#include <qtimer.h>
11 11
12class CDrawBuffer; 12class CDrawBuffer;
13//class CBuffer; 13//class CBuffer;
14class QPainter; 14class QPainter;
15class QTimer; 15class QTimer;
16class QPixmap;
17class statedata;
16 18
17class QTReader : public QWidget 19class QTReader : public QWidget
18{ 20{
19 Q_OBJECT 21 Q_OBJECT
20 22
21 friend class QTReaderApp; 23 friend class QTReaderApp;
24 void suspend() { buffdoc.suspend(); }
22 void drawText(QPainter& p, int x, int y, tchar* text); 25 void drawText(QPainter& p, int x, int y, tchar* text);
23 int m_delay; 26 int m_delay;
24 unsigned int m_overlap; 27 unsigned int m_overlap;
25 bool m_autoScroll; 28 bool m_autoScroll;
26 void autoscroll(); 29 void autoscroll();
27 QTimer* timer; 30 QTimer* timer;
28 int m_scrolldy1, m_scrolldy2, m_encd; 31 int m_scrolldy1, m_scrolldy2, m_encd;
29 void focusInEvent(QFocusEvent*); 32 void focusInEvent(QFocusEvent*);
30 void focusOutEvent(QFocusEvent*); 33 void focusOutEvent(QFocusEvent*);
31 bool ChangeFont(int); 34 bool ChangeFont(int);
32 bool getline(CDrawBuffer*); 35 bool getline(CDrawBuffer*);
33 int m_charWidth; 36 int m_charWidth;
34 int m_charpc; 37 int m_charpc;
35 FontControl m_fontControl; 38 FontControl m_fontControl;
36public: 39public:
37 QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0); 40 QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0);
38 // QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0); 41 // QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0);
39 ~QTReader(); 42 ~QTReader();
43 void zoomin();
44 void zoomout();
45 void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
46 {
47 buffdoc.setSaveData(data, len, src, srclen);
48 }
49 void putSaveData(unsigned char*& src, unsigned short& srclen)
50 {
51 buffdoc.putSaveData(src, srclen);
52 }
40 bool empty(); 53 bool empty();
54 void setContinuous(bool _b);
41 void toggle_autoscroll(); 55 void toggle_autoscroll();
42 void setautoscroll(bool); 56 void setautoscroll(bool);
43 void disableAutoscroll() { m_autoScroll = false; } 57 void disableAutoscroll() { m_autoScroll = false; }
44 void copy() 58 void copy()
45 { 59 {
46/* 60/*
47 size_t nd = locate(); 61 size_t nd = locate();
48 jumpto(m_mark); 62 jumpto(m_mark);
49 QString text; 63 QString text;
50 while (m_mark < nd) 64 while (m_mark < nd)
51 { 65 {
52 text += buffdoc.getch(); 66 text += buffdoc.getch();
53 m_mark++; 67 m_mark++;
54 } 68 }
55 QApplication::clipboard()->setText(text); 69 QApplication::clipboard()->setText(text);
56 jumpto(nd); 70 jumpto(nd);
57*/ 71*/
58 }; 72 };
59 void clear() {}; 73 void clear() {};
60 void setText(const QString& n, const QString& s) { m_string = n; load_file((const char*)s); }; 74 void setText(const QString& n, const QString& s) { m_string = n; load_file((const char*)s); };
61 /* 75 /*
62 void setText(bool oldfile) 76 void setText(bool oldfile)
63 { 77 {
64 if (oldfile) 78 if (oldfile)
65 { 79 {
66 m_string = m_lastfile; 80 m_string = m_lastfile;
67 load_file((const tchar*)m_string); 81 load_file((const tchar*)m_string);
68 } 82 }
69 else 83 else
70 { 84 {
71 m_string = QString::null; 85 m_string = QString::null;
72 } 86 }
73 }; 87 };
74 */ 88 */
75 void setpeanut(bool _b) 89 void setpeanut(bool _b)
76 { 90 {
77 bpeanut = _b; 91 bpeanut = _b;
78 setfilter(getfilter()); 92 setfilter(getfilter());
79 } 93 }
80 void setremap(bool _b) 94 void setremap(bool _b)
81 { 95 {
82 bremap = _b; 96 bremap = _b;
83 setfilter(getfilter()); 97 setfilter(getfilter());
84 } 98 }
85 void setmakebold(bool _b) 99 void setmakebold(bool _b)
86 { 100 {
87 bmakebold = _b; 101 bmakebold = _b;
88 setfilter(getfilter()); 102 setfilter(getfilter());
89 } 103 }
90 void setautofmt(bool _b) 104 void setautofmt(bool _b)
91 { 105 {
92 bautofmt = _b; 106 bautofmt = _b;
93 if (bautofmt) 107 if (bautofmt)
94 { 108 {
95 btextfmt = false; 109 btextfmt = false;
96 bstriphtml = false;; 110 bstriphtml = false;;
97 bpeanut = false; 111 bpeanut = false;
98 } 112 }
99 setfilter(getfilter()); 113 setfilter(getfilter());
100 } 114 }
101 void settextfmt(bool _b) 115 void settextfmt(bool _b)
102 { 116 {
103 btextfmt = _b; 117 btextfmt = _b;
104 setfilter(getfilter()); 118 setfilter(getfilter());
105 } 119 }
106 void setstripcr(bool _b) 120 void setstripcr(bool _b)
107 { 121 {
108 bstripcr = _b; 122 bstripcr = _b;
109 setfilter(getfilter()); 123 setfilter(getfilter());
110 } 124 }
125 void setonespace(bool _b)
126 {
127 bonespace = _b;
128 setfilter(getfilter());
129 }
130#ifdef REPALM
131 void setrepalm(bool _b)
132 {
133 brepalm = _b;
134 setfilter(getfilter());
135 }
136#endif
111 void setstriphtml(bool _b) 137 void setstriphtml(bool _b)
112 { 138 {
113 bstriphtml = _b; 139 bstriphtml = _b;
114 setfilter(getfilter()); 140 setfilter(getfilter());
115 } 141 }
116 void setdehyphen(bool _b) 142 void setdehyphen(bool _b)
117 { 143 {
118 bdehyphen = _b; 144 bdehyphen = _b;
119 setfilter(getfilter()); 145 setfilter(getfilter());
120 } 146 }
121 void setunindent(bool _b) 147 void setunindent(bool _b)
122 { 148 {
123 bunindent = _b; 149 bunindent = _b;
124 setfilter(getfilter()); 150 setfilter(getfilter());
125 } 151 }
126 void setrepara(bool _b) 152 void setrepara(bool _b)
127 { 153 {
128 brepara = _b; 154 brepara = _b;
129 setfilter(getfilter()); 155 setfilter(getfilter());
130 } 156 }
131 void setdblspce(bool _b) 157 void setdblspce(bool _b)
132 { 158 {
133 bdblspce = _b; 159 bdblspce = _b;
134 setfilter(getfilter()); 160 setfilter(getfilter());
135 } 161 }
136 void indentplus() 162 void indentplus()
137 { 163 {
138 if (bindenter < 15) bindenter += 2; 164 if (bindenter < 15) bindenter += 2;
139 setfilter(getfilter()); 165 setfilter(getfilter());
140 } 166 }
141 void indentminus() 167 void indentminus()
142 { 168 {
143 if (bindenter > 1) bindenter -= 2; 169 if (bindenter > 1) bindenter -= 2;
144 setfilter(getfilter()); 170 setfilter(getfilter());
145 } 171 }
146 void setpagemode(bool _b) 172 void setpagemode(bool _b)
147 { 173 {
148 m_bpagemode = _b; 174 m_bpagemode = _b;
149 } 175 }
150 void setmono(bool _b) 176 void setmono(bool _b)
151 { 177 {
152 m_bMonoSpaced = _b; 178 m_bMonoSpaced = _b;
153 ChangeFont(m_fontControl.currentsize()); 179 ChangeFont(m_fontControl.currentsize());
154 locate(pagelocate()); 180 locate(pagelocate());
155 } 181 }
156 void setencoding(int _f) 182 void setencoding(int _f)
157 { 183 {
158 m_encd = _f; 184 m_encd = _f;
159 setfilter(getfilter()); 185 setfilter(getfilter());
160 } 186 }
161 MarkupType PreferredMarkup(); 187 MarkupType PreferredMarkup();
162 CEncoding* getencoding() 188 CEncoding* getencoding()
163 { 189 {
164 switch (m_encd) 190 switch (m_encd)
165 { 191 {
166 case 5: 192 case 5:
167 return new Ccp1252; 193 return new Ccp1252;
168 case 4: 194 case 4:
169 return new CPalm; 195 return new CPalm;
170 case 1: 196 case 1:
171 return new CUtf8; 197 return new CUtf8;
172 case 2: 198 case 2:
173 return new CUcs16be; 199 return new CUcs16be;
174 case 3: 200 case 3:
175 return new CUcs16le; 201 return new CUcs16le;
176 case 0: 202 case 0:
177 default: 203 default:
178 return new CAscii; 204 return new CAscii;
179 } 205 }
180 } 206 }
181 CFilterChain* getfilter() 207 CFilterChain* getfilter()
182 { 208 {
183 CFilterChain * filt = new CFilterChain(getencoding()); 209 CFilterChain * filt = new CFilterChain(getencoding());
184 if (bstripcr) filt->addfilter(new stripcr); 210 if (bstripcr) filt->addfilter(new stripcr);
185 211
186 if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt); 212 if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt);
187 if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter); 213 if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter);
188 if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml); 214 if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml);
189 215
190 if (bdehyphen) filt->addfilter(new dehyphen); 216 if (bdehyphen) filt->addfilter(new dehyphen);
191 if (bunindent) filt->addfilter(new unindent); 217 if (bunindent) filt->addfilter(new unindent);
192 if (brepara) filt->addfilter(new repara); 218 if (brepara) filt->addfilter(new repara);
219 if (bonespace) filt->addfilter(new OnePara);
193 if (bindenter) filt->addfilter(new indenter(bindenter)); 220 if (bindenter) filt->addfilter(new indenter(bindenter));
194 if (bdblspce) filt->addfilter(new dblspce); 221 if (bdblspce) filt->addfilter(new dblspce);
222#ifdef REPALM
223 if (brepalm) filt->addfilter(new repalm);
224#endif
195 if (bremap) filt->addfilter(new remap); 225 if (bremap) filt->addfilter(new remap);
196 if (bmakebold) filt->addfilter(new embolden); 226 if (bmakebold) filt->addfilter(new embolden);
197 return filt; 227 return filt;
198 } 228 }
199 229
200 230
201private slots: 231private slots:
202 void doscroll(); 232 void doscroll();
203 void drawIt( QPainter * ); 233 void drawIt( QPainter * );
204 void paintEvent( QPaintEvent * ); 234 void paintEvent( QPaintEvent * );
205// void resizeEvent( QResizeEvent * p ) { update(); } 235// void resizeEvent( QResizeEvent * p ) { update(); }
206 void keyPressEvent(QKeyEvent*); 236 void keyPressEvent(QKeyEvent*);
207 void drawFonts(QPainter*); 237 void drawFonts(QPainter*);
208 private: 238 private:
209 void setTwoTouch(bool _b); 239 void setTwoTouch(bool _b);
210 void init(); 240 void init();
211 void mousePressEvent( QMouseEvent* ); 241 void mousePressEvent( QMouseEvent* );
212 void mouseReleaseEvent( QMouseEvent* ); 242 void mouseReleaseEvent( QMouseEvent* );
213// void mouseDoubleClickEvent( QMouseEvent* ); 243// void mouseDoubleClickEvent( QMouseEvent* );
214 QString m_string, m_fontname; 244 QString m_string, m_fontname;
215 void setfont(); 245 void setfont();
216 //myoutput stuff 246 //myoutput stuff
217 private: 247 private:
218 bool mouseUpOn; 248 bool mouseUpOn;
219 bool getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt); 249 linkType getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt);
220 bool m_twotouch, m_touchone; 250 bool m_twotouch, m_touchone;
221 size_t m_startpos, m_startoffset; 251 size_t m_startpos, m_startoffset;
252 void dopageup(unsigned int);
222 void dopageup(); 253 void dopageup();
223 void lineDown(); 254 void lineDown();
224 void lineUp(); 255 void lineUp();
225 void dopagedn(); 256 void dopagedn();
226 long real_delay(); 257 long real_delay();
227 int m_textsize; 258 int m_textsize;
228 int m_lastwidth, m_lastheight; 259 int m_lastwidth, m_lastheight;
229 CBufferFace<CDrawBuffer*> textarray; 260 CBufferFace<CDrawBuffer*> textarray;
230 CBufferFace<size_t> locnarray; 261 CBufferFace<size_t> locnarray;
231 unsigned int numlines; 262 unsigned int numlines;
232 bool bstripcr, btextfmt, bstriphtml, bdehyphen, bunindent, brepara, bdblspce, btight, bmakebold, bremap, bpeanut, bautofmt; 263 bool bstripcr, btextfmt, bstriphtml, bdehyphen, bunindent, brepara, bdblspce, btight, bmakebold, bremap, bpeanut, bautofmt, bonespace;
233 bool m_bpagemode, m_bMonoSpaced; 264#ifdef REPALM
265 bool brepalm;
266#endif
267 bool m_bpagemode, m_bMonoSpaced, m_continuousDocument;
234 unsigned char bindenter; 268 unsigned char bindenter;
235 QString m_lastfile; 269 QString m_lastfile;
236 size_t m_lastposn; 270 size_t m_lastposn;
237 public: 271 public:
272 bool bDoUpdates;
273 bool m_navkeys;
274 void NavUp();
275 void NavDown();
238 int getch() { return buffdoc.getch(); } 276 int getch() { return buffdoc.getch(); }
239 bool tight; 277 bool tight;
240 bool load_file(const char *newfile, unsigned int lcn=0); 278 bool load_file(const char *newfile, unsigned int lcn=0);
241 BuffDoc buffdoc; 279 BuffDoc buffdoc;
242 CList<Bkmk>* getbkmklist() { return buffdoc.getbkmklist(); } 280 CList<Bkmk>* getbkmklist() { return buffdoc.getbkmklist(); }
243 bool locate(unsigned long n); 281 bool locate(unsigned long n);
244 void jumpto(unsigned long n) { buffdoc.locate(n); } 282 void jumpto(unsigned long n) { buffdoc.unsuspend(); buffdoc.locate(n); }
245 unsigned long locate() { return buffdoc.locate(); } 283 unsigned long locate() { buffdoc.unsuspend(); return buffdoc.locate(); }
246 unsigned long explocate() { return buffdoc.explocate(); } 284 unsigned long explocate() { buffdoc.unsuspend(); return buffdoc.explocate(); }
247 unsigned long pagelocate() { return locnarray[0]; } 285 unsigned long pagelocate() { return locnarray[0]; }
248 unsigned long mylastpos; 286 unsigned long mylastpos;
249 void setfilter(CFilterChain *f) { buffdoc.setfilter(f); locate(pagelocate()); } 287 void setfilter(CFilterChain *f) { buffdoc.unsuspend(); buffdoc.setfilter(f); locate(pagelocate()); }
250 void restore() { jumpto(mylastpos); } 288 void restore() { jumpto(mylastpos); }
251 void goUp(); 289 void goUp();
252 void refresh() { locate(pagelocate()); } 290 void refresh() { locate(pagelocate()); }
253 void goDown(); 291 void goDown();
254 // bool bold; 292 // bool bold;
255 int textsize() { return m_textsize; } 293 int textsize() { return m_textsize; }
256 void textsize(int ts) { m_textsize = ts; } 294 void textsize(int ts) { m_textsize = ts; }
257 bool fillbuffer(int ru = 0, int ht = 0); 295 bool fillbuffer(int ru = 0, int ht = 0);
258 unsigned int screenlines(); 296 unsigned int screenlines();
259 void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.sizes(fs,ts); } 297 void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.unsuspend(); buffdoc.sizes(fs,ts); }
260 static const char *fonts[]; 298 static const char *fonts[];
261// unsigned int *fontsizes; 299// unsigned int *fontsizes;
262 int m_ascent, m_descent, m_linespacing; 300 int m_ascent, m_descent, m_linespacing;
263 QFontMetrics* m_fm; 301 QFontMetrics* m_fm;
264 QString firstword(); 302 QString firstword();
303 void setstate(const statedata& sd);
265 304
266 signals: 305 signals:
267 void OnRedraw(); 306 void OnRedraw();
268 void OnWordSelected(const QString&, size_t, const QString&); 307 void OnWordSelected(const QString&, size_t, const QString&);
269 void OnActionPressed(); 308 void OnActionPressed();
309 void OnShowPicture(QPixmap&);
270}; 310};
271 311
272#endif 312#endif
diff --git a/noncore/apps/opie-reader/QTReaderApp.cpp b/noncore/apps/opie-reader/QTReaderApp.cpp
index 8726df7..2044b1d 100644
--- a/noncore/apps/opie-reader/QTReaderApp.cpp
+++ b/noncore/apps/opie-reader/QTReaderApp.cpp
@@ -1,2029 +1,2606 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. Allrights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include <qclipboard.h> 21#include <qclipboard.h>
22#include <qwidgetstack.h> 22#include <qwidgetstack.h>
23#include <qpe/qpemenubar.h> 23#include <qpe/qpemenubar.h>
24#include <qpe/qpetoolbar.h> 24//#include <qpe/qpetoolbar.h>
25#include <qmenubar.h>
26#include <qtoolbar.h>
27#include <qpe/menubutton.h>
25#include <qpe/fontdatabase.h> 28#include <qpe/fontdatabase.h>
26#include <qcombobox.h> 29#include <qcombobox.h>
27#include <qpopupmenu.h> 30#include <qpopupmenu.h>
28#include <qaction.h> 31#include <qaction.h>
29#include <qapplication.h> 32#include <qapplication.h>
30#include <qlineedit.h> 33#include <qlineedit.h>
31#include <qtoolbutton.h> 34#include <qtoolbutton.h>
32#include <qspinbox.h> 35#include <qspinbox.h>
33#include <qobjectlist.h> 36#include <qobjectlist.h>
34#include <qpe/global.h> 37#include <qpe/global.h>
35#include <qpe/applnk.h> 38#include <qpe/applnk.h>
36#include <qfileinfo.h> 39#include <qfileinfo.h>
37#include <stdlib.h> //getenv 40#include <stdlib.h> //getenv
38#include <qprogressbar.h> 41#include <qprogressbar.h>
39#include <qpe/config.h> 42#include <qpe/config.h>
40#include <qbuttongroup.h> 43#include <qbuttongroup.h>
41#include <qradiobutton.h> 44#include <qradiobutton.h>
42#include <qpe/qcopenvelope_qws.h> 45#include <qpe/qcopenvelope_qws.h>
43 46
44#include "QTReader.h" 47#include "QTReader.h"
48#include "GraphicWin.h"
45#include "Bkmks.h" 49#include "Bkmks.h"
46#include "cbkmkselector.h" 50#include "cbkmkselector.h"
47#include "infowin.h" 51#include "infowin.h"
48#include "CAnnoEdit.h" 52#include "CAnnoEdit.h"
49#include "QFloatBar.h" 53#include "QFloatBar.h"
50//#include <qpe/fontdatabase.h> 54//#include <qpe/fontdatabase.h>
51 55
52#include <qpe/resource.h> 56#include <qpe/resource.h>
53#include <qpe/qpeapplication.h> 57#include <qpe/qpeapplication.h>
54 58
55#include "QTReaderApp.h" 59#include "QTReaderApp.h"
56#include "fileBrowser.h" 60#include "fileBrowser.h"
57#include "CDrawBuffer.h" 61#include "CDrawBuffer.h"
62#include "Filedata.h"
63#include "opie.h"
64#include "name.h"
65#include "StateData.h"
66
67#ifdef OPIE
68#define PICDIR "opie-reader/"
69#else
70#define PICDIR
71#endif
58 72
59 73
60unsigned long QTReaderApp::m_uid = 0; 74unsigned long QTReaderApp::m_uid = 0;
61 75
62void QTReaderApp::setScrollState(bool _b) { m_scrollButton->setOn(_b); } 76void QTReaderApp::setScrollState(bool _b) { m_scrollButton->setOn(_b); }
63 77
64#include <unistd.h> 78#include <unistd.h>
65#include <stddef.h> 79#include <stddef.h>
66#include <dirent.h> 80#include <dirent.h>
67 81
68void QTReaderApp::listBkmkFiles() 82void QTReaderApp::listBkmkFiles()
69{ 83{
70 bkmkselector->clear(); 84 bkmkselector->clear();
85 bkmkselector->setText("Cancel");
71 int cnt = 0; 86 int cnt = 0;
72 DIR *d; 87 DIR *d;
73 d = opendir((const char *)Global::applicationFileName("uqtreader","")); 88 d = opendir((const char *)Global::applicationFileName(APPDIR,""));
74 89
75 while(1) 90 while(1)
76 { 91 {
77 struct dirent* de; 92 struct dirent* de;
78 struct stat buf; 93 struct stat buf;
79 de = readdir(d); 94 de = readdir(d);
80 if (de == NULL) break; 95 if (de == NULL) break;
81 96
82 if (lstat((const char *)Global::applicationFileName("uqtreader",de->d_name),&buf) == 0 && S_ISREG(buf.st_mode)) 97 if (lstat((const char *)Global::applicationFileName(APPDIR,de->d_name),&buf) == 0 && S_ISREG(buf.st_mode))
83 { 98 {
84 bkmkselector->insertItem(de->d_name); 99 bkmkselector->insertItem(de->d_name);
85 cnt++; 100 cnt++;
86 } 101 }
87 } 102 }
88 103
89 closedir(d); 104 closedir(d);
90 105
91 if (cnt > 0) 106 if (cnt > 0)
92 { 107 {
93//tjw menu->hide(); 108//tjw menu->hide();
94 editBar->hide(); 109 editBar->hide();
95 if (m_fontVisible) m_fontBar->hide(); 110 if (m_fontVisible) m_fontBar->hide();
96 if (regVisible) regBar->hide(); 111 if (regVisible)
97 if (searchVisible) searchBar->hide(); 112 {
98 m_nRegAction = cRmBkmkFile; 113 Global::hideInputMethod();
114 regBar->hide();
115 }
116 if (searchVisible)
117 {
118 Global::hideInputMethod();
119 searchBar->hide();
120 }
121 m_nRegAction = cRmBkmkFile;
99 editorStack->raiseWidget( bkmkselector ); 122 editorStack->raiseWidget( bkmkselector );
100 } 123 }
101 else 124 else
102 QMessageBox::information(this, "OpieReader", "No bookmark files"); 125 QMessageBox::information(this, PROGNAME, "No bookmark files");
103} 126}
104 127
105QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) 128QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
106 : QMainWindow( parent, name, f ), bFromDocView( FALSE ), m_dontSave(false) 129 : QMainWindow( parent, name, f ), bFromDocView( FALSE ), m_dontSave(false)
107{ 130{
108// qDebug("Application directory = %s", (const tchar *)QPEApplication::documentDir()); 131// qDebug("Application directory = %s", (const tchar *)QPEApplication::documentDir());
109// qDebug("Application directory = %s", (const tchar *)Global::applicationFileName("uqtreader","bkmks.xml")); 132// qDebug("Application directory = %s", (const tchar *)Global::applicationFileName("uqtreader","bkmks.xml"));
110 133
111 pBkmklist = NULL; 134 pBkmklist = NULL;
112 doc = 0; 135 pOpenlist = NULL;
136// doc = 0;
113 137
114 m_fBkmksChanged = false; 138 m_fBkmksChanged = false;
115 139
116 QString lang = getenv( "LANG" ); 140 QString lang = getenv( "LANG" );
117 141
118 m_autogenstr = "^ *[A-Z].*[a-z] *$"; 142 m_autogenstr = "^ *[A-Z].*[a-z] *$";
119 setToolBarsMovable( FALSE ); 143 setToolBarsMovable( FALSE );
120 144
121 setIcon( Resource::loadPixmap( "opie-reader/uqtreader" ) ); 145 setIcon( Resource::loadPixmap( "uqtreader" ) );
122 146
123 QPEToolBar *bar = new QPEToolBar( this ); 147// QPEToolBar *bar = new QPEToolBar( this );
148 QToolBar *bar = new QToolBar( this );
124 bar->setHorizontalStretchable( TRUE ); 149 bar->setHorizontalStretchable( TRUE );
125 addToolBar(bar, "tool",QMainWindow::Top, true); 150 addToolBar(bar, "tool",QMainWindow::Top, true);
126//tjw menu = bar; 151//tjw menu = bar;
127 152
128 QPEMenuBar *mb = new QPEMenuBar( bar ); 153 QPEMenuBar *mb = new QPEMenuBar( bar );
154// QMenuBar *mb = new QMenuBar( bar );
129 QPopupMenu *file = new QPopupMenu( this ); 155 QPopupMenu *file = new QPopupMenu( this );
130 QPopupMenu *format = new QPopupMenu( this ); 156 QPopupMenu *format = new QPopupMenu( this );
131 // QPopupMenu *edit = new QPopupMenu( this ); 157 // QPopupMenu *edit = new QPopupMenu( this );
132 158
133// bar = new QToolBar( this ); 159// bar = new QToolBar( this );
134 editBar = bar; 160 editBar = bar;
135 161
136 /* 162 /*
137 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); 163 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
138 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 164 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
139 a->addTo( bar ); 165 a->addTo( bar );
140 a->addTo( file ); 166 a->addTo( file );
141 */ 167 */
142 168
143 editorStack = new QWidgetStack( this ); 169 editorStack = new QWidgetStack( this );
144 setCentralWidget( editorStack ); 170 setCentralWidget( editorStack );
145 171
146 searchVisible = FALSE; 172 searchVisible = FALSE;
147 regVisible = FALSE; 173 regVisible = FALSE;
148 m_fontVisible = false; 174 m_fontVisible = false;
149 175
150 pbar = new QProgressBar(this); 176 pbar = new QProgressBar(this);
151 pbar->hide(); 177 pbar->hide();
152 178
153 m_annoWin = new CAnnoEdit(editorStack); 179 m_annoWin = new CAnnoEdit(editorStack);
154 editorStack->addWidget(m_annoWin, get_unique_id()); 180 editorStack->addWidget(m_annoWin, get_unique_id());
155 connect( m_annoWin, SIGNAL( finished(const QString&, const QString&) ), this, SLOT( addAnno(const QString&, const QString&) ) ); 181 connect( m_annoWin, SIGNAL( finished(const QString&, const QString&) ), this, SLOT( addAnno(const QString&, const QString&) ) );
156 connect( m_annoWin, SIGNAL( cancelled() ), this, SLOT( infoClose() ) ); 182 connect( m_annoWin, SIGNAL( cancelled() ), this, SLOT( infoClose() ) );
157 183
158 m_infoWin = new infowin(editorStack); 184 m_infoWin = new infowin(editorStack);
159 editorStack->addWidget(m_infoWin, get_unique_id()); 185 editorStack->addWidget(m_infoWin, get_unique_id());
160 connect( m_infoWin, SIGNAL( Close() ), this, SLOT( infoClose() ) ); 186 connect( m_infoWin, SIGNAL( Close() ), this, SLOT( infoClose() ) );
161 187
188 m_graphicwin = new GraphicWin(editorStack);
189 editorStack->addWidget(m_graphicwin, get_unique_id());
190 connect( m_graphicwin, SIGNAL( Closed() ), this, SLOT( infoClose() ) );
191
162// bkmkselector = new QListBox(editorStack, "Bookmarks"); 192// bkmkselector = new QListBox(editorStack, "Bookmarks");
163 bkmkselector = new CBkmkSelector(editorStack, "Bookmarks"); 193 bkmkselector = new CBkmkSelector(editorStack, "Bookmarks");
164 // connect(bkmkselector, SIGNAL( selected(const QString&) ), this, SLOT( gotobkmk(const QString&) ) ); 194 // connect(bkmkselector, SIGNAL( selected(const QString&) ), this, SLOT( gotobkmk(const QString&) ) );
165 connect(bkmkselector, SIGNAL( selected(int) ), this, SLOT( gotobkmk(int) ) ); 195 connect(bkmkselector, SIGNAL( selected(int) ), this, SLOT( gotobkmk(int) ) );
166 connect(bkmkselector, SIGNAL( cancelled() ), this, SLOT( cancelbkmk() ) ); 196 connect(bkmkselector, SIGNAL( cancelled() ), this, SLOT( cancelbkmk() ) );
167 editorStack->addWidget( bkmkselector, get_unique_id() ); 197 editorStack->addWidget( bkmkselector, get_unique_id() );
168 198
169/* 199/*
170 importSelector = new FileSelector( "*", editorStack, "importselector", false ); 200 importSelector = new FileSelector( "*", editorStack, "importselector", false );
171 connect( importSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( importFile( const DocLnk & ) ) ); 201 connect( importSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( importFile( const DocLnk & ) ) );
172 202
173 editorStack->addWidget( importSelector, get_unique_id() ); 203 editorStack->addWidget( importSelector, get_unique_id() );
174 204
175 // don't need the close visible, it is redundant... 205 // don't need the close visible, it is redundant...
176 importSelector->setCloseVisible( FALSE ); 206 importSelector->setCloseVisible( FALSE );
177*/ 207*/
208 qDebug("Reading file list");
209 readfilelist();
178 210
179 reader = new QTReader( editorStack ); 211 reader = new QTReader( editorStack );
180 212
213 reader->bDoUpdates = false;
214
181 ((QPEApplication*)qApp)->setStylusOperation(reader, QPEApplication::RightOnHold); 215 ((QPEApplication*)qApp)->setStylusOperation(reader, QPEApplication::RightOnHold);
182 216
183 Config config( "uqtreader" ); 217 qDebug("Reading config");
218 Config config( APPDIR );
184 config.setGroup( "View" ); 219 config.setGroup( "View" );
185 220
186 reader->bstripcr = config.readBoolEntry( "StripCr", true ); 221 reader->bstripcr = config.readBoolEntry( "StripCr", true );
187 reader->btextfmt = config.readBoolEntry( "TextFmt", false ); 222 reader->btextfmt = config.readBoolEntry( "TextFmt", false );
188 reader->bautofmt = config.readBoolEntry( "AutoFmt", true ); 223 reader->bautofmt = config.readBoolEntry( "AutoFmt", true );
189 reader->bstriphtml = config.readBoolEntry( "StripHtml", false ); 224 reader->bstriphtml = config.readBoolEntry( "StripHtml", false );
190 reader->bpeanut = config.readBoolEntry( "Peanut", false ); 225 reader->bpeanut = config.readBoolEntry( "Peanut", false );
191 reader->bdehyphen = config.readBoolEntry( "Dehyphen", false ); 226 reader->bdehyphen = config.readBoolEntry( "Dehyphen", false );
227 reader->bonespace = config.readBoolEntry( "OneSpace", false );
192 reader->bunindent = config.readBoolEntry( "Unindent", false ); 228 reader->bunindent = config.readBoolEntry( "Unindent", false );
193 reader->brepara = config.readBoolEntry( "Repara", false ); 229 reader->brepara = config.readBoolEntry( "Repara", false );
194 reader->bdblspce = config.readBoolEntry( "DoubleSpace", false ); 230 reader->bdblspce = config.readBoolEntry( "DoubleSpace", false );
195 reader->bindenter = config.readNumEntry( "Indent", 0 ); 231 reader->bindenter = config.readNumEntry( "Indent", 0 );
196 reader->m_textsize = config.readNumEntry( "FontSize", 12 ); 232 reader->m_textsize = config.readNumEntry( "FontSize", 12 );
197 reader->m_delay = config.readNumEntry( "ScrollDelay", 5184); 233 reader->m_delay = config.readNumEntry( "ScrollDelay", 5184);
198 reader->m_lastfile = config.readEntry( "LastFile", QString::null ); 234 reader->m_lastfile = config.readEntry( "LastFile", QString::null );
199 reader->m_lastposn = config.readNumEntry( "LastPosn", 0 ); 235 reader->m_lastposn = config.readNumEntry( "LastPosn", 0 );
200 reader->m_bpagemode = config.readBoolEntry( "PageMode", true ); 236 reader->m_bpagemode = config.readBoolEntry( "PageMode", true );
237 reader->m_navkeys = config.readBoolEntry( "CursorNavigation", false );
201 reader->m_bMonoSpaced = config.readBoolEntry( "MonoSpaced", false); 238 reader->m_bMonoSpaced = config.readBoolEntry( "MonoSpaced", false);
202 reader->m_fontname = config.readEntry( "Fontname", "helvetica" ); 239 reader->m_fontname = config.readEntry( "Fontname", "helvetica" );
203 reader->m_encd = config.readNumEntry( "Encoding", 0 ); 240 reader->m_encd = config.readNumEntry( "Encoding", 0 );
204 reader->m_charpc = config.readNumEntry( "CharSpacing", 100 ); 241 reader->m_charpc = config.readNumEntry( "CharSpacing", 100 );
205 reader->m_overlap = config.readNumEntry( "Overlap", 0 ); 242 reader->m_overlap = config.readNumEntry( "Overlap", 0 );
243#ifdef REPALM
244 reader->brepalm = config.readBoolEntry( "Repalm", true );
245#endif
206 reader->bremap = config.readBoolEntry( "Remap", true ); 246 reader->bremap = config.readBoolEntry( "Remap", true );
207 reader->bmakebold = config.readBoolEntry( "MakeBold", false ); 247 reader->bmakebold = config.readBoolEntry( "MakeBold", false );
248 reader->setContinuous(config.readBoolEntry( "Continuous", true ));
208 m_targetapp = config.readEntry( "TargetApp", QString::null ); 249 m_targetapp = config.readEntry( "TargetApp", QString::null );
209 m_targetmsg = config.readEntry( "TargetMsg", QString::null ); 250 m_targetmsg = config.readEntry( "TargetMsg", QString::null );
210 m_twoTouch = config.readBoolEntry( "TwoTouch", false); 251 m_twoTouch = config.readBoolEntry( "TwoTouch", false);
211 m_doAnnotation = config.readBoolEntry( "Annotation", false); 252 m_doAnnotation = config.readBoolEntry( "Annotation", false);
212 m_doDictionary = config.readBoolEntry( "Dictionary", false); 253 m_doDictionary = config.readBoolEntry( "Dictionary", false);
213 m_doClipboard = config.readBoolEntry( "Clipboard", false); 254 m_doClipboard = config.readBoolEntry( "Clipboard", false);
214 m_spaceTarget = (ActionTypes)config.readNumEntry("SpaceTarget", cesAutoScroll); 255 m_spaceTarget = (ActionTypes)config.readNumEntry("SpaceTarget", cesAutoScroll);
215 setTwoTouch(m_twoTouch); 256 setTwoTouch(m_twoTouch);
216 257
217 258
259 connect( reader, SIGNAL( OnShowPicture(QPixmap&) ), this, SLOT( showgraphic(QPixmap&) ) );
260
218 connect( reader, SIGNAL( OnRedraw() ), this, SLOT( OnRedraw() ) ); 261 connect( reader, SIGNAL( OnRedraw() ), this, SLOT( OnRedraw() ) );
219 connect( reader, SIGNAL( OnActionPressed() ), this, SLOT( OnActionPressed() ) ); 262 connect( reader, SIGNAL( OnActionPressed() ), this, SLOT( OnActionPressed() ) );
220 connect( reader, SIGNAL( OnWordSelected(const QString&, size_t, const QString&) ), this, SLOT( OnWordSelected(const QString&, size_t, const QString&) ) ); 263 connect( reader, SIGNAL( OnWordSelected(const QString&, size_t, const QString&) ), this, SLOT( OnWordSelected(const QString&, size_t, const QString&) ) );
221 editorStack->addWidget( reader, get_unique_id() ); 264 editorStack->addWidget( reader, get_unique_id() );
222 265
223 QAction *a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); 266 QAction *a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
224 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); 267 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
225 a->addTo( bar ); 268 a->addTo( bar );
226 a->addTo( file ); 269 a->addTo( file );
227 270
271 a = new QAction( tr( "Close" ), Resource::loadPixmap( "fileclose" ), QString::null, 0, this, 0 );
272 connect( a, SIGNAL( activated() ), this, SLOT( fileClose() ) );
273// a->addTo( bar );
274 a->addTo( file );
275
228 /* 276 /*
229 a = new QAction( tr( "Revert" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 277 a = new QAction( tr( "Revert" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
230 connect( a, SIGNAL( activated() ), this, SLOT( fileRevert() ) ); 278 connect( a, SIGNAL( activated() ), this, SLOT( fileRevert() ) );
231 a->addTo( file ); 279 a->addTo( file );
232 280
233 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); 281 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 );
234 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); 282 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
235 a->addTo( editBar ); 283 a->addTo( editBar );
236 a->addTo( edit ); 284 a->addTo( edit );
237 */ 285 */
238 286
239 a = new QAction( tr( "Info" ), QString::null, 0, this, NULL); 287 a = new QAction( tr( "Info" ), QString::null, 0, this, NULL);
240 connect( a, SIGNAL( activated() ), this, SLOT( showinfo() ) ); 288 connect( a, SIGNAL( activated() ), this, SLOT( showinfo() ) );
241 a->addTo( file ); 289 a->addTo( file );
242 290
243 QActionGroup* ag = new QActionGroup(this); 291 QActionGroup* ag = new QActionGroup(this);
244 QPopupMenu *spacemenu = new QPopupMenu(this); 292 QPopupMenu *spacemenu = new QPopupMenu(this);
245 file->insertItem( tr( "On Action..." ), spacemenu ); 293 file->insertItem( tr( "On Action..." ), spacemenu );
246 294
247 m_buttonAction[0] = new QAction( tr( "Open File" ), QString::null, 0, ag, NULL, true ); 295 m_buttonAction[0] = new QAction( tr( "Open File" ), QString::null, 0, ag, NULL, true );
248 296
249 m_buttonAction[1] = new QAction( tr( "Autoscroll" ), QString::null, 0, ag, NULL, true ); 297 m_buttonAction[1] = new QAction( tr( "Autoscroll" ), QString::null, 0, ag, NULL, true );
250 298
251 m_buttonAction[2] = new QAction( tr( "Mark" ), QString::null, 0, ag, NULL, true ); 299 m_buttonAction[2] = new QAction( tr( "Mark" ), QString::null, 0, ag, NULL, true );
252 300
301 m_buttonAction[3] = new QAction( tr( "Fullscreen" ), QString::null, 0, ag, NULL, true );
302
253 ag->addTo(spacemenu); 303 ag->addTo(spacemenu);
254 304
255 connect(ag, SIGNAL( selected(QAction*) ), this, SLOT( buttonActionSelected(QAction*) ) ); 305 connect(ag, SIGNAL( selected(QAction*) ), this, SLOT( buttonActionSelected(QAction*) ) );
256 306
307 file->insertSeparator();
308
309 ag = new QActionGroup(this);
310 ag->setExclusive(false);
311 QPopupMenu *encoding = new QPopupMenu(this);
312 file->insertItem( tr( "Navigation" ), encoding );
313
314 a = m_scrollButton = new QAction( tr( "Scroll" ), Resource::loadPixmap( PICDIR "panel-arrow-down" ), QString::null, 0, ag, 0, true );
257 315
258 a = m_scrollButton = new QAction( tr( "Scroll" ), Resource::loadPixmap( "opie-reader/panel-arrow-down" ), QString::null, 0, this, 0, true );
259// connect( a, SIGNAL( activated() ), this, SLOT( autoScroll() ) );
260 a->setOn(false); 316 a->setOn(false);
261 connect( a, SIGNAL( toggled(bool) ), this, SLOT( autoScroll(bool) ) ); 317 connect( a, SIGNAL( toggled(bool) ), this, SLOT( autoScroll(bool) ) );
262 file->insertSeparator();
263 a->addTo( bar ); 318 a->addTo( bar );
264 a->addTo( file ); 319
320 a = new QAction( tr( "Jump" ), QString::null, 0, ag, NULL);
321 connect( a, SIGNAL( activated() ), this, SLOT( jump() ) );
322
323 a = new QAction( tr( "Page/Line Scroll" ), QString::null, 0, ag, NULL, true );
324 connect( a, SIGNAL( toggled(bool) ), this, SLOT( pagemode(bool) ) );
325 a->setOn(reader->m_bpagemode);
326
327 a = new QAction( tr( "Set Overlap" ), QString::null, 0, ag, NULL);
328 connect( a, SIGNAL( activated() ), this, SLOT( setoverlap() ) );
329
330 a = new QAction( tr( "Use Cursor" ), QString::null, 0, ag, NULL, true );
331 connect( a, SIGNAL( toggled(bool) ), this, SLOT( navkeys(bool) ) );
332 a->setOn(reader->m_navkeys);
333
334 ag->addTo(encoding);
265 335
266 /* 336 /*
267 a = new QAction( tr( "Find" ), QString::null, 0, this, NULL, true ); 337 a = new QAction( tr( "Find" ), QString::null, 0, this, NULL, true );
268 // connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) ); 338 // connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) );
269 a->addTo( file ); 339 a->addTo( file );
270 340
271 a = new QAction( tr( "Find Again" ), QString::null, 0, this, NULL, true ); 341 a = new QAction( tr( "Find Again" ), QString::null, 0, this, NULL, true );
272 // connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) ); 342 // connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) );
273 a->addTo( file ); 343 a->addTo( file );
274 */ 344 */
275 a = new QAction( tr( "Jump" ), QString::null, 0, this, NULL);
276 connect( a, SIGNAL( activated() ), this, SLOT( jump() ) );
277 a->addTo( file );
278
279 a = new QAction( tr( "Page/Line Scroll" ), QString::null, 0, this, NULL, true );
280 connect( a, SIGNAL( toggled(bool) ), this, SLOT( pagemode(bool) ) );
281 a->setOn(reader->m_bpagemode);
282 a->addTo( file );
283
284 a = new QAction( tr( "Set Overlap" ), QString::null, 0, this, NULL);
285 connect( a, SIGNAL( activated() ), this, SLOT( setoverlap() ) );
286 a->addTo( file );
287 345
288 file->insertSeparator(); 346 file->insertSeparator();
289 347
290 a = new QAction( tr( "Set Dictionary" ), QString::null, 0, this, NULL); 348 a = new QAction( tr( "Set Dictionary" ), QString::null, 0, this, NULL);
291 connect( a, SIGNAL( activated() ), this, SLOT( settarget() ) ); 349 connect( a, SIGNAL( activated() ), this, SLOT( settarget() ) );
292 a->addTo( file ); 350 a->addTo( file );
293 351
294 a = new QAction( tr( "Two/One Touch" ), QString::null, 0, this, NULL, true ); 352 a = new QAction( tr( "Two/One Touch" ), QString::null, 0, this, NULL, true );
295 connect( a, SIGNAL( toggled(bool) ), this, SLOT( setTwoTouch(bool) ) ); 353 connect( a, SIGNAL( toggled(bool) ), this, SLOT( setTwoTouch(bool) ) );
296 a->setOn(m_twoTouch); 354 a->setOn(m_twoTouch);
297 a->addTo( file ); 355 a->addTo( file );
298 356
299 ag = new QActionGroup(this); 357 ag = new QActionGroup(this);
300 ag->setExclusive(false); 358 ag->setExclusive(false);
301 QPopupMenu *encoding = new QPopupMenu(this); 359 encoding = new QPopupMenu(this);
302 file->insertItem( tr( "Target" ), encoding ); 360 file->insertItem( tr( "Target" ), encoding );
303 361
304 a = new QAction( tr( "Annotation" ), QString::null, 0, ag, NULL, true ); 362 a = new QAction( tr( "Annotation" ), QString::null, 0, ag, NULL, true );
305 connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnAnnotation(bool) ) ); 363 connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnAnnotation(bool) ) );
306 a->setOn(m_doAnnotation); 364 a->setOn(m_doAnnotation);
307 365
308 a = new QAction( tr( "Dictionary" ), QString::null, 0, ag, NULL, true ); 366 a = new QAction( tr( "Dictionary" ), QString::null, 0, ag, NULL, true );
309 connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnDictionary(bool) ) ); 367 connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnDictionary(bool) ) );
310 a->setOn(m_doDictionary); 368 a->setOn(m_doDictionary);
311 369
312 a = new QAction( tr( "Clipboard" ), QString::null, 0, ag, NULL, true ); 370 a = new QAction( tr( "Clipboard" ), QString::null, 0, ag, NULL, true );
313 connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnClipboard(bool) ) ); 371 connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnClipboard(bool) ) );
314 a->setOn(m_doClipboard); 372 a->setOn(m_doClipboard);
315 373
316 ag->addTo(encoding); 374 ag->addTo(encoding);
317 375
318 376
319/* 377/*
320 a = new QAction( tr( "Import" ), QString::null, 0, this, NULL ); 378 a = new QAction( tr( "Import" ), QString::null, 0, this, NULL );
321 connect( a, SIGNAL( activated() ), this, SLOT( importFiles() ) ); 379 connect( a, SIGNAL( activated() ), this, SLOT( importFiles() ) );
322 a->addTo( file ); 380 a->addTo( file );
323*/ 381*/
324 382
325 a = new QAction( tr( "Up" ), Resource::loadPixmap( "up" ), QString::null, 0, this, 0 ); 383 a = new QAction( tr( "Up" ), Resource::loadPixmap( "up" ), QString::null, 0, this, 0 );
326 connect( a, SIGNAL( activated() ), this, SLOT( pageup() ) ); 384 connect( a, SIGNAL( activated() ), this, SLOT( pageup() ) );
327 a->addTo( editBar ); 385 a->addTo( editBar );
328 386
329 a = new QAction( tr( "Down" ), Resource::loadPixmap( "down" ), QString::null, 0, this, 0 ); 387 a = new QAction( tr( "Down" ), Resource::loadPixmap( "down" ), QString::null, 0, this, 0 );
330 connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) ); 388 connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) );
331 a->addTo( editBar ); 389 a->addTo( editBar );
332 390
333 /* 391 /*
334 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); 392 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
335 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); 393 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
336 a->addTo( editBar ); 394 a->addTo( editBar );
337 a->addTo( edit ); 395 a->addTo( edit );
338 */ 396 */
339 397
340// a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); 398// a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
341 a = new QAction( tr( "Find..." ), QString::null, 0, this, NULL); 399 a = new QAction( tr( "Find..." ), QString::null, 0, this, NULL);
342 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); 400 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) );
343 file->insertSeparator(); 401 file->insertSeparator();
344// a->addTo( bar ); 402// a->addTo( bar );
345 a->addTo( file ); 403 a->addTo( file );
346 404
347 405
406 m_fullscreen = false;
407 a = m_actFullscreen = new QAction( tr( "Fullscreen" ), QString::null, 0, this, NULL, true );
408 connect( a, SIGNAL( toggled(bool) ), this, SLOT( setfullscreen(bool) ) );
409 a->setOn(m_fullscreen);
410 a->addTo( file );
411
412 a = new QAction( tr( "Continuous" ), QString::null, 0, ag, NULL, true );
413 connect( a, SIGNAL( toggled(bool) ), this, SLOT( setcontinuous(bool) ) );
414 a->setOn(reader->m_continuousDocument);
415 a->addTo( file );
416
348 a = m_bkmkAvail = new QAction( tr( "Annotation" ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); 417 a = m_bkmkAvail = new QAction( tr( "Annotation" ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
349 connect( a, SIGNAL( activated() ), this, SLOT( showAnnotation() ) ); 418 connect( a, SIGNAL( activated() ), this, SLOT( showAnnotation() ) );
350 a->addTo( bar ); 419 a->addTo( bar );
351 420
352 m_bkmkAvail->setEnabled(false); 421 m_bkmkAvail->setEnabled(false);
353 422
354 423
355 ag = new QActionGroup(this); 424 ag = new QActionGroup(this);
356// ag->setExclusive(false); 425// ag->setExclusive(false);
357 encoding = new QPopupMenu(this); 426 encoding = new QPopupMenu(this);
358 format->insertItem( tr( "Markup" ), encoding ); 427 format->insertItem( tr( "Markup" ), encoding );
359 428
360 a = new QAction( tr( "Auto" ), QString::null, 0, ag, NULL, true ); 429 a = new QAction( tr( "Auto" ), QString::null, 0, ag, NULL, true );
361 a->setOn(reader->bautofmt); 430 a->setOn(reader->bautofmt);
362 connect( a, SIGNAL( toggled(bool) ), this, SLOT( autofmt(bool) ) ); 431 connect( a, SIGNAL( toggled(bool) ), this, SLOT( autofmt(bool) ) );
363 432
364 a = new QAction( tr( "None" ), QString::null, 0, ag, NULL, true ); 433 a = new QAction( tr( "None" ), QString::null, 0, ag, NULL, true );
365 a->setOn(!reader->bautofmt && !(reader->btextfmt || reader->bstriphtml || reader->bpeanut)); 434 a->setOn(!reader->bautofmt && !(reader->btextfmt || reader->bstriphtml || reader->bpeanut));
366// connect( a, SIGNAL( toggled(bool) ), this, SLOT( textfmt(bool) ) ); 435// connect( a, SIGNAL( toggled(bool) ), this, SLOT( textfmt(bool) ) );
367 436
368 a = new QAction( tr( "Text" ), QString::null, 0, ag, NULL, true ); 437 a = new QAction( tr( "Text" ), QString::null, 0, ag, NULL, true );
369 a->setOn(reader->btextfmt); 438 a->setOn(reader->btextfmt);
370 connect( a, SIGNAL( toggled(bool) ), this, SLOT( textfmt(bool) ) ); 439 connect( a, SIGNAL( toggled(bool) ), this, SLOT( textfmt(bool) ) );
371 440
372 a = new QAction( tr( "HTML" ), QString::null, 0, ag, NULL, true ); 441 a = new QAction( tr( "HTML" ), QString::null, 0, ag, NULL, true );
373 a->setOn(reader->bstriphtml); 442 a->setOn(reader->bstriphtml);
374 connect( a, SIGNAL( toggled(bool) ), this, SLOT( striphtml(bool) ) ); 443 connect( a, SIGNAL( toggled(bool) ), this, SLOT( striphtml(bool) ) );
375 444
376 a = new QAction( tr( "Peanut/PML" ), QString::null, 0, ag, NULL, true ); 445 a = new QAction( tr( "Peanut/PML" ), QString::null, 0, ag, NULL, true );
377 a->setOn(reader->bpeanut); 446 a->setOn(reader->bpeanut);
378 connect( a, SIGNAL( toggled(bool) ), this, SLOT( peanut(bool) ) ); 447 connect( a, SIGNAL( toggled(bool) ), this, SLOT( peanut(bool) ) );
379 448
380 ag->addTo(encoding); 449 ag->addTo(encoding);
381 450
382 451
383 452
384 ag = new QActionGroup(this); 453 ag = new QActionGroup(this);
385 ag->setExclusive(false); 454 ag->setExclusive(false);
386 encoding = new QPopupMenu(this); 455 encoding = new QPopupMenu(this);
387 format->insertItem( tr( "Layout" ), encoding ); 456 format->insertItem( tr( "Layout" ), encoding );
388 457
389 a = new QAction( tr( "Strip CR" ), QString::null, 0, ag, NULL, true ); 458 a = new QAction( tr( "Strip CR" ), QString::null, 0, ag, NULL, true );
390 a->setOn(reader->bstripcr); 459 a->setOn(reader->bstripcr);
391 connect( a, SIGNAL( toggled(bool) ), this, SLOT( stripcr(bool) ) ); 460 connect( a, SIGNAL( toggled(bool) ), this, SLOT( stripcr(bool) ) );
392 461
393 a = new QAction( tr( "Dehyphen" ), QString::null, 0, ag, NULL, true ); 462 a = new QAction( tr( "Dehyphen" ), QString::null, 0, ag, NULL, true );
394 a->setOn(reader->bdehyphen); 463 a->setOn(reader->bdehyphen);
395 connect( a, SIGNAL( toggled(bool) ), this, SLOT( dehyphen(bool) ) ); 464 connect( a, SIGNAL( toggled(bool) ), this, SLOT( dehyphen(bool) ) );
396// a->addTo( format ); 465// a->addTo( format );
397 466
467 a = new QAction( tr( "Single Space" ), QString::null, 0, ag, NULL, true );
468 a->setOn(reader->bonespace);
469 connect( a, SIGNAL( toggled(bool) ), this, SLOT( onespace(bool) ) );
470
398 a = new QAction( tr( "Unindent" ), QString::null, 0, ag, NULL, true ); 471 a = new QAction( tr( "Unindent" ), QString::null, 0, ag, NULL, true );
399 connect( a, SIGNAL( toggled(bool) ), this, SLOT( unindent(bool) ) ); 472 connect( a, SIGNAL( toggled(bool) ), this, SLOT( unindent(bool) ) );
400 a->setOn(reader->bunindent); 473 a->setOn(reader->bunindent);
401// a->addTo( format ); 474// a->addTo( format );
402 475
403 a = new QAction( tr( "Re-paragraph" ), QString::null, 0, ag, NULL, true ); 476 a = new QAction( tr( "Re-paragraph" ), QString::null, 0, ag, NULL, true );
404 connect( a, SIGNAL( toggled(bool) ), this, SLOT( repara(bool) ) ); 477 connect( a, SIGNAL( toggled(bool) ), this, SLOT( repara(bool) ) );
405 a->setOn(reader->brepara); 478 a->setOn(reader->brepara);
406// a->addTo( format ); 479// a->addTo( format );
407 480
408 a = new QAction( tr( "Double Space" ), QString::null, 0, ag, NULL, true ); 481 a = new QAction( tr( "Double Space" ), QString::null, 0, ag, NULL, true );
409 connect( a, SIGNAL( toggled(bool) ), this, SLOT( dblspce(bool) ) ); 482 connect( a, SIGNAL( toggled(bool) ), this, SLOT( dblspce(bool) ) );
410 a->setOn(reader->bdblspce); 483 a->setOn(reader->bdblspce);
411// a->addTo( format ); 484// a->addTo( format );
412 485
413 a = new QAction( tr( "Indent+" ), QString::null, 0, ag, NULL ); 486 a = new QAction( tr( "Indent+" ), QString::null, 0, ag, NULL );
414 connect( a, SIGNAL( activated() ), this, SLOT( indentplus() ) ); 487 connect( a, SIGNAL( activated() ), this, SLOT( indentplus() ) );
415// a->addTo( format ); 488// a->addTo( format );
416 489
417 a = new QAction( tr( "Indent-" ), QString::null, 0, ag, NULL ); 490 a = new QAction( tr( "Indent-" ), QString::null, 0, ag, NULL );
418 connect( a, SIGNAL( activated() ), this, SLOT( indentminus() ) ); 491 connect( a, SIGNAL( activated() ), this, SLOT( indentminus() ) );
419 492#ifdef REPALM
493 a = new QAction( tr( "Repalm" ), QString::null, 0, ag, NULL, true );
494 a->setOn(reader->brepalm);
495 connect( a, SIGNAL( toggled(bool) ), this, SLOT( repalm(bool) ) );
496#endif
420 a = new QAction( tr( "Remap" ), QString::null, 0, ag, NULL, true ); 497 a = new QAction( tr( "Remap" ), QString::null, 0, ag, NULL, true );
421 connect( a, SIGNAL( toggled(bool) ), this, SLOT( remap(bool) ) ); 498 connect( a, SIGNAL( toggled(bool) ), this, SLOT( remap(bool) ) );
422 a->setOn(reader->bremap); 499 a->setOn(reader->bremap);
423 500
424 a = new QAction( tr( "Embolden" ), QString::null, 0, ag, NULL, true ); 501 a = new QAction( tr( "Embolden" ), QString::null, 0, ag, NULL, true );
425 connect( a, SIGNAL( toggled(bool) ), this, SLOT( embolden(bool) ) ); 502 connect( a, SIGNAL( toggled(bool) ), this, SLOT( embolden(bool) ) );
426 a->setOn(reader->bmakebold); 503 a->setOn(reader->bmakebold);
427 504
428 ag->addTo(encoding); 505 ag->addTo(encoding);
429 506
430 // a = new QAction( tr( "Zoom" ), QString::null, 0, this, NULL, true ); 507 // a = new QAction( tr( "Zoom" ), QString::null, 0, this, NULL, true );
431 // a = new QAction( tr( "Zoom" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); 508 // a = new QAction( tr( "Zoom" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 );
432 a = new QAction( tr( "Zoom" ), QString::null, 0, this);
433 connect( a, SIGNAL( activated() ), this, SLOT( TBDzoom() ) );
434 format->insertSeparator(); 509 format->insertSeparator();
510 a = new QAction( tr( "Zoom In" ), QString::null, 0, this);
511 connect( a, SIGNAL( activated() ), this, SLOT( zoomin() ) );
512 a->addTo( format );
513 a = new QAction( tr( "Zoom Out" ), QString::null, 0, this);
514 connect( a, SIGNAL( activated() ), this, SLOT( zoomout() ) );
435 a->addTo( format ); 515 a->addTo( format );
436 // a->addTo( editBar ); 516 // a->addTo( editBar );
517 format->insertSeparator();
437 518
438 519
439 a = new QAction( tr( "Ideogram/Word" ), QString::null, 0, this, NULL, true ); 520 a = new QAction( tr( "Ideogram/Word" ), QString::null, 0, this, NULL, true );
440 connect( a, SIGNAL( toggled(bool) ), this, SLOT( monospace(bool) ) ); 521 connect( a, SIGNAL( toggled(bool) ), this, SLOT( monospace(bool) ) );
441 a->setOn(reader->m_bMonoSpaced); 522 a->setOn(reader->m_bMonoSpaced);
442 format->insertSeparator();
443 a->addTo( format ); 523 a->addTo( format );
444 524
445 a = new QAction( tr( "Set width" ), QString::null, 0, this, NULL); 525 a = new QAction( tr( "Set width" ), QString::null, 0, this, NULL);
446 connect( a, SIGNAL( activated() ), this, SLOT( setspacing() ) ); 526 connect( a, SIGNAL( activated() ), this, SLOT( setspacing() ) );
447 a->addTo( format ); 527 a->addTo( format );
448 528
449 encoding = new QPopupMenu(this); 529 encoding = new QPopupMenu(this);
450// format->insertSeparator(); 530// format->insertSeparator();
451 format->insertItem( tr( "Encoding" ), encoding ); 531 format->insertItem( tr( "Encoding" ), encoding );
452 532
453 ag = new QActionGroup(this); 533 ag = new QActionGroup(this);
454 534
455 m_EncodingAction[0] = new QAction( tr( "Ascii" ), QString::null, 0, ag, NULL, true ); 535 m_EncodingAction[0] = new QAction( tr( "Ascii" ), QString::null, 0, ag, NULL, true );
456 536
457 m_EncodingAction[1] = new QAction( tr( "UTF-8" ), QString::null, 0, ag, NULL, true ); 537 m_EncodingAction[1] = new QAction( tr( "UTF-8" ), QString::null, 0, ag, NULL, true );
458 538
459 m_EncodingAction[2] = new QAction( tr( "UCS-2(BE)" ), QString::null, 0, ag, NULL, true ); 539 m_EncodingAction[2] = new QAction( tr( "UCS-2(BE)" ), QString::null, 0, ag, NULL, true );
460 540
461 m_EncodingAction[3] = new QAction( tr( "USC-2(LE)" ), QString::null, 0, ag, NULL, true ); 541 m_EncodingAction[3] = new QAction( tr( "USC-2(LE)" ), QString::null, 0, ag, NULL, true );
462 542
463 m_EncodingAction[4] = new QAction( tr( "Palm" ), QString::null, 0, ag, NULL, true ); 543 m_EncodingAction[4] = new QAction( tr( "Palm" ), QString::null, 0, ag, NULL, true );
464 544
465 m_EncodingAction[5] = new QAction( tr( "Windows(1252)" ), QString::null, 0, ag, NULL, true ); 545 m_EncodingAction[5] = new QAction( tr( "Windows(1252)" ), QString::null, 0, ag, NULL, true );
466 546
467 ag->addTo(encoding); 547 ag->addTo(encoding);
468 548
469 connect(ag, SIGNAL( selected(QAction*) ), this, SLOT( encodingSelected(QAction*) ) ); 549 connect(ag, SIGNAL( selected(QAction*) ), this, SLOT( encodingSelected(QAction*) ) );
470 550
471 a = new QAction( tr( "Set Font" ), QString::null, 0, this); 551 a = new QAction( tr( "Set Font" ), QString::null, 0, this);
472 connect( a, SIGNAL( activated() ), this, SLOT( setfont() ) ); 552 connect( a, SIGNAL( activated() ), this, SLOT( setfont() ) );
473 format->insertSeparator(); 553 format->insertSeparator();
474 a->addTo( format ); 554 a->addTo( format );
475 555
476 QPopupMenu *marks = new QPopupMenu( this ); 556 QPopupMenu *marks = new QPopupMenu( this );
477 557
478 a = new QAction( tr( "Mark" ), QString::null, 0, this, NULL); 558 a = new QAction( tr( "Mark" ), QString::null, 0, this, NULL);
479 connect( a, SIGNAL( activated() ), this, SLOT( addbkmk() ) ); 559 connect( a, SIGNAL( activated() ), this, SLOT( addbkmk() ) );
480 a->addTo( marks ); 560 a->addTo( marks );
481 561
482 a = new QAction( tr( "Annotate" ), QString::null, 0, this, NULL); 562 a = new QAction( tr( "Annotate" ), QString::null, 0, this, NULL);
483 connect( a, SIGNAL( activated() ), this, SLOT( addanno() ) ); 563 connect( a, SIGNAL( activated() ), this, SLOT( addanno() ) );
484 a->addTo( marks ); 564 a->addTo( marks );
485 565
486 a = new QAction( tr( "Goto" ), QString::null, 0, this, NULL, false ); 566 a = new QAction( tr( "Goto" ), QString::null, 0, this, NULL, false );
487 connect( a, SIGNAL( activated() ), this, SLOT( do_gotomark() ) ); 567 connect( a, SIGNAL( activated() ), this, SLOT( do_gotomark() ) );
488 a->addTo( marks ); 568 a->addTo( marks );
489 569
490 a = new QAction( tr( "Delete" ), QString::null, 0, this, NULL); 570 a = new QAction( tr( "Delete" ), QString::null, 0, this, NULL);
491 connect( a, SIGNAL( activated() ), this, SLOT( do_delmark() ) ); 571 connect( a, SIGNAL( activated() ), this, SLOT( do_delmark() ) );
492 a->addTo( marks ); 572 a->addTo( marks );
493 573
494 a = new QAction( tr( "Autogen" ), QString::null, 0, this, NULL, false ); 574 a = new QAction( tr( "Autogen" ), QString::null, 0, this, NULL, false );
495 connect( a, SIGNAL( activated() ), this, SLOT( do_autogen() ) ); 575 connect( a, SIGNAL( activated() ), this, SLOT( do_autogen() ) );
496 marks->insertSeparator(); 576 marks->insertSeparator();
497 a->addTo( marks ); 577 a->addTo( marks );
498 578
499 a = new QAction( tr( "Clear" ), QString::null, 0, this, NULL); 579 a = new QAction( tr( "Clear" ), QString::null, 0, this, NULL);
500 connect( a, SIGNAL( activated() ), this, SLOT( clearBkmkList() ) ); 580 connect( a, SIGNAL( activated() ), this, SLOT( clearBkmkList() ) );
501 a->addTo( marks ); 581 a->addTo( marks );
502 582
503 a = new QAction( tr( "Save" ), QString::null, 0, this, NULL ); 583 a = new QAction( tr( "Save" ), QString::null, 0, this, NULL );
504 connect( a, SIGNAL( activated() ), this, SLOT( savebkmks() ) ); 584 connect( a, SIGNAL( activated() ), this, SLOT( savebkmks() ) );
505 a->addTo( marks ); 585 a->addTo( marks );
506 586
507 a = new QAction( tr( "Tidy" ), QString::null, 0, this, NULL); 587 a = new QAction( tr( "Tidy" ), QString::null, 0, this, NULL);
508 connect( a, SIGNAL( activated() ), this, SLOT( listBkmkFiles() ) ); 588 connect( a, SIGNAL( activated() ), this, SLOT( listBkmkFiles() ) );
509 marks->insertSeparator(); 589 marks->insertSeparator();
510 a->addTo( marks ); 590 a->addTo( marks );
511 591
512 a = new QAction( tr( "Start Block" ), QString::null, 0, this, NULL); 592 a = new QAction( tr( "Start Block" ), QString::null, 0, this, NULL);
513 connect( a, SIGNAL( activated() ), this, SLOT( editMark() ) ); 593 connect( a, SIGNAL( activated() ), this, SLOT( editMark() ) );
514 marks->insertSeparator(); 594 marks->insertSeparator();
515 a->addTo( marks ); 595 a->addTo( marks );
516 596
517 a = new QAction( tr( "Copy Block" ), QString::null, 0, this, NULL); 597 a = new QAction( tr( "Copy Block" ), QString::null, 0, this, NULL);
518 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); 598 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
519 a->addTo( marks ); 599 a->addTo( marks );
520 600
521 601
522 mb->insertItem( tr( "File" ), file ); 602 mb->insertItem( tr( "File" ), file );
523 // mb->insertItem( tr( "Edit" ), edit ); 603 // mb->insertItem( tr( "Edit" ), edit );
524 mb->insertItem( tr( "Format" ), format ); 604 mb->insertItem( tr( "Format" ), format );
525 mb->insertItem( tr( "Marks" ), marks ); 605 mb->insertItem( tr( "Marks" ), marks );
526 606
527 searchBar = new QFloatBar( "Search", this, QMainWindow::Top, TRUE ); 607 searchBar = new QFloatBar( "Search", this, QMainWindow::Top, TRUE );
528 608
529 searchBar->setHorizontalStretchable( TRUE ); 609 searchBar->setHorizontalStretchable( TRUE );
530 610
531 connect(searchBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() )); 611 connect(searchBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() ));
532 612
533 searchEdit = new QLineEdit( searchBar, "searchEdit" ); 613 searchEdit = new QLineEdit( searchBar, "searchEdit" );
534// QFont f("unifont", 16 /*, QFont::Bold*/); 614// QFont f("unifont", 16 /*, QFont::Bold*/);
535// searchEdit->setFont( f ); 615// searchEdit->setFont( f );
536 searchBar->setStretchableWidget( searchEdit ); 616 searchBar->setStretchableWidget( searchEdit );
537 617
538#ifdef __ISEARCH 618#ifdef __ISEARCH
539 connect( searchEdit, SIGNAL( textChanged( const QString & ) ), 619 connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
540 this, SLOT( search( const QString& ) ) ); 620 this, SLOT( search( const QString& ) ) );
541#else 621#else
542 connect( searchEdit, SIGNAL( returnPressed( ) ), 622 connect( searchEdit, SIGNAL( returnPressed( ) ),
543 this, SLOT( search( ) ) ); 623 this, SLOT( search( ) ) );
544#endif 624#endif
545 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); 625 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
546 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); 626 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
547 a->addTo( searchBar ); 627 a->addTo( searchBar );
548 628
549 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 629 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
550 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); 630 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
551 a->addTo( searchBar ); 631 a->addTo( searchBar );
552 632
553 searchBar->hide(); 633 searchBar->hide();
554 634
555 regBar = new QFloatBar( "Autogen", this, QMainWindow::Top, TRUE ); 635 regBar = new QFloatBar( "Autogen", this, QMainWindow::Top, TRUE );
556 connect(regBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() )); 636 connect(regBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() ));
557 637
558 regBar->setHorizontalStretchable( TRUE ); 638 regBar->setHorizontalStretchable( TRUE );
559 639
560 regEdit = new QLineEdit( regBar, "regEdit" ); 640 regEdit = new QLineEdit( regBar, "regEdit" );
561// regEdit->setFont( f ); 641// regEdit->setFont( f );
562 642
563 regBar->setStretchableWidget( regEdit ); 643 regBar->setStretchableWidget( regEdit );
564 644
565 connect( regEdit, SIGNAL( returnPressed( ) ), 645 connect( regEdit, SIGNAL( returnPressed( ) ),
566 this, SLOT( do_regaction() ) ); 646 this, SLOT( do_regaction() ) );
567 647
568 a = new QAction( tr( "Do Reg" ), Resource::loadPixmap( "enter" ), QString::null, 0, this, 0 ); 648 a = new QAction( tr( "Do Reg" ), Resource::loadPixmap( "enter" ), QString::null, 0, this, 0 );
569 connect( a, SIGNAL( activated() ), this, SLOT( do_regaction() ) ); 649 connect( a, SIGNAL( activated() ), this, SLOT( do_regaction() ) );
570 a->addTo( regBar ); 650 a->addTo( regBar );
571 651
572 a = new QAction( tr( "Close Edit" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 652 a = new QAction( tr( "Close Edit" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
573 connect( a, SIGNAL( activated() ), this, SLOT( regClose() ) ); 653 connect( a, SIGNAL( activated() ), this, SLOT( regClose() ) );
574 a->addTo( regBar ); 654 a->addTo( regBar );
575 655
576 regBar->hide(); 656 regBar->hide();
577 657
578 m_fontBar = new QToolBar( "Autogen", this, QMainWindow::Top, TRUE ); 658 m_fontBar = new QToolBar( "Autogen", this, QMainWindow::Top, TRUE );
579 659
580 m_fontBar->setHorizontalStretchable( TRUE ); 660 m_fontBar->setHorizontalStretchable( TRUE );
581 661
662 qDebug("Font selector");
582 m_fontSelector = new QComboBox(false, m_fontBar); 663 m_fontSelector = new QComboBox(false, m_fontBar);
583 m_fontBar->setStretchableWidget( m_fontSelector ); 664 m_fontBar->setStretchableWidget( m_fontSelector );
584 { 665 {
585 FontDatabase f; 666 FontDatabase f;
586 QStringList flist = f.families(); 667 QStringList flist = f.families();
587 m_fontSelector->insertStringList(flist); 668 m_fontSelector->insertStringList(flist);
588 669
589 bool realfont = false; 670 bool realfont = false;
590 for (QStringList::Iterator nm = flist.begin(); nm != flist.end(); nm++) 671 for (QStringList::Iterator nm = flist.begin(); nm != flist.end(); nm++)
591 { 672 {
592 if (reader->m_fontname == *nm) 673 if (reader->m_fontname == *nm)
593 { 674 {
594 realfont = true; 675 realfont = true;
595 break; 676 }
596 } 677 if (*nm == "courier") reader->m_fontControl.hasCourier(true);
597 } 678 }
598 if (!realfont) reader->m_fontname = flist[0]; 679 if (!realfont) reader->m_fontname = flist[0];
599 } // delete the FontDatabase!!! 680 } // delete the FontDatabase!!!
600 681
601 connect( m_fontSelector, SIGNAL( activated(const QString& ) ), 682 connect( m_fontSelector, SIGNAL( activated(const QString& ) ),
602 this, SLOT( do_setfont(const QString&) ) ); 683 this, SLOT( do_setfont(const QString&) ) );
603 684
604 m_fontBar->hide(); 685 m_fontBar->hide();
605 m_fontVisible = false; 686 m_fontVisible = false;
606 687
607 connect(qApp, SIGNAL( appMessage(const QCString&, const QByteArray& ) ), 688 connect(qApp, SIGNAL( appMessage(const QCString&, const QByteArray& ) ),
608 this, SLOT( msgHandler(const QCString&, const QByteArray&) ) ); 689 this, SLOT( msgHandler(const QCString&, const QByteArray&) ) );
609
610 690
691 qDebug("Initing");
611 reader->init(); 692 reader->init();
612 if (!reader->m_lastfile.isEmpty()) 693 qDebug("Inited");
613 {
614 openFile( reader->m_lastfile );
615 doc = new DocLnk(reader->m_lastfile);
616 }
617 m_EncodingAction[reader->m_encd]->setOn(true); 694 m_EncodingAction[reader->m_encd]->setOn(true);
618 m_buttonAction[m_spaceTarget]->setOn(true); 695 m_buttonAction[m_spaceTarget]->setOn(true);
696 qDebug("fonting");
619 do_setfont(reader->m_fontname); 697 do_setfont(reader->m_fontname);
620} 698 if (!reader->m_lastfile.isEmpty())
699 {
700 qDebug("doclnk");
701 //doc = new DocLnk(reader->m_lastfile);
702 qDebug("doclnk done");
703 if (pOpenlist != NULL)
704 {
705
706/*
707 int ind = 0;
708 Bkmk* p = (*pOpenlist)[ind];
709 while (p != NULL && toQString(CFiledata(p->anno()).name()) != reader->m_lastfile)
710 {
711 p = (*pOpenlist)[++ind];
712 }
713*/
714 Bkmk* p = NULL;
715 for (CList<Bkmk>::iterator iter = pOpenlist->begin(); iter != pOpenlist->end(); iter++)
716 {
717 p = iter.pContent();
718 if (toQString(CFiledata(p->anno()).name()) == reader->m_lastfile)
719 {
720 break;
721 }
722 qDebug("Item:%s", (const char*)toQString(CFiledata(p->anno()).name()));
723 p = NULL;
724 }
725 if (p != NULL)
726 {
727 qDebug("openfrombkmk");
728 openfrombkmk(p);
729 }
730 else
731 {
732 qDebug("openfile");
733 openFile( reader->m_lastfile );
734 }
735 }
736 else
737 {
738 qDebug("Openfile 2");
739 if (!reader->m_lastfile.isNull())
740 openFile( reader->m_lastfile );
741 }
742 }
743 qApp->processEvents();
744 reader->bDoUpdates = true;
745 reader->update();
746 qDebug("finished update");
747}
748
749void QTReaderApp::suspend() { reader->suspend(); }
621 750
622void QTReaderApp::msgHandler(const QCString& _msg, const QByteArray& _data) 751void QTReaderApp::msgHandler(const QCString& _msg, const QByteArray& _data)
623{ 752{
624 QString msg = QString::fromUtf8(_msg); 753 QString msg = QString::fromUtf8(_msg);
625 754
626// qDebug("Received:%s", (const char*)msg); 755// qDebug("Received:%s", (const char*)msg);
627 756
628 QDataStream stream( _data, IO_ReadOnly ); 757 QDataStream stream( _data, IO_ReadOnly );
629 if ( msg == "info(QString)" ) 758 if ( msg == "info(QString)" )
630 { 759 {
631 QString info; 760 QString info;
632 stream >> info; 761 stream >> info;
633 QMessageBox::information(this, "OpieReader", info); 762 QMessageBox::information(this, PROGNAME, info);
634 } 763 }
635 else if ( msg == "warn(QString)" ) 764 else if ( msg == "warn(QString)" )
636 { 765 {
637 QString info; 766 QString info;
638 stream >> info; 767 stream >> info;
639 QMessageBox::warning(this, "OpieReader", info); 768 QMessageBox::warning(this, PROGNAME, info);
640 } 769 }
641 770
642 771
643 else if ( msg == "exit()" ) 772 else if ( msg == "exit()" )
644 { 773 {
645 m_dontSave = true; 774 m_dontSave = true;
646 close(); 775 close();
647 } 776 }
648 else if ( msg == "pageDown()" ) 777 else if ( msg == "pageDown()" )
649 { 778 {
650 reader->dopagedn(); 779 reader->dopagedn();
651 } 780 }
652 else if ( msg == "pageUp()" ) 781 else if ( msg == "pageUp()" )
653 { 782 {
654 reader->dopageup(); 783 reader->dopageup();
655 } 784 }
656 else if ( msg == "lineDown()" ) 785 else if ( msg == "lineDown()" )
657 { 786 {
658 reader->lineDown(); 787 reader->lineDown();
659 } 788 }
660 else if ( msg == "lineUp()" ) 789 else if ( msg == "lineUp()" )
661 { 790 {
662 reader->lineUp(); 791 reader->lineUp();
663 } 792 }
664 else if ( msg == "showText()" ) 793 else if ( msg == "showText()" )
665 { 794 {
666 showEditTools(); 795 showEditTools();
667 } 796 }
668 else if ( msg == "File/Open(QString)" ) 797 else if ( msg == "File/Open(QString)" )
669 { 798 {
670 QString info; 799 QString info;
671 stream >> info; 800 stream >> info;
672 openFile( info ); 801 openFile( info );
673 } 802 }
674 else if ( msg == "File/Info()" ) 803 else if ( msg == "File/Info()" )
675 { 804 {
676 showinfo(); 805 showinfo();
677 } 806 }
678 else if ( msg == "File/Start Block()" ) 807 else if ( msg == "File/Start Block()" )
679 { 808 {
680 editMark(); 809 editMark();
681 } 810 }
682 else if ( msg == "File/Copy Block()" ) 811 else if ( msg == "File/Copy Block()" )
683 { 812 {
684 editCopy(); 813 editCopy();
685 } 814 }
686 else if ( msg == "File/Scroll(int)" ) 815 else if ( msg == "File/Scroll(int)" )
687 { 816 {
688 int info; 817 int info;
689 stream >> info; 818 stream >> info;
690 autoScroll(info); 819 autoScroll(info);
691 } 820 }
692 else if ( msg == "File/Jump(int)" ) 821 else if ( msg == "File/Jump(int)" )
693 { 822 {
694 int info; 823 int info;
695 stream >> info; 824 stream >> info;
696 reader->locate(info); 825 reader->locate(info);
697 } 826 }
698 else if ( msg == "File/Page/Line Scroll(int)" ) 827 else if ( msg == "File/Page/Line Scroll(int)" )
699 { 828 {
700 int info; 829 int info;
701 stream >> info; 830 stream >> info;
702 pagemode(info); 831 pagemode(info);
703 } 832 }
704 else if ( msg == "File/Set Overlap(int)" ) 833 else if ( msg == "File/Set Overlap(int)" )
705 { 834 {
706 int info; 835 int info;
707 stream >> info; 836 stream >> info;
708 reader->m_overlap = info; 837 reader->m_overlap = info;
709 } 838 }
710 else if ( msg == "File/Set Dictionary(QString)" ) 839 else if ( msg == "File/Set Dictionary(QString)" )
711 { 840 {
712 QString info; 841 QString info;
713 stream >> info; 842 stream >> info;
714 do_settarget(info); 843 do_settarget(info);
715 } 844 }
716 else if ( msg == "File/Two/One Touch(int)" ) 845 else if ( msg == "File/Two/One Touch(int)" )
717 { 846 {
718 int info; 847 int info;
719 stream >> info; 848 stream >> info;
720 setTwoTouch(info); 849 setTwoTouch(info);
721 } 850 }
722 else if ( msg == "Target/Annotation(int)" ) 851 else if ( msg == "Target/Annotation(int)" )
723 { 852 {
724 int info; 853 int info;
725 stream >> info; 854 stream >> info;
726 OnAnnotation(info); 855 OnAnnotation(info);
727 } 856 }
728 else if ( msg == "Target/Dictionary(int)" ) 857 else if ( msg == "Target/Dictionary(int)" )
729 { 858 {
730 int info; 859 int info;
731 stream >> info; 860 stream >> info;
732 OnDictionary(info); 861 OnDictionary(info);
733 } 862 }
734 else if ( msg == "Target/Clipboard(int)" ) 863 else if ( msg == "Target/Clipboard(int)" )
735 { 864 {
736 int info; 865 int info;
737 stream >> info; 866 stream >> info;
738 OnClipboard(info); 867 OnClipboard(info);
739 } 868 }
740 else if ( msg == "File/Find(QString)" ) 869 else if ( msg == "File/Find(QString)" )
741 { 870 {
742 QString info; 871 QString info;
743 stream >> info; 872 stream >> info;
744 QRegExp arg(info); 873 QRegExp arg(info);
745 size_t pos = reader->pagelocate(); 874 size_t pos = reader->pagelocate();
746 size_t start = pos; 875 size_t start = pos;
747 CDrawBuffer test(&(reader->m_fontControl)); 876 CDrawBuffer test(&(reader->m_fontControl));
748 reader->buffdoc.getline(&test,reader->width()); 877 reader->buffdoc.getline(&test,reader->width());
749 while (arg.match(toQString(test.data())) == -1) 878 while (arg.match(toQString(test.data())) == -1)
750 { 879 {
751 pos = reader->locate(); 880 pos = reader->locate();
752 if (!reader->buffdoc.getline(&test,reader->width())) 881 if (!reader->buffdoc.getline(&test,reader->width()))
753 { 882 {
754 QMessageBox::information(this, "OpieReader", QString("Can't find\n")+info); 883 QMessageBox::information(this, PROGNAME, QString("Can't find\n")+info);
755 pos = start; 884 pos = start;
756 break; 885 break;
757 } 886 }
758 } 887 }
759 reader->locate(pos); 888 reader->locate(pos);
760 } 889 }
761 else if ( msg == "Layout/Strip CR(int)" ) 890 else if ( msg == "Layout/Strip CR(int)" )
762 { 891 {
763 int info; 892 int info;
764 stream >> info; 893 stream >> info;
765 stripcr(info); 894 stripcr(info);
895 }
896 else if ( msg == "Layout/Single Space" )
897 {
898 int info;
899 stream >> info;
900 onespace(info);
901 }
902#ifdef REPALM
903 else if ( msg == "Layout/Repalm(int)" )
904 {
905 int info;
906 stream >> info;
907 repalm(info);
766 } 908 }
909#endif
767 else if ( msg == "Markup/Auto(int)" ) 910 else if ( msg == "Markup/Auto(int)" )
768 { 911 {
769 int info; 912 int info;
770 stream >> info; 913 stream >> info;
771 autofmt(info); 914 autofmt(info);
772 } 915 }
773 else if ( msg == "Markup/Text(int)" ) 916 else if ( msg == "Markup/Text(int)" )
774 { 917 {
775 int info; 918 int info;
776 stream >> info; 919 stream >> info;
777 textfmt(info); 920 textfmt(info);
778 } 921 }
779 else if ( msg == "Markup/HTML(int)" ) 922 else if ( msg == "Markup/HTML(int)" )
780 { 923 {
781 int info; 924 int info;
782 stream >> info; 925 stream >> info;
783 striphtml(info); 926 striphtml(info);
784 } 927 }
785 else if ( msg == "Markup/Peanut(int)" ) 928 else if ( msg == "Markup/Peanut(int)" )
786 { 929 {
787 int info; 930 int info;
788 stream >> info; 931 stream >> info;
789 peanut(info); 932 peanut(info);
790 } 933 }
791 else if ( msg == "Layout/Dehyphen(int)" ) 934 else if ( msg == "Layout/Dehyphen(int)" )
792 { 935 {
793 int info; 936 int info;
794 stream >> info; 937 stream >> info;
795 dehyphen(info); 938 dehyphen(info);
796 } 939 }
797 else if ( msg == "Layout/Unindent(int)" ) 940 else if ( msg == "Layout/Unindent(int)" )
798 { 941 {
799 int info; 942 int info;
800 stream >> info; 943 stream >> info;
801 unindent(info); 944 unindent(info);
802 } 945 }
803 else if ( msg == "Layout/Re-paragraph(int)" ) 946 else if ( msg == "Layout/Re-paragraph(int)" )
804 { 947 {
805 int info; 948 int info;
806 stream >> info; 949 stream >> info;
807 repara(info); 950 repara(info);
808 } 951 }
809 else if ( msg == "Layout/Double Space(int)" ) 952 else if ( msg == "Layout/Double Space(int)" )
810 { 953 {
811 int info; 954 int info;
812 stream >> info; 955 stream >> info;
813 dblspce(info); 956 dblspce(info);
814 } 957 }
815 else if ( msg == "Layout/Indent(int)" ) 958 else if ( msg == "Layout/Indent(int)" )
816 { 959 {
817 int info; 960 int info;
818 stream >> info; 961 stream >> info;
819 reader->bindenter = info; 962 reader->bindenter = info;
820 reader->setfilter(reader->getfilter()); 963 reader->setfilter(reader->getfilter());
821 } 964 }
822 else if ( msg == "Layout/Remap(int)" ) 965 else if ( msg == "Layout/Remap(int)" )
823 { 966 {
824 int info; 967 int info;
825 stream >> info; 968 stream >> info;
826 remap(info); 969 remap(info);
827 } 970 }
828 else if ( msg == "Layout/Embolden(int)" ) 971 else if ( msg == "Layout/Embolden(int)" )
829 { 972 {
830 int info; 973 int info;
831 stream >> info; 974 stream >> info;
832 embolden(info); 975 embolden(info);
833 } 976 }
834 else if ( msg == "Format/Ideogram/Word(int)" ) 977 else if ( msg == "Format/Ideogram/Word(int)" )
835 { 978 {
836 int info; 979 int info;
837 stream >> info; 980 stream >> info;
838 monospace(info); 981 monospace(info);
839 } 982 }
840 else if ( msg == "Format/Set width(int)" ) 983 else if ( msg == "Format/Set width(int)" )
841 { 984 {
842 int info; 985 int info;
843 stream >> info; 986 stream >> info;
844 reader->m_charpc = info; 987 reader->m_charpc = info;
845 reader->setfont(); 988 reader->setfont();
846 reader->refresh(); 989 reader->refresh();
847 } 990 }
848 else if ( msg == "Format/Encoding(QString)" ) 991 else if ( msg == "Format/Encoding(QString)" )
849 { 992 {
850 QString info; 993 QString info;
851 stream >> info; 994 stream >> info;
852 reader->setencoding(EncNameToInt(info)); 995 reader->setencoding(EncNameToInt(info));
853 } 996 }
854 else if ( msg == "Format/Set Font(QString,int)" ) 997 else if ( msg == "Format/Set Font(QString,int)" )
855 { 998 {
856 QString fontname; 999 QString fontname;
857 int size; 1000 int size;
858 stream >> fontname; 1001 stream >> fontname;
859 stream >> size; 1002 stream >> size;
860 setfontHelper(fontname, size); 1003 setfontHelper(fontname, size);
861 } 1004 }
862 else if ( msg == "Marks/Autogen(QString)" ) 1005 else if ( msg == "Marks/Autogen(QString)" )
863 { 1006 {
864 QString info; 1007 QString info;
865 stream >> info; 1008 stream >> info;
866 do_autogen(info); 1009 do_autogen(info);
867 } 1010 }
868} 1011}
869 1012
870ActionTypes QTReaderApp::ActNameToInt(const QString& _enc) 1013ActionTypes QTReaderApp::ActNameToInt(const QString& _enc)
871{ 1014{
872 for (int i = 0; i < MAX_ACTIONS; i++) 1015 for (int i = 0; i < MAX_ACTIONS; i++)
873 { 1016 {
874 if (m_buttonAction[i]->text() == _enc) return (ActionTypes)i; 1017 if (m_buttonAction[i]->text() == _enc) return (ActionTypes)i;
875 } 1018 }
876 return cesAutoScroll; 1019 return cesAutoScroll;
877} 1020}
878 1021
1022void QTReaderApp::setfullscreen(bool sfs)
1023{
1024 reader->bDoUpdates = false;
1025 m_fullscreen = sfs;
1026 showEditTools();
1027 qApp->processEvents();
1028 reader->bDoUpdates = true;
1029 reader->update();
1030}
1031
1032void QTReaderApp::setcontinuous(bool sfs)
1033{
1034 reader->setContinuous(sfs);
1035 reader->refresh();
1036}
1037
879int QTReaderApp::EncNameToInt(const QString& _enc) 1038int QTReaderApp::EncNameToInt(const QString& _enc)
880{ 1039{
881 for (int i = 0; i < MAX_ENCODING; i++) 1040 for (int i = 0; i < MAX_ENCODING; i++)
882 { 1041 {
883 if (m_EncodingAction[i]->text() == _enc) return i; 1042 if (m_EncodingAction[i]->text() == _enc) return i;
884 } 1043 }
885 return 0; 1044 return 0;
886/* 1045/*
887 if (_enc == "Ascii") return 0; 1046 if (_enc == "Ascii") return 0;
888 if (_enc == "UTF-8") return 1; 1047 if (_enc == "UTF-8") return 1;
889 if (_enc == "UCS-2(BE)") return 2; 1048 if (_enc == "UCS-2(BE)") return 2;
890 if (_enc == "USC-2(LE)") return 3; 1049 if (_enc == "USC-2(LE)") return 3;
891*/ 1050*/
892} 1051}
893 1052
894void QTReaderApp::encodingSelected(QAction* _a) 1053void QTReaderApp::encodingSelected(QAction* _a)
895{ 1054{
896// qDebug("es:%x : %s", _a, (const char *)(_a->text())); 1055// qDebug("es:%x : %s", _a, (const char *)(_a->text()));
897 reader->setencoding(EncNameToInt(_a->text())); 1056 reader->setencoding(EncNameToInt(_a->text()));
898} 1057}
899 1058
900void QTReaderApp::buttonActionSelected(QAction* _a) 1059void QTReaderApp::buttonActionSelected(QAction* _a)
901{ 1060{
902// qDebug("es:%x : %s (%u)", _a, (const char *)(_a->text()), ActNameToInt(_a->text())); 1061// qDebug("es:%x : %s (%u)", _a, (const char *)(_a->text()), ActNameToInt(_a->text()));
903 m_spaceTarget = ActNameToInt(_a->text()); 1062 m_spaceTarget = ActNameToInt(_a->text());
904} 1063}
905 1064
906QTReaderApp::~QTReaderApp() 1065QTReaderApp::~QTReaderApp()
907{ 1066{
908} 1067}
909 1068
910void QTReaderApp::autoScroll(bool _b) 1069void QTReaderApp::autoScroll(bool _b)
911{ 1070{
912 reader->setautoscroll(_b); 1071 reader->setautoscroll(_b);
1072 setScrollState(reader->m_autoScroll);
913} 1073}
914 1074
915void QTReaderApp::TBD() 1075void QTReaderApp::zoomin()
916{ 1076{
917 QMessageBox::information(this, "OpieReader", "Not yet implemented", 1); 1077 reader->zoomin();
918} 1078}
919 1079
920void QTReaderApp::TBDzoom() 1080void QTReaderApp::zoomout()
921{ 1081{
922 QMessageBox::information(this, "OpieReader", "Zooming is done interactively\nTry left/right cursor keys", 1); 1082 reader->zoomout();
923} 1083}
924 1084
925void QTReaderApp::clearBkmkList() 1085void QTReaderApp::clearBkmkList()
926{ 1086{
927 delete pBkmklist; 1087 delete pBkmklist;
928 pBkmklist = NULL; 1088 pBkmklist = NULL;
929 m_fBkmksChanged = false; 1089 m_fBkmksChanged = false;
1090}
1091
1092void QTReaderApp::fileClose()
1093{
1094 if (pOpenlist != NULL)
1095 {
1096 int ind = 0;
1097 Bkmk* p = (*pOpenlist)[ind];
1098 while (p != NULL && toQString(CFiledata(p->anno()).name()) != reader->m_lastfile)
1099 {
1100 p = (*pOpenlist)[++ind];
1101 }
1102 if (p != NULL) pOpenlist->erase(ind);
1103 switch (QMessageBox::information ( this , PROGNAME, "What do you want to delete?", "Nothing", "Marks", "Marks\nFile", 1, 0 ))
1104 {
1105 case 0:
1106 default:
1107 break;
1108 case 2:
1109 unlink((const char*)reader->m_lastfile);
1110 case 1:
1111 unlink((const char *)Global::applicationFileName(APPDIR, reader->m_string));
1112 }
1113 }
1114
1115 fileOpen2();
1116}
1117
1118void QTReaderApp::updatefileinfo()
1119{
1120 if (reader->m_string.isNull()) return;
1121 if (reader->m_lastfile.isNull()) return;
1122 tchar* nm = fromQString(reader->m_string);
1123 tchar* fl = fromQString(reader->m_lastfile);
1124 qDebug("Lastfile:%x", fl);
1125 bool notadded = true;
1126 if (pOpenlist == NULL) pOpenlist = new CList<Bkmk>;
1127 else
1128 {
1129 for (CList<Bkmk>::iterator iter = pOpenlist->begin(); iter != pOpenlist->end(); iter++)
1130 {
1131 if (ustrcmp(CFiledata(iter->anno()).name(), fl) == 0)
1132 {
1133 iter->value(reader->pagelocate());
1134 unsigned short dlen;
1135 unsigned char* data;
1136 CFiledata fd(iter->anno());
1137 reader->setSaveData(data, dlen, fd.content(), fd.length());
1138 qDebug("Filedata(1):%u, %u", fd.length(), dlen);
1139 // getstate(data, dlen);
1140 iter->setAnno(data, dlen);
1141 notadded = false;
1142 delete [] data;
1143 break;
1144 }
1145 }
1146 }
1147 qDebug("Added?:%x", notadded);
1148 if (notadded)
1149 {
1150 struct stat fnstat;
1151 stat((const char *)reader->m_lastfile, &fnstat);
1152 CFiledata fd(fnstat.st_mtime, fl);
1153 unsigned short dlen;
1154 unsigned char* data;
1155 reader->setSaveData(data, dlen, fd.content(), fd.length());
1156 pOpenlist->push_front(Bkmk(nm, data, dlen, reader->pagelocate()));
1157 qDebug("Filedata(2):%u, %u", fd.length(), dlen);
1158 delete [] data;
1159 }
1160 delete [] nm;
1161 delete [] fl;
930} 1162}
931 1163
932void QTReaderApp::fileOpen() 1164void QTReaderApp::fileOpen()
933{ 1165{
934/* 1166/*
935 menu->hide(); 1167 menu->hide();
936 editBar->hide(); 1168 editBar->hide();
937 if (regVisible) regBar->hide(); 1169 if (regVisible) regBar->hide();
938 if (searchVisible) searchBar->hide(); 1170 if (searchVisible) searchBar->hide();
939*/ 1171*/
1172 qDebug("fileOpen");
1173// if (!reader->m_lastfile.isEmpty())
1174 updatefileinfo();
1175 fileOpen2();
1176}
1177
1178void QTReaderApp::fileOpen2()
1179{
940 if (pBkmklist != NULL) 1180 if (pBkmklist != NULL)
941 { 1181 {
942 if (m_fBkmksChanged) 1182 if (m_fBkmksChanged)
943 { 1183 {
944 if (QMessageBox::warning(this, "OpieReader", "Save bookmarks?", "Save", "Don't bother") == 0) 1184 if (QMessageBox::warning(this, PROGNAME, "Save bookmarks?", "Save", "Don't bother") == 0)
945 savebkmks(); 1185 savebkmks();
946 } 1186 }
947 delete pBkmklist; 1187 delete pBkmklist;
948 pBkmklist = NULL; 1188 pBkmklist = NULL;
949 m_fBkmksChanged = false; 1189 m_fBkmksChanged = false;
950 } 1190 }
951 reader->disableAutoscroll(); 1191 reader->disableAutoscroll();
952/* 1192/*
953 editorStack->raiseWidget( fileSelector ); 1193 editorStack->raiseWidget( fileSelector );
954 fileSelector->reread(); 1194 fileSelector->reread();
955*/ 1195*/
956 fileBrowser* fb = new fileBrowser(this,"OpieReader",TRUE, 1196 if (pOpenlist != NULL)
957 0, 1197 {
958// WStyle_Customize | WStyle_NoBorderEx, 1198 m_nRegAction = cOpenFile;
959 "*", QFileInfo(reader->m_lastfile).dirPath(true)); 1199 listbkmk(pOpenlist, "Browse");
1200 }
1201 else
1202 {
1203 QString fn = usefilebrowser();
1204 if (!fn.isEmpty() && QFileInfo(fn).isFile())
1205 {
1206 openFile(fn);
1207 }
1208 reader->setFocus();
1209 }
1210}
1211
1212QString QTReaderApp::usefilebrowser()
1213{
1214 fileBrowser* fb = new fileBrowser(this,"QTReader",TRUE,
1215 0,
1216 // WStyle_Customize | WStyle_NoBorderEx,
1217 "*", QFileInfo(reader->m_lastfile).dirPath(true));
960 1218
1219
1220 QString fn;
961 if (fb->exec()) 1221 if (fb->exec())
962 { 1222 {
963 QString fn(fb->fileList[0]); 1223 fn = fb->fileList[0];
964// fb->populateList();
965 if (!fn.isEmpty() && QFileInfo(fn).isFile()) openFile(fn);
966 } 1224 }
1225 qDebug("Selected %s", (const char*)fn);
967 delete fb; 1226 delete fb;
968 reader->setFocus(); 1227 return fn;
1228}
1229
1230void QTReaderApp::showgraphic(QPixmap& pm)
1231{
1232 m_graphicwin->setPixmap(pm);
1233 editorStack->raiseWidget( m_graphicwin );
1234 m_graphicwin->setFocus();
969} 1235}
970 1236
971void QTReaderApp::showinfo() 1237void QTReaderApp::showinfo()
972{ 1238{
973 unsigned long fs, ts, pl; 1239 unsigned long fs, ts, pl;
974 if (reader->empty()) 1240 if (reader->empty())
975 { 1241 {
976 QMessageBox::information(this, "OpieReader", "No file loaded", 1); 1242 QMessageBox::information(this, PROGNAME, "No file loaded", 1);
977 } 1243 }
978 else 1244 else
979 { 1245 {
980 reader->sizes(fs,ts); 1246 reader->sizes(fs,ts);
981 pl = reader->pagelocate(); 1247 pl = reader->pagelocate();
982 m_infoWin->setFileSize(fs); 1248 m_infoWin->setFileSize(fs);
983 m_infoWin->setTextSize(ts); 1249 m_infoWin->setTextSize(ts);
984 m_infoWin->setRatio(100-(100*fs + (ts >> 1))/ts); 1250 m_infoWin->setRatio(100-(100*fs + (ts >> 1))/ts);
985 m_infoWin->setLocation(pl); 1251 m_infoWin->setLocation(pl);
986 m_infoWin->setRead((100*pl + (ts >> 1))/ts); 1252 m_infoWin->setRead((100*pl + (ts >> 1))/ts);
987 editorStack->raiseWidget( m_infoWin ); 1253 editorStack->raiseWidget( m_infoWin );
988 m_infoWin->setFocus(); 1254 m_infoWin->setFocus();
989 } 1255 }
990} 1256}
991 1257
992void QTReaderApp::addAnno(const QString& name, const QString& text, size_t posn) 1258void QTReaderApp::addAnno(const QString& name, const QString& text, size_t posn)
993{ 1259{
994 if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>; 1260 if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>;
995#ifdef _UNICODE 1261#ifdef _UNICODE
996 CBuffer buff(name.length()+1); 1262 CBuffer buff(name.length()+1);
997 int i; 1263 int i;
998 for (i = 0; i < name.length(); i++) 1264 for (i = 0; i < name.length(); i++)
999 { 1265 {
1000 buff[i] = name[i].unicode(); 1266 buff[i] = name[i].unicode();
1001 } 1267 }
1002 buff[i] = 0; 1268 buff[i] = 0;
1003 CBuffer buff2(text.length()+1); 1269 CBuffer buff2(text.length()+1);
1004 for (i = 0; i < text.length(); i++) 1270 for (i = 0; i < text.length(); i++)
1005 { 1271 {
1006 buff2[i] = text[i].unicode(); 1272 buff2[i] = text[i].unicode();
1007 } 1273 }
1008 buff2[i] = 0; 1274 buff2[i] = 0;
1009 pBkmklist->push_front(Bkmk(buff.data(), buff2.data(), posn)); 1275 pBkmklist->push_front(Bkmk(buff.data(), buff2.data(), posn));
1010#else 1276#else
1011 pBkmklist->push_front(Bkmk((const tchar*)text,posn)); 1277 pBkmklist->push_front(Bkmk((const tchar*)text,posn));
1012#endif 1278#endif
1013 m_fBkmksChanged = true; 1279 m_fBkmksChanged = true;
1014 pBkmklist->sort(); 1280 pBkmklist->sort();
1015} 1281}
1016 1282
1017void QTReaderApp::addAnno(const QString& name, const QString& text) 1283void QTReaderApp::addAnno(const QString& name, const QString& text)
1018{ 1284{
1019 if (m_annoIsEditing) 1285 if (m_annoIsEditing)
1020 { 1286 {
1021 if (name.isEmpty()) 1287 if (name.isEmpty())
1022 { 1288 {
1023 QMessageBox::information(this, "OpieReader", "Need a name for the bookmark\nPlease try again", 1); 1289 QMessageBox::information(this, PROGNAME, "Need a name for the bookmark\nPlease try again", 1);
1024 } 1290 }
1025 else 1291 else
1026 { 1292 {
1027 addAnno(name, text, m_annoWin->getPosn()); 1293 addAnno(name, text, m_annoWin->getPosn());
1028 } 1294 }
1029 showEditTools(); 1295 showEditTools();
1030 } 1296 }
1031 else 1297 else
1032 { 1298 {
1033 if (m_annoWin->edited()) 1299 if (m_annoWin->edited())
1034 { 1300 {
1035 CBuffer buff(text.length()+1); 1301 CBuffer buff(text.length()+1);
1036 int i; 1302 int i;
1037 for (i = 0; i < text.length(); i++) 1303 for (i = 0; i < text.length(); i++)
1038 { 1304 {
1039 buff[i] = text[i].unicode(); 1305 buff[i] = text[i].unicode();
1040 } 1306 }
1041 buff[i] = 0; 1307 buff[i] = 0;
1042 m_fBkmksChanged = true; 1308 m_fBkmksChanged = true;
1043 m_anno->setAnno(buff.data()); 1309 m_anno->setAnno(buff.data());
1044 } 1310 }
1045 bool found = findNextBookmark(m_anno->value()+1); 1311 bool found = findNextBookmark(m_anno->value()+1);
1046 if (found) 1312 if (found)
1047 { 1313 {
1048 m_annoWin->setName(toQString(m_anno->name())); 1314 m_annoWin->setName(toQString(m_anno->name()));
1049 m_annoWin->setAnno(toQString(m_anno->anno())); 1315 m_annoWin->setAnno(toQString(m_anno->anno()));
1050 } 1316 }
1051 else 1317 else
1052 { 1318 {
1053 showEditTools(); 1319 showEditTools();
1054 } 1320 }
1055 } 1321 }
1056} 1322}
1057 1323
1058bool QTReaderApp::findNextBookmark(size_t start) 1324bool QTReaderApp::findNextBookmark(size_t start)
1059{ 1325{
1060 bool found = false; 1326 bool found = false;
1061 for (CList<Bkmk>::iterator iter = pBkmklist->begin(); iter != pBkmklist->end(); iter++) 1327 for (CList<Bkmk>::iterator iter = pBkmklist->begin(); iter != pBkmklist->end(); iter++)
1062 { 1328 {
1063 if (iter->value() >= start) 1329 if (iter->value() >= start)
1064 { 1330 {
1065 if (iter->value() < reader->locate()) 1331 if (iter->value() < reader->locate())
1066 { 1332 {
1067 found = true; 1333 found = true;
1068 m_anno = iter.pContent(); 1334 m_anno = iter.pContent();
1069 } 1335 }
1070 break; 1336 break;
1071 } 1337 }
1072 } 1338 }
1073 return found; 1339 return found;
1074} 1340}
1075 1341
1076void QTReaderApp::addanno() 1342void QTReaderApp::addanno()
1077{ 1343{
1078 if (reader->empty()) 1344 if (reader->empty())
1079 { 1345 {
1080 QMessageBox::information(this, "OpieReader", "No file loaded", 1); 1346 QMessageBox::information(this, PROGNAME, "No file loaded", 1);
1081 } 1347 }
1082 else 1348 else
1083 { 1349 {
1084 m_annoWin->setName(""); 1350 m_annoWin->setName("");
1085 m_annoWin->setAnno(""); 1351 m_annoWin->setAnno("");
1086 m_annoWin->setPosn(reader->pagelocate()); 1352 m_annoWin->setPosn(reader->pagelocate());
1087 m_annoIsEditing = true; 1353 m_annoIsEditing = true;
1088 editorStack->raiseWidget( m_annoWin ); 1354 editorStack->raiseWidget( m_annoWin );
1089 m_annoWin->setFocus(); 1355 Global::showInputMethod();
1356 m_annoWin->setFocus();
1090 } 1357 }
1091} 1358}
1092 1359
1093void QTReaderApp::infoClose() 1360void QTReaderApp::infoClose()
1094{ 1361{
1095 showEditTools(); 1362 showEditTools();
1096} 1363}
1097 1364
1098/* 1365/*
1099void QTReaderApp::fileRevert() 1366void QTReaderApp::fileRevert()
1100{ 1367{
1101 clear(); 1368 clear();
1102 fileOpen(); 1369 fileOpen();
1103} 1370}
1104 1371
1105void QTReaderApp::editCut() 1372void QTReaderApp::editCut()
1106{ 1373{
1107#ifndef QT_NO_CLIPBOARD 1374#ifndef QT_NO_CLIPBOARD
1108 editor->cut(); 1375 editor->cut();
1109#endif 1376#endif
1110} 1377}
1111*/ 1378*/
1112void QTReaderApp::editMark() 1379void QTReaderApp::editMark()
1113{ 1380{
1114 m_savedpos = reader->pagelocate(); 1381 m_savedpos = reader->pagelocate();
1115} 1382}
1116 1383
1117void QTReaderApp::editCopy() 1384void QTReaderApp::editCopy()
1118{ 1385{
1119 QClipboard* cb = QApplication::clipboard(); 1386 QClipboard* cb = QApplication::clipboard();
1120 QString text; 1387 QString text;
1121 int ch; 1388 int ch;
1122 unsigned long currentpos = reader->pagelocate(); 1389 unsigned long currentpos = reader->pagelocate();
1123 unsigned long endpos = reader->locate(); 1390 unsigned long endpos = reader->locate();
1124 reader->jumpto(m_savedpos); 1391 reader->jumpto(m_savedpos);
1125 while (reader->explocate() < endpos && (ch = reader->getch()) != UEOF) 1392 while (reader->explocate() < endpos && (ch = reader->getch()) != UEOF)
1126 { 1393 {
1127 text += ch; 1394 text += ch;
1128 } 1395 }
1129 cb->setText(text); 1396 cb->setText(text);
1130 reader->locate(currentpos); 1397 reader->locate(currentpos);
1131} 1398}
1132 1399
1133void QTReaderApp::pageup() 1400void QTReaderApp::pageup()
1134{ 1401{
1135 reader->goUp(); 1402 reader->NavUp();
1136} 1403}
1137 1404
1138void QTReaderApp::pagedn() 1405void QTReaderApp::pagedn()
1139{ 1406{
1140 reader->goDown(); 1407 reader->NavDown();
1141} 1408}
1142 1409
1143void QTReaderApp::stripcr(bool _b) 1410void QTReaderApp::stripcr(bool _b)
1144{ 1411{
1145 reader->setstripcr(_b); 1412 reader->setstripcr(_b);
1146} 1413}
1414void QTReaderApp::onespace(bool _b)
1415{
1416 reader->setonespace(_b);
1417}
1418#ifdef REPALM
1419void QTReaderApp::repalm(bool _b)
1420{
1421 reader->setrepalm(_b);
1422}
1423#endif
1147void QTReaderApp::remap(bool _b) 1424void QTReaderApp::remap(bool _b)
1148{ 1425{
1149 reader->setremap(_b); 1426 reader->setremap(_b);
1150} 1427}
1151void QTReaderApp::peanut(bool _b) 1428void QTReaderApp::peanut(bool _b)
1152{ 1429{
1153 reader->setpeanut(_b); 1430 reader->setpeanut(_b);
1154} 1431}
1155void QTReaderApp::embolden(bool _b) 1432void QTReaderApp::embolden(bool _b)
1156{ 1433{
1157 reader->setmakebold(_b); 1434 reader->setmakebold(_b);
1158} 1435}
1159void QTReaderApp::autofmt(bool _b) 1436void QTReaderApp::autofmt(bool _b)
1160{ 1437{
1161 reader->setautofmt(_b); 1438 reader->setautofmt(_b);
1162} 1439}
1163void QTReaderApp::textfmt(bool _b) 1440void QTReaderApp::textfmt(bool _b)
1164{ 1441{
1165 reader->settextfmt(_b); 1442 reader->settextfmt(_b);
1166} 1443}
1167void QTReaderApp::striphtml(bool _b) 1444void QTReaderApp::striphtml(bool _b)
1168{ 1445{
1169 reader->setstriphtml(_b); 1446 reader->setstriphtml(_b);
1170} 1447}
1171void QTReaderApp::dehyphen(bool _b) 1448void QTReaderApp::dehyphen(bool _b)
1172{ 1449{
1173 reader->setdehyphen(_b); 1450 reader->setdehyphen(_b);
1174} 1451}
1175void QTReaderApp::unindent(bool _b) 1452void QTReaderApp::unindent(bool _b)
1176{ 1453{
1177 reader->setunindent(_b); 1454 reader->setunindent(_b);
1178} 1455}
1179void QTReaderApp::repara(bool _b) 1456void QTReaderApp::repara(bool _b)
1180{ 1457{
1181 reader->setrepara(_b); 1458 reader->setrepara(_b);
1182} 1459}
1183void QTReaderApp::dblspce(bool _b) 1460void QTReaderApp::dblspce(bool _b)
1184{ 1461{
1185 reader->setdblspce(_b); 1462 reader->setdblspce(_b);
1186} 1463}
1187void QTReaderApp::pagemode(bool _b) 1464void QTReaderApp::pagemode(bool _b)
1188{ 1465{
1189 reader->setpagemode(_b); 1466 reader->setpagemode(_b);
1190} 1467}
1191 1468void QTReaderApp::navkeys(bool _b)
1469{
1470 reader->m_navkeys = _b;
1471}
1192void QTReaderApp::monospace(bool _b) 1472void QTReaderApp::monospace(bool _b)
1193{ 1473{
1194 reader->setmono(_b); 1474 reader->setmono(_b);
1195} 1475}
1196 1476
1197void QTReaderApp::setspacing() 1477void QTReaderApp::setspacing()
1198{ 1478{
1199 m_nRegAction = cMonoSpace; 1479 m_nRegAction = cMonoSpace;
1200 char lcn[20]; 1480 char lcn[20];
1201 sprintf(lcn, "%lu", reader->m_charpc); 1481 sprintf(lcn, "%lu", reader->m_charpc);
1202 regEdit->setText(lcn); 1482 regEdit->setText(lcn);
1203 do_regedit(); 1483 do_regedit();
1204} 1484}
1205 1485
1206void QTReaderApp::setoverlap() 1486void QTReaderApp::setoverlap()
1207{ 1487{
1208 m_nRegAction = cOverlap; 1488 m_nRegAction = cOverlap;
1209 char lcn[20]; 1489 char lcn[20];
1210 sprintf(lcn, "%lu", reader->m_overlap); 1490 sprintf(lcn, "%lu", reader->m_overlap);
1211 regEdit->setText(lcn); 1491 regEdit->setText(lcn);
1212 do_regedit(); 1492 do_regedit();
1213} 1493}
1214 1494
1215void QTReaderApp::settarget() 1495void QTReaderApp::settarget()
1216{ 1496{
1217 m_nRegAction = cSetTarget; 1497 m_nRegAction = cSetTarget;
1218 QString text = ((m_targetapp.isEmpty()) ? QString("") : m_targetapp) 1498 QString text = ((m_targetapp.isEmpty()) ? QString("") : m_targetapp)
1219 + "/" 1499 + "/"
1220 + ((m_targetmsg.isEmpty()) ? QString("") : m_targetmsg); 1500 + ((m_targetmsg.isEmpty()) ? QString("") : m_targetmsg);
1221 regEdit->setText(text); 1501 regEdit->setText(text);
1222 do_regedit(); 1502 do_regedit();
1223} 1503}
1224 1504
1225void QTReaderApp::do_overlap(const QString& lcn) 1505void QTReaderApp::do_overlap(const QString& lcn)
1226{ 1506{
1227 bool ok; 1507 bool ok;
1228 unsigned long ulcn = lcn.toULong(&ok); 1508 unsigned long ulcn = lcn.toULong(&ok);
1229 if (ok) 1509 if (ok)
1230 { 1510 {
1231 reader->m_overlap = ulcn; 1511 reader->m_overlap = ulcn;
1232 } 1512 }
1233 else 1513 else
1234 QMessageBox::information(this, "OpieReader", "Must be a number"); 1514 QMessageBox::information(this, PROGNAME, "Must be a number");
1235} 1515}
1236 1516
1237void QTReaderApp::do_mono(const QString& lcn) 1517void QTReaderApp::do_mono(const QString& lcn)
1238{ 1518{
1239 bool ok; 1519 bool ok;
1240 unsigned long ulcn = lcn.toULong(&ok); 1520 unsigned long ulcn = lcn.toULong(&ok);
1241 if (ok) 1521 if (ok)
1242 { 1522 {
1243 reader->m_charpc = ulcn; 1523 reader->m_charpc = ulcn;
1244 reader->setfont(); 1524 reader->setfont();
1245 reader->refresh(); 1525 reader->refresh();
1246// reader->setmono(true); 1526 //reader->setmono(true);
1247 } 1527 }
1248 else 1528 else
1249 QMessageBox::information(this, "OpieReader", "Must be a number"); 1529 QMessageBox::information(this, PROGNAME, "Must be a number");
1250} 1530}
1251 1531
1252/* 1532/*
1253void QTReaderApp::editPaste() 1533void QTReaderApp::editPaste()
1254{ 1534{
1255#ifndef QT_NO_CLIPBOARD 1535#ifndef QT_NO_CLIPBOARD
1256 editor->paste(); 1536 editor->paste();
1257#endif 1537#endif
1258} 1538}
1259*/ 1539*/
1260 1540
1261void QTReaderApp::editFind() 1541void QTReaderApp::editFind()
1262{ 1542{
1263 searchStart = reader->pagelocate(); 1543 searchStart = reader->pagelocate();
1264#ifdef __ISEARCH 1544#ifdef __ISEARCH
1265 searchStack = new QStack<searchrecord>; 1545 searchStack = new QStack<searchrecord>;
1266#endif 1546#endif
1547 Global::showInputMethod();
1267 searchBar->show(); 1548 searchBar->show();
1268 searchVisible = TRUE; 1549 searchVisible = TRUE;
1269 searchEdit->setFocus(); 1550 searchEdit->setFocus();
1270#ifdef __ISEARCH 1551#ifdef __ISEARCH
1271 searchStack->push(new searchrecord("",reader->pagelocate())); 1552 searchStack->push(new searchrecord("",reader->pagelocate()));
1272#endif 1553#endif
1273} 1554}
1274 1555
1275void QTReaderApp::findNext() 1556void QTReaderApp::findNext()
1276{ 1557{
1277 // qDebug("findNext called\n"); 1558 // qDebug("findNext called\n");
1278#ifdef __ISEARCH 1559#ifdef __ISEARCH
1279 QString arg = searchEdit->text(); 1560 QString arg = searchEdit->text();
1280#else 1561#else
1281 QRegExp arg = searchEdit->text(); 1562 QRegExp arg = searchEdit->text();
1282#endif 1563#endif
1283 CDrawBuffer test(&(reader->m_fontControl)); 1564 CDrawBuffer test(&(reader->m_fontControl));
1284 size_t start = reader->pagelocate(); 1565 size_t start = reader->pagelocate();
1285 reader->jumpto(start); 1566 reader->jumpto(start);
1286 reader->buffdoc.getline(&test,reader->width()); 1567 reader->buffdoc.getline(&test,reader->width());
1287 dosearch(start, test, arg); 1568 dosearch(start, test, arg);
1288} 1569}
1289 1570
1290void QTReaderApp::findClose() 1571void QTReaderApp::findClose()
1291{ 1572{
1292 searchVisible = FALSE; 1573 searchVisible = FALSE;
1293 searchEdit->setText(""); 1574 searchEdit->setText("");
1575 Global::hideInputMethod();
1294 searchBar->hide(); 1576 searchBar->hide();
1295#ifdef __ISEARCH 1577#ifdef __ISEARCH
1296// searchStack = new QStack<searchrecord>; 1578// searchStack = new QStack<searchrecord>;
1297 while (!searchStack->isEmpty()) 1579 while (!searchStack->isEmpty())
1298 { 1580 {
1299 delete searchStack->pop(); 1581 delete searchStack->pop();
1300 } 1582 }
1301 delete searchStack; 1583 delete searchStack;
1302#endif 1584#endif
1303 reader->setFocus(); 1585 reader->setFocus();
1304} 1586}
1305 1587
1306void QTReaderApp::regClose() 1588void QTReaderApp::regClose()
1307{ 1589{
1308 regVisible = FALSE; 1590 regVisible = FALSE;
1309 regEdit->setText(""); 1591 regEdit->setText("");
1310 regBar->hide(); 1592 regBar->hide();
1593 Global::hideInputMethod();
1311 reader->setFocus(); 1594 reader->setFocus();
1312} 1595}
1313 1596
1314#ifdef __ISEARCH 1597#ifdef __ISEARCH
1315bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QString& arg) 1598bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QString& arg)
1316#else 1599#else
1317bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg) 1600bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg)
1318#endif 1601#endif
1319{ 1602{
1320 bool ret = true; 1603 bool ret = true;
1604 unsigned long fs, ts;
1605 reader->sizes(fs,ts);
1321 size_t pos = reader->locate(); 1606 size_t pos = reader->locate();
1322 reader->buffdoc.getline(&test,reader->width()); 1607 reader->buffdoc.getline(&test,reader->width());
1608 pbar->show();
1609 pbar->resize(width(), editBar->height());
1610 pbar->reset();
1611 int lastpc = (100*pos)/ts;
1612 pbar->setProgress(lastpc);
1613 qApp->processEvents();
1614 reader->setFocus();
1323#ifdef __ISEARCH 1615#ifdef __ISEARCH
1324 while (strstr(test.data(),(const tchar*)arg) == NULL) 1616 while (strstr(test.data(),(const tchar*)arg) == NULL)
1325#else 1617#else
1326#ifdef _UNICODE 1618#ifdef _UNICODE
1327 while (arg.match(toQString(test.data())) == -1) 1619 while (arg.match(toQString(test.data())) == -1)
1328#else 1620#else
1329 while (arg.match(test.data()) == -1) 1621 while (arg.match(test.data()) == -1)
1330#endif 1622#endif
1331#endif 1623#endif
1332 { 1624 {
1333 pos = reader->locate(); 1625 pos = reader->locate();
1626 unsigned int lcn = reader->locate();
1627 int pc = (100*pos)/ts;
1628 if (pc != lastpc)
1629 {
1630 pbar->setProgress(pc);
1631 qApp->processEvents();
1632 reader->setFocus();
1633 lastpc = pc;
1634 }
1635
1334 if (!reader->buffdoc.getline(&test,reader->width())) 1636 if (!reader->buffdoc.getline(&test,reader->width()))
1335 { 1637 {
1336 if (QMessageBox::warning(this, "Can't find", searchEdit->text(), 1, 2) == 2) 1638 if (QMessageBox::warning(this, "Can't find", searchEdit->text(), 1, 2) == 2)
1337 pos = searchStart; 1639 pos = searchStart;
1338 else 1640 else
1339 pos = start; 1641 pos = start;
1340 ret = false; 1642 ret = false;
1341 findClose(); 1643 findClose();
1342 break; 1644 break;
1343 } 1645 }
1344 } 1646 }
1647 pbar->hide();
1345 reader->locate(pos); 1648 reader->locate(pos);
1346 return ret; 1649 return ret;
1347} 1650}
1348 1651
1349#ifdef __ISEARCH 1652#ifdef __ISEARCH
1350void QTReaderApp::search(const QString & arg) 1653void QTReaderApp::search(const QString & arg)
1351{ 1654{
1352 searchrecord* ss = searchStack->top(); 1655 searchrecord* ss = searchStack->top();
1353 CBuffer test; 1656 CBuffer test;
1354 size_t start = reader->pagelocate(); 1657 size_t start = reader->pagelocate();
1355 bool haspopped = false; 1658 bool haspopped = false;
1356 while (arg.left(ss->s.length()) != ss->s) 1659 while (arg.left(ss->s.length()) != ss->s)
1357 { 1660 {
1358 haspopped = true; 1661 haspopped = true;
1359 start = ss->pos; 1662 start = ss->pos;
1360// reader->locate(start); 1663// reader->locate(start);
1361 searchStack->pop(); 1664 searchStack->pop();
1362 delete ss; 1665 delete ss;
1363 } 1666 }
1364 if (haspopped) reader->locate(start); 1667 if (haspopped) reader->locate(start);
1365/* 1668/*
1366 if (arg.length() < ss->len) 1669 if (arg.length() < ss->len)
1367 { 1670 {
1368 start = ss->pos; 1671 start = ss->pos;
1369 reader->locate(start); 1672 reader->locate(start);
1370 searchStack->pop(); 1673 searchStack->pop();
1371 delete ss; 1674 delete ss;
1372 } 1675 }
1373*/ 1676*/
1374 else 1677 else
1375 { 1678 {
1376 start = reader->pagelocate(); 1679 start = reader->pagelocate();
1377 reader->jumpto(start); 1680 reader->jumpto(start);
1378 searchStack->push(new searchrecord(arg,start)); 1681 searchStack->push(new searchrecord(arg,start));
1379 } 1682 }
1380 dosearch(start, test, arg); 1683 dosearch(start, test, arg);
1381} 1684}
1382#else 1685#else
1383void QTReaderApp::search() 1686void QTReaderApp::search()
1384{ 1687{
1385 findNext(); 1688 findNext();
1386} 1689}
1387#endif 1690#endif
1388 1691
1389void QTReaderApp::openFile( const QString &f ) 1692void QTReaderApp::openFile( const QString &f )
1390{ 1693{
1391 openFile(DocLnk(f)); 1694 qDebug("File:%s", (const char*)f);
1392} 1695// openFile(DocLnk(f));
1393 1696//}
1394void QTReaderApp::openFile( const DocLnk &f ) 1697//
1395{ 1698//void QTReaderApp::openFile( const DocLnk &f )
1699//{
1396 clear(); 1700 clear();
1397 FileManager fm; 1701 QFileInfo fm(f);
1398 if ( fm.exists( f ) ) 1702 if ( fm.exists() )
1399 { 1703 {
1400// QMessageBox::information(0, "Progress", "Calling fileNew()"); 1704// QMessageBox::information(0, "Progress", "Calling fileNew()");
1401 1705
1402 clear(); 1706 if (fm.extension( FALSE ) == "desktop")
1707 {
1708 DocLnk d(f);
1709 QFileInfo fnew(d.file());
1710 fm = fnew;
1711 if (!fm.exists()) return;
1712 }
1403 1713
1404 // editorStack->raiseWidget( reader ); 1714 clear();
1405
1406 // reader->setFocus();
1407
1408 // QMessageBox::information(0, "DocLnk", "Begin");
1409 doc = new DocLnk(f);
1410 // QMessageBox::information(0, "DocLnk done", doc->file());
1411 // QMessageBox::information(0, "Progress", "Calling setText()");
1412 // QMessageBox::information(0, "Progress", "Textset");
1413 1715
1414 // updateCaption(); 1716 reader->setText(fm.baseName(), fm.absFilePath());
1415 showEditTools(); 1717 showEditTools();
1416 reader->setText(doc->name(), doc->file());
1417 readbkmks(); 1718 readbkmks();
1418 } 1719 }
1419 else 1720 else
1420 { 1721 {
1421 QMessageBox::information(this, "OpieReader", "File does not exist"); 1722 QMessageBox::information(this, PROGNAME, "File does not exist");
1723 }
1724
1725}
1726/*
1727void QTReaderApp::resizeEvent(QResizeEvent* e)
1728{
1729 if (m_fullscreen)
1730 {
1731 showNormal();
1732 showFullScreen();
1733 }
1734}
1735*/
1736void QTReaderApp::keyPressEvent(QKeyEvent* e)
1737{
1738 if (m_fullscreen)
1739 {
1740 switch(e->key())
1741 {
1742 case Key_Escape:
1743 m_actFullscreen->setOn(false);
1744 if (m_fullscreen)
1745 {
1746 qDebug("Fullscreen already set - remove this!");
1747 }
1748 else
1749 {
1750 m_fullscreen = false;
1751 reader->bDoUpdates = false;
1752 showEditTools();
1753 qApp->processEvents();
1754 reader->bDoUpdates = true;
1755 reader->update();
1756 }
1757 e->accept();
1758 break;
1759 default:
1760 e->ignore();
1761 }
1762 }
1763 else
1764 {
1765 e->ignore();
1422 } 1766 }
1423
1424} 1767}
1425 1768
1426void QTReaderApp::showEditTools() 1769void QTReaderApp::showEditTools()
1427{ 1770{
1428 if ( !doc ) 1771// if ( !doc )
1429 close(); 1772 //close();
1430// fileSelector->hide(); 1773 if (m_fullscreen)
1431//tjw menu->show(); 1774 {
1432 editBar->show(); 1775 editBar->hide();
1433 if ( searchVisible ) 1776 searchBar->hide();
1434 searchBar->show(); 1777 regBar->hide();
1435 if ( regVisible ) 1778 Global::hideInputMethod();
1436 regBar->show(); 1779 m_fontBar->hide();
1437 if (m_fontVisible) m_fontBar->show(); 1780 //showNormal();
1438 1781 showFullScreen();
1782 }
1783 else
1784 {
1785 qDebug("him");
1786 Global::hideInputMethod();
1787 qDebug("eb");
1788 editBar->show();
1789 if ( searchVisible )
1790 {
1791 Global::showInputMethod();
1792 searchBar->show();
1793 }
1794 if ( regVisible )
1795 {
1796 Global::showInputMethod();
1797 regBar->show();
1798 }
1799 if (m_fontVisible) m_fontBar->show();
1800 qDebug("sn");
1801 showNormal();
1802 qDebug("sm");
1803 showMaximized();
1804 //setCentralWidget(reader);
1805 }
1806
1807 qDebug("uc");
1439 updateCaption(); 1808 updateCaption();
1809 qDebug("rw");
1440 editorStack->raiseWidget( reader ); 1810 editorStack->raiseWidget( reader );
1811 qDebug("sf");
1441 reader->setFocus(); 1812 reader->setFocus();
1442} 1813}
1443/* 1814/*
1444void QTReaderApp::save() 1815void QTReaderApp::save()
1445{ 1816{
1446 if ( !doc ) 1817 if ( !doc )
1447 return; 1818 return;
1448 if ( !editor->edited() ) 1819 if ( !editor->edited() )
1449 return; 1820 return;
1450 1821
1451 QString rt = editor->text(); 1822 QString rt = editor->text();
1452 QString pt = rt; 1823 QString pt = rt;
1453 1824
1454 if ( doc->name().isEmpty() ) { 1825 if ( doc->name().isEmpty() ) {
1455 unsigned ispace = pt.find( ' ' ); 1826 unsigned ispace = pt.find( ' ' );
1456 unsigned ienter = pt.find( '\n' ); 1827 unsigned ienter = pt.find( '\n' );
1457 int i = (ispace < ienter) ? ispace : ienter; 1828 int i = (ispace < ienter) ? ispace : ienter;
1458 QString docname; 1829 QString docname;
1459 if ( i == -1 ) { 1830 if ( i == -1 ) {
1460 if ( pt.isEmpty() ) 1831 if ( pt.isEmpty() )
1461 docname = "Empty Text"; 1832 docname = "Empty Text";
1462 else 1833 else
1463 docname = pt; 1834 docname = pt;
1464 } else { 1835 } else {
1465 docname = pt.left( i ); 1836 docname = pt.left( i );
1466 } 1837 }
1467 doc->setName(docname); 1838 doc->setName(docname);
1468 } 1839 }
1469 FileManager fm; 1840 FileManager fm;
1470 fm.saveFile( *doc, rt ); 1841 fm.saveFile( *doc, rt );
1471} 1842}
1472*/ 1843*/
1473 1844
1474void QTReaderApp::clear() 1845void QTReaderApp::clear()
1475{ 1846{
1476 if (doc != 0) 1847// if (doc != 0)
1477 { 1848// {
1478// QMessageBox::information(this, "QTReader", "Deleting doc", 1); 1849// QMessageBox::information(this, PROGNAME, "Deleting doc", 1);
1479 delete doc; 1850 //delete doc;
1480// QMessageBox::information(this, "QTReader", "Deleted doc", 1); 1851// QMessageBox::information(this, PROGNAME, "Deleted doc", 1);
1481 doc = 0; 1852 //doc = 0;
1482 } 1853 // }
1483 reader->clear(); 1854 reader->clear();
1484} 1855}
1485 1856
1486void QTReaderApp::updateCaption() 1857void QTReaderApp::updateCaption()
1487{ 1858{
1488 if ( !doc ) 1859// if ( !doc )
1489 setCaption( tr("OpieReader") ); 1860 //setCaption( tr("QTReader") );
1490 else { 1861// else {
1491 QString s = doc->name(); 1862 //QString s = doc->name();
1492 if ( s.isEmpty() ) 1863 //if ( s.isEmpty() )
1493 s = tr( "Unnamed" ); 1864 // s = tr( "Unnamed" );
1494 setCaption( s + " - " + tr("OpieReader") ); 1865 setCaption( reader->m_string + " - " + tr(SHORTPROGNAME) );
1495 } 1866// }
1496} 1867}
1497 1868
1498void QTReaderApp::setDocument(const QString& fileref) 1869void QTReaderApp::setDocument(const QString& fileref)
1499{ 1870{
1500 bFromDocView = TRUE; 1871 bFromDocView = TRUE;
1501//QMessageBox::information(0, "setDocument", fileref); 1872//QMessageBox::information(0, "setDocument", fileref);
1502 openFile(DocLnk(fileref)); 1873 openFile(fileref);
1503// showEditTools(); 1874// showEditTools();
1504} 1875}
1505 1876
1506void QTReaderApp::closeEvent( QCloseEvent *e ) 1877void QTReaderApp::closeEvent( QCloseEvent *e )
1507{ 1878{
1508 if (m_dontSave) 1879 if (m_fullscreen)
1509 { 1880 {
1510 e->accept(); 1881 m_fullscreen = false;
1882 showEditTools();
1883 e->accept();
1884 }
1885 else if (m_dontSave)
1886 {
1887 e->accept();
1511 } 1888 }
1512 else 1889 else
1513 { 1890 {
1514 if (editorStack->visibleWidget() == reader) 1891 if (editorStack->visibleWidget() == reader)
1515 { 1892 {
1516 if (m_fontVisible) 1893 if (m_fontVisible)
1517 { 1894 {
1518 m_fontBar->hide(); 1895 m_fontBar->hide();
1519 m_fontVisible = false; 1896 m_fontVisible = false;
1520 } 1897 }
1521 if (regVisible) 1898 if (regVisible)
1522 { 1899 {
1523 regBar->hide(); 1900 regBar->hide();
1524 regVisible = false; 1901 Global::hideInputMethod();
1525 return; 1902 regVisible = false;
1526 } 1903 return;
1527 if (searchVisible) 1904 }
1528 { 1905 if (searchVisible)
1529 searchBar->hide(); 1906 {
1530 searchVisible = false; 1907 searchBar->hide();
1531 return; 1908 Global::hideInputMethod();
1532 } 1909 searchVisible = false;
1533 if (m_fBkmksChanged && pBkmklist != NULL) 1910 return;
1534 { 1911 }
1535 if (QMessageBox::warning(this, "OpieReader", "Save bookmarks?", "Save", "Don't bother") == 0) 1912 if (m_fBkmksChanged && pBkmklist != NULL)
1536 savebkmks(); 1913 {
1537 delete pBkmklist; 1914 if (QMessageBox::warning(this, PROGNAME, "Save bookmarks?", "Save", "Don't bother") == 0)
1538 pBkmklist = NULL; 1915 savebkmks();
1539 m_fBkmksChanged = false; 1916 delete pBkmklist;
1540 } 1917 pBkmklist = NULL;
1541 bFromDocView = FALSE; 1918 m_fBkmksChanged = false;
1542 saveprefs(); 1919 }
1543 e->accept(); 1920 bFromDocView = FALSE;
1544 } 1921 updatefileinfo();
1545 else 1922 saveprefs();
1546 { 1923 e->accept();
1547 showEditTools(); 1924 }
1548 } 1925 else
1926 {
1927 showEditTools();
1928 }
1549 } 1929 }
1550} 1930}
1551 1931
1552void QTReaderApp::do_gotomark() 1932void QTReaderApp::do_gotomark()
1553{ 1933{
1554 m_nRegAction = cGotoBkmk; 1934 m_nRegAction = cGotoBkmk;
1555 listbkmk(); 1935 listbkmk(pBkmklist);
1556} 1936}
1557 1937
1558void QTReaderApp::do_delmark() 1938void QTReaderApp::do_delmark()
1559{ 1939{
1560 m_nRegAction = cDelBkmk; 1940 m_nRegAction = cDelBkmk;
1561 listbkmk(); 1941 listbkmk(pBkmklist);
1562} 1942}
1563 1943
1564void QTReaderApp::listbkmk() 1944void QTReaderApp::listbkmk(CList<Bkmk>* plist, const QString& _lab)
1565{ 1945{
1566 bkmkselector->clear(); 1946 bkmkselector->clear();
1947 if (_lab.isNull())
1948 bkmkselector->setText("Cancel");
1949 else
1950 bkmkselector->setText(_lab);
1567 int cnt = 0; 1951 int cnt = 0;
1568 if (pBkmklist != NULL) 1952 if (plist != NULL)
1569 { 1953 {
1570 for (CList<Bkmk>::iterator i = pBkmklist->begin(); i != pBkmklist->end(); i++) 1954 for (CList<Bkmk>::iterator i = plist->begin(); i != plist->end(); i++)
1571 { 1955 {
1572#ifdef _UNICODE 1956#ifdef _UNICODE
1573 bkmkselector->insertItem(toQString(i->name())); 1957 qDebug("Item:%s", (const char*)toQString(i->name()));
1958 bkmkselector->insertItem(toQString(i->name()));
1574#else 1959#else
1575 bkmkselector->insertItem(i->name()); 1960 bkmkselector->insertItem(i->name());
1576#endif 1961#endif
1577 cnt++; 1962 cnt++;
1578 } 1963 }
1579 } 1964 }
1580 if (cnt > 0) 1965 if (cnt > 0)
1581 { 1966 {
1582//tjw menu->hide(); 1967//tjw menu->hide();
1583 editBar->hide(); 1968 editBar->hide();
1584 if (m_fontVisible) m_fontBar->hide(); 1969 if (m_fontVisible) m_fontBar->hide();
1585 if (regVisible) regBar->hide(); 1970 if (regVisible)
1586 if (searchVisible) searchBar->hide(); 1971 {
1972 Global::hideInputMethod();
1973 regBar->hide();
1974 }
1975 if (searchVisible)
1976 {
1977 Global::hideInputMethod();
1978 searchBar->hide();
1979 }
1587 editorStack->raiseWidget( bkmkselector ); 1980 editorStack->raiseWidget( bkmkselector );
1588 } 1981 }
1589 else 1982 else
1590 QMessageBox::information(this, "OpieReader", "No bookmarks in memory"); 1983 QMessageBox::information(this, PROGNAME, "No bookmarks in memory");
1591} 1984}
1592 1985
1593void QTReaderApp::do_autogen() 1986void QTReaderApp::do_autogen()
1594{ 1987{
1595 m_nRegAction = cAutoGen; 1988 m_nRegAction = cAutoGen;
1596 regEdit->setText(m_autogenstr); 1989 regEdit->setText(m_autogenstr);
1597 do_regedit(); 1990 do_regedit();
1598} 1991}
1599 1992
1600void QTReaderApp::do_regedit() 1993void QTReaderApp::do_regedit()
1601{ 1994{
1602// editBar->hide(); 1995// editBar->hide();
1996 reader->bDoUpdates = false;
1997 qDebug("Showing regbar");
1603 regBar->show(); 1998 regBar->show();
1999 qDebug("Showing kbd");
2000 Global::showInputMethod();
1604 regVisible = true; 2001 regVisible = true;
1605 regEdit->setFocus(); 2002 regEdit->setFocus();
2003 qApp->processEvents();
2004 reader->bDoUpdates = true;
2005 reader->update();
2006}
2007
2008bool QTReaderApp::openfrombkmk(Bkmk* bk)
2009{
2010 QString fn = toQString(
2011 CFiledata(bk->anno()).name()
2012 );
2013 qDebug("fileinfo");
2014 if (!fn.isEmpty() && QFileInfo(fn).isFile())
2015 {
2016 qDebug("Opening");
2017 openFile(fn);
2018 struct stat fnstat;
2019 stat((const char *)reader->m_lastfile, &fnstat);
2020
2021 if (CFiledata(bk->anno()).date()
2022 != fnstat.st_mtime)
2023 {
2024 CFiledata fd(bk->anno());
2025 fd.setdate(fnstat.st_mtime);
2026 bk->value(0);
2027 }
2028 else
2029 {
2030 unsigned short svlen = bk->filedatalen();
2031 unsigned char* svdata = bk->filedata();
2032 reader->putSaveData(svdata, svlen);
2033 // setstate(svdata, svlen);
2034 if (svlen != 0)
2035 {
2036 QMessageBox::warning(this, PROGNAME, "Not all file data used\nNew version?");
2037 }
2038 qDebug("updating");
2039 reader->locate(bk->value());
2040 }
2041 return true;
2042 }
2043 else
2044 {
2045 return false;
2046 }
1606} 2047}
1607 2048
1608void QTReaderApp::gotobkmk(int ind) 2049void QTReaderApp::gotobkmk(int ind)
1609{ 2050{
1610 switch (m_nRegAction) 2051 switch (m_nRegAction)
1611 { 2052 {
1612 case cGotoBkmk: 2053 case cOpenFile:
1613 reader->locate((*pBkmklist)[ind]->value()); 2054 {
1614 break; 2055 if (!openfrombkmk((*pOpenlist)[ind]))
1615 case cDelBkmk: 2056 {
1616// qDebug("Deleting:%s\n",(*pBkmklist)[ind]->name()); 2057 pOpenlist->erase(ind);
1617 pBkmklist->erase(ind); 2058 QMessageBox::information(this, PROGNAME, "Can't find file");
1618 m_fBkmksChanged = true; 2059 }
1619// pBkmklist->sort(); 2060 }
1620 break; 2061 break;
1621 case cRmBkmkFile: 2062 case cGotoBkmk:
1622 unlink((const char *)Global::applicationFileName("uqtreader",bkmkselector->text(ind))); 2063 reader->locate((*pBkmklist)[ind]->value());
1623 break; 2064 break;
2065 case cDelBkmk:
2066 // qDebug("Deleting:%s\n",(*pBkmklist)[ind]->name());
2067 pBkmklist->erase(ind);
2068 m_fBkmksChanged = true;
2069 // pBkmklist->sort();
2070 break;
2071 case cRmBkmkFile:
2072 unlink((const char *)Global::applicationFileName(APPDIR,bkmkselector->text(ind)));
2073 break;
1624 } 2074 }
1625 showEditTools(); 2075 showEditTools();
1626} 2076}
1627 2077
1628void QTReaderApp::cancelbkmk() 2078void QTReaderApp::cancelbkmk()
1629{ 2079{
2080 if (m_nRegAction == cOpenFile)
2081 {
2082 QString fn = usefilebrowser();
2083 if (!fn.isEmpty() && QFileInfo(fn).isFile()) openFile(fn);
2084 }
1630 showEditTools(); 2085 showEditTools();
1631} 2086}
1632 2087
1633void QTReaderApp::jump() 2088void QTReaderApp::jump()
1634{ 2089{
1635 m_nRegAction = cJump; 2090 m_nRegAction = cJump;
1636 char lcn[20]; 2091 char lcn[20];
1637 sprintf(lcn, "%lu", reader->pagelocate()); 2092 sprintf(lcn, "%lu", reader->pagelocate());
1638 regEdit->setText(lcn); 2093 regEdit->setText(lcn);
1639 do_regedit(); 2094 do_regedit();
1640} 2095}
1641 2096
1642void QTReaderApp::do_jump(const QString& lcn) 2097void QTReaderApp::do_jump(const QString& lcn)
1643{ 2098{
1644 bool ok; 2099 bool ok;
1645 unsigned long ulcn = lcn.toULong(&ok); 2100 unsigned long ulcn = lcn.toULong(&ok);
1646 if (ok) 2101 if (ok)
1647 reader->locate(ulcn); 2102 reader->locate(ulcn);
1648 else 2103 else
1649 QMessageBox::information(this, "OpieReader", "Must be a number"); 2104 QMessageBox::information(this, PROGNAME, "Must be a number");
1650} 2105}
1651 2106
1652void QTReaderApp::do_regaction() 2107void QTReaderApp::do_regaction()
1653{ 2108{
2109 reader->bDoUpdates = false;
1654 regBar->hide(); 2110 regBar->hide();
2111 Global::hideInputMethod();
1655 regVisible = false; 2112 regVisible = false;
1656 switch(m_nRegAction) 2113 switch(m_nRegAction)
1657 { 2114 {
1658 case cAutoGen: 2115 case cAutoGen:
1659 do_autogen(regEdit->text()); 2116 do_autogen(regEdit->text());
1660 break; 2117 break;
1661 case cAddBkmk: 2118 case cAddBkmk:
1662 do_addbkmk(regEdit->text()); 2119 do_addbkmk(regEdit->text());
1663 break; 2120 break;
1664 case cJump: 2121 case cJump:
1665 do_jump(regEdit->text()); 2122 do_jump(regEdit->text());
1666 break; 2123 break;
1667 case cMonoSpace: 2124 case cMonoSpace:
1668 do_mono(regEdit->text()); 2125 do_mono(regEdit->text());
1669 break; 2126 break;
1670 case cOverlap: 2127 case cOverlap:
1671 do_overlap(regEdit->text()); 2128 do_overlap(regEdit->text());
1672 break; 2129 break;
1673 case cSetTarget: 2130 case cSetTarget:
1674 do_settarget(regEdit->text()); 2131 do_settarget(regEdit->text());
1675 break; 2132 break;
1676 } 2133 }
1677 reader->restore(); 2134 reader->restore();
1678// editBar->show(); 2135// editBar->show();
1679 reader->setFocus(); 2136 reader->setFocus();
2137 qApp->processEvents();
2138 reader->bDoUpdates = true;
2139 reader->update();
1680} 2140}
1681 2141
1682void QTReaderApp::do_settarget(const QString& _txt) 2142void QTReaderApp::do_settarget(const QString& _txt)
1683{ 2143{
1684 int ind = _txt.find('/'); 2144 int ind = _txt.find('/');
1685 if (ind == -1) 2145 if (ind == -1)
1686 { 2146 {
1687 m_targetapp = ""; 2147 m_targetapp = "";
1688 m_targetmsg = ""; 2148 m_targetmsg = "";
1689 QMessageBox::information(this, "OpieReader", "Format is\nappname/messagename"); 2149 QMessageBox::information(this, PROGNAME, "Format is\nappname/messagename");
1690 } 2150 }
1691 else 2151 else
1692 { 2152 {
1693 m_targetapp = _txt.left(ind); 2153 m_targetapp = _txt.left(ind);
1694 m_targetmsg = _txt.right(_txt.length()-ind-1); 2154 m_targetmsg = _txt.right(_txt.length()-ind-1);
1695 } 2155 }
1696} 2156}
1697 2157
1698void QTReaderApp::setfont() 2158void QTReaderApp::setfont()
1699{ 2159{
1700 for (int i = 1; i <= m_fontSelector->count(); i++) 2160 for (int i = 1; i <= m_fontSelector->count(); i++)
1701 { 2161 {
1702 if (m_fontSelector->text(i) == reader->m_fontname) 2162 if (m_fontSelector->text(i) == reader->m_fontname)
1703 { 2163 {
1704 m_fontSelector->setCurrentItem(i); 2164 m_fontSelector->setCurrentItem(i);
1705 break; 2165 break;
1706 } 2166 }
1707 } 2167 }
1708 m_fontBar->show(); 2168 m_fontBar->show();
1709 m_fontVisible = true; 2169 m_fontVisible = true;
1710} 2170}
1711 2171
1712void QTReaderApp::setfontHelper(const QString& lcn, int size) 2172void QTReaderApp::setfontHelper(const QString& lcn, int size = 0)
1713{ 2173{
1714 if (size == 0) size = reader->m_fontControl.currentsize(); 2174 if (size == 0) size = reader->m_fontControl.currentsize();
1715 QFont f(lcn, 10 /*, QFont::Bold*/); 2175 QFont f(lcn, 10 /*, QFont::Bold*/);
2176 qDebug("bs");
1716 bkmkselector->setFont( f ); 2177 bkmkselector->setFont( f );
2178 qDebug("re");
1717 regEdit->setFont( f ); 2179 regEdit->setFont( f );
2180 qDebug("se");
1718 searchEdit->setFont( f ); 2181 searchEdit->setFont( f );
2182 qDebug("aw");
1719 m_annoWin->setFont( f ); 2183 m_annoWin->setFont( f );
1720 reader->m_fontname = lcn; 2184 reader->m_fontname = lcn;
2185 qDebug("cf1");
1721 if (!reader->ChangeFont(size)) 2186 if (!reader->ChangeFont(size))
1722 { 2187 {
1723 reader->ChangeFont(size); 2188 qDebug("cf2");
2189 reader->ChangeFont(size);
1724 } 2190 }
2191 qDebug("ref");
1725 reader->refresh(); 2192 reader->refresh();
1726 m_fontBar->hide(); 2193 m_fontBar->hide();
1727 m_fontVisible = false; 2194 m_fontVisible = false;
1728 showEditTools(); 2195 qDebug("showedit");
2196 if (reader->isVisible()) showEditTools();
2197 qDebug("showeditdone");
1729} 2198}
1730 2199
1731void QTReaderApp::do_setfont(const QString& lcn) 2200void QTReaderApp::do_setfont(const QString& lcn)
1732{ 2201{
1733 setfontHelper(lcn); 2202 setfontHelper(lcn);
1734} 2203}
1735 2204
1736void QTReaderApp::do_autogen(const QString& regText) 2205void QTReaderApp::do_autogen(const QString& regText)
1737{ 2206{
1738 unsigned long fs, ts; 2207 unsigned long fs, ts;
1739 reader->sizes(fs,ts); 2208 reader->sizes(fs,ts);
1740 // qDebug("Reg:%s\n", (const tchar*)(regEdit->text())); 2209 // qDebug("Reg:%s\n", (const tchar*)(regEdit->text()));
1741 m_autogenstr = regText; 2210 m_autogenstr = regText;
1742 QRegExp re(regText); 2211 QRegExp re(regText);
1743 CBuffer buff; 2212 CBuffer buff;
1744 if (pBkmklist != NULL) delete pBkmklist; 2213 if (pBkmklist != NULL) delete pBkmklist;
1745 pBkmklist = new CList<Bkmk>; 2214 pBkmklist = new CList<Bkmk>;
1746 m_fBkmksChanged = true; 2215 m_fBkmksChanged = true;
1747 pbar->show(); 2216 pbar->show();
1748pbar->resize(width(), editBar->height()); 2217pbar->resize(width(), editBar->height());
1749 pbar->reset(); 2218 pbar->reset();
1750 qApp->processEvents(); 2219 qApp->processEvents();
1751 reader->setFocus(); 2220 reader->setFocus();
1752 reader->jumpto(0); 2221 reader->jumpto(0);
1753 int lastpc = 0; 2222 int lastpc = 0;
1754 int i = 0; 2223 int i = 0;
1755 while (i >= 0) 2224 while (i >= 0)
1756 { 2225 {
1757 unsigned int lcn = reader->locate(); 2226 unsigned int lcn = reader->locate();
1758 int pc = (100*lcn)/ts; 2227 int pc = (100*lcn)/ts;
1759 if (pc != lastpc) 2228 if (pc != lastpc)
1760 { 2229 {
1761 pbar->setProgress(pc); 2230 pbar->setProgress(pc);
1762 qApp->processEvents(); 2231 qApp->processEvents();
1763 if (reader->locate() != lcn) reader->jumpto(lcn); 2232 if (reader->locate() != lcn) reader->jumpto(lcn);
1764 reader->setFocus(); 2233 reader->setFocus();
1765 lastpc = pc; 2234 lastpc = pc;
1766 } 2235 }
1767 i = reader->buffdoc.getpara(buff); 2236 i = reader->buffdoc.getpara(buff);
1768#ifdef _UNICODE 2237#ifdef _UNICODE
1769 if (re.match(toQString(buff.data())) != -1) 2238 if (re.match(toQString(buff.data())) != -1)
1770#else 2239#else
1771 if (re.match(buff.data()) != -1) 2240 if (re.match(buff.data()) != -1)
1772#endif 2241#endif
1773 pBkmklist->push_back(Bkmk(buff.data(), NULL, lcn)); 2242 pBkmklist->push_back(Bkmk(buff.data(), NULL, lcn));
1774 } 2243 }
1775 pBkmklist->sort(); 2244 pBkmklist->sort();
1776 pbar->setProgress(100); 2245 pbar->setProgress(100);
1777 qApp->processEvents(); 2246 qApp->processEvents();
1778 pbar->hide(); 2247 pbar->hide();
1779} 2248}
1780 2249
1781void QTReaderApp::saveprefs() 2250void QTReaderApp::saveprefs()
1782{ 2251{
1783// reader->saveprefs("uqtreader"); 2252// reader->saveprefs("uqtreader");
1784 Config config( "uqtreader" ); 2253 Config config( APPDIR );
1785 config.setGroup( "View" ); 2254 config.setGroup( "View" );
1786 2255
1787 reader->m_lastposn = reader->pagelocate(); 2256 reader->m_lastposn = reader->pagelocate();
1788 2257
1789 config.writeEntry( "StripCr", reader->bstripcr ); 2258 config.writeEntry( "StripCr", reader->bstripcr );
1790 config.writeEntry( "AutoFmt", reader->bautofmt ); 2259 config.writeEntry( "AutoFmt", reader->bautofmt );
1791 config.writeEntry( "TextFmt", reader->btextfmt ); 2260 config.writeEntry( "TextFmt", reader->btextfmt );
1792 config.writeEntry( "StripHtml", reader->bstriphtml ); 2261 config.writeEntry( "StripHtml", reader->bstriphtml );
1793 config.writeEntry( "Dehyphen", reader->bdehyphen ); 2262 config.writeEntry( "Dehyphen", reader->bdehyphen );
2263 config.writeEntry( "OneSpace", reader->bonespace );
1794 config.writeEntry( "Unindent", reader->bunindent ); 2264 config.writeEntry( "Unindent", reader->bunindent );
1795 config.writeEntry( "Repara", reader->brepara ); 2265 config.writeEntry( "Repara", reader->brepara );
1796 config.writeEntry( "DoubleSpace", reader->bdblspce ); 2266 config.writeEntry( "DoubleSpace", reader->bdblspce );
1797 config.writeEntry( "Indent", reader->bindenter ); 2267 config.writeEntry( "Indent", reader->bindenter );
1798 config.writeEntry( "FontSize", (int)(reader->m_fontControl.currentsize()) ); 2268 config.writeEntry( "FontSize", (int)(reader->m_fontControl.currentsize()) );
1799 config.writeEntry( "ScrollDelay", reader->m_delay); 2269 config.writeEntry( "ScrollDelay", reader->m_delay);
1800 config.writeEntry( "LastFile", reader->m_lastfile ); 2270 config.writeEntry( "LastFile", reader->m_lastfile );
1801 config.writeEntry( "LastPosn", (int)(reader->pagelocate()) ); 2271 config.writeEntry( "LastPosn", (int)(reader->pagelocate()) );
1802 config.writeEntry( "PageMode", reader->m_bpagemode ); 2272 config.writeEntry( "PageMode", reader->m_bpagemode );
2273 config.writeEntry( "CursorNavigation", reader->m_navkeys );
1803 config.writeEntry( "MonoSpaced", reader->m_bMonoSpaced ); 2274 config.writeEntry( "MonoSpaced", reader->m_bMonoSpaced );
1804 config.writeEntry( "Fontname", reader->m_fontname ); 2275 config.writeEntry( "Fontname", reader->m_fontname );
1805 config.writeEntry( "Encoding", reader->m_encd ); 2276 config.writeEntry( "Encoding", reader->m_encd );
1806 config.writeEntry( "CharSpacing", reader->m_charpc ); 2277 config.writeEntry( "CharSpacing", reader->m_charpc );
1807 config.writeEntry( "Overlap", (int)(reader->m_overlap) ); 2278 config.writeEntry( "Overlap", (int)(reader->m_overlap) );
1808 config.writeEntry( "TargetApp", m_targetapp ); 2279 config.writeEntry( "TargetApp", m_targetapp );
1809 config.writeEntry( "TargetMsg", m_targetmsg ); 2280 config.writeEntry( "TargetMsg", m_targetmsg );
1810 config.writeEntry( "TwoTouch", m_twoTouch ); 2281 config.writeEntry( "TwoTouch", m_twoTouch );
1811 config.writeEntry( "Annotation", m_doAnnotation); 2282 config.writeEntry( "Annotation", m_doAnnotation);
1812 config.writeEntry( "Dictionary", m_doDictionary); 2283 config.writeEntry( "Dictionary", m_doDictionary);
1813 config.writeEntry( "Clipboard", m_doClipboard); 2284 config.writeEntry( "Clipboard", m_doClipboard);
1814 config.writeEntry( "SpaceTarget", m_spaceTarget); 2285 config.writeEntry( "SpaceTarget", m_spaceTarget);
2286#ifdef REPALM
2287 config.writeEntry( "Repalm", reader->brepalm );
2288#endif
1815 config.writeEntry( "Remap", reader->bremap ); 2289 config.writeEntry( "Remap", reader->bremap );
1816 config.writeEntry( "Peanut", reader->bpeanut ); 2290 config.writeEntry( "Peanut", reader->bpeanut );
1817 config.writeEntry( "MakeBold", reader->bmakebold ); 2291 config.writeEntry( "MakeBold", reader->bmakebold );
2292 config.writeEntry( "Continuous", reader->m_continuousDocument );
2293
2294 savefilelist();
1818} 2295}
1819 2296
1820void QTReaderApp::indentplus() 2297void QTReaderApp::indentplus()
1821{ 2298{
1822 reader->indentplus(); 2299 reader->indentplus();
1823} 2300}
1824 2301
1825void QTReaderApp::indentminus() 2302void QTReaderApp::indentminus()
1826{ 2303{
1827 reader->indentminus(); 2304 reader->indentminus();
1828} 2305}
1829 2306
1830/* 2307/*
1831void QTReaderApp::oldFile() 2308void QTReaderApp::oldFile()
1832{ 2309{
1833 qDebug("oldFile called"); 2310 qDebug("oldFile called");
1834 reader->setText(true); 2311 reader->setText(true);
1835 qDebug("settext called"); 2312 qDebug("settext called");
1836 showEditTools(); 2313 showEditTools();
1837 qDebug("showedit called"); 2314 qDebug("showedit called");
1838} 2315}
1839*/ 2316*/
1840 2317
1841/* 2318/*
1842void info_cb(Fl_Widget* o, void* _data) 2319void info_cb(Fl_Widget* o, void* _data)
1843{ 2320{
1844 2321
1845 if (infowin == NULL) 2322 if (infowin == NULL)
1846 { 2323 {
1847 2324
1848 infowin = new Fl_Window(160,240); 2325 infowin = new Fl_Window(160,240);
1849 filename = new Fl_Output(45,5,110,14,"Filename"); 2326 filename = new Fl_Output(45,5,110,14,"Filename");
1850 filesize = new Fl_Output(45,25,110,14,"Filesize"); 2327 filesize = new Fl_Output(45,25,110,14,"Filesize");
1851 textsize = new Fl_Output(45,45,110,14,"Textsize"); 2328 textsize = new Fl_Output(45,45,110,14,"Textsize");
1852 comprat = new CBar(45,65,110,14,"Ratio %"); 2329 comprat = new CBar(45,65,110,14,"Ratio %");
1853 posn = new Fl_Output(45,85,110,14,"Location"); 2330 posn = new Fl_Output(45,85,110,14,"Location");
1854 frcn = new CBar(45,105,110,14,"% Read"); 2331 frcn = new CBar(45,105,110,14,"% Read");
1855 about = new Fl_Multiline_Output(5,125,150,90); 2332 about = new Fl_Multiline_Output(5,125,150,90);
1856 about->value("TWReader - $Name$\n\nA file reader program for the Agenda\n\nReads text, PalmDoc and ppms format files"); 2333 about->value("TWReader - $Name$\n\nA file reader program for the Agenda\n\nReads text, PalmDoc and ppms format files");
1857 Fl_Button *jump_accept = new Fl_Button(62,220,35,14,"Okay"); 2334 Fl_Button *jump_accept = new Fl_Button(62,220,35,14,"Okay");
1858 infowin->set_modal(); 2335 infowin->set_modal();
1859 } 2336 }
1860 if (((reader_ui *)_data)->g_filename[0] != '\0') 2337 if (((reader_ui *)_data)->g_filename[0] != '\0')
1861 { 2338 {
1862 unsigned long fs,ts; 2339 unsigned long fs,ts;
1863 tchar sz[20]; 2340 tchar sz[20];
1864 ((reader_ui *)_data)->input->sizes(fs,ts); 2341 ((reader_ui *)_data)->input->sizes(fs,ts);
1865 unsigned long pl = ((reader_ui *)_data)->input->locate(); 2342 unsigned long pl = ((reader_ui *)_data)->input->locate();
1866 2343
1867 filename->value(((reader_ui *)_data)->g_filename); 2344 filename->value(((reader_ui *)_data)->g_filename);
1868 2345
1869 sprintf(sz,"%u",fs); 2346 sprintf(sz,"%u",fs);
1870 filesize->value(sz); 2347 filesize->value(sz);
1871 2348
1872 sprintf(sz,"%u",ts); 2349 sprintf(sz,"%u",ts);
1873 textsize->value(sz); 2350 textsize->value(sz);
1874 2351
1875 comprat->value(100-(100*fs + (ts >> 1))/ts); 2352 comprat->value(100-(100*fs + (ts >> 1))/ts);
1876 2353
1877 sprintf(sz,"%u",pl); 2354 sprintf(sz,"%u",pl);
1878 posn->value(sz); 2355 posn->value(sz);
1879 2356
1880 frcn->value((100*pl + (ts >> 1))/ts); 2357 frcn->value((100*pl + (ts >> 1))/ts);
1881 } 2358 }
1882 infowin->show(); 2359 infowin->show();
1883} 2360}
1884*/ 2361*/
1885 2362
1886void QTReaderApp::savebkmks() 2363void QTReaderApp::savebkmks()
1887{ 2364{
1888 if (pBkmklist != NULL) 2365 if (pBkmklist != NULL)
1889 { 2366 {
1890 BkmkFile bf((const char *)Global::applicationFileName("uqtreader",reader->m_string), true); 2367 BkmkFile bf((const char *)Global::applicationFileName(APPDIR, reader->m_string), true);
1891 bf.write(*pBkmklist); 2368 bf.write(*pBkmklist);
2369 }
2370 m_fBkmksChanged = false;
2371}
2372
2373void QTReaderApp::readfilelist()
2374{
2375 BkmkFile bf((const char *)Global::applicationFileName(APPDIR, ".openfiles"));
2376 qDebug("Reading open files");
2377 pOpenlist = bf.readall();
2378 if (pOpenlist != NULL) qDebug("...with success");
2379 else qDebug("...without success!");
2380}
2381
2382void QTReaderApp::savefilelist()
2383{
2384 if (pOpenlist != NULL)
2385 {
2386 BkmkFile bf((const char *)Global::applicationFileName(APPDIR, ".openfiles"), true);
2387 qDebug("Writing open files");
2388 bf.write(*pOpenlist);
1892 } 2389 }
1893 m_fBkmksChanged = false;
1894} 2390}
1895 2391
1896void QTReaderApp::readbkmks() 2392void QTReaderApp::readbkmks()
1897{ 2393{
1898 if (pBkmklist != NULL) 2394 if (pBkmklist != NULL)
1899 { 2395 {
1900 delete pBkmklist; 2396 delete pBkmklist;
2397 }
2398 struct stat fnstat;
2399 struct stat bkstat;
2400 if (
2401 stat((const char *)reader->m_lastfile, &fnstat) == 0
2402 &&
2403 stat((const char *)Global::applicationFileName(APPDIR, reader->m_string), &bkstat) == 0
2404 )
2405 {
2406 if (bkstat.st_mtime < fnstat.st_mtime)
2407 {
2408 unlink((const char *)Global::applicationFileName(APPDIR, reader->m_string));
2409 }
1901 } 2410 }
1902 BkmkFile bf((const char *)Global::applicationFileName("uqtreader",reader->m_string)); 2411
2412 BkmkFile bf((const char *)Global::applicationFileName(APPDIR, reader->m_string));
2413
1903 pBkmklist = bf.readall(); 2414 pBkmklist = bf.readall();
1904 m_fBkmksChanged = bf.upgraded(); 2415 m_fBkmksChanged = bf.upgraded();
1905 if (pBkmklist == NULL) 2416 if (pBkmklist == NULL)
1906 { 2417 {
1907 pBkmklist = reader->getbkmklist(); 2418 pBkmklist = reader->getbkmklist();
1908 } 2419 }
1909 if (pBkmklist != NULL) 2420 if (pBkmklist != NULL)
1910 pBkmklist->sort(); 2421 pBkmklist->sort();
1911} 2422}
1912 2423
1913void QTReaderApp::addbkmk() 2424void QTReaderApp::addbkmk()
1914{ 2425{
1915 m_nRegAction = cAddBkmk; 2426 m_nRegAction = cAddBkmk;
1916 regEdit->setText(reader->firstword()); 2427 regEdit->setText(reader->firstword());
1917 do_regedit(); 2428 do_regedit();
1918} 2429}
1919 2430
1920void QTReaderApp::do_addbkmk(const QString& text) 2431void QTReaderApp::do_addbkmk(const QString& text)
1921{ 2432{
1922 if (text.isEmpty()) 2433 if (text.isEmpty())
1923 { 2434 {
1924 QMessageBox::information(this, "OpieReader", "Need a name for the bookmark\nSelect add again", 1); 2435 QMessageBox::information(this, PROGNAME, "Need a name for the bookmark\nSelect add again", 1);
1925 } 2436 }
1926 else 2437 else
1927 { 2438 {
1928 if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>; 2439 if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>;
1929#ifdef _UNICODE 2440#ifdef _UNICODE
1930 CBuffer buff; 2441 CBuffer buff;
1931 int i = 0; 2442 int i = 0;
1932 for (i = 0; i < text.length(); i++) 2443 for (i = 0; i < text.length(); i++)
1933 { 2444 {
1934 buff[i] = text[i].unicode(); 2445 buff[i] = text[i].unicode();
1935 } 2446 }
1936 buff[i] = 0; 2447 buff[i] = 0;
1937 pBkmklist->push_front(Bkmk(buff.data(), NULL, reader->pagelocate())); 2448 pBkmklist->push_front(Bkmk(buff.data(), NULL, reader->pagelocate()));
1938#else 2449#else
1939 pBkmklist->push_front(Bkmk((const tchar*)text,reader->pagelocate())); 2450 pBkmklist->push_front(Bkmk((const tchar*)text, reader->pagelocate()));
1940#endif 2451#endif
1941 m_fBkmksChanged = true; 2452 m_fBkmksChanged = true;
1942 pBkmklist->sort(); 2453 pBkmklist->sort();
1943 } 2454 }
1944} 2455}
1945 2456
1946void QTReaderApp::OnRedraw() 2457void QTReaderApp::OnRedraw()
1947{ 2458{
1948 if (pBkmklist != NULL) 2459 if (pBkmklist != NULL)
1949 { 2460 {
1950 bool found = findNextBookmark(reader->pagelocate()); 2461 bool found = findNextBookmark(reader->pagelocate());
1951 m_bkmkAvail->setEnabled(found); 2462 m_bkmkAvail->setEnabled(found);
1952 } 2463 }
1953} 2464}
1954 2465
1955void QTReaderApp::showAnnotation() 2466void QTReaderApp::showAnnotation()
1956{ 2467{
1957 m_annoWin->setName(toQString(m_anno->name())); 2468 m_annoWin->setName(toQString(m_anno->name()));
1958 m_annoWin->setAnno(toQString(m_anno->anno())); 2469 m_annoWin->setAnno(toQString(m_anno->anno()));
1959 m_annoIsEditing = false; 2470 m_annoIsEditing = false;
2471 Global::showInputMethod();
1960 editorStack->raiseWidget( m_annoWin ); 2472 editorStack->raiseWidget( m_annoWin );
1961 m_annoWin->setFocus(); 2473 m_annoWin->setFocus();
1962} 2474}
1963 2475
1964void QTReaderApp::OnWordSelected(const QString& wrd, size_t posn, const QString& line) 2476void QTReaderApp::OnWordSelected(const QString& wrd, size_t posn, const QString& line)
1965{ 2477{
1966// qDebug("OnWordSelected(%u):%s", posn, (const char*)wrd); 2478// qDebug("OnWordSelected(%u):%s", posn, (const char*)wrd);
1967 2479
1968 if (m_doClipboard) 2480 if (m_doClipboard)
1969 { 2481 {
1970 QClipboard* cb = QApplication::clipboard(); 2482 QClipboard* cb = QApplication::clipboard();
1971 cb->setText(wrd); 2483 cb->setText(wrd);
1972 if (wrd.length() > 10) 2484 if (wrd.length() > 10)
1973 { 2485 {
1974 Global::statusMessage(wrd.left(8) + ".."); 2486 Global::statusMessage(wrd.left(8) + "..");
1975 } 2487 }
1976 else 2488 else
1977 { 2489 {
1978 Global::statusMessage(wrd); 2490 Global::statusMessage(wrd);
1979 } 2491 }
1980 } 2492 }
1981 if (m_doAnnotation) 2493 if (m_doAnnotation)
1982 { 2494 {
1983// addAnno(wrd, "Need to be able to edit this", posn); 2495 //addAnno(wrd, "Need to be able to edit this", posn);
1984 m_annoWin->setName(line); 2496 m_annoWin->setName(line);
1985 m_annoWin->setAnno(""); 2497 m_annoWin->setAnno("");
1986 m_annoWin->setPosn(posn); 2498 m_annoWin->setPosn(posn);
1987 m_annoIsEditing = true; 2499 m_annoIsEditing = true;
1988 editorStack->raiseWidget( m_annoWin ); 2500 Global::showInputMethod();
2501 editorStack->raiseWidget( m_annoWin );
1989 } 2502 }
1990 if (m_doDictionary) 2503 if (m_doDictionary)
1991 { 2504 {
1992 if (!m_targetapp.isEmpty() && !m_targetmsg.isEmpty()) 2505 if (!m_targetapp.isEmpty() && !m_targetmsg.isEmpty())
1993 { 2506 {
1994 QCopEnvelope e(("QPE/Application/"+m_targetapp).utf8(), (m_targetmsg+"(QString)").utf8()); 2507 QCopEnvelope e(("QPE/Application/"+m_targetapp).utf8(), (m_targetmsg+"(QString)").utf8());
1995 e << wrd; 2508 e << wrd;
1996 } 2509 }
1997 } 2510 }
1998} 2511}
1999 2512
2000void QTReaderApp::OnActionPressed() 2513void QTReaderApp::OnActionPressed()
2001{ 2514{
2002 switch (m_spaceTarget) 2515 switch (m_spaceTarget)
2003 { 2516 {
2004 case cesOpenFile: 2517 case cesOpenFile:
2005 { 2518 {
2006 fileOpen(); 2519 fileOpen();
2007 } 2520 }
2008 break; 2521 break;
2009 case cesAutoScroll: 2522 case cesAutoScroll:
2010 { 2523 {
2011 reader->setautoscroll(!reader->m_autoScroll); 2524 reader->setautoscroll(!reader->m_autoScroll);
2012 setScrollState(reader->m_autoScroll); 2525 setScrollState(reader->m_autoScroll);
2013 } 2526 }
2014 break; 2527 break;
2015 case cesActionMark: 2528 case cesActionMark:
2016 { 2529 {
2017 addbkmk(); 2530 addbkmk();
2018 } 2531 }
2019 break; 2532 break;
2020 default: 2533 case cesFullScreen:
2021 { 2534 {
2022 qDebug("Unknown ActionType:%u", m_spaceTarget); 2535 m_actFullscreen->setOn(true);
2023 } 2536 }
2024 break; 2537 break;
2538 default:
2539 {
2540 qDebug("Unknown ActionType:%u", m_spaceTarget);
2541 }
2542 break;
2025 } 2543 }
2026} 2544}
2027 2545
2028void QTReaderApp::setTwoTouch(bool _b) { reader->setTwoTouch(_b); } 2546void QTReaderApp::setTwoTouch(bool _b) { reader->setTwoTouch(_b); }
2029void QTReaderApp::restoreFocus() { reader->setFocus(); } 2547void QTReaderApp::restoreFocus() { reader->setFocus(); }
2548
2549/*
2550void QTReaderApp::setstate(unsigned char* _sd, unsigned short _sdlen)
2551{
2552 unsigned short sdlen;
2553 memcpy(&sdlen, _sd, sizeof(sdlen));
2554 sdlen -= sizeof(sdlen);
2555 _sd += sizeof(sdlen);
2556 statedata* sd;
2557 char* data;
2558 if (sdlen < sizeof(statedata)+1)
2559 {
2560 sdlen = sizeof(statedata)+1;
2561 }
2562 data = new char[sdlen];
2563 sd = (statedata*)data;
2564 memcpy(sd, _sd, sdlen);
2565 data[sdlen] = 0;
2566 reader->setstate(*sd);
2567 delete [] data;
2568}
2569
2570void QTReaderApp::getstate(unsigned char*& data, unsigned short& len)
2571{
2572 unsigned char* olddata = data;
2573 unsigned short oldlen = len;
2574 len = oldlen+sizeof(unsigned short)+sizeof(statedata)+reader->m_fontname.length();
2575 data = new unsigned char[len];
2576 memcpy(data, olddata, oldlen);
2577 delete [] olddata;
2578 memcpy(data+oldlen, &len, sizeof(len));
2579 statedata* sd = (statedata*)(data+oldlen+sizeof(unsigned short));
2580
2581 sd->bstripcr = reader->bstripcr;
2582 sd->btextfmt = reader->btextfmt;
2583 sd->bautofmt = reader->bautofmt;
2584 sd->bstriphtml = reader->bstriphtml;
2585 sd->bpeanut = reader->bpeanut;
2586 sd->bdehyphen = reader->bdehyphen;
2587 sd->bonespace = reader->bonespace;
2588 sd->bunindent = reader->bunindent;
2589 sd->brepara = reader->brepara;
2590 sd->bdblspce = reader->bdblspce;
2591 sd->m_bpagemode = reader->m_bpagemode;
2592 sd->m_navkeys = reader->m_navkeys;
2593 sd->m_bMonoSpaced = reader->m_bMonoSpaced;
2594 sd->bremap = reader->bremap;
2595 sd->bmakebold = reader->bmakebold;
2596 sd->Continuous = reader->m_continuousDocument;
2597#ifdef REPALM
2598 sd->brepalm = reader->brepalm;
2599#endif
2600 sd->bindenter = reader->bindenter;
2601 sd->m_textsize = reader->m_textsize; //reader->m_fontControl.currentsize()
2602 sd->m_encd = reader->m_encd;
2603 sd->m_charpc = reader->m_charpc;
2604 strcpy(sd->m_fontname, reader->m_fontname.latin1());
2605}
2606*/
diff --git a/noncore/apps/opie-reader/QTReaderApp.h b/noncore/apps/opie-reader/QTReaderApp.h
index 22c57e4..cb33e4a 100644
--- a/noncore/apps/opie-reader/QTReaderApp.h
+++ b/noncore/apps/opie-reader/QTReaderApp.h
@@ -1,263 +1,291 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef __QTREADERAPP_H 20#ifndef __QTREADERAPP_H
21#define __QTREADERAPP_H 21#define __QTREADERAPP_H
22 22
23//#define __ISEARCH 23//#define __ISEARCH
24 24
25#define MAX_ENCODING 6 25#define MAX_ENCODING 6
26#define MAX_ACTIONS 3 26#define MAX_ACTIONS 4
27 27
28#include <qmainwindow.h> 28#include <qmainwindow.h>
29#include "CExpander.h" 29#include "CExpander.h"
30#include <qlist.h> 30#include <qlist.h>
31#include <qpe/filemanager.h> 31#include <qpe/filemanager.h>
32#include <qmap.h> 32#include <qmap.h>
33#include <qlineedit.h> 33#include <qlineedit.h>
34#include <qstack.h> 34#include <qstack.h>
35#include <qlistbox.h> 35#include <qlistbox.h>
36//#include "Queue.h" 36//#include "Queue.h"
37 37
38class QWidgetStack; 38class QWidgetStack;
39class QToolButton; 39class QToolButton;
40class QPopupMenu; 40class QPopupMenu;
41class QToolBar; 41class QToolBar;
42class QPEToolBar; 42//class QPEToolBar;
43class CBkmkSelector; 43class CBkmkSelector;
44class QProgressBar; 44class QProgressBar;
45class QAction; 45class QAction;
46class CAnnoEdit; 46class CAnnoEdit;
47class QFloatBar; 47class QFloatBar;
48class CDrawBuffer; 48class CDrawBuffer;
49class QTReader; 49class QTReader;
50class QPixmap;
50 51
51enum ActionTypes 52enum ActionTypes
52{ 53{
53 cesOpenFile = 0, 54 cesOpenFile = 0,
54 cesAutoScroll, 55 cesAutoScroll,
55 cesActionMark 56 cesActionMark,
57 cesFullScreen
56}; 58};
57 59
58#ifdef __ISEARCH 60#ifdef __ISEARCH
59struct searchrecord 61struct searchrecord
60{ 62{
61 QString s; 63 QString s;
62 size_t pos; 64 size_t pos;
63 searchrecord(const QString& _s, size_t _pos) : s(_s), pos(_pos) {} 65 searchrecord(const QString& _s, size_t _pos) : s(_s), pos(_pos) {}
64}; 66};
65#endif 67#endif
66 68
67class infowin; 69class infowin;
70class GraphicWin;
68 71
69class QTReaderApp : public QMainWindow 72class QTReaderApp : public QMainWindow
70{ 73{
71 Q_OBJECT 74 Q_OBJECT
72 75
73 unsigned long m_savedpos; 76 unsigned long m_savedpos;
74 bool m_annoIsEditing; 77 bool m_annoIsEditing;
75 78
76 public: 79 public:
77 QTReaderApp( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); 80 QTReaderApp( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
78 ~QTReaderApp(); 81 ~QTReaderApp();
79 82 void suspend();
80 void openFile( const QString & ); 83 void openFile( const QString & );
81 84
82 void setScrollState(bool _b); 85 void setScrollState(bool _b);
83 86
84 protected: 87 protected:
85 void setfontHelper(const QString& lcn, int size = 0); 88 void setfontHelper(const QString& lcn, int size = 0);
86 QAction* m_bkmkAvail; 89 QAction* m_bkmkAvail, *m_actFullscreen;
87 CAnnoEdit* m_annoWin; 90 CAnnoEdit* m_annoWin;
88 Bkmk* m_anno; 91 Bkmk* m_anno;
92// void resizeEvent(QResizeEvent* e);
93 void keyPressEvent(QKeyEvent* e);
89 void closeEvent( QCloseEvent *e ); 94 void closeEvent( QCloseEvent *e );
90 void readbkmks(); 95 void readbkmks();
91 void do_mono(const QString&); 96 void do_mono(const QString&);
92 void do_jump(const QString&); 97 void do_jump(const QString&);
93 void do_overlap(const QString&); 98 void do_overlap(const QString&);
94 void do_settarget(const QString&); 99 void do_settarget(const QString&);
95 int EncNameToInt(const QString&); 100 int EncNameToInt(const QString&);
96 ActionTypes ActNameToInt(const QString&); 101 ActionTypes ActNameToInt(const QString&);
97 bool m_doAnnotation; 102 bool m_doAnnotation;
98 bool m_doDictionary; 103 bool m_doDictionary;
99 bool m_doClipboard; 104 bool m_doClipboard;
105 bool m_fullscreen;
100 106
101 public: 107 public:
102 void saveprefs(); 108 void saveprefs();
103private slots: 109private slots:
110 void zoomin();
111 void zoomout();
112 void setfullscreen(bool sfs);
113 void setcontinuous(bool sfs);
104 void setTwoTouch(bool _b); 114 void setTwoTouch(bool _b);
105 void restoreFocus(); 115 void restoreFocus();
106 void OnAnnotation(bool _b) 116 void OnAnnotation(bool _b)
107 { 117 {
108 m_doAnnotation = _b; 118 m_doAnnotation = _b;
109 } 119 }
110 void OnDictionary(bool _b) 120 void OnDictionary(bool _b)
111 { 121 {
112 m_doDictionary = _b; 122 m_doDictionary = _b;
113 } 123 }
114 void OnClipboard(bool _b) 124 void OnClipboard(bool _b)
115 { 125 {
116 m_doClipboard = _b; 126 m_doClipboard = _b;
117 } 127 }
118 void OnWordSelected(const QString&, size_t, const QString&); 128 void OnWordSelected(const QString&, size_t, const QString&);
129 void showgraphic(QPixmap&);
119 void addAnno(const QString&, const QString&, size_t); 130 void addAnno(const QString&, const QString&, size_t);
120 void addAnno(const QString&, const QString&); 131 void addAnno(const QString&, const QString&);
121 void addanno(); 132 void addanno();
122 void showAnnotation(); 133 void showAnnotation();
123 void do_setfont(const QString&); 134 void do_setfont(const QString&);
124 void encodingSelected(QAction*); 135 void encodingSelected(QAction*);
125 void buttonActionSelected(QAction*); 136 void buttonActionSelected(QAction*);
126 void msgHandler(const QCString&, const QByteArray&); 137 void msgHandler(const QCString&, const QByteArray&);
127 void monospace(bool); 138 void monospace(bool);
128 void jump(); 139 void jump();
129 void setoverlap(); 140 void setoverlap();
130 void settarget(); 141 void settarget();
131 void setspacing(); 142 void setspacing();
132 void setfont(); 143 void setfont();
133 void clearBkmkList(); 144 void clearBkmkList();
134 void listBkmkFiles(); 145 void listBkmkFiles();
135 void editMark(); 146 void editMark();
136 void autoScroll(bool); 147 void autoScroll(bool);
137 void addbkmk(); 148 void addbkmk();
138 void savebkmks(); 149 void savebkmks();
139 //void importFiles(); 150 //void importFiles();
140 void infoClose(); 151 void infoClose();
141 // void oldFile(); 152 // void oldFile();
142 void showinfo(); 153 void showinfo();
143 void setDocument(const QString&); 154 void setDocument(const QString&);
144 void TBD();
145 void TBDzoom();
146 155
147 void indentplus(); 156 void indentplus();
148 void indentminus(); 157 void indentminus();
149 158
150 void fileOpen(); 159 void fileOpen();
160 void fileClose();
151 161
152 void editCopy(); 162 void editCopy();
153 void editFind(); 163 void editFind();
154 164
155 void pageup(); 165 void pageup();
156 void pagedn(); 166 void pagedn();
157 167
158 void findNext(); 168 void findNext();
159 void findClose(); 169 void findClose();
160 170
161 void regClose(); 171 void regClose();
162 172
163#ifdef __ISEARCH 173#ifdef __ISEARCH
164// void search( const QString& ); 174// void search( const QString& );
165#else 175#else
166 void search(); 176 void search();
167#endif 177#endif
168 178
169 void openFile( const DocLnk & );
170 void showEditTools(); 179 void showEditTools();
171 180
172 void stripcr(bool); 181 void stripcr(bool);
182 void onespace(bool);
183#ifdef REPALM
184// void repalm(bool);
185#endif
173 void peanut(bool _b); 186 void peanut(bool _b);
174 void remap(bool); 187 void remap(bool);
175 void embolden(bool); 188 void embolden(bool);
176 void autofmt(bool); 189 void autofmt(bool);
177 void textfmt(bool); 190 void textfmt(bool);
178 void striphtml(bool); 191 void striphtml(bool);
179 void dehyphen(bool); 192 void dehyphen(bool);
180 void unindent(bool); 193 void unindent(bool);
181 void repara(bool); 194 void repara(bool);
182 void dblspce(bool); 195 void dblspce(bool);
183 void pagemode(bool); 196 void pagemode(bool);
197 void navkeys(bool);
184 // void gotobkmk(const QString& bm); 198 // void gotobkmk(const QString& bm);
185 void gotobkmk(int); 199 void gotobkmk(int);
186 void cancelbkmk(); 200 void cancelbkmk();
187 void do_gotomark(); 201 void do_gotomark();
188 void do_delmark(); 202 void do_delmark();
189 void do_autogen(); 203 void do_autogen();
190 void do_regaction(); 204 void do_regaction();
191 void OnRedraw(); 205 void OnRedraw();
192 void OnActionPressed(); 206 void OnActionPressed();
193 207
194 private: 208 private:
209/*
210 void setstate(unsigned char* _sd, unsigned short _sdlen);
211 void getstate(unsigned char*& data, unsigned short& len);
212*/
213 void fileOpen2();
214 void readfilelist();
215 void savefilelist();
216 void updatefileinfo();
217 bool openfrombkmk(Bkmk*);
195 QString m_targetapp, m_targetmsg; 218 QString m_targetapp, m_targetmsg;
196 void listbkmk(); 219 void listbkmk(CList<Bkmk>*, const QString& _lab = QString::null);
220 QString usefilebrowser();
197 void do_regedit(); 221 void do_regedit();
198 void colorChanged( const QColor &c ); 222 void colorChanged( const QColor &c );
199 void clear(); 223 void clear();
200 void updateCaption(); 224 void updateCaption();
201 void do_autogen(const QString&); 225 void do_autogen(const QString&);
202 void do_addbkmk(const QString&); 226 void do_addbkmk(const QString&);
203 bool findNextBookmark(size_t start); 227 bool findNextBookmark(size_t start);
204 228
205 private: 229 private:
206 230
207 QAction* m_scrollButton; 231 QAction* m_scrollButton;
208 232
209 QAction* m_EncodingAction[MAX_ENCODING]; 233 QAction* m_EncodingAction[MAX_ENCODING];
210 234
211 QAction* m_buttonAction[MAX_ACTIONS]; 235 QAction* m_buttonAction[MAX_ACTIONS];
212 236
213 CBkmkSelector* bkmkselector; 237 CBkmkSelector* bkmkselector;
214 238
215 ActionTypes m_spaceTarget; 239 ActionTypes m_spaceTarget;
216 size_t searchStart; 240 size_t searchStart;
217#ifdef __ISEARCH 241#ifdef __ISEARCH
218 QStack<searchrecord>* searchStack; 242 QStack<searchrecord>* searchStack;
219 bool dosearch(size_t start, CDrawBuffer& test, const QString& arg); 243 bool dosearch(size_t start, CDrawBuffer& test, const QString& arg);
220#else 244#else
221 bool dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg); 245 bool dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg);
222#endif 246#endif
223 QWidgetStack *editorStack; 247 QWidgetStack *editorStack;
224 QTReader* reader; 248 QTReader* reader;
225 QComboBox* m_fontSelector; 249 QComboBox* m_fontSelector;
226 QPEToolBar /* *menu,*/ *editBar; 250// QPEToolBar /* *menu,*/ *editBar;
251 QToolBar /* *menu,*/ *editBar;
227 QFloatBar *searchBar, *regBar/*, *m_fontBar*/; 252 QFloatBar *searchBar, *regBar/*, *m_fontBar*/;
228 QToolBar /* *searchBar, *regBar,*/ *m_fontBar; 253 QToolBar /* *searchBar, *regBar,*/ *m_fontBar;
229 QLineEdit *searchEdit, *regEdit; 254 QLineEdit *searchEdit, *regEdit;
230 DocLnk *doc;
231 bool searchVisible; 255 bool searchVisible;
232 bool regVisible; 256 bool regVisible;
233 bool m_fontVisible, m_twoTouch; 257 bool m_fontVisible, m_twoTouch;
234 bool bFromDocView; 258 bool bFromDocView;
235 static unsigned long m_uid; 259 static unsigned long m_uid;
236 long unsigned get_unique_id() { return m_uid++; } 260 long unsigned get_unique_id() { return m_uid++; }
237 /* 261 /*
238 void resizeEvent( QResizeEvent * r) 262 void resizeEvent( QResizeEvent * r)
239 { 263 {
240 qDebug("resize:(%u,%u)", r->oldSize().width(), r->oldSize().height()); 264 qDebug("resize:(%u,%u)", r->oldSize().width(), r->oldSize().height());
241 qDebug("resize:(%u,%u)", r->size().width(), r->size().height()); 265 qDebug("resize:(%u,%u)", r->size().width(), r->size().height());
242 // bgroup->move( width()-bgroup->width(), 0 ); 266 // bgroup->move( width()-bgroup->width(), 0 );
243 } 267 }
244 */ 268 */
245 CList<Bkmk>* pBkmklist; 269 CList<Bkmk>* pBkmklist;
270 CList<Bkmk>* pOpenlist;
246 infowin* m_infoWin; 271 infowin* m_infoWin;
272 GraphicWin* m_graphicwin;
247 QProgressBar* pbar; 273 QProgressBar* pbar;
248 bool m_fBkmksChanged; 274 bool m_fBkmksChanged;
249 int m_nRegAction; 275 int m_nRegAction;
250 QString m_autogenstr; 276 QString m_autogenstr;
251 bool m_dontSave; 277 bool m_dontSave;
252}; 278};
253 279
254const int cAutoGen = 0; 280const int cAutoGen = 0;
255const int cAddBkmk = 1; 281const int cAddBkmk = 1;
256const int cDelBkmk = 2; 282const int cDelBkmk = 2;
257const int cGotoBkmk = 3; 283const int cGotoBkmk = 3;
258const int cRmBkmkFile = 4; 284const int cRmBkmkFile = 4;
259const int cJump = 5; 285const int cJump = 5;
260const int cMonoSpace = 6; 286const int cMonoSpace = 6;
261const int cOverlap = 7; 287const int cOverlap = 7;
262const int cSetTarget = 8; 288const int cSetTarget = 8;
289const int cOpenFile = 9;
290
263#endif 291#endif
diff --git a/noncore/apps/opie-reader/StateData.h b/noncore/apps/opie-reader/StateData.h
new file mode 100644
index 0000000..0cb0f07
--- a/dev/null
+++ b/noncore/apps/opie-reader/StateData.h
@@ -0,0 +1,32 @@
1#ifndef __STATEDATA_H
2#define __STATEDATA_H
3
4struct statedata
5{
6 bool bstripcr/*:1*/;
7 bool btextfmt/*:1*/;
8 bool bautofmt/*:1*/;
9 bool bstriphtml/*:1*/;
10 bool bpeanut/*:1*/;
11 bool bdehyphen/*:1*/;
12 bool bonespace/*:1*/;
13 bool bunindent/*:1*/;
14 bool brepara/*:1*/;
15 bool bdblspce/*:1*/;
16 bool m_bpagemode/*:1*/;
17 bool m_navkeys/*:1*/;
18 bool m_bMonoSpaced/*:1*/;
19 bool bremap/*:1*/;
20 bool bmakebold/*:1*/;
21 bool Continuous/*:1*/;
22#ifdef REPALM
23 bool brepalm/*:1*/;
24#endif
25 int bindenter;
26 int m_textsize;
27 int m_encd;
28 int m_charpc;
29 char m_fontname[1];
30};
31
32#endif
diff --git a/noncore/apps/opie-reader/StyleConsts.cpp b/noncore/apps/opie-reader/StyleConsts.cpp
new file mode 100644
index 0000000..e111dbd
--- a/dev/null
+++ b/noncore/apps/opie-reader/StyleConsts.cpp
@@ -0,0 +1,99 @@
1
2#include <qpixmap.h>
3#include "StyleConsts.h"
4
5GraphicLink::~GraphicLink() { delete graphic; }
6
7pmstore::~pmstore()
8{
9// qDebug("Deleting image");
10 delete graphic;
11}
12
13CStyle::~CStyle()
14{
15 if (graphic != NULL)
16 {
17 if (--(graphic->count) == 0)
18 {
19 delete graphic;
20 }
21 }
22}
23
24CStyle::CStyle(CStyle& rhs) : graphic(NULL)
25{
26 *this = rhs;
27}
28
29CStyle::CStyle(const CStyle& rhs) : graphic(NULL)
30{
31 *this = rhs;
32}
33
34CStyle& CStyle::operator=(const CStyle& rhs)
35{
36 if (rhs.graphic != NULL)
37 {
38 (rhs.graphic->count)++;
39 if (graphic != NULL)
40 {
41 if (--(graphic->count) == 0)
42 {
43 delete graphic;
44 }
45 }
46 graphic = rhs.graphic;
47 }
48 else
49 {
50 if (graphic != NULL)
51 {
52 if (--(graphic->count) == 0)
53 {
54 delete graphic;
55 }
56 graphic = NULL;
57 }
58 }
59 sty = rhs.sty;
60 return *this;
61}
62
63void CStyle::clearPicture()
64{
65 if (graphic != NULL)
66 {
67 if (--(graphic->count) == 0)
68 {
69 delete graphic;
70 }
71 graphic = NULL;
72 }
73}
74
75void CStyle::unset()
76{
77 sty.unset();
78 if (graphic != NULL)
79 {
80 if (--(graphic->count) == 0)
81 {
82 delete graphic;
83 }
84 graphic = NULL;
85 }
86}
87
88void CStyle::setPicture(QPixmap* _g, bool il, unsigned long tgt)
89{
90 if (graphic != NULL)
91 {
92 if (--(graphic->count) == 0)
93 {
94 delete graphic;
95 }
96 graphic = NULL;
97 }
98 if (_g != NULL) graphic = new pmstore(_g, il, tgt);
99}
diff --git a/noncore/apps/opie-reader/StyleConsts.h b/noncore/apps/opie-reader/StyleConsts.h
index b6dd861..5aacdf0 100644
--- a/noncore/apps/opie-reader/StyleConsts.h
+++ b/noncore/apps/opie-reader/StyleConsts.h
@@ -1,113 +1,177 @@
1#ifndef __STYLECONSTS_H 1#ifndef __STYLECONSTS_H
2#define __STYLECONSTS_H 2#define __STYLECONSTS_H
3 3
4typedef unsigned short StyleType; 4typedef unsigned short StyleType;
5 5
6class CStyle 6#include <stdlib.h>
7#include <qglobal.h>
8class QPixmap;
9
10struct GraphicLink
7{ 11{
8// 15 14 13-5 4 3 2 1 0 12 QPixmap* graphic;
9//bold italic spare align align fs fs fs 13 bool isLink;
10 static const StyleType m_Bold = 1 << 15; 14 unsigned long link;
11 static const StyleType m_Italic = 1 << 14; 15 GraphicLink(QPixmap* p, bool isLnk, unsigned long tgt) :
12 static const StyleType m_FontMask = 7; 16 graphic(p), isLink(isLnk), link(tgt) {}
13 static const StyleType m_FontBase = 3; 17 ~GraphicLink();
14 18};
15 static const StyleType m_AlignShift = 3;
16 static const StyleType m_AlignMask = 3 << m_AlignShift;
17 static const StyleType m_EveryBit = 0xffff;
18 19
20struct pmstore
21{
22 unsigned int count;
23 GraphicLink* graphic;
24 pmstore(QPixmap* p, bool isLnk, unsigned long tgt) : count(1)
25 {
26 graphic = new GraphicLink(p, isLnk, tgt);
27 }
28 ~pmstore();
29};
19 30
20 StyleType sty; 31enum EalignmentType
32{
33 m_AlignLeft,
34 m_AlignRight,
35 m_AlignCentre,
36 m_AlignJustify
37};
21 38
22 void unjustify() { sty &= m_EveryBit ^ m_AlignMask; } 39class CBasicStyle
40{
41 friend class CStyle;
42 bool m_bold,
43 m_italic;
44 int m_fontsize;
45 EalignmentType m_align;
23 unsigned char red, green, blue; 46 unsigned char red, green, blue;
24 unsigned long data; 47 unsigned long data;
25 bool isLink; 48 bool isLink;
26 public: 49 bool m_underline;
27 unsigned char Red() { return red; } 50 bool m_strikethru;
28 unsigned char Green() { return green; } 51 bool m_monospaced;
29 unsigned char Blue() { return blue; } 52 unsigned char m_leftmargin, m_rightmargin;
30 void setColour(unsigned char r, unsigned char g, unsigned char b) 53 CBasicStyle()
31 { 54 {
32 red = r; 55 unset();
33 green = g; 56 }
34 blue = b; 57 bool operator!=(const CBasicStyle& rhs)
35 } 58 {
36 static const StyleType m_AlignLeft = 0; 59 return (memcmp(this, &rhs, sizeof(CBasicStyle)) != 0);
37 static const StyleType m_AlignRight = 1 << m_AlignShift; 60 }
38 static const StyleType m_AlignCentre = 2 << m_AlignShift;
39 static const StyleType m_AlignJustify = 3 << m_AlignShift;
40 CStyle()
41 :
42 sty(m_FontBase),
43 red(0), green(0), blue(0),
44 data(0), isLink(false)
45 {}
46// CStyle(const int _fs) : sty(m_FontBase+_fs) {}
47
48 void unset() 61 void unset()
49 { 62 {
50 sty = m_FontBase; 63 m_bold = false;
64 m_italic = false;
65 m_fontsize = 0;
66 m_align = m_AlignLeft;
51 red = green = blue = 0; 67 red = green = blue = 0;
52 data = 0; 68 data = 0;
53 isLink = false; 69 isLink = false;
70 m_underline = false;
71 m_strikethru = false;
72 m_leftmargin = 0;
73 m_rightmargin = 0;
74 m_monospaced = false;
54 } 75 }
76};
55 77
56 void setBold() { sty |= m_Bold; } 78class CStyle
57 void setItalic() { sty |= m_Italic; } 79{
58 void unsetBold() { sty &= m_EveryBit ^ m_Bold; } 80 CBasicStyle sty;
59 void unsetItalic() { sty &= m_EveryBit ^ m_Italic; } 81 pmstore* graphic;
60 bool isBold() { return ((sty & m_Bold) != 0); } 82 public:
61 bool isItalic() { return ((sty & m_Italic) != 0); } 83 bool getPictureLink()
84 {
85 return (graphic != NULL && graphic->graphic->isLink);
86 }
87 unsigned long getPictureLinkData()
88 {
89 return graphic->graphic->link;
90 }
91 void setLeftMargin(unsigned char m) { sty.m_leftmargin = m; }
92 unsigned char getLeftMargin() { return sty.m_leftmargin; }
93 void setRightMargin(unsigned char m) { sty.m_rightmargin = m; }
94 unsigned char getRightMargin() { return sty.m_rightmargin; }
95 unsigned char Red() { return sty.red; }
96 unsigned char Green() { return sty.green; }
97 unsigned char Blue() { return sty.blue; }
98 void setColour(unsigned char r, unsigned char g, unsigned char b)
99 {
100 sty.red = r;
101 sty.green = g;
102 sty.blue = b;
103 }
104 CStyle() : graphic(NULL) {}
105 ~CStyle();
106 CStyle(CStyle&);
107 CStyle(const CStyle&);
108 CStyle& operator=(const CStyle&);
109 void unset();
110 bool isPicture() { return (graphic != NULL); }
111 void clearPicture();
112 void setPicture(QPixmap* _g, bool il=false, unsigned long tgt=0);
113 QPixmap* getPicture()
114 {
115 QPixmap* pm = ((graphic != NULL) ? graphic->graphic->graphic : NULL);
116 return pm;
117 }
118 void setUnderline() { sty.m_underline = true; }
119 void unsetUnderline() { sty.m_underline = false; }
120 bool isUnderline() { return sty.m_underline; }
121 void setStrikethru() { sty.m_strikethru = true; }
122 void unsetStrikethru() { sty.m_strikethru = false; }
123 bool isStrikethru() { return sty.m_strikethru; }
124 void setBold() { sty.m_bold = true; }
125 void unsetBold() { sty.m_bold = false; }
126 bool isBold() { return sty.m_bold; }
127 void setItalic() { sty.m_italic = true; }
128 void unsetItalic() { sty.m_italic = false; }
129 bool isItalic() { return sty.m_italic; }
130 void setMono() { sty.m_monospaced = true; }
131 void unsetMono() { sty.m_monospaced = false; }
132 bool isMono() { return sty.m_monospaced; }
62 133
63 void setLeftJustify() 134 void setLeftJustify()
64 { 135 {
65 unjustify(); 136 sty.m_align = m_AlignLeft;
66 sty |= m_AlignLeft;
67 } 137 }
68 void setRightJustify() 138 void setRightJustify()
69 { 139 {
70 unjustify(); 140 sty.m_align = m_AlignRight;
71 sty |= m_AlignRight;
72 } 141 }
73 void setCentreJustify() 142 void setCentreJustify()
74 { 143 {
75 unjustify(); 144 sty.m_align = m_AlignCentre;
76 sty |= m_AlignCentre;
77 } 145 }
78 void setFullJustify() 146 void setFullJustify()
79 { 147 {
80 unjustify(); 148 sty.m_align = m_AlignJustify;
81 sty |= m_AlignJustify;
82 } 149 }
83 StyleType getJustify() 150 StyleType getJustify()
84 { 151 {
85 return sty & m_AlignMask; 152 return sty.m_align;
86 } 153 }
87 154
88 void setFontSize(int _fs) 155 void setFontSize(int _fs)
89 { 156 {
90 sty &= m_EveryBit ^ m_FontMask; 157 sty.m_fontsize = _fs;
91 sty |= m_FontBase + _fs;
92 } 158 }
93 int getFontSize() 159 int getFontSize()
94 { 160 {
95 return (sty & m_FontMask) - m_FontBase; 161 return sty.m_fontsize;
96 } 162 }
97 bool operator!=(const CStyle& rhs) 163 bool operator!=(const CStyle& rhs)
98 { 164 {
99 return 165 return
100 ( 166 (
101 (sty != rhs.sty) || (red != rhs.red) || (green != rhs.green) || 167 (sty != rhs.sty) ||
102 (blue != rhs.blue) || 168 (graphic != rhs.graphic)
103 (data != rhs.data) || 169 );
104 (isLink != rhs.isLink) 170 }
105 ); 171 void setLink(bool _l) { sty.isLink = _l; }
106 } 172 bool getLink() { return sty.isLink; }
107 void setLink(bool _l) { isLink = _l; } 173 void setData(unsigned long _d) { sty.data = _d; }
108 bool getLink() { return isLink; } 174 unsigned long getData() { return sty.data; }
109 void setData(unsigned long _d) { data = _d; }
110 unsigned long getData() { return data; }
111}; 175};
112 176
113#endif 177#endif
diff --git a/noncore/apps/opie-reader/Text.h b/noncore/apps/opie-reader/Text.h
deleted file mode 100644
index 4c689be..0000000
--- a/noncore/apps/opie-reader/Text.h
+++ b/dev/null
@@ -1,28 +0,0 @@
1#ifndef __Text_h
2#define __Text_h
3#include <stdio.h>
4#include <sys/stat.h>
5#include "CExpander.h"
6
7class Text: public CExpander {
8 FILE* file;
9public:
10 Text() : file(NULL) {};
11 virtual ~Text() { if (file != NULL) fclose(file); }
12 virtual int openfile(const tchar *src)
13 {
14 if (file != NULL) fclose(file);
15 return ((file = fopen(src,"rb")) == NULL);
16 }
17 virtual int getch() { return fgetc(file); }
18 virtual unsigned int locate() { return ftell(file); }
19 virtual void locate(unsigned int n) { fseek(file,n,SEEK_SET); }
20 virtual bool hasrandomaccess() { return true; }
21 virtual void sizes(unsigned long& _file, unsigned long& _text)
22 {
23 struct stat _stat;
24 fstat(fileno(file),&_stat);
25 _text = _file = _stat.st_size;
26 }
27};
28#endif
diff --git a/noncore/apps/opie-reader/ZText.h b/noncore/apps/opie-reader/ZText.h
index debfe8c..22d3733 100644
--- a/noncore/apps/opie-reader/ZText.h
+++ b/noncore/apps/opie-reader/ZText.h
@@ -1,39 +1,68 @@
1#ifndef __Text_h 1#ifndef __Text_h
2#define __Text_h 2#define __Text_h
3#include <stdio.h> 3#include <stdio.h>
4#include "zlib/zlib.h" 4#include "zlib/zlib.h"
5#include <sys/stat.h> 5#include <sys/stat.h>
6 6
7#include "CExpander.h" 7#include "CExpander.h"
8 8
9class Text: public CExpander { 9class Text: public CExpander {
10 gzFile file; 10 gzFile file;
11 unsigned long fsize; 11 unsigned long fsize;
12public: 12public:
13 virtual void suspend()
14 {
15 bSuspended = true;
16 suspos = gztell(file);
17 gzclose(file);
18 file = NULL;
19 sustime = time(NULL);
20 }
21 virtual void unsuspend()
22 {
23 if (bSuspended)
24 {
25 bSuspended = false;
26 int delay = time(NULL) - sustime;
27 if (delay < 10) sleep(10-delay);
28 file = gzopen(fname, "rb");
29 for (int i = 0; file == NULL && i < 5; i++)
30 {
31 sleep(5);
32 file = gzopen(fname, "rb");
33 }
34 if (file == NULL)
35 {
36 QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file");
37 exit(0);
38 }
39 suspos = gzseek(file, suspos, SEEK_SET);
40 }
41 }
13 Text() : file(NULL) {}; 42 Text() : file(NULL) {};
14 virtual ~Text() 43 virtual ~Text()
15 { 44 {
16 if (file != NULL) gzclose(file); 45 if (file != NULL) gzclose(file);
17 } 46 }
18 virtual int openfile(const char *src) 47 virtual int OpenFile(const char *src)
19 { 48 {
20 if (file != NULL) gzclose(file); 49 if (file != NULL) gzclose(file);
21 struct stat _stat; 50 struct stat _stat;
22 stat(src,&_stat); 51 stat(src,&_stat);
23 fsize = _stat.st_size; 52 fsize = _stat.st_size;
24 return ((file = gzopen(src,"rb")) == NULL); 53 return ((file = gzopen(src,"rb")) == NULL);
25 } 54 }
26 virtual int getch() { return gzgetc(file); } 55 virtual int getch() { return gzgetc(file); }
27 virtual unsigned int locate() { return gztell(file); } 56 virtual unsigned int locate() { return gztell(file); }
28 virtual void locate(unsigned int n) { gzseek(file,n,SEEK_SET); } 57 virtual void locate(unsigned int n) { gzseek(file,n,SEEK_SET); }
29 virtual bool hasrandomaccess() { return true; } 58 virtual bool hasrandomaccess() { return true; }
30 virtual void sizes(unsigned long& _file, unsigned long& _text) 59 virtual void sizes(unsigned long& _file, unsigned long& _text)
31 { 60 {
32 _text = _file = fsize; 61 _text = _file = fsize;
33 } 62 }
34 virtual MarkupType PreferredMarkup() 63 virtual MarkupType PreferredMarkup()
35 { 64 {
36 return cTEXT; 65 return cTEXT;
37 } 66 }
38}; 67};
39#endif 68#endif
diff --git a/noncore/apps/opie-reader/cbkmkselector.h b/noncore/apps/opie-reader/cbkmkselector.h
index 1a49c5a..1a70048 100644
--- a/noncore/apps/opie-reader/cbkmkselector.h
+++ b/noncore/apps/opie-reader/cbkmkselector.h
@@ -1,41 +1,43 @@
1#include <qwidget.h> 1#include <qwidget.h>
2#include <qlistbox.h> 2#include <qlistbox.h>
3#include <qpushbutton.h> 3#include <qpushbutton.h>
4#include <qlayout.h> 4#include <qlayout.h>
5 5
6class CBkmkSelector : public QWidget 6class CBkmkSelector : public QWidget
7{ 7{
8 8
9 Q_OBJECT 9 Q_OBJECT
10 10
11 QListBox* bkmkselector; 11 QListBox* bkmkselector;
12 QPushButton* exitButton;
12 13
13signals: 14signals:
14 void selected(int i); 15 void selected(int i);
15 void cancelled(); 16 void cancelled();
16private slots: 17private slots:
17 void slotSelected(QListBoxItem* t) { emit selected(bkmkselector->index(t)); } 18 void slotSelected(QListBoxItem* t) { emit selected(bkmkselector->index(t)); }
18 void slotSelected(int t) { emit selected(t); } 19 void slotSelected(int t) { emit selected(t); }
19 void slotCancel() { emit cancelled(); } 20 void slotCancel() { emit cancelled(); }
20public: 21public:
21 CBkmkSelector( QWidget *parent=0, const char *name=0, WFlags f = 0) : 22 CBkmkSelector( QWidget *parent=0, const char *name=0, WFlags f = 0) :
22 QWidget(parent, name, f) 23 QWidget(parent, name, f)
23 { 24 {
24 25
25// QFont f("unifont", 16); 26// QFont f("unifont", 16);
26// setFont( f ); 27// setFont( f );
27 28
28 QVBoxLayout* grid = new QVBoxLayout(this); 29 QVBoxLayout* grid = new QVBoxLayout(this);
29 bkmkselector = new QListBox(this, "Bookmarks"); 30 bkmkselector = new QListBox(this, "Bookmarks");
30 QPushButton* exitButton = new QPushButton("Cancel", this); 31 exitButton = new QPushButton("Cancel", this);
31 connect(bkmkselector, SIGNAL( selected(int) ), this, SLOT( slotSelected(int) ) ); 32 connect(bkmkselector, SIGNAL( selected(int) ), this, SLOT( slotSelected(int) ) );
32 connect(bkmkselector, SIGNAL( clicked(QListBoxItem*) ), this, SLOT( slotSelected(QListBoxItem*) ) ); 33 connect(bkmkselector, SIGNAL( clicked(QListBoxItem*) ), this, SLOT( slotSelected(QListBoxItem*) ) );
33 connect(exitButton, SIGNAL( released() ), this, SLOT( slotCancel() ) ); 34 connect(exitButton, SIGNAL( released() ), this, SLOT( slotCancel() ) );
34 grid->addWidget(bkmkselector,1); 35 grid->addWidget(bkmkselector,1);
35 grid->addWidget(exitButton); 36 grid->addWidget(exitButton);
36 } 37 }
37 void clear() { bkmkselector->clear(); } 38 void clear() { bkmkselector->clear(); }
38 void insertItem(const QString& item) { bkmkselector->insertItem(item); } 39 void insertItem(const QString& item) { bkmkselector->insertItem(item); }
39 QString text(int index) const { return bkmkselector->text(index); } 40 QString text(int index) const { return bkmkselector->text(index); }
41 void setText(const QString& _l) { exitButton->setText(_l); }
40}; 42};
41 43
diff --git a/noncore/apps/opie-reader/config.h b/noncore/apps/opie-reader/config.h
index 5150270..b6281a4 100644
--- a/noncore/apps/opie-reader/config.h
+++ b/noncore/apps/opie-reader/config.h
@@ -1,21 +1,25 @@
1#ifndef __CONFIG_H 1#ifndef __CONFIG_H
2#define __CONFIG_H 2#define __CONFIG_H
3 3
4#define _UNICODE 4#define _UNICODE
5 5
6#ifdef _UNICODE 6#ifdef _UNICODE
7#include <limits.h> 7#include <limits.h>
8 8
9#define UTF8 9#define UTF8
10 10
11typedef unsigned short tchar; 11typedef unsigned short tchar;
12const tchar UEOF = USHRT_MAX; 12const tchar UEOF = USHRT_MAX;
13 13
14#else 14#else
15typedef char tchar; 15typedef char tchar;
16const int UEOF = -1; 16const int UEOF = -1;
17#endif 17#endif
18 18
19#include "ustring.h" 19#include "ustring.h"
20 20
21#define BORDER 2
22
23//#define _FAST
24
21#endif 25#endif
diff --git a/noncore/apps/opie-reader/fileBrowser.cpp b/noncore/apps/opie-reader/fileBrowser.cpp
index b21d59d..21c970b 100644
--- a/noncore/apps/opie-reader/fileBrowser.cpp
+++ b/noncore/apps/opie-reader/fileBrowser.cpp
@@ -1,204 +1,207 @@
1/**************************************************************************** 1/****************************************************************************
2 2
3Derived from a file browser which was 3Derived from a file browser which was
4 4
5** copyright 2001 ljp ljp@llornkcor.com 5** copyright 2001 ljp ljp@llornkcor.com
6 6
7Extensive modification by Tim Wentford to allow it to work in rotated mode 7Extensive modification by Tim Wentford to allow it to work in rotated mode
8 8
9****************************************************************************/ 9****************************************************************************/
10#include "fileBrowser.h" 10#include "fileBrowser.h"
11 11
12#include "QtrListView.h" 12#include "QtrListView.h"
13#include <qpushbutton.h> 13#include <qpushbutton.h>
14#include <qfile.h> 14#include <qfile.h>
15#include <qmessagebox.h> 15#include <qmessagebox.h>
16#include <unistd.h> 16#include <unistd.h>
17#include <qlayout.h> 17#include <qlayout.h>
18 18
19fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter, const QString iPath ) 19fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter, const QString iPath )
20 : QDialog( parent, name, modal, fl ), filterspec(QDir::All) 20 : QDialog( parent, name, modal, fl ), filterspec(QDir::All)
21{ 21{
22// showMaximized(); 22// showMaximized();
23 if ( !name ) 23 if ( !name )
24 setName( "fileBrowser" ); 24 setName( "fileBrowser" );
25 if (parent != NULL) resize( parent->width(), parent->height() ); 25 if (parent != NULL) resize( parent->width(), parent->height() );
26 setCaption(tr( "Browse for file" ) ); 26 setCaption(tr( "Browse for file" ) );
27 filterStr=filter; 27 filterStr=filter;
28 28
29 buttonOk = new QPushButton( this, "buttonOk" ); 29 buttonOk = new QPushButton( this, "buttonOk" );
30 buttonOk->setFixedSize( 25, 25 ); 30 buttonOk->setFixedSize( 25, 25 );
31 buttonOk->setAutoDefault( false ); 31 buttonOk->setAutoDefault( false );
32 buttonOk->setText( tr( "/" ) ); 32 buttonOk->setText( tr( "/" ) );
33 33
34 buttonShowHidden = new QPushButton( this, "buttonShowHidden" ); 34 buttonShowHidden = new QPushButton( this, "buttonShowHidden" );
35// buttonShowHidden->setFixedSize( 50, 25 ); 35// buttonShowHidden->setFixedSize( 50, 25 );
36 buttonShowHidden->setText( tr( "Hidden" ) ); 36 buttonShowHidden->setText( tr( "Hidden" ) );
37 buttonShowHidden->setAutoDefault( false ); 37 buttonShowHidden->setAutoDefault( false );
38 buttonShowHidden->setToggleButton( true ); 38 buttonShowHidden->setToggleButton( true );
39 buttonShowHidden->setOn( false ); 39 buttonShowHidden->setOn( false );
40 40
41 dirLabel = new QLabel(this, "DirLabel"); 41 dirLabel = new QLabel(this, "DirLabel");
42 dirLabel->setAlignment(AlignLeft | AlignVCenter | ExpandTabs | WordBreak);
42 dirLabel->setText(currentDir.canonicalPath()); 43 dirLabel->setText(currentDir.canonicalPath());
43 44
44 ListView = new QtrListView( this, "ListView" ); 45 ListView = new QtrListView( this, "ListView" );
45 ListView->addColumn( tr( "Name" ) ); 46 ListView->addColumn( tr( "Name" ) );
46 ListView->setSorting( 2, FALSE); 47 ListView->setSorting( 2, FALSE);
47 ListView->addColumn( tr( "Size" ) ); 48 ListView->addColumn( tr( "Size" ) );
48 ListView->setSelectionMode(QListView::Single); 49 ListView->setSelectionMode(QListView::Single);
49 ListView->setAllColumnsShowFocus( TRUE ); 50 ListView->setAllColumnsShowFocus( TRUE );
51 ListView->setColumnWidthMode(0, QListView::Manual);
52 ListView->setColumnWidthMode(1, QListView::Manual);
50 53
51 // signals and slots connections 54 // signals and slots connections
52 connect( buttonShowHidden, SIGNAL( toggled(bool) ), this, SLOT( setHidden(bool) ) ); 55 connect( buttonShowHidden, SIGNAL( toggled(bool) ), this, SLOT( setHidden(bool) ) );
53 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( OnRoot() ) ); 56 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( OnRoot() ) );
54 connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); 57 connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) );
55 connect( ListView, SIGNAL(clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); 58 connect( ListView, SIGNAL(clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
56 connect( ListView, SIGNAL(OnOKButton( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); 59 connect( ListView, SIGNAL(OnOKButton( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
57 connect( ListView, SIGNAL(OnCentreButton( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); 60 connect( ListView, SIGNAL(OnCentreButton( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
58 connect( ListView, SIGNAL(OnCancelButton()), SLOT(OnCancel()) ); 61 connect( ListView, SIGNAL(OnCancelButton()), SLOT(OnCancel()) );
59 62
60 QVBoxLayout* grid = new QVBoxLayout(this); 63 QVBoxLayout* grid = new QVBoxLayout(this);
61 QHBoxLayout* hgrid = new QHBoxLayout(grid); 64 QHBoxLayout* hgrid = new QHBoxLayout(grid);
62 hgrid->addWidget(dirLabel,1); 65 hgrid->addWidget(dirLabel,1);
63 hgrid->addWidget(buttonShowHidden); 66 hgrid->addWidget(buttonShowHidden);
64 hgrid->addWidget(buttonOk); 67 hgrid->addWidget(buttonOk);
65 grid->addWidget(ListView,1); 68 grid->addWidget(ListView,1);
66 69
67 if (QFileInfo(iPath).exists()) 70 if (QFileInfo(iPath).exists())
68 { 71 {
69 currentDir.setPath(iPath); 72 currentDir.setPath(iPath);
70 chdir(iPath.latin1()); 73 chdir(iPath.latin1());
71 } 74 }
72 else 75 else
73 { 76 {
74 currentDir.setPath(QDir::currentDirPath()); 77 currentDir.setPath(QDir::currentDirPath());
75 chdir(QDir::currentDirPath().latin1()); 78 chdir(QDir::currentDirPath().latin1());
76 } 79 }
77 80
78 populateList(); 81 populateList();
79} 82}
80 83
81void fileBrowser::resizeEvent(QResizeEvent* e) 84void fileBrowser::resizeEvent(QResizeEvent* e)
82{ 85{
83 ListView->setColumnWidth(1,(ListView->width())/4); 86 ListView->setColumnWidth(1,(ListView->width())/4);
84 ListView->setColumnWidth(0,ListView->width()-20-ListView->columnWidth(1)); 87 ListView->setColumnWidth(0,ListView->width()-20-ListView->columnWidth(1));
85} 88}
86 89
87fileBrowser::~fileBrowser() 90fileBrowser::~fileBrowser()
88{ 91{
89} 92}
90 93
91 94
92void fileBrowser::populateList() 95void fileBrowser::populateList()
93{ 96{
94 ListView->clear(); 97 ListView->clear();
95//qDebug(currentDir.canonicalPath()); 98//qDebug(currentDir.canonicalPath());
96// currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks ); 99// currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks );
97 currentDir.setFilter( filterspec ); 100 currentDir.setFilter( filterspec );
98 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); 101 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
99 currentDir.setMatchAllDirs(TRUE); 102 currentDir.setMatchAllDirs(TRUE);
100 103
101 currentDir.setNameFilter(filterStr); 104 currentDir.setNameFilter(filterStr);
102// currentDir.setNameFilter("*.txt;*.etx"); 105// currentDir.setNameFilter("*.txt;*.etx");
103 QString fileL, fileS; 106 QString fileL, fileS;
104 const QFileInfoList *list = currentDir.entryInfoList(); 107 const QFileInfoList *list = currentDir.entryInfoList();
105 QFileInfoListIterator it(*list); 108 QFileInfoListIterator it(*list);
106 QFileInfo *fi; 109 QFileInfo *fi;
107 while ( (fi=it.current()) ) 110 while ( (fi=it.current()) )
108 { 111 {
109 if (fi->fileName() != ".") 112 if (fi->fileName() != ".")
110 { 113 {
111 fileS.sprintf( "%10li", fi->size() ); 114 fileS.sprintf( "%10li", fi->size() );
112 fileL.sprintf( "%s",fi->fileName().data() ); 115 fileL.sprintf( "%s",fi->fileName().data() );
113 if( fi->isDir() ) 116 if( fi->isDir() )
114 { 117 {
115 fileL+="/"; 118 fileL+="/";
116 } 119 }
117 else 120 else
118 { 121 {
119// qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); 122// qDebug("Not a dir: "+currentDir.canonicalPath()+fileL);
120 } 123 }
121 new QListViewItem( ListView,fileL,fileS ); 124 new QListViewItem( ListView,fileL,fileS );
122 } 125 }
123 ++it; 126 ++it;
124 } 127 }
125 ListView->setSorting( 2, FALSE); 128 ListView->setSorting( 2, FALSE);
126 dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); 129 dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath());
127 ListView->setFocus(); 130 ListView->setFocus();
128} 131}
129 132
130void fileBrowser::upDir() 133void fileBrowser::upDir()
131{ 134{
132// qDebug(currentDir.canonicalPath()); 135// qDebug(currentDir.canonicalPath());
133} 136}
134 137
135void fileBrowser::listClicked(QListViewItem *selectedItem) 138void fileBrowser::listClicked(QListViewItem *selectedItem)
136{ 139{
137 if (selectedItem == NULL) return; 140 if (selectedItem == NULL) return;
138 QString strItem=selectedItem->text(0); 141 QString strItem=selectedItem->text(0);
139 142
140// qDebug("%s", (const char*)strItem); 143// qDebug("%s", (const char*)strItem);
141 144
142 145
143 QString strSize=selectedItem->text(1); 146 QString strSize=selectedItem->text(1);
144 147
145 strSize.stripWhiteSpace(); 148 strSize.stripWhiteSpace();
146 149
147 bool ok; 150 bool ok;
148 151
149 QFileInfo fi(strItem); 152 QFileInfo fi(strItem);
150 while (fi.isSymLink()) fi.setFile(fi.readLink()); 153 while (fi.isSymLink()) fi.setFile(fi.readLink());
151 if (fi.isDir()) 154 if (fi.isDir())
152 { 155 {
153 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); 156 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem);
154 157
155 if(QDir(strItem).exists()) 158 if(QDir(strItem).exists())
156 { 159 {
157 currentDir.cd(strItem, TRUE); 160 currentDir.cd(strItem, TRUE);
158 populateList(); 161 populateList();
159 } 162 }
160 } else 163 } else
161 OnOK(); 164 OnOK();
162 chdir(strItem.latin1()); 165 chdir(strItem.latin1());
163// 166//
164 167
165} 168}
166 169
167// you may want to switch these 2 functions. I like single clicks 170// you may want to switch these 2 functions. I like single clicks
168void fileBrowser::listDoubleClicked(QListViewItem *selectedItem) 171void fileBrowser::listDoubleClicked(QListViewItem *selectedItem)
169{ 172{
170} 173}
171 174
172void fileBrowser::OnOK() { 175void fileBrowser::OnOK() {
173 176
174 QListViewItemIterator it1( ListView); 177 QListViewItemIterator it1( ListView);
175 for ( ; it1.current(); ++it1 ) { 178 for ( ; it1.current(); ++it1 ) {
176 if ( it1.current()->isSelected() ) { 179 if ( it1.current()->isSelected() ) {
177 selectedFileName=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+it1.current()->text(0)); 180 selectedFileName=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+it1.current()->text(0));
178 // qDebug("selected filename is "+selectedFileName); 181 // qDebug("selected filename is "+selectedFileName);
179 fileList.append( selectedFileName ); 182 fileList.append( selectedFileName );
180 } 183 }
181 } 184 }
182 accept(); 185 accept();
183} 186}
184 187
185void fileBrowser::OnRoot() 188void fileBrowser::OnRoot()
186{ 189{
187 currentDir.cd("/", TRUE); 190 currentDir.cd("/", TRUE);
188 populateList(); 191 populateList();
189 chdir("/"); 192 chdir("/");
190} 193}
191 194
192void fileBrowser::OnCancel() 195void fileBrowser::OnCancel()
193{ 196{
194 reject(); 197 reject();
195} 198}
196 199
197void fileBrowser::setHidden(bool _hidden) 200void fileBrowser::setHidden(bool _hidden)
198{ 201{
199 if (_hidden) 202 if (_hidden)
200 filterspec = QDir::All | QDir::Hidden; 203 filterspec = QDir::All | QDir::Hidden;
201 else 204 else
202 filterspec = QDir::All; 205 filterspec = QDir::All;
203 populateList(); 206 populateList();
204} 207}
diff --git a/noncore/apps/opie-reader/infowin.cpp b/noncore/apps/opie-reader/infowin.cpp
index 7b8f280..30adebf 100644
--- a/noncore/apps/opie-reader/infowin.cpp
+++ b/noncore/apps/opie-reader/infowin.cpp
@@ -1,42 +1,43 @@
1#include "name.h"
1#include "infowin.h" 2#include "infowin.h"
2#include "version.h" 3#include "version.h"
3#include <stdio.h> 4#include <stdio.h>
4 5
5infowin::infowin( QWidget *parent, const char *name, WFlags f) : 6infowin::infowin( QWidget *parent=0, const char *name=0, WFlags f = 0) :
6 QWidget(parent, name, f) 7 QWidget(parent, name, f)
7{ 8{
8 grid = new QGridLayout(this, 6, 2); 9 grid = new QGridLayout(this, 6, 2);
9 QLabel* l; 10 QLabel* l;
10 l = new QLabel("Compressed file size", this); 11 l = new QLabel("Compressed file size", this);
11 grid->addWidget(l, 0, 0); 12 grid->addWidget(l, 0, 0);
12 fileSize = new QLabel("0", this); 13 fileSize = new QLabel("0", this);
13 fileSize->setAlignment( AlignVCenter | AlignRight ); 14 fileSize->setAlignment( AlignVCenter | AlignRight );
14 grid->addWidget(fileSize, 0, 1); 15 grid->addWidget(fileSize, 0, 1);
15 l = new QLabel("Original text size", this); 16 l = new QLabel("Original text size", this);
16 grid->addWidget(l, 1, 0); 17 grid->addWidget(l, 1, 0);
17 textSize = new QLabel("0", this); 18 textSize = new QLabel("0", this);
18 textSize->setAlignment( AlignVCenter | AlignRight ); 19 textSize->setAlignment( AlignVCenter | AlignRight );
19 grid->addWidget(textSize, 1, 1); 20 grid->addWidget(textSize, 1, 1);
20 l = new QLabel("Compression Ratio", this); 21 l = new QLabel("Compression Ratio", this);
21 grid->addWidget(l, 2, 0); 22 grid->addWidget(l, 2, 0);
22 ratio = new QLabel("0", this); 23 ratio = new QLabel("0", this);
23 grid->addWidget(ratio, 2, 1); 24 grid->addWidget(ratio, 2, 1);
24 ratio->setAlignment( AlignVCenter | AlignRight ); 25 ratio->setAlignment( AlignVCenter | AlignRight );
25 l = new QLabel("Current location", this); 26 l = new QLabel("Current location", this);
26 grid->addWidget(l, 3, 0); 27 grid->addWidget(l, 3, 0);
27 location = new QLabel("0", this); 28 location = new QLabel("0", this);
28 location->setAlignment( AlignVCenter | AlignRight ); 29 location->setAlignment( AlignVCenter | AlignRight );
29 grid->addWidget(location, 3, 1); 30 grid->addWidget(location, 3, 1);
30 l = new QLabel("Per centage read", this); 31 l = new QLabel("Per centage read", this);
31 grid->addWidget(l, 4, 0); 32 grid->addWidget(l, 4, 0);
32 read = new QLabel("0", this); 33 read = new QLabel("0", this);
33 read->setAlignment( AlignVCenter | AlignRight ); 34 read->setAlignment( AlignVCenter | AlignRight );
34 grid->addWidget(read, 4, 1); 35 grid->addWidget(read, 4, 1);
35 char vstr[128]; 36 char vstr[128];
36 sprintf(vstr, "QT Reader v%u.%u%c (%s)\nA small e-text reader", MAJOR, BKMKTYPE, MINOR, RELEASE_TYPE); 37 sprintf(vstr, PROGNAME " v%u.%u%c (%s)\nA small e-text reader", MAJOR, BKMKTYPE, MINOR, RELEASE_TYPE);
37 l = new QLabel(vstr, this); 38 l = new QLabel(vstr, this);
38 grid->addWidget(l, 5, 0); 39 grid->addWidget(l, 5, 0);
39 QPushButton* exitbutton = new QPushButton("Cancel", this); 40 QPushButton* exitbutton = new QPushButton("Cancel", this);
40 connect( exitbutton, SIGNAL( released() ), this, SLOT( infoClose() ) ); 41 connect( exitbutton, SIGNAL( released() ), this, SLOT( infoClose() ) );
41 grid->addWidget(exitbutton, 5, 1); 42 grid->addWidget(exitbutton, 5, 1);
42} 43}
diff --git a/noncore/apps/opie-reader/main.cpp b/noncore/apps/opie-reader/main.cpp
index 08f59a8..2440037 100644
--- a/noncore/apps/opie-reader/main.cpp
+++ b/noncore/apps/opie-reader/main.cpp
@@ -1,30 +1,34 @@
1#include <qpe/qpeapplication.h> 1#include <qpe/qpeapplication.h>
2#include "QTReaderApp.h" 2#include "QTReaderApp.h"
3 3
4#include "signal.h" 4#include "signal.h"
5#include "stdio.h" 5#include "stdio.h"
6#include "time.h" 6#include "time.h"
7 7
8QTReaderApp* app = NULL; 8QTReaderApp* app = NULL;
9 9
10void handler(int signum) 10void handler(int signum)
11{ 11{
12 if (app != NULL) app->saveprefs(); 12 if (app != NULL)
13 {
14 app->suspend();
15 app->saveprefs();
16 }
13 signal(signum, handler); 17 signal(signum, handler);
14} 18}
15 19
16int main( int argc, char ** argv ) 20int main( int argc, char ** argv )
17{ 21{
18 signal(SIGCONT, handler); 22 signal(SIGCONT, handler);
19 23
20 QPEApplication a( argc, argv ); 24 QPEApplication a( argc, argv );
21 25
22 QTReaderApp m; 26 QTReaderApp m;
23 27
24 a.showMainDocumentWidget( &m ); 28 a.showMainDocumentWidget( &m );
25 29
26 app = &m; 30 app = &m;
27 31
28 return a.exec(); 32 return a.exec();
29} 33}
30 34
diff --git a/noncore/apps/opie-reader/name.h b/noncore/apps/opie-reader/name.h
new file mode 100644
index 0000000..d419005
--- a/dev/null
+++ b/noncore/apps/opie-reader/name.h
@@ -0,0 +1,8 @@
1#ifndef __NAME_H
2#define __NAME_H
3
4#define PROGNAME "Opie-Reader"
5#define SHORTPROGNAME "Reader"
6#define APPDIR "uqtreader"
7
8#endif
diff --git a/noncore/apps/opie-reader/opie-reader.pro b/noncore/apps/opie-reader/opie-reader.pro
index 51849a3..139c03a 100644
--- a/noncore/apps/opie-reader/opie-reader.pro
+++ b/noncore/apps/opie-reader/opie-reader.pro
@@ -1,58 +1,73 @@
1TEMPLATE = app 1 TEMPLATE= app
2CONFIG = qt warn_on release 2 CONFIG = qt warn_on release
3HEADERS = Aportis.h \ 3 HEADERS = Aportis.h \
4 BuffDoc.h \ 4 Bkmks.h \
5 CBuffer.h \ 5 BuffDoc.h \
6 CDrawBuffer.h \ 6 CAnnoEdit.h \
7 CExpander.h \ 7 CBuffer.h \
8 CFilter.h \ 8 CDrawBuffer.h \
9 QTReader.h \ 9 CEncoding.h \
10 QTReaderApp.h \ 10 CExpander.h \
11 ZText.h \ 11 CFilter.h \
12 arith.h \ 12 Filedata.h \
13 my_list.h \ 13 FontControl.h \
14 ppm.h \ 14 GraphicWin.h \
15 ppm_expander.h \ 15 Markups.h \
16 cbkmkselector.h \ 16 Navigation.h \
17 fileBrowser.h \ 17 Palm2QImage.h \
18 ztxt.h \ 18 QFloatBar.h \
19 QtrListView.h \ 19 QTReader.h \
20 infowin.h \ 20 QTReaderApp.h \
21 version.h \ 21 QtrListView.h \
22 pdb.h \ 22 Queue.h \
23 utypes.h \ 23 StateData.h \
24 ustring.h \ 24 StyleConsts.h \
25 CEncoding.h \ 25 ZText.h \
26 CAnnoEdit.h \ 26 arith.h \
27 QFloatBar.h \ 27 cbkmkselector.h \
28 StyleConsts.h \ 28 config.h \
29 FontControl.h \ 29 fileBrowser.h \
30 plucker.h \ 30 infowin.h \
31 Markups.h \ 31 my_list.h \
32 Bkmks.h \ 32 name.h \
33 config.h 33 opie.h \
34SOURCES = Aportis.cpp \ 34 pdb.h \
35 BuffDoc.cpp \ 35 plucker.h \
36 CBuffer.cpp \ 36 ppm.h \
37 CDrawBuffer.cpp \ 37 ppm_expander.h \
38 QTReader.cpp \ 38 ustring.h \
39 QTReaderApp.cpp \ 39 utypes.h \
40 arith_d.cpp \ 40 version.h \
41 main.cpp \ 41 ztxt.h
42 ppm.cpp \ 42
43 ppm_expander.cpp \ 43 SOURCES = Aportis.cpp \
44 ztxt.cpp \ 44 Bkmks.cpp \
45 QtrListView.cpp \ 45 BuffDoc.cpp \
46 infowin.cpp \ 46 CBuffer.cpp \
47 pdb.cpp \ 47 CDrawBuffer.cpp \
48 CEncoding.cpp \ 48 CEncoding.cpp \
49 CFilter.cpp \ 49 CFilter.cpp \
50 plucker.cpp \ 50 FontControl.cpp \
51 Bkmks.cpp \ 51 Navigation.cpp \
52 fileBrowser.cpp 52 Palm2QImage.cpp \
53DESTDIR = $(OPIEDIR)/bin 53 QTReader.cpp \
54INCLUDEPATH += $(OPIEDIR)/include 54 QTReaderApp.cpp \
55DEPENDPATH += $(OPIEDIR)/include 55 QtrListView.cpp \
56TARGET = reader 56 StyleConsts.cpp \
57LIBS += -lqpe 57 arith_d.cpp \
58 fileBrowser.cpp \
59 infowin.cpp \
60 main.cpp \
61 pdb.cpp \
62 plucker.cpp \
63 ppm.cpp \
64 ppm_expander.cpp \
65 ztxt.cpp
66
67 INTERFACES=
68 DESTDIR = $(OPIEDIR)/bin
69 INCLUDEPATH+= $(OPIEDIR)/include
70 DEPENDPATH+= $(OPIEDIR)/include
71 TARGET = reader
72 LIBS += -lqpe
58 73
diff --git a/noncore/apps/opie-reader/opie.h b/noncore/apps/opie-reader/opie.h
new file mode 100644
index 0000000..e28c2ab
--- a/dev/null
+++ b/noncore/apps/opie-reader/opie.h
@@ -0,0 +1,6 @@
1#ifndef __OPIE_H
2#define __OPIE_H
3
4#define OPIE
5
6#endif
diff --git a/noncore/apps/opie-reader/pdb.cpp b/noncore/apps/opie-reader/pdb.cpp
index 68b904e..3054424 100644
--- a/noncore/apps/opie-reader/pdb.cpp
+++ b/noncore/apps/opie-reader/pdb.cpp
@@ -1,57 +1,63 @@
1#include "pdb.h" 1#include "pdb.h"
2#include <sys/types.h>
3#include <sys/stat.h>
4#include <unistd.h>
2 5
3size_t Cpdb::recordpos(int n) 6size_t Cpdb::recordpos(int n)
4{ 7{
5 UInt16 mxn = ntohs(head.recordList.numRecords); 8 UInt16 mxn = ntohs(head.recordList.numRecords);
6 if (n >= mxn) 9 if (n >= mxn)
7 { 10 {
8 return file_length; 11 return file_length;
9 } 12 }
10 else 13 else
11 { 14 {
12 size_t dataoffset = sizeof(DatabaseHdrType) - sizeof(UInt16); 15 size_t dataoffset = sizeof(DatabaseHdrType) - sizeof(UInt16);
13 dataoffset += /*dataoffset%4 + */ sizeof(RecordListType) * n; 16 dataoffset += /*dataoffset%4 + */ sizeof(RecordListType) * n;
14 fseek(fin, dataoffset, SEEK_SET); 17 fseek(fin, dataoffset, SEEK_SET);
15 RecordListType hdr; 18 RecordListType hdr;
16 fread(&hdr, 1, sizeof(hdr), fin); 19 fread(&hdr, 1, sizeof(hdr), fin);
17 return ntohl(hdr.nextRecordListID); 20 return ntohl(hdr.nextRecordListID);
18 } 21 }
19 22
20} 23}
21 24
22size_t Cpdb::recordlength(int n) 25size_t Cpdb::recordlength(int n)
23{ 26{
24 return recordpos(n+1)-recordpos(n); 27 return recordpos(n+1)-recordpos(n);
25} 28}
26 29
27void Cpdb::gotorecordnumber(int n) 30void Cpdb::gotorecordnumber(int n)
28{ 31{
29 fseek(fin, recordpos(n), SEEK_SET); 32 fseek(fin, recordpos(n), SEEK_SET);
30} 33}
31 34
32bool Cpdb::openfile(const char *src) 35bool Cpdb::openfile(const char *src)
33{ 36{
34 37
35 // printf("In openfile\n"); 38 // printf("In openfile\n");
36 int ret = 0; 39 int ret = 0;
37 // printf("closing fin:%x\n",fin); 40 // printf("closing fin:%x\n",fin);
38 if (fin != NULL) fclose(fin); 41 if (fin != NULL) fclose(fin);
39 // printf("opening fin\n"); 42 // printf("opening fin\n");
40 fin = fopen(src,"rb"); 43 fin = fopen(src,"rb");
41 44
42 if (fin==0) 45 if (fin==0)
43 { 46 {
44 return false; 47 return false;
45 } 48 }
46 49
47 // just holds the first few chars of the file 50 // just holds the first few chars of the file
48 //char buf[0x100]; 51 //char buf[0x100];
49 fseek(fin,0,SEEK_END); 52 struct stat buf;
50 file_length = ftell(fin); 53 stat(src, &buf);
54 file_length = buf.st_size;
55// fseek(fin,0,SEEK_END);
56// file_length = ftell(fin);
51 57
52 fseek(fin,0,SEEK_SET); 58// fseek(fin,0,SEEK_SET);
53 59
54 fread(&head, 1, sizeof(head), fin); 60 fread(&head, 1, sizeof(head), fin);
55 61
56 return true; 62 return true;
57} 63}
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,579 +1,1241 @@
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
18CPlucker::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
8CPlucker::CPlucker() : expandedtextbuffer(NULL), compressedtextbuffer(NULL) { /*printf("constructing:%x\n",fin);*/ }
9 28
29void 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
11int CPlucker::openfile(const char *src) 50int 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
169void 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
188char* 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
202CPlucker::~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
54int CPlucker::bgetch() 212int 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
88int CPlucker::getch() 259int 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
263void CPlucker::getch(int& ch, CStyle& sty) 569void CPlucker::getch(int& ch, CStyle& sty)
264{ 570{
265 ch = getch(); 571 ch = getch();
266 sty = mystyle; 572 sty = mystyle;
267} 573}
268 574
269unsigned int CPlucker::locate() 575unsigned 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
288void CPlucker::locate(unsigned int n) 594void 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
314bool CPlucker::hyperlink(unsigned int n) 624bool 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/*
741bool 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*/
347bool CPlucker::expand(int thisrec) 851bool 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
413void CPlucker::UnZip(size_t reclen, UInt8* tgtbuffer, UInt16 bsize) 901void 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
448void CPlucker::UnDoc(size_t reclen, UInt8* tgtbuffer, UInt16 bsize) 938void 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 ) {
467 UInt16 c; 957 UInt16 c;
468 958
469 c = (UInt16) inBuf[ j++ ]; 959 c = (UInt16) inBuf[ j++ ];
470 if ( 0 < c && c < 9 ) { 960 if ( 0 < c && c < 9 ) {
471 while ( 0 < c-- ) 961 while ( 0 < c-- )
472 outBuf[ i++ ] = inBuf[ j++ ]; 962 outBuf[ i++ ] = inBuf[ j++ ];
473 } 963 }
474 else if ( c < 0x80 ) 964 else if ( c < 0x80 )
475 outBuf[ i++ ] = c; 965 outBuf[ i++ ] = c;
476 else if ( 0xc0 <= c ) { 966 else if ( 0xc0 <= c ) {
477 outBuf[ i++ ] = ' '; 967 outBuf[ i++ ] = ' ';
478 outBuf[ i++ ] = c ^ 0x80; 968 outBuf[ i++ ] = c ^ 0x80;
479 } 969 }
480 else { 970 else {
481 Int16 m; 971 Int16 m;
482 Int16 n; 972 Int16 n;
483 973
484 c <<= 8; 974 c <<= 8;
485 c += inBuf[ j++ ]; 975 c += inBuf[ j++ ];
486 976
487 m = ( c & 0x3fff ) >> COUNT_BITS; 977 m = ( c & 0x3fff ) >> COUNT_BITS;
488 n = c & ( ( 1 << COUNT_BITS ) - 1 ); 978 n = c & ( ( 1 << COUNT_BITS ) - 1 );
489 n += 2; 979 n += 2;
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
501void CPlucker::home() 991void CPlucker::home()
502{ 992{
503 currentpos = 0; 993 currentpos = 0;
504 expand(1); 994 expand(1);
505} 995}
506 996
507CList<Bkmk>* CPlucker::getbkmklist() 997CList<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
529void CPlucker::expandimg(UInt16 tgt) 1019QImage* 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
1060QPixmap* 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
1087QPixmap* 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>
1107void 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
1142void 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
1167void 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
1196unsigned 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}
diff --git a/noncore/apps/opie-reader/plucker.h b/noncore/apps/opie-reader/plucker.h
index d3ca732..083eac6 100644
--- a/noncore/apps/opie-reader/plucker.h
+++ b/noncore/apps/opie-reader/plucker.h
@@ -1,86 +1,123 @@
1#ifndef __plucker_h 1#ifndef __plucker_h
2#define __plucker_h 2#define __plucker_h
3 3
4#include "CExpander.h" 4#include "CExpander.h"
5#include "zlib/zlib.h" 5#include "zlib/zlib.h"
6#include "ztxt.h" 6#include "ztxt.h"
7#include "pdb.h" 7#include "pdb.h"
8#include "CBuffer.h" 8#include "CBuffer.h"
9#include "Navigation.h"
10#include "my_list.h"
11
12#ifdef LOCALPICTURES
13class QScrollView;
14class QWidget;
15#endif
9 16
10struct CPlucker_dataRecord 17struct CPlucker_dataRecord
11{ 18{
12 UInt16 uid; 19 UInt16 uid;
13 UInt16 nParagraphs; 20 UInt16 nParagraphs;
14 UInt16 size; 21 UInt16 size;
15 UInt8 type; 22 UInt8 type;
16 UInt8 reserved; 23 UInt8 reserved;
17}; 24};
18 25
19struct CPlucker_record0 26struct CPlucker_record0
20{ 27{
21 UInt16 uid; 28 UInt16 uid;
22 UInt16 version; 29 UInt16 version;
23 UInt16 nRecords; 30 UInt16 nRecords;
24}; 31};
25 32
26struct CPluckerbkmk 33struct CPluckerbkmk
27{ 34{
28 UInt32 offset; 35 UInt32 offset;
29 tchar title[MAX_BMRK_LENGTH]; 36 tchar title[MAX_BMRK_LENGTH];
30}; 37};
31 38
32
33const UInt32 CPLUCKER_ID = 0x5458547a; 39const UInt32 CPLUCKER_ID = 0x5458547a;
34 40
35class CPlucker : public CExpander, Cpdb 41class CPlucker : public CExpander, Cpdb
36{ 42{
37 size_t textlength; 43 unsigned short finduid(unsigned short);
44 char* geturl(UInt16);
45 void Expand(UInt16, UInt8, UInt8*, UInt16);
46 CList<unsigned long> visited;
47 bool m_lastIsBreak;
48#ifdef LOCALPICTURES
49 QScrollView* m_viewer;
50 QWidget* m_picture;
51#endif
52 size_t textlength, m_lastBreak;
38 UInt16 uid; 53 UInt16 uid;
54 UInt8 EOPPhase;
39 int m_nextPara, m_nextParaIndex; 55 int m_nextPara, m_nextParaIndex;
40 CBufferFace<UInt16> m_ParaOffsets; 56 CBufferFace<UInt16> m_ParaOffsets;
41 CBufferFace<UInt16> m_ParaAttrs; 57 CBufferFace<UInt16> m_ParaAttrs;
42 UInt16 m_nParas; 58 UInt16 m_nParas;
43 CStyle mystyle; 59 CStyle mystyle;
44// bool bInit; 60// bool bInit;
45 UInt32 buffersize; 61 UInt32 buffersize;
46 UInt32 buffercontent; 62 UInt32 buffercontent;
47 UInt8* expandedtextbuffer; 63 UInt8* expandedtextbuffer;
48 UInt8* compressedtextbuffer; 64 UInt8* compressedtextbuffer;
65 char* urls;
66 size_t urlsize;
49 size_t bufferpos; 67 size_t bufferpos;
50 UInt16 bufferrec; 68 UInt16 bufferrec;
51 CPlucker_record0 hdr0; 69 CPlucker_record0 hdr0;
52 size_t currentpos; 70 size_t currentpos;
53 bool expand(int); 71 bool expand(int);
54 void UnZip(size_t, UInt8*, UInt16); 72 void UnZip(size_t, UInt8*, UInt16);
55 void UnDoc(size_t, UInt8*, UInt16); 73 void UnDoc(size_t, UInt8*, UInt16);
56 void expandimg(UInt16 tgt); 74#ifdef LOCALPICTURES
75 void showimg(UInt16 tgt);
76#endif
77 QImage* getimg(UInt16 tgt);
78 QPixmap* expandimg(UInt16 tgt, bool border=false);
57 void home(); 79 void home();
58 int bgetch(); 80 int bgetch();
81 CNavigation m_nav;
59 public: 82 public:
60 virtual void sizes(unsigned long& _file, unsigned long& _text) 83 virtual void suspend()
61 { 84 {
62 _file = file_length; 85 CExpander::suspend(fin);
63 _text = textlength; 86 }
64//ntohl(hdr0.size); 87 virtual void unsuspend()
65 } 88 {
89 CExpander::unsuspend(fin);
90 }
91 virtual QPixmap* getPicture(unsigned long tgt);
92 virtual void sizes(unsigned long& _file, unsigned long& _text);
66 virtual bool hasrandomaccess() { return true; } 93 virtual bool hasrandomaccess() { return true; }
67 virtual ~CPlucker() 94 virtual ~CPlucker();
68 {
69 if (expandedtextbuffer != NULL) delete [] expandedtextbuffer;
70 if (compressedtextbuffer != NULL) delete [] compressedtextbuffer;
71 }
72 CPlucker(); 95 CPlucker();
73 virtual int openfile(const char *src); 96 virtual int OpenFile(const char *src);
74 virtual int getch(); 97 virtual int getch();
75 virtual void getch(int&, CStyle&); 98 virtual void getch(int&, CStyle&);
76 virtual unsigned int locate(); 99 virtual unsigned int locate();
77 virtual void locate(unsigned int n); 100 virtual void locate(unsigned int n);
78 virtual CList<Bkmk>* getbkmklist(); 101 virtual CList<Bkmk>* getbkmklist();
79 virtual bool hyperlink(unsigned int n); 102 virtual bool hyperlink(unsigned int n);
80 virtual MarkupType PreferredMarkup() 103 virtual MarkupType PreferredMarkup()
81 { 104 {
82 return cNONE; 105 return cNONE;
83 } 106 }
107 void saveposn(size_t posn) { m_nav.saveposn(posn); }
108 bool forward(size_t& loc) { return m_nav.forward(loc); }
109 bool back(size_t& loc) { return m_nav.back(loc); }
110 bool hasnavigation() { return true; }
111 unsigned long startSection()
112 {
113 return currentpos-bufferpos;
114 }
115 unsigned long endSection()
116 {
117 return startSection()+buffercontent;
118 }
119 void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen);
120 void putSaveData(unsigned char*& src, unsigned short& srclen);
84}; 121};
85 122
86#endif 123#endif
diff --git a/noncore/apps/opie-reader/ppm_expander.cpp b/noncore/apps/opie-reader/ppm_expander.cpp
index 4f0a277..fe2745c 100644
--- a/noncore/apps/opie-reader/ppm_expander.cpp
+++ b/noncore/apps/opie-reader/ppm_expander.cpp
@@ -1,108 +1,108 @@
1/* 1/*
2 * Interface pour le programme de compression 2 * Interface pour le programme de compression
3 * (c) 1995 Fabrice Bellard 3 * (c) 1995 Fabrice Bellard
4 */ 4 */
5 5
6#include <stdlib.h> 6#include <stdlib.h>
7//#include <unistd.h> 7//#include <unistd.h>
8#include <stdio.h> 8#include <stdio.h>
9#include <string.h> 9#include <string.h>
10#include <time.h> 10#include <time.h>
11 11
12/*************************************************************************** 12/***************************************************************************
13 * Interface avec les routines de compression 13 * Interface avec les routines de compression
14 */ 14 */
15 15
16#define METHOD_NB 2 /* nombre total de méthodes de compression */ 16#define METHOD_NB 2 /* nombre total de méthodes de compression */
17 17
18#define METHOD_STORE 0 18#define METHOD_STORE 0
19#define METHOD_PPM 1 19#define METHOD_PPM 1
20 20
21 21
22#define DEFAULT_SUFFIX ".st" /* extension par défault */ 22#define DEFAULT_SUFFIX ".st" /* extension par défault */
23/* signature en début de fichier */ 23/* signature en début de fichier */
24#define STAT_MAGIC_SIZE 4 24#define STAT_MAGIC_SIZE 4
25char stat_magic[STAT_MAGIC_SIZE]={'P','P','M','S'}; 25char stat_magic[STAT_MAGIC_SIZE]={'P','P','M','S'};
26 26
27#include "ppm_expander.h" 27#include "ppm_expander.h"
28 28
29ppm_expander::~ppm_expander() { 29ppm_expander::~ppm_expander() {
30 if (needppmend) ppm.PPM_End(); 30 if (needppmend) ppm.PPM_End();
31 ppm.arith.Arith_DecodeEnd(); 31 ppm.arith.Arith_DecodeEnd();
32 if (buf_in!=NULL) delete [] buf_in; 32 if (buf_in!=NULL) delete [] buf_in;
33 if (buf_out!=NULL) delete [] buf_out; 33 if (buf_out!=NULL) delete [] buf_out;
34 if (my_read_buf != NULL) delete my_read_buf; 34 if (my_read_buf != NULL) delete my_read_buf;
35 if (my_file_in != NULL) fclose(my_file_in); 35 if (my_file_in != NULL) fclose(my_file_in);
36} 36}
37 37
38int ppm_expander::openfile(const char* infile) 38int ppm_expander::OpenFile(const char* infile)
39{ 39{
40 my_file_in=fopen(infile,"rb"); 40 my_file_in=fopen(infile,"rb");
41 my_read_buf = new PPM_ReadBuf(my_file_in); 41 my_read_buf = new PPM_ReadBuf(my_file_in);
42 return home(); 42 return home();
43} 43}
44 44
45void ppm_expander::sizes(unsigned long& file, unsigned long& text) 45void ppm_expander::sizes(unsigned long& file, unsigned long& text)
46{ 46{
47 struct stat _stat; 47 struct stat _stat;
48 fstat(fileno(my_file_in),&_stat); 48 fstat(fileno(my_file_in),&_stat);
49 file = _stat.st_size; 49 file = _stat.st_size;
50 text = numblocks*blocksize; 50 text = numblocks*blocksize;
51} 51}
52 52
53int ppm_expander::home() 53int ppm_expander::home()
54{ 54{
55 fseek(my_file_in,0, SEEK_SET); 55 fseek(my_file_in,0, SEEK_SET);
56 unsigned char header[STAT_MAGIC_SIZE]; 56 unsigned char header[STAT_MAGIC_SIZE];
57 size_t len=fread(header,1,STAT_MAGIC_SIZE,my_file_in); 57 size_t len=fread(header,1,STAT_MAGIC_SIZE,my_file_in);
58 if (strncmp((char*)header,stat_magic,STAT_MAGIC_SIZE)!=0) { 58 if (strncmp((char*)header,stat_magic,STAT_MAGIC_SIZE)!=0) {
59 return 1; 59 return 1;
60 } 60 }
61 if (len!=(STAT_MAGIC_SIZE)) { 61 if (len!=(STAT_MAGIC_SIZE)) {
62 return 1; 62 return 1;
63 } 63 }
64 if (fread(&maxnode,sizeof(maxnode),1,my_file_in) != 1) return 1; 64 if (fread(&maxnode,sizeof(maxnode),1,my_file_in) != 1) return 1;
65 if (fread(&blocksize,sizeof(blocksize),1,my_file_in) != 1) return 1; 65 if (fread(&blocksize,sizeof(blocksize),1,my_file_in) != 1) return 1;
66 if (fread(&numblocks,sizeof(numblocks),1,my_file_in) != 1) return 1; 66 if (fread(&numblocks,sizeof(numblocks),1,my_file_in) != 1) return 1;
67 //fprintf(stderr,"<%u,%u,%u>\n",maxnode,blocksize,numblocks); 67 //fprintf(stderr,"<%u,%u,%u>\n",maxnode,blocksize,numblocks);
68 int err = locate(0,0); 68 int err = locate(0,0);
69 outbytes = 0; 69 outbytes = 0;
70 return err; 70 return err;
71} 71}
72 72
73void ppm_expander::locate(unsigned int n) { 73void ppm_expander::locate(unsigned int n) {
74 locate(n/blocksize, n%blocksize); 74 locate(n/blocksize, n%blocksize);
75 outbytes = n; 75 outbytes = n;
76} 76}
77 77
78int ppm_expander::locate(unsigned short block, unsigned int n) 78int ppm_expander::locate(unsigned short block, unsigned int n)
79{ 79{
80 if (needppmend) 80 if (needppmend)
81 { 81 {
82 ppm.PPM_End(); 82 ppm.PPM_End();
83 needppmend = false; 83 needppmend = false;
84 } 84 }
85 size_t fpos; 85 size_t fpos;
86 fseek(my_file_in,STAT_MAGIC_SIZE+sizeof(maxnode)+sizeof(blocksize)+sizeof(numblocks)+block*sizeof(fpos),SEEK_SET); 86 fseek(my_file_in,STAT_MAGIC_SIZE+sizeof(maxnode)+sizeof(blocksize)+sizeof(numblocks)+block*sizeof(fpos),SEEK_SET);
87 if (fread(&fpos,sizeof(fpos),1,my_file_in) != 1) return 1; 87 if (fread(&fpos,sizeof(fpos),1,my_file_in) != 1) return 1;
88 fseek(my_file_in,fpos,SEEK_SET); 88 fseek(my_file_in,fpos,SEEK_SET);
89 89
90 ppm.arith.Arith_DecodeInit(my_read_buf,buf_in,bufsize); 90 ppm.arith.Arith_DecodeInit(my_read_buf,buf_in,bufsize);
91 int err=ppm.PPM_Init(maxnode); 91 int err=ppm.PPM_Init(maxnode);
92 needppmend = true; 92 needppmend = true;
93 curblock = block; 93 curblock = block;
94 for (int i = 0; i < n; i++) getch(); 94 for (int i = 0; i < n; i++) getch();
95} 95}
96 96
97int ppm_expander::getch() { 97int ppm_expander::getch() {
98 if (curblock >= numblocks) return EOF; 98 if (curblock >= numblocks) return EOF;
99 int c=ppm.PPM_Decode(); 99 int c=ppm.PPM_Decode();
100 if (c == SYM_EOF) 100 if (c == SYM_EOF)
101 { 101 {
102 if (++curblock >= numblocks) return EOF; 102 if (++curblock >= numblocks) return EOF;
103 locate(curblock,0); 103 locate(curblock,0);
104 c = ppm.PPM_Decode(); 104 c = ppm.PPM_Decode();
105 } 105 }
106 outbytes++; 106 outbytes++;
107 return (c==SYM_EOF) ? EOF : c; 107 return (c==SYM_EOF) ? EOF : c;
108} 108}
diff --git a/noncore/apps/opie-reader/ppm_expander.h b/noncore/apps/opie-reader/ppm_expander.h
index 115988d..4278c82 100644
--- a/noncore/apps/opie-reader/ppm_expander.h
+++ b/noncore/apps/opie-reader/ppm_expander.h
@@ -1,50 +1,58 @@
1#ifndef __ppm_expander_h 1#ifndef __ppm_expander_h
2#define __ppm_expander_h 2#define __ppm_expander_h
3 3
4#include "CExpander.h" 4#include "CExpander.h"
5#include <sys/stat.h> 5#include <sys/stat.h>
6 6
7 7
8#include "utypes.h" 8#include "utypes.h"
9#include "ppm.h" 9#include "ppm.h"
10#include "arith.h" 10#include "arith.h"
11 11
12 12
13#define SYM_EOF 256 13#define SYM_EOF 256
14 14
15class ppm_expander : public CExpander { 15class ppm_expander : public CExpander {
16 UCHAR *buf_in,*buf_out; 16 UCHAR *buf_in,*buf_out;
17 unsigned int bufsize; 17 unsigned int bufsize;
18 unsigned int outbytes; 18 unsigned int outbytes;
19 unsigned long blocksize; 19 unsigned long blocksize;
20 unsigned short numblocks; 20 unsigned short numblocks;
21 unsigned short curblock; 21 unsigned short curblock;
22 unsigned short maxnode; 22 unsigned short maxnode;
23 bool needppmend; 23 bool needppmend;
24 int home(); 24 int home();
25 FILE* my_file_in; 25 FILE* my_file_in;
26 PPM_ReadBuf* my_read_buf; 26 PPM_ReadBuf* my_read_buf;
27 ppm_worker ppm; 27 ppm_worker ppm;
28 public: 28public:
29 virtual void suspend()
30 {
31 CExpander::suspend(my_file_in);
32 }
33 virtual void unsuspend()
34 {
35 CExpander::unsuspend(my_file_in);
36 }
29 ppm_expander() : needppmend(false), my_file_in(NULL), my_read_buf(NULL) 37 ppm_expander() : needppmend(false), my_file_in(NULL), my_read_buf(NULL)
30 { 38 {
31 bufsize = 1024; 39 bufsize = 1024;
32 buf_in = new UCHAR[bufsize]; 40 buf_in = new UCHAR[bufsize];
33 buf_out = new UCHAR[bufsize]; 41 buf_out = new UCHAR[bufsize];
34 outbytes = 0; 42 outbytes = 0;
35 } 43 }
36 virtual int openfile(const char* infile); 44 virtual int OpenFile(const char* infile);
37 virtual int getch(); 45 virtual int getch();
38 int locate(unsigned short block, unsigned int n); 46 int locate(unsigned short block, unsigned int n);
39 virtual ~ppm_expander(); 47 virtual ~ppm_expander();
40 virtual unsigned int locate() { return outbytes; } 48 virtual unsigned int locate() { return outbytes; }
41 virtual void locate(unsigned int n); 49 virtual void locate(unsigned int n);
42 virtual bool hasrandomaccess() { return (numblocks > 1); } 50 virtual bool hasrandomaccess() { return (numblocks > 1); }
43 virtual void sizes(unsigned long& file, unsigned long& text); 51 virtual void sizes(unsigned long& file, unsigned long& text);
44 virtual MarkupType PreferredMarkup() 52 virtual MarkupType PreferredMarkup()
45 { 53 {
46 return cTEXT; 54 return cTEXT;
47 } 55 }
48}; 56};
49 57
50#endif 58#endif
diff --git a/noncore/apps/opie-reader/ustring.h b/noncore/apps/opie-reader/ustring.h
index a4dc048..a3ef8df 100644
--- a/noncore/apps/opie-reader/ustring.h
+++ b/noncore/apps/opie-reader/ustring.h
@@ -1,71 +1,83 @@
1#include <qstring.h> 1#include <qstring.h>
2 2
3#ifdef _UNICODE 3#ifdef _UNICODE
4inline size_t ustrlen(const tchar* _p) 4inline size_t ustrlen(const tchar* _p)
5{ 5{
6 if (_p == NULL) return 0; 6 if (_p == NULL) return 0;
7 const tchar *p = _p; 7 const tchar *p = _p;
8 while (*p != 0) 8 while (*p != 0)
9 { 9 {
10 p++; 10 p++;
11/* 11/*
12 if (p - _p == 20) 12 if (p - _p == 20)
13 { 13 {
14 printf("ustrlen::String too long:"); 14 printf("ustrlen::String too long:");
15 for (int i = 0; i < 20; i++) printf("%c",_p[i]); 15 for (int i = 0; i < 20; i++) printf("%c",_p[i]);
16 printf("\n"); 16 printf("\n");
17 } 17 }
18*/ 18*/
19 } 19 }
20 return p - _p; 20 return p - _p;
21} 21}
22 22
23inline int ustrcmp(const tchar* _p1, const tchar* _p2) 23inline int ustrcmp(const tchar* _p1, const tchar* _p2)
24{ 24{
25 if (_p1 == 0) return 1; 25 if (_p1 == 0) return 1;
26 if (_p2 == 0) return -1; 26 if (_p2 == 0) return -1;
27 const tchar* p1 = _p1, *p2 = _p2; 27 const tchar* p1 = _p1, *p2 = _p2;
28 while (*p1 != 0) 28 while (*p1 != 0)
29 { 29 {
30/* 30/*
31 if (p1 - _p1 == 20) 31 if (p1 - _p1 == 20)
32 { 32 {
33 printf("ustrcmp::String too long:"); 33 printf("ustrcmp::String too long:");
34 for (int i = 0; i < 20; i++) printf("%c",_p1[i]); 34 for (int i = 0; i < 20; i++) printf("%c",_p1[i]);
35 printf("\n"); 35 printf("\n");
36 } 36 }
37*/ 37*/
38 if (*p1 < *p2) return -1; 38 if (*p1 < *p2) return -1;
39 if (*p1 > *p2) return 1; 39 if (*p1 > *p2) return 1;
40 if (*p2 == 0) return 1; 40 if (*p2 == 0) return 1;
41 p1++, p2++; 41 p1++, p2++;
42 } 42 }
43 if (*p2 != 0) return -1; 43 if (*p2 != 0) return -1;
44 return 0; 44 return 0;
45} 45}
46 46
47inline QString toQString(tchar *_p) 47inline QString toQString(tchar *_p)
48{ 48{
49 if (_p == NULL) return 0; 49 if (_p == NULL) return 0;
50 int i = 0; 50 int i = 0;
51 tchar *p = _p; 51 tchar *p = _p;
52 QString ret; 52 QString ret;
53 while (*p != 0) ret[i++] = *(p++); 53 while (*p != 0) ret[i++] = *(p++);
54 return ret; 54 return ret;
55} 55}
56 56
57inline QString toQString(tchar *_p, unsigned int len) 57inline QString toQString(tchar *_p, unsigned int len)
58{ 58{
59 if (_p == NULL) return 0; 59 if (_p == NULL) return 0;
60 unsigned int i = 0; 60 unsigned int i = 0;
61 tchar *p = _p; 61 tchar *p = _p;
62 QString ret; 62 QString ret;
63 while (*p != 0 && i < len) ret[i++] = *(p++); 63 while (*p != 0 && i < len) ret[i++] = *(p++);
64 return ret; 64 return ret;
65} 65}
66
67inline tchar* fromQString(const QString& qs)
68{
69 int len = qs.length();
70 tchar* ret = new tchar[len+1];
71 for (int i = 0; i < len; i++)
72 {
73 ret[i] = qs[i].unicode();
74 }
75 ret[len] = 0;
76 return ret;
77}
66#else 78#else
67 79
68inline size_t ustrlen(const tchar* _p) { return strlen(_p); } 80inline size_t ustrlen(const tchar* _p) { return strlen(_p); }
69inline int ustrcmp(const tchar* _p1, const tchar* _p2) { return strcmp(_p1, _p2); } 81inline int ustrcmp(const tchar* _p1, const tchar* _p2) { return strcmp(_p1, _p2); }
70 82
71#endif 83#endif
diff --git a/noncore/apps/opie-reader/version.h b/noncore/apps/opie-reader/version.h
index 8b6c756..003e9db 100644
--- a/noncore/apps/opie-reader/version.h
+++ b/noncore/apps/opie-reader/version.h
@@ -1,5 +1,5 @@
1 1
2#define MAJOR 0 2#define MAJOR 0
3#define BKMKTYPE 5 3#define BKMKTYPE 6
4#define MINOR 'a' 4#define MINOR 'a'
5#define RELEASE_TYPE "beta" 5#define RELEASE_TYPE "beta"
diff --git a/noncore/apps/opie-reader/ztxt.cpp b/noncore/apps/opie-reader/ztxt.cpp
index 289b13a..8091d32 100644
--- a/noncore/apps/opie-reader/ztxt.cpp
+++ b/noncore/apps/opie-reader/ztxt.cpp
@@ -1,161 +1,161 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <string.h> 2#include <string.h>
3#include "ztxt.h" 3#include "ztxt.h"
4#include "my_list.h" 4#include "my_list.h"
5#include "Bkmks.h" 5#include "Bkmks.h"
6 6
7ztxt::ztxt() : bInit(false), expandedtextbuffer(NULL), compressedtextbuffer(NULL) { /*printf("constructing:%x\n",fin);*/ } 7ztxt::ztxt() : bInit(false), expandedtextbuffer(NULL), compressedtextbuffer(NULL) { /*printf("constructing:%x\n",fin);*/ }
8 8
9 9
10int ztxt::openfile(const char *src) 10int ztxt::OpenFile(const char *src)
11{ 11{
12 if (!Cpdb::openfile(src)) 12 if (!Cpdb::openfile(src))
13 { 13 {
14 return -1; 14 return -1;
15 } 15 }
16 16
17//printf("Okay %u\n", 4); 17//printf("Okay %u\n", 4);
18 18
19 if (head.type != ZTXT_ID) return -1; 19 if (head.type != ZTXT_ID) return -1;
20 20
21 gotorecordnumber(0); 21 gotorecordnumber(0);
22 fread(&hdr0, 1, sizeof(hdr0), fin); 22 fread(&hdr0, 1, sizeof(hdr0), fin);
23//printf("Okay %u\n", 5); 23//printf("Okay %u\n", 5);
24 buffersize = ntohl(hdr0.size); 24 buffersize = ntohl(hdr0.size);
25 compressedtextbuffer = new UInt8[buffersize]; 25 compressedtextbuffer = new UInt8[buffersize];
26 expandedtextbuffer = new UInt8[buffersize]; 26 expandedtextbuffer = new UInt8[buffersize];
27//printf("Okay %u\n", 6); 27//printf("Okay %u\n", 6);
28 28
29 home(); 29 home();
30//printf("Okay %u\n", 7); 30//printf("Okay %u\n", 7);
31 31
32// printf("Returning 0\n"); 32// printf("Returning 0\n");
33 33
34 return 0; 34 return 0;
35} 35}
36 36
37int ztxt::getch() 37int ztxt::getch()
38{ 38{
39 if (bufferpos >= buffercontent) 39 if (bufferpos >= buffercontent)
40 { 40 {
41 size_t reclen = recordlength(++bufferrec); 41 size_t reclen = recordlength(++bufferrec);
42 if (reclen == 0) return -1; 42 if (reclen == 0) return -1;
43 gotorecordnumber(bufferrec); 43 gotorecordnumber(bufferrec);
44 fread(compressedtextbuffer, reclen, sizeof(char), fin); 44 fread(compressedtextbuffer, reclen, sizeof(char), fin);
45 45
46 zstream.next_in = compressedtextbuffer; 46 zstream.next_in = compressedtextbuffer;
47 zstream.next_out = expandedtextbuffer; 47 zstream.next_out = expandedtextbuffer;
48 zstream.avail_out = buffersize; 48 zstream.avail_out = buffersize;
49 zstream.avail_in = reclen; 49 zstream.avail_in = reclen;
50 50
51 int ret = inflate(&zstream, Z_SYNC_FLUSH); 51 int ret = inflate(&zstream, Z_SYNC_FLUSH);
52 buffercontent = buffersize - zstream.avail_out; 52 buffercontent = buffersize - zstream.avail_out;
53 bufferpos = 0; 53 bufferpos = 0;
54 54
55 } 55 }
56 currentpos++; 56 currentpos++;
57 return expandedtextbuffer[bufferpos++]; 57 return expandedtextbuffer[bufferpos++];
58} 58}
59 59
60unsigned int ztxt::locate() 60unsigned int ztxt::locate()
61{ 61{
62 return currentpos; 62 return currentpos;
63} 63}
64 64
65void ztxt::locate(unsigned int n) 65void ztxt::locate(unsigned int n)
66{ 66{
67 67
68 if (hasrandomaccess()) 68 if (hasrandomaccess())
69 { 69 {
70 bufferrec = n / ntohs(hdr0.recordSize) + 1; 70 bufferrec = n / ntohs(hdr0.recordSize) + 1;
71 if (bufferrec == 1) 71 if (bufferrec == 1)
72 { 72 {
73 inflateEnd(&zstream); 73 inflateEnd(&zstream);
74 } 74 }
75 size_t reclen = recordlength(bufferrec); 75 size_t reclen = recordlength(bufferrec);
76 if (reclen == 0) return; 76 if (reclen == 0) return;
77 gotorecordnumber(bufferrec); 77 gotorecordnumber(bufferrec);
78 fread(compressedtextbuffer, reclen, sizeof(char), fin); 78 fread(compressedtextbuffer, reclen, sizeof(char), fin);
79 79
80 zstream.next_in = compressedtextbuffer; 80 zstream.next_in = compressedtextbuffer;
81 zstream.next_out = expandedtextbuffer; 81 zstream.next_out = expandedtextbuffer;
82 zstream.avail_out = buffersize; 82 zstream.avail_out = buffersize;
83 zstream.avail_in = reclen; 83 zstream.avail_in = reclen;
84 84
85 if (bufferrec == 1) 85 if (bufferrec == 1)
86 { 86 {
87 zstream.zalloc = Z_NULL; 87 zstream.zalloc = Z_NULL;
88 zstream.zfree = Z_NULL; 88 zstream.zfree = Z_NULL;
89 zstream.opaque = Z_NULL; 89 zstream.opaque = Z_NULL;
90 90
91 inflateInit(&zstream); 91 inflateInit(&zstream);
92 } 92 }
93 93
94 94
95 int ret = inflate(&zstream, Z_SYNC_FLUSH); 95 int ret = inflate(&zstream, Z_SYNC_FLUSH);
96 buffercontent = buffersize - zstream.avail_out; 96 buffercontent = buffersize - zstream.avail_out;
97 bufferpos = 0; 97 bufferpos = 0;
98 currentpos = n - n % ntohs(hdr0.recordSize); 98 currentpos = n - n % ntohs(hdr0.recordSize);
99 while (currentpos < n) getch(); 99 while (currentpos < n) getch();
100 } 100 }
101 else 101 else
102 { 102 {
103 home(); 103 home();
104 while (currentpos < n && getch() != EOF); 104 while (currentpos < n && getch() != EOF);
105 } 105 }
106} 106}
107 107
108void ztxt::home() 108void ztxt::home()
109{ 109{
110 if (bInit) 110 if (bInit)
111 { 111 {
112 inflateEnd(&zstream); 112 inflateEnd(&zstream);
113 } 113 }
114 bInit = true; 114 bInit = true;
115 size_t reclen = recordlength(1); 115 size_t reclen = recordlength(1);
116 gotorecordnumber(1); 116 gotorecordnumber(1);
117 fread(compressedtextbuffer, reclen, sizeof(char), fin); 117 fread(compressedtextbuffer, reclen, sizeof(char), fin);
118 118
119 zstream.next_in = compressedtextbuffer; 119 zstream.next_in = compressedtextbuffer;
120 zstream.next_out = expandedtextbuffer; 120 zstream.next_out = expandedtextbuffer;
121 zstream.avail_out = buffersize; 121 zstream.avail_out = buffersize;
122 zstream.avail_in = reclen; 122 zstream.avail_in = reclen;
123 123
124 zstream.zalloc = Z_NULL; 124 zstream.zalloc = Z_NULL;
125 zstream.zfree = Z_NULL; 125 zstream.zfree = Z_NULL;
126 zstream.opaque = Z_NULL; 126 zstream.opaque = Z_NULL;
127 127
128// printf("Initialising\n"); 128// printf("Initialising\n");
129 129
130 inflateInit(&zstream); 130 inflateInit(&zstream);
131 131
132 int ret = inflate(&zstream, Z_SYNC_FLUSH); 132 int ret = inflate(&zstream, Z_SYNC_FLUSH);
133// printf("Inflate : %d\n", ret); 133// printf("Inflate : %d\n", ret);
134 bufferpos = 0; 134 bufferpos = 0;
135 bufferrec = 1; 135 bufferrec = 1;
136 currentpos = 0; 136 currentpos = 0;
137 buffercontent = buffersize - zstream.avail_out; 137 buffercontent = buffersize - zstream.avail_out;
138 //printf("buffercontent:%u\n", buffercontent); 138 //printf("buffercontent:%u\n", buffercontent);
139} 139}
140 140
141CList<Bkmk>* ztxt::getbkmklist() 141CList<Bkmk>* ztxt::getbkmklist()
142{ 142{
143 UInt16 recno = ntohs(hdr0.bookmarkRecord); 143 UInt16 recno = ntohs(hdr0.bookmarkRecord);
144 144
145// printf("Bookmarks - record %d contains %d\n", recno, ntohs(hdr0.numBookmarks)); 145// printf("Bookmarks - record %d contains %d\n", recno, ntohs(hdr0.numBookmarks));
146 146
147 if (recno == 0) return NULL; 147 if (recno == 0) return NULL;
148 148
149 CList<Bkmk>* t = new CList<Bkmk>; 149 CList<Bkmk>* t = new CList<Bkmk>;
150 size_t cur = ftell(fin); 150 size_t cur = ftell(fin);
151 gotorecordnumber(recno); 151 gotorecordnumber(recno);
152 for (int i = 0; i < ntohs(hdr0.numBookmarks); i++) 152 for (int i = 0; i < ntohs(hdr0.numBookmarks); i++)
153 { 153 {
154 zTXTbkmk bkmk; 154 zTXTbkmk bkmk;
155 if (fread(&bkmk, sizeof(bkmk), 1, fin) != 1) break; 155 if (fread(&bkmk, sizeof(bkmk), 1, fin) != 1) break;
156// printf("Bookmark number:%d:%.20s\n", i, bkmk.title); 156// printf("Bookmark number:%d:%.20s\n", i, bkmk.title);
157 t->push_back(Bkmk(bkmk.title, NULL, ntohl(bkmk.offset))); 157 t->push_back(Bkmk(bkmk.title, NULL, ntohl(bkmk.offset)));
158 } 158 }
159 fseek(fin, cur, SEEK_SET); 159 fseek(fin, cur, SEEK_SET);
160 return t; 160 return t;
161} 161}
diff --git a/noncore/apps/opie-reader/ztxt.h b/noncore/apps/opie-reader/ztxt.h
index 20558a6..d7cb96a 100644
--- a/noncore/apps/opie-reader/ztxt.h
+++ b/noncore/apps/opie-reader/ztxt.h
@@ -1,105 +1,113 @@
1#ifndef __ztxt_h 1#ifndef __ztxt_h
2#define __ztxt_h 2#define __ztxt_h
3 3
4#include "CExpander.h" 4#include "CExpander.h"
5#include "zlib/zlib.h" 5#include "zlib/zlib.h"
6#include "pdb.h" 6#include "pdb.h"
7/* 7/*
8 * Stuff common to both Weasel Reader and makeztxt 8 * Stuff common to both Weasel Reader and makeztxt
9 * 9 *
10 * $Id$ 10 * $Id$
11 * 11 *
12 */ 12 */
13 13
14#ifndef _WEASEL_COMMON_H_ 14#ifndef _WEASEL_COMMON_H_
15#define _WEASEL_COMMON_H_ 1 15#define _WEASEL_COMMON_H_ 1
16 16
17 17
18/* Padding is no good */ 18/* Padding is no good */
19#if defined(__GNUC__) && defined(__UNIX__) 19#if defined(__GNUC__) && defined(__UNIX__)
20# pragma pack(2) 20# pragma pack(2)
21#endif 21#endif
22 22
23/* The default creator is Weasel Reader 'GPlm' */ 23/* The default creator is Weasel Reader 'GPlm' */
24#define GPLM_CREATOR_ID "GPlm" 24#define GPLM_CREATOR_ID "GPlm"
25/* Databases of type 'zTXT' */ 25/* Databases of type 'zTXT' */
26#define ZTXT_TYPE_ID "zTXT" 26#define ZTXT_TYPE_ID "zTXT"
27/* Size of one database record */ 27/* Size of one database record */
28#define RECORD_SIZE 8192 28#define RECORD_SIZE 8192
29/* Allow largest WBIT size for data. Lower with command line options 29/* Allow largest WBIT size for data. Lower with command line options
30 in makeztxt */ 30 in makeztxt */
31#define MAXWBITS 15 31#define MAXWBITS 15
32/* Max length for a bookmark/annotation title */ 32/* Max length for a bookmark/annotation title */
33#define MAX_BMRK_LENGTH 20 33#define MAX_BMRK_LENGTH 20
34 34
35 35
36/***************************************************** 36/*****************************************************
37 * This is the zTXT document header (record #0) * 37 * This is the zTXT document header (record #0) *
38 * ----zTXT version 1.42---- * 38 * ----zTXT version 1.42---- *
39 *****************************************************/ 39 *****************************************************/
40typedef struct zTXT_record0Type { 40typedef struct zTXT_record0Type {
41 UInt16 version; /* zTXT format version */ 41 UInt16 version; /* zTXT format version */
42 UInt16 numRecords; /* Number of data (TEXT) records */ 42 UInt16 numRecords; /* Number of data (TEXT) records */
43 UInt32 size; /* Size in bytes of uncomp. data */ 43 UInt32 size; /* Size in bytes of uncomp. data */
44 UInt16 recordSize; /* Size of a single data record */ 44 UInt16 recordSize; /* Size of a single data record */
45 UInt16 numBookmarks; /* Number of bookmarks in DB */ 45 UInt16 numBookmarks; /* Number of bookmarks in DB */
46 UInt16 bookmarkRecord; /* Record containing bookmarks */ 46 UInt16 bookmarkRecord; /* Record containing bookmarks */
47 UInt16 numAnnotations; /* Number of annotation records */ 47 UInt16 numAnnotations; /* Number of annotation records */
48 UInt16 annotationRecord; /* Record # of annotation index */ 48 UInt16 annotationRecord; /* Record # of annotation index */
49 UInt8 randomAccess; /* 1 if compressed w/Z_FULL_FLUSH */ 49 UInt8 randomAccess; /* 1 if compressed w/Z_FULL_FLUSH */
50 UInt8 padding[0x20 - 19]; /* Pad to a size of 0x20 bytes */ 50 UInt8 padding[0x20 - 19]; /* Pad to a size of 0x20 bytes */
51} zTXT_record0; 51} zTXT_record0;
52 52
53struct zTXTbkmk 53struct zTXTbkmk
54{ 54{
55 UInt32 offset; 55 UInt32 offset;
56 tchar title[MAX_BMRK_LENGTH]; 56 tchar title[MAX_BMRK_LENGTH];
57}; 57};
58 58
59#endif 59#endif
60 60
61 61
62const UInt32 ZTXT_ID = 0x5458547a; 62const UInt32 ZTXT_ID = 0x5458547a;
63 63
64class ztxt : public CExpander, Cpdb 64class ztxt : public CExpander, Cpdb
65{ 65{
66 bool bInit; 66 bool bInit;
67 UInt32 buffersize; 67 UInt32 buffersize;
68 UInt32 buffercontent; 68 UInt32 buffercontent;
69 UInt8* expandedtextbuffer; 69 UInt8* expandedtextbuffer;
70 UInt8* compressedtextbuffer; 70 UInt8* compressedtextbuffer;
71 z_stream zstream; 71 z_stream zstream;
72 size_t bufferpos; 72 size_t bufferpos;
73 UInt16 bufferrec; 73 UInt16 bufferrec;
74 zTXT_record0 hdr0; 74 zTXT_record0 hdr0;
75 size_t currentpos; 75 size_t currentpos;
76 void home(); 76 void home();
77 public: 77public:
78 virtual void suspend()
79 {
80 CExpander::suspend(fin);
81 }
82 virtual void unsuspend()
83 {
84 CExpander::unsuspend(fin);
85 }
78 virtual void sizes(unsigned long& _file, unsigned long& _text) 86 virtual void sizes(unsigned long& _file, unsigned long& _text)
79 { 87 {
80 _file = file_length; 88 _file = file_length;
81 _text = ntohl(hdr0.size); 89 _text = ntohl(hdr0.size);
82 } 90 }
83 virtual bool hasrandomaccess() { return (hdr0.randomAccess != 0); } 91 virtual bool hasrandomaccess() { return (hdr0.randomAccess != 0); }
84 virtual ~ztxt() 92 virtual ~ztxt()
85 { 93 {
86 if (expandedtextbuffer != NULL) delete [] expandedtextbuffer; 94 if (expandedtextbuffer != NULL) delete [] expandedtextbuffer;
87 if (compressedtextbuffer != NULL) delete [] compressedtextbuffer; 95 if (compressedtextbuffer != NULL) delete [] compressedtextbuffer;
88 if (bInit) 96 if (bInit)
89 { 97 {
90 inflateEnd(&zstream); 98 inflateEnd(&zstream);
91 } 99 }
92 } 100 }
93 ztxt(); 101 ztxt();
94 virtual int openfile(const char *src); 102 virtual int OpenFile(const char *src);
95 virtual int getch(); 103 virtual int getch();
96 virtual unsigned int locate(); 104 virtual unsigned int locate();
97 virtual void locate(unsigned int n); 105 virtual void locate(unsigned int n);
98 virtual CList<Bkmk>* getbkmklist(); 106 virtual CList<Bkmk>* getbkmklist();
99 virtual MarkupType PreferredMarkup() 107 virtual MarkupType PreferredMarkup()
100 { 108 {
101 return cTEXT; 109 return cTEXT;
102 } 110 }
103}; 111};
104 112
105#endif 113#endif