From 78d7cc0570392521aa37e558f0c2aa62ceb4ad6d Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 12 Jun 2018 14:53:12 +0800 Subject: [PATCH 1/2] Work around crash when procesing recursive download The messagebox is modal and exec() it makes it generates a new local event loop, however the new local event loop will continue to process libtorrent events (in Session::readAlerts()), at the time exec() returns, the original libt::alert pointers are lost and resume processing alerts will cause the crash. One solution is to make the messagebox use show() and avoid exec(). Closes #9086. --- src/gui/mainwindow.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index dbe5a85ef..1c29a3604 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -927,18 +927,26 @@ void MainWindow::askRecursiveTorrentDownloadConfirmation(BitTorrent::TorrentHand { Preferences *const pref = Preferences::instance(); if (pref->recursiveDownloadDisabled()) return; - // Get Torrent name - QString torrentName = torrent->name(); - QMessageBox confirmBox(QMessageBox::Question, tr("Recursive download confirmation"), tr("The torrent '%1' contains torrent files, do you want to proceed with their download?").arg(torrentName), QMessageBox::NoButton, this); - QPushButton *yes = confirmBox.addButton(tr("Yes"), QMessageBox::YesRole); - /*QPushButton *no = */ confirmBox.addButton(tr("No"), QMessageBox::NoRole); - QPushButton *never = confirmBox.addButton(tr("Never"), QMessageBox::NoRole); - confirmBox.exec(); - - if (confirmBox.clickedButton() == yes) - BitTorrent::Session::instance()->recursiveTorrentDownload(torrent->hash()); - else if (confirmBox.clickedButton() == never) - pref->disableRecursiveDownload(); + + const auto torrentHash = torrent->hash(); + + QMessageBox *confirmBox = new QMessageBox(QMessageBox::Question, tr("Recursive download confirmation") + , tr("The torrent '%1' contains torrent files, do you want to proceed with their download?").arg(torrent->name()) + , QMessageBox::NoButton, this); + confirmBox->setAttribute(Qt::WA_DeleteOnClose); + confirmBox->setModal(true); + + const QPushButton *yes = confirmBox->addButton(tr("Yes"), QMessageBox::YesRole); + /*QPushButton *no = */ confirmBox->addButton(tr("No"), QMessageBox::NoRole); + const QPushButton *never = confirmBox->addButton(tr("Never"), QMessageBox::NoRole); + connect(confirmBox, &QMessageBox::buttonClicked, this, [torrentHash, yes, never](const QAbstractButton *button) + { + if (button == yes) + BitTorrent::Session::instance()->recursiveTorrentDownload(torrentHash); + if (button == never) + Preferences::instance()->disableRecursiveDownload(); + }); + confirmBox->show(); } void MainWindow::handleDownloadFromUrlFailure(QString url, QString reason) const From 6bf3f1d0b81f6e69f8413c92695a6208b96de515 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 12 Jun 2018 15:14:19 +0800 Subject: [PATCH 2/2] Add checkbox for recursive download dialog Also group similar options together. --- src/gui/optionsdialog.cpp | 3 +++ src/gui/optionsdialog.ui | 35 +++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index 7880796b2..6f91cbe38 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -254,6 +254,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) connect(m_ui->textTempPath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton); connect(m_ui->checkAppendqB, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkPreallocateAll, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); + connect(m_ui->checkRecursiveDownload, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkAdditionDialog, &QGroupBox::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkAdditionDialogFront, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkStartPaused, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); @@ -602,6 +603,7 @@ void OptionsDialog::saveOptions() session->setTempPath(Utils::Fs::expandPathAbs(m_ui->textTempPath->selectedPath())); session->setAppendExtensionEnabled(m_ui->checkAppendqB->isChecked()); session->setPreallocationEnabled(preAllocateAllFiles()); + pref->disableRecursiveDownload(!m_ui->checkRecursiveDownload->isChecked()); AddNewTorrentDialog::setEnabled(useAdditionDialog()); AddNewTorrentDialog::setTopLevel(m_ui->checkAdditionDialogFront->isChecked()); session->setAddTorrentPaused(addTorrentsInPause()); @@ -849,6 +851,7 @@ void OptionsDialog::loadOptions() m_ui->textTempPath->setSelectedPath(Utils::Fs::toNativePath(session->tempPath())); m_ui->checkAppendqB->setChecked(session->isAppendExtensionEnabled()); m_ui->checkPreallocateAll->setChecked(session->isPreallocationEnabled()); + m_ui->checkRecursiveDownload->setChecked(!pref->recursiveDownloadDisabled()); strValue = session->torrentExportDirectory(); if (strValue.isEmpty()) { diff --git a/src/gui/optionsdialog.ui b/src/gui/optionsdialog.ui index 0393990f8..9911c3158 100644 --- a/src/gui/optionsdialog.ui +++ b/src/gui/optionsdialog.ui @@ -779,6 +779,27 @@ + + + + Pre-allocate disk space for all files + + + + + + + Append .!qB extension to incomplete files + + + + + + + Enable recursive download dialog + + + @@ -1004,20 +1025,6 @@ - - - - Pre-allocate disk space for all files - - - - - - - Append .!qB extension to incomplete files - - -