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).
This commit is contained in:
Chocobo1 2019-10-02 20:03:50 +08:00
parent 7ed0cd0c35
commit 6a462edb72
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C

View File

@ -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();
}