Redesign the whole UI around a dashboard with stat cards, quick actions and recent activity, a header bar with contextual page titles, and a denser table-based package listing with an instant local filter on the installed page and a filterable history table. Register the std::vector<PackageInfo> metatype so worker results actually reach the UI thread instead of being dropped silently.
179 lines
4.8 KiB
C++
179 lines
4.8 KiB
C++
#pragma once
|
|
|
|
#include <QMainWindow>
|
|
#include <QLineEdit>
|
|
#include <QPushButton>
|
|
#include <QLabel>
|
|
#include <QVBoxLayout>
|
|
#include <QHBoxLayout>
|
|
#include <QProgressBar>
|
|
#include <QComboBox>
|
|
#include <QThread>
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "package-manager.h"
|
|
#include "pacman-manager.h"
|
|
#include "history-manager.h"
|
|
|
|
class QStackedWidget;
|
|
class QTableWidget;
|
|
class QTextEdit;
|
|
class QListWidget;
|
|
class QButtonGroup;
|
|
class QFrame;
|
|
|
|
// Runs a package search off the UI thread.
|
|
class SearchWorker : public QThread {
|
|
Q_OBJECT
|
|
public:
|
|
SearchWorker(IPackageManager* pm, const std::string& query);
|
|
void run() override;
|
|
signals:
|
|
void finished(std::vector<PackageInfo> results);
|
|
private:
|
|
IPackageManager* m_pm;
|
|
std::string m_query;
|
|
};
|
|
|
|
// Loads a package list (installed or outdated) off the UI thread.
|
|
class ListWorker : public QThread {
|
|
Q_OBJECT
|
|
public:
|
|
enum Mode { Installed, Updates };
|
|
ListWorker(IPackageManager* pm, Mode mode);
|
|
void run() override;
|
|
signals:
|
|
void finished(std::vector<PackageInfo> results);
|
|
private:
|
|
IPackageManager* m_pm;
|
|
Mode m_mode;
|
|
};
|
|
|
|
// Runs an install/remove/update/refresh action off the UI thread.
|
|
class InstallWorker : public QThread {
|
|
Q_OBJECT
|
|
public:
|
|
enum class Op { Install, Remove, Update, UpdateAll, Refresh };
|
|
InstallWorker(IPackageManager* pm, Op op, const std::string& package);
|
|
void run() override;
|
|
signals:
|
|
void progress(const QString& message);
|
|
void finished(bool success);
|
|
private:
|
|
IPackageManager* m_pm;
|
|
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 onListFinished(std::vector<PackageInfo> results);
|
|
void onPackageSelected(int row);
|
|
void onNavChanged(int id);
|
|
void onClearHistory();
|
|
void onRefreshLogs();
|
|
void onHistoryFilterChanged();
|
|
void onInstalledFilterChanged(const QString& text);
|
|
|
|
private:
|
|
enum BrowseMode { ModeSearch, ModeInstalled, ModeUpdates };
|
|
|
|
void setupUI();
|
|
void setupSidebar();
|
|
void setupHeader();
|
|
void setupDashboardPage();
|
|
void setupBrowsePage();
|
|
void setupHistoryPage();
|
|
void setupLogsPage();
|
|
void setupMenuBar();
|
|
void updatePageTitle();
|
|
void updateStatusBar();
|
|
void refreshDashboard();
|
|
void refreshRecentActivity();
|
|
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 setBusy(bool busy);
|
|
void reloadCurrentView();
|
|
void loadInstalled();
|
|
void loadUpdates();
|
|
void refreshHistoryTable();
|
|
void loadLogs();
|
|
QFrame* makeCard();
|
|
QFrame* makeStatCard(const QString& icon, 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;
|
|
QTableWidget* m_packageTable = nullptr;
|
|
QLabel* m_packageName = nullptr;
|
|
QLabel* m_packageVersion = nullptr;
|
|
QLabel* m_packageRepo = nullptr;
|
|
QLabel* m_packageSize = nullptr;
|
|
QLabel* 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;
|
|
|
|
// Backend
|
|
PacmanManager* m_pacman = nullptr;
|
|
HistoryManager* m_historyManager = nullptr;
|
|
BrowseMode m_browseMode = ModeSearch;
|
|
|
|
std::vector<PackageInfo> m_currentResults;
|
|
std::vector<PackageInfo> m_installedPackages;
|
|
PackageInfo m_selectedPackage;
|
|
};
|