Warning, file /plasma/plasma-welcome/src/main.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Felipe Kinoshita <kinofhek@gmail.com> 0003 * SPDX-FileCopyrightText: 2022 Nate Graham <nate@kde.org> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #include <QApplication> 0009 #include <QCommandLineOption> 0010 #include <QCommandLineParser> 0011 #include <QQmlApplicationEngine> 0012 #include <QQuickWindow> 0013 #include <QSurfaceFormat> 0014 #include <QUrl> 0015 #include <QtQml> 0016 0017 #include "applicationInfo.h" 0018 #include "controller.h" 0019 #include "plasma-welcome-version.h" 0020 #include "qmlconfig.h" 0021 0022 #include "module.h" 0023 #include <KAboutData> 0024 #include <KDBusService> 0025 #include <KLocalizedContext> 0026 #include <KLocalizedString> 0027 #include <KWindowSystem> 0028 0029 int main(int argc, char *argv[]) 0030 { 0031 auto format = QSurfaceFormat::defaultFormat(); 0032 format.setOption(QSurfaceFormat::ResetNotification); 0033 QSurfaceFormat::setDefaultFormat(format); 0034 0035 QApplication app(argc, argv); 0036 QCoreApplication::setOrganizationName(QStringLiteral("KDE")); 0037 QCoreApplication::setApplicationName(QStringLiteral("plasma-welcome")); 0038 KLocalizedString::setApplicationDomain(QByteArrayLiteral("plasma-welcome")); 0039 0040 const QString description = i18nc("@info:usagetip", "A welcome app for KDE Plasma"); 0041 KAboutData aboutData( 0042 // The program name used internally. 0043 QStringLiteral("plasma-welcome"), 0044 // A displayable program name string. 0045 i18nc("@title", "Welcome Center"), 0046 // The program version string. 0047 QStringLiteral(PLASMA_WELCOME_VERSION_STRING), 0048 // Short description of what the app does. 0049 description, 0050 // The license this code is released under. 0051 KAboutLicense::GPL, 0052 // Copyright Statement. 0053 i18nc("@info copyright string", "(c) 2021")); 0054 aboutData.addAuthor(i18nc("@info:credit", "Felipe Kinoshita"), 0055 i18nc("@info:credit", "Author"), 0056 QStringLiteral("kinofhek@gmail.com"), 0057 QStringLiteral("https://fhek.gitlab.io.com")); 0058 aboutData.addAuthor(i18nc("@info:credit", "Nate Graham"), 0059 i18nc("@info:credit", "Author"), 0060 QStringLiteral("nate@kde.org"), 0061 QStringLiteral("https://pointieststick.com")); 0062 KAboutData::setApplicationData(aboutData); 0063 0064 QQmlApplicationEngine engine; 0065 0066 0067 // Parse CLI args 0068 QCommandLineParser parser; 0069 parser.setApplicationDescription(description); 0070 aboutData.setupCommandLine(&parser); 0071 parser.addOption(QCommandLineOption(QStringLiteral("post-update"), i18n("Display release notes for the current Plasma release."))); 0072 parser.addOption(QCommandLineOption(QStringLiteral("post-update-beta"), i18n("Display release notes for the current Plasma release, for beta versions."))); 0073 parser.addOption(QCommandLineOption(QStringLiteral("live-environment"), i18n("Display the live page intended for distro live environments."))); 0074 0075 parser.process(app); 0076 aboutData.processCommandLine(&parser); 0077 0078 engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); 0079 0080 auto controller = engine.singletonInstance<Controller *>("org.kde.plasma.welcome", "Controller"); 0081 if (parser.isSet(QStringLiteral("post-update"))) { 0082 controller->setMode(Controller::Mode::Update); 0083 } else if (parser.isSet(QStringLiteral("post-update-beta"))) { 0084 controller->setMode(Controller::Mode::Beta); 0085 } else if (parser.isSet(QStringLiteral("live-environment"))) { 0086 controller->setMode(Controller::Mode::Live); 0087 } 0088 0089 engine.loadFromModule("org.kde.plasma.welcome", "Main"); 0090 0091 if (engine.rootObjects().isEmpty()) { 0092 return -1; 0093 } 0094 0095 // Make it single-instance so it raises e.g. when middle-clicking on taskmanager 0096 // or accidentally launching it while it's already open 0097 KDBusService service(KDBusService::Unique); 0098 QObject::connect(&service, &KDBusService::activateRequested, &engine, [&engine](const QStringList & /*arguments*/, const QString & /*workingDirectory*/) { 0099 const auto rootObjects = engine.rootObjects(); 0100 for (auto obj : rootObjects) { 0101 auto view = qobject_cast<QQuickWindow *>(obj); 0102 if (view) { 0103 KWindowSystem::updateStartupId(view); 0104 KWindowSystem::activateWindow(view); 0105 return; 0106 } 0107 } 0108 }); 0109 0110 return app.exec(); 0111 }