wxTTLSConfigPanel: Split to make reusable

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2020-01-15 12:42:54 +01:00
parent bacd4fd8d8
commit 4331de8605
2 changed files with 96 additions and 77 deletions

View File

@ -1,30 +1,28 @@
/* /*
Copyright 2015-2020 Amebis Copyright 2015-2020 Amebis
Copyright 2016 GÉANT Copyright 2016 GÉANT
This file is part of GÉANTLink. This file is part of GÉANTLink.
GÉANTLink is free software: you can redistribute it and/or modify it GÉANTLink is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
GÉANTLink is distributed in the hope that it will be useful, but GÉANTLink is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with GÉANTLink. If not, see <http://www.gnu.org/licenses/>. along with GÉANTLink. If not, see <http://www.gnu.org/licenses/>.
*/ */
class wxTTLSConfigPanel; class wxTLSTunnelConfigWindow;
class wxTTLSConfigWindow; class wxTTLSConfigWindow;
#pragma once #pragma once
#include "../res/wxTTLS_UI.h"
#include "../../TLS_UI/include/TLS_UI.h" #include "../../TLS_UI/include/TLS_UI.h"
#include "../../TTLS/include/Config.h" #include "../../TTLS/include/Config.h"
@ -46,33 +44,45 @@ class wxTTLSConfigWindow;
/// @{ /// @{
/// ///
/// TTLS configuration panel /// TLS tunnel configuration scrollable window
/// ///
class wxTTLSConfigPanel : public wxTTLSConfigPanelBase class wxTLSTunnelConfigWindow : public wxEAPConfigWindow
{ {
public: public:
/// ///
/// Constructs a configuration panel /// Constructs a configuration window
/// ///
wxTTLSConfigPanel(const eap::config_provider &prov, eap::config_method_tls_tunnel &cfg, wxWindow* parent); /// \param[in] prov Provider configuration data
/// \param[inout] cfg Method configuration data
/// \param[in] parent Parent window
///
wxTLSTunnelConfigWindow(eap::config_provider &prov, eap::config_method &cfg, wxWindow* parent);
///
/// Destructs the configuration window
///
virtual ~wxTLSTunnelConfigWindow();
protected: protected:
/// \cond internal /// \cond internal
virtual bool TransferDataToWindow(); virtual bool TransferDataToWindow();
virtual bool TransferDataFromWindow(); virtual void OnInitDialog(wxInitDialogEvent& event);
virtual void OnUpdateUI(wxUpdateUIEvent& event); virtual void OnUpdateUI(wxUpdateUIEvent& event);
/// \endcond /// \endcond
protected: protected:
const eap::config_provider &m_prov; ///< EAP provider wxStaticText *m_outer_title; ///< Outer authentication title
eap::config_method_tls_tunnel &m_cfg; ///< TLS tunnel configuration wxEAPIdentityConfigPanel *m_outer_identity; ///< Outer identity configuration panel
wxPanel *m_tls; ///< TLS configuration panel
wxStaticText *m_inner_title; ///< Inner authentication title
wxChoicebook *m_inner_type; ///< Inner authentication type
}; };
/// ///
/// TTLS configuration scrollable window /// TTLS configuration scrollable window
/// ///
class wxTTLSConfigWindow : public wxEAPConfigWindow class wxTTLSConfigWindow : public wxTLSTunnelConfigWindow
{ {
public: public:
/// ///
@ -84,26 +94,13 @@ public:
/// ///
wxTTLSConfigWindow(eap::config_provider &prov, eap::config_method &cfg, wxWindow* parent); wxTTLSConfigWindow(eap::config_provider &prov, eap::config_method &cfg, wxWindow* parent);
///
/// Destructs the configuration window
///
virtual ~wxTTLSConfigWindow();
protected: protected:
/// \cond internal /// \cond internal
virtual bool TransferDataToWindow(); virtual bool TransferDataToWindow();
virtual bool TransferDataFromWindow(); virtual bool TransferDataFromWindow();
virtual void OnInitDialog(wxInitDialogEvent& event);
virtual void OnUpdateUI(wxUpdateUIEvent& event);
/// \endcond /// \endcond
protected: protected:
wxStaticText *m_outer_title; ///< Outer authentication title
wxTTLSConfigPanel *m_outer_identity; ///< Outer identity configuration panel
wxTLSConfigPanel *m_tls; ///< TLS configuration panel
wxStaticText *m_inner_title; ///< Inner authentication title
wxChoicebook *m_inner_type; ///< Inner authentication type
// Temporary inner method configurations to hold data until applied // Temporary inner method configurations to hold data until applied
eap::config_method_pap m_cfg_pap; ///< PAP configuration eap::config_method_pap m_cfg_pap; ///< PAP configuration
eap::config_method_mschapv2 m_cfg_mschapv2; ///< MSCHAPv2 configuration eap::config_method_mschapv2 m_cfg_mschapv2; ///< MSCHAPv2 configuration

View File

@ -22,17 +22,10 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// wxTTLSConfigWindow // wxTLSTunnelConfigWindow
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
wxTTLSConfigWindow::wxTTLSConfigWindow(eap::config_provider &prov, eap::config_method &cfg, wxWindow* parent) : wxTLSTunnelConfigWindow::wxTLSTunnelConfigWindow(eap::config_provider &prov, eap::config_method &cfg, wxWindow* parent) :
m_cfg_pap (cfg.m_module, cfg.m_level + 1),
m_cfg_mschapv2 (cfg.m_module, cfg.m_level + 1),
m_cfg_eapmschapv2(cfg.m_module, cfg.m_level + 1),
m_cfg_eapgtc (cfg.m_module, cfg.m_level + 1),
#if EAP_INNER_EAPHOST
m_cfg_eaphost (cfg.m_module, cfg.m_level + 1),
#endif
wxEAPConfigWindow(prov, cfg, parent) wxEAPConfigWindow(prov, cfg, parent)
{ {
wxBoxSizer* sb_content; wxBoxSizer* sb_content;
@ -48,18 +41,6 @@ wxTTLSConfigWindow::wxTTLSConfigWindow(eap::config_provider &prov, eap::config_m
m_inner_type = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxCHB_DEFAULT); m_inner_type = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxCHB_DEFAULT);
m_inner_type->SetToolTip( _("Select inner authentication method from the list") ); m_inner_type->SetToolTip( _("Select inner authentication method from the list") );
wxPAPConfigPanel *panel_pap = new wxPAPConfigPanel(m_prov, m_cfg_pap, m_inner_type);
m_inner_type->AddPage(panel_pap, _("PAP"));
wxMSCHAPv2ConfigPanel *panel_mschapv2 = new wxMSCHAPv2ConfigPanel(m_prov, m_cfg_mschapv2, m_inner_type);
m_inner_type->AddPage(panel_mschapv2, _("MSCHAPv2"));
wxMSCHAPv2ConfigPanel *panel_eapmschapv2 = new wxMSCHAPv2ConfigPanel(m_prov, m_cfg_eapmschapv2, m_inner_type);
m_inner_type->AddPage(panel_eapmschapv2, _("EAP-MSCHAPv2"));
wxGTCConfigPanel *panel_eapgtc = new wxGTCConfigPanel(m_prov, m_cfg_eapgtc, m_inner_type);
m_inner_type->AddPage(panel_eapgtc, _("EAP-GTC"));
#if EAP_INNER_EAPHOST
wxEapHostConfigPanel *panel_eaphost = new wxEapHostConfigPanel(m_prov, m_cfg_eaphost, m_inner_type);
m_inner_type->AddPage(panel_eaphost, _("Other EAP methods..."));
#endif
sb_content->Add(m_inner_type, 0, wxALL|wxEXPAND, FromDIP(5)); sb_content->Add(m_inner_type, 0, wxALL|wxEXPAND, FromDIP(5));
sb_content->Add(FromDIP(20), FromDIP(20), 1, wxALL|wxEXPAND, FromDIP(5)); sb_content->Add(FromDIP(20), FromDIP(20), 1, wxALL|wxEXPAND, FromDIP(5));
@ -86,16 +67,77 @@ wxTTLSConfigWindow::wxTTLSConfigWindow(eap::config_provider &prov, eap::config_m
this->SetSizer(sb_content); this->SetSizer(sb_content);
this->Layout(); this->Layout();
// m_inner_type->SetFocusFromKbd(); // This control steals mouse-wheel scrolling for itself this->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxTLSTunnelConfigWindow::OnUpdateUI));
panel_pap->SetFocusFromKbd();
this->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxTTLSConfigWindow::OnUpdateUI));
} }
wxTTLSConfigWindow::~wxTTLSConfigWindow() wxTLSTunnelConfigWindow::~wxTLSTunnelConfigWindow()
{ {
this->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxTTLSConfigWindow::OnUpdateUI)); this->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxTLSTunnelConfigWindow::OnUpdateUI));
}
/// \cond internal
bool wxTLSTunnelConfigWindow::TransferDataToWindow()
{
// Do not invoke inherited TransferDataToWindow(), as it will call others TransferDataToWindow().
// This will handle wxTLSTunnelConfigWindow::OnInitDialog() via wxEVT_INIT_DIALOG forwarding.
return true /*wxEAPConfigWindow::TransferDataToWindow()*/;
}
void wxTLSTunnelConfigWindow::OnInitDialog(wxInitDialogEvent& event)
{
wxEAPConfigWindow::OnInitDialog(event);
// Forward the event to child panels.
m_outer_identity->GetEventHandler()->ProcessEvent(event);
m_tls->GetEventHandler()->ProcessEvent(event);
for (wxWindowList::compatibility_iterator inner = m_inner_type->GetChildren().GetFirst(); inner; inner = inner->GetNext())
inner->GetData()->GetEventHandler()->ProcessEvent(event);
}
void wxTLSTunnelConfigWindow::OnUpdateUI(wxUpdateUIEvent& event)
{
m_inner_type->GetChoiceCtrl()->Enable(!m_prov.m_read_only);
event.Skip();
}
/// \endcond
//////////////////////////////////////////////////////////////////////
// wxTTLSConfigWindow
//////////////////////////////////////////////////////////////////////
wxTTLSConfigWindow::wxTTLSConfigWindow(eap::config_provider &prov, eap::config_method &cfg, wxWindow* parent) :
m_cfg_pap (cfg.m_module, cfg.m_level + 1),
m_cfg_mschapv2 (cfg.m_module, cfg.m_level + 1),
m_cfg_eapmschapv2(cfg.m_module, cfg.m_level + 1),
m_cfg_eapgtc (cfg.m_module, cfg.m_level + 1),
#if EAP_INNER_EAPHOST
m_cfg_eaphost (cfg.m_module, cfg.m_level + 1),
#endif
wxTLSTunnelConfigWindow(prov, cfg, parent)
{
wxPAPConfigPanel *panel_pap = new wxPAPConfigPanel(m_prov, m_cfg_pap, m_inner_type);
m_inner_type->AddPage(panel_pap, _("PAP"));
wxMSCHAPv2ConfigPanel *panel_mschapv2 = new wxMSCHAPv2ConfigPanel(m_prov, m_cfg_mschapv2, m_inner_type);
m_inner_type->AddPage(panel_mschapv2, _("MSCHAPv2"));
wxMSCHAPv2ConfigPanel *panel_eapmschapv2 = new wxMSCHAPv2ConfigPanel(m_prov, m_cfg_eapmschapv2, m_inner_type);
m_inner_type->AddPage(panel_eapmschapv2, _("EAP-MSCHAPv2"));
wxGTCConfigPanel *panel_eapgtc = new wxGTCConfigPanel(m_prov, m_cfg_eapgtc, m_inner_type);
m_inner_type->AddPage(panel_eapgtc, _("EAP-GTC"));
#if EAP_INNER_EAPHOST
wxEapHostConfigPanel *panel_eaphost = new wxEapHostConfigPanel(m_prov, m_cfg_eaphost, m_inner_type);
m_inner_type->AddPage(panel_eaphost, _("Other EAP methods..."));
#endif
// m_inner_type->SetFocusFromKbd(); // This control steals mouse-wheel scrolling for itself
panel_pap->SetFocusFromKbd();
} }
@ -144,7 +186,7 @@ bool wxTTLSConfigWindow::TransferDataToWindow()
bool wxTTLSConfigWindow::TransferDataFromWindow() bool wxTTLSConfigWindow::TransferDataFromWindow()
{ {
wxCHECK(wxScrolledWindow::TransferDataFromWindow(), false); wxCHECK(wxTLSTunnelConfigWindow::TransferDataFromWindow(), false);
auto &cfg_ttls = dynamic_cast<eap::config_method_tls_tunnel&>(m_cfg); auto &cfg_ttls = dynamic_cast<eap::config_method_tls_tunnel&>(m_cfg);
@ -181,24 +223,4 @@ bool wxTTLSConfigWindow::TransferDataFromWindow()
return true; return true;
} }
void wxTTLSConfigWindow::OnInitDialog(wxInitDialogEvent& event)
{
wxEAPConfigWindow::OnInitDialog(event);
// Forward the event to child panels.
m_outer_identity->GetEventHandler()->ProcessEvent(event);
m_tls->GetEventHandler()->ProcessEvent(event);
for (wxWindowList::compatibility_iterator inner = m_inner_type->GetChildren().GetFirst(); inner; inner = inner->GetNext())
inner->GetData()->GetEventHandler()->ProcessEvent(event);
}
void wxTTLSConfigWindow::OnUpdateUI(wxUpdateUIEvent& event)
{
m_inner_type->GetChoiceCtrl()->Enable(!m_prov.m_read_only);
event.Skip();
}
/// \endcond /// \endcond