From: Stefan Bund Date: Wed, 11 Apr 2012 20:44:27 +0000 (+0200) Subject: add 'view' global JS object to main frame X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=7145998e867dd31df2de6641b3c0323c59189154;p=pykit.git add 'view' global JS object to main frame --- diff --git a/Viewer.cc b/Viewer.cc index 89b0335..03e8452 100644 --- a/Viewer.cc +++ b/Viewer.cc @@ -19,6 +19,8 @@ #include #include #include +#include +#include //#include "Viewer.mpp" #define prefix_ @@ -114,6 +116,15 @@ prefix_ pykit::Viewer::Viewer(QUrl const & url, Publisher * publisher, QWidget * load(url); inspector_ = new QWebInspector(); inspector_->setPage(page()); + connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), + this, SLOT(initJSObjects())); + initJSObjects(); +} + +prefix_ pykit::Viewer::~Viewer() +{ + if (inspector_) + delete inspector_; } prefix_ pykit::Viewer * pykit::Viewer::instance() @@ -121,10 +132,19 @@ prefix_ pykit::Viewer * pykit::Viewer::instance() return instance_; } -prefix_ pykit::Viewer::~Viewer() +prefix_ bool pykit::Viewer::canGoBack() { - if (inspector_) - delete inspector_; + return page()->history()->canGoBack(); +} + +prefix_ bool pykit::Viewer::canGoForward() +{ + return page()->history()->canGoForward(); +} + +prefix_ void pykit::Viewer::initJSObjects() +{ + page()->mainFrame()->addToJavaScriptWindowObject("view", this); } prefix_ void pykit::Viewer::printRequested() diff --git a/Viewer.hh b/Viewer.hh index 445d894..ff99a3f 100644 --- a/Viewer.hh +++ b/Viewer.hh @@ -32,7 +32,11 @@ namespace pykit { static Viewer * instance(); + Q_INVOKABLE bool canGoBack(); + Q_INVOKABLE bool canGoForward(); + private slots: + void initJSObjects(); void printRequested(); private: