author | llornkcor <llornkcor> | 2002-12-20 01:35:01 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-12-20 01:35:01 (UTC) |
commit | 876e1a4724a7bd75dc642e295de354241096e028 (patch) (unidiff) | |
tree | a37c5dcc9d78e04bb6b859ab89d8cf81e6745087 | |
parent | 5fd6636ba3d94b48dd543887316c47c5388a43c2 (diff) | |
download | opie-876e1a4724a7bd75dc642e295de354241096e028.zip opie-876e1a4724a7bd75dc642e295de354241096e028.tar.gz opie-876e1a4724a7bd75dc642e295de354241096e028.tar.bz2 |
update - sorry it took so long. hope this works correctly
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 | |||
@@ -89,9 +89,9 @@ CList<Bkmk>* Aportis::getbkmklist() | |||
89 | fseek(fin, cur, SEEK_SET); | 89 | fseek(fin, cur, SEEK_SET); |
90 | return t; | 90 | return t; |
91 | } | 91 | } |
92 | 92 | ||
93 | int Aportis::openfile(const char *src) | 93 | int 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 | ||
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 | |||
@@ -74,17 +74,25 @@ class Aportis : public CExpander, Cpdb { | |||
74 | unsigned int outptr; | 74 | unsigned int outptr; |
75 | unsigned char circbuf[2048]; | 75 | unsigned char circbuf[2048]; |
76 | char bCompressed; | 76 | char bCompressed; |
77 | public: | 77 | public: |
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(); |
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,4 +1,5 @@ | |||
1 | #include "name.h" | ||
1 | #include <qmessagebox.h> | 2 | #include <qmessagebox.h> |
2 | 3 | ||
3 | #include "Bkmks.h" | 4 | #include "Bkmks.h" |
4 | 5 | ||
@@ -8,28 +9,58 @@ | |||
8 | #include "version.h" | 9 | #include "version.h" |
9 | 10 | ||
10 | const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE); | 11 | const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE); |
11 | 12 | ||
13 | Bkmk::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 | |||
18 | Bkmk::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 | ||
13 | Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p) | 23 | Bkmk::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 | ||
37 | void 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 | |||
32 | Bkmk::~Bkmk() | 63 | Bkmk::~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; |
@@ -40,201 +71,252 @@ Bkmk::~Bkmk() | |||
40 | Bkmk& Bkmk::operator=(const Bkmk& rhs) | 71 | Bkmk& 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 | ||
72 | bool Bkmk::operator==(const Bkmk& rhs) | 103 | bool 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 | |||
108 | void 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 | ||
77 | void Bkmk::setAnno(tchar* t) | 129 | void 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 | ||
94 | BkmkFile::BkmkFile(const char *fnm, bool w ) | 151 | BkmkFile::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 | ||
108 | BkmkFile::~BkmkFile() | 165 | BkmkFile::~BkmkFile() |
109 | { | 166 | { |
110 | if (f != NULL) fclose(f); | 167 | if (f != NULL) fclose(f); |
111 | } | 168 | } |
112 | 169 | ||
113 | void BkmkFile::write(tchar* nm, tchar* an, const unsigned int& pos) | 170 | void 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 | ||
127 | void BkmkFile::write(const Bkmk& b) { write(b.name(), b.anno(), b.value()); } | ||
128 | |||
129 | void BkmkFile::write(CList<Bkmk>& bl) | 182 | void 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 | |||
141 | Bkmk* 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 | ||
164 | CList<Bkmk>* BkmkFile::readall() | 194 | CList<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 | ||
193 | CList<Bkmk>* BkmkFile::readall04() | 239 | CList<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 | ||
206 | CList<Bkmk>* BkmkFile::readall03() | 252 | Bkmk* 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 | ||
219 | Bkmk* BkmkFile::read03() | 276 | Bkmk* 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; | 299 | Bkmk* 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,34 +1,52 @@ | |||
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 | ||
7 | template<class T> | 8 | template<class T> |
8 | class CList; | 9 | class CList; |
9 | 10 | ||
10 | class Bkmk | 11 | class 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 | ||
33 | class BkmkFile | 51 | class BkmkFile |
34 | { | 52 | { |
@@ -36,13 +54,12 @@ class BkmkFile | |||
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); |
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,4 +1,6 @@ | |||
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" |
@@ -12,10 +14,10 @@ bool BuffDoc::hyperlink(unsigned int n) | |||
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 | ||
@@ -29,43 +31,159 @@ void BuffDoc::locate(unsigned int n) | |||
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 | ||
33 | bool BuffDoc::getline(CDrawBuffer* buff, int w) | 35 | #define NEWLINEBREAK |
36 | #ifdef NEWLINEBREAK | ||
37 | bool 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 | ||
137 | bool 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 | { |
@@ -76,8 +194,9 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w) | |||
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]; |
@@ -87,29 +206,42 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w) | |||
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'; |
@@ -121,30 +253,39 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w) | |||
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 | ||
128 | bool BuffDoc::getline(CDrawBuffer* buff, int w, int cw) | 267 | bool 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 | ||
150 | int BuffDoc::openfile(QWidget* _parent, const char *src) | 291 | int BuffDoc::openfile(QWidget* _parent, const char *src) |
@@ -163,55 +304,46 @@ int BuffDoc::openfile(QWidget* _parent, const char *src) | |||
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(); |
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 | |||
@@ -18,8 +18,29 @@ class BuffDoc | |||
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; |
@@ -60,12 +81,17 @@ class BuffDoc | |||
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); } |
@@ -78,7 +104,11 @@ class BuffDoc | |||
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 | |||
@@ -10,9 +10,9 @@ CBufferBase& CBufferBase::assign(const void* sztmp, size_t ms) | |||
10 | memcpy(buffer, sztmp, ms*membersize); | 10 | memcpy(buffer, sztmp, ms*membersize); |
11 | return *this; | 11 | return *this; |
12 | } | 12 | } |
13 | 13 | ||
14 | CBufferBase::CBufferBase(size_t ms, size_t n) : len(n), membersize(ms) | 14 | CBufferBase::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 | } |
@@ -30,9 +30,9 @@ void* CBufferBase::operator[](int i) | |||
30 | } | 30 | } |
31 | return buffer+i*membersize; | 31 | return buffer+i*membersize; |
32 | } | 32 | } |
33 | 33 | ||
34 | size_t CBufferBase::bstrlen(unsigned char* _buffer) | 34 | size_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); |
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,35 +1,43 @@ | |||
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 | |||
8 | CDrawBuffer::~CDrawBuffer() | ||
9 | { | ||
10 | while (!segs.isEmpty()) segs.erase(0); | ||
11 | } | ||
6 | 12 | ||
7 | void CDrawBuffer::setright(CDrawBuffer& rhs, int f) | 13 | void 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 | ||
34 | CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs) | 42 | CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs) |
35 | { | 43 | { |
@@ -39,9 +47,13 @@ CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs) | |||
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 | } |
@@ -54,9 +66,12 @@ CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs) | |||
54 | 66 | ||
55 | CDrawBuffer& CDrawBuffer::operator=(const tchar*sztmp) | 67 | CDrawBuffer& 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; |
@@ -66,35 +81,26 @@ CDrawBuffer& CDrawBuffer::operator=(const tchar*sztmp) | |||
66 | void CDrawBuffer::empty() | 81 | void 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 | ||
75 | void CDrawBuffer::addch(tchar ch, CStyle _style/* = ucFontBase*/) | 94 | void 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 | } |
@@ -119,77 +125,188 @@ int CDrawBuffer::width(int 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 | ||
155 | int CDrawBuffer::leftMargin() | ||
156 | { | ||
157 | return (segs.begin()->style.getLeftMargin()*fc->getsize(segs.begin()->style))/6; | ||
158 | } | ||
159 | |||
160 | int CDrawBuffer::rightMargin() | ||
161 | { | ||
162 | return (segs.begin()->style.getRightMargin()*fc->getsize(segs.begin()->style))/6; | ||
163 | } | ||
164 | |||
165 | int 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 | |||
133 | void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scwidth) | 191 | void 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 | ||
186 | CStyle CDrawBuffer::laststyle() | 303 | CStyle CDrawBuffer::laststyle() |
187 | { | 304 | { |
188 | return segs.last().style; | 305 | return segs.last().style; |
189 | } | 306 | } |
190 | 307 | ||
191 | bool CDrawBuffer::isLink(int numchars, size_t& tgt) | 308 | linkType 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(); |
@@ -197,15 +314,66 @@ bool CDrawBuffer::isLink(int numchars, size_t& tgt) | |||
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 | |||
341 | void 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 | |||
@@ -6,13 +6,20 @@ | |||
6 | #include "my_list.h" | 6 | #include "my_list.h" |
7 | 7 | ||
8 | class QPainter; | 8 | class QPainter; |
9 | 9 | ||
10 | enum linkType | ||
11 | { | ||
12 | eNone, | ||
13 | eLink, | ||
14 | ePicture | ||
15 | }; | ||
16 | |||
10 | struct textsegment | 17 | struct 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 | }; |
@@ -23,16 +30,25 @@ class 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) |
@@ -40,20 +56,21 @@ class CDrawBuffer : public CBuffer | |||
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,11 +1,17 @@ | |||
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 | ||
13 | class QPixmap; | ||
8 | class Bkmk; | 14 | class Bkmk; |
9 | 15 | ||
10 | template<class T> | 16 | template<class T> |
11 | class CList; | 17 | class CList; |
@@ -17,12 +23,28 @@ class CCharacterSource | |||
17 | }; | 23 | }; |
18 | 24 | ||
19 | class CExpander | 25 | class 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; |
@@ -38,6 +60,65 @@ class CExpander | |||
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 | |||
@@ -531,9 +531,9 @@ void PeanutFormatter::getch(tchar& ch, CStyle& sty) | |||
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 |
@@ -542,9 +542,9 @@ void PeanutFormatter::getch(tchar& ch, CStyle& sty) | |||
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 |
@@ -558,4 +558,127 @@ void PeanutFormatter::getch(tchar& ch, CStyle& sty) | |||
558 | } | 558 | } |
559 | } | 559 | } |
560 | sty = currentstyle; | 560 | sty = currentstyle; |
561 | } | 561 | } |
562 | |||
563 | void 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 | ||
574 | void 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 | |||
@@ -265,5 +265,23 @@ class PeanutFormatter : public CFilter | |||
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 | |||
270 | class 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 | ||
280 | class 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 | |||
6 | class 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 | |||
4 | bool 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 | |||
@@ -10,24 +10,36 @@ class FontControl | |||
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()); |
@@ -85,37 +97,8 @@ class FontControl | |||
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 | |||
9 | class 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 | |||
40 | class 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 | |||
3 | void 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 | |||
12 | bool 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 | |||
27 | bool 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 | |||
59 | void 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 | |||
79 | void 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 | |||
3 | const size_t NAVIGATION_HISTORY_SIZE = 32; | ||
4 | |||
5 | class 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 | |||
36 | typedef struct { | ||
37 | unsigned char red; | ||
38 | unsigned char green; | ||
39 | unsigned char blue; | ||
40 | } ColorMapEntry; | ||
41 | |||
42 | static 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 | |||
108 | static ColorMapEntry Palm1BitColormap[] = {{ 255, 255, 255 }, { 0, 0, 0 }}; | ||
109 | |||
110 | static ColorMapEntry Palm2BitColormap[] = { | ||
111 | { 255, 255, 255 }, { 192, 192, 192 }, { 128, 128, 128 }, { 0, 0, 0 }}; | ||
112 | |||
113 | static 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 | |||
119 | QImage* 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 | |||
284 | QPixmap* 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 | |||
4 | QImage* Palm2QImage | ||
5 | (unsigned char *image_bytes_in, int byte_count_in); | ||
6 | |||
7 | QPixmap* 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 | |||
@@ -21,8 +21,9 @@ | |||
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 |
27 | const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 }; | 28 | const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 }; |
28 | #else | 29 | #else |
@@ -34,9 +35,9 @@ const char *QTReader::fonts[] = { "Helvetica", "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 | ||
38 | QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : | 39 | QTReader::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), |
@@ -47,9 +48,11 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : | |||
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 | } |
@@ -80,23 +83,62 @@ long QTReader::real_delay() | |||
80 | } | 83 | } |
81 | 84 | ||
82 | void QTReader::mousePressEvent( QMouseEvent* _e ) | 85 | void 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 | ||
98 | bool QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt) | 140 | linkType 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)) |
@@ -111,22 +153,30 @@ bool QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t | |||
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 | ||
121 | void QTReader::setTwoTouch(bool _b) | 164 | void 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 | ||
170 | void QTReader::setContinuous(bool _b) | ||
171 | { | ||
172 | buffdoc.unsuspend(); | ||
173 | buffdoc.setContinuous(m_continuousDocument = _b); | ||
174 | } | ||
175 | |||
127 | void QTReader::mouseReleaseEvent( QMouseEvent* _e ) | 176 | void 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 | { |
@@ -140,20 +190,45 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e ) | |||
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) |
@@ -211,13 +286,14 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e ) | |||
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 | } |
@@ -281,10 +357,79 @@ void QTReader::goUp() | |||
281 | lineUp(); | 357 | lineUp(); |
282 | } | 358 | } |
283 | } | 359 | } |
284 | 360 | ||
361 | void 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 | |||
381 | void 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 | |||
401 | void 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 | |||
415 | void 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 | |||
285 | void QTReader::keyPressEvent(QKeyEvent* e) | 429 | void 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 | { |
@@ -356,38 +501,36 @@ void QTReader::keyPressEvent(QKeyEvent* e) | |||
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(); |
@@ -408,16 +551,19 @@ void QTReader::setautoscroll(bool _sc) | |||
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 | ||
418 | bool QTReader::getline(CDrawBuffer *buff) | 563 | bool 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 | } |
@@ -458,19 +604,18 @@ void QTReader::doscroll() | |||
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 | } |
@@ -491,80 +636,72 @@ void QTReader::setfont() | |||
491 | } | 636 | } |
492 | 637 | ||
493 | void QTReader::drawFonts( QPainter *p ) | 638 | void 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 | ||
569 | QString QTReader::firstword() | 706 | QString QTReader::firstword() |
570 | { | 707 | { |
@@ -606,8 +743,9 @@ bool QTReader::ChangeFont(int tgt) | |||
606 | void QTReader::init() | 743 | void 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()); |
@@ -617,16 +755,16 @@ void QTReader::init() | |||
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 |
@@ -700,8 +838,9 @@ int main( int argc, tchar **argv ) | |||
700 | 838 | ||
701 | 839 | ||
702 | bool QTReader::locate(unsigned long n) { | 840 | bool 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"); |
@@ -718,16 +857,17 @@ unsigned int QTReader::screenlines() | |||
718 | }; | 857 | }; |
719 | 858 | ||
720 | bool QTReader::fillbuffer(int reuse, int ht) | 859 | bool 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); |
@@ -737,9 +877,9 @@ bool QTReader::fillbuffer(int reuse, int ht) | |||
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 | } |
@@ -760,15 +900,17 @@ bool QTReader::fillbuffer(int reuse, int ht) | |||
760 | 900 | ||
761 | 901 | ||
762 | void QTReader::dopagedn() | 902 | void 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 | { |
@@ -776,8 +918,9 @@ void QTReader::dopagedn() | |||
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++; |
@@ -790,52 +933,75 @@ void QTReader::dopagedn() | |||
790 | } | 933 | } |
791 | 934 | ||
792 | void QTReader::dopageup() | 935 | void QTReader::dopageup() |
793 | { | 936 | { |
937 | buffdoc.unsuspend(); | ||
938 | dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]); | ||
939 | } | ||
940 | |||
941 | void 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); |
@@ -844,28 +1010,38 @@ void QTReader::dopageup() | |||
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 | } |
@@ -882,11 +1058,14 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn) | |||
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 | } |
@@ -1011,15 +1190,17 @@ void QTReader::lineUp() | |||
1011 | } | 1190 | } |
1012 | */ | 1191 | */ |
1013 | void QTReader::lineUp() | 1192 | void 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; |
@@ -1033,8 +1214,16 @@ void QTReader::lineUp() | |||
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); |
@@ -1106,4 +1295,33 @@ MarkupType QTReader::PreferredMarkup() | |||
1106 | } | 1295 | } |
1107 | } | 1296 | } |
1108 | return m; | 1297 | return m; |
1109 | } | 1298 | } |
1299 | |||
1300 | void 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 | |||
@@ -12,14 +12,17 @@ | |||
12 | class CDrawBuffer; | 12 | class CDrawBuffer; |
13 | //class CBuffer; | 13 | //class CBuffer; |
14 | class QPainter; | 14 | class QPainter; |
15 | class QTimer; | 15 | class QTimer; |
16 | class QPixmap; | ||
17 | class statedata; | ||
16 | 18 | ||
17 | class QTReader : public QWidget | 19 | class 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; |
@@ -36,9 +39,20 @@ class QTReader : public QWidget | |||
36 | public: | 39 | public: |
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() |
@@ -107,8 +121,20 @@ public: | |||
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()); |
@@ -189,10 +215,14 @@ public: | |||
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 | } |
@@ -215,11 +245,12 @@ private slots: | |||
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(); |
@@ -228,26 +259,33 @@ private slots: | |||
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(); |
@@ -255,18 +293,20 @@ private slots: | |||
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,6 +1,6 @@ | |||
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 |
@@ -20,9 +20,12 @@ | |||
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> |
@@ -41,8 +44,9 @@ | |||
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" |
@@ -54,8 +58,18 @@ | |||
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 | ||
60 | unsigned long QTReaderApp::m_uid = 0; | 74 | unsigned long QTReaderApp::m_uid = 0; |
61 | 75 | ||
@@ -67,24 +81,25 @@ void QTReaderApp::setScrollState(bool _b) { m_scrollButton->setOn(_b); } | |||
67 | 81 | ||
68 | void QTReaderApp::listBkmkFiles() | 82 | void 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 | ||
@@ -92,15 +107,23 @@ void QTReaderApp::listBkmkFiles() | |||
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 | ||
105 | QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | 128 | QTReaderApp::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) |
@@ -108,25 +131,28 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
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 | ||
@@ -158,8 +184,12 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
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) ) ); |
@@ -174,22 +204,28 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
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 ); |
@@ -197,15 +233,20 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
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); |
@@ -214,8 +255,10 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
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() ); |
@@ -224,8 +267,13 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
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 ); |
@@ -249,20 +297,42 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
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() ) ); |
@@ -271,20 +341,8 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
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); |
@@ -297,9 +355,9 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
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) ) ); |
@@ -344,8 +402,19 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
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 | ||
@@ -394,8 +463,12 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
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 ); |
@@ -415,9 +488,13 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
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 | ||
@@ -428,19 +505,22 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
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() ) ); |
@@ -536,12 +616,12 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags 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 ); |
@@ -562,9 +642,9 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags 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 ); |
@@ -578,47 +658,96 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
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 | |||
749 | void QTReaderApp::suspend() { reader->suspend(); } | ||
621 | 750 | ||
622 | void QTReaderApp::msgHandler(const QCString& _msg, const QByteArray& _data) | 751 | void QTReaderApp::msgHandler(const QCString& _msg, const QByteArray& _data) |
623 | { | 752 | { |
624 | QString msg = QString::fromUtf8(_msg); | 753 | QString msg = QString::fromUtf8(_msg); |
@@ -627,261 +756,291 @@ void QTReaderApp::msgHandler(const QCString& _msg, const QByteArray& _data) | |||
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 | ||
870 | ActionTypes QTReaderApp::ActNameToInt(const QString& _enc) | 1013 | ActionTypes 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 | ||
1022 | void 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 | |||
1032 | void QTReaderApp::setcontinuous(bool sfs) | ||
1033 | { | ||
1034 | reader->setContinuous(sfs); | ||
1035 | reader->refresh(); | ||
1036 | } | ||
1037 | |||
879 | int QTReaderApp::EncNameToInt(const QString& _enc) | 1038 | int 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; |
@@ -909,25 +1068,98 @@ QTReaderApp::~QTReaderApp() | |||
909 | 1068 | ||
910 | void QTReaderApp::autoScroll(bool _b) | 1069 | void QTReaderApp::autoScroll(bool _b) |
911 | { | 1070 | { |
912 | reader->setautoscroll(_b); | 1071 | reader->setautoscroll(_b); |
1072 | setScrollState(reader->m_autoScroll); | ||
913 | } | 1073 | } |
914 | 1074 | ||
915 | void QTReaderApp::TBD() | 1075 | void QTReaderApp::zoomin() |
916 | { | 1076 | { |
917 | QMessageBox::information(this, "OpieReader", "Not yet implemented", 1); | 1077 | reader->zoomin(); |
918 | } | 1078 | } |
919 | 1079 | ||
920 | void QTReaderApp::TBDzoom() | 1080 | void 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 | ||
925 | void QTReaderApp::clearBkmkList() | 1085 | void 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 | |||
1092 | void 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 | |||
1118 | void 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 | ||
932 | void QTReaderApp::fileOpen() | 1164 | void QTReaderApp::fileOpen() |
933 | { | 1165 | { |
@@ -936,57 +1168,91 @@ void QTReaderApp::fileOpen() | |||
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 | |||
1178 | void 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 | |||
1212 | QString 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 | |||
1230 | void QTReaderApp::showgraphic(QPixmap& pm) | ||
1231 | { | ||
1232 | m_graphicwin->setPixmap(pm); | ||
1233 | editorStack->raiseWidget( m_graphicwin ); | ||
1234 | m_graphicwin->setFocus(); | ||
969 | } | 1235 | } |
970 | 1236 | ||
971 | void QTReaderApp::showinfo() | 1237 | void 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 | ||
992 | void QTReaderApp::addAnno(const QString& name, const QString& text, size_t posn) | 1258 | void QTReaderApp::addAnno(const QString& name, const QString& text, size_t posn) |
@@ -996,15 +1262,15 @@ void QTReaderApp::addAnno(const QString& name, const QString& text, size_t posn) | |||
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 |
@@ -1017,77 +1283,78 @@ void QTReaderApp::addAnno(const QString& name, const QString& text, size_t posn) | |||
1017 | void QTReaderApp::addAnno(const QString& name, const QString& text) | 1283 | void 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 | ||
1058 | bool QTReaderApp::findNextBookmark(size_t start) | 1324 | bool 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 | ||
1076 | void QTReaderApp::addanno() | 1342 | void 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 | ||
1093 | void QTReaderApp::infoClose() | 1360 | void QTReaderApp::infoClose() |
@@ -1115,36 +1382,46 @@ void QTReaderApp::editMark() | |||
1115 | } | 1382 | } |
1116 | 1383 | ||
1117 | void QTReaderApp::editCopy() | 1384 | void 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 | ||
1133 | void QTReaderApp::pageup() | 1400 | void QTReaderApp::pageup() |
1134 | { | 1401 | { |
1135 | reader->goUp(); | 1402 | reader->NavUp(); |
1136 | } | 1403 | } |
1137 | 1404 | ||
1138 | void QTReaderApp::pagedn() | 1405 | void QTReaderApp::pagedn() |
1139 | { | 1406 | { |
1140 | reader->goDown(); | 1407 | reader->NavDown(); |
1141 | } | 1408 | } |
1142 | 1409 | ||
1143 | void QTReaderApp::stripcr(bool _b) | 1410 | void QTReaderApp::stripcr(bool _b) |
1144 | { | 1411 | { |
1145 | reader->setstripcr(_b); | 1412 | reader->setstripcr(_b); |
1146 | } | 1413 | } |
1414 | void QTReaderApp::onespace(bool _b) | ||
1415 | { | ||
1416 | reader->setonespace(_b); | ||
1417 | } | ||
1418 | #ifdef REPALM | ||
1419 | void QTReaderApp::repalm(bool _b) | ||
1420 | { | ||
1421 | reader->setrepalm(_b); | ||
1422 | } | ||
1423 | #endif | ||
1147 | void QTReaderApp::remap(bool _b) | 1424 | void QTReaderApp::remap(bool _b) |
1148 | { | 1425 | { |
1149 | reader->setremap(_b); | 1426 | reader->setremap(_b); |
1150 | } | 1427 | } |
@@ -1187,9 +1464,12 @@ void QTReaderApp::dblspce(bool _b) | |||
1187 | void QTReaderApp::pagemode(bool _b) | 1464 | void QTReaderApp::pagemode(bool _b) |
1188 | { | 1465 | { |
1189 | reader->setpagemode(_b); | 1466 | reader->setpagemode(_b); |
1190 | } | 1467 | } |
1191 | 1468 | void QTReaderApp::navkeys(bool _b) | |
1469 | { | ||
1470 | reader->m_navkeys = _b; | ||
1471 | } | ||
1192 | void QTReaderApp::monospace(bool _b) | 1472 | void QTReaderApp::monospace(bool _b) |
1193 | { | 1473 | { |
1194 | reader->setmono(_b); | 1474 | reader->setmono(_b); |
1195 | } | 1475 | } |
@@ -1215,10 +1495,10 @@ void QTReaderApp::setoverlap() | |||
1215 | void QTReaderApp::settarget() | 1495 | void 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 | ||
@@ -1227,27 +1507,27 @@ void QTReaderApp::do_overlap(const QString& lcn) | |||
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 | ||
1237 | void QTReaderApp::do_mono(const QString& lcn) | 1517 | void 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 | /* |
1253 | void QTReaderApp::editPaste() | 1533 | void QTReaderApp::editPaste() |
@@ -1263,8 +1543,9 @@ void QTReaderApp::editFind() | |||
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 |
@@ -1290,8 +1571,9 @@ void QTReaderApp::findNext() | |||
1290 | void QTReaderApp::findClose() | 1571 | void 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()) |
@@ -1307,8 +1589,9 @@ void 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 |
@@ -1317,10 +1600,19 @@ bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QString& arg) | |||
1317 | bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg) | 1600 | bool 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 |
@@ -1330,19 +1622,30 @@ bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg) | |||
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 | ||
@@ -1387,208 +1690,298 @@ void QTReaderApp::search() | |||
1387 | #endif | 1690 | #endif |
1388 | 1691 | ||
1389 | void QTReaderApp::openFile( const QString &f ) | 1692 | void 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 | //} | |
1394 | void 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 | /* | ||
1727 | void QTReaderApp::resizeEvent(QResizeEvent* e) | ||
1728 | { | ||
1729 | if (m_fullscreen) | ||
1730 | { | ||
1731 | showNormal(); | ||
1732 | showFullScreen(); | ||
1733 | } | ||
1734 | } | ||
1735 | */ | ||
1736 | void 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 | ||
1426 | void QTReaderApp::showEditTools() | 1769 | void 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 | /* |
1444 | void QTReaderApp::save() | 1815 | void 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 | ||
1474 | void QTReaderApp::clear() | 1845 | void 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 | ||
1486 | void QTReaderApp::updateCaption() | 1857 | void 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 | ||
1498 | void QTReaderApp::setDocument(const QString& fileref) | 1869 | void 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 | ||
1506 | void QTReaderApp::closeEvent( QCloseEvent *e ) | 1877 | void 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 | ||
1552 | void QTReaderApp::do_gotomark() | 1932 | void QTReaderApp::do_gotomark() |
1553 | { | 1933 | { |
1554 | m_nRegAction = cGotoBkmk; | 1934 | m_nRegAction = cGotoBkmk; |
1555 | listbkmk(); | 1935 | listbkmk(pBkmklist); |
1556 | } | 1936 | } |
1557 | 1937 | ||
1558 | void QTReaderApp::do_delmark() | 1938 | void QTReaderApp::do_delmark() |
1559 | { | 1939 | { |
1560 | m_nRegAction = cDelBkmk; | 1940 | m_nRegAction = cDelBkmk; |
1561 | listbkmk(); | 1941 | listbkmk(pBkmklist); |
1562 | } | 1942 | } |
1563 | 1943 | ||
1564 | void QTReaderApp::listbkmk() | 1944 | void 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 | ||
1593 | void QTReaderApp::do_autogen() | 1986 | void QTReaderApp::do_autogen() |
1594 | { | 1987 | { |
@@ -1599,35 +1992,97 @@ void QTReaderApp::do_autogen() | |||
1599 | 1992 | ||
1600 | void QTReaderApp::do_regedit() | 1993 | void 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 | |||
2008 | bool 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 | ||
1608 | void QTReaderApp::gotobkmk(int ind) | 2049 | void 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 | ||
1628 | void QTReaderApp::cancelbkmk() | 2078 | void 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 | ||
1633 | void QTReaderApp::jump() | 2088 | void QTReaderApp::jump() |
@@ -1643,90 +2098,104 @@ void 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 | ||
1652 | void QTReaderApp::do_regaction() | 2107 | void 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 | ||
1682 | void QTReaderApp::do_settarget(const QString& _txt) | 2142 | void 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 | ||
1698 | void QTReaderApp::setfont() | 2158 | void 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 | ||
1712 | void QTReaderApp::setfontHelper(const QString& lcn, int size) | 2172 | void 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 | ||
1731 | void QTReaderApp::do_setfont(const QString& lcn) | 2200 | void QTReaderApp::do_setfont(const QString& lcn) |
1732 | { | 2201 | { |
@@ -1758,20 +2227,20 @@ pbar->resize(width(), editBar->height()); | |||
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(); |
@@ -1780,9 +2249,9 @@ pbar->resize(width(), editBar->height()); | |||
1780 | 2249 | ||
1781 | void QTReaderApp::saveprefs() | 2250 | void 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 | ||
@@ -1790,8 +2259,9 @@ void QTReaderApp::saveprefs() | |||
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 ); |
@@ -1799,8 +2269,9 @@ void QTReaderApp::saveprefs() | |||
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 ); |
@@ -1811,11 +2282,17 @@ void QTReaderApp::saveprefs() | |||
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 | ||
1820 | void QTReaderApp::indentplus() | 2297 | void QTReaderApp::indentplus() |
1821 | { | 2298 | { |
@@ -1843,42 +2320,42 @@ void 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 | */ |
@@ -1886,29 +2363,63 @@ void info_cb(Fl_Widget* o, void* _data) | |||
1886 | void QTReaderApp::savebkmks() | 2363 | void 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 | |||
2373 | void 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 | |||
2382 | void 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 | ||
1896 | void QTReaderApp::readbkmks() | 2392 | void 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 | ||
1913 | void QTReaderApp::addbkmk() | 2424 | void QTReaderApp::addbkmk() |
1914 | { | 2425 | { |
@@ -1918,46 +2429,47 @@ void QTReaderApp::addbkmk() | |||
1918 | } | 2429 | } |
1919 | 2430 | ||
1920 | void QTReaderApp::do_addbkmk(const QString& text) | 2431 | void 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 | ||
1946 | void QTReaderApp::OnRedraw() | 2457 | void 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 | ||
1955 | void QTReaderApp::showAnnotation() | 2466 | void 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 | ||
@@ -1966,64 +2478,129 @@ void QTReaderApp::OnWordSelected(const QString& wrd, size_t posn, const QString& | |||
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 | ||
2000 | void QTReaderApp::OnActionPressed() | 2513 | void 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 | ||
2028 | void QTReaderApp::setTwoTouch(bool _b) { reader->setTwoTouch(_b); } | 2546 | void QTReaderApp::setTwoTouch(bool _b) { reader->setTwoTouch(_b); } |
2029 | void QTReaderApp::restoreFocus() { reader->setFocus(); } | 2547 | void QTReaderApp::restoreFocus() { reader->setFocus(); } |
2548 | |||
2549 | /* | ||
2550 | void 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 | |||
2570 | void 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 | |||
@@ -22,9 +22,9 @@ | |||
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> |
@@ -38,22 +38,24 @@ | |||
38 | class QWidgetStack; | 38 | class QWidgetStack; |
39 | class QToolButton; | 39 | class QToolButton; |
40 | class QPopupMenu; | 40 | class QPopupMenu; |
41 | class QToolBar; | 41 | class QToolBar; |
42 | class QPEToolBar; | 42 | //class QPEToolBar; |
43 | class CBkmkSelector; | 43 | class CBkmkSelector; |
44 | class QProgressBar; | 44 | class QProgressBar; |
45 | class QAction; | 45 | class QAction; |
46 | class CAnnoEdit; | 46 | class CAnnoEdit; |
47 | class QFloatBar; | 47 | class QFloatBar; |
48 | class CDrawBuffer; | 48 | class CDrawBuffer; |
49 | class QTReader; | 49 | class QTReader; |
50 | class QPixmap; | ||
50 | 51 | ||
51 | enum ActionTypes | 52 | enum 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 |
59 | struct searchrecord | 61 | struct searchrecord |
@@ -64,8 +66,9 @@ struct searchrecord | |||
64 | }; | 66 | }; |
65 | #endif | 67 | #endif |
66 | 68 | ||
67 | class infowin; | 69 | class infowin; |
70 | class GraphicWin; | ||
68 | 71 | ||
69 | class QTReaderApp : public QMainWindow | 72 | class QTReaderApp : public QMainWindow |
70 | { | 73 | { |
71 | Q_OBJECT | 74 | Q_OBJECT |
@@ -75,18 +78,20 @@ class QTReaderApp : public QMainWindow | |||
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&); |
@@ -96,12 +101,17 @@ class QTReaderApp : public QMainWindow | |||
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(); |
103 | private slots: | 109 | private 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 | { |
@@ -115,8 +125,9 @@ private slots: | |||
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(); |
@@ -140,15 +151,14 @@ private slots: | |||
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 | ||
@@ -165,12 +175,15 @@ private slots: | |||
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); |
@@ -180,8 +193,9 @@ private slots: | |||
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(); |
@@ -191,10 +205,20 @@ private slots: | |||
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(); |
@@ -222,13 +246,13 @@ private slots: | |||
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; |
@@ -242,9 +266,11 @@ private slots: | |||
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; |
@@ -259,5 +285,7 @@ const int cRmBkmkFile = 4; | |||
259 | const int cJump = 5; | 285 | const int cJump = 5; |
260 | const int cMonoSpace = 6; | 286 | const int cMonoSpace = 6; |
261 | const int cOverlap = 7; | 287 | const int cOverlap = 7; |
262 | const int cSetTarget = 8; | 288 | const int cSetTarget = 8; |
289 | const 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 | |||
4 | struct 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 | |||
5 | GraphicLink::~GraphicLink() { delete graphic; } | ||
6 | |||
7 | pmstore::~pmstore() | ||
8 | { | ||
9 | // qDebug("Deleting image"); | ||
10 | delete graphic; | ||
11 | } | ||
12 | |||
13 | CStyle::~CStyle() | ||
14 | { | ||
15 | if (graphic != NULL) | ||
16 | { | ||
17 | if (--(graphic->count) == 0) | ||
18 | { | ||
19 | delete graphic; | ||
20 | } | ||
21 | } | ||
22 | } | ||
23 | |||
24 | CStyle::CStyle(CStyle& rhs) : graphic(NULL) | ||
25 | { | ||
26 | *this = rhs; | ||
27 | } | ||
28 | |||
29 | CStyle::CStyle(const CStyle& rhs) : graphic(NULL) | ||
30 | { | ||
31 | *this = rhs; | ||
32 | } | ||
33 | |||
34 | CStyle& 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 | |||
63 | void CStyle::clearPicture() | ||
64 | { | ||
65 | if (graphic != NULL) | ||
66 | { | ||
67 | if (--(graphic->count) == 0) | ||
68 | { | ||
69 | delete graphic; | ||
70 | } | ||
71 | graphic = NULL; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | void 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 | |||
88 | void 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 | |||
@@ -2,112 +2,176 @@ | |||
2 | #define __STYLECONSTS_H | 2 | #define __STYLECONSTS_H |
3 | 3 | ||
4 | typedef unsigned short StyleType; | 4 | typedef unsigned short StyleType; |
5 | 5 | ||
6 | class CStyle | 6 | #include <stdlib.h> |
7 | #include <qglobal.h> | ||
8 | class QPixmap; | ||
9 | |||
10 | struct 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 | ||
20 | struct 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; | 31 | enum 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; } | 39 | class 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; } | 78 | class 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 | |||
7 | class Text: public CExpander { | ||
8 | FILE* file; | ||
9 | public: | ||
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 | |||
@@ -9,16 +9,45 @@ | |||
9 | class Text: public CExpander { | 9 | class Text: public CExpander { |
10 | gzFile file; | 10 | gzFile file; |
11 | unsigned long fsize; | 11 | unsigned long fsize; |
12 | public: | 12 | public: |
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); |
@@ -32,8 +61,8 @@ public: | |||
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 | |||
@@ -8,8 +8,9 @@ class CBkmkSelector : public QWidget | |||
8 | 8 | ||
9 | Q_OBJECT | 9 | Q_OBJECT |
10 | 10 | ||
11 | QListBox* bkmkselector; | 11 | QListBox* bkmkselector; |
12 | QPushButton* exitButton; | ||
12 | 13 | ||
13 | signals: | 14 | signals: |
14 | void selected(int i); | 15 | void selected(int i); |
15 | void cancelled(); | 16 | void cancelled(); |
@@ -26,9 +27,9 @@ public: | |||
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); |
@@ -36,6 +37,7 @@ public: | |||
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 | |||
@@ -17,5 +17,9 @@ const 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 | |||
@@ -38,16 +38,19 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags | |||
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() ) ); |
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,9 +1,10 @@ | |||
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 | ||
5 | infowin::infowin( QWidget *parent, const char *name, WFlags f) : | 6 | infowin::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; |
@@ -32,9 +33,9 @@ infowin::infowin( QWidget *parent, const char *name, WFlags f) : | |||
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() ) ); |
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 | |||
@@ -8,9 +8,13 @@ | |||
8 | QTReaderApp* app = NULL; | 8 | QTReaderApp* app = NULL; |
9 | 9 | ||
10 | void handler(int signum) | 10 | void 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 | ||
16 | int main( int argc, char ** argv ) | 20 | int main( int argc, char ** argv ) |
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 @@ | |||
1 | TEMPLATE = app | 1 | TEMPLATE= app |
2 | CONFIG = qt warn_on release | 2 | CONFIG = qt warn_on release |
3 | HEADERS = 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 \ |
34 | SOURCES = 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 \ |
53 | DESTDIR = $(OPIEDIR)/bin | 53 | QTReader.cpp \ |
54 | INCLUDEPATH += $(OPIEDIR)/include | 54 | QTReaderApp.cpp \ |
55 | DEPENDPATH += $(OPIEDIR)/include | 55 | QtrListView.cpp \ |
56 | TARGET = reader | 56 | StyleConsts.cpp \ |
57 | LIBS += -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,5 +1,8 @@ | |||
1 | #include "pdb.h" | 1 | #include "pdb.h" |
2 | #include <sys/types.h> | ||
3 | #include <sys/stat.h> | ||
4 | #include <unistd.h> | ||
2 | 5 | ||
3 | size_t Cpdb::recordpos(int n) | 6 | size_t Cpdb::recordpos(int n) |
4 | { | 7 | { |
5 | UInt16 mxn = ntohs(head.recordList.numRecords); | 8 | UInt16 mxn = ntohs(head.recordList.numRecords); |
@@ -45,12 +48,15 @@ bool Cpdb::openfile(const char *src) | |||
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; |
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,263 +1,569 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <string.h> | 2 | #include <string.h> |
3 | #include <qmessagebox.h> | 3 | #include <qmessagebox.h> |
4 | #include "plucker.h" | 4 | #include <qpixmap.h> |
5 | #include <qpe/qcopenvelope_qws.h> | ||
6 | #ifdef LOCALPICTURES | ||
7 | #include <qscrollview.h> | ||
8 | #endif | ||
9 | #include <qpe/global.h> | ||
10 | #include <qclipboard.h> | ||
11 | #include <qpe/qpeapplication.h> | ||
5 | 12 | ||
13 | #include "plucker.h" | ||
6 | #include "Aportis.h" | 14 | #include "Aportis.h" |
15 | #include "Palm2QImage.h" | ||
16 | #include "name.h" | ||
17 | |||
18 | CPlucker::CPlucker() : | ||
19 | #ifdef LOCALPICTURES | ||
20 | m_viewer(NULL), | ||
21 | m_picture(NULL), | ||
22 | #endif | ||
23 | expandedtextbuffer(NULL), | ||
24 | compressedtextbuffer(NULL), | ||
25 | urls(NULL) | ||
26 | { /*printf("constructing:%x\n",fin);*/ } | ||
7 | 27 | ||
8 | CPlucker::CPlucker() : expandedtextbuffer(NULL), compressedtextbuffer(NULL) { /*printf("constructing:%x\n",fin);*/ } | ||
9 | 28 | ||
29 | void CPlucker::Expand(UInt16 reclen, UInt8 type, UInt8* buffer, UInt16 buffersize) | ||
30 | { | ||
31 | if (type%2 == 0) | ||
32 | { | ||
33 | fread(buffer, reclen, sizeof(char), fin); | ||
34 | } | ||
35 | else | ||
36 | { | ||
37 | fread(compressedtextbuffer, reclen, sizeof(char), fin); | ||
38 | switch (ntohs(hdr0.version)) | ||
39 | { | ||
40 | case 2: | ||
41 | UnZip(reclen, buffer, buffersize); | ||
42 | break; | ||
43 | case 1: | ||
44 | UnDoc(reclen, buffer, buffersize); | ||
45 | break; | ||
46 | } | ||
47 | } | ||
48 | } | ||
10 | 49 | ||
11 | int CPlucker::openfile(const char *src) | 50 | int CPlucker::OpenFile(const char *src) |
12 | { | 51 | { |
52 | m_lastBreak = 0; | ||
13 | if (!Cpdb::openfile(src)) | 53 | if (!Cpdb::openfile(src)) |
14 | { | 54 | { |
15 | return -1; | 55 | return -1; |
16 | } | 56 | } |
17 | 57 | ||
18 | //printf("Okay %u\n", 4); | 58 | //printf("Okay %u\n", 4); |
19 | 59 | ||
20 | if (memcmp(&head.type, "DataPlkr", 8) != 0) return -1; | 60 | if (memcmp(&head.type, "DataPlkr", 8) != 0) return -1; |
21 | 61 | ||
22 | // qDebug("Cool - this IS plucker"); | 62 | // qDebug("Cool - this IS plucker"); |
23 | 63 | ||
24 | textlength = 0; | 64 | EOPPhase = 0; |
25 | for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | ||
26 | { | ||
27 | CPlucker_dataRecord thisHdr; | ||
28 | gotorecordnumber(recptr); | ||
29 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
30 | if (thisHdr.type < 2) textlength += htons(thisHdr.size); | ||
31 | } | ||
32 | |||
33 | gotorecordnumber(0); | 65 | gotorecordnumber(0); |
34 | fread(&hdr0, 1, sizeof(hdr0), fin); | 66 | fread(&hdr0, 1, sizeof(hdr0), fin); |
35 | //printf("Okay %u\n", 5); | 67 | //printf("Okay %u\n", 5); |
36 | buffersize = 32*1024; | 68 | buffersize = 32*1024; |
37 | compressedtextbuffer = new UInt8[buffersize]; | 69 | compressedtextbuffer = new UInt8[buffersize]; |
38 | expandedtextbuffer = new UInt8[buffersize]; | 70 | expandedtextbuffer = new UInt8[buffersize]; |
39 | 71 | ||
40 | // qDebug("Total number of records:%u", ntohs(head.recordList.numRecords)); | 72 | qDebug("Total number of records:%u", ntohs(head.recordList.numRecords)); |
41 | 73 | ||
42 | unsigned int nrecs = ntohs(hdr0.nRecords); | 74 | unsigned int nrecs = ntohs(hdr0.nRecords); |
43 | // qDebug("Version %u, no. res %u", ntohs(hdr0.version), nrecs); | 75 | qDebug("Version %u, no. recs %u", ntohs(hdr0.version), nrecs); |
44 | for (unsigned int i = 0; i < 4*nrecs; i++) | 76 | UInt16 homerecid = 1; |
77 | UInt16 urlid = 0; | ||
78 | bool urlsfound = false; | ||
79 | for (unsigned int i = 0; i < nrecs; i++) | ||
45 | { | 80 | { |
46 | UInt8 id; | 81 | UInt16 id, name; |
47 | fread(&id, 1, sizeof(id), fin); | 82 | fread(&name, 1, sizeof(name), fin); |
48 | // qDebug("%x", id); | 83 | fread(&id, 1, sizeof(id), fin); |
84 | qDebug("N:%d, I:%d", ntohs(name), ntohs(id)); | ||
85 | if (ntohs(name) == 0) homerecid = ntohs(id); | ||
86 | if (ntohs(name) == 2) | ||
87 | { | ||
88 | urlsfound = true; | ||
89 | urlid = id; | ||
90 | qDebug("Found url index:%d", ntohs(urlid)); | ||
91 | } | ||
92 | //qDebug("%x", id); | ||
49 | } | 93 | } |
94 | |||
95 | textlength = 0; | ||
96 | for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | ||
97 | { | ||
98 | CPlucker_dataRecord thisHdr; | ||
99 | gotorecordnumber(recptr); | ||
100 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
101 | if (ntohs(thisHdr.uid) == homerecid) | ||
102 | { | ||
103 | m_homepos = textlength; | ||
104 | qDebug("Home pos found after %u records", recptr); | ||
105 | break; | ||
106 | } | ||
107 | if (thisHdr.type < 2) textlength += ntohs(thisHdr.size); | ||
108 | } | ||
109 | textlength = 0; | ||
110 | |||
111 | if (urlsfound) | ||
112 | { | ||
113 | unsigned short recptr = finduid(ntohs(urlid)); | ||
114 | if (recptr != 0) | ||
115 | { | ||
116 | CPlucker_dataRecord thisHdr; | ||
117 | gotorecordnumber(recptr); | ||
118 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
119 | fread(&urlid, 1, sizeof(urlid), fin); | ||
120 | fread(&urlid, 1, sizeof(urlid), fin); | ||
121 | qDebug("urls are in %d", ntohs(urlid)); | ||
122 | recptr = finduid(ntohs(urlid)); | ||
123 | if (recptr != 0) | ||
124 | { | ||
125 | gotorecordnumber(recptr); | ||
126 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
127 | qDebug("Found urls:%x",thisHdr.type); | ||
128 | UInt16 reclen = recordlength(recptr) - sizeof(thisHdr); | ||
129 | gotorecordnumber(recptr); | ||
130 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
131 | urlsize = ntohs(thisHdr.size); | ||
132 | urls = new char[urlsize]; | ||
133 | Expand(reclen, thisHdr.type, (UInt8*)urls, urlsize); | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | /* | ||
138 | for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | ||
139 | { | ||
140 | CPlucker_dataRecord thisHdr; | ||
141 | gotorecordnumber(recptr); | ||
142 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
143 | if (thisHdr.uid == urlid) | ||
144 | { | ||
145 | qDebug("Found urls:%x",thisHdr.type); | ||
146 | UInt16 reclen = recordlength(recptr) - sizeof(thisHdr); | ||
147 | gotorecordnumber(recptr); | ||
148 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
149 | urlsize = ntohs(thisHdr.size); | ||
150 | urls = new char[urlsize]; | ||
151 | Expand(reclen, thisHdr.type, (UInt8*)urls, urlsize); | ||
152 | break; | ||
153 | } | ||
154 | } | ||
155 | */ | ||
50 | home(); | 156 | home(); |
157 | #ifdef LOCALPICTURES | ||
158 | if (m_viewer == NULL) | ||
159 | { | ||
160 | m_viewer = new QScrollView(NULL); | ||
161 | m_picture = new QWidget(m_viewer->viewport()); | ||
162 | m_viewer->addChild(m_picture); | ||
163 | } | ||
164 | #endif | ||
51 | return 0; | 165 | return 0; |
166 | |||
167 | } | ||
168 | |||
169 | void CPlucker::sizes(unsigned long& _file, unsigned long& _text) | ||
170 | { | ||
171 | qDebug("Sizes called:%u",textlength); | ||
172 | _file = file_length; | ||
173 | if (textlength == 0) | ||
174 | { | ||
175 | for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | ||
176 | { | ||
177 | CPlucker_dataRecord thisHdr; | ||
178 | gotorecordnumber(recptr); | ||
179 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
180 | if (thisHdr.type < 2) textlength += ntohs(thisHdr.size); | ||
181 | } | ||
182 | } | ||
183 | _text = textlength; | ||
184 | //ntohl(hdr0.size); | ||
185 | } | ||
186 | |||
187 | |||
188 | char* CPlucker::geturl(UInt16 i) | ||
189 | { | ||
190 | if (urls == NULL) return NULL; | ||
191 | char* ptr = urls; | ||
192 | int rn = 1; | ||
193 | while (ptr - urls < urlsize) | ||
194 | { | ||
195 | if (rn == i) return ptr; | ||
196 | ptr += strlen(ptr)+1; | ||
197 | rn++; | ||
198 | } | ||
199 | return NULL; | ||
200 | } | ||
201 | |||
202 | CPlucker::~CPlucker() | ||
203 | { | ||
204 | if (expandedtextbuffer != NULL) delete [] expandedtextbuffer; | ||
205 | if (compressedtextbuffer != NULL) delete [] compressedtextbuffer; | ||
206 | if (urls != NULL) delete [] urls; | ||
207 | #ifdef LOCALPICTURES | ||
208 | if (m_viewer != NULL) delete m_viewer; | ||
209 | #endif | ||
52 | } | 210 | } |
53 | 211 | ||
54 | int CPlucker::bgetch() | 212 | int CPlucker::bgetch() |
55 | { | 213 | { |
56 | int ch = EOF; | 214 | int ch = EOF; |
57 | if (bufferpos >= buffercontent) | 215 | if (bufferpos >= buffercontent) |
58 | { | 216 | { |
59 | if (bufferrec >= ntohs(head.recordList.numRecords) - 1) return EOF; | 217 | if (!m_continuous) return EOF; |
60 | // qDebug("Passing through %u", currentpos); | 218 | if (bufferrec >= ntohs(head.recordList.numRecords) - 1) return EOF; |
61 | if (!expand(bufferrec+1)) return EOF; | 219 | //qDebug("Passing through %u", currentpos); |
62 | mystyle.unset(); | 220 | if (!expand(bufferrec+1)) return EOF; |
221 | mystyle.unset(); | ||
222 | ch = 10; | ||
223 | EOPPhase = 4; | ||
63 | } | 224 | } |
64 | 225 | else if (bufferpos == m_nextPara) | |
65 | if (bufferpos == m_nextPara) | ||
66 | { | 226 | { |
67 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; | 227 | while (bufferpos == m_nextPara) |
68 | m_nextParaIndex++; | 228 | { |
69 | if (m_nextParaIndex == m_nParas) | 229 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; |
70 | { | 230 | m_nextParaIndex++; |
71 | m_nextPara = -1; | 231 | if (m_nextParaIndex == m_nParas) |
72 | } | 232 | { |
73 | else | 233 | m_nextPara = -1; |
74 | { | 234 | } |
75 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; | 235 | else |
76 | } | 236 | { |
77 | // qDebug("New paragraph"); | 237 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; |
78 | ch = 10; | 238 | } |
239 | } | ||
240 | mystyle.unset(); | ||
241 | if (m_lastBreak == locate()) | ||
242 | { | ||
243 | currentpos++; | ||
244 | ch = expandedtextbuffer[bufferpos++]; | ||
245 | } | ||
246 | else | ||
247 | { | ||
248 | ch = 10; | ||
249 | } | ||
79 | } | 250 | } |
80 | else | 251 | else |
81 | { | 252 | { |
82 | currentpos++; | 253 | currentpos++; |
83 | ch = expandedtextbuffer[bufferpos++]; | 254 | ch = expandedtextbuffer[bufferpos++]; |
84 | } | 255 | } |
85 | return ch; | 256 | return ch; |
86 | } | 257 | } |
87 | 258 | ||
88 | int CPlucker::getch() | 259 | int CPlucker::getch() |
89 | { | 260 | { |
90 | int ch = bgetch(); | 261 | mystyle.clearPicture(); |
91 | while (ch == 0) | 262 | |
92 | { | 263 | |
93 | ch = bgetch(); | 264 | if (EOPPhase > 0) |
94 | // qDebug("Function:%x", ch); | ||
95 | switch (ch) | ||
96 | { | ||
97 | case 0x38: | ||
98 | ch = 10; | ||
99 | break; | ||
100 | case 0x0a: | ||
101 | case 0x0c: | ||
102 | { | ||
103 | unsigned long ln = 0; | ||
104 | int skip = ch & 7; | ||
105 | for (int i = 0; i < 2; i++) | ||
106 | { | 265 | { |
107 | int ch = bgetch(); | 266 | int ch = 10; |
108 | ln = (ln << 8) + ch; | 267 | switch (EOPPhase) |
109 | // qDebug("ch:%d, ln:%u", ch, ln); | 268 | { |
269 | case 4: | ||
270 | mystyle.setPicture(hRule(100,5)); | ||
271 | mystyle.setCentreJustify(); | ||
272 | ch = '#'; | ||
273 | break; | ||
274 | case 3: | ||
275 | mystyle.setFontSize(3); | ||
276 | ch = 10; | ||
277 | break; | ||
278 | case 2: | ||
279 | ch = 10; | ||
280 | break; | ||
281 | case 1: | ||
282 | mystyle.unset(); | ||
283 | default: | ||
284 | ch = 10; | ||
285 | } | ||
286 | EOPPhase--; | ||
287 | return ch; | ||
110 | } | 288 | } |
111 | if (skip == 2) | 289 | |
290 | |||
291 | int ch = bgetch(); | ||
292 | while (ch == 0) | ||
112 | { | 293 | { |
113 | ln <<= 16; | 294 | ch = bgetch(); |
295 | //qDebug("Function:%x", ch); | ||
296 | switch (ch) | ||
297 | { | ||
298 | case 0x38: | ||
299 | // qDebug("Break:%u", locate()); | ||
300 | if (m_lastBreak == locate()) | ||
301 | { | ||
302 | ch = bgetch(); | ||
303 | } | ||
304 | else | ||
305 | { | ||
306 | ch = 10; | ||
307 | } | ||
308 | m_lastBreak = locate(); | ||
309 | break; | ||
310 | case 0x0a: | ||
311 | case 0x0c: | ||
312 | { | ||
313 | unsigned long ln = 0; | ||
314 | int skip = ch & 7; | ||
315 | for (int i = 0; i < 2; i++) | ||
316 | { | ||
317 | int ch = bgetch(); | ||
318 | ln = (ln << 8) + ch; | ||
319 | // qDebug("ch:%d, ln:%u", ch, ln); | ||
320 | } | ||
321 | if (skip == 2) | ||
322 | { | ||
323 | ln <<= 16; | ||
324 | } | ||
325 | else | ||
326 | { | ||
327 | for (int i = 0; i < 2; i++) | ||
328 | { | ||
329 | int ch = bgetch(); | ||
330 | ln = (ln << 8) + ch; | ||
331 | // qDebug("ch:%d, ln:%u", ch, ln); | ||
332 | } | ||
333 | } | ||
334 | // qDebug("ln:%u", ln); | ||
335 | mystyle.setLink(true); | ||
336 | mystyle.setData(ln); | ||
337 | // mystyle.setColour(255, 0, 0); | ||
338 | bool hasseen = false; | ||
339 | for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) | ||
340 | { | ||
341 | if (*it == ln) | ||
342 | { | ||
343 | hasseen = true; | ||
344 | break; | ||
345 | } | ||
346 | } | ||
347 | if (hasseen) | ||
348 | { | ||
349 | mystyle.setStrikethru(); | ||
350 | } | ||
351 | else | ||
352 | { | ||
353 | mystyle.setUnderline(); | ||
354 | } | ||
355 | ch = bgetch(); | ||
356 | } | ||
357 | break; | ||
358 | case 0x08: | ||
359 | ch = bgetch(); | ||
360 | // mystyle.setColour(0, 0, 0); | ||
361 | mystyle.unsetUnderline(); | ||
362 | mystyle.unsetStrikethru(); | ||
363 | mystyle.setLink(false); | ||
364 | mystyle.setData(0); | ||
365 | break; | ||
366 | case 0x40: | ||
367 | mystyle.setItalic(); | ||
368 | ch = bgetch(); | ||
369 | break; | ||
370 | case 0x48: | ||
371 | mystyle.unsetItalic(); | ||
372 | ch = bgetch(); | ||
373 | break; | ||
374 | case 0x11: | ||
375 | { | ||
376 | ch = bgetch(); | ||
377 | // qDebug("Font:%d",ch); | ||
378 | switch (ch) | ||
379 | { | ||
380 | case 0: | ||
381 | mystyle.unsetMono(); | ||
382 | mystyle.unsetBold(); | ||
383 | mystyle.setFontSize(0); | ||
384 | break; | ||
385 | case 1: | ||
386 | mystyle.unsetMono(); | ||
387 | mystyle.setBold(); | ||
388 | mystyle.setFontSize(3); | ||
389 | break; | ||
390 | case 2: | ||
391 | mystyle.unsetMono(); | ||
392 | mystyle.setBold(); | ||
393 | mystyle.setFontSize(2); | ||
394 | break; | ||
395 | case 3: | ||
396 | mystyle.unsetMono(); | ||
397 | mystyle.setBold(); | ||
398 | // mystyle.unsetBold(); | ||
399 | mystyle.setFontSize(1); | ||
400 | break; | ||
401 | case 4: | ||
402 | mystyle.unsetMono(); | ||
403 | mystyle.setBold(); | ||
404 | // mystyle.unsetBold(); | ||
405 | mystyle.setFontSize(0); | ||
406 | break; | ||
407 | case 5: | ||
408 | mystyle.unsetMono(); | ||
409 | mystyle.setBold(); | ||
410 | mystyle.setFontSize(0); | ||
411 | break; | ||
412 | case 6: | ||
413 | mystyle.unsetMono(); | ||
414 | mystyle.setBold(); | ||
415 | mystyle.setFontSize(0); | ||
416 | break; | ||
417 | case 7: | ||
418 | mystyle.unsetMono(); | ||
419 | mystyle.setBold(); | ||
420 | mystyle.setFontSize(0); | ||
421 | break; | ||
422 | case 8: // should be fixed width | ||
423 | qDebug("Trying fixed width"); | ||
424 | mystyle.unsetBold(); | ||
425 | mystyle.setFontSize(0); | ||
426 | mystyle.setMono(); | ||
427 | break; | ||
428 | default: | ||
429 | mystyle.unsetBold(); | ||
430 | mystyle.unsetMono(); | ||
431 | mystyle.setFontSize(0); | ||
432 | break; | ||
433 | } | ||
434 | ch = bgetch(); | ||
435 | } | ||
436 | break; | ||
437 | case 0x29: | ||
438 | ch = bgetch(); | ||
439 | switch (ch) | ||
440 | { | ||
441 | case 0: | ||
442 | mystyle.setLeftJustify(); | ||
443 | // qDebug("left"); | ||
444 | break; | ||
445 | case 1: | ||
446 | mystyle.setRightJustify(); | ||
447 | // qDebug("right"); | ||
448 | break; | ||
449 | case 2: | ||
450 | mystyle.setCentreJustify(); | ||
451 | // qDebug("centre"); | ||
452 | break; | ||
453 | case 3: | ||
454 | mystyle.setFullJustify(); | ||
455 | // qDebug("full"); | ||
456 | break; | ||
457 | |||
458 | } | ||
459 | ch = bgetch(); | ||
460 | break; | ||
461 | case 0x53: | ||
462 | { | ||
463 | int r = bgetch(); | ||
464 | int g = bgetch(); | ||
465 | int b = bgetch(); | ||
466 | mystyle.setColour(r,g,b); | ||
467 | ch = bgetch(); | ||
468 | } | ||
469 | break; | ||
470 | case 0x1a: | ||
471 | case 0x5c: | ||
472 | { | ||
473 | bool hasalternate = (ch == 0x5c); | ||
474 | UInt16 ir = bgetch(); | ||
475 | ir = (ir << 8) + bgetch(); | ||
476 | if (hasalternate) | ||
477 | { | ||
478 | qDebug("Alternate image:%x", ir); | ||
479 | UInt16 ir2 = bgetch(); | ||
480 | ir2 = (ir2 << 8) + bgetch(); | ||
481 | mystyle.setPicture(expandimg(ir2, true), true, ir); | ||
482 | #ifdef LOCALPICTURES | ||
483 | UInt32 ln = ir; | ||
484 | ln <<= 16; | ||
485 | mystyle.setLink(true); | ||
486 | mystyle.setData(ln); | ||
487 | #endif | ||
488 | } | ||
489 | else | ||
490 | { | ||
491 | mystyle.setPicture(expandimg(ir)); | ||
492 | } | ||
493 | if (mystyle.getLink()) qDebug("Picture link!"); | ||
494 | ch = '#'; | ||
495 | } | ||
496 | // ch = bgetch(); | ||
497 | break; | ||
498 | case 0x33: | ||
499 | { | ||
500 | UInt8 h = bgetch(); | ||
501 | UInt8 wc = bgetch(); | ||
502 | UInt8 pc = bgetch(); | ||
503 | UInt16 w = wc; | ||
504 | // qDebug("h,w,pc [%u, %u, %u]", h, w, pc); | ||
505 | if (w == 0) | ||
506 | { | ||
507 | w = (240*(unsigned long)pc)/100; | ||
508 | } | ||
509 | if (w == 0) w = 320; | ||
510 | mystyle.setPicture(hRule(w,h,mystyle.Red(),mystyle.Green(),mystyle.Blue())); | ||
511 | // if (mystyle.getLink()) qDebug("hRule link!"); | ||
512 | ch = '#'; | ||
513 | } | ||
514 | break; | ||
515 | case 0x60: | ||
516 | mystyle.setUnderline(); | ||
517 | ch = bgetch(); | ||
518 | break; | ||
519 | case 0x68: | ||
520 | mystyle.unsetUnderline(); | ||
521 | ch = bgetch(); | ||
522 | break; | ||
523 | case 0x22: | ||
524 | ch = bgetch(); | ||
525 | mystyle.setLeftMargin(ch); | ||
526 | // qDebug("Left margin:%d", ch); | ||
527 | ch = bgetch(); | ||
528 | mystyle.setRightMargin(ch); | ||
529 | // qDebug("Right margin:%d", ch); | ||
530 | ch = bgetch(); | ||
531 | break; | ||
532 | case 0x70: | ||
533 | mystyle.setStrikethru(); | ||
534 | ch = bgetch(); | ||
535 | break; | ||
536 | case 0x78: | ||
537 | mystyle.unsetStrikethru(); | ||
538 | ch = bgetch(); | ||
539 | break; | ||
540 | case 0x83: | ||
541 | case 0x85: | ||
542 | default: | ||
543 | qDebug("Function:%x NOT IMPLEMENTED", ch); | ||
544 | { | ||
545 | int skip = ch & 7; | ||
546 | for (int i = 0; i < skip; i++) | ||
547 | { | ||
548 | ch = bgetch(); | ||
549 | // qDebug("Arg %d, %d", i, ch); | ||
550 | } | ||
551 | ch = bgetch(); | ||
552 | } | ||
553 | } | ||
114 | } | 554 | } |
115 | else | 555 | |
556 | if (m_lastIsBreak && !mystyle.isMono()) | ||
116 | { | 557 | { |
117 | for (int i = 0; i < 2; i++) | 558 | while (ch == ' ') |
118 | { | 559 | { |
119 | int ch = bgetch(); | 560 | ch = getch(); |
120 | ln = (ln << 8) + ch; | 561 | } |
121 | // qDebug("ch:%d, ln:%u", ch, ln); | ||
122 | } | ||
123 | } | ||
124 | // qDebug("ln:%u", ln); | ||
125 | mystyle.setLink(true); | ||
126 | mystyle.setData(ln); | ||
127 | mystyle.setColour(255, 0, 0); | ||
128 | ch = bgetch(); | ||
129 | } | ||
130 | break; | ||
131 | case 0x08: | ||
132 | ch = bgetch(); | ||
133 | mystyle.setColour(0, 0, 0); | ||
134 | mystyle.setLink(false); | ||
135 | mystyle.setData(0); | ||
136 | break; | ||
137 | case 0x40: | ||
138 | mystyle.setItalic(); | ||
139 | ch = bgetch(); | ||
140 | break; | ||
141 | case 0x48: | ||
142 | mystyle.unsetItalic(); | ||
143 | ch = bgetch(); | ||
144 | break; | ||
145 | case 0x11: | ||
146 | { | ||
147 | ch = bgetch(); | ||
148 | qDebug("Font:%d",ch); | ||
149 | switch (ch) | ||
150 | { | ||
151 | case 0: | ||
152 | mystyle.unsetBold(); | ||
153 | mystyle.setFontSize(0); | ||
154 | break; | ||
155 | case 1: | ||
156 | mystyle.setBold(); | ||
157 | mystyle.setFontSize(1); | ||
158 | break; | ||
159 | case 2: | ||
160 | mystyle.setBold(); | ||
161 | mystyle.setFontSize(1); | ||
162 | break; | ||
163 | case 3: | ||
164 | // mystyle.setBold(); | ||
165 | mystyle.setFontSize(1); | ||
166 | break; | ||
167 | case 4: | ||
168 | // mystyle.setBold(); | ||
169 | mystyle.setFontSize(1); | ||
170 | break; | ||
171 | case 5: | ||
172 | mystyle.setBold(); | ||
173 | mystyle.setFontSize(0); | ||
174 | break; | ||
175 | case 6: | ||
176 | mystyle.setBold(); | ||
177 | mystyle.setFontSize(0); | ||
178 | break; | ||
179 | case 7: | ||
180 | mystyle.setBold(); | ||
181 | mystyle.setFontSize(0); | ||
182 | break; | ||
183 | case 8: // should be fixed width | ||
184 | mystyle.unsetBold(); | ||
185 | mystyle.setFontSize(0); | ||
186 | break; | ||
187 | default: | ||
188 | mystyle.unsetBold(); | ||
189 | mystyle.setFontSize(0); | ||
190 | break; | ||
191 | } | ||
192 | ch = bgetch(); | ||
193 | } | ||
194 | break; | ||
195 | case 0x29: | ||
196 | ch = bgetch(); | ||
197 | switch (ch) | ||
198 | { | ||
199 | case 0: | ||
200 | mystyle.setLeftJustify(); | ||
201 | // qDebug("left"); | ||
202 | break; | ||
203 | case 1: | ||
204 | mystyle.setRightJustify(); | ||
205 | // qDebug("right"); | ||
206 | break; | ||
207 | case 2: | ||
208 | mystyle.setCentreJustify(); | ||
209 | // qDebug("centre"); | ||
210 | break; | ||
211 | case 3: | ||
212 | mystyle.setFullJustify(); | ||
213 | // qDebug("full"); | ||
214 | break; | ||
215 | |||
216 | } | ||
217 | ch = bgetch(); | ||
218 | break; | ||
219 | case 0x53: | ||
220 | { | ||
221 | int r = bgetch(); | ||
222 | int g = bgetch(); | ||
223 | int b = bgetch(); | ||
224 | mystyle.setColour(r,g,b); | ||
225 | ch = bgetch(); | ||
226 | } | ||
227 | break; | ||
228 | case 0x1a: | ||
229 | /* | ||
230 | { | ||
231 | UInt16 ir = bgetch(); | ||
232 | ir = (ir << 8) + bgetch(); | ||
233 | expandimg(ir); | ||
234 | } | ||
235 | ch = bgetch(); | ||
236 | break; | ||
237 | */ | ||
238 | case 0x33: | ||
239 | case 0x22: | ||
240 | case 0x5c: | ||
241 | case 0x60: | ||
242 | case 0x68: | ||
243 | case 0x70: | ||
244 | case 0x78: | ||
245 | case 0x83: | ||
246 | case 0x85: | ||
247 | default: | ||
248 | qDebug("Function:%x NOT IMPLEMENTED", ch); | ||
249 | { | ||
250 | int skip = ch & 7; | ||
251 | for (int i = 0; i < skip; i++) | ||
252 | { | ||
253 | ch = bgetch(); | ||
254 | qDebug("Arg %d, %d", i, ch); | ||
255 | } | ||
256 | ch = bgetch(); | ||
257 | } | ||
258 | } | ||
259 | } | 562 | } |
563 | |||
564 | m_lastIsBreak = (ch == 10); | ||
565 | |||
260 | return ch; | 566 | return ch; |
261 | } | 567 | } |
262 | 568 | ||
263 | void CPlucker::getch(int& ch, CStyle& sty) | 569 | void CPlucker::getch(int& ch, CStyle& sty) |
@@ -275,12 +581,12 @@ unsigned int CPlucker::locate() | |||
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 | } |
@@ -292,119 +598,301 @@ void CPlucker::locate(unsigned int n) | |||
292 | unsigned long bs = 0; | 598 | unsigned long bs = 0; |
293 | CPlucker_dataRecord thisHdr; | 599 | CPlucker_dataRecord thisHdr; |
294 | do | 600 | do |
295 | { | 601 | { |
296 | thisrec++; | 602 | thisrec++; |
297 | locpos += bs; | 603 | locpos += bs; |
298 | gotorecordnumber(thisrec); | 604 | gotorecordnumber(thisrec); |
299 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | 605 | fread(&thisHdr, 1, sizeof(thisHdr), fin); |
300 | if (thisHdr.type < 2) | 606 | if (thisHdr.type < 2) |
301 | { | 607 | { |
302 | bs = htons(thisHdr.size); | 608 | bs = ntohs(thisHdr.size); |
303 | } | 609 | } |
304 | else | 610 | else |
305 | { | 611 | { |
306 | bs = 0; | 612 | bs = 0; |
307 | } | 613 | } |
308 | } while (locpos + bs < n); | 614 | } while (locpos + bs <= n); |
309 | currentpos = locpos; | 615 | currentpos = locpos; |
310 | expand(thisrec); | 616 | expand(thisrec); |
617 | #ifdef _FAST | ||
311 | while (currentpos < n && bufferpos < buffercontent) bgetch(); | 618 | while (currentpos < n && bufferpos < buffercontent) bgetch(); |
619 | #else | ||
620 | while (currentpos < n && bufferpos < buffercontent) getch(); | ||
621 | #endif | ||
312 | } | 622 | } |
313 | 623 | ||
314 | bool CPlucker::hyperlink(unsigned int n) | 624 | bool CPlucker::hyperlink(unsigned int n) |
315 | { | 625 | { |
626 | visited.push_front(n); | ||
316 | UInt16 tuid = (n >> 16); | 627 | UInt16 tuid = (n >> 16); |
317 | n &= 0xffff; | 628 | n &= 0xffff; |
629 | // qDebug("Hyper:<%u,%u>", tuid, n); | ||
318 | UInt16 thisrec = 1; | 630 | UInt16 thisrec = 1; |
319 | currentpos = 0; | 631 | currentpos = 0; |
320 | gotorecordnumber(thisrec); | 632 | gotorecordnumber(thisrec); |
321 | CPlucker_dataRecord thisHdr; | 633 | CPlucker_dataRecord thisHdr; |
322 | while (1) | 634 | while (1) |
323 | { | 635 | { |
324 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | 636 | fread(&thisHdr, 1, sizeof(thisHdr), fin); |
325 | if (tuid <= htons(thisHdr.uid)) break; | 637 | if (tuid == ntohs(thisHdr.uid)) break; |
326 | if (thisHdr.type < 2) currentpos += htons(thisHdr.size); | 638 | if (thisHdr.type < 2) currentpos += ntohs(thisHdr.size); |
327 | // qDebug("hyper-cp:%u", currentpos); | 639 | //qDebug("hyper-cp:%u", currentpos); |
328 | thisrec++; | 640 | thisrec++; |
329 | gotorecordnumber(thisrec); | 641 | if (thisrec >= ntohs(head.recordList.numRecords)) |
642 | { | ||
643 | if (urls == NULL) | ||
644 | { | ||
645 | QMessageBox::information(NULL, | ||
646 | PROGNAME, | ||
647 | QString("No external links\nin this pluck") | ||
648 | ); | ||
649 | } | ||
650 | else | ||
651 | { | ||
652 | char *turl = geturl(tuid); | ||
653 | if (turl == NULL) | ||
654 | { | ||
655 | QMessageBox::information(NULL, | ||
656 | PROGNAME, | ||
657 | QString("Couldn't find link") | ||
658 | ); | ||
659 | } | ||
660 | else | ||
661 | { | ||
662 | QString wrd(turl); | ||
663 | QClipboard* cb = QApplication::clipboard(); | ||
664 | cb->setText(wrd); | ||
665 | if (wrd.length() > 10) | ||
666 | { | ||
667 | Global::statusMessage(wrd.left(8) + ".."); | ||
668 | } | ||
669 | } | ||
670 | } | ||
671 | return false; | ||
672 | } | ||
673 | gotorecordnumber(thisrec); | ||
330 | } | 674 | } |
331 | if (thisHdr.type > 1) | 675 | if (thisHdr.type > 1) |
332 | { | 676 | { |
333 | QMessageBox::information(NULL, | 677 | if (thisHdr.type == 4) |
334 | QString("OpieReader"), | 678 | { |
335 | QString("External links\nnot yet supported") | 679 | QMessageBox::information(NULL, |
336 | ); | 680 | PROGNAME, |
337 | return false; | 681 | QString("Mailto links\nnot yet supported (2)")); |
682 | } | ||
683 | else | ||
684 | { | ||
685 | #ifdef LOCALPICTURES | ||
686 | if (thisHdr.type > 3) | ||
687 | { | ||
688 | #endif | ||
689 | QMessageBox::information(NULL, | ||
690 | PROGNAME, | ||
691 | QString("External links\nnot yet supported (2)") | ||
692 | ); | ||
693 | #ifdef LOCALPICTURES | ||
694 | } | ||
695 | else | ||
696 | { | ||
697 | showimg(tuid); | ||
698 | } | ||
699 | #endif | ||
700 | } | ||
701 | return false; | ||
702 | } | ||
703 | /* | ||
704 | if (thisHdr.type == 2 || thisHdr.type == 3) | ||
705 | { | ||
706 | expandimg(thisrec); | ||
707 | |||
338 | } | 708 | } |
709 | */ | ||
339 | else | 710 | else |
340 | { | 711 | { |
341 | expand(thisrec); | 712 | expand(thisrec); |
342 | while (bufferpos < n && bufferpos < buffercontent) getch(); | 713 | if (n != 0) |
714 | { | ||
715 | if (n >= m_nParas) | ||
716 | { | ||
717 | QMessageBox::information(NULL, | ||
718 | PROGNAME, | ||
719 | QString("Error in link\nPara # too big") | ||
720 | ); | ||
721 | return false; | ||
722 | } | ||
723 | unsigned int noff = 0; | ||
724 | for (int i = 0; i < n; i++) noff += m_ParaOffsets[i]; | ||
725 | n = noff; | ||
726 | } | ||
727 | if (n > ntohs(thisHdr.size)) | ||
728 | { | ||
729 | QMessageBox::information(NULL, | ||
730 | PROGNAME, | ||
731 | QString("Error in link\nOffset too big") | ||
732 | ); | ||
733 | return false; | ||
734 | } | ||
735 | qDebug("Hyper:<%u,%u>", tuid, n); | ||
736 | while (bufferpos < n && bufferpos < buffercontent) getch(); | ||
343 | } | 737 | } |
344 | return true; | 738 | return true; |
345 | } | 739 | } |
740 | /* | ||
741 | bool CPlucker::hyperlink(unsigned int n) | ||
742 | { | ||
743 | visited.push_front(n); | ||
744 | UInt16 tuid = (n >> 16); | ||
745 | n &= 0xffff; | ||
746 | // qDebug("Hyper:<%u,%u>", tuid, n); | ||
747 | UInt16 thisrec = finduid(tuid); | ||
748 | if (thisrec == 0) | ||
749 | { | ||
750 | if (urls == NULL) | ||
751 | { | ||
752 | QMessageBox::information(NULL, | ||
753 | PROGNAME, | ||
754 | QString("No external links\nin this pluck") | ||
755 | ); | ||
756 | } | ||
757 | else | ||
758 | { | ||
759 | char *turl = geturl(tuid); | ||
760 | if (turl == NULL) | ||
761 | { | ||
762 | QMessageBox::information(NULL, | ||
763 | PROGNAME, | ||
764 | QString("Couldn't find link") | ||
765 | ); | ||
766 | } | ||
767 | else | ||
768 | { | ||
769 | QString wrd(turl); | ||
770 | QClipboard* cb = QApplication::clipboard(); | ||
771 | cb->setText(wrd); | ||
772 | if (wrd.length() > 10) | ||
773 | { | ||
774 | Global::statusMessage(wrd.left(8) + ".."); | ||
775 | } | ||
776 | } | ||
777 | } | ||
778 | return false; | ||
779 | } | ||
780 | else | ||
781 | { | ||
782 | currentpos = 0; | ||
783 | gotorecordnumber(thisrec); | ||
784 | CPlucker_dataRecord thisHdr; | ||
785 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
346 | 786 | ||
787 | if (thisHdr.type > 1) | ||
788 | { | ||
789 | if (thisHdr.type == 4) | ||
790 | { | ||
791 | QMessageBox::information(NULL, | ||
792 | PROGNAME, | ||
793 | QString("Mailto links\nnot yet supported (2)")); | ||
794 | } | ||
795 | else | ||
796 | { | ||
797 | #ifdef LOCALPICTURES | ||
798 | if (thisHdr.type > 3) | ||
799 | { | ||
800 | #endif | ||
801 | QMessageBox::information(NULL, | ||
802 | PROGNAME, | ||
803 | QString("External links\nnot yet supported (2)") | ||
804 | ); | ||
805 | #ifdef LOCALPICTURES | ||
806 | } | ||
807 | else | ||
808 | { | ||
809 | showimg(tuid); | ||
810 | } | ||
811 | #endif | ||
812 | } | ||
813 | return false; | ||
814 | } | ||
815 | // if (thisHdr.type == 2 || thisHdr.type == 3) | ||
816 | // { | ||
817 | // expandimg(thisrec); | ||
818 | // } | ||
819 | else | ||
820 | { | ||
821 | expand(thisrec); | ||
822 | if (n != 0) | ||
823 | { | ||
824 | if (n >= m_nParas) | ||
825 | { | ||
826 | QMessageBox::information(NULL, | ||
827 | PROGNAME, | ||
828 | QString("Error in link\nPara # too big") | ||
829 | ); | ||
830 | return false; | ||
831 | } | ||
832 | unsigned int noff = 0; | ||
833 | for (int i = 0; i < n; i++) noff += m_ParaOffsets[i]; | ||
834 | n = noff; | ||
835 | } | ||
836 | if (n > ntohs(thisHdr.size)) | ||
837 | { | ||
838 | QMessageBox::information(NULL, | ||
839 | PROGNAME, | ||
840 | QString("Error in link\nOffset too big") | ||
841 | ); | ||
842 | return false; | ||
843 | } | ||
844 | qDebug("Hyper:<%u,%u>", tuid, n); | ||
845 | while (bufferpos < n && bufferpos < buffercontent) getch(); | ||
846 | } | ||
847 | return true; | ||
848 | } | ||
849 | } | ||
850 | */ | ||
347 | bool CPlucker::expand(int thisrec) | 851 | bool CPlucker::expand(int thisrec) |
348 | { | 852 | { |
349 | mystyle.unset(); | 853 | mystyle.unset(); |
350 | size_t reclen = recordlength(thisrec); | 854 | size_t reclen = recordlength(thisrec); |
351 | gotorecordnumber(thisrec); | 855 | gotorecordnumber(thisrec); |
352 | CPlucker_dataRecord thisHdr; | 856 | CPlucker_dataRecord thisHdr; |
353 | while (1) | 857 | while (1) |
354 | { | 858 | { |
355 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | 859 | fread(&thisHdr, 1, sizeof(thisHdr), fin); |
356 | // qDebug("This (%d) type is %d, uid is %u", thisrec, thisHdr.type, ntohs(thisHdr.uid)); | 860 | //qDebug("This (%d) type is %d, uid is %u", thisrec, thisHdr.type, ntohs(thisHdr.uid)); |
357 | if (thisHdr.type < 2) break; | 861 | if (thisHdr.type < 2) break; |
358 | qDebug("Skipping paragraph of type %d", thisHdr.type); | 862 | qDebug("Skipping paragraph of type %d", thisHdr.type); |
359 | if (++thisrec >= ntohs(head.recordList.numRecords) - 1) return false; | 863 | if (++thisrec >= ntohs(head.recordList.numRecords) - 1) return false; |
360 | reclen = recordlength(thisrec); | 864 | reclen = recordlength(thisrec); |
361 | gotorecordnumber(thisrec); | 865 | gotorecordnumber(thisrec); |
362 | } | 866 | } |
363 | m_nParas = ntohs(thisHdr.nParagraphs); | 867 | m_nParas = ntohs(thisHdr.nParagraphs); |
364 | // qDebug("It has %u paragraphs and is %u bytes", htons(thisHdr.nParagraphs), htons(thisHdr.size)); | 868 | //qDebug("It has %u paragraphs and is %u bytes", ntohs(thisHdr.nParagraphs), ntohs(thisHdr.size)); |
365 | uid = ntohs(thisHdr.uid); | 869 | uid = ntohs(thisHdr.uid); |
366 | for (int i = 0; i < m_nParas; i++) | 870 | for (int i = 0; i < m_nParas; i++) |
367 | { | 871 | { |
368 | UInt16 ubytes, attrs; | 872 | UInt16 ubytes, attrs; |
369 | fread(&ubytes, 1, sizeof(ubytes), fin); | 873 | fread(&ubytes, 1, sizeof(ubytes), fin); |
370 | fread(&attrs, 1, sizeof(attrs), fin); | 874 | fread(&attrs, 1, sizeof(attrs), fin); |
371 | m_ParaOffsets[i] = ntohs(ubytes); | 875 | m_ParaOffsets[i] = ntohs(ubytes); |
372 | m_ParaAttrs[i] = ntohs(attrs); | 876 | m_ParaAttrs[i] = ntohs(attrs); |
373 | // qDebug("Bytes %u, Attr %x", ntohs(ubytes), attrs); | 877 | //qDebug("Bytes %u, Attr %x", ntohs(ubytes), attrs); |
374 | } | 878 | } |
375 | if (m_nParas > 0) | 879 | if (m_nParas > 0) |
376 | { | 880 | { |
377 | m_nextPara = m_ParaOffsets[0]; | 881 | m_nextPara = m_ParaOffsets[0]; |
378 | // qDebug("First offset = %u", m_nextPara); | 882 | //qDebug("First offset = %u", m_nextPara); |
379 | m_nextParaIndex = 0; | 883 | m_nextParaIndex = 0; |
380 | } | 884 | } |
381 | else | 885 | else |
382 | { | 886 | { |
383 | m_nextPara = -1; | 887 | m_nextPara = -1; |
384 | } | 888 | } |
385 | 889 | ||
386 | reclen -= sizeof(thisHdr)+4*m_nParas; | 890 | reclen -= sizeof(thisHdr)+4*m_nParas; |
387 | 891 | ||
388 | buffercontent = htons(thisHdr.size); | 892 | buffercontent = ntohs(thisHdr.size); |
389 | 893 | ||
390 | if (thisHdr.type == 0) | 894 | Expand(reclen, thisHdr.type, expandedtextbuffer, buffercontent); |
391 | { | ||
392 | fread(expandedtextbuffer, reclen, sizeof(char), fin); | ||
393 | } | ||
394 | else | ||
395 | { | ||
396 | fread(compressedtextbuffer, reclen, sizeof(char), fin); | ||
397 | switch (ntohs(hdr0.version)) | ||
398 | { | ||
399 | case 2: | ||
400 | UnZip(reclen, expandedtextbuffer, buffercontent); | ||
401 | break; | ||
402 | case 1: | ||
403 | UnDoc(reclen, expandedtextbuffer, buffercontent); | ||
404 | break; | ||
405 | } | ||
406 | } | ||
407 | bufferpos = 0; | 895 | bufferpos = 0; |
408 | bufferrec = thisrec; | 896 | bufferrec = thisrec; |
409 | // qDebug("BC:%u, HS:%u", buffercontent, ntohs(thisHdr.size)); | 897 | // qDebug("BC:%u, HS:%u", buffercontent, ntohs(thisHdr.size)); |
410 | return true; | 898 | return true; |
@@ -439,8 +927,10 @@ void CPlucker::UnZip(size_t reclen, UInt8* tgtbuffer, UInt16 bsize) | |||
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 | } |
@@ -510,70 +1000,242 @@ CList<Bkmk>* CPlucker::getbkmklist() | |||
510 | CPlucker_dataRecord thisHdr; | 1000 | CPlucker_dataRecord thisHdr; |
511 | 1001 | ||
512 | for (int i = 1; i < ntohs(head.recordList.numRecords); i++) | 1002 | for (int i = 1; i < ntohs(head.recordList.numRecords); i++) |
513 | { | 1003 | { |
514 | gotorecordnumber(i); | 1004 | gotorecordnumber(i); |
515 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | 1005 | fread(&thisHdr, 1, sizeof(thisHdr), fin); |
516 | if (thisHdr.type == 8) | 1006 | if (thisHdr.type == 8) |
517 | { | 1007 | { |
518 | UInt16 n; | 1008 | UInt16 n; |
519 | fread(&n, 1, sizeof(n), fin); | 1009 | fread(&n, 1, sizeof(n), fin); |
520 | n = ntohs(n); | 1010 | n = ntohs(n); |
521 | qDebug("Found %u bookmarks", n); | 1011 | qDebug("Found %u bookmarks", n); |
522 | } | 1012 | } |
523 | qDebug("Found:%d, %u", i , thisHdr.type); | 1013 | qDebug("Found:%d, %u", i , thisHdr.type); |
524 | } | 1014 | } |
525 | */ | 1015 | */ |
526 | return NULL; | 1016 | return NULL; |
527 | } | 1017 | } |
528 | 1018 | ||
529 | void CPlucker::expandimg(UInt16 tgt) | 1019 | QImage* CPlucker::getimg(UInt16 tgt) |
530 | { | 1020 | { |
531 | qDebug("Image:%u", tgt); | 1021 | // static int imageno; |
1022 | // char* file = "tmp1"; | ||
1023 | // sprintf(file, "image%04u.tbmp", imageno++); | ||
1024 | // qDebug("Image:%u", tgt); | ||
532 | CPlucker_dataRecord thisHdr; | 1025 | CPlucker_dataRecord thisHdr; |
533 | size_t reclen; | 1026 | size_t reclen; |
1027 | UInt16 thisrec = finduid(tgt); | ||
1028 | reclen = recordlength(thisrec); | ||
1029 | gotorecordnumber(thisrec); | ||
1030 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
1031 | /* | ||
534 | UInt16 thisrec = 0; | 1032 | UInt16 thisrec = 0; |
535 | do | 1033 | do |
536 | { | 1034 | { |
537 | thisrec++; | 1035 | hthisrec++; |
538 | reclen = recordlength(thisrec); | 1036 | reclen = recordlength(thisrec); |
539 | gotorecordnumber(thisrec); | 1037 | gotorecordnumber(thisrec); |
540 | qDebug("thisrec:%u.%u", ftell(fin),thisrec); | 1038 | //qDebug("thisrec:%u.%u", ftell(fin),thisrec); |
541 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | 1039 | fread(&thisHdr, 1, sizeof(thisHdr), fin); |
542 | } | 1040 | } |
543 | while (ntohs(thisHdr.uid) != tgt); | 1041 | while (ntohs(thisHdr.uid) != tgt); |
544 | 1042 | */ | |
545 | reclen -= sizeof(thisHdr); | 1043 | reclen -= sizeof(thisHdr); |
546 | 1044 | ||
547 | UInt16 imgsize = htons(thisHdr.size); | 1045 | UInt16 imgsize = ntohs(thisHdr.size); |
548 | UInt8* imgbuffer = new UInt8[imgsize]; | 1046 | UInt8* imgbuffer = new UInt8[imgsize]; |
549 | 1047 | ||
550 | qDebug("type:%u", thisHdr.type); | 1048 | // qDebug("type:%u", thisHdr.type); |
1049 | Expand(reclen, thisHdr.type, imgbuffer, imgsize); | ||
551 | 1050 | ||
552 | if (thisHdr.type == 2) | 1051 | QImage* qimage = Palm2QImage(imgbuffer, imgsize); |
1052 | |||
1053 | delete [] imgbuffer; | ||
1054 | |||
1055 | return qimage; | ||
1056 | } | ||
1057 | |||
1058 | #include <qnamespace.h> | ||
1059 | |||
1060 | QPixmap* CPlucker::expandimg(UInt16 tgt, bool border) | ||
1061 | { | ||
1062 | QImage* qimage = getimg(tgt); | ||
1063 | if (qimage == NULL) return NULL; | ||
1064 | QPixmap* image = new QPixmap(0,0); | ||
1065 | QPixmap* ret; | ||
1066 | // qDebug("New image"); | ||
1067 | image->convertFromImage(*qimage); | ||
1068 | delete qimage; | ||
1069 | if (border) | ||
553 | { | 1070 | { |
554 | qDebug("Not compressed:%u.%u", ftell(fin),reclen); | 1071 | ret = new QPixmap(image->width()+4, image->height()+4); |
555 | fread(imgbuffer, reclen, sizeof(char), fin); | 1072 | ret->fill(Qt::red); |
556 | qDebug("Not compressed:%u.%u", ftell(fin),reclen); | 1073 | bitBlt(ret, 2, 2, image, 0, 0, -1, -1);//, Qt::RasterOp::CopyROP); |
1074 | delete image; | ||
557 | } | 1075 | } |
558 | else | 1076 | else |
559 | { | 1077 | { |
560 | qDebug("Compressed"); | 1078 | ret = image; |
561 | fread(compressedtextbuffer, reclen, sizeof(char), fin); | ||
562 | switch (ntohs(hdr0.version)) | ||
563 | { | ||
564 | case 2: | ||
565 | UnZip(reclen, imgbuffer, imgsize); | ||
566 | break; | ||
567 | case 1: | ||
568 | UnDoc(reclen, imgbuffer, imgsize); | ||
569 | break; | ||
570 | } | ||
571 | } | 1079 | } |
572 | FILE* imgfile = fopen("/home/tim/newreader/imagefile.tbmp", "w"); | 1080 | return ret; |
573 | if (imgfile != NULL) | 1081 | } |
1082 | |||
1083 | #ifdef _BUFFERPICS | ||
1084 | #include <qmap.h> | ||
1085 | #endif | ||
1086 | |||
1087 | QPixmap* CPlucker::getPicture(unsigned long tgt) | ||
1088 | { | ||
1089 | #ifdef _BUFFERPICS | ||
1090 | static QMap<unsigned long, QPixmap> pix; | ||
1091 | QMap<unsigned long, QPixmap>::Iterator t = pix.find(tgt); | ||
1092 | if (t == pix.end()) | ||
574 | { | 1093 | { |
575 | fwrite(imgbuffer, 1, imgsize, imgfile); | 1094 | pix[tgt] = *expandimg(tgt); |
576 | fclose(imgfile); | 1095 | return &pix[tgt]; |
577 | } | 1096 | } |
578 | delete [] imgbuffer; | 1097 | else |
1098 | return &(t.data()); | ||
1099 | #else | ||
1100 | return expandimg(tgt); | ||
1101 | #endif | ||
1102 | } | ||
1103 | |||
1104 | #ifdef LOCALPICTURES | ||
1105 | #include <unistd.h> | ||
1106 | #include <qpe/global.h> | ||
1107 | void CPlucker::showimg(UInt16 tgt) | ||
1108 | { | ||
1109 | qDebug("Crassssssh!"); | ||
1110 | QPixmap* qimage = expandimg(tgt); | ||
1111 | m_picture->setFixedSize(qimage->size()); | ||
1112 | m_picture->setBackgroundPixmap(*qimage); | ||
1113 | delete qimage; | ||
1114 | m_viewer->show(); | ||
1115 | |||
1116 | /* | ||
1117 | char tmp[] = "uqtreader.XXXXXX"; | ||
1118 | QImage* qimage = getimg(tgt); | ||
1119 | QPixmap* image = new QPixmap(0,0); | ||
1120 | // qDebug("New image"); | ||
1121 | image->convertFromImage(*qimage); | ||
1122 | delete qimage; | ||
1123 | char tmpfile[sizeof(tmp)+1]; | ||
1124 | strcpy(tmpfile,tmp); | ||
1125 | int f = mkstemp(tmpfile); | ||
1126 | close(f); | ||
1127 | qDebug("TMPFILE:%s", tmpfile); | ||
1128 | if (image->save(tmpfile,"PNG")) | ||
1129 | { | ||
1130 | QCopEnvelope e("QPE/Application/showimg", "setDocument(QString)"); | ||
1131 | e << QString(tmpfile); | ||
1132 | } | ||
1133 | Global::statusMessage("Opening image"); | ||
1134 | sleep(5); | ||
1135 | delete image; | ||
1136 | unlink(tmpfile); | ||
1137 | */ | ||
1138 | } | ||
1139 | |||
1140 | #endif | ||
1141 | |||
1142 | void CPlucker::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) | ||
1143 | { | ||
1144 | unsigned short sz = 0; | ||
1145 | for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) | ||
1146 | { | ||
1147 | sz++; | ||
1148 | } | ||
1149 | size_t newlen = srclen+sizeof(sz)+sz*sizeof(unsigned long); | ||
1150 | unsigned char* newdata = new unsigned char[newlen]; | ||
1151 | unsigned char* pdata = newdata; | ||
1152 | memcpy(newdata, src, srclen); | ||
1153 | newdata += srclen; | ||
1154 | memcpy(newdata, &sz, sizeof(sz)); | ||
1155 | newdata += sizeof(sz); | ||
1156 | for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) | ||
1157 | { | ||
1158 | unsigned long t = *it; | ||
1159 | qDebug("[%u]", t); | ||
1160 | memcpy(newdata, &t, sizeof(t)); | ||
1161 | newdata += sizeof(t); | ||
1162 | } | ||
1163 | m_nav.setSaveData(data, len, pdata, newlen); | ||
1164 | delete [] pdata; | ||
1165 | } | ||
1166 | |||
1167 | void CPlucker::putSaveData(unsigned char*& src, unsigned short& srclen) | ||
1168 | { | ||
1169 | unsigned short sz; | ||
1170 | if (srclen >= sizeof(sz)) | ||
1171 | { | ||
1172 | memcpy(&sz, src, sizeof(sz)); | ||
1173 | src += sizeof(sz); | ||
1174 | srclen -= sizeof(sz); | ||
1175 | } | ||
1176 | for (int i = 0; i < sz; i++) | ||
1177 | { | ||
1178 | unsigned long t; | ||
1179 | if (srclen >= sizeof(t)) | ||
1180 | { | ||
1181 | memcpy(&t, src, sizeof(t)); | ||
1182 | qDebug("[%u]", t); | ||
1183 | visited.push_front(t); | ||
1184 | src += sizeof(t); | ||
1185 | srclen -= sizeof(t); | ||
1186 | } | ||
1187 | else | ||
1188 | { | ||
1189 | QMessageBox::warning(NULL, PROGNAME, "File data mismatch\nMight fix itself"); | ||
1190 | break; | ||
1191 | } | ||
1192 | } | ||
1193 | m_nav.putSaveData(src, srclen); | ||
1194 | } | ||
1195 | |||
1196 | unsigned short CPlucker::finduid(unsigned short urlid) | ||
1197 | { | ||
1198 | // qDebug("Finding %u", urlid); | ||
1199 | unsigned short jmin = 1, jmax = ntohs(head.recordList.numRecords); | ||
1200 | unsigned short jmid = (jmin+jmax) >> 1; | ||
1201 | while (jmax - jmin > 1) | ||
1202 | { | ||
1203 | CPlucker_dataRecord thisHdr; | ||
1204 | gotorecordnumber(jmid); | ||
1205 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
1206 | unsigned short luid = ntohs(thisHdr.uid); | ||
1207 | //qDebug("%u %u %u : %u", jmin, jmid, jmax, urlid); | ||
1208 | if (luid == urlid) | ||
1209 | { | ||
1210 | return jmid; | ||
1211 | } | ||
1212 | if (luid < urlid) | ||
1213 | { | ||
1214 | jmin = jmid; | ||
1215 | } | ||
1216 | else | ||
1217 | { | ||
1218 | jmax = jmid; | ||
1219 | } | ||
1220 | jmid = (jmin+jmax) >> 1; | ||
1221 | } | ||
1222 | CPlucker_dataRecord thisHdr; | ||
1223 | gotorecordnumber(jmin); | ||
1224 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
1225 | unsigned short luid = ntohs(thisHdr.uid); | ||
1226 | qDebug("jmin at end:%u,%u", jmin, luid); | ||
1227 | if (luid == urlid) | ||
1228 | { | ||
1229 | return jmin; | ||
1230 | } | ||
1231 | gotorecordnumber(jmax); | ||
1232 | fread(&thisHdr, 1, sizeof(thisHdr), fin); | ||
1233 | luid = ntohs(thisHdr.uid); | ||
1234 | qDebug("jmax at end:%u,%u", jmax, luid); | ||
1235 | if (luid == urlid) | ||
1236 | { | ||
1237 | return jmax; | ||
1238 | } | ||
1239 | qDebug("Couldn't find %u", urlid); | ||
1240 | return 0; // Not found! | ||
579 | } | 1241 | } |
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 | |||
@@ -5,8 +5,15 @@ | |||
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 | ||
13 | class QScrollView; | ||
14 | class QWidget; | ||
15 | #endif | ||
9 | 16 | ||
10 | struct CPlucker_dataRecord | 17 | struct CPlucker_dataRecord |
11 | { | 18 | { |
12 | UInt16 uid; | 19 | UInt16 uid; |
@@ -28,15 +35,24 @@ struct CPluckerbkmk | |||
28 | UInt32 offset; | 35 | UInt32 offset; |
29 | tchar title[MAX_BMRK_LENGTH]; | 36 | tchar title[MAX_BMRK_LENGTH]; |
30 | }; | 37 | }; |
31 | 38 | ||
32 | |||
33 | const UInt32 CPLUCKER_ID = 0x5458547a; | 39 | const UInt32 CPLUCKER_ID = 0x5458547a; |
34 | 40 | ||
35 | class CPlucker : public CExpander, Cpdb | 41 | class 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; |
@@ -45,42 +61,63 @@ class CPlucker : public CExpander, Cpdb | |||
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 | |||
@@ -34,9 +34,9 @@ ppm_expander::~ppm_expander() { | |||
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 | ||
38 | int ppm_expander::openfile(const char* infile) | 38 | int 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(); |
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 | |||
@@ -24,17 +24,25 @@ class ppm_expander : public CExpander { | |||
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: | 28 | public: |
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; } |
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 | |||
@@ -62,8 +62,20 @@ inline QString toQString(tchar *_p, unsigned int len) | |||
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 | |||
67 | inline 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 | ||
68 | inline size_t ustrlen(const tchar* _p) { return strlen(_p); } | 80 | inline size_t ustrlen(const tchar* _p) { return strlen(_p); } |
69 | inline int ustrcmp(const tchar* _p1, const tchar* _p2) { return strcmp(_p1, _p2); } | 81 | inline int ustrcmp(const tchar* _p1, const tchar* _p2) { return strcmp(_p1, _p2); } |
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 | |||
@@ -6,9 +6,9 @@ | |||
6 | 6 | ||
7 | ztxt::ztxt() : bInit(false), expandedtextbuffer(NULL), compressedtextbuffer(NULL) { /*printf("constructing:%x\n",fin);*/ } | 7 | ztxt::ztxt() : bInit(false), expandedtextbuffer(NULL), compressedtextbuffer(NULL) { /*printf("constructing:%x\n",fin);*/ } |
8 | 8 | ||
9 | 9 | ||
10 | int ztxt::openfile(const char *src) | 10 | int 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; |
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 | |||
@@ -73,33 +73,41 @@ class ztxt : public CExpander, Cpdb | |||
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: | 77 | public: |
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 |