Browse Source

Move a few torrent context menu actions into "Torrent options" dialog

Automatic torrent management
Save path
Category
Download in sequential order
Download first and last pieces first

closes #15447, closes #14064
adaptive-webui-19844
thalieht 3 years ago
parent
commit
046d6f3bc1
  1. 197
      src/gui/torrentoptionsdialog.cpp
  2. 11
      src/gui/torrentoptionsdialog.h
  3. 83
      src/gui/torrentoptionsdialog.ui
  4. 87
      src/gui/transferlistwidget.cpp
  5. 3
      src/gui/transferlistwidget.h

197
src/gui/torrentoptionsdialog.cpp

@ -30,6 +30,7 @@
#include "torrentoptionsdialog.h" #include "torrentoptionsdialog.h"
#include <QLineEdit>
#include <QMessageBox> #include <QMessageBox>
#include <QString> #include <QString>
@ -38,6 +39,7 @@
#include "base/bittorrent/torrent.h" #include "base/bittorrent/torrent.h"
#include "base/global.h" #include "base/global.h"
#include "base/unicodestrings.h" #include "base/unicodestrings.h"
#include "base/utils/fs.h"
#include "ui_torrentoptionsdialog.h" #include "ui_torrentoptionsdialog.h"
#include "utils.h" #include "utils.h"
@ -59,13 +61,22 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
: QDialog {parent} : QDialog {parent}
, m_ui {new Ui::TorrentOptionsDialog} , m_ui {new Ui::TorrentOptionsDialog}
, m_storeDialogSize {SETTINGS_KEY("Size")} , m_storeDialogSize {SETTINGS_KEY("Size")}
, m_currentCategoriesString {QString::fromLatin1("--%1--").arg(tr("Currently used categories"))}
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->savePath->setMode(FileSystemPathEdit::Mode::DirectorySave);
m_ui->savePath->setDialogCaption(tr("Choose save path"));
Q_ASSERT(!torrents.empty()); Q_ASSERT(!torrents.empty());
const auto *session = BitTorrent::Session::instance(); const auto *session = BitTorrent::Session::instance();
bool allSameUpLimit = true, allSameDownLimit = true, allSameRatio = true, allSameSeedingTime = true bool allSameUpLimit = true, allSameDownLimit = true, allSameRatio = true, allSameSeedingTime = true
, allTorrentsArePrivate = true, allSameDHT = true, allSamePEX = true, allSameLSD = true; , allTorrentsArePrivate = true, allSameDHT = true, allSamePEX = true, allSameLSD = true
, allSameSequential = true, allSameFirstLastPieces = true, allSameAutoTMM = true, allSameSavePath = true;
const bool isFirstTorrentAutoTMMEnabled = torrents[0]->isAutoTMMEnabled();
const QString firstTorrentSavePath = torrents[0]->savePath();
const QString firstTorrentCategory = torrents[0]->category();
const int firstTorrentUpLimit = qMax(0, torrents[0]->uploadLimit()); const int firstTorrentUpLimit = qMax(0, torrents[0]->uploadLimit());
const int firstTorrentDownLimit = qMax(0, torrents[0]->downloadLimit()); const int firstTorrentDownLimit = qMax(0, torrents[0]->downloadLimit());
@ -76,11 +87,29 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
const bool isFirstTorrentDHTDisabled = torrents[0]->isDHTDisabled(); const bool isFirstTorrentDHTDisabled = torrents[0]->isDHTDisabled();
const bool isFirstTorrentPEXDisabled = torrents[0]->isPEXDisabled(); const bool isFirstTorrentPEXDisabled = torrents[0]->isPEXDisabled();
const bool isFirstTorrentLSDDisabled = torrents[0]->isLSDDisabled(); const bool isFirstTorrentLSDDisabled = torrents[0]->isLSDDisabled();
const bool isFirstTorrentSequentialEnabled = torrents[0]->isSequentialDownload();
const bool isFirstTorrentFirstLastPiecesEnabled = torrents[0]->hasFirstLastPiecePriority();
m_torrentIDs.reserve(torrents.size()); m_torrentIDs.reserve(torrents.size());
for (const BitTorrent::Torrent *torrent : torrents) for (const BitTorrent::Torrent *torrent : torrents)
{ {
m_torrentIDs << torrent->id(); m_torrentIDs << torrent->id();
if (allSameAutoTMM)
{
if (torrent->isAutoTMMEnabled() != isFirstTorrentAutoTMMEnabled)
allSameAutoTMM = false;
}
if (allSameSavePath)
{
if (torrent->savePath() != firstTorrentSavePath)
allSameSavePath = false;
}
if (m_allSameCategory)
{
if (torrent->category() != firstTorrentCategory)
m_allSameCategory = false;
}
if (allSameUpLimit) if (allSameUpLimit)
{ {
if (qMax(0, torrent->uploadLimit()) != firstTorrentUpLimit) if (qMax(0, torrent->uploadLimit()) != firstTorrentUpLimit)
@ -109,29 +138,61 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
if (allSameDHT) if (allSameDHT)
{ {
if (torrent->isDHTDisabled() != isFirstTorrentDHTDisabled) if (torrent->isDHTDisabled() != isFirstTorrentDHTDisabled)
{
m_ui->checkDisableDHT->setCheckState(Qt::PartiallyChecked);
allSameDHT = false; allSameDHT = false;
} }
}
if (allSamePEX) if (allSamePEX)
{ {
if (torrent->isPEXDisabled() != isFirstTorrentPEXDisabled) if (torrent->isPEXDisabled() != isFirstTorrentPEXDisabled)
{
m_ui->checkDisablePEX->setCheckState(Qt::PartiallyChecked);
allSamePEX = false; allSamePEX = false;
} }
}
if (allSameLSD) if (allSameLSD)
{ {
if (torrent->isLSDDisabled() != isFirstTorrentLSDDisabled) if (torrent->isLSDDisabled() != isFirstTorrentLSDDisabled)
{
m_ui->checkDisableLSD->setCheckState(Qt::PartiallyChecked);
allSameLSD = false; allSameLSD = false;
} }
if (allSameSequential)
{
if (torrent->isSequentialDownload() != isFirstTorrentSequentialEnabled)
allSameSequential = false;
}
if (allSameFirstLastPieces)
{
if (torrent->hasFirstLastPiecePriority() != isFirstTorrentFirstLastPiecesEnabled)
allSameFirstLastPieces = false;
} }
} }
if (allSameAutoTMM)
m_ui->checkAutoTMM->setChecked(isFirstTorrentAutoTMMEnabled);
else
m_ui->checkAutoTMM->setCheckState(Qt::PartiallyChecked);
if (allSameSavePath)
m_ui->savePath->setSelectedPath(firstTorrentSavePath);
if (!m_allSameCategory)
{
m_ui->comboCategory->addItem(m_currentCategoriesString);
m_ui->comboCategory->clearEditText();
m_ui->comboCategory->lineEdit()->setPlaceholderText(m_currentCategoriesString);
}
else if (!firstTorrentCategory.isEmpty())
{
m_ui->comboCategory->setCurrentText(firstTorrentCategory);
m_ui->comboCategory->addItem(firstTorrentCategory);
}
m_ui->comboCategory->addItem(QString());
m_categories = session->categories().keys();
std::sort(m_categories.begin(), m_categories.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
for (const QString &category : asConst(m_categories))
{
if (m_allSameCategory && (category == firstTorrentCategory))
continue;
m_ui->comboCategory->addItem(category);
}
const bool isAltLimitEnabled = session->isAltGlobalSpeedLimitEnabled(); const bool isAltLimitEnabled = session->isAltGlobalSpeedLimitEnabled();
const int globalUploadLimit = isAltLimitEnabled const int globalUploadLimit = isAltLimitEnabled
? (session->altGlobalUploadSpeedLimit() / 1024) ? (session->altGlobalUploadSpeedLimit() / 1024)
@ -219,12 +280,20 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
if (!allTorrentsArePrivate) if (!allTorrentsArePrivate)
{ {
if (m_ui->checkDisableDHT->checkState() != Qt::PartiallyChecked) if (allSameDHT)
m_ui->checkDisableDHT->setChecked(isFirstTorrentDHTDisabled); m_ui->checkDisableDHT->setChecked(isFirstTorrentDHTDisabled);
if (m_ui->checkDisablePEX->checkState() != Qt::PartiallyChecked) else
m_ui->checkDisableDHT->setCheckState(Qt::PartiallyChecked);
if (allSamePEX)
m_ui->checkDisablePEX->setChecked(isFirstTorrentPEXDisabled); m_ui->checkDisablePEX->setChecked(isFirstTorrentPEXDisabled);
if (m_ui->checkDisableLSD->checkState() != Qt::PartiallyChecked) else
m_ui->checkDisablePEX->setCheckState(Qt::PartiallyChecked);
if (allSameLSD)
m_ui->checkDisableLSD->setChecked(isFirstTorrentLSDDisabled); m_ui->checkDisableLSD->setChecked(isFirstTorrentLSDDisabled);
else
m_ui->checkDisableLSD->setCheckState(Qt::PartiallyChecked);
} }
else else
{ {
@ -241,17 +310,38 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
m_ui->checkDisablePEX->setToolTip(privateTorrentsTooltip); m_ui->checkDisablePEX->setToolTip(privateTorrentsTooltip);
m_ui->checkDisableLSD->setToolTip(privateTorrentsTooltip); m_ui->checkDisableLSD->setToolTip(privateTorrentsTooltip);
if (allSameSequential)
m_ui->checkSequential->setChecked(isFirstTorrentSequentialEnabled);
else
m_ui->checkSequential->setCheckState(Qt::PartiallyChecked);
if (allSameFirstLastPieces)
m_ui->checkFirstLastPieces->setChecked(isFirstTorrentFirstLastPiecesEnabled);
else
m_ui->checkFirstLastPieces->setCheckState(Qt::PartiallyChecked);
m_initialValues = m_initialValues =
{ {
m_ui->savePath->selectedPath(),
m_ui->comboCategory->currentText(),
getRatio(), getRatio(),
getSeedingTime(), getSeedingTime(),
m_ui->spinUploadLimit->value(), m_ui->spinUploadLimit->value(),
m_ui->spinDownloadLimit->value(), m_ui->spinDownloadLimit->value(),
m_ui->checkAutoTMM->checkState(),
m_ui->checkDisableDHT->checkState(), m_ui->checkDisableDHT->checkState(),
m_ui->checkDisablePEX->checkState(), m_ui->checkDisablePEX->checkState(),
m_ui->checkDisableLSD->checkState() m_ui->checkDisableLSD->checkState(),
m_ui->checkSequential->checkState(),
m_ui->checkFirstLastPieces->checkState()
}; };
// Needs to be called after the initial values struct is initialized
handleTMMChanged();
connect(m_ui->checkAutoTMM, &QCheckBox::clicked, this, &TorrentOptionsDialog::handleTMMChanged);
connect(m_ui->comboCategory, &QComboBox::activated, this, &TorrentOptionsDialog::handleCategoryChanged);
// Sync up/down speed limit sliders with their corresponding spinboxes // Sync up/down speed limit sliders with their corresponding spinboxes
connect(m_ui->sliderUploadLimit, &QSlider::valueChanged, m_ui->spinUploadLimit, &QSpinBox::setValue); connect(m_ui->sliderUploadLimit, &QSlider::valueChanged, m_ui->spinUploadLimit, &QSpinBox::setValue);
connect(m_ui->sliderDownloadLimit, &QSlider::valueChanged, m_ui->spinDownloadLimit, &QSpinBox::setValue); connect(m_ui->sliderDownloadLimit, &QSlider::valueChanged, m_ui->spinDownloadLimit, &QSpinBox::setValue);
@ -282,12 +372,27 @@ void TorrentOptionsDialog::accept()
return; return;
} }
const auto *session = BitTorrent::Session::instance(); auto *session = BitTorrent::Session::instance();
for (const BitTorrent::TorrentID &id : asConst(m_torrentIDs)) for (const BitTorrent::TorrentID &id : asConst(m_torrentIDs))
{ {
BitTorrent::Torrent *torrent = session->findTorrent(id); BitTorrent::Torrent *torrent = session->findTorrent(id);
if (!torrent) continue; if (!torrent) continue;
const QString savePath = m_ui->savePath->selectedPath();
if (m_initialValues.autoTMM != m_ui->checkAutoTMM->checkState())
torrent->setAutoTMMEnabled(m_ui->checkAutoTMM->isChecked());
if (!m_ui->checkAutoTMM->isChecked() && (m_initialValues.savePath != savePath))
torrent->move(Utils::Fs::expandPathAbs(savePath));
const QString category = m_ui->comboCategory->currentText();
// index 0 is always the current category
if ((m_initialValues.category != category) || (m_ui->comboCategory->currentIndex() != 0))
{
if (!m_categories.contains(category))
session->addCategory(category);
torrent->setCategory(category);
}
if (m_initialValues.upSpeedLimit != m_ui->spinUploadLimit->value()) if (m_initialValues.upSpeedLimit != m_ui->spinUploadLimit->value())
torrent->setUploadLimit(m_ui->spinUploadLimit->value() * 1024); torrent->setUploadLimit(m_ui->spinUploadLimit->value() * 1024);
if (m_initialValues.downSpeedLimit != m_ui->spinDownloadLimit->value()) if (m_initialValues.downSpeedLimit != m_ui->spinDownloadLimit->value())
@ -310,6 +415,11 @@ void TorrentOptionsDialog::accept()
if (m_initialValues.disableLSD != m_ui->checkDisableLSD->checkState()) if (m_initialValues.disableLSD != m_ui->checkDisableLSD->checkState())
torrent->setLSDDisabled(m_ui->checkDisableLSD->isChecked()); torrent->setLSDDisabled(m_ui->checkDisableLSD->isChecked());
} }
if (m_initialValues.sequential != m_ui->checkSequential->checkState())
torrent->setSequentialDownload(m_ui->checkSequential->isChecked());
if (m_initialValues.firstLastPieces != m_ui->checkFirstLastPieces->checkState())
torrent->setFirstLastPiecePriority(m_ui->checkFirstLastPieces->isChecked());
} }
QDialog::accept(); QDialog::accept();
@ -343,6 +453,65 @@ int TorrentOptionsDialog::getSeedingTime() const
return m_ui->spinTimeLimit->value(); return m_ui->spinTimeLimit->value();
} }
void TorrentOptionsDialog::handleCategoryChanged(const int index)
{
Q_UNUSED(index);
if (m_ui->checkAutoTMM->checkState() == Qt::Checked)
{
if (!m_allSameCategory && (m_ui->comboCategory->currentIndex() == 0))
{
m_ui->savePath->setSelectedPath(QString());
}
else
{
const QString savePath = BitTorrent::Session::instance()->categorySavePath(m_ui->comboCategory->currentText());
m_ui->savePath->setSelectedPath(Utils::Fs::toNativePath(savePath));
}
}
if (!m_allSameCategory && (m_ui->comboCategory->currentIndex() == 0))
{
m_ui->comboCategory->clearEditText();
m_ui->comboCategory->lineEdit()->setPlaceholderText(m_currentCategoriesString);
}
else
{
m_ui->comboCategory->lineEdit()->setPlaceholderText(QString());
}
}
void TorrentOptionsDialog::handleTMMChanged()
{
if (m_ui->checkAutoTMM->checkState() == Qt::Unchecked)
{
m_ui->labelSavePath->setEnabled(true);
m_ui->savePath->setEnabled(true);
m_ui->savePath->setSelectedPath(Utils::Fs::toNativePath(m_initialValues.savePath));
}
else
{
m_ui->labelSavePath->setEnabled(false);
m_ui->savePath->setEnabled(false);
if (m_ui->checkAutoTMM->checkState() == Qt::Checked)
{
if (!m_allSameCategory && (m_ui->comboCategory->currentIndex() == 0))
{
m_ui->savePath->setSelectedPath(QString());
}
else
{
const QString savePath = BitTorrent::Session::instance()->categorySavePath(m_ui->comboCategory->currentText());
m_ui->savePath->setSelectedPath(Utils::Fs::toNativePath(savePath));
}
}
else // partially checked
{
m_ui->savePath->setSelectedPath(QString());
}
}
}
void TorrentOptionsDialog::handleRatioTypeChanged() void TorrentOptionsDialog::handleRatioTypeChanged()
{ {
m_ui->checkMaxRatio->setEnabled(m_ui->radioTorrentLimit->isChecked()); m_ui->checkMaxRatio->setEnabled(m_ui->radioTorrentLimit->isChecked());

11
src/gui/torrentoptionsdialog.h

@ -58,6 +58,9 @@ public slots:
void accept() override; void accept() override;
private slots: private slots:
void handleCategoryChanged(int index);
void handleTMMChanged();
void handleUpSpeedLimitChanged(); void handleUpSpeedLimitChanged();
void handleDownSpeedLimitChanged(); void handleDownSpeedLimitChanged();
@ -70,14 +73,22 @@ private:
QVector<BitTorrent::TorrentID> m_torrentIDs; QVector<BitTorrent::TorrentID> m_torrentIDs;
Ui::TorrentOptionsDialog *m_ui; Ui::TorrentOptionsDialog *m_ui;
SettingValue<QSize> m_storeDialogSize; SettingValue<QSize> m_storeDialogSize;
QStringList m_categories;
QString m_currentCategoriesString;
bool m_allSameCategory = true;
struct struct
{ {
QString savePath;
QString category;
qreal ratio; qreal ratio;
int seedingTime; int seedingTime;
int upSpeedLimit; int upSpeedLimit;
int downSpeedLimit; int downSpeedLimit;
Qt::CheckState autoTMM;
Qt::CheckState disableDHT; Qt::CheckState disableDHT;
Qt::CheckState disablePEX; Qt::CheckState disablePEX;
Qt::CheckState disableLSD; Qt::CheckState disableLSD;
Qt::CheckState sequential;
Qt::CheckState firstLastPieces;
} m_initialValues; } m_initialValues;
}; };

