summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/outputcodec.h
blob: 727575cf6f9483035859b4c29f414281ca4fecb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdlib.h>
#include <qfileinfo.h>
#include <qdir.h>

#ifdef USEQPE
#include <qpe/global.h>
#endif

class COutput
{
 public:
  virtual ~COutput() {}
  virtual void output(const QString&) = 0;
  virtual QString about() = 0;
};

#ifndef __STATIC
#include <dlfcn.h>
class outputcodec : public COutput
{
  COutput *codec;
  void *handle;
  int status;
 public:
  void output(const QString& q) { codec->output(q); }
  QString about()
    {
      return QString("Plug-in output codec interface (c) Tim Wentford\n")+codec->about();
    }
  outputcodec(const QString& _s) : codec(NULL), handle(NULL), status(-1)
    {
#ifdef USEQPE
#ifdef OPIE
      QString codecpath(getenv("OPIEDIR"));
#else
      QString codecpath(getenv("QTDIR"));
#endif
      codecpath += "/plugins/reader/outcodecs/lib";
#else
      QString codecpath(getenv("READERDIR"));
      codecpath += "/outcodecs/lib";
#endif
      codecpath += _s;
      codecpath += ".so";
      if (QFile::exists(codecpath))
	{
	  qDebug("Codec:%s", (const char*)codecpath);
	  handle = dlopen(codecpath, RTLD_LAZY);
	  if (handle == 0)
	    {
	      qDebug("Can't find codec:%s", dlerror());
	      status = -10;
	      return;
	    }
	  COutput* (*newcodec)();
	  newcodec = (COutput* (*)())dlsym(handle, "newcodec");
	  if (newcodec == NULL)
	    {
	      qDebug("Can't find newcodec");
	      status = -20;
	      return;
	    }
	  codec = (*newcodec)();
	  status = 0;
	}
      else
	{
	  qDebug("Can't find codec:%s", (const char*)codecpath);
	}
      if (codec == NULL)
	{
	  qDebug("Can't do newcodec");
	  status = -30;
	  return;
	}
    }
  virtual ~outputcodec()
    {
      if (codec != NULL) delete codec;
      if (handle != NULL) dlclose(handle);
    }
  int getStatus() { return status; }
};
#endif