diff --git a/src/kpackage-install-handlers/kns/CMakeLists.txt b/src/kpackage-install-handlers/kns/CMakeLists.txt index 30f4b7c..52c591f 100644 --- a/src/kpackage-install-handlers/kns/CMakeLists.txt +++ b/src/kpackage-install-handlers/kns/CMakeLists.txt @@ -1,16 +1,17 @@ +configure_file(knshandlerversion.h.in knshandlerversion.h) add_executable(knshandler main.cpp) target_link_libraries(knshandler KF5::NewStuffCore KF5::I18n KF5::Notifications Qt5::Xml) install(TARGETS knshandler DESTINATION ${KDE_INSTALL_LIBEXECDIR_KF5}/kpackagehandlers) add_executable(knshandlertest main.cpp) target_link_libraries(knshandlertest KF5::NewStuffCore KF5::I18n KF5::Notifications Qt5::Xml) target_compile_definitions(knshandlertest PRIVATE -DTEST) if(EXISTS "${CMAKE_INSTALL_PREFIX}/${CONFIG_INSTALL_DIR}/colorschemes.knsrc") add_test(NAME test_kns-kpackage COMMAND knshandlertest kns://colorschemes.knsrc/api.kde-look.org/1136471) add_test(NAME test_kns-kpackage-fail COMMAND knshandlertest kns://colorschemes.knsrc/xxx/1136471) set_tests_properties(test_kns-kpackage-fail PROPERTIES WILL_FAIL TRUE) message(STATUS "KNS-KPackage test enabled") endif() diff --git a/src/kpackage-install-handlers/kns/knshandlerversion.h.in b/src/kpackage-install-handlers/kns/knshandlerversion.h.in new file mode 100644 index 0000000..6c064fd --- /dev/null +++ b/src/kpackage-install-handlers/kns/knshandlerversion.h.in @@ -0,0 +1,28 @@ +/* This file is part of the KDE libraries + * Copyright (C) 2019 Dan Leinir Turthra Jensen + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License or ( at + * your option ) version 3 or, at the discretion of KDE e.V. ( which shall + * act as a proxy as in section 14 of the GPLv3 ), any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KNSHANDLERVERSION_H +#define KNSHANDLERVERSION_H + +#include + +static QLatin1String knshandlerversion("@PROJECT_VERSION@"); + +#endif//KNSHANDLERVERSION_H diff --git a/src/kpackage-install-handlers/kns/main.cpp b/src/kpackage-install-handlers/kns/main.cpp index d654cbe..eb62285 100644 --- a/src/kpackage-install-handlers/kns/main.cpp +++ b/src/kpackage-install-handlers/kns/main.cpp @@ -1,147 +1,151 @@ /* This file is part of the KDE libraries * Copyright 2016 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License or ( at * your option ) version 3 or, at the discretion of KDE e.V. ( which shall * act as a proxy as in section 14 of the GPLv3 ), any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #include #include +#include "knshandlerversion.h" + int main(int argc, char** argv) { QCoreApplication app(argc, argv); + app.setApplicationName(QLatin1String("kpackage-knshandler")); + app.setApplicationVersion(knshandlerversion); app.setQuitLockEnabled(false); Q_ASSERT(app.arguments().count() == 2); #ifdef TEST QStandardPaths::setTestModeEnabled(true); #endif const QUrl url(app.arguments().last()); Q_ASSERT(url.isValid()); Q_ASSERT(url.scheme() == QLatin1String("kns")); QString knsname; for (const auto &location : KNSCore::Engine::configSearchLocations(true)) { QString candidate = location + QLatin1Char('/') + url.host(); if (QFile::exists(candidate)) { knsname = candidate; break; } } if (knsname.isEmpty()) { qWarning() << "couldn't find knsrc file for" << url.host(); return 1; } const auto pathParts = url.path().split(QLatin1Char('/'), QString::SkipEmptyParts); if (pathParts.size() != 2) { qWarning() << "wrong format in the url path" << url << pathParts; return 1; } const auto providerid = pathParts.at(0); const auto entryid = pathParts.at(1); int linkid = 1; if (url.hasQuery()) { QUrlQuery query(url); if (query.hasQueryItem(QLatin1String("linkid"))) { bool ok; linkid = query.queryItemValue(QLatin1String("linkid")).toInt(&ok); if (!ok) { qWarning() << "linkid is not an integer" << url << pathParts; return 1; } } } KNSCore::Engine engine; int installedCount = 0; QObject::connect(KNSCore::QuestionManager::instance(), &KNSCore::QuestionManager::askQuestion, &engine, [](KNSCore::Question* question){ auto discardQuestion = [question]() { question->setResponse(KNSCore::Question::InvalidResponse); }; switch(question->questionType()) { case KNSCore::Question::YesNoQuestion: { auto f = KNotification::event(KNotification::StandardEvent::Notification, question->title(), question->question()); f->setActions({i18n("Yes"), i18n("No")}); QObject::connect(f, &KNotification::action1Activated, question, [question](){ question->setResponse(KNSCore::Question::YesResponse); }); QObject::connect(f, &KNotification::action2Activated, question, [question](){ question->setResponse(KNSCore::Question::NoResponse); }); QObject::connect(f, &KNotification::closed, question, discardQuestion); } break; case KNSCore::Question::ContinueCancelQuestion: { auto f = KNotification::event(KNotification::StandardEvent::Notification, question->title(), question->question()); f->setActions({i18n("Continue"), i18n("Cancel")}); QObject::connect(f, &KNotification::action1Activated, question, [question](){ question->setResponse(KNSCore::Question::ContinueResponse); }); QObject::connect(f, &KNotification::action2Activated, question, [question](){ question->setResponse(KNSCore::Question::CancelResponse); }); QObject::connect(f, &KNotification::closed, question, discardQuestion); } break; case KNSCore::Question::InputTextQuestion: case KNSCore::Question::SelectFromListQuestion: case KNSCore::Question::PasswordQuestion: discardQuestion(); break; } }); QObject::connect(&engine, &KNSCore::Engine::signalProvidersLoaded, &engine, [&engine, entryid](){ engine.fetchEntryById(entryid); }); QObject::connect(&engine, &KNSCore::Engine::signalErrorCode, &engine, [](const KNSCore::ErrorCode &errorCode, const QString &message, const QVariant &metadata) { qWarning() << "kns error:" << errorCode << message << metadata; QCoreApplication::exit(1); }); QObject::connect(&engine, &KNSCore::Engine::signalEntryDetailsLoaded, &engine, [providerid, linkid, &engine, &installedCount](const KNSCore::EntryInternal &entry) { // qDebug() << "checking..." << entry.status() << entry.providerId(); if (providerid != QUrl(entry.providerId()).host()) { qWarning() << "Wrong provider" << providerid << "instead of" << QUrl(entry.providerId()).host(); QCoreApplication::exit(1); } else if (entry.status() == KNS3::Entry::Downloadable) { qDebug() << "installing..."; installedCount++; engine.install(entry, linkid); } else if (installedCount == 0) { qDebug() << "already installed."; QCoreApplication::exit(0); } }); QObject::connect(&engine, &KNSCore::Engine::signalEntryChanged, &engine, [&engine, &installedCount](const KNSCore::EntryInternal &entry) { if (entry.status() == KNS3::Entry::Installed) { installedCount--; } if (installedCount == 0) QCoreApplication::exit(0); }); if (!engine.init(knsname)) { qWarning() << "couldn't initialize" << knsname; return 1; } return app.exec(); }