Update changelog.
[dorian] / bookview.cpp
index 271370e..d960e26 100644 (file)
 #endif
 
 BookView::BookView(QWidget *parent):
-        QWebView(parent), contentIndex(0), mBook(0), restore(true), restorePos(0),
-        loadFinished(false)
+    QWebView(parent), contentIndex(-1), mBook(0),
+    restore(true), restorePos(0), loadFinished(false)
 {
     settings()->setAttribute(QWebSettings::AutoLoadImages, true);
     settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
     settings()->setAttribute(QWebSettings::PluginsEnabled, false);
     settings()->setAttribute(QWebSettings::ZoomTextOnly, true);
-    settings()->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, false);
+    settings()->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls,
+                             false);
     page()->setContentEditable(false);
 
 #if defined(Q_WS_MAEMO_5)
@@ -78,6 +79,7 @@ void BookView::loadContent(int index)
     }
     else {
         loadFinished = false;
+        emit chapterLoadStart(index);
         load(QUrl(contentFile));
     }
     contentIndex = index;
@@ -91,10 +93,12 @@ void BookView::setBook(Book *book)
     if (book != mBook) {
         mBook = book;
         if (book) {
+            contentIndex = -1;
             book->open();
             goToBookmark(book->lastBookmark());
         }
         else {
+            contentIndex = 0;
             setHtml(tr("No book"));
         }
     }
@@ -130,7 +134,11 @@ void BookView::goToBookmark(const Book::Bookmark &bookmark)
     if (mBook) {
         restore = true;
         restorePos = bookmark.pos;
-        loadContent(bookmark.chapter);
+        if (bookmark.chapter != contentIndex) {
+            loadContent(bookmark.chapter);
+        } else {
+            onLoadFinished(true);
+        }
     }
 }
 
@@ -140,6 +148,7 @@ void BookView::onLoadFinished(bool ok)
     loadFinished = true;
     addNavigationBar();
     onSettingsChanged("scheme");
+    emit chapterLoadEnd(contentIndex);
     if (restore) {
         restore = false;
         if (ok && mBook) {
@@ -227,8 +236,9 @@ void BookView::addBookmark()
 
 void BookView::addNavigationBar()
 {
-    QWebFrame *frame = page()->currentFrame();
-    frame->addToJavaScriptWindowObject("bv", this);
+    if (!mBook) {
+        return;
+    }
 
     QString naviPrev =
             "<a href=\"javascript:bv.goPrevious();\">"
@@ -244,7 +254,6 @@ void BookView::addNavigationBar()
             + tmpPath() +
             "/next.png\" />"
             "</a>";
-
     if (contentIndex == 0) {
         naviPrev = "";
     }
@@ -252,6 +261,8 @@ void BookView::addNavigationBar()
         naviNext = "";
     }
 
+    QWebFrame *frame = page()->currentFrame();
+    frame->addToJavaScriptWindowObject("bv", this);
     QString headerScript = "document.body.innerHTML = '" +
         naviPrev + naviNext + "<br />" + "' + document.body.innerHTML;";
     QString trailerScript = "document.body.innerHTML += '<br /><br />" +
@@ -259,8 +270,6 @@ void BookView::addNavigationBar()
 
     frame->evaluateJavaScript(headerScript);
     frame->evaluateJavaScript(trailerScript);
-
-    // qDebug() << page()->currentFrame()->toHtml();
 }
 
 QString BookView::tmpPath()