From: Stefan Bund Date: Wed, 11 Apr 2012 16:58:26 +0000 (+0200) Subject: implement _pykit.canGoBack / _pykit.canGoForward X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=bd2ccd69f3c9fc5c4e7238ec379cfb8fc505dee3;p=pykit.git implement _pykit.canGoBack / _pykit.canGoForward --- diff --git a/PythonPublisher.cc b/PythonPublisher.cc index f944b6d..f84b8da 100644 --- a/PythonPublisher.cc +++ b/PythonPublisher.cc @@ -14,6 +14,8 @@ #include #include "Publisher.hh" #include +#include +#include "Viewer.hh" //#include "PythonPublisher.mpp" #define prefix_ @@ -419,6 +421,20 @@ BOOST_PYTHON_MODULE(_qt) ; } +namespace { + + bool canGoBack() + { + return pykit::Viewer::instance()->page()->history()->canGoBack(); + } + + bool canGoForward() + { + return pykit::Viewer::instance()->page()->history()->canGoForward(); + } + +} + BOOST_PYTHON_MODULE(_pykit) { py::class_("Request", py::no_init) @@ -439,6 +455,9 @@ BOOST_PYTHON_MODULE(_pykit) ; py::def("openUrl", &QDesktopServices::openUrl); + + py::def("canGoBack", &canGoBack); + py::def("canGoForward", &canGoForward); } PYTHON_EXTERN_MODULE(_httpapi); diff --git a/Viewer.cc b/Viewer.cc index 0076481..89b0335 100644 --- a/Viewer.cc +++ b/Viewer.cc @@ -94,9 +94,14 @@ prefix_ QList PDFWebPluginFactory::plugins() /////////////////////////////////////////////////////////////////////////// // pykit::Viewer +namespace { + pykit::Viewer * instance_ (0); +} + prefix_ pykit::Viewer::Viewer(QUrl const & url, Publisher * publisher, QWidget * parent) : QWebView (parent) { + instance_ = this; QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true); if (! QWebSettings::globalSettings()->testAttribute(QWebSettings::DeveloperExtrasEnabled)) setContextMenuPolicy(Qt::NoContextMenu); @@ -111,6 +116,11 @@ prefix_ pykit::Viewer::Viewer(QUrl const & url, Publisher * publisher, QWidget * inspector_->setPage(page()); } +prefix_ pykit::Viewer * pykit::Viewer::instance() +{ + return instance_; +} + prefix_ pykit::Viewer::~Viewer() { if (inspector_) diff --git a/Viewer.hh b/Viewer.hh index e7bed7a..445d894 100644 --- a/Viewer.hh +++ b/Viewer.hh @@ -30,6 +30,8 @@ namespace pykit { Viewer(QUrl const & url, Publisher * publisher, QWidget * parent = 0); ~Viewer(); + static Viewer * instance(); + private slots: void printRequested();