Show better bookmark descriptions.
authorAkos Polster <polster@filemon.pipacs.com>
Sat, 21 Aug 2010 23:44:14 +0000 (01:44 +0200)
committerAkos Polster <polster@filemon.pipacs.com>
Sat, 21 Aug 2010 23:44:14 +0000 (01:44 +0200)
bookmarksdialog.cpp
model/book.cpp
model/book.h
model/ncxhandler.h
pkg/changelog
pkg/version.txt

index 38f39a8..555b09f 100644 (file)
@@ -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);
index 6291419..bf29f3a 100644 (file)
@@ -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;
 }
 
index 6e53829..dbc0b71 100644 (file)
@@ -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.
 
index 4afcb35..211252b 100644 (file)
@@ -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);
index ca37058..7b0524e 100644 (file)
@@ -1,3 +1,9 @@
+dorian (0.1.4-1) unstable; urgency=low
+
+  * Show better bookmark descriptions
+
+ -- Akos Polster <akos@pipacs.com>  Sun, 22 Aug 2010 02:00:00 +0200
+
 dorian (0.1.3-1) unstable; urgency=low
 
   * Retrieve book metadata when adding it to library
index b1e80bb..845639e 100644 (file)
@@ -1 +1 @@
-0.1.3
+0.1.4