diff -up kdebase-workspace-4.2.85/libs/kworkspace/kdisplaymanager.cpp.ck-shutdown kdebase-workspace-4.2.85/libs/kworkspace/kdisplaymanager.cpp --- kdebase-workspace-4.2.85/libs/kworkspace/kdisplaymanager.cpp.ck-shutdown 2009-04-28 15:46:11.000000000 +0200 +++ kdebase-workspace-4.2.85/libs/kworkspace/kdisplaymanager.cpp 2009-05-11 22:49:41.000000000 +0200 @@ -26,6 +26,7 @@ #include <QtDBus/QtDBus> #include <QRegExp> +#include <QLatin1String> #include <X11/Xauth.h> #include <X11/Xlib.h> @@ -85,6 +86,7 @@ KDisplayManager::KDisplayManager() : d(n strcpy( sa.sun_path, "/tmp/.gdm_socket" ); if (::connect( d->fd, (struct sockaddr *)&sa, sizeof(sa) )) { ::close( d->fd ); + DMType = NoDM; d->fd = -1; break; } @@ -186,6 +188,21 @@ KDisplayManager::exec( const char *cmd, bool KDisplayManager::canShutdown() { + if (DMType == NoDM) { + // No DM or newest GDM running, we'll try shutting down through ConsoleKit. + // Unfortunately, ConsoleKit won't tell us if we're allowed to do that + // (it also depends on whether there are other users logged in on the + // system), so we can only check if it's running at all. + QDBusConnection systemBus = QDBusConnection::systemBus(); + if (!systemBus.isConnected()) + return false; + QDBusInterface consoleKit( QLatin1String( "org.freedesktop.ConsoleKit" ), + QLatin1String( "/org/freedesktop/ConsoleKit/Manager" ), + QLatin1String( "org.freedesktop.ConsoleKit.Manager" ), + systemBus ); + return consoleKit.isValid(); + } + if (DMType == OldKDM) return strstr( ctl, ",maysd" ) != 0; @@ -205,6 +222,21 @@ KDisplayManager::shutdown( KWorkSpace::S if (shutdownType == KWorkSpace::ShutdownTypeNone || shutdownType == KWorkSpace::ShutdownTypeLogout) return; + if (DMType == NoDM) { + // No DM or newest GDM running, try shutting down through ConsoleKit. + QDBusConnection systemBus = QDBusConnection::systemBus(); + if (!systemBus.isConnected()) + return; + QDBusInterface consoleKit( QLatin1String( "org.freedesktop.ConsoleKit" ), + QLatin1String( "/org/freedesktop/ConsoleKit/Manager" ), + QLatin1String( "org.freedesktop.ConsoleKit.Manager" ), + systemBus ); + if (consoleKit.isValid()) + consoleKit.call( QLatin1String( shutdownType == KWorkSpace::ShutdownTypeReboot ? + "Restart" : "Stop" ) ); + return; + } + bool cap_ask; if (DMType == NewKDM) { QByteArray re;