Browse Source

Convert existing speed dialog to global + alt global limits only

adaptive-webui-19844
thalieht 5 years ago
parent
commit
76f285f19c
  1. 41
      src/gui/mainwindow.cpp
  2. 3
      src/gui/mainwindow.h
  3. 19
      src/gui/mainwindow.ui
  4. 137
      src/gui/speedlimitdialog.cpp
  5. 20
      src/gui/speedlimitdialog.h
  6. 180
      src/gui/speedlimitdialog.ui
  7. 35
      src/gui/statusbar.cpp
  8. 3
      src/gui/statusbar.h
  9. 76
      src/gui/transferlistwidget.cpp
  10. 3
      src/gui/transferlistwidget.h

41
src/gui/mainwindow.cpp

@ -172,10 +172,7 @@ MainWindow::MainWindow(QWidget *parent) @@ -172,10 +172,7 @@ MainWindow::MainWindow(QWidget *parent)
m_ui->actionOpen->setIcon(UIThemeManager::instance()->getIcon("list-add"));
m_ui->actionDownloadFromURL->setIcon(UIThemeManager::instance()->getIcon("insert-link"));
m_ui->actionSetUploadLimit->setIcon(UIThemeManager::instance()->getIcon("kt-set-max-upload-speed"));
m_ui->actionSetDownloadLimit->setIcon(UIThemeManager::instance()->getIcon("kt-set-max-download-speed"));
m_ui->actionSetGlobalUploadLimit->setIcon(UIThemeManager::instance()->getIcon("kt-set-max-upload-speed"));
m_ui->actionSetGlobalDownloadLimit->setIcon(UIThemeManager::instance()->getIcon("kt-set-max-download-speed"));
m_ui->actionSetGlobalSpeedLimits->setIcon(UIThemeManager::instance()->getIcon("speedometer"));
m_ui->actionCreateTorrent->setIcon(UIThemeManager::instance()->getIcon("document-edit"));
m_ui->actionAbout->setIcon(UIThemeManager::instance()->getIcon("help-about"));
m_ui->actionStatistics->setIcon(UIThemeManager::instance()->getIcon("view-statistics"));
@ -1008,36 +1005,11 @@ void MainWindow::handleDownloadFromUrlFailure(const QString &url, const QString @@ -1008,36 +1005,11 @@ void MainWindow::handleDownloadFromUrlFailure(const QString &url, const QString
, tr("Couldn't download file at URL '%1', reason: %2.").arg(url, reason));
}
void MainWindow::on_actionSetGlobalUploadLimit_triggered()
void MainWindow::on_actionSetGlobalSpeedLimits_triggered()
{
qDebug() << Q_FUNC_INFO;
BitTorrent::Session *const session = BitTorrent::Session::instance();
bool ok = false;
const long newLimit = SpeedLimitDialog::askSpeedLimit(
this, &ok, tr("Global Upload Speed Limit"), session->uploadSpeedLimit());
if (ok)
{
qDebug("Setting global upload rate limit to %.1fKb/s", newLimit / 1024.);
session->setUploadSpeedLimit(newLimit);
}
}
void MainWindow::on_actionSetGlobalDownloadLimit_triggered()
{
qDebug() << Q_FUNC_INFO;
BitTorrent::Session *const session = BitTorrent::Session::instance();
bool ok = false;
const long newLimit = SpeedLimitDialog::askSpeedLimit(
this, &ok, tr("Global Download Speed Limit"), session->downloadSpeedLimit());
if (ok)
{
qDebug("Setting global download rate limit to %.1fKb/s", newLimit / 1024.);
session->setDownloadSpeedLimit(newLimit);
}
auto dialog = new SpeedLimitDialog {this};
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->open();
}
// Necessary if we want to close the window
@ -1808,8 +1780,7 @@ QMenu *MainWindow::trayIconMenu() @@ -1808,8 +1780,7 @@ QMenu *MainWindow::trayIconMenu()
updateAltSpeedsBtn(isAltBWEnabled);
m_ui->actionUseAlternativeSpeedLimits->setChecked(isAltBWEnabled);
m_trayIconMenu->addAction(m_ui->actionUseAlternativeSpeedLimits);
m_trayIconMenu->addAction(m_ui->actionSetGlobalDownloadLimit);
m_trayIconMenu->addAction(m_ui->actionSetGlobalUploadLimit);
m_trayIconMenu->addAction(m_ui->actionSetGlobalSpeedLimits);
m_trayIconMenu->addSeparator();
m_trayIconMenu->addAction(m_ui->actionStartAll);
m_trayIconMenu->addAction(m_ui->actionPauseAll);

