source: filezilla/trunk/fuentes/src/interface/settings/optionspage_transfer.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: 6.0 KB
Line 
1#include <filezilla.h>
2#include "../Options.h"
3#include "../sizeformatting.h"
4#include "settingsdialog.h"
5#include "optionspage.h"
6#include "optionspage_transfer.h"
7
8BEGIN_EVENT_TABLE(COptionsPageTransfer, COptionsPage)
9EVT_CHECKBOX(XRCID("ID_ENABLE_SPEEDLIMITS"), COptionsPageTransfer::OnToggleSpeedLimitEnable)
10END_EVENT_TABLE()
11
12void COptionsPageTransfer::OnToggleSpeedLimitEnable(wxCommandEvent&)
13{
14        bool enable_speedlimits = GetCheck(XRCID("ID_ENABLE_SPEEDLIMITS"));
15        XRCCTRL(*this, "ID_DOWNLOADLIMIT", wxTextCtrl)->Enable(enable_speedlimits);
16        XRCCTRL(*this, "ID_UPLOADLIMIT", wxTextCtrl)->Enable(enable_speedlimits);
17        XRCCTRL(*this, "ID_BURSTTOLERANCE", wxChoice)->Enable(enable_speedlimits);
18}
19
20bool COptionsPageTransfer::LoadPage()
21{
22        bool failure = false;
23
24        bool enable_speedlimits = m_pOptions->GetOptionVal(OPTION_SPEEDLIMIT_ENABLE) != 0;
25        SetCheck(XRCID("ID_ENABLE_SPEEDLIMITS"), enable_speedlimits, failure);
26
27        wxTextCtrl* pTextCtrl = XRCCTRL(*this, "ID_DOWNLOADLIMIT", wxTextCtrl);
28        if (!pTextCtrl)
29                return false;
30        pTextCtrl->SetMaxLength(9);
31        pTextCtrl->ChangeValue(m_pOptions->GetOption(OPTION_SPEEDLIMIT_INBOUND));
32        pTextCtrl->Enable(enable_speedlimits);
33
34        pTextCtrl = XRCCTRL(*this, "ID_UPLOADLIMIT", wxTextCtrl);
35        if (!pTextCtrl)
36                return false;
37        pTextCtrl->SetMaxLength(9);
38        pTextCtrl->ChangeValue(m_pOptions->GetOption(OPTION_SPEEDLIMIT_OUTBOUND));
39        pTextCtrl->Enable(enable_speedlimits);
40
41        XRCCTRL(*this, "ID_NUMTRANSFERS", wxSpinCtrl)->SetValue(m_pOptions->GetOptionVal(OPTION_NUMTRANSFERS));
42        XRCCTRL(*this, "ID_NUMDOWNLOADS", wxSpinCtrl)->SetValue(m_pOptions->GetOptionVal(OPTION_CONCURRENTDOWNLOADLIMIT));
43        XRCCTRL(*this, "ID_NUMUPLOADS", wxSpinCtrl)->SetValue(m_pOptions->GetOptionVal(OPTION_CONCURRENTUPLOADLIMIT));
44
45        SetChoice(XRCID("ID_BURSTTOLERANCE"), m_pOptions->GetOptionVal(OPTION_SPEEDLIMIT_BURSTTOLERANCE), failure);
46        XRCCTRL(*this, "ID_BURSTTOLERANCE", wxChoice)->Enable(enable_speedlimits);
47
48        wxStaticText* pUnit = XRCCTRL(*this, "ID_DOWNLOADLIMIT_UNIT", wxStaticText);
49        if (!pUnit)
50                return false;
51        pUnit->SetLabel(wxString::Format(pUnit->GetLabel(), CSizeFormat::GetUnitWithBase(CSizeFormat::kilo, 1024)));
52
53        pUnit = XRCCTRL(*this, "ID_UPLOADLIMIT_UNIT", wxStaticText);
54        if (!pUnit)
55                return false;
56        pUnit->SetLabel(wxString::Format(pUnit->GetLabel(), CSizeFormat::GetUnitWithBase(CSizeFormat::kilo, 1024)));
57
58        pTextCtrl = XRCCTRL(*this, "ID_REPLACE", wxTextCtrl);
59        pTextCtrl->SetMaxLength(1);
60        pTextCtrl->ChangeValue(m_pOptions->GetOption(OPTION_INVALID_CHAR_REPLACE));
61
62        SetCheckFromOption(XRCID("ID_ENABLE_REPLACE"), OPTION_INVALID_CHAR_REPLACE_ENABLE, failure);
63
64#ifdef __WXMSW__
65        wxString invalid = _T("\\ / : * ? \" < > |");
66        wxString filtered = wxString::Format(_("The following characters will be replaced: %s"), invalid);
67#else
68        wxString invalid = _T("/");
69        wxString filtered = wxString::Format(_("The following character will be replaced: %s"), invalid);
70#endif
71        XRCCTRL(*this, "ID_REPLACED", wxStaticText)->SetLabel(filtered);
72
73        SetCheckFromOption(XRCID("ID_ENABLE_PREALLOCATION"), OPTION_PREALLOCATE_SPACE, failure);
74
75        return !failure;
76}
77
78bool COptionsPageTransfer::SavePage()
79{
80        SetOptionFromCheck(XRCID("ID_ENABLE_SPEEDLIMITS"), OPTION_SPEEDLIMIT_ENABLE);
81
82        m_pOptions->SetOption(OPTION_NUMTRANSFERS,                              XRCCTRL(*this, "ID_NUMTRANSFERS", wxSpinCtrl)->GetValue());
83        m_pOptions->SetOption(OPTION_CONCURRENTDOWNLOADLIMIT,   XRCCTRL(*this, "ID_NUMDOWNLOADS", wxSpinCtrl)->GetValue());
84        m_pOptions->SetOption(OPTION_CONCURRENTUPLOADLIMIT,             XRCCTRL(*this, "ID_NUMUPLOADS", wxSpinCtrl)->GetValue());
85
86        SetOptionFromText(XRCID("ID_DOWNLOADLIMIT"), OPTION_SPEEDLIMIT_INBOUND);
87        SetOptionFromText(XRCID("ID_UPLOADLIMIT"), OPTION_SPEEDLIMIT_OUTBOUND);
88        m_pOptions->SetOption(OPTION_SPEEDLIMIT_BURSTTOLERANCE, GetChoice(XRCID("ID_BURSTTOLERANCE")));
89        SetOptionFromText(XRCID("ID_REPLACE"), OPTION_INVALID_CHAR_REPLACE);
90        SetOptionFromCheck(XRCID("ID_ENABLE_REPLACE"), OPTION_INVALID_CHAR_REPLACE_ENABLE);
91
92        SetOptionFromCheck(XRCID("ID_ENABLE_PREALLOCATION"), OPTION_PREALLOCATE_SPACE);
93
94        return true;
95}
96
97bool COptionsPageTransfer::Validate()
98{
99        long tmp;
100        wxTextCtrl* pCtrl;
101        wxSpinCtrl* pSpinCtrl;
102        int spinValue;
103
104        pSpinCtrl = XRCCTRL(*this, "ID_NUMTRANSFERS", wxSpinCtrl);
105        spinValue = pSpinCtrl->GetValue();
106        if (spinValue < 1 || spinValue > 10)
107                return DisplayError(pSpinCtrl, _("Please enter a number between 1 and 10 for the number of concurrent transfers."));
108
109        pSpinCtrl = XRCCTRL(*this, "ID_NUMDOWNLOADS", wxSpinCtrl);
110        spinValue = pSpinCtrl->GetValue();
111        if (spinValue < 0 || spinValue > 10)
112                return DisplayError(pSpinCtrl, _("Please enter a number between 0 and 10 for the number of concurrent downloads."));
113
114        pSpinCtrl = XRCCTRL(*this, "ID_NUMUPLOADS", wxSpinCtrl);
115        spinValue = pSpinCtrl->GetValue();
116        if (spinValue < 0 || spinValue > 10)
117                return DisplayError(pSpinCtrl, _("Please enter a number between 0 and 10 for the number of concurrent uploads."));
118
119        pCtrl = XRCCTRL(*this, "ID_DOWNLOADLIMIT", wxTextCtrl);
120        if (!pCtrl->GetValue().ToLong(&tmp) || (tmp < 0))
121        {
122                const wxString unit = CSizeFormat::GetUnitWithBase(CSizeFormat::kilo, 1024);
123                return DisplayError(pCtrl, wxString::Format(_("Please enter a download speed limit greater or equal to 0 %s/s."), unit));
124        }
125
126        pCtrl = XRCCTRL(*this, "ID_UPLOADLIMIT", wxTextCtrl);
127        if (!pCtrl->GetValue().ToLong(&tmp) || (tmp < 0))
128        {
129                const wxString unit = CSizeFormat::GetUnitWithBase(CSizeFormat::kilo, 1024);
130                return DisplayError(pCtrl, wxString::Format(_("Please enter an upload speed limit greater or equal to 0 %s/s."), unit));
131        }
132
133        pCtrl = XRCCTRL(*this, "ID_REPLACE", wxTextCtrl);
134        wxString replace = pCtrl->GetValue();
135#ifdef __WXMSW__
136        if (replace == _T("\\") ||
137                replace == _T("/") ||
138                replace == _T(":") ||
139                replace == _T("*") ||
140                replace == _T("?") ||
141                replace == _T("\"") ||
142                replace == _T("<") ||
143                replace == _T(">") ||
144                replace == _T("|"))
145#else
146        if (replace == _T("/"))
147#endif
148        {
149                return DisplayError(pCtrl, _("You cannot replace an invalid character with another invalid character. Please enter a character that is allowed in filenames."));
150        }
151
152        return true;
153}
Note: See TracBrowser for help on using the repository browser.