PowerComponentMac.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "PowerComponentMac.h"
  2. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3. void PowerComponentMac::doDisableScreensaver()
  4. {
  5. if (m_assertion == 0)
  6. {
  7. CFStringRef why = CFSTR("tv.jellyfin.player");
  8. IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep,
  9. kIOPMAssertionLevelOn,
  10. why,
  11. &m_assertion);
  12. }
  13. }
  14. ///////////////////////////////////////////////////////////////////////////////////////////////////
  15. void PowerComponentMac::doEnableScreensaver()
  16. {
  17. if (m_assertion != 0)
  18. {
  19. IOPMAssertionRelease(m_assertion);
  20. m_assertion = 0;
  21. }
  22. }
  23. ///////////////////////////////////////////////////////////////////////////////////////////////////
  24. bool PowerComponentMac::PowerOff()
  25. {
  26. OSErr error = OSXUtils::SendAppleEventToSystemProcess(kAEShutDown);
  27. if (error == noErr)
  28. qDebug() << "Computer is going to shutdown!";
  29. else
  30. qDebug() << "Computer wouldn't shutdown!";
  31. return (error == noErr);
  32. }
  33. ///////////////////////////////////////////////////////////////////////////////////////////////////
  34. bool PowerComponentMac::Reboot()
  35. {
  36. OSErr error = OSXUtils::SendAppleEventToSystemProcess(kAERestart);
  37. if (error == noErr)
  38. qDebug() << "Computer is going to reboot!";
  39. else
  40. qDebug() << "Computer wouldn't reboot!";
  41. return (error == noErr);
  42. }
  43. ///////////////////////////////////////////////////////////////////////////////////////////////////
  44. bool PowerComponentMac::Suspend()
  45. {
  46. OSErr error = OSXUtils::SendAppleEventToSystemProcess(kAESleep);
  47. if (error == noErr)
  48. qDebug() << "Computer is going to sleep!";
  49. else
  50. qDebug() << "Computer wouldn't sleep!";
  51. return (error == noErr);
  52. }