Skip to content

Commit

Permalink
fix encoding problem when clicking a link on StartPage if application…
Browse files Browse the repository at this point in the history
… is installed into a directory with non-ASCII characters
  • Loading branch information
wwmayer committed Nov 5, 2019
1 parent 0b1b916 commit 5c2b7be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Mod/Web/Gui/BrowserView.cpp
Expand Up @@ -85,6 +85,7 @@

#include <Base/Parameter.h>
#include <Base/Exception.h>
#include <Base/Tools.h>
#include <CXX/Extensions.hxx>

using namespace WebGui;
Expand Down Expand Up @@ -224,7 +225,7 @@ Py::Object BrowserViewPy::setHtml(const Py::Tuple& args)
PyMem_Free(HtmlCode);

if (myWebView)
myWebView->setHtml(QString::fromUtf8(EncodedHtml.c_str()), QUrl(QString::fromLatin1(BaseUrl)));
myWebView->setHtml(QString::fromUtf8(EncodedHtml.c_str()), QUrl(QString::fromUtf8(BaseUrl)));
return Py::None();
}
}
Expand Down Expand Up @@ -439,7 +440,8 @@ BrowserView::BrowserView(QWidget* parent)
connect(view->page(), SIGNAL(iconChanged(const QIcon &)),
this, SLOT(setWindowIcon(const QIcon &)));
#endif

connect(view->page(), SIGNAL(linkHovered(const QString &)),
this, SLOT(onLinkHovered(const QString &)));
connect(view, SIGNAL(viewSource(const QUrl&)),
this, SLOT(onViewSource(const QUrl&)));
connect(view, SIGNAL(loadStarted()),
Expand All @@ -463,6 +465,11 @@ BrowserView::~BrowserView()
delete view;
}

void BrowserView::onLinkHovered(const QString& url)
{
Gui::getMainWindow()->statusBar()->showMessage(url);
}

#ifdef QTWEBENGINE
void BrowserView::urlFilter(const QUrl &url)
#else
Expand Down Expand Up @@ -523,7 +530,12 @@ void BrowserView::onLinkClicked (const QUrl & url)
Gui::Command::doCommand(Gui::Command::Gui,q.toStdString().c_str());
}
// Gui::Command::doCommand(Gui::Command::Gui,"execfile('%s')",(const char*) fi.absoluteFilePath(). toLocal8Bit());
Gui::Command::doCommand(Gui::Command::Gui,"exec(open('%s').read())",(const char*) fi.absoluteFilePath() .toLocal8Bit());
QString filename = Base::Tools::escapeEncodeFilename(fi.absoluteFilePath());
#if PY_MAJOR_VERSION < 3
Gui::Command::doCommand(Gui::Command::Gui,"exec(open(unicode('%s', 'utf-8')).read())",(const char*) filename.toUtf8());
#else
Gui::Command::doCommand(Gui::Command::Gui,"exec(open('%s').read())",(const char*) filename.toUtf8());
#endif
}
catch (const Base::Exception& e) {
QMessageBox::critical(this, tr("Error"), QString::fromUtf8(e.what()));
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Web/Gui/BrowserView.h
Expand Up @@ -119,6 +119,7 @@ protected Q_SLOTS:
void onUnsupportedContent(QNetworkReply* reply);
void onLinkClicked (const QUrl& url);
#endif
void onLinkHovered(const QString& url);
void onViewSource(const QUrl &url);
void onOpenLinkInExternalBrowser(const QUrl& url);
void onOpenLinkInNewWindow(const QUrl&);
Expand Down

0 comments on commit 5c2b7be

Please sign in to comment.