FEATURE: Added per-torrent ratio limiting (Christian Kandeler)

This commit is contained in:
Christophe Dumez 2011-03-07 19:26:44 +00:00
parent 4b1eade157
commit 82e41f36ee
15 changed files with 356 additions and 32 deletions

View file

@ -6,6 +6,7 @@
- FEATURE: Inhibit system sleep when torrents are active (Vladimir Golovnev) - FEATURE: Inhibit system sleep when torrents are active (Vladimir Golovnev)
- FEATURE: Added option to bypass Web UI authentication for localhost - FEATURE: Added option to bypass Web UI authentication for localhost
- FEATURE: Added option to disable program exit confirmation - FEATURE: Added option to disable program exit confirmation
- FEATURE: Added per-torrent ratio limiting (Christian Kandeler)
- BUGFIX: Fix compilation with namespaced Qt (Christian Kandeler) - BUGFIX: Fix compilation with namespaced Qt (Christian Kandeler)
* Sun Jan 9 2011 - Christophe Dumez <chris@qbittorrent.org> - v2.6.0 * Sun Jan 9 2011 - Christophe Dumez <chris@qbittorrent.org> - v2.6.0

BIN
src/Icons/skin/ratio.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 483 B

View file

@ -40,6 +40,7 @@
<file>Icons/skin/filteractive.png</file> <file>Icons/skin/filteractive.png</file>
<file>Icons/skin/bg-handle-horizontal.gif</file> <file>Icons/skin/bg-handle-horizontal.gif</file>
<file>Icons/skin/download.png</file> <file>Icons/skin/download.png</file>
<file>Icons/skin/ratio.png</file>
<file>Icons/flags/sm.png</file> <file>Icons/flags/sm.png</file>
<file>Icons/flags/lt.png</file> <file>Icons/flags/lt.png</file>
<file>Icons/flags/th.png</file> <file>Icons/flags/th.png</file>

View file