3
src/gui/mainwindow.h

@ -171,8 +171,7 @@ private slots: @@ -171,8 +171,7 @@ private slots:
void on_actionStatistics_triggered();
void on_actionCreateTorrent_triggered();
void on_actionOptions_triggered();
void on_actionSetGlobalUploadLimit_triggered();
void on_actionSetGlobalDownloadLimit_triggered();
void on_actionSetGlobalSpeedLimits_triggered();
void on_actionDocumentation_triggered() const;
void on_actionOpen_triggered();
void on_actionDownloadFromURL_triggered();

19
src/gui/mainwindow.ui

@ -223,29 +223,14 @@ @@ -223,29 +223,14 @@
<string>Torrent &amp;Creator</string>
</property>
</action>
<action name="actionSetUploadLimit">
<property name="text">
<string>Set Upload Limit...</string>
</property>
</action>
<action name="actionSetDownloadLimit">
<property name="text">
<string>Set Download Limit...</string>
</property>
</action>
<action name="actionDocumentation">
<property name="text">
<string>&amp;Documentation</string>
</property>
</action>
<action name="actionSetGlobalDownloadLimit">
<property name="text">
<string>Set Global Download Limit...</string>
</property>
</action>
<action name="actionSetGlobalUploadLimit">
<action name="actionSetGlobalSpeedLimits">
<property name="text">
<string>Set Global Upload Limit...</string>
<string>Set Global Speed Limits...</string>
</property>
</action>
<action name="actionBottomQueuePos">

137
src/gui/speedlimitdialog.cpp

