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)
m_ui->actionOpen->setIcon(UIThemeManager::instance()->getIcon("list-add")); m_ui->actionOpen->setIcon(UIThemeManager::instance()->getIcon("list-add"));
m_ui->actionDownloadFromURL->setIcon(UIThemeManager::instance()->getIcon("insert-link")); m_ui->actionDownloadFromURL->setIcon(UIThemeManager::instance()->getIcon("insert-link"));
m_ui->actionSetUploadLimit->setIcon(UIThemeManager::instance()->getIcon("kt-set-max-upload-speed")); m_ui->actionSetGlobalSpeedLimits->setIcon(UIThemeManager::instance()->getIcon("speedometer"));
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->actionCreateTorrent->setIcon(UIThemeManager::instance()->getIcon("document-edit")); m_ui->actionCreateTorrent->setIcon(UIThemeManager::instance()->getIcon("document-edit"));
m_ui->actionAbout->setIcon(UIThemeManager::instance()->getIcon("help-about")); m_ui->actionAbout->setIcon(UIThemeManager::instance()->getIcon("help-about"));
m_ui->actionStatistics->setIcon(UIThemeManager::instance()->getIcon("view-statistics")); m_ui->actionStatistics->setIcon(UIThemeManager::instance()->getIcon("view-statistics"));
@ -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)); , 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; auto dialog = new SpeedLimitDialog {this};
dialog->setAttribute(Qt::WA_DeleteOnClose);
BitTorrent::Session *const session = BitTorrent::Session::instance(); dialog->open();
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);
}
} }
// Necessary if we want to close the window // Necessary if we want to close the window
@ -1808,8 +1780,7 @@ QMenu *MainWindow::trayIconMenu()
updateAltSpeedsBtn(isAltBWEnabled); updateAltSpeedsBtn(isAltBWEnabled);
m_ui->actionUseAlternativeSpeedLimits->setChecked(isAltBWEnabled); m_ui->actionUseAlternativeSpeedLimits->setChecked(isAltBWEnabled);
m_trayIconMenu->addAction(m_ui->actionUseAlternativeSpeedLimits); m_trayIconMenu->addAction(m_ui->actionUseAlternativeSpeedLimits);
m_trayIconMenu->addAction(m_ui->actionSetGlobalDownloadLimit); m_trayIconMenu->addAction(m_ui->actionSetGlobalSpeedLimits);
m_trayIconMenu->addAction(m_ui->actionSetGlobalUploadLimit);
m_trayIconMenu->addSeparator(); m_trayIconMenu->addSeparator();
m_trayIconMenu->addAction(m_ui->actionStartAll); m_trayIconMenu->addAction(m_ui->actionStartAll);
m_trayIconMenu->addAction(m_ui->actionPauseAll); m_trayIconMenu->addAction(m_ui->actionPauseAll);

3
src/gui/mainwindow.h

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

19
src/gui/mainwindow.ui

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

137
src/gui/speedlimitdialog.cpp

@ -28,80 +28,107 @@
#include "speedlimitdialog.h" #include "speedlimitdialog.h"
#include <QStyle>
#include "base/bittorrent/session.h"
#include "ui_speedlimitdialog.h" #include "ui_speedlimitdialog.h"
#include "uithememanager.h"
#include "utils.h" #include "utils.h"
SpeedLimitDialog::SpeedLimitDialog(QWidget *parent) namespace
: QDialog(parent)
, m_ui(new Ui::SpeedLimitDialog)
{ {
m_ui->setupUi(this); void updateSliderValue(QSlider *slider, const int value)
{
// Connect to slots if (value > slider->maximum())
connect(m_ui->bandwidthSlider, &QSlider::valueChanged, this, &SpeedLimitDialog::updateSpinValue); slider->setMaximum(value);
connect(m_ui->spinBandwidth, qOverload<int>(&QSpinBox::valueChanged) slider->setValue(value);
, this, &SpeedLimitDialog::updateSliderValue); }
Utils::Gui::resize(this);
}
SpeedLimitDialog::~SpeedLimitDialog()
{
delete m_ui;
} }
// -2: if cancel SpeedLimitDialog::SpeedLimitDialog(QWidget *parent)
long SpeedLimitDialog::askSpeedLimit(QWidget *parent, bool *ok, const QString &title, const long defaultVal, const long maxVal) : QDialog {parent}
, m_ui {new Ui::SpeedLimitDialog}
{ {
if (ok) *ok = false; m_ui->setupUi(this);
SpeedLimitDialog dlg(parent); m_ui->labelGlobalSpeedIcon->setPixmap(Utils::Gui::scaledPixmap(UIThemeManager::instance()->getIcon(QLatin1String("slow_off"))
dlg.setWindowTitle(title); , this, style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this)));
dlg.setupDialog((maxVal / 1024.), (defaultVal / 1024.)); 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; slider->setMaximum(maximum);
slider->setValue(value);
const int val = dlg.getSpeedLimit(); };
if (val < 0) const auto *session = BitTorrent::Session::instance();
return 0; const int uploadVal = qMax(0, (session->globalUploadSpeedLimit() / 1024));
return (val * 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));
return -2; 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) Utils::Gui::resize(this);
{
m_ui->spinBandwidth->setValue(value);
} }
void SpeedLimitDialog::updateSliderValue(const int value) SpeedLimitDialog::~SpeedLimitDialog()
{ {
if (value > m_ui->bandwidthSlider->maximum()) delete m_ui;
m_ui->bandwidthSlider->setMaximum(value);
m_ui->bandwidthSlider->setValue(value);
} }
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) const int downloadLimit = (m_ui->spinDownloadLimit->value() * 1024);
{ if (m_initialValues.downloadSpeedLimit != m_ui->spinDownloadLimit->value())
val = qMax<long>(0, val); session->setGlobalDownloadSpeedLimit(downloadLimit);
if (maxSlider <= 0) const int altUploadLimit = (m_ui->spinAltUploadLimit->value() * 1024);
maxSlider = 10000; if (m_initialValues.altUploadSpeedLimit != m_ui->spinAltUploadLimit->value())
session->setAltGlobalUploadSpeedLimit(altUploadLimit);
// This can happen for example if global rate limit is lower const int altDownloadLimit = (m_ui->spinAltDownloadLimit->value() * 1024);
// than torrent rate limit. if (m_initialValues.altDownloadSpeedLimit != m_ui->spinAltDownloadLimit->value())
if (val > maxSlider) session->setAltGlobalDownloadSpeedLimit(altDownloadLimit);
maxSlider = val;
m_ui->bandwidthSlider->setMaximum(maxSlider); QDialog::accept();
m_ui->bandwidthSlider->setValue(val);
updateSpinValue(val);
} }

20
src/gui/speedlimitdialog.h

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

180
src/gui/speedlimitdialog.ui

@ -6,34 +6,166 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>338</width> <width>481</width>
<height>83</height> <height>272</height>
</rect> </rect>
</property> </property>
<property name="windowTitle">
<string>Global Speed Limits</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <widget class="QGroupBox" name="groupBox">
<item> <property name="title">
<widget class="QSlider" name="bandwidthSlider"> <string>Speed limits</string>
<property name="orientation"> </property>
<enum>Qt::Horizontal</enum> <layout class="QGridLayout" name="gridLayout">
</property> <item row="0" column="0" rowspan="2">
</widget> <widget class="QLabel" name="labelGlobalSpeedIcon">
</item> <property name="text">
<item> <string/>
<widget class="QSpinBox" name="spinBandwidth"> </property>
<property name="specialValueText"> </widget>
<string>∞</string> </item>
</property> <item row="0" column="1">
<property name="suffix"> <widget class="QLabel" name="label">
<string> KiB/s</string> <property name="text">
</property> <string>Upload:</string>
<property name="maximum"> </property>
<number>65535</number> </widget>
</property> </item>
</widget> <item row="0" column="2">
</item> <widget class="QSlider" name="sliderUploadLimit">
</layout> <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>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">

35
src/gui/statusbar.cpp

@ -71,7 +71,7 @@ StatusBar::StatusBar(QWidget *parent)
m_dlSpeedLbl = new QPushButton(this); m_dlSpeedLbl = new QPushButton(this);
m_dlSpeedLbl->setIcon(UIThemeManager::instance()->getIcon(QLatin1String("downloading_small"))); 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->setFlat(true);
m_dlSpeedLbl->setFocusPolicy(Qt::NoFocus); m_dlSpeedLbl->setFocusPolicy(Qt::NoFocus);
m_dlSpeedLbl->setCursor(Qt::PointingHandCursor); m_dlSpeedLbl->setCursor(Qt::PointingHandCursor);
@ -80,7 +80,7 @@ StatusBar::StatusBar(QWidget *parent)
m_upSpeedLbl = new QPushButton(this); m_upSpeedLbl = new QPushButton(this);
m_upSpeedLbl->setIcon(UIThemeManager::instance()->getIcon(QLatin1String("seeding"))); 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->setFlat(true);
m_upSpeedLbl->setFocusPolicy(Qt::NoFocus); m_upSpeedLbl->setFocusPolicy(Qt::NoFocus);
m_upSpeedLbl->setCursor(Qt::PointingHandCursor); m_upSpeedLbl->setCursor(Qt::PointingHandCursor);
@ -251,32 +251,9 @@ void StatusBar::updateAltSpeedsBtn(bool alternative)
refresh(); refresh();
} }
void StatusBar::capDownloadSpeed() void StatusBar::capSpeed()
{ {
BitTorrent::Session *const session = BitTorrent::Session::instance(); auto dialog = new SpeedLimitDialog {parentWidget()};
dialog->setAttribute(Qt::WA_DeleteOnClose);
bool ok = false; dialog->open();
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();
}
} }

3
src/gui/statusbar.h

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

76
src/gui/transferlistwidget.cpp

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

3
src/gui/transferlistwidget.h

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

Loading…
Cancel
Save