Replace the single-screen layout with a sidebar and stacked pages: Search, Installed, Updates, History and Logs. Also fix the update-all and refresh actions, which previously called install with an empty package name instead of running the proper pacman commands. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
147 lines
3.7 KiB
C++
147 lines
3.7 KiB
C++
#pragma once
|
|
|
|
#include <QMainWindow>
|
|
#include <QLineEdit>
|
|
#include <QListWidget>
|
|
#include <QPushButton>
|
|
#include <QLabel>
|
|
#include <QVBoxLayout>
|
|
#include <QHBoxLayout>
|
|
#include <QProgressBar>
|
|
#include <QStatusBar>
|
|
#include <QMenuBar>
|
|
#include <QMenu>
|
|
#include <QAction>
|
|
#include <QThread>
|
|
|
|
#include "package-manager.h"
|
|
#include "pacman-manager.h"
|
|
#include "history-manager.h"
|
|
|
|
class QStackedWidget;
|
|
class QButtonGroup;
|
|
class QTableWidget;
|
|
class QTextEdit;
|
|
|
|
// 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();
|
|
|
|
private:
|
|
enum BrowseMode { ModeSearch, ModeInstalled, ModeUpdates };
|
|
|
|
void setupUI();
|
|
void setupBrowsePage();
|
|
void setupHistoryPage();
|
|
void setupLogsPage();
|
|
void setupMenuBar();
|
|
void updatePackageInfo(const PackageInfo& pkg);
|
|
void updateStatusBar();
|
|
void setBrowseMode(BrowseMode mode);
|
|
void performInstall(const std::string& package);
|
|
void performRemove(const std::string& package);
|
|
void populatePackageList(const std::vector<PackageInfo>& results);
|
|
QListWidgetItem* makePackageRow(const PackageInfo& pkg);
|
|
void setBusy(bool busy);
|
|
void reloadCurrentView();
|
|
void loadInstalled();
|
|
void loadUpdates();
|
|
void refreshHistoryTable();
|
|
void loadLogs();
|
|
|
|
// Sidebar
|
|
QButtonGroup* m_navGroup;
|
|
QStackedWidget* m_pages;
|
|
QPushButton* m_refreshButton;
|
|
|
|
// Browse page
|
|
QWidget* m_searchRowWidget;
|
|
QLabel* m_browseTitle;
|
|
QLineEdit* m_searchBar;
|
|
QPushButton* m_searchButton;
|
|
QPushButton* m_installButton;
|
|
QPushButton* m_removeButton;
|
|
QPushButton* m_updateButton;
|
|
QPushButton* m_updateAllButton;
|
|
QProgressBar* m_progressBar;
|
|
QListWidget* m_packageList;
|
|
QLabel* m_packageName;
|
|
QLabel* m_packageVersion;
|
|
QLabel* m_packageRepo;
|
|
QLabel* m_packageSize;
|
|
QLabel* m_packageDescription;
|
|
|
|
// History page
|
|
QTableWidget* m_historyTable;
|
|
|
|
// Logs page
|
|
QTextEdit* m_logsText;
|
|
|
|
// Backend
|
|
PacmanManager* m_pacman;
|
|
HistoryManager* m_historyManager;
|
|
BrowseMode m_browseMode = ModeSearch;
|
|
|
|
std::vector<PackageInfo> m_currentResults;
|
|
PackageInfo m_selectedPackage;
|
|
};
|