Commit 333e8ef5 authored by David Edmundson's avatar David Edmundson
Browse files

Port logout greeter from KDElibs4Support

This also makes use of ksmserver a lot more optional. Requests to logout
go directly to org.plasma.Shutdown.

Effort has been put into keeping the QML context property usage API
compatiable even though the current code is really a mess.
parent 63e0ba2d
......@@ -14,12 +14,13 @@ target_link_libraries(ksmserver-logout-greeter
Qt5::Widgets
Qt5::Quick
Qt5::X11Extras
Qt5::DBus
KF5::Declarative
KF5::I18n
KF5::Package
KF5::QuickAddons
KF5::KDELibs4Support # Solid/PowerManagement
KF5::WaylandClient
KF5::WindowSystem
${X11_LIBRARIES}
)
install(TARGETS ksmserver-logout-greeter DESTINATION ${KDE_INSTALL_LIBEXECDIR})
......
......@@ -41,9 +41,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <KWayland/Client/registry.h>
#include <KWayland/Client/plasmashell.h>
Greeter::Greeter(bool shutdownAllowed)
Greeter::Greeter()
: QObject()
, m_shutdownAllowed(shutdownAllowed)
, m_waylandPlasmaShell(nullptr)
{
new LogoutPromptAdaptor(this);
......@@ -91,7 +90,7 @@ void Greeter::init()
void Greeter::adoptScreen(QScreen* screen)
{
// TODO: last argument is the theme, maybe add command line option for it?
KSMShutdownDlg *w = new KSMShutdownDlg(nullptr, m_shutdownAllowed, m_shutdownType, m_waylandPlasmaShell);
KSMShutdownDlg *w = new KSMShutdownDlg(nullptr, m_shutdownType, m_waylandPlasmaShell);
w->installEventFilter(this);
m_dialogs << w;
......@@ -100,9 +99,7 @@ void Greeter::adoptScreen(QScreen* screen)
w->deleteLater();
});
connect(w, &KSMShutdownDlg::rejected, this, &Greeter::rejected);
connect(w, &KSMShutdownDlg::accepted, this, [w]() {
OrgKdeKSMServerInterfaceInterface ksmserver(QStringLiteral("org.kde.ksmserver"), QStringLiteral("/KSMServer"), QDBusConnection::sessionBus());
ksmserver.logout(KWorkSpace::ShutdownConfirmNo, w->shutdownType(), KWorkSpace::ShutdownModeDefault);
connect(w, &KSMShutdownDlg::accepted, this, []() {
QApplication::exit(1);
});
w->setScreen(screen);
......
......@@ -43,7 +43,7 @@ class Greeter : public QObject
{
Q_OBJECT
public:
Greeter(bool shutdownAllowed);
Greeter();
~Greeter() override;
void init();
......@@ -60,7 +60,6 @@ private:
void rejected();
void setupWaylandIntegration();
bool m_shutdownAllowed;
bool m_running = false;
KWorkSpace::ShutdownType m_shutdownType = KWorkSpace::ShutdownTypeHalt;
......
......@@ -32,6 +32,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "greeter.h"
#include <sessionmanagement.h>
int main(int argc, char *argv[])
{
qunsetenv("SESSION_MANAGER");
......@@ -44,19 +46,28 @@ int main(int argc, char *argv[])
OrgKdeKSMServerInterfaceInterface ksmserver(QStringLiteral("org.kde.ksmserver"), QStringLiteral("/KSMServer"), QDBusConnection::sessionBus());
QDBusPendingReply<bool> isShuttingDownPending = ksmserver.isShuttingDown();
QDBusPendingReply<bool> canShutdownPending = ksmserver.canShutdown();
isShuttingDownPending.waitForFinished();
canShutdownPending.waitForFinished();
//if ksmserver is shutting us down already, we don't want another prompt
if (isShuttingDownPending.value()) {
return 0;
}
bool shutdownAllowed = canShutdownPending.value();
// because we export stuff as horrific contextProperties we need to know "maysd" may shutdown, at the time of initial creation and can't update
// later.
// Force the backend to load everything now, then the shared backend will be cached when a new object is created later
// TODO Plasma 6, just have the greeter QML import and use the SessionManagement object directly
// We don't need any special slot handling in ShutdownDlg
SessionManagement m_session;
if (m_session.state() == SessionManagement::State::Loading) {
QEventLoop e;
QObject::connect(&m_session, &SessionManagement::stateChanged, &e, &QEventLoop::quit);
e.exec();
}
Greeter greeter(shutdownAllowed);
Greeter greeter;
if (argc > 1) {
//special case, invoked from ksmserver from a former release which had a tonne of args
......
......@@ -48,7 +48,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <KAuthorized>
#include <KLocalizedString>
#include <KUser>
#include <Solid/PowerManagement>
#include <KWindowEffects>
#include <KWindowSystem>
#include <KDeclarative/KDeclarative>
......@@ -74,10 +73,8 @@ static const QString s_dbusPropertiesInterface = QStringLiteral("org.freedesktop
static const QString s_login1ManagerInterface = QStringLiteral("org.freedesktop.login1.Manager");
static const QString s_login1RebootToFirmwareSetup = QStringLiteral("RebootToFirmwareSetup");
Q_DECLARE_METATYPE(Solid::PowerManagement::SleepState)
KSMShutdownDlg::KSMShutdownDlg(QWindow* parent,
bool maysd, KWorkSpace::ShutdownType sdtype,
KWorkSpace::ShutdownType sdtype,
KWayland::Client::PlasmaShell *plasmaShell)
: QuickViewSharedEngine(parent),
m_result(false),
......@@ -107,7 +104,7 @@ KSMShutdownDlg::KSMShutdownDlg(QWindow* parent,
//QQuickView *windowContainer = QQuickView::createWindowContainer(m_view, this);
//windowContainer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
QQmlContext *context = rootContext();
context->setContextProperty(QStringLiteral("maysd"), maysd);
context->setContextProperty(QStringLiteral("maysd"), m_session.canShutdown());
context->setContextProperty(QStringLiteral("sdtype"), sdtype);
QQmlPropertyMap *mapShutdownType = new QQmlPropertyMap(this);
......@@ -119,12 +116,11 @@ KSMShutdownDlg::KSMShutdownDlg(QWindow* parent,
context->setContextProperty(QStringLiteral("ShutdownType"), mapShutdownType);
QQmlPropertyMap *mapSpdMethods = new QQmlPropertyMap(this);
QSet<Solid::PowerManagement::SleepState> spdMethods = Solid::PowerManagement::supportedSleepStates();
mapSpdMethods->insert(QStringLiteral("StandbyState"), QVariant::fromValue(spdMethods.contains(Solid::PowerManagement::StandbyState)));
mapSpdMethods->insert(QStringLiteral("SuspendState"), QVariant::fromValue(spdMethods.contains(Solid::PowerManagement::SuspendState)));
mapSpdMethods->insert(QStringLiteral("HibernateState"), QVariant::fromValue(spdMethods.contains(Solid::PowerManagement::HibernateState)));
mapSpdMethods->insert(QStringLiteral("StandbyState"), m_session.canSuspend());
mapSpdMethods->insert(QStringLiteral("SuspendState"), m_session.canSuspend());
mapSpdMethods->insert(QStringLiteral("HibernateState"), m_session.canHibernate());
context->setContextProperty(QStringLiteral("spdMethods"), mapSpdMethods);
context->setContextProperty(QStringLiteral("canLogout"), KAuthorized::authorize(QStringLiteral("logout")));
context->setContextProperty(QStringLiteral("canLogout"), m_session.canLogout());
// Trying to access a non-existent context property throws an error, always create the property and then update it later
context->setContextProperty("rebootToFirmwareSetup", false);
......@@ -273,7 +269,7 @@ void KSMShutdownDlg::setupWaylandIntegration()
void KSMShutdownDlg::slotLogout()
{
m_shutdownType = KWorkSpace::ShutdownTypeNone;
m_session.requestLogout();
accept();
}
......@@ -281,7 +277,7 @@ void KSMShutdownDlg::slotReboot()
{
// no boot option selected -> current
m_bootOption.clear();
m_shutdownType = KWorkSpace::ShutdownTypeReboot;
m_session.requestReboot();
accept();
}
......@@ -289,7 +285,7 @@ void KSMShutdownDlg::slotReboot(int opt)
{
if (int(rebootOptions.size()) > opt)
m_bootOption = rebootOptions[opt];
m_shutdownType = KWorkSpace::ShutdownTypeReboot;
m_session.requestReboot();
accept();
}
......@@ -297,11 +293,7 @@ void KSMShutdownDlg::slotReboot(int opt)
void KSMShutdownDlg::slotLockScreen()
{
m_bootOption.clear();
QDBusMessage call = QDBusMessage::createMethodCall(QStringLiteral("org.kde.screensaver"),
QStringLiteral("/ScreenSaver"),
QStringLiteral("org.freedesktop.ScreenSaver"),
QStringLiteral("Lock"));
QDBusConnection::sessionBus().asyncCall(call);
m_session.lock();
reject();
}
......@@ -316,12 +308,11 @@ void KSMShutdownDlg::slotSuspend(int spdMethod)
{
m_bootOption.clear();
switch (spdMethod) {
case Solid::PowerManagement::StandbyState:
case Solid::PowerManagement::SuspendState:
Solid::PowerManagement::requestSleep(Solid::PowerManagement::SuspendState, nullptr, nullptr);
break;
case Solid::PowerManagement::HibernateState:
Solid::PowerManagement::requestSleep(Solid::PowerManagement::HibernateState, nullptr, nullptr);
case 0: //Solid::PowerManagement::StandbyState:
case 1: //Solid::PowerManagement::SuspendState:
m_session.suspend();
case 2:// Solid::PowerManagement::HibernateState:
m_session.hibernate();
break;
}
reject();
......
......@@ -27,6 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <kquickaddons/quickviewsharedengine.h>
#include <kworkspace.h>
#include <sessionmanagement.h>
namespace KWayland
{
......@@ -43,15 +44,11 @@ class KSMShutdownDlg : public KQuickAddons::QuickViewSharedEngine
Q_OBJECT
public:
KSMShutdownDlg( QWindow* parent, bool maysd, KWorkSpace::ShutdownType sdtype, KWayland::Client::PlasmaShell *plasmaShell = nullptr );
KSMShutdownDlg( QWindow* parent, KWorkSpace::ShutdownType sdtype, KWayland::Client::PlasmaShell *plasmaShell = nullptr );
void init();
bool result() const;
KWorkSpace::ShutdownType shutdownType() const {
return m_shutdownType;
}
public Q_SLOTS:
void accept();
void reject();
......@@ -76,6 +73,7 @@ private:
QString m_bootOption;
QStringList rebootOptions;
bool m_result : 1;
SessionManagement m_session;
KWayland::Client::PlasmaShell *m_waylandPlasmaShell;
KWayland::Client::PlasmaShellSurface *m_shellSurface = nullptr;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment