Implement class for handling filesystem paths

PR #15915.
This commit is contained in:
Vladimir Golovnev 2022-02-08 06:03:48 +03:00 committed by GitHub
parent facfa26eed
commit dd1bd8ad10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
131 changed files with 2252 additions and 1868 deletions

View file

@ -93,12 +93,12 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, const BitTorrent::Torr
const QVector<qreal> fp = torrent->filesProgress();
for (int i = 0; i < torrent->filesCount(); ++i)
{
const QString fileName = Utils::Fs::fileName(torrent->filePath(i));
if (Utils::Misc::isPreviewable(fileName))
const Path filePath = torrent->filePath(i);
if (Utils::Misc::isPreviewable(filePath))
{
int row = m_previewListModel->rowCount();
m_previewListModel->insertRow(row);
m_previewListModel->setData(m_previewListModel->index(row, NAME), fileName);
m_previewListModel->setData(m_previewListModel->index(row, NAME), filePath.filename());
m_previewListModel->setData(m_previewListModel->index(row, SIZE), torrent->fileSize(i));
m_previewListModel->setData(m_previewListModel->index(row, PROGRESS), fp[i]);
m_previewListModel->setData(m_previewListModel->index(row, FILE_INDEX), i);
@ -133,14 +133,14 @@ void PreviewSelectDialog::previewButtonClicked()
// Only one file should be selected
const int fileIndex = selectedIndexes.at(0).data().toInt();
const QString path = QDir(m_torrent->actualStorageLocation()).absoluteFilePath(m_torrent->actualFilePath(fileIndex));
const Path path = m_torrent->actualStorageLocation() / m_torrent->actualFilePath(fileIndex);
// File
if (!QFile::exists(path))
if (!path.exists())
{
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: \"%1\".").arg(Utils::Fs::toNativePath(path)));
, tr("Sorry, we can't preview this file: \"%1\".").arg(path.toString()));
if (isSingleFile)
reject();
return;