peer_ttls_ui now initializes wxWidgets further to support localization

This commit is contained in:
Simon Rozman 2016-08-27 17:54:00 +02:00
parent bc1c56174a
commit 9f770bbb3f
3 changed files with 145 additions and 78 deletions

View File

@ -46,28 +46,14 @@ bool wxEventMonitorApp::OnInit()
::MsiUseFeature(_T(PRODUCT_VERSION_GUID), _T("featEventMonitor")); ::MsiUseFeature(_T(PRODUCT_VERSION_GUID), _T("featEventMonitor"));
#endif #endif
wxConfigBase *cfgPrev = wxConfigBase::Set(new wxConfig(wxT(PRODUCT_NAME_STR), wxT(VENDOR_NAME_STR))); wxInitializeConfig();
if (cfgPrev) wxDELETE(cfgPrev);
if (!wxApp::OnInit()) if (!wxApp::OnInit())
return false; return false;
// Set desired locale. if (wxInitializeLocale(m_locale)) {
wxLanguage lang_code; //wxVERIFY(m_locale.AddCatalog(wxT("wxExtend") wxT(wxExtendVersion)));
wxString lang; wxVERIFY(m_locale.AddCatalog(wxT("EventMonitor")));
if (wxConfigBase::Get()->Read(wxT("Language"), &lang)) {
const wxLanguageInfo *lang_info = wxLocale::FindLanguageInfo(lang);
lang_code = lang_info ? (wxLanguage)lang_info->Language : wxLANGUAGE_DEFAULT;
} else
lang_code = wxLANGUAGE_DEFAULT;
if (wxLocale::IsAvailable(lang_code)) {
wxString sPath;
if (wxConfigBase::Get()->Read(wxT("LocalizationRepositoryPath"), &sPath))
m_locale.AddCatalogLookupPathPrefix(sPath);
if (m_locale.Init(lang_code)) {
//wxVERIFY(m_locale.AddCatalog(wxT("wxExtend") wxT(wxExtendVersion)));
wxVERIFY(m_locale.AddCatalog(wxT("EventMonitor")));
}
} }
#ifdef __WXMSW__ #ifdef __WXMSW__

View File