@ -28,80 +28,107 @@ @@ -28,80 +28,107 @@
#include "speedlimitdialog.h"
#include <QStyle>
#include "base/bittorrent/session.h"
#include "ui_speedlimitdialog.h"
#include "uithememanager.h"
#include "utils.h"
SpeedLimitDialog::SpeedLimitDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::SpeedLimitDialog)
namespace
{
m_ui->setupUi(this);
// Connect to slots
connect(m_ui->bandwidthSlider, &QSlider::valueChanged, this, &SpeedLimitDialog::updateSpinValue);
connect(m_ui->spinBandwidth, qOverload<int>(&QSpinBox::valueChanged)
, this, &SpeedLimitDialog::updateSliderValue);
Utils::Gui::resize(this);
}
SpeedLimitDialog::~SpeedLimitDialog()
{
delete m_ui;
void updateSliderValue(QSlider *slider, const int value)
{
if (value > slider->maximum())
slider->setMaximum(value);
slider->setValue(value);
}
}
// -2: if cancel
long SpeedLimitDialog::askSpeedLimit(QWidget *parent, bool *ok, const QString &title, const long defaultVal, const long maxVal)
SpeedLimitDialog::SpeedLimitDialog(QWidget *parent)
: QDialog {parent}
, m_ui {new Ui::SpeedLimitDialog}
{
if (ok) *ok = false;
m_ui->setupUi(this);
SpeedLimitDialog dlg(parent);
dlg.setWindowTitle(title);
dlg.setupDialog((maxVal / 1024.), (defaultVal / 1024.));
m_ui->labelGlobalSpeedIcon->setPixmap(Utils::Gui::scaledPixmap(UIThemeManager::instance()->getIcon(QLatin1String("slow_off"))
, this, style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this)));
m_ui->labelAltGlobalSpeedIcon->setPixmap(Utils::Gui::scaledPixmap(UIThemeManager::instance()->getIcon(QLatin1String("slow"))
, this, style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this)));
if (dlg.exec() == QDialog::Accepted)
const auto initSlider = [](QSlider *slider, const int value, const int maximum)
{
if (ok) *ok = true;
const int val = dlg.getSpeedLimit();
if (val < 0)
return 0;
return (val * 1024);
}
return -2;
}
slider->setMaximum(maximum);
slider->setValue(value);
};
const auto *session = BitTorrent::Session::instance();
const int uploadVal = qMax(0, (session->globalUploadSpeedLimit() / 1024));
const int downloadVal = qMax(0, (session->globalDownloadSpeedLimit() / 1024));
const int maxUpload = qMax(10000, (session->globalUploadSpeedLimit() / 1024));
const int maxDownload = qMax(10000, (session->globalDownloadSpeedLimit() / 1024));
initSlider(m_ui->sliderUploadLimit, uploadVal, maxUpload);
initSlider(m_ui->sliderDownloadLimit, downloadVal, maxDownload);
const int altUploadVal = qMax(0, (session->altGlobalUploadSpeedLimit() / 1024));
const int altDownloadVal = qMax(0, (session->altGlobalDownloadSpeedLimit() / 1024));
const int altMaxUpload = qMax(10000, (session->altGlobalUploadSpeedLimit() / 1024));
const int altMaxDownload = qMax(10000, (session->altGlobalDownloadSpeedLimit() / 1024));
initSlider(m_ui->sliderAltUploadLimit, altUploadVal, altMaxUpload);
initSlider(m_ui->sliderAltDownloadLimit, altDownloadVal, altMaxDownload);
m_ui->spinUploadLimit->setValue(uploadVal);
m_ui->spinDownloadLimit->setValue(downloadVal);
m_ui->spinAltUploadLimit->setValue(altUploadVal);
m_ui->spinAltDownloadLimit->setValue(altDownloadVal);
m_initialValues =
{
m_ui->spinUploadLimit->value(),
m_ui->spinDownloadLimit->value(),
m_ui->spinAltUploadLimit->value(),
m_ui->spinAltDownloadLimit->value()
};
// Sync up/down speed limit sliders with their corresponding spinboxes
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->spinUploadLimit, qOverload<int>(&QSpinBox::valueChanged)
, this, [this](const int value) { updateSliderValue(m_ui->sliderUploadLimit, value); });
connect(m_ui->spinDownloadLimit, qOverload<int>(&QSpinBox::valueChanged)
, this, [this](const int value) { updateSliderValue(m_ui->sliderDownloadLimit, value); });
connect(m_ui->sliderAltUploadLimit, &QSlider::valueChanged, m_ui->spinAltUploadLimit, &QSpinBox::setValue);
connect(m_ui->sliderAltDownloadLimit, &QSlider::valueChanged, m_ui->spinAltDownloadLimit, &QSpinBox::setValue);
connect(m_ui->spinAltUploadLimit, qOverload<int>(&QSpinBox::valueChanged)
, this, [this](const int value) { updateSliderValue(m_ui->sliderAltUploadLimit, value); });
connect(m_ui->spinAltDownloadLimit, qOverload<int>(&QSpinBox::valueChanged)
, this, [this](const int value) { updateSliderValue(m_ui->sliderAltDownloadLimit, value); });
void SpeedLimitDialog::updateSpinValue(const int value)
{
m_ui->spinBandwidth->setValue(value);
Utils::Gui::resize(this);
}
void SpeedLimitDialog::updateSliderValue(const int value)
SpeedLimitDialog::~SpeedLimitDialog()
{
if (value > m_ui->bandwidthSlider->maximum())
m_ui->bandwidthSlider->setMaximum(value);
m_ui->bandwidthSlider->setValue(value);
delete m_ui;
}
int SpeedLimitDialog::getSpeedLimit() const
void SpeedLimitDialog::accept()
{
return m_ui->spinBandwidth->value();
}
auto *session = BitTorrent::Session::instance();
const int uploadLimit = (m_ui->spinUploadLimit->value() * 1024);
if (m_initialValues.uploadSpeedLimit != m_ui->spinUploadLimit->value())
session->setGlobalUploadSpeedLimit(uploadLimit);
void SpeedLimitDialog::setupDialog(long maxSlider, long val)
{
val = qMax<long>(0, val);
const int downloadLimit = (m_ui->spinDownloadLimit->value() * 1024);
if (m_initialValues.downloadSpeedLimit != m_ui->spinDownloadLimit->value())
session->setGlobalDownloadSpeedLimit(downloadLimit);
if (maxSlider <= 0)
maxSlider = 10000;
const int altUploadLimit = (m_ui->spinAltUploadLimit->value() * 1024);
if (m_initialValues.altUploadSpeedLimit != m_ui->spinAltUploadLimit->value())
session->setAltGlobalUploadSpeedLimit(altUploadLimit);
// This can happen for example if global rate limit is lower
// than torrent rate limit.
if (val > maxSlider)
maxSlider = val;
const int altDownloadLimit = (m_ui->spinAltDownloadLimit->value() * 1024);
if (m_initialValues.altDownloadSpeedLimit != m_ui->spinAltDownloadLimit->value())
session->setAltGlobalDownloadSpeedLimit(altDownloadLimit);
m_ui->bandwidthSlider->setMaximum(maxSlider);
m_ui->bandwidthSlider->setValue(val);
updateSpinValue(val);
QDialog::accept();
}

