Handle .!qB extension behind the scenes

PR #15920.
This commit is contained in:
Vladimir Golovnev
2022-01-08 08:45:50 +03:00
committed by GitHub
parent 9f6130cbaa
commit f44341a8e2
11 changed files with 63 additions and 105 deletions

View File

@@ -28,6 +28,7 @@
#include "previewselectdialog.h"
#include <QDir>
#include <QFile>
#include <QHeaderView>
#include <QMessageBox>
@@ -36,7 +37,6 @@
#include <QStandardItemModel>
#include <QTableView>
#include "base/bittorrent/common.h"
#include "base/bittorrent/torrent.h"
#include "base/preferences.h"
#include "base/utils/fs.h"
@@ -91,9 +91,7 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, const BitTorrent::Torr
const QVector<qreal> fp = torrent->filesProgress();
for (int i = 0; i < torrent->filesCount(); ++i)
{
QString fileName = Utils::Fs::fileName(torrent->filePath(i));
if (fileName.endsWith(QB_EXT))
fileName.chop(QB_EXT.length());
const QString fileName = Utils::Fs::fileName(torrent->filePath(i));
if (Utils::Misc::isPreviewable(fileName))
{
int row = m_previewListModel->rowCount();
@@ -128,9 +126,9 @@ void PreviewSelectDialog::previewButtonClicked()
// Flush data
m_torrent->flushCache();
const QStringList absolutePaths = m_torrent->absoluteFilePaths();
// Only one file should be selected
const QString path = absolutePaths.at(selectedIndexes.at(0).data().toInt());
const int fileIndex = selectedIndexes.at(0).data().toInt();
const QString path = QDir(m_torrent->actualStorageLocation()).absoluteFilePath(m_torrent->actualFilePath(fileIndex));
// File
if (!QFile::exists(path))
{

View File

@@ -28,7 +28,6 @@
#include "torrentcontentmodelfile.h"
#include "base/bittorrent/common.h"
#include "torrentcontentmodelfolder.h"
TorrentContentModelFile::TorrentContentModelFile(const QString &fileName, qulonglong fileSize,
@@ -39,11 +38,6 @@ TorrentContentModelFile::TorrentContentModelFile(const QString &fileName, qulong
Q_ASSERT(parent);
m_name = fileName;
// Do not display incomplete extensions
if (m_name.endsWith(QB_EXT))
m_name.chop(4);
m_size = fileSize;
}

View File

@@ -30,7 +30,6 @@
#include <QVariant>
#include "base/bittorrent/common.h"
#include "base/global.h"
TorrentContentModelFolder::TorrentContentModelFolder(const QString &name, TorrentContentModelFolder *parent)
@@ -38,9 +37,6 @@ TorrentContentModelFolder::TorrentContentModelFolder(const QString &name, Torren
{
Q_ASSERT(parent);
m_name = name;
// Do not display incomplete extensions
if (m_name.endsWith(QB_EXT))
m_name.chop(4);
}
TorrentContentModelFolder::TorrentContentModelFolder(const QVector<QString> &data)

View File

@@ -43,7 +43,6 @@
#include <QVector>
#include <QWheelEvent>
#include "base/bittorrent/common.h"
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrent.h"
#include "base/bittorrent/trackerentry.h"
@@ -93,9 +92,7 @@ namespace
for (const QString &filePath : asConst(torrent->filePaths()))
{
QString fileName = Utils::Fs::fileName(filePath);
if (fileName.endsWith(QB_EXT))
fileName.chop(QB_EXT.length());
const QString fileName = Utils::Fs::fileName(filePath);
if (Utils::Misc::isPreviewable(fileName))
return true;
}