Browse Source

- Bandwidth allocation per torrent class should be almost ready now

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
b08d08512f
  1. 56
      src/allocationDlg.h

56
src/allocationDlg.h

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

Loading…
Cancel
Save