fix unicode issue on tab of StartPage

This commit is contained in:
wmayer
2019-03-10 11:03:45 +01:00
parent ba6092502c
commit c1c5dd9bb4
2 changed files with 21 additions and 7 deletions

View File

@@ -44,6 +44,7 @@
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Interpreter.h>
#include <Base/Tools.h>
#include <Mod/Start/App/StartConfiguration.h>
@@ -71,6 +72,7 @@ void StartGui::Workbench::activated()
try {
QByteArray utf8Title = title.toUtf8();
std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(utf8Title);
QByteArray cmd;
QTextStream str(&cmd);
str << "import WebGui,sys,Start" << endl;
@@ -78,7 +80,7 @@ void StartGui::Workbench::activated()
str << endl;
str << "class WebPage(object):" << endl;
str << " def __init__(self):" << endl;
str << " self.browser=WebGui.openBrowserWindow('" << utf8Title << "')" << endl;
str << " self.browser=WebGui.openBrowserWindow(u'" << escapedstr.c_str() << "')" << endl;
#if defined(FC_OS_WIN32)
str << " self.browser.setHtml(StartPage.handle(), App.getResourceDir() + 'Mod/Start/StartPage/')" << endl;
#else

View File

@@ -91,15 +91,21 @@ private:
{
const char* HtmlCode;
const char* BaseUrl;
const char* TabName = "Browser";
if (! PyArg_ParseTuple(args.ptr(), "ss|s",&HtmlCode,&BaseUrl,&TabName))
char* TabName = nullptr;
if (! PyArg_ParseTuple(args.ptr(), "ss|et", &HtmlCode, &BaseUrl, "utf-8", &TabName))
throw Py::Exception();
std::string EncodedName = "Browser";
if (TabName) {
EncodedName = std::string(TabName);
PyMem_Free(TabName);
}
WebGui::BrowserView* pcBrowserView = 0;
pcBrowserView = new WebGui::BrowserView(Gui::getMainWindow());
pcBrowserView->resize(400, 300);
pcBrowserView->setHtml(QString::fromUtf8(HtmlCode),QUrl(QString::fromLatin1(BaseUrl)));
pcBrowserView->setWindowTitle(QString::fromUtf8(TabName));
pcBrowserView->setWindowTitle(QString::fromUtf8(EncodedName.c_str()));
Gui::getMainWindow()->addWindow(pcBrowserView);
if (!Gui::getMainWindow()->activeWindow())
Gui::getMainWindow()->setActiveWindow(pcBrowserView);
@@ -109,14 +115,20 @@ private:
Py::Object openBrowserWindow(const Py::Tuple& args)
{
const char* TabName = "Browser";
if (! PyArg_ParseTuple(args.ptr(), "|s",&TabName))
char* TabName = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "|et", "utf-8", &TabName))
throw Py::Exception();
std::string EncodedName = "Browser";
if (TabName) {
EncodedName = std::string(TabName);
PyMem_Free(TabName);
}
WebGui::BrowserView* pcBrowserView = 0;
pcBrowserView = new WebGui::BrowserView(Gui::getMainWindow());
pcBrowserView->resize(400, 300);
pcBrowserView->setWindowTitle(QString::fromUtf8(TabName));
pcBrowserView->setWindowTitle(QString::fromUtf8(EncodedName.c_str()));
Gui::getMainWindow()->addWindow(pcBrowserView);
if (!Gui::getMainWindow()->activeWindow())
Gui::getMainWindow()->setActiveWindow(pcBrowserView);