kpilot/lib
pluginfactory.h00001 #ifndef _KPILOT_PLUGINFACTORY_H
00002 #define _KPILOT_PLUGINFACTORY_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00032 #include <qwidget.h>
00033 #include <klibloader.h>
00034 #include <kdebug.h>
00035
00036 class KPilotLink;
00037
00040 template <class Widget, class Action> class ConduitFactory : public KLibFactory
00041 {
00042 public:
00043 ConduitFactory(QObject *parent = 0, const char *name = 0) :
00044 KLibFactory(parent,name)
00045 { fInstance = new KInstance(name); } ;
00046 virtual ~ConduitFactory()
00047 { delete fInstance; } ;
00048
00049 protected:
00050 virtual QObject *createObject(
00051 QObject* parent = 0,
00052 const char* name = 0,
00053 const char* classname = "QObject",
00054 const QStringList &args = QStringList() )
00055 {
00056 if (qstrcmp(classname,"ConduitConfigBase")==0)
00057 {
00058 QWidget *w = dynamic_cast<QWidget *>(parent);
00059 if (w) return new Widget(w,name);
00060 else
00061 {
00062 kdError() << k_funcinfo
00063 << ": Couldn't cast parent to widget."
00064 << endl;
00065 return 0L;
00066 }
00067 }
00068
00069 if (qstrcmp(classname,"SyncAction")==0)
00070 {
00071 KPilotLink *d = 0L;
00072 if (parent) d = dynamic_cast<KPilotLink *>(parent);
00073
00074 if (d || !parent)
00075 {
00076 if (!parent)
00077 {
00078 kdDebug() << k_funcinfo << ": Using NULL device." << endl;
00079 }
00080 return new Action(d,name,args);
00081 }
00082 else
00083 {
00084 kdError() << k_funcinfo
00085 << ": Couldn't cast parent to KPilotLink"
00086 << endl;
00087 return 0L;
00088 }
00089 }
00090 return 0L;
00091 }
00092
00093 KInstance *fInstance;
00094 } ;
00095
00096 #endif
00097
|