feat(ui): stream search results and show real download progress

Search now publishes provider results in small batches as they arrive, so
the first matches appear in the table while slower providers keep running.

The bottom status-bar bar is now a determinate indicator: pacman output is
streamed live and its (n/Total) package counter is parsed into a percentage
that fills the bar during install/update, instead of an indeterminate spinner.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
BlackAngelTV committed 2026-08-29 20:17:45 +02:00
1 parent 26ca0e4d88
commit cd5bed0f4d
8 files changed
+246 -112

No files matched your search

+122 -49
View File
@@ -35,11 +35,26 @@ void SearchWorker::run() {
std::vector<PackageInfo> results;
for (IPackageManager* pm : m_providers) {
if (!pm->canSearch()) continue;
// Publish the freshly found packages right away, grouped in small
// batches so the table starts filling while the next provider is still
// running its (potentially slow) search in the background.
std::vector<PackageInfo> providerResults;
for (auto& pkg : pm->search(m_query)) {
pkg.provider = pm->getName();
results.push_back(pkg);
providerResults.push_back(pkg);
}
constexpr int kBatchSize = 10;
for (size_t i = 0; i < providerResults.size(); i += kBatchSize) {
std::vector<PackageInfo> batch(
providerResults.begin() + i,
providerResults.begin() + std::min(i + kBatchSize, providerResults.size()));
emit chunk(std::move(batch));
}
results.insert(results.end(), providerResults.begin(), providerResults.end());
}
// One row per package name, whatever the number of providers offering it.
mergeProviderDuplicates(results);
@@ -86,7 +101,8 @@ void InstallWorker::run() {
bool success = true;
for (IPackageManager* pm : m_providers) {
// Prefix progress lines with the provider when several run at once.
auto cb = [this, pm](const std::string& msg) {
// A real percentage (>= 0) also drives the determinate status bar bar.
auto cb = [this, pm](const std::string& msg, int percent) {
if (m_providers.size() > 1) {
emit progress(QString("[%1] %2")
.arg(QString::fromStdString(pm->getName()),
@@ -94,6 +110,7 @@ void InstallWorker::run() {
} else {
emit progress(QString::fromStdString(msg));
}
if (percent >= 0) emit progressValue(percent);
};
// Keep running the remaining providers even if one fails.
@@ -241,6 +258,17 @@ void MainWindow::setupUI() {
statusBar()->showMessage("Prêt");
// Tiny indeterminate bar anchored at the bottom of the window: it appears
// while install/update/remove/search operations run, without taking space
// on the content pages.
m_installProgressBar = new QProgressBar();
m_installProgressBar->setRange(0, 0);
m_installProgressBar->setTextVisible(false);
m_installProgressBar->setFixedHeight(4);
m_installProgressBar->setFixedWidth(120);
m_installProgressBar->setVisible(false);
statusBar()->addPermanentWidget(m_installProgressBar);
setStyleSheet(
// ---- Base ----
"QMainWindow, QWidget { background: #0d1017; color: #dbe2f0; }"
@@ -1263,11 +1291,18 @@ void MainWindow::onSearch() {
m_packageTable->setRowCount(0);
SearchWorker* worker = new SearchWorker(providers, query);
connect(worker, &SearchWorker::chunk, this, &MainWindow::onSearchChunk);
connect(worker, &SearchWorker::finished, this, &MainWindow::onSearchFinished);
connect(worker, &SearchWorker::finished, this, [worker] { worker->wait(); worker->deleteLater(); });
worker->start();
}
// Called as results stream in: append the incoming row instead of rebuilding
// the whole table, so the first matches appear while the search continues.
void MainWindow::onSearchChunk(std::vector<PackageInfo> results) {
appendPackageRows(results);
}
void MainWindow::loadInstalled() {
setBusy(true);
statusBar()->showMessage("Chargement des paquets installés...");
@@ -1294,6 +1329,8 @@ void MainWindow::loadUpdates() {
void MainWindow::onSearchFinished(std::vector<PackageInfo> results) {
setBusy(false);
// The table is already filled incrementally via onSearchChunk; rebuild it
// once at the end to guarantee a consistent final list.
populatePackageTable(results);
statusBar()->showMessage(QString("%1 paquet(s) trouvé(s)").arg(results.size()));
}
@@ -1349,53 +1386,8 @@ void MainWindow::populatePackageTable(const std::vector<PackageInfo>& results) {
m_packageTable->setRowCount(0);
m_packageTable->setRowCount(static_cast<int>(results.size()));
QFont nameFont;
nameFont.setWeight(QFont::DemiBold);
for (int i = 0; i < static_cast<int>(results.size()); ++i) {
const PackageInfo& pkg = results[i];
QTableWidgetItem* nameItem = new QTableWidgetItem(QString::fromStdString(pkg.name));
nameItem->setFont(nameFont);
m_packageTable->setItem(i, 0, nameItem);
m_packageTable->setItem(i, 1,
new QTableWidgetItem(QString::fromStdString(pkg.version)));
m_packageTable->setItem(i, 2, new QTableWidgetItem(
pkg.repository.empty() ? "—" : QString::fromStdString(pkg.repository)));
QTableWidgetItem* providerItem = new QTableWidgetItem(
providersLabel(m_pluginManager, pkg));
providerItem->setForeground(QColor("#98a0b3"));
providerItem->setIcon(loadIcon("package"));
m_packageTable->setItem(i, 3, providerItem);
QString statusText;
QString statusIcon;
QColor statusColor;
if (pkg.installed && pkg.updateAvailable) {
statusText = "MAJ dispo";
statusIcon = "arrow-up";
statusColor = QColor("#e0af68");
} else if (pkg.installed) {
statusText = "Installé";
statusIcon = "check";
statusColor = QColor("#3fb950");
} else if (!pkg.repository.empty()) {
statusText = "Disponible";
statusIcon = "package";
statusColor = QColor("#98a0b3");
} else {
statusText = "—";
statusIcon.clear();
statusColor = QColor("#565f73");
}
QTableWidgetItem* statusItem = new QTableWidgetItem(statusText);
statusItem->setForeground(statusColor);
if (!statusIcon.isEmpty()) statusItem->setIcon(loadIcon(statusIcon));
m_packageTable->setItem(i, 4, statusItem);
addPackageRow(i, results[i]);
}
m_resultCount->setText(QString("%1 paquet(s)").arg(results.size()));
@@ -1421,6 +1413,66 @@ void MainWindow::populatePackageTable(const std::vector<PackageInfo>& results) {
m_packageTable->selectRow(0);
}
// Appends an incoming search chunk to the already-displayed rows, updating the
// stored result set so selection and the details panel stay consistent.
void MainWindow::appendPackageRows(const std::vector<PackageInfo>& results) {
const int startRow = static_cast<int>(m_currentResults.size());
m_currentResults.insert(m_currentResults.end(), results.begin(), results.end());
m_packageTable->setRowCount(static_cast<int>(m_currentResults.size()));
for (size_t i = 0; i < results.size(); ++i) {
addPackageRow(startRow + static_cast<int>(i), results[i]);
}
m_resultCount->setText(QString("%1 paquet(s)").arg(m_currentResults.size()));
}
void MainWindow::addPackageRow(int i, const PackageInfo& pkg) {
QFont nameFont;
nameFont.setWeight(QFont::DemiBold);
QTableWidgetItem* nameItem = new QTableWidgetItem(QString::fromStdString(pkg.name));
nameItem->setFont(nameFont);
m_packageTable->setItem(i, 0, nameItem);
m_packageTable->setItem(i, 1,
new QTableWidgetItem(QString::fromStdString(pkg.version)));
m_packageTable->setItem(i, 2, new QTableWidgetItem(
pkg.repository.empty() ? "—" : QString::fromStdString(pkg.repository)));
QTableWidgetItem* providerItem = new QTableWidgetItem(
providersLabel(m_pluginManager, pkg));
providerItem->setForeground(QColor("#98a0b3"));
providerItem->setIcon(loadIcon("package"));
m_packageTable->setItem(i, 3, providerItem);
QString statusText;
QString statusIcon;
QColor statusColor;
if (pkg.installed && pkg.updateAvailable) {
statusText = "MAJ dispo";
statusIcon = "arrow-up";
statusColor = QColor("#e0af68");
} else if (pkg.installed) {
statusText = "Installé";
statusIcon = "check";
statusColor = QColor("#3fb950");
} else if (!pkg.repository.empty()) {
statusText = "Disponible";
statusIcon = "package";
statusColor = QColor("#98a0b3");
} else {
statusText = "—";
statusIcon.clear();
statusColor = QColor("#565f73");
}
QTableWidgetItem* statusItem = new QTableWidgetItem(statusText);
statusItem->setForeground(statusColor);
if (!statusIcon.isEmpty()) statusItem->setIcon(loadIcon(statusIcon));
m_packageTable->setItem(i, 4, statusItem);
}
void MainWindow::onPackageSelected(int row) {
if (row < 0 || row >= static_cast<int>(m_currentResults.size())) {
resetDetailsPanel();
@@ -1491,6 +1543,7 @@ void MainWindow::onUpdate() {
connect(worker, &InstallWorker::progress, this, [this](const QString& msg) {
statusBar()->showMessage(msg);
});
connect(worker, &InstallWorker::progressValue, this, &MainWindow::onInstallProgress);
connect(worker, &InstallWorker::finished, this, [this, provider](bool success) {
setBusy(false);
if (success) {
@@ -1523,6 +1576,7 @@ void MainWindow::onUpdateAll() {
connect(worker, &InstallWorker::progress, this, [this](const QString& msg) {
statusBar()->showMessage(msg);
});
connect(worker, &InstallWorker::progressValue, this, &MainWindow::onInstallProgress);
connect(worker, &InstallWorker::finished, this, [this, providers](bool success) {
setBusy(false);
if (success) {
@@ -1560,6 +1614,7 @@ void MainWindow::onRefresh() {
connect(worker, &InstallWorker::progress, this, [this](const QString& msg) {
statusBar()->showMessage(msg);
});
connect(worker, &InstallWorker::progressValue, this, &MainWindow::onInstallProgress);
connect(worker, &InstallWorker::finished, this, [this, providers](bool success) {
setBusy(false);
if (success) {
@@ -1594,6 +1649,7 @@ void MainWindow::performInstall(const std::string& package) {
connect(worker, &InstallWorker::progress, this, [this](const QString& msg) {
statusBar()->showMessage(msg);
});
connect(worker, &InstallWorker::progressValue, this, &MainWindow::onInstallProgress);
connect(worker, &InstallWorker::finished, this, [this, provider](bool success) {
setBusy(false);
if (success) {
@@ -1629,6 +1685,7 @@ void MainWindow::performRemove(const std::string& package) {
connect(worker, &InstallWorker::progress, this, [this](const QString& msg) {
statusBar()->showMessage(msg);
});
connect(worker, &InstallWorker::progressValue, this, &MainWindow::onInstallProgress);
connect(worker, &InstallWorker::finished, this, [this, provider](bool success) {
setBusy(false);
if (success) {
@@ -1663,11 +1720,26 @@ void MainWindow::reloadCurrentView() {
void MainWindow::setBusy(bool busy) {
m_progressBar->setVisible(busy);
m_installProgressBar->setVisible(busy);
if (busy) {
m_progressBar->setRange(0, 0); // Indeterminate
// Start indeterminate; a real percentage (onInstallProgress) switches
// the bottom bar to a determinate fill once the tool reports progress.
m_progressBar->setRange(0, 0);
m_progressBar->setValue(0);
m_installProgressBar->setRange(0, 0);
m_installProgressBar->setValue(0);
}
}
// A real download percentage reported by the provider fills the bottom bar as
// a determinate progress. -1 (unknown) leaves the bar in its previous state.
void MainWindow::onInstallProgress(int percent) {
if (percent < 0) return;
m_installProgressBar->setVisible(true);
m_installProgressBar->setRange(0, 100);
m_installProgressBar->setValue(percent);
}
void MainWindow::refreshHistoryTable() {
const auto& all = m_historyManager->getHistory();
@@ -1917,6 +1989,7 @@ void MainWindow::onInstallProviderTool() {
connect(worker, &InstallWorker::progress, this, [this](const QString& msg) {
statusBar()->showMessage(msg);
});
connect(worker, &InstallWorker::progressValue, this, &MainWindow::onInstallProgress);
connect(worker, &InstallWorker::finished, this, [this, id](bool success) {
setBusy(false);
clearCredentialsAfterUse();