20 #ifndef EPLUGINLOADER_H
21 #define EPLUGINLOADER_H
26 #include <QPluginLoader>
106 template <
class PluginType>
109 QList<PluginType*> result;
111 QDir dir(searchPath);
112 if ( !dir.exists() || !dir.isReadable())
116 QStringList files = dir.entryList(QDir::Files | QDir::Readable);
117 foreach ( QString file, files ) {
119 QFileInfo info(dir.filePath(file));
120 if(info.isSymLink()){
122 bool doubleEntry =
false;
123 foreach(QString compareFile, files){
124 if(compareFile == file)
126 if(info.symLinkTarget() == dir.filePath(compareFile)){
137 PluginType *plugin = mLoader.
doLoadPlugin(dir.filePath ( file ), item);
144 template <
class PluginType>
150 QDir dir(searchPath);
151 if ( !dir.exists() || !dir.isReadable()){
153 item->
setErrorMessage(QObject::tr(
"Directory does not exists or is not readable:\n%1").arg(dir.absolutePath()));
159 filter << QString(
"*%1*").arg(name);
160 QStringList files = dir.entryList (filter, QDir::Files | QDir::Readable);
162 if(files.size() < 1){
165 QObject::tr(
"%1 not found at \n%2\n\nFilters: %3\n")
167 .arg(dir.absolutePath())
168 .arg(filter.join(
", "))
173 foreach ( QString file, files ) {
174 PluginType *plugin = mLoader.
doLoadPlugin(dir.filePath ( file ), item);
181 template <
class PluginType>
184 QFileInfo file(absFilePath);
186 item->
setFile(file.absoluteFilePath());
187 if(!file.exists() || !file.isReadable()){
189 item->
setErrorMessage(QObject::tr(
"File does not exists or is not readable:\n%1").arg(file.absoluteFilePath()));
193 if(!QLibrary::isLibrary(file.absoluteFilePath())){
195 item->
setErrorMessage(QObject::tr(
"%1 is no library file").arg(file.absoluteFilePath()));
199 QPluginLoader loader ( file.absoluteFilePath() );
200 QObject *plugin = loader.instance();
204 QObject::tr(
"While loading %1 an error occured:\n%2\n" )
205 .arg ( file.absoluteFilePath() ).arg(loader.errorString())
210 PluginType *newPlugin = qobject_cast<PluginType *> ( plugin );
213 item->
setErrorMessage(QObject::tr(
"Could not load %1!\n(Plugin is not of specified type!)").arg(file.absoluteFilePath()));
219 QObject *
object =
dynamic_cast<QObject*
>(newPlugin);
226 #endif // EPLUGINLOADER_H
static QList< PluginType * > loadPlugins(QString searchPath, EngSaS::ModuleListWidgetItems &log)
Loads all plugins of type PluginType in a directory.
Definition: epluginloader.h:107
QList< EModuleListWidgetItem * > ModuleListWidgetItems
A type to replace QList<EModuleListWidgetItem*> with a shorter name.
Definition: eglobal.h:168
Provides functions to load Qt plugins properly.
Definition: epluginloader.h:75
PluginType * doLoadPlugin(QString absFilePath, EModuleListWidgetItem *item=NULL)
Used internally to really load a plugin.
Definition: epluginloader.h:182
static PluginType * loadPlugin(QString name, QString searchPath, EModuleListWidgetItem *item=NULL)
Loads the first plugin matching PluginType and name in a directory.
Definition: epluginloader.h:145