From 6a462edb72c80cd1d518da702787baee8752fa84 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 2 Oct 2019 20:03:50 +0800 Subject: [PATCH] Don't close preview dialog if selected file failed to open User may have made a mis-selection and this should not close the dialog (only when the torrent has multiple previewable files). --- src/gui/previewselectdialog.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/gui/previewselectdialog.cpp b/src/gui/previewselectdialog.cpp index 2de213876..3108b582f 100644 --- a/src/gui/previewselectdialog.cpp +++ b/src/gui/previewselectdialog.cpp @@ -112,21 +112,26 @@ PreviewSelectDialog::~PreviewSelectDialog() void PreviewSelectDialog::previewButtonClicked() { - QModelIndexList selectedIndexes = m_ui->previewList->selectionModel()->selectedRows(FILE_INDEX); + const QModelIndexList selectedIndexes = m_ui->previewList->selectionModel()->selectedRows(FILE_INDEX); if (selectedIndexes.isEmpty()) return; // Flush data m_torrent->flushCache(); - QStringList absolutePaths(m_torrent->absoluteFilePaths()); + const QStringList absolutePaths = m_torrent->absoluteFilePaths(); // Only one file should be selected - QString path = absolutePaths.at(selectedIndexes.at(0).data().toInt()); + const QString path = absolutePaths.at(selectedIndexes.at(0).data().toInt()); // File - if (QFile::exists(path)) - emit readyToPreviewFile(path); - else - QMessageBox::critical(this->parentWidget(), tr("Preview impossible"), tr("Sorry, we can't preview this file")); + if (!QFile::exists(path)) { + const bool isSingleFile = (m_previewListModel->rowCount() == 1); + QWidget *parent = isSingleFile ? this->parentWidget() : this; + QMessageBox::critical(parent, tr("Preview impossible"), tr("Sorry, we can't preview this file")); + if (isSingleFile) + reject(); + return; + } + emit readyToPreviewFile(path); accept(); }