From 8c5d38400ae42933b93409ffe7417ea1284913e5 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 14 Jul 2007 10:50:38 +0000 Subject: [PATCH] - Allow to set global upload/download bandwidth limit from tray icon menu - Fixed a bug in bandwidth limitation per torrent (confused bytes with kbytes) - Fixed a bug with paused torrents still displayed as checking --- Changelog | 2 + TODO | 3 +- src/GUI.cpp | 19 ++++++++ src/GUI.h | 2 + src/MainWindow.ui | 112 +++++++++++++++++++++++++++++++++++--------- src/allocationDlg.h | 112 +++++++++++++++++++++++++++++--------------- src/bittorrent.cpp | 4 ++ src/bittorrent.h | 1 + 8 files changed, 194 insertions(+), 61 deletions(-) diff --git a/Changelog b/Changelog index 0e581ad96..23bfa999d 100644 --- a/Changelog +++ b/Changelog @@ -19,6 +19,8 @@ - FEATURE: Filtered files are not allocated on the hard-drive anymore (sparse file support) - FEATURE: IPs blocked by filter are now logged in GUI - FEATURE: Added a way to link against static libtorrent (useful for deb packages) + - FEATURE: Allow to set global upload/download limits from tray icon menu + - FEATURE: IPv6 is now fully supported - I18N: Added Hungarian translation - BUGFIX: Progress of paused torrents is now correct on restart - BUGFIX: Progress column gets sorted on restart it is was during last execution diff --git a/TODO b/TODO index 4a8fe6949..094655140 100644 --- a/TODO +++ b/TODO @@ -43,4 +43,5 @@ - Fix all (or almost all) opened bugs in bug tracker - Fix sorting with Qt 4.3 - Reported to Trolltech, waiting for fix - update sorting when a new torrent is added? -- Allow to adjust UP/DL speed limit from tray icon menu \ No newline at end of file +- Open -> cancel on tray icon closes qBT... +- Save bandwidth limits per torrent on hard disk \ No newline at end of file diff --git a/src/GUI.cpp b/src/GUI.cpp index 780b77b22..f781e7edb 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -101,6 +101,8 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){ actionPreview_file->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/preview.png"))); actionSet_upload_limit->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/seeding.png"))); actionSet_download_limit->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/downloading.png"))); + actionSet_global_upload_limit->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/seeding.png"))); + actionSet_global_download_limit->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/downloading.png"))); actionDocumentation->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/qb_question.png"))); connecStatusLblIcon = new QLabel(); connecStatusLblIcon->setFrameShape(QFrame::NoFrame); @@ -340,6 +342,16 @@ void GUI::on_actionSet_upload_limit_triggered(){ new BandwidthAllocationDialog(this, true, &BTSession, hashes); } +void GUI::on_actionSet_global_upload_limit_triggered(){ + qDebug("actionSet_global_upload_limit_triggered"); + new BandwidthAllocationDialog(this, true, &BTSession, QStringList()); +} + +void GUI::on_actionSet_global_download_limit_triggered(){ + qDebug("actionSet_global_download_limit_triggered"); + new BandwidthAllocationDialog(this, false, &BTSession, QStringList()); +} + void GUI::on_actionPreview_file_triggered(){ if(tabs->currentIndex() > 1) return; bool inDownloadList = true; @@ -506,6 +518,9 @@ void GUI::updateDlList(bool force){ if(torrentStatus.state != torrent_status::checking_files && torrentStatus.state != torrent_status::queued_for_checking){ qDebug("Paused torrent finished checking with state: %d", torrentStatus.state); DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)torrentStatus.progress)); + DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Paused"))); + DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/paused.png")), Qt::DecorationRole); + setRowColor(row, "red"); BTSession.pauseTorrent(fileHash); continue; } @@ -816,6 +831,7 @@ void GUI::closeEvent(QCloseEvent *e){ return; } } + hide(); // Save DHT entry BTSession.saveDHTEntry(); // Save window size, columns size @@ -1572,6 +1588,9 @@ void GUI::createTrayIcon(){ myTrayIconMenu->addAction(actionOpen); myTrayIconMenu->addAction(actionDownload_from_URL); myTrayIconMenu->addSeparator(); + myTrayIconMenu->addAction(actionSet_global_download_limit); + myTrayIconMenu->addAction(actionSet_global_upload_limit); + myTrayIconMenu->addSeparator(); myTrayIconMenu->addAction(actionStart_All); myTrayIconMenu->addAction(actionPause_All); myTrayIconMenu->addSeparator(); diff --git a/src/GUI.h b/src/GUI.h index 814f9bed2..84779b3ad 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -140,6 +140,8 @@ class GUI : public QMainWindow, private Ui::MainWindow{ void on_actionDelete_triggered(); void on_actionSet_download_limit_triggered(); void on_actionSet_upload_limit_triggered(); + void on_actionSet_global_upload_limit_triggered(); + void on_actionSet_global_download_limit_triggered(); void on_actionDocumentation_triggered(); void checkConnectionStatus(); void configureSession(bool deleteOptions); diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 59dc54852..c773e102d 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -15,14 +15,26 @@ + + false + - - 9 - 6 + + 9 + + + 9 + + + 9 + + + 9 + @@ -36,28 +48,55 @@ Downloads - - 9 - 6 + + 9 + + + 9 + + + 9 + + + 9 + - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + @@ -275,18 +314,25 @@ Log - - 9 - 6 + + 9 + + + 9 + + + 9 + + + 9 + - - 7 - 7 + 0 0 @@ -309,12 +355,21 @@ IP filter - - 9 - 6 + + 9 + + + 9 + + + 9 + + + 9 + @@ -408,7 +463,10 @@ - 4 + TopToolBarArea + + + false @@ -528,6 +586,16 @@ Documentation + + + Set global download limit + + + + + Set global upload limit + + diff --git a/src/allocationDlg.h b/src/allocationDlg.h index cab40fe4c..1ddef25e4 100644 --- a/src/allocationDlg.h +++ b/src/allocationDlg.h @@ -21,6 +21,7 @@ #include #include +#include #include "ui_bandwidth_limit.h" #include "misc.h" #include "bittorrent.h" @@ -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 { 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 { private: bool uploadMode; + bool global; bittorrent *BTSession; QList handles; }; diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 45e8f9640..4cc6b56e5 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -594,6 +594,10 @@ void bittorrent::setDownloadRateLimit(int rate){ s->set_download_rate_limit(rate); } +session* bittorrent::getSession() const{ + return s; +} + // Set upload rate limit // -1 to disable void bittorrent::setUploadRateLimit(int rate){ diff --git a/src/bittorrent.h b/src/bittorrent.h index f3b0e22e8..daf4c1d56 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -85,6 +85,7 @@ class bittorrent : public QObject{ long getETA(QString hash) const; size_type torrentEffectiveSize(QString hash) const; bool inFullAllocationMode(const QString& hash) const; + session* getSession() const; public slots: void addTorrent(const QString& path, bool fromScanDir = false, bool onStartup = false, const QString& from_url = QString());