summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2018-12-15 01:44:04 +0100
committerAleix Pol <[email protected]>2018-12-15 01:44:04 +0100
commite3b49c448279209f26f3ea69772cf7cf6c36dbba (patch)
tree68d803b1d001fa24a674f7abcba15899f847faab
parent6ea64d5e780892b78a80ccd0f8b720c500efe50f (diff)
Fix opening flatpakref of already-existing repositories
Instead of loading it, which won't work, pick the resource that we already have. BUG: 401832
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp11
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.cpp14
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.h1
3 files changed, 26 insertions, 0 deletions
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp b/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
index efcacb9..10e8b86 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
+++ b/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
@@ -383,6 +383,17 @@ FlatpakResource * FlatpakBackend::addAppFromFlatpakRef(const QUrl &url)
{
QSettings settings(url.toLocalFile(), QSettings::NativeFormat);
const QString refurl = settings.value(QStringLiteral("Flatpak Ref/Url")).toString();
+ const QString name = settings.value(QStringLiteral("Flatpak Ref/Name")).toString();
+
+ auto item = m_sources->sourceByUrl(refurl);
+ if (item) {
+ const auto resources = resourcesByAppstreamName(name);
+ for (auto resource : resources) {
+ if (resource->origin() == item->data(AbstractSourcesBackend::IdRole)) {
+ return static_cast<FlatpakResource*>(resource);
+ }
+ }
+ }
g_autoptr(GError) error = nullptr;
g_autoptr(FlatpakRemoteRef) remoteRef = nullptr;
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.cpp b/libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.cpp
index ba11f89..c2649ec 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.cpp
+++ b/libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.cpp
@@ -131,6 +131,19 @@ QStandardItem * FlatpakSourcesBackend::sourceById(const QString& id) const
return sourceIt;
}
+QStandardItem * FlatpakSourcesBackend::sourceByUrl(const QString& url) const
+{
+ QStandardItem* sourceIt = nullptr;
+ for (int i = 0, c = m_sources->rowCount(); i<c; ++i) {
+ auto it = m_sources->item(i);
+ if (it->data(Qt::StatusTipRole) == url) {
+ sourceIt = it;
+ break;
+ }
+ }
+ return sourceIt;
+}
+
bool FlatpakSourcesBackend::removeSource(const QString &id)
{
auto sourceIt = sourceById(id);
@@ -244,6 +257,7 @@ void FlatpakSourcesBackend::addRemote(FlatpakRemote *remote, FlatpakInstallation
FlatpakSourceItem *it = new FlatpakSourceItem(!title.isEmpty() ? title : id);
it->setCheckState(flatpak_remote_get_disabled(remote) ? Qt::Unchecked : Qt::Checked);
it->setData(remoteUrl.isLocalFile() ? remoteUrl.toLocalFile() : remoteUrl.host(), Qt::ToolTipRole);
+ it->setData(remoteUrl, Qt::StatusTipRole);
it->setData(id, IdRole);
it->setFlatpakInstallation(installation);
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.h b/libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.h
index 8ac11e2..8918810 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.h
+++ b/libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.h
@@ -50,6 +50,7 @@ public:
bool moveSource(const QString & sourceId, int delta) override;
int originIndex(const QString& sourceId) const;
+ QStandardItem* sourceByUrl(const QString & url) const;
private:
QStandardItem* sourceById(const QString & sourceId) const;