Browse Source

Merge pull request #13885 from thalieht/torrentOptionsDialog

Rework global speed limit dialog and introduce torrent options dialog
adaptive-webui-19844
Mike Tzou 4 years ago committed by GitHub
parent
commit
60d65d8137
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/base/bittorrent/torrenthandle.h
  2. 63
      src/base/bittorrent/torrenthandleimpl.cpp
  3. 6
      src/base/bittorrent/torrenthandleimpl.h
  4. 1
      src/base/unicodestrings.h
  5. 6
      src/gui/CMakeLists.txt
  6. 8
      src/gui/gui.pri
  7. 41
      src/gui/mainwindow.cpp
  8. 3
      src/gui/mainwindow.h
  9. 19
      src/gui/mainwindow.ui
  10. 8
      src/gui/optionsdialog.ui
  11. 30
      src/gui/properties/trackerlistwidget.cpp
  12. 137
      src/gui/speedlimitdialog.cpp
  13. 20
      src/gui/speedlimitdialog.h
  14. 146
      src/gui/speedlimitdialog.ui
  15. 35
      src/gui/statusbar.cpp
  16. 3
      src/gui/statusbar.h
  17. 368
      src/gui/torrentoptionsdialog.cpp
  18. 45
      src/gui/torrentoptionsdialog.h
  19. 278
      src/gui/torrentoptionsdialog.ui
  20. 112
      src/gui/transferlistwidget.cpp
  21. 4
      src/gui/transferlistwidget.h
  22. 137
      src/gui/updownratiodialog.cpp
  23. 177
      src/gui/updownratiodialog.ui

6
src/base/bittorrent/torrenthandle.h

@ -238,6 +238,9 @@ namespace BitTorrent
virtual int downloadLimit() const = 0; virtual int downloadLimit() const = 0;
virtual int uploadLimit() const = 0; virtual int uploadLimit() const = 0;
virtual bool superSeeding() const = 0; virtual bool superSeeding() const = 0;
virtual bool isDHTDisabled() const = 0;
virtual bool isPEXDisabled() const = 0;
virtual bool isLSDDisabled() const = 0;
virtual QVector<PeerInfo> peers() const = 0; virtual QVector<PeerInfo> peers() const = 0;
virtual QBitArray pieces() const = 0; virtual QBitArray pieces() const = 0;
virtual QBitArray downloadingPieces() const = 0; virtual QBitArray downloadingPieces() const = 0;
@ -277,6 +280,9 @@ namespace BitTorrent
virtual void setUploadLimit(int limit) = 0; virtual void setUploadLimit(int limit) = 0;
virtual void setDownloadLimit(int limit) = 0; virtual void setDownloadLimit(int limit) = 0;
virtual void setSuperSeeding(bool enable) = 0; virtual void setSuperSeeding(bool enable) = 0;
virtual void setDHTDisabled(bool disable) = 0;
virtual void setPEXDisabled(bool disable) = 0;
virtual void setLSDDisabled(bool disable) = 0;
virtual void flushCache() const = 0; virtual void flushCache() const = 0;
virtual void addTrackers(const QVector<TrackerEntry> &trackers) = 0; virtual void addTrackers(const QVector<TrackerEntry> &trackers) = 0;
virtual void replaceTrackers(const QVector<TrackerEntry> &trackers) = 0; virtual void replaceTrackers(const QVector<TrackerEntry> &trackers) = 0;

63
src/base/bittorrent/torrenthandleimpl.cpp

@ -1016,6 +1016,21 @@ bool TorrentHandleImpl::superSeeding() const
return static_cast<bool>(m_nativeStatus.flags & lt::torrent_flags::super_seeding); return static_cast<bool>(m_nativeStatus.flags & lt::torrent_flags::super_seeding);
} }
bool TorrentHandleImpl::isDHTDisabled() const
{
return static_cast<bool>(m_nativeStatus.flags & lt::torrent_flags::disable_dht);
}
bool TorrentHandleImpl::isPEXDisabled() const
{
return static_cast<bool>(m_nativeStatus.flags & lt::torrent_flags::disable_pex);
}
bool TorrentHandleImpl::isLSDDisabled() const
{
return static_cast<bool>(m_nativeStatus.flags & lt::torrent_flags::disable_lsd);
}
QVector<PeerInfo> TorrentHandleImpl::peers() const QVector<PeerInfo> TorrentHandleImpl::peers() const
{ {
std::vector<lt::peer_info> nativePeers; std::vector<lt::peer_info> nativePeers;
@ -1935,20 +1950,68 @@ void TorrentHandleImpl::setSeedingTimeLimit(int limit)
void TorrentHandleImpl::setUploadLimit(const int limit) void TorrentHandleImpl::setUploadLimit(const int limit)
{ {
if (limit == uploadLimit())
return;
m_nativeHandle.set_upload_limit(limit); m_nativeHandle.set_upload_limit(limit);
saveResumeData();
} }
void TorrentHandleImpl::setDownloadLimit(const int limit) void TorrentHandleImpl::setDownloadLimit(const int limit)
{ {
if (limit == downloadLimit())
return;
m_nativeHandle.set_download_limit(limit); m_nativeHandle.set_download_limit(limit);
saveResumeData();
} }
void TorrentHandleImpl::setSuperSeeding(const bool enable) void TorrentHandleImpl::setSuperSeeding(const bool enable)
{ {
if (enable == superSeeding())
return;
if (enable) if (enable)
m_nativeHandle.set_flags(lt::torrent_flags::super_seeding); m_nativeHandle.set_flags(lt::torrent_flags::super_seeding);
else else
m_nativeHandle.unset_flags(lt::torrent_flags::super_seeding); m_nativeHandle.unset_flags(lt::torrent_flags::super_seeding);
saveResumeData();
}
void TorrentHandleImpl::setDHTDisabled(const bool disable)
{
if (disable == isDHTDisabled())
return;
if (disable)
m_nativeHandle.set_flags(lt::torrent_flags::disable_dht);
else
m_nativeHandle.unset_flags(lt::torrent_flags::disable_dht);
saveResumeData();
}
void TorrentHandleImpl::setPEXDisabled(const bool disable)
{
if (disable == isPEXDisabled())
return;
if (disable)
m_nativeHandle.set_flags(lt::torrent_flags::disable_pex);
else
m_nativeHandle.unset_flags(lt::torrent_flags::disable_pex);
saveResumeData();
}
void TorrentHandleImpl::setLSDDisabled(const bool disable)
{
if (disable == isLSDDisabled())
return;
if (disable)
m_nativeHandle.set_flags(lt::torrent_flags::disable_lsd);
else
m_nativeHandle.unset_flags(lt::torrent_flags::disable_lsd);
saveResumeData();
} }
void TorrentHandleImpl::flushCache() const void TorrentHandleImpl::flushCache() const

6
src/base/bittorrent/torrenthandleimpl.h

@ -191,6 +191,9 @@ namespace BitTorrent
int downloadLimit() const override; int downloadLimit() const override;
int uploadLimit() const override; int uploadLimit() const override;
bool superSeeding() const override; bool superSeeding() const override;
bool isDHTDisabled() const override;
bool isPEXDisabled() const override;
bool isLSDDisabled() const override;
QVector<PeerInfo> peers() const override; QVector<PeerInfo> peers() const override;
QBitArray pieces() const override; QBitArray pieces() const override;
QBitArray downloadingPieces() const override; QBitArray downloadingPieces() const override;
@ -224,6 +227,9 @@ namespace BitTorrent
void setUploadLimit(int limit) override; void setUploadLimit(int limit) override;
void setDownloadLimit(int limit) override; void setDownloadLimit(int limit) override;
void setSuperSeeding(bool enable) override; void setSuperSeeding(bool enable) override;
void setDHTDisabled(bool disable) override;
void setPEXDisabled(bool disable) override;
void setLSDDisabled(bool disable) override;
void flushCache() const override; void flushCache() const override;
void addTrackers(const QVector<TrackerEntry> &trackers) override; void addTrackers(const QVector<TrackerEntry> &trackers) override;
void replaceTrackers(const QVector<TrackerEntry> &trackers) override; void replaceTrackers(const QVector<TrackerEntry> &trackers) override;

1
src/base/unicodestrings.h

@ -38,6 +38,7 @@
// See issue #3059 for more details (https://github.com/qbittorrent/qBittorrent/issues/3059). // See issue #3059 for more details (https://github.com/qbittorrent/qBittorrent/issues/3059).
const char C_COPYRIGHT[] = "©"; const char C_COPYRIGHT[] = "©";
const char C_INEQUALITY[] = "";
const char C_INFINITY[] = ""; const char C_INFINITY[] = "";
const char C_NON_BREAKING_SPACE[] = " "; const char C_NON_BREAKING_SPACE[] = " ";
const char C_THIN_SPACE[] = ""; const char C_THIN_SPACE[] = "";

6
src/gui/CMakeLists.txt

@ -67,6 +67,7 @@ add_library(qbt_gui STATIC
torrentcontentmodelitem.h torrentcontentmodelitem.h
torrentcontenttreeview.h torrentcontenttreeview.h
torrentcreatordialog.h torrentcreatordialog.h
torrentoptionsdialog.h
trackerentriesdialog.h trackerentriesdialog.h
transferlistdelegate.h transferlistdelegate.h
transferlistfilterswidget.h transferlistfilterswidget.h
@ -76,7 +77,6 @@ add_library(qbt_gui STATIC
tristateaction.h tristateaction.h
tristatewidget.h tristatewidget.h
uithememanager.h uithememanager.h
updownratiodialog.h
utils.h utils.h
# sources # sources
@ -147,6 +147,7 @@ add_library(qbt_gui STATIC
torrentcontentmodelitem.cpp torrentcontentmodelitem.cpp
torrentcontenttreeview.cpp torrentcontenttreeview.cpp
torrentcreatordialog.cpp torrentcreatordialog.cpp
torrentoptionsdialog.cpp
trackerentriesdialog.cpp trackerentriesdialog.cpp
transferlistdelegate.cpp transferlistdelegate.cpp
transferlistfilterswidget.cpp transferlistfilterswidget.cpp
@ -156,7 +157,6 @@ add_library(qbt_gui STATIC
tristateaction.cpp tristateaction.cpp
tristatewidget.cpp tristatewidget.cpp
uithememanager.cpp uithememanager.cpp
updownratiodialog.cpp
utils.cpp utils.cpp
# forms # forms
@ -186,8 +186,8 @@ add_library(qbt_gui STATIC
statsdialog.ui statsdialog.ui
torrentcategorydialog.ui torrentcategorydialog.ui
torrentcreatordialog.ui torrentcreatordialog.ui
torrentoptionsdialog.ui
trackerentriesdialog.ui trackerentriesdialog.ui
updownratiodialog.ui
) )
target_sources(qbt_gui INTERFACE about.qrc) target_sources(qbt_gui INTERFACE about.qrc)

8
src/gui/gui.pri

@ -68,6 +68,7 @@ HEADERS += \
$$PWD/torrentcontentmodelitem.h \ $$PWD/torrentcontentmodelitem.h \
$$PWD/torrentcontenttreeview.h \ $$PWD/torrentcontenttreeview.h \
$$PWD/torrentcreatordialog.h \ $$PWD/torrentcreatordialog.h \
$$PWD/torrentoptionsdialog.h \
$$PWD/trackerentriesdialog.h \ $$PWD/trackerentriesdialog.h \
$$PWD/transferlistdelegate.h \ $$PWD/transferlistdelegate.h \
$$PWD/transferlistfilterswidget.h \ $$PWD/transferlistfilterswidget.h \
@ -77,7 +78,6 @@ HEADERS += \
$$PWD/tristateaction.h \ $$PWD/tristateaction.h \
$$PWD/tristatewidget.h \ $$PWD/tristatewidget.h \
$$PWD/uithememanager.h \ $$PWD/uithememanager.h \
$$PWD/updownratiodialog.h \
$$PWD/utils.h $$PWD/utils.h
SOURCES += \ SOURCES += \
@ -148,6 +148,7 @@ SOURCES += \
$$PWD/torrentcontentmodelitem.cpp \ $$PWD/torrentcontentmodelitem.cpp \
$$PWD/torrentcontenttreeview.cpp \ $$PWD/torrentcontenttreeview.cpp \
$$PWD/torrentcreatordialog.cpp \ $$PWD/torrentcreatordialog.cpp \
$$PWD/torrentoptionsdialog.cpp \
$$PWD/trackerentriesdialog.cpp \ $$PWD/trackerentriesdialog.cpp \
$$PWD/transferlistdelegate.cpp \ $$PWD/transferlistdelegate.cpp \
$$PWD/transferlistfilterswidget.cpp \ $$PWD/transferlistfilterswidget.cpp \
@ -157,7 +158,6 @@ SOURCES += \
$$PWD/tristateaction.cpp \ $$PWD/tristateaction.cpp \
$$PWD/tristatewidget.cpp \ $$PWD/tristatewidget.cpp \
$$PWD/uithememanager.cpp \ $$PWD/uithememanager.cpp \
$$PWD/updownratiodialog.cpp \
$$PWD/utils.cpp $$PWD/utils.cpp
win32|macx { win32|macx {
@ -207,7 +207,7 @@ FORMS += \
$$PWD/statsdialog.ui \ $$PWD/statsdialog.ui \
$$PWD/torrentcategorydialog.ui \ $$PWD/torrentcategorydialog.ui \
$$PWD/torrentcreatordialog.ui \ $$PWD/torrentcreatordialog.ui \
$$PWD/trackerentriesdialog.ui \ $$PWD/torrentoptionsdialog.ui \
$$PWD/updownratiodialog.ui $$PWD/trackerentriesdialog.ui
RESOURCES += $$PWD/about.qrc RESOURCES += $$PWD/about.qrc

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">

8
src/gui/optionsdialog.ui

@ -1902,7 +1902,7 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s
<string> KiB/s</string> <string> KiB/s</string>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>1000000</number> <number>2000000</number>
</property> </property>
<property name="value"> <property name="value">
<number>100</number> <number>100</number>
@ -1918,7 +1918,7 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s
<string> KiB/s</string> <string> KiB/s</string>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>1000000</number> <number>2000000</number>
</property> </property>
<property name="value"> <property name="value">
<number>100</number> <number>100</number>
@ -1973,7 +1973,7 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s
<string> KiB/s</string> <string> KiB/s</string>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>1000000</number> <number>2000000</number>
</property> </property>
<property name="value"> <property name="value">
<number>10</number> <number>10</number>
@ -2109,7 +2109,7 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s
<string> KiB/s</string> <string> KiB/s</string>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>1000000</number> <number>2000000</number>
</property> </property>
<property name="value"> <property name="value">
<number>10</number> <number>10</number>

30
src/gui/properties/trackerlistwidget.cpp

@ -283,26 +283,34 @@ void TrackerListWidget::clear()
void TrackerListWidget::loadStickyItems(const BitTorrent::TorrentHandle *torrent) void TrackerListWidget::loadStickyItems(const BitTorrent::TorrentHandle *torrent)
{ {
QString working = tr("Working"); const QString working {tr("Working")};
QString disabled = tr("Disabled"); const QString disabled {tr("Disabled")};
const QString torrentDisabled {tr("Disabled for this torrent")};
const auto *session = BitTorrent::Session::instance();
// load DHT information // load DHT information
if (BitTorrent::Session::instance()->isDHTEnabled() && !torrent->isPrivate()) if (torrent->isPrivate() || torrent->isDHTDisabled())
m_DHTItem->setText(COL_STATUS, working); m_DHTItem->setText(COL_STATUS, torrentDisabled);
else else if (!session->isDHTEnabled())
m_DHTItem->setText(COL_STATUS, disabled); m_DHTItem->setText(COL_STATUS, disabled);
else
m_DHTItem->setText(COL_STATUS, working);
// Load PeX Information // Load PeX Information
if (BitTorrent::Session::instance()->isPeXEnabled() && !torrent->isPrivate()) if (torrent->isPrivate() || torrent->isPEXDisabled())
m_PEXItem->setText(COL_STATUS, working); m_PEXItem->setText(COL_STATUS, torrentDisabled);
else else if (!session->isPeXEnabled())
m_PEXItem->setText(COL_STATUS, disabled); m_PEXItem->setText(COL_STATUS, disabled);
else
m_PEXItem->setText(COL_STATUS, working);
// Load LSD Information // Load LSD Information
if (BitTorrent::Session::instance()->isLSDEnabled() && !torrent->isPrivate()) if (torrent->isPrivate() || torrent->isLSDDisabled())
m_LSDItem->setText(COL_STATUS, working); m_LSDItem->setText(COL_STATUS, torrentDisabled);
else else if (!session->isLSDEnabled())
m_LSDItem->setText(COL_STATUS, disabled); m_LSDItem->setText(COL_STATUS, disabled);
else
m_LSDItem->setText(COL_STATUS, working);
if (torrent->isPrivate()) if (torrent->isPrivate())
{ {

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;
}; };

146
src/gui/speedlimitdialog.ui

@ -6,22 +6,140 @@
<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>
<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"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </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> <item>
<widget class="QSpinBox" name="spinBandwidth"> <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"> <property name="specialValueText">
<string>∞</string> <string>∞</string>
</property> </property>
@ -29,11 +147,25 @@
<string> KiB/s</string> <string> KiB/s</string>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>65535</number> <number>2000000</number>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </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();

368
src/gui/torrentoptionsdialog.cpp

@ -0,0 +1,368 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#include "torrentoptionsdialog.h"
#include <QMessageBox>
#include <QString>
#include "base/bittorrent/infohash.h"
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/global.h"
#include "base/unicodestrings.h"
#include "ui_torrentoptionsdialog.h"
#include "utils.h"
namespace
{
const int MIXED_SHARE_LIMITS = -9;
void updateSliderValue(QSlider *slider, const int value)
{
if (value > slider->maximum())
slider->setMaximum(value);
slider->setValue(value);
}
}
TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTorrent::TorrentHandle *> &torrents)
: QDialog {parent}
, m_ui {new Ui::TorrentOptionsDialog}
{
m_ui->setupUi(this);
Q_ASSERT(!torrents.empty());
const auto *session = BitTorrent::Session::instance();
bool allSameUpLimit = true, allSameDownLimit = true, allSameRatio = true, allSameSeedingTime = true
, allTorrentsArePrivate = true, allSameDHT = true, allSamePEX = true, allSameLSD = true;
const int firstTorrentUpLimit = qMax(0, torrents[0]->uploadLimit());
const int firstTorrentDownLimit = qMax(0, torrents[0]->downloadLimit());
const qreal firstTorrentRatio = torrents[0]->ratioLimit();
const int firstTorrentSeedingTime = torrents[0]->seedingTimeLimit();
const bool isFirstTorrentDHTDisabled = torrents[0]->isDHTDisabled();
const bool isFirstTorrentPEXDisabled = torrents[0]->isPEXDisabled();
const bool isFirstTorrentLSDDisabled = torrents[0]->isLSDDisabled();
m_torrentHashes.reserve(torrents.size());
for (const BitTorrent::TorrentHandle *torrent : torrents)
{
m_torrentHashes << torrent->hash();
if (allSameUpLimit)
{
if (qMax(0, torrent->uploadLimit()) != firstTorrentUpLimit)
allSameUpLimit = false;
}
if (allSameDownLimit)
{
if (qMax(0, torrent->downloadLimit()) != firstTorrentDownLimit)
allSameDownLimit = false;
}
if (allSameRatio)
{
if (torrent->ratioLimit() != firstTorrentRatio)
allSameRatio = false;
}
if (allSameSeedingTime)
{
if (torrent->seedingTimeLimit() != firstTorrentSeedingTime)
allSameSeedingTime = false;
}
if (allTorrentsArePrivate)
{
if (!torrent->isPrivate())
allTorrentsArePrivate = false;
}
if (allSameDHT)
{
if (torrent->isDHTDisabled() != isFirstTorrentDHTDisabled)
{
m_ui->checkDisableDHT->setCheckState(Qt::PartiallyChecked);
allSameDHT = false;
}
}
if (allSamePEX)
{
if (torrent->isPEXDisabled() != isFirstTorrentPEXDisabled)
{
m_ui->checkDisablePEX->setCheckState(Qt::PartiallyChecked);
allSamePEX = false;
}
}
if (allSameLSD)
{
if (torrent->isLSDDisabled() != isFirstTorrentLSDDisabled)
{
m_ui->checkDisableLSD->setCheckState(Qt::PartiallyChecked);
allSameLSD = false;
}
}
}
const bool isAltLimitEnabled = session->isAltGlobalSpeedLimitEnabled();
const int globalUploadLimit = isAltLimitEnabled
? (session->altGlobalUploadSpeedLimit() / 1024)
: (session->globalUploadSpeedLimit() / 1024);
const int globalDownloadLimit = isAltLimitEnabled
? (session->altGlobalDownloadSpeedLimit() / 1024)
: (session->globalDownloadSpeedLimit() / 1024);
const int uploadVal = qMax(0, (firstTorrentUpLimit / 1024));
const int downloadVal = qMax(0, (firstTorrentDownLimit / 1024));
int maxUpload = (globalUploadLimit <= 0) ? 10000 : globalUploadLimit;
int maxDownload = (globalDownloadLimit <= 0) ? 10000 : globalDownloadLimit;
// This can happen for example if global rate limit is lower than torrent rate limit.
if (uploadVal > maxUpload)
maxUpload = uploadVal;
if (downloadVal > maxDownload)
maxDownload = downloadVal;
m_ui->sliderUploadLimit->setMaximum(maxUpload);
m_ui->sliderUploadLimit->setValue(allSameUpLimit ? uploadVal : (maxUpload / 2));
if (allSameUpLimit)
{
m_ui->spinUploadLimit->setValue(uploadVal);
}
else
{
m_ui->spinUploadLimit->setSpecialValueText(QString::fromUtf8(C_INEQUALITY));
m_ui->spinUploadLimit->setMinimum(-1);
m_ui->spinUploadLimit->setValue(-1);
connect(m_ui->spinUploadLimit, qOverload<int>(&QSpinBox::valueChanged)
, this, &TorrentOptionsDialog::handleUpSpeedLimitChanged);
}
m_ui->sliderDownloadLimit->setMaximum(maxDownload);
m_ui->sliderDownloadLimit->setValue(allSameDownLimit ? downloadVal : (maxDownload / 2));
if (allSameDownLimit)
{
m_ui->spinDownloadLimit->setValue(downloadVal);
}
else
{
m_ui->spinDownloadLimit->setSpecialValueText(QString::fromUtf8(C_INEQUALITY));
m_ui->spinDownloadLimit->setMinimum(-1);
m_ui->spinDownloadLimit->setValue(-1);
connect(m_ui->spinDownloadLimit, qOverload<int>(&QSpinBox::valueChanged)
, this, &TorrentOptionsDialog::handleDownSpeedLimitChanged);
}
const bool useGlobalValue = allSameRatio && allSameSeedingTime
&& (firstTorrentRatio == BitTorrent::TorrentHandle::USE_GLOBAL_RATIO)
&& (firstTorrentSeedingTime == BitTorrent::TorrentHandle::USE_GLOBAL_SEEDING_TIME);
if (!allSameRatio || !allSameSeedingTime)
{
m_ui->radioUseGlobalShareLimits->setChecked(false);
m_ui->radioNoLimit->setChecked(false);
m_ui->radioTorrentLimit->setChecked(false);
}
else if (useGlobalValue)
{
m_ui->radioUseGlobalShareLimits->setChecked(true);
}
else if ((firstTorrentRatio == BitTorrent::TorrentHandle::NO_RATIO_LIMIT)
&& (firstTorrentSeedingTime == BitTorrent::TorrentHandle::NO_SEEDING_TIME_LIMIT))
{
m_ui->radioNoLimit->setChecked(true);
}
else
{
m_ui->radioTorrentLimit->setChecked(true);
if (firstTorrentRatio >= 0)
m_ui->checkMaxRatio->setChecked(true);
if (firstTorrentSeedingTime >= 0)
m_ui->checkMaxTime->setChecked(true);
}
const qreal maxRatio = (allSameRatio && (firstTorrentRatio >= 0))
? firstTorrentRatio : session->globalMaxRatio();
const int maxSeedingTime = (allSameSeedingTime && (firstTorrentSeedingTime >= 0))
? firstTorrentSeedingTime : session->globalMaxSeedingMinutes();
m_ui->spinRatioLimit->setValue(maxRatio);
m_ui->spinTimeLimit->setValue(maxSeedingTime);
handleRatioTypeChanged();
if (!allTorrentsArePrivate)
{
if (m_ui->checkDisableDHT->checkState() != Qt::PartiallyChecked)
m_ui->checkDisableDHT->setChecked(isFirstTorrentDHTDisabled);
if (m_ui->checkDisablePEX->checkState() != Qt::PartiallyChecked)
m_ui->checkDisablePEX->setChecked(isFirstTorrentPEXDisabled);
if (m_ui->checkDisableLSD->checkState() != Qt::PartiallyChecked)
m_ui->checkDisableLSD->setChecked(isFirstTorrentLSDDisabled);
}
else
{
m_ui->checkDisableDHT->setChecked(true);
m_ui->checkDisableDHT->setEnabled(false);
m_ui->checkDisablePEX->setChecked(true);
m_ui->checkDisablePEX->setEnabled(false);
m_ui->checkDisableLSD->setChecked(true);
m_ui->checkDisableLSD->setEnabled(false);
}
const QString privateTorrentsTooltip = tr("Not applicable to private torrents");
m_ui->checkDisableDHT->setToolTip(privateTorrentsTooltip);
m_ui->checkDisablePEX->setToolTip(privateTorrentsTooltip);
m_ui->checkDisableLSD->setToolTip(privateTorrentsTooltip);
m_initialValues =
{
getRatio(),
getSeedingTime(),
m_ui->spinUploadLimit->value(),
m_ui->spinDownloadLimit->value(),
m_ui->checkDisableDHT->checkState(),
m_ui->checkDisablePEX->checkState(),
m_ui->checkDisableLSD->checkState()
};
// 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->checkMaxRatio, &QCheckBox::toggled, m_ui->spinRatioLimit, &QDoubleSpinBox::setEnabled);
connect(m_ui->checkMaxTime, &QCheckBox::toggled, m_ui->spinTimeLimit, &QSpinBox::setEnabled);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
connect(m_ui->buttonGroup, &QButtonGroup::idClicked, this, &TorrentOptionsDialog::handleRatioTypeChanged);
#else
connect(m_ui->buttonGroup, qOverload<int>(&QButtonGroup::buttonClicked)
, this, &TorrentOptionsDialog::handleRatioTypeChanged);
#endif
Utils::Gui::resize(this);
}
TorrentOptionsDialog::~TorrentOptionsDialog()
{
delete m_ui;
}
void TorrentOptionsDialog::accept()
{
if (m_ui->radioTorrentLimit->isChecked() && !m_ui->checkMaxRatio->isChecked() && !m_ui->checkMaxTime->isChecked())
{
QMessageBox::critical(this, tr("No share limit method selected"), tr("Please select a limit method first"));
return;
}
const auto *session = BitTorrent::Session::instance();
for (const BitTorrent::InfoHash &hash : asConst(m_torrentHashes))
{
BitTorrent::TorrentHandle *torrent = session->findTorrent(hash);
if (!torrent) continue;
if (m_initialValues.upSpeedLimit != m_ui->spinUploadLimit->value())
torrent->setUploadLimit(m_ui->spinUploadLimit->value() * 1024);
if (m_initialValues.downSpeedLimit != m_ui->spinDownloadLimit->value())
torrent->setDownloadLimit(m_ui->spinDownloadLimit->value() * 1024);
const qreal ratioLimit = getRatio();
if (m_initialValues.ratio != ratioLimit)
torrent->setRatioLimit(ratioLimit);
const int seedingTimeLimit = getSeedingTime();
if (m_initialValues.seedingTime != seedingTimeLimit)
torrent->setSeedingTimeLimit(seedingTimeLimit);
if (!torrent->isPrivate())
{
if (m_initialValues.disableDHT != m_ui->checkDisableDHT->checkState())
torrent->setDHTDisabled(m_ui->checkDisableDHT->isChecked());
if (m_initialValues.disablePEX != m_ui->checkDisablePEX->checkState())
torrent->setPEXDisabled(m_ui->checkDisablePEX->isChecked());
if (m_initialValues.disableLSD != m_ui->checkDisableLSD->checkState())
torrent->setLSDDisabled(m_ui->checkDisableLSD->isChecked());
}
}
QDialog::accept();
}
qreal TorrentOptionsDialog::getRatio() const
{
if (m_ui->buttonGroup->checkedId() == -1) // No radio button is selected
return MIXED_SHARE_LIMITS;
if (m_ui->radioUseGlobalShareLimits->isChecked())
return BitTorrent::TorrentHandle::USE_GLOBAL_RATIO;
if (m_ui->radioNoLimit->isChecked() || !m_ui->checkMaxRatio->isChecked())
return BitTorrent::TorrentHandle::NO_RATIO_LIMIT;
return m_ui->spinRatioLimit->value();
}
int TorrentOptionsDialog::getSeedingTime() const
{
if (m_ui->buttonGroup->checkedId() == -1) // No radio button is selected
return MIXED_SHARE_LIMITS;
if (m_ui->radioUseGlobalShareLimits->isChecked())
return BitTorrent::TorrentHandle::USE_GLOBAL_SEEDING_TIME;
if (m_ui->radioNoLimit->isChecked() || !m_ui->checkMaxTime->isChecked())
return BitTorrent::TorrentHandle::NO_SEEDING_TIME_LIMIT;
return m_ui->spinTimeLimit->value();
}
void TorrentOptionsDialog::handleRatioTypeChanged()
{
m_ui->checkMaxRatio->setEnabled(m_ui->radioTorrentLimit->isChecked());
m_ui->checkMaxTime->setEnabled(m_ui->radioTorrentLimit->isChecked());
m_ui->spinRatioLimit->setEnabled(m_ui->radioTorrentLimit->isChecked() && m_ui->checkMaxRatio->isChecked());
m_ui->spinTimeLimit->setEnabled(m_ui->radioTorrentLimit->isChecked() && m_ui->checkMaxTime->isChecked());
}
void TorrentOptionsDialog::handleUpSpeedLimitChanged()
{
m_ui->spinUploadLimit->setMinimum(0);
m_ui->spinUploadLimit->setSpecialValueText(QString::fromUtf8(C_INFINITY));
disconnect(m_ui->spinUploadLimit, qOverload<int>(&QSpinBox::valueChanged)
, this, &TorrentOptionsDialog::handleUpSpeedLimitChanged);
}
void TorrentOptionsDialog::handleDownSpeedLimitChanged()
{
m_ui->spinDownloadLimit->setMinimum(0);
m_ui->spinDownloadLimit->setSpecialValueText(QString::fromUtf8(C_INFINITY));
disconnect(m_ui->spinDownloadLimit, qOverload<int>(&QSpinBox::valueChanged)
, this, &TorrentOptionsDialog::handleDownSpeedLimitChanged);
}

45
src/gui/updownratiodialog.h → src/gui/torrentoptionsdialog.h

@ -1,7 +1,7 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Christian Kandeler * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* Copyright (C) 2011 Christophe Dumez <chris@qbittorrent.org> *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
@ -30,33 +30,48 @@
#include <QDialog> #include <QDialog>
namespace BitTorrent
{
class InfoHash;
class TorrentHandle;
}
namespace Ui namespace Ui
{ {
class UpDownRatioDialog; class TorrentOptionsDialog;
} }
class UpDownRatioDialog final : public QDialog class TorrentOptionsDialog final : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
UpDownRatioDialog(bool useDefault, qreal initialValue, qreal maxValue, explicit TorrentOptionsDialog(QWidget *parent, const QVector<BitTorrent::TorrentHandle *> &torrents);
int initialTimeValue, int maxTimeValue, ~TorrentOptionsDialog() override;
QWidget *parent = nullptr);
~UpDownRatioDialog();
bool useDefault() const;
qreal ratio() const;
int seedingTime() const;
public slots: public slots:
void accept() override; void accept() override;
private slots: private slots:
void handleUpSpeedLimitChanged();
void handleDownSpeedLimitChanged();
void handleRatioTypeChanged(); void handleRatioTypeChanged();
void enableRatioSpin();
void enableTimeSpin();
private: private:
Ui::UpDownRatioDialog *m_ui; qreal getRatio() const;
int getSeedingTime() const;
QVector<BitTorrent::InfoHash> m_torrentHashes;
Ui::TorrentOptionsDialog *m_ui;
struct
{
qreal ratio;
int seedingTime;
int upSpeedLimit;
int downSpeedLimit;
Qt::CheckState disableDHT;
Qt::CheckState disablePEX;
Qt::CheckState disableLSD;
} m_initialValues;
}; };

278
src/gui/torrentoptionsdialog.ui

@ -0,0 +1,278 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TorrentOptionsDialog</class>
<widget class="QDialog" name="TorrentOptionsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>390</width>
<height>450</height>
</rect>
</property>
<property name="windowTitle">
<string>Torrent Options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Torrent speed limits</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Download:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<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>
<item row="0" column="2">
<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="2" column="1" colspan="2">
<widget class="QLabel" name="labelWarning">
<property name="text">
<string>These will not exceed the global limits</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Upload:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="sliderUploadLimit">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="sliderDownloadLimit">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Torrent share limits</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="radioUseGlobalShareLimits">
<property name="text">
<string>Use global share limit</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioNoLimit">
<property name="text">
<string>Set no share limit</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QRadioButton" name="radioTorrentLimit">
<property name="text">
<string>Set share limit to</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkMaxTime">
<property name="text">
<string>minutes</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QDoubleSpinBox" name="spinRatioLimit">
<property name="maximum">
<double>9999.000000000000000</double>
</property>
<property name="singleStep">
<double>0.050000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="spinTimeLimit">
<property name="maximum">
<number>525600</number>
</property>
<property name="value">
<number>1440</number>
</property>
</widget>
</item>
<item row="1" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkMaxRatio">
<property name="text">
<string>ratio</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QCheckBox" name="checkDisableDHT">
<property name="text">
<string>Disable DHT for this torrent</string>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkDisablePEX">
<property name="text">
<string>Disable PeX for this torrent</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkDisableLSD">
<property name="text">
<string>Disable LSD for this torrent</string>
</property>
</widget>
</item>
</layout>
</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">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>TorrentOptionsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>221</x>
<y>73</y>
</hint>
<hint type="destinationlabel">
<x>221</x>
<y>82</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>TorrentOptionsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>277</x>
<y>59</y>
</hint>
<hint type="destinationlabel">
<x>343</x>
<y>80</y>
</hint>
</hints>
</connection>
</connections>
<buttongroups>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>

112
src/gui/transferlistwidget.cpp

@ -62,13 +62,13 @@
#include "previewselectdialog.h" #include "previewselectdialog.h"
#include "speedlimitdialog.h" #include "speedlimitdialog.h"
#include "torrentcategorydialog.h" #include "torrentcategorydialog.h"
#include "torrentoptionsdialog.h"
#include "trackerentriesdialog.h" #include "trackerentriesdialog.h"
#include "transferlistdelegate.h" #include "transferlistdelegate.h"
#include "transferlistmodel.h" #include "transferlistmodel.h"
#include "transferlistsortmodel.h" #include "transferlistsortmodel.h"
#include "tristateaction.h" #include "tristateaction.h"
#include "uithememanager.h" #include "uithememanager.h"
#include "updownratiodialog.h"
#include "utils.h" #include "utils.h"
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
@ -551,102 +551,13 @@ void TransferListWidget::previewSelectedTorrents()
} }
} }
void TransferListWidget::setDlLimitSelectedTorrents() void TransferListWidget::setTorrentOptions()
{ {
QVector<BitTorrent::TorrentHandle *> torrentsList; const QVector<BitTorrent::TorrentHandle *> selectedTorrents = getSelectedTorrents();
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents())) if (selectedTorrents.empty()) return;
{
if (torrent->isSeed())
continue;
torrentsList += torrent;
}
if (torrentsList.empty()) return;
int oldLimit = torrentsList.first()->downloadLimit();
for (BitTorrent::TorrentHandle *const torrent : asConst(torrentsList))
{
if (torrent->downloadLimit() != oldLimit)
{
oldLimit = -1;
break;
}
}
bool ok = false; auto dialog = new TorrentOptionsDialog {this, selectedTorrents};
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)
{
oldLimit = -1;
break;
}
}
bool ok = false;
const long newLimit = SpeedLimitDialog::askSpeedLimit(
this, &ok, tr("Torrent Upload Speed Limiting"), oldLimit
, BitTorrent::Session::instance()->globalUploadSpeedLimit());
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);
}
}
void TransferListWidget::setMaxRatioSelectedTorrents()
{
const QVector<BitTorrent::TorrentHandle *> torrents = getSelectedTorrents();
if (torrents.isEmpty()) return;
qreal currentMaxRatio = BitTorrent::Session::instance()->globalMaxRatio();
if (torrents.count() == 1)
currentMaxRatio = torrents[0]->maxRatio();
int currentMaxSeedingTime = BitTorrent::Session::instance()->globalMaxSeedingMinutes();
if (torrents.count() == 1)
currentMaxSeedingTime = torrents[0]->maxSeedingTime();
bool useGlobalValue = true;
if (torrents.count() == 1)
useGlobalValue = (torrents[0]->ratioLimit() == BitTorrent::TorrentHandle::USE_GLOBAL_RATIO)
&& (torrents[0]->seedingTimeLimit() == BitTorrent::TorrentHandle::USE_GLOBAL_SEEDING_TIME);
auto dialog = new UpDownRatioDialog(useGlobalValue, currentMaxRatio, BitTorrent::TorrentHandle::MAX_RATIO,
currentMaxSeedingTime, BitTorrent::TorrentHandle::MAX_SEEDING_TIME, this);
dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setAttribute(Qt::WA_DeleteOnClose);
connect(dialog, &QDialog::accepted, this, [dialog, torrents]()
{
for (BitTorrent::TorrentHandle *const torrent : torrents)
{
const qreal ratio = (dialog->useDefault()
? BitTorrent::TorrentHandle::USE_GLOBAL_RATIO : dialog->ratio());
torrent->setRatioLimit(ratio);
const int seedingTime = (dialog->useDefault()
? BitTorrent::TorrentHandle::USE_GLOBAL_SEEDING_TIME : dialog->seedingTime());
torrent->setSeedingTimeLimit(seedingTime);
}
});
dialog->open(); dialog->open();
} }
@ -897,12 +808,8 @@ void TransferListWidget::displayListMenu(const QPoint &)
connect(actionDelete, &QAction::triggered, this, &TransferListWidget::softDeleteSelectedTorrents); connect(actionDelete, &QAction::triggered, this, &TransferListWidget::softDeleteSelectedTorrents);
auto *actionPreviewFile = new QAction(UIThemeManager::instance()->getIcon("view-preview"), tr("Preview file..."), listMenu); auto *actionPreviewFile = new QAction(UIThemeManager::instance()->getIcon("view-preview"), tr("Preview file..."), listMenu);
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 *actionTorrentOptions = new QAction(UIThemeManager::instance()->getIcon("configure"), tr("Torrent options..."), listMenu);
connect(actionSetMaxRatio, &QAction::triggered, this, &TransferListWidget::setMaxRatioSelectedTorrents); connect(actionTorrentOptions, &QAction::triggered, this, &TransferListWidget::setTorrentOptions);
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 *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,10 +1039,7 @@ void TransferListWidget::displayListMenu(const QPoint &)
listMenu->addAction(actionAutoTMM); listMenu->addAction(actionAutoTMM);
listMenu->addSeparator(); listMenu->addSeparator();
if (oneNotSeed) listMenu->addAction(actionTorrentOptions);
listMenu->addAction(actionSetDownloadLimit);
listMenu->addAction(actionSetUploadLimit);
listMenu->addAction(actionSetMaxRatio);
if (!oneNotSeed && oneHasMetadata) if (!oneNotSeed && oneHasMetadata)
{ {
actionSuperSeedingMode->setCheckState(allSameSuperSeeding actionSuperSeedingMode->setCheckState(allSameSuperSeeding

4
src/gui/transferlistwidget.h

@ -79,9 +79,7 @@ public slots:
void openSelectedTorrentsFolder() const; void openSelectedTorrentsFolder() const;
void recheckSelectedTorrents(); void recheckSelectedTorrents();
void reannounceSelectedTorrents(); void reannounceSelectedTorrents();
void setDlLimitSelectedTorrents(); void setTorrentOptions();
void setUpLimitSelectedTorrents();
void setMaxRatioSelectedTorrents();
void previewSelectedTorrents(); void previewSelectedTorrents();
void hideQueuePosColumn(bool hide); void hideQueuePosColumn(bool hide);
void displayDLHoSMenu(const QPoint&); void displayDLHoSMenu(const QPoint&);

137
src/gui/updownratiodialog.cpp

@ -1,137 +0,0 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Christian Kandeler
* Copyright (C) 2011 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#include "updownratiodialog.h"
#include <QMessageBox>
#include "base/bittorrent/session.h"
#include "ui_updownratiodialog.h"
#include "utils.h"
UpDownRatioDialog::UpDownRatioDialog(bool useDefault, qreal initialRatioValue,
qreal maxRatioValue, int initialTimeValue,
int maxTimeValue, QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::UpDownRatioDialog)
{
m_ui->setupUi(this);
if (useDefault)
{
m_ui->useDefaultButton->setChecked(true);
}
else if ((initialRatioValue == -1.) && (initialTimeValue == -1))
{
m_ui->noLimitButton->setChecked(true);
initialRatioValue = BitTorrent::Session::instance()->globalMaxRatio();
initialTimeValue = BitTorrent::Session::instance()->globalMaxSeedingMinutes();
}
else
{
m_ui->torrentLimitButton->setChecked(true);
if (initialRatioValue >= 0)
m_ui->checkMaxRatio->setChecked(true);
if (initialTimeValue >= 0)
m_ui->checkMaxTime->setChecked(true);
}
m_ui->ratioSpinBox->setMinimum(0);
m_ui->ratioSpinBox->setMaximum(maxRatioValue);
m_ui->ratioSpinBox->setValue(initialRatioValue);
m_ui->timeSpinBox->setMinimum(0);
m_ui->timeSpinBox->setMaximum(maxTimeValue);
m_ui->timeSpinBox->setValue(initialTimeValue);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
connect(m_ui->buttonGroup, &QButtonGroup::idClicked
, this, &UpDownRatioDialog::handleRatioTypeChanged);
#else
connect(m_ui->buttonGroup, qOverload<int>(&QButtonGroup::buttonClicked)
, this, &UpDownRatioDialog::handleRatioTypeChanged);
#endif
connect(m_ui->checkMaxRatio, &QCheckBox::toggled, this, &UpDownRatioDialog::enableRatioSpin);
connect(m_ui->checkMaxTime, &QCheckBox::toggled, this, &UpDownRatioDialog::enableTimeSpin);
handleRatioTypeChanged();
Utils::Gui::resize(this);
}
void UpDownRatioDialog::accept()
{
if (m_ui->torrentLimitButton->isChecked() && !m_ui->checkMaxRatio->isChecked() && !m_ui->checkMaxTime->isChecked())
QMessageBox::critical(this, tr("No share limit method selected"),
tr("Please select a limit method first"));
else
QDialog::accept();
}
bool UpDownRatioDialog::useDefault() const
{
return m_ui->useDefaultButton->isChecked();
}
qreal UpDownRatioDialog::ratio() const
{
return (m_ui->noLimitButton->isChecked() || !m_ui->checkMaxRatio->isChecked()) ? -1. : m_ui->ratioSpinBox->value();
}
int UpDownRatioDialog::seedingTime() const
{
return (m_ui->noLimitButton->isChecked() || !m_ui->checkMaxTime->isChecked()) ? -1 : m_ui->timeSpinBox->value();
}
void UpDownRatioDialog::handleRatioTypeChanged()
{
// ui->ratioSpinBox->setEnabled(ui->torrentLimitButton->isChecked());
m_ui->checkMaxRatio->setEnabled(m_ui->torrentLimitButton->isChecked());
m_ui->checkMaxTime->setEnabled(m_ui->torrentLimitButton->isChecked());
m_ui->ratioSpinBox->setEnabled(m_ui->torrentLimitButton->isChecked() && m_ui->checkMaxRatio->isChecked());
m_ui->timeSpinBox->setEnabled(m_ui->torrentLimitButton->isChecked() && m_ui->checkMaxTime->isChecked());
}
void UpDownRatioDialog::enableRatioSpin()
{
m_ui->ratioSpinBox->setEnabled(m_ui->checkMaxRatio->isChecked());
}
void UpDownRatioDialog::enableTimeSpin()
{
m_ui->timeSpinBox->setEnabled(m_ui->checkMaxTime->isChecked());
}
UpDownRatioDialog::~UpDownRatioDialog()
{
delete m_ui;
}

177
src/gui/updownratiodialog.ui

@ -1,177 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UpDownRatioDialog</class>
<widget class="QDialog" name="UpDownRatioDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>399</width>
<height>195</height>
</rect>
</property>
<property name="windowTitle">
<string>Torrent Upload/Download Ratio Limiting</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="useDefaultButton">
<property name="text">
<string>Use global share limit</string>
</property>
<attribute name="buttonGroup">
<string>buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="noLimitButton">
<property name="text">
<string>Set no share limit</string>
</property>
<attribute name="buttonGroup">
<string>buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QRadioButton" name="torrentLimitButton">
<property name="text">
<string>Set share limit to</string>
</property>
<attribute name="buttonGroup">
<string>buttonGroup</string>
</attribute>
</widget>
</item>
<item row="0" column="2">
<widget class="QDoubleSpinBox" name="ratioSpinBox">
<property name="maximum">
<double>9998.000000000000000</double>
</property>
<property name="singleStep">
<double>0.050000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QDoubleSpinBox" name="timeSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>0</number>
</property>
<property name="maximum">
<double>525600.000000000000000</double>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
<property name="value">
<double>1440.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkMaxRatio">
<property name="text">
<string>ratio</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkMaxTime">
<property name="text">
<string>minutes</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>UpDownRatioDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>UpDownRatioDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
<buttongroups>
<buttongroup name="shareButtonGroup"/>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>
Loading…
Cancel
Save