From 5dd70b88d31a2e8dd8df7218959f1cc015dbe3aa Mon Sep 17 00:00:00 2001 From: a-sum-duma <68896601+a-sum-duma@users.noreply.github.com> Date: Mon, 1 Nov 2021 04:45:48 +0100 Subject: [PATCH] Fix torrent content sorting Fix improper sorting of the list of files contained by a torrent. Always load all torrent content data so that the files list can be sorted properly. Load torrent content only when needed. Don't load the list of files contained by a torrent if the list widget is not visible. PR #15604. --- src/gui/properties/propertieswidget.cpp | 54 ++++++++++++++++--------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index 531447fc8..bbd26894a 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -362,20 +362,6 @@ void PropertiesWidget::loadTorrentInfos(BitTorrent::Torrent *const torrent) loadUrlSeeds(); m_ui->labelCreatedByVal->setText(m_torrent->creator()); - - // List files in torrent - m_propListModel->model()->setupModelData(m_torrent->info()); - - // Expand single-item folders recursively - QModelIndex currentIndex; - while (m_propListModel->rowCount(currentIndex) == 1) - { - currentIndex = m_propListModel->index(0, 0, currentIndex); - m_ui->filesList->setExpanded(currentIndex, true); - } - - // Load file priorities - m_propListModel->model()->updateFilesPriorities(m_torrent->filePriorities()); } // Load dynamic data loadDynamicData(); @@ -536,12 +522,40 @@ void PropertiesWidget::loadDynamicData() { qDebug("Updating priorities in files tab"); m_ui->filesList->setUpdatesEnabled(false); - m_propListModel->model()->updateFilesProgress(m_torrent->filesProgress()); - m_propListModel->model()->updateFilesAvailability(m_torrent->availableFileFractions()); - // XXX: We don't update file priorities regularly for performance - // reasons. This means that priorities will not be updated if - // set from the Web UI. - // PropListModel->model()->updateFilesPriorities(h.file_priorities()); + + // Load torrent content if not yet done so + const bool isContentInitialized = m_propListModel->model()->hasIndex(0, 0); + if (!isContentInitialized) + { + // List files in torrent + m_propListModel->model()->setupModelData(m_torrent->info()); + // Load file priorities + m_propListModel->model()->updateFilesPriorities(m_torrent->filePriorities()); + // Update file progress/availability + m_propListModel->model()->updateFilesProgress(m_torrent->filesProgress()); + m_propListModel->model()->updateFilesAvailability(m_torrent->availableFileFractions()); + + // Expand single-item folders recursively. + // This will trigger sorting and filtering so do it after all relevant data is loaded. + QModelIndex currentIndex; + while (m_propListModel->rowCount(currentIndex) == 1) + { + currentIndex = m_propListModel->index(0, 0, currentIndex); + m_ui->filesList->setExpanded(currentIndex, true); + } + } + else + { + // Torrent content was loaded already, only make some updates + + m_propListModel->model()->updateFilesProgress(m_torrent->filesProgress()); + m_propListModel->model()->updateFilesAvailability(m_torrent->availableFileFractions()); + // XXX: We don't update file priorities regularly for performance + // reasons. This means that priorities will not be updated if + // set from the Web UI. + // m_propListModel->model()->updateFilesPriorities(m_torrent->filePriorities()); + } + m_ui->filesList->setUpdatesEnabled(true); } break;