mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
Consider explicitly specified parameters when resolving optional ones
PR #18955. Closes #18951.
This commit is contained in:
parent
58ae98026b
commit
c10f1f0ad2
3 changed files with 45 additions and 39 deletions
|
@ -2611,50 +2611,30 @@ LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &add
|
||||||
const auto defaultSavePath = suggestedSavePath(loadTorrentParams.category, addTorrentParams.useAutoTMM);
|
const auto defaultSavePath = suggestedSavePath(loadTorrentParams.category, addTorrentParams.useAutoTMM);
|
||||||
const auto defaultDownloadPath = suggestedDownloadPath(loadTorrentParams.category, addTorrentParams.useAutoTMM);
|
const auto defaultDownloadPath = suggestedDownloadPath(loadTorrentParams.category, addTorrentParams.useAutoTMM);
|
||||||
|
|
||||||
loadTorrentParams.useAutoTMM = addTorrentParams.useAutoTMM.value_or(!isAutoTMMDisabledByDefault());
|
loadTorrentParams.useAutoTMM = addTorrentParams.useAutoTMM.value_or(
|
||||||
|
addTorrentParams.savePath.isEmpty() && addTorrentParams.downloadPath.isEmpty() && !isAutoTMMDisabledByDefault());
|
||||||
|
|
||||||
if (!addTorrentParams.useAutoTMM.has_value())
|
if (!loadTorrentParams.useAutoTMM)
|
||||||
{
|
{
|
||||||
// Default TMM settings
|
if (addTorrentParams.savePath.isAbsolute())
|
||||||
|
loadTorrentParams.savePath = addTorrentParams.savePath;
|
||||||
|
else
|
||||||
|
loadTorrentParams.savePath = defaultSavePath / addTorrentParams.savePath;
|
||||||
|
|
||||||
if (!loadTorrentParams.useAutoTMM)
|
// if useDownloadPath isn't specified but downloadPath is explicitly set we prefer to use it
|
||||||
|
const bool useDownloadPath = addTorrentParams.useDownloadPath.value_or(!addTorrentParams.downloadPath.isEmpty() || isDownloadPathEnabled());
|
||||||
|
if (useDownloadPath)
|
||||||
{
|
{
|
||||||
loadTorrentParams.savePath = defaultSavePath;
|
// Overridden "Download path" settings
|
||||||
if (isDownloadPathEnabled())
|
|
||||||
loadTorrentParams.downloadPath = (!defaultDownloadPath.isEmpty() ? defaultDownloadPath : downloadPath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Overridden TMM settings
|
|
||||||
|
|
||||||
if (!loadTorrentParams.useAutoTMM)
|
if (addTorrentParams.downloadPath.isAbsolute())
|
||||||
{
|
|
||||||
if (addTorrentParams.savePath.isAbsolute())
|
|
||||||
loadTorrentParams.savePath = addTorrentParams.savePath;
|
|
||||||
else
|
|
||||||
loadTorrentParams.savePath = defaultSavePath / addTorrentParams.savePath;
|
|
||||||
|
|
||||||
if (!addTorrentParams.useDownloadPath.has_value())
|
|
||||||
{
|
{
|
||||||
// Default "Download path" settings
|
loadTorrentParams.downloadPath = addTorrentParams.downloadPath;
|
||||||
|
|
||||||
if (isDownloadPathEnabled())
|
|
||||||
loadTorrentParams.downloadPath = (!defaultDownloadPath.isEmpty() ? defaultDownloadPath : downloadPath());
|
|
||||||
}
|
}
|
||||||
else if (addTorrentParams.useDownloadPath.value())
|
else
|
||||||
{
|
{
|
||||||
// Overridden "Download path" settings
|
const Path basePath = (!defaultDownloadPath.isEmpty() ? defaultDownloadPath : downloadPath());
|
||||||
|
loadTorrentParams.downloadPath = basePath / addTorrentParams.downloadPath;
|
||||||
if (addTorrentParams.downloadPath.isAbsolute())
|
|
||||||
{
|
|
||||||
loadTorrentParams.downloadPath = addTorrentParams.downloadPath;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const Path basePath = (!defaultDownloadPath.isEmpty() ? defaultDownloadPath : downloadPath());
|
|
||||||
loadTorrentParams.downloadPath = basePath / addTorrentParams.downloadPath;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -860,6 +860,16 @@ void AddNewTorrentDialog::accept()
|
||||||
m_torrentParams.downloadPath = downloadPath;
|
m_torrentParams.downloadPath = downloadPath;
|
||||||
updatePathHistory(KEY_DOWNLOADPATHHISTORY, downloadPath, savePathHistoryLength());
|
updatePathHistory(KEY_DOWNLOADPATHHISTORY, downloadPath, savePathHistoryLength());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_torrentParams.downloadPath = Path();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_torrentParams.savePath = Path();
|
||||||
|
m_torrentParams.downloadPath = Path();
|
||||||
|
m_torrentParams.useDownloadPath = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
setEnabled(!m_ui->checkBoxNeverShow->isChecked());
|
setEnabled(!m_ui->checkBoxNeverShow->isChecked());
|
||||||
|
|
|
@ -48,12 +48,28 @@ namespace
|
||||||
Q_ASSERT(data.userType() == QMetaType::Bool);
|
Q_ASSERT(data.userType() == QMetaType::Bool);
|
||||||
return data.toBool();
|
return data.toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BitTorrent::AddTorrentParams cleanParams(BitTorrent::AddTorrentParams params)
|
||||||
|
{
|
||||||
|
if (!params.useAutoTMM.has_value() || params.useAutoTMM.value())
|
||||||
|
{
|
||||||
|
params.savePath = Path();
|
||||||
|
params.downloadPath = Path();
|
||||||
|
params.useDownloadPath = std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!params.useDownloadPath.has_value() || !params.useDownloadPath.value())
|
||||||
|
{
|
||||||
|
params.downloadPath = Path();
|
||||||
|
}
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AddTorrentParamsWidget::AddTorrentParamsWidget(BitTorrent::AddTorrentParams addTorrentParams, QWidget *parent)
|
AddTorrentParamsWidget::AddTorrentParamsWidget(BitTorrent::AddTorrentParams addTorrentParams, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, m_ui {new Ui::AddTorrentParamsWidget}
|
, m_ui {new Ui::AddTorrentParamsWidget}
|
||||||
, m_addTorrentParams {std::move(addTorrentParams)}
|
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
|
@ -110,7 +126,7 @@ AddTorrentParamsWidget::AddTorrentParamsWidget(BitTorrent::AddTorrentParams addT
|
||||||
miscParamsLayout->addWidget(m_ui->stopConditionWidget);
|
miscParamsLayout->addWidget(m_ui->stopConditionWidget);
|
||||||
miscParamsLayout->addWidget(m_ui->addToQueueTopWidget);
|
miscParamsLayout->addWidget(m_ui->addToQueueTopWidget);
|
||||||
|
|
||||||
populate();
|
setAddTorrentParams(std::move(addTorrentParams));
|
||||||
}
|
}
|
||||||
|
|
||||||
AddTorrentParamsWidget::~AddTorrentParamsWidget()
|
AddTorrentParamsWidget::~AddTorrentParamsWidget()
|
||||||
|
@ -126,7 +142,7 @@ void AddTorrentParamsWidget::setAddTorrentParams(BitTorrent::AddTorrentParams ad
|
||||||
|
|
||||||
BitTorrent::AddTorrentParams AddTorrentParamsWidget::addTorrentParams() const
|
BitTorrent::AddTorrentParams AddTorrentParamsWidget::addTorrentParams() const
|
||||||
{
|
{
|
||||||
return m_addTorrentParams;
|
return cleanParams(m_addTorrentParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddTorrentParamsWidget::populate()
|
void AddTorrentParamsWidget::populate()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue