File indexing completed on 2024-05-05 05:38:40

0001 /*
0002     ksmserver - the KDE session management server
0003 
0004     SPDX-FileCopyrightText: 2016 Martin Graesslin <mgraesslin@kde.org>
0005 
0006     SPDX-License-Identifier: MIT
0007 */
0008 #include <KConfigGroup>
0009 #include <KSharedConfig>
0010 #include <QApplication>
0011 #include <QCommandLineParser>
0012 #include <QDBusConnection>
0013 #include <QDBusConnectionInterface>
0014 #include <QLibraryInfo>
0015 #include <QQuickWindow>
0016 #include <QSurfaceFormat>
0017 
0018 #include "debug.h"
0019 #include "greeter.h"
0020 
0021 #include <sessionmanagement.h>
0022 
0023 using namespace Qt::StringLiterals;
0024 
0025 int main(int argc, char *argv[])
0026 {
0027     qunsetenv("SESSION_MANAGER");
0028 
0029     auto format = QSurfaceFormat::defaultFormat();
0030     format.setOption(QSurfaceFormat::ResetNotification);
0031     QSurfaceFormat::setDefaultFormat(format);
0032 
0033     QQuickWindow::setDefaultAlphaBuffer(true);
0034     QGuiApplication app(argc, argv);
0035 
0036     bool windowed = false;
0037     KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), u"KDE"_s);
0038     QString packageName = cg.readEntry("LookAndFeelPackage", QString());
0039     {
0040         QCommandLineParser parser;
0041         QCommandLineOption testingOption("windowed", "have the dialog show, windowed, regardless of the session state");
0042         QCommandLineOption lnfOption("lookandfeel", "The look and feel package name to use", "name", packageName);
0043         parser.addOption(testingOption);
0044         parser.addOption(lnfOption);
0045         parser.addHelpOption();
0046         parser.process(app);
0047         windowed = parser.isSet(testingOption);
0048         if (parser.isSet(lnfOption)) {
0049             packageName = parser.value(lnfOption);
0050         }
0051     }
0052 
0053     // because we export stuff as horrific contextProperties we need to know "maysd" may shutdown, at the time of initial creation and can't update
0054     // later.
0055     // Force the backend to load everything now, then the shared backend will be cached when a new object is created later
0056 
0057     // TODO Plasma 6, just have the greeter QML import and use the SessionManagement object directly
0058     // We don't need any special slot handling in ShutdownDlg
0059     SessionManagement m_session;
0060     if (m_session.state() == SessionManagement::State::Loading) {
0061         QEventLoop e;
0062         QObject::connect(&m_session, &SessionManagement::stateChanged, &e, &QEventLoop::quit);
0063         e.exec();
0064     }
0065 
0066     const auto pkg = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"), packageName);
0067 
0068     if (!pkg.isValid()) {
0069         qCWarning(LOGOUT_GREETER) << "Failed to load lookandfeel package" << packageName;
0070     }
0071 
0072     Greeter greeter(pkg);
0073     if (windowed) {
0074         greeter.enableWindowed();
0075     }
0076 
0077     return app.exec();
0078 }