The window carried a palette of its own, so the desktop app and the site looked like two different products. The stylesheet now uses the website's tokens (slate surfaces on a #0f172a page, sky-blue accent, serif headings, pill-shaped badges); the site's rgba() borders are pre-blended because a Qt stylesheet only takes solid colours, and plain widgets are left transparent so the page glow shows through them. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
218 lines
8.4 KiB
C++
218 lines
8.4 KiB
C++
#include "plugins-page.h"
|
|
|
|
#include <QColor>
|
|
#include <QFrame>
|
|
#include <QHBoxLayout>
|
|
#include <QLabel>
|
|
#include <QPushButton>
|
|
#include <QTableWidget>
|
|
#include <QVBoxLayout>
|
|
|
|
#include "ui-kit.h"
|
|
|
|
PluginsPage::PluginsPage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
|
layout->setContentsMargins(24, 20, 24, 20);
|
|
layout->setSpacing(12);
|
|
|
|
QFrame* hintCard = ui::card();
|
|
QVBoxLayout* hintLayout = new QVBoxLayout(hintCard);
|
|
hintLayout->setContentsMargins(18, 16, 18, 16);
|
|
hintLayout->setSpacing(4);
|
|
|
|
QLabel* hintTitle = new QLabel("AJOUTER UN PLUGIN");
|
|
hintTitle->setObjectName("cardTitle");
|
|
hintLayout->addWidget(hintTitle);
|
|
|
|
QLabel* hint = new QLabel(
|
|
"Pacman est intégré et le plugin Flatpak est livré par défaut. Si un "
|
|
"fournisseur est « Indisponible », sélectionnez-le puis cliquez sur "
|
|
"« Installer l'outil » pour l'installer via pacman. Un plugin peut être "
|
|
"un gestionnaire de paquets (apt, dnf, ...) ou n'importe quelle extension "
|
|
"(addon graphique, helper, ...) tant qu'il est écrit en C++ : compilez une "
|
|
"bibliothèque partagée (voir plugins/example-provider et "
|
|
"plugins/example-addon) et déposez-la dans "
|
|
"~/.local/share/PacManager/plugins/ ou dans le dossier plugins/ à côté de "
|
|
"l'exécutable, puis cliquez sur « Recharger ».");
|
|
hint->setWordWrap(true);
|
|
hint->setStyleSheet("font-size: 12px; color: #94a3b8;");
|
|
hintLayout->addWidget(hint);
|
|
|
|
layout->addWidget(hintCard);
|
|
|
|
m_table = ui::table({"Plugin", "Type", "Version", "Auteur", "Statut"});
|
|
connect(m_table, &QTableWidget::currentCellChanged, this,
|
|
[this](int currentRow, int, int, int) { onSelected(currentRow); });
|
|
layout->addWidget(m_table, 1);
|
|
|
|
m_description = new QLabel("");
|
|
m_description->setWordWrap(true);
|
|
m_description->setStyleSheet(
|
|
"font-size: 13px; color: #94a3b8; background: transparent; padding: 2px 4px;");
|
|
layout->addWidget(m_description);
|
|
|
|
QHBoxLayout* buttonBar = new QHBoxLayout();
|
|
buttonBar->addStretch();
|
|
|
|
// Installs the OS package backing a provider whose tool is missing
|
|
// (e.g. pacman -S flatpak), then rescans so it becomes available.
|
|
m_installButton = new QPushButton("Installer l'outil");
|
|
m_installButton->setProperty("variant", "primary");
|
|
m_installButton->setEnabled(false);
|
|
m_installButton->setVisible(false);
|
|
connect(m_installButton, &QPushButton::clicked, this, [this, core] {
|
|
if (m_selectedId.empty()) return;
|
|
start(core->installPluginTool(m_selectedId), tr("Installation de l'outil"));
|
|
});
|
|
buttonBar->addWidget(m_installButton);
|
|
|
|
m_toggleButton = new QPushButton("Activer");
|
|
m_toggleButton->setEnabled(false);
|
|
connect(m_toggleButton, &QPushButton::clicked, this, [this, core] {
|
|
if (m_selectedId.empty()) return;
|
|
const std::string id = m_selectedId;
|
|
const bool enabled = !core->plugins()->isEnabled(id);
|
|
core->setPluginEnabled(id, enabled);
|
|
|
|
// A freshly enabled addon gets the window so it can attach its UI (it
|
|
// may have been disabled when onUiReady ran at launch). The core already
|
|
// announced the change, which refreshed this table.
|
|
if (enabled) {
|
|
for (const auto& entry : core->plugins()->plugins()) {
|
|
if (entry.info.id == id && entry.plugin) {
|
|
entry.plugin->onUiReady(mainWindow());
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
});
|
|
buttonBar->addWidget(m_toggleButton);
|
|
|
|
QPushButton* rescanButton = new QPushButton("Recharger");
|
|
rescanButton->setIcon(ui::icon("refresh"));
|
|
rescanButton->setToolTip("Rescanner les dossiers de plugins");
|
|
connect(rescanButton, &QPushButton::clicked, this, [this, core] {
|
|
core->reloadPlugins();
|
|
for (IPlugin* addon : core->plugins()->availableAddons()) {
|
|
addon->onUiReady(mainWindow());
|
|
}
|
|
});
|
|
buttonBar->addWidget(rescanButton);
|
|
|
|
layout->addLayout(buttonBar);
|
|
|
|
connect(core, &AppCore::pluginsChanged, this, &PluginsPage::refresh);
|
|
refreshTable();
|
|
}
|
|
|
|
void PluginsPage::refresh() {
|
|
refreshTable();
|
|
}
|
|
|
|
void PluginsPage::refreshTable() {
|
|
const auto& plugins = core()->plugins()->plugins();
|
|
|
|
QFont nameFont;
|
|
nameFont.setWeight(QFont::DemiBold);
|
|
|
|
ui::TableFillBatch batch(m_table);
|
|
m_table->setRowCount(0);
|
|
m_table->setRowCount(static_cast<int>(plugins.size()));
|
|
|
|
for (int i = 0; i < static_cast<int>(plugins.size()); ++i) {
|
|
const auto& entry = plugins[i];
|
|
const bool enabled = core()->plugins()->isEnabled(entry.info.id);
|
|
|
|
QTableWidgetItem* nameItem =
|
|
new QTableWidgetItem(QString::fromStdString(entry.info.name));
|
|
nameItem->setFont(nameFont);
|
|
nameItem->setData(Qt::UserRole, QString::fromStdString(entry.info.id));
|
|
m_table->setItem(i, 0, nameItem);
|
|
|
|
// Type column distinguishes package-manager providers from generic
|
|
// addons; the build origin is appended for external plugins.
|
|
const QString kindText = entry.info.kind == PluginKind::Addon ? "Extension"
|
|
: "Fournisseur";
|
|
QTableWidgetItem* typeItem =
|
|
new QTableWidgetItem(entry.info.builtin ? kindText : kindText + " (externe)");
|
|
typeItem->setForeground(QColor("#94a3b8"));
|
|
m_table->setItem(i, 1, typeItem);
|
|
|
|
m_table->setItem(i, 2, new QTableWidgetItem(QString::fromStdString(entry.info.version)));
|
|
m_table->setItem(i, 3, new QTableWidgetItem(QString::fromStdString(entry.info.author)));
|
|
|
|
QString statusText;
|
|
QColor statusColor;
|
|
if (!entry.info.available) {
|
|
statusText = "Indisponible";
|
|
statusColor = QColor("#64748b");
|
|
} else if (enabled) {
|
|
statusText = "Actif";
|
|
statusColor = QColor("#34d399");
|
|
} else {
|
|
statusText = "Désactivé";
|
|
statusColor = QColor("#fbbf24");
|
|
}
|
|
|
|
QTableWidgetItem* statusItem = new QTableWidgetItem(statusText);
|
|
statusItem->setForeground(statusColor);
|
|
statusItem->setIcon(ui::icon(entry.info.available ? (enabled ? "check" : "close")
|
|
: "alert"));
|
|
m_table->setItem(i, 4, statusItem);
|
|
}
|
|
batch.release();
|
|
|
|
if (plugins.empty()) {
|
|
m_toggleButton->setEnabled(false);
|
|
m_installButton->setVisible(false);
|
|
m_description->clear();
|
|
return;
|
|
}
|
|
|
|
// Keep the previously selected plugin selected when possible.
|
|
int row = 0;
|
|
for (int i = 0; i < static_cast<int>(plugins.size()); ++i) {
|
|
if (plugins[i].info.id == m_selectedId) {
|
|
row = i;
|
|
break;
|
|
}
|
|
}
|
|
m_table->selectRow(row);
|
|
onSelected(row);
|
|
}
|
|
|
|
void PluginsPage::onSelected(int row) {
|
|
const auto& plugins = core()->plugins()->plugins();
|
|
if (row < 0 || row >= static_cast<int>(plugins.size())) {
|
|
m_toggleButton->setEnabled(false);
|
|
m_installButton->setVisible(false);
|
|
m_description->clear();
|
|
return;
|
|
}
|
|
|
|
const auto& entry = plugins[row];
|
|
m_selectedId = entry.info.id;
|
|
m_description->setText(QString::fromStdString(entry.info.description));
|
|
|
|
const bool toggleable = entry.info.available;
|
|
m_toggleButton->setEnabled(toggleable);
|
|
m_toggleButton->setToolTip(
|
|
toggleable ? QString()
|
|
: QString("Outil « %1 » non détecté sur ce système.")
|
|
.arg(QString::fromStdString(entry.info.name)));
|
|
m_toggleButton->setText(core()->plugins()->isEnabled(entry.info.id) ? "Désactiver"
|
|
: "Activer");
|
|
|
|
// Offer to install the backing tool (e.g. flatpak via pacman) when it is
|
|
// missing and we know which OS package provides it.
|
|
const bool pacmanAvailable = core()->plugins()->findAvailable("pacman") != nullptr;
|
|
const bool installable = !entry.info.available && !entry.info.installHint.empty()
|
|
&& pacmanAvailable;
|
|
m_installButton->setVisible(!entry.info.available);
|
|
m_installButton->setEnabled(installable);
|
|
m_installButton->setToolTip(
|
|
installable
|
|
? QString("sudo pacman -S %1").arg(QString::fromStdString(entry.info.installHint))
|
|
: QString());
|
|
}
|