Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "% Selected" column to transfer list #22131

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/gui/transferlistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
}
Expand All @@ -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 {};
}
}
Expand Down Expand Up @@ -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'%';
thalieht marked this conversation as resolved.
Show resolved Hide resolved
}

return {};
Expand Down Expand Up @@ -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 {};
Expand Down
1 change: 1 addition & 0 deletions src/gui/transferlistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class TransferListModel final : public QAbstractListModel
TR_INFOHASH_V2,
TR_REANNOUNCE,
TR_PRIVATE,
TR_PERCENT_SELECTED,

NB_COLUMNS
};
Expand Down
3 changes: 3 additions & 0 deletions src/gui/transferlistsortmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/gui/transferlistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/webui/api/serialize/serialize_torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
}
1 change: 1 addition & 0 deletions src/webui/api/serialize/serialize_torrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/webui/webapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 13 additions & 0 deletions src/webui/www/private/scripts/dynamicTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) => {
Expand Down