GEANTLink/lib/GTC_UI/src/GTC_UI.cpp
Simon Rozman a2cab07a30 WinStd: Update
Signed-off-by: Simon Rozman <simon@rozman.si>
2022-03-03 18:02:31 +01:00

153 lines
4.9 KiB
C++

/*
SPDX-License-Identifier: GPL-3.0-or-later
Copyright © 2015-2022 Amebis
Copyright © 2016 GÉANT
*/
#include "PCH.h"
//////////////////////////////////////////////////////////////////////
// wxGTCConfigPanel
//////////////////////////////////////////////////////////////////////
wxGTCConfigPanel::wxGTCConfigPanel(const eap::config_provider &prov, eap::config_method_eapgtc &cfg, wxWindow* parent) :
m_prov (prov ),
m_cfg (cfg ),
m_cfg_resp(cfg.m_module, cfg.m_level),
m_cfg_pass(cfg.m_module, cfg.m_level),
wxGTCConfigPanelBase(parent)
{
// Initialize Password authentication mode properly. Challenge/Response mode does not require initialization, since it is initialized so by default.
m_cfg_pass.m_cred.reset(new eap::credentials_pass(m_cfg.m_module));
m_credentials_resp = new wxGTCResponseCredentialsConfigPanel(m_prov, m_cfg_resp, m_auth_mode);
m_auth_mode->AddPage(m_credentials_resp, _("Challenge/Response"));
m_credentials_pass = new wxGTCPasswordCredentialsConfigPanel(m_prov, m_cfg_pass, m_auth_mode);
m_auth_mode->AddPage(m_credentials_pass, _("Password"));
}
/// \cond internal
bool wxGTCConfigPanel::TransferDataToWindow()
{
eap::credentials_identity *cred_resp;
eap::credentials_pass *cred_pass;
if ((cred_resp = dynamic_cast<eap::credentials_identity*>(m_cfg.m_cred.get())) != NULL) {
m_cfg_resp = m_cfg;
m_auth_mode->SetSelection(0); // 0=Challenge/Response
} else if ((cred_pass = dynamic_cast<eap::credentials_pass*>(m_cfg.m_cred.get())) != NULL) {
m_cfg_pass = m_cfg;
m_auth_mode->SetSelection(1); // 1=Password
} else
wxFAIL_MSG(wxT("Unsupported authentication mode."));
return wxGTCConfigPanelBase::TransferDataToWindow();
}
bool wxGTCConfigPanel::TransferDataFromWindow()
{
wxCHECK(wxGTCConfigPanelBase::TransferDataFromWindow(), false);
if (!m_prov.m_read_only) {
// This is not a provider-locked configuration. Save the data.
switch (m_auth_mode->GetSelection()) {
case 0: // 0=Challenge/Response
m_cfg = m_cfg_resp;
break;
case 1: // 1=Password
m_cfg = m_cfg_pass;
break;
default:
wxFAIL_MSG(wxT("Unsupported authentication mode."));
}
}
return true;
}
void wxGTCConfigPanel::OnUpdateUI(wxUpdateUIEvent& event)
{
UNREFERENCED_PARAMETER(event);
if (m_prov.m_read_only) {
// This is provider-locked configuration. Disable controls.
m_auth_mode_label ->Enable(false);
m_auth_mode ->Enable(false);
m_credentials_resp->Enable(false);
m_credentials_pass->Enable(false);
} else {
// This is not a provider-locked configuration. Enable controls.
m_auth_mode_label ->Enable(true);
m_auth_mode ->Enable(true);
m_credentials_resp->Enable(true);
m_credentials_pass ->Enable(true);
}
}
/// \endcond
//////////////////////////////////////////////////////////////////////
// wxGTCResponseDialog
//////////////////////////////////////////////////////////////////////
wxGTCResponseDialog::wxGTCResponseDialog(const eap::config_provider &prov, wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos, const wxSize &size, long style) :
wxEAPGeneralDialog(parent, id, title, pos, size, style)
{
// Set banner title.
m_banner->m_title->SetLabel(wxString::Format(_("%s Challenge"), wxEAPGetProviderName(prov.m_name)));
}
//////////////////////////////////////////////////////////////////////
// wxGTCResponsePanel
//////////////////////////////////////////////////////////////////////
wxGTCResponsePanel::wxGTCResponsePanel(winstd::sanitizing_wstring &response, const wchar_t *challenge, wxWindow* parent) :
wxGTCResponsePanelBase(parent),
m_response_value(response)
{
// Load and set icon.
winstd::library lib_shell32(LoadLibraryEx(_T("shell32.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE));
if (!!lib_shell32)
m_response_icon->SetIcon(wxLoadIconFromResource(lib_shell32, MAKEINTRESOURCE(24)));
// Set challenge label.
m_challenge->SetLabelText(challenge);
m_challenge->Wrap(FromDIP(200));
// Response must not be empty.
m_response->SetValidator(wxTextValidator(wxFILTER_EMPTY));
this->Layout();
}
/// \cond internal
bool wxGTCResponsePanel::TransferDataToWindow()
{
m_response->SetValue(m_response_value.c_str());
return wxGTCResponsePanelBase::TransferDataToWindow();
}
bool wxGTCResponsePanel::TransferDataFromWindow()
{
wxCHECK(wxGTCResponsePanelBase::TransferDataFromWindow(), false);
m_response_value = m_response->GetValue();
return true;
}
/// \endcond