Browse Source

- Upload/download limits per torrent are now saved on restart. I can't test this feature yet though because libtorrent is crashing when I try to use it :)

adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
f0353e50b2
  1. 4
      TODO
  2. 29
      src/allocationDlg.h
  3. 51
      src/bittorrent.cpp
  4. 4
      src/bittorrent.h

4
TODO

@ -44,4 +44,6 @@
- Fix sorting with Qt 4.3 - Reported to Trolltech, waiting for fix - Fix sorting with Qt 4.3 - Reported to Trolltech, waiting for fix
- update sorting when a new torrent is added? - update sorting when a new torrent is added?
* beta2 * beta2
- Save bandwidth limits per torrent on hard disk - Wait for some bug fixes in libtorrent :
- upload/download limit per torrent
- ipfilter crash

29
src/allocationDlg.h

@ -32,7 +32,7 @@ class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg {
Q_OBJECT Q_OBJECT
public: public:
BandwidthAllocationDialog(QWidget *parent, bool uploadMode, bittorrent *BTSession, QStringList hashes): QDialog(parent), uploadMode(uploadMode){ BandwidthAllocationDialog(QWidget *parent, bool uploadMode, bittorrent *BTSession, QStringList hashes): QDialog(parent), uploadMode(uploadMode), hashes(hashes){
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
qDebug("Bandwidth allocation dialog creation"); qDebug("Bandwidth allocation dialog creation");
@ -47,21 +47,11 @@ class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg {
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)));
if(!global){ if(!global){
QString hash; unsigned int nbTorrents = hashes.size();
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(); if(!nbTorrents) close();
int val; int val;
if(nbTorrents == 1){ if(nbTorrents == 1){
torrent_handle h = handles.at(0); torrent_handle h = BTSession->getTorrentHandle(hashes.at(0));
if(uploadMode) if(uploadMode)
val = h.upload_limit(); val = h.upload_limit();
else else
@ -118,17 +108,18 @@ class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg {
} }
void setBandwidth(){ void setBandwidth(){
qDebug("setBandwidth called");
int val = bandwidthSlider->value(); int val = bandwidthSlider->value();
if(!global){ if(!global){
torrent_handle h; QString hash;
if(uploadMode) { if(uploadMode) {
foreach(h, handles) { foreach(hash, hashes) {
h.set_upload_limit(val*1024); BTSession->setUploadLimit(hash, val*1024);
qDebug("Setting upload limit"); qDebug("Setting upload limit");
} }
} else { } else {
foreach(h, handles) { foreach(hash, hashes) {
h.set_download_limit(val*1024); BTSession->setDownloadLimit(hash, val*1024);
qDebug("Setting download limit"); qDebug("Setting download limit");
} }
} }
@ -150,7 +141,7 @@ class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg {
bool uploadMode; bool uploadMode;
bool global; bool global;
bittorrent *BTSession; bittorrent *BTSession;
QList<torrent_handle> handles; QStringList hashes;
}; };
#endif #endif

51
src/bittorrent.cpp

@ -62,6 +62,19 @@ void bittorrent::resumeUnfinishedTorrents(){
resumeUnfinished(); resumeUnfinished();
} }
void bittorrent::setDownloadLimit(QString hash, int val){
torrent_handle h = getTorrentHandle(hash);
h.set_download_limit(val);
saveTorrentSpeedLimits(hash);
}
void bittorrent::setUploadLimit(QString hash, int val){
qDebug("Set upload limit rate to %d", val);
torrent_handle h = getTorrentHandle(hash);
h.set_upload_limit(val);
saveTorrentSpeedLimits(hash);
}
void bittorrent::updateETAs(){ void bittorrent::updateETAs(){
std::vector<torrent_handle> handles = s->get_torrents(); std::vector<torrent_handle> handles = s->get_torrents();
for(unsigned int i=0; i<handles.size(); ++i){ for(unsigned int i=0; i<handles.size(); ++i){
@ -129,6 +142,7 @@ void bittorrent::deleteTorrent(const QString& hash, bool permanent){
torrentBackup.remove(hash+".priorities"); torrentBackup.remove(hash+".priorities");
torrentBackup.remove(hash+".savepath"); torrentBackup.remove(hash+".savepath");
torrentBackup.remove(hash+".trackers"); torrentBackup.remove(hash+".trackers");
torrentBackup.remove(hash+".speedLimits");
// Remove it from ETAs hash tables // Remove it from ETAs hash tables
ETAstats.take(hash); ETAstats.take(hash);
ETAs.take(hash); ETAs.take(hash);
@ -271,6 +285,8 @@ void bittorrent::addTorrent(const QString& path, bool fromScanDir, bool onStartu
qDebug("Torrent hash is " + hash.toUtf8()); qDebug("Torrent hash is " + hash.toUtf8());
// Load filtered files // Load filtered files
loadFilesPriorities(h); loadFilesPriorities(h);
// Load speed limit from hard drive
loadTorrentSpeedLimits(hash);
// Load trackers // Load trackers
bool loaded_trackers = loadTrackerFile(hash); bool loaded_trackers = loadTrackerFile(hash);
// Doing this to order trackers well // Doing this to order trackers well
@ -442,6 +458,38 @@ void bittorrent::disableDHT(){
} }
} }
void bittorrent::saveTorrentSpeedLimits(QString hash){
qDebug("Saving speedLimits file for %s", (const char*)hash.toUtf8());
torrent_handle h = getTorrentHandle(hash);
int download_limit = h.download_limit();
int upload_limit = h.upload_limit();
QFile speeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".speedLimits");
if(!speeds_file.open(QIODevice::WriteOnly | QIODevice::Text)){
qDebug("* Error: Couldn't open speed limits file for torrent: %s", (const char*)hash.toUtf8());
return;
}
speeds_file.write(QByteArray(misc::toString(download_limit).c_str())+QByteArray(" ")+QByteArray(misc::toString(upload_limit).c_str()));
speeds_file.close();
}
void bittorrent::loadTorrentSpeedLimits(QString hash){
qDebug("Loading speedLimits file for %s", (const char*)hash.toUtf8());
torrent_handle h = getTorrentHandle(hash);
QFile speeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".speedLimits");
if(!speeds_file.open(QIODevice::ReadOnly | QIODevice::Text)){
return;
}
QByteArray speed_limits = speeds_file.readAll();
speeds_file.close();
QList<QByteArray> speeds = speed_limits.split(' ');
if(speeds.size() != 2){
std::cerr << "Invalid .speedLimits file for " << hash.toStdString() << '\n';
return;
}
h.set_download_limit(speeds.at(0).toInt());
h.set_upload_limit(speeds.at(1).toInt());
}
// Read pieces priorities from .priorities file // Read pieces priorities from .priorities file
// and ask torrent_handle to consider them // and ask torrent_handle to consider them
void bittorrent::loadFilesPriorities(torrent_handle &h){ void bittorrent::loadFilesPriorities(torrent_handle &h){
@ -816,7 +864,8 @@ void bittorrent::reloadTorrent(const torrent_handle &h){
new_h.set_max_uploads(-1); new_h.set_max_uploads(-1);
// Load filtered Files // Load filtered Files
loadFilesPriorities(new_h); loadFilesPriorities(new_h);
// Load speed limit from hard drive
loadTorrentSpeedLimits(fileHash);
// Pause torrent if it was paused last time // Pause torrent if it was paused last time
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused")){ if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused")){
new_h.pause(); new_h.pause();

4
src/bittorrent.h

@ -109,6 +109,8 @@ class bittorrent : public QObject{
void setTorrentFinishedChecking(QString hash); void setTorrentFinishedChecking(QString hash);
void resumeUnfinishedTorrents(); void resumeUnfinishedTorrents();
void updateETAs(); void updateETAs();
void saveTorrentSpeedLimits(QString hash);
void loadTorrentSpeedLimits(QString hash);
// Session configuration - Setters // Session configuration - Setters
void setListeningPortsRange(std::pair<unsigned short, unsigned short> ports); void setListeningPortsRange(std::pair<unsigned short, unsigned short> ports);
void setMaxConnections(int maxConnec); void setMaxConnections(int maxConnec);
@ -121,6 +123,8 @@ class bittorrent : public QObject{
void setDefaultSavePath(const QString& savepath); void setDefaultSavePath(const QString& savepath);
void applyEncryptionSettings(pe_settings se); void applyEncryptionSettings(pe_settings se);
void loadFilesPriorities(torrent_handle& h); void loadFilesPriorities(torrent_handle& h);
void setDownloadLimit(QString hash, int val);
void setUploadLimit(QString hash, int val);
protected slots: protected slots:
void cleanDeleter(deleteThread* deleter); void cleanDeleter(deleteThread* deleter);

Loading…
Cancel
Save