summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2017-04-19 16:34:40 +0200
committerAleix Pol <[email protected]>2017-04-19 16:34:40 +0200
commit6d1c4f6a2d2fb370e7d095d687f33af22c1b9465 (patch)
tree78799d899e013ceb9d051fcf1f1ae733e0b31979
parentd873c0b8a995f7ddd9dac7810a62c15f99f3eddd (diff)
Remove the concept of scope
Store the FlatpakInstallation instance the resource is coming from rather than having a scope property we go back and forth from. This allows to integrate any sources without having to take into consideration these specificities. Allows for example the inclusion of installations with flatpak_get_system_installations
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp39
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakBackend.h1
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakResource.cpp54
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakResource.h23
4 files changed, 32 insertions, 85 deletions
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp b/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
index f212c15..da51a67 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
+++ b/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
@@ -280,7 +280,7 @@ FlatpakResource * FlatpakBackend::addAppFromFlatpakBundle(const QUrl &url)
gsize len = 0;
g_autoptr(GBytes) iconData = nullptr;
g_autoptr(GBytes) metadata = nullptr;
- FlatpakResource *resource = new FlatpakResource(asComponent, this);
+ FlatpakResource *resource = new FlatpakResource(asComponent, preferredInstallation(), this);
metadata = flatpak_bundle_ref_get_metadata(bundleRef);
QByteArray metadataContent = QByteArray((char *)g_bytes_get_data(metadata, &len));
@@ -359,7 +359,7 @@ FlatpakResource * FlatpakBackend::addAppFromFlatpakRef(const QUrl &url)
}
AppStream::Component *asComponent = new AppStream::Component(component);
- auto resource = new FlatpakResource(asComponent, this);
+ auto resource = new FlatpakResource(asComponent, preferredInstallation(), this);
resource->setFlatpakFileType(QStringLiteral("flatpakref"));
resource->setOrigin(QString::fromUtf8(remoteName));
resource->updateFromRef(ref);
@@ -397,7 +397,7 @@ FlatpakResource * FlatpakBackend::addSourceFromFlatpakRepo(const QUrl &url)
}
AppStream::Component *asComponent = new AppStream::Component(component);
- auto resource = new FlatpakResource(asComponent, this);
+ auto resource = new FlatpakResource(asComponent, preferredInstallation(), this);
// Use metadata only for stuff which are not common for all resources
resource->addMetadata(QStringLiteral("gpg-key"), gpgKey);
resource->addMetadata(QStringLiteral("repo-url"), repoUrl);
@@ -422,7 +422,7 @@ void FlatpakBackend::addResource(FlatpakResource *resource)
qWarning() << "Failed to parse metadata from app bundle for " << resource->name();
}
- auto installation = flatpakInstallationForAppScope(resource->scope());
+ auto installation = resource->installation();
updateAppState(installation, resource);
// This will update also metadata (required runtime)
@@ -438,7 +438,6 @@ bool FlatpakBackend::compareAppFlatpakRef(FlatpakInstallation *flatpakInstallati
const QString arch = QString::fromUtf8(flatpak_ref_get_arch(FLATPAK_REF(ref)));
const QString branch = QString::fromUtf8(flatpak_ref_get_branch(FLATPAK_REF(ref)));
FlatpakResource::ResourceType appType = flatpak_ref_get_kind(FLATPAK_REF(ref)) == FLATPAK_REF_KIND_APP ? FlatpakResource::DesktopApp : FlatpakResource::Runtime;
- FlatpakResource::Scope appScope = flatpak_installation_get_is_user(flatpakInstallation) ? FlatpakResource::User : FlatpakResource::System;
g_autofree gchar *appId = nullptr;
@@ -448,7 +447,7 @@ bool FlatpakBackend::compareAppFlatpakRef(FlatpakInstallation *flatpakInstallati
appId = g_strdup(flatpak_ref_get_name(FLATPAK_REF(ref)));
}
- const QString uniqueId = QStringLiteral("%1/%2/%3/%4/%5/%6").arg(FlatpakResource::scopeAsString(appScope))
+ const QString uniqueId = QStringLiteral("%1/%2/%3/%4/%5/%6").arg(FlatpakResource::installationPath(flatpakInstallation))
.arg(QLatin1String("flatpak"))
.arg(QString::fromUtf8(flatpak_installed_ref_get_origin(ref)))
.arg(FlatpakResource::typeAsString(appType))
@@ -542,12 +541,10 @@ void FlatpakBackend::integrateRemote(FlatpakInstallation *flatpakInstallation, F
}
g_autoptr(GPtrArray) components = as_metadata_get_components(metadata);
- const FlatpakResource::Scope scope = flatpak_installation_get_is_user(flatpakInstallation) ? FlatpakResource::User : FlatpakResource::System;
for (uint i = 0; i < components->len; i++) {
AsComponent *component = AS_COMPONENT(g_ptr_array_index(components, i));
AppStream::Component *appstreamComponent = new AppStream::Component(component);
- FlatpakResource *resource = new FlatpakResource(appstreamComponent, this);
- resource->setScope(scope);
+ FlatpakResource *resource = new FlatpakResource(appstreamComponent, flatpakInstallation, this);
resource->setIconPath(appstreamDirPath);
resource->setOrigin(source.name());
addResource(resource);
@@ -556,12 +553,11 @@ void FlatpakBackend::integrateRemote(FlatpakInstallation *flatpakInstallation, F
bool FlatpakBackend::loadInstalledApps(FlatpakInstallation *flatpakInstallation)
{
- Q_ASSERT(flatpakInstallation)
+ Q_ASSERT(flatpakInstallation);
// List installed applications from installed desktop files
- g_autoptr(GFile) path = flatpak_installation_get_path(flatpakInstallation);
- const auto pathExports = QString::fromUtf8(g_file_get_path(path)) + QLatin1String("/exports/");
- const auto pathApps = pathExports + QLatin1String("share/applications/");
+ const QString pathExports = FlatpakResource::installationPath(flatpakInstallation) + QLatin1String("/exports/");
+ const QString pathApps = pathExports + QLatin1String("share/applications/");
const QDir dir(pathApps);
if (dir.exists()) {
@@ -591,9 +587,8 @@ bool FlatpakBackend::loadInstalledApps(FlatpakInstallation *flatpakInstallation)
component = as_metadata_get_component(metadata);
AppStream::Component *appstreamComponent = new AppStream::Component(component);
- FlatpakResource *resource = new FlatpakResource(appstreamComponent, this);
+ FlatpakResource *resource = new FlatpakResource(appstreamComponent, flatpakInstallation, this);
- resource->setScope(flatpak_installation_get_is_user(flatpakInstallation) ? FlatpakResource::User : FlatpakResource::System);
resource->setIconPath(pathExports);
resource->setType(FlatpakResource::DesktopApp);
resource->setState(AbstractResource::Installed);
@@ -604,7 +599,6 @@ bool FlatpakBackend::loadInstalledApps(FlatpakInstallation *flatpakInstallation)
// Compare the only information we have
if (res->appstreamId() == QStringLiteral("%1.desktop").arg(resource->appstreamId()) && res->name() == resource->name()) {
resourceExists = true;
- res->setScope(resource->scope());
res->setState(resource->state());
break;
}
@@ -965,15 +959,6 @@ AbstractReviewsBackend * FlatpakBackend::reviewsBackend() const
return m_reviews;
}
-FlatpakInstallation * FlatpakBackend::flatpakInstallationForAppScope(FlatpakResource::Scope appScope) const
-{
- if (appScope == FlatpakResource::Scope::System) {
- return preferredInstallation();
- } else {
- return m_installations.last();
- }
-}
-
void FlatpakBackend::installApplication(AbstractResource *app, const AddonList &addons)
{
Q_UNUSED(addons);
@@ -991,7 +976,7 @@ void FlatpakBackend::installApplication(AbstractResource *app, const AddonList &
}
FlatpakTransaction *transaction = nullptr;
- FlatpakInstallation *installation = flatpakInstallationForAppScope(resource->scope());
+ FlatpakInstallation *installation = resource->installation();
if (resource->propertyState(FlatpakResource::RequiredRuntime) == FlatpakResource::NotKnownYet && resource->type() == FlatpakResource::DesktopApp) {
transaction = new FlatpakTransaction(installation, resource, Transaction::InstallRole, true);
@@ -1041,7 +1026,7 @@ void FlatpakBackend::removeApplication(AbstractResource *app)
return;
}
- FlatpakInstallation *installation = flatpakInstallationForAppScope(resource->scope());
+ FlatpakInstallation *installation = resource->installation();
FlatpakTransaction *transaction = new FlatpakTransaction(installation, resource, Transaction::RemoveRole);
connect(transaction, &FlatpakTransaction::statusChanged, [this, installation, resource] (Transaction::Status status) {
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakBackend.h b/libdiscover/backends/FlatpakBackend/FlatpakBackend.h
index 8b31bd4..1f8d9b3 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakBackend.h
+++ b/libdiscover/backends/FlatpakBackend/FlatpakBackend.h
@@ -53,7 +53,6 @@ public:
bool isValid() const override;
QList<QAction*> messageActions() const override { return m_messageActions; }
- FlatpakInstallation *flatpakInstallationForAppScope(FlatpakResource::Scope appScope) const;
void installApplication(AbstractResource* app) override;
void installApplication(AbstractResource* app, const AddonList& addons) override;
void removeApplication(AbstractResource* app) override;
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakResource.cpp b/libdiscover/backends/FlatpakBackend/FlatpakResource.cpp
index b356fcb..2de60a5 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakResource.cpp
+++ b/libdiscover/backends/FlatpakBackend/FlatpakResource.cpp
@@ -42,13 +42,13 @@
#include <QStringList>
#include <QTimer>
-FlatpakResource::FlatpakResource(AppStream::Component *component, FlatpakBackend *parent)
+FlatpakResource::FlatpakResource(AppStream::Component *component, FlatpakInstallation* installation, FlatpakBackend *parent)
: AbstractResource(parent)
, m_appdata(component)
, m_downloadSize(0)
, m_installedSize(0)
, m_propertyStates({{DownloadSize, NotKnownYet}, {InstalledSize, NotKnownYet},{RequiredRuntime, NotKnownYet}})
- , m_scope(FlatpakResource::System)
+ , m_installation(installation)
, m_state(AbstractResource::None)
, m_type(FlatpakResource::DesktopApp)
{
@@ -328,16 +328,6 @@ static QUrl screenshot(AppStream::Component *comp, AppStream::Image::Kind kind)
return ret;
}
-FlatpakResource::Scope FlatpakResource::scope() const
-{
- return m_scope;
-}
-
-QString FlatpakResource::scopeAsString() const
-{
- return m_scope == System ? QLatin1String("system") : QLatin1String("user");
-}
-
QUrl FlatpakResource::screenshotUrl()
{
return screenshot(m_appdata, AppStream::Image::KindSource);
@@ -410,8 +400,7 @@ QString FlatpakResource::typeAsString() const
QString FlatpakResource::uniqueId() const
{
// Build uniqueId
- const QString scope = m_scope == System ? QLatin1String("system") : QLatin1String("user");
- return QString::fromUtf8("%1/%2/%3/%4/%5/%6").arg(scope)
+ return QString::fromUtf8("%1/%2/%3/%4/%5/%6").arg(installationPath())
.arg(QLatin1String("flatpak"))
.arg(origin())
.arg(typeAsString())
@@ -424,9 +413,7 @@ void FlatpakResource::invokeApplication() const
g_autoptr(GCancellable) cancellable = g_cancellable_new();
g_autoptr(GError) localError = nullptr;
- const FlatpakBackend *p = static_cast<FlatpakBackend*>(parent());
-
- if (!flatpak_installation_launch(p->flatpakInstallationForAppScope(scope()),
+ if (!flatpak_installation_launch(m_installation,
flatpakName().toStdString().c_str(),
arch().toStdString().c_str(),
branch().toStdString().c_str(),
@@ -539,11 +526,6 @@ void FlatpakResource::setRuntime(const QString &runtime)
setPropertyState(RequiredRuntime, AlreadyKnown);
}
-void FlatpakResource::setScope(FlatpakResource::Scope scope)
-{
- m_scope = scope;
-}
-
void FlatpakResource::setState(AbstractResource::State state)
{
if (m_state != state) {
@@ -558,21 +540,13 @@ void FlatpakResource::setType(FlatpakResource::ResourceType type)
m_type = type;
}
-// void FlatpakResource::setAddons(const AddonList& addons)
-// {
-// Q_FOREACH (const QString& toInstall, addons.addonsToInstall()) {
-// setAddonInstalled(toInstall, true);
-// }
-// Q_FOREACH (const QString& toRemove, addons.addonsToRemove()) {
-// setAddonInstalled(toRemove, false);
-// }
-// }
-
-// void FlatpakResource::setAddonInstalled(const QString& addon, bool installed)
-// {
-// for(auto & elem : m_addons) {
-// if(elem.name() == addon) {
-// elem.setInstalled(installed);
-// }
-// }
-// }
+QString FlatpakResource::installationPath() const
+{
+ return installationPath(m_installation);
+}
+
+QString FlatpakResource::installationPath(FlatpakInstallation* flatpakInstallation)
+{
+ g_autoptr(GFile) path = flatpak_installation_get_path(flatpakInstallation);
+ return QString::fromUtf8(g_file_get_path(path));
+}
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakResource.h b/libdiscover/backends/FlatpakBackend/FlatpakResource.h
index 1c3ba8e..9f6c3d9 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakResource.h
+++ b/libdiscover/backends/FlatpakBackend/FlatpakResource.h
@@ -38,7 +38,7 @@ class FlatpakResource : public AbstractResource
{
Q_OBJECT
public:
- explicit FlatpakResource(AppStream::Component *component, FlatpakBackend *parent);
+ explicit FlatpakResource(AppStream::Component *component, FlatpakInstallation* installation, FlatpakBackend *parent);
enum PropertyKind {
DownloadSize = 0,
@@ -58,13 +58,6 @@ public:
Source
};
- enum Scope {
- System = 0,
- User
- };
-
- Q_ENUM(Scope)
-
static QString typeAsString(ResourceType type) {
if (type == DesktopApp) {
return QLatin1String("app");
@@ -72,12 +65,8 @@ public:
return QLatin1String("runtime");
}
- static QString scopeAsString(Scope scope) {
- if (scope == System) {
- return QLatin1String("system");
- }
- return QLatin1String("user");
- }
+ QString installationPath() const;
+ static QString installationPath(FlatpakInstallation* installation);
AppStream::Component *appstreamComponent() const;
QList<PackageState> addonsInformation() override;
@@ -107,7 +96,6 @@ public:
QUrl resourceFile() const;
QString runtime() const;
QUrl screenshotUrl() override;
- Scope scope() const;
QString scopeAsString() const;
QString section() override;
int size() override;
@@ -118,6 +106,8 @@ public:
QString typeAsString() const;
QString uniqueId() const;
+ FlatpakInstallation* installation() const { return m_installation; }
+
void invokeApplication() const override;
void fetchChangelog() override;
void fetchScreenshots() override;
@@ -135,7 +125,6 @@ public:
void setPropertyState(PropertyKind kind, PropertyState state);
void setResourceFile(const QUrl &url);
void setRuntime(const QString &runtime);
- void setScope(Scope scope);
void setState(State state);
void setType(ResourceType type);
// void setAddons(const AddonList& addons);
@@ -163,7 +152,7 @@ public:
QHash<PropertyKind, PropertyState> m_propertyStates;
QUrl m_resourceFile;
QString m_runtime;
- Scope m_scope;
+ FlatpakInstallation* const m_installation;
AbstractResource::State m_state;
ResourceType m_type;
};