Skip to content

Commit

Permalink
Respect tracker tier when adding trackers
Browse files Browse the repository at this point in the history
  • Loading branch information
vktr committed May 15, 2021
1 parent 257a506 commit 7a8f438
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/picotorrent/ui/dialogs/addtrackerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,8 @@ std::string AddTrackerDialog::GetUrl()
{
return m_url->GetValue().ToStdString();
}

void AddTrackerDialog::SetTier(int tier)
{
m_tier->SetValue(std::to_string(tier));
}
1 change: 1 addition & 0 deletions src/picotorrent/ui/dialogs/addtrackerdialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Dialogs

int GetTier();
std::string GetUrl();
void SetTier(int tier);

private:
wxTextCtrl* m_url;
Expand Down
19 changes: 10 additions & 9 deletions src/picotorrent/ui/torrentdetailstrackerspanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,23 @@ void TorrentDetailsTrackersPanel::ShowTrackerContextMenu(wxDataViewEvent& evt)
wxEVT_MENU,
[this](wxCommandEvent const&)
{
auto trackers = m_torrent->Trackers();
auto maxTier = std::max_element(
trackers.begin(),
trackers.end(),
[](lt::announce_entry const& lhs, lt::announce_entry const& rhs)
{ return lhs.tier < rhs.tier; });

Dialogs::AddTrackerDialog addDialog(this, wxID_ANY);
addDialog.SetTier(maxTier != trackers.end() ? maxTier->tier + 1 : 0);

if (addDialog.ShowModal() == wxID_OK
&& addDialog.GetUrl().size() > 0)
{
// Get max tier
auto trackers = m_torrent->Trackers();
auto maxTier = std::max_element(
trackers.begin(),
trackers.end(),
[](lt::announce_entry const& lhs, lt::announce_entry const& rhs)
{ return lhs.tier < rhs.tier; });

lt::announce_entry ae;
ae.tier = maxTier != trackers.end() ? maxTier->tier + 1 : 0;
ae.tier = addDialog.GetTier();
ae.url = addDialog.GetUrl();

m_torrent->AddTracker(ae);
m_trackersModel->Update(m_torrent);
}
Expand Down

0 comments on commit 7a8f438

Please sign in to comment.