summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/outputcodec.h
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/outputcodec.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/outputcodec.h84
1 files changed, 84 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/outputcodec.h b/noncore/apps/opie-reader/outputcodec.h
new file mode 100644
index 0000000..727575c
--- a/dev/null
+++ b/noncore/apps/opie-reader/outputcodec.h
@@ -0,0 +1,84 @@
1#include <stdlib.h>
2#include <qfileinfo.h>
3#include <qdir.h>
4
5#ifdef USEQPE
6#include <qpe/global.h>
7#endif
8
9class COutput
10{
11 public:
12 virtual ~COutput() {}
13 virtual void output(const QString&) = 0;
14 virtual QString about() = 0;
15};
16
17#ifndef __STATIC
18#include <dlfcn.h>
19class outputcodec : public COutput
20{
21 COutput *codec;
22 void *handle;
23 int status;
24 public:
25 void output(const QString& q) { codec->output(q); }
26 QString about()
27 {
28 return QString("Plug-in output codec interface (c) Tim Wentford\n")+codec->about();
29 }
30 outputcodec(const QString& _s) : codec(NULL), handle(NULL), status(-1)
31 {
32#ifdef USEQPE
33#ifdef OPIE
34 QString codecpath(getenv("OPIEDIR"));
35#else
36 QString codecpath(getenv("QTDIR"));
37#endif
38 codecpath += "/plugins/reader/outcodecs/lib";
39#else
40 QString codecpath(getenv("READERDIR"));
41 codecpath += "/outcodecs/lib";
42#endif
43 codecpath += _s;
44 codecpath += ".so";
45 if (QFile::exists(codecpath))
46 {
47 qDebug("Codec:%s", (const char*)codecpath);
48 handle = dlopen(codecpath, RTLD_LAZY);
49 if (handle == 0)
50 {
51 qDebug("Can't find codec:%s", dlerror());
52 status = -10;
53 return;
54 }
55 COutput* (*newcodec)();
56 newcodec = (COutput* (*)())dlsym(handle, "newcodec");
57 if (newcodec == NULL)
58 {
59 qDebug("Can't find newcodec");
60 status = -20;
61 return;
62 }
63 codec = (*newcodec)();
64 status = 0;
65 }
66 else
67 {
68 qDebug("Can't find codec:%s", (const char*)codecpath);
69 }
70 if (codec == NULL)
71 {
72 qDebug("Can't do newcodec");
73 status = -30;
74 return;
75 }
76 }
77 virtual ~outputcodec()
78 {
79 if (codec != NULL) delete codec;
80 if (handle != NULL) dlclose(handle);
81 }
82 int getStatus() { return status; }
83};
84#endif