Browse Source

Use dynamic linking for SetSuspendState function

adaptive-webui-19844
Chocobo1 7 years ago
parent
commit
644e7d0450
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 19
      src/base/utils/misc.cpp
  2. 8
      winconf.pri

19
src/base/utils/misc.cpp

@ -35,7 +35,6 @@
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <windows.h> #include <windows.h>
#include <powrprof.h>
#include <Shlobj.h> #include <Shlobj.h>
#else #else
#include <sys/types.h> #include <sys/types.h>
@ -113,12 +112,20 @@ void Utils::Misc::shutdownComputer(const ShutdownDialogAction &action)
if (GetLastError() != ERROR_SUCCESS) if (GetLastError() != ERROR_SUCCESS)
return; return;
if (action == ShutdownDialogAction::Suspend) using PSETSUSPENDSTATE = BOOLEAN (WINAPI *)(BOOLEAN, BOOLEAN, BOOLEAN);
SetSuspendState(false, false, false); const auto setSuspendState = Utils::Misc::loadWinAPI<PSETSUSPENDSTATE>("PowrProf.dll", "SetSuspendState");
else if (action == ShutdownDialogAction::Hibernate)
SetSuspendState(true, false, false); if (action == ShutdownDialogAction::Suspend) {
else if (setSuspendState)
setSuspendState(false, false, false);
}
else if (action == ShutdownDialogAction::Hibernate) {
if (setSuspendState)
setSuspendState(true, false, false);
}
else {
InitiateSystemShutdownA(0, QCoreApplication::translate("misc", "qBittorrent will shutdown the computer now because all downloads are complete.").toLocal8Bit().data(), 10, true, false); InitiateSystemShutdownA(0, QCoreApplication::translate("misc", "qBittorrent will shutdown the computer now because all downloads are complete.").toLocal8Bit().data(), 10, true, false);
}
// Disable shutdown privilege. // Disable shutdown privilege.
tkp.Privileges[0].Attributes = 0; tkp.Privileges[0].Attributes = 0;

8
winconf.pri

@ -33,8 +33,8 @@ win32-g++* {
} }
RC_FILE = qbittorrent_mingw.rc RC_FILE = qbittorrent_mingw.rc
LIBS += libadvapi32 libshell32 libuser32 libole32 libwsock32 libws2_32 libpowrprof LIBS += libadvapi32 libshell32 libuser32 libole32 libwsock32 libws2_32
} }
else:win32-msvc* { else:win32-msvc* {
CONFIG -= embed_manifest_exe CONFIG -= embed_manifest_exe
@ -42,8 +42,8 @@ else:win32-msvc* {
QMAKE_LFLAGS_RELEASE += "/OPT:REF /OPT:ICF" QMAKE_LFLAGS_RELEASE += "/OPT:REF /OPT:ICF"
RC_FILE = qbittorrent.rc RC_FILE = qbittorrent.rc
LIBS += advapi32.lib shell32.lib crypt32.lib User32.lib ole32.lib PowrProf.lib LIBS += advapi32.lib shell32.lib crypt32.lib User32.lib ole32.lib
} }
# See an example build configuration in "conf.pri.windows" # See an example build configuration in "conf.pri.windows"

Loading…
Cancel
Save