Skip to content

Commit 32cd498

Browse files
committed
Make options independent
1 parent ec2b417 commit 32cd498

4 files changed

Lines changed: 27 additions & 33 deletions

File tree

src/base/bittorrent/sessionimpl.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,7 +2651,7 @@ bool SessionImpl::removeTorrent(const TorrentID &id, const TorrentRemoveOption d
26512651
// Remove it from torrent resume directory
26522652
m_resumeDataStorage->remove(torrentID);
26532653

2654-
if (isTorrentFileBackupEnabled() && removeTorrentFileBackup())
2654+
if (removeTorrentFileBackup())
26552655
{
26562656
const QString torrentBackupInfo = m_backupTorrentFilesRegistry->fetchValue(torrent->id().toString()).takeResult().toString();
26572657
if (!torrentBackupInfo.isEmpty() && !torrentBackupInfo.startsWith(u"magnet:", Qt::CaseInsensitive))
@@ -5527,11 +5527,6 @@ void SessionImpl::handleTorrentFinished(TorrentImpl *const torrent)
55275527
{
55285528
m_pendingFinishedTorrents.append(torrent);
55295529

5530-
if (!isTorrentFileBackupEnabled())
5531-
return;
5532-
5533-
const bool needMoveBackup = isFinishedTorrentBackupDirectoryEnabled();
5534-
const Path backupDirPath = resolvePath((needMoveBackup ? finishedTorrentBackupDirectory() : torrentBackupDirectory()), specialFolderLocation(SpecialFolder::Data));
55355530
const QString torrentBackupInfo = m_backupTorrentFilesRegistry->fetchValue(torrent->id().toString()).takeResult().toString();
55365531
if (torrentBackupInfo.isEmpty())
55375532
return;
@@ -5540,10 +5535,17 @@ void SessionImpl::handleTorrentFinished(TorrentImpl *const torrent)
55405535

55415536
if (torrentBackupInfo.startsWith(u"magnet:", Qt::CaseInsensitive))
55425537
{
5543-
backupTorrentFile(torrent, torrentBackupInfo, backupDirPath);
5538+
if (isTorrentFileBackupEnabled())
5539+
{
5540+
const Path backupDirPath = resolvePath(
5541+
(isFinishedTorrentBackupDirectoryEnabled() ? finishedTorrentBackupDirectory() : torrentBackupDirectory())
5542+
, specialFolderLocation(SpecialFolder::Data));
5543+
backupTorrentFile(torrent, torrentBackupInfo, backupDirPath);
5544+
}
55445545
}
5545-
else if (needMoveBackup)
5546+
else if (isFinishedTorrentBackupDirectoryEnabled())
55465547
{
5548+
const Path backupDirPath = resolvePath(finishedTorrentBackupDirectory(), specialFolderLocation(SpecialFolder::Data));
55475549
const Path oldTorrentBackupPath {torrentBackupInfo};
55485550
if (backupDirPath != oldTorrentBackupPath.parentPath())
55495551
{

src/gui/optionsdialog.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,17 +593,19 @@ void OptionsDialog::loadDownloadsTabOptions()
593593
m_ui->checkConfirmMergeTrackers->setChecked(m_ui->checkConfirmMergeTrackers->isEnabled() ? pref->confirmMergeTrackers() : false);
594594
});
595595

596+
m_ui->backupDirCheckBox->setChecked(session->isTorrentFileBackupEnabled());
596597
m_ui->backupDirPathEdit->setDialogCaption(tr("Choose backup directory"));
597598
m_ui->backupDirPathEdit->setMode(FileSystemPathEdit::Mode::DirectorySave);
598599
m_ui->backupDirPathEdit->setBasePath(specialFolderLocation(SpecialFolder::Data));
599600
m_ui->backupDirPathEdit->setSelectedPath(session->torrentBackupDirectory());
601+
m_ui->backupDirPathEdit->setEnabled(m_ui->backupDirCheckBox->isChecked());
600602
m_ui->finishedBackupDirCheckBox->setChecked(session->isFinishedTorrentBackupDirectoryEnabled());
601603
m_ui->finishedBackupDirPathEdit->setDialogCaption(tr("Choose backup directory"));
602604
m_ui->finishedBackupDirPathEdit->setMode(FileSystemPathEdit::Mode::DirectorySave);
603605
m_ui->finishedBackupDirPathEdit->setBasePath(specialFolderLocation(SpecialFolder::Data));
604606
m_ui->finishedBackupDirPathEdit->setSelectedPath(session->finishedTorrentBackupDirectory());
607+
m_ui->finishedBackupDirPathEdit->setEnabled(m_ui->finishedBackupDirCheckBox->isChecked());
605608
m_ui->removeBackupTorrentFileCheckBox->setChecked(session->removeTorrentFileBackup());
606-
m_ui->backupTorrentFileGroupBox->setChecked(session->isTorrentFileBackupEnabled());
607609

608610
const TorrentFileGuard::AutoDeleteMode autoDeleteMode = TorrentFileGuard::autoDeleteMode();
609611
m_ui->deleteTorrentBox->setChecked(autoDeleteMode != TorrentFileGuard::Never);
@@ -748,7 +750,8 @@ void OptionsDialog::loadDownloadsTabOptions()
748750
connect(m_ui->checkMergeTrackers, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
749751
connect(m_ui->checkConfirmMergeTrackers, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
750752

751-
connect(m_ui->backupTorrentFileGroupBox, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
753+
connect(m_ui->backupDirCheckBox, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
754+
connect(m_ui->backupDirCheckBox, &QAbstractButton::toggled, m_ui->backupDirPathEdit, &QWidget::setEnabled);
752755
connect(m_ui->finishedBackupDirCheckBox, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
753756
connect(m_ui->finishedBackupDirCheckBox, &QAbstractButton::toggled, m_ui->finishedBackupDirPathEdit, &QWidget::setEnabled);
754757
connect(m_ui->backupDirPathEdit, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
@@ -820,7 +823,7 @@ void OptionsDialog::saveDownloadsTabOptions() const
820823
session->setAddTorrentStopped(addTorrentsStopped());
821824
session->setTorrentStopCondition(m_ui->stopConditionComboBox->currentData().value<BitTorrent::Torrent::StopCondition>());
822825

823-
session->setTorrentFileBackupEnabled(m_ui->backupTorrentFileGroupBox->isChecked());
826+
session->setTorrentFileBackupEnabled(m_ui->backupDirCheckBox->isChecked());
824827
session->setTorrentBackupDirectory(m_ui->backupDirPathEdit->selectedPath());
825828
session->setFinishedTorrentBackupDirectoryEnabled(m_ui->finishedBackupDirCheckBox->isChecked());
826829
session->setFinishedTorrentBackupDirectory(m_ui->finishedBackupDirPathEdit->selectedPath());

src/gui/optionsdialog.ui

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,15 +1140,9 @@
11401140
<property name="title">
11411141
<string>Store backup .torrent file</string>
11421142
</property>
1143-
<property name="checkable">
1144-
<bool>true</bool>
1145-
</property>
1146-
<property name="checked">
1147-
<bool>false</bool>
1148-
</property>
11491143
<layout class="QGridLayout" name="backupTorrentFileLayout">
11501144
<item row="0" column="0">
1151-
<widget class="QLabel" name="backupDirLabel">
1145+
<widget class="QCheckBox" name="backupDirCheckBox">
11521146
<property name="text">
11531147
<string>Store backup in:</string>
11541148
</property>

src/webui/www/private/views/preferences.html

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,17 @@
190190
</fieldset>
191191
<fieldset class="settings">
192192
<legend>
193-
<input type="checkbox" id="torrent_backup_checkbox" onclick="qBittorrent.Preferences.updateTorrentBackupControls();">
194-
<label for="torrent_backup_checkbox">QBT_TR(Store backup .torrent file)QBT_TR[CONTEXT=OptionsDialog]</label>
193+
<label>QBT_TR(Store backup .torrent file)QBT_TR[CONTEXT=OptionsDialog]</label>
195194
</legend>
196195
<table id="torrent_backup_settings">
197196
<tbody>
198197
<tr>
199198
<td>
200-
<label id="backupDirLabel" for="torrent_backup_dir">QBT_TR(Store backup in:)QBT_TR[CONTEXT=OptionsDialog]</label>
199+
<input type="checkbox" id="torrent_backup_dir_checkbox" onclick="qBittorrent.Preferences.updateTorrentBackupControls();">
200+
<label id="backupDirLabel" for="torrent_backup_dir_checkbox">QBT_TR(Store backup in:)QBT_TR[CONTEXT=OptionsDialog]</label>
201201
</td>
202202
<td>
203-
<input type="text" id="torrent_backup_dir" class="pathDirectory" autocorrect="off" autocapitalize="none" aria-labelledby="backupDirLabel">
203+
<input type="text" id="torrent_backup_dir" class="pathDirectory" style="width: 30em;" autocorrect="off" autocapitalize="none" aria-labelledby="backupDirLabel">
204204
</td>
205205
</tr>
206206
<tr>
@@ -209,7 +209,7 @@
209209
<label id="backupDirFinLabel" for="torrent_backup_findir_checkbox">QBT_TR(When torrent finished move backup to:)QBT_TR[CONTEXT=OptionsDialog]</label>
210210
</td>
211211
<td>
212-
<input type="text" id="torrent_backup_findir" class="pathDirectory" autocorrect="off" autocapitalize="none" aria-labelledby="backupDirFinLabel">
212+
<input type="text" id="torrent_backup_findir" class="pathDirectory" style="width: 30em;" autocorrect="off" autocapitalize="none" aria-labelledby="backupDirFinLabel">
213213
</td>
214214
</tr>
215215
<tr>
@@ -2043,14 +2043,8 @@
20432043
};
20442044

20452045
const updateTorrentBackupControls = () => {
2046-
const isTorrentBackupEnabled = document.getElementById("torrent_backup_checkbox").checked;
2047-
2046+
const isTorrentBackupEnabled = document.getElementById("torrent_backup_dir_checkbox").checked;
20482047
document.getElementById("torrent_backup_dir").disabled = !isTorrentBackupEnabled;
2049-
document.getElementById("torrent_backup_findir_checkbox").disabled = !isTorrentBackupEnabled;
2050-
document.getElementById("torrent_backup_remove_checkbox").disabled = !isTorrentBackupEnabled;
2051-
2052-
const isFinishedTorrentBackupEnabled = document.getElementById("torrent_backup_findir_checkbox").checked;
2053-
document.getElementById("torrent_backup_findir").disabled = !(isTorrentBackupEnabled && isFinishedTorrentBackupEnabled);
20542048
};
20552049

20562050
const updateFinishedTorrentBackupControls = () => {
@@ -2474,12 +2468,13 @@
24742468
document.getElementById("temppath_text").value = pref.temp_path;
24752469
updateTempDirEnabled();
24762470

2477-
document.getElementById("torrent_backup_checkbox").checked = pref.torrent_files_backup_enabled;
2471+
document.getElementById("torrent_backup_dir_checkbox").checked = pref.torrent_files_backup_enabled;
24782472
document.getElementById("torrent_backup_dir").value = pref.torrent_files_backup_dir;
2473+
updateTorrentBackupControls();
24792474
document.getElementById("torrent_backup_findir_checkbox").checked = pref.torrent_files_finished_backup_dir_enabled;
24802475
document.getElementById("torrent_backup_findir").value = pref.torrent_files_finished_backup_dir;
2476+
updateFinishedTorrentBackupControls();
24812477
document.getElementById("torrent_backup_remove_checkbox").checked = pref.remove_torrent_file_backup;
2482-
updateTorrentBackupControls();
24832478

24842479
// Automatically add torrents from
24852480
for (const folder in pref.scan_dirs) {
@@ -2890,7 +2885,7 @@
28902885
settings["temp_path"] = document.getElementById("temppath_text").value;
28912886

28922887
// Backup management
2893-
settings["torrent_files_backup_enabled"] = document.getElementById("torrent_backup_checkbox").checked;
2888+
settings["torrent_files_backup_enabled"] = document.getElementById("torrent_backup_dir_checkbox").checked;
28942889
settings["torrent_files_backup_dir"] = document.getElementById("torrent_backup_dir").value;
28952890
settings["torrent_files_finished_backup_dir_enabled"] = document.getElementById("torrent_backup_findir_checkbox").checked;
28962891
settings["torrent_files_finished_backup_dir"] = document.getElementById("torrent_backup_findir").value;

0 commit comments

Comments
 (0)