Not much progress.
[dorian] / bookview.cpp
index 3003165..840f878 100644 (file)
@@ -25,7 +25,7 @@
 BookView::BookView(QWidget *parent):
     QWebView(parent), contentIndex(-1), mBook(0),
     restorePositionAfterLoad(false), positionAfterLoad(0), loaded(false),
-    contentsHeight(0), decorated(false), scrollerMonitor(-1)
+    contentsHeight(0), scrollerMonitor(-1)
 {
     Trace t("BookView::BookView");
     settings()->setAttribute(QWebSettings::AutoLoadImages, true);
@@ -78,7 +78,6 @@ BookView::BookView(QWidget *parent):
     s->setValue("scheme", s->value("scheme", "default"));
     setBook(0);
 
-    extractIcons();
 #ifdef Q_WS_MAEMO_5
     scroller = property("kineticScroller").value<QAbstractKineticScroller *>();
 #endif
@@ -87,7 +86,6 @@ BookView::BookView(QWidget *parent):
 BookView::~BookView()
 {
     Trace t("BookView::~BookView");
-    removeIcons();
 }
 
 void BookView::loadContent(int index)
@@ -106,7 +104,6 @@ void BookView::loadContent(int index)
     }
     else {
         loaded = false;
-        decorated = false;
         emit partLoadStart(index);
         load(QUrl(contentFile));
     }
@@ -207,7 +204,6 @@ void BookView::onLoadFinished(bool ok)
         return;
     }
     loaded = true;
-    addNavigationBar();
     onSettingsChanged("scheme");
     emit partLoadEnd(contentIndex);
     showProgress();
@@ -297,67 +293,11 @@ void BookView::addBookmark()
     update();
 }
 
-void BookView::addNavigationBar()
-{
-    Trace t("BookView::addNavigationBar");
-    if (!mBook) {
-        return;
-    }
-
-    QString naviPrev =
-            "<a href=\"javascript:bv.goPrevious();\">"
-            "<img width=\"95\" height=\"95\" style=\"float:left;clear:none;\" "
-            "src=\"file://"
-            + tmpPath() +
-            "/previous.png\" />"
-            "</a>";
-    QString naviNext =
-            "<a href=\"javascript:bv.goNext();\">"
-            "<img width=\"95\" height=\"95\" style=\"float:right;clear:none;\" "
-            "src=\"file://"
-            + tmpPath() +
-            "/next.png\" />"
-            "</a>";
-    if (contentIndex == 0) {
-        naviPrev = "";
-    }
-    if (contentIndex >= mBook->parts.size() - 1) {
-        naviNext = "";
-    }
-
-    QWebFrame *frame = page()->currentFrame();
-    QString headerScript = "document.body.innerHTML = '" +
-        naviPrev + naviNext + "<br />" + "' + document.body.innerHTML;";
-    QString trailerScript = "document.body.innerHTML += '<br /><br />" +
-        naviPrev + naviNext + "';";
-
-    frame->evaluateJavaScript(headerScript);
-    frame->evaluateJavaScript(trailerScript);
-    decorated = true;
-}
-
 QString BookView::tmpPath()
 {
     return QDir::tempPath() + "/dorian";
 }
 
-void BookView::extractIcons()
-{
-    QFile next(ICON_PREFIX + QString("/next.png"));
-    QFile prev(ICON_PREFIX + QString("/previous.png"));
-
-    QDir().mkpath(tmpPath());
-    next.copy(tmpPath() + "/next.png");
-    prev.copy(tmpPath() + "/previous.png");
-}
-
-void BookView::removeIcons()
-{
-    QFile(ICON_PREFIX + QString("/next.png")).remove();
-    QFile(ICON_PREFIX + QString("/previous.png")).remove();
-    QDir().rmpath(tmpPath());
-}
-
 bool BookView::eventFilter(QObject *o, QEvent *e)
 {
     if (e->type() != QEvent::Paint && e->type() != QEvent::MouseMove) {
@@ -401,12 +341,10 @@ void BookView::addJavaScriptObjects()
 void BookView::onContentsSizeChanged(const QSize &size)
 {
     contentsHeight = size.height();
-    if (decorated) {
-        if (restorePositionAfterLoad) {
-            qDebug() << "BookView::onContentSizeChanged: Time to restore";
-            restorePositionAfterLoad = false;
-            goToPosition(positionAfterLoad);
-        }
+    if (restorePositionAfterLoad) {
+        qDebug() << "BookView::onContentSizeChanged: Time to restore";
+        restorePositionAfterLoad = false;
+        goToPosition(positionAfterLoad);
     }
 }
 
@@ -484,7 +422,9 @@ void BookView::goPreviousPage()
     frame->scroll(0, -height());
     if (pos == frame->scrollPosition().y()) {
         if (contentIndex > 0) {
-            goToBookmark(Book::Bookmark(contentIndex - 1, 1.0));
+            Book::Bookmark bookmark(contentIndex - 1, 1.0);
+            mBook->setLastBookmark(contentIndex - 1, 1.0);
+            goToBookmark(bookmark);
         }
     } else {
         showProgress();
@@ -500,6 +440,7 @@ void BookView::goNextPage()
     if (pos == frame->scrollPosition().y()) {
         goNext();
     } else {
+        setLastBookmark();
         showProgress();
     }
 }