ソースを参照

Options for ctkCmdLineModuleDefaultPathBuilder to default all directories to off

MattClarkson 13 年 前
コミット
c8eb1d4436
共有2 個のファイルを変更した105 個の追加19 個の削除を含む
  1. 92 16
      Libs/CommandLineModules/Core/ctkCmdLineModuleDefaultPathBuilder.cpp
  2. 13 3
      Libs/CommandLineModules/Core/ctkCmdLineModuleDefaultPathBuilder.h

+ 92 - 16
Libs/CommandLineModules/Core/ctkCmdLineModuleDefaultPathBuilder.cpp

@@ -30,7 +30,18 @@ struct ctkCmdLineModuleDefaultPathBuilderPrivate
 public:
   ctkCmdLineModuleDefaultPathBuilderPrivate();
   ~ctkCmdLineModuleDefaultPathBuilderPrivate();
-  QStringList build();
+  QStringList build() const;
+
+  void setLoadFromHomeDir(const bool& doLoad);
+  void setLoadFromCurrentDir(const bool& doLoad);
+  void setLoadFromApplicationDir(const bool& doLoad);
+  void setLoadFromCtkModuleLoadPath(const bool& doLoad);
+
+  bool LoadFromHomeDir;
+  bool LoadFromCurrentDir;
+  bool LoadFromApplicationDir;
+  bool LoadFromCtkModuleLoadPath;
+
 };
 
 //-----------------------------------------------------------------------------
@@ -38,6 +49,10 @@ public:
 
 //-----------------------------------------------------------------------------
 ctkCmdLineModuleDefaultPathBuilderPrivate::ctkCmdLineModuleDefaultPathBuilderPrivate()
+: LoadFromHomeDir(false)
+, LoadFromCurrentDir(false)
+, LoadFromApplicationDir(false)
+, LoadFromCtkModuleLoadPath(false)
 {
 
 }
@@ -49,36 +64,73 @@ ctkCmdLineModuleDefaultPathBuilderPrivate::~ctkCmdLineModuleDefaultPathBuilderPr
 }
 
 //-----------------------------------------------------------------------------
-QStringList ctkCmdLineModuleDefaultPathBuilderPrivate::build()
+void ctkCmdLineModuleDefaultPathBuilderPrivate::setLoadFromHomeDir(const bool& doLoad)
+{
+  LoadFromHomeDir = doLoad;
+}
+
+//-----------------------------------------------------------------------------
+void ctkCmdLineModuleDefaultPathBuilderPrivate::setLoadFromCurrentDir(const bool& doLoad)
+{
+  LoadFromCurrentDir = doLoad;
+}
+
+//-----------------------------------------------------------------------------
+void ctkCmdLineModuleDefaultPathBuilderPrivate::setLoadFromApplicationDir(const bool& doLoad)
+{
+  LoadFromApplicationDir = doLoad;
+}
+
+//-----------------------------------------------------------------------------
+void ctkCmdLineModuleDefaultPathBuilderPrivate::setLoadFromCtkModuleLoadPath(const bool& doLoad)
+{
+  LoadFromCtkModuleLoadPath = doLoad;
+}
+
+
+//-----------------------------------------------------------------------------
+QStringList ctkCmdLineModuleDefaultPathBuilderPrivate::build() const
 {
   QStringList result;
 
   QString suffix = "cli-modules";
 
-  char *ctkModuleLoadPath = getenv("CTK_MODULE_LOAD_PATH");
-  if (ctkModuleLoadPath != NULL)
+  if (LoadFromCtkModuleLoadPath)
   {
-    QDir dir = QDir(QString(ctkModuleLoadPath));
-    if (dir.exists())
+    char *ctkModuleLoadPath = getenv("CTK_MODULE_LOAD_PATH");
+    if (ctkModuleLoadPath != NULL)
     {
-      result << dir.canonicalPath();
+      QDir dir = QDir(QString(ctkModuleLoadPath));
+      if (dir.exists())
+      {
+        result << dir.canonicalPath();
+      }
     }
   }
 
-  if (QDir::home().exists())
+  if (LoadFromHomeDir)
   {
-    result << QDir::homePath();
-    result << QDir::homePath() + QDir::separator() + suffix;
+    if (QDir::home().exists())
+    {
+      result << QDir::homePath();
+      result << QDir::homePath() + QDir::separator() + suffix;
+    }
   }
 
-  if (QDir::current().exists())
+  if (LoadFromCurrentDir)
   {
-    result << QDir::currentPath();
-    result << QDir::currentPath() + QDir::separator() + suffix;
+    if (QDir::current().exists())
+    {
+      result << QDir::currentPath();
+      result << QDir::currentPath() + QDir::separator() + suffix;
+    }
   }
 
-  result << QCoreApplication::applicationDirPath();
-  result << QCoreApplication::applicationDirPath() + QDir::separator() + suffix;
+  if (LoadFromApplicationDir)
+  {
+    result << QCoreApplication::applicationDirPath();
+    result << QCoreApplication::applicationDirPath() + QDir::separator() + suffix;
+  }
 
   return result;
 }
