- Bandwidth allocation per torrent class should be almost ready now

This commit is contained in:
Christophe Dumez 2007-04-10 09:43:26 +00:00
parent a25cc14af4
commit b08d08512f

View file

@ -23,6 +23,7 @@
#define BANDWIDTH_ALLOCATION_H
#include <QDialog>
#include <QList>
#include "ui_bandwidth_limit.h"
#include "misc.h"
#include "bittorrent.h"
@ -31,7 +32,7 @@ using namespace libtorrent;
class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg {
public:
BandwidthAllocationDialog(QWidget *parent, bool uploadMode, bittorrent *BTSession, QString hash): QDialog(parent), uploadMode(uploadMode){
BandwidthAllocationDialog(QWidget *parent, bool uploadMode, bittorrent *BTSession, QStringList hashes): QDialog(parent), uploadMode(uploadMode){
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
this->BTSession = BTSession;
@ -40,13 +41,21 @@ class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg {
else
lblTitle->setText(tr("Download limit:"));
connect(bandwidthSlider, SIGNAL(valueChanged(int)), this, SLOT(updateBandwidthLabel(int)));
h = BTSession->getTorrentHandle(hash);
QString hash;
foreach(hash, hashes){
torrent_handle h = BTSession->getTorrentHandle(hash);
if(!h.is_valid()){
qDebug("Error: Invalid Handle!");
close();
continue;
}else{
handles << h;
}
}
unsigned int nbTorrents = handles.size();
if(!nbTorrents) close();
// TODO: Uncomment the following lines as soon as we upgrade
// to libtorrent svn to correctly initialize the bandwidth slider.
// if(nbTorrents == 1){
// if(uploadMode) {
// int val = h.upload_limit();
// if(val > bandwidthSlider->maximum() || val < bandwidthSlider->minimum())
@ -57,6 +66,9 @@ class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg {
// if(val > bandwidthSlider->maximum() || val < bandwidthSlider->minimum())
// val = -1;
// bandwidthSlider->setValue(val);
// }
// }else{
// bandwidthSlider->setValue(-1);
// }
connect(buttonBox, SIGNAL(accepted()), this, SLOT(setBandwidth()));
}
@ -78,17 +90,21 @@ class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg {
void setBandwidth(){
int val = bandwidthSlider->value();
if(uploadMode)
torrent_handle h;
if(uploadMode) {
foreach(h, handles)
h.set_upload_limit(val);
else
} else {
foreach(h, handles)
h.set_download_limit(val);
}
close();
}
private:
bool uploadMode;
bittorrent *BTSession;
torrent_handle h;
QList<torrent_handle> handles;
};
#endif