From cea3f71e6121ee4f3c366a5d40a19a22818a1147 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Thu, 14 Aug 2014 20:46:55 +0300 Subject: [PATCH] Added 'Ratio Limit' column. Closes #936. --- src/qtlibtorrent/qbtsession.cpp | 6 ++++-- src/qtlibtorrent/torrentmodel.cpp | 3 +++ src/qtlibtorrent/torrentmodel.h | 2 +- src/transferlistdelegate.h | 16 +++++++++------- src/transferlistwidget.cpp | 1 + 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 20275683c..b1330ad6b 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -2073,9 +2073,11 @@ qreal QBtSession::getMaxRatioPerTorrent(const QString &hash, bool *usesGlobalRat qreal ratio_limit = TorrentPersistentData::getRatioLimit(hash); if (ratio_limit == TorrentPersistentData::USE_GLOBAL_RATIO) { ratio_limit = global_ratio_limit; - *usesGlobalRatio = true; + if (usesGlobalRatio) + *usesGlobalRatio = true; } else { - *usesGlobalRatio = false; + if (usesGlobalRatio) + *usesGlobalRatio = false; } return ratio_limit; } diff --git a/src/qtlibtorrent/torrentmodel.cpp b/src/qtlibtorrent/torrentmodel.cpp index 3d57e1a0d..9bd1d2287 100644 --- a/src/qtlibtorrent/torrentmodel.cpp +++ b/src/qtlibtorrent/torrentmodel.cpp @@ -218,6 +218,8 @@ QVariant TorrentModelItem::data(int column, int role) const return m_torrent.save_path_parsed(); case TR_COMPLETED: return static_cast(m_torrent.total_wanted_done()); + case TR_RATIO_LIMIT: + return QBtSession::instance()->getMaxRatioPerTorrent(m_hash, NULL); default: return QVariant(); } @@ -292,6 +294,7 @@ QVariant TorrentModel::headerData(int section, Qt::Orientation orientation, case TorrentModelItem::TR_TIME_ELAPSED: return tr("Time Active", "Time (duration) the torrent is active (not paused)"); case TorrentModelItem::TR_SAVE_PATH: return tr("Save path", "Torrent save path"); case TorrentModelItem::TR_COMPLETED: return tr("Completed", "Amount of data completed (e.g. in MB)"); + case TorrentModelItem::TR_RATIO_LIMIT: return tr("Ratio Limit", "Upload share ratio limit"); default: return QVariant(); } diff --git a/src/qtlibtorrent/torrentmodel.h b/src/qtlibtorrent/torrentmodel.h index 6fca0d44c..6cd22c4cf 100644 --- a/src/qtlibtorrent/torrentmodel.h +++ b/src/qtlibtorrent/torrentmodel.h @@ -49,7 +49,7 @@ Q_OBJECT public: enum State {STATE_DOWNLOADING, STATE_DOWNLOADING_META, STATE_ALLOCATING, STATE_STALLED_DL, STATE_STALLED_UP, STATE_SEEDING, STATE_PAUSED_DL, STATE_PAUSED_UP, STATE_QUEUED_DL, STATE_QUEUED_UP, STATE_CHECKING_UP, STATE_CHECKING_DL, STATE_QUEUED_CHECK, STATE_QUEUED_FASTCHECK, STATE_INVALID}; - enum Column {TR_NAME, TR_PRIORITY, TR_SIZE, TR_PROGRESS, TR_STATUS, TR_SEEDS, TR_PEERS, TR_DLSPEED, TR_UPSPEED, TR_ETA, TR_RATIO, TR_LABEL, TR_ADD_DATE, TR_SEED_DATE, TR_TRACKER, TR_DLLIMIT, TR_UPLIMIT, TR_AMOUNT_DOWNLOADED, TR_AMOUNT_UPLOADED, TR_AMOUNT_LEFT, TR_TIME_ELAPSED, TR_SAVE_PATH, TR_COMPLETED, NB_COLUMNS}; + enum Column {TR_NAME, TR_PRIORITY, TR_SIZE, TR_PROGRESS, TR_STATUS, TR_SEEDS, TR_PEERS, TR_DLSPEED, TR_UPSPEED, TR_ETA, TR_RATIO, TR_LABEL, TR_ADD_DATE, TR_SEED_DATE, TR_TRACKER, TR_DLLIMIT, TR_UPLIMIT, TR_AMOUNT_DOWNLOADED, TR_AMOUNT_UPLOADED, TR_AMOUNT_LEFT, TR_TIME_ELAPSED, TR_SAVE_PATH, TR_COMPLETED, TR_RATIO_LIMIT, NB_COLUMNS}; public: TorrentModelItem(const QTorrentHandle& h); diff --git a/src/transferlistdelegate.h b/src/transferlistdelegate.h index ca5a27741..e2d104bd9 100644 --- a/src/transferlistdelegate.h +++ b/src/transferlistdelegate.h @@ -62,12 +62,12 @@ public: case TorrentModelItem::TR_AMOUNT_UPLOADED: case TorrentModelItem::TR_AMOUNT_LEFT: case TorrentModelItem::TR_COMPLETED: - case TorrentModelItem::TR_SIZE:{ + case TorrentModelItem::TR_SIZE: { QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong())); break; } - case TorrentModelItem::TR_ETA:{ + case TorrentModelItem::TR_ETA: { QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, option.rect, misc::userFriendlyDuration(index.data().toLongLong())); break; @@ -129,14 +129,14 @@ public: break; } case TorrentModelItem::TR_UPSPEED: - case TorrentModelItem::TR_DLSPEED:{ + case TorrentModelItem::TR_DLSPEED: { QItemDelegate::drawBackground(painter, opt, index); const qulonglong speed = index.data().toULongLong(); QItemDelegate::drawDisplay(painter, opt, opt.rect, misc::friendlyUnit(speed)+tr("/s", "/second (.i.e per second)")); break; } case TorrentModelItem::TR_UPLIMIT: - case TorrentModelItem::TR_DLLIMIT:{ + case TorrentModelItem::TR_DLLIMIT: { QItemDelegate::drawBackground(painter, opt, index); const qlonglong limit = index.data().toLongLong(); QItemDelegate::drawDisplay(painter, opt, opt.rect, limit > 0 ? misc::accurateDoubleToString(limit/1024., 1) + " " + tr("KiB/s", "KiB/second (.i.e per second)") : QString::fromUtf8("∞")); @@ -156,10 +156,12 @@ public: QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, opt.rect, index.data().toDateTime().toLocalTime().toString(Qt::DefaultLocaleShortDate)); break; - case TorrentModelItem::TR_RATIO:{ + case TorrentModelItem::TR_RATIO_LIMIT: + case TorrentModelItem::TR_RATIO: { QItemDelegate::drawBackground(painter, opt, index); const qreal ratio = index.data().toDouble(); - QItemDelegate::drawDisplay(painter, opt, opt.rect, ratio > QBtSession::MAX_RATIO ? QString::fromUtf8("∞") : misc::accurateDoubleToString(ratio, 2)); + QItemDelegate::drawDisplay(painter, opt, opt.rect, + (ratio == -1 || ratio > QBtSession::MAX_RATIO) ? QString::fromUtf8("∞") : misc::accurateDoubleToString(ratio, 2)); break; } case TorrentModelItem::TR_PRIORITY: { @@ -172,7 +174,7 @@ public: } break; } - case TorrentModelItem::TR_PROGRESS:{ + case TorrentModelItem::TR_PROGRESS: { QStyleOptionProgressBarV2 newopt; qreal progress = index.data().toDouble()*100.; newopt.rect = opt.rect; diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index 1f6791fe0..f82030142 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -126,6 +126,7 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window, setColumnHidden(TorrentModelItem::TR_TIME_ELAPSED, true); setColumnHidden(TorrentModelItem::TR_SAVE_PATH, true); setColumnHidden(TorrentModelItem::TR_COMPLETED, true); + setColumnHidden(TorrentModelItem::TR_RATIO_LIMIT, true); } //Ensure that at least one column is visible at all times