git: 50d2fdf85d45 - main - sysutils/plasma5-discover: Unbreak build after AppStreamQt update.

From: Gleb Popov <arrowd_at_FreeBSD.org>
Date: Thu, 16 Nov 2023 13:58:31 UTC
The branch main has been updated by arrowd:

URL: https://cgit.FreeBSD.org/ports/commit/?id=50d2fdf85d45fdcc211086be0893c6132642877a

commit 50d2fdf85d45fdcc211086be0893c6132642877a
Author:     Gleb Popov <arrowd@FreeBSD.org>
AuthorDate: 2023-11-16 13:57:32 +0000
Commit:     Gleb Popov <arrowd@FreeBSD.org>
CommitDate: 2023-11-16 13:58:24 +0000

    sysutils/plasma5-discover: Unbreak build after AppStreamQt update.
    
    Sponsored by:   Serenity Cybersecurity, LLC
---
 sysutils/plasma5-discover/Makefile                 |   3 +-
 .../plasma5-discover/files/patch-CMakeLists.txt    |  11 ++
 .../patch-libdiscover_appstream_AppStreamUtils.cpp | 113 +++++++++++++++++++++
 .../patch-libdiscover_appstream_AppStreamUtils.h   |  22 ++++
 .../patch-libdiscover_backends_CMakeLists.txt      |  16 +++
 5 files changed, 164 insertions(+), 1 deletion(-)

diff --git a/sysutils/plasma5-discover/Makefile b/sysutils/plasma5-discover/Makefile
index f96e638dea41..6adf984da5b8 100644
--- a/sysutils/plasma5-discover/Makefile
+++ b/sysutils/plasma5-discover/Makefile
@@ -1,5 +1,6 @@
 PORTNAME=	discover
 DISTVERSION=	${KDE_PLASMA_VERSION}
+PORTREVISION=	1
 CATEGORIES=	sysutils kde kde-plasma
 
 MAINTAINER=	kde@FreeBSD.org
@@ -8,7 +9,7 @@ WWW=		https://www.kde.org/plasma-desktop
 
 # TODO: update packagekit-qt5
 #LIB_DEPENDS=	libpackagekit-qt.so:ports-mgmt/packagekit-qt5
-LIB_DEPENDS=	libAppStreamQt.so:devel/appstream-qt
+LIB_DEPENDS=	libAppStreamQt5.so:devel/appstream-qt
 
 USES=		cmake compiler:c++11-lib cpe desktop-file-utils gettext kde:5 \
 		pkgconfig qt:5 tar:xz xorg
diff --git a/sysutils/plasma5-discover/files/patch-CMakeLists.txt b/sysutils/plasma5-discover/files/patch-CMakeLists.txt
new file mode 100644
index 000000000000..157ffb29cb3f
--- /dev/null
+++ b/sysutils/plasma5-discover/files/patch-CMakeLists.txt
@@ -0,0 +1,11 @@
+--- CMakeLists.txt.orig	2023-10-24 12:55:33 UTC
++++ CMakeLists.txt
+@@ -31,7 +31,7 @@ find_package(packagekitqt5 1.0.1 CONFIG)
+ find_package(KF5Kirigami2 2.7.0)
+ 
+ find_package(packagekitqt5 1.0.1 CONFIG)
+-find_package(AppStreamQt 0.15.3 CONFIG REQUIRED)
++find_package(AppStreamQt5 1.0.0 CONFIG REQUIRED)
+ find_package(KF5Attica 5.23 CONFIG)
+ find_package(KF5NewStuff 5.53 CONFIG)
+ 
diff --git a/sysutils/plasma5-discover/files/patch-libdiscover_appstream_AppStreamUtils.cpp b/sysutils/plasma5-discover/files/patch-libdiscover_appstream_AppStreamUtils.cpp
new file mode 100644
index 000000000000..c8b6adf0c5ad
--- /dev/null
+++ b/sysutils/plasma5-discover/files/patch-libdiscover_appstream_AppStreamUtils.cpp
@@ -0,0 +1,113 @@
+--- libdiscover/appstream/AppStreamUtils.cpp.orig	2023-10-24 12:55:33 UTC
++++ libdiscover/appstream/AppStreamUtils.cpp
+@@ -7,11 +7,11 @@
+ #include "AppStreamUtils.h"
+ 
+ #include "utils.h"
+-#include <AppStreamQt/pool.h>
+-#include <AppStreamQt/release.h>
+-#include <AppStreamQt/screenshot.h>
+-#include <AppStreamQt/spdx.h>
+-#include <AppStreamQt/version.h>
++#include <AppStreamQt5/pool.h>
++#include <AppStreamQt5/release.h>
++#include <AppStreamQt5/screenshot.h>
++#include <AppStreamQt5/spdx.h>
++#include <AppStreamQt5/version.h>
+ #include <Category/Category.h>
+ #include <KLocalizedString>
+ #include <QDebug>
+@@ -35,10 +35,20 @@ QString AppStreamUtils::changelogToHtml(const AppStrea
+ 
+ QString AppStreamUtils::changelogToHtml(const AppStream::Component &appdata)
+ {
+-    if (appdata.releases().isEmpty())
++#if ASQ_CHECK_VERSION(1, 0, 0)
++    const auto releases = appdata.releasesPlain();
++#else
++    const auto releases = appdata.releases();
++#endif
++    if (releases.isEmpty()) {
+         return {};
++    }
+ 
+-    const auto release = appdata.releases().constFirst();
++#if ASQ_CHECK_VERSION(1, 0, 0)
++    const auto release = releases.indexSafe(0).value();
++#else
++    const auto release = releases.constFirst();
++#endif
+     if (release.description().isEmpty())
+         return {};
+ 
+@@ -49,17 +59,19 @@ Screenshots AppStreamUtils::fetchScreenshots(const App
+ 
+ Screenshots AppStreamUtils::fetchScreenshots(const AppStream::Component &appdata)
+ {
+-    const auto appdataScreenshots = appdata.screenshots();
++    const auto appdataScreenshots = appdata.screenshotsAll();
+     Screenshots ret;
+     ret.reserve(appdataScreenshots.size());
+     for (const AppStream::Screenshot &s : appdataScreenshots) {
+         const auto images = s.images();
+         const QUrl thumbnail = AppStreamUtils::imageOfKind(images, AppStream::Image::KindThumbnail);
+-        const QUrl plain = AppStreamUtils::imageOfKind(images, AppStream::Image::KindSource);
+-        if (plain.isEmpty())
+-            qWarning() << "invalid screenshot for" << appdata.name();
++        const QUrl full = AppStreamUtils::imageOfKind(images, AppStream::Image::KindSource);
++        if (full.isEmpty()) {
++            qWarning() << "AppStreamUtils: Invalid screenshot for" << appdata.name();
++        }
++        const bool isAnimated = s.mediaKind() == AppStream::Screenshot::MediaKindVideo;
+ 
+-        ret.append(Screenshot{plain, thumbnail.isEmpty() ? plain : thumbnail, s.mediaKind() == AppStream::Screenshot::MediaKindVideo});
++        ret.append(Screenshot{thumbnail.isEmpty() ? full : thumbnail, full, isAnimated});
+     }
+     return ret;
+ }
+@@ -128,20 +140,13 @@ QString AppStreamUtils::versionString(const QString &v
+ 
+ QString AppStreamUtils::versionString(const QString &version, const AppStream::Component &appdata)
+ {
++    Q_UNUSED(appdata);
++
+     if (version.isEmpty()) {
+         return {};
+-    } else {
+-        if (appdata.releases().isEmpty())
+-            return version;
+-
+-        auto release = appdata.releases().constFirst();
+-        if (release.timestamp().isValid() && version.startsWith(release.version())) {
+-            QLocale l;
+-            return i18n("%1, released on %2", version, l.toString(release.timestamp().date(), QLocale::ShortFormat));
+-        } else {
+-            return version;
+-        }
+     }
++
++    return version;
+ }
+ 
+ QString AppStreamUtils::contentRatingDescription(const AppStream::Component &appdata)
+@@ -238,7 +243,7 @@ uint AppStreamUtils::contentRatingMinimumAge(const App
+ #endif
+ }
+ 
+-static void kRemoveDuplicates(QList<AppStream::Component> &input, AppStream::Bundle::Kind kind)
++static void kRemoveDuplicates(AppStream::ComponentBox &input, AppStream::Bundle::Kind kind)
+ {
+     QSet<QString> ret;
+     for (auto it = input.begin(); it != input.end();) {
+@@ -252,9 +257,9 @@ static void kRemoveDuplicates(QList<AppStream::Compone
+     }
+ }
+ 
+-QList<AppStream::Component> AppStreamUtils::componentsByCategories(AppStream::Pool *pool, Category *cat, AppStream::Bundle::Kind kind)
++AppStream::ComponentBox AppStreamUtils::componentsByCategories(AppStream::Pool *pool, Category *cat, AppStream::Bundle::Kind kind)
+ {
+-    QList<AppStream::Component> ret;
++    AppStream::ComponentBox ret(AppStream::ComponentBox::FlagNoChecks);
+     for (const auto &categoryName : cat->involvedCategories()) {
+         ret += pool->componentsByCategories({categoryName});
+     }
diff --git a/sysutils/plasma5-discover/files/patch-libdiscover_appstream_AppStreamUtils.h b/sysutils/plasma5-discover/files/patch-libdiscover_appstream_AppStreamUtils.h
new file mode 100644
index 000000000000..02cef6467b97
--- /dev/null
+++ b/sysutils/plasma5-discover/files/patch-libdiscover_appstream_AppStreamUtils.h
@@ -0,0 +1,22 @@
+--- libdiscover/appstream/AppStreamUtils.h.orig	2023-10-24 12:55:33 UTC
++++ libdiscover/appstream/AppStreamUtils.h
+@@ -6,9 +6,9 @@
+ 
+ #pragma once
+ 
+-#include <AppStreamQt/component.h>
+-#include <AppStreamQt/image.h>
+-#include <AppStreamQt/pool.h>
++#include <AppStreamQt5/component.h>
++#include <AppStreamQt5/image.h>
++#include <AppStreamQt5/pool.h>
+ #include <QColor>
+ #include <QList>
+ #include <QUrl>
+@@ -38,5 +38,5 @@ Q_DECL_EXPORT uint contentRatingMinimumAge(const AppSt
+ Q_DECL_EXPORT AbstractResource::ContentIntensity contentRatingIntensity(const AppStream::Component &appdata);
+ Q_DECL_EXPORT uint contentRatingMinimumAge(const AppStream::Component &appdata);
+ 
+-Q_DECL_EXPORT QList<AppStream::Component> componentsByCategories(AppStream::Pool *pool, Category *cat, AppStream::Bundle::Kind kind);
++Q_DECL_EXPORT AppStream::ComponentBox componentsByCategories(AppStream::Pool *pool, Category *cat, AppStream::Bundle::Kind kind);
+ }
diff --git a/sysutils/plasma5-discover/files/patch-libdiscover_backends_CMakeLists.txt b/sysutils/plasma5-discover/files/patch-libdiscover_backends_CMakeLists.txt
new file mode 100644
index 000000000000..ed1820a7eb43
--- /dev/null
+++ b/sysutils/plasma5-discover/files/patch-libdiscover_backends_CMakeLists.txt
@@ -0,0 +1,16 @@
+--- libdiscover/backends/CMakeLists.txt.orig	2023-10-24 12:55:33 UTC
++++ libdiscover/backends/CMakeLists.txt
+@@ -8,11 +8,11 @@ endfunction()
+         Qt::Test Qt::Core ${EXTRA_LIBS})
+ endfunction()
+ 
+-if(KF5Attica_FOUND AND KF5NewStuff_FOUND AND AppStreamQt_FOUND)
++if(KF5Attica_FOUND AND KF5NewStuff_FOUND AND AppStreamQt5_FOUND)
+    add_subdirectory(KNSBackend)
+ endif()
+ 
+-if(packagekitqt5_FOUND AND AppStreamQt_FOUND)
++if(packagekitqt5_FOUND AND AppStreamQt5_FOUND)
+     add_subdirectory(PackageKitBackend)
+ endif()
+