Don't reload volume if bookmark is in the same volume.
authorAkos Polster <polster@marzipan.pipacs.com>
Sat, 17 Jul 2010 18:46:14 +0000 (20:46 +0200)
committerAkos Polster <polster@marzipan.pipacs.com>
Sat, 17 Jul 2010 18:46:14 +0000 (20:46 +0200)
TODO.txt
book.cpp
book.h
bookmarksdialog.cpp
bookmarksdialog.h
bookview.cpp
bookview.h
pkg/changelog

index e299010..ae2c05a 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -1,7 +1,10 @@
+To dos migrated to Maemo Garage:
+https://garage.maemo.org/tracker/?group_id=1757 . Old to dos below are kept as
+historical artifacts.
+
 To Do
 -----
 
-2010-05-29 Submit to extras-devel
 2010-06-09 Table of contents
 2010-06-09 Symbian installable package
 2010-06-12 Smooth transitions to fullscreen and back
@@ -9,7 +12,6 @@ To Do
 2010-06-19 Notes
 2010-06-20 Improve bookmark manager: Delete bookmarks
 2010-06-24 Add support for Project Gutenberg chapter navigation
-2010-06-24 Sort bookmarks by chapter/percent
 2010-06-28 Mac installable package
 2010-06-28 Mac icon, application menu
 2010-07-09 Direct access to Project Gutenberg and epubbooks.com library
@@ -19,6 +21,14 @@ To Do
 Done
 ----
 
+0.0.9
+
+2010-07013 2010-06-24 Sort bookmarks by chapter/percent
+
+0.0.6
+
+2010-07-11 2010-05-29 Submit to extras-devel
+
 0.0.5
 
 2010-07-10 2010-07-10 Show navigation arrows only when needed
index 31c4136..497ec75 100644 (file)
--- a/book.cpp
+++ b/book.cpp
@@ -5,6 +5,7 @@
 #include <qtextdocument.h>  // Qt::escape is currently defined here...
 #include <QDirIterator>
 #include <QFileInfo>
+#include <QtAlgorithms>
 
 #include "book.h"
 #include "opshandler.h"
@@ -263,6 +264,7 @@ Book::Bookmark Book::lastBookmark() const
 void Book::addBookmark(int chapter, qreal position)
 {
     mBookmarks.append(Bookmark(chapter, position));
+    qSort(mBookmarks.begin(), mBookmarks.end());
     save();
 }
 
diff --git a/book.h b/book.h
index b3e5e43..5d3c393 100644 (file)
--- a/book.h
+++ b/book.h
@@ -18,13 +18,20 @@ public:
         QString type;
     };
 
-    /** Bookmark: a chapter index and a relative position in chapter. */
+    /** Bookmark: a volume index and a relative position in volume. */
     struct Bookmark
     {
         Bookmark(int chapter_, qreal pos_): chapter(chapter_), pos(pos_) {}
         Bookmark() {chapter = pos = 0;}
         int chapter;
         qreal pos;
+        bool operator<(const Bookmark&other) const {
+            if (chapter != other.chapter) {
+                return chapter < other.chapter;
+            } else {
+                return pos < other.pos;
+            }
+        }
     };
 
     /** Construct a book from an EPUB file in path. */
index 8ecc115..9594bbd 100644 (file)
@@ -15,7 +15,7 @@ BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent):
     list = new QListWidget(this);
     list->setSelectionMode(QAbstractItemView::SingleSelection);
     foreach (Book::Bookmark bookmark, book_->bookmarks()) {
-        list->addItem("Chapter " + QString::number(bookmark.chapter) + ", at " +
+        list->addItem("Volume " + QString::number(bookmark.chapter + 1) + ", at " +
                       QString::number((int)(bookmark.pos * 100)) + "%");
     }
 
index e879b24..9d07e47 100644 (file)
@@ -7,6 +7,7 @@ class Book;
 class QListWidget;
 class QListWidgetItem;
 
+/** Dialog box managing bookmarks. */
 class BookmarksDialog: public QDialog
 {
     Q_OBJECT
index 12626e8..a490f8c 100644 (file)
@@ -17,7 +17,7 @@
 #endif
 
 BookView::BookView(QWidget *parent):
-        QWebView(parent), contentIndex(0), mBook(0), restore(true), restorePos(0),
+        QWebView(parent), contentIndex(-1), mBook(0), restore(true), restorePos(0),
         loadFinished(false)
 {
     settings()->setAttribute(QWebSettings::AutoLoadImages, true);
@@ -91,10 +91,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 +132,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);
+        }
     }
 }
 
index bb32698..f67d1f2 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "book.h"
 
+/** Visual representation of a book. */
 class BookView: public QWebView
 {
     Q_OBJECT
index 29342d4..5f0710f 100644 (file)
@@ -3,6 +3,8 @@ dorian (0.0.9-1) unstable; urgency=low
   * Optify Maemo package
   * Better dialogs on Mac
   * Make returning from full screen mode more obvious
+  * Keep bookmarks sorted
+  * Don't reload volume if the bookmark is in the same volume
 
  -- Akos Polster <akos@pipacs.com>  Fri, 16 Jul 2010 20:00:00 +0200