Commit 326501d6 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

Provide the alternatives to an appstream id together with the URL

This way we can count on the symmetry and don't reach cases like in the
closed bug report where the flatpak id is not offered by the one coming
from packagekit but not vice-versa.

BUG: 441299


(cherry picked from commit 238f68a9)
parent 48ee7b1e
Pipeline #238098 passed with stage
in 1 minute and 43 seconds
......@@ -49,6 +49,7 @@
#include <glib.h>
#include <optional>
#include <set>
#include <sys/stat.h>
DISCOVER_BACKEND_PLUGIN(FlatpakBackend)
......@@ -1585,13 +1586,21 @@ ResultsStream *FlatpakBackend::findResourceByPackageName(const QUrl &url)
if (appstreamIds.isEmpty())
Q_EMIT passiveMessage(i18n("Malformed appstream url '%1'", url.toDisplayString()));
else {
auto stream = new ResultsStream(QStringLiteral("FlatpakStream"));
auto f = [this, stream, appstreamIds]() {
const auto resources = kAppend<QVector<AbstractResource *>>(appstreamIds, [this](const QString &appstreamId) {
return resourcesByAppstreamName(appstreamId);
});
if (!resources.isEmpty())
Q_EMIT stream->resourcesFound(resources);
auto stream = new ResultsStream(QStringLiteral("FlatpakStream-AppStreamUrl"));
auto f = [this, stream, appstreamIds] {
std::set<AbstractResource *> resources;
QVector<AbstractResource *> resourcesVector;
for (const auto &appstreamId : appstreamIds) {
const auto resourcesFound = resourcesByAppstreamName(appstreamId);
for (auto res : resourcesFound) {
auto [x, inserted] = resources.insert(res);
if (inserted) {
resourcesVector.append(res);
}
}
}
if (!resourcesVector.isEmpty())
Q_EMIT stream->resourcesFound(resourcesVector);
stream->finish();
};
......
......@@ -625,7 +625,19 @@ QString FlatpakResource::installPath() const
QUrl FlatpakResource::url() const
{
return m_resourceFile.isEmpty() ? QUrl(QStringLiteral("appstream://") + appstreamId()) : m_resourceFile;
if (!m_resourceFile.isEmpty()) {
return m_resourceFile;
}
QUrl ret(QStringLiteral("appstream://") + appstreamId());
const AppStream::Provided::Kind AppStream_Provided_KindId = (AppStream::Provided::Kind)12; // Should be AppStream::Provided::KindId when released
const auto provided = m_appdata.provided(AppStream_Provided_KindId).items();
if (!provided.isEmpty()) {
QUrlQuery qq;
qq.addQueryItem("alt", provided.join(QLatin1Char(',')));
ret.setQuery(qq);
}
return ret;
}
QDate FlatpakResource::releaseDate() const
......
......@@ -17,6 +17,7 @@
#include <QIcon>
#include <QProcess>
#include <QStandardPaths>
#include <QUrlQuery>
#include <appstream/AppStreamUtils.h>
AppPackageKitResource::AppPackageKitResource(const AppStream::Component &data, const QString &packageName, PackageKitBackend *parent)
......@@ -128,6 +129,19 @@ QSet<QString> AppPackageKitResource::alternativeAppstreamIds() const
return QSet<QString>(ret.begin(), ret.end());
}
QUrl AppPackageKitResource::url() const
{
QUrl ret(QStringLiteral("appstream://") + appstreamId());
const AppStream::Provided::Kind AppStream_Provided_KindId = (AppStream::Provided::Kind)12; // Should be AppStream::Provided::KindId when released
const auto provided = m_appdata.provided(AppStream_Provided_KindId).items();
if (!provided.isEmpty()) {
QUrlQuery qq;
qq.addQueryItem("alt", provided.join(QLatin1Char(',')));
ret.setQuery(qq);
}
return ret;
}
QUrl AppPackageKitResource::homepage()
{
return m_appdata.url(AppStream::Component::UrlKindHomepage);
......
......@@ -24,6 +24,7 @@ public:
QStringList mimetypes() const override;
QStringList categories() override;
QString longDescription() override;
QUrl url() const override;
QUrl homepage() override;
QUrl helpURL() override;
QUrl bugURL() override;
......
......@@ -531,6 +531,8 @@ bool ResourcesProxyModel::isSorted(const QVector<AbstractResource *> &resources)
void ResourcesProxyModel::sortedInsertion(const QVector<AbstractResource *> &_res)
{
Q_ASSERT(_res.size() == QSet(_res.constBegin(), _res.constEnd()).size());
auto resources = _res;
Q_ASSERT(!resources.isEmpty());
......
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