@@ -98,7 +150,31 @@ ctkCmdLineModuleDefaultPathBuilder::~ctkCmdLineModuleDefaultPathBuilder()
 }
 
 //-----------------------------------------------------------------------------
-QStringList ctkCmdLineModuleDefaultPathBuilder::build()
+QStringList ctkCmdLineModuleDefaultPathBuilder::build() const
 {
   return d->build();
 }
+
+//-----------------------------------------------------------------------------
+void ctkCmdLineModuleDefaultPathBuilder::setLoadFromHomeDir(const bool& doLoad)
+{
+  d->setLoadFromHomeDir(doLoad);
+}
+
+//-----------------------------------------------------------------------------
+void ctkCmdLineModuleDefaultPathBuilder::setLoadFromCurrentDir(const bool& doLoad)
+{
+  d->setLoadFromCurrentDir(doLoad);
+}
+
+//-----------------------------------------------------------------------------
+void ctkCmdLineModuleDefaultPathBuilder::setLoadFromApplicationDir(const bool& doLoad)
+{
+  d->setLoadFromApplicationDir(doLoad);
+}
+
+//-----------------------------------------------------------------------------
+void ctkCmdLineModuleDefaultPathBuilder::setLoadFromCtkModuleLoadPath(const bool& doLoad)
+{
+  d->setLoadFromCtkModuleLoadPath(doLoad);
+}

+ 13 - 3
Libs/CommandLineModules/Core/ctkCmdLineModuleDefaultPathBuilder.h

@@ -30,12 +30,14 @@ class ctkCmdLineModuleDefaultPathBuilderPrivate;
 
 /**
  * \class ctkCmdLineModuleDefaultPathBuilder
- * \brief Builds up a list of file paths to search for command line modules.
+ * \brief Builds up a list of directory paths to search for command line modules.
  *
  * Unfinished:
  *
  * <pre>
- * Implements the following basic strategy:
+ * Implements the following basic strategy, depending on which boolean flags are on:
+ * By default they are all off, as directory scanning is often time consuming.
+ *
  * 1. CTK_MODULE_LOAD_PATH environment variable
  * 2. Home directory
  * 3. Home directory / cli-modules
@@ -55,7 +57,15 @@ public:
   ctkCmdLineModuleDefaultPathBuilder();
   ~ctkCmdLineModuleDefaultPathBuilder();
 
-  virtual QStringList build();
+  virtual void setLoadFromHomeDir(const bool& doLoad);
+
+  virtual void setLoadFromCurrentDir(const bool& doLoad);
+
+  virtual void setLoadFromApplicationDir(const bool& doLoad);
+
+  virtual void setLoadFromCtkModuleLoadPath(const bool& doLoad);
+
+  virtual QStringList build() const;
 
 private: