#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
// Restore previous reading position
if (bookView) {
- QTimer::singleShot(230, bookView, SLOT(restoreLastBookmark()));
+ bookView->scheduleRestoreLastBookmark();
}
#endif // defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
}
{
TRACE;
+ // Create timer for scheduling restores
+ restoreTimer = new QTimer(this);
+
// Set up web view defaults
settings()->setAttribute(QWebSettings::AutoLoadImages, true);
settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
{
TRACE;
- // Save position in current book
+ // Bail out if new book is the same as current book
+ if (book == mBook) {
+ return;
+ }
+
+ // Save reading position of current book
setLastBookmark();
- // Open new book, restore last position
- if (book != mBook) {
- mBook = book;
- if (book) {
- contentIndex = -1;
- if (book->open()) {
- restoreLastBookmark();
- } else {
- mBook = 0;
- contentIndex = 0;
- setHtml(tr("Failed to open book"));
- }
- }
- else {
- contentIndex = 0;
- setHtml(tr("No book"));
- }
+ // Set new book as the current book
+ mBook = book;
+
+ // Bail out if new book is null
+ if (!book) {
+ contentIndex = 0;
+ setHtml(tr("No book"));
+ return;
+ }
+
+ // Open new book
+ if (book->open()) {
+ // Restore last reading position - this will force
+ // a reload as well
+ contentIndex = -1;
+ restoreLastBookmark();
+ } else {
+ mBook = 0;
+ contentIndex = 0;
+ setHtml(tr("Failed to open book"));
}
}
qDebug() << QString("At %1 (%2%, height %3)").
arg(pos).arg((qreal)pos / (qreal)height * 100).arg(height);
mBook->setLastBookmark(contentIndex, (qreal)pos / (qreal)height, fast);
+ } else {
+ qDebug() << "(no book)";
}
}
onSettingsChanged("scheme");
onSettingsChanged("zoom");
onSettingsChanged("font");
+ scheduleRestoreAfterLoad();
+}
- QTimer::singleShot(210, this, SLOT(restoreAfterLoad()));
+void BookView::scheduleRestoreAfterLoad()
+{
+ TRACE;
+ if (restoreTimer->isActive()) {
+ // Ignore request if a restore is already in progress
+ return;
+ }
+
+ disconnect(restoreTimer, SIGNAL(timeout()), this, 0);
+ connect(restoreTimer, SIGNAL(timeout()), this, SLOT(restoreAfterLoad()));
+ restoreTimer->setSingleShot(true);
+ restoreTimer->start(210);
+}
+
+void BookView::scheduleRestoreLastBookmark()
+{
+ TRACE;
+ if (restoreTimer->isActive()) {
+ // Ignore request if a restore is already in progress
+ return;
+ }
+
+ disconnect(restoreTimer, SIGNAL(timeout()), this, 0);
+ connect(restoreTimer, SIGNAL(timeout()), this,
+ SLOT(restoreLastBookmark()));
+ restoreTimer->setSingleShot(true);
+ restoreTimer->start(210);
}
void BookView::restoreAfterLoad()
void BookView::addJavaScriptObjects()
{
+ TRACE;
page()->mainFrame()->addToJavaScriptWindowObject("bv", this);
}
void BookView::goToPosition(qreal position)
{
+ TRACE;
int contentsHeight = page()->mainFrame()->contentsSize().height();
int scrollPos = (int)((qreal)contentsHeight * position);
page()->mainFrame()->setScrollPosition(QPoint(0, scrollPos));
class QAbstractKineticScroller;
class ProgressDialog;
class FlickCharm;
+class QTimer;
/** Visual representation of a book. */
class BookView: public QWebView
/** If grab is true, volume keys will generate act as page up/down. */
void grabVolumeKeys(bool grab);
+ /** Schedule restoring last reading position after loading part. */
+ void scheduleRestoreAfterLoad();
+
+ /** Schedule restoring last reading position. */
+ void scheduleRestoreLastBookmark();
+
signals:
/** Part loading started. */
void partLoadStart(int index);
/** Go to next page. */
void goNextPage();
- /** Restore saved position after URL loading finished. */
+protected slots:
+ /** Restore last reading position after part loading finished. */
void restoreAfterLoad();
- /** Restore book's last reading position. */
+ /** Restore book's last reading position, load new part if needed. */
void restoreLastBookmark();
-protected slots:
#ifdef Q_OS_SYMBIAN
/** Observe media keys. */
void onMediaKeysPressed(MediaKeysObserver::MediaKeys key);
void showProgress();
private:
- int contentIndex; /**< Current part in book. */
- Book *mBook; /**< Book to show. */
+ int contentIndex; /**< Current part in book. */
+ Book *mBook; /**< Book to show. */
bool restorePositionAfterLoad;
- /**< If true, restore current position after load. */
- qreal positionAfterLoad;/**< Position to be restored after load. */
+ /**< If true, restore reading position after load. */
+ qreal positionAfterLoad;
+ /**< Position to be restored after load. */
bool restoreFragmentAfterLoad;
- /**< If true, restore fragment location after load. */
+ /**< If true, restore fragment location after load. */
QString fragmentAfterLoad;
- /**< Fragment location to be restored after load. */
- QImage bookmarkImage; /**< Bookmark icon pre-loaded. */
- bool loaded; /**< True, if content has been loaded. */
- bool mousePressed; /**< Event filter's mouse button state. */
- bool grabbingVolumeKeys;/**< True, if volume keys should be grabbed. */
+ /**< Fragment location to be restored after load. */
+ QImage bookmarkImage;
+ /**< Bookmark icon pre-loaded. */
+ bool loaded; /**< True, if content has been loaded. */
+ bool mousePressed; /**< Event filter's mouse button state. */
+ bool grabbingVolumeKeys;
+ /**< True, if volume keys should be grabbed. */
+ QTimer *restoreTimer;
+ /**< Single timer for scheduling all restore ops. */
#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
- int scrollerMonitor; /**< ID of timer monitoring kinetic scroll. */
+ int scrollerMonitor;/**< ID of timer monitoring kinetic scroll. */
#endif
#if defined(Q_WS_MAEMO_5)
#endif
#if defined(Q_OS_SYMBIAN)
- FlickCharm *charm; /**< Kinetic scroller. */
+ FlickCharm *charm; /**< Kinetic scroller. */
#endif
};
TRACE;
Library *library = Library::instance();
+ // Show in regular (non full-screen) mode
+ showRegular();
+
// Upgrade library if needed, then load it
library->upgrade();
library->load();
library->setNowReading(sorted.mapToSource(sorted.index(0, 0)));
}
}
-
- // Show in regular (non full-screen) mode
- showRegular();
}
void MainWindow::onCurrentBookChanged()
fullScreenWindow->hide();
show();
- view->restoreLastBookmark();
+ view->scheduleRestoreLastBookmark();
}
void MainWindow::showBig()
hide();
#endif
fullScreenWindow->showFullScreen();
- view->restoreLastBookmark();
+ view->scheduleRestoreLastBookmark();
}
void MainWindow::setCurrentBook(const QModelIndex ¤t)