PowerComponentDBus.h 899 B

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef POWERCOMPONENTDBUS_H
  2. #define POWERCOMPONENTDBUS_H
  3. #include "PowerComponent.h"
  4. class PowerComponentDBus : public PowerComponent
  5. {
  6. public:
  7. PowerComponentDBus() : PowerComponent(0) {};
  8. ~PowerComponentDBus() {};
  9. public Q_SLOTS:
  10. virtual int getPowerCapabilities() override
  11. {
  12. int flags = 0;
  13. if (isPowerMethodAvailable("CanPowerOff"))
  14. flags |= CAP_POWER_OFF;
  15. if (isPowerMethodAvailable("CanReboot"))
  16. flags |= CAP_REBOOT;
  17. if (isPowerMethodAvailable("CanSuspend"))
  18. flags |= CAP_SUSPEND;
  19. return flags;
  20. }
  21. virtual bool PowerOff() { return callPowerMethod("PowerOff"); }
  22. virtual bool Reboot() { return callPowerMethod("Reboot"); }
  23. virtual bool Suspend() { return callPowerMethod("Suspend"); }
  24. private:
  25. bool callPowerMethod(QString method);
  26. bool isPowerMethodAvailable(QString method);
  27. };
  28. #endif // POWERCOMPONENTDBUS_H