Commit 834c7566 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

snap: Properly communicate a snap's licence

Treat it as an SPDX expression and parse it using AppStream.
http://people.ubuntu.com/~robert-ancell/snapd-glib/reference/SnapdSnap.html#snapd-snap-get-license

CCBUG: 454480
parent c196423a
Pipeline #221517 passed with stage
in 1 minute and 13 seconds
......@@ -62,11 +62,16 @@ QPair<QList<QUrl>, QList<QUrl>> AppStreamUtils::fetchScreenshots(const AppStream
}
QJsonArray AppStreamUtils::licenses(const AppStream::Component &appdata)
{
return licenses(appdata.projectLicense());
}
QJsonArray AppStreamUtils::licenses(const QString &spdx)
{
static const QSet<QChar> tokens = {'&', '+', '|', '^', '(', ')'};
QJsonArray ret;
const auto licenses = AppStream::SPDX::tokenizeLicense(appdata.projectLicense());
const auto licenses = AppStream::SPDX::tokenizeLicense(spdx);
for (const auto &token : licenses) {
if (token.size() == 1 && tokens.contains(token.at(0)))
continue;
......
......@@ -22,6 +22,8 @@ Q_DECL_EXPORT QPair<QList<QUrl>, QList<QUrl>> fetchScreenshots(const AppStream::
Q_DECL_EXPORT QJsonArray licenses(const AppStream::Component &appdata);
Q_DECL_EXPORT QJsonArray licenses(const QString &spdxExpression);
Q_DECL_EXPORT QJsonObject license(const QString &spdxId);
Q_DECL_EXPORT QStringList appstreamIds(const QUrl &appstreamUrl);
......
......@@ -17,6 +17,7 @@
#include <Snapd/MarkdownParser>
#endif
#include <appstream/AppStreamUtils.h>
#include <utils.h>
QDebug operator<<(QDebug debug, const QSnapdPlug &plug)
......@@ -149,7 +150,7 @@ QString SnapResource::installedVersion() const
QJsonArray SnapResource::licenses()
{
return {QJsonObject{{QStringLiteral("name"), m_snap->license()}}};
return AppStreamUtils::licenses(m_snap->license());
}
#ifdef SNAP_MARKDOWN
......
Supports Markdown
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