Changeset View
Changeset View
Standalone View
Standalone View
src/kpackage-install-handlers/kns/main.cpp
Show All 18 Lines | |||||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include <QCoreApplication> | 21 | #include <QCoreApplication> | ||
22 | #include <QUrl> | 22 | #include <QUrl> | ||
23 | #include <QUrlQuery> | 23 | #include <QUrlQuery> | ||
24 | #include <QTimer> | 24 | #include <QTimer> | ||
25 | #include <QDebug> | 25 | #include <QDebug> | ||
26 | #include <QStandardPaths> | 26 | #include <QStandardPaths> | ||
27 | #include <QFile> | ||||
27 | 28 | | |||
28 | #include <KLocalizedString> | 29 | #include <KLocalizedString> | ||
29 | 30 | | |||
30 | #include <KNotifications/KNotification> | 31 | #include <KNotifications/KNotification> | ||
31 | 32 | | |||
32 | #include <KNSCore/Engine> | 33 | #include <KNSCore/Engine> | ||
33 | #include <KNSCore/QuestionManager> | 34 | #include <KNSCore/QuestionManager> | ||
34 | 35 | | |||
35 | int main(int argc, char** argv) | 36 | int main(int argc, char** argv) | ||
36 | { | 37 | { | ||
37 | QCoreApplication app(argc, argv); | 38 | QCoreApplication app(argc, argv); | ||
38 | app.setQuitLockEnabled(false); | 39 | app.setQuitLockEnabled(false); | ||
39 | Q_ASSERT(app.arguments().count() == 2); | 40 | Q_ASSERT(app.arguments().count() == 2); | ||
40 | 41 | | |||
41 | #ifdef TEST | 42 | #ifdef TEST | ||
42 | QStandardPaths::setTestModeEnabled(true); | 43 | QStandardPaths::setTestModeEnabled(true); | ||
43 | #endif | 44 | #endif | ||
44 | 45 | | |||
45 | const QUrl url(app.arguments().last()); | 46 | const QUrl url(app.arguments().last()); | ||
46 | Q_ASSERT(url.isValid()); | 47 | Q_ASSERT(url.isValid()); | ||
47 | Q_ASSERT(url.scheme() == QLatin1String("kns")); | 48 | Q_ASSERT(url.scheme() == QLatin1String("kns")); | ||
48 | 49 | | |||
49 | const auto knsname = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, url.host()); | 50 | QString knsname; | ||
51 | for (const auto &location : KNSCore::Engine::configSearchLocations()) { | ||||
52 | QString candidate = location + QLatin1Char('/') + url.host(); | ||||
53 | if (QFile::exists(candidate)) { | ||||
54 | knsname = candidate; | ||||
55 | break; | ||||
56 | } | ||||
57 | } | ||||
58 | | ||||
leinir: Since frameworkintegration requires KNewStuff (and Frameworks 5.58), i'd probably suggest using… | |||||
50 | if (knsname.isEmpty()) { | 59 | if (knsname.isEmpty()) { | ||
51 | qWarning() << "couldn't find knsrc file for" << url.host(); | 60 | qWarning() << "couldn't find knsrc file for" << url.host(); | ||
52 | return 1; | 61 | return 1; | ||
53 | } | 62 | } | ||
54 | 63 | | |||
55 | const auto pathParts = url.path().split(QLatin1Char('/'), QString::SkipEmptyParts); | 64 | const auto pathParts = url.path().split(QLatin1Char('/'), QString::SkipEmptyParts); | ||
56 | if (pathParts.size() != 2) { | 65 | if (pathParts.size() != 2) { | ||
57 | qWarning() << "wrong format in the url path" << url << pathParts; | 66 | qWarning() << "wrong format in the url path" << url << pathParts; | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | |||||
105 | }); | 114 | }); | ||
106 | 115 | | |||
107 | QObject::connect(&engine, &KNSCore::Engine::signalError, &engine, [](const QString &error) { | 116 | QObject::connect(&engine, &KNSCore::Engine::signalError, &engine, [](const QString &error) { | ||
108 | qWarning() << "kns error:" << error; | 117 | qWarning() << "kns error:" << error; | ||
109 | QCoreApplication::exit(1); | 118 | QCoreApplication::exit(1); | ||
110 | }); | 119 | }); | ||
111 | QObject::connect(&engine, &KNSCore::Engine::signalEntryDetailsLoaded, &engine, [providerid, linkid, &engine, &installedCount](const KNSCore::EntryInternal &entry) { | 120 | QObject::connect(&engine, &KNSCore::Engine::signalEntryDetailsLoaded, &engine, [providerid, linkid, &engine, &installedCount](const KNSCore::EntryInternal &entry) { | ||
112 | // qDebug() << "checking..." << entry.status() << entry.providerId(); | 121 | // qDebug() << "checking..." << entry.status() << entry.providerId(); | ||
113 | if (providerid != QUrl(entry.providerId()).host()) { | 122 | if (providerid != QUrl(entry.providerId()).host()) { | ||
leinir: Did you mean to leave this in? | |||||
114 | qWarning() << "Wrong provider" << providerid << "instead of" << QUrl(entry.providerId()).host(); | 123 | qWarning() << "Wrong provider" << providerid << "instead of" << QUrl(entry.providerId()).host(); | ||
115 | QCoreApplication::exit(1); | 124 | QCoreApplication::exit(1); | ||
116 | } else if (entry.status() == KNS3::Entry::Downloadable) { | 125 | } else if (entry.status() == KNS3::Entry::Downloadable) { | ||
117 | qDebug() << "installing..."; | 126 | qDebug() << "installing..."; | ||
118 | installedCount++; | 127 | installedCount++; | ||
119 | engine.install(entry, linkid); | 128 | engine.install(entry, linkid); | ||
120 | } else if (installedCount == 0) { | 129 | } else if (installedCount == 0) { | ||
121 | qDebug() << "already installed."; | 130 | qDebug() << "already installed."; | ||
Show All 17 Lines |
Since frameworkintegration requires KNewStuff (and Frameworks 5.58), i'd probably suggest using the static function in KNewStuffCore::Engine which gives you this information without having to do manual heuristic type stuff :)
static QStringList Engine::configSearchLocations(bool includeFallbackLocations = false):
https://api.kde.org/frameworks/knewstuff/html/classKNSCore_1_1Engine.html#a030b62a72c0c486939461983e225bb49