ctkCmdLineModuleDirectoryWatcher.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) University College London
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =============================================================================*/
  14. #ifndef __ctkCmdLineModuleDirectoryWatcher_h
  15. #define __ctkCmdLineModuleDirectoryWatcher_h
  16. #include <ctkCommandLineModulesCoreExport.h>
  17. #include <QObject>
  18. #include <QScopedPointer>
  19. class ctkCmdLineModuleManager;
  20. class ctkCmdLineModuleDirectoryWatcherPrivate;
  21. /**
  22. * \class ctkCmdLineModuleDirectoryWatcher
  23. * \brief Provides directory scanning and file watching via QFileSystemWatcher to
  24. * automatically load new modules into a ctkCmdLineModuleManager.
  25. *
  26. * \ingroup CommandLineModulesCore_API
  27. * \author m.clarkson@ucl.ac.uk
  28. *
  29. * This class can be used in 3 ways.
  30. *
  31. * 1. The user can provide a set of directories by calling setDirectories().
  32. * These directories are scanned for valid command line executables, which
  33. * are registered with the ctkCmdLineModuleManager. The QFileSystemWatcher
  34. * then watches for any changes in these directories and files.
  35. *
  36. * OR
  37. *
  38. * 2. The user can directly provide a list of files, which should be
  39. * valid command line executables, which are registered with the ctkCmdLineModuleManager
  40. * and the QFileSystemWatcher then watches for changes in these files.
  41. *
  42. * OR
  43. *
  44. * 3. Both of the above. In this case, the set of files specified must
  45. * not be contained within the set of directories specified. For this reason, we have
  46. * "setDirectories", and then "setAdditionalModules", as the list of files should
  47. * be considered as being "in addition" to any directories we are watching.
  48. *
  49. * If either directories or files are invalid (not existing, not executable etc),
  50. * they are filtered out and ignored.
  51. */
  52. class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleDirectoryWatcher
  53. : public QObject
  54. {
  55. Q_OBJECT
  56. public:
  57. ctkCmdLineModuleDirectoryWatcher(ctkCmdLineModuleManager* moduleManager);
  58. virtual ~ctkCmdLineModuleDirectoryWatcher();
  59. /**
  60. * \brief Set the watcher into debug mode, for more output.
  61. * \param debug if true, you get more output on the console, otherwise, less output.
  62. */
  63. void setDebug(bool debug);
  64. /**
  65. * \brief Set the directories to be watched.
  66. * \param directories a list of directory names. If any of these are
  67. * invalid, they will be filtered out and ignored.
  68. */
  69. void setDirectories(const QStringList& directories);
  70. /**
  71. * \brief Returns the list of directories currently being watched.
  72. */
  73. QStringList directories() const;
  74. /**
  75. * \brief Sets an additional list of command line executables to watch.
  76. * \param files a list of file names. If any of these file names are
  77. * not valid command line executables, they will be filtered out and ignored.
  78. */
  79. void setAdditionalModules(const QStringList& files);
  80. /**
  81. * \brief Gets the list of additional command line executable, where
  82. * "additional" means "in addition to those directories we are watching".
  83. */
  84. QStringList additionalModules() const;
  85. /**
  86. * \brief Returns the complete list of files (command line executables)
  87. * currently being watched.
  88. */
  89. QStringList commandLineModules() const;
  90. /**
  91. * \brief public method to emit the errorDetected signal.
  92. */
  93. void emitErrorDectectedSignal(const QString&);
  94. Q_SIGNALS:
  95. /**
  96. * \brief Signals that an error was detected, and the caller should raise an error to the user.
  97. */
  98. void errorDetected(const QString&);
  99. private:
  100. QScopedPointer<ctkCmdLineModuleDirectoryWatcherPrivate> d;
  101. Q_DISABLE_COPY(ctkCmdLineModuleDirectoryWatcher)
  102. };
  103. #endif // __ctkCmdLineModuleDirectoryWatcher_h