mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
Handle "Delete confirmation" dialog result asynchronously
This is to avoid creating nested event loops as discussed in https://github.com/qbittorrent/qBittorrent/pull/10786#issuecomment-502795822
This commit is contained in:
parent
19b6f56a0a
commit
c632a91ee5
@ -39,10 +39,12 @@ DeletionConfirmationDialog::DeletionConfirmationDialog(QWidget *parent, const in
|
|||||||
, m_ui(new Ui::DeletionConfirmationDialog)
|
, m_ui(new Ui::DeletionConfirmationDialog)
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
if (size == 1)
|
if (size == 1)
|
||||||
m_ui->label->setText(tr("Are you sure you want to delete '%1' from the transfer list?", "Are you sure you want to delete 'ubuntu-linux-iso' from the transfer list?").arg(name.toHtmlEscaped()));
|
m_ui->label->setText(tr("Are you sure you want to delete '%1' from the transfer list?", "Are you sure you want to delete 'ubuntu-linux-iso' from the transfer list?").arg(name.toHtmlEscaped()));
|
||||||
else
|
else
|
||||||
m_ui->label->setText(tr("Are you sure you want to delete these %1 torrents from the transfer list?", "Are you sure you want to delete these 5 torrents from the transfer list?").arg(QString::number(size)));
|
m_ui->label->setText(tr("Are you sure you want to delete these %1 torrents from the transfer list?", "Are you sure you want to delete these 5 torrents from the transfer list?").arg(QString::number(size)));
|
||||||
|
|
||||||
// Icons
|
// Icons
|
||||||
const QSize iconSize = Utils::Gui::largeIconSize();
|
const QSize iconSize = Utils::Gui::largeIconSize();
|
||||||
m_ui->labelWarning->setPixmap(UIThemeManager::instance()->getIcon("dialog-warning").pixmap(iconSize));
|
m_ui->labelWarning->setPixmap(UIThemeManager::instance()->getIcon("dialog-warning").pixmap(iconSize));
|
||||||
@ -62,21 +64,11 @@ DeletionConfirmationDialog::~DeletionConfirmationDialog()
|
|||||||
delete m_ui;
|
delete m_ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeletionConfirmationDialog::shouldDeleteLocalFiles() const
|
bool DeletionConfirmationDialog::isDeleteFileSelected() const
|
||||||
{
|
{
|
||||||
return m_ui->checkPermDelete->isChecked();
|
return m_ui->checkPermDelete->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeletionConfirmationDialog::askForDeletionConfirmation(QWidget *parent, bool &deleteLocalFiles, const int size, const QString &name)
|
|
||||||
{
|
|
||||||
DeletionConfirmationDialog dlg(parent, size, name, deleteLocalFiles);
|
|
||||||
if (dlg.exec() == QDialog::Accepted) {
|
|
||||||
deleteLocalFiles = dlg.shouldDeleteLocalFiles();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeletionConfirmationDialog::updateRememberButtonState()
|
void DeletionConfirmationDialog::updateRememberButtonState()
|
||||||
{
|
{
|
||||||
m_ui->rememberBtn->setEnabled(m_ui->checkPermDelete->isChecked() != Preferences::instance()->deleteTorrentFilesAsDefault());
|
m_ui->rememberBtn->setEnabled(m_ui->checkPermDelete->isChecked() != Preferences::instance()->deleteTorrentFilesAsDefault());
|
||||||
|
@ -46,8 +46,7 @@ public:
|
|||||||
DeletionConfirmationDialog(QWidget *parent, int size, const QString &name, bool defaultDeleteFiles);
|
DeletionConfirmationDialog(QWidget *parent, int size, const QString &name, bool defaultDeleteFiles);
|
||||||
~DeletionConfirmationDialog();
|
~DeletionConfirmationDialog();
|
||||||
|
|
||||||
bool shouldDeleteLocalFiles() const;
|
bool isDeleteFileSelected() const;
|
||||||
static bool askForDeletionConfirmation(QWidget *parent, bool &deleteLocalFiles, int size, const QString &name);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateRememberButtonState();
|
void updateRememberButtonState();
|
||||||
|
@ -96,6 +96,14 @@ namespace
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void removeTorrents(const QVector<BitTorrent::TorrentHandle *> &torrents, const bool isDeleteFileSelected)
|
||||||
|
{
|
||||||
|
auto *session = BitTorrent::Session::instance();
|
||||||
|
const DeleteOption deleteOption = isDeleteFileSelected ? TorrentAndFiles : Torrent;
|
||||||
|
for (const BitTorrent::TorrentHandle *torrent : torrents)
|
||||||
|
session->deleteTorrent(torrent->hash(), deleteOption);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *mainWindow)
|
TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *mainWindow)
|
||||||
@ -363,19 +371,25 @@ void TransferListWidget::permDeleteSelectedTorrents()
|
|||||||
deleteSelectedTorrents(true);
|
deleteSelectedTorrents(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::deleteSelectedTorrents(bool deleteLocalFiles)
|
void TransferListWidget::deleteSelectedTorrents(const bool deleteLocalFiles)
|
||||||
{
|
{
|
||||||
if (m_mainWindow->currentTabWidget() != this) return;
|
if (m_mainWindow->currentTabWidget() != this) return;
|
||||||
|
|
||||||
const QVector<BitTorrent::TorrentHandle *> torrents = getSelectedTorrents();
|
const QVector<BitTorrent::TorrentHandle *> torrents = getSelectedTorrents();
|
||||||
if (torrents.empty()) return;
|
if (torrents.empty()) return;
|
||||||
|
|
||||||
if (Preferences::instance()->confirmTorrentDeletion()
|
if (Preferences::instance()->confirmTorrentDeletion()) {
|
||||||
&& !DeletionConfirmationDialog::askForDeletionConfirmation(this, deleteLocalFiles, torrents.size(), torrents[0]->name()))
|
auto *dialog = new DeletionConfirmationDialog(this, torrents.size(), torrents[0]->name(), deleteLocalFiles);
|
||||||
return;
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
const DeleteOption deleteOption = deleteLocalFiles ? TorrentAndFiles : Torrent;
|
connect(dialog, &DeletionConfirmationDialog::accepted, this, [dialog, torrents]()
|
||||||
for (const BitTorrent::TorrentHandle *torrent : torrents)
|
{
|
||||||
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteOption);
|
removeTorrents(torrents, dialog->isDeleteFileSelected());
|
||||||
|
});
|
||||||
|
dialog->open();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
removeTorrents(torrents, deleteLocalFiles);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::deleteVisibleTorrents()
|
void TransferListWidget::deleteVisibleTorrents()
|
||||||
@ -386,14 +400,18 @@ void TransferListWidget::deleteVisibleTorrents()
|
|||||||
for (int i = 0; i < m_sortFilterModel->rowCount(); ++i)
|
for (int i = 0; i < m_sortFilterModel->rowCount(); ++i)
|
||||||
torrents << m_listModel->torrentHandle(mapToSource(m_sortFilterModel->index(i, 0)));
|
torrents << m_listModel->torrentHandle(mapToSource(m_sortFilterModel->index(i, 0)));
|
||||||
|
|
||||||
bool deleteLocalFiles = false;
|
if (Preferences::instance()->confirmTorrentDeletion()) {
|
||||||
if (Preferences::instance()->confirmTorrentDeletion()
|
auto *dialog = new DeletionConfirmationDialog(this, torrents.size(), torrents[0]->name(), false);
|
||||||
&& !DeletionConfirmationDialog::askForDeletionConfirmation(this, deleteLocalFiles, torrents.size(), torrents[0]->name()))
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
return;
|
connect(dialog, &DeletionConfirmationDialog::accepted, this, [dialog, torrents]()
|
||||||
|
{
|
||||||
const DeleteOption deleteOption = deleteLocalFiles ? TorrentAndFiles : Torrent;
|
removeTorrents(torrents, dialog->isDeleteFileSelected());
|
||||||
for (const BitTorrent::TorrentHandle *torrent : asConst(torrents))
|
});
|
||||||
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteOption);
|
dialog->open();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
removeTorrents(torrents, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::increaseQueuePosSelectedTorrents()
|
void TransferListWidget::increaseQueuePosSelectedTorrents()
|
||||||
|
Loading…
Reference in New Issue
Block a user