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
@@ -4,2 +4,4 @@
4 4
5#include "StyleConsts.h"
6#include "Markups.h"
5#include "my_list.h" 7#include "my_list.h"
@@ -10,3 +12,3 @@ const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned lo
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{
@@ -22,3 +24,15 @@ Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_
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)
@@ -32,2 +46,4 @@ Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_
32 } 46 }
47 m_position2 = _p2;
48 m_red = m_green = m_blue = 127;
33} 49}
@@ -58,2 +74,5 @@ void Bkmk::init(const void* _nm, unsigned short _nmlen, const void* _anno, unsig
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}
@@ -97,2 +116,7 @@ Bkmk& Bkmk::operator=(const Bkmk& rhs)
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;
@@ -102,3 +126,3 @@ bool 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}
@@ -148,5 +172,5 @@ void Bkmk::setAnno(tchar* t)
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{
@@ -176,2 +200,10 @@ void BkmkFile::write(const Bkmk& b)
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 }
@@ -216,6 +248,11 @@ CList<Bkmk>* BkmkFile::readall()
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;
@@ -224,6 +261,6 @@ CList<Bkmk>* BkmkFile::readall()
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;
@@ -236,3 +273,3 @@ CList<Bkmk>* BkmkFile::readall()
236 273
237CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(FILE*)) 274CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(BkmkFile*, FILE*))
238{ 275{
@@ -241,3 +278,3 @@ CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(FILE*))
241 { 278 {
242 Bkmk* b = (*readfn)(f); 279 Bkmk* b = (*readfn)(this, f);
243 if (b == NULL) break; 280 if (b == NULL) break;
@@ -249,3 +286,3 @@ CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(FILE*))
249 286
250Bkmk* BkmkFile::read03(FILE* f) 287Bkmk* BkmkFile::read03(BkmkFile* /*_this*/, FILE* f)
251{ 288{
@@ -273,3 +310,3 @@ Bkmk* BkmkFile::read03(FILE* f)
273 310
274Bkmk* BkmkFile::read05(FILE* f) 311Bkmk* BkmkFile::read05(BkmkFile* /*_this*/, FILE* f)
275{ 312{
@@ -296,3 +333,3 @@ Bkmk* BkmkFile::read05(FILE* f)
296 333
297Bkmk* BkmkFile::read06(FILE* f) 334Bkmk* BkmkFile::read06(BkmkFile* /*_this*/, FILE* f)
298{ 335{
@@ -316,2 +353,5 @@ Bkmk* BkmkFile::read06(FILE* f)
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 }
@@ -320 +360,40 @@ Bkmk* BkmkFile::read06(FILE* f)
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}