The window accepts a drop and the desktop entry's %U hands over the file the user picked, so both gestures end up as the same request. The frame asks the core which files it can install and never names a format itself; dropped files queue up because the core runs one operation at a time, and the search and log fields stop swallowing drops so a file dropped on them reaches the window. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
580 lines
22 KiB
C++
580 lines
22 KiB
C++
#include "browse-page.h"
|
|
|
|
#include <QColor>
|
|
#include <QDir>
|
|
#include <QFile>
|
|
#include <QFileDialog>
|
|
#include <QFrame>
|
|
#include <QHBoxLayout>
|
|
#include <QHeaderView>
|
|
#include <QLabel>
|
|
#include <QLineEdit>
|
|
#include <QMessageBox>
|
|
#include <QProgressBar>
|
|
#include <QPushButton>
|
|
#include <QSplitter>
|
|
#include <QStackedWidget>
|
|
#include <QTableWidget>
|
|
#include <QTextStream>
|
|
#include <QVBoxLayout>
|
|
|
|
#include "ui-kit.h"
|
|
|
|
BrowsePage::BrowsePage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
|
layout->setContentsMargins(24, 20, 24, 20);
|
|
layout->setSpacing(12);
|
|
|
|
// Search row (search mode only)
|
|
m_searchRow = new QWidget();
|
|
QHBoxLayout* searchRow = new QHBoxLayout(m_searchRow);
|
|
searchRow->setContentsMargins(0, 0, 0, 0);
|
|
searchRow->setSpacing(10);
|
|
|
|
m_searchBar = new QLineEdit();
|
|
// Drops belong to the window: a .flatpakref let go over the search field
|
|
// must install, not paste its path (see MainWindow::dragEnterEvent).
|
|
m_searchBar->setAcceptDrops(false);
|
|
m_searchBar->setPlaceholderText("Rechercher un paquet (ex : firefox)...");
|
|
m_searchBar->setMinimumHeight(40);
|
|
m_searchBar->addAction(ui::icon("search"), QLineEdit::LeadingPosition);
|
|
connect(m_searchBar, &QLineEdit::returnPressed, this, &BrowsePage::onSearch);
|
|
searchRow->addWidget(m_searchBar, 1);
|
|
|
|
m_searchButton = new QPushButton("Rechercher");
|
|
m_searchButton->setProperty("variant", "primary");
|
|
m_searchButton->setMinimumHeight(40);
|
|
m_searchButton->setMinimumWidth(130);
|
|
connect(m_searchButton, &QPushButton::clicked, this, &BrowsePage::onSearch);
|
|
searchRow->addWidget(m_searchButton);
|
|
|
|
layout->addWidget(m_searchRow);
|
|
|
|
// Filter row (installed mode only)
|
|
m_filterRow = new QWidget();
|
|
QHBoxLayout* filterRow = new QHBoxLayout(m_filterRow);
|
|
filterRow->setContentsMargins(0, 0, 0, 0);
|
|
filterRow->setSpacing(10);
|
|
|
|
m_filterBar = new QLineEdit();
|
|
m_filterBar->setAcceptDrops(false); // drops go to the window (see above)
|
|
m_filterBar->setPlaceholderText("Filtrer par nom...");
|
|
m_filterBar->setMinimumHeight(36);
|
|
m_filterBar->addAction(ui::icon("filter"), QLineEdit::LeadingPosition);
|
|
m_filterBar->setClearButtonEnabled(true);
|
|
connect(m_filterBar, &QLineEdit::textChanged, this, &BrowsePage::onFilterChanged);
|
|
filterRow->addWidget(m_filterBar, 1);
|
|
|
|
QLabel* filterHint = new QLabel("Filtre local, instantané");
|
|
filterHint->setStyleSheet("font-size: 12px; color: #64748b;");
|
|
filterRow->addWidget(filterHint);
|
|
|
|
m_filterRow->setVisible(false);
|
|
layout->addWidget(m_filterRow);
|
|
|
|
// Thin progress bar, shown while the core works on a listing.
|
|
m_progressBar = new QProgressBar();
|
|
m_progressBar->setVisible(false);
|
|
m_progressBar->setFixedHeight(6);
|
|
m_progressBar->setTextVisible(false);
|
|
layout->addWidget(m_progressBar);
|
|
|
|
// Action toolbar
|
|
QHBoxLayout* actionBar = new QHBoxLayout();
|
|
actionBar->setSpacing(8);
|
|
|
|
m_installButton = new QPushButton("Installer");
|
|
m_installButton->setProperty("variant", "success");
|
|
m_installButton->setIcon(ui::icon("package"));
|
|
m_installButton->setEnabled(false);
|
|
connect(m_installButton, &QPushButton::clicked, this, [this, core] {
|
|
if (m_selected.name.empty()) return;
|
|
m_pendingSelect = QString::fromStdString(m_selected.name);
|
|
start(core->install(m_selected), tr("Installation"));
|
|
});
|
|
actionBar->addWidget(m_installButton);
|
|
|
|
m_removeButton = new QPushButton("Supprimer");
|
|
m_removeButton->setProperty("variant", "danger");
|
|
m_removeButton->setIcon(ui::icon("trash"));
|
|
m_removeButton->setEnabled(false);
|
|
connect(m_removeButton, &QPushButton::clicked, this, [this, core] {
|
|
if (m_selected.name.empty()) return;
|
|
m_pendingSelect = QString::fromStdString(m_selected.name);
|
|
start(core->remove(m_selected), tr("Suppression"));
|
|
});
|
|
actionBar->addWidget(m_removeButton);
|
|
|
|
m_updateButton = new QPushButton("Mettre à jour");
|
|
m_updateButton->setProperty("variant", "warning");
|
|
m_updateButton->setIcon(ui::icon("refresh"));
|
|
m_updateButton->setEnabled(false);
|
|
connect(m_updateButton, &QPushButton::clicked, this, [this, core] {
|
|
if (m_selected.name.empty()) return;
|
|
m_pendingSelect = QString::fromStdString(m_selected.name);
|
|
start(core->update(m_selected), tr("Mise à jour"));
|
|
});
|
|
actionBar->addWidget(m_updateButton);
|
|
|
|
m_updateAllButton = new QPushButton("Tout mettre à jour");
|
|
m_updateAllButton->setProperty("variant", "info");
|
|
m_updateAllButton->setIcon(ui::icon("arrow-up"));
|
|
m_updateAllButton->setEnabled(false);
|
|
connect(m_updateAllButton, &QPushButton::clicked, this, [this, core] {
|
|
start(core->updateAll(), tr("Mise à jour globale"));
|
|
});
|
|
actionBar->addWidget(m_updateAllButton);
|
|
|
|
QPushButton* exportButton = new QPushButton("Exporter");
|
|
exportButton->setToolTip("Exporter la liste affichée en CSV");
|
|
connect(exportButton, &QPushButton::clicked, this, &BrowsePage::exportCsv);
|
|
actionBar->addWidget(exportButton);
|
|
|
|
actionBar->addStretch();
|
|
|
|
m_resultCount = ui::countLabel();
|
|
actionBar->addWidget(m_resultCount);
|
|
|
|
layout->addLayout(actionBar);
|
|
|
|
// Splitter: package table | details
|
|
QSplitter* splitter = new QSplitter(Qt::Horizontal);
|
|
splitter->setHandleWidth(10);
|
|
|
|
QFrame* listCard = ui::card();
|
|
QVBoxLayout* listLayout = new QVBoxLayout(listCard);
|
|
listLayout->setContentsMargins(8, 8, 8, 8);
|
|
listLayout->setSpacing(6);
|
|
|
|
QLabel* listHeader = new QLabel("PAQUETS");
|
|
listHeader->setObjectName("cardTitle");
|
|
listLayout->addWidget(listHeader);
|
|
|
|
m_table = ui::table({"Nom", "Version", "Dépôt", "Fournisseur", "Statut"});
|
|
connect(m_table, &QTableWidget::currentCellChanged, this,
|
|
[this](int currentRow, int, int, int) { onPackageSelected(currentRow); });
|
|
|
|
m_tableStack = ui::withEmptyState(
|
|
m_table,
|
|
"Aucun paquet à afficher.\nLancez une recherche ou ouvrez la liste des "
|
|
"paquets installés.");
|
|
// The "Tout mettre à jour" button only makes sense on the updates tab, but
|
|
// there it must be usable without selecting a row first; the per-package
|
|
// buttons stay gated on the selection.
|
|
m_updateAllButton->setToolTip("Mettre à jour tous les paquets listés");
|
|
listLayout->addWidget(m_tableStack);
|
|
splitter->addWidget(listCard);
|
|
|
|
QFrame* detailsCard = ui::card();
|
|
QVBoxLayout* detailsLayout = new QVBoxLayout(detailsCard);
|
|
detailsLayout->setContentsMargins(20, 18, 20, 18);
|
|
detailsLayout->setSpacing(10);
|
|
|
|
m_pkgName = new QLabel("Sélectionnez un paquet");
|
|
m_pkgName->setWordWrap(true);
|
|
// Serif like the site's package headings.
|
|
m_pkgName->setStyleSheet(
|
|
"font-family: serif; font-size: 22px; font-weight: 700; color: #e2e8f0;"
|
|
"background: transparent;");
|
|
detailsLayout->addWidget(m_pkgName);
|
|
|
|
m_pkgVersion = new QLabel("");
|
|
m_pkgVersion->setStyleSheet(
|
|
"font-size: 13px; color: #94a3b8; background: transparent;");
|
|
detailsLayout->addWidget(m_pkgVersion);
|
|
|
|
QHBoxLayout* metaRow = new QHBoxLayout();
|
|
metaRow->setSpacing(8);
|
|
|
|
auto makeMetaBadge = [](QLabel** out) {
|
|
QLabel* label = new QLabel("—");
|
|
label->setStyleSheet(
|
|
"background: #273449; color: #94a3b8; border: 1px solid #303b4e;"
|
|
"border-radius: 999px; padding: 3px 12px; font-size: 12px;");
|
|
*out = label;
|
|
return label;
|
|
};
|
|
metaRow->addWidget(makeMetaBadge(&m_pkgRepo));
|
|
metaRow->addWidget(makeMetaBadge(&m_pkgSize));
|
|
metaRow->addWidget(makeMetaBadge(&m_pkgProvider));
|
|
metaRow->addStretch();
|
|
detailsLayout->addLayout(metaRow);
|
|
|
|
QFrame* separator = new QFrame();
|
|
separator->setFrameShape(QFrame::HLine);
|
|
separator->setStyleSheet(
|
|
"color: #303b4e; background: #303b4e; max-height: 1px; border: none;");
|
|
detailsLayout->addWidget(separator);
|
|
|
|
m_pkgDescription = new QLabel("");
|
|
m_pkgDescription->setWordWrap(true);
|
|
m_pkgDescription->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
|
m_pkgDescription->setStyleSheet(
|
|
"font-size: 14px; color: #94a3b8; background: transparent;");
|
|
detailsLayout->addWidget(m_pkgDescription, 1);
|
|
|
|
detailsLayout->addStretch();
|
|
splitter->addWidget(detailsCard);
|
|
|
|
splitter->setSizes({560, 420});
|
|
layout->addWidget(splitter, 1);
|
|
|
|
// ---- Core wiring ----
|
|
connect(core, &AppCore::searchChunk, this,
|
|
[this](std::vector<PackageInfo> results) { appendRows(results); });
|
|
connect(core, &AppCore::searchFinished, this,
|
|
[this](std::vector<PackageInfo> results) { populateTable(results); });
|
|
connect(core, &AppCore::listFinished, this,
|
|
[this](AppCore::ListMode mode, std::vector<PackageInfo> results) {
|
|
if (mode == AppCore::ListMode::Installed) {
|
|
m_installed = results;
|
|
if (m_mode == Mode::Installed) onFilterChanged(m_filterBar->text());
|
|
} else if (mode == AppCore::ListMode::Updates) {
|
|
// The "searching" hint is replaced by the outcome: an empty
|
|
// result means the system is up to date, not that the check
|
|
// is still running.
|
|
if (results.empty()) {
|
|
ui::setEmptyStateText(
|
|
m_tableStack,
|
|
"Aucune mise à jour disponible.\nVotre système est à "
|
|
"jour.");
|
|
}
|
|
if (m_mode == Mode::Updates) populateTable(results);
|
|
}
|
|
});
|
|
connect(core, &AppCore::busyChanged, this, [this](bool busy) {
|
|
// A listing started from elsewhere (dashboard) while the user was
|
|
// already on the updates tab would leave it without data: reload now
|
|
// that the core is free again.
|
|
if (!busy && m_mode == Mode::Updates && isVisible()) reloadCurrentView();
|
|
});
|
|
connect(core, &AppCore::busyChanged, this, [this](bool busy) {
|
|
m_progressBar->setVisible(busy);
|
|
if (!busy) {
|
|
// A band stopped just before the end reads as a cancellation: when
|
|
// real progress was shown, it is completed first.
|
|
if (m_progressBar->maximum() > 0) m_progressBar->setValue(100);
|
|
return;
|
|
}
|
|
m_progressValue = 0;
|
|
// Start indeterminate; the first real percentage reported by the tool
|
|
// turns the band into a determinate fill.
|
|
m_progressBar->setRange(0, 0);
|
|
m_progressBar->setValue(0);
|
|
});
|
|
connect(core, &AppCore::actionProgress, this,
|
|
[this](const QString&, int percent) {
|
|
if (percent < 0) return;
|
|
// Providers (and the commands inside one operation) each count
|
|
// from 0 again, so the band only ever moves forward.
|
|
if (percent > m_progressValue) m_progressValue = percent;
|
|
m_progressBar->setRange(0, 100);
|
|
m_progressBar->setValue(m_progressValue);
|
|
});
|
|
connect(core, &AppCore::actionFinished, this,
|
|
[this](const QString& action, const QString&, bool success, const QString&,
|
|
bool) {
|
|
// The installed state changed: show the fresh state of what the
|
|
// user is looking at, but only when they are looking at it.
|
|
if (!success || !isVisible()) return;
|
|
if (action == QLatin1String("install") || action == QLatin1String("remove")
|
|
|| action == QLatin1String("update")
|
|
|| action == QLatin1String("update-all")
|
|
|| action == QLatin1String("refresh")) {
|
|
reloadCurrentView();
|
|
}
|
|
});
|
|
}
|
|
|
|
QString BrowsePage::navTitle() const {
|
|
if (m_mode == Mode::Installed) return QStringLiteral("Paquets installés");
|
|
if (m_mode == Mode::Updates) return QStringLiteral("Mises à jour disponibles");
|
|
return QStringLiteral("Recherche");
|
|
}
|
|
|
|
QString BrowsePage::navSubtitle() const {
|
|
if (m_mode == Mode::Installed) return QStringLiteral("Parcourez les paquets de votre système");
|
|
if (m_mode == Mode::Updates) return QStringLiteral("Maintenez votre système à jour");
|
|
return QStringLiteral("Trouvez et installez des paquets");
|
|
}
|
|
|
|
void BrowsePage::refresh() {
|
|
reloadCurrentView();
|
|
}
|
|
|
|
void BrowsePage::showSearch() {
|
|
setMode(Mode::Search);
|
|
m_searchBar->setFocus();
|
|
}
|
|
|
|
void BrowsePage::focusSearch() {
|
|
setMode(Mode::Search);
|
|
m_searchBar->setFocus();
|
|
m_searchBar->selectAll();
|
|
}
|
|
|
|
void BrowsePage::showInstalled(const QString& select) {
|
|
setMode(Mode::Installed);
|
|
if (!select.isEmpty()) m_pendingSelect = select;
|
|
start(core()->loadInstalled(), tr("Paquets installés"));
|
|
}
|
|
|
|
void BrowsePage::showUpdates() {
|
|
setMode(Mode::Updates);
|
|
// The update check is what the user came for: run it on every arrival on
|
|
// the tab (pacman caches its queries for a few seconds, so a click right
|
|
// after the dashboard loaded reuses that answer instead of respawning it).
|
|
// The "searching" hint replaces the empty-state text for the duration, so
|
|
// the tab never looks stuck on an empty table.
|
|
ui::setEmptyStateText(m_tableStack,
|
|
"Recherche des mises à jour en cours...\nLes résultats "
|
|
"s'afficheront automatiquement.");
|
|
if (core()->busy()) {
|
|
// Something else is loading (e.g. the dashboard asked for the counts):
|
|
// the busyChanged handler below reloads when the core frees up.
|
|
return;
|
|
}
|
|
start(core()->loadUpdates(), tr("Mises à jour"));
|
|
}
|
|
|
|
void BrowsePage::setMode(Mode mode) {
|
|
m_mode = mode;
|
|
m_searchRow->setVisible(mode == Mode::Search);
|
|
m_filterRow->setVisible(mode == Mode::Installed);
|
|
m_installButton->setVisible(mode == Mode::Search);
|
|
|
|
// "Tout mettre à jour" acts on the whole list, so it is only offered on the
|
|
// tab that displays pending updates; there it needs no row selection.
|
|
if (m_updateAllButton) {
|
|
m_updateAllButton->setVisible(mode == Mode::Updates);
|
|
m_updateAllButton->setEnabled(mode == Mode::Updates
|
|
&& core()->hasAvailableProvider());
|
|
}
|
|
|
|
// The updates tab rewrote the empty-state hint for its own states; restore
|
|
// the generic one so the other tabs never show a stale updates message.
|
|
if (mode != Mode::Updates) {
|
|
ui::setEmptyStateText(
|
|
m_tableStack,
|
|
"Aucun paquet à afficher.\nLancez une recherche ou ouvrez la liste des "
|
|
"paquets installés.");
|
|
}
|
|
|
|
// Clear any stale selection and reset the details panel
|
|
m_table->clearSelection();
|
|
resetDetails();
|
|
}
|
|
|
|
void BrowsePage::reloadCurrentView() {
|
|
if (m_mode == Mode::Installed) {
|
|
start(core()->loadInstalled(), tr("Paquets installés"));
|
|
} else if (m_mode == Mode::Updates) {
|
|
start(core()->loadUpdates(), tr("Mises à jour"));
|
|
} else if (!m_searchBar->text().trimmed().isEmpty()) {
|
|
onSearch();
|
|
}
|
|
}
|
|
|
|
void BrowsePage::onSearch() {
|
|
if (m_searchBar->text().trimmed().isEmpty()) {
|
|
// Refocus the field instead of interrupting with a dialog.
|
|
m_searchBar->setFocus();
|
|
emit message(tr("Entrez un terme de recherche."));
|
|
return;
|
|
}
|
|
|
|
m_table->setRowCount(0);
|
|
m_results.clear();
|
|
start(core()->search(m_searchBar->text()), tr("Recherche"));
|
|
}
|
|
|
|
void BrowsePage::onFilterChanged(const QString& text) {
|
|
if (m_mode != Mode::Installed) return;
|
|
|
|
std::vector<PackageInfo> filtered;
|
|
if (text.isEmpty()) {
|
|
filtered = m_installed;
|
|
} else {
|
|
const QString needle = text.toLower();
|
|
for (const auto& pkg : m_installed) {
|
|
if (QString::fromStdString(pkg.name).toLower().contains(needle)) {
|
|
filtered.push_back(pkg);
|
|
}
|
|
}
|
|
}
|
|
populateTable(filtered);
|
|
}
|
|
|
|
void BrowsePage::populateTable(const std::vector<PackageInfo>& packages) {
|
|
m_results = packages;
|
|
ui::showEmptyState(m_tableStack, packages.empty());
|
|
{
|
|
ui::TableFillBatch batch(m_table);
|
|
m_table->setRowCount(0);
|
|
m_table->setRowCount(static_cast<int>(packages.size()));
|
|
for (int i = 0; i < static_cast<int>(packages.size()); ++i) {
|
|
addRow(i, packages[i]);
|
|
}
|
|
}
|
|
|
|
m_resultCount->setText(QString("%1 paquet(s)").arg(packages.size()));
|
|
|
|
if (packages.empty()) {
|
|
resetDetails();
|
|
return;
|
|
}
|
|
|
|
// If we came here for a specific package (dashboard history, or the one an
|
|
// operation just touched), select it.
|
|
if (!m_pendingSelect.isEmpty()) {
|
|
const QString target = m_pendingSelect;
|
|
m_pendingSelect.clear();
|
|
for (int i = 0; i < static_cast<int>(m_results.size()); ++i) {
|
|
if (QString::fromStdString(m_results[i].name) == target) {
|
|
m_table->selectRow(i);
|
|
onPackageSelected(i); // update the details panel immediately
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
m_table->selectRow(0);
|
|
}
|
|
|
|
// Appends an incoming search chunk to the rows already displayed, so the first
|
|
// matches appear while the remaining providers are still searching.
|
|
void BrowsePage::appendRows(const std::vector<PackageInfo>& packages) {
|
|
const int startRow = static_cast<int>(m_results.size());
|
|
m_results.insert(m_results.end(), packages.begin(), packages.end());
|
|
|
|
ui::TableFillBatch batch(m_table);
|
|
m_table->setRowCount(static_cast<int>(m_results.size()));
|
|
for (int i = 0; i < static_cast<int>(packages.size()); ++i) {
|
|
addRow(startRow + i, packages[i]);
|
|
}
|
|
ui::showEmptyState(m_tableStack, m_results.empty());
|
|
m_resultCount->setText(QString("%1 paquet(s)").arg(m_results.size()));
|
|
}
|
|
|
|
void BrowsePage::addRow(int row, const PackageInfo& pkg) {
|
|
QFont nameFont;
|
|
nameFont.setWeight(QFont::DemiBold);
|
|
|
|
QTableWidgetItem* nameItem = new QTableWidgetItem(QString::fromStdString(pkg.name));
|
|
nameItem->setFont(nameFont);
|
|
m_table->setItem(row, 0, nameItem);
|
|
|
|
m_table->setItem(row, 1, new QTableWidgetItem(QString::fromStdString(pkg.version)));
|
|
m_table->setItem(row, 2,
|
|
new QTableWidgetItem(pkg.repository.empty()
|
|
? QStringLiteral("—")
|
|
: QString::fromStdString(pkg.repository)));
|
|
|
|
QTableWidgetItem* providerItem =
|
|
new QTableWidgetItem(ui::providersLabel(core()->plugins(), pkg));
|
|
providerItem->setForeground(QColor("#94a3b8"));
|
|
m_table->setItem(row, 3, providerItem);
|
|
|
|
QTableWidgetItem* statusItem = new QTableWidgetItem(ui::packageStatusText(pkg));
|
|
if (pkg.installed && pkg.updateAvailable) {
|
|
statusItem->setForeground(QColor("#fbbf24"));
|
|
statusItem->setIcon(ui::icon("arrow-up"));
|
|
} else if (pkg.installed) {
|
|
statusItem->setForeground(QColor("#34d399"));
|
|
statusItem->setIcon(ui::icon("check"));
|
|
} else {
|
|
statusItem->setIcon(ui::icon("package"));
|
|
}
|
|
m_table->setItem(row, 4, statusItem);
|
|
}
|
|
|
|
void BrowsePage::onPackageSelected(int row) {
|
|
if (row < 0 || row >= static_cast<int>(m_results.size())) {
|
|
resetDetails();
|
|
return;
|
|
}
|
|
|
|
m_selected = m_results[row];
|
|
updateDetails(m_selected);
|
|
|
|
IPackageManager* provider =
|
|
core()->providerFor(QString::fromStdString(m_selected.provider));
|
|
m_installButton->setEnabled(provider && provider->canInstall()
|
|
&& !m_selected.installed);
|
|
m_removeButton->setEnabled(provider && provider->canRemove() && m_selected.installed);
|
|
m_updateButton->setEnabled(provider && provider->canUpdate()
|
|
&& m_selected.updateAvailable);
|
|
}
|
|
|
|
void BrowsePage::updateDetails(const PackageInfo& pkg) {
|
|
m_pkgName->setText(QString::fromStdString(pkg.name));
|
|
|
|
QString versionText = QString("Version : %1").arg(QString::fromStdString(pkg.version));
|
|
if (pkg.updateAvailable) versionText += " (mise à jour disponible)";
|
|
m_pkgVersion->setText(versionText);
|
|
|
|
m_pkgRepo->setText(pkg.repository.empty()
|
|
? "Dépôt : —"
|
|
: QString("Dépôt : %1").arg(QString::fromStdString(pkg.repository)));
|
|
m_pkgSize->setText(pkg.size.empty()
|
|
? "Taille : —"
|
|
: QString("Taille : %1").arg(QString::fromStdString(pkg.size)));
|
|
m_pkgProvider->setText(
|
|
QString("Fournisseur : %1").arg(ui::providersLabel(core()->plugins(), pkg)));
|
|
|
|
// Rich details (dependencies, required-by, install date, update size): the
|
|
// core queries pacman on demand and caches the answer, so selecting a row
|
|
// stays instant even when pacman is slow.
|
|
QString details = QString::fromStdString(pkg.description);
|
|
const QString rich = core()->packageDetails(pkg);
|
|
if (!rich.isEmpty()) {
|
|
if (!details.isEmpty()) details += "\n\n";
|
|
details += rich;
|
|
}
|
|
m_pkgDescription->setText(details);
|
|
}
|
|
|
|
void BrowsePage::resetDetails() {
|
|
m_selected = PackageInfo{};
|
|
m_pkgName->setText("Sélectionnez un paquet");
|
|
m_pkgVersion->setText("");
|
|
m_pkgRepo->setText("—");
|
|
m_pkgSize->setText("—");
|
|
m_pkgProvider->setText("—");
|
|
m_pkgDescription->setText("");
|
|
m_installButton->setEnabled(false);
|
|
m_removeButton->setEnabled(false);
|
|
m_updateButton->setEnabled(false);
|
|
}
|
|
|
|
void BrowsePage::exportCsv() {
|
|
if (m_results.empty()) {
|
|
emit message(tr("Aucune liste à exporter."));
|
|
return;
|
|
}
|
|
|
|
const QString path = QFileDialog::getSaveFileName(
|
|
this, "Exporter la liste des paquets",
|
|
QDir::homePath() + "/pacmanager-paquets.csv", "CSV (*.csv)");
|
|
if (path.isEmpty()) return;
|
|
|
|
QFile file(path);
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
QMessageBox::warning(this, "Export",
|
|
QString("Impossible d'écrire dans %1").arg(path));
|
|
return;
|
|
}
|
|
QTextStream out(&file);
|
|
out << "Nom;Version;Depot;Fournisseur;Statut\n";
|
|
for (const auto& pkg : m_results) {
|
|
out << ui::csvField(QString::fromStdString(pkg.name)) << ';'
|
|
<< ui::csvField(QString::fromStdString(pkg.version)) << ';'
|
|
<< ui::csvField(QString::fromStdString(pkg.repository)) << ';'
|
|
<< ui::csvField(ui::providersLabel(core()->plugins(), pkg)) << ';'
|
|
<< ui::csvField(ui::packageStatusText(pkg)) << '\n';
|
|
}
|
|
emit message(QString("%1 paquet(s) exporté(s) vers %2")
|
|
.arg(m_results.size())
|
|
.arg(path));
|
|
}
|