summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/Bkmks.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/Bkmks.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/Bkmks.cpp107
1 files changed, 93 insertions, 14 deletions
diff --git a/noncore/apps/opie-reader/Bkmks.cpp b/noncore/apps/opie-reader/Bkmks.cpp
index 480c240..440d8be 100644
--- a/noncore/apps/opie-reader/Bkmks.cpp
+++ b/noncore/apps/opie-reader/Bkmks.cpp
@@ -1,38 +1,54 @@
1#include <qmessagebox.h> 1#include <qmessagebox.h>
2 2
3#include "Bkmks.h" 3#include "Bkmks.h"
4 4
5#include "StyleConsts.h"
6#include "Markups.h"
5#include "my_list.h" 7#include "my_list.h"
6#include "version.h" 8#include "version.h"
7#include "names.h" 9#include "names.h"
8 10
9const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE); 11const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE);
10 12
11Bkmk::Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p) : m_position(_p) 13Bkmk::Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p)
12{ 14{
13 init(_nm, _nmlen, _anno, _annolen, _p); 15 init(_nm, _nmlen, _anno, _annolen, _p);
14} 16}
15 17
16Bkmk::Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short annolen, unsigned int _p) : m_position(_p) 18Bkmk::Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short annolen, unsigned int _p) : m_position(_p)
17{ 19{
18 init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, annolen, _p); 20 init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, annolen, _p);
19} 21}
20 22
21Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p) 23Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p)
22{ 24{
25 if (_anno == NULL)
26 {
27 tchar t = 0;
28 init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), &t, sizeof(t), _p);
29 }
30 else
31 {
32 init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, sizeof(tchar)*(ustrlen(_anno)+1), _p);
33 }
34}
23 35
36Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p, unsigned int _p2) : m_position(_p)
37{
24 if (_anno == NULL) 38 if (_anno == NULL)
25 { 39 {
26 tchar t = 0; 40 tchar t = 0;
27 init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), &t, sizeof(t), _p); 41 init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), &t, sizeof(t), _p);
28 } 42 }
29 else 43 else
30 { 44 {
31 init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, sizeof(tchar)*(ustrlen(_anno)+1), _p); 45 init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, sizeof(tchar)*(ustrlen(_anno)+1), _p);
32 } 46 }
47 m_position2 = _p2;
48 m_red = m_green = m_blue = 127;
33} 49}
34 50
35void Bkmk::init(const void* _nm, unsigned short _nmlen, const void* _anno, unsigned short _annolen, unsigned int _p) 51void Bkmk::init(const void* _nm, unsigned short _nmlen, const void* _anno, unsigned short _annolen, unsigned int _p)
36{ 52{
37 m_namelen = _nmlen; 53 m_namelen = _nmlen;
38 if (m_namelen > 0) 54 if (m_namelen > 0)
@@ -53,12 +69,15 @@ void Bkmk::init(const void* _nm, unsigned short _nmlen, const void* _anno, unsig
53 } 69 }
54 else 70 else
55 { 71 {
56 m_anno = NULL; 72 m_anno = NULL;
57 } 73 }
58 m_position = _p; 74 m_position = _p;
75 m_position2 = _p;
76 m_red = m_green = m_blue = 255;
77 m_level = 0;
59} 78}
60 79
61Bkmk::~Bkmk() 80Bkmk::~Bkmk()
62{ 81{
63 if (m_name != NULL) delete [] m_name; 82 if (m_name != NULL) delete [] m_name;
64 m_name = NULL; 83 m_name = NULL;
@@ -92,18 +111,23 @@ Bkmk& Bkmk::operator=(const Bkmk& rhs)
92 m_anno = new unsigned char[m_annolen]; 111 m_anno = new unsigned char[m_annolen];
93 memcpy(m_anno, rhs.m_anno, m_annolen); 112 memcpy(m_anno, rhs.m_anno, m_annolen);
94 } 113 }
95 else 114 else
96 m_anno = NULL; 115 m_anno = NULL;
97 m_position = rhs.m_position; 116 m_position = rhs.m_position;
117 m_position2 = rhs.m_position2;
118 m_red = rhs.m_red;
119 m_green = rhs.m_green;
120 m_blue = rhs.m_blue;
121 m_level = rhs.m_level;
98 return *this; 122 return *this;
99} 123}
100 124
101bool Bkmk::operator==(const Bkmk& rhs) 125bool Bkmk::operator==(const Bkmk& rhs)
102{ 126{
103 return (m_position == rhs.m_position && (rhs.m_namelen == m_namelen) && memcmp(m_name,rhs.m_name,m_namelen) == 0); 127 return ((m_position == rhs.m_position) && (m_position2 == rhs.m_position2) && (rhs.m_namelen == m_namelen) && memcmp(m_name,rhs.m_name,m_namelen) == 0);
104} 128}
105 129
106void Bkmk::setAnno(unsigned char* t, unsigned short len) 130void Bkmk::setAnno(unsigned char* t, unsigned short len)
107{ 131{
108 if (m_anno != NULL) 132 if (m_anno != NULL)
109 { 133 {
@@ -143,15 +167,15 @@ void Bkmk::setAnno(tchar* t)
143 m_annolen = sizeof(tchar); 167 m_annolen = sizeof(tchar);
144 m_anno = new unsigned char[m_annolen]; 168 m_anno = new unsigned char[m_annolen];
145 *((tchar*)m_anno) = 0; 169 *((tchar*)m_anno) = 0;
146 } 170 }
147} 171}
148 172
149BkmkFile::BkmkFile(const char *fnm, bool w) 173BkmkFile::BkmkFile(const char *fnm, bool w, bool _x)
150 : 174 :
151 wt(w), isUpgraded(false) 175 wt(w), isUpgraded(false), m_extras(_x)
152{ 176{
153 if (w) 177 if (w)
154 { 178 {
155 f = fopen(fnm, "wb"); 179 f = fopen(fnm, "wb");
156 } 180 }
157 else 181 else
@@ -171,12 +195,20 @@ void BkmkFile::write(const Bkmk& b)
171 { 195 {
172 fwrite(&b.m_namelen, sizeof(b.m_namelen),1,f); 196 fwrite(&b.m_namelen, sizeof(b.m_namelen),1,f);
173 fwrite(b.m_name,1,b.m_namelen,f); 197 fwrite(b.m_name,1,b.m_namelen,f);
174 fwrite(&b.m_annolen, sizeof(b.m_annolen),1,f); 198 fwrite(&b.m_annolen, sizeof(b.m_annolen),1,f);
175 fwrite(b.m_anno,1,b.m_annolen,f); 199 fwrite(b.m_anno,1,b.m_annolen,f);
176 fwrite(&b.m_position,sizeof(b.m_position),1,f); 200 fwrite(&b.m_position,sizeof(b.m_position),1,f);
201 if (m_extras)
202 {
203 fwrite(&b.m_position2,sizeof(b.m_position2),1,f);
204 fwrite(&b.m_red,sizeof(b.m_red),1,f);
205 fwrite(&b.m_green,sizeof(b.m_green),1,f);
206 fwrite(&b.m_blue,sizeof(b.m_blue),1,f);
207 fwrite(&b.m_level,sizeof(b.m_level),1,f);
208 }
177 } 209 }
178} 210}
179 211
180void BkmkFile::write(CList<Bkmk>& bl) 212void BkmkFile::write(CList<Bkmk>& bl)
181{ 213{
182 if (f != NULL) 214 if (f != NULL)
@@ -211,46 +243,51 @@ CList<Bkmk>* BkmkFile::readall()
211 isUpgraded = true; 243 isUpgraded = true;
212 } 244 }
213 else 245 else
214 { 246 {
215 switch(newmagic & 0xff) 247 switch(newmagic & 0xff)
216 { 248 {
217 case 6: 249 case 7:
218 isUpgraded = false; 250 isUpgraded = false;
251 bl = readall00(read07);
252 // qDebug("Correct version!");
253 break;
254 case 6:
255 isUpgraded = true;
219 bl = readall00(read06); 256 bl = readall00(read06);
220 // odebug << "Correct version!" << oendl; 257 // qDebug("Correct version!");
221 break; 258 break;
222 case 5: 259 case 5:
223 isUpgraded = true; 260 isUpgraded = true;
224 bl = readall00(read05); 261 bl = readall00(read05);
225 // odebug << "Known version!" << oendl; 262 // qDebug("Known version!");
226 break; 263 break;
227 default: 264 default:
228 // odebug << "Unknown version!" << oendl; 265 // qDebug("Unknown version!");
229 isUpgraded = true; 266 isUpgraded = true;
230 bl = readall00(read05); 267 bl = readall00(read05);
231 } 268 }
232 } 269 }
233 } 270 }
234 return bl; 271 return bl;
235} 272}
236 273
237CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(FILE*)) 274CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(BkmkFile*, FILE*))
238{ 275{
239 CList<Bkmk>* bl = new CList<Bkmk>; 276 CList<Bkmk>* bl = new CList<Bkmk>;
240 while (1) 277 while (1)
241 { 278 {
242 Bkmk* b = (*readfn)(f); 279 Bkmk* b = (*readfn)(this, f);
243 if (b == NULL) break; 280 if (b == NULL) break;
244 bl->push_back(*b); 281 bl->push_back(*b);
245 delete b; 282 delete b;
246 } 283 }
247 return bl; 284 return bl;
248} 285}
249 286
250Bkmk* BkmkFile::read03(FILE* f) 287Bkmk* BkmkFile::read03(BkmkFile* /*_this*/, FILE* f)
251{ 288{
252 Bkmk* b = NULL; 289 Bkmk* b = NULL;
253 if (f != NULL) 290 if (f != NULL)
254 { 291 {
255 unsigned short ln; 292 unsigned short ln;
256 if (fread(&ln,sizeof(ln),1,f) == 1) 293 if (fread(&ln,sizeof(ln),1,f) == 1)
@@ -268,13 +305,13 @@ Bkmk* BkmkFile::read03(FILE* f)
268 b = new Bkmk(name,anno,pos); 305 b = new Bkmk(name,anno,pos);
269 } 306 }
270 } 307 }
271 return b; 308 return b;
272} 309}
273 310
274Bkmk* BkmkFile::read05(FILE* f) 311Bkmk* BkmkFile::read05(BkmkFile* /*_this*/, FILE* f)
275{ 312{
276 Bkmk* b = NULL; 313 Bkmk* b = NULL;
277 if (f != NULL) 314 if (f != NULL)
278 { 315 {
279 unsigned short ln; 316 unsigned short ln;
280 if (fread(&ln,sizeof(ln),1,f) == 1) 317 if (fread(&ln,sizeof(ln),1,f) == 1)
@@ -291,13 +328,13 @@ Bkmk* BkmkFile::read05(FILE* f)
291 b = new Bkmk(nm,anno,pos); 328 b = new Bkmk(nm,anno,pos);
292 } 329 }
293 } 330 }
294 return b; 331 return b;
295} 332}
296 333
297Bkmk* BkmkFile::read06(FILE* f) 334Bkmk* BkmkFile::read06(BkmkFile* /*_this*/, FILE* f)
298{ 335{
299 Bkmk* b = NULL; 336 Bkmk* b = NULL;
300 if (f != NULL) 337 if (f != NULL)
301 { 338 {
302 unsigned short ln; 339 unsigned short ln;
303 if (fread(&ln,sizeof(ln),1,f) == 1) 340 if (fread(&ln,sizeof(ln),1,f) == 1)
@@ -311,10 +348,52 @@ Bkmk* BkmkFile::read06(FILE* f)
311 if (b->m_annolen > 0) 348 if (b->m_annolen > 0)
312 { 349 {
313 b->m_anno = new unsigned char[b->m_annolen]; 350 b->m_anno = new unsigned char[b->m_annolen];
314 fread(b->m_anno,1,b->m_annolen,f); 351 fread(b->m_anno,1,b->m_annolen,f);
315 } 352 }
316 fread(&(b->m_position),sizeof(b->m_position),1,f); 353 fread(&(b->m_position),sizeof(b->m_position),1,f);
354 b->m_position2 = b->m_position+b->m_namelen-1;
355 b->m_red = b->m_green = b->m_blue = 127;
356 b->m_level = 0;
317 } 357 }
318 } 358 }
319 return b; 359 return b;
320} 360}
361
362Bkmk* BkmkFile::read07(BkmkFile* _this, FILE* f)
363{
364 Bkmk* b = NULL;
365 if (f != NULL)
366 {
367 unsigned short ln;
368 if (fread(&ln,sizeof(ln),1,f) == 1)
369 {
370 b = new Bkmk;
371 b->m_namelen = ln;
372 b->m_name = new unsigned char[b->m_namelen];
373 fread(b->m_name,1,b->m_namelen,f);
374
375 fread(&(b->m_annolen),sizeof(b->m_annolen),1,f);
376 if (b->m_annolen > 0)
377 {
378 b->m_anno = new unsigned char[b->m_annolen];
379 fread(b->m_anno,1,b->m_annolen,f);
380 }
381 fread(&(b->m_position),sizeof(b->m_position),1,f);
382 if (_this->m_extras)
383 {
384 fread(&(b->m_position2),sizeof(b->m_position2),1,f);
385 fread(&(b->m_red),sizeof(b->m_red),1,f);
386 fread(&(b->m_green),sizeof(b->m_green),1,f);
387 fread(&(b->m_blue),sizeof(b->m_blue),1,f);
388 fread(&(b->m_level),sizeof(b->m_level),1,f);
389 }
390 else
391 {
392 b->m_position2 = b->m_position;
393 b->m_red = b->m_green = b->m_blue = 255;
394 b->m_level = 0;
395 }
396 }
397 }
398 return b;
399}