refactor(arch): split the app into a logic core and per-screen pages
All the business logic now lives in AppCore (providers, workers, history, plugins, sudo and pacman-lock handling), freed from any widget so it runs headless and is testable on its own. The Qt window becomes a thin frame around one file per screen under pages/, wired through a common Page contract and a shared ui-kit. CMake gains the app-core-test target, which links Qt Core only to enforce the headless guarantee. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
1 parent
576daf2fae
commit
897c174925
24 files changed
+4322
-3056
No files matched your search
@@ -0,0 +1,242 @@
|
||||
#pragma once
|
||||
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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;
|
||||
|
||||
// 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; }
|
||||
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);
|
||||
StartResult update(const PackageInfo& package);
|
||||
StartResult updateAll();
|
||||
StartResult refresh();
|
||||
StartResult cleanCaches();
|
||||
// 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;
|
||||
// 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();
|
||||
|
||||
// ---- Application self-update ----
|
||||
bool shouldCheckForAppUpdate() const;
|
||||
void checkForAppUpdate();
|
||||
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();
|
||||
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;
|
||||
std::string pluginId;
|
||||
};
|
||||
|
||||
StartResult startRequest(const 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;
|
||||
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)
|
||||
+84
-294
@@ -1,111 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QProgressBar>
|
||||
#include <QComboBox>
|
||||
#include <QThread>
|
||||
#include <QSettings>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QHash>
|
||||
#include <QMainWindow>
|
||||
#include <QString>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "app-core.h"
|
||||
#include "package-manager.h"
|
||||
#include "pacman-manager.h"
|
||||
#include "plugin-manager.h"
|
||||
#include "history-manager.h"
|
||||
#include "update-manager.h"
|
||||
|
||||
class QStackedWidget;
|
||||
class QTableWidget;
|
||||
class QTextEdit;
|
||||
class QListWidget;
|
||||
class QListWidgetItem;
|
||||
class QAction;
|
||||
class QButtonGroup;
|
||||
class QFrame;
|
||||
class QAction;
|
||||
class QLabel;
|
||||
class QProgressBar;
|
||||
class QPushButton;
|
||||
class QStackedWidget;
|
||||
class QSystemTrayIcon;
|
||||
class QWidget;
|
||||
|
||||
// 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,
|
||||
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;
|
||||
};
|
||||
class BrowsePage;
|
||||
class CleanupPage;
|
||||
class DashboardPage;
|
||||
class HistoryPage;
|
||||
class LogsPage;
|
||||
class Page;
|
||||
class PluginsPage;
|
||||
|
||||
// The window is only a frame: it owns the sidebar, the header, the status bar,
|
||||
// the menu, the tray and every dialog, and it stacks one screen per file from
|
||||
// pages/ inside it. No package-manager command, no privileged operation and no
|
||||
// pacman query lives here — see include/app-core.h for the logic and
|
||||
// pages/page.h for the contract a screen honours.
|
||||
//
|
||||
// Adding a screen means writing one Page subclass under pages/, registering it
|
||||
// in setupUI() and giving it a sidebar entry: nothing else in this file has to
|
||||
// learn about it.
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
public:
|
||||
@@ -113,46 +44,33 @@ public:
|
||||
~MainWindow();
|
||||
|
||||
private slots:
|
||||
void onSearch();
|
||||
void onInstall();
|
||||
void onRemove();
|
||||
void onUpdate();
|
||||
void onUpdateAll();
|
||||
void onRefresh();
|
||||
void onSearchFinished(std::vector<PackageInfo> results);
|
||||
void onSearchChunk(std::vector<PackageInfo> results);
|
||||
void onListFinished(std::vector<PackageInfo> results);
|
||||
void onInstallProgress(int percent);
|
||||
void onPackageSelected(int row);
|
||||
void onNavChanged(int id);
|
||||
void onClearHistory();
|
||||
void onRefreshLogs();
|
||||
void onExportHistory();
|
||||
void onExportPackageList();
|
||||
void onLogsFilterChanged();
|
||||
void onPreviewUpdates();
|
||||
void onRefresh();
|
||||
void onUpdateAll();
|
||||
void onTrayActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
void onHistoryFilterChanged();
|
||||
void onInstalledFilterChanged(const QString& text);
|
||||
void onRecentActivityClicked(QListWidgetItem* item);
|
||||
void onPluginTableSelected(int row);
|
||||
void onTogglePlugin();
|
||||
void onRescanPlugins();
|
||||
void onInstallPluginTool();
|
||||
void onCheckForUpdates();
|
||||
void onUpdateCheckFinished(bool hasUpdate, const QString& latestVersion,
|
||||
const QString& errorMessage);
|
||||
void onSelfUpdateFinished(bool success, const QString& message);
|
||||
void onCleanupScan();
|
||||
void onCleanupListFinished(std::vector<PackageInfo> results);
|
||||
void onCleanupSelectionChanged(int row);
|
||||
void onRemoveCleanupOrphans();
|
||||
void onRemoveCleanupSelection();
|
||||
void onCleanCaches();
|
||||
|
||||
// ---- What a page asks the frame to do ----
|
||||
// A page hands over a request so the frame can walk the user through what
|
||||
// the core needs (sudo password, freeing pacman's lock) and replay it.
|
||||
void onStartRequested(const AppCore::StartResult& result, const QString& title);
|
||||
void onPageMessage(const QString& text);
|
||||
void onOpenPage(const QString& pageId);
|
||||
void onOpenPackage(const QString& name);
|
||||
|
||||
// ---- What the core reports back ----
|
||||
void onCoreListFinished(AppCore::ListMode mode, std::vector<PackageInfo> results);
|
||||
void onCoreActionProgress(const QString& message, int percent);
|
||||
void onCoreActionFinished(const QString& action, const QString& name, bool success,
|
||||
const QString& error, bool locked);
|
||||
void onCoreBusyChanged(bool busy);
|
||||
void onCoreStatusMessage(const QString& message);
|
||||
void onCoreHistoryChanged();
|
||||
void onCoreUpdateCheckFinished(bool hasUpdate, const QString& latestVersion,
|
||||
const QString& errorMessage);
|
||||
void onCoreSelfUpdateFinished(bool success, const QString& message);
|
||||
|
||||
private:
|
||||
enum BrowseMode { ModeSearch, ModeInstalled, ModeUpdates };
|
||||
|
||||
// Sidebar entries, in display order. Named so the sidebar, the dashboard
|
||||
// shortcuts, the menu bar and the keyboard shortcuts cannot drift apart
|
||||
// when a page is inserted.
|
||||
@@ -167,100 +85,41 @@ private:
|
||||
NavPlugins,
|
||||
};
|
||||
|
||||
// Indices in the stacked widget. Search / Installed / Updates share the
|
||||
// browse page, so these deliberately differ from the nav ids.
|
||||
enum StackedPage {
|
||||
PageDashboard = 0,
|
||||
PageBrowse,
|
||||
PageHistory,
|
||||
PageLogs,
|
||||
PagePlugins,
|
||||
PageCleanup,
|
||||
};
|
||||
|
||||
// When the sudo password is requested: once per session (at launch) or
|
||||
// before every privileged operation.
|
||||
enum class CredentialMode { AtLaunch, EachTime };
|
||||
|
||||
void applyCredentialMode(CredentialMode mode);
|
||||
bool ensureCredentials(const std::vector<IPackageManager*>& providers);
|
||||
void clearCredentialsAfterUse();
|
||||
|
||||
// Manager owning a package, based on its provider tag; falls back to the
|
||||
// first available provider when the tag is unknown or empty.
|
||||
IPackageManager* providerFor(const std::string& id) const;
|
||||
|
||||
// Show the provider's last error in a dialog when one is available, so a
|
||||
// failed operation explains itself instead of failing silently.
|
||||
// Returns true when the error was a locked pacman DB (caller may offer
|
||||
// a retry once the lock is gone).
|
||||
bool showProviderError(const QString& title, IPackageManager* provider);
|
||||
|
||||
// Names the process holding pacman's database and offers to close it — or to
|
||||
// drop a stale lock — before re-running the pending action. Returns true when
|
||||
// it handled the failure, so the caller skips its own reporting.
|
||||
bool handleDatabaseLock(const QString& title);
|
||||
void startLockRecovery(const PacmanManager::LockHolder& holder);
|
||||
// Re-runs the action that failed, when it can still run.
|
||||
void retryPendingAction();
|
||||
|
||||
// Re-runs the given privileged action. Used by the "Réessayer" button
|
||||
// on db-lock errors: the lock (other manager / stale db.lck) is often
|
||||
// gone by the time the user retries.
|
||||
void retryPrivilegedAction(const QString& action);
|
||||
|
||||
QString m_pendingRetryAction;
|
||||
|
||||
void setupUI();
|
||||
void setupSidebar();
|
||||
void setupHeader();
|
||||
void setupDashboardPage();
|
||||
void setupBrowsePage();
|
||||
void setupHistoryPage();
|
||||
void setupLogsPage();
|
||||
void setupPluginsPage();
|
||||
void setupCleanupPage();
|
||||
void setupPages();
|
||||
void setupMenuBar();
|
||||
void setupTray();
|
||||
void setupShortcuts();
|
||||
// Wires a screen: the frame answers its requests and shows the page it asks
|
||||
// for. Called once per screen by setupPages().
|
||||
void registerPage(const QString& id, int navId, Page* page);
|
||||
// Screen currently displayed, and the screens themselves.
|
||||
Page* currentPage() const;
|
||||
void updatePageTitle();
|
||||
void updateStatusBar();
|
||||
void refreshDashboard();
|
||||
void refreshRecentActivity();
|
||||
// Mirrors the pending update count on the sidebar entry, so the page that
|
||||
// needs attention is visible from wherever the user is.
|
||||
void setUpdatesBadge(int count);
|
||||
void refreshPluginsTable();
|
||||
void updatePackageInfo(const PackageInfo& pkg);
|
||||
std::string richDetails(const PackageInfo& pkg);
|
||||
void resetDetailsPanel();
|
||||
void setBrowseMode(BrowseMode mode);
|
||||
void performInstall(const std::string& package);
|
||||
void performRemove(const std::string& package);
|
||||
void populatePackageTable(const std::vector<PackageInfo>& results);
|
||||
void appendPackageRows(const std::vector<PackageInfo>& results);
|
||||
void addPackageRow(int row, const PackageInfo& pkg);
|
||||
void setBusy(bool busy);
|
||||
// Single privileged op at a time (pacman DB lock). Returns false + a
|
||||
// status message when an operation already runs.
|
||||
bool tryAcquireOp();
|
||||
void reloadCurrentView();
|
||||
void loadInstalled();
|
||||
void loadUpdates();
|
||||
void refreshHistoryTable();
|
||||
void loadCleanup();
|
||||
void populateCleanupTable(const std::vector<PackageInfo>& candidates);
|
||||
// Runs a bulk removal of the given candidates, one provider at a time, and
|
||||
// refreshes the cleanup list when the last group is done.
|
||||
void removeCleanupPackages(const std::vector<PackageInfo>& packages,
|
||||
const QString& description);
|
||||
void startNextCleanupRemoval();
|
||||
void loadLogs();
|
||||
void applyLogsFilter();
|
||||
void setupTray();
|
||||
void setupShortcuts();
|
||||
void notifyUpdatesAvailable(int count);
|
||||
QFrame* makeCard();
|
||||
QFrame* makeStatCard(const QString& iconName, const QString& title,
|
||||
const QString& accent, QLabel** valueOut);
|
||||
// Runs a request and, when the core refused it, walks the user through what
|
||||
// it needs before replaying it.
|
||||
void handleStartResult(const AppCore::StartResult& result, const QString& title);
|
||||
// Asks for the sudo password and hands it to the core. Returns false when
|
||||
// the user cancelled.
|
||||
bool promptForSudoPassword();
|
||||
// Names the process holding pacman's database and offers to close it — or to
|
||||
// drop a stale lock — so the pending action can resume.
|
||||
void handleDatabaseLock(const QString& title);
|
||||
// Lock-aware failure reporting: a locked database opens the recovery
|
||||
// dialog, anything else is shown as-is.
|
||||
void showActionError(const QString& title, const QString& error, bool locked);
|
||||
void applyCredentialMode(AppCore::CredentialMode mode);
|
||||
|
||||
// Logic layer: it owns the providers, the workers, the history, the
|
||||
// credentials and the self-updater. The frame never talks to them directly.
|
||||
AppCore* m_core = nullptr;
|
||||
|
||||
// Sidebar
|
||||
QFrame* m_sidebar = nullptr;
|
||||
@@ -273,54 +132,22 @@ private:
|
||||
QWidget* m_headerWidget = nullptr;
|
||||
QLabel* m_headerTitle = nullptr;
|
||||
QLabel* m_headerSubtitle = nullptr;
|
||||
QPushButton* m_headerUpdateAllButton = nullptr;
|
||||
|
||||
// Pages
|
||||
// Screens, stacked in sidebar order.
|
||||
QStackedWidget* m_pages = nullptr;
|
||||
QHash<QString, Page*> m_pageById; // "search" -> screen
|
||||
QHash<QString, int> m_navIdByPage; // "search" -> NavSearch
|
||||
DashboardPage* m_dashboard = nullptr;
|
||||
BrowsePage* m_browse = nullptr;
|
||||
CleanupPage* m_cleanup = nullptr;
|
||||
HistoryPage* m_history = nullptr;
|
||||
LogsPage* m_logs = nullptr;
|
||||
PluginsPage* m_plugins = nullptr;
|
||||
|
||||
// Dashboard
|
||||
QLabel* m_statInstalled = nullptr;
|
||||
QLabel* m_statUpdates = nullptr;
|
||||
QLabel* m_statHistory = nullptr;
|
||||
QLabel* m_statManager = nullptr;
|
||||
QListWidget* m_recentList = nullptr;
|
||||
|
||||
// Browse page
|
||||
QWidget* m_searchRowWidget = nullptr;
|
||||
QLineEdit* m_searchBar = nullptr;
|
||||
QPushButton* m_searchButton = nullptr;
|
||||
QWidget* m_filterRowWidget = nullptr;
|
||||
QLineEdit* m_filterBar = nullptr;
|
||||
QLabel* m_resultCount = nullptr;
|
||||
QPushButton* m_installButton = nullptr;
|
||||
QPushButton* m_removeButton = nullptr;
|
||||
QPushButton* m_updateButton = nullptr;
|
||||
QPushButton* m_updateAllButton = nullptr;
|
||||
QProgressBar* m_progressBar = nullptr;
|
||||
// Small indeterminate bar anchored in the status bar, shown at the bottom
|
||||
// of the window while any install/search runs.
|
||||
QProgressBar* m_installProgressBar = nullptr;
|
||||
QTableWidget* m_packageTable = nullptr;
|
||||
// Listing + empty-state hint, swapped depending on the row count.
|
||||
QStackedWidget* m_packageTableStack = nullptr;
|
||||
QLabel* m_packageName = nullptr;
|
||||
QLabel* m_packageVersion = nullptr;
|
||||
QLabel* m_packageRepo = nullptr;
|
||||
QLabel* m_packageSize = nullptr;
|
||||
QLabel* m_packageProvider = nullptr;
|
||||
QLabel* m_packageDescription = nullptr;
|
||||
// Rich pacman details are cached per package so re-selecting a row (or
|
||||
// arrowing through the list) does not re-spawn pacman queries.
|
||||
QHash<QString, std::string> m_detailsCache;
|
||||
|
||||
// History page
|
||||
QTableWidget* m_historyTable = nullptr;
|
||||
QComboBox* m_historyFilter = nullptr;
|
||||
QLabel* m_historyCount = nullptr;
|
||||
|
||||
// Logs page
|
||||
QTextEdit* m_logsText = nullptr;
|
||||
QLineEdit* m_logsFilter = nullptr;
|
||||
QString m_logsRaw;
|
||||
|
||||
// Tray (optional: hidden when the desktop has no system tray)
|
||||
QSystemTrayIcon* m_tray = nullptr;
|
||||
@@ -328,44 +155,7 @@ private:
|
||||
// dashboard refreshes do not spam the user.
|
||||
int m_lastNotifiedUpdates = -1;
|
||||
|
||||
// Cleanup page
|
||||
QTableWidget* m_cleanupTable = nullptr;
|
||||
QStackedWidget* m_cleanupTableStack = nullptr;
|
||||
QLabel* m_cleanupCount = nullptr;
|
||||
QPushButton* m_cleanupRemoveOrphansButton = nullptr;
|
||||
QPushButton* m_cleanupRemoveSelectionButton = nullptr;
|
||||
QPushButton* m_cleanupCacheButton = nullptr;
|
||||
std::vector<PackageInfo> m_cleanupCandidates;
|
||||
// Providers left to process for the bulk removal in progress, with the
|
||||
// packages each of them owns. They run one after another because pacman
|
||||
// locks its database.
|
||||
std::vector<std::pair<IPackageManager*, std::vector<std::string>>> m_pendingRemovals;
|
||||
|
||||
// Plugins page
|
||||
QTableWidget* m_pluginTable = nullptr;
|
||||
QPushButton* m_pluginToggleButton = nullptr;
|
||||
QPushButton* m_pluginInstallButton = nullptr;
|
||||
QLabel* m_pluginDescription = nullptr;
|
||||
std::string m_selectedPluginId;
|
||||
|
||||
// Backend
|
||||
PacmanManager* m_pacman = nullptr; // non-owning, used for sudo credentials/logs
|
||||
PluginManager* m_pluginManager = nullptr; // owns every provider
|
||||
HistoryManager* m_historyManager = nullptr;
|
||||
UpdateManager* m_updateManager = nullptr; // checks Gitea releases (owned)
|
||||
BrowseMode m_browseMode = ModeSearch;
|
||||
// True while a privileged op (or blocking load) runs; guards the pacman
|
||||
// DB lock against concurrent operations from double-clicks.
|
||||
bool m_busy = false;
|
||||
|
||||
// Settings
|
||||
QSettings m_settings;
|
||||
CredentialMode m_credentialMode = CredentialMode::EachTime;
|
||||
// Menu
|
||||
QAction* m_credLaunchAction = nullptr;
|
||||
QAction* m_credEachTimeAction = nullptr;
|
||||
|
||||
std::vector<PackageInfo> m_currentResults;
|
||||
std::vector<PackageInfo> m_installedPackages;
|
||||
PackageInfo m_selectedPackage;
|
||||
std::string m_pendingSelect; // package to auto-select after the installed list loads
|
||||
};
|
||||
@@ -0,0 +1,86 @@
|
||||
#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,
|
||||
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