From 162273da47cda21b5d3a5bab54c098dbb1d7468d Mon Sep 17 00:00:00 2001 From: BallsOfSpaghetti <115404710+OpenSpaghettiSauce@users.noreply.github.com> Date: Tue, 8 Nov 2022 04:31:18 +0100 Subject: [PATCH] Add confirmation to resume/pause all This adds a confirmation dialog to Pause All and Resume All. First I wanted to only add it in Tray, but honestly, clicking around in the menu, using hotkeys might trigger it just as easy. Closes #17683. PR #17945. --- src/gui/transferlistwidget.cpp | 18 ++++++++++++++ src/webui/www/private/scripts/mocha-init.js | 26 +++++++++++++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index 93e8906b7..196334702 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -363,12 +363,30 @@ void TransferListWidget::setSelectedTorrentsLocation() void TransferListWidget::pauseAllTorrents() { + // Show confirmation if user would really like to Pause All + const QMessageBox::StandardButton ret = + QMessageBox::question(this, tr("Confirm pause") + , tr("Would you like to pause all torrents?") + , (QMessageBox::Yes | QMessageBox::No)); + + if (ret != QMessageBox::Yes) + return; + for (BitTorrent::Torrent *const torrent : asConst(BitTorrent::Session::instance()->torrents())) torrent->pause(); } void TransferListWidget::resumeAllTorrents() { + // Show confirmation if user would really like to Resume All + const QMessageBox::StandardButton ret = + QMessageBox::question(this, tr("Confirm resume") + , tr("Would you like to resume all torrents?") + , (QMessageBox::Yes | QMessageBox::No)); + + if (ret != QMessageBox::Yes) + return; + for (BitTorrent::Torrent *const torrent : asConst(BitTorrent::Session::instance()->torrents())) torrent->resume(); } diff --git a/src/webui/www/private/scripts/mocha-init.js b/src/webui/www/private/scripts/mocha-init.js index dd93e4d4c..87748bf85 100644 --- a/src/webui/www/private/scripts/mocha-init.js +++ b/src/webui/www/private/scripts/mocha-init.js @@ -979,18 +979,34 @@ const initializeWindows = function() { } }; - ['pause', 'resume'].each(function(item) { - addClickEvent(item + 'All', function(e) { - new Event(e).stop(); + addClickEvent('pauseAll', (e) => { + new Event(e).stop(); + + if (confirm('QBT_TR(Would you like to pause all torrents?)QBT_TR[CONTEXT=MainWindow]')) { new Request({ - url: 'api/v2/torrents/' + item, + url: 'api/v2/torrents/pause', method: 'post', data: { hashes: "all" } }).send(); updateMainData(); - }); + } + }); + + addClickEvent('resumeAll', (e) => { + new Event(e).stop(); + + if (confirm('QBT_TR(Would you like to resume all torrents?)QBT_TR[CONTEXT=MainWindow]')) { + new Request({ + url: 'api/v2/torrents/resume', + method: 'post', + data: { + hashes: "all" + } + }).send(); + updateMainData(); + } }); ['pause', 'resume', 'recheck'].each(function(item) {