Bläddra i källkod

Added setVerboseOutput() method to CmdLineModuleManager.

Sascha Zelzer 12 år sedan
förälder
incheckning
f21b5f65b5

+ 1 - 0
Libs/CommandLineModules/Core/CMakeLists.txt

@@ -18,6 +18,7 @@ set(KIT_SRCS
   ctkCmdLineModuleDescription.cpp
   ctkCmdLineModuleDescriptionPrivate.h
   ctkCmdLineModuleDirectoryWatcher.cpp
+  ctkCmdLineModuleDirectoryWatcherPrivate.h
   ctkCmdLineModuleInstance.cpp
   ctkCmdLineModuleInstanceFactory.cpp
   ctkCmdLineModuleManager.cpp

+ 5 - 1
Libs/CommandLineModules/Core/ctkCmdLineModuleDirectoryWatcher.cpp

@@ -21,12 +21,14 @@
 #include "ctkCmdLineModuleDirectoryWatcher.h"
 #include "ctkCmdLineModuleDirectoryWatcherPrivate.h"
 #include "ctkCmdLineModuleManager.h"
+
 #include <QObject>
 #include <QFileSystemWatcher>
 #include <QDir>
 #include <QFile>
 #include <QFileInfo>
 #include <QDebug>
+
 #include <iostream>
 
 //-----------------------------------------------------------------------------
@@ -36,6 +38,7 @@
 ctkCmdLineModuleDirectoryWatcher::ctkCmdLineModuleDirectoryWatcher(ctkCmdLineModuleManager* moduleManager)
   : d(new ctkCmdLineModuleDirectoryWatcherPrivate(moduleManager))
 {
+  Q_ASSERT(moduleManager);
 }
 
 
@@ -102,6 +105,7 @@ ctkCmdLineModuleDirectoryWatcherPrivate::~ctkCmdLineModuleDirectoryWatcherPrivat
 void ctkCmdLineModuleDirectoryWatcherPrivate::setDebug(const bool& debug)
 {
   this->Debug = debug;
+  this->ModuleManager->setVerboseOutput(debug);
 }
 
 
@@ -309,7 +313,7 @@ void ctkCmdLineModuleDirectoryWatcherPrivate::updateModuleReferences(const QStri
 //-----------------------------------------------------------------------------
 ctkCmdLineModuleReference ctkCmdLineModuleDirectoryWatcherPrivate::loadModule(const QString& pathToExecutable)
 {
-  ctkCmdLineModuleReference ref = this->ModuleManager->registerModule(pathToExecutable, !this->Debug);
+  ctkCmdLineModuleReference ref = this->ModuleManager->registerModule(pathToExecutable);
   if (ref)
   {
     this->MapFileNameToReference[pathToExecutable] = ref;

+ 23 - 6
Libs/CommandLineModules/Core/ctkCmdLineModuleManager.cpp

@@ -36,9 +36,14 @@
 
 struct ctkCmdLineModuleManagerPrivate
 {
+  ctkCmdLineModuleManagerPrivate()
+    : Verbose(false)
+  {}
+
   ctkCmdLineModuleInstanceFactory* InstanceFactory;
 
   QHash<QString, ctkCmdLineModuleReference> Cache;
+  bool Verbose;
 };
 
 ctkCmdLineModuleManager::ctkCmdLineModuleManager(ctkCmdLineModuleInstanceFactory *instanceFactory,
@@ -52,6 +57,16 @@ ctkCmdLineModuleManager::~ctkCmdLineModuleManager()
 {
 }
 
+void ctkCmdLineModuleManager::setVerboseOutput(bool verbose)
+{
+  d->Verbose = verbose;
+}
+
+bool ctkCmdLineModuleManager::verboseOutput() const
+{
+  return d->Verbose;
+}
+
 ctkCmdLineModuleReference
 ctkCmdLineModuleManager::registerModule(const QString& location)
 {
@@ -64,15 +79,16 @@ ctkCmdLineModuleManager::registerModule(const QString& location)
   if (!process.waitForFinished() || process.exitStatus() == QProcess::CrashExit ||
       process.error() != QProcess::UnknownError)
   {
-    qWarning() << "The executable at" << location << "could not be started:" << process.errorString();
+    if(d->Verbose)
+    {
+      qWarning() << "The executable at" << location << "could not be started:" << process.errorString();
+    }
     return ref;
   }
 
   process.waitForReadyRead();
   QByteArray xml = process.readAllStandardOutput();
 
-  qDebug() << xml;
-
   // validate the outputted xml description
   QBuffer input(&xml);
   input.open(QIODevice::ReadOnly);
@@ -80,13 +96,14 @@ ctkCmdLineModuleManager::registerModule(const QString& location)
   ctkCmdLineModuleXmlValidator validator(&input);
   if (!validator.validateInput())
   {
-    qCritical() << validator.errorString();
+    if(d->Verbose)
+    {
+      qWarning() << validator.errorString();
+    }
     return ref;
   }
 
   ref.d->RawXmlDescription = xml;
-//  ref.d->objectRepresentation = descriptionFactory->createObjectRepresentationFromXML(ref.d->xml);
-//  ref.d->setGUI(descriptionFactory->createGUIFromXML(ref.d->xml));
 
   d->Cache[location] = ref;
 

+ 3 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleManager.h

@@ -59,6 +59,9 @@ public:
 
   ~ctkCmdLineModuleManager();
 
+  void setVerboseOutput(bool verbose);
+  bool verboseOutput() const;
+
   ctkCmdLineModuleReference registerModule(const QString& location);
   void unregisterModule(const ctkCmdLineModuleReference& moduleRef);