KNewStuff

main.cpp
1/*
2 This file is part of KNewStuff2.
3 SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <admin@leinir.dk>
4
5 SPDX-License-Identifier: LGPL-2.1-or-later
6*/
7
8#include "knsrcmodel.h"
9
10#include <KLocalizedString>
11
12#include <QApplication>
13#include <QCommandLineOption>
14#include <QCommandLineParser>
15#include <QQmlApplicationEngine>
16#include <QQmlContext>
17
18int main(int argc, char **argv)
19{
20 QApplication app(argc, argv);
21 QCoreApplication::setApplicationName(QStringLiteral("knewstuff-dialog"));
22 QCoreApplication::setApplicationVersion(QStringLiteral("1.0"));
23 QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
25
27 parser->addHelpOption();
28 parser->addPositionalArgument(QStringLiteral("knsrcfile"),
29 i18n("The KNSRC file you want to show. If none is passed, you will be presented with a dialog which lets you switch between "
30 "all the config files installed into the systemwide knsrc file location"));
31 parser->addOption(
32 QCommandLineOption(QStringLiteral("url"),
33 i18n("A kns url to show information from. The format for a kns url is kns://knsrcfile/providerid/entryid\n'knsrcfile'\nis the name "
34 "of a knsrc file as might be passed directly through this tool's knsrcfile argument\n'providerid'\nis the hostname of the "
35 "provider the entry should exist on\n'entryid'\nis the unique ID of an entry found in the provider specified by the knsrc "
36 "file.\n An example of such a url is kns://sddmtheme.knsrc/api.kde-look.org/2059021"),
37 QStringLiteral("knsurl")));
38 parser->process(app);
39
41 qmlRegisterType<KNSRCModel>("org.kde.newstuff.tools.dialog", 1, 0, "KNSRCModel");
42 auto *context = new KLocalizedContext(appengine);
43 context->setTranslationDomain(QStringLiteral("knewstuff6"));
44 appengine->rootContext()->setContextObject(context);
45
46 if (parser->optionNames().contains(QStringLiteral("url"))) {
47 const QUrl url(parser->value(QStringLiteral("url")));
48 Q_ASSERT(url.isValid());
49 Q_ASSERT(url.scheme() == QLatin1String("kns"));
50
51 const QString knsrcfile{url.host()};
52
53 const QStringList pathParts = url.path().split(QLatin1Char('/'), Qt::SkipEmptyParts);
54 const QString providerId = pathParts.at(0);
55 const QString entryId = pathParts.at(1);
56 if (pathParts.size() != 2) {
57 qWarning() << "wrong format in the url path" << url << pathParts;
58 }
59 Q_ASSERT(!providerId.isEmpty() && !entryId.isEmpty());
60
61 appengine->rootContext()->setContextProperty(QStringLiteral("knsrcfile"), knsrcfile);
62 appengine->rootContext()->setContextProperty(QStringLiteral("knsProviderId"), providerId);
63 appengine->rootContext()->setContextProperty(QStringLiteral("knsEntryId"), entryId);
64 appengine->load(QStringLiteral("qrc:/qml/dialog.qml"));
65 } else if (!parser->positionalArguments().isEmpty()) {
66 appengine->rootContext()->setContextProperty(QStringLiteral("knsrcfile"), parser->positionalArguments().first());
67 appengine->load(QStringLiteral("qrc:/qml/dialog.qml"));
68 } else {
69 appengine->load(QStringLiteral("qrc:/qml/main.qml"));
70 }
71
72 return app.exec();
73}
static void setApplicationDomain(const QByteArray &domain)
QString i18n(const char *text, const TYPE &arg...)
QCommandLineOption addHelpOption()
bool addOption(const QCommandLineOption &option)
void addPositionalArgument(const QString &name, const QString &description, const QString &syntax)
QStringList optionNames() const const
QStringList positionalArguments() const const
void process(const QCoreApplication &app)
QString value(const QCommandLineOption &option) const const
void setApplicationName(const QString &application)
void setApplicationVersion(const QString &version)
void setOrganizationDomain(const QString &orgDomain)
const_reference at(qsizetype i) const const
T & first()
bool isEmpty() const const
qsizetype size() const const
void load(const QString &filePath)
void setContextObject(QObject *object)
void setContextProperty(const QString &name, QObject *value)
QQmlContext * rootContext() const const
bool isEmpty() const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
SkipEmptyParts
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:20:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.