From c117d4284c7128f22fce6dc7ac4a5877eb1a8443 Mon Sep 17 00:00:00 2001 From: Akos Polster Date: Sun, 22 Aug 2010 01:44:14 +0200 Subject: [PATCH] Show better bookmark descriptions. --- bookmarksdialog.cpp | 13 +++++++++---- model/book.cpp | 22 +++++++++++++++++++--- model/book.h | 6 +++--- model/ncxhandler.h | 1 - pkg/changelog | 6 ++++++ pkg/version.txt | 2 +- 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/bookmarksdialog.cpp b/bookmarksdialog.cpp index 38f39a8..555b09f 100644 --- a/bookmarksdialog.cpp +++ b/bookmarksdialog.cpp @@ -20,10 +20,15 @@ BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent): list = new QListWidget(this); list->setSelectionMode(QAbstractItemView::SingleSelection); foreach (Book::Bookmark bookmark, book_->bookmarks()) { - QString contentId = book_->parts[bookmark.part]; - QString contentTitle = book_->content[contentId].name; - (void)new QListWidgetItem(QIcon(":icons/bookmark.png"), contentTitle + - "\nAt " + QString::number((int)(bookmark.pos*100)) + "%", list); + QString label("At "); + label += QString::number((int)(100 * book_-> + getProgress(bookmark.part, bookmark.pos))) + "%"; + int chapterIndex = book_->chapterFromPart(bookmark.part); + if (chapterIndex != -1) { + QString chapterId = book_->chapters[chapterIndex]; + label += "\nIn \"" + book_->content[chapterId].name + "\""; + } + (void)new QListWidgetItem(QIcon(":icons/bookmark.png"), label, list); } horizontalLayout->addWidget(list); diff --git a/model/book.cpp b/model/book.cpp index 6291419..bf29f3a 100644 --- a/model/book.cpp +++ b/model/book.cpp @@ -202,7 +202,6 @@ bool Book::parse() QFileInfo info(content[part].href); content[part].size = info.size(); size += content[part].size; - t.trace(QString("Size of part %1: %2").arg(part).arg(content[part].size)); } return ret; @@ -406,9 +405,26 @@ QString Book::shortName() const int Book::chapterFromPart(int index) { - // FIXME - Q_UNUSED(index); int ret = -1; + + QString partId = parts[index]; + QString partHref = content[partId].href; + + for (int i = 0; i < chapters.size(); i++) { + QString id = chapters[i]; + 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); + } + if (baseRef == partHref) { + ret = i; + // Don't break, keep looking + } + } + return ret; } diff --git a/model/book.h b/model/book.h index 6e53829..dbc0b71 100644 --- a/model/book.h +++ b/model/book.h @@ -16,7 +16,7 @@ class Book: public QObject public: - /** Content item in the table of contents. */ + /** Content item: An individual, named part of the book. */ struct ContentItem { QString href; @@ -116,8 +116,8 @@ public: QString subject; //< Subject. QString source; //< Source. QString rights; //< Rights. - QString tocPath; //< Path to toc ncx. - QString coverPath; //< Path to cover html. + QString tocPath; //< Path to toc NCX file. + QString coverPath; //< Path to cover HTML file. QStringList chapters; //< Main navigation items from EPUB. qint64 size; //< Size of all parts. diff --git a/model/ncxhandler.h b/model/ncxhandler.h index 4afcb35..211252b 100644 --- a/model/ncxhandler.h +++ b/model/ncxhandler.h @@ -35,7 +35,6 @@ public: (void)namespaceUri; (void)qName; if (name == "text") { - t.trace(currentText); contentTitle = currentText; } else if (name == "navPoint") { t.trace(QString("url: ") + contentUrl); diff --git a/pkg/changelog b/pkg/changelog index ca37058..7b0524e 100644 --- a/pkg/changelog +++ b/pkg/changelog @@ -1,3 +1,9 @@ +dorian (0.1.4-1) unstable; urgency=low + + * Show better bookmark descriptions + + -- Akos Polster Sun, 22 Aug 2010 02:00:00 +0200 + dorian (0.1.3-1) unstable; urgency=low * Retrieve book metadata when adding it to library diff --git a/pkg/version.txt b/pkg/version.txt index b1e80bb..845639e 100644 --- a/pkg/version.txt +++ b/pkg/version.txt @@ -1 +1 @@ -0.1.3 +0.1.4 -- 1.7.9.5