@ -20,6 +20,7 @@
#include <wx/hyperlink.h> #include <wx/hyperlink.h>
#include <wx/icon.h> #include <wx/icon.h>
#include <wx/intl.h>
#include <wx/scrolwin.h> #include <wx/scrolwin.h>
#include <Windows.h> #include <Windows.h>
@ -104,6 +105,17 @@ inline wxIcon wxLoadIconFromResource(HINSTANCE hinst, PCWSTR pszName, const wxSi
/// ///
inline wxString wxEAPGetProviderName(const std::wstring &id); inline wxString wxEAPGetProviderName(const std::wstring &id);
///
/// Initializes wxWidgets application configuration scheme
///
inline void wxInitializeConfig();
///
/// Inizializes wxWidgets localization scheme
///
inline bool wxInitializeLocale(wxLocale &locale);
namespace eap namespace eap
{ {
/// ///
@ -124,6 +136,7 @@ namespace eap
#include <WinStd/Cred.h> #include <WinStd/Cred.h>
#include <WinStd/Win.h> #include <WinStd/Win.h>
#include <wx/config.h>
#include <wx/log.h> #include <wx/log.h>
#include <CommCtrl.h> #include <CommCtrl.h>
@ -826,6 +839,36 @@ inline wxString wxEAPGetProviderName(const std::wstring &id)
} }
inline void wxInitializeConfig()
{
wxConfigBase *cfgPrev = wxConfigBase::Set(new wxConfig(wxT(PRODUCT_NAME_STR), wxT(VENDOR_NAME_STR)));
if (cfgPrev) wxDELETE(cfgPrev);
}
inline bool wxInitializeLocale(wxLocale &locale)
{
// Read language from configuration.
wxLanguage lang_code;
wxString lang;
if (wxConfigBase::Get()->Read(wxT("Language"), &lang)) {
const wxLanguageInfo *lang_info = wxLocale::FindLanguageInfo(lang);
lang_code = lang_info ? (wxLanguage)lang_info->Language : wxLANGUAGE_DEFAULT;
} else
lang_code = wxLANGUAGE_DEFAULT;
if (wxLocale::IsAvailable(lang_code)) {
// Language is "available". Well... Known actually.
wxString sPath;
if (wxConfigBase::Get()->Read(wxT("LocalizationRepositoryPath"), &sPath))
locale.AddCatalogLookupPathPrefix(sPath);
return locale.Init(lang_code);
}
return false;
}
namespace eap namespace eap
{ {
class monitor_ui class monitor_ui

View File

@ -24,6 +24,21 @@ using namespace std;
using namespace winstd; using namespace winstd;
//////////////////////////////////////////////////////////////////////
// wxInitializerPeer
//////////////////////////////////////////////////////////////////////
class wxInitializerPeer
{
public:
wxInitializerPeer(_In_ HINSTANCE instance);
virtual ~wxInitializerPeer();
protected:
wxLocale m_locale; ///< Locale
};
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// eap::peer_ttls_ui // eap::peer_ttls_ui
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@ -104,28 +119,27 @@ void eap::peer_ttls_ui::invoke_config_ui(
cfg.m_providers.push_back(std::move(cfg_provider)); cfg.m_providers.push_back(std::move(cfg_provider));
} }
// Initialize application.
new wxApp();
wxEntryStart(m_instance);
int result; int result;
{ {
// Create wxWidget-approved parent window. // Initialize application.
wxWindow parent; wxInitializerPeer init(m_instance);
parent.SetHWND((WXHWND)(hwndParent ? hwndParent : GetForegroundWindow()));
parent.AdoptAttributesFromHWND();
wxTopLevelWindows.Append(&parent);
// Create and launch configuration dialog. {
wxEAPConfigDialog<wxTTLSConfigWindow> dlg(cfg, &parent); // Create wxWidget-approved parent window.
result = dlg.ShowModal(); wxWindow parent;
parent.SetHWND((WXHWND)(hwndParent ? hwndParent : GetForegroundWindow()));
parent.AdoptAttributesFromHWND();
wxTopLevelWindows.Append(&parent);
wxTopLevelWindows.DeleteObject(&parent); // Create and launch configuration dialog.
parent.SetHWND((WXHWND)NULL); wxEAPConfigDialog<wxTTLSConfigWindow> dlg(cfg, &parent);
result = dlg.ShowModal();
wxTopLevelWindows.DeleteObject(&parent);
parent.SetHWND((WXHWND)NULL);
}
} }
// Clean-up and return.
wxEntryCleanup();
if (result != wxID_OK) if (result != wxID_OK)
throw win_runtime_error(ERROR_CANCELLED, __FUNCTION__ " Cancelled."); throw win_runtime_error(ERROR_CANCELLED, __FUNCTION__ " Cancelled.");
@ -196,61 +210,60 @@ void eap::peer_ttls_ui::invoke_identity_ui(
cfg_method->m_inner->m_allow_save = false; cfg_method->m_inner->m_allow_save = false;
} }
// Initialize application.
new wxApp();
wxEntryStart(m_instance);
int result; int result;
{ {
// Create wxWidget-approved parent window. // Initialize application.
wxWindow parent; wxInitializerPeer init(m_instance);
parent.SetHWND((WXHWND)(hwndParent ? hwndParent : GetForegroundWindow()));
parent.AdoptAttributesFromHWND();
wxTopLevelWindows.Append(&parent);
// Create credentials dialog. {
wxEAPCredentialsDialog dlg(cfg_prov, &parent); // Create wxWidget-approved parent window.
wxTTLSCredentialsPanel *panel = new wxTTLSCredentialsPanel(cfg_prov, *cfg_method, cred_out, cfg_prov.m_id.c_str(), &dlg); wxWindow parent;
dlg.AddContent(panel); parent.SetHWND((WXHWND)(hwndParent ? hwndParent : GetForegroundWindow()));
parent.AdoptAttributesFromHWND();
wxTopLevelWindows.Append(&parent);
// Set "Remember" checkboxes according to credential source, // Create credentials dialog.
panel->m_outer_cred->SetRememberValue(cred_source.first == eap::credentials::source_storage); wxEAPCredentialsDialog dlg(cfg_prov, &parent);
wxPAPCredentialsPanel *panel_inner_cred_pap = dynamic_cast<wxPAPCredentialsPanel*>(panel->m_inner_cred); wxTTLSCredentialsPanel *panel = new wxTTLSCredentialsPanel(cfg_prov, *cfg_method, cred_out, cfg_prov.m_id.c_str(), &dlg);
if (panel_inner_cred_pap) dlg.AddContent(panel);
panel_inner_cred_pap->SetRememberValue(cred_source.second == eap::credentials::source_storage);
// Centre and display dialog. // Set "Remember" checkboxes according to credential source,
dlg.Centre(wxBOTH); panel->m_outer_cred->SetRememberValue(cred_source.first == eap::credentials::source_storage);
result = dlg.ShowModal(); wxPAPCredentialsPanel *panel_inner_cred_pap = dynamic_cast<wxPAPCredentialsPanel*>(panel->m_inner_cred);
if (result == wxID_OK) { if (panel_inner_cred_pap)
// Write credentials to credential manager. panel_inner_cred_pap->SetRememberValue(cred_source.second == eap::credentials::source_storage);
if (panel->m_outer_cred->GetRememberValue()) {
try { // Centre and display dialog.
cred_out.credentials_tls::store(cfg_prov.m_id.c_str()); dlg.Centre(wxBOTH);
} catch (winstd::win_runtime_error &err) { result = dlg.ShowModal();
wxLogError(winstd::tstring_printf(_("Error writing credentials to Credential Manager: %hs (error %u)"), err.what(), err.number()).c_str()); if (result == wxID_OK) {
} catch (...) { // Write credentials to credential manager.
wxLogError(_("Writing credentials failed.")); if (panel->m_outer_cred->GetRememberValue()) {
try {
cred_out.credentials_tls::store(cfg_prov.m_id.c_str());
} catch (winstd::win_runtime_error &err) {
wxLogError(winstd::tstring_printf(_("Error writing credentials to Credential Manager: %hs (error %u)"), err.what(), err.number()).c_str());
} catch (...) {
wxLogError(_("Writing credentials failed."));
}
}
if (panel_inner_cred_pap && panel_inner_cred_pap->GetRememberValue()) {
try {
cred_out.m_inner->store(cfg_prov.m_id.c_str());
} catch (winstd::win_runtime_error &err) {
wxLogError(winstd::tstring_printf(_("Error writing credentials to Credential Manager: %hs (error %u)"), err.what(), err.number()).c_str());
} catch (...) {
wxLogError(_("Writing credentials failed."));
}
} }
} }
if (panel_inner_cred_pap && panel_inner_cred_pap->GetRememberValue()) { wxTopLevelWindows.DeleteObject(&parent);
try { parent.SetHWND((WXHWND)NULL);
cred_out.m_inner->store(cfg_prov.m_id.c_str());
} catch (winstd::win_runtime_error &err) {
wxLogError(winstd::tstring_printf(_("Error writing credentials to Credential Manager: %hs (error %u)"), err.what(), err.number()).c_str());
} catch (...) {
wxLogError(_("Writing credentials failed."));
}
}
} }
wxTopLevelWindows.DeleteObject(&parent);
parent.SetHWND((WXHWND)NULL);
} }
// Clean-up and return.
wxEntryCleanup();
if (result != wxID_OK) if (result != wxID_OK)
throw win_runtime_error(ERROR_CANCELLED, __FUNCTION__ " Cancelled."); throw win_runtime_error(ERROR_CANCELLED, __FUNCTION__ " Cancelled.");
@ -281,3 +294,28 @@ void eap::peer_ttls_ui::invoke_interactive_ui(
InitCommonControls(); InitCommonControls();
MessageBox(hwndParent, _T(PRODUCT_NAME_STR) _T(" interactive UI goes here!"), _T(PRODUCT_NAME_STR) _T(" Prompt"), MB_OK); MessageBox(hwndParent, _T(PRODUCT_NAME_STR) _T(" interactive UI goes here!"), _T(PRODUCT_NAME_STR) _T(" Prompt"), MB_OK);
} }
//////////////////////////////////////////////////////////////////////
// wxInitializerPeer
//////////////////////////////////////////////////////////////////////
wxInitializerPeer::wxInitializerPeer(_In_ HINSTANCE instance)
{
// Initialize application.
new wxApp();
wxEntryStart(instance);
// Do our wxWidgets configuration and localization initialization.
wxInitializeConfig();
if (wxInitializeLocale(m_locale)) {
//m_locale.AddCatalog(wxT("wxExtend") wxT(wxExtendVersion));
m_locale.AddCatalog(wxT("EAPTTLSUI"));
}
}
wxInitializerPeer::~wxInitializerPeer()
{
wxEntryCleanup();
}