20
src/gui/speedlimitdialog.h

@ -35,22 +35,24 @@ namespace Ui @@ -35,22 +35,24 @@ namespace Ui
class SpeedLimitDialog;
}
class SpeedLimitDialog : public QDialog
class SpeedLimitDialog final : public QDialog
{
Q_OBJECT
public:
explicit SpeedLimitDialog(QWidget *parent);
~SpeedLimitDialog();
static long askSpeedLimit(QWidget *parent, bool *ok, const QString &title, long defaultVal, long maxVal = 10240000);
~SpeedLimitDialog() override;
private slots:
void updateSpinValue(int val);
void updateSliderValue(int val);
public slots:
void accept() override;
private:
void setupDialog(long maxSlider, long val);
int getSpeedLimit() const;
Ui::SpeedLimitDialog *m_ui;
struct
{
int uploadSpeedLimit;
int downloadSpeedLimit;
int altUploadSpeedLimit;
int altDownloadSpeedLimit;
} m_initialValues;
};

180
src/gui/speedlimitdialog.ui

@ -6,34 +6,166 @@ @@ -6,34 +6,166 @@
<rect>
<x>0</x>
<y>0</y>
<width>338</width>
<height>83</height>
<width>481</width>
<height>272</height>
</rect>
</property>
<property name="windowTitle">
<string>Global Speed Limits</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QSlider" name="bandwidthSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBandwidth">
<property name="specialValueText">
<string>∞</string>
</property>
<property name="suffix">
<string> KiB/s</string>
</property>
<property name="maximum">
<number>65535</number>
</property>
</widget>
</item>
</layout>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Speed limits</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="2">
<widget class="QLabel" name="labelGlobalSpeedIcon">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Upload:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QSlider" name="sliderUploadLimit">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QSpinBox" name="spinUploadLimit">
<property name="specialValueText">
<string>∞</string>
</property>
<property name="suffix">
<string> KiB/s</string>
</property>
<property name="maximum">
<number>2000000</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Download:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSlider" name="sliderDownloadLimit">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QSpinBox" name="spinDownloadLimit">
<property name="specialValueText">
<string>∞</string>
</property>
<property name="suffix">
<string> KiB/s</string>
</property>
<property name="maximum">
<number>2000000</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Alternative speed limits</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" rowspan="2">
<widget class="QLabel" name="labelAltGlobalSpeedIcon">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Upload:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QSlider" name="sliderAltUploadLimit">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QSpinBox" name="spinAltUploadLimit">
<property name="specialValueText">
<string>∞</string>
</property>
<property name="suffix">
<string> KiB/s</string>
</property>
<property name="maximum">
<number>2000000</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Download:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSlider" name="sliderAltDownloadLimit">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QSpinBox" name="spinAltDownloadLimit">
<property name="specialValueText">
<string>∞</string>
</property>
<property name="suffix">
<string> KiB/s</string>
</property>
<property name="maximum">
<number>2000000</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">

35
src/gui/statusbar.cpp

