author | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
---|---|---|
committer | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
commit | 73253e93327cf4ef0932de1b4afb56af22a0f37e (patch) (side-by-side diff) | |
tree | 1c9a7a6dd3341e036a894d348a3372525d29acec /noncore/apps/opie-reader/Bkmks.cpp | |
parent | e90847c784c48bd21bf8768cb38edb853b832697 (diff) | |
download | opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.zip opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.gz opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.bz2 |
updated source to opie-reader 0.7g
Diffstat (limited to 'noncore/apps/opie-reader/Bkmks.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/Bkmks.cpp | 105 |
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 @@ -1,40 +1,56 @@ #include <qmessagebox.h> #include "Bkmks.h" +#include "StyleConsts.h" +#include "Markups.h" #include "my_list.h" #include "version.h" #include "names.h" const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE); -Bkmk::Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p) : m_position(_p) +Bkmk::Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p) { init(_nm, _nmlen, _anno, _annolen, _p); } Bkmk::Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short annolen, unsigned int _p) : m_position(_p) { init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, annolen, _p); } Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p) { + if (_anno == NULL) + { + tchar t = 0; + init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), &t, sizeof(t), _p); + } + else + { + init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, sizeof(tchar)*(ustrlen(_anno)+1), _p); + } +} +Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p, unsigned int _p2) : m_position(_p) +{ if (_anno == NULL) { tchar t = 0; init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), &t, sizeof(t), _p); } else { init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, sizeof(tchar)*(ustrlen(_anno)+1), _p); } + m_position2 = _p2; + m_red = m_green = m_blue = 127; } void Bkmk::init(const void* _nm, unsigned short _nmlen, const void* _anno, unsigned short _annolen, unsigned int _p) { m_namelen = _nmlen; if (m_namelen > 0) { m_name = new unsigned char[m_namelen]; @@ -51,16 +67,19 @@ void Bkmk::init(const void* _nm, unsigned short _nmlen, const void* _anno, unsig m_anno = new unsigned char[m_annolen]; memcpy(m_anno, _anno, m_annolen); } else { m_anno = NULL; } m_position = _p; + m_position2 = _p; + m_red = m_green = m_blue = 255; + m_level = 0; } Bkmk::~Bkmk() { if (m_name != NULL) delete [] m_name; m_name = NULL; if (m_anno != NULL) delete [] m_anno; m_anno = NULL; @@ -90,22 +109,27 @@ Bkmk& Bkmk::operator=(const Bkmk& rhs) { m_annolen = rhs.m_annolen; m_anno = new unsigned char[m_annolen]; memcpy(m_anno, rhs.m_anno, m_annolen); } else m_anno = NULL; m_position = rhs.m_position; + m_position2 = rhs.m_position2; + m_red = rhs.m_red; + m_green = rhs.m_green; + m_blue = rhs.m_blue; + m_level = rhs.m_level; return *this; } bool Bkmk::operator==(const Bkmk& rhs) { - return (m_position == rhs.m_position && (rhs.m_namelen == m_namelen) && memcmp(m_name,rhs.m_name,m_namelen) == 0); + 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); } void Bkmk::setAnno(unsigned char* t, unsigned short len) { if (m_anno != NULL) { delete [] m_anno; m_anno = NULL; @@ -141,19 +165,19 @@ void Bkmk::setAnno(tchar* t) else { m_annolen = sizeof(tchar); m_anno = new unsigned char[m_annolen]; *((tchar*)m_anno) = 0; } } -BkmkFile::BkmkFile(const char *fnm, bool w) +BkmkFile::BkmkFile(const char *fnm, bool w, bool _x) : - wt(w), isUpgraded(false) + wt(w), isUpgraded(false), m_extras(_x) { if (w) { f = fopen(fnm, "wb"); } else { f = fopen(fnm, "rb"); @@ -169,16 +193,24 @@ void BkmkFile::write(const Bkmk& b) { if (f != NULL) { fwrite(&b.m_namelen, sizeof(b.m_namelen),1,f); fwrite(b.m_name,1,b.m_namelen,f); fwrite(&b.m_annolen, sizeof(b.m_annolen),1,f); fwrite(b.m_anno,1,b.m_annolen,f); fwrite(&b.m_position,sizeof(b.m_position),1,f); + if (m_extras) + { + fwrite(&b.m_position2,sizeof(b.m_position2),1,f); + fwrite(&b.m_red,sizeof(b.m_red),1,f); + fwrite(&b.m_green,sizeof(b.m_green),1,f); + fwrite(&b.m_blue,sizeof(b.m_blue),1,f); + fwrite(&b.m_level,sizeof(b.m_level),1,f); + } } } void BkmkFile::write(CList<Bkmk>& bl) { if (f != NULL) { fwrite(&magic, sizeof(magic), 1, f); @@ -209,50 +241,55 @@ CList<Bkmk>* BkmkFile::readall() bl = readall00(&read03); } isUpgraded = true; } else { switch(newmagic & 0xff) { - case 6: + case 7: isUpgraded = false; + bl = readall00(read07); +// qDebug("Correct version!"); + break; + case 6: + isUpgraded = true; bl = readall00(read06); -// odebug << "Correct version!" << oendl; +// qDebug("Correct version!"); break; case 5: isUpgraded = true; bl = readall00(read05); -// odebug << "Known version!" << oendl; +// qDebug("Known version!"); break; default: -// odebug << "Unknown version!" << oendl; +// qDebug("Unknown version!"); isUpgraded = true; bl = readall00(read05); } } } return bl; } -CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(FILE*)) +CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(BkmkFile*, FILE*)) { CList<Bkmk>* bl = new CList<Bkmk>; while (1) { - Bkmk* b = (*readfn)(f); + Bkmk* b = (*readfn)(this, f); if (b == NULL) break; bl->push_back(*b); delete b; } return bl; } -Bkmk* BkmkFile::read03(FILE* f) +Bkmk* BkmkFile::read03(BkmkFile* /*_this*/, FILE* f) { Bkmk* b = NULL; if (f != NULL) { unsigned short ln; if (fread(&ln,sizeof(ln),1,f) == 1) { tchar* name = new tchar[ln+1]; @@ -266,17 +303,17 @@ Bkmk* BkmkFile::read03(FILE* f) unsigned int pos; fread(&pos,sizeof(pos),1,f); b = new Bkmk(name,anno,pos); } } return b; } -Bkmk* BkmkFile::read05(FILE* f) +Bkmk* BkmkFile::read05(BkmkFile* /*_this*/, FILE* f) { Bkmk* b = NULL; if (f != NULL) { unsigned short ln; if (fread(&ln,sizeof(ln),1,f) == 1) { tchar* nm = new tchar[ln+1]; @@ -289,17 +326,45 @@ Bkmk* BkmkFile::read05(FILE* f) unsigned int pos; fread(&pos,sizeof(pos),1,f); b = new Bkmk(nm,anno,pos); } } return b; } -Bkmk* BkmkFile::read06(FILE* f) +Bkmk* BkmkFile::read06(BkmkFile* /*_this*/, FILE* f) +{ + Bkmk* b = NULL; + if (f != NULL) + { + unsigned short ln; + if (fread(&ln,sizeof(ln),1,f) == 1) + { + b = new Bkmk; + b->m_namelen = ln; + b->m_name = new unsigned char[b->m_namelen]; + fread(b->m_name,1,b->m_namelen,f); + + fread(&(b->m_annolen),sizeof(b->m_annolen),1,f); + if (b->m_annolen > 0) + { + b->m_anno = new unsigned char[b->m_annolen]; + fread(b->m_anno,1,b->m_annolen,f); + } + fread(&(b->m_position),sizeof(b->m_position),1,f); + b->m_position2 = b->m_position+b->m_namelen-1; + b->m_red = b->m_green = b->m_blue = 127; + b->m_level = 0; + } + } + return b; +} + +Bkmk* BkmkFile::read07(BkmkFile* _this, FILE* f) { Bkmk* b = NULL; if (f != NULL) { unsigned short ln; if (fread(&ln,sizeof(ln),1,f) == 1) { b = new Bkmk; @@ -309,12 +374,26 @@ Bkmk* BkmkFile::read06(FILE* f) fread(&(b->m_annolen),sizeof(b->m_annolen),1,f); if (b->m_annolen > 0) { b->m_anno = new unsigned char[b->m_annolen]; fread(b->m_anno,1,b->m_annolen,f); } fread(&(b->m_position),sizeof(b->m_position),1,f); + if (_this->m_extras) + { + fread(&(b->m_position2),sizeof(b->m_position2),1,f); + fread(&(b->m_red),sizeof(b->m_red),1,f); + fread(&(b->m_green),sizeof(b->m_green),1,f); + fread(&(b->m_blue),sizeof(b->m_blue),1,f); + fread(&(b->m_level),sizeof(b->m_level),1,f); + } + else + { + b->m_position2 = b->m_position; + b->m_red = b->m_green = b->m_blue = 255; + b->m_level = 0; + } } } return b; } |