Implement class for handling filesystem paths

PR #15915.
This commit is contained in:
Vladimir Golovnev
2022-02-08 06:03:48 +03:00
committed by GitHub
parent facfa26eed
commit dd1bd8ad10
131 changed files with 2252 additions and 1868 deletions

View File

@@ -153,7 +153,7 @@ void TorrentCategoryDialog::setCategoryOptions(const BitTorrent::CategoryOptions
if (categoryOptions.downloadPath)
{
m_ui->comboUseDownloadPath->setCurrentIndex(categoryOptions.downloadPath->enabled ? 1 : 2);
m_ui->comboDownloadPath->setSelectedPath(categoryOptions.downloadPath->enabled ? categoryOptions.downloadPath->path : QString());
m_ui->comboDownloadPath->setSelectedPath(categoryOptions.downloadPath->enabled ? categoryOptions.downloadPath->path : Path());
}
else
{
@@ -164,30 +164,29 @@ void TorrentCategoryDialog::setCategoryOptions(const BitTorrent::CategoryOptions
void TorrentCategoryDialog::categoryNameChanged(const QString &categoryName)
{
const QString categoryPath = Utils::Fs::toValidFileSystemName(categoryName, true);
const Path categoryPath = Utils::Fs::toValidPath(categoryName);
const auto *btSession = BitTorrent::Session::instance();
m_ui->comboSavePath->setPlaceholder(Utils::Fs::resolvePath(categoryPath, btSession->savePath()));
m_ui->comboSavePath->setPlaceholder(btSession->savePath() / categoryPath);
const int index = m_ui->comboUseDownloadPath->currentIndex();
const bool useDownloadPath = (index == 1) || ((index == 0) && BitTorrent::Session::instance()->isDownloadPathEnabled());
if (useDownloadPath)
m_ui->comboDownloadPath->setPlaceholder(Utils::Fs::resolvePath(categoryPath, btSession->downloadPath()));
m_ui->comboDownloadPath->setPlaceholder(btSession->downloadPath() / categoryPath);
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!categoryName.isEmpty());
}
void TorrentCategoryDialog::useDownloadPathChanged(const int index)
{
if (const QString selectedPath = m_ui->comboDownloadPath->selectedPath(); !selectedPath.isEmpty())
if (const Path selectedPath = m_ui->comboDownloadPath->selectedPath(); !selectedPath.isEmpty())
m_lastEnteredDownloadPath = selectedPath;
m_ui->labelDownloadPath->setEnabled(index == 1);
m_ui->comboDownloadPath->setEnabled(index == 1);
m_ui->comboDownloadPath->setSelectedPath((index == 1) ? m_lastEnteredDownloadPath : QString());
m_ui->comboDownloadPath->setSelectedPath((index == 1) ? m_lastEnteredDownloadPath : Path());
const QString categoryName = m_ui->textCategoryName->text();
const QString categoryPath = Utils::Fs::resolvePath(Utils::Fs::toValidFileSystemName(categoryName, true)
, BitTorrent::Session::instance()->downloadPath());
const Path categoryPath = BitTorrent::Session::instance()->downloadPath() / Utils::Fs::toValidPath(categoryName);
const bool useDownloadPath = (index == 1) || ((index == 0) && BitTorrent::Session::instance()->isDownloadPathEnabled());
m_ui->comboDownloadPath->setPlaceholder(useDownloadPath ? categoryPath : QString());
m_ui->comboDownloadPath->setPlaceholder(useDownloadPath ? categoryPath : Path());
}