Call Windows API directly

We already bumped the OS requirement to Windows 7 and those functions
can be called directly without the need to load them first.
This commit is contained in:
Chocobo1 2019-09-28 15:46:26 +08:00
parent 975b44d05f
commit 7276a79cef
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
5 changed files with 15 additions and 39 deletions

View file

@ -30,6 +30,7 @@
#ifdef Q_OS_WIN
#include <windows.h>
#include <powrprof.h>
#include <Shlobj.h>
#else
#include <sys/types.h>
@ -117,16 +118,11 @@ void Utils::Misc::shutdownComputer(const ShutdownDialogAction &action)
if (GetLastError() != ERROR_SUCCESS)
return;
using PSETSUSPENDSTATE = BOOLEAN (WINAPI *)(BOOLEAN, BOOLEAN, BOOLEAN);
const auto setSuspendState = Utils::Misc::loadWinAPI<PSETSUSPENDSTATE>("PowrProf.dll", "SetSuspendState");
if (action == ShutdownDialogAction::Suspend) {
if (setSuspendState)
setSuspendState(false, false, false);
::SetSuspendState(false, false, false);
}
else if (action == ShutdownDialogAction::Hibernate) {
if (setSuspendState)
setSuspendState(true, false, false);
::SetSuspendState(true, false, false);
}
else {
const QString msg = QCoreApplication::translate("misc", "qBittorrent will shutdown the computer now because all downloads are complete.");