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);
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);
else {
loaded = false;
decorated = false;
- emit chapterLoadStart(index);
+ emit partLoadStart(index);
load(QUrl(contentFile));
}
contentIndex = index;
{
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);
}
loaded = true;
addNavigationBar();
onSettingsChanged("scheme");
- emit chapterLoadEnd(contentIndex);
+ emit partLoadEnd(contentIndex);
}
void BookView::onSettingsChanged(const QString &key)
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;
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();
/** Remove extracted icons. */
void removeIcons();
- /** Load given chapter. */
+ /** Load given part. */
void loadContent(int index);
/** Decorate web page frame with navigation icons. */
/** 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. */
#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);
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)
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();
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
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);
// 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));
}
}
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);
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();
}
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();
}
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;
+}
/** 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);
}
};
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);
/** 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.
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