gui: Options, Scheduler, Speed Limiter, Batch, Grabber, and the tray icon

Continues the build order past the Add-URL/File-Info/Progress dialog flow.

- OptionsDialog: General/Save To/Connection/Downloads/Proxy/Sounds tabs, every
  control bound to a real settings.* key (contracts/schema/types/Settings.
  schema.json). The spec's File Types and Site Logins tabs have no settings.*
  backing (categories go through category.upsert, credentials through the
  Secret Service) so they don't exist here — a tab either binds to a real key
  or isn't shipped. diffChanged() sends only what actually changed, matching
  settings.set's "changed[] names exactly what took effect" contract.
- SchedulerDialog: per-queue schedule (schedule.get/set) plus maxConcurrent/
  onComplete (queue.upsert), Start Now/Stop. Queue.schema.json already carries
  the schedule so queue.list alone seeds the window.
- SpeedLimiterDialog: the live global limiter (limiter.get/set) — a different
  thing from Options' downloads.speedLimit* default. buildParams() enforces
  the schema's "0 with enabled true must not be offered".
- BatchDialog: clipboard-blob and {start..end}-wildcard tabs sharing one
  category/queue/start-mode footer into download.addBatch.
- GrabberWizard: 4-step QWizard (project label -> start URL/depth/filters ->
  file-type filter -> review), grabber.start feeding a poll+event.grabber.
  progress-driven review page, Finish = grabber.harvest for the checked files.
- TrayIcon: active-count tooltip, Show/Add URL/Pause All/Resume All/Speed
  Limiter submenu/Quit. Quit only closes the GUI — there is no RPC to stop
  veloxd itself, filed as a new gap in daemon-requests-m1.md. MainWindow now
  also hides to tray instead of closing when general.minimizeToTray is set.

Every dialog's non-widget logic (diffChanged, buildSchedule, buildParams,
parseUrlBlob/expandWildcard/buildAddBatchParams, buildFileTypes/
buildStartParams/buildHarvestParams) is a static pure function with its own
test, same shape as FileInfoDialog::buildSpec from the previous round.

