Browse Source

- Fixed per torrent speed limiting

- A lot of cleanup in speed limiting dialog
adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
5ffcf5a9dc
  1. 24
      src/GUI.cpp
  2. 65
      src/TransferListWidget.cpp
  3. 188
      src/allocationDlg.h
  4. 100
      src/bandwidth_limit.ui
  5. 24
      src/bittorrent.cpp
  6. 2
      src/bittorrent.h
  7. 15
      src/peeraddition.h
  8. 12
      src/preferences.h
  9. 96
      src/speedlimitdlg.h
  10. 2
      src/src.pro

24
src/GUI.cpp

@ -58,7 +58,7 @@ @@ -58,7 +58,7 @@
#include "about_imp.h"
#include "trackerLogin.h"
#include "options_imp.h"
#include "allocationDlg.h"
#include "speedlimitdlg.h"
#include "preferences.h"
#include <stdlib.h>
#include "console_imp.h"
@ -482,7 +482,16 @@ void GUI::handleDownloadFromUrlFailure(QString url, QString reason) const{ @@ -482,7 +482,16 @@ void GUI::handleDownloadFromUrlFailure(QString url, QString reason) const{
void GUI::on_actionSet_global_upload_limit_triggered() {
qDebug("actionSet_global_upload_limit_triggered");
new BandwidthAllocationDialog(this, true, BTSession, QStringList());
bool ok;
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Upload Speed Limit"), BTSession->getSession()->upload_rate_limit());
if(ok) {
qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.);
BTSession->getSession()->set_upload_rate_limit(new_limit);
if(new_limit <= 0)
Preferences::setGlobalUploadLimit(-1);
else
Preferences::setGlobalUploadLimit(new_limit/1024.);
}
}
void GUI::on_actionShow_console_triggered() {
@ -491,7 +500,16 @@ void GUI::on_actionShow_console_triggered() { @@ -491,7 +500,16 @@ void GUI::on_actionShow_console_triggered() {
void GUI::on_actionSet_global_download_limit_triggered() {
qDebug("actionSet_global_download_limit_triggered");
new BandwidthAllocationDialog(this, false, BTSession, QStringList());
bool ok;
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), BTSession->getSession()->download_rate_limit());
if(ok) {
qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.);
BTSession->getSession()->set_download_rate_limit(new_limit);
if(new_limit <= 0)
Preferences::setGlobalDownloadLimit(-1);
else
Preferences::setGlobalDownloadLimit(new_limit/1024.);
}
}
// Necessary if we want to close the window

65
src/TransferListWidget.cpp

@ -33,7 +33,7 @@ @@ -33,7 +33,7 @@
#include "bittorrent.h"
#include "torrentPersistentData.h"
#include "previewSelect.h"
#include "allocationDlg.h"
#include "speedlimitdlg.h"
#include "options_imp.h"
#include <QStandardItemModel>
#include <QSortFilterProxyModel>
@ -559,26 +559,75 @@ void TransferListWidget::previewSelectedTorrents() { @@ -559,26 +559,75 @@ void TransferListWidget::previewSelectedTorrents() {
void TransferListWidget::setDlLimitSelectedTorrents() {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QStringList hashes;
QList<QTorrentHandle> selected_torrents;
bool first = true;
bool all_same_limit = true;
foreach(const QModelIndex &index, selectedIndexes) {
// Get the file hash
QString hash = getHashFromRow(proxyModel->mapToSource(index).row());
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid() && !h.is_seed())
hashes << hash;
if(h.is_valid() && !h.is_seed()) {
selected_torrents << h;
// Determine current limit for selected torrents
if(first) {
first = false;
} else {
if(all_same_limit && h.download_limit() != selected_torrents.first().download_limit())
all_same_limit = false;
}
}
}
if(selected_torrents.empty()) return;
bool ok=false;
int default_limit = -1;
if(all_same_limit)
default_limit = selected_torrents.first().download_limit();
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Download Speed Limiting"), default_limit);
if(ok) {
foreach(QTorrentHandle h, selected_torrents) {
qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), h.hash().toLocal8Bit().data());
h.set_download_limit(new_limit);
TorrentPersistentData::saveSpeedLimits(h);
}
}
Q_ASSERT(hashes.size() > 0);
new BandwidthAllocationDialog(this, false, BTSession, hashes);
}
void TransferListWidget::setUpLimitSelectedTorrents() {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QStringList hashes;
QList<QTorrentHandle> selected_torrents;
bool first = true;
bool all_same_limit = true;
foreach(const QModelIndex &index, selectedIndexes) {
// Get the file hash
hashes << getHashFromRow(proxyModel->mapToSource(index).row());
QString hash = getHashFromRow(proxyModel->mapToSource(index).row());
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid() && !h.is_seed()) {
selected_torrents << h;
// Determine current limit for selected torrents
if(first) {
first = false;
} else {
if(all_same_limit && h.upload_limit() != selected_torrents.first().upload_limit())
all_same_limit = false;
}
}
}
if(selected_torrents.empty()) return;
bool ok=false;
int default_limit = -1;
if(all_same_limit)
default_limit = selected_torrents.first().upload_limit();
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Upload Speed Limiting"), default_limit);
if(ok) {
foreach(QTorrentHandle h, selected_torrents) {
qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), h.hash().toLocal8Bit().data());
h.set_upload_limit(new_limit);
TorrentPersistentData::saveSpeedLimits(h);
}
}
Q_ASSERT(hashes.size() > 0);
new BandwidthAllocationDialog(this, true, BTSession, hashes);
}
void TransferListWidget::recheckSelectedTorrents() {

188
src/allocationDlg.h

@ -1,188 +0,0 @@ @@ -1,188 +0,0 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* 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.
*
* Contact : chris@qbittorrent.org
*/
#ifndef BANDWIDTH_ALLOCATION_H
#define BANDWIDTH_ALLOCATION_H
#include <QDialog>
#include <QList>
#include <QSettings>
#include "ui_bandwidth_limit.h"
#include "misc.h"
#include "bittorrent.h"
using namespace libtorrent;
class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg {
Q_OBJECT
public:
BandwidthAllocationDialog(QWidget *parent, bool uploadMode, bittorrent *BTSession, QStringList hashes): QDialog(parent), uploadMode(uploadMode), hashes(hashes){
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
qDebug("Bandwidth allocation dialog creation");
this->BTSession = BTSession;
if(hashes.size() == 0)
global = true;
else
global = false;
if(uploadMode)
lblTitle->setText(tr("Upload limit:"));
else
lblTitle->setText(tr("Download limit:"));
connect(bandwidthSlider, SIGNAL(valueChanged(int)), this, SLOT(updateBandwidthLabel(int)));
if(!global){
unsigned int nbTorrents = hashes.size();
if(!nbTorrents) close();
int val = 0;
int max = -1;
if(nbTorrents == 1){
QTorrentHandle h = BTSession->getTorrentHandle(hashes.at(0));
if(uploadMode){
if(h.upload_limit() > 0)
val = (int)(h.upload_limit() / 1024.);
if(BTSession->getSession()->upload_rate_limit() > 0)
max = (int)(BTSession->getSession()->upload_rate_limit() / 1024.);
}else{
if(h.download_limit() > 0)
val = (int)(h.download_limit() / 1024.);
if(BTSession->getSession()->download_rate_limit() > 0){
qDebug("there is a global download rate limit at: %d kb/s", (int)(BTSession->getSession()->download_rate_limit() / 1024.));
max = (int)(BTSession->getSession()->download_rate_limit() / 1024.);
}
}
if(max != -1)
bandwidthSlider->setMaximum(max);
qDebug("Bandwidth limit: %d", val);
if(val > bandwidthSlider->maximum())
val = bandwidthSlider->maximum();
else if(val < bandwidthSlider->minimum())
val = 0;
bandwidthSlider->setValue(val);
if(val == 0) {
limit_lbl->setText(tr("Unlimited", "Unlimited (bandwidth)"));
kb_lbl->setText(QString::fromUtf8(""));
} else {
limit_lbl->setText(misc::toQString(val));
}
}else{
qDebug("More than one torrent selected, no initilization");
bandwidthSlider->setValue(0);
limit_lbl->setText(tr("Unlimited", "Unlimited (bandwidth)"));
kb_lbl->setText(QString::fromUtf8(""));
}
}else{
// Global limit
int val = 0;
session *s = BTSession->getSession();
if(uploadMode){
if(s->upload_rate_limit() > 0)
val = (int)(s->upload_rate_limit()/1024.);
}else{
if(s->download_rate_limit() > 0)
val = (int)(s->download_rate_limit()/1024.);
}
if(val == 0){
bandwidthSlider->setValue(0);
limit_lbl->setText(tr("Unlimited", "Unlimited (bandwidth)"));
kb_lbl->setText(QString::fromUtf8(""));
}else{
bandwidthSlider->setValue(val);
}
}
connect(buttonBox, SIGNAL(accepted()), this, SLOT(setBandwidth()));
show();
}
~BandwidthAllocationDialog(){
qDebug("Deleting bandwidth allocation dialog");
}
protected slots:
void updateBandwidthLabel(int val){
if(val == 0){
limit_lbl->setText(tr("Unlimited", "Unlimited (bandwidth)"));
kb_lbl->setText(QString::fromUtf8(""));
}else{
limit_lbl->setText(misc::toQString(val));
kb_lbl->setText(tr("KiB/s"));
}
}
void setBandwidth(){
qDebug("setBandwidth called");
int val = bandwidthSlider->value();
if(!global){
QString hash;
if(uploadMode) {
foreach(hash, hashes) {
if(!val)
BTSession->setUploadLimit(hash, -1);
else
BTSession->setUploadLimit(hash, val*1024);
qDebug("Setting upload limit");
}
} else {
foreach(hash, hashes) {
if(!val)
BTSession->setDownloadLimit(hash, -1);
else
BTSession->setDownloadLimit(hash, val*1024);
qDebug("Setting download limit");
}
}
}else{
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
session *s = BTSession->getSession();
if(uploadMode){
if(!val)
s->set_upload_rate_limit(-1);
else
s->set_upload_rate_limit(val*1024);
settings.setValue(QString::fromUtf8("Preferences/Connection/GlobalUPLimit"), val);
}else{
if(!val)
s->set_download_rate_limit(-1);
else
s->set_download_rate_limit(val*1024);
settings.setValue(QString::fromUtf8("Preferences/Connection/GlobalDLLimit"), val);
}
}
close();
}
private:
bool uploadMode;
bool global;
bittorrent *BTSession;
QStringList hashes;
};
#endif

100
src/bandwidth_limit.ui

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>bandwidth_dlg</class>
<widget class="QDialog" name="bandwidth_dlg">
@ -5,79 +6,57 @@ @@ -5,79 +6,57 @@
<rect>
<x>0</x>
<y>0</y>
<width>222</width>
<height>129</height>
<width>338</width>
<height>83</height>
</rect>
</property>
<property name="windowTitle">
<string>Bandwidth allocation</string>
<string notr="true">Bandwidth allocation</string>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QSlider" name="bandwidthSlider">
<property name="minimum">
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
<property name="maximum">
<number>1000</number>
</property>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<property name="sliderPosition">
<number>0</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="lblTitle" >
<property name="text" >
<string/>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="limit_lbl">
<property name="text">
<string/>
<string notr="true">∞</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="kb_lbl">
<property name="text">
<string>KiB/s</string>
<string/>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QSlider" name="bandwidthSlider" >
<property name="minimum" >
<number>0</number>
</property>
<property name="maximum" >
<number>1000</number>
</property>
<property name="sliderPosition" >
<number>0</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
</widget>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
@ -85,11 +64,14 @@ @@ -85,11 +64,14 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
<zorder>bandwidthSlider</zorder>
<zorder>buttonBox</zorder>
<zorder>kb_lbl</zorder>
</widget>
<resources/>
<connections>
@ -100,12 +82,28 @@ @@ -100,12 +82,28 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>212</x>
<y>83</y>
<x>221</x>
<y>73</y>
</hint>
<hint type="destinationlabel">
<x>221</x>
<y>98</y>
<y>82</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>bandwidth_dlg</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>

24
src/bittorrent.cpp

@ -59,7 +59,7 @@ @@ -59,7 +59,7 @@
enum ProxyType {HTTP=1, SOCKS5=2, HTTP_PW=3, SOCKS5_PW=4};
// Main constructor
bittorrent::bittorrent() : DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4), ratio_limit(-1), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), queueingEnabled(false), geoipDBLoaded(false) {
bittorrent::bittorrent() : DHTEnabled(false), preAllocateAll(false), addInPause(false), ratio_limit(-1), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), queueingEnabled(false), geoipDBLoaded(false) {
resolve_countries = false;
// To avoid some exceptions
fs::path::default_name_check(fs::no_check);
@ -692,9 +692,14 @@ QTorrentHandle bittorrent::addMagnetUri(QString magnet_uri, bool resumed) { @@ -692,9 +692,14 @@ QTorrentHandle bittorrent::addMagnetUri(QString magnet_uri, bool resumed) {
}
Q_ASSERT(h.hash() == hash);
// Connections limit per torrent
h.set_max_connections(maxConnecsPerTorrent);
h.set_max_connections(Preferences::getMaxConnecsPerTorrent());
// Uploads limit per torrent
h.set_max_uploads(maxUploadsPerTorrent);
h.set_max_uploads(Preferences::getMaxUploadsPerTorrent());
// Speed limits
if(TorrentPersistentData::isKnownTorrent(h.hash())) {
h.set_download_limit(TorrentPersistentData::getDownloadLimit(h.hash()));
h.set_upload_limit(TorrentPersistentData::getUploadLimit(h.hash()));
}
// Resolve countries
h.resolve_countries(resolve_countries);
// Load filtered files
@ -866,9 +871,14 @@ QTorrentHandle bittorrent::addTorrent(QString path, bool fromScanDir, QString fr @@ -866,9 +871,14 @@ QTorrentHandle bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
return h;
}
// Connections limit per torrent
h.set_max_connections(maxConnecsPerTorrent);
h.set_max_connections(Preferences::getMaxConnecsPerTorrent());
// Uploads limit per torrent
h.set_max_uploads(maxUploadsPerTorrent);
h.set_max_uploads(Preferences::getMaxUploadsPerTorrent());
// Speed limits
if(TorrentPersistentData::isKnownTorrent(h.hash())) {
h.set_download_limit(TorrentPersistentData::getDownloadLimit(h.hash()));
h.set_upload_limit(TorrentPersistentData::getUploadLimit(h.hash()));
}
// Resolve countries
qDebug("AddTorrent: Resolve_countries: %d", (int)resolve_countries);
h.resolve_countries(resolve_countries);
@ -951,7 +961,6 @@ void bittorrent::setMaxConnections(int maxConnec) { @@ -951,7 +961,6 @@ void bittorrent::setMaxConnections(int maxConnec) {
}
void bittorrent::setMaxConnectionsPerTorrent(int max) {
maxConnecsPerTorrent = max;
// Apply this to all session torrents
std::vector<torrent_handle> handles = s->get_torrents();
unsigned int nbHandles = handles.size();
@ -962,11 +971,11 @@ void bittorrent::setMaxConnectionsPerTorrent(int max) { @@ -962,11 +971,11 @@ void bittorrent::setMaxConnectionsPerTorrent(int max) {
continue;
}
h.set_max_connections(max);
TorrentPersistentData::saveSpeedLimits(h);
}
}
void bittorrent::setMaxUploadsPerTorrent(int max) {
maxUploadsPerTorrent = max;
// Apply this to all session torrents
std::vector<torrent_handle> handles = s->get_torrents();
unsigned int nbHandles = handles.size();
@ -977,6 +986,7 @@ void bittorrent::setMaxUploadsPerTorrent(int max) { @@ -977,6 +986,7 @@ void bittorrent::setMaxUploadsPerTorrent(int max) {
continue;
}
h.set_max_uploads(max);
TorrentPersistentData::saveSpeedLimits(h);
}
}

2
src/bittorrent.h

@ -66,8 +66,6 @@ class bittorrent : public QObject { @@ -66,8 +66,6 @@ class bittorrent : public QObject {
QStringList peerBanMessages;
bool preAllocateAll;
bool addInPause;
int maxConnecsPerTorrent;
int maxUploadsPerTorrent;
float ratio_limit;
bool UPnPEnabled;
bool NATPMPEnabled;

15
src/peeraddition.h

@ -40,11 +40,8 @@ @@ -40,11 +40,8 @@
class PeerAdditionDlg: public QDialog, private Ui::addPeerDialog {
Q_OBJECT
private:
bool valid;
public:
PeerAdditionDlg(QWidget *parent=0): QDialog(parent), valid(false) {
PeerAdditionDlg(QWidget *parent=0): QDialog(parent) {
setupUi(this);
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(validateInput()));
@ -60,15 +57,10 @@ public: @@ -60,15 +57,10 @@ public:
return spinPort->value();
}
bool isValid() const {
return valid;
}
static boost::asio::ip::tcp::endpoint askForPeerEndpoint() {
boost::asio::ip::tcp::endpoint ep;
PeerAdditionDlg dlg;
dlg.exec();
if(dlg.isValid()) {
if(dlg.exec() == QDialog::Accepted) {
const QRegExp is_ipv6(QString::fromUtf8("[0-9a-f]{4}(:[0-9a-f]{4}){7}"), Qt::CaseInsensitive, QRegExp::RegExp);
const QRegExp is_ipv4(QString::fromUtf8("(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))(\\.(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))){3}"), Qt::CaseInsensitive, QRegExp::RegExp);
QString IP = dlg.getIP();
@ -91,18 +83,15 @@ protected slots: @@ -91,18 +83,15 @@ protected slots:
QString IP = getIP();
if(is_ipv4.exactMatch(IP)) {
qDebug("Detected IPv4 address: %s", IP.toLocal8Bit().data());
valid = true;
accept();
} else {
if(is_ipv6.exactMatch(IP)) {
qDebug("Detected IPv6 address: %s", IP.toLocal8Bit().data());
valid = true;
accept();
} else {
QMessageBox::warning(this, tr("Invalid IP"),
tr("The IP you provided is invalid."),
QMessageBox::Ok);
}
}
}

12
src/preferences.h

@ -182,11 +182,23 @@ public: @@ -182,11 +182,23 @@ public:
return settings.value(QString::fromUtf8("Preferences/Connection/GlobalDLLimit"), -1).toInt();
}
static void setGlobalDownloadLimit(int limit) {
QSettings settings("qBittorrent", "qBittorrent");
if(limit == 0) limit = -1;
settings.setValue("Preferences/Connection/GlobalDLLimit", limit);
}
static int getGlobalUploadLimit() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/GlobalUPLimit"), -1).toInt();
}
static void setGlobalUploadLimit(int limit) {
QSettings settings("qBittorrent", "qBittorrent");
if(limit == 0) limit = -1;
settings.setValue("Preferences/Connection/GlobalUPLimit", limit);
}
static bool resolvePeerCountries() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/ResolvePeerCountries"), false).toBool();

96
src/speedlimitdlg.h

@ -0,0 +1,96 @@ @@ -0,0 +1,96 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* 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.
*
* Contact : chris@qbittorrent.org
*/
#ifndef BANDWIDTH_ALLOCATION_H
#define BANDWIDTH_ALLOCATION_H
#include <QDialog>
#include <QList>
#include <QSettings>
#include "ui_bandwidth_limit.h"
#include "misc.h"
#include "bittorrent.h"
using namespace libtorrent;
class SpeedLimitDialog : public QDialog, private Ui_bandwidth_dlg {
Q_OBJECT
public:
SpeedLimitDialog(QWidget *parent=0): QDialog(parent) {
setupUi(this);
qDebug("Bandwidth allocation dialog creation");
// Connect to slots
connect(bandwidthSlider, SIGNAL(valueChanged(int)), this, SLOT(updateBandwidthLabel(int)));
}
~SpeedLimitDialog(){
qDebug("Deleting bandwidth allocation dialog");
}
// -2: if cancel
static long askSpeedLimit(bool *ok, QString title, long default_value) {
SpeedLimitDialog dlg;
dlg.setWindowTitle(title);
dlg.setDefaultValue(default_value/1024.);
if(dlg.exec() == QDialog::Accepted) {
*ok = true;
return dlg.getSpeedLimit()*1024;
} else {
*ok = false;
return -2;
}
}
protected slots:
void updateBandwidthLabel(int val){
if(val <= 0){
limit_lbl->setText(QString::fromUtf8(""));
kb_lbl->setText(QString::fromUtf8(""));
}else{
limit_lbl->setText(misc::toQString(val));
kb_lbl->setText(tr("KiB/s"));
}
}
long getSpeedLimit() const {
long val = bandwidthSlider->value();
if(val > 0)
return val;
return -1;
}
void setDefaultValue(long val) const {
if(val < 0) val = 0;
bandwidthSlider->setValue(val);
}
};
#endif

2
src/src.pro

@ -157,7 +157,7 @@ HEADERS += GUI.h \ @@ -157,7 +157,7 @@ HEADERS += GUI.h \
searchEngine.h \
rss.h \
rss_imp.h \
allocationDlg.h \
speedlimitdlg.h \
qtorrenthandle.h \
engineSelectDlg.h \
pluginSource.h \

Loading…
Cancel
Save