summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/Bkmks.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/Bkmks.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-reader/Bkmks.cpp105
1 files changed, 92 insertions, 13 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
@@ -2,13 +2,15 @@
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}
@@ -20,7 +22,19 @@ Bkmk::Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short annolen,
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;
@@ -30,6 +44,8 @@ Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_
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)
@@ -56,6 +72,9 @@ void Bkmk::init(const void* _nm, unsigned short _nmlen, const void* _anno, unsig
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()
@@ -95,12 +114,17 @@ Bkmk& Bkmk::operator=(const Bkmk& rhs)
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)
@@ -146,9 +170,9 @@ void Bkmk::setAnno(tchar* t)
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 {
@@ -174,6 +198,14 @@ void BkmkFile::write(const Bkmk& b)
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
@@ -214,18 +246,23 @@ CList<Bkmk>* BkmkFile::readall()
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 }
@@ -234,12 +271,12 @@ CList<Bkmk>* BkmkFile::readall()
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;
@@ -247,7 +284,7 @@ CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(FILE*))
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)
@@ -271,7 +308,7 @@ Bkmk* BkmkFile::read03(FILE* f)
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)
@@ -294,7 +331,35 @@ Bkmk* BkmkFile::read05(FILE* f)
294 return b; 331 return b;
295} 332}
296 333
297Bkmk* BkmkFile::read06(FILE* f) 334Bkmk* BkmkFile::read06(BkmkFile* /*_this*/, FILE* f)
335{
336 Bkmk* b = NULL;
337 if (f != NULL)
338 {
339 unsigned short ln;
340 if (fread(&ln,sizeof(ln),1,f) == 1)
341 {
342 b = new Bkmk;
343 b->m_namelen = ln;
344 b->m_name = new unsigned char[b->m_namelen];
345 fread(b->m_name,1,b->m_namelen,f);
346
347 fread(&(b->m_annolen),sizeof(b->m_annolen),1,f);
348 if (b->m_annolen > 0)
349 {
350 b->m_anno = new unsigned char[b->m_annolen];
351 fread(b->m_anno,1,b->m_annolen,f);
352 }
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;
357 }
358 }
359 return b;
360}
361
362Bkmk* BkmkFile::read07(BkmkFile* _this, FILE* f)
298{ 363{
299 Bkmk* b = NULL; 364 Bkmk* b = NULL;
300 if (f != NULL) 365 if (f != NULL)
@@ -314,6 +379,20 @@ Bkmk* BkmkFile::read06(FILE* f)
314 fread(b->m_anno,1,b->m_annolen,f); 379 fread(b->m_anno,1,b->m_annolen,f);
315 } 380 }
316 fread(&(b->m_position),sizeof(b->m_position),1,f); 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 }
317 } 396 }
318 } 397 }
319 return b; 398 return b;