if (!mBook) {
return;
}
- if ((index < 0) || (index >= mBook->toc.size())) {
+ if ((index < 0) || (index >= mBook->parts.size())) {
return;
}
- QString contentFile(mBook->content[mBook->toc[index]].href);
- if (mBook->toc[index] == "error") {
+ QString contentFile(mBook->content[mBook->parts[index]].href);
+ if (mBook->parts[index] == "error") {
setHtml(contentFile);
}
else {
if (contentIndex == 0) {
naviPrev = "";
}
- if (contentIndex >= mBook->toc.size() - 1) {
+ if (contentIndex >= mBook->parts.size() - 1) {
naviNext = "";
}
if (index > 0) {
enablePrevious = true;
}
- if (index < (book->toc.size() - 1)) {
+ if (index < (book->parts.size() - 1)) {
enableNext = true;
}
}
Book *book = Library::instance()->book(mCurrent);
if (book) {
- int partIndex = book->tocFromChapter(index);
+ int partIndex = book->partFromChapter(index);
if (partIndex != -1) {
view->goToBookmark(Book::Bookmark(partIndex, 0));
}
Book::Book(const QString &p, QObject *parent): QObject(parent)
{
mPath = "";
- if (p != "") {
+ if (p.size()) {
QFileInfo info(p);
mPath = info.absoluteFilePath();
title = info.baseName();
t.trace(path());
close();
clear();
- if (path() == "") {
+ if (path().isEmpty()) {
title = "No book";
return false;
}
{
Trace t("Book::close");
content.clear();
- toc.clear();
+ parts.clear();
QDir::setCurrent(QDir::rootPath());
clearDir(tmpDir());
}
// Initially, put all content items in the chapter list.
// This will be refined by parsing the NCX file later
- chapters = toc;
+ chapters = parts;
// Load cover image
QStringList coverKeys;
delete source;
}
+ // Calculate book part sizes
+ foreach (QString part, parts) {
+ QFileInfo info(content[part].href);
+ content[part].size = info.size();
+ t.trace(QString("Size of part %1: %2").arg(part).arg(content[part].size));
+ }
+
return ret;
}
QString Book::name() const
{
- if (title != "") {
+ if (title.size()) {
QString ret = title;
if (creators.length()) {
ret += "\nBy " + creators[0];
QString Book::shortName() const
{
- if (title == "") {
- return QFileInfo(path()).baseName();
- } else {
- return title;
- }
+ return (title.isEmpty())? QFileInfo(path()).baseName(): title;
}
-int Book::chapterFromToc(int index)
+int Book::chapterFromPart(int index)
{
+ // FIXME
+ Q_UNUSED(index);
int ret = -1;
return ret;
}
-int Book::tocFromChapter(int index)
+int Book::partFromChapter(int index)
{
- Trace t("Book::tocFromChapter");
+ Trace t("Book::partFromChapter");
QString id = chapters[index];
QString href = content[id].href;
QString baseRef(href);
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;
+ int partIndex = parts.indexOf(contentKey);
+ if (partIndex == -1) {
+ qCritical()
+ << "Book::partFromChapter: Could not find part index of chapter"
+ << id;
}
- return tocIndex;
+ return partIndex;
}
{
QString href;
QString name;
+ qint64 size;
};
/** Bookmark: a volume index and a relative position in volume. */
/** Get short friendly name: title or file name. */
QString shortName() const;
- /** Get chapter index from toc index. */
- int chapterFromToc(int index);
+ /** Get chapter index from part index. */
+ int chapterFromPart(int index);
- /** Get toc index from chapter index. */
- int tocFromChapter(int index);
+ /** Get part index from chapter index. */
+ int partFromChapter(int index);
QString title; //< Book title from EPUB.
- QStringList toc; //< Table of contents from EPUB.
+ QStringList parts; //< EPUB part list.
QHash<QString, ContentItem> content; //< Content items from EPUB.
QImage cover; //< Cover image.
QStringList creators; //< Creators.
/** Extract EPUB as ZIP. */
bool extract();
- /** Parse exteacted EPUB. */
+ /** Parse extracted EPUB. */
bool parse();
/** Clear all book fields except path. */
OpsHandler(Book &b): book(b), partCount(0) {}
bool endDocument() {return true;}
bool endPrefixMapping(const QString &) {return true;}
- QString errorString() const {return "";}
+ QString errorString() const {return QString();}
bool ignorableWhitespace(const QString &) {return true;}
bool processingInstruction(const QString &, const QString &) {
return true;
const QString &qName) {
(void)namespaceUri;
(void)qName;
- if (currentText != "") {
+ if (currentText.size()) {
if (name == "title") {
book.title = currentText;
} else if (name == "creator") {
bool startElement(const QString &namespaceUri, const QString &name,
const QString &qName, const QXmlAttributes &attrs) {
- Trace t("OpsHandler::startElement" + name);
+ Trace t("OpsHandler::startElement " + name);
(void)namespaceUri;
(void)qName;
currentText = "";
Book::ContentItem item;
item.href = book.rootPath() + "/" + attrs.value("href");
item.name = QString("Part %1").arg(partCount + 1);
+ item.size = 0;
QString key = attrs.value("id");
book.content[key] = item;
partCount++;
t.trace(QString("name: ") + item.name);
t.trace(QString("href: ") + attrs.value("href"));
t.trace(QString("id: ") + key);
- }
- else if (name == "itemref") {
+ } else if (name == "itemref") {
t.trace(QString("id: ") + attrs.value("idref"));
- book.toc.append(attrs.value("idref"));
+ book.parts.append(attrs.value("idref"));
}
return true;
}