|
|
|
@ -21,6 +21,7 @@
@@ -21,6 +21,7 @@
|
|
|
|
|
|
|
|
|
|
#include <QDialog> |
|
|
|
|
#include <QList> |
|
|
|
|
#include <QSettings> |
|
|
|
|
#include "ui_bandwidth_limit.h" |
|
|
|
|
#include "misc.h" |
|
|
|
|
#include "bittorrent.h" |
|
|
|
@ -34,49 +35,71 @@ class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg {
@@ -34,49 +35,71 @@ class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg {
|
|
|
|
|
BandwidthAllocationDialog(QWidget *parent, bool uploadMode, bittorrent *BTSession, QStringList hashes): QDialog(parent), uploadMode(uploadMode){ |
|
|
|
|
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))); |
|
|
|
|
QString hash; |
|
|
|
|
foreach(hash, hashes){ |
|
|
|
|
torrent_handle h = BTSession->getTorrentHandle(hash); |
|
|
|
|
if(!h.is_valid()){ |
|
|
|
|
qDebug("Error: Invalid Handle!"); |
|
|
|
|
continue; |
|
|
|
|
if(!global){ |
|
|
|
|
QString hash; |
|
|
|
|
foreach(hash, hashes){ |
|
|
|
|
torrent_handle h = BTSession->getTorrentHandle(hash); |
|
|
|
|
if(!h.is_valid()){ |
|
|
|
|
qDebug("Error: Invalid Handle!"); |
|
|
|
|
continue; |
|
|
|
|
}else{ |
|
|
|
|
handles << h; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
unsigned int nbTorrents = handles.size(); |
|
|
|
|
if(!nbTorrents) close(); |
|
|
|
|
int val; |
|
|
|
|
if(nbTorrents == 1){ |
|
|
|
|
torrent_handle h = handles.at(0); |
|
|
|
|
if(uploadMode) |
|
|
|
|
val = h.upload_limit(); |
|
|
|
|
else |
|
|
|
|
val = h.download_limit(); |
|
|
|
|
qDebug("Bandwidth limit: %d", val); |
|
|
|
|
if(val > bandwidthSlider->maximum() || val < bandwidthSlider->minimum()) |
|
|
|
|
val = -1; |
|
|
|
|
bandwidthSlider->setValue(val); |
|
|
|
|
if(val == -1) { |
|
|
|
|
limit_lbl->setText(tr("Unlimited", "Unlimited (bandwidth)")); |
|
|
|
|
kb_lbl->setText(""); |
|
|
|
|
} else { |
|
|
|
|
limit_lbl->setText(QString(misc::toString(val).c_str())); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
handles << h; |
|
|
|
|
qDebug("More than one torrent selected, no initilization"); |
|
|
|
|
bandwidthSlider->setValue(-1); |
|
|
|
|
limit_lbl->setText(tr("Unlimited", "Unlimited (bandwidth)")); |
|
|
|
|
kb_lbl->setText(""); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
unsigned int nbTorrents = handles.size(); |
|
|
|
|
if(!nbTorrents) close(); |
|
|
|
|
int val; |
|
|
|
|
if(nbTorrents == 1){ |
|
|
|
|
torrent_handle h = handles.at(0); |
|
|
|
|
}else{ |
|
|
|
|
// Global limit
|
|
|
|
|
int val; |
|
|
|
|
session *s = BTSession->getSession(); |
|
|
|
|
if(uploadMode) |
|
|
|
|
val = h.upload_limit(); |
|
|
|
|
val = (int)(s->upload_rate_limit()/1024.); |
|
|
|
|
else |
|
|
|
|
val = h.download_limit(); |
|
|
|
|
qDebug("Bandwidth limit: %d", val); |
|
|
|
|
if(val > bandwidthSlider->maximum() || val < bandwidthSlider->minimum()) |
|
|
|
|
val = -1; |
|
|
|
|
bandwidthSlider->setValue(val); |
|
|
|
|
if(val == -1) { |
|
|
|
|
val = (int)(s->download_rate_limit()/1024.); |
|
|
|
|
if(val == -1){ |
|
|
|
|
bandwidthSlider->setValue(-1); |
|
|
|
|
limit_lbl->setText(tr("Unlimited", "Unlimited (bandwidth)")); |
|
|
|
|
kb_lbl->setText(""); |
|
|
|
|
} else { |
|
|
|
|
limit_lbl->setText(QString(misc::toString(val).c_str())); |
|
|
|
|
}else{ |
|
|
|
|
bandwidthSlider->setValue(val); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
qDebug("More than one torrent selected, no initilization"); |
|
|
|
|
bandwidthSlider->setValue(-1); |
|
|
|
|
limit_lbl->setText(tr("Unlimited", "Unlimited (bandwidth)")); |
|
|
|
|
kb_lbl->setText(""); |
|
|
|
|
} |
|
|
|
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(setBandwidth())); |
|
|
|
|
show(); |
|
|
|
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(setBandwidth())); |
|
|
|
|
show(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
~BandwidthAllocationDialog(){ |
|
|
|
@ -96,16 +119,28 @@ class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg {
@@ -96,16 +119,28 @@ class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg {
|
|
|
|
|
|
|
|
|
|
void setBandwidth(){ |
|
|
|
|
int val = bandwidthSlider->value(); |
|
|
|
|
torrent_handle h; |
|
|
|
|
if(uploadMode) { |
|
|
|
|
foreach(h, handles) { |
|
|
|
|
h.set_upload_limit(val); |
|
|
|
|
qDebug("Setting upload limit"); |
|
|
|
|
if(!global){ |
|
|
|
|
torrent_handle h; |
|
|
|
|
if(uploadMode) { |
|
|
|
|
foreach(h, handles) { |
|
|
|
|
h.set_upload_limit(val*1024); |
|
|
|
|
qDebug("Setting upload limit"); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
foreach(h, handles) { |
|
|
|
|
h.set_download_limit(val*1024); |
|
|
|
|
qDebug("Setting download limit"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
foreach(h, handles) { |
|
|
|
|
h.set_download_limit(val); |
|
|
|
|
qDebug("Setting download limit"); |
|
|
|
|
}else{ |
|
|
|
|
QSettings settings("qBittorrent", "qBittorrent"); |
|
|
|
|
session *s = BTSession->getSession(); |
|
|
|
|
if(uploadMode){ |
|
|
|
|
s->set_upload_rate_limit(val*1024); |
|
|
|
|
settings.setValue("Options/Main/UPLimit", val); |
|
|
|
|
}else{ |
|
|
|
|
s->set_download_rate_limit(val*1024); |
|
|
|
|
settings.setValue("Options/Main/DLLimit", val); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
close(); |
|
|
|
@ -113,6 +148,7 @@ class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg {
@@ -113,6 +148,7 @@ class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg {
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
bool uploadMode; |
|
|
|
|
bool global; |
|
|
|
|
bittorrent *BTSession; |
|
|
|
|
QList<torrent_handle> handles; |
|
|
|
|
}; |
|
|
|
|