summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/Aportis.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/Aportis.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/Aportis.cpp125
1 files changed, 103 insertions, 22 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
@@ -3,6 +3,7 @@
3#include "Aportis.h" 3#include "Aportis.h"
4#include "my_list.h" 4#include "my_list.h"
5#include "Bkmks.h" 5#include "Bkmks.h"
6#include "static.h"
6 7
7Aportis::Aportis() : peanutfile(false) { /*printf("constructing:%x\n",fin);*/ } 8Aportis::Aportis() : peanutfile(false) { /*printf("constructing:%x\n",fin);*/ }
8 9
@@ -28,14 +29,14 @@ CList<Bkmk>* Aportis::getbkmklist()
28 { 29 {
29 char name[17]; 30 char name[17];
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);
33 fread(name,1,16,fin); 34 fread(name,1,16,fin);
34 unsigned long lcn; 35 unsigned long lcn;
35 fread(&lcn,sizeof(lcn),1,fin); 36 fread(&lcn,sizeof(lcn),1,fin);
36 lcn ^= 0xa5a5a5a5; 37 lcn ^= 0xa5a5a5a5;
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];
40 memset(tname, 0, sizeof(tname)); 41 memset(tname, 0, sizeof(tname));
41 for (int i = 0; name[i] != 0; i++) 42 for (int i = 0; name[i] != 0; i++)
@@ -94,26 +95,45 @@ int Aportis::OpenFile(const char *src)
94{ 95{
95 // printf("In openfile\n"); 96 // printf("In openfile\n");
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 {
106 peanutfile = true; 108 peanutfile = true;
107 } 109 }
108 else 110 else if (memcmp(&head.creator, "MOBI", 4) == 0 && memcmp(&head.type, "BOOK", 4) == 0)
109 { 111 {
110 return -2; 112 html = true;
111 } 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 }
124 else
125 {
126 return -2;
112 } 127 }
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
118 if (peanutfile) 138 if (peanutfile)
119 { 139 {
@@ -121,7 +141,7 @@ int Aportis::OpenFile(const char *src)
121 PeanutHeader hdr0; 141 PeanutHeader hdr0;
122 gotorecordnumber(0); 142 gotorecordnumber(0);
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)
126 { 146 {
127 bCompressed = 2; 147 bCompressed = 2;
@@ -141,7 +161,8 @@ int Aportis::OpenFile(const char *src)
141 fread(&hdr0, sizeof(hdr0), 1, fin); 161 fread(&hdr0, sizeof(hdr0), 1, fin);
142 bCompressed = SwapWord(hdr0.wVersion); 162 bCompressed = SwapWord(hdr0.wVersion);
143 if (bCompressed!=1 && bCompressed!=2 && bCompressed != 4) { 163 if (bCompressed!=1 && bCompressed!=2 && bCompressed != 4) {
144 ret = bCompressed; 164 qDebug("ERROR:Unrecognised compression type in Aportis:%u", bCompressed);
165 ret = bCompressed;
145 bCompressed = 2; 166 bCompressed = 2;
146 } 167 }
147 switch (bCompressed) 168 switch (bCompressed)
@@ -164,6 +185,7 @@ int Aportis::OpenFile(const char *src)
164 case 2: 185 case 2:
165 default: 186 default:
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);
168 BlockSize = SwapWord(hdr0.wRecSize); 190 BlockSize = SwapWord(hdr0.wRecSize);
169 if (BlockSize == 0) 191 if (BlockSize == 0)
@@ -173,8 +195,8 @@ int Aportis::OpenFile(const char *src)
173 } 195 }
174 } 196 }
175 } 197 }
176 198
177 199 qDebug("Mobi image rec:%u", mobiimagerec);
178 200
179 // this is the main record buffer 201 // this is the main record buffer
180 // it knows how to stretch to accomodate the decompress 202 // it knows how to stretch to accomodate the decompress
@@ -182,7 +204,39 @@ int Aportis::OpenFile(const char *src)
182 cbptr = 0; 204 cbptr = 0;
183 outptr = 0; 205 outptr = 0;
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;
187} 241}
188 242
@@ -372,3 +426,30 @@ bool Aportis::refreshbuffer()
372 return false; 426 return false;
373 } 427 }
374} 428}
429
430#include <qimage.h>
431
432QImage* 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
451extern "C"
452{
453 CExpander* newcodec() { return new Aportis; }
454}
455#endif