Skip to content

Commit

Permalink
Show torrent availability column (#528)
Browse files Browse the repository at this point in the history
Closes #451
  • Loading branch information
vktr committed Mar 2, 2018
1 parent 2b172c2 commit ea15aa7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions lang/1033.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
"fails": "Fails",
"verified": "Verified",
"force_recheck": "Force recheck",
"availability": "Availability",
"total_active": "Total active",
"active_downloads": "Active downloads",
"active_seeds": "Active seeds"
Expand Down
8 changes: 8 additions & 0 deletions src/picotorrent/torrentlistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ TorrentListView::TorrentListView(wxWindow* parent, wxWindowID id, std::shared_pt
wxALIGN_RIGHT,
wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE);

AppendTextColumn(
i18n(tr, "availability"),
TorrentListViewModel::Columns::Availability,
wxDATAVIEW_CELL_INERT,
80,
wxALIGN_RIGHT,
wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE);

AppendTextColumn(
i18n(tr, "ratio"),
TorrentListViewModel::Columns::Ratio,
Expand Down
22 changes: 22 additions & 0 deletions src/picotorrent/torrentlistviewmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ void TorrentListViewModel::Sort(int columnId, bool ascending)

break;
}
case Columns::Availability:
{
sorter = [this, ascending](lt::torrent_status const& ts1, lt::torrent_status const& ts2)
{
if (ascending) { return ts1.distributed_copies < ts2.distributed_copies; }
return ts1.distributed_copies > ts2.distributed_copies;
};

break;
}
case Columns::Ratio:
{
sorter = [this, ascending](lt::torrent_status const& ts1, lt::torrent_status const& ts2)
Expand Down Expand Up @@ -257,6 +267,18 @@ void TorrentListViewModel::GetValueByRow(wxVariant &variant, unsigned int row, u
}
break;
}
case Columns::Availability:
{
if (ts.distributed_copies < 0)
{
variant = "-";
}
else
{
variant = wxString::Format("%.3f", ts.distributed_copies);
}
break;
}
case Columns::Ratio:
{
float ratio = GetRatio(ts);
Expand Down
1 change: 1 addition & 0 deletions src/picotorrent/torrentlistviewmodel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace pt
ETA,
DownloadSpeed,
UploadSpeed,
Availability,
Ratio,
Seeds,
Peers,
Expand Down

0 comments on commit ea15aa7

Please sign in to comment.