mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 23:07:59 +00:00
Add helpers for suggesting torrent paths
This commit is contained in:
parent
d629c77184
commit
bb959bda8c
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Bittorrent Client using Qt and libtorrent.
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
* Copyright (C) 2015-2022 Vladimir Golovnev <glassez@yandex.ru>
|
* Copyright (C) 2015-2023 Vladimir Golovnev <glassez@yandex.ru>
|
||||||
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
@ -170,6 +170,9 @@ namespace BitTorrent
|
|||||||
virtual bool useCategoryPathsInManualMode() const = 0;
|
virtual bool useCategoryPathsInManualMode() const = 0;
|
||||||
virtual void setUseCategoryPathsInManualMode(bool value) = 0;
|
virtual void setUseCategoryPathsInManualMode(bool value) = 0;
|
||||||
|
|
||||||
|
virtual Path suggestedSavePath(const QString &categoryName, std::optional<bool> useAutoTMM) const = 0;
|
||||||
|
virtual Path suggestedDownloadPath(const QString &categoryName, std::optional<bool> useAutoTMM) const = 0;
|
||||||
|
|
||||||
static bool isValidTag(const QString &tag);
|
static bool isValidTag(const QString &tag);
|
||||||
virtual QSet<QString> tags() const = 0;
|
virtual QSet<QString> tags() const = 0;
|
||||||
virtual bool hasTag(const QString &tag) const = 0;
|
virtual bool hasTag(const QString &tag) const = 0;
|
||||||
|
@ -759,11 +759,13 @@ void SessionImpl::setFinishedTorrentExportDirectory(const Path &path)
|
|||||||
|
|
||||||
Path SessionImpl::savePath() const
|
Path SessionImpl::savePath() const
|
||||||
{
|
{
|
||||||
|
// TODO: Make sure it is always non-empty
|
||||||
return m_savePath;
|
return m_savePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
Path SessionImpl::downloadPath() const
|
Path SessionImpl::downloadPath() const
|
||||||
{
|
{
|
||||||
|
// TODO: Make sure it is always non-empty
|
||||||
return m_downloadPath;
|
return m_downloadPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -943,6 +945,21 @@ void SessionImpl::setUseCategoryPathsInManualMode(const bool value)
|
|||||||
m_useCategoryPathsInManualMode = value;
|
m_useCategoryPathsInManualMode = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Path SessionImpl::suggestedSavePath(const QString &categoryName, std::optional<bool> useAutoTMM) const
|
||||||
|
{
|
||||||
|
const bool useCategoryPaths = useAutoTMM.value_or(!isAutoTMMDisabledByDefault()) || useCategoryPathsInManualMode();
|
||||||
|
const auto path = (useCategoryPaths ? categorySavePath(categoryName) : savePath());
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
Path SessionImpl::suggestedDownloadPath(const QString &categoryName, std::optional<bool> useAutoTMM) const
|
||||||
|
{
|
||||||
|
const bool useCategoryPaths = useAutoTMM.value_or(!isAutoTMMDisabledByDefault()) || useCategoryPathsInManualMode();
|
||||||
|
const auto categoryDownloadPath = this->categoryDownloadPath(categoryName);
|
||||||
|
const auto path = ((useCategoryPaths && !categoryDownloadPath.isEmpty()) ? categoryDownloadPath : downloadPath());
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
QSet<QString> SessionImpl::tags() const
|
QSet<QString> SessionImpl::tags() const
|
||||||
{
|
{
|
||||||
return m_tags;
|
return m_tags;
|
||||||
@ -2576,61 +2593,39 @@ LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &add
|
|||||||
else
|
else
|
||||||
loadTorrentParams.category = category;
|
loadTorrentParams.category = category;
|
||||||
|
|
||||||
|
const auto defaultSavePath = suggestedSavePath(loadTorrentParams.category, addTorrentParams.useAutoTMM);
|
||||||
|
const auto defaultDownloadPath = suggestedDownloadPath(loadTorrentParams.category, addTorrentParams.useAutoTMM);
|
||||||
|
|
||||||
|
loadTorrentParams.useAutoTMM = addTorrentParams.useAutoTMM.value_or(!isAutoTMMDisabledByDefault());
|
||||||
|
|
||||||
if (!addTorrentParams.useAutoTMM.has_value())
|
if (!addTorrentParams.useAutoTMM.has_value())
|
||||||
{
|
{
|
||||||
// Default TMM settings
|
// Default TMM settings
|
||||||
|
|
||||||
loadTorrentParams.useAutoTMM = !isAutoTMMDisabledByDefault();
|
|
||||||
|
|
||||||
if (!loadTorrentParams.useAutoTMM)
|
if (!loadTorrentParams.useAutoTMM)
|
||||||
{
|
{
|
||||||
const bool useCategoryPaths = useCategoryPathsInManualMode();
|
loadTorrentParams.savePath = defaultSavePath;
|
||||||
const Path categorySavePath = this->categorySavePath(loadTorrentParams.category);
|
|
||||||
Q_ASSERT(!categorySavePath.isEmpty());
|
|
||||||
loadTorrentParams.savePath = (useCategoryPaths && Q_LIKELY(!categorySavePath.isEmpty()))
|
|
||||||
? categorySavePath : savePath();
|
|
||||||
|
|
||||||
if (isDownloadPathEnabled())
|
if (isDownloadPathEnabled())
|
||||||
{
|
loadTorrentParams.downloadPath = (!defaultDownloadPath.isEmpty() ? defaultDownloadPath : downloadPath());
|
||||||
const Path categoryDownloadPath = this->categoryDownloadPath(loadTorrentParams.category);
|
|
||||||
loadTorrentParams.downloadPath = (useCategoryPaths && !categoryDownloadPath.isEmpty())
|
|
||||||
? categoryDownloadPath : downloadPath();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Overridden TMM settings
|
// Overridden TMM settings
|
||||||
|
|
||||||
loadTorrentParams.useAutoTMM = addTorrentParams.useAutoTMM.value();
|
|
||||||
|
|
||||||
if (!loadTorrentParams.useAutoTMM)
|
if (!loadTorrentParams.useAutoTMM)
|
||||||
{
|
{
|
||||||
if (addTorrentParams.savePath.isAbsolute())
|
if (addTorrentParams.savePath.isAbsolute())
|
||||||
{
|
|
||||||
loadTorrentParams.savePath = addTorrentParams.savePath;
|
loadTorrentParams.savePath = addTorrentParams.savePath;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
loadTorrentParams.savePath = defaultSavePath / addTorrentParams.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!addTorrentParams.useDownloadPath.has_value())
|
if (!addTorrentParams.useDownloadPath.has_value())
|
||||||
{
|
{
|
||||||
// Default "Download path" settings
|
// Default "Download path" settings
|
||||||
|
|
||||||
if (isDownloadPathEnabled())
|
if (isDownloadPathEnabled())
|
||||||
{
|
loadTorrentParams.downloadPath = (!defaultDownloadPath.isEmpty() ? defaultDownloadPath : downloadPath());
|
||||||
const bool useCategoryPaths = useCategoryPathsInManualMode();
|
|
||||||
const Path categoryDownloadPath = this->categoryDownloadPath(loadTorrentParams.category);
|
|
||||||
loadTorrentParams.downloadPath = (useCategoryPaths && !categoryDownloadPath.isEmpty())
|
|
||||||
? categoryDownloadPath : downloadPath();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (addTorrentParams.useDownloadPath.value())
|
else if (addTorrentParams.useDownloadPath.value())
|
||||||
{
|
{
|
||||||
@ -2642,10 +2637,7 @@ LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &add
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const bool useCategoryPaths = useCategoryPathsInManualMode();
|
const Path basePath = (!defaultDownloadPath.isEmpty() ? defaultDownloadPath : downloadPath());
|
||||||
const Path categoryDownloadPath = this->categoryDownloadPath(loadTorrentParams.category);
|
|
||||||
const Path basePath = (useCategoryPaths && !categoryDownloadPath.isEmpty())
|
|
||||||
? categoryDownloadPath : downloadPath();
|
|
||||||
loadTorrentParams.downloadPath = basePath / addTorrentParams.downloadPath;
|
loadTorrentParams.downloadPath = basePath / addTorrentParams.downloadPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Bittorrent Client using Qt and libtorrent.
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
* Copyright (C) 2015-2022 Vladimir Golovnev <glassez@yandex.ru>
|
* Copyright (C) 2015-2023 Vladimir Golovnev <glassez@yandex.ru>
|
||||||
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
@ -160,6 +160,9 @@ namespace BitTorrent
|
|||||||
bool useCategoryPathsInManualMode() const override;
|
bool useCategoryPathsInManualMode() const override;
|
||||||
void setUseCategoryPathsInManualMode(bool value) override;
|
void setUseCategoryPathsInManualMode(bool value) override;
|
||||||
|
|
||||||
|
Path suggestedSavePath(const QString &categoryName, std::optional<bool> useAutoTMM) const override;
|
||||||
|
Path suggestedDownloadPath(const QString &categoryName, std::optional<bool> useAutoTMM) const override;
|
||||||
|
|
||||||
QSet<QString> tags() const override;
|
QSet<QString> tags() const override;
|
||||||
bool hasTag(const QString &tag) const override;
|
bool hasTag(const QString &tag) const override;
|
||||||
bool addTag(const QString &tag) override;
|
bool addTag(const QString &tag) override;
|
||||||
|
@ -38,6 +38,18 @@
|
|||||||
#include "torrenttagsdialog.h"
|
#include "torrenttagsdialog.h"
|
||||||
#include "ui_addtorrentparamswidget.h"
|
#include "ui_addtorrentparamswidget.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
std::optional<bool> toOptionalBool(const QVariant &data)
|
||||||
|
{
|
||||||
|
if (!data.isValid())
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
Q_ASSERT(data.userType() == QMetaType::Bool);
|
||||||
|
return data.toBool();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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}
|
||||||
@ -47,7 +59,6 @@ AddTorrentParamsWidget::AddTorrentParamsWidget(BitTorrent::AddTorrentParams addT
|
|||||||
|
|
||||||
m_ui->savePathEdit->setMode(FileSystemPathEdit::Mode::DirectorySave);
|
m_ui->savePathEdit->setMode(FileSystemPathEdit::Mode::DirectorySave);
|
||||||
m_ui->savePathEdit->setDialogCaption(tr("Choose save path"));
|
m_ui->savePathEdit->setDialogCaption(tr("Choose save path"));
|
||||||
m_ui->savePathEdit->setPlaceholder(Path(u"Default"_qs));
|
|
||||||
|
|
||||||
m_ui->downloadPathEdit->setMode(FileSystemPathEdit::Mode::DirectorySave);
|
m_ui->downloadPathEdit->setMode(FileSystemPathEdit::Mode::DirectorySave);
|
||||||
m_ui->downloadPathEdit->setDialogCaption(tr("Choose save path"));
|
m_ui->downloadPathEdit->setDialogCaption(tr("Choose save path"));
|
||||||
@ -125,11 +136,7 @@ void AddTorrentParamsWidget::populate()
|
|||||||
? m_ui->comboTTM->findData(*m_addTorrentParams.useAutoTMM) : 0);
|
? m_ui->comboTTM->findData(*m_addTorrentParams.useAutoTMM) : 0);
|
||||||
connect(m_ui->comboTTM, &QComboBox::currentIndexChanged, this, [this]
|
connect(m_ui->comboTTM, &QComboBox::currentIndexChanged, this, [this]
|
||||||
{
|
{
|
||||||
const QVariant data = m_ui->comboTTM->currentData();
|
m_addTorrentParams.useAutoTMM = toOptionalBool(m_ui->comboTTM->currentData());
|
||||||
if (!data.isValid())
|
|
||||||
m_addTorrentParams.useAutoTMM = std::nullopt;
|
|
||||||
else
|
|
||||||
m_addTorrentParams.useAutoTMM = data.toBool();
|
|
||||||
|
|
||||||
populateSavePathOptions();
|
populateSavePathOptions();
|
||||||
});
|
});
|
||||||
@ -153,9 +160,13 @@ void AddTorrentParamsWidget::populate()
|
|||||||
const auto *btSession = BitTorrent::Session::instance();
|
const auto *btSession = BitTorrent::Session::instance();
|
||||||
const bool useAutoTMM = m_addTorrentParams.useAutoTMM.value_or(!btSession->isAutoTMMDisabledByDefault());
|
const bool useAutoTMM = m_addTorrentParams.useAutoTMM.value_or(!btSession->isAutoTMMDisabledByDefault());
|
||||||
if (useAutoTMM)
|
if (useAutoTMM)
|
||||||
loadCategorySavePathOptions();
|
{
|
||||||
else
|
const auto downloadPathOption = btSession->categoryOptions(m_addTorrentParams.category).downloadPath;
|
||||||
loadCustomSavePathOptions();
|
m_ui->useDownloadPathComboBox->setCurrentIndex(downloadPathOption.has_value()
|
||||||
|
? m_ui->useDownloadPathComboBox->findData(downloadPathOption->enabled) : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
populateDefaultPaths();
|
||||||
});
|
});
|
||||||
|
|
||||||
m_ui->savePathEdit->disconnect(this);
|
m_ui->savePathEdit->disconnect(this);
|
||||||
@ -174,13 +185,9 @@ void AddTorrentParamsWidget::populate()
|
|||||||
});
|
});
|
||||||
connect(m_ui->useDownloadPathComboBox, &QComboBox::currentIndexChanged, this, [this]
|
connect(m_ui->useDownloadPathComboBox, &QComboBox::currentIndexChanged, this, [this]
|
||||||
{
|
{
|
||||||
const QVariant data = m_ui->useDownloadPathComboBox->currentData();
|
m_addTorrentParams.useDownloadPath = toOptionalBool(m_ui->useDownloadPathComboBox->currentData());
|
||||||
if (!data.isValid())
|
|
||||||
m_addTorrentParams.useDownloadPath = std::nullopt;
|
|
||||||
else
|
|
||||||
m_addTorrentParams.useDownloadPath = data.toBool();
|
|
||||||
|
|
||||||
populateDownloadPathEdit();
|
loadCustomDownloadPath();
|
||||||
});
|
});
|
||||||
|
|
||||||
m_ui->contentLayoutComboBox->disconnect(this);
|
m_ui->contentLayoutComboBox->disconnect(this);
|
||||||
@ -243,48 +250,20 @@ void AddTorrentParamsWidget::populate()
|
|||||||
|
|
||||||
void AddTorrentParamsWidget::loadCustomSavePathOptions()
|
void AddTorrentParamsWidget::loadCustomSavePathOptions()
|
||||||
{
|
{
|
||||||
const auto *btSession = BitTorrent::Session::instance();
|
[[maybe_unused]] const auto *btSession = BitTorrent::Session::instance();
|
||||||
const bool useCategoryPaths = btSession->useCategoryPathsInManualMode();
|
Q_ASSERT(!m_addTorrentParams.useAutoTMM.value_or(!btSession->isAutoTMMDisabledByDefault()));
|
||||||
|
|
||||||
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->savePathEdit->setSelectedPath(m_addTorrentParams.savePath);
|
||||||
|
|
||||||
m_ui->useDownloadPathComboBox->setCurrentIndex(m_addTorrentParams.useDownloadPath
|
m_ui->useDownloadPathComboBox->setCurrentIndex(m_addTorrentParams.useDownloadPath
|
||||||
? m_ui->useDownloadPathComboBox->findData(*m_addTorrentParams.useDownloadPath) : 0);
|
? m_ui->useDownloadPathComboBox->findData(*m_addTorrentParams.useDownloadPath) : 0);
|
||||||
|
|
||||||
populateDownloadPathEdit();
|
loadCustomDownloadPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddTorrentParamsWidget::loadCategorySavePathOptions()
|
void AddTorrentParamsWidget::loadCustomDownloadPath()
|
||||||
{
|
{
|
||||||
const auto *btSession = BitTorrent::Session::instance();
|
populateDefaultDownloadPath();
|
||||||
|
|
||||||
const Path savePath = btSession->categorySavePath(m_addTorrentParams.category);
|
|
||||||
m_ui->savePathEdit->setPlaceholder(savePath);
|
|
||||||
|
|
||||||
const Path downloadPath = btSession->categoryDownloadPath(m_addTorrentParams.category);
|
|
||||||
m_ui->downloadPathEdit->setPlaceholder(downloadPath);
|
|
||||||
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
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())
|
if (!m_addTorrentParams.useDownloadPath.has_value())
|
||||||
{
|
{
|
||||||
@ -293,9 +272,6 @@ void AddTorrentParamsWidget::populateDownloadPathEdit()
|
|||||||
m_ui->downloadPathEdit->setEnabled(false);
|
m_ui->downloadPathEdit->setEnabled(false);
|
||||||
m_ui->downloadPathEdit->blockSignals(true);
|
m_ui->downloadPathEdit->blockSignals(true);
|
||||||
m_ui->downloadPathEdit->setSelectedPath(Path());
|
m_ui->downloadPathEdit->setSelectedPath(Path());
|
||||||
|
|
||||||
const bool useDownloadPath = btSession->isDownloadPathEnabled();
|
|
||||||
m_ui->downloadPathEdit->setPlaceholder(useDownloadPath ? defaultDownloadPath : Path());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -304,7 +280,6 @@ void AddTorrentParamsWidget::populateDownloadPathEdit()
|
|||||||
const bool useDownloadPath = m_addTorrentParams.useDownloadPath.value();
|
const bool useDownloadPath = m_addTorrentParams.useDownloadPath.value();
|
||||||
if (useDownloadPath)
|
if (useDownloadPath)
|
||||||
{
|
{
|
||||||
m_ui->downloadPathEdit->setPlaceholder(defaultDownloadPath);
|
|
||||||
m_ui->downloadPathEdit->setSelectedPath(m_addTorrentParams.downloadPath);
|
m_ui->downloadPathEdit->setSelectedPath(m_addTorrentParams.downloadPath);
|
||||||
|
|
||||||
m_ui->downloadPathEdit->blockSignals(false);
|
m_ui->downloadPathEdit->blockSignals(false);
|
||||||
@ -315,12 +290,49 @@ void AddTorrentParamsWidget::populateDownloadPathEdit()
|
|||||||
m_ui->downloadPathEdit->setEnabled(false);
|
m_ui->downloadPathEdit->setEnabled(false);
|
||||||
m_ui->downloadPathEdit->blockSignals(true);
|
m_ui->downloadPathEdit->blockSignals(true);
|
||||||
|
|
||||||
m_ui->downloadPathEdit->setPlaceholder(Path());
|
|
||||||
m_ui->downloadPathEdit->setSelectedPath(Path());
|
m_ui->downloadPathEdit->setSelectedPath(Path());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddTorrentParamsWidget::loadCategorySavePathOptions()
|
||||||
|
{
|
||||||
|
const auto *btSession = BitTorrent::Session::instance();
|
||||||
|
Q_ASSERT(m_addTorrentParams.useAutoTMM.value_or(!btSession->isAutoTMMDisabledByDefault()));
|
||||||
|
|
||||||
|
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::populateDefaultPaths()
|
||||||
|
{
|
||||||
|
const auto *btSession = BitTorrent::Session::instance();
|
||||||
|
|
||||||
|
const Path defaultSavePath = btSession->suggestedSavePath(
|
||||||
|
m_ui->categoryComboBox->currentText(), toOptionalBool(m_ui->comboTTM->currentData()));
|
||||||
|
m_ui->savePathEdit->setPlaceholder(defaultSavePath);
|
||||||
|
|
||||||
|
populateDefaultDownloadPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddTorrentParamsWidget::populateDefaultDownloadPath()
|
||||||
|
{
|
||||||
|
const auto *btSession = BitTorrent::Session::instance();
|
||||||
|
|
||||||
|
const std::optional<bool> useDownloadPath = toOptionalBool(m_ui->useDownloadPathComboBox->currentData());
|
||||||
|
if (useDownloadPath.value_or(btSession->isDownloadPathEnabled()))
|
||||||
|
{
|
||||||
|
const Path defaultDownloadPath = btSession->suggestedDownloadPath(
|
||||||
|
m_ui->categoryComboBox->currentText(), toOptionalBool(m_ui->comboTTM->currentData()));
|
||||||
|
m_ui->downloadPathEdit->setPlaceholder(defaultDownloadPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_ui->downloadPathEdit->setPlaceholder(Path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AddTorrentParamsWidget::populateSavePathOptions()
|
void AddTorrentParamsWidget::populateSavePathOptions()
|
||||||
{
|
{
|
||||||
if (!m_addTorrentParams.useAutoTMM.has_value())
|
if (!m_addTorrentParams.useAutoTMM.has_value())
|
||||||
@ -328,6 +340,7 @@ void AddTorrentParamsWidget::populateSavePathOptions()
|
|||||||
// Default TMM settings
|
// Default TMM settings
|
||||||
|
|
||||||
m_ui->groupBoxSavePath->setEnabled(false);
|
m_ui->groupBoxSavePath->setEnabled(false);
|
||||||
|
m_ui->defaultsNoteLabel->setVisible(true);
|
||||||
m_ui->savePathEdit->blockSignals(true);
|
m_ui->savePathEdit->blockSignals(true);
|
||||||
m_ui->savePathEdit->setSelectedPath(Path());
|
m_ui->savePathEdit->setSelectedPath(Path());
|
||||||
m_ui->downloadPathEdit->blockSignals(true);
|
m_ui->downloadPathEdit->blockSignals(true);
|
||||||
@ -343,27 +356,8 @@ void AddTorrentParamsWidget::populateSavePathOptions()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const bool useCategoryPaths = btSession->useCategoryPathsInManualMode();
|
m_ui->useDownloadPathComboBox->setCurrentIndex(
|
||||||
|
m_ui->useDownloadPathComboBox->findData(btSession->isDownloadPathEnabled()));
|
||||||
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
|
else
|
||||||
@ -374,6 +368,7 @@ void AddTorrentParamsWidget::populateSavePathOptions()
|
|||||||
if (useAutoTMM)
|
if (useAutoTMM)
|
||||||
{
|
{
|
||||||
m_ui->groupBoxSavePath->setEnabled(false);
|
m_ui->groupBoxSavePath->setEnabled(false);
|
||||||
|
m_ui->defaultsNoteLabel->setVisible(true);
|
||||||
m_ui->savePathEdit->blockSignals(true);
|
m_ui->savePathEdit->blockSignals(true);
|
||||||
m_ui->savePathEdit->setSelectedPath(Path());
|
m_ui->savePathEdit->setSelectedPath(Path());
|
||||||
m_ui->downloadPathEdit->blockSignals(true);
|
m_ui->downloadPathEdit->blockSignals(true);
|
||||||
@ -387,8 +382,11 @@ void AddTorrentParamsWidget::populateSavePathOptions()
|
|||||||
loadCustomSavePathOptions();
|
loadCustomSavePathOptions();
|
||||||
|
|
||||||
m_ui->groupBoxSavePath->setEnabled(true);
|
m_ui->groupBoxSavePath->setEnabled(true);
|
||||||
|
m_ui->defaultsNoteLabel->setVisible(false);
|
||||||
m_ui->savePathEdit->blockSignals(false);
|
m_ui->savePathEdit->blockSignals(false);
|
||||||
m_ui->useDownloadPathComboBox->blockSignals(false);
|
m_ui->useDownloadPathComboBox->blockSignals(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
populateDefaultPaths();
|
||||||
}
|
}
|
||||||
|
@ -52,9 +52,12 @@ public:
|
|||||||
private:
|
private:
|
||||||
void populate();
|
void populate();
|
||||||
void loadCustomSavePathOptions();
|
void loadCustomSavePathOptions();
|
||||||
|
void loadCustomDownloadPath();
|
||||||
void loadCategorySavePathOptions();
|
void loadCategorySavePathOptions();
|
||||||
|
void populateDefaultPaths();
|
||||||
|
void populateDefaultDownloadPath();
|
||||||
void populateSavePathOptions();
|
void populateSavePathOptions();
|
||||||
void populateDownloadPathEdit();
|
|
||||||
|
|
||||||
Ui::AddTorrentParamsWidget *m_ui;
|
Ui::AddTorrentParamsWidget *m_ui;
|
||||||
BitTorrent::AddTorrentParams m_addTorrentParams;
|
BitTorrent::AddTorrentParams m_addTorrentParams;
|
||||||
|
@ -51,6 +51,18 @@
|
|||||||
<string>Save at</string>
|
<string>Save at</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="defaultsNoteLabel">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<italic>true</italic>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Note: the current defaults are displayed for reference.</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="FileSystemPathLineEdit" name="savePathEdit" native="true"/>
|
<widget class="FileSystemPathLineEdit" name="savePathEdit" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
@ -113,7 +125,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer_7">
|
<spacer name="categorySpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
Loading…
Reference in New Issue
Block a user