Commit c52df700 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Make it possible for 5.8 to compile against the last AppStreamQt

Summary: Builds, works. Needs patch in appstream, see pull request

Reviewers: #plasma, rdieter

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D3265
parent 3297fe60
......@@ -21,6 +21,9 @@
#include "AppPackageKitResource.h"
#include <AppstreamQt/screenshot.h>
#include <AppstreamQt/image.h>
#ifdef NEWAPPSTREAM
#include <AppStreamQt/icon.h>
#endif
// #include <AppstreamQt/release.h>
#include <KLocalizedString>
#include <KToolInvocation>
......@@ -52,7 +55,23 @@ QString AppPackageKitResource::longDescription()
QVariant AppPackageKitResource::icon() const
{
QIcon ret;
#ifdef NEWAPPSTREAM
const auto icons = m_appdata.icons();
if (icons.isEmpty()) {
ret = QIcon::fromTheme(QStringLiteral("package-x-generic"));
} else foreach(const AppStream::Icon &icon, icons) {
switch(icon.kind()) {
case AppStream::Icon::KindLocal:
ret.addFile(icon.url().toLocalFile(), icon.size());
break;
case AppStream::Icon::KindCached:
ret.addFile(icon.url().toLocalFile(), icon.size());
break;
default:
break;
}
}
#else
const auto icons = m_appdata.iconUrls();
if (icons.isEmpty())
return m_appdata.name();
......@@ -66,7 +85,7 @@ QVariant AppPackageKitResource::icon() const
if (ret.isNull()) {
ret = QIcon::fromTheme(QStringLiteral("package-x-generic"));
}
#endif
return ret;
}
......@@ -105,7 +124,11 @@ QString AppPackageKitResource::appstreamId() const
QUrl AppPackageKitResource::homepage()
{
#ifdef NEWAPPSTREAM
return m_appdata.url(Appstream::Component::UrlKindHomepage);
#else
return m_appdata.urls().value(Appstream::Component::UrlKindHomepage);
#endif
}
bool AppPackageKitResource::isTechnical() const
......@@ -183,11 +206,15 @@ bool AppPackageKitResource::canExecute() const
QStringList AppPackageKitResource::findProvides(Appstream::Provides::Kind kind) const
{
#ifdef NEWAPPSTREAM
return m_appdata.provided(kind).items();
#else
QStringList ret;
Q_FOREACH (Appstream::Provides p, m_appdata.provides())
if (p.kind() == kind)
ret += p.value();
return ret;
#endif
}
QStringList AppPackageKitResource::allPackageNames() const
......
......@@ -10,7 +10,13 @@ add_library(packagekit-backend MODULE PackageKitBackend.cpp
PackageKitSourcesBackend.cpp
AppstreamReviews.cpp
)
target_link_libraries(packagekit-backend PRIVATE Discover::Common Qt5::Core PK::packagekitqt5 KF5::ConfigGui KF5::Service KF5::KIOWidgets KF5::Archive AppstreamQt)
set(AppstreamTarget "AppstreamQt")
if (${AppstreamQt_VERSION} VERSION_GREATER 0.10.3)
target_compile_definitions(packagekit-backend PRIVATE -DNEWAPPSTREAM=0)
set(AppstreamTarget "AppStreamQt")
endif()
target_link_libraries(packagekit-backend PRIVATE Discover::Common Qt5::Core PK::packagekitqt5 KF5::ConfigGui KF5::Service KF5::KIOWidgets KF5::Archive ${AppstreamTarget})
install(TARGETS packagekit-backend DESTINATION ${PLUGIN_INSTALL_DIR}/discover)
install(FILES packagekit-backend.desktop DESTINATION ${DATA_INSTALL_DIR}/libdiscover/backends)
......
......@@ -54,7 +54,11 @@ PackageKitBackend::PackageKitBackend(QObject* parent)
, m_isFetching(0)
, m_reviews(new AppstreamReviews(this))
{
#ifdef NEWAPPSTREAM
bool b = m_appdata.load();
#else
bool b = m_appdata.open();
#endif
if (!b) {
qWarning() << "Could not open the AppStream metadata pool";
......@@ -122,7 +126,11 @@ void PackageKitBackend::reloadPackageList()
disconnect(m_refresher.data(), &PackageKit::Transaction::finished, this, &PackageKitBackend::reloadPackageList);
}
#ifdef NEWAPPSTREAM
const auto components = m_appdata.components();
#else
const auto components = m_appdata.allComponents();
#endif
QStringList neededPackages;
neededPackages.reserve(components.size());
foreach(const Appstream::Component& component, components) {
......@@ -343,7 +351,11 @@ AbstractResource* PackageKitBackend::resourceByPackageName(const QString& name)
QList<AbstractResource*> PackageKitBackend::searchPackageName(const QString& searchText)
{
#ifdef NEWAPPSTREAM
const QList<Appstream::Component> components = m_appdata.search(searchText);
#else
const QList<Appstream::Component> components = m_appdata.findComponentsByString(searchText, {});
#endif
const QStringList ids = kTransform<QStringList>(components, [](const Appstream::Component& comp) { return comp.id(); });
return resourcesByPackageNames<QList<AbstractResource*>>(ids);
......
......@@ -29,7 +29,18 @@
#include <QTimer>
#include <QSet>
#include <PackageKit/Transaction>
#ifdef NEWAPPSTREAM
#include <AppstreamQt/pool.h>
#include <AppstreamQt/provided.h>
namespace AppStream {
typedef Provided Provides;
typedef Pool Database;
}
namespace Appstream = AppStream;
#else
#include <AppstreamQt/database.h>
#endif
class AppstreamReviews;
class AppPackageKitResource;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment