mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-31 12:48:04 -06:00
Revamp content layout handling
Apply content layout only if desired file names aren't provided. Remove helpers with confusing signatures. Don't remove root folder twice. PR #16724. Closes #16259.
This commit is contained in:
committed by
GitHub
parent
eecd221d40
commit
df2d449f9b
@@ -256,6 +256,38 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP
|
||||
m_ui->categoryComboBox->setFocus();
|
||||
}
|
||||
|
||||
void AddNewTorrentDialog::applyContentLayout()
|
||||
{
|
||||
Q_ASSERT(hasMetadata());
|
||||
Q_ASSERT(!m_torrentParams.filePaths.isEmpty());
|
||||
|
||||
const auto originalContentLayout = (m_originalRootFolder.isEmpty()
|
||||
? BitTorrent::TorrentContentLayout::NoSubfolder
|
||||
: BitTorrent::TorrentContentLayout::Subfolder);
|
||||
const int currentIndex = m_ui->contentLayoutComboBox->currentIndex();
|
||||
const auto contentLayout = ((currentIndex == 0)
|
||||
? originalContentLayout
|
||||
: static_cast<BitTorrent::TorrentContentLayout>(currentIndex));
|
||||
if (contentLayout != m_currentContentLayout)
|
||||
{
|
||||
PathList &filePaths = m_torrentParams.filePaths;
|
||||
|
||||
if (contentLayout == BitTorrent::TorrentContentLayout::NoSubfolder)
|
||||
{
|
||||
Path::stripRootFolder(filePaths);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto rootFolder = ((originalContentLayout == BitTorrent::TorrentContentLayout::Subfolder)
|
||||
? m_originalRootFolder
|
||||
: filePaths.at(0).removedExtension());
|
||||
Path::addRootFolder(filePaths, rootFolder);
|
||||
}
|
||||
|
||||
m_currentContentLayout = contentLayout;
|
||||
}
|
||||
}
|
||||
|
||||
AddNewTorrentDialog::~AddNewTorrentDialog()
|
||||
{
|
||||
saveState();
|
||||
@@ -538,7 +570,7 @@ void AddNewTorrentDialog::categoryChanged(int index)
|
||||
}
|
||||
}
|
||||
|
||||
void AddNewTorrentDialog::contentLayoutChanged(const int index)
|
||||
void AddNewTorrentDialog::contentLayoutChanged()
|
||||
{
|
||||
if (!hasMetadata())
|
||||
return;
|
||||
@@ -546,11 +578,8 @@ void AddNewTorrentDialog::contentLayoutChanged(const int index)
|
||||
const auto filePriorities = m_contentModel->model()->getFilePriorities();
|
||||
m_contentModel->model()->clear();
|
||||
|
||||
Q_ASSERT(!m_torrentParams.filePaths.isEmpty());
|
||||
const auto contentLayout = ((index == 0)
|
||||
? BitTorrent::detectContentLayout(m_torrentInfo.filePaths())
|
||||
: static_cast<BitTorrent::TorrentContentLayout>(index));
|
||||
BitTorrent::applyContentLayout(m_torrentParams.filePaths, contentLayout, Path::findRootFolder(m_torrentInfo.filePaths()));
|
||||
applyContentLayout();
|
||||
|
||||
m_contentModel->model()->setupModelData(FileStorageAdaptor(m_torrentInfo, m_torrentParams.filePaths));
|
||||
m_contentModel->model()->updateFilesPriorities(filePriorities);
|
||||
|
||||
@@ -905,12 +934,16 @@ void AddNewTorrentDialog::setupTreeview()
|
||||
connect(m_ui->buttonSelectAll, &QPushButton::clicked, m_contentModel, &TorrentContentFilterModel::selectAll);
|
||||
connect(m_ui->buttonSelectNone, &QPushButton::clicked, m_contentModel, &TorrentContentFilterModel::selectNone);
|
||||
|
||||
const auto contentLayout = ((m_ui->contentLayoutComboBox->currentIndex() == 0)
|
||||
? BitTorrent::detectContentLayout(m_torrentInfo.filePaths())
|
||||
: static_cast<BitTorrent::TorrentContentLayout>(m_ui->contentLayoutComboBox->currentIndex()));
|
||||
|
||||
if (m_torrentParams.filePaths.isEmpty())
|
||||
m_torrentParams.filePaths = m_torrentInfo.filePaths();
|
||||
BitTorrent::applyContentLayout(m_torrentParams.filePaths, contentLayout, Path::findRootFolder(m_torrentInfo.filePaths()));
|
||||
|
||||
m_originalRootFolder = Path::findRootFolder(m_torrentInfo.filePaths());
|
||||
m_currentContentLayout = (m_originalRootFolder.isEmpty()
|
||||
? BitTorrent::TorrentContentLayout::NoSubfolder
|
||||
: BitTorrent::TorrentContentLayout::Subfolder);
|
||||
applyContentLayout();
|
||||
|
||||
// List files in torrent
|
||||
m_contentModel->model()->setupModelData(FileStorageAdaptor(m_torrentInfo, m_torrentParams.filePaths));
|
||||
if (const QByteArray state = m_storeTreeHeaderState; !state.isEmpty())
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "base/bittorrent/addtorrentparams.h"
|
||||
#include "base/bittorrent/magneturi.h"
|
||||
#include "base/bittorrent/torrentinfo.h"
|
||||
#include "base/path.h"
|
||||
#include "base/settingvalue.h"
|
||||
|
||||
namespace BitTorrent
|
||||
@@ -88,7 +89,7 @@ private slots:
|
||||
void handleDownloadFinished(const Net::DownloadResult &downloadResult);
|
||||
void TMMChanged(int index);
|
||||
void categoryChanged(int index);
|
||||
void contentLayoutChanged(int index);
|
||||
void contentLayoutChanged();
|
||||
void doNotDeleteTorrentClicked(bool checked);
|
||||
void renameSelectedFile();
|
||||
|
||||
@@ -97,6 +98,8 @@ private slots:
|
||||
|
||||
private:
|
||||
explicit AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inParams, QWidget *parent);
|
||||
|
||||
void applyContentLayout();
|
||||
bool loadTorrentFile(const QString &source);
|
||||
bool loadTorrentImpl();
|
||||
bool loadMagnet(const BitTorrent::MagnetUri &magnetUri);
|
||||
@@ -115,6 +118,8 @@ private:
|
||||
PropListDelegate *m_contentDelegate = nullptr;
|
||||
BitTorrent::MagnetUri m_magnetURI;
|
||||
BitTorrent::TorrentInfo m_torrentInfo;
|
||||
Path m_originalRootFolder;
|
||||
BitTorrent::TorrentContentLayout m_currentContentLayout;
|
||||
int m_savePathIndex = -1;
|
||||
int m_downloadPathIndex = -1;
|
||||
bool m_useDownloadPath = false;
|
||||
|
||||
Reference in New Issue
Block a user