00001 #include "CExpander.h"
00002
00003 #include <qfileinfo.h>
00004 #include <qdir.h>
00005
00006 #ifdef USEQPE
00007 #include <qpe/global.h>
00008 #endif
00009
00010 #ifndef __STATIC
00011 #include <dlfcn.h>
00012 class ebookcodec : public CExpander_Interface
00013 {
00014 CExpander *codec;
00015 void *handle;
00016 int status;
00017 public:
00018 QString getTableAsHtml(unsigned long loc) { return codec->getTableAsHtml(loc); }
00019 QString about()
00020 {
00021 return QString("Plug-in ebook codec interface (c) Tim Wentford\n")+codec->about();
00022 }
00023 ebookcodec(const QString& _s) : codec(NULL), handle(NULL), status(0)
00024 {
00025 #ifdef USEQPE
00026 #ifdef OPIE
00027 QString codecpath(getenv("OPIEDIR"));
00028 #else
00029 QString codecpath(getenv("QTDIR"));
00030 #endif
00031 codecpath += "/plugins/reader/codecs/";
00032 #else
00033 QString codecpath(getenv("READERDIR"));
00034 codecpath += "/codecs/";
00035 #endif
00036 codecpath += _s;
00037 if (QFile::exists(codecpath))
00038 {
00039 qDebug("Codec:%s", (const char*)codecpath);
00040 handle = dlopen(codecpath, RTLD_LAZY);
00041 if (handle == 0)
00042 {
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 qDebug("Can't find codec:%s", dlerror());
00056 status = -10;
00057 return;
00058 }
00059 CExpander* (*newcodec)();
00060 newcodec = (CExpander* (*)())dlsym(handle, "newcodec");
00061 if (newcodec == NULL)
00062 {
00063 qDebug("Can't find newcodec");
00064 status = -20;
00065 return;
00066 }
00067 codec = (*newcodec)();
00068 }
00069 else
00070 {
00071 qDebug("Can't find codec");
00072 }
00073 if (codec == NULL)
00074 {
00075 qDebug("Can't do newcodec");
00076 status = -30;
00077 return;
00078 }
00079 }
00080 virtual ~ebookcodec()
00081 {
00082 if (codec != NULL) delete codec;
00083 if (handle != NULL) dlclose(handle);
00084 }
00085 size_t getHome() { return codec->getHome(); }
00086 #ifdef USEQPE
00087 void suspend() { codec->suspend(); }
00088 void unsuspend() { codec->unsuspend(); }
00089 void suspend(FILE*& fin) { codec->suspend(fin); }
00090 void unsuspend(FILE*& fin) { codec->unsuspend(fin); }
00091 #endif
00092 unsigned int locate() { return codec->locate(); }
00093 void locate(unsigned int n) { codec->locate(n); }
00094 bool hasrandomaccess() { return codec->hasrandomaccess(); }
00095 void sizes(unsigned long& file, unsigned long& text)
00096 {
00097 codec->sizes(file, text);
00098
00099 }
00100 CList<Bkmk>* getbkmklist() { return codec->getbkmklist(); }
00101 void getch(tchar& ch, CStyle& sty, unsigned long& pos) { codec->getch(ch, sty, pos); }
00102 int getch() { return codec->getch(); }
00103 linkType hyperlink(unsigned int n, unsigned int noff, QString& wrd, QString& nm) { return codec->hyperlink(n, noff, wrd, nm); }
00104 MarkupType PreferredMarkup() { return codec->PreferredMarkup(); }
00105 void saveposn(size_t posn) { codec->saveposn(posn); }
00106 void writeposn(size_t posn) { codec->writeposn(posn); }
00107 linkType forward(size_t& loc) { return codec->forward(loc); }
00108 linkType back(size_t& loc) { return codec->back(loc); }
00109 bool hasnavigation() { return codec->hasnavigation(); }
00110 void start2endSection() { codec->start2endSection(); }
00111 QImage* getPicture(unsigned long tgt) { return codec->getPicture(tgt); }
00112 void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) { return codec->setSaveData(data, len, src, srclen); }
00113 void putSaveData(unsigned char*& src, unsigned short& srclen) { codec->putSaveData(src, srclen); }
00114 void setContinuous(bool _b) { codec->setContinuous(_b); }
00115 void setwidth(int w) { codec->setwidth(w); }
00116 unsigned long startSection() { return codec->startSection(); }
00117 unsigned long endSection() { return codec->endSection(); }
00118 int openfile(const char *src)
00119 {
00120
00121 return (status != 0) ? status : codec->openfile(src);
00122 }
00123 int getwidth() { return codec->getwidth(); }
00124 QImage* getPicture(const QString& href) { return codec->getPicture(href); }
00125 bool getFile(const QString& href, const QString& nm) { return codec->getFile(href, nm); }
00126 bool findanchor(const QString& nm)
00127 {
00128 return codec->findanchor(nm);
00129 }
00130 };
00131 #endif