ComponentManager.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <QObject>
  2. #include <QtQml>
  3. #include <qqmlwebchannel.h>
  4. #include <QDebug>
  5. #include "ComponentManager.h"
  6. #include "power/PowerComponent.h"
  7. #include "input/InputComponent.h"
  8. #include "player/PlayerComponent.h"
  9. #include "display/DisplayComponent.h"
  10. #include "system/SystemComponent.h"
  11. #include "settings/SettingsComponent.h"
  12. #include "taskbar/TaskbarComponent.h"
  13. #if KONVERGO_OPENELEC
  14. #include "system/openelec/OESystemComponent.h"
  15. #endif
  16. ///////////////////////////////////////////////////////////////////////////////////////////////////
  17. ComponentManager::ComponentManager() : QObject(nullptr)
  18. {
  19. }
  20. ///////////////////////////////////////////////////////////////////////////////////////////////////
  21. void ComponentManager::registerComponent(ComponentBase* comp)
  22. {
  23. if (m_components.contains(comp->componentName()))
  24. {
  25. qCritical() << "Component" << comp->componentName() << "already registered!";
  26. return;
  27. }
  28. if (comp->componentInitialize())
  29. {
  30. qInfo() << "Component:" << comp->componentName() << "inited";
  31. m_components[comp->componentName()] = comp;
  32. // define component as property for qml
  33. m_qmlProperyMap.insert(comp->componentName(), QVariant::fromValue(comp));
  34. }
  35. else
  36. {
  37. qCritical() << "Failed to init component:" << comp->componentName();
  38. }
  39. }
  40. ///////////////////////////////////////////////////////////////////////////////////////////////////
  41. void ComponentManager::initialize()
  42. {
  43. // then settings, since all other components
  44. // might have some settings
  45. //
  46. registerComponent(&SettingsComponent::Get());
  47. registerComponent(&InputComponent::Get());
  48. registerComponent(&SystemComponent::Get());
  49. registerComponent(&DisplayComponent::Get());
  50. registerComponent(&PlayerComponent::Get());
  51. registerComponent(&PowerComponent::Get());
  52. registerComponent(&TaskbarComponent::Get());
  53. #if KONVERGO_OPENELEC
  54. registerComponent(&OESystemComponent::Get());
  55. #endif
  56. for(ComponentBase* component : m_components.values())
  57. component->componentPostInitialize();
  58. }
  59. /////////////////////////////////////////////////////////////////////////////////////////
  60. void ComponentManager::setWebChannel(QWebChannel* webChannel)
  61. {
  62. for(ComponentBase* comp : m_components.values())
  63. {
  64. if (comp->componentExport())
  65. {
  66. qDebug() << "Adding component:" << comp->componentName() << "to webchannel";
  67. webChannel->registerObject(comp->componentName(), comp);
  68. }
  69. }
  70. }