#include <QtCore/QCoreApplication>#include <QtCore/QTimer>#include <QtDBus/QtDBus>#define SERVICE_NAME "org.freedesktop.ConsoleKit.Manager"//#define SERVICE_NAME "org.freedesktop.ScreenSaver"int main(int argc, char **argv){ QCoreApplication app(argc, argv); // Создаем соединение с системной шиной D-Bus QDBusConnection conn = QDBusConnection::systemBus(); if (!conn.isConnected()) { qDebug() << "Err: isConnected systemBus"; return 1; } if (!conn.registerService(SERVICE_NAME)) { qDebug() << "Err: registerService"; exit(1); } QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.ConsoleKit.Manager", "/Manager", "org.freedesktop.ConsoleKit.Manager", "Stop");// QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.ScreenSaver",// "/ScreenSaver",// "org.freedesktop.ScreenSaver",// "Lock"); conn.systemBus().send(msg); return 0;}
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"><busconfig> <policy context="default"> <allow own="org.freedesktop.ConsoleKit.Manager"/> <allow send_destination="org.freedesktop.ConsoleKit.Manager"/> <allow receive_sender ="org.freedesktop.ConsoleKit.Manager"/> </policy></busconfig>
dbus-send --system --print-reply --dest="org.freedesktop.Hal" /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop
QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.ScreenSaver", [b]"/ScreenSaver",[/b] "org.freedesktop.ScreenSaver", "Lock");
C++ (Qt)QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", "Stop");
C++ (Qt) QDBusInterface remoteApp("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus()); remoteApp.call("Stop"); // нужно ещё проверить ответ если он есть и вывести ошибку если есть