Diffstat (limited to 'noncore/apps/opie-reader/ebookcodec.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/ebookcodec.h | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/ebookcodec.h b/noncore/apps/opie-reader/ebookcodec.h new file mode 100644 index 0000000..b341e55 --- a/dev/null +++ b/noncore/apps/opie-reader/ebookcodec.h | |||
@@ -0,0 +1,120 @@ | |||
1 | #include "CExpander.h" | ||
2 | |||
3 | #include <qfileinfo.h> | ||
4 | #include <qdir.h> | ||
5 | |||
6 | #include "useqpe.h" | ||
7 | #ifdef USEQPE | ||
8 | #include <qpe/global.h> | ||
9 | #endif | ||
10 | |||
11 | #include "util.h" | ||
12 | |||
13 | #include "static.h" | ||
14 | #ifndef __STATIC | ||
15 | #include <dlfcn.h> | ||
16 | class ebookcodec : public CExpander_Interface | ||
17 | { | ||
18 | CExpander *codec; | ||
19 | void *handle; | ||
20 | int status; | ||
21 | public: | ||
22 | QString about() | ||
23 | { | ||
24 | return QString("Plug-in ebook codec interface (c) Tim Wentford\n")+codec->about(); | ||
25 | } | ||
26 | ebookcodec(const QString& _s) : codec(NULL), handle(NULL), status(0) | ||
27 | { | ||
28 | QString codecpath(QTReaderUtil::getPluginPath()); | ||
29 | codecpath += _s; | ||
30 | if (QFile::exists(codecpath)) | ||
31 | { | ||
32 | qDebug("Codec:%s", (const char*)codecpath); | ||
33 | handle = dlopen(codecpath, RTLD_LAZY); | ||
34 | if (handle == 0) | ||
35 | { | ||
36 | /* | ||
37 | QString wrn(dlerror()); | ||
38 | QString fmt; | ||
39 | while (wrn.length() > 10) | ||
40 | { | ||
41 | fmt += wrn.left(10); | ||
42 | fmt += '\n'; | ||
43 | wrn = wrn.right(wrn.length()-10); | ||
44 | } | ||
45 | fmt += wrn; | ||
46 | QMessageBox::warning(NULL, PROGNAME, fmt); | ||
47 | */ | ||
48 | qDebug("Can't find codec:%s", dlerror()); | ||
49 | status = -10; | ||
50 | return; | ||
51 | } | ||
52 | CExpander* (*newcodec)(); | ||
53 | newcodec = (CExpander* (*)())dlsym(handle, "newcodec"); | ||
54 | if (newcodec == NULL) | ||
55 | { | ||
56 | qDebug("Can't find newcodec"); | ||
57 | status = -20; | ||
58 | return; | ||
59 | } | ||
60 | codec = (*newcodec)(); | ||
61 | } | ||
62 | else | ||
63 | { | ||
64 | qDebug("Can't find codec"); | ||
65 | } | ||
66 | if (codec == NULL) | ||
67 | { | ||
68 | qDebug("Can't do newcodec"); | ||
69 | status = -30; | ||
70 | return; | ||
71 | } | ||
72 | } | ||
73 | virtual ~ebookcodec() | ||
74 | { | ||
75 | if (codec != NULL) delete codec; | ||
76 | if (handle != NULL) dlclose(handle); | ||
77 | } | ||
78 | size_t getHome() { return codec->getHome(); } | ||
79 | #ifdef USEQPE | ||
80 | void suspend() { codec->suspend(); } | ||
81 | void unsuspend() { codec->unsuspend(); } | ||
82 | void suspend(FILE*& fin) { codec->suspend(fin); } | ||
83 | void unsuspend(FILE*& fin) { codec->unsuspend(fin); } | ||
84 | #endif | ||
85 | unsigned int locate() { return codec->locate(); } | ||
86 | void locate(unsigned int n) { codec->locate(n); } | ||
87 | bool hasrandomaccess() { return codec->hasrandomaccess(); } | ||
88 | void sizes(unsigned long& file, unsigned long& text) | ||
89 | { | ||
90 | codec->sizes(file, text); | ||
91 | //qDebug("Codec sizes:(%u, %u)", file, text); | ||
92 | } | ||
93 | CList<Bkmk>* getbkmklist() { return codec->getbkmklist(); } | ||
94 | void getch(tchar& ch, CStyle& sty, unsigned long& pos) { codec->getch(ch, sty, pos); } | ||
95 | int getch() { return codec->getch(); } | ||
96 | linkType hyperlink(unsigned int n, unsigned int noff, QString& wrd, QString& nm) { return codec->hyperlink(n, noff, wrd, nm); } | ||
97 | MarkupType PreferredMarkup() { return codec->PreferredMarkup(); } | ||
98 | void saveposn(size_t posn) { codec->saveposn(posn); } | ||
99 | void writeposn(size_t posn) { codec->writeposn(posn); } | ||
100 | linkType forward(size_t& loc) { return codec->forward(loc); } | ||
101 | linkType back(size_t& loc) { return codec->back(loc); } | ||
102 | bool hasnavigation() { return codec->hasnavigation(); } | ||
103 | void start2endSection() { codec->start2endSection(); } | ||
104 | QImage* getPicture(unsigned long tgt) { return codec->getPicture(tgt); } | ||
105 | void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) { return codec->setSaveData(data, len, src, srclen); } | ||
106 | void putSaveData(unsigned char*& src, unsigned short& srclen) { codec->putSaveData(src, srclen); } | ||
107 | void setContinuous(bool _b) { codec->setContinuous(_b); } | ||
108 | void setwidth(int w) { codec->setwidth(w); } | ||
109 | unsigned long startSection() { return codec->startSection(); } | ||
110 | unsigned long endSection() { return codec->endSection(); } | ||
111 | int openfile(const char *src) | ||
112 | { | ||
113 | //qDebug("ebook openfile:%s", src); | ||
114 | return (status != 0) ? status : codec->openfile(src); | ||
115 | } | ||
116 | int getwidth() { return codec->getwidth(); } | ||
117 | QImage* getPicture(const QString& href) { return codec->getPicture(href); } | ||
118 | bool getFile(const QString& href) { return codec->getFile(href); } | ||
119 | }; | ||
120 | #endif | ||