Fix "preview file" action not working

Root cause is the PreviewSelectDialog::readyToPreviewFile signal is
emitted before it is connected to a slot.
Only single-file torrents are affected.

Closes #11315.
This commit is contained in:
Chocobo1 2019-10-02 19:29:28 +08:00
parent 0607050ecc
commit 7ed0cd0c35
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
2 changed files with 11 additions and 12 deletions

View file

@ -101,16 +101,6 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, const BitTorrent::Torr
// Restore dialog state
loadWindowState();
if (m_previewListModel->rowCount() == 1) {
qDebug("Torrent file only contains one file, no need to display selection dialog before preview");
// Only one file : no choice
previewButtonClicked();
}
else {
qDebug("Displaying media file selection dialog for preview");
show();
}
}
PreviewSelectDialog::~PreviewSelectDialog()
@ -161,13 +151,21 @@ void PreviewSelectDialog::loadWindowState()
void PreviewSelectDialog::showEvent(QShowEvent *event)
{
Q_UNUSED(event);
// event originated from system
if (event->spontaneous()) {
QDialog::showEvent(event);
return;
}
// Default size, have to be called after show(), because width is needed
// Set Name column width to 60% of TreeView
if (!m_headerStateInitialized) {
int nameSize = (m_ui->previewList->size().width() * 0.6);
const int nameSize = (m_ui->previewList->size().width() * 0.6);
m_ui->previewList->header()->resizeSection(0, nameSize);
m_headerStateInitialized = true;
}
// Only one file, no choice
if (m_previewListModel->rowCount() <= 1)
previewButtonClicked();
}

View file

@ -506,6 +506,7 @@ void TransferListWidget::previewSelectedTorrents()
auto *dialog = new PreviewSelectDialog(this, torrent);
dialog->setAttribute(Qt::WA_DeleteOnClose);
connect(dialog, &PreviewSelectDialog::readyToPreviewFile, this, &TransferListWidget::previewFile);
dialog->show();
}
else {
QMessageBox::critical(this, tr("Unable to preview"), tr("The selected torrent does not contain previewable files"));