@ -71,7 +71,7 @@ StatusBar::StatusBar(QWidget *parent) @@ -71,7 +71,7 @@ StatusBar::StatusBar(QWidget *parent)
m_dlSpeedLbl = new QPushButton(this);
m_dlSpeedLbl->setIcon(UIThemeManager::instance()->getIcon(QLatin1String("downloading_small")));
connect(m_dlSpeedLbl, &QAbstractButton::clicked, this, &StatusBar::capDownloadSpeed);
connect(m_dlSpeedLbl, &QAbstractButton::clicked, this, &StatusBar::capSpeed);
m_dlSpeedLbl->setFlat(true);
m_dlSpeedLbl->setFocusPolicy(Qt::NoFocus);
m_dlSpeedLbl->setCursor(Qt::PointingHandCursor);
@ -80,7 +80,7 @@ StatusBar::StatusBar(QWidget *parent) @@ -80,7 +80,7 @@ StatusBar::StatusBar(QWidget *parent)
m_upSpeedLbl = new QPushButton(this);
m_upSpeedLbl->setIcon(UIThemeManager::instance()->getIcon(QLatin1String("seeding")));
connect(m_upSpeedLbl, &QAbstractButton::clicked, this, &StatusBar::capUploadSpeed);
connect(m_upSpeedLbl, &QAbstractButton::clicked, this, &StatusBar::capSpeed);
m_upSpeedLbl->setFlat(true);
m_upSpeedLbl->setFocusPolicy(Qt::NoFocus);
m_upSpeedLbl->setCursor(Qt::PointingHandCursor);
@ -251,32 +251,9 @@ void StatusBar::updateAltSpeedsBtn(bool alternative) @@ -251,32 +251,9 @@ void StatusBar::updateAltSpeedsBtn(bool alternative)
refresh();
}
void StatusBar::capDownloadSpeed()
void StatusBar::capSpeed()
{
BitTorrent::Session *const session = BitTorrent::Session::instance();
bool ok = false;
const long newLimit = SpeedLimitDialog::askSpeedLimit(
parentWidget(), &ok, tr("Global Download Speed Limit"), session->downloadSpeedLimit());
if (ok)
{
qDebug("Setting global download rate limit to %.1fKb/s", newLimit / 1024.);
session->setDownloadSpeedLimit(newLimit);
refresh();
}
}
void StatusBar::capUploadSpeed()
{
BitTorrent::Session *const session = BitTorrent::Session::instance();
bool ok = false;
const long newLimit = SpeedLimitDialog::askSpeedLimit(
parentWidget(), &ok, tr("Global Upload Speed Limit"), session->uploadSpeedLimit());
if (ok)
{
qDebug("Setting global upload rate limit to %.1fKb/s", newLimit / 1024.);
session->setUploadSpeedLimit(newLimit);
refresh();
}
auto dialog = new SpeedLimitDialog {parentWidget()};
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->open();
}

3
src/gui/statusbar.h

@ -57,8 +57,7 @@ public slots: @@ -57,8 +57,7 @@ public slots:
private slots:
void refresh();
void updateAltSpeedsBtn(bool alternative);
void capDownloadSpeed();
void capUploadSpeed();
void capSpeed();
private:
void updateConnectionStatus();

76
src/gui/transferlistwidget.cpp

@ -551,65 +551,47 @@ void TransferListWidget::previewSelectedTorrents() @@ -551,65 +551,47 @@ void TransferListWidget::previewSelectedTorrents()
}
}
void TransferListWidget::setDlLimitSelectedTorrents()
void TransferListWidget::setSpeedLimitsSelectedTorrents()
{
QVector<BitTorrent::TorrentHandle *> torrentsList;
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents()))
{
if (torrent->isSeed())
continue;
torrentsList += torrent;
}
const QVector<BitTorrent::TorrentHandle *> torrentsList = getSelectedTorrents();
if (torrentsList.empty()) return;
int oldLimit = torrentsList.first()->downloadLimit();
for (BitTorrent::TorrentHandle *const torrent : asConst(torrentsList))
int oldUploadLimit = torrentsList.first()->uploadLimit();
int oldDownloadLimit = torrentsList.first()->downloadLimit();
for (const BitTorrent::TorrentHandle *torrent : torrentsList)
{
if (torrent->downloadLimit() != oldLimit)
if (torrent->uploadLimit() != oldUploadLimit)
{
oldLimit = -1;
oldUploadLimit = -1;
break;
}
}
bool ok = false;
const long newLimit = SpeedLimitDialog::askSpeedLimit(
this, &ok, tr("Torrent Download Speed Limiting"), oldLimit
, BitTorrent::Session::instance()->globalDownloadSpeedLimit());
if (!ok) return;
for (BitTorrent::TorrentHandle *const torrent : asConst(torrentsList))
{
qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (newLimit / 1024l), qUtf8Printable(torrent->hash()));
torrent->setDownloadLimit(newLimit);
}
}
void TransferListWidget::setUpLimitSelectedTorrents()
{
QVector<BitTorrent::TorrentHandle *> torrentsList = getSelectedTorrents();
if (torrentsList.empty()) return;
int oldLimit = torrentsList.first()->uploadLimit();
for (BitTorrent::TorrentHandle *const torrent : asConst(torrentsList))
for (const BitTorrent::TorrentHandle *torrent : torrentsList)
{
if (torrent->uploadLimit() != oldLimit)
if (torrent->downloadLimit() != oldDownloadLimit)
{
oldLimit = -1;
oldDownloadLimit = -1;
break;
}
}
bool ok = false;
const long newLimit = SpeedLimitDialog::askSpeedLimit(
this, &ok, tr("Torrent Upload Speed Limiting"), oldLimit
, BitTorrent::Session::instance()->globalUploadSpeedLimit());
const BitTorrent::Session *session = BitTorrent::Session::instance();
const bool isAltLimitEnabled = session->isAltGlobalSpeedLimitEnabled();
OldSpeedLimits oldSpeedLimits = {
oldUploadLimit,
oldDownloadLimit,
isAltLimitEnabled ? session->altGlobalUploadSpeedLimit() : session->globalUploadSpeedLimit(),
isAltLimitEnabled ? session->altGlobalDownloadSpeedLimit() : session->globalDownloadSpeedLimit(),
};
NewSpeedLimits newSpeedLimits;
const bool ok = SpeedLimitDialog::askNewSpeedLimits(this, oldSpeedLimits, newSpeedLimits);
if (!ok) return;
for (BitTorrent::TorrentHandle *const torrent : asConst(torrentsList))
{
qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (newLimit / 1024l), qUtf8Printable(torrent->hash()));
torrent->setUploadLimit(newLimit);
for (BitTorrent::TorrentHandle *const torrent : torrentsList) {
torrent->setUploadLimit(newSpeedLimits.uploadLimit);
torrent->setDownloadLimit(newSpeedLimits.downloadLimit);
}
}
@ -899,10 +881,8 @@ void TransferListWidget::displayListMenu(const QPoint &) @@ -899,10 +881,8 @@ void TransferListWidget::displayListMenu(const QPoint &)
connect(actionPreviewFile, &QAction::triggered, this, &TransferListWidget::previewSelectedTorrents);
auto *actionSetMaxRatio = new QAction(UIThemeManager::instance()->getIcon(QLatin1String("ratio")), tr("Limit share ratio..."), listMenu);
connect(actionSetMaxRatio, &QAction::triggered, this, &TransferListWidget::setMaxRatioSelectedTorrents);
auto *actionSetUploadLimit = new QAction(UIThemeManager::instance()->getIcon("kt-set-max-upload-speed"), tr("Limit upload rate..."), listMenu);
connect(actionSetUploadLimit, &QAction::triggered, this, &TransferListWidget::setUpLimitSelectedTorrents);
auto *actionSetDownloadLimit = new QAction(UIThemeManager::instance()->getIcon("kt-set-max-download-speed"), tr("Limit download rate..."), listMenu);
connect(actionSetDownloadLimit, &QAction::triggered, this, &TransferListWidget::setDlLimitSelectedTorrents);
auto *actionSetSpeedLimits = new QAction(UIThemeManager::instance()->getIcon("speedometer"), tr("Limit speed rates..."), listMenu);
connect(actionSetSpeedLimits, &QAction::triggered, this, &TransferListWidget::setSpeedLimitsSelectedTorrents);
auto *actionOpenDestinationFolder = new QAction(UIThemeManager::instance()->getIcon("inode-directory"), tr("Open destination folder"), listMenu);
connect(actionOpenDestinationFolder, &QAction::triggered, this, &TransferListWidget::openSelectedTorrentsFolder);
auto *actionIncreaseQueuePos = new QAction(UIThemeManager::instance()->getIcon("go-up"), tr("Move up", "i.e. move up in the queue"), listMenu);
@ -1132,9 +1112,7 @@ void TransferListWidget::displayListMenu(const QPoint &) @@ -1132,9 +1112,7 @@ void TransferListWidget::displayListMenu(const QPoint &)
listMenu->addAction(actionAutoTMM);
listMenu->addSeparator();
if (oneNotSeed)
listMenu->addAction(actionSetDownloadLimit);
listMenu->addAction(actionSetUploadLimit);
listMenu->addAction(actionSetSpeedLimits);
listMenu->addAction(actionSetMaxRatio);
if (!oneNotSeed && oneHasMetadata)
{

3
src/gui/transferlistwidget.h

@ -79,8 +79,7 @@ public slots: @@ -79,8 +79,7 @@ public slots:
void openSelectedTorrentsFolder() const;
void recheckSelectedTorrents();
void reannounceSelectedTorrents();
void setDlLimitSelectedTorrents();
void setUpLimitSelectedTorrents();
void setSpeedLimitsSelectedTorrents();
void setMaxRatioSelectedTorrents();
void previewSelectedTorrents();
void hideQueuePosColumn(bool hide);

Loading…
Cancel
Save