summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2017-04-19 16:10:53 +0200
committerAleix Pol <[email protected]>2017-04-19 16:10:53 +0200
commitd873c0b8a995f7ddd9dac7810a62c15f99f3eddd (patch)
treeda3e9a789512e0df0594cd8293b5517df95bfe07
parentb464b2ef5ae723f4e00a986067da77ad4b670e36 (diff)
Reduce semantics between user and system installations
They are not really bringing anything and it's largely circumstantial An distro could be relying on the user installing himself rather than the on the system
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp87
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakBackend.h4
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.cpp20
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.h4
4 files changed, 50 insertions, 65 deletions
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp b/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
index fcc8f12..f212c15 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
+++ b/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
@@ -77,7 +77,7 @@ FlatpakBackend::FlatpakBackend(QObject* parent)
checkForUpdates();
- m_sources = new FlatpakSourcesBackend(m_flatpakInstallationSystem, m_flatpakInstallationUser, this);
+ m_sources = new FlatpakSourcesBackend(m_installations, this);
SourcesModel::global()->addSourcesBackend(m_sources);
}
@@ -94,14 +94,15 @@ FlatpakBackend::FlatpakBackend(QObject* parent)
FlatpakBackend::~FlatpakBackend()
{
- g_object_unref(m_flatpakInstallationSystem);
- g_object_unref(m_flatpakInstallationUser);
+ for(auto inst : m_installations)
+ g_object_unref(inst);
+
g_object_unref(m_cancellable);
}
bool FlatpakBackend::isValid() const
{
- return m_sources && m_flatpakInstallationUser && m_flatpakInstallationSystem;
+ return m_sources && !m_installations.isEmpty();
}
void FlatpakBackend::announceRatingsReady()
@@ -318,7 +319,6 @@ FlatpakResource * FlatpakBackend::addAppFromFlatpakBundle(const QUrl &url)
FlatpakResource * FlatpakBackend::addAppFromFlatpakRef(const QUrl &url)
{
- auto installation = m_flatpakInstallationSystem;
QSettings settings(url.toLocalFile(), QSettings::NativeFormat);
const QString refurl = settings.value(QStringLiteral("Flatpak Ref/Url")).toString();
@@ -334,7 +334,7 @@ FlatpakResource * FlatpakBackend::addAppFromFlatpakRef(const QUrl &url)
g_autoptr(GBytes) bytes = g_bytes_new (contents.data(), contents.size());
- remoteRef = flatpak_installation_install_ref_file (installation, bytes, m_cancellable, &error);
+ remoteRef = flatpak_installation_install_ref_file (preferredInstallation(), bytes, m_cancellable, &error);
if (!remoteRef) {
qWarning() << "Failed to install ref file: " << error->message;
return nullptr;
@@ -405,7 +405,7 @@ FlatpakResource * FlatpakBackend::addSourceFromFlatpakRepo(const QUrl &url)
resource->setFlatpakName(url.fileName().remove(QStringLiteral(".flatpakrepo")));
resource->setType(FlatpakResource::Source);
- auto repo = flatpak_installation_get_remote_by_name(m_flatpakInstallationSystem, resource->flatpakName().toStdString().c_str(), m_cancellable, nullptr);
+ auto repo = flatpak_installation_get_remote_by_name(preferredInstallation(), resource->flatpakName().toStdString().c_str(), m_cancellable, nullptr);
if (!repo) {
resource->setState(AbstractResource::State::None);
} else {
@@ -556,21 +556,14 @@ void FlatpakBackend::integrateRemote(FlatpakInstallation *flatpakInstallation, F
bool FlatpakBackend::loadInstalledApps(FlatpakInstallation *flatpakInstallation)
{
- QDir dir;
- QString pathExports;
- QString pathApps;
- g_autoptr(GFile) path = nullptr;
-
- if (!flatpakInstallation) {
- return false;
- }
+ Q_ASSERT(flatpakInstallation)
// List installed applications from installed desktop files
- path = flatpak_installation_get_path(flatpakInstallation);
- pathExports = QString::fromUtf8(g_file_get_path(path)) + QLatin1String("/exports/");
- pathApps = pathExports + QLatin1String("share/applications/");
+ 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/");
- dir = QDir(pathApps);
+ const QDir dir(pathApps);
if (dir.exists()) {
foreach (const QString &file, dir.entryList(QDir::NoDotAndDotDot | QDir::Files)) {
QString fnDesktop;
@@ -706,22 +699,16 @@ void FlatpakBackend::reloadPackageList()
{
setFetching(true);
- // Load applications from appstream metadata
- if (!loadAppsFromAppstreamData(m_flatpakInstallationSystem)) {
- qWarning() << "Failed to load packages from appstream data from system installation";
- }
-
- if (!loadAppsFromAppstreamData(m_flatpakInstallationUser)) {
- qWarning() << "Failed to load packages from appstream data from user installation";
- }
-
- // Load installed applications and update existing resources with info from installed application
- if (!loadInstalledApps(m_flatpakInstallationSystem)) {
- qWarning() << "Failed to load installed packages from system installation";
- }
+ for (auto installation : qAsConst(m_installations)) {
+ // Load applications from appstream metadata
+ if (!loadAppsFromAppstreamData(installation)) {
+ qWarning() << "Failed to load packages from appstream data from installation" << installation;
+ }
- if (!loadInstalledApps(m_flatpakInstallationUser)) {
- qWarning() << "Failed to load installed packages from user installation";
+ // Load installed applications and update existing resources with info from installed application
+ if (!loadInstalledApps(installation)) {
+ qWarning() << "Failed to load installed packages from installation" << installation;
+ }
}
setFetching(false);
@@ -729,17 +716,17 @@ void FlatpakBackend::reloadPackageList()
bool FlatpakBackend::setupFlatpakInstallations(GError **error)
{
- m_flatpakInstallationSystem = flatpak_installation_new_system(m_cancellable, error);
- if (!m_flatpakInstallationSystem) {
- return false;
+ auto system = flatpak_installation_new_system(m_cancellable, error);
+ if (system) {
+ m_installations << system;
}
- m_flatpakInstallationUser = flatpak_installation_new_user(m_cancellable, error);
- if (!m_flatpakInstallationUser) {
- return false;
+ auto user = flatpak_installation_new_user(m_cancellable, error);
+ if (user) {
+ m_installations << user;
}
- return true;
+ return !m_installations.isEmpty();
}
void FlatpakBackend::updateAppInstalledMetadata(FlatpakInstalledRef *installedRef, FlatpakResource *resource)
@@ -981,9 +968,9 @@ AbstractReviewsBackend * FlatpakBackend::reviewsBackend() const
FlatpakInstallation * FlatpakBackend::flatpakInstallationForAppScope(FlatpakResource::Scope appScope) const
{
if (appScope == FlatpakResource::Scope::System) {
- return m_flatpakInstallationSystem;
+ return preferredInstallation();
} else {
- return m_flatpakInstallationUser;
+ return m_installations.last();
}
}
@@ -998,7 +985,7 @@ void FlatpakBackend::installApplication(AbstractResource *app, const AddonList &
FlatpakRemote *remote = m_sources->installSource(resource);
if (remote) {
resource->setState(AbstractResource::Installed);
- integrateRemote(m_flatpakInstallationSystem, remote);
+ integrateRemote(preferredInstallation(), remote);
}
return;
}
@@ -1066,13 +1053,13 @@ void FlatpakBackend::removeApplication(AbstractResource *app)
void FlatpakBackend::checkForUpdates()
{
- // Load local updates, comparing current and latest commit
- loadLocalUpdates(m_flatpakInstallationSystem);
- loadLocalUpdates(m_flatpakInstallationUser);
+ for (auto installation : qAsConst(m_installations)) {
+ // Load local updates, comparing current and latest commit
+ loadLocalUpdates(installation);
- // Load updates from remote repositories
- loadRemoteUpdates(m_flatpakInstallationSystem);
- loadRemoteUpdates(m_flatpakInstallationUser);
+ // Load updates from remote repositories
+ loadRemoteUpdates(installation);
+ }
}
AbstractResource * FlatpakBackend::resourceForFile(const QUrl &url)
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakBackend.h b/libdiscover/backends/FlatpakBackend/FlatpakBackend.h
index a8b58c8..8b31bd4 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakBackend.h
+++ b/libdiscover/backends/FlatpakBackend/FlatpakBackend.h
@@ -69,6 +69,7 @@ private Q_SLOTS:
private:
void announceRatingsReady();
+ FlatpakInstallation * preferredInstallation() const { return m_installations.constFirst(); }
void integrateRemote(FlatpakInstallation *flatpakInstallation, FlatpakRemote *remote);
FlatpakRemote * getFlatpakRemoteByUrl(const QString &url, FlatpakInstallation *installation) const;
FlatpakInstalledRef * getInstalledRefForApp(FlatpakInstallation *flatpakInstallation, FlatpakResource *resource);
@@ -104,8 +105,7 @@ private:
QList<QAction*> m_messageActions;
GCancellable *m_cancellable;
- FlatpakInstallation *m_flatpakInstallationUser = nullptr;
- FlatpakInstallation *m_flatpakInstallationSystem = nullptr;
+ QVector<FlatpakInstallation *> m_installations;
};
#endif // FLATPAKBACKEND_H
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.cpp b/libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.cpp
index 9b6308d..387d87a 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.cpp
+++ b/libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.cpp
@@ -37,9 +37,9 @@ private:
FlatpakInstallation *m_installation;
};
-FlatpakSourcesBackend::FlatpakSourcesBackend(FlatpakInstallation *systemInstallation, FlatpakInstallation *userInstallation, QObject* parent)
+FlatpakSourcesBackend::FlatpakSourcesBackend(const QVector<FlatpakInstallation *> &installations, QObject* parent)
: AbstractSourcesBackend(parent)
- , m_systemInstallation(systemInstallation)
+ , m_preferredInstallation(installations.constFirst())
, m_sources(new QStandardItemModel(this))
{
QHash<int, QByteArray> roles = m_sources->roleNames();
@@ -47,12 +47,10 @@ FlatpakSourcesBackend::FlatpakSourcesBackend(FlatpakInstallation *systemInstalla
roles.insert(Qt::UserRole, "flatpakInstallation");
m_sources->setItemRoleNames(roles);
- if (!listRepositories(systemInstallation)) {
- qWarning() << "Failed to list repositories from system installation";
- }
-
- if (!listRepositories(userInstallation)) {
- qWarning() << "Failed to list repositories from user installation";
+ for (auto installation : installations) {
+ if (!listRepositories(installation)) {
+ qWarning() << "Failed to list repositories from installation" << installation;
+ }
}
}
@@ -131,7 +129,7 @@ FlatpakRemote * FlatpakSourcesBackend::installSource(FlatpakResource *resource)
{
g_autoptr(GCancellable) cancellable = g_cancellable_new();
- auto remote = flatpak_installation_get_remote_by_name(m_systemInstallation, resource->flatpakName().toStdString().c_str(), cancellable, nullptr);
+ auto remote = flatpak_installation_get_remote_by_name(m_preferredInstallation, resource->flatpakName().toStdString().c_str(), cancellable, nullptr);
if (remote) {
qWarning() << "Source " << resource->flatpakName() << " already exists";
return nullptr;
@@ -159,7 +157,7 @@ FlatpakRemote * FlatpakSourcesBackend::installSource(FlatpakResource *resource)
flatpak_remote_set_default_branch(remote, resource->branch().toStdString().c_str());
}
- if (!flatpak_installation_modify_remote(m_systemInstallation, remote, cancellable, nullptr)) {
+ if (!flatpak_installation_modify_remote(m_preferredInstallation, remote, cancellable, nullptr)) {
qWarning() << "Failed to add source " << resource->flatpakName();
return nullptr;
}
@@ -169,7 +167,7 @@ FlatpakRemote * FlatpakSourcesBackend::installSource(FlatpakResource *resource)
it->setData(resource->comment().isEmpty() ? resource->flatpakName() : resource->comment(), Qt::ToolTipRole);
it->setData(name(), AbstractSourcesBackend::SectionRole);
it->setData(QVariant::fromValue<QObject*>(this), AbstractSourcesBackend::SourcesBackend);
- it->setFlatpakInstallation(m_systemInstallation);
+ it->setFlatpakInstallation(m_preferredInstallation);
m_sources->appendRow(it);
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.h b/libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.h
index 32e2339..df66280 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.h
+++ b/libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.h
@@ -33,7 +33,7 @@ class FlatpakResource;
class FlatpakSourcesBackend : public AbstractSourcesBackend
{
public:
- explicit FlatpakSourcesBackend(FlatpakInstallation *systemInstallation, FlatpakInstallation *userInstallation, QObject *parent);
+ explicit FlatpakSourcesBackend(const QVector<FlatpakInstallation *>& installations, QObject *parent);
QAbstractItemModel* sources() override;
bool addSource(const QString &id) override;
@@ -46,7 +46,7 @@ public:
private:
bool listRepositories(FlatpakInstallation *installation);
- FlatpakInstallation *m_systemInstallation;
+ FlatpakInstallation *m_preferredInstallation;
QStandardItemModel* m_sources;
};