Removes FlatpakManager from the built-in sources and from MainWindow's registration, so only pacman ships inside the binary. Flatpak is now provided exclusively by the external plugin. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
240 lines
7.8 KiB
C++
240 lines
7.8 KiB
C++
#pragma once
|
|
|
|
#include <QMainWindow>
|
|
#include <QLineEdit>
|
|
#include <QPushButton>
|
|
#include <QLabel>
|
|
#include <QVBoxLayout>
|
|
#include <QHBoxLayout>
|
|
#include <QProgressBar>
|
|
#include <QComboBox>
|
|
#include <QThread>
|
|
#include <QSettings>
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "package-manager.h"
|
|
#include "pacman-manager.h"
|
|
#include "plugin-manager.h"
|
|
#include "history-manager.h"
|
|
|
|
class QStackedWidget;
|
|
class QTableWidget;
|
|
class QTextEdit;
|
|
class QListWidget;
|
|
class QListWidgetItem;
|
|
class QButtonGroup;
|
|
class QFrame;
|
|
class QAction;
|
|
|
|
// 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 };
|
|
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 };
|
|
InstallWorker(IPackageManager* pm, Op op, const std::string& package);
|
|
InstallWorker(const std::vector<IPackageManager*>& providers, Op op);
|
|
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;
|
|
};
|
|
|
|
class MainWindow : public QMainWindow {
|
|
Q_OBJECT
|
|
public:
|
|
explicit MainWindow(QWidget* parent = nullptr);
|
|
~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 onHistoryFilterChanged();
|
|
void onInstalledFilterChanged(const QString& text);
|
|
void onRecentActivityClicked(QListWidgetItem* item);
|
|
void onProviderTableSelected(int row);
|
|
void onToggleProvider();
|
|
void onRescanProviders();
|
|
void onInstallProviderTool();
|
|
|
|
private:
|
|
enum BrowseMode { ModeSearch, ModeInstalled, ModeUpdates };
|
|
|
|
// 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.
|
|
void showProviderError(const QString& title, IPackageManager* provider);
|
|
|
|
void setupUI();
|
|
void setupSidebar();
|
|
void setupHeader();
|
|
void setupDashboardPage();
|
|
void setupBrowsePage();
|
|
void setupHistoryPage();
|
|
void setupLogsPage();
|
|
void setupProvidersPage();
|
|
void setupMenuBar();
|
|
void updatePageTitle();
|
|
void updateStatusBar();
|
|
void refreshDashboard();
|
|
void refreshRecentActivity();
|
|
void refreshProvidersTable();
|
|
void updatePackageInfo(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);
|
|
void reloadCurrentView();
|
|
void loadInstalled();
|
|
void loadUpdates();
|
|
void refreshHistoryTable();
|
|
void loadLogs();
|
|
QFrame* makeCard();
|
|
QFrame* makeStatCard(const QString& iconName, const QString& title, QLabel** valueOut);
|
|
|
|
// Sidebar
|
|
QFrame* m_sidebar = nullptr;
|
|
QButtonGroup* m_navGroup = nullptr;
|
|
QPushButton* m_refreshButton = nullptr;
|
|
|
|
// Header
|
|
QWidget* m_headerWidget = nullptr;
|
|
QLabel* m_headerTitle = nullptr;
|
|
QLabel* m_headerSubtitle = nullptr;
|
|
|
|
// Pages
|
|
QStackedWidget* m_pages = 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;
|
|
QLabel* m_packageName = nullptr;
|
|
QLabel* m_packageVersion = nullptr;
|
|
QLabel* m_packageRepo = nullptr;
|
|
QLabel* m_packageSize = nullptr;
|
|
QLabel* m_packageProvider = nullptr;
|
|
QWidget* m_packageUpdateBadge = nullptr;
|
|
QLabel* m_packageDescription = nullptr;
|
|
|
|
// History page
|
|
QTableWidget* m_historyTable = nullptr;
|
|
QComboBox* m_historyFilter = nullptr;
|
|
QLabel* m_historyCount = nullptr;
|
|
|
|
// Logs page
|
|
QTextEdit* m_logsText = nullptr;
|
|
|
|
// Providers page
|
|
QTableWidget* m_providerTable = nullptr;
|
|
QPushButton* m_providerToggleButton = nullptr;
|
|
QPushButton* m_providerInstallButton = nullptr;
|
|
QLabel* m_providerDescription = nullptr;
|
|
std::string m_selectedProviderId;
|
|
|
|
// Backend
|
|
PacmanManager* m_pacman = nullptr; // non-owning, used for sudo credentials/logs
|
|
PluginManager* m_pluginManager = nullptr; // owns every provider
|
|
HistoryManager* m_historyManager = nullptr;
|
|
BrowseMode m_browseMode = ModeSearch;
|
|
|
|
// Settings
|
|
QSettings m_settings;
|
|
CredentialMode m_credentialMode = CredentialMode::EachTime;
|
|
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
|
|
};
|