From e336d3f1aa732a21a997a2be0711cf0aaa280e52 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 10 Mar 2019 11:03:45 +0100 Subject: [PATCH] fix unicode issue on tab of StartPage --- src/Mod/Start/Gui/Workbench.cpp | 4 +++- src/Mod/Web/Gui/AppWebGui.cpp | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Mod/Start/Gui/Workbench.cpp b/src/Mod/Start/Gui/Workbench.cpp index 6a8b492e8e..4d4a9752ee 100644 --- a/src/Mod/Start/Gui/Workbench.cpp +++ b/src/Mod/Start/Gui/Workbench.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include @@ -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 diff --git a/src/Mod/Web/Gui/AppWebGui.cpp b/src/Mod/Web/Gui/AppWebGui.cpp index c91327a967..8901e04957 100644 --- a/src/Mod/Web/Gui/AppWebGui.cpp +++ b/src/Mod/Web/Gui/AppWebGui.cpp @@ -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);