mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-20 16:08:44 +00:00
Parse local files (ingame help) with new html parser
--HG-- branch : libxml2-html-parser
This commit is contained in:
parent
1dc48143f3
commit
d1d0c0cf50
2 changed files with 77 additions and 12 deletions
|
@ -677,6 +677,12 @@ namespace NLGUI
|
||||||
// read style attribute
|
// read style attribute
|
||||||
void getStyleParams(const std::string &styleString, CStyleParams &style, bool inherit = true);
|
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:
|
private:
|
||||||
// decode all HTML entities
|
// decode all HTML entities
|
||||||
static ucstring decodeHTMLEntities(const ucstring &str);
|
static ucstring decodeHTMLEntities(const ucstring &str);
|
||||||
|
|
|
@ -3824,6 +3824,10 @@ namespace NLGUI
|
||||||
stopBrowse ();
|
stopBrowse ();
|
||||||
updateRefreshButton();
|
updateRefreshButton();
|
||||||
|
|
||||||
|
// Browsing
|
||||||
|
_Browsing = true;
|
||||||
|
updateRefreshButton();
|
||||||
|
|
||||||
// Home ?
|
// Home ?
|
||||||
if (_URL == "home")
|
if (_URL == "home")
|
||||||
_URL = home();
|
_URL = home();
|
||||||
|
@ -3843,17 +3847,24 @@ namespace NLGUI
|
||||||
_Connecting = true;
|
_Connecting = true;
|
||||||
_ConnectingTimeout = ( times.thisFrameMs / 1000.0f ) + _TimeoutValue;
|
_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;
|
CButtonFreezer freezer;
|
||||||
this->visit(&freezer);
|
this->visit(&freezer);
|
||||||
|
|
||||||
// Browsing
|
|
||||||
_Browsing = true;
|
|
||||||
updateRefreshButton();
|
|
||||||
|
|
||||||
// Save new url
|
|
||||||
_URL = finalUrl;
|
|
||||||
|
|
||||||
// display HTTP query
|
// display HTTP query
|
||||||
//nlinfo("WEB: GET '%s'", finalUrl.c_str());
|
//nlinfo("WEB: GET '%s'", finalUrl.c_str());
|
||||||
|
|
||||||
|
@ -3869,12 +3880,7 @@ namespace NLGUI
|
||||||
C3WSmartPtr uri = HTParse(finalUrl.c_str(), NULL, PARSE_ALL);
|
C3WSmartPtr uri = HTParse(finalUrl.c_str(), NULL, PARSE_ALL);
|
||||||
|
|
||||||
// Create an anchor
|
// Create an anchor
|
||||||
#ifdef NL_OS_WINDOWS
|
|
||||||
if ((_LibWWW->Anchor = HTAnchor_findAddress(uri)) == NULL)
|
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());
|
browseError((string("The page address is malformed : ")+(const char*)uri).c_str());
|
||||||
}
|
}
|
||||||
|
@ -3911,6 +3917,8 @@ namespace NLGUI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // !isLocal
|
||||||
|
|
||||||
_BrowseNextTime = false;
|
_BrowseNextTime = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4099,6 +4107,57 @@ namespace NLGUI
|
||||||
#endif
|
#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 ()
|
void CGroupHTML::draw ()
|
||||||
|
|
Loading…
Reference in a new issue