|
@@ -23,25 +23,30 @@
|
|
|
#include <QDebug>
|
|
|
#include <QCoreApplication>
|
|
|
#include <cstdlib>
|
|
|
+#include <QStringList>
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
struct ctkCmdLineModuleDefaultPathBuilderPrivate
|
|
|
{
|
|
|
public:
|
|
|
+
|
|
|
ctkCmdLineModuleDefaultPathBuilderPrivate();
|
|
|
~ctkCmdLineModuleDefaultPathBuilderPrivate();
|
|
|
- QStringList build() const;
|
|
|
+ void clear();
|
|
|
+ void setStrictMode(const bool& strict);
|
|
|
+ bool strictMode() const;
|
|
|
+ void addHomeDir(const QString& subFolder = QString());
|
|
|
+ void addCurrentDir(const QString& subFolder = QString());
|
|
|
+ void addApplicationDir(const QString& subFolder = QString());
|
|
|
+ void addCtkModuleLoadPath();
|
|
|
+ QStringList getDirectoryList() const;
|
|
|
|
|
|
- void setLoadFromHomeDir(bool doLoad);
|
|
|
- void setLoadFromCurrentDir(bool doLoad);
|
|
|
- void setLoadFromApplicationDir(bool doLoad);
|
|
|
- void setLoadFromCtkModuleLoadPath(bool doLoad);
|
|
|
+ bool isStrictMode;
|
|
|
+ QStringList directoryList;
|
|
|
|
|
|
- bool LoadFromHomeDir;
|
|
|
- bool LoadFromCurrentDir;
|
|
|
- bool LoadFromApplicationDir;
|
|
|
- bool LoadFromCtkModuleLoadPath;
|
|
|
+private:
|
|
|
|
|
|
+ QString addSubFolder(const QString& folder, const QString& subFolder);
|
|
|
};
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
@@ -49,92 +54,135 @@ public:
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
ctkCmdLineModuleDefaultPathBuilderPrivate::ctkCmdLineModuleDefaultPathBuilderPrivate()
|
|
|
-: LoadFromHomeDir(false)
|
|
|
-, LoadFromCurrentDir(false)
|
|
|
-, LoadFromApplicationDir(false)
|
|
|
-, LoadFromCtkModuleLoadPath(false)
|
|
|
+: isStrictMode(false)
|
|
|
{
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
ctkCmdLineModuleDefaultPathBuilderPrivate::~ctkCmdLineModuleDefaultPathBuilderPrivate()
|
|
|
{
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void ctkCmdLineModuleDefaultPathBuilderPrivate::setLoadFromHomeDir(bool doLoad)
|
|
|
+void ctkCmdLineModuleDefaultPathBuilderPrivate::clear()
|
|
|
{
|
|
|
- LoadFromHomeDir = doLoad;
|
|
|
+ directoryList.clear();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void ctkCmdLineModuleDefaultPathBuilderPrivate::setLoadFromCurrentDir(bool doLoad)
|
|
|
+void ctkCmdLineModuleDefaultPathBuilderPrivate::setStrictMode(const bool& strict)
|
|
|
{
|
|
|
- LoadFromCurrentDir = doLoad;
|
|
|
+ isStrictMode = strict;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void ctkCmdLineModuleDefaultPathBuilderPrivate::setLoadFromApplicationDir(bool doLoad)
|
|
|
+bool ctkCmdLineModuleDefaultPathBuilderPrivate::strictMode() const
|
|
|
{
|
|
|
- LoadFromApplicationDir = doLoad;
|
|
|
+ return isStrictMode;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void ctkCmdLineModuleDefaultPathBuilderPrivate::setLoadFromCtkModuleLoadPath(bool doLoad)
|
|
|
+QString ctkCmdLineModuleDefaultPathBuilderPrivate::addSubFolder(
|
|
|
+ const QString& folder, const QString& subFolder)
|
|
|
{
|
|
|
- LoadFromCtkModuleLoadPath = doLoad;
|
|
|
+ if (subFolder.length() > 0)
|
|
|
+ {
|
|
|
+ return folder + QDir::separator() + subFolder;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return folder;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-QStringList ctkCmdLineModuleDefaultPathBuilderPrivate::build() const
|
|
|
+void ctkCmdLineModuleDefaultPathBuilderPrivate::addHomeDir(const QString& subFolder)
|
|
|
{
|
|
|
- QStringList result;
|
|
|
+ if (QDir::home().exists())
|
|
|
+ {
|
|
|
+ QString result = addSubFolder(QDir::homePath(), subFolder);
|
|
|
+ directoryList << result;
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- QString suffix = "cli-modules";
|
|
|
|
|
|
- if (LoadFromCtkModuleLoadPath)
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkCmdLineModuleDefaultPathBuilderPrivate::addCurrentDir(const QString& subFolder)
|
|
|
+{
|
|
|
+ if (QDir::current().exists())
|
|
|
{
|
|
|
- char *ctkModuleLoadPath = getenv("CTK_MODULE_LOAD_PATH");
|
|
|
- if (ctkModuleLoadPath != NULL)
|
|
|
- {
|
|
|
- QDir dir = QDir(QString(ctkModuleLoadPath));
|
|
|
- if (dir.exists())
|
|
|
- {
|
|
|
- result << dir.canonicalPath();
|
|
|
- }
|
|
|
- }
|
|
|
+ QString result = addSubFolder(QDir::currentPath(), subFolder);
|
|
|
+ directoryList << result;
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
- if (LoadFromHomeDir)
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkCmdLineModuleDefaultPathBuilderPrivate::addApplicationDir(const QString& subFolder)
|
|
|
+{
|
|
|
+ QString result = addSubFolder(QCoreApplication::applicationDirPath(), subFolder);
|
|
|
+ directoryList << result;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkCmdLineModuleDefaultPathBuilderPrivate::addCtkModuleLoadPath()
|
|
|
+{
|
|
|
+ char *ctkModuleLoadPath = getenv("CTK_MODULE_LOAD_PATH");
|
|
|
+ if (ctkModuleLoadPath != NULL)
|
|
|
{
|
|
|
- if (QDir::home().exists())
|
|
|
+ // The load path may in fact be a semi-colon or colon separated list of directories, not just one.
|
|
|
+ QString paths(ctkModuleLoadPath);
|
|
|
+
|
|
|
+#ifdef Q_OS_WIN32
|
|
|
+ QString pathSeparator(";");
|
|
|
+#else
|
|
|
+ QString pathSeparator(":");
|
|
|
+#endif
|
|
|
+
|
|
|
+ QStringList splitPath = paths.split(pathSeparator, QString::SkipEmptyParts);
|
|
|
+
|
|
|
+ foreach (QString path, splitPath)
|
|
|
{
|
|
|
- result << QDir::homePath();
|
|
|
- result << QDir::homePath() + QDir::separator() + suffix;
|
|
|
+ QDir dir = QDir(path);
|
|
|
+ directoryList << dir.absolutePath();
|
|
|
}
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
- if (LoadFromCurrentDir)
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+QStringList ctkCmdLineModuleDefaultPathBuilderPrivate::getDirectoryList() const
|
|
|
+{
|
|
|
+ if (!isStrictMode)
|
|
|
{
|
|
|
- if (QDir::current().exists())
|
|
|
+ return directoryList;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ QStringList filteredList;
|
|
|
+ foreach (QString directory, directoryList)
|
|
|
{
|
|
|
- result << QDir::currentPath();
|
|
|
- result << QDir::currentPath() + QDir::separator() + suffix;
|
|
|
+ QDir dir(directory);
|
|
|
+ if (dir.exists())
|
|
|
+ {
|
|
|
+ filteredList << directory;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (LoadFromApplicationDir)
|
|
|
- {
|
|
|
- result << QCoreApplication::applicationDirPath();
|
|
|
- result << QCoreApplication::applicationDirPath() + QDir::separator() + suffix;
|
|
|
+ qDebug() << "Filtered directory list " << directoryList << " to " << filteredList;
|
|
|
+ return filteredList;
|
|
|
}
|
|
|
-
|
|
|
- return result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
// ctkCmdLineModuleDefaultPathBuilder methods
|
|
|
|
|
@@ -149,32 +197,58 @@ ctkCmdLineModuleDefaultPathBuilder::~ctkCmdLineModuleDefaultPathBuilder()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkCmdLineModuleDefaultPathBuilder::clear()
|
|
|
+{
|
|
|
+ d->clear();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-QStringList ctkCmdLineModuleDefaultPathBuilder::build() const
|
|
|
+void ctkCmdLineModuleDefaultPathBuilder::setStrictMode(const bool& strict)
|
|
|
{
|
|
|
- return d->build();
|
|
|
+ d->setStrictMode(strict);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void ctkCmdLineModuleDefaultPathBuilder::setLoadFromHomeDir(bool doLoad)
|
|
|
+bool ctkCmdLineModuleDefaultPathBuilder::strictMode() const
|
|
|
{
|
|
|
- d->setLoadFromHomeDir(doLoad);
|
|
|
+ return d->strictMode();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void ctkCmdLineModuleDefaultPathBuilder::setLoadFromCurrentDir(bool doLoad)
|
|
|
+void ctkCmdLineModuleDefaultPathBuilder::addHomeDir(const QString& subFolder)
|
|
|
{
|
|
|
- d->setLoadFromCurrentDir(doLoad);
|
|
|
+ d->addHomeDir(subFolder);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void ctkCmdLineModuleDefaultPathBuilder::setLoadFromApplicationDir(bool doLoad)
|
|
|
+void ctkCmdLineModuleDefaultPathBuilder::addCurrentDir(const QString& subFolder)
|
|
|
{
|
|
|
- d->setLoadFromApplicationDir(doLoad);
|
|
|
+ d->addCurrentDir(subFolder);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkCmdLineModuleDefaultPathBuilder::addApplicationDir(const QString& subFolder)
|
|
|
+{
|
|
|
+ d->addApplicationDir(subFolder);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkCmdLineModuleDefaultPathBuilder::addCtkModuleLoadPath()
|
|
|
+{
|
|
|
+ d->addCtkModuleLoadPath();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void ctkCmdLineModuleDefaultPathBuilder::setLoadFromCtkModuleLoadPath(bool doLoad)
|
|
|
+QStringList ctkCmdLineModuleDefaultPathBuilder::getDirectoryList() const
|
|
|
{
|
|
|
- d->setLoadFromCtkModuleLoadPath(doLoad);
|
|
|
+ return d->getDirectoryList();
|
|
|
}
|