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. 78
      src/base/bittorrent/sessionimpl.cpp
  2. 133
      src/gui/addtorrentparamswidget.cpp

78
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,29 +2576,78 @@ LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &add @@ -2577,29 +2576,78 @@ LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &add
else
loadTorrentParams.category = category;
if (!loadTorrentParams.useAutoTMM)
if (!addTorrentParams.useAutoTMM.has_value())
{
if (addTorrentParams.savePath.isAbsolute())
{
loadTorrentParams.savePath = addTorrentParams.savePath;
}
else
// Default TMM settings
loadTorrentParams.useAutoTMM = !isAutoTMMDisabledByDefault();
if (!loadTorrentParams.useAutoTMM)
{
const Path basePath = useCategoryPathsInManualMode() ? categorySavePath(loadTorrentParams.category) : savePath();
loadTorrentParams.savePath = basePath / addTorrentParams.savePath;
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();
const bool useDownloadPath = addTorrentParams.useDownloadPath.value_or(isDownloadPathEnabled());
if (useDownloadPath)
if (!loadTorrentParams.useAutoTMM)
{
if (addTorrentParams.downloadPath.isAbsolute())
if (addTorrentParams.savePath.isAbsolute())
{
loadTorrentParams.downloadPath = addTorrentParams.downloadPath;
loadTorrentParams.savePath = addTorrentParams.savePath;
}
else
{
const Path basePath = useCategoryPathsInManualMode() ? categoryDownloadPath(loadTorrentParams.category) : downloadPath();
loadTorrentParams.downloadPath = basePath / addTorrentParams.downloadPath;
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;
}
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 bool useCategoryPaths = useCategoryPathsInManualMode();
const Path categoryDownloadPath = this->categoryDownloadPath(loadTorrentParams.category);
const Path basePath = (useCategoryPaths && !categoryDownloadPath.isEmpty())
? categoryDownloadPath : downloadPath();
loadTorrentParams.downloadPath = basePath / addTorrentParams.downloadPath;
}
}
}
}

133
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();
loadCategorySavePathOptions();
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,51 +266,132 @@ void AddTorrentParamsWidget::loadCategorySavePathOptions() @@ -256,51 +266,132 @@ 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));
m_ui->downloadPathEdit->setSelectedPath(m_addTorrentParams.downloadPath);
// Default "Download path" settings
m_ui->downloadPathEdit->blockSignals(false);
m_ui->downloadPathEdit->setEnabled(true);
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
{
m_ui->downloadPathEdit->setEnabled(false);
m_ui->downloadPathEdit->blockSignals(true);
// Overridden "Download path" settings
m_ui->downloadPathEdit->setPlaceholder(Path());
m_ui->downloadPathEdit->setSelectedPath(Path());
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);
m_ui->downloadPathEdit->setEnabled(true);
}
else
{
m_ui->downloadPathEdit->setEnabled(false);
m_ui->downloadPathEdit->blockSignals(true);
m_ui->downloadPathEdit->setPlaceholder(Path());
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();
loadCategorySavePathOptions();
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
{
loadCustomSavePathOptions();
// 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();
}
else
{
loadCustomSavePathOptions();
m_ui->groupBoxSavePath->setEnabled(true);
m_ui->savePathEdit->blockSignals(false);
m_ui->useDownloadPathComboBox->blockSignals(false);
m_ui->groupBoxSavePath->setEnabled(true);
m_ui->savePathEdit->blockSignals(false);
m_ui->useDownloadPathComboBox->blockSignals(false);
}
}
}

Loading…
Cancel
Save