diff --git a/src/gui/transferlistmodel.cpp b/src/gui/transferlistmodel.cpp index 7c827c1a6a84..3d00b442ebd3 100644 --- a/src/gui/transferlistmodel.cpp +++ b/src/gui/transferlistmodel.cpp @@ -194,6 +194,7 @@ QVariant TransferListModel::headerData(const int section, const Qt::Orientation case TR_INFOHASH_V2: return tr("Info Hash v2", "i.e: torrent info hash v2"); case TR_REANNOUNCE: return tr("Reannounce In", "Indicates the time until next trackers reannounce"); case TR_PRIVATE: return tr("Private", "Flags private torrents"); + case TR_PERCENT_SELECTED: return tr("%", "Percentage of selected data to download."); default: return {}; } } @@ -202,6 +203,7 @@ QVariant TransferListModel::headerData(const int section, const Qt::Orientation switch (section) { case TR_POPULARITY: return tr("Ratio / Time Active (in months), indicates how popular the torrent is"); + case TR_PERCENT_SELECTED: return tr("Wanted / Total size, indicates percentage of selected data to download."); default: return {}; } } @@ -443,6 +445,10 @@ QString TransferListModel::displayValue(const BitTorrent::Torrent *torrent, cons return reannounceString(torrent->nextAnnounce()); case TR_PRIVATE: return privateString(torrent->isPrivate(), torrent->hasMetadata()); + case TR_PERCENT_SELECTED: + if (!torrent->hasMetadata()) + return tr("N/A"); + return QString::number((torrent->wantedSize() * 100) / torrent->totalSize()) + u'%'; } return {}; @@ -526,6 +532,10 @@ QVariant TransferListModel::internalValue(const BitTorrent::Torrent *torrent, co return torrent->nextAnnounce(); case TR_PRIVATE: return (torrent->hasMetadata() ? torrent->isPrivate() : QVariant()); + case TR_PERCENT_SELECTED: + if (!torrent->hasMetadata()) + return 0; + return (torrent->wantedSize() * 100) / torrent->totalSize(); } return {}; diff --git a/src/gui/transferlistmodel.h b/src/gui/transferlistmodel.h index 306beee0b9a3..04f0b155df31 100644 --- a/src/gui/transferlistmodel.h +++ b/src/gui/transferlistmodel.h @@ -87,6 +87,7 @@ class TransferListModel final : public QAbstractListModel TR_INFOHASH_V2, TR_REANNOUNCE, TR_PRIVATE, + TR_PERCENT_SELECTED, NB_COLUMNS }; diff --git a/src/gui/transferlistsortmodel.cpp b/src/gui/transferlistsortmodel.cpp index 782aead74276..45199553d488 100644 --- a/src/gui/transferlistsortmodel.cpp +++ b/src/gui/transferlistsortmodel.cpp @@ -242,6 +242,9 @@ int TransferListSortModel::compare(const QModelIndex &left, const QModelIndex &r return threeWayCompare(totalL, totalR); } + case TransferListModel::TR_PERCENT_SELECTED: + return customCompare(leftValue.toFloat(), rightValue.toFloat()); + default: Q_ASSERT_X(false, Q_FUNC_INFO, "Missing comparison case"); break; diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index 9435b05beada..8a173887d55e 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -189,6 +189,7 @@ TransferListWidget::TransferListWidget(IGUIApplication *app, QWidget *parent) setColumnHidden(TransferListModel::TR_TOTAL_SIZE, true); setColumnHidden(TransferListModel::TR_REANNOUNCE, true); setColumnHidden(TransferListModel::TR_PRIVATE, true); + setColumnHidden(TransferListModel::TR_PERCENT_SELECTED, true); } //Ensure that at least one column is visible at all times diff --git a/src/webui/api/serialize/serialize_torrent.cpp b/src/webui/api/serialize/serialize_torrent.cpp index bc75a76985dd..67a6a1bf4fb3 100644 --- a/src/webui/api/serialize/serialize_torrent.cpp +++ b/src/webui/api/serialize/serialize_torrent.cpp @@ -166,6 +166,7 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent) {KEY_TORRENT_COMMENT, torrent.comment()}, {KEY_TORRENT_PRIVATE, (torrent.hasMetadata() ? torrent.isPrivate() : QVariant())}, {KEY_TORRENT_TOTAL_SIZE, torrent.totalSize()}, - {KEY_TORRENT_HAS_METADATA, torrent.hasMetadata()} + {KEY_TORRENT_HAS_METADATA, torrent.hasMetadata()}, + {KEY_TORRENT_PERCENT_SELECTED, torrent.hasMetadata() ? (torrent.wantedSize() * 100) / torrent.totalSize() : -1}, }; } diff --git a/src/webui/api/serialize/serialize_torrent.h b/src/webui/api/serialize/serialize_torrent.h index 883efa6dd5cd..2004edf3e701 100644 --- a/src/webui/api/serialize/serialize_torrent.h +++ b/src/webui/api/serialize/serialize_torrent.h @@ -96,5 +96,6 @@ inline const QString KEY_TORRENT_REANNOUNCE = u"reannounce"_s; inline const QString KEY_TORRENT_COMMENT = u"comment"_s; inline const QString KEY_TORRENT_PRIVATE = u"private"_s; inline const QString KEY_TORRENT_HAS_METADATA = u"has_metadata"_s; +inline const QString KEY_TORRENT_PERCENT_SELECTED = u"percent_selected"_s; QVariantMap serialize(const BitTorrent::Torrent &torrent); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index 514ed3f14d96..46ca4152936b 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -54,7 +54,7 @@ #include "base/utils/version.h" #include "api/isessionmanager.h" -inline const Utils::Version<3, 2> API_VERSION {2, 11, 3}; +inline const Utils::Version<3, 2> API_VERSION {2, 11, 4}; class QTimer; diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index 88edb34c1cd3..28babbcb2e7d 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -1025,6 +1025,7 @@ window.qBittorrent.DynamicTable ??= (() => { this.newColumn("infohash_v2", "", "QBT_TR(Info Hash v2)QBT_TR[CONTEXT=TransferListModel]", 100, false); this.newColumn("reannounce", "", "QBT_TR(Reannounce In)QBT_TR[CONTEXT=TransferListModel]", 100, false); this.newColumn("private", "", "QBT_TR(Private)QBT_TR[CONTEXT=TransferListModel]", 100, false); + this.newColumn("percent_selected", "", "QBT_TR(%)QBT_TR[CONTEXT=TransferListModel]", 100, false); this.columns["state_icon"].onclick = ""; this.columns["state_icon"].dataProperties[0] = "state"; @@ -1449,6 +1450,18 @@ window.qBittorrent.DynamicTable ??= (() => { td.textContent = string; td.title = string; }; + + // percent_selected + this.columns["percent_selected"].updateTd = function(td, row) { + if (this.getRowValue(row) === -1) { + td.textContent = "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]"; + td.title = "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]"; + return; + } + const value = window.qBittorrent.Misc.toFixedPointString(this.getRowValue(row), 2) + "%"; + td.textContent = value; + td.title = value; + }; }, applyFilter: (row, filterName, categoryHash, tagHash, trackerHash, filterTerms) => {