PowerComponent.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef POWERMANAGER
  2. #define POWERMANAGER
  3. #include <QDebug>
  4. #include "ComponentManager.h"
  5. class PowerComponent : public ComponentBase
  6. {
  7. Q_OBJECT
  8. public:
  9. enum PowerCapabilities
  10. {
  11. CAP_POWER_OFF = 0x01,
  12. CAP_REBOOT = 0x02,
  13. CAP_SUSPEND = 0x04,
  14. CAP_RELAUNCH = 0x08
  15. };
  16. static PowerComponent& Get();
  17. explicit PowerComponent(QObject* parent = nullptr)
  18. : ComponentBase(parent)
  19. { }
  20. bool componentInitialize() override;
  21. bool componentExport() override { return true; }
  22. const char* componentName() override { return "power"; }
  23. void componentPostInitialize() override;
  24. public Q_SLOTS:
  25. bool checkCap(PowerCapabilities capability);
  26. bool canPowerOff() { return checkCap(CAP_POWER_OFF); }
  27. bool canReboot() { return checkCap(CAP_REBOOT); }
  28. bool canSuspend() { return checkCap(CAP_SUSPEND); }
  29. bool canRelaunch()
  30. {
  31. #if OPENELEC
  32. return true;
  33. #else
  34. return false;
  35. #endif
  36. }
  37. virtual int getPowerCapabilities() { return 0; }
  38. virtual bool PowerOff() { return false; }
  39. virtual bool Reboot() { return false; }
  40. virtual bool Suspend() { return false; }
  41. void setScreensaverEnabled(bool enabled);
  42. Q_SIGNALS:
  43. // Short-term compatibility with old web-client. Does nothing.
  44. void screenSaverEnabled();
  45. void screenSaverDisabled();
  46. protected:
  47. virtual void doDisableScreensaver() {};
  48. virtual void doEnableScreensaver() {};
  49. };
  50. #endif // POWERMANAGER