gui: finish Add URL -> File Info -> Progress dialog flow

Wires up the three dialogs from build order step 5 (docs/03-gui-spec.md
§§2-3) and the MainWindow slots that were declared but never implemented:

- AddUrlDialog: clipboard prefill is the explicit path docs/06 R2 calls
  for (no passive monitoring, not advertised).
- FileInfoDialog: async download.probe never blocks the UI; ends by
  calling download.add itself (Now / Later / Add to Queue). buildSpec()
  is a pure static so the optional-field-omission logic is unit-testable
  without touching a widget.
- ProgressDialog: non-modal, WA_DeleteOnClose, driven by the taskProgress/
  taskStateChanged signals RpcClient already re-broadcasts; download.get
  seeds state once for a dialog opened mid-transfer. Hosts SegmentBarsWidget
  and SpeedGraphWidget.

MainWindow: openAddUrlDialog/openPropertiesForSelection/showTableContextMenu
now have bodies; category.list/queue.list responses are cached so File Info
can populate its category combo and queue menu without a second round trip.
The row context menu covers what already exists (Resume/Pause/Stop/Delete/
Properties) and deliberately leaves out Open/Open With/Move-Rename/
Redownload/Add to Queue — those need dialogs later build-order steps haven't
reached yet.

util/Format.hpp: pulled the bytes/rate/eta formatting out of MainWindow and
DownloadTableModel once the dialogs wanted the same strings a third time.

