Commit 47d6d143 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Share appstream screenshots code

parent b53ad168
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
#include <Transaction/AddonList.h> #include <Transaction/AddonList.h>
#include <AppStreamQt/icon.h> #include <AppStreamQt/icon.h>
#include <AppStreamQt/image.h>
#include <AppStreamQt/screenshot.h> #include <AppStreamQt/screenshot.h>
#include <appstream/AppStreamUtils.h>
#include <KFormat> #include <KFormat>
#include <KLocalizedString> #include <KLocalizedString>
...@@ -305,29 +305,6 @@ QString FlatpakResource::runtime() const ...@@ -305,29 +305,6 @@ QString FlatpakResource::runtime() const
return m_runtime; return m_runtime;
} }
static QUrl imageOfKind(const QList<AppStream::Image> &images, AppStream::Image::Kind kind)
{
QUrl ret;
Q_FOREACH (const AppStream::Image &i, images) {
if (i.kind() == kind) {
ret = i.url();
break;
}
}
return ret;
}
static QUrl screenshot(AppStream::Component comp, AppStream::Image::Kind kind)
{
QUrl ret;
Q_FOREACH (const AppStream::Screenshot &s, comp.screenshots()) {
ret = imageOfKind(s.images(), kind);
if (s.isDefault() && !ret.isEmpty())
break;
}
return ret;
}
QString FlatpakResource::section() QString FlatpakResource::section()
{ {
return QString(); return QString();
...@@ -427,8 +404,8 @@ void FlatpakResource::fetchScreenshots() ...@@ -427,8 +404,8 @@ void FlatpakResource::fetchScreenshots()
QList<QUrl> thumbnails, screenshots; QList<QUrl> thumbnails, screenshots;
Q_FOREACH (const AppStream::Screenshot &s, m_appdata.screenshots()) { Q_FOREACH (const AppStream::Screenshot &s, m_appdata.screenshots()) {
const QUrl thumbnail = imageOfKind(s.images(), AppStream::Image::KindThumbnail); const QUrl thumbnail = AppStreamUtils::imageOfKind(s.images(), AppStream::Image::KindThumbnail);
const QUrl plain = imageOfKind(s.images(), AppStream::Image::KindSource); const QUrl plain = AppStreamUtils::imageOfKind(s.images(), AppStream::Image::KindSource);
if (plain.isEmpty()) if (plain.isEmpty())
qWarning() << "invalid screenshot for" << name(); qWarning() << "invalid screenshot for" << name();
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <AppStreamQt/icon.h> #include <AppStreamQt/icon.h>
#include <AppStreamQt/image.h> #include <AppStreamQt/image.h>
#include <AppStreamQt/release.h> #include <AppStreamQt/release.h>
#include <appstream/AppStreamUtils.h>
#include <KLocalizedString> #include <KLocalizedString>
#include <KToolInvocation> #include <KToolInvocation>
#include <QIcon> #include <QIcon>
...@@ -131,36 +132,13 @@ QStringList AppPackageKitResource::executables() const ...@@ -131,36 +132,13 @@ QStringList AppPackageKitResource::executables() const
return m_appdata.provided(AppStream::Provided::KindBinary).items(); return m_appdata.provided(AppStream::Provided::KindBinary).items();
} }
static QUrl imageOfKind(const QList<AppStream::Image>& images, AppStream::Image::Kind kind)
{
QUrl ret;
Q_FOREACH (const AppStream::Image &i, images) {
if (i.kind() == kind) {
ret = i.url();
break;
}
}
return ret;
}
static QUrl screenshot(const AppStream::Component& comp, AppStream::Image::Kind kind)
{
QUrl ret;
Q_FOREACH (const AppStream::Screenshot &s, comp.screenshots()) {
ret = imageOfKind(s.images(), kind);
if (s.isDefault() && !ret.isEmpty())
break;
}
return ret;
}
void AppPackageKitResource::fetchScreenshots() void AppPackageKitResource::fetchScreenshots()
{ {
QList<QUrl> thumbnails, screenshots; QList<QUrl> thumbnails, screenshots;
Q_FOREACH (const AppStream::Screenshot &s, m_appdata.screenshots()) { Q_FOREACH (const AppStream::Screenshot &s, m_appdata.screenshots()) {
const QUrl thumbnail = imageOfKind(s.images(), AppStream::Image::KindThumbnail); const QUrl thumbnail = AppStreamUtils::imageOfKind(s.images(), AppStream::Image::KindThumbnail);
const QUrl plain = imageOfKind(s.images(), AppStream::Image::KindSource); const QUrl plain = AppStreamUtils::imageOfKind(s.images(), AppStream::Image::KindSource);
if (plain.isEmpty()) if (plain.isEmpty())
qWarning() << "invalid screenshot for" << name(); qWarning() << "invalid screenshot for" << name();
......
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