83
src/gui/torrentoptionsdialog.ui

@ -6,14 +6,71 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>390</width> <width>450</width>
<height>450</height> <height>540</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Torrent Options</string> <string>Torrent Options</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="checkAutoTMM">
<property name="toolTip">
<string>Automatic mode means that various torrent properties (e.g. save path) will be decided by the associated category</string>
</property>
<property name="text">
<string>Automatic Torrent Management</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="labelSavePath">
<property name="text">
<string>Save path:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="FileSystemPathLineEdit" name="savePath" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelCategory">
<property name="text">
<string>Category:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboCategory">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="maxVisibleItems">
<number>2147483647</number>
</property>
<property name="insertPolicy">
<enum>QComboBox::InsertAtTop</enum>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">
@ -187,6 +244,13 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QCheckBox" name="checkSequential">
<property name="text">
<string>Download in sequential order</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -206,6 +270,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkFirstLastPieces">
<property name="text">
<string>Download first and last pieces first</string>
</property>
</widget>
</item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QCheckBox" name="checkDisableLSD"> <widget class="QCheckBox" name="checkDisableLSD">
<property name="text"> <property name="text">
@ -237,6 +308,14 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>FileSystemPathLineEdit</class>
<extends>QWidget</extends>
<header>gui/fspathedit.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections> <connections>
<connection> <connection>

87
src/gui/transferlistwidget.cpp

@ -328,21 +328,6 @@ QVector<BitTorrent::Torrent *> TransferListWidget::getVisibleTorrents() const
return torrents; return torrents;
} }
void TransferListWidget::setSelectedTorrentsLocation()
{
const QVector<BitTorrent::Torrent *> torrents = getSelectedTorrents();
if (torrents.isEmpty()) return;
const QString oldLocation = torrents[0]->savePath();
const QString newLocation = QFileDialog::getExistingDirectory(this, tr("Choose save path"), oldLocation,
QFileDialog::DontConfirmOverwrite | QFileDialog::ShowDirsOnly | QFileDialog::HideNameFilterDetails);
if (newLocation.isEmpty() || !QDir(newLocation).exists()) return;
// Actually move storage
for (BitTorrent::Torrent *const torrent : torrents)
torrent->move(Utils::Fs::expandPathAbs(newLocation));
}
void TransferListWidget::pauseAllTorrents() void TransferListWidget::pauseAllTorrents()
{ {
for (BitTorrent::Torrent *const torrent : asConst(BitTorrent::Session::instance()->torrents())) for (BitTorrent::Torrent *const torrent : asConst(BitTorrent::Session::instance()->torrents()))
@ -659,18 +644,6 @@ void TransferListWidget::setSelectedTorrentsSuperSeeding(const bool enabled) con
} }
} }
void TransferListWidget::setSelectedTorrentsSequentialDownload(const bool enabled) const
{
for (BitTorrent::Torrent *const torrent : asConst(getSelectedTorrents()))
torrent->setSequentialDownload(enabled);
}
void TransferListWidget::setSelectedFirstLastPiecePrio(const bool enabled) const
{
for (BitTorrent::Torrent *const torrent : asConst(getSelectedTorrents()))
torrent->setFirstLastPiecePriority(enabled);
}
void TransferListWidget::setSelectedAutoTMMEnabled(const bool enabled) const void TransferListWidget::setSelectedAutoTMMEnabled(const bool enabled) const
{ {
for (BitTorrent::Torrent *const torrent : asConst(getSelectedTorrents())) for (BitTorrent::Torrent *const torrent : asConst(getSelectedTorrents()))
@ -845,8 +818,6 @@ void TransferListWidget::displayListMenu(const QPoint &)
connect(actionTopQueuePos, &QAction::triggered, this, &TransferListWidget::topQueuePosSelectedTorrents); connect(actionTopQueuePos, &QAction::triggered, this, &TransferListWidget::topQueuePosSelectedTorrents);
auto *actionBottomQueuePos = new QAction(UIThemeManager::instance()->getIcon("go-bottom"), tr("Move to bottom", "i.e. Move to bottom of the queue"), listMenu); auto *actionBottomQueuePos = new QAction(UIThemeManager::instance()->getIcon("go-bottom"), tr("Move to bottom", "i.e. Move to bottom of the queue"), listMenu);
connect(actionBottomQueuePos, &QAction::triggered, this, &TransferListWidget::bottomQueuePosSelectedTorrents); connect(actionBottomQueuePos, &QAction::triggered, this, &TransferListWidget::bottomQueuePosSelectedTorrents);
auto *actionSetTorrentPath = new QAction(UIThemeManager::instance()->getIcon("inode-directory"), tr("Set location..."), listMenu);
connect(actionSetTorrentPath, &QAction::triggered, this, &TransferListWidget::setSelectedTorrentsLocation);
auto *actionForceRecheck = new QAction(UIThemeManager::instance()->getIcon("document-edit-verify"), tr("Force recheck"), listMenu); auto *actionForceRecheck = new QAction(UIThemeManager::instance()->getIcon("document-edit-verify"), tr("Force recheck"), listMenu);
connect(actionForceRecheck, &QAction::triggered, this, &TransferListWidget::recheckSelectedTorrents); connect(actionForceRecheck, &QAction::triggered, this, &TransferListWidget::recheckSelectedTorrents);
auto *actionForceReannounce = new QAction(UIThemeManager::instance()->getIcon("document-edit-verify"), tr("Force reannounce"), listMenu); auto *actionForceReannounce = new QAction(UIThemeManager::instance()->getIcon("document-edit-verify"), tr("Force reannounce"), listMenu);
@ -865,13 +836,6 @@ void TransferListWidget::displayListMenu(const QPoint &)
connect(actionSuperSeedingMode, &QAction::triggered, this, &TransferListWidget::setSelectedTorrentsSuperSeeding); connect(actionSuperSeedingMode, &QAction::triggered, this, &TransferListWidget::setSelectedTorrentsSuperSeeding);
auto *actionRename = new QAction(UIThemeManager::instance()->getIcon("edit-rename"), tr("Rename..."), listMenu); auto *actionRename = new QAction(UIThemeManager::instance()->getIcon("edit-rename"), tr("Rename..."), listMenu);
connect(actionRename, &QAction::triggered, this, &TransferListWidget::renameSelectedTorrent); connect(actionRename, &QAction::triggered, this, &TransferListWidget::renameSelectedTorrent);
auto *actionSequentialDownload = new TriStateAction(tr("Download in sequential order"), listMenu);
connect(actionSequentialDownload, &QAction::triggered, this, &TransferListWidget::setSelectedTorrentsSequentialDownload);
auto *actionFirstLastPiecePrio = new TriStateAction(tr("Download first and last pieces first"), listMenu);
connect(actionFirstLastPiecePrio, &QAction::triggered, this, &TransferListWidget::setSelectedFirstLastPiecePrio);
auto *actionAutoTMM = new TriStateAction(tr("Automatic Torrent Management"), listMenu);
actionAutoTMM->setToolTip(tr("Automatic mode means that various torrent properties(eg save path) will be decided by the associated category"));
connect(actionAutoTMM, &QAction::triggered, this, &TransferListWidget::setSelectedAutoTMMEnabled);
auto *actionEditTracker = new QAction(UIThemeManager::instance()->getIcon("edit-rename"), tr("Edit trackers..."), listMenu); auto *actionEditTracker = new QAction(UIThemeManager::instance()->getIcon("edit-rename"), tr("Edit trackers..."), listMenu);
connect(actionEditTracker, &QAction::triggered, this, &TransferListWidget::editTorrentTrackers); connect(actionEditTracker, &QAction::triggered, this, &TransferListWidget::editTorrentTrackers);
// End of actions // End of actions
@ -884,8 +848,6 @@ void TransferListWidget::displayListMenu(const QPoint &)
bool sequentialDownloadMode = false, prioritizeFirstLast = false; bool sequentialDownloadMode = false, prioritizeFirstLast = false;
bool oneHasMetadata = false, oneNotSeed = false; bool oneHasMetadata = false, oneNotSeed = false;
bool allSameCategory = true; bool allSameCategory = true;
bool allSameAutoTMM = true;
bool firstAutoTMM = false;
QString firstCategory; QString firstCategory;
bool first = true; bool first = true;
TagSet tagsInAny; TagSet tagsInAny;
@ -909,7 +871,6 @@ void TransferListWidget::displayListMenu(const QPoint &)
if (first) if (first)
{ {
firstAutoTMM = torrent->isAutoTMMEnabled();
tagsInAll = torrentTags; tagsInAll = torrentTags;
} }
else else
@ -917,9 +878,6 @@ void TransferListWidget::displayListMenu(const QPoint &)
tagsInAll.intersect(torrentTags); tagsInAll.intersect(torrentTags);
} }
if (firstAutoTMM != torrent->isAutoTMMEnabled())
allSameAutoTMM = false;
if (torrent->hasMetadata()) if (torrent->hasMetadata())
oneHasMetadata = true; oneHasMetadata = true;
if (!torrent->isSeed()) if (!torrent->isSeed())
@ -979,7 +937,7 @@ void TransferListWidget::displayListMenu(const QPoint &)
if (oneHasMetadata && oneNotSeed && !allSameSequentialDownloadMode if (oneHasMetadata && oneNotSeed && !allSameSequentialDownloadMode
&& !allSamePrioFirstlast && !allSameSuperSeeding && !allSameCategory && !allSamePrioFirstlast && !allSameSuperSeeding && !allSameCategory
&& needsStart && needsForce && needsPause && needsPreview && !allSameAutoTMM && needsStart && needsForce && needsPause && needsPreview
&& hasInfohashV1 && hasInfohashV2) && hasInfohashV1 && hasInfohashV2)
{ {
break; break;
@ -995,36 +953,10 @@ void TransferListWidget::displayListMenu(const QPoint &)
listMenu->addSeparator(); listMenu->addSeparator();
listMenu->addAction(actionDelete); listMenu->addAction(actionDelete);
listMenu->addSeparator(); listMenu->addSeparator();
listMenu->addAction(actionSetTorrentPath);
if (selectedIndexes.size() == 1) if (selectedIndexes.size() == 1)
listMenu->addAction(actionRename); listMenu->addAction(actionRename);
listMenu->addAction(actionEditTracker); listMenu->addAction(actionEditTracker);
// Category Menu
QStringList categories = BitTorrent::Session::instance()->categories().keys();
std::sort(categories.begin(), categories.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
QMenu *categoryMenu = listMenu->addMenu(UIThemeManager::instance()->getIcon("view-categories"), tr("Category"));
categoryMenu->addAction(UIThemeManager::instance()->getIcon("list-add"), tr("New...", "New category...")
, this, &TransferListWidget::askNewCategoryForSelection);
categoryMenu->addAction(UIThemeManager::instance()->getIcon("edit-clear"), tr("Reset", "Reset category")
, this, [this]() { setSelectionCategory(""); });
categoryMenu->addSeparator();
for (const QString &category : asConst(categories))
{
const QString escapedCategory = QString(category).replace('&', "&&"); // avoid '&' becomes accelerator key
QAction *cat = categoryMenu->addAction(UIThemeManager::instance()->getIcon("inode-directory"), escapedCategory
, this, [this, category]() { setSelectionCategory(category); });
if (allSameCategory && (category == firstCategory))
{
cat->setCheckable(true);
cat->setChecked(true);
}
}
// Tag Menu // Tag Menu
QStringList tags(BitTorrent::Session::instance()->tags().values()); QStringList tags(BitTorrent::Session::instance()->tags().values());
std::sort(tags.begin(), tags.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>()); std::sort(tags.begin(), tags.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
@ -1063,11 +995,6 @@ void TransferListWidget::displayListMenu(const QPoint &)
tagsMenu->addAction(action); tagsMenu->addAction(action);
} }
actionAutoTMM->setCheckState(allSameAutoTMM
? (firstAutoTMM ? Qt::Checked : Qt::Unchecked)
: Qt::PartiallyChecked);
listMenu->addAction(actionAutoTMM);
listMenu->addSeparator(); listMenu->addSeparator();
listMenu->addAction(actionTorrentOptions); listMenu->addAction(actionTorrentOptions);
if (!oneNotSeed && oneHasMetadata) if (!oneNotSeed && oneHasMetadata)
@ -1085,19 +1012,7 @@ void TransferListWidget::displayListMenu(const QPoint &)
addedPreviewAction = true; addedPreviewAction = true;
} }
if (oneNotSeed) if (oneNotSeed)
{
actionSequentialDownload->setCheckState(allSameSequentialDownloadMode
? (sequentialDownloadMode ? Qt::Checked : Qt::Unchecked)
: Qt::PartiallyChecked);
listMenu->addAction(actionSequentialDownload);
actionFirstLastPiecePrio->setCheckState(allSamePrioFirstlast
? (prioritizeFirstLast ? Qt::Checked : Qt::Unchecked)
: Qt::PartiallyChecked);
listMenu->addAction(actionFirstLastPiecePrio);
addedPreviewAction = true; addedPreviewAction = true;
}
if (addedPreviewAction) if (addedPreviewAction)
listMenu->addSeparator(); listMenu->addSeparator();

3
src/gui/transferlistwidget.h

@ -65,7 +65,6 @@ public slots:
void addSelectionTag(const QString &tag); void addSelectionTag(const QString &tag);
void removeSelectionTag(const QString &tag); void removeSelectionTag(const QString &tag);
void clearSelectionTags(); void clearSelectionTags();
void setSelectedTorrentsLocation();
void pauseAllTorrents(); void pauseAllTorrents();
void resumeAllTorrents(); void resumeAllTorrents();
void startSelectedTorrents(); void startSelectedTorrents();
@ -109,8 +108,6 @@ private slots:
void displayListMenu(const QPoint &); void displayListMenu(const QPoint &);
void currentChanged(const QModelIndex &current, const QModelIndex&) override; void currentChanged(const QModelIndex &current, const QModelIndex&) override;
void setSelectedTorrentsSuperSeeding(bool enabled) const; void setSelectedTorrentsSuperSeeding(bool enabled) const;
void setSelectedTorrentsSequentialDownload(bool enabled) const;
void setSelectedFirstLastPiecePrio(bool enabled) const;
void setSelectedAutoTMMEnabled(bool enabled) const; void setSelectedAutoTMMEnabled(bool enabled) const;
void askNewCategoryForSelection(); void askNewCategoryForSelection();
void saveSettings(); void saveSettings();

Loading…
Cancel
Save