From e311239a2850cda506173fc0f3be0556bc9c55d3 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 16 Aug 2010 17:42:21 +0000 Subject: [PATCH] Blind implementation of auto-shutdown for Mac OS --- src/misc.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index 11ea0b878..02722285f 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -124,7 +124,7 @@ QString misc::QDesktopServicesCacheLocation() { QString path; QByteArray ba(2048, 0); if (FSRefMakePath(&ref, reinterpret_cast(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(); return path; #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()); computer.call("Shutdown"); #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 t) { @@ -390,7 +428,7 @@ QPoint misc::screenCenter(QWidget *win) { QString misc::searchEngineLocation() { const QString location = QDir::cleanPath(QDesktopServicesDataLocation() - + QDir::separator() + "search_engine"); + + QDir::separator() + "search_engine"); QDir locationDir(location); if(!locationDir.exists()) locationDir.mkpath(locationDir.absolutePath()); @@ -399,7 +437,7 @@ QString misc::searchEngineLocation() { QString misc::BTBackupLocation() { const QString location = QDir::cleanPath(QDesktopServicesDataLocation() - + QDir::separator() + "BT_backup"); + + QDir::separator() + "BT_backup"); QDir locationDir(location); if(!locationDir.exists()) locationDir.mkpath(locationDir.absolutePath()); @@ -639,11 +677,11 @@ QList misc::intListfromStringList(const QStringList &l) { QList misc::boolListfromStringList(const QStringList &l) { QList ret; - foreach(const QString &s, l) { - if(s == "1") - ret << true; - else - ret << false; - } - return ret; + foreach(const QString &s, l) { + if(s == "1") + ret << true; + else + ret << false; + } + return ret; }