File indexing completed on 2024-04-28 16:54:46
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 "greeter.h" 0019 0020 #include <sessionmanagement.h> 0021 0022 int main(int argc, char *argv[]) 0023 { 0024 qunsetenv("SESSION_MANAGER"); 0025 0026 auto format = QSurfaceFormat::defaultFormat(); 0027 format.setOption(QSurfaceFormat::ResetNotification); 0028 QSurfaceFormat::setDefaultFormat(format); 0029 0030 KWorkSpace::detectPlatform(argc, argv); 0031 QQuickWindow::setDefaultAlphaBuffer(true); 0032 QGuiApplication app(argc, argv); 0033 0034 // If we're already shutting down we don't need another prompt 0035 if (QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.Shutdown")) { 0036 return 0; 0037 } 0038 0039 bool windowed = false; 0040 KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE"); 0041 QString packageName = cg.readEntry("LookAndFeelPackage", QString()); 0042 { 0043 QCommandLineParser parser; 0044 QCommandLineOption testingOption("windowed", "have the dialog show, windowed, regardless of the session state"); 0045 QCommandLineOption lnfOption("lookandfeel", "The look and feel package name to use", "name", packageName); 0046 parser.addOption(testingOption); 0047 parser.addOption(lnfOption); 0048 parser.addHelpOption(); 0049 parser.process(app); 0050 windowed = parser.isSet(testingOption); 0051 if (parser.isSet(lnfOption)) { 0052 packageName = parser.value(lnfOption); 0053 } 0054 } 0055 0056 // because we export stuff as horrific contextProperties we need to know "maysd" may shutdown, at the time of initial creation and can't update 0057 // later. 0058 // Force the backend to load everything now, then the shared backend will be cached when a new object is created later 0059 0060 // TODO Plasma 6, just have the greeter QML import and use the SessionManagement object directly 0061 // We don't need any special slot handling in ShutdownDlg 0062 SessionManagement m_session; 0063 if (m_session.state() == SessionManagement::State::Loading) { 0064 QEventLoop e; 0065 QObject::connect(&m_session, &SessionManagement::stateChanged, &e, &QEventLoop::quit); 0066 e.exec(); 0067 } 0068 0069 const auto pkg = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"), packageName); 0070 Greeter greeter(pkg); 0071 if (windowed) { 0072 greeter.enableWindowed(); 0073 } 0074 0075 return app.exec(); 0076 }