refactor(pages): group the screens by what the user is doing
pages/ was a flat row of eight screens, so a change to one meant scanning the whole folder to see what else was in it. The screens now sit in packages/ (browse, cleanup), overview/ (dashboard, history), system/ (logs, settings) and extensions/ (plugins), with the scaffolding they all build on — the Page base and the shared widgets — in base/.
This commit is contained in:
19 files changed
+19
-19
No files matched your search
@@ -0,0 +1,13 @@
|
||||
#include "page.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
Page::Page(AppCore* core, QWidget* parent) : QWidget(parent), m_core(core) {}
|
||||
|
||||
QMainWindow* Page::mainWindow() const {
|
||||
return qobject_cast<QMainWindow*>(window());
|
||||
}
|
||||
|
||||
void Page::start(const AppCore::StartResult& result, const QString& title) {
|
||||
emit requestStart(result, title);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
|
||||
#include "app-core.h"
|
||||
|
||||
// One screen of the application. Each screen lives in its own file under
|
||||
// pages/ and owns nothing but its own widgets: the frame (MainWindow) keeps the
|
||||
// sidebar, the header, the status bar and every dialog, and the logic stays in
|
||||
// AppCore.
|
||||
//
|
||||
// Adding a screen therefore means writing one Page subclass here and
|
||||
// registering it in MainWindow::setupUI — no backend code involved.
|
||||
class QMainWindow;
|
||||
|
||||
class Page : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Page(AppCore* core, QWidget* parent = nullptr);
|
||||
|
||||
// Header text, asked by the frame whenever the screen is shown. A screen
|
||||
// whose title depends on its state (the browse page shows search, installed
|
||||
// or updates) just returns the current one.
|
||||
virtual QString navTitle() const = 0;
|
||||
virtual QString navSubtitle() const = 0;
|
||||
|
||||
// Called every time the screen becomes visible, so it can reload whatever
|
||||
// may be stale. Default: nothing to reload.
|
||||
virtual void refresh() {}
|
||||
|
||||
signals:
|
||||
// Ask the frame to switch to another screen (dashboard shortcuts) or to run
|
||||
// a request on the user's behalf.
|
||||
void goToPage(const QString& pageId);
|
||||
void requestStart(AppCore::StartResult result, const QString& title);
|
||||
// Something the user should read in the status bar, with no operation
|
||||
// behind it ("Aucune liste à exporter.", ...).
|
||||
void message(const QString& text);
|
||||
// The screen picked another sudo credential mode. The frame answers it
|
||||
// rather than the screen writing the preference itself, because prompting
|
||||
// for the password is the frame's job and the menu bar's checkmarks have to
|
||||
// follow along.
|
||||
void credentialModeRequested(bool atLaunch);
|
||||
|
||||
protected:
|
||||
AppCore* core() const { return m_core; }
|
||||
|
||||
// Top-level window this screen is stacked in. Needed by the addon hook,
|
||||
// which attaches a plugin's own UI to the main window.
|
||||
QMainWindow* mainWindow() const;
|
||||
|
||||
// Hands a request to the frame: it owns the sudo-password and pacman-lock
|
||||
// dialogs and replays the request once the user answered.
|
||||
void start(const AppCore::StartResult& result, const QString& title);
|
||||
|
||||
private:
|
||||
AppCore* m_core = nullptr; // non-owning: the frame owns the core
|
||||
};
|
||||
@@ -0,0 +1,173 @@
|
||||
#include "ui-kit.h"
|
||||
|
||||
#include <QAbstractItemView>
|
||||
#include <QCoreApplication>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QSignalBlocker>
|
||||
#include <QStackedWidget>
|
||||
#include <QTableWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace ui {
|
||||
|
||||
QIcon icon(const QString& name) {
|
||||
return QIcon(QString(":/icons/%1.svg").arg(name));
|
||||
}
|
||||
|
||||
QPixmap iconPixmap(const QString& name, int size) {
|
||||
return icon(name).pixmap(QSize(size, size));
|
||||
}
|
||||
|
||||
// A pill, like the website's .paquet-since / .nav-dropdown-version tags: a low
|
||||
// tint of a colour as background, the colour itself as text, fully rounded.
|
||||
QLabel* badge(const QString& text, const QString& background, const QString& foreground) {
|
||||
QLabel* label = new QLabel(text);
|
||||
label->setStyleSheet(QString(
|
||||
"background: %1; color: %2; border-radius: 999px;"
|
||||
"padding: 2px 10px; font-size: 11px; font-weight: 700;")
|
||||
.arg(background, foreground));
|
||||
return label;
|
||||
}
|
||||
|
||||
QFrame* card() {
|
||||
QFrame* frame = new QFrame();
|
||||
frame->setObjectName("card");
|
||||
return frame;
|
||||
}
|
||||
|
||||
QFrame* statCard(const QString& iconName, const QString& title, const QString& accent,
|
||||
QLabel** valueOut) {
|
||||
QFrame* frame = card();
|
||||
// Read by the stylesheet rule that draws the coloured left edge.
|
||||
frame->setProperty("accent", accent);
|
||||
QVBoxLayout* layout = new QVBoxLayout(frame);
|
||||
layout->setContentsMargins(18, 16, 18, 16);
|
||||
layout->setSpacing(6);
|
||||
|
||||
QLabel* iconLabel = new QLabel();
|
||||
iconLabel->setPixmap(iconPixmap(iconName, 24));
|
||||
iconLabel->setStyleSheet("background: transparent;");
|
||||
layout->addWidget(iconLabel);
|
||||
|
||||
QLabel* value = new QLabel("…");
|
||||
value->setObjectName("statValue");
|
||||
layout->addWidget(value);
|
||||
|
||||
QLabel* titleLabel = new QLabel(title);
|
||||
titleLabel->setObjectName("statTitle");
|
||||
layout->addWidget(titleLabel);
|
||||
|
||||
if (valueOut) *valueOut = value;
|
||||
return frame;
|
||||
}
|
||||
|
||||
QTableWidget* table(const QStringList& headers, bool allStretch) {
|
||||
QTableWidget* widget = new QTableWidget(0, headers.size());
|
||||
widget->setHorizontalHeaderLabels(headers);
|
||||
widget->verticalHeader()->setVisible(false);
|
||||
widget->verticalHeader()->setDefaultSectionSize(36);
|
||||
widget->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
widget->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
widget->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
widget->setShowGrid(false);
|
||||
widget->setAlternatingRowColors(true);
|
||||
widget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
|
||||
for (int column = 0; column < headers.size(); ++column) {
|
||||
widget->horizontalHeader()->setSectionResizeMode(
|
||||
column,
|
||||
allStretch ? QHeaderView::Stretch
|
||||
: (column == 0 ? QHeaderView::Stretch : QHeaderView::ResizeToContents));
|
||||
}
|
||||
return widget;
|
||||
}
|
||||
|
||||
QStackedWidget* withEmptyState(QTableWidget* widget, const QString& hint) {
|
||||
QStackedWidget* stack = new QStackedWidget();
|
||||
stack->addWidget(widget);
|
||||
|
||||
QWidget* placeholder = new QWidget();
|
||||
QVBoxLayout* layout = new QVBoxLayout(placeholder);
|
||||
layout->addStretch();
|
||||
QLabel* label = new QLabel(hint);
|
||||
label->setAlignment(Qt::AlignCenter);
|
||||
label->setWordWrap(true);
|
||||
label->setStyleSheet("background: transparent; color: #64748b; font-size: 13px;");
|
||||
layout->addWidget(label);
|
||||
layout->addStretch();
|
||||
stack->addWidget(placeholder);
|
||||
return stack;
|
||||
}
|
||||
|
||||
void showEmptyState(QStackedWidget* stack, bool empty) {
|
||||
if (stack) stack->setCurrentIndex(empty ? 1 : 0);
|
||||
}
|
||||
|
||||
void setEmptyStateText(QStackedWidget* stack, const QString& hint) {
|
||||
if (!stack) return;
|
||||
// withEmptyState() puts the hint label second in the placeholder's layout:
|
||||
// the only label of the stack, so this stays a safe lookup.
|
||||
if (QLabel* label = stack->findChild<QLabel*>()) label->setText(hint);
|
||||
}
|
||||
|
||||
QLabel* countLabel() {
|
||||
QLabel* label = new QLabel();
|
||||
label->setStyleSheet("font-size: 12px; color: #64748b; font-weight: 600;");
|
||||
return label;
|
||||
}
|
||||
|
||||
QString providersLabel(const PluginManager* plugins, const PackageInfo& pkg) {
|
||||
auto labelFor = [plugins](const std::string& id) {
|
||||
for (const auto& entry : plugins->plugins()) {
|
||||
if (entry.info.id == id) return QString::fromStdString(entry.info.name);
|
||||
}
|
||||
return QString::fromStdString(id);
|
||||
};
|
||||
|
||||
QStringList names;
|
||||
for (const auto& id : pkg.providers) names << labelFor(id);
|
||||
if (names.isEmpty() && !pkg.provider.empty()) names << labelFor(pkg.provider);
|
||||
return names.join(", ");
|
||||
}
|
||||
|
||||
QString packageStatusText(const PackageInfo& pkg) {
|
||||
if (pkg.installed && pkg.updateAvailable) return QCoreApplication::translate("ui", "MAJ dispo");
|
||||
if (pkg.installed) return QCoreApplication::translate("ui", "Installé");
|
||||
if (!pkg.repository.empty()) return QStringLiteral("Disponible");
|
||||
return QStringLiteral("—");
|
||||
}
|
||||
|
||||
QString csvField(const QString& value) {
|
||||
if (!value.contains(';') && !value.contains('"') && !value.contains('\n')) {
|
||||
return value;
|
||||
}
|
||||
QString escaped = value;
|
||||
escaped.replace(QLatin1String("\""), QLatin1String("\"\""));
|
||||
return QLatin1Char('"') + escaped + QLatin1Char('"');
|
||||
}
|
||||
|
||||
struct TableFillBatch::Impl {
|
||||
QTableWidget* table = nullptr;
|
||||
std::unique_ptr<QSignalBlocker> blocker;
|
||||
};
|
||||
|
||||
TableFillBatch::TableFillBatch(QTableWidget* widget)
|
||||
: m_impl(std::make_unique<Impl>()) {
|
||||
m_impl->table = widget;
|
||||
if (!widget) return;
|
||||
widget->setUpdatesEnabled(false);
|
||||
m_impl->blocker = std::make_unique<QSignalBlocker>(widget);
|
||||
}
|
||||
|
||||
void TableFillBatch::release() {
|
||||
if (!m_impl->table || !m_impl->blocker) return;
|
||||
m_impl->blocker.reset();
|
||||
m_impl->table->setUpdatesEnabled(true);
|
||||
}
|
||||
|
||||
TableFillBatch::~TableFillBatch() {
|
||||
release();
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
@@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include <QFrame>
|
||||
#include <QIcon>
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "package-manager.h"
|
||||
#include "plugin-manager.h"
|
||||
|
||||
class QStackedWidget;
|
||||
class QTableWidget;
|
||||
|
||||
// Small widget helpers shared by the screens. They exist so a screen file shows
|
||||
// its layout and its wording instead of repeating the same table, card and pill
|
||||
// setup — the look itself is still driven by the application stylesheet (see
|
||||
// MainWindow::setupUI).
|
||||
namespace ui {
|
||||
|
||||
// One of the embedded SVG icons (resources/resources.qrc).
|
||||
QIcon icon(const QString& name);
|
||||
QPixmap iconPixmap(const QString& name, int size);
|
||||
|
||||
// Rounded status pill (coloured background + foreground).
|
||||
QLabel* badge(const QString& text, const QString& background, const QString& foreground);
|
||||
|
||||
// Plain raised surface, and the coloured stat card used by the dashboard.
|
||||
QFrame* card();
|
||||
QFrame* statCard(const QString& iconName, const QString& title, const QString& accent,
|
||||
QLabel** valueOut);
|
||||
|
||||
// Listing used by every screen: no frame, alternating rows, and the name column
|
||||
// taking the free space (every column when allStretch).
|
||||
QTableWidget* table(const QStringList& headers, bool allStretch = false);
|
||||
|
||||
// Wraps a listing in a stack that swaps in a centered hint while it is empty,
|
||||
// so a screen with no result explains itself instead of showing a bare header.
|
||||
QStackedWidget* withEmptyState(QTableWidget* table, const QString& hint);
|
||||
void showEmptyState(QStackedWidget* stack, bool empty);
|
||||
// Rewrites the hint shown while the listing is empty, so a screen can walk the
|
||||
// user through its states ("searching..." then "nothing found").
|
||||
void setEmptyStateText(QStackedWidget* stack, const QString& hint);
|
||||
|
||||
// Small grey counter ("12 paquet(s)").
|
||||
QLabel* countLabel();
|
||||
|
||||
// Display names of every provider offering a package (the Fournisseur column).
|
||||
QString providersLabel(const PluginManager* plugins, const PackageInfo& pkg);
|
||||
// Human-readable status of a package row, shared by the table and the exports.
|
||||
QString packageStatusText(const PackageInfo& pkg);
|
||||
// Quotes a CSV field when it contains the separator, a quote or a newline, so
|
||||
// exported lists stay importable in a spreadsheet.
|
||||
QString csvField(const QString& value);
|
||||
|
||||
// Fills a table in one repaint batch, with its signals muted: without it every
|
||||
// setItem() repaints the viewport, and on the browse page each selection change
|
||||
// fires the pacman queries behind the details panel (a thousand rows meant a
|
||||
// thousand repaints and a pacman call in the middle of the fill).
|
||||
class TableFillBatch {
|
||||
public:
|
||||
explicit TableFillBatch(QTableWidget* table);
|
||||
~TableFillBatch();
|
||||
// Called before selecting a row: that selection is what refreshes the
|
||||
// details panel, so it has to be seen by the table's signals. Idempotent,
|
||||
// which lets the destructor cover an early return too.
|
||||
void release();
|
||||
|
||||
TableFillBatch(const TableFillBatch&) = delete;
|
||||
TableFillBatch& operator=(const TableFillBatch&) = delete;
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> m_impl;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
Reference in new issue
Block a user