|
@@ -21,6 +21,9 @@
|
|
|
#ifndef __ctkAbstractFileBasedFactory_tpp
|
|
|
#define __ctkAbstractFileBasedFactory_tpp
|
|
|
|
|
|
+// Qt includes
|
|
|
+#include <QDirIterator>
|
|
|
+
|
|
|
// CTK includes
|
|
|
#include "ctkAbstractFileBasedFactory.h"
|
|
|
|
|
@@ -38,8 +41,8 @@ ctkAbstractFactoryFileBasedItem<BaseClassType>::ctkAbstractFactoryFileBasedItem(
|
|
|
//----------------------------------------------------------------------------
|
|
|
template<typename BaseClassType>
|
|
|
QString ctkAbstractFactoryFileBasedItem<BaseClassType>::path()const
|
|
|
-{
|
|
|
- return this->Path;
|
|
|
+{
|
|
|
+ return this->Path;
|
|
|
}
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
@@ -51,7 +54,7 @@ ctkAbstractFileBasedFactory<BaseClassType>::ctkAbstractFileBasedFactory()
|
|
|
:ctkAbstractFactory<BaseClassType>()
|
|
|
{
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
template<typename BaseClassType>
|
|
|
ctkAbstractFileBasedFactory<BaseClassType>::~ctkAbstractFileBasedFactory()
|
|
@@ -68,4 +71,71 @@ QString ctkAbstractFileBasedFactory<BaseClassType>::path(const QString& key)
|
|
|
return _item->path();
|
|
|
}
|
|
|
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+template<typename BaseClassType>
|
|
|
+void ctkAbstractFileBasedFactory<BaseClassType>::registerAllFileItems(const QStringList& directories)
|
|
|
+{
|
|
|
+ // Process one path at a time
|
|
|
+ foreach (QString path, directories)
|
|
|
+ {
|
|
|
+ QDirIterator it(path);
|
|
|
+ while (it.hasNext())
|
|
|
+ {
|
|
|
+ it.next();
|
|
|
+ QFileInfo fileInfo = it.fileInfo();
|
|
|
+ if (fileInfo.isSymLink())
|
|
|
+ {
|
|
|
+ // symLinkTarget() handles links pointing to symlinks.
|
|
|
+ // How about a symlink pointing to a symlink ?
|
|
|
+ fileInfo = QFileInfo(fileInfo.symLinkTarget());
|
|
|
+ }
|
|
|
+ // Skip if item isn't a file
|
|
|
+ if (!fileInfo.isFile())
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this->verbose())
|
|
|
+ {
|
|
|
+ qDebug() << "Attempt to register command line module:" << fileInfo.fileName();
|
|
|
+ }
|
|
|
+
|
|
|
+ QString key = this->fileNameToKey(fileInfo.filePath());
|
|
|
+ QSharedPointer<ctkAbstractFactoryItem<BaseClassType> >
|
|
|
+ itemToRegister = QSharedPointer<ctkAbstractFactoryItem<BaseClassType> >(
|
|
|
+ this->createFactoryFileBasedItem(fileInfo));
|
|
|
+ if (itemToRegister.isNull())
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ itemToRegister->setVerbose(this->verbose());
|
|
|
+ if (!this->registerItem(key, itemToRegister))
|
|
|
+ {
|
|
|
+ if (this->verbose())
|
|
|
+ {
|
|
|
+ qWarning() << "Failed to register module: " << key;
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+template<typename BaseClassType>
|
|
|
+ctkAbstractFactoryItem<BaseClassType>* ctkAbstractFileBasedFactory<BaseClassType>
|
|
|
+::createFactoryFileBasedItem(const QFileInfo& file)
|
|
|
+{
|
|
|
+ Q_UNUSED(file);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+template<typename BaseClassType>
|
|
|
+QString ctkAbstractFileBasedFactory<BaseClassType>
|
|
|
+::fileNameToKey(const QString& fileName)const
|
|
|
+{
|
|
|
+ return QFileInfo(fileName).baseName().toLower();
|
|
|
+}
|
|
|
+
|
|
|
#endif
|