author | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
---|---|---|
committer | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
commit | 73253e93327cf4ef0932de1b4afb56af22a0f37e (patch) (unidiff) | |
tree | 1c9a7a6dd3341e036a894d348a3372525d29acec /noncore/apps/opie-reader/Aportis.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/Aportis.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/Aportis.cpp | 109 |
1 files changed, 95 insertions, 14 deletions
diff --git a/noncore/apps/opie-reader/Aportis.cpp b/noncore/apps/opie-reader/Aportis.cpp index 06f44a4..7528e78 100644 --- a/noncore/apps/opie-reader/Aportis.cpp +++ b/noncore/apps/opie-reader/Aportis.cpp | |||
@@ -5,2 +5,3 @@ | |||
5 | #include "Bkmks.h" | 5 | #include "Bkmks.h" |
6 | #include "static.h" | ||
6 | 7 | ||
@@ -30,3 +31,3 @@ CList<Bkmk>* Aportis::getbkmklist() | |||
30 | name[16] = '\0'; | 31 | name[16] = '\0'; |
31 | // odebug << "Record:" << i << ", Length:" << recordlength(i) << "" << oendl; | 32 | // qDebug("Record:%d, Length:%u",i,recordlength(i)); |
32 | gotorecordnumber(i); | 33 | gotorecordnumber(i); |
@@ -37,3 +38,3 @@ CList<Bkmk>* Aportis::getbkmklist() | |||
37 | lcn = SwapLong(lcn); | 38 | lcn = SwapLong(lcn); |
38 | // odebug << "Bookmark:" << name << ":" << lcn << "" << oendl; | 39 | // qDebug("Bookmark:%s:%u", name,lcn); |
39 | tchar tname[17]; | 40 | tchar tname[17]; |
@@ -96,10 +97,11 @@ int Aportis::OpenFile(const char *src) | |||
96 | int ret = 0; | 97 | int ret = 0; |
98 | html = false; | ||
99 | mobiimagerec = 0; | ||
100 | if (!Cpdb::openpdbfile(src)) return -1; | ||
97 | 101 | ||
98 | if (!Cpdb::openfile(src)) return -1; | 102 | if (head.creator == 0x64414552 // 'dAER' |
99 | 103 | || head.type == 0x74584554) // 'tXET') | |
100 | if (head.creator != 0x64414552 // 'dAER' | ||
101 | || head.type != 0x74584554) // 'tXET') | ||
102 | { | 104 | { |
103 | 105 | } | |
104 | if (memcmp(&head.creator, "PPrs", 4) == 0 && memcmp(&head.type, "PNRd", 4) == 0) | 106 | else if (memcmp(&head.creator, "PPrs", 4) == 0 && memcmp(&head.type, "PNRd", 4) == 0) |
105 | { | 107 | { |
@@ -107,2 +109,16 @@ int Aportis::OpenFile(const char *src) | |||
107 | } | 109 | } |
110 | else if (memcmp(&head.creator, "MOBI", 4) == 0 && memcmp(&head.type, "BOOK", 4) == 0) | ||
111 | { | ||
112 | html = true; | ||
113 | unsigned char vsn; | ||
114 | fseek(fin, recordpos(0)+39, SEEK_SET); | ||
115 | fread(&vsn, 1, sizeof(vsn), fin); | ||
116 | qDebug("Mobi version:%x", vsn); | ||
117 | if (vsn > 2) | ||
118 | { | ||
119 | fseek(fin, recordpos(0)+110, SEEK_SET); | ||
120 | fread(&mobiimagerec, 1, sizeof(mobiimagerec), fin); | ||
121 | mobiimagerec = ntohs(mobiimagerec)-1; | ||
122 | } | ||
123 | } | ||
108 | else | 124 | else |
@@ -111,7 +127,11 @@ int Aportis::OpenFile(const char *src) | |||
111 | } | 127 | } |
112 | } | ||
113 | 128 | ||
114 | nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1; | 129 | nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1; |
115 | fseek(fin,0,SEEK_END); | 130 | |
116 | dwLen = ftell(fin); | 131 | struct stat _stat; |
132 | stat(src,&_stat); | ||
133 | dwLen = _stat.st_size; | ||
134 | |||
135 | //fseek(fin,0,SEEK_END); | ||
136 | //dwLen = ftell(fin); | ||
117 | 137 | ||
@@ -123,3 +143,3 @@ int Aportis::OpenFile(const char *src) | |||
123 | fread(&hdr0, sizeof(hdr0), 1, fin); | 143 | fread(&hdr0, sizeof(hdr0), 1, fin); |
124 | // odebug << "Version:" << ntohs(hdr0.Version) << "" << oendl; | 144 | // qDebug("Version:%x", ntohs(hdr0.Version)); |
125 | if (hdr0.Version && 0x0200) | 145 | if (hdr0.Version && 0x0200) |
@@ -143,2 +163,3 @@ int Aportis::OpenFile(const char *src) | |||
143 | if (bCompressed!=1 && bCompressed!=2 && bCompressed != 4) { | 163 | if (bCompressed!=1 && bCompressed!=2 && bCompressed != 4) { |
164 | qDebug("ERROR:Unrecognised compression type in Aportis:%u", bCompressed); | ||
144 | ret = bCompressed; | 165 | ret = bCompressed; |
@@ -166,2 +187,3 @@ int Aportis::OpenFile(const char *src) | |||
166 | nRecs = SwapWord(hdr0.wNumRecs); | 187 | nRecs = SwapWord(hdr0.wNumRecs); |
188 | if (mobiimagerec == 0 || mobiimagerec > nRecs2) mobiimagerec = nRecs; | ||
167 | dwTLen = SwapLong(hdr0.dwStoryLen); | 189 | dwTLen = SwapLong(hdr0.dwStoryLen); |
@@ -176,3 +198,3 @@ int Aportis::OpenFile(const char *src) | |||
176 | 198 | ||
177 | 199 | qDebug("Mobi image rec:%u", mobiimagerec); | |
178 | 200 | ||
@@ -184,3 +206,35 @@ int Aportis::OpenFile(const char *src) | |||
184 | refreshbuffer(); | 206 | refreshbuffer(); |
185 | // odebug << "Number of records:[" << nRecs << "," << nRecs2 << "]" << oendl; | 207 | if (!html) |
208 | { | ||
209 | int c; | ||
210 | char htmltag[] = "<HTML>"; | ||
211 | char *p = htmltag; | ||
212 | while (1) | ||
213 | { | ||
214 | c = getch(); | ||
215 | char ch = *p++; | ||
216 | if (ch == 0) | ||
217 | { | ||
218 | html = true; | ||
219 | break; | ||
220 | } | ||
221 | if (c != ch) | ||
222 | { | ||
223 | html = false; | ||
224 | break; | ||
225 | } | ||
226 | } | ||
227 | currentrec = 0; | ||
228 | cbptr = 0; | ||
229 | outptr = 0; | ||
230 | refreshbuffer(); | ||
231 | } | ||
232 | /* | ||
233 | for (int i = 0; i < nRecs2; i++) | ||
234 | { | ||
235 | qDebug("Record:%u - %u bytes at position %x", i, recordlength(i), recordpos(i)); | ||
236 | } | ||
237 | */ | ||
238 | |||
239 | qDebug("Number of records:[%u,%u]", nRecs, nRecs2); | ||
186 | return ret; | 240 | return ret; |
@@ -374 +428,28 @@ bool Aportis::refreshbuffer() | |||
374 | } | 428 | } |
429 | |||
430 | #include <qimage.h> | ||
431 | |||
432 | QImage* Aportis::getPicture(unsigned long tgt) | ||
433 | { | ||
434 | unsigned short tgtrec = tgt+mobiimagerec; | ||
435 | if (tgtrec > nRecs2) return NULL; | ||
436 | size_t cur = ftell(fin); | ||
437 | unsigned short reclen = recordlength(tgtrec); | ||
438 | gotorecordnumber(tgtrec); | ||
439 | UInt8* imgbuffer = new UInt8[reclen]; | ||
440 | fread(imgbuffer, 1, reclen, fin); | ||
441 | QByteArray arr; | ||
442 | arr.assign((const char*)imgbuffer, reclen); | ||
443 | |||
444 | QImage* qimage = new QImage(arr); | ||
445 | fseek(fin, cur, SEEK_SET); | ||
446 | |||
447 | return qimage; | ||
448 | } | ||
449 | |||
450 | #ifndef __STATIC | ||
451 | extern "C" | ||
452 | { | ||
453 | CExpander* newcodec() { return new Aportis; } | ||
454 | } | ||
455 | #endif | ||