Skip to content

Commit

Permalink
Merge pull request #273 from vktr/f/rate-limit-validation
Browse files Browse the repository at this point in the history
Validate rate limits.
  • Loading branch information
vktr committed May 12, 2016
2 parents 65457b2 + 19e5c08 commit 33924a9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lang/1033.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,7 @@
"sparse": "Sparse",
"full": "Full",
"show_qr_code": "<a href=\"#\">Show QR code</a>",
"invalid_download_rate_limit": "Invalid download rate limit.",
"invalid_upload_rate_limit": "Invalid upload rate limit."
}
}
14 changes: 14 additions & 0 deletions src/client/controllers/view_preferences_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@ bool view_preferences_controller::on_downloads_validate()
return false;
}

if (dl_page_->download_rate() < 0)
{
dl_page_->show_error_message(
TR("invalid_download_rate_limit"));
return false;
}

if (dl_page_->upload_rate() < 0)
{
dl_page_->show_error_message(
TR("invalid_upload_rate_limit"));
return false;
}

return true;
}

Expand Down
6 changes: 4 additions & 2 deletions src/client/ui/property_sheets/preferences/downloads_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ std::string downloads_page::downloads_path()

int downloads_page::download_rate()
{
return std::stoi(get_dlg_item_text(ID_PREFS_GLOBAL_DL_LIMIT));
std::string dl = get_dlg_item_text(ID_PREFS_GLOBAL_DL_LIMIT);
return dl.empty() ? -1 : std::stoi(dl);
}

bool downloads_page::prompt_for_save_path()
Expand All @@ -33,7 +34,8 @@ bool downloads_page::prompt_for_save_path()
}
int downloads_page::upload_rate()
{
return std::stoi(get_dlg_item_text(ID_PREFS_GLOBAL_UL_LIMIT));
std::string ul = get_dlg_item_text(ID_PREFS_GLOBAL_UL_LIMIT);
return ul.empty() ? -1 : std::stoi(ul);
}

void downloads_page::set_downloads_path(const std::string &path)
Expand Down

0 comments on commit 33924a9

Please sign in to comment.