From 125117f9fc33b37c6665f25be38fb75a7207847b Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Sun, 3 Jun 2018 01:53:52 +0300 Subject: [PATCH] [Manager] Add HTML TOU support to Wizard Terms Of Use can be displayed now as HTML as well as plain text. Fixed xml_unescape function to support escaped \r and \n tags. Enlarged the size of Terms Of Use field to fill all wizard page. Signed-off-by: Vitalii Koshura --- clientgui/TermsOfUsePage.cpp | 23 +++++++++++++++++------ clientgui/TermsOfUsePage.h | 2 +- lib/parse.cpp | 6 ++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/clientgui/TermsOfUsePage.cpp b/clientgui/TermsOfUsePage.cpp index ba7d71e1d7..f4d3a08a50 100644 --- a/clientgui/TermsOfUsePage.cpp +++ b/clientgui/TermsOfUsePage.cpp @@ -103,6 +103,8 @@ bool CTermsOfUsePage::Create( CBOINCBaseWizard* parent ) void CTermsOfUsePage::CreateControls() { +#define TERMSOFUSEWIDTH ADJUSTFORXDPI(580) +#define TERMSOFUSEHEIGHT ADJUSTFORYDPI(250) ////@begin CTermsOfUsePage content construction CTermsOfUsePage* itemWizardPage96 = this; @@ -120,8 +122,8 @@ void CTermsOfUsePage::CreateControls() m_pDirectionsStaticCtrl->Create( itemWizardPage96, wxID_STATIC, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); itemBoxSizer97->Add(m_pDirectionsStaticCtrl, 0, wxALIGN_LEFT|wxALL, 5); - m_pTermsOfUseCtrl = new wxTextCtrl; - m_pTermsOfUseCtrl->Create( itemWizardPage96, ID_TERMSOFUSECTRL, wxEmptyString, wxDefaultPosition, wxSize(300, 125), wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH ); + m_pTermsOfUseCtrl = new wxHtmlWindow; + m_pTermsOfUseCtrl->Create( itemWizardPage96, ID_TERMSOFUSECTRL, wxDefaultPosition, wxSize(TERMSOFUSEWIDTH, TERMSOFUSEHEIGHT), wxHW_SCROLLBAR_AUTO, wxEmptyString); itemBoxSizer97->Add(m_pTermsOfUseCtrl, 0, wxGROW|wxALL, 5); m_pAgreeCtrl = new wxRadioButton; @@ -222,10 +224,19 @@ void CTermsOfUsePage::OnPageChanged( wxWizardExEvent& event ) { _("Please read the following terms of use:") ); - m_pTermsOfUseCtrl->SetValue( - wxString(pc.terms_of_use.c_str(), wxConvUTF8) - ); - m_pTermsOfUseCtrl->SetSelection(0,0); + std::string tou = pc.terms_of_use; + xml_unescape(tou); + wxString terms_of_use(tou.c_str(), wxConvUTF8); + // HTML TOU can have no open/close html tags + // so I see no proper way to identify + // whether it is html or plain text + // and I have to use this dirty hack + if (pc.terms_of_use == tou) { + terms_of_use.Replace("\r\n", "
"); + terms_of_use.Replace("\r", "
"); + terms_of_use.Replace("\n", "
"); + } + m_pTermsOfUseCtrl->SetPage(terms_of_use); m_pAgreeCtrl->SetLabel( _("I agree to the terms of use.") diff --git a/clientgui/TermsOfUsePage.h b/clientgui/TermsOfUsePage.h index 36ae0aba34..1492a979c0 100644 --- a/clientgui/TermsOfUsePage.h +++ b/clientgui/TermsOfUsePage.h @@ -87,7 +87,7 @@ public: ////@begin CTermsOfUsePage member variables wxStaticText* m_pTitleStaticCtrl; wxStaticText* m_pDirectionsStaticCtrl; - wxTextCtrl* m_pTermsOfUseCtrl; + wxHtmlWindow* m_pTermsOfUseCtrl; wxRadioButton* m_pAgreeCtrl; wxRadioButton* m_pDisagreeCtrl; ////@end CTermsOfUsePage member variables diff --git a/lib/parse.cpp b/lib/parse.cpp index c856cd8661..db38e00e1b 100644 --- a/lib/parse.cpp +++ b/lib/parse.cpp @@ -412,6 +412,12 @@ void xml_unescape(char* buf) { } else if (!strncmp(in, "&", 5)) { *out++ = '&'; in += 5; + } else if (!strncmp(in, " ", 5) || !strncmp(in, " ", 5)) { + *out++ = '\r'; + in += 5; + } else if (!strncmp(in, " ", 5) || !strncmp(in, " ", 5)) { + *out++ = '\n'; + in += 5; } else if (!strncmp(in, "&#", 2)) { in += 2; char c = atoi(in);