Skip to content

Commit

Permalink
Allow adjusting of total active/downloads/seeds in preferences (#527)
Browse files Browse the repository at this point in the history
Closes #514, closes #472
  • Loading branch information
vktr committed Mar 2, 2018
1 parent 658371a commit 2b172c2
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 10 deletions.
5 changes: 4 additions & 1 deletion lang/1033.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@
"info_hash": "Info hash",
"fails": "Fails",
"verified": "Verified",
"force_recheck": "Force recheck"
"force_recheck": "Force recheck",
"total_active": "Total active",
"active_downloads": "Active downloads",
"active_seeds": "Active seeds"
}
}
3 changes: 3 additions & 0 deletions src/picotorrent/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ namespace pt
int ActiveChecking();
int ActiveDhtLimit();
int ActiveDownloads();
void ActiveDownloads(int value);
int ActiveLimit();
void ActiveLimit(int value);
int ActiveLsdLimit();
int ActiveSeeds();
void ActiveSeeds(int value);
int ActiveTrackerLimit();

bool EnableAnonymousMode();
Expand Down
15 changes: 15 additions & 0 deletions src/picotorrent/config_sessionsection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ int Configuration::SessionSection::ActiveDownloads()
return Get("session", "active_downloads", 3);
}

void Configuration::SessionSection::ActiveDownloads(int value)
{
Set("session", "active_downloads", value);
}

int Configuration::SessionSection::ActiveLimit()
{
return Get("session", "active_limit", 15);
}

void Configuration::SessionSection::ActiveLimit(int value)
{
Set("session", "active_limit", value);
}

int Configuration::SessionSection::ActiveLsdLimit()
{
return Get("session", "active_lsd_limit", 60);
Expand All @@ -37,6 +47,11 @@ int Configuration::SessionSection::ActiveSeeds()
return Get("session", "active_seeds", 5);
}

void Configuration::SessionSection::ActiveSeeds(int value)
{
Set("session", "active_seeds", value);
}

int Configuration::SessionSection::ActiveTrackerLimit()
{
return Get("session", "active_tracker_limit", 1600);
Expand Down
62 changes: 53 additions & 9 deletions src/picotorrent/downloadspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "translator.hpp"

#include <wx/filepicker.h>
#include <wx/statline.h>

using pt::DownloadsPage;

Expand All @@ -22,8 +23,11 @@ DownloadsPage::DownloadsPage(wxWindow* parent, std::shared_ptr<pt::Configuration
transfersGrid->Add(m_savePathCtrl, 1, wxEXPAND);
transfersSizer->Add(transfersGrid, 1, wxEXPAND | wxALL, 5);


wxStaticBoxSizer* limitsSizer = new wxStaticBoxSizer(wxVERTICAL, this, i18n(tran, "limits"));
wxFlexGridSizer* limitsGrid = new wxFlexGridSizer(3, 10, 10);

/* Rate limits */
wxFlexGridSizer* transferLimitsGrid = new wxFlexGridSizer(3, 10, 10);

m_enableDownloadLimit = new wxCheckBox(limitsSizer->GetStaticBox(), wxID_ANY, i18n(tran, "dl_limit"));
m_enableDownloadLimit->SetValue(m_cfg->Session()->EnableDownloadRateLimit());
Expand All @@ -44,14 +48,40 @@ DownloadsPage::DownloadsPage(wxWindow* parent, std::shared_ptr<pt::Configuration
m_enableDownloadLimit->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent&) { m_downloadLimit->Enable(m_enableDownloadLimit->GetValue()); });
m_enableUploadLimit->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent&) { m_uploadLimit->Enable(m_enableUploadLimit->GetValue()); });

limitsGrid->AddGrowableCol(1, 1);
limitsGrid->Add(m_enableDownloadLimit, 0, wxALIGN_CENTER_VERTICAL);
limitsGrid->Add(m_downloadLimit, 0, wxALIGN_RIGHT);
limitsGrid->Add(new wxStaticText(limitsSizer->GetStaticBox(), wxID_ANY, "KB/s"), 0, wxALIGN_CENTER_VERTICAL);
limitsGrid->Add(m_enableUploadLimit, 0, wxALIGN_CENTER_VERTICAL);
limitsGrid->Add(m_uploadLimit, 0, wxALIGN_RIGHT);
limitsGrid->Add(new wxStaticText(limitsSizer->GetStaticBox(), wxID_ANY, "KB/s"), 0, wxALIGN_CENTER_VERTICAL);
limitsSizer->Add(limitsGrid, 1, wxEXPAND | wxALL, 5);
transferLimitsGrid->AddGrowableCol(1, 1);
transferLimitsGrid->Add(m_enableDownloadLimit, 0, wxALIGN_CENTER_VERTICAL);
transferLimitsGrid->Add(m_downloadLimit, 0, wxALIGN_RIGHT);
transferLimitsGrid->Add(new wxStaticText(limitsSizer->GetStaticBox(), wxID_ANY, "KB/s"), 0, wxALIGN_CENTER_VERTICAL);
transferLimitsGrid->Add(m_enableUploadLimit, 0, wxALIGN_CENTER_VERTICAL);
transferLimitsGrid->Add(m_uploadLimit, 0, wxALIGN_RIGHT);
transferLimitsGrid->Add(new wxStaticText(limitsSizer->GetStaticBox(), wxID_ANY, "KB/s"), 0, wxALIGN_CENTER_VERTICAL);

/* Active limits */
wxFlexGridSizer* activeLimitsGrid = new wxFlexGridSizer(2, 10, 10);

m_activeLimit = new wxTextCtrl(limitsSizer->GetStaticBox(), wxID_ANY);
m_activeLimit->SetValidator(wxTextValidator(wxFILTER_DIGITS));
m_activeLimit->SetValue(wxString::Format("%i", m_cfg->Session()->ActiveLimit()));

m_activeDownloadsLimit = new wxTextCtrl(limitsSizer->GetStaticBox(), wxID_ANY);
m_activeDownloadsLimit->SetValidator(wxTextValidator(wxFILTER_DIGITS));
m_activeDownloadsLimit->SetValue(wxString::Format("%i", m_cfg->Session()->ActiveDownloads()));

m_activeSeedsLimit = new wxTextCtrl(limitsSizer->GetStaticBox(), wxID_ANY);
m_activeSeedsLimit->SetValidator(wxTextValidator(wxFILTER_DIGITS));
m_activeSeedsLimit->SetValue(wxString::Format("%i", m_cfg->Session()->ActiveSeeds()));

activeLimitsGrid->AddGrowableCol(0, 1);
activeLimitsGrid->Add(new wxStaticText(limitsSizer->GetStaticBox(), wxID_ANY, i18n(tran, "total_active")));
activeLimitsGrid->Add(m_activeLimit, 0, wxALIGN_RIGHT);
activeLimitsGrid->Add(new wxStaticText(limitsSizer->GetStaticBox(), wxID_ANY, i18n(tran, "active_downloads")));
activeLimitsGrid->Add(m_activeDownloadsLimit, 0, wxALIGN_RIGHT);
activeLimitsGrid->Add(new wxStaticText(limitsSizer->GetStaticBox(), wxID_ANY, i18n(tran, "active_seeds")));
activeLimitsGrid->Add(m_activeSeedsLimit, 0, wxALIGN_RIGHT);

limitsSizer->Add(transferLimitsGrid, 0, wxEXPAND | wxALL, 5);
limitsSizer->Add(new wxStaticLine(limitsSizer->GetStaticBox(), wxID_ANY), 0, wxEXPAND | wxALL, 5);
limitsSizer->Add(activeLimitsGrid, 0, wxEXPAND | wxALL, 5);

wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(transfersSizer, 0, wxEXPAND);
Expand All @@ -75,6 +105,20 @@ void DownloadsPage::ApplyConfiguration()
m_cfg->Session()->DownloadRateLimit(static_cast<int>(dlLimit));
m_cfg->Session()->EnableUploadRateLimit(m_enableUploadLimit->GetValue());
m_cfg->Session()->UploadRateLimit(static_cast<int>(ulLimit));

// Active limits
long activeLimit = 0;
m_activeLimit->GetValue().ToLong(&activeLimit);

long activeDownloads = 0;
m_activeDownloadsLimit->GetValue().ToLong(&activeDownloads);

long activeSeeds = 0;
m_activeSeedsLimit->GetValue().ToLong(&activeSeeds);

m_cfg->Session()->ActiveLimit(static_cast<int>(activeLimit));
m_cfg->Session()->ActiveDownloads(static_cast<int>(activeDownloads));
m_cfg->Session()->ActiveSeeds(static_cast<int>(activeSeeds));
}

bool DownloadsPage::ValidateConfiguration(wxString& error)
Expand Down
3 changes: 3 additions & 0 deletions src/picotorrent/downloadspage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ namespace pt
wxTextCtrl* m_downloadLimit;
wxCheckBox* m_enableUploadLimit;
wxTextCtrl* m_uploadLimit;
wxTextCtrl* m_activeLimit;
wxTextCtrl* m_activeDownloadsLimit;
wxTextCtrl* m_activeSeedsLimit;
};
}

0 comments on commit 2b172c2

Please sign in to comment.