Fix naming: book parts vs. chapters.
authorAkos Polster <polster@marzipan.pipacs.com>
Sat, 7 Aug 2010 12:11:46 +0000 (14:11 +0200)
committerAkos Polster <polster@marzipan.pipacs.com>
Sat, 7 Aug 2010 12:11:46 +0000 (14:11 +0200)
bookmarkinfodialog.cpp
bookmarksdialog.cpp
bookview.cpp
bookview.h
mainwindow.cpp
mainwindow.h
model/book.cpp
model/book.h
pkg/changelog

index ca21963..f3a9d5d 100644 (file)
@@ -11,7 +11,7 @@ BookmarkInfoDialog::BookmarkInfoDialog(Book *b, int i, QWidget *parent):
     setWindowTitle(tr("Bookmark Details"));
 
     Book::Bookmark bookmark = book->bookmarks()[index];
-    QString contentId = book->toc[bookmark.chapter];
+    QString contentId = book->toc[bookmark.part];
     QString contentTitle = book->content[contentId].name;
     QLabel *info = new QLabel(contentTitle + "\nAt " +
         QString::number((int)(bookmark.pos*100)) + "%", this);
index 033c8c4..498ec07 100644 (file)
@@ -20,7 +20,7 @@ BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent):
     list = new QListWidget(this);
     list->setSelectionMode(QAbstractItemView::SingleSelection);
     foreach (Book::Bookmark bookmark, book_->bookmarks()) {
-        QString contentId = book_->toc[bookmark.chapter];
+        QString contentId = book_->toc[bookmark.part];
         QString contentTitle = book_->content[contentId].name;
         (void)new QListWidgetItem(QIcon(":icons/bookmark.png"), contentTitle +
             "\nAt " + QString::number((int)(bookmark.pos*100)) + "%", list);
index c28bc87..9c2ed9e 100644 (file)
@@ -99,7 +99,7 @@ void BookView::loadContent(int index)
     else {
         loaded = false;
         decorated = false;
-        emit chapterLoadStart(index);
+        emit partLoadStart(index);
         load(QUrl(contentFile));
     }
     contentIndex = index;
@@ -173,12 +173,12 @@ void BookView::goToBookmark(const Book::Bookmark &bookmark)
 {
     Trace t("BookView::goToBookmark");
     if (mBook) {
-        if (bookmark.chapter != contentIndex) {
-            t.trace(QString("Loading new chapter %1").arg(bookmark.chapter));
-            mBook->setLastBookmark(bookmark.chapter, bookmark.pos);
+        if (bookmark.part != contentIndex) {
+            t.trace(QString("Loading new part %1").arg(bookmark.part));
+            mBook->setLastBookmark(bookmark.part, bookmark.pos);
             restorePositionAfterLoad = true;
             positionAfterLoad = bookmark.pos;
-            loadContent(bookmark.chapter);
+            loadContent(bookmark.part);
         } else {
             goToPosition(bookmark.pos);
         }
@@ -195,7 +195,7 @@ void BookView::onLoadFinished(bool ok)
     loaded = true;
     addNavigationBar();
     onSettingsChanged("scheme");
-    emit chapterLoadEnd(contentIndex);
+    emit partLoadEnd(contentIndex);
 }
 
 void BookView::onSettingsChanged(const QString &key)
@@ -235,7 +235,7 @@ void BookView::paintEvent(QPaintEvent *e)
     QPixmap bookmarkPixmap = QPixmap::fromImage(bookmarkImage);
     QPainter painter(this);
     foreach (Book::Bookmark b, mBook->bookmarks()) {
-        if (b.chapter != contentIndex) {
+        if (b.part != contentIndex) {
             continue;
         }
         int height = contentsHeight;
index 66422d7..ee7cfc2 100644 (file)
@@ -27,8 +27,8 @@ public:
     void restoreLastBookmark();
 
 signals:
-    void chapterLoadStart(int index);
-    void chapterLoadEnd(int index);
+    void partLoadStart(int index);
+    void partLoadEnd(int index);
 
     /** Signal button press when the real event has been suppressed. */
     void suppressedMouseButtonPress();
@@ -59,7 +59,7 @@ private:
     /** Remove extracted icons. */
     void removeIcons();
 
-    /** Load given chapter. */
+    /** Load given part. */
     void loadContent(int index);
 
     /** Decorate web page frame with navigation icons. */
@@ -68,10 +68,10 @@ private:
     /** Get temporary directory for extracting book contents. */
     QString tmpPath();
 
-    /** Go to a given (relative) position in current chapter. */
+    /** Go to a given (relative) position in current part. */
     void goToPosition(qreal position);
 
-    int contentIndex;   /**< Current chapter in book. */
+    int contentIndex;   /**< Current part in book. */
     Book *mBook;        /**< Book to show. */
     bool restorePositionAfterLoad;
                         /**< If true, restoring position after load is needed. */
index b8956da..b43f326 100755 (executable)
@@ -282,17 +282,17 @@ void MainWindow::onSettingsChanged(const QString &key)
 #endif // Q_WS_MAEMO_5
 }
 
-void MainWindow::onChapterLoadStart()
+void MainWindow::onPartLoadStart()
 {
-    Trace t("MainWindow::onChapterLoadStart");
+    Trace t("MainWindow::onPartLoadStart");
 #ifdef Q_WS_MAEMO_5
     setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
 #endif
 }
 
-void MainWindow::onChapterLoadEnd(int index)
+void MainWindow::onPartLoadEnd(int index)
 {
-    Trace t("MainWindow::onChapterLoadEnd");
+    Trace t("MainWindow::onPartLoadEnd");
     bool enablePrevious = false;
     bool enableNext = false;
     Book *book = Library::instance()->book(mCurrent);
@@ -345,45 +345,12 @@ void MainWindow::onGoToChapter(int index)
     Trace t("MainWindow::onGoToChapter");
 
     Book *book = Library::instance()->book(mCurrent);
-    if (!book) {
-        t.trace("No current book?");
-        return;
-    }
-
-    QString id = book->chapters[index];
-    QString href = book->content[id].href;
-    QString baseRef(href);
-    QUrl url(QString("file://") + href);
-    if (url.hasFragment()) {
-        QString fragment = url.fragment();
-        baseRef.chop(fragment.length() + 1);
-    }
-
-    // Swipe through all content items to find the one matching the chapter href
-    // FIXME: Do we need to index content items by href, too?
-    QString contentKey;
-    bool found = false;
-    foreach (contentKey, book->content.keys()) {
-        if (contentKey == id) {
-            continue;
-        }
-        if (book->content[contentKey].href == baseRef) {
-            found = true;
-            t.trace(QString("Key for %1 is %2").arg(baseRef).arg(contentKey));
-            break;
+    if (book) {
+        int partIndex = book->tocFromChapter(index);
+        if (partIndex != -1) {
+            view->goToBookmark(Book::Bookmark(partIndex, 0));
         }
     }
-    if (!found) {
-        t.trace("Could not find key for " + baseRef);
-        return;
-    }
-
-    int tocIndex = book->toc.indexOf(contentKey);
-    if (tocIndex != -1) {
-        view->goToBookmark(Book::Bookmark(tocIndex, 0));
-    } else {
-        qCritical() << "Could not find toc index of chapter" << id;
-    }
 }
 
 void MainWindow::timerEvent(QTimerEvent *event)
index c44599e..53cb276 100755 (executable)
@@ -29,8 +29,8 @@ public slots:
     void showRegular();
     void showBig();
     void onSettingsChanged(const QString &key);
-    void onChapterLoadStart();
-    void onChapterLoadEnd(int index);
+    void onPartLoadStart();
+    void onPartLoadEnd(int index);
     void onAddBookmark();
     void onGoToBookmark(int index);
     void showChapters();
index dab120c..a11d3d3 100644 (file)
@@ -137,7 +137,7 @@ bool Book::parse()
     delete source;
 
     // Initially, put all content items in the chapter list.
-    // This can be refined by parsing the NCX file later
+    // This will be refined by parsing the NCX file later
     chapters = toc;
 
     // Load cover image
@@ -234,7 +234,7 @@ void Book::load()
     subject = settings.value(key + "subject").toString();
     source = settings.value(key + "source").toString();
     rights = settings.value(key + "rights").toString();
-    mLastBookmark.chapter = settings.value(key + "lastchapter").toInt();
+    mLastBookmark.part = settings.value(key + "lastpart").toInt();
     mLastBookmark.pos = settings.value(key + "lastpos").toReal();
     cover = settings.value(key + "cover").value<QImage>().scaled(COVER_WIDTH,
         COVER_HEIGHT, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
@@ -247,13 +247,13 @@ void Book::load()
     // Load bookmarks
     int size = settings.value(key + "bookmarks").toInt();
     for (int i = 0; i < size; i++) {
-        int chapter = settings.value(key + "bookmark" + QString::number(i) +
-                                     "/chapter").toInt();
+        int part = settings.value(key + "bookmark" + QString::number(i) +
+                                     "/part").toInt();
         qreal pos = settings.value(key + "bookmark" + QString::number(i) +
                                    "/pos").toReal();
-        t.trace(QString("Bookmark %1 at chapter %2, %3").
-                arg(i).arg(chapter).arg(pos));
-        mBookmarks.append(Bookmark(chapter, pos));
+        t.trace(QString("Bookmark %1 at part %2, %3").
+                arg(i).arg(part).arg(pos));
+        mBookmarks.append(Bookmark(part, pos));
     }
 }
 
@@ -274,7 +274,7 @@ void Book::save()
     settings.setValue(key + "subject", subject);
     settings.setValue(key + "source", source);
     settings.setValue(key + "rights", rights);
-    settings.setValue(key + "lastchapter", mLastBookmark.chapter);
+    settings.setValue(key + "lastpart", mLastBookmark.part);
     settings.setValue(key + "lastpos", mLastBookmark.pos);
     settings.setValue(key + "cover", cover);
 
@@ -282,17 +282,17 @@ void Book::save()
     settings.setValue(key + "bookmarks", mBookmarks.size());
     for (int i = 0; i < mBookmarks.size(); i++) {
         t.trace(QString("Bookmark %1 at %2, %3").
-                arg(i).arg(mBookmarks[i].chapter).arg(mBookmarks[i].pos));
-        settings.setValue(key + "bookmark" + QString::number(i) + "/chapter",
-                          mBookmarks[i].chapter);
+                arg(i).arg(mBookmarks[i].part).arg(mBookmarks[i].pos));
+        settings.setValue(key + "bookmark" + QString::number(i) + "/part",
+                          mBookmarks[i].part);
         settings.setValue(key + "bookmark" + QString::number(i) + "/pos",
                           mBookmarks[i].pos);
     }
 }
 
-void Book::setLastBookmark(int chapter, qreal position)
+void Book::setLastBookmark(int part, qreal position)
 {
-    mLastBookmark.chapter = chapter;
+    mLastBookmark.part = part;
     mLastBookmark.pos = position;
     save();
 }
@@ -302,9 +302,9 @@ Book::Bookmark Book::lastBookmark() const
     return Book::Bookmark(mLastBookmark);
 }
 
-void Book::addBookmark(int chapter, qreal position)
+void Book::addBookmark(int part, qreal position)
 {
-    mBookmarks.append(Bookmark(chapter, position));
+    mBookmarks.append(Bookmark(part, position));
     qSort(mBookmarks.begin(), mBookmarks.end());
     save();
 }
@@ -374,3 +374,47 @@ QString Book::shortName() const
         return title;
     }
 }
+
+int Book::chapterFromToc(int index)
+{
+    int ret = -1;
+    return ret;
+}
+
+int Book::tocFromChapter(int index)
+{
+    Trace t("Book::tocFromChapter");
+    QString id = chapters[index];
+    QString href = content[id].href;
+    QString baseRef(href);
+    QUrl url(QString("file://") + href);
+    if (url.hasFragment()) {
+        QString fragment = url.fragment();
+        baseRef.chop(fragment.length() + 1);
+    }
+
+    // Swipe through all content items to find the one matching the chapter href
+    // FIXME: Do we need to index content items by href, too?
+    QString contentKey;
+    bool found = false;
+    foreach (contentKey, content.keys()) {
+        if (contentKey == id) {
+            continue;
+        }
+        if (content[contentKey].href == baseRef) {
+            found = true;
+            t.trace(QString("Key for %1 is %2").arg(baseRef).arg(contentKey));
+            break;
+        }
+    }
+    if (!found) {
+        t.trace("Could not find key for " + baseRef);
+        return -1;
+    }
+    int tocIndex = toc.indexOf(contentKey);
+    if (tocIndex == -1) {
+        qCritical() << "Book::tocFromChapter: Could not find toc index of chapter"
+                << id;
+    }
+    return tocIndex;
+}
index ddf1403..060fbb4 100644 (file)
@@ -25,16 +25,12 @@ public:
     /** 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;
+        Bookmark(int part_, qreal pos_): part(part_), pos(pos_) {}
+        Bookmark() {part = pos = 0;}
+        int part;
         qreal pos;
         bool operator<(const Bookmark&other) const {
-            if (chapter != other.chapter) {
-                return chapter < other.chapter;
-            } else {
-                return pos < other.pos;
-            }
+            return (part == other.part)? (pos < other.pos): (part < other.part);
         }
     };
 
@@ -72,13 +68,13 @@ public:
     bool clearDir(const QString &directory);
 
     /** Set last bookmark. */
-    void setLastBookmark(int chapter, qreal position);
+    void setLastBookmark(int part, qreal position);
 
     /** Get last bookmark. */
     Bookmark lastBookmark() const;
 
     /** Add bookmark. */
-    void addBookmark(int chapter, qreal position);
+    void addBookmark(int part, qreal position);
 
     /** Delete bookmark. */
     void deleteBookmark(int index);
@@ -95,6 +91,12 @@ public:
     /** Get short friendly name: title or file name. */
     QString shortName() const;
 
+    /** Get chapter index from toc index. */
+    int chapterFromToc(int index);
+
+    /** Get toc index from chapter index. */
+    int tocFromChapter(int index);
+
     QString title;                          //< Book title from EPUB.
     QStringList toc;                        //< Table of contents from EPUB.
     QHash<QString, ContentItem> content;    //< Content items from EPUB.
index 8c657d6..b13d588 100644 (file)
@@ -1,6 +1,7 @@
 dorian (0.1.2-1) unstable; urgency=low
 
   * Improve cover image display
+  * Fix naming: book parts vs. chapters
 
  -- Akos Polster <akos@pipacs.com>  Sat,  7 Aug 2010 20:00:00 +0200