Commit 36095ea6 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Implement adding flatpak repositories from the sources page

parent fc4f50aa
......@@ -115,7 +115,6 @@ DiscoverPage {
// iconName: "list-add"
text: i18n("Add Source")
visible: sourcesMenu.items.count > 0
tooltip: text
menu: sourcesMenu
}
......
......@@ -62,6 +62,7 @@ public:
void checkForUpdates() override;
QString displayName() const override;
bool hasApplications() const override { return true; }
FlatpakResource * addSourceFromFlatpakRepo(const QUrl &url);
private Q_SLOTS:
void onFetchMetadataFinished(FlatpakInstallation *flatpakInstallation, FlatpakResource *resource, const QByteArray &metadata);
......@@ -79,7 +80,6 @@ private:
FlatpakResource * addAppFromFlatpakBundle(const QUrl &url);
FlatpakResource * addAppFromFlatpakRef(const QUrl &url);
FlatpakResource * addSourceFromFlatpakRepo(const QUrl &url);
void addResource(FlatpakResource *resource);
bool compareAppFlatpakRef(FlatpakInstallation *flatpakInstallation, FlatpakResource *resource, FlatpakInstalledRef *ref);
bool loadAppsFromAppstreamData(FlatpakInstallation *flatpakInstallation);
......
......@@ -21,10 +21,15 @@
#include "FlatpakSourcesBackend.h"
#include "FlatpakResource.h"
#include "FlatpakBackend.h"
#include <KLocalizedString>
#include <QDebug>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <glib.h>
#include <QTemporaryFile>
#include <QStandardPaths>
class FlatpakSourceItem : public QStandardItem
{
......@@ -59,10 +64,42 @@ QAbstractItemModel* FlatpakSourcesBackend::sources()
return m_sources;
}
static void addRepo(FlatpakBackend* backend, const QUrl &fileUrl)
{
Q_ASSERT(backend);
auto res = backend->addSourceFromFlatpakRepo(fileUrl);
if (!res) {
qWarning() << "Couldn't add" << fileUrl;
return;
}
backend->installApplication(res);
}
bool FlatpakSourcesBackend::addSource(const QString &id)
{
Q_UNUSED(id);
return false;
FlatpakBackend* backend = qobject_cast<FlatpakBackend*>(parent());
const QUrl flatpakrepoUrl = QUrl::fromUserInput(id);
if (flatpakrepoUrl.isLocalFile()) {
addRepo(backend, flatpakrepoUrl);
} else {
const QUrl fileUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + QLatin1Char('/') + flatpakrepoUrl.fileName());
QNetworkAccessManager* manager = new QNetworkAccessManager(this);
auto replyGet = manager->get(QNetworkRequest(flatpakrepoUrl));
connect(replyGet, &QNetworkReply::finished, this, [this, manager, replyGet, fileUrl, backend] {
if (replyGet->error() != QNetworkReply::NoError)
return;
auto replyPut = manager->put(QNetworkRequest(fileUrl), replyGet->readAll());
connect(replyPut, &QNetworkReply::finished, this, [fileUrl, backend, manager]() {
addRepo(backend, fileUrl);
delete manager;
});
});
}
return true;
}
bool FlatpakSourcesBackend::removeSource(const QString &id)
......@@ -173,3 +210,8 @@ FlatpakRemote * FlatpakSourcesBackend::installSource(FlatpakResource *resource)
return remote;
}
QString FlatpakSourcesBackend::idDescription()
{
return i18n("Flatpak repository URI (*.flatpakrepo)");
}
......@@ -39,7 +39,7 @@ public:
bool addSource(const QString &id) override;
bool removeSource(const QString &id) override;
QString name() const override { return QStringLiteral("Flatpak"); }
QString idDescription() override { return QStringLiteral("Flatpak remote repositories"); }
QString idDescription() override;
QList<QAction*> actions() const override;
FlatpakRemote * installSource(FlatpakResource *resource);
......
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