PowerComponent.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // Created by Tobias Hieta on 25/03/15.
  3. //
  4. #include "PowerComponent.h"
  5. #include "input/InputComponent.h"
  6. #include "settings/SettingsComponent.h"
  7. #ifdef Q_OS_MAC
  8. #include "PowerComponentMac.h"
  9. #elif defined(LINUX_DBUS)
  10. #include "PowerComponentDBus.h"
  11. #elif defined(USE_X11POWER)
  12. #include "PowerComponentX11.h"
  13. #elif defined(Q_OS_WIN32)
  14. #include "PowerComponentWin.h"
  15. #endif
  16. /////////////////////////////////////////////////////////////////////////////////////////
  17. PowerComponent& PowerComponent::Get()
  18. {
  19. #ifdef Q_OS_MAC
  20. static PowerComponentMac instance;
  21. return instance;
  22. #elif defined(LINUX_DBUS)
  23. static PowerComponentDBus instance;
  24. return instance;
  25. #elif defined(USE_X11POWER)
  26. static PowerComponentX11 instance;
  27. return instance;
  28. #elif defined(Q_OS_WIN32)
  29. static PowerComponentWin instance;
  30. return instance;
  31. #else
  32. qWarning() << "Could not find a power component matching this platform. OS screensaver control disabled.";
  33. static PowerComponent instance;
  34. return instance;
  35. #endif
  36. }
  37. /////////////////////////////////////////////////////////////////////////////////////////
  38. bool PowerComponent::componentInitialize()
  39. {
  40. return true;
  41. }
  42. /////////////////////////////////////////////////////////////////////////////////////////
  43. void PowerComponent::setScreensaverEnabled(bool enabled)
  44. {
  45. if (enabled)
  46. {
  47. qDebug() << "Enabling OS screensaver";
  48. doEnableScreensaver();
  49. }
  50. else
  51. {
  52. qDebug() << "Disabling OS screensaver";
  53. doDisableScreensaver();
  54. }
  55. }
  56. /////////////////////////////////////////////////////////////////////////////////////////
  57. void PowerComponent::componentPostInitialize()
  58. {
  59. InputComponent::Get().registerHostCommand("poweroff", this, "PowerOff");
  60. InputComponent::Get().registerHostCommand("reboot", this, "Reboot");
  61. InputComponent::Get().registerHostCommand("suspend", this, "Suspend");
  62. }
  63. /////////////////////////////////////////////////////////////////////////////////////////
  64. bool PowerComponent::checkCap(PowerCapabilities capability)
  65. {
  66. if (!SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "showPowerOptions").toBool())
  67. return false;
  68. return (getPowerCapabilities() & capability);
  69. }