00001 #include <stdlib.h> 00002 #include <qfileinfo.h> 00003 #include <qdir.h> 00004 00005 #ifdef USEQPE 00006 #include <qpe/global.h> 00007 #endif 00008 00009 class COutput 00010 { 00011 public: 00012 virtual ~COutput() {} 00013 virtual void output(const QString&) = 0; 00014 virtual QString about() = 0; 00015 }; 00016 00017 #ifndef __STATIC 00018 #include <dlfcn.h> 00019 class outputcodec : public COutput 00020 { 00021 COutput *codec; 00022 void *handle; 00023 int status; 00024 public: 00025 void output(const QString& q) { codec->output(q); } 00026 QString about() 00027 { 00028 return QString("Plug-in output codec interface (c) Tim Wentford\n")+codec->about(); 00029 } 00030 outputcodec(const QString& _s) : codec(NULL), handle(NULL), status(-1) 00031 { 00032 #ifdef USEQPE 00033 #ifdef OPIE 00034 QString codecpath(getenv("OPIEDIR")); 00035 #else 00036 QString codecpath(getenv("QTDIR")); 00037 #endif 00038 codecpath += "/plugins/reader/outcodecs/lib"; 00039 #else 00040 QString codecpath(getenv("READERDIR")); 00041 codecpath += "/outcodecs/lib"; 00042 #endif 00043 codecpath += _s; 00044 codecpath += ".so"; 00045 if (QFile::exists(codecpath)) 00046 { 00047 qDebug("Codec:%s", (const char*)codecpath); 00048 handle = dlopen(codecpath, RTLD_LAZY); 00049 if (handle == 0) 00050 { 00051 qDebug("Can't find codec:%s", dlerror()); 00052 status = -10; 00053 return; 00054 } 00055 COutput* (*newcodec)(); 00056 newcodec = (COutput* (*)())dlsym(handle, "newcodec"); 00057 if (newcodec == NULL) 00058 { 00059 qDebug("Can't find newcodec"); 00060 status = -20; 00061 return; 00062 } 00063 codec = (*newcodec)(); 00064 status = 0; 00065 } 00066 else 00067 { 00068 qDebug("Can't find codec:%s", (const char*)codecpath); 00069 } 00070 if (codec == NULL) 00071 { 00072 qDebug("Can't do newcodec"); 00073 status = -30; 00074 return; 00075 } 00076 } 00077 virtual ~outputcodec() 00078 { 00079 if (codec != NULL) delete codec; 00080 if (handle != NULL) dlclose(handle); 00081 } 00082 int getStatus() { return status; } 00083 }; 00084 #endif
1.4.2