File indexing completed on 2024-05-12 05:36:15
0001 // SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org> 0002 // SPDX-License-Identifier: LGPL-2.0-or-later 0003 0004 #include <QApplication> 0005 #include <QCommandLineParser> 0006 #include <QIcon> 0007 #include <QQmlApplicationEngine> 0008 #include <QQmlContext> 0009 #include <QString> 0010 0011 #include <KAboutData> 0012 #include <KLocalizedString> 0013 0014 #include "settings.h" 0015 #include "version.h" 0016 #include "wizard.h" 0017 0018 std::unique_ptr<QCommandLineParser> createParser() 0019 { 0020 auto parser = std::make_unique<QCommandLineParser>(); 0021 parser->addOption(QCommandLineOption(QStringLiteral("test-wizard"), i18n("Opens the initial start wizard without modifying configuration"))); 0022 return parser; 0023 } 0024 0025 int main(int argc, char *argv[]) 0026 { 0027 QApplication app(argc, argv); 0028 0029 // start wizard 0030 KLocalizedString::setApplicationDomain("plasma_org.kde.plasma.mobileinitialstart"); 0031 KAboutData aboutData(QStringLiteral("plasma-mobile-initial-start"), 0032 QStringLiteral("Initial Start"), 0033 QStringLiteral(PLASMA_MOBILE_VERSION_STRING), 0034 QStringLiteral(""), 0035 KAboutLicense::GPL, 0036 i18n("© 2023 KDE Community")); 0037 aboutData.addAuthor(i18n("Devin Lin"), QString(), QStringLiteral("devin@kde.org")); 0038 KAboutData::setApplicationData(aboutData); 0039 0040 // parse command 0041 auto parser = createParser(); 0042 aboutData.setupCommandLine(parser.get()); 0043 parser->process(app); 0044 aboutData.processCommandLine(parser.get()); 0045 0046 const bool testWizard = parser->isSet(QStringLiteral("test-wizard")); 0047 if (!testWizard) { 0048 // if the wizard has already been run, or we aren't in plasma mobile 0049 if (!Settings::self()->shouldStartWizard()) { 0050 qDebug() << "Wizard will not be started since either it has already been run, or the current session is not Plasma Mobile."; 0051 return 0; 0052 } 0053 } 0054 0055 QQmlApplicationEngine engine; 0056 engine.rootContext()->setContextObject(new KLocalizedContext{&engine}); 0057 0058 Wizard *wizard = new Wizard{nullptr, &engine}; 0059 wizard->setTestingMode(testWizard); 0060 wizard->load(); 0061 0062 qmlRegisterSingletonType<Wizard>("initialstart", 1, 0, "Wizard", [wizard](QQmlEngine *, QJSEngine *) -> QObject * { 0063 return wizard; 0064 }); 0065 0066 engine.load(QUrl(QStringLiteral("qrc:org/kde/plasma/mobileinitialstart/initialstart/qml/Main.qml"))); 0067 0068 app.setWindowIcon(QIcon::fromTheme(QStringLiteral("start-here-symbolic"))); 0069 0070 return app.exec(); 0071 }