Verified end-to-end against a running mockd (category.list/queue.list,
download.probe, download.add, download.get, and live event.task.progress/
event.task.state) under ASan+UBSan: all three dialogs render correctly
against real fixture data and the flow runs clean with no leaks or
sanitizer reports.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NSCdCWFXBTSBBK3MzWtJiC
This commit is contained in:
2026-09-11 12:11:13 +04:00
co-authored by Claude Sonnet 5
parent 41bce91770
commit a71d904a1f
13 changed files with 989 additions and 38 deletions
+74 -13
View File
@@ -22,22 +22,18 @@
#include <QVBoxLayout>
#include <QWidget>
#include "dialogs/AddUrlDialog.hpp"
#include "dialogs/FileInfoDialog.hpp"
#include "dialogs/ProgressDialog.hpp"
#include "mainwindow/CategoryPanel.hpp"
#include "models/DownloadTableModel.hpp"
#include "rpc/RpcClient.hpp"
#include "util/Format.hpp"
#include "widgets/ProgressDelegate.hpp"
namespace velox::gui {
namespace {
QString humanRate(qint64 bps) {
if (bps <= 0) {
return QStringLiteral("0 B/s");
}
return MainWindow::tr("%1/s").arg(
QLocale().formattedDataSize(bps, 1, QLocale::DataSizeIecFormat));
}
QString dotStyle(const QString &colour) {
return QStringLiteral("color: %1; font-size: 14px;").arg(colour);
}
@@ -70,6 +66,10 @@ MainWindow::MainWindow(rpc::RpcClient *client, QWidget *parent)
view_->setSelectionMode(QAbstractItemView::ExtendedSelection);
view_->setSortingEnabled(true);
view_->setItemDelegateForColumn(DownloadTableModel::ColStatus, new ProgressDelegate(this));
view_->setContextMenuPolicy(Qt::CustomContextMenu);
connect(view_, &QWidget::customContextMenuRequested, this, &MainWindow::showTableContextMenu);
connect(view_, &QAbstractItemView::doubleClicked, this,
&MainWindow::openPropertiesForSelection);
view_->header()->setSectionsMovable(true);
view_->header()->setStretchLastSection(true);
@@ -141,7 +141,7 @@ MainWindow::~MainWindow() = default;
void MainWindow::buildActions() {
actAddUrl_ = new QAction(tr("Add &URL…"), this);
actAddUrl_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N));
actAddUrl_->setEnabled(false); // wired up with the Add URL dialog (build order step 5)
connect(actAddUrl_, &QAction::triggered, this, &MainWindow::openAddUrlDialog);
actResume_ = new QAction(tr("&Resume"), this);
actResume_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R));
@@ -163,6 +163,9 @@ void MainWindow::buildActions() {
actPauseAll_ = new QAction(tr("Pause All"), this);
connect(actPauseAll_, &QAction::triggered, this, &MainWindow::pauseAll);
actProperties_ = new QAction(tr("&Properties…"), this);
connect(actProperties_, &QAction::triggered, this, &MainWindow::openPropertiesForSelection);
}
void MainWindow::buildMenus() {
@@ -174,6 +177,7 @@ void MainWindow::buildMenus() {
tasks->addAction(actStop_);
tasks->addSeparator();
tasks->addAction(actRemove_);
tasks->addAction(actProperties_);
tasks->addSeparator();
tasks->addAction(tr("E&xit"), QKeySequence::Quit, this, &QWidget::close);
@@ -237,7 +241,8 @@ void MainWindow::onConnectionState(rpc::ConnectionState state) {
: tr("The Velox service is not running. Downloads are unaffected; "
"this list is read-only until it returns."));
}
for (QAction *a : {actResume_, actPause_, actStop_, actRemove_, actResumeAll_, actPauseAll_}) {
for (QAction *a : {actResume_, actPause_, actStop_, actRemove_, actResumeAll_, actPauseAll_,
actAddUrl_, actProperties_}) {
a->setEnabled(online);
}
@@ -249,16 +254,72 @@ void MainWindow::onConnectionState(rpc::ConnectionState state) {
void MainWindow::fetchTree() {
client_->call(QStringLiteral("category.list"), {}, [this](const rpc::RpcReply &reply) {
if (reply.ok()) {
panel_->setCategories(reply.result.toObject().value("items").toArray());
categoriesCache_ = reply.result.toObject().value("items").toArray();
panel_->setCategories(categoriesCache_);
}
});
client_->call(QStringLiteral("queue.list"), {}, [this](const rpc::RpcReply &reply) {
if (reply.ok()) {
panel_->setQueues(reply.result.toObject().value("items").toArray());
queuesCache_ = reply.result.toObject().value("items").toArray();
panel_->setQueues(queuesCache_);
}
});
}
void MainWindow::openAddUrlDialog() {
AddUrlDialog dlg(this);
if (dlg.exec() != QDialog::Accepted) {
return;
}
const QString url = dlg.url();
if (url.isEmpty()) {
return;
}
// Non-modal: several File Info dialogs can be open at once (spec §2), and it must
// never block the main window while download.probe is in flight.
auto *info = new FileInfoDialog(client_, url, categoriesCache_, queuesCache_, this);
info->setAttribute(Qt::WA_DeleteOnClose);
info->show();
}
void MainWindow::openPropertiesForSelection() {
const QStringList ids = selectedTaskIds();
if (ids.isEmpty()) {
return;
}
// One Progress dialog per selected task, same as double-clicking each row.
for (const QString &id : ids) {
auto *dlg = new ProgressDialog(client_, id, this);
dlg->show();
}
}
// docs/03-gui-spec.md §1 lists a fuller row menu (Open · Open With · Open Folder ·
// Move/Rename · Redownload · Refresh Download Address · Add to Queue ▸ · ...). Those all
// need dialogs or state this build order hasn't reached yet (Options for file-type
// associations, Batch for Add to Queue) — offering them now would be a fake affordance,
// same reasoning as the disabled Scheduler/Speed Limiter menu entries above.
void MainWindow::showTableContextMenu(const QPoint &pos) {
const QModelIndex idx = view_->indexAt(pos);
if (idx.isValid() && view_->selectionModel() && !view_->selectionModel()->isSelected(idx)) {
view_->selectionModel()->setCurrentIndex(
idx, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
}
if (selectedTaskIds().isEmpty()) {
return;
}
QMenu menu(this);
menu.addAction(actResume_);
menu.addAction(actPause_);
menu.addAction(actStop_);
menu.addSeparator();
menu.addAction(actRemove_);
menu.addSeparator();
menu.addAction(actProperties_);
menu.exec(view_->viewport()->mapToGlobal(pos));
}
void MainWindow::onFilterChanged(const TaskSelection &selection) {
proxy_->setSelection(selection);
// TODO(gui): also push proxy_->asTaskFilter() to a fresh download.list once the daemon
@@ -315,7 +376,7 @@ void MainWindow::refreshCounts() {
.arg(shown)
.arg(total)
.arg(active)
.arg(humanRate(globalDownBps_)));
.arg(fmt::rate(globalDownBps_)));
}
QStringList MainWindow::selectedTaskIds() const {
+14 -3
View File
@@ -1,13 +1,16 @@
// The main window. Lane GUI.
//
// M1 slice: dialogs and the tray still come later. This is the menus + toolbar + splitter
// (category tree | table), the table driven by mockd, a status-bar connection dot, an
// offline banner instead of a modal, and the actions that need no dialog.
// M1 slice: the tray and the Options/Scheduler/Speed-Limiter/Batch/Grabber dialogs still
// come later. This is the menus + toolbar + splitter (category tree | table), the table
// driven by mockd, a status-bar connection dot, an offline banner instead of a modal, the
// Add URL -> File Info flow, and a per-task progress dialog.
#pragma once
#include <QHash>
#include <QJsonArray>
#include <QMainWindow>
#include <QPoint>
#include "models/DownloadFilterProxy.hpp"
#include "rpc/Protocol.hpp"
@@ -49,6 +52,10 @@ class MainWindow : public QMainWindow {
void resumeAll();
void pauseAll();
void openAddUrlDialog();
void openPropertiesForSelection();
void showTableContextMenu(const QPoint &pos);
private:
void buildActions();
void buildMenus();
@@ -73,6 +80,10 @@ class MainWindow : public QMainWindow {
QAction *actRemove_ = nullptr;
QAction *actResumeAll_ = nullptr;
QAction *actPauseAll_ = nullptr;
QAction *actProperties_ = nullptr;
QJsonArray categoriesCache_;
QJsonArray queuesCache_;
QLabel *connDot_;
QLabel *connText_;