source: filezilla/trunk/fuentes/src/interface/settings/optionspage_connection_active.cpp @ 130

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

First release to xenial

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