mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-13 08:43:08 -07:00
- Fixed per torrent speed limiting
- A lot of cleanup in speed limiting dialog
This commit is contained in:
parent
490ef19e64
commit
5ffcf5a9dc
10 changed files with 278 additions and 296 deletions
24
src/GUI.cpp
24
src/GUI.cpp
|
@ -58,7 +58,7 @@
|
||||||
#include "about_imp.h"
|
#include "about_imp.h"
|
||||||
#include "trackerLogin.h"
|
#include "trackerLogin.h"
|
||||||
#include "options_imp.h"
|
#include "options_imp.h"
|
||||||
#include "allocationDlg.h"
|
#include "speedlimitdlg.h"
|
||||||
#include "preferences.h"
|
#include "preferences.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "console_imp.h"
|
#include "console_imp.h"
|
||||||
|
@ -482,7 +482,16 @@ void GUI::handleDownloadFromUrlFailure(QString url, QString reason) const{
|
||||||
|
|
||||||
void GUI::on_actionSet_global_upload_limit_triggered() {
|
void GUI::on_actionSet_global_upload_limit_triggered() {
|
||||||
qDebug("actionSet_global_upload_limit_triggered");
|
qDebug("actionSet_global_upload_limit_triggered");
|
||||||
new BandwidthAllocationDialog(this, true, BTSession, QStringList());
|
bool ok;
|
||||||
|
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Upload Speed Limit"), BTSession->getSession()->upload_rate_limit());
|
||||||
|
if(ok) {
|
||||||
|
qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.);
|
||||||
|
BTSession->getSession()->set_upload_rate_limit(new_limit);
|
||||||
|
if(new_limit <= 0)
|
||||||
|
Preferences::setGlobalUploadLimit(-1);
|
||||||
|
else
|
||||||
|
Preferences::setGlobalUploadLimit(new_limit/1024.);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::on_actionShow_console_triggered() {
|
void GUI::on_actionShow_console_triggered() {
|
||||||
|
@ -491,7 +500,16 @@ void GUI::on_actionShow_console_triggered() {
|
||||||
|
|
||||||
void GUI::on_actionSet_global_download_limit_triggered() {
|
void GUI::on_actionSet_global_download_limit_triggered() {
|
||||||
qDebug("actionSet_global_download_limit_triggered");
|
qDebug("actionSet_global_download_limit_triggered");
|
||||||
new BandwidthAllocationDialog(this, false, BTSession, QStringList());
|
bool ok;
|
||||||
|
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), BTSession->getSession()->download_rate_limit());
|
||||||
|
if(ok) {
|
||||||
|
qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.);
|
||||||
|
BTSession->getSession()->set_download_rate_limit(new_limit);
|
||||||
|
if(new_limit <= 0)
|
||||||
|
Preferences::setGlobalDownloadLimit(-1);
|
||||||
|
else
|
||||||
|
Preferences::setGlobalDownloadLimit(new_limit/1024.);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Necessary if we want to close the window
|
// Necessary if we want to close the window
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
#include "bittorrent.h"
|
#include "bittorrent.h"
|
||||||
#include "torrentPersistentData.h"
|
#include "torrentPersistentData.h"
|
||||||
#include "previewSelect.h"
|
#include "previewSelect.h"
|
||||||
#include "allocationDlg.h"
|
#include "speedlimitdlg.h"
|
||||||
#include "options_imp.h"
|
#include "options_imp.h"
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
@ -559,26 +559,75 @@ void TransferListWidget::previewSelectedTorrents() {
|
||||||
void TransferListWidget::setDlLimitSelectedTorrents() {
|
void TransferListWidget::setDlLimitSelectedTorrents() {
|
||||||
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||||||
QStringList hashes;
|
QStringList hashes;
|
||||||
|
QList<QTorrentHandle> selected_torrents;
|
||||||
|
bool first = true;
|
||||||
|
bool all_same_limit = true;
|
||||||
foreach(const QModelIndex &index, selectedIndexes) {
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||||||
// Get the file hash
|
// Get the file hash
|
||||||
QString hash = getHashFromRow(proxyModel->mapToSource(index).row());
|
QString hash = getHashFromRow(proxyModel->mapToSource(index).row());
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||||
if(h.is_valid() && !h.is_seed())
|
if(h.is_valid() && !h.is_seed()) {
|
||||||
hashes << hash;
|
selected_torrents << h;
|
||||||
|
// Determine current limit for selected torrents
|
||||||
|
if(first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
if(all_same_limit && h.download_limit() != selected_torrents.first().download_limit())
|
||||||
|
all_same_limit = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(selected_torrents.empty()) return;
|
||||||
|
|
||||||
|
bool ok=false;
|
||||||
|
int default_limit = -1;
|
||||||
|
if(all_same_limit)
|
||||||
|
default_limit = selected_torrents.first().download_limit();
|
||||||
|
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Download Speed Limiting"), default_limit);
|
||||||
|
if(ok) {
|
||||||
|
foreach(QTorrentHandle h, selected_torrents) {
|
||||||
|
qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), h.hash().toLocal8Bit().data());
|
||||||
|
h.set_download_limit(new_limit);
|
||||||
|
TorrentPersistentData::saveSpeedLimits(h);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Q_ASSERT(hashes.size() > 0);
|
|
||||||
new BandwidthAllocationDialog(this, false, BTSession, hashes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::setUpLimitSelectedTorrents() {
|
void TransferListWidget::setUpLimitSelectedTorrents() {
|
||||||
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||||||
QStringList hashes;
|
QStringList hashes;
|
||||||
|
QList<QTorrentHandle> selected_torrents;
|
||||||
|
bool first = true;
|
||||||
|
bool all_same_limit = true;
|
||||||
foreach(const QModelIndex &index, selectedIndexes) {
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||||||
// Get the file hash
|
// Get the file hash
|
||||||
hashes << getHashFromRow(proxyModel->mapToSource(index).row());
|
QString hash = getHashFromRow(proxyModel->mapToSource(index).row());
|
||||||
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||||
|
if(h.is_valid() && !h.is_seed()) {
|
||||||
|
selected_torrents << h;
|
||||||
|
// Determine current limit for selected torrents
|
||||||
|
if(first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
if(all_same_limit && h.upload_limit() != selected_torrents.first().upload_limit())
|
||||||
|
all_same_limit = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(selected_torrents.empty()) return;
|
||||||
|
|
||||||
|
bool ok=false;
|
||||||
|
int default_limit = -1;
|
||||||
|
if(all_same_limit)
|
||||||
|
default_limit = selected_torrents.first().upload_limit();
|
||||||
|
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Upload Speed Limiting"), default_limit);
|
||||||
|
if(ok) {
|
||||||
|
foreach(QTorrentHandle h, selected_torrents) {
|
||||||
|
qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), h.hash().toLocal8Bit().data());
|
||||||
|
h.set_upload_limit(new_limit);
|
||||||
|
TorrentPersistentData::saveSpeedLimits(h);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Q_ASSERT(hashes.size() > 0);
|
|
||||||
new BandwidthAllocationDialog(this, true, BTSession, hashes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::recheckSelectedTorrents() {
|
void TransferListWidget::recheckSelectedTorrents() {
|
||||||
|
|
|
@ -1,188 +0,0 @@
|
||||||
/*
|
|
||||||
* Bittorrent Client using Qt4 and libtorrent.
|
|
||||||
* Copyright (C) 2006 Christophe Dumez
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
* In addition, as a special exception, the copyright holders give permission to
|
|
||||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
||||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
||||||
* and distribute the linked executables. You must obey the GNU General Public
|
|
||||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
||||||
* modify file(s), you may extend this exception to your version of the file(s),
|
|
||||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
||||||
* exception statement from your version.
|
|
||||||
*
|
|
||||||
* Contact : chris@qbittorrent.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BANDWIDTH_ALLOCATION_H
|
|
||||||
#define BANDWIDTH_ALLOCATION_H
|
|
||||||
|
|
||||||
#include <QDialog>
|
|
||||||
#include <QList>
|
|
||||||
#include <QSettings>
|
|
||||||
#include "ui_bandwidth_limit.h"
|
|
||||||
#include "misc.h"
|
|
||||||
#include "bittorrent.h"
|
|
||||||
|
|
||||||
using namespace libtorrent;
|
|
||||||
|
|
||||||
class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
BandwidthAllocationDialog(QWidget *parent, bool uploadMode, bittorrent *BTSession, QStringList hashes): QDialog(parent), uploadMode(uploadMode), hashes(hashes){
|
|
||||||
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)));
|
|
||||||
if(!global){
|
|
||||||
unsigned int nbTorrents = hashes.size();
|
|
||||||
if(!nbTorrents) close();
|
|
||||||
int val = 0;
|
|
||||||
int max = -1;
|
|
||||||
if(nbTorrents == 1){
|
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hashes.at(0));
|
|
||||||
if(uploadMode){
|
|
||||||
if(h.upload_limit() > 0)
|
|
||||||
val = (int)(h.upload_limit() / 1024.);
|
|
||||||
if(BTSession->getSession()->upload_rate_limit() > 0)
|
|
||||||
max = (int)(BTSession->getSession()->upload_rate_limit() / 1024.);
|
|
||||||
}else{
|
|
||||||
if(h.download_limit() > 0)
|
|
||||||
val = (int)(h.download_limit() / 1024.);
|
|
||||||
if(BTSession->getSession()->download_rate_limit() > 0){
|
|
||||||
qDebug("there is a global download rate limit at: %d kb/s", (int)(BTSession->getSession()->download_rate_limit() / 1024.));
|
|
||||||
max = (int)(BTSession->getSession()->download_rate_limit() / 1024.);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(max != -1)
|
|
||||||
bandwidthSlider->setMaximum(max);
|
|
||||||
qDebug("Bandwidth limit: %d", val);
|
|
||||||
if(val > bandwidthSlider->maximum())
|
|
||||||
val = bandwidthSlider->maximum();
|
|
||||||
else if(val < bandwidthSlider->minimum())
|
|
||||||
val = 0;
|
|
||||||
bandwidthSlider->setValue(val);
|
|
||||||
if(val == 0) {
|
|
||||||
limit_lbl->setText(tr("Unlimited", "Unlimited (bandwidth)"));
|
|
||||||
kb_lbl->setText(QString::fromUtf8(""));
|
|
||||||
} else {
|
|
||||||
limit_lbl->setText(misc::toQString(val));
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
qDebug("More than one torrent selected, no initilization");
|
|
||||||
bandwidthSlider->setValue(0);
|
|
||||||
limit_lbl->setText(tr("Unlimited", "Unlimited (bandwidth)"));
|
|
||||||
kb_lbl->setText(QString::fromUtf8(""));
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
// Global limit
|
|
||||||
int val = 0;
|
|
||||||
session *s = BTSession->getSession();
|
|
||||||
if(uploadMode){
|
|
||||||
if(s->upload_rate_limit() > 0)
|
|
||||||
val = (int)(s->upload_rate_limit()/1024.);
|
|
||||||
}else{
|
|
||||||
if(s->download_rate_limit() > 0)
|
|
||||||
val = (int)(s->download_rate_limit()/1024.);
|
|
||||||
}
|
|
||||||
if(val == 0){
|
|
||||||
bandwidthSlider->setValue(0);
|
|
||||||
limit_lbl->setText(tr("Unlimited", "Unlimited (bandwidth)"));
|
|
||||||
kb_lbl->setText(QString::fromUtf8(""));
|
|
||||||
}else{
|
|
||||||
bandwidthSlider->setValue(val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(setBandwidth()));
|
|
||||||
show();
|
|
||||||
}
|
|
||||||
|
|
||||||
~BandwidthAllocationDialog(){
|
|
||||||
qDebug("Deleting bandwidth allocation dialog");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected slots:
|
|
||||||
void updateBandwidthLabel(int val){
|
|
||||||
if(val == 0){
|
|
||||||
limit_lbl->setText(tr("Unlimited", "Unlimited (bandwidth)"));
|
|
||||||
kb_lbl->setText(QString::fromUtf8(""));
|
|
||||||
}else{
|
|
||||||
limit_lbl->setText(misc::toQString(val));
|
|
||||||
kb_lbl->setText(tr("KiB/s"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setBandwidth(){
|
|
||||||
qDebug("setBandwidth called");
|
|
||||||
int val = bandwidthSlider->value();
|
|
||||||
if(!global){
|
|
||||||
QString hash;
|
|
||||||
if(uploadMode) {
|
|
||||||
foreach(hash, hashes) {
|
|
||||||
if(!val)
|
|
||||||
BTSession->setUploadLimit(hash, -1);
|
|
||||||
else
|
|
||||||
BTSession->setUploadLimit(hash, val*1024);
|
|
||||||
qDebug("Setting upload limit");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach(hash, hashes) {
|
|
||||||
if(!val)
|
|
||||||
BTSession->setDownloadLimit(hash, -1);
|
|
||||||
else
|
|
||||||
BTSession->setDownloadLimit(hash, val*1024);
|
|
||||||
qDebug("Setting download limit");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
|
||||||
session *s = BTSession->getSession();
|
|
||||||
if(uploadMode){
|
|
||||||
if(!val)
|
|
||||||
s->set_upload_rate_limit(-1);
|
|
||||||
else
|
|
||||||
s->set_upload_rate_limit(val*1024);
|
|
||||||
settings.setValue(QString::fromUtf8("Preferences/Connection/GlobalUPLimit"), val);
|
|
||||||
}else{
|
|
||||||
if(!val)
|
|
||||||
s->set_download_rate_limit(-1);
|
|
||||||
else
|
|
||||||
s->set_download_rate_limit(val*1024);
|
|
||||||
settings.setValue(QString::fromUtf8("Preferences/Connection/GlobalDLLimit"), val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool uploadMode;
|
|
||||||
bool global;
|
|
||||||
bittorrent *BTSession;
|
|
||||||
QStringList hashes;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,95 +1,77 @@
|
||||||
<ui version="4.0" >
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
<class>bandwidth_dlg</class>
|
<class>bandwidth_dlg</class>
|
||||||
<widget class="QDialog" name="bandwidth_dlg" >
|
<widget class="QDialog" name="bandwidth_dlg">
|
||||||
<property name="geometry" >
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>222</width>
|
<width>338</width>
|
||||||
<height>129</height>
|
<height>83</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle" >
|
<property name="windowTitle">
|
||||||
<string>Bandwidth allocation</string>
|
<string notr="true">Bandwidth allocation</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" >
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<property name="margin" >
|
|
||||||
<number>9</number>
|
|
||||||
</property>
|
|
||||||
<property name="spacing" >
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" >
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<property name="margin" >
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="spacing" >
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="lblTitle" >
|
<widget class="QSlider" name="bandwidthSlider">
|
||||||
<property name="text" >
|
<property name="minimum">
|
||||||
<string/>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="maximum">
|
||||||
</item>
|
<number>1000</number>
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="limit_lbl" >
|
|
||||||
<property name="text" >
|
|
||||||
<string/>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="sliderPosition">
|
||||||
</item>
|
<number>0</number>
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="kb_lbl" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>KiB/s</string>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="orientation">
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer>
|
|
||||||
<property name="orientation" >
|
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" >
|
</widget>
|
||||||
<size>
|
</item>
|
||||||
<width>40</width>
|
<item>
|
||||||
<height>20</height>
|
<layout class="QHBoxLayout">
|
||||||
</size>
|
<property name="spacing">
|
||||||
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
<property name="margin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="limit_lbl">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">∞</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="kb_lbl">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSlider" name="bandwidthSlider" >
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<property name="minimum" >
|
<property name="orientation">
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="maximum" >
|
|
||||||
<number>1000</number>
|
|
||||||
</property>
|
|
||||||
<property name="sliderPosition" >
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="orientation" >
|
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="standardButtons">
|
||||||
</item>
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
<item>
|
|
||||||
<widget class="QDialogButtonBox" name="buttonBox" >
|
|
||||||
<property name="orientation" >
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="standardButtons" >
|
|
||||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
<zorder>bandwidthSlider</zorder>
|
||||||
|
<zorder>buttonBox</zorder>
|
||||||
|
<zorder>kb_lbl</zorder>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
|
@ -99,13 +81,29 @@
|
||||||
<receiver>bandwidth_dlg</receiver>
|
<receiver>bandwidth_dlg</receiver>
|
||||||
<slot>reject()</slot>
|
<slot>reject()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel" >
|
<hint type="sourcelabel">
|
||||||
<x>212</x>
|
|
||||||
<y>83</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel" >
|
|
||||||
<x>221</x>
|
<x>221</x>
|
||||||
<y>98</y>
|
<y>73</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>221</x>
|
||||||
|
<y>82</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>bandwidth_dlg</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>277</x>
|
||||||
|
<y>59</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>343</x>
|
||||||
|
<y>80</y>
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
enum ProxyType {HTTP=1, SOCKS5=2, HTTP_PW=3, SOCKS5_PW=4};
|
enum ProxyType {HTTP=1, SOCKS5=2, HTTP_PW=3, SOCKS5_PW=4};
|
||||||
|
|
||||||
// Main constructor
|
// Main constructor
|
||||||
bittorrent::bittorrent() : DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4), ratio_limit(-1), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), queueingEnabled(false), geoipDBLoaded(false) {
|
bittorrent::bittorrent() : DHTEnabled(false), preAllocateAll(false), addInPause(false), ratio_limit(-1), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), queueingEnabled(false), geoipDBLoaded(false) {
|
||||||
resolve_countries = false;
|
resolve_countries = false;
|
||||||
// To avoid some exceptions
|
// To avoid some exceptions
|
||||||
fs::path::default_name_check(fs::no_check);
|
fs::path::default_name_check(fs::no_check);
|
||||||
|
@ -692,9 +692,14 @@ QTorrentHandle bittorrent::addMagnetUri(QString magnet_uri, bool resumed) {
|
||||||
}
|
}
|
||||||
Q_ASSERT(h.hash() == hash);
|
Q_ASSERT(h.hash() == hash);
|
||||||
// Connections limit per torrent
|
// Connections limit per torrent
|
||||||
h.set_max_connections(maxConnecsPerTorrent);
|
h.set_max_connections(Preferences::getMaxConnecsPerTorrent());
|
||||||
// Uploads limit per torrent
|
// Uploads limit per torrent
|
||||||
h.set_max_uploads(maxUploadsPerTorrent);
|
h.set_max_uploads(Preferences::getMaxUploadsPerTorrent());
|
||||||
|
// Speed limits
|
||||||
|
if(TorrentPersistentData::isKnownTorrent(h.hash())) {
|
||||||
|
h.set_download_limit(TorrentPersistentData::getDownloadLimit(h.hash()));
|
||||||
|
h.set_upload_limit(TorrentPersistentData::getUploadLimit(h.hash()));
|
||||||
|
}
|
||||||
// Resolve countries
|
// Resolve countries
|
||||||
h.resolve_countries(resolve_countries);
|
h.resolve_countries(resolve_countries);
|
||||||
// Load filtered files
|
// Load filtered files
|
||||||
|
@ -866,9 +871,14 @@ QTorrentHandle bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
// Connections limit per torrent
|
// Connections limit per torrent
|
||||||
h.set_max_connections(maxConnecsPerTorrent);
|
h.set_max_connections(Preferences::getMaxConnecsPerTorrent());
|
||||||
// Uploads limit per torrent
|
// Uploads limit per torrent
|
||||||
h.set_max_uploads(maxUploadsPerTorrent);
|
h.set_max_uploads(Preferences::getMaxUploadsPerTorrent());
|
||||||
|
// Speed limits
|
||||||
|
if(TorrentPersistentData::isKnownTorrent(h.hash())) {
|
||||||
|
h.set_download_limit(TorrentPersistentData::getDownloadLimit(h.hash()));
|
||||||
|
h.set_upload_limit(TorrentPersistentData::getUploadLimit(h.hash()));
|
||||||
|
}
|
||||||
// Resolve countries
|
// Resolve countries
|
||||||
qDebug("AddTorrent: Resolve_countries: %d", (int)resolve_countries);
|
qDebug("AddTorrent: Resolve_countries: %d", (int)resolve_countries);
|
||||||
h.resolve_countries(resolve_countries);
|
h.resolve_countries(resolve_countries);
|
||||||
|
@ -951,7 +961,6 @@ void bittorrent::setMaxConnections(int maxConnec) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void bittorrent::setMaxConnectionsPerTorrent(int max) {
|
void bittorrent::setMaxConnectionsPerTorrent(int max) {
|
||||||
maxConnecsPerTorrent = max;
|
|
||||||
// Apply this to all session torrents
|
// Apply this to all session torrents
|
||||||
std::vector<torrent_handle> handles = s->get_torrents();
|
std::vector<torrent_handle> handles = s->get_torrents();
|
||||||
unsigned int nbHandles = handles.size();
|
unsigned int nbHandles = handles.size();
|
||||||
|
@ -962,11 +971,11 @@ void bittorrent::setMaxConnectionsPerTorrent(int max) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
h.set_max_connections(max);
|
h.set_max_connections(max);
|
||||||
|
TorrentPersistentData::saveSpeedLimits(h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bittorrent::setMaxUploadsPerTorrent(int max) {
|
void bittorrent::setMaxUploadsPerTorrent(int max) {
|
||||||
maxUploadsPerTorrent = max;
|
|
||||||
// Apply this to all session torrents
|
// Apply this to all session torrents
|
||||||
std::vector<torrent_handle> handles = s->get_torrents();
|
std::vector<torrent_handle> handles = s->get_torrents();
|
||||||
unsigned int nbHandles = handles.size();
|
unsigned int nbHandles = handles.size();
|
||||||
|
@ -977,6 +986,7 @@ void bittorrent::setMaxUploadsPerTorrent(int max) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
h.set_max_uploads(max);
|
h.set_max_uploads(max);
|
||||||
|
TorrentPersistentData::saveSpeedLimits(h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,8 +66,6 @@ class bittorrent : public QObject {
|
||||||
QStringList peerBanMessages;
|
QStringList peerBanMessages;
|
||||||
bool preAllocateAll;
|
bool preAllocateAll;
|
||||||
bool addInPause;
|
bool addInPause;
|
||||||
int maxConnecsPerTorrent;
|
|
||||||
int maxUploadsPerTorrent;
|
|
||||||
float ratio_limit;
|
float ratio_limit;
|
||||||
bool UPnPEnabled;
|
bool UPnPEnabled;
|
||||||
bool NATPMPEnabled;
|
bool NATPMPEnabled;
|
||||||
|
|
|
@ -40,11 +40,8 @@
|
||||||
class PeerAdditionDlg: public QDialog, private Ui::addPeerDialog {
|
class PeerAdditionDlg: public QDialog, private Ui::addPeerDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
|
||||||
bool valid;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PeerAdditionDlg(QWidget *parent=0): QDialog(parent), valid(false) {
|
PeerAdditionDlg(QWidget *parent=0): QDialog(parent) {
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(validateInput()));
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(validateInput()));
|
||||||
|
@ -60,15 +57,10 @@ public:
|
||||||
return spinPort->value();
|
return spinPort->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isValid() const {
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
static boost::asio::ip::tcp::endpoint askForPeerEndpoint() {
|
static boost::asio::ip::tcp::endpoint askForPeerEndpoint() {
|
||||||
boost::asio::ip::tcp::endpoint ep;
|
boost::asio::ip::tcp::endpoint ep;
|
||||||
PeerAdditionDlg dlg;
|
PeerAdditionDlg dlg;
|
||||||
dlg.exec();
|
if(dlg.exec() == QDialog::Accepted) {
|
||||||
if(dlg.isValid()) {
|
|
||||||
const QRegExp is_ipv6(QString::fromUtf8("[0-9a-f]{4}(:[0-9a-f]{4}){7}"), Qt::CaseInsensitive, QRegExp::RegExp);
|
const QRegExp is_ipv6(QString::fromUtf8("[0-9a-f]{4}(:[0-9a-f]{4}){7}"), Qt::CaseInsensitive, QRegExp::RegExp);
|
||||||
const QRegExp is_ipv4(QString::fromUtf8("(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))(\\.(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))){3}"), Qt::CaseInsensitive, QRegExp::RegExp);
|
const QRegExp is_ipv4(QString::fromUtf8("(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))(\\.(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))){3}"), Qt::CaseInsensitive, QRegExp::RegExp);
|
||||||
QString IP = dlg.getIP();
|
QString IP = dlg.getIP();
|
||||||
|
@ -91,18 +83,15 @@ protected slots:
|
||||||
QString IP = getIP();
|
QString IP = getIP();
|
||||||
if(is_ipv4.exactMatch(IP)) {
|
if(is_ipv4.exactMatch(IP)) {
|
||||||
qDebug("Detected IPv4 address: %s", IP.toLocal8Bit().data());
|
qDebug("Detected IPv4 address: %s", IP.toLocal8Bit().data());
|
||||||
valid = true;
|
|
||||||
accept();
|
accept();
|
||||||
} else {
|
} else {
|
||||||
if(is_ipv6.exactMatch(IP)) {
|
if(is_ipv6.exactMatch(IP)) {
|
||||||
qDebug("Detected IPv6 address: %s", IP.toLocal8Bit().data());
|
qDebug("Detected IPv6 address: %s", IP.toLocal8Bit().data());
|
||||||
valid = true;
|
|
||||||
accept();
|
accept();
|
||||||
} else {
|
} else {
|
||||||
QMessageBox::warning(this, tr("Invalid IP"),
|
QMessageBox::warning(this, tr("Invalid IP"),
|
||||||
tr("The IP you provided is invalid."),
|
tr("The IP you provided is invalid."),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,11 +182,23 @@ public:
|
||||||
return settings.value(QString::fromUtf8("Preferences/Connection/GlobalDLLimit"), -1).toInt();
|
return settings.value(QString::fromUtf8("Preferences/Connection/GlobalDLLimit"), -1).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setGlobalDownloadLimit(int limit) {
|
||||||
|
QSettings settings("qBittorrent", "qBittorrent");
|
||||||
|
if(limit == 0) limit = -1;
|
||||||
|
settings.setValue("Preferences/Connection/GlobalDLLimit", limit);
|
||||||
|
}
|
||||||
|
|
||||||
static int getGlobalUploadLimit() {
|
static int getGlobalUploadLimit() {
|
||||||
QSettings settings("qBittorrent", "qBittorrent");
|
QSettings settings("qBittorrent", "qBittorrent");
|
||||||
return settings.value(QString::fromUtf8("Preferences/Connection/GlobalUPLimit"), -1).toInt();
|
return settings.value(QString::fromUtf8("Preferences/Connection/GlobalUPLimit"), -1).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setGlobalUploadLimit(int limit) {
|
||||||
|
QSettings settings("qBittorrent", "qBittorrent");
|
||||||
|
if(limit == 0) limit = -1;
|
||||||
|
settings.setValue("Preferences/Connection/GlobalUPLimit", limit);
|
||||||
|
}
|
||||||
|
|
||||||
static bool resolvePeerCountries() {
|
static bool resolvePeerCountries() {
|
||||||
QSettings settings("qBittorrent", "qBittorrent");
|
QSettings settings("qBittorrent", "qBittorrent");
|
||||||
return settings.value(QString::fromUtf8("Preferences/Connection/ResolvePeerCountries"), false).toBool();
|
return settings.value(QString::fromUtf8("Preferences/Connection/ResolvePeerCountries"), false).toBool();
|
||||||
|
|
96
src/speedlimitdlg.h
Normal file
96
src/speedlimitdlg.h
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt4 and libtorrent.
|
||||||
|
* Copyright (C) 2006 Christophe Dumez
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* In addition, as a special exception, the copyright holders give permission to
|
||||||
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||||
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||||
|
* and distribute the linked executables. You must obey the GNU General Public
|
||||||
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||||
|
* modify file(s), you may extend this exception to your version of the file(s),
|
||||||
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||||
|
* exception statement from your version.
|
||||||
|
*
|
||||||
|
* Contact : chris@qbittorrent.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BANDWIDTH_ALLOCATION_H
|
||||||
|
#define BANDWIDTH_ALLOCATION_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QList>
|
||||||
|
#include <QSettings>
|
||||||
|
#include "ui_bandwidth_limit.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "bittorrent.h"
|
||||||
|
|
||||||
|
using namespace libtorrent;
|
||||||
|
|
||||||
|
class SpeedLimitDialog : public QDialog, private Ui_bandwidth_dlg {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
SpeedLimitDialog(QWidget *parent=0): QDialog(parent) {
|
||||||
|
setupUi(this);
|
||||||
|
qDebug("Bandwidth allocation dialog creation");
|
||||||
|
// Connect to slots
|
||||||
|
connect(bandwidthSlider, SIGNAL(valueChanged(int)), this, SLOT(updateBandwidthLabel(int)));
|
||||||
|
}
|
||||||
|
|
||||||
|
~SpeedLimitDialog(){
|
||||||
|
qDebug("Deleting bandwidth allocation dialog");
|
||||||
|
}
|
||||||
|
|
||||||
|
// -2: if cancel
|
||||||
|
static long askSpeedLimit(bool *ok, QString title, long default_value) {
|
||||||
|
SpeedLimitDialog dlg;
|
||||||
|
dlg.setWindowTitle(title);
|
||||||
|
dlg.setDefaultValue(default_value/1024.);
|
||||||
|
if(dlg.exec() == QDialog::Accepted) {
|
||||||
|
*ok = true;
|
||||||
|
return dlg.getSpeedLimit()*1024;
|
||||||
|
} else {
|
||||||
|
*ok = false;
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void updateBandwidthLabel(int val){
|
||||||
|
if(val <= 0){
|
||||||
|
limit_lbl->setText(QString::fromUtf8("∞"));
|
||||||
|
kb_lbl->setText(QString::fromUtf8(""));
|
||||||
|
}else{
|
||||||
|
limit_lbl->setText(misc::toQString(val));
|
||||||
|
kb_lbl->setText(tr("KiB/s"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long getSpeedLimit() const {
|
||||||
|
long val = bandwidthSlider->value();
|
||||||
|
if(val > 0)
|
||||||
|
return val;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDefaultValue(long val) const {
|
||||||
|
if(val < 0) val = 0;
|
||||||
|
bandwidthSlider->setValue(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -157,7 +157,7 @@ HEADERS += GUI.h \
|
||||||
searchEngine.h \
|
searchEngine.h \
|
||||||
rss.h \
|
rss.h \
|
||||||
rss_imp.h \
|
rss_imp.h \
|
||||||
allocationDlg.h \
|
speedlimitdlg.h \
|
||||||
qtorrenthandle.h \
|
qtorrenthandle.h \
|
||||||
engineSelectDlg.h \
|
engineSelectDlg.h \
|
||||||
pluginSource.h \
|
pluginSource.h \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue