Browse Source

Override add torrent params in a more comprehensible way

adaptive-webui-19844
Vladimir Golovnev (Glassez) 2 years ago
parent
commit
6fa53b5ed8
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 58
      src/base/bittorrent/sessionimpl.cpp
  2. 107
      src/gui/addtorrentparamswidget.cpp

58
src/base/bittorrent/sessionimpl.cpp

@ -2560,7 +2560,6 @@ LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &add @@ -2560,7 +2560,6 @@ LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &add
LoadTorrentParams loadTorrentParams;
loadTorrentParams.name = addTorrentParams.name;
loadTorrentParams.useAutoTMM = addTorrentParams.useAutoTMM.value_or(!isAutoTMMDisabledByDefault());
loadTorrentParams.firstLastPiecePriority = addTorrentParams.firstLastPiecePriority;
loadTorrentParams.hasFinishedStatus = addTorrentParams.skipChecking; // do not react on 'torrent_finished_alert' when skipping
loadTorrentParams.contentLayout = addTorrentParams.contentLayout.value_or(torrentContentLayout());
@ -2577,6 +2576,34 @@ LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &add @@ -2577,6 +2576,34 @@ LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &add
else
loadTorrentParams.category = category;
if (!addTorrentParams.useAutoTMM.has_value())
{
// Default TMM settings
loadTorrentParams.useAutoTMM = !isAutoTMMDisabledByDefault();
if (!loadTorrentParams.useAutoTMM)
{
const bool useCategoryPaths = useCategoryPathsInManualMode();
const Path categorySavePath = this->categorySavePath(loadTorrentParams.category);
Q_ASSERT(!categorySavePath.isEmpty());
loadTorrentParams.savePath = (useCategoryPaths && Q_LIKELY(!categorySavePath.isEmpty()))
? categorySavePath : savePath();
if (isDownloadPathEnabled())
{
const Path categoryDownloadPath = this->categoryDownloadPath(loadTorrentParams.category);
loadTorrentParams.downloadPath = (useCategoryPaths && !categoryDownloadPath.isEmpty())
? categoryDownloadPath : downloadPath();
}
}
}
else
{
// Overridden TMM settings
loadTorrentParams.useAutoTMM = addTorrentParams.useAutoTMM.value();
if (!loadTorrentParams.useAutoTMM)
{
if (addTorrentParams.savePath.isAbsolute())
@ -2585,24 +2612,45 @@ LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &add @@ -2585,24 +2612,45 @@ LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &add
}
else
{
const Path basePath = useCategoryPathsInManualMode() ? categorySavePath(loadTorrentParams.category) : savePath();
const bool useCategoryPaths = useCategoryPathsInManualMode();
const Path categorySavePath = this->categorySavePath(loadTorrentParams.category);
Q_ASSERT(!categorySavePath.isEmpty());
const Path basePath = (useCategoryPaths && Q_LIKELY(!categorySavePath.isEmpty()))
? categorySavePath : savePath();
loadTorrentParams.savePath = basePath / addTorrentParams.savePath;
}
const bool useDownloadPath = addTorrentParams.useDownloadPath.value_or(isDownloadPathEnabled());
if (useDownloadPath)
if (!addTorrentParams.useDownloadPath.has_value())
{
// Default "Download path" settings
if (isDownloadPathEnabled())
{
const bool useCategoryPaths = useCategoryPathsInManualMode();
const Path categoryDownloadPath = this->categoryDownloadPath(loadTorrentParams.category);
loadTorrentParams.downloadPath = (useCategoryPaths && !categoryDownloadPath.isEmpty())
? categoryDownloadPath : downloadPath();
}
}
else if (addTorrentParams.useDownloadPath.value())
{
// Overridden "Download path" settings
if (addTorrentParams.downloadPath.isAbsolute())
{
loadTorrentParams.downloadPath = addTorrentParams.downloadPath;
}
else
{
const Path basePath = useCategoryPathsInManualMode() ? categoryDownloadPath(loadTorrentParams.category) : downloadPath();
const bool useCategoryPaths = useCategoryPathsInManualMode();
const Path categoryDownloadPath = this->categoryDownloadPath(loadTorrentParams.category);
const Path basePath = (useCategoryPaths && !categoryDownloadPath.isEmpty())
? categoryDownloadPath : downloadPath();
loadTorrentParams.downloadPath = basePath / addTorrentParams.downloadPath;
}
}
}
}
for (const QString &tag : addTorrentParams.tags)
{

107
src/gui/addtorrentparamswidget.cpp

@ -151,7 +151,13 @@ void AddTorrentParamsWidget::populate() @@ -151,7 +151,13 @@ void AddTorrentParamsWidget::populate()
connect(m_ui->categoryComboBox, &QComboBox::currentIndexChanged, this, [this]
{
m_addTorrentParams.category = m_ui->categoryComboBox->currentText();
const auto *btSession = BitTorrent::Session::instance();
const bool useAutoTMM = m_addTorrentParams.useAutoTMM.value_or(!btSession->isAutoTMMDisabledByDefault());
if (useAutoTMM)
loadCategorySavePathOptions();
else
loadCustomSavePathOptions();
});
m_ui->savePathEdit->disconnect(this);
@ -241,9 +247,13 @@ void AddTorrentParamsWidget::populate() @@ -241,9 +247,13 @@ void AddTorrentParamsWidget::populate()
void AddTorrentParamsWidget::loadCustomSavePathOptions()
{
const auto *btSession = BitTorrent::Session::instance();
const bool useCategoryPaths = btSession->useCategoryPathsInManualMode();
const Path defaultSavePath = btSession->savePath();
m_ui->savePathEdit->setSelectedPath(!m_addTorrentParams.savePath.isEmpty() ? m_addTorrentParams.savePath : defaultSavePath);
const Path categorySavePath = btSession->categorySavePath(m_addTorrentParams.category);
const Path defaultSavePath = (useCategoryPaths && !categorySavePath.isEmpty())
? categorySavePath : btSession->savePath();
m_ui->savePathEdit->setPlaceholder(defaultSavePath);
m_ui->savePathEdit->setSelectedPath(m_addTorrentParams.savePath);
m_ui->useDownloadPathComboBox->setCurrentIndex(m_addTorrentParams.useDownloadPath
? m_ui->useDownloadPathComboBox->findData(*m_addTorrentParams.useDownloadPath) : 0);
@ -256,19 +266,48 @@ void AddTorrentParamsWidget::loadCategorySavePathOptions() @@ -256,19 +266,48 @@ void AddTorrentParamsWidget::loadCategorySavePathOptions()
const auto *btSession = BitTorrent::Session::instance();
const Path savePath = btSession->categorySavePath(m_addTorrentParams.category);
m_ui->savePathEdit->setSelectedPath(savePath);
m_ui->savePathEdit->setPlaceholder(savePath);
const Path downloadPath = btSession->categoryDownloadPath(m_addTorrentParams.category);
m_ui->downloadPathEdit->setSelectedPath(downloadPath);
m_ui->downloadPathEdit->setPlaceholder(downloadPath);
m_ui->useDownloadPathComboBox->setCurrentIndex(m_ui->useDownloadPathComboBox->findData(!downloadPath.isEmpty()));
const bool useAutoTMM = m_addTorrentParams.useAutoTMM.value_or(!btSession->isAutoTMMDisabledByDefault());
if (useAutoTMM)
{
const auto downloadPathOption = btSession->categoryOptions(m_addTorrentParams.category).downloadPath;
m_ui->useDownloadPathComboBox->setCurrentIndex(downloadPathOption.has_value()
? m_ui->useDownloadPathComboBox->findData(downloadPathOption->enabled) : 0);
}
}
void AddTorrentParamsWidget::populateDownloadPathEdit()
{
if (m_addTorrentParams.useDownloadPath.value_or(true))
const auto *btSession = BitTorrent::Session::instance();
const bool useCategoryPaths = btSession->useCategoryPathsInManualMode();
const Path categoryDownloadPath = btSession->categoryDownloadPath(m_addTorrentParams.category);
const Path defaultDownloadPath = (useCategoryPaths && !categoryDownloadPath.isEmpty())
? categoryDownloadPath : btSession->downloadPath();
if (!m_addTorrentParams.useDownloadPath.has_value())
{
m_ui->downloadPathEdit->setPlaceholder(Path(u"Default"_qs));
// Default "Download path" settings
m_ui->downloadPathEdit->setEnabled(false);
m_ui->downloadPathEdit->blockSignals(true);
m_ui->downloadPathEdit->setSelectedPath(Path());
const bool useDownloadPath = btSession->isDownloadPathEnabled();
m_ui->downloadPathEdit->setPlaceholder(useDownloadPath ? defaultDownloadPath : Path());
}
else
{
// Overridden "Download path" settings
const bool useDownloadPath = m_addTorrentParams.useDownloadPath.value();
if (useDownloadPath)
{
m_ui->downloadPathEdit->setPlaceholder(defaultDownloadPath);
m_ui->downloadPathEdit->setSelectedPath(m_addTorrentParams.downloadPath);
m_ui->downloadPathEdit->blockSignals(false);
@ -283,15 +322,66 @@ void AddTorrentParamsWidget::populateDownloadPathEdit() @@ -283,15 +322,66 @@ void AddTorrentParamsWidget::populateDownloadPathEdit()
m_ui->downloadPathEdit->setSelectedPath(Path());
}
}
}
void AddTorrentParamsWidget::populateSavePathOptions()
{
if (m_addTorrentParams.useAutoTMM.value_or(false))
if (!m_addTorrentParams.useAutoTMM.has_value())
{
// Default TMM settings
m_ui->groupBoxSavePath->setEnabled(false);
m_ui->savePathEdit->blockSignals(true);
m_ui->savePathEdit->setSelectedPath(Path());
m_ui->downloadPathEdit->blockSignals(true);
m_ui->useDownloadPathComboBox->blockSignals(true);
m_ui->downloadPathEdit->setSelectedPath(Path());
const auto *btSession = BitTorrent::Session::instance();
const bool useAutoTMM = !btSession->isAutoTMMDisabledByDefault();
if (useAutoTMM)
{
loadCategorySavePathOptions();
}
else
{
const bool useCategoryPaths = btSession->useCategoryPathsInManualMode();
const Path categorySavePath = btSession->categorySavePath(m_addTorrentParams.category);
Q_ASSERT(!categorySavePath.isEmpty());
const Path defaultSavePath = (useCategoryPaths && Q_LIKELY(!categorySavePath.isEmpty()))
? categorySavePath : btSession->savePath();
m_ui->savePathEdit->setPlaceholder(defaultSavePath);
const bool useDownloadPath = btSession->isDownloadPathEnabled();
m_ui->useDownloadPathComboBox->setCurrentIndex(0);
if (useDownloadPath)
{
const Path categoryDownloadPath = btSession->categoryDownloadPath(m_addTorrentParams.category);
const Path defaultDownloadPath = (useCategoryPaths && !categoryDownloadPath.isEmpty())
? categoryDownloadPath : btSession->downloadPath();
m_ui->downloadPathEdit->setPlaceholder(defaultDownloadPath);
}
else
{
m_ui->downloadPathEdit->setPlaceholder(Path());
}
}
}
else
{
// Overridden TMM settings
const bool useAutoTMM = m_addTorrentParams.useAutoTMM.value();
if (useAutoTMM)
{
m_ui->groupBoxSavePath->setEnabled(false);
m_ui->savePathEdit->blockSignals(true);
m_ui->savePathEdit->setSelectedPath(Path());
m_ui->downloadPathEdit->blockSignals(true);
m_ui->useDownloadPathComboBox->blockSignals(true);
m_ui->downloadPathEdit->setSelectedPath(Path());
loadCategorySavePathOptions();
}
@ -304,3 +394,4 @@ void AddTorrentParamsWidget::populateSavePathOptions() @@ -304,3 +394,4 @@ void AddTorrentParamsWidget::populateSavePathOptions()
m_ui->useDownloadPathComboBox->blockSignals(false);
}
}
}

Loading…
Cancel
Save