source: filezilla/trunk/fuentes/src/interface/settings/optionspage_connection_active.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: 3.9 KB
Line 
1#include <filezilla.h>
2#include "../Options.h"
3#include "settingsdialog.h"
4#include "optionspage.h"
5#include "optionspage_connection_active.h"
6
7#include <libfilezilla/iputils.hpp>
8
9BEGIN_EVENT_TABLE(COptionsPageConnectionActive, COptionsPage)
10EVT_CHECKBOX(XRCID("ID_LIMITPORTS"), COptionsPageConnectionActive::OnRadioOrCheckEvent)
11EVT_RADIOBUTTON(XRCID("ID_ACTIVEMODE1"), COptionsPageConnectionActive::OnRadioOrCheckEvent)
12EVT_RADIOBUTTON(XRCID("ID_ACTIVEMODE2"), COptionsPageConnectionActive::OnRadioOrCheckEvent)
13EVT_RADIOBUTTON(XRCID("ID_ACTIVEMODE3"), COptionsPageConnectionActive::OnRadioOrCheckEvent)
14END_EVENT_TABLE()
15
16bool COptionsPageConnectionActive::LoadPage()
17{
18        bool failure = false;
19        SetCheckFromOption(XRCID("ID_LIMITPORTS"), OPTION_LIMITPORTS, failure);
20        SetTextFromOption(XRCID("ID_LOWESTPORT"), OPTION_LIMITPORTS_LOW, failure);
21        SetTextFromOption(XRCID("ID_HIGHESTPORT"), OPTION_LIMITPORTS_HIGH, failure);
22
23        SetRCheck(XRCID("ID_ACTIVEMODE1"), m_pOptions->GetOptionVal(OPTION_EXTERNALIPMODE) == 0, failure);
24        SetRCheck(XRCID("ID_ACTIVEMODE2"), m_pOptions->GetOptionVal(OPTION_EXTERNALIPMODE) == 1, failure);
25        SetRCheck(XRCID("ID_ACTIVEMODE3"), m_pOptions->GetOptionVal(OPTION_EXTERNALIPMODE) == 2, failure);
26
27        SetTextFromOption(XRCID("ID_ACTIVEIP"), OPTION_EXTERNALIP, failure);
28        SetTextFromOption(XRCID("ID_ACTIVERESOLVER"), OPTION_EXTERNALIPRESOLVER, failure);
29        SetCheckFromOption(XRCID("ID_NOEXTERNALONLOCAL"), OPTION_NOEXTERNALONLOCAL, failure);
30
31        if (!failure)
32                SetCtrlState();
33
34        return !failure;
35}
36
37bool COptionsPageConnectionActive::SavePage()
38{
39        SetOptionFromCheck(XRCID("ID_LIMITPORTS"), OPTION_LIMITPORTS);
40
41        SetIntOptionFromText(XRCID("ID_LOWESTPORT"), OPTION_LIMITPORTS_LOW);
42        SetIntOptionFromText(XRCID("ID_HIGHESTPORT"), OPTION_LIMITPORTS_HIGH);
43
44        int mode;
45        if (GetRCheck(XRCID("ID_ACTIVEMODE1")))
46                mode = 0;
47        else
48                mode = GetRCheck(XRCID("ID_ACTIVEMODE2")) ? 1 : 2;
49        m_pOptions->SetOption(OPTION_EXTERNALIPMODE, mode);
50
51        if (mode == 1)
52                SetOptionFromText(XRCID("ID_ACTIVEIP"), OPTION_EXTERNALIP);
53        else if (mode == 2)
54                SetOptionFromText(XRCID("ID_ACTIVERESOLVER"), OPTION_EXTERNALIPRESOLVER);
55        SetOptionFromCheck(XRCID("ID_NOEXTERNALONLOCAL"), OPTION_NOEXTERNALONLOCAL);
56
57        return true;
58}
59
60bool COptionsPageConnectionActive::Validate()
61{
62        // Validate port limiting settings
63        if (GetCheck(XRCID("ID_LIMITPORTS")))
64        {
65                wxTextCtrl* pLow = XRCCTRL(*this, "ID_LOWESTPORT", wxTextCtrl);
66
67                long low;
68                if (!pLow->GetValue().ToLong(&low) || low < 1024 || low > 65535)
69                        return DisplayError(pLow, _("Lowest available port has to be a number between 1024 and 65535."));
70
71                wxTextCtrl* pHigh = XRCCTRL(*this, "ID_LOWESTPORT", wxTextCtrl);
72
73                long high;
74                if (!pHigh->GetValue().ToLong(&high) || high < 1024 || high > 65535)
75                        return DisplayError(pHigh, _("Highest available port has to be a number between 1024 and 65535."));
76
77                if (low > high)
78                        return DisplayError(pLow, _("The lowest available port has to be less or equal than the highest available port."));
79        }
80
81        int mode;
82        if (GetRCheck(XRCID("ID_ACTIVEMODE1")))
83                mode = 0;
84        else
85                mode = GetRCheck(XRCID("ID_ACTIVEMODE2")) ? 1 : 2;
86
87        if (mode == 1) {
88                wxTextCtrl* pActiveIP = XRCCTRL(*this, "ID_ACTIVEIP", wxTextCtrl);
89                wxString const ip = pActiveIP->GetValue();
90                if (fz::get_address_type(ip.ToStdWstring()) != fz::address_type::ipv4) {
91                        return DisplayError(pActiveIP, _("You have to enter a valid IPv4 address."));
92                }
93        }
94
95        return true;
96}
97
98void COptionsPageConnectionActive::SetCtrlState()
99{
100        FindWindow(XRCID("ID_LOWESTPORT"))->Enable(GetCheck(XRCID("ID_LIMITPORTS")));
101        FindWindow(XRCID("ID_HIGHESTPORT"))->Enable(GetCheck(XRCID("ID_LIMITPORTS")));
102
103        int mode;
104        if (GetRCheck(XRCID("ID_ACTIVEMODE1")))
105                mode = 0;
106        else
107                mode = GetRCheck(XRCID("ID_ACTIVEMODE2")) ? 1 : 2;
108        FindWindow(XRCID("ID_ACTIVEIP"))->Enable(mode == 1);
109        FindWindow(XRCID("ID_ACTIVERESOLVER"))->Enable(mode == 2);
110
111        FindWindow(XRCID("ID_NOEXTERNALONLOCAL"))->Enable(mode != 0);
112}
113
114void COptionsPageConnectionActive::OnRadioOrCheckEvent(wxCommandEvent&)
115{
116        SetCtrlState();
117}
Note: See TracBrowser for help on using the repository browser.