ctkPluginEvent.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #include "ctkPluginEvent.h"
  16. #include "ctkPlugin.h"
  17. #include <QDebug>
  18. class ctkPluginEventData : public QSharedData
  19. {
  20. public:
  21. ctkPluginEventData(ctkPluginEvent::Type type, QSharedPointer<ctkPlugin> plugin)
  22. : type(type), plugin(plugin)
  23. {
  24. }
  25. ctkPluginEventData(const ctkPluginEventData& other)
  26. : QSharedData(other), type(other.type), plugin(other.plugin)
  27. {
  28. }
  29. const ctkPluginEvent::Type type;
  30. const QSharedPointer<ctkPlugin> plugin;
  31. };
  32. //----------------------------------------------------------------------------
  33. ctkPluginEvent::ctkPluginEvent()
  34. : d(0)
  35. {
  36. }
  37. //----------------------------------------------------------------------------
  38. ctkPluginEvent::~ctkPluginEvent()
  39. {
  40. }
  41. //----------------------------------------------------------------------------
  42. bool ctkPluginEvent::isNull() const
  43. {
  44. return !d;
  45. }
  46. //----------------------------------------------------------------------------
  47. ctkPluginEvent::ctkPluginEvent(Type type, QSharedPointer<ctkPlugin> plugin)
  48. : d(new ctkPluginEventData(type, plugin))
  49. {
  50. }
  51. //----------------------------------------------------------------------------
  52. ctkPluginEvent::ctkPluginEvent(const ctkPluginEvent& other)
  53. : d(other.d)
  54. {
  55. }
  56. //----------------------------------------------------------------------------
  57. ctkPluginEvent& ctkPluginEvent::operator=(const ctkPluginEvent& other)
  58. {
  59. d = other.d;
  60. return *this;
  61. }
  62. //----------------------------------------------------------------------------
  63. QSharedPointer<ctkPlugin> ctkPluginEvent::getPlugin() const
  64. {
  65. return d->plugin;
  66. }
  67. //----------------------------------------------------------------------------
  68. ctkPluginEvent::Type ctkPluginEvent::getType() const
  69. {
  70. return d->type;
  71. }
  72. //----------------------------------------------------------------------------
  73. QDebug operator<<(QDebug debug, ctkPluginEvent::Type eventType)
  74. {
  75. switch (eventType)
  76. {
  77. case ctkPluginEvent::INSTALLED: return debug << "INSTALLED";
  78. case ctkPluginEvent::STARTED: return debug << "STARTED";
  79. case ctkPluginEvent::STOPPED: return debug << "STOPPED";
  80. case ctkPluginEvent::UPDATED: return debug << "UPDATED";
  81. case ctkPluginEvent::UNINSTALLED: return debug << "UNINSTALLED";
  82. case ctkPluginEvent::RESOLVED: return debug << "RESOLVED";
  83. case ctkPluginEvent::UNRESOLVED: return debug << "UNRESOLVED";
  84. case ctkPluginEvent::STARTING: return debug << "STARTING";
  85. case ctkPluginEvent::STOPPING: return debug << "STOPPING";
  86. case ctkPluginEvent::LAZY_ACTIVATION: return debug << "LAZY_ACTIVATION";
  87. default: return debug << "Unknown plugin event type (" << static_cast<int>(eventType) << ")";
  88. }
  89. }
  90. //----------------------------------------------------------------------------
  91. QDebug operator<<(QDebug debug, const ctkPluginEvent& event)
  92. {
  93. if (event.isNull()) return debug << "NONE";
  94. QSharedPointer<ctkPlugin> p = event.getPlugin();
  95. debug.nospace() << event.getType() << " #" << p->getPluginId() << " (" << p->getLocation() << ")";
  96. return debug.maybeSpace();
  97. }