refactor(tree): give the logic layer and the shell a folder each
src/ and include/ are what is left: the controller the screens delegate to, its workers and its data model (core/), and the window and entry point that hold them together (app/). With those moved, src/ and include/ are empty and go away — a header is now always next to its source, in a folder named after what it does.
This commit is contained in:
10 files changed
+22
-22
No files matched your search
+1282
File diff suppressed because it is too large.
Load diff
+302
@@ -0,0 +1,302 @@
|
||||
#pragma once
|
||||
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "app-settings.h"
|
||||
#include "history-manager.h"
|
||||
#include "package-manager.h"
|
||||
#include "pacman-manager.h"
|
||||
#include "plugin-manager.h"
|
||||
#include "update-manager.h"
|
||||
|
||||
class QThread;
|
||||
class SearchWorker;
|
||||
class ListWorker;
|
||||
class InstallWorker;
|
||||
class PluginPackage;
|
||||
|
||||
// Logic layer: everything the application *does*. It owns the providers
|
||||
// (pacman, Flatpak, AUR, ...), the plugin registry, the history, the privileged
|
||||
// commands, pacman's database lock and the self-updater — and knows nothing
|
||||
// about widgets, dialogs or layouts.
|
||||
//
|
||||
// MainWindow is only a view on top of it: it builds widgets, calls these
|
||||
// methods and renders the signals below. Two rules keep the split honest:
|
||||
// - every operation that shells out is asynchronous and reports through
|
||||
// signals; the *StartResult answers only say whether the request was
|
||||
// accepted;
|
||||
// - whatever needs a human (the sudo password, freeing pacman's lock) is
|
||||
// decided by the view: the core says what it lacks and the view calls back
|
||||
// once the user answered.
|
||||
// The layer therefore runs without a display — tests/app-core.test.cpp links no
|
||||
// QtWidgets at all.
|
||||
class AppCore : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
// Which listing is being loaded.
|
||||
enum class ListMode { Installed, Updates, Cleanup };
|
||||
// When the sudo password is requested: once per session (at launch) or
|
||||
// before every privileged operation.
|
||||
enum class CredentialMode { AtLaunch, EachTime };
|
||||
|
||||
// Outcome of a request. A refused request carries the reason and flags what
|
||||
// the view has to do before replaying it: ask for the sudo password, or
|
||||
// free pacman's database lock.
|
||||
struct StartResult {
|
||||
bool started = false;
|
||||
bool needsPassword = false;
|
||||
bool locked = false;
|
||||
QString error;
|
||||
};
|
||||
|
||||
explicit AppCore(QObject* parent = nullptr);
|
||||
~AppCore() override;
|
||||
|
||||
// ---- Backend handles the view renders ----
|
||||
PluginManager* plugins() const { return m_plugins; }
|
||||
HistoryManager* history() const { return m_history; }
|
||||
UpdateManager* updateManager() const { return m_update; }
|
||||
PluginPackage* packages() const { return m_packages; }
|
||||
// User preferences (journal, drag & drop, language, update policy). The
|
||||
// core reads them to decide whether a version check may run; the Settings
|
||||
// screen writes them. Shared process-wide, hence the accessor rather than
|
||||
// an owned member.
|
||||
AppSettings* settings() const { return &AppSettings::instance(); }
|
||||
std::vector<IPackageManager*> availableProviders() const;
|
||||
QStringList availableProviderNames() const;
|
||||
bool hasAvailableProvider() const;
|
||||
// Provider owning a package id, falling back to the first available one.
|
||||
IPackageManager* providerFor(const QString& providerId) const;
|
||||
QString version() const;
|
||||
int historyCount() const;
|
||||
bool busy() const { return m_busy; }
|
||||
|
||||
// Last completed listings; -1 when a list was never loaded.
|
||||
const std::vector<PackageInfo>& installedPackages() const { return m_installedPackages; }
|
||||
const std::vector<PackageInfo>& updatePackages() const { return m_updatePackages; }
|
||||
const std::vector<PackageInfo>& cleanupCandidates() const { return m_cleanupCandidates; }
|
||||
int installedCount() const;
|
||||
int updateCount() const;
|
||||
|
||||
// ---- Listings ----
|
||||
StartResult search(const QString& query);
|
||||
StartResult loadInstalled();
|
||||
StartResult loadUpdates();
|
||||
StartResult loadCleanup();
|
||||
// Dashboard: loads the installed and update lists back to back, so the
|
||||
// counts and the badges are fresh without the view doing any chaining.
|
||||
StartResult loadCounts();
|
||||
|
||||
// ---- Actions ----
|
||||
StartResult install(const PackageInfo& package);
|
||||
StartResult remove(const PackageInfo& package);
|
||||
// Removes only the installations the user picked, when the provider can
|
||||
// have several copies of the same application (flatpak: one in the user
|
||||
// installation and one system-wide, or two remotes or branches). The targets
|
||||
// are the ones the provider listed in PackageInfo::instances, so the core
|
||||
// never builds them; an empty list is the plain remove().
|
||||
StartResult removeInstances(const PackageInfo& package,
|
||||
const std::vector<std::string>& targets);
|
||||
StartResult update(const PackageInfo& package);
|
||||
StartResult updateAll();
|
||||
StartResult refresh();
|
||||
StartResult cleanCaches();
|
||||
// Installs the package a file describes — a Flatpak .flatpakref, .flatpakrepo
|
||||
// or .flatpak bundle dropped on the window or opened from the file manager
|
||||
// ("Ouvrir avec PacManager"). The provider owning the format is picked here,
|
||||
// so the view never names one.
|
||||
StartResult installFile(const QString& path);
|
||||
// Whether any available provider knows that file, so the window only accepts
|
||||
// drops it can act on.
|
||||
bool canInstallFile(const QString& path) const;
|
||||
// Whether a file is a plugin package (.fwspacm). Packages are not installed
|
||||
// by a provider: they carry a plugin, they are not packages to install, so
|
||||
// they never take the sudo gate and never enter the file install queue.
|
||||
bool isPluginPackage(const QString& path) const;
|
||||
// Bulk removal: one command per provider, run one provider at a time
|
||||
// (pacman locks its database for the whole operation).
|
||||
StartResult removePackages(const std::vector<PackageInfo>& packages,
|
||||
const QString& description);
|
||||
StartResult installPluginTool(const std::string& pluginId);
|
||||
StartResult releaseDatabaseLock();
|
||||
|
||||
// Replays the request that was waiting for a password or for the database
|
||||
// lock to be freed, so the view can retry right after the user answered.
|
||||
StartResult retryPendingRequest();
|
||||
void cancelPendingRequest();
|
||||
bool hasPendingRequest() const { return m_pending.has_value(); }
|
||||
|
||||
// ---- Credentials (the view prompts, the core holds the state) ----
|
||||
CredentialMode credentialMode() const { return m_credentialMode; }
|
||||
void setCredentialMode(CredentialMode mode);
|
||||
void setSudoPassword(const QString& password);
|
||||
void clearSudoPassword();
|
||||
bool hasSudoPassword() const;
|
||||
|
||||
// ---- History, logs, package details ----
|
||||
void clearHistory();
|
||||
// Full content of /var/log/pacman.log; `error` is filled when it cannot be
|
||||
// read (file missing, no permission).
|
||||
QString readPackageLog(QString* error = nullptr) const;
|
||||
// Full content of the application's own journal (every operation and event,
|
||||
// including the raw output of the commands that ran).
|
||||
QString readAppLog(QString* error = nullptr) const;
|
||||
// Extra pacman information for the details panel (-Qi / -Si), cached per
|
||||
// package so selecting rows repeatedly does not re-spawn pacman.
|
||||
QString packageDetails(const PackageInfo& package);
|
||||
|
||||
// ---- Plugins ----
|
||||
void setPluginEnabled(const std::string& pluginId, bool enabled);
|
||||
void reloadPlugins();
|
||||
|
||||
// ---- Plugin packages ----
|
||||
// Installs a .fwspacm package (the archive the packaging script builds) and
|
||||
// removes one that was installed this way. Installing writes the shared
|
||||
// library in the per-user plugin directory and reloads the registry, so the
|
||||
// plugin is usable right away.
|
||||
void installPluginPackage(const QString& path);
|
||||
void removePluginPackage(const QString& id);
|
||||
|
||||
// ---- Application self-update ----
|
||||
// Whether a version check may run right now: the daily check is not asked
|
||||
// for, the automatic check is off, or the user put the app's own updates on
|
||||
// hold (see AppSettings).
|
||||
bool shouldCheckForAppUpdate() const;
|
||||
void checkForAppUpdate();
|
||||
// Why checkForAppUpdate() would refuse, for the status bar and the Settings
|
||||
// screen. Empty when a check may run.
|
||||
QString appUpdateCheckRefusal() const;
|
||||
bool canSelfUpdate() const;
|
||||
UpdateManager::UpdateMethod updateMethod() const;
|
||||
QString updateMethodDescription() const;
|
||||
QString releasePageUrl() const;
|
||||
QString binDir() const;
|
||||
bool binDirWritable() const;
|
||||
// Starts the background rebuild/install. Returns false with `error` filled
|
||||
// when the update cannot run (no method available).
|
||||
bool applySelfUpdate(const QString& sudoPassword, QString* error);
|
||||
|
||||
// ---- pacman's database lock ----
|
||||
bool databaseLocked() const;
|
||||
// What currently holds the lock, so the view can name the process it offers
|
||||
// to close (or the stale lock file it offers to drop).
|
||||
PacmanManager::LockHolder lockHolder() const;
|
||||
QString databaseLockDescription() const;
|
||||
|
||||
signals:
|
||||
// Search results, streamed in batches then once complete.
|
||||
void searchChunk(std::vector<PackageInfo> results);
|
||||
void searchFinished(std::vector<PackageInfo> results);
|
||||
// A listing finished; the view renders it and keeps what it needs.
|
||||
void listFinished(AppCore::ListMode mode, std::vector<PackageInfo> results);
|
||||
// Progress of a running action: `message` is a log line, `percent` is -1
|
||||
// when the tool does not report a real percentage.
|
||||
void actionProgress(const QString& message, int percent);
|
||||
void actionFinished(const QString& action, const QString& name, bool success,
|
||||
const QString& error, bool locked);
|
||||
void busyChanged(bool busy);
|
||||
void statusMessage(const QString& message);
|
||||
void historyChanged();
|
||||
void pluginsChanged();
|
||||
// A plugin package was installed or removed (or the attempt was refused).
|
||||
void pluginPackageInstalled(const QString& id, bool success, const QString& message);
|
||||
void pluginPackageRemoved(const QString& id, bool success, const QString& message);
|
||||
void updateCheckFinished(bool hasUpdate, const QString& latestVersion,
|
||||
const QString& errorMessage);
|
||||
void selfUpdateFinished(bool success, const QString& message);
|
||||
|
||||
private:
|
||||
// Everything the core knows how to run. The pending request is kept so it
|
||||
// can be replayed once the password is provided or the lock released.
|
||||
struct Request {
|
||||
QString action;
|
||||
PackageInfo package;
|
||||
std::vector<PackageInfo> packages;
|
||||
QString description;
|
||||
// File a file-based request acts on (see installFile), kept apart from
|
||||
// `package.name`, which only carries the label for the UI and history.
|
||||
QString path;
|
||||
// The exact installation a request acts on, when the provider named one
|
||||
// (see removeInstances). Like `path`, it is what the provider is given
|
||||
// instead of the display label, which the UI and the history keep.
|
||||
QString target;
|
||||
// Several installations of the same application, acted on in one
|
||||
// operation (see removeInstances).
|
||||
std::vector<std::string> targets;
|
||||
std::string pluginId;
|
||||
};
|
||||
|
||||
// Taken by value: the label and the pending copy are filled in from the
|
||||
// request's contents once the target action is known.
|
||||
StartResult startRequest(Request request);
|
||||
StartResult startList(ListMode mode);
|
||||
StartResult startSearch(const QString& query);
|
||||
StartResult startAction(InstallWorker* worker, const Request& request,
|
||||
const std::vector<IPackageManager*>& providers);
|
||||
void finishAction(const Request& request,
|
||||
const std::vector<IPackageManager*>& providers, bool success);
|
||||
// Deletes a worker once its thread has really stopped. wait() has to run on
|
||||
// the core's thread (a worker cannot wait on itself), so the cleanup is
|
||||
// connected with the core as context and therefore queued back here.
|
||||
void disposeWorker(QThread* worker);
|
||||
// Chains the provider groups of a bulk removal, one after the other.
|
||||
void startNextRemovalGroup();
|
||||
void setBusy(bool busy);
|
||||
|
||||
// Everything the status bar and the dialogs get to read: the core decides
|
||||
// what happened, the view decides how to show it.
|
||||
QString startMessage(const QString& action, const QString& label) const;
|
||||
QString successMessage(const QString& action, const QString& name) const;
|
||||
QString failureMessage(const QString& action, const QString& name) const;
|
||||
QString firstError(const std::vector<IPackageManager*>& providers) const;
|
||||
void recordHistory(const QString& action, const QString& name,
|
||||
IPackageManager* provider, bool success);
|
||||
void invalidateDetails();
|
||||
void refreshProviderCache();
|
||||
|
||||
// Refusal shared by every privileged request: the view is told which of the
|
||||
// three doors is closed (busy, password, unavailable provider).
|
||||
StartResult credentialGate(const std::vector<IPackageManager*>& providers) const;
|
||||
// Per-operation mode: the password is single-use, drop it after a command.
|
||||
void clearCredentialsAfterUse();
|
||||
|
||||
PluginManager* m_plugins = nullptr;
|
||||
PluginPackage* m_packages = nullptr;
|
||||
PacmanManager* m_pacman = nullptr; // non-owning, for sudo credentials and the lock
|
||||
HistoryManager* m_history = nullptr;
|
||||
UpdateManager* m_update = nullptr;
|
||||
QSettings m_settings;
|
||||
|
||||
CredentialMode m_credentialMode = CredentialMode::EachTime;
|
||||
|
||||
std::vector<PackageInfo> m_installedPackages;
|
||||
std::vector<PackageInfo> m_updatePackages;
|
||||
std::vector<PackageInfo> m_cleanupCandidates;
|
||||
QHash<QString, QString> m_detailsCache;
|
||||
|
||||
// One worker of each kind at a time; a second listing request is queued
|
||||
// rather than refused, since the dashboard loads two in a row.
|
||||
SearchWorker* m_search = nullptr;
|
||||
ListWorker* m_list = nullptr;
|
||||
QList<ListMode> m_queuedLists;
|
||||
InstallWorker* m_action = nullptr;
|
||||
|
||||
std::optional<Request> m_pending;
|
||||
|
||||
// Bulk removal state.
|
||||
std::vector<std::pair<IPackageManager*, std::vector<std::string>>> m_pendingRemovals;
|
||||
bool m_removalSuccess = true;
|
||||
QString m_cleanupRemovalDescription;
|
||||
|
||||
bool m_busy = false;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(AppCore::ListMode)
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "package-model.h"
|
||||
|
||||
PackageModel::PackageModel(QObject* parent) : QAbstractListModel(parent) {}
|
||||
|
||||
int PackageModel::rowCount(const QModelIndex& parent) const {
|
||||
Q_UNUSED(parent);
|
||||
return static_cast<int>(m_packages.size());
|
||||
}
|
||||
|
||||
QVariant PackageModel::data(const QModelIndex& index, int role) const {
|
||||
if (!index.isValid() || index.row() >= static_cast<int>(m_packages.size())) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
const PackageInfo& pkg = m_packages[index.row()];
|
||||
|
||||
switch (role) {
|
||||
case NameRole: return QString::fromStdString(pkg.name);
|
||||
case VersionRole: return QString::fromStdString(pkg.version);
|
||||
case DescriptionRole: return QString::fromStdString(pkg.description);
|
||||
case RepositoryRole: return QString::fromStdString(pkg.repository);
|
||||
case InstalledRole: return pkg.installed;
|
||||
case SizeRole: return QString::fromStdString(pkg.size);
|
||||
case UpdateAvailableRole: return pkg.updateAvailable;
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> PackageModel::roleNames() const {
|
||||
return {
|
||||
{NameRole, "name"},
|
||||
{VersionRole, "version"},
|
||||
{DescriptionRole, "description"},
|
||||
{RepositoryRole, "repository"},
|
||||
{InstalledRole, "installed"},
|
||||
{SizeRole, "size"},
|
||||
{UpdateAvailableRole, "updateAvailable"}
|
||||
};
|
||||
}
|
||||
|
||||
void PackageModel::setPackages(const std::vector<PackageInfo>& packages) {
|
||||
beginResetModel();
|
||||
m_packages = packages;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void PackageModel::clear() {
|
||||
beginResetModel();
|
||||
m_packages.clear();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
PackageInfo PackageModel::getPackage(int row) const {
|
||||
if (row >= 0 && row < static_cast<int>(m_packages.size())) {
|
||||
return m_packages[row];
|
||||
}
|
||||
return PackageInfo{};
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QAbstractListModel>
|
||||
#include <QVariant>
|
||||
#include <vector>
|
||||
#include "package-manager.h"
|
||||
|
||||
class PackageModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Roles {
|
||||
NameRole = Qt::UserRole + 1,
|
||||
VersionRole,
|
||||
DescriptionRole,
|
||||
RepositoryRole,
|
||||
InstalledRole,
|
||||
SizeRole,
|
||||
UpdateAvailableRole
|
||||
};
|
||||
|
||||
explicit PackageModel(QObject* parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
void setPackages(const std::vector<PackageInfo>& packages);
|
||||
void clear();
|
||||
PackageInfo getPackage(int row) const;
|
||||
|
||||
private:
|
||||
std::vector<PackageInfo> m_packages;
|
||||
};
|
||||
@@ -0,0 +1,140 @@
|
||||
#include "workers.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
SearchWorker::SearchWorker(const std::vector<IPackageManager*>& providers,
|
||||
const std::string& query)
|
||||
: m_providers(providers), m_query(query) {}
|
||||
|
||||
void SearchWorker::run() {
|
||||
std::vector<PackageInfo> results;
|
||||
for (IPackageManager* pm : m_providers) {
|
||||
if (!pm->canSearch()) continue;
|
||||
|
||||
// Publish the freshly found packages right away, grouped in small
|
||||
// batches so the table starts filling while the next provider is still
|
||||
// running its (potentially slow) search in the background.
|
||||
std::vector<PackageInfo> providerResults;
|
||||
for (auto& pkg : pm->search(m_query)) {
|
||||
pkg.provider = pm->getName();
|
||||
providerResults.push_back(pkg);
|
||||
}
|
||||
constexpr int kBatchSize = 10;
|
||||
for (size_t i = 0; i < providerResults.size(); i += kBatchSize) {
|
||||
std::vector<PackageInfo> batch(
|
||||
providerResults.begin() + i,
|
||||
providerResults.begin() + std::min(i + kBatchSize, providerResults.size()));
|
||||
emit chunk(std::move(batch));
|
||||
}
|
||||
|
||||
results.insert(results.end(), providerResults.begin(), providerResults.end());
|
||||
}
|
||||
|
||||
// One row per package name, whatever the number of providers offering it.
|
||||
mergeProviderDuplicates(results);
|
||||
|
||||
// Group by provider (query order), then sort alphabetically within each.
|
||||
std::vector<std::string> providerOrder;
|
||||
for (IPackageManager* pm : m_providers) providerOrder.push_back(pm->getName());
|
||||
sortByProviderThenName(results, providerOrder);
|
||||
|
||||
emit finished(results);
|
||||
}
|
||||
|
||||
ListWorker::ListWorker(const std::vector<IPackageManager*>& providers, Mode mode)
|
||||
: m_providers(providers), m_mode(mode) {}
|
||||
|
||||
void ListWorker::run() {
|
||||
std::vector<PackageInfo> results;
|
||||
for (IPackageManager* pm : m_providers) {
|
||||
if (m_mode == Installed) {
|
||||
if (!pm->canListInstalled()) continue;
|
||||
for (auto& pkg : pm->listInstalled()) {
|
||||
pkg.provider = pm->getName();
|
||||
results.push_back(pkg);
|
||||
}
|
||||
} else if (m_mode == Updates) {
|
||||
if (!pm->canUpdate()) continue;
|
||||
for (auto& pkg : pm->listUpdates()) {
|
||||
pkg.provider = pm->getName();
|
||||
results.push_back(pkg);
|
||||
}
|
||||
} else {
|
||||
if (!pm->canListCleanup()) continue;
|
||||
for (auto& pkg : pm->listCleanupCandidates()) {
|
||||
pkg.provider = pm->getName();
|
||||
results.push_back(pkg);
|
||||
}
|
||||
}
|
||||
}
|
||||
// One row per package name, whatever the number of providers offering it.
|
||||
// Cleanup candidates stay as reported: each row is tied to the provider
|
||||
// that must remove it, and merging would hide which one reported it.
|
||||
if (m_mode != Cleanup) mergeProviderDuplicates(results);
|
||||
emit finished(results);
|
||||
}
|
||||
|
||||
InstallWorker::InstallWorker(IPackageManager* pm, Op op, const std::string& package)
|
||||
: m_providers{pm}, m_op(op), m_package(package) {}
|
||||
|
||||
InstallWorker::InstallWorker(IPackageManager* pm, Op op,
|
||||
const std::vector<std::string>& packages)
|
||||
: m_providers{pm}, m_op(op), m_packages(packages) {}
|
||||
|
||||
InstallWorker::InstallWorker(const std::vector<IPackageManager*>& providers, Op op)
|
||||
: m_providers(providers), m_op(op) {}
|
||||
|
||||
InstallWorker::InstallWorker(PacmanManager* pacman, const PacmanManager::LockHolder& holder)
|
||||
: m_op(Op::ReleaseLock), m_pacman(pacman), m_lockHolder(holder) {}
|
||||
|
||||
void InstallWorker::run() {
|
||||
// Lock recovery bypasses the provider loop: it is one pacman-side operation
|
||||
// whose progress comes back through the same signal as an install.
|
||||
if (m_op == Op::ReleaseLock) {
|
||||
auto cb = [this](const std::string& message, int) {
|
||||
emit progress(QString::fromStdString(message));
|
||||
};
|
||||
emit finished(m_pacman && m_pacman->releaseDatabaseLock(m_lockHolder, cb));
|
||||
return;
|
||||
}
|
||||
|
||||
const int providerCount = static_cast<int>(m_providers.size());
|
||||
bool success = true;
|
||||
for (int index = 0; index < providerCount; ++index) {
|
||||
IPackageManager* pm = m_providers[static_cast<size_t>(index)];
|
||||
// Prefix progress lines with the provider when several run at once.
|
||||
// A real percentage (>= 0) also drives the determinate status bar bar.
|
||||
auto cb = [this, pm, index, providerCount](const std::string& msg, int percent) {
|
||||
if (providerCount > 1) {
|
||||
emit progress(QString("[%1] %2")
|
||||
.arg(QString::fromStdString(pm->getName()),
|
||||
QString::fromStdString(msg)));
|
||||
} else {
|
||||
emit progress(QString::fromStdString(msg));
|
||||
}
|
||||
if (percent < 0) return;
|
||||
|
||||
// Providers run one after the other, so each one owns an equal
|
||||
// slice of the bar. Without this the bar dropped back to 0 when the
|
||||
// second provider (flatpak, after pacman) started its own count.
|
||||
const int scaled = (index * 100 + percent) / providerCount;
|
||||
emit progressValue(std::min(scaled, 99));
|
||||
};
|
||||
|
||||
// Keep running the remaining providers even if one fails.
|
||||
switch (m_op) {
|
||||
case Op::Install: success = pm->install(m_package, cb) && success; break;
|
||||
case Op::Remove: success = pm->remove(m_package, cb) && success; break;
|
||||
case Op::Update: success = pm->update(m_package, cb) && success; break;
|
||||
case Op::UpdateAll: success = pm->update("", cb) && success; break;
|
||||
case Op::InstallFile: success = pm->installFile(m_package, cb) && success; break;
|
||||
case Op::Refresh: success = pm->refresh(cb) && success; break;
|
||||
case Op::RemovePackages:
|
||||
success = pm->removePackages(m_packages, cb) && success;
|
||||
break;
|
||||
case Op::CleanCache: success = pm->cleanCache(cb) && success; break;
|
||||
case Op::ReleaseLock: break; // handled before the provider loop
|
||||
}
|
||||
}
|
||||
emit finished(success);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
#pragma once
|
||||
|
||||
#include <QThread>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "package-manager.h"
|
||||
#include "pacman-manager.h"
|
||||
|
||||
// Background workers shared by every front-end (the Qt window and the web UI).
|
||||
// They own the aggregation rules — each provider queried in turn, every result
|
||||
// tagged with its provider id — so both interfaces display the same list.
|
||||
|
||||
// Runs a package search off the UI thread. Queries every given provider and
|
||||
// merges the results, tagging each package with its provider id.
|
||||
class SearchWorker : public QThread {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SearchWorker(const std::vector<IPackageManager*>& providers, const std::string& query);
|
||||
void run() override;
|
||||
signals:
|
||||
void finished(std::vector<PackageInfo> results);
|
||||
// Emitted as search results are accumulated, so a few packages can be
|
||||
// shown immediately while the remaining searches keep running.
|
||||
void chunk(std::vector<PackageInfo> results);
|
||||
private:
|
||||
std::vector<IPackageManager*> m_providers;
|
||||
std::string m_query;
|
||||
};
|
||||
|
||||
// Loads a package list (installed or outdated) off the UI thread, aggregated
|
||||
// across every given provider.
|
||||
class ListWorker : public QThread {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Mode { Installed, Updates, Cleanup };
|
||||
ListWorker(const std::vector<IPackageManager*>& providers, Mode mode);
|
||||
void run() override;
|
||||
signals:
|
||||
void finished(std::vector<PackageInfo> results);
|
||||
private:
|
||||
std::vector<IPackageManager*> m_providers;
|
||||
Mode m_mode;
|
||||
};
|
||||
|
||||
// Runs install/remove/update/refresh actions off the UI thread. Single-package
|
||||
// operations take one provider; UpdateAll/Refresh take every provider and run
|
||||
// on each of them in sequence.
|
||||
class InstallWorker : public QThread {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum class Op {
|
||||
Install,
|
||||
Remove,
|
||||
Update,
|
||||
UpdateAll,
|
||||
Refresh,
|
||||
// Installs the package a file describes (.flatpakref, .flatpakrepo or
|
||||
// .flatpak bundle); `m_package` then holds the file path, not a name.
|
||||
InstallFile,
|
||||
RemovePackages,
|
||||
CleanCache,
|
||||
ReleaseLock,
|
||||
};
|
||||
InstallWorker(IPackageManager* pm, Op op, const std::string& package);
|
||||
// Bulk variant: removes several packages in one provider call (cleanup
|
||||
// page) instead of one call per package.
|
||||
InstallWorker(IPackageManager* pm, Op op, const std::vector<std::string>& packages);
|
||||
InstallWorker(const std::vector<IPackageManager*>& providers, Op op);
|
||||
// Pacman database-lock recovery: stops whatever holds the lock, or drops a
|
||||
// stale lock file. Runs off the UI thread because waiting for the other
|
||||
// manager to exit takes seconds.
|
||||
InstallWorker(PacmanManager* pacman, const PacmanManager::LockHolder& holder);
|
||||
void run() override;
|
||||
signals:
|
||||
void progress(const QString& message);
|
||||
// Real download percentage (0-100) when the provider reports it, used to
|
||||
// fill the determinate progress bar in the status bar.
|
||||
void progressValue(int percent);
|
||||
void finished(bool success);
|
||||
private:
|
||||
std::vector<IPackageManager*> m_providers;
|
||||
Op m_op;
|
||||
std::string m_package;
|
||||
std::vector<std::string> m_packages;
|
||||
PacmanManager* m_pacman = nullptr; // lock recovery only
|
||||
PacmanManager::LockHolder m_lockHolder;
|
||||
};
|
||||
Reference in new issue
Block a user