ctkCmdLineModuleDirectoryWatcher.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 "ctkCmdLineModuleReference.h"
  18. #include <QObject>
  19. #include <QScopedPointer>
  20. class ctkCmdLineModuleManager;
  21. class ctkCmdLineModuleDirectoryWatcherPrivate;
  22. /**
  23. * \class ctkCmdLineModuleDirectoryWatcher
  24. * \brief Provides directory scanning and file watching via QFileSystemWatcher to
  25. * automatically load new modules into a ctkCmdLineModuleManager.
  26. *
  27. * \ingroup CommandLineModulesCore_API
  28. * \author m.clarkson@ucl.ac.uk
  29. *
  30. * This class can be used in 3 ways.
  31. *
  32. * 1. The user can provide a set of directories by calling setDirectories().
  33. * These directories are scanned for valid command line executables, which
  34. * are registered with the ctkCmdLineModuleManager. The QFileSystemWatcher
  35. * then watches for any changes in these directories and files.
  36. *
  37. * OR
  38. *
  39. * 2. The user can directly provide a list of files, which should be
  40. * valid command line executables, which are registered with the ctkCmdLineModuleManager
  41. * and the QFileSystemWatcher then watches for changes in these files.
  42. *
  43. * OR
  44. *
  45. * 3. Both of the above. In this case, the set of files specified must
  46. * not be contained within the set of directories specified. For this reason, we have
  47. * "setDirectories", and then "setAdditionalModules", as the list of files should
  48. * be considered as being "in addition" to any directories we are watching.
  49. *
  50. * If either directories or files are invalid (not existing, not executable etc),
  51. * they are filtered out and ignored.
  52. */
  53. class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleDirectoryWatcher
  54. : public QObject
  55. {
  56. Q_OBJECT
  57. public:
  58. ctkCmdLineModuleDirectoryWatcher(ctkCmdLineModuleManager* moduleManager);
  59. virtual ~ctkCmdLineModuleDirectoryWatcher();
  60. /**
  61. * \brief Set the watcher into debug mode, for more output.
  62. * \param debug if true, you get more output, otherwise, less output.
  63. */
  64. void setDebug(bool debug);
  65. /**
  66. * \brief Set the directories to be watched.
  67. * \param directories a list of directory names. If any of these are
  68. * invalid, they will be filtered out and ignored.
  69. */
  70. void setDirectories(const QStringList& directories);
  71. /**
  72. * \brief Returns the list of directories currently being watched.
  73. */
  74. QStringList directories() const;
  75. /**
  76. * \brief Sets an additional list of command line executables to watch.
  77. * \param files a list of file names. If any of these file names are
  78. * not valid command line executables, they will be filtered out and ignored.
  79. */
  80. void setAdditionalModules(const QStringList& files);
  81. /**
  82. * \brief Gets the list of additional command line executable, where
  83. * "additional" means "in addition to those directories we are watching".
  84. */
  85. QStringList additionalModules() const;
  86. /**
  87. * \brief Returns the complete list of files (command line executables)
  88. * currently being watched.
  89. */
  90. QStringList commandLineModules() const;
  91. private:
  92. QScopedPointer<ctkCmdLineModuleDirectoryWatcherPrivate> d;
  93. Q_DISABLE_COPY(ctkCmdLineModuleDirectoryWatcher)
  94. };
  95. #endif // __ctkCmdLineModuleDirectoryWatcher_h