Merge branch 'feat/fwspacm-plugin-packages' into release-1.6.0
This commit is contained in:
29 files changed
+2107
-1047
No files matched your search
+125
-144
@@ -1,16 +1,16 @@
|
||||
#include "plugins-page.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QFrame>
|
||||
#include <QHBoxLayout>
|
||||
#include <QInputDialog>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QTableWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "plugin-shop.h"
|
||||
#include "plugin-package.h"
|
||||
#include "ui-kit.h"
|
||||
|
||||
PluginsPage::PluginsPage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
@@ -27,16 +27,16 @@ PluginsPage::PluginsPage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
hintTitle->setObjectName("cardTitle");
|
||||
hintLayout->addWidget(hintTitle);
|
||||
|
||||
QLabel* hint = new QLabel(
|
||||
QLabel* hint = new QLabel(QString(
|
||||
"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 ».");
|
||||
"plugins/example-addon), empaquetez-la avec ./make-plugin-package.py, puis "
|
||||
"déposez le fichier %1 obtenu n'importe où sur la fenêtre.")
|
||||
.arg(PluginPackage::suffix()));
|
||||
hint->setWordWrap(true);
|
||||
hint->setStyleSheet("font-size: 12px; color: #94a3b8;");
|
||||
hintLayout->addWidget(hint);
|
||||
@@ -104,180 +104,161 @@ PluginsPage::PluginsPage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
|
||||
layout->addLayout(buttonBar);
|
||||
|
||||
// ---- Shop: the catalogue of installable plugins ----
|
||||
QFrame* shopCard = ui::card();
|
||||
QVBoxLayout* shopLayout = new QVBoxLayout(shopCard);
|
||||
shopLayout->setContentsMargins(18, 16, 18, 16);
|
||||
shopLayout->setSpacing(8);
|
||||
// ---- Plugin packages: the drop zone and what was installed from one ----
|
||||
QFrame* packageCard = ui::card();
|
||||
QVBoxLayout* packageLayout = new QVBoxLayout(packageCard);
|
||||
packageLayout->setContentsMargins(18, 16, 18, 16);
|
||||
packageLayout->setSpacing(8);
|
||||
|
||||
QLabel* shopTitle = new QLabel("MAGASIN DE PLUGINS");
|
||||
shopTitle->setObjectName("cardTitle");
|
||||
shopLayout->addWidget(shopTitle);
|
||||
QLabel* packageTitle = new QLabel("PAQUETS DE PLUGIN");
|
||||
packageTitle->setObjectName("cardTitle");
|
||||
packageLayout->addWidget(packageTitle);
|
||||
|
||||
m_shopHint = new QLabel();
|
||||
m_shopHint->setTextFormat(Qt::RichText);
|
||||
m_shopHint->setWordWrap(true);
|
||||
m_shopHint->setStyleSheet("font-size: 12px; color: #94a3b8;");
|
||||
shopLayout->addWidget(m_shopHint);
|
||||
m_packageHint = new QLabel();
|
||||
m_packageHint->setTextFormat(Qt::RichText);
|
||||
m_packageHint->setWordWrap(true);
|
||||
m_packageHint->setStyleSheet("font-size: 12px; color: #94a3b8;");
|
||||
packageLayout->addWidget(m_packageHint);
|
||||
|
||||
m_shopTable = ui::table({"Plugin", "Type", "Version", "Auteur", "État"});
|
||||
connect(m_shopTable, &QTableWidget::currentCellChanged, this,
|
||||
[this](int currentRow, int, int, int) { onShopSelected(currentRow); });
|
||||
shopLayout->addWidget(m_shopTable, 1);
|
||||
m_packageTable = ui::table({"Paquet", "Fichier installé"});
|
||||
connect(m_packageTable, &QTableWidget::currentCellChanged, this,
|
||||
[this](int currentRow, int, int, int) { onPackageSelected(currentRow); });
|
||||
packageLayout->addWidget(m_packageTable, 1);
|
||||
|
||||
QHBoxLayout* shopBar = new QHBoxLayout();
|
||||
shopBar->setSpacing(8);
|
||||
QHBoxLayout* packageBar = new QHBoxLayout();
|
||||
packageBar->setSpacing(8);
|
||||
|
||||
QPushButton* catalogButton = new QPushButton("Charger le catalogue");
|
||||
catalogButton->setProperty("variant", "primary");
|
||||
catalogButton->setIcon(ui::icon("refresh"));
|
||||
catalogButton->setToolTip("Lire la liste des plugins disponibles sur le catalogue");
|
||||
connect(catalogButton, &QPushButton::clicked, core, &AppCore::loadPluginCatalog);
|
||||
shopBar->addWidget(catalogButton);
|
||||
m_browseButton = new QPushButton("Ouvrir un paquet...");
|
||||
m_browseButton->setProperty("variant", "primary");
|
||||
m_browseButton->setIcon(ui::icon("package"));
|
||||
m_browseButton->setToolTip(
|
||||
"Choisir un fichier de paquet de plugin à installer (le glisser-déposer fait "
|
||||
"la même chose)");
|
||||
connect(m_browseButton, &QPushButton::clicked, this, &PluginsPage::browsePackage);
|
||||
packageBar->addWidget(m_browseButton);
|
||||
|
||||
m_shopInstallButton = new QPushButton("Installer");
|
||||
m_shopInstallButton->setProperty("variant", "success");
|
||||
m_shopInstallButton->setIcon(ui::icon("plugin"));
|
||||
m_shopInstallButton->setEnabled(false);
|
||||
m_shopInstallButton->setToolTip(
|
||||
"Télécharger le plugin dans ~/.local/share/PacManager/plugins ; il est "
|
||||
"chargé immédiatement");
|
||||
connect(m_shopInstallButton, &QPushButton::clicked, this, [this, core] {
|
||||
if (!m_shopSelectedId.isEmpty()) core->installShopPlugin(m_shopSelectedId);
|
||||
m_removeButton = new QPushButton("Supprimer le paquet");
|
||||
m_removeButton->setProperty("variant", "danger");
|
||||
m_removeButton->setIcon(ui::icon("trash"));
|
||||
m_removeButton->setEnabled(false);
|
||||
m_removeButton->setToolTip(
|
||||
"Supprimer la bibliothèque installée depuis un paquet (jamais une bibliothèque "
|
||||
"copiée à la main)");
|
||||
connect(m_removeButton, &QPushButton::clicked, this, [this, core] {
|
||||
if (!m_selectedPackageId.isEmpty()) core->removePluginPackage(m_selectedPackageId);
|
||||
});
|
||||
shopBar->addWidget(m_shopInstallButton);
|
||||
packageBar->addWidget(m_removeButton);
|
||||
|
||||
m_shopRemoveButton = new QPushButton("Désinstaller");
|
||||
m_shopRemoveButton->setProperty("variant", "danger");
|
||||
m_shopRemoveButton->setIcon(ui::icon("trash"));
|
||||
m_shopRemoveButton->setEnabled(false);
|
||||
m_shopRemoveButton->setToolTip("Supprimer le plugin installé par le magasin");
|
||||
connect(m_shopRemoveButton, &QPushButton::clicked, this, [this, core] {
|
||||
if (!m_shopSelectedId.isEmpty()) core->removeShopPlugin(m_shopSelectedId);
|
||||
});
|
||||
shopBar->addWidget(m_shopRemoveButton);
|
||||
packageBar->addStretch();
|
||||
packageLayout->addLayout(packageBar);
|
||||
|
||||
QPushButton* sourceButton = new QPushButton("Source du catalogue...");
|
||||
sourceButton->setToolTip("Pointer le magasin vers un autre catalogue");
|
||||
connect(sourceButton, &QPushButton::clicked, this, [this, core] {
|
||||
bool ok = false;
|
||||
const QString url = QInputDialog::getText(
|
||||
this, "Catalogue de plugins", "Adresse du catalogue JSON :",
|
||||
QLineEdit::Normal, core->shop()->catalogUrl(), &ok);
|
||||
if (!ok || url.trimmed().isEmpty()) return;
|
||||
|
||||
core->shop()->setCatalogUrl(url);
|
||||
updateShopHint();
|
||||
emit message(QString("Catalogue : %1").arg(core->shop()->catalogUrl()));
|
||||
});
|
||||
shopBar->addWidget(sourceButton);
|
||||
shopBar->addStretch();
|
||||
shopLayout->addLayout(shopBar);
|
||||
|
||||
layout->addWidget(shopCard, 1);
|
||||
layout->addWidget(packageCard, 1);
|
||||
|
||||
connect(core, &AppCore::pluginsChanged, this, &PluginsPage::refresh);
|
||||
// The core reloads the registry itself after a shop install or removal;
|
||||
// this page only renders the catalogue and reports what happened.
|
||||
connect(core, &AppCore::pluginCatalogChanged, this, [this, core] {
|
||||
refreshShopTable();
|
||||
const PluginShop* shop = core->shop();
|
||||
emit message(shop->catalogLoaded()
|
||||
? QString("Catalogue chargé : %1 plugin(s) disponible(s)")
|
||||
.arg(static_cast<int>(shop->catalog().size()))
|
||||
: shop->lastError());
|
||||
});
|
||||
connect(core, &AppCore::shopInstallFinished, this,
|
||||
// The core reloads the registry itself after a package is installed or
|
||||
// removed; this page only renders the list and reports what happened.
|
||||
connect(core, &AppCore::pluginPackageInstalled, this,
|
||||
[this](const QString& id, bool success, const QString& detail) {
|
||||
refreshShopTable();
|
||||
emit message(success ? QString("Plugin « %1 » installé").arg(id)
|
||||
refreshPackageList();
|
||||
emit message(success
|
||||
? QString("Paquet « %1 » installé (%2)").arg(id, detail)
|
||||
: QString("Échec pour « %1 » : %2").arg(id, detail));
|
||||
});
|
||||
connect(core, &AppCore::pluginPackageRemoved, this,
|
||||
[this](const QString& id, bool success, const QString& detail) {
|
||||
refreshPackageList();
|
||||
emit message(success ? QString("Paquet « %1 » supprimé").arg(id)
|
||||
: QString("Échec pour « %1 » : %2").arg(id, detail));
|
||||
});
|
||||
|
||||
refreshTable();
|
||||
updateShopHint();
|
||||
refreshShopTable();
|
||||
updateDropHint();
|
||||
refreshPackageList();
|
||||
}
|
||||
|
||||
void PluginsPage::browsePackage() {
|
||||
const QString path = QFileDialog::getOpenFileName(
|
||||
this, QStringLiteral("Ouvrir un paquet de plugin"), QString(),
|
||||
QStringLiteral("Paquets de plugin (*%1);;Tous les fichiers (*)")
|
||||
.arg(PluginPackage::suffix()));
|
||||
if (path.isEmpty()) return;
|
||||
core()->installPluginPackage(path);
|
||||
}
|
||||
|
||||
void PluginsPage::refresh() {
|
||||
refreshTable();
|
||||
updateShopHint();
|
||||
refreshShopTable();
|
||||
updateDropHint();
|
||||
refreshPackageList();
|
||||
}
|
||||
|
||||
// Source line of the shop: where the catalogue is read from, and what installing
|
||||
// actually does. Kept next to the table so the two never disagree.
|
||||
void PluginsPage::updateShopHint() {
|
||||
m_shopHint->setText(QString(
|
||||
"Le magasin lit un catalogue JSON et installe les plugins choisis dans "
|
||||
"<code>~/.local/share/PacManager/plugins</code>, sans mot de passe ; ils sont "
|
||||
"chargés immédiatement, sans redémarrer. Catalogue actuel : <code>%1</code>.")
|
||||
.arg(core()->shop()->catalogUrl().toHtmlEscaped()));
|
||||
// What the drop zone does, next to the zone itself so the two cannot disagree.
|
||||
void PluginsPage::updateDropHint() {
|
||||
m_packageHint->setText(QString(
|
||||
"Déposez un fichier <code>%1</code> n'importe où sur la fenêtre : son "
|
||||
"bibliothèque est extraite dans <code>%2</code>, sans mot de passe, et le "
|
||||
"plugin est chargé immédiatement, sans redémarrer. Le paquet contient un "
|
||||
"manifeste <code>plugin.json</code> et la bibliothèque ; il se crée avec "
|
||||
"<code>./make-plugin-package.py</code> (voir doc/plugins.md).")
|
||||
.arg(PluginPackage::suffix().toHtmlEscaped(),
|
||||
core()->packages()->installDirectory().toHtmlEscaped()));
|
||||
}
|
||||
|
||||
void PluginsPage::refreshShopTable() {
|
||||
const PluginShop* shop = core()->shop();
|
||||
const auto& catalog = shop->catalog();
|
||||
void PluginsPage::refreshPackageList() {
|
||||
const PluginPackage* packages = core()->packages();
|
||||
const QStringList ids = packages->installedIds();
|
||||
|
||||
QFont nameFont;
|
||||
nameFont.setWeight(QFont::DemiBold);
|
||||
|
||||
ui::TableFillBatch batch(m_shopTable);
|
||||
m_shopTable->setRowCount(0);
|
||||
m_shopTable->setRowCount(static_cast<int>(catalog.size()));
|
||||
ui::TableFillBatch batch(m_packageTable);
|
||||
m_packageTable->setRowCount(0);
|
||||
m_packageTable->setRowCount(static_cast<int>(ids.size()));
|
||||
|
||||
for (int i = 0; i < static_cast<int>(catalog.size()); ++i) {
|
||||
const PluginShop::CatalogEntry& entry = catalog[i];
|
||||
for (int i = 0; i < static_cast<int>(ids.size()); ++i) {
|
||||
const QString& id = ids[i];
|
||||
const QString path = packages->installedPath(id);
|
||||
|
||||
QTableWidgetItem* nameItem =
|
||||
new QTableWidgetItem(entry.name.isEmpty() ? entry.id : entry.name);
|
||||
nameItem->setFont(nameFont);
|
||||
nameItem->setData(Qt::UserRole, entry.id);
|
||||
if (!entry.description.isEmpty()) nameItem->setToolTip(entry.description);
|
||||
m_shopTable->setItem(i, 0, nameItem);
|
||||
QTableWidgetItem* idItem = new QTableWidgetItem(id);
|
||||
idItem->setFont(nameFont);
|
||||
idItem->setData(Qt::UserRole, id);
|
||||
idItem->setToolTip(id);
|
||||
m_packageTable->setItem(i, 0, idItem);
|
||||
|
||||
// The catalogue's own kind label; the authoritative one is what the
|
||||
// library declares once the registry loads it.
|
||||
const QString kind = entry.kind == QLatin1String("provider") ? QStringLiteral("Fournisseur")
|
||||
: entry.kind == QLatin1String("addon") ? QStringLiteral("Extension")
|
||||
: QStringLiteral("—");
|
||||
QTableWidgetItem* typeItem = new QTableWidgetItem(kind);
|
||||
typeItem->setForeground(QColor("#94a3b8"));
|
||||
m_shopTable->setItem(i, 1, typeItem);
|
||||
|
||||
m_shopTable->setItem(i, 2, new QTableWidgetItem(
|
||||
entry.version.isEmpty() ? QStringLiteral("—") : entry.version));
|
||||
m_shopTable->setItem(i, 3, new QTableWidgetItem(
|
||||
entry.author.isEmpty() ? QStringLiteral("—") : entry.author));
|
||||
|
||||
const bool installed = shop->isInstalled(entry.id);
|
||||
QTableWidgetItem* stateItem =
|
||||
new QTableWidgetItem(installed ? QStringLiteral("Installé") : QStringLiteral("Disponible"));
|
||||
stateItem->setForeground(QColor(installed ? "#34d399" : "#38bdf8"));
|
||||
stateItem->setIcon(ui::icon(installed ? "check" : "package"));
|
||||
m_shopTable->setItem(i, 4, stateItem);
|
||||
QTableWidgetItem* fileItem = new QTableWidgetItem(QFileInfo(path).fileName());
|
||||
fileItem->setForeground(QColor("#94a3b8"));
|
||||
fileItem->setToolTip(path);
|
||||
m_packageTable->setItem(i, 1, fileItem);
|
||||
}
|
||||
batch.release();
|
||||
|
||||
if (!catalog.empty()) m_shopTable->selectRow(0);
|
||||
onShopSelected(m_shopTable->currentRow());
|
||||
}
|
||||
|
||||
void PluginsPage::onShopSelected(int row) {
|
||||
const auto& catalog = core()->shop()->catalog();
|
||||
if (row < 0 || row >= static_cast<int>(catalog.size())) {
|
||||
m_shopSelectedId.clear();
|
||||
m_shopInstallButton->setEnabled(false);
|
||||
m_shopRemoveButton->setEnabled(false);
|
||||
if (ids.isEmpty()) {
|
||||
m_selectedPackageId.clear();
|
||||
m_removeButton->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
m_shopSelectedId = catalog[row].id;
|
||||
// An entry is either to install or installed: only one of the two buttons
|
||||
// ever makes sense for the selected row.
|
||||
const bool installed = core()->shop()->isInstalled(m_shopSelectedId);
|
||||
m_shopInstallButton->setEnabled(!installed);
|
||||
m_shopRemoveButton->setEnabled(installed);
|
||||
// Keep the same package selected across a reload, so installing a second
|
||||
// package does not move the selection away from what the user was looking at.
|
||||
int row = 0;
|
||||
for (int i = 0; i < static_cast<int>(ids.size()); ++i) {
|
||||
if (ids[i] == m_selectedPackageId) {
|
||||
row = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_packageTable->selectRow(row);
|
||||
onPackageSelected(row);
|
||||
}
|
||||
|
||||
void PluginsPage::onPackageSelected(int row) {
|
||||
const QStringList ids = core()->packages()->installedIds();
|
||||
if (row < 0 || row >= static_cast<int>(ids.size())) {
|
||||
m_selectedPackageId.clear();
|
||||
m_removeButton->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
m_selectedPackageId = ids[row];
|
||||
m_removeButton->setEnabled(true);
|
||||
}
|
||||
|
||||
void PluginsPage::refreshTable() {
|
||||
|
||||
+19
-14
@@ -10,14 +10,15 @@ class QLabel;
|
||||
class QPushButton;
|
||||
class QTableWidget;
|
||||
|
||||
// Plugins: what is installed, and the shop it can be installed from.
|
||||
// Plugins: what is installed, and how to add more.
|
||||
//
|
||||
// The upper half lists every plugin known to the application (package-manager
|
||||
// providers and generic addons, built-in and external) and lets the user
|
||||
// enable/disable one, install the tool behind an unavailable provider and
|
||||
// rescan the plugin directories. The lower half is the shop: the catalogue the
|
||||
// core fetches (see PluginShop), with the entries that are not installed here
|
||||
// yet one click away from being downloaded into the per-user plugin directory.
|
||||
// rescan the plugin directories. The lower half is the drop zone: a .fwspacm
|
||||
// package dropped anywhere on the window is installed there (the window owns
|
||||
// the drop, see MainWindow::dropEvent), and what was installed from a package
|
||||
// can be removed again.
|
||||
class PluginsPage : public Page {
|
||||
Q_OBJECT
|
||||
public:
|
||||
@@ -33,11 +34,15 @@ public:
|
||||
private:
|
||||
void refreshTable();
|
||||
void onSelected(int row);
|
||||
// Shop half: the catalogue table, the source line above it and the
|
||||
// Installer/Désinstaller state of the selected entry.
|
||||
void refreshShopTable();
|
||||
void onShopSelected(int row);
|
||||
void updateShopHint();
|
||||
// Package half: the drop zone, and the list of what was installed from a
|
||||
// .fwspacm package with the button removing the selected one.
|
||||
void refreshPackageList();
|
||||
void onPackageSelected(int row);
|
||||
void updateDropHint();
|
||||
|
||||
// Opens a file dialog on the package format and installs what was picked,
|
||||
// for users who would rather click than drag the file onto the window.
|
||||
void browsePackage();
|
||||
|
||||
QTableWidget* m_table = nullptr;
|
||||
QLabel* m_description = nullptr;
|
||||
@@ -45,9 +50,9 @@ private:
|
||||
QPushButton* m_installButton = nullptr;
|
||||
std::string m_selectedId;
|
||||
|
||||
QLabel* m_shopHint = nullptr;
|
||||
QTableWidget* m_shopTable = nullptr;
|
||||
QPushButton* m_shopInstallButton = nullptr;
|
||||
QPushButton* m_shopRemoveButton = nullptr;
|
||||
QString m_shopSelectedId;
|
||||
QTableWidget* m_packageTable = nullptr;
|
||||
QLabel* m_packageHint = nullptr;
|
||||
QPushButton* m_browseButton = nullptr;
|
||||
QPushButton* m_removeButton = nullptr;
|
||||
QString m_selectedPackageId;
|
||||
};
|
||||
Reference in new issue
Block a user