Changeset View
Changeset View
Standalone View
Standalone View
shell/main.cpp
Show All 18 Lines | |||||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include <QApplication> | 21 | #include <QApplication> | ||
22 | #include <QCommandLineParser> | 22 | #include <QCommandLineParser> | ||
23 | #include <QQuickWindow> | 23 | #include <QQuickWindow> | ||
24 | #include <QSessionManager> | 24 | #include <QSessionManager> | ||
25 | #include <QDebug> | 25 | #include <QDebug> | ||
26 | #include <QMessageBox> | 26 | #include <QMessageBox> | ||
27 | #include <QDBusConnection> | ||||
28 | #include <QDBusMessage> | ||||
27 | 29 | | |||
28 | #include <KAboutData> | 30 | #include <KAboutData> | ||
29 | #include <KQuickAddons/QtQuickSettings> | 31 | #include <KQuickAddons/QtQuickSettings> | ||
30 | 32 | | |||
31 | #include <kdbusservice.h> | 33 | #include <kdbusservice.h> | ||
32 | #include <klocalizedstring.h> | 34 | #include <klocalizedstring.h> | ||
33 | #include <kcrash.h> | 35 | #include <kcrash.h> | ||
34 | #include <kworkspace.h> | 36 | #include <kworkspace.h> | ||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 46 | { | |||
97 | 99 | | |||
98 | QCommandLineOption shellPluginOption(QStringList() << QStringLiteral("p") << QStringLiteral("shell-plugin"), | 100 | QCommandLineOption shellPluginOption(QStringList() << QStringLiteral("p") << QStringLiteral("shell-plugin"), | ||
99 | i18n("Force loading the given shell plugin"), | 101 | i18n("Force loading the given shell plugin"), | ||
100 | QStringLiteral("plugin")); | 102 | QStringLiteral("plugin")); | ||
101 | 103 | | |||
102 | QCommandLineOption standaloneOption(QStringList() << QStringLiteral("a") << QStringLiteral("standalone"), | 104 | QCommandLineOption standaloneOption(QStringList() << QStringLiteral("a") << QStringLiteral("standalone"), | ||
103 | i18n("Load plasmashell as a standalone application, needs the shell-plugin option to be specified")); | 105 | i18n("Load plasmashell as a standalone application, needs the shell-plugin option to be specified")); | ||
104 | 106 | | |||
107 | QCommandLineOption replaceOption({QStringLiteral("replace")}, | ||||
apol: QStringList() is not necessary. | |||||
108 | i18n("Replace an existing instance")); | ||||
105 | 109 | | |||
106 | QCommandLineOption testOption(QStringList() << QStringLiteral("test"), | 110 | QCommandLineOption testOption(QStringList() << QStringLiteral("test"), | ||
107 | i18n("Enables test mode and specifies the layout javascript file to set up the testing environment"), i18n("file"), QStringLiteral("layout.js")); | 111 | i18n("Enables test mode and specifies the layout javascript file to set up the testing environment"), i18n("file"), QStringLiteral("layout.js")); | ||
108 | 112 | | |||
109 | cliOptions.addOption(dbgOption); | 113 | cliOptions.addOption(dbgOption); | ||
110 | cliOptions.addOption(noRespawnOption); | 114 | cliOptions.addOption(noRespawnOption); | ||
111 | cliOptions.addOption(shellPluginOption); | 115 | cliOptions.addOption(shellPluginOption); | ||
112 | cliOptions.addOption(standaloneOption); | 116 | cliOptions.addOption(standaloneOption); | ||
113 | cliOptions.addOption(testOption); | 117 | cliOptions.addOption(testOption); | ||
118 | cliOptions.addOption(replaceOption); | ||||
114 | 119 | | |||
115 | aboutData.setupCommandLine(&cliOptions); | 120 | aboutData.setupCommandLine(&cliOptions); | ||
116 | cliOptions.process(app); | 121 | cliOptions.process(app); | ||
117 | aboutData.processCommandLine(&cliOptions); | 122 | aboutData.processCommandLine(&cliOptions); | ||
118 | 123 | | |||
119 | QGuiApplication::setFallbackSessionManagementEnabled(false); | 124 | QGuiApplication::setFallbackSessionManagementEnabled(false); | ||
120 | 125 | | |||
121 | auto disableSessionManagement = [](QSessionManager &sm) { | 126 | auto disableSessionManagement = [](QSessionManager &sm) { | ||
Show All 38 Lines | 160 | if (cliOptions.isSet(shellPluginOption)) { | |||
160 | KDBusService service(KDBusService::Unique); | 165 | KDBusService service(KDBusService::Unique); | ||
161 | //This will not leak, because corona deletes itself on window close | 166 | //This will not leak, because corona deletes itself on window close | ||
162 | new StandaloneAppCorona(cliOptions.value(shellPluginOption)); | 167 | new StandaloneAppCorona(cliOptions.value(shellPluginOption)); | ||
163 | return app.exec(); | 168 | return app.exec(); | ||
164 | } else { | 169 | } else { | ||
165 | cliOptions.showHelp(1); | 170 | cliOptions.showHelp(1); | ||
166 | } | 171 | } | ||
167 | } | 172 | } | ||
173 | | ||||
174 | if (cliOptions.isSet(replaceOption)) { | ||||
175 | auto message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"), | ||||
176 | QStringLiteral("/MainApplication"), | ||||
177 | QStringLiteral("org.qtproject.Qt.QCoreApplication"), | ||||
178 | QStringLiteral("quit")); | ||||
179 | QDBusConnection::sessionBus().call(message); //deliberately block until it's done, so we register the name after the app quits | ||||
180 | } | ||||
168 | } | 181 | } | ||
169 | 182 | | |||
170 | KDBusService service(KDBusService::Unique); | 183 | KDBusService service(KDBusService::Unique); | ||
171 | 184 | | |||
172 | QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, ShellManager::instance(), &QObject::deleteLater); | 185 | QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, ShellManager::instance(), &QObject::deleteLater); | ||
173 | 186 | | |||
174 | return app.exec(); | 187 | return app.exec(); | ||
175 | } | 188 | } |
QStringList() is not necessary.