implement _pykit.canGoBack / _pykit.canGoForward
Stefan Bund [Wed, 11 Apr 2012 16:58:26 +0000 (18:58 +0200)]
PythonPublisher.cc
Viewer.cc
Viewer.hh

index f944b6d..f84b8da 100644 (file)
@@ -14,6 +14,8 @@
 #include <boost/python.hpp>
 #include "Publisher.hh"
 #include <QDesktopServices>
+#include <QWebHistory>
+#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_<pykit::Request>("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);
index 0076481..89b0335 100644 (file)
--- a/Viewer.cc
+++ b/Viewer.cc
@@ -94,9 +94,14 @@ prefix_ QList<QWebPluginFactory::Plugin> 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_)
index e7bed7a..445d894 100644 (file)
--- 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();