Commit 04b755cc authored by Volker Krause's avatar Volker Krause
Browse files

Allow the AssetRepository to contribute attribution data to results

This allows us to use line logos under licenses needing attribution,
which significantly increases the amount of icons we can use from
Wikimedia Commons.
parent 44c5eb17
Pipeline #90097 passed with stage
in 1 minute and 41 seconds
......@@ -480,6 +480,10 @@ void Generator::verifyImageMetaData(std::vector<wd::Image> &&images)
const QStringList valid_licenses({
QStringLiteral("cc0"),
QStringLiteral("public domain"),
QStringLiteral("cc by 3.0"),
QStringLiteral("cc by-sa 3.0"),
QStringLiteral("cc-by-sa-3.0"),
QStringLiteral("cc by-sa 4.0"),
});
for (auto &image : images) {
......
......@@ -99,6 +99,7 @@ target_sources(KPublicTransport PRIVATE
ifopt/ifoptutil.cpp
knowledgedb/asset-attributions.qrc
knowledgedb/linemetadata.cpp
models/abstractquerymodel.cpp
......
......@@ -5,10 +5,15 @@
*/
#include "assetrepository_p.h"
#include "logging.h"
#include <KPublicTransport/Attribution>
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QJsonArray>
#include <QJsonDocument>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QStandardPaths>
......@@ -133,3 +138,18 @@ void AssetRepository::downloadNext()
downloadNext();
});
}
const std::vector<Attribution>& AssetRepository::attributions() const
{
if (m_attributions.empty()) {
QFile f(QStringLiteral(":/org.kde.kpublictransport/assets/asset-attributions.json"));
if (!f.open(QFile::ReadOnly)) {
qCWarning(Log) << f.fileName() << f.errorString();
return m_attributions;
}
m_attributions = Attribution::fromJson(QJsonDocument::fromJson(f.readAll()).array());
}
return m_attributions;
}
......@@ -18,6 +18,8 @@ class QNetworkAccessManager;
namespace KPublicTransport {
class Attribution;
/**
* Access and downloading of line logos.
*/
......@@ -42,6 +44,9 @@ public:
/** Returns @c true if no further download jobs are queued or in progress. */
bool isQueueEmpty();
/** Returns attributions for the provided assets. */
const std::vector<Attribution>& attributions() const;
static AssetRepository* instance();
Q_SIGNALS:
......@@ -60,6 +65,7 @@ private:
static AssetRepository *s_instance;
std::deque<QUrl> m_queue;
QNetworkAccessManager *m_nam = nullptr;
mutable std::vector<Attribution> m_attributions;
};
}
......
......@@ -14,12 +14,20 @@ using namespace KPublicTransport;
static bool attrLessThan(const Attribution &lhs, const Attribution &rhs)
{
return QString::compare(lhs.name(), rhs.name(), Qt::CaseInsensitive) < 0;
const auto nameCmp = QString::compare(lhs.name(), rhs.name(), Qt::CaseInsensitive);
if (nameCmp == 0) {
return QString::compare(lhs.license(), rhs.license(), Qt::CaseInsensitive) < 0;
}
return nameCmp < 0;
}
static bool attrEqual(const Attribution &lhs, const Attribution &rhs)
{
return QString::compare(lhs.name(),rhs.name(), Qt::CaseInsensitive) == 0;
const auto nameCmp = QString::compare(lhs.name(), rhs.name(), Qt::CaseInsensitive);
if (nameCmp == 0) {
return QString::compare(lhs.license(), rhs.license(), Qt::CaseInsensitive) == 0;
}
return nameCmp == 0;
}
void AttributionUtil::sort(std::vector<Attribution> &attrs)
......
[
{
"name": "Wikimedia Commons",
"url": "https://commons.wikimedia.org/",
"license": "CC-BY-SA-4.0",
"licenseUrl": "https://creativecommons.org/licenses/by-sa/4.0/"
},
{
"name": "Wikimedia Commons",
"url": "https://commons.wikimedia.org/",
"license": "CC-BY-SA-3.0",
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0/"
},
{
"name": "Wikimedia Commons",
"url": "https://commons.wikimedia.org/",
"license": "CC-BY-3.0",
"licenseUrl": "https://creativecommons.org/licenses/by/3.0/"
},
{
"name": "Wikimedia Commons",
"url": "https://commons.wikimedia.org/",
"license": "CC0-1.0",
"licenseUrl": "https://creativecommons.org/publicdomain/zero/1.0/"
}
]
# SPDX-FileCopyrightText: 2021 Volker Krause
# SPDX-License-Identifier: CC0-1.0
<!--
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: CC0-1.0
-->
<RCC>
<qresource prefix="/org.kde.kpublictransport/assets/">
<file>asset-attributions.json</file>
</qresource>
</RCC>
......@@ -566,6 +566,9 @@ JourneyReply* Manager::queryJourney(const JourneyRequest &req) const
}
}
if (req.downloadAssets()) {
reply->addAttributions(AssetRepository::instance()->attributions());
}
reply->setPendingOps(pendingOps);
return reply;
}
......@@ -637,6 +640,9 @@ StopoverReply* Manager::queryStopover(const StopoverRequest &req) const
}
}
if (req.downloadAssets()) {
reply->addAttributions(AssetRepository::instance()->attributions());
}
reply->setPendingOps(pendingOps);
return reply;
}
......
......@@ -100,3 +100,8 @@ void Reply::addAttribution(const Attribution &attr)
{
AttributionUtil::merge(d_ptr->attributions, attr);
}
void Reply::addAttributions(const std::vector<Attribution> &attributions)
{
AttributionUtil::merge(d_ptr->attributions, attributions);
}
......@@ -68,6 +68,7 @@ protected:
*/
Q_DECL_HIDDEN void addError(Error error, const QString &errorMsg);
Q_DECL_HIDDEN void addAttributions(std::vector<Attribution> &&attributions);
Q_DECL_HIDDEN void addAttributions(const std::vector<Attribution> &attributions);
friend class Manager;
friend class ManagerPrivate;
......
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