From f27e75e8fa5b77105bf5d9a0cfc676867ea6f4ce Mon Sep 17 00:00:00 2001 From: thalieht Date: Wed, 6 Sep 2017 22:47:05 +0300 Subject: [PATCH] Properly pre-select the selected torrent's current ratio limiting options in UpDownRatioDlg dialogs. Fixes #7352 --- src/base/bittorrent/session.cpp | 2 +- src/base/bittorrent/torrenthandle.cpp | 36 +++++++-------------------- src/base/bittorrent/torrenthandle.h | 4 +-- src/gui/transferlistwidget.cpp | 10 +++++--- 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index b22363f1f..9ca65b702 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -3383,7 +3383,7 @@ bool Session::isKnownTorrent(const InfoHash &hash) const void Session::updateSeedingLimitTimer() { - if ((globalMaxRatio() == -1) && !hasPerTorrentRatioLimit() + if ((globalMaxRatio() == TorrentHandle::NO_RATIO_LIMIT) && !hasPerTorrentRatioLimit() && (globalMaxSeedingMinutes() == TorrentHandle::NO_SEEDING_TIME_LIMIT) && !hasPerTorrentSeedingTimeLimit()) { if (m_seedingLimitTimer->isActive()) m_seedingLimitTimer->stop(); diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 8616c8a27..7f3f1fe9b 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -1180,38 +1180,20 @@ qreal TorrentHandle::distributedCopies() const return m_nativeStatus.distributed_copies; } -qreal TorrentHandle::maxRatio(bool *usesGlobalRatio) const +qreal TorrentHandle::maxRatio() const { - qreal ratioLimit = m_ratioLimit; + if (m_ratioLimit == USE_GLOBAL_RATIO) + return m_session->globalMaxRatio(); - if (ratioLimit == USE_GLOBAL_RATIO) { - ratioLimit = m_session->globalMaxRatio(); - if (usesGlobalRatio) - *usesGlobalRatio = true; - } - else { - if (usesGlobalRatio) - *usesGlobalRatio = false; - } - - return ratioLimit; + return m_ratioLimit; } -int TorrentHandle::maxSeedingTime(bool *usesGlobalSeedingTime) const +int TorrentHandle::maxSeedingTime() const { - int seedingTimeLimit = m_seedingTimeLimit; + if (m_seedingTimeLimit == USE_GLOBAL_SEEDING_TIME) + return m_session->globalMaxSeedingMinutes(); - if (seedingTimeLimit == USE_GLOBAL_SEEDING_TIME) { - seedingTimeLimit = m_session->globalMaxSeedingMinutes(); - if (usesGlobalSeedingTime) - *usesGlobalSeedingTime = true; - } - else { - if (usesGlobalSeedingTime) - *usesGlobalSeedingTime = false; - } - - return seedingTimeLimit; + return m_seedingTimeLimit; } qreal TorrentHandle::realRatio() const @@ -1688,7 +1670,7 @@ void TorrentHandle::handleSaveResumeDataAlert(libtorrent::save_resume_data_alert } resumeData["qBt-savePath"] = m_useAutoTMM ? "" : Profile::instance().toPortablePath(m_savePath).toStdString(); resumeData["qBt-ratioLimit"] = QString::number(m_ratioLimit).toStdString(); - resumeData["qBt-seedingTimeLimit"] = QString::number(m_seedingTimeLimit).toStdString(); + resumeData["qBt-seedingTimeLimit"] = m_seedingTimeLimit; resumeData["qBt-category"] = m_category.toStdString(); resumeData["qBt-tags"] = setToEntryList(m_tags); resumeData["qBt-name"] = m_name.toStdString(); diff --git a/src/base/bittorrent/torrenthandle.h b/src/base/bittorrent/torrenthandle.h index b6aa59c86..167fec71d 100644 --- a/src/base/bittorrent/torrenthandle.h +++ b/src/base/bittorrent/torrenthandle.h @@ -328,8 +328,8 @@ namespace BitTorrent QBitArray downloadingPieces() const; QVector pieceAvailability() const; qreal distributedCopies() const; - qreal maxRatio(bool *usesGlobalRatio = 0) const; - int maxSeedingTime(bool *usesGlobalSeedingTime = 0) const; + qreal maxRatio() const; + int maxSeedingTime() const; qreal realRatio() const; int uploadPayloadRate() const; int downloadPayloadRate() const; diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index 53f1913b3..53a36b431 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -627,14 +627,18 @@ void TransferListWidget::setMaxRatioSelectedTorrents() const QList torrents = getSelectedTorrents(); if (torrents.isEmpty()) return; - bool useGlobalValue = true; qreal currentMaxRatio = BitTorrent::Session::instance()->globalMaxRatio(); if (torrents.count() == 1) - currentMaxRatio = torrents[0]->maxRatio(&useGlobalValue); + currentMaxRatio = torrents[0]->maxRatio(); int currentMaxSeedingTime = BitTorrent::Session::instance()->globalMaxSeedingMinutes(); if (torrents.count() == 1) - currentMaxSeedingTime = torrents[0]->maxSeedingTime(&useGlobalValue); + currentMaxSeedingTime = torrents[0]->maxSeedingTime(); + + bool useGlobalValue = true; + if (torrents.count() == 1) + useGlobalValue = (torrents[0]->ratioLimit() == BitTorrent::TorrentHandle::USE_GLOBAL_RATIO) + && (torrents[0]->seedingTimeLimit() == BitTorrent::TorrentHandle::USE_GLOBAL_SEEDING_TIME); UpDownRatioDlg dlg(useGlobalValue, currentMaxRatio, BitTorrent::TorrentHandle::MAX_RATIO, currentMaxSeedingTime, BitTorrent::TorrentHandle::MAX_SEEDING_TIME, this);