[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 <lestat.de.lionkur@gmail.com>
This commit is contained in:
Vitalii Koshura 2018-06-03 01:53:52 +03:00
parent 716ebdd9e1
commit 125117f9fc
No known key found for this signature in database
GPG Key ID: CE0DB1726070A5A3
3 changed files with 24 additions and 7 deletions

View File

@ -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", "<br>");
terms_of_use.Replace("\r", "<br>");
terms_of_use.Replace("\n", "<br>");
}
m_pTermsOfUseCtrl->SetPage(terms_of_use);
m_pAgreeCtrl->SetLabel(
_("I agree to the terms of use.")

View File

@ -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

View File

@ -412,6 +412,12 @@ void xml_unescape(char* buf) {
} else if (!strncmp(in, "&amp;", 5)) {
*out++ = '&';
in += 5;
} else if (!strncmp(in, "&#xD;", 5) || !strncmp(in, "&#xd;", 5)) {
*out++ = '\r';
in += 5;
} else if (!strncmp(in, "&#xA;", 5) || !strncmp(in, "&#xa;", 5)) {
*out++ = '\n';
in += 5;
} else if (!strncmp(in, "&#", 2)) {
in += 2;
char c = atoi(in);