Parse local files (ingame help) with new html parser

This commit is contained in:
Nimetu 2015-04-13 20:53:10 +03:00
parent 55a3c66c78
commit 6198b7f496
2 changed files with 77 additions and 12 deletions

View file

@ -677,6 +677,12 @@ namespace NLGUI
// read style attribute
void getStyleParams(const std::string &styleString, CStyleParams &style, bool inherit = true);
// load and render local html file (from bnp for example)
void doBrowseLocalFile(const std::string &filename);
// render html string as new browser page
bool renderHtmlString(const std::string &html);
private:
// decode all HTML entities
static ucstring decodeHTMLEntities(const ucstring &str);

View file

@ -3824,6 +3824,10 @@ namespace NLGUI
stopBrowse ();
updateRefreshButton();
// Browsing
_Browsing = true;
updateRefreshButton();
// Home ?
if (_URL == "home")
_URL = home();
@ -3843,17 +3847,24 @@ namespace NLGUI
_Connecting = true;
_ConnectingTimeout = ( times.thisFrameMs / 1000.0f ) + _TimeoutValue;
// Save new url
_URL = finalUrl;
// file is probably from bnp (ingame help)
if (isLocal)
{
if (strlwr(finalUrl).find("file:/") == 0)
{
finalUrl = finalUrl.substr(6, finalUrl.size() - 6);
}
doBrowseLocalFile(finalUrl);
}
else
{
CButtonFreezer freezer;
this->visit(&freezer);
// Browsing
_Browsing = true;
updateRefreshButton();
// Save new url
_URL = finalUrl;
// display HTTP query
//nlinfo("WEB: GET '%s'", finalUrl.c_str());
@ -3869,12 +3880,7 @@ namespace NLGUI
C3WSmartPtr uri = HTParse(finalUrl.c_str(), NULL, PARSE_ALL);
// Create an anchor
#ifdef NL_OS_WINDOWS
if ((_LibWWW->Anchor = HTAnchor_findAddress(uri)) == NULL)
#else
// temporarily disable local URL's until LibWWW can be replaced.
if (isLocal || ((_LibWWW->Anchor = HTAnchor_findAddress(uri)) == NULL))
#endif
{
browseError((string("The page address is malformed : ")+(const char*)uri).c_str());
}
@ -3911,6 +3917,8 @@ namespace NLGUI
}
}
} // !isLocal
_BrowseNextTime = false;
}
@ -4099,6 +4107,57 @@ namespace NLGUI
#endif
}
// ***************************************************************************
void CGroupHTML::doBrowseLocalFile(const std::string &filename)
{
CIFile in;
if (in.open(filename))
{
std::string html;
while(!in.eof())
{
char buf[1024];
in.getline(buf, 1024);
html += std::string(buf) + "\n";
}
in.close();
if (!renderHtmlString(html))
{
browseError((string("Failed to parse html from file : ")+filename).c_str());
}
}
else
{
browseError((string("The page address is malformed : ")+filename).c_str());
}
}
// ***************************************************************************
bool CGroupHTML::renderHtmlString(const std::string &html)
{
bool success;
// clear content
beginBuild();
success = parseHtml(html);
// invalidate coords
endBuild();
// libwww would call requestTerminated() here
_Browsing = false;
if (_TitleString.empty())
{
setTitle(_TitlePrefix);
}
updateRefreshButton();
return success;
}
// ***************************************************************************
void CGroupHTML::draw ()