mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-28 15:34:16 +00:00
Blind implementation of auto-shutdown for Mac OS
This commit is contained in:
parent
df677789d2
commit
e311239a28
58
src/misc.cpp
58
src/misc.cpp
@ -124,7 +124,7 @@ QString misc::QDesktopServicesCacheLocation() {
|
|||||||
QString path;
|
QString path;
|
||||||
QByteArray ba(2048, 0);
|
QByteArray ba(2048, 0);
|
||||||
if (FSRefMakePath(&ref, reinterpret_cast<UInt8 *>(ba.data()), ba.size()) == noErr)
|
if (FSRefMakePath(&ref, reinterpret_cast<UInt8 *>(ba.data()), ba.size()) == noErr)
|
||||||
path = QString::fromUtf8(ba).normalized(QString::NormalizationForm_C);
|
path = QString::fromUtf8(ba).normalized(QString::NormalizationForm_C);
|
||||||
path += QLatin1Char('/') + qApp->applicationName();
|
path += QLatin1Char('/') + qApp->applicationName();
|
||||||
return path;
|
return path;
|
||||||
#else
|
#else
|
||||||
@ -196,6 +196,44 @@ void misc::shutdownComputer() {
|
|||||||
QDBusInterface computer("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device.SystemPowerManagement", QDBusConnection::systemBus());
|
QDBusInterface computer("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device.SystemPowerManagement", QDBusConnection::systemBus());
|
||||||
computer.call("Shutdown");
|
computer.call("Shutdown");
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef Q_WS_MAC
|
||||||
|
AEEventID EventToSend = kAEShutDown;
|
||||||
|
AEAddressDesc targetDesc;
|
||||||
|
static const ProcessSerialNumber kPSNOfSystemProcess = { 0, kSystemProcess };
|
||||||
|
AppleEvent eventReply = {typeNull, NULL};
|
||||||
|
AppleEvent appleEventToSend = {typeNull, NULL};
|
||||||
|
|
||||||
|
OSStatus error = noErr;
|
||||||
|
|
||||||
|
error = AECreateDesc(typeProcessSerialNumber, &kPSNOfSystemProcess,
|
||||||
|
sizeof(kPSNOfSystemProcess), &targetDesc);
|
||||||
|
|
||||||
|
if (error != noErr)
|
||||||
|
{
|
||||||
|
return(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
error = AECreateAppleEvent(kCoreEventClass, EventToSend, &targetDesc,
|
||||||
|
kAutoGenerateReturnID, kAnyTransactionID, &appleEventToSend);
|
||||||
|
|
||||||
|
AEDisposeDesc(&targetDesc);
|
||||||
|
if (error != noErr)
|
||||||
|
{
|
||||||
|
return(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
error = AESend(&appleEventToSend, &eventReply, kAENoReply,
|
||||||
|
kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
|
||||||
|
|
||||||
|
AEDisposeDesc(&appleEventToSend);
|
||||||
|
if (error != noErr)
|
||||||
|
{
|
||||||
|
return(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
AEDisposeDesc(&eventReply);
|
||||||
|
#endif
|
||||||
|
// TODO: Windows support
|
||||||
}
|
}
|
||||||
|
|
||||||
QString misc::truncateRootFolder(boost::intrusive_ptr<torrent_info> t) {
|
QString misc::truncateRootFolder(boost::intrusive_ptr<torrent_info> t) {
|
||||||
@ -390,7 +428,7 @@ QPoint misc::screenCenter(QWidget *win) {
|
|||||||
|
|
||||||
QString misc::searchEngineLocation() {
|
QString misc::searchEngineLocation() {
|
||||||
const QString location = QDir::cleanPath(QDesktopServicesDataLocation()
|
const QString location = QDir::cleanPath(QDesktopServicesDataLocation()
|
||||||
+ QDir::separator() + "search_engine");
|
+ QDir::separator() + "search_engine");
|
||||||
QDir locationDir(location);
|
QDir locationDir(location);
|
||||||
if(!locationDir.exists())
|
if(!locationDir.exists())
|
||||||
locationDir.mkpath(locationDir.absolutePath());
|
locationDir.mkpath(locationDir.absolutePath());
|
||||||
@ -399,7 +437,7 @@ QString misc::searchEngineLocation() {
|
|||||||
|
|
||||||
QString misc::BTBackupLocation() {
|
QString misc::BTBackupLocation() {
|
||||||
const QString location = QDir::cleanPath(QDesktopServicesDataLocation()
|
const QString location = QDir::cleanPath(QDesktopServicesDataLocation()
|
||||||
+ QDir::separator() + "BT_backup");
|
+ QDir::separator() + "BT_backup");
|
||||||
QDir locationDir(location);
|
QDir locationDir(location);
|
||||||
if(!locationDir.exists())
|
if(!locationDir.exists())
|
||||||
locationDir.mkpath(locationDir.absolutePath());
|
locationDir.mkpath(locationDir.absolutePath());
|
||||||
@ -639,11 +677,11 @@ QList<int> misc::intListfromStringList(const QStringList &l) {
|
|||||||
|
|
||||||
QList<bool> misc::boolListfromStringList(const QStringList &l) {
|
QList<bool> misc::boolListfromStringList(const QStringList &l) {
|
||||||
QList<bool> ret;
|
QList<bool> ret;
|
||||||
foreach(const QString &s, l) {
|
foreach(const QString &s, l) {
|
||||||
if(s == "1")
|
if(s == "1")
|
||||||
ret << true;
|
ret << true;
|
||||||
else
|
else
|
||||||
ret << false;
|
ret << false;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user