Verified end-to-end against a running mockd under ASan+UBSan: all five
surfaces render real data (settings.get values, queue.list's two seeded
queues, limiter.get, a live grabber.start/status crawl returning 3 files) with
no sanitizer reports. gui-check (non-ASan) and dev (ASan+UBSan) presets both
build the whole repo clean; all gui-labeled ctest targets pass.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NSCdCWFXBTSBBK3MzWtJiC
This commit is contained in:
2026-09-11 17:17:43 +04:00
co-authored by Claude Sonnet 5
parent 39c69f3871
commit de83ee3cce
22 changed files with 2678 additions and 13 deletions
+119 -9
View File
@@ -2,6 +2,7 @@
#include <QAction>
#include <QCloseEvent>
#include <QCoreApplication>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QItemSelectionModel>
@@ -16,6 +17,7 @@
#include <QSettings>
#include <QSplitter>
#include <QStatusBar>
#include <QSystemTrayIcon>
#include <QTimer>
#include <QToolBar>
#include <QTreeView>
@@ -23,11 +25,17 @@
#include <QWidget>
#include "dialogs/AddUrlDialog.hpp"
#include "dialogs/BatchDialog.hpp"
#include "dialogs/FileInfoDialog.hpp"
#include "dialogs/GrabberWizard.hpp"
#include "dialogs/OptionsDialog.hpp"
#include "dialogs/ProgressDialog.hpp"
#include "dialogs/SchedulerDialog.hpp"
#include "dialogs/SpeedLimiterDialog.hpp"
#include "mainwindow/CategoryPanel.hpp"
#include "models/DownloadTableModel.hpp"
#include "rpc/RpcClient.hpp"
#include "tray/TrayIcon.hpp"
#include "util/Format.hpp"
#include "widgets/ProgressDelegate.hpp"
@@ -102,6 +110,7 @@ MainWindow::MainWindow(rpc::RpcClient *client, QWidget *parent)
buildActions();
buildMenus();
buildToolBar();
buildTray();
// --- status bar -----------------------------------------------------------------
connDot_->setStyleSheet(dotStyle(QStringLiteral("#c0392b")));
@@ -123,6 +132,7 @@ MainWindow::MainWindow(rpc::RpcClient *client, QWidget *parent)
&DownloadTableModel::applyTaskState);
connect(client_, &rpc::RpcClient::taskRemoved, model_, &DownloadTableModel::applyTaskRemoved);
connect(client_, &rpc::RpcClient::speedGlobal, this, &MainWindow::onSpeedGlobal);
connect(client_, &rpc::RpcClient::settingsChanged, this, &MainWindow::onSettingsChanged);
connect(model_, &QAbstractItemModel::modelReset, this, &MainWindow::scheduleCounts);
connect(model_, &QAbstractItemModel::rowsInserted, this, &MainWindow::scheduleCounts);
@@ -166,6 +176,24 @@ void MainWindow::buildActions() {
actProperties_ = new QAction(tr("&Properties…"), this);
connect(actProperties_, &QAction::triggered, this, &MainWindow::openPropertiesForSelection);
actOptions_ = new QAction(tr("&Options…"), this);
connect(actOptions_, &QAction::triggered, this, &MainWindow::openOptionsDialog);
actScheduler_ = new QAction(tr("&Scheduler…"), this);
connect(actScheduler_, &QAction::triggered, this, &MainWindow::openSchedulerDialog);
actSpeedLimiter_ = new QAction(tr("Speed &Limiter…"), this);
connect(actSpeedLimiter_, &QAction::triggered, this, &MainWindow::openSpeedLimiterDialog);
actBatch_ = new QAction(tr("&Batch Download…"), this);
connect(actBatch_, &QAction::triggered, this, &MainWindow::openBatchDialog);
actGrabber_ = new QAction(tr("Site &Grabber…"), this);
connect(actGrabber_, &QAction::triggered, this, &MainWindow::openGrabberWizard);
actShow_ = new QAction(tr("&Show Velox"), this);
connect(actShow_, &QAction::triggered, this, &MainWindow::showAndRaise);
}
void MainWindow::buildMenus() {
@@ -185,10 +213,14 @@ void MainWindow::buildMenus() {
downloads->addAction(actResumeAll_);
downloads->addAction(actPauseAll_);
downloads->addSeparator();
QAction *scheduler = downloads->addAction(tr("Scheduler…"));
scheduler->setEnabled(false); // build order step 5
QAction *limiter = downloads->addAction(tr("Speed Limiter…"));
limiter->setEnabled(false);
downloads->addAction(actScheduler_);
downloads->addAction(actSpeedLimiter_);
QMenu *tools = menuBar()->addMenu(tr("&Tools"));
tools->addAction(actBatch_);
tools->addAction(actGrabber_);
tools->addSeparator();
tools->addAction(actOptions_);
QMenu *view = menuBar()->addMenu(tr("&View"));
QAction *togglePanel = view->addAction(tr("&Category Panel"));
@@ -214,9 +246,27 @@ void MainWindow::buildToolBar() {
tb->addAction(actStop_);
tb->addSeparator();
tb->addAction(actRemove_);
tb->addSeparator();
tb->addAction(actScheduler_);
tb->addAction(actOptions_);
tb->addAction(actGrabber_);
}
void MainWindow::buildTray() {
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
return; // headless/mockd-only test environments, some minimal WMs
}
trayIcon_ = new TrayIcon(client_, actShow_, actAddUrl_, actResumeAll_, actPauseAll_, this);
connect(trayIcon_, &TrayIcon::quitRequested, qApp, &QCoreApplication::quit);
trayIcon_->show();
}
void MainWindow::closeEvent(QCloseEvent *event) {
if (minimizeToTrayEnabled_ && trayIcon_ && trayIcon_->isVisible()) {
hide();
event->ignore();
return;
}
saveLayout();
QMainWindow::closeEvent(event);
event->accept();
@@ -241,13 +291,15 @@ 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_,
actAddUrl_, actProperties_}) {
for (QAction *a :
{actResume_, actPause_, actStop_, actRemove_, actResumeAll_, actPauseAll_, actAddUrl_,
actProperties_, actScheduler_, actSpeedLimiter_, actBatch_, actGrabber_, actOptions_}) {
a->setEnabled(online);
}
if (online) {
fetchTree();
fetchMinimizeToTraySetting();
}
}
@@ -266,6 +318,29 @@ void MainWindow::fetchTree() {
});
}
void MainWindow::fetchMinimizeToTraySetting() {
client_->call(QStringLiteral("settings.get"),
QJsonObject{{"keys", QJsonArray{QStringLiteral("general.minimizeToTray")}}},
[this](const rpc::RpcReply &reply) {
if (reply.ok()) {
minimizeToTrayEnabled_ = reply.result.toObject()
.value("values")
.toObject()
.value("general.minimizeToTray")
.toBool();
}
});
}
void MainWindow::onSettingsChanged(const QJsonObject &params) {
for (const QJsonValue &key : params.value("keys").toArray()) {
if (key.toString() == QLatin1String("general.minimizeToTray")) {
fetchMinimizeToTraySetting();
break;
}
}
}
void MainWindow::openAddUrlDialog() {
AddUrlDialog dlg(this);
if (dlg.exec() != QDialog::Accepted) {
@@ -294,11 +369,43 @@ void MainWindow::openPropertiesForSelection() {
}
}
void MainWindow::openOptionsDialog() {
OptionsDialog dlg(client_, this);
dlg.exec();
}
void MainWindow::openSchedulerDialog() {
SchedulerDialog dlg(client_, this);
dlg.exec();
}
void MainWindow::openSpeedLimiterDialog() {
SpeedLimiterDialog dlg(client_, this);
dlg.exec();
}
void MainWindow::openBatchDialog() {
BatchDialog dlg(client_, categoriesCache_, queuesCache_, this);
dlg.exec();
}
void MainWindow::openGrabberWizard() {
auto *wizard = new GrabberWizard(client_, categoriesCache_, this);
wizard->setAttribute(Qt::WA_DeleteOnClose);
wizard->show();
}
void MainWindow::showAndRaise() {
show();
raise();
activateWindow();
}
// 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.
// need state this build order hasn't reached yet (Options' file-type associations aren't
// per-row actions, and Batch's "Add to Queue" is a different flow than re-filing an
// existing task) — offering them now would be a fake affordance.
void MainWindow::showTableContextMenu(const QPoint &pos) {
const QModelIndex idx = view_->indexAt(pos);
if (idx.isValid() && view_->selectionModel() && !view_->selectionModel()->isSelected(idx)) {
@@ -370,6 +477,9 @@ void MainWindow::refreshCounts() {
}
panel_->setCounts(total, unfinished, finished, byCategory, byQueue);
if (trayIcon_) {
trayIcon_->setActiveCount(active);
}
const int shown = proxy_->rowCount();
countsLabel_->setText(tr("%1 of %2 downloads, %3 active ↓ %4")
+23 -4
View File
@@ -1,9 +1,10 @@
// The main window. Lane GUI.
//
// 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.
// M1 slice: 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, a per-task progress dialog, Options/Scheduler/Speed Limiter/Batch/
// Grabber, and the tray icon. The floating drop target and clipboard capture are still to
// come.
#pragma once
@@ -24,6 +25,7 @@ namespace velox::gui {
class DownloadTableModel;
class CategoryPanel;
class TrayIcon;
namespace rpc {
class RpcClient;
} // namespace rpc
@@ -55,12 +57,21 @@ class MainWindow : public QMainWindow {
void openAddUrlDialog();
void openPropertiesForSelection();
void showTableContextMenu(const QPoint &pos);
void openOptionsDialog();
void openSchedulerDialog();
void openSpeedLimiterDialog();
void openBatchDialog();
void openGrabberWizard();
void showAndRaise();
void onSettingsChanged(const QJsonObject &params);
private:
void buildActions();
void buildMenus();
void buildToolBar();
void buildTray();
void fetchTree();
void fetchMinimizeToTraySetting();
QStringList selectedTaskIds() const;
QStringList allTaskIds() const;
void actOnTasks(const char *methodName, const QStringList &ids);
@@ -81,9 +92,17 @@ class MainWindow : public QMainWindow {
QAction *actResumeAll_ = nullptr;
QAction *actPauseAll_ = nullptr;
QAction *actProperties_ = nullptr;
QAction *actOptions_ = nullptr;
QAction *actScheduler_ = nullptr;
QAction *actSpeedLimiter_ = nullptr;
QAction *actBatch_ = nullptr;
QAction *actGrabber_ = nullptr;
QAction *actShow_ = nullptr;
QJsonArray categoriesCache_;
QJsonArray queuesCache_;
TrayIcon *trayIcon_ = nullptr;
bool minimizeToTrayEnabled_ = false;
QLabel *connDot_;
QLabel *connText_;