Commit 1ef4447b authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Share appstream screenshots code extraction between flatpak and packagekit

parent aeb9e71f
......@@ -23,9 +23,11 @@
#include <QUrl>
#include <QList>
#include <QDebug>
#include <AppStreamQt/image.h>
#include <AppStreamQt/component.h>
#include <AppStreamQt/release.h>
#include <AppStreamQt/screenshot.h>
namespace AppStreamUtils
{
......@@ -55,6 +57,22 @@ static QString changelogToHtml(const AppStream::Component &appdata)
return changelog;
}
static QPair<QList<QUrl>, QList<QUrl>> fetchScreenshots(const AppStream::Component &appdata)
{
QList<QUrl> screenshots, thumbnails;
Q_FOREACH (const AppStream::Screenshot &s, appdata.screenshots()) {
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();
screenshots << plain;
thumbnails << (thumbnail.isEmpty() ? plain : thumbnail);
}
return {screenshots, thumbnails};
}
}
#endif
......@@ -414,19 +414,8 @@ void FlatpakResource::fetchChangelog()
void FlatpakResource::fetchScreenshots()
{
QList<QUrl> thumbnails, screenshots;
Q_FOREACH (const AppStream::Screenshot &s, m_appdata.screenshots()) {
const QUrl thumbnail = AppStreamUtils::imageOfKind(s.images(), AppStream::Image::KindThumbnail);
const QUrl plain = AppStreamUtils::imageOfKind(s.images(), AppStream::Image::KindSource);
if (plain.isEmpty())
qWarning() << "invalid screenshot for" << name();
screenshots << plain;
thumbnails << (thumbnail.isEmpty() ? plain : thumbnail);
}
Q_EMIT screenshotsFetched(thumbnails, screenshots);
const auto sc = AppStreamUtils::fetchScreenshots(m_appdata);
Q_EMIT screenshotsFetched(sc.first, sc.second);
}
void FlatpakResource::setArch(const QString &arch)
......
......@@ -162,19 +162,8 @@ bool AppPackageKitResource::isTechnical() const
void AppPackageKitResource::fetchScreenshots()
{
QList<QUrl> thumbnails, screenshots;
Q_FOREACH (const AppStream::Screenshot &s, m_appdata.screenshots()) {
const QUrl thumbnail = AppStreamUtils::imageOfKind(s.images(), AppStream::Image::KindThumbnail);
const QUrl plain = AppStreamUtils::imageOfKind(s.images(), AppStream::Image::KindSource);
if (plain.isEmpty())
qWarning() << "invalid screenshot for" << name();
screenshots << plain;
thumbnails << (thumbnail.isEmpty() ? plain : thumbnail);
}
Q_EMIT screenshotsFetched(thumbnails, screenshots);
const auto sc = AppStreamUtils::fetchScreenshots(m_appdata);
Q_EMIT screenshotsFetched(sc.first, sc.second);
}
QStringList AppPackageKitResource::allPackageNames() const
......
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