@ -15,6 +15,7 @@
<file>lang/qbittorrent_fr.qm</file> <file>lang/qbittorrent_fr.qm</file>
<file>lang/qbittorrent_uk.qm</file> <file>lang/qbittorrent_uk.qm</file>
<file>lang/qbittorrent_zh.qm</file> <file>lang/qbittorrent_zh.qm</file>
<file>lang/qbittorrent_lt.qm</file>
<file>lang/qbittorrent_ko.qm</file> <file>lang/qbittorrent_ko.qm</file>
<file>lang/qbittorrent_nb.qm</file> <file>lang/qbittorrent_nb.qm</file>
<file>lang/qbittorrent_sv.qm</file> <file>lang/qbittorrent_sv.qm</file>
@ -32,6 +33,5 @@
<file>lang/qbittorrent_en.qm</file> <file>lang/qbittorrent_en.qm</file>
<file>lang/qbittorrent_hr.qm</file> <file>lang/qbittorrent_hr.qm</file>
<file>lang/qbittorrent_ro.qm</file> <file>lang/qbittorrent_ro.qm</file>
<file>lang/qbittorrent_lt.qm</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -391,7 +391,7 @@ void options_imp::saveOptions(){
pref.setDHTPort(getDHTPort()); pref.setDHTPort(getDHTPort());
pref.setLSDEnabled(isLSDEnabled()); pref.setLSDEnabled(isLSDEnabled());
pref.setEncryptionSetting(getEncryptionSetting()); pref.setEncryptionSetting(getEncryptionSetting());
pref.setMaxRatio(getMaxRatio()); pref.setGlobalMaxRatio(getMaxRatio());
pref.setMaxRatioAction(comboRatioLimitAct->currentIndex()); pref.setMaxRatioAction(comboRatioLimitAct->currentIndex());
// End Bittorrent preferences // End Bittorrent preferences
// Misc preferences // Misc preferences
@ -624,7 +624,7 @@ void options_imp::loadOptions(){
checkLSD->setChecked(pref.isLSDEnabled()); checkLSD->setChecked(pref.isLSDEnabled());
comboEncryption->setCurrentIndex(pref.getEncryptionSetting()); comboEncryption->setCurrentIndex(pref.getEncryptionSetting());
// Ratio limit // Ratio limit
floatValue = pref.getMaxRatio(); floatValue = pref.getGlobalMaxRatio();
if(floatValue >= 0.) { if(floatValue >= 0.) {
// Enable // Enable
checkMaxRatio->setChecked(true); checkMaxRatio->setChecked(true);

View file

@ -547,11 +547,11 @@ public:
setValue(QString::fromUtf8("Preferences/Bittorrent/Encryption"), val); setValue(QString::fromUtf8("Preferences/Bittorrent/Encryption"), val);
} }
qreal getMaxRatio() const { qreal getGlobalMaxRatio() const {
return value(QString::fromUtf8("Preferences/Bittorrent/MaxRatio"), -1).toDouble(); return value(QString::fromUtf8("Preferences/Bittorrent/MaxRatio"), -1).toDouble();
} }
void setMaxRatio(qreal ratio) { void setGlobalMaxRatio(qreal ratio) {
setValue(QString::fromUtf8("Preferences/Bittorrent/MaxRatio"), ratio); setValue(QString::fromUtf8("Preferences/Bittorrent/MaxRatio"), ratio);
} }

View file

@ -88,7 +88,7 @@ enum VersionType { NORMAL,ALPHA,BETA,RELEASE_CANDIDATE,DEVEL };
// Main constructor // Main constructor
QBtSession::QBtSession() QBtSession::QBtSession()
: m_scanFolders(ScanFoldersModel::instance(this)), : m_scanFolders(ScanFoldersModel::instance(this)),
preAllocateAll(false), addInPause(false), ratio_limit(-1), preAllocateAll(false), addInPause(false), global_ratio_limit(-1),
UPnPEnabled(false), LSDEnabled(false), UPnPEnabled(false), LSDEnabled(false),
DHTEnabled(false), current_dht_port(0), queueingEnabled(false), DHTEnabled(false), current_dht_port(0), queueingEnabled(false),
torrentExport(false) torrentExport(false)
@ -97,6 +97,9 @@ QBtSession::QBtSession()
#endif #endif
, m_tracker(0) , m_tracker(0)
{ {
BigRatioTimer = new QTimer(this);
BigRatioTimer->setInterval(10000);
connect(BigRatioTimer, SIGNAL(timeout()), SLOT(processBigRatios()));
Preferences pref; Preferences pref;
// To avoid some exceptions // To avoid some exceptions
boost::filesystem::path::default_name_check(boost::filesystem::no_check); boost::filesystem::path::default_name_check(boost::filesystem::no_check);
@ -130,19 +133,19 @@ QBtSession::QBtSession()
} }
s->add_extension(&create_smart_ban_plugin); s->add_extension(&create_smart_ban_plugin);
timerAlerts = new QTimer(this); timerAlerts = new QTimer(this);
connect(timerAlerts, SIGNAL(timeout()), this, SLOT(readAlerts())); connect(timerAlerts, SIGNAL(timeout()), SLOT(readAlerts()));
timerAlerts->start(3000); timerAlerts->start(3000);
connect(&resumeDataTimer, SIGNAL(timeout()), this, SLOT(saveTempFastResumeData())); connect(&resumeDataTimer, SIGNAL(timeout()), SLOT(saveTempFastResumeData()));
resumeDataTimer.start(180000); // 3min resumeDataTimer.start(180000); // 3min
// To download from urls // To download from urls
downloader = new DownloadThread(this); downloader = new DownloadThread(this);
connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString))); connect(downloader, SIGNAL(downloadFinished(QString, QString)), SLOT(processDownloadedFile(QString, QString)));
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString))); connect(downloader, SIGNAL(downloadFailure(QString, QString)), SLOT(handleDownloadFailure(QString, QString)));
appendLabelToSavePath = pref.appendTorrentLabel(); appendLabelToSavePath = pref.appendTorrentLabel();
#if LIBTORRENT_VERSION_MINOR > 14 #if LIBTORRENT_VERSION_MINOR > 14
appendqBExtension = pref.useIncompleteFilesExtension(); appendqBExtension = pref.useIncompleteFilesExtension();
#endif #endif
connect(m_scanFolders, SIGNAL(torrentsAdded(QStringList&)), this, SLOT(addTorrentsFromScanFolder(QStringList&))); connect(m_scanFolders, SIGNAL(torrentsAdded(QStringList&)), SLOT(addTorrentsFromScanFolder(QStringList&)));
// Apply user settings to Bittorrent session // Apply user settings to Bittorrent session
configureSession(); configureSession();
// Torrent speed monitor // Torrent speed monitor
@ -190,7 +193,6 @@ void QBtSession::preAllocateAllFiles(bool b) {
} }
void QBtSession::processBigRatios() { void QBtSession::processBigRatios() {
if(ratio_limit < 0) return;
qDebug("Process big ratios..."); qDebug("Process big ratios...");
std::vector<torrent_handle> torrents = s->get_torrents(); std::vector<torrent_handle> torrents = s->get_torrents();
std::vector<torrent_handle>::iterator torrentIT; std::vector<torrent_handle>::iterator torrentIT;
@ -200,7 +202,13 @@ void QBtSession::processBigRatios() {
if(h.is_seed()) { if(h.is_seed()) {
const QString hash = h.hash(); const QString hash = h.hash();
const qreal ratio = getRealRatio(hash); const qreal ratio = getRealRatio(hash);
qreal ratio_limit = TorrentPersistentData::getRatioLimit(hash);
if(ratio_limit == TorrentPersistentData::NO_RATIO_LIMIT)
continue;
if(ratio_limit == TorrentPersistentData::USE_GLOBAL_RATIO)
ratio_limit = global_ratio_limit;
qDebug("Ratio: %f (limit: %f)", ratio, ratio_limit); qDebug("Ratio: %f (limit: %f)", ratio, ratio_limit);
Q_ASSERT(ratio_limit >= 0.f);
if(ratio <= MAX_RATIO && ratio >= ratio_limit) { if(ratio <= MAX_RATIO && ratio >= ratio_limit) {
if(high_ratio_action == REMOVE_ACTION) { if(high_ratio_action == REMOVE_ACTION) {
addConsoleMessage(tr("%1 reached the maximum ratio you set.").arg(h.name())); addConsoleMessage(tr("%1 reached the maximum ratio you set.").arg(h.name()));
@ -502,7 +510,8 @@ void QBtSession::configureSession() {
applyEncryptionSettings(encryptionSettings); applyEncryptionSettings(encryptionSettings);
// * Maximum ratio // * Maximum ratio
high_ratio_action = pref.getMaxRatioAction(); high_ratio_action = pref.getMaxRatioAction();
setMaxRatio(pref.getMaxRatio()); setGlobalMaxRatio(pref.getGlobalMaxRatio());
updateRatioTimer();
// Ip Filter // Ip Filter
FilterParserThread::processFilterList(s, pref.bannedIPs()); FilterParserThread::processFilterList(s, pref.bannedIPs());
if(pref.isFilteringEnabled()) { if(pref.isFilteringEnabled()) {
@ -1774,22 +1783,53 @@ void QBtSession::setUploadRateLimit(long rate) {
// Torrents will a ratio superior to the given value will // Torrents will a ratio superior to the given value will
// be automatically deleted // be automatically deleted
void QBtSession::setMaxRatio(qreal ratio) { void QBtSession::setGlobalMaxRatio(qreal ratio) {
if(ratio < 0) ratio = -1.; if(ratio < 0) ratio = -1.;
if(ratio_limit == -1 && ratio != -1) { if(global_ratio_limit != ratio) {
Q_ASSERT(!BigRatioTimer); global_ratio_limit = ratio;
BigRatioTimer = new QTimer(this); qDebug("* Set global deleteRatio to %.1f", global_ratio_limit);
connect(BigRatioTimer, SIGNAL(timeout()), this, SLOT(processBigRatios())); updateRatioTimer();
BigRatioTimer->start(10000);
} else {
if(ratio_limit != -1 && ratio == -1) {
delete BigRatioTimer;
}
} }
if(ratio_limit != ratio) { }
ratio_limit = ratio;
qDebug("* Set deleteRatio to %.1f", ratio_limit); void QBtSession::setMaxRatioPerTorrent(const QString &hash, qreal ratio)
processBigRatios(); {
if (ratio < 0)
ratio = -1;
if (ratio > MAX_RATIO)
ratio = MAX_RATIO;
qDebug("* Set individual max ratio for torrent %s to %.1f.",
qPrintable(hash), ratio);
TorrentPersistentData::setRatioLimit(hash, ratio);
updateRatioTimer();
}
void QBtSession::removeRatioPerTorrent(const QString &hash)
{
qDebug("* Remove individual max ratio for torrent %s.", qPrintable(hash));
TorrentPersistentData::setRatioLimit(hash, TorrentPersistentData::USE_GLOBAL_RATIO);
updateRatioTimer();
}
qreal QBtSession::getMaxRatioPerTorrent(const QString &hash, bool *usesGlobalRatio) const
{
qreal ratio_limit = TorrentPersistentData::getRatioLimit(hash);
if(ratio_limit == TorrentPersistentData::USE_GLOBAL_RATIO) {
ratio_limit = global_ratio_limit;
*usesGlobalRatio = true;
} else {
*usesGlobalRatio = false;
}
return ratio_limit;
}
void QBtSession::updateRatioTimer()
{
if (global_ratio_limit == -1 && !TorrentPersistentData::hasPerTorrentRatioLimit()) {
if (BigRatioTimer->isActive())
BigRatioTimer->stop();
} else if (!BigRatioTimer->isActive()) {
BigRatioTimer->start();
} }
} }

View file

@ -129,7 +129,11 @@ public slots:
void setMaxUploadsPerTorrent(int max); void setMaxUploadsPerTorrent(int max);
void setDownloadRateLimit(long rate); void setDownloadRateLimit(long rate);
void setUploadRateLimit(long rate); void setUploadRateLimit(long rate);
void setMaxRatio(qreal ratio); void setGlobalMaxRatio(qreal ratio);
qreal getGlobalMaxRatio() const { return global_ratio_limit; }
void setMaxRatioPerTorrent(const QString &hash, qreal ratio);
qreal getMaxRatioPerTorrent(const QString &hash, bool *usesGlobalRatio) const;
void removeRatioPerTorrent(const QString &hash);
void setDHTPort(int dht_port); void setDHTPort(int dht_port);
void setProxySettings(const libtorrent::proxy_settings &proxySettings); void setProxySettings(const libtorrent::proxy_settings &proxySettings);
void setSessionSettings(const libtorrent::session_settings &sessionSettings); void setSessionSettings(const libtorrent::session_settings &sessionSettings);
@ -168,6 +172,7 @@ private:
void loadTorrentTempData(QTorrentHandle &h, QString savePath, bool magnet); void loadTorrentTempData(QTorrentHandle &h, QString savePath, bool magnet);
libtorrent::add_torrent_params initializeAddTorrentParams(const QString &hash); libtorrent::add_torrent_params initializeAddTorrentParams(const QString &hash);
libtorrent::entry generateFilePriorityResumeData(boost::intrusive_ptr<libtorrent::torrent_info> &t, const std::vector<int> &fp); libtorrent::entry generateFilePriorityResumeData(boost::intrusive_ptr<libtorrent::torrent_info> &t, const std::vector<int> &fp);
void updateRatioTimer();
private slots: private slots:
void addTorrentsFromScanFolder(QStringList&); void addTorrentsFromScanFolder(QStringList&);
@ -233,7 +238,7 @@ private:
// Settings // Settings
bool preAllocateAll; bool preAllocateAll;
bool addInPause; bool addInPause;
qreal ratio_limit; qreal global_ratio_limit;
int high_ratio_action; int high_ratio_action;
bool UPnPEnabled; bool UPnPEnabled;
bool LSDEnabled; bool LSDEnabled;

View file

@ -101,13 +101,15 @@ HEADERS += misc.h \
filesystemwatcher.h \ filesystemwatcher.h \
scannedfoldersmodel.h \ scannedfoldersmodel.h \
qinisettings.h \ qinisettings.h \
smtp.h smtp.h \
updownratiodlg.h
SOURCES += main.cpp \ SOURCES += main.cpp \
downloadthread.cpp \ downloadthread.cpp \
scannedfoldersmodel.cpp \ scannedfoldersmodel.cpp \
misc.cpp \ misc.cpp \
smtp.cpp smtp.cpp \
updownratiodlg.cpp
nox { nox {
HEADERS += headlessloader.h HEADERS += headlessloader.h
@ -164,6 +166,7 @@ nox {
downloadfromurldlg.ui \ downloadfromurldlg.ui \
torrentadditiondlg.ui \ torrentadditiondlg.ui \
bandwidth_limit.ui \ bandwidth_limit.ui \
updownratiodlg.ui \
confirmdeletiondlg.ui \ confirmdeletiondlg.ui \
torrentimportdlg.ui \ torrentimportdlg.ui \
executionlog.ui executionlog.ui

View file

@ -171,7 +171,12 @@ public:
class TorrentPersistentData { class TorrentPersistentData {
public: public:
enum RatioLimit {
USE_GLOBAL_RATIO = -2,
NO_RATIO_LIMIT = -1
};
public:
static bool isKnownTorrent(QString hash) { static bool isKnownTorrent(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
@ -184,6 +189,34 @@ public:
return all_data.keys(); return all_data.keys();
} }
static void setRatioLimit(const QString &hash, qreal ratio) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data.value(hash).toHash();
data["max_ratio"] = ratio;
all_data[hash] = data;
settings.setValue("torrents", all_data);
}
static qreal getRatioLimit(const QString &hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
return data.value("max_ratio", USE_GLOBAL_RATIO).toReal();
}
static bool hasPerTorrentRatioLimit() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant>::ConstIterator it;
for(it = all_data.constBegin(); it != all_data.constEnd(); it++) {
if(it.value().toHash().value("max_ratio", USE_GLOBAL_RATIO).toReal() >= 0) {
return true;
}
}
return false;
}
static void setAddedDate(QString hash) { static void setAddedDate(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents").toHash(); QHash<QString, QVariant> all_data = settings.value("torrents").toHash();

View file

@ -51,6 +51,7 @@
#include "transferlistdelegate.h" #include "transferlistdelegate.h"
#include "previewselect.h" #include "previewselect.h"
#include "speedlimitdlg.h" #include "speedlimitdlg.h"
#include "updownratiodlg.h"
#include "options_imp.h" #include "options_imp.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "preferences.h" #include "preferences.h"
@ -482,6 +483,29 @@ void TransferListWidget::setUpLimitSelectedTorrents() {
} }
} }
void TransferListWidget::setMaxRatioSelectedTorrents() {
const QStringList hashes = getSelectedTorrentsHashes();
if (hashes.isEmpty())
return;
bool useGlobalValue;
qreal currentMaxRatio;
if (hashes.count() == 1) {
currentMaxRatio = BTSession->getMaxRatioPerTorrent(hashes.first(), &useGlobalValue);
} else {
useGlobalValue = true;
currentMaxRatio = BTSession->getGlobalMaxRatio();
}
UpDownRatioDlg dlg(useGlobalValue, currentMaxRatio, QBtSession::MAX_RATIO, this);
if (dlg.exec() != QDialog::Accepted)
return;
foreach (const QString &hash, hashes) {
if (dlg.useDefault())
BTSession->removeRatioPerTorrent(hash);
else
BTSession->setMaxRatioPerTorrent(hash, dlg.ratio());
}
}
void TransferListWidget::recheckSelectedTorrents() { void TransferListWidget::recheckSelectedTorrents() {
const QStringList hashes = getSelectedTorrentsHashes(); const QStringList hashes = getSelectedTorrentsHashes();
foreach(const QString &hash, hashes) { foreach(const QString &hash, hashes) {
@ -620,6 +644,8 @@ void TransferListWidget::displayListMenu(const QPoint&) {
connect(&actionDelete, SIGNAL(triggered()), this, SLOT(deleteSelectedTorrents())); connect(&actionDelete, SIGNAL(triggered()), this, SLOT(deleteSelectedTorrents()));
QAction actionPreview_file(IconProvider::instance()->getIcon("view-preview"), tr("Preview file..."), 0); QAction actionPreview_file(IconProvider::instance()->getIcon("view-preview"), tr("Preview file..."), 0);
connect(&actionPreview_file, SIGNAL(triggered()), this, SLOT(previewSelectedTorrents())); connect(&actionPreview_file, SIGNAL(triggered()), this, SLOT(previewSelectedTorrents()));
QAction actionSet_max_ratio(QIcon(QString::fromUtf8(":/Icons/skin/ratio.png")), tr("Limit share ratio..."), 0);
connect(&actionSet_max_ratio, SIGNAL(triggered()), this, SLOT(setMaxRatioSelectedTorrents()));
QAction actionSet_upload_limit(QIcon(QString::fromUtf8(":/Icons/skin/seeding.png")), tr("Limit upload rate..."), 0); QAction actionSet_upload_limit(QIcon(QString::fromUtf8(":/Icons/skin/seeding.png")), tr("Limit upload rate..."), 0);
connect(&actionSet_upload_limit, SIGNAL(triggered()), this, SLOT(setUpLimitSelectedTorrents())); connect(&actionSet_upload_limit, SIGNAL(triggered()), this, SLOT(setUpLimitSelectedTorrents()));
QAction actionSet_download_limit(QIcon(QString::fromUtf8(":/Icons/skin/download.png")), tr("Limit download rate..."), 0); QAction actionSet_download_limit(QIcon(QString::fromUtf8(":/Icons/skin/download.png")), tr("Limit download rate..."), 0);
@ -742,6 +768,7 @@ void TransferListWidget::displayListMenu(const QPoint&) {
listMenu.addSeparator(); listMenu.addSeparator();
if(one_not_seed) if(one_not_seed)
listMenu.addAction(&actionSet_download_limit); listMenu.addAction(&actionSet_download_limit);
listMenu.addAction(&actionSet_max_ratio);
listMenu.addAction(&actionSet_upload_limit); listMenu.addAction(&actionSet_upload_limit);
#if LIBTORRENT_VERSION_MINOR > 14 #if LIBTORRENT_VERSION_MINOR > 14
if(!one_not_seed && all_same_super_seeding && one_has_metadata) { if(!one_not_seed && all_same_super_seeding && one_has_metadata) {

View file

@ -74,6 +74,7 @@ public slots:
void recheckSelectedTorrents(); void recheckSelectedTorrents();
void setDlLimitSelectedTorrents(); void setDlLimitSelectedTorrents();
void setUpLimitSelectedTorrents(); void setUpLimitSelectedTorrents();
void setMaxRatioSelectedTorrents();
void previewSelectedTorrents(); void previewSelectedTorrents();
void hidePriorityColumn(bool hide); void hidePriorityColumn(bool hide);
void displayDLHoSMenu(const QPoint&); void displayDLHoSMenu(const QPoint&);

45
src/updownratiodlg.cpp Normal file
View file

@ -0,0 +1,45 @@
#include "updownratiodlg.h"
#include "ui_updownratiodlg.h"
#include "preferences.h"
UpDownRatioDlg::UpDownRatioDlg(bool useDefault, qreal initialValue,
qreal maxValue, QWidget *parent)
: QDialog(parent), ui(new Ui::UpDownRatioDlg)
{
ui->setupUi(this);
if (useDefault) {
ui->useDefaultButton->setChecked(true);
} else if (initialValue == -1) {
ui->noLimitButton->setChecked(true);
initialValue = Preferences().getGlobalMaxRatio();
} else {
ui->torrentLimitButton->setChecked(true);
}
ui->ratioSpinBox->setMinimum(0);
ui->ratioSpinBox->setMaximum(maxValue);
ui->ratioSpinBox->setValue(initialValue);
connect(ui->buttonGroup, SIGNAL(buttonClicked(int)),
SLOT(handleRatioTypeChanged()));
handleRatioTypeChanged();
}
bool UpDownRatioDlg::useDefault() const
{
return ui->useDefaultButton->isChecked();
}
qreal UpDownRatioDlg::ratio() const
{
return ui->noLimitButton->isChecked() ? -1 : ui->ratioSpinBox->value();
}
void UpDownRatioDlg::handleRatioTypeChanged()
{
ui->ratioSpinBox->setEnabled(ui->torrentLimitButton->isChecked());
}
UpDownRatioDlg::~UpDownRatioDlg()
{
delete ui;
}

31
src/updownratiodlg.h Normal file
View file

@ -0,0 +1,31 @@
#ifndef UPDOWNRATIODLG_H
#define UPDOWNRATIODLG_H
#include <QtGui/QDialog>
QT_BEGIN_NAMESPACE
namespace Ui {
class UpDownRatioDlg;
}
QT_END_NAMESPACE
class UpDownRatioDlg : public QDialog
{
Q_OBJECT
public:
explicit UpDownRatioDlg(bool useDefault, qreal initialValue, qreal maxValue,
QWidget *parent = 0);
~UpDownRatioDlg();
bool useDefault() const;
qreal ratio() const;
private slots:
void handleRatioTypeChanged();
private:
Ui::UpDownRatioDlg *ui;
};
#endif // UPDOWNRATIODLG_H

137
src/updownratiodlg.ui Normal file
View file

@ -0,0 +1,137 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UpDownRatioDlg</class>
<widget class="QDialog" name="UpDownRatioDlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>317</width>
<height>152</height>
</rect>
</property>
<property name="windowTitle">
<string>Torrent Upload/Download Ratio Limiting</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="useDefaultButton">
<property name="text">
<string>Use global ratio limit</string>
</property>
<attribute name="buttonGroup">
<string>buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="noLimitButton">
<property name="text">
<string>Set no ratio limit</string>
</property>
<attribute name="buttonGroup">
<string>buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="torrentLimitButton">
<property name="text">
<string>Set ratio limit to</string>
</property>
<attribute name="buttonGroup">
<string>buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="ratioSpinBox">
<property name="decimals">
<number>1</number>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>UpDownRatioDlg</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>UpDownRatioDlg</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
<buttongroups>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>