source: filezilla/trunk/fuentes/src/interface/speedlimits_dialog.cpp @ 3185

Last change on this file since 3185 was 3185, checked in by jrpelegrina, 3 years ago

Update new version: 3.15.02

File size: 2.8 KB
Line 
1#include <filezilla.h>
2#include "sizeformatting.h"
3#include "speedlimits_dialog.h"
4#include "Options.h"
5
6BEGIN_EVENT_TABLE(CSpeedLimitsDialog, wxDialogEx)
7EVT_BUTTON(wxID_OK, CSpeedLimitsDialog::OnOK)
8EVT_CHECKBOX(XRCID("ID_ENABLE_SPEEDLIMITS"), CSpeedLimitsDialog::OnToggleEnable)
9END_EVENT_TABLE()
10
11void CSpeedLimitsDialog::Run(wxWindow* parent)
12{
13        if (!Load(parent, _T("ID_SPEEDLIMITS")))
14                return;
15
16        int downloadlimit = COptions::Get()->GetOptionVal(OPTION_SPEEDLIMIT_INBOUND);
17        int uploadlimit = COptions::Get()->GetOptionVal(OPTION_SPEEDLIMIT_OUTBOUND);
18        bool enable = COptions::Get()->GetOptionVal(OPTION_SPEEDLIMIT_ENABLE) != 0;
19        if (!downloadlimit && !uploadlimit)
20                enable = false;
21
22        XRCCTRL(*this, "ID_ENABLE_SPEEDLIMITS", wxCheckBox)->SetValue(enable);
23
24        wxTextCtrl* pCtrl = XRCCTRL(*this, "ID_DOWNLOADLIMIT", wxTextCtrl);
25        pCtrl->Enable(enable);
26        pCtrl->SetMaxLength(9);
27        pCtrl->ChangeValue(wxString::Format(_T("%d"), downloadlimit));
28
29        pCtrl = XRCCTRL(*this, "ID_UPLOADLIMIT", wxTextCtrl);
30        pCtrl->Enable(enable);
31        pCtrl->SetMaxLength(9);
32        pCtrl->ChangeValue(wxString::Format(_T("%d"), uploadlimit));
33
34        const wxString unit = CSizeFormat::GetUnitWithBase(CSizeFormat::kilo, 1024);
35
36        wxStaticText* pUnit = XRCCTRL(*this, "ID_DOWNLOADLIMIT_UNIT", wxStaticText);
37        if (pUnit)
38                pUnit->SetLabel(wxString::Format(pUnit->GetLabel(), unit));
39
40        pUnit = XRCCTRL(*this, "ID_UPLOADLIMIT_UNIT", wxStaticText);
41        if (pUnit)
42                pUnit->SetLabel(wxString::Format(pUnit->GetLabel(), unit));
43
44        ShowModal();
45}
46
47void CSpeedLimitsDialog::OnOK(wxCommandEvent&)
48{
49        long download, upload;
50        wxTextCtrl* pCtrl = XRCCTRL(*this, "ID_DOWNLOADLIMIT", wxTextCtrl);
51        if (!pCtrl->GetValue().ToLong(&download) || (download < 0))
52        {
53                const wxString unit = CSizeFormat::GetUnitWithBase(CSizeFormat::kilo, 1024);
54                wxMessageBoxEx(wxString::Format(_("Please enter a download speed limit greater or equal to 0 %s/s."), unit), _("Speed Limits"), wxOK, this);
55                return;
56        }
57
58        pCtrl = XRCCTRL(*this, "ID_UPLOADLIMIT", wxTextCtrl);
59        if (!pCtrl->GetValue().ToLong(&upload) || (upload < 0))
60        {
61                const wxString unit = CSizeFormat::GetUnitWithBase(CSizeFormat::kilo, 1024);
62                wxMessageBoxEx(wxString::Format(_("Please enter an upload speed limit greater or equal to 0 %s/s."), unit), _("Speed Limits"), wxOK, this);
63                return;
64        }
65
66        COptions::Get()->SetOption(OPTION_SPEEDLIMIT_INBOUND, download);
67        COptions::Get()->SetOption(OPTION_SPEEDLIMIT_OUTBOUND, upload);
68
69        bool enable = XRCCTRL(*this, "ID_ENABLE_SPEEDLIMITS", wxCheckBox)->GetValue() ? 1 : 0;
70        COptions::Get()->SetOption(OPTION_SPEEDLIMIT_ENABLE, enable && (download || upload));
71
72        EndDialog(wxID_OK);
73}
74
75void CSpeedLimitsDialog::OnToggleEnable(wxCommandEvent& event)
76{
77        XRCCTRL(*this, "ID_DOWNLOADLIMIT", wxTextCtrl)->Enable(event.IsChecked());
78        XRCCTRL(*this, "ID_UPLOADLIMIT", wxTextCtrl)->Enable(event.IsChecked());
79}
Note: See TracBrowser for help on using the repository browser.