More naming fixes.
authorAkos Polster <polster@marzipan.pipacs.com>
Sat, 7 Aug 2010 19:56:40 +0000 (21:56 +0200)
committerAkos Polster <polster@marzipan.pipacs.com>
Sat, 7 Aug 2010 19:56:40 +0000 (21:56 +0200)
bookview.cpp
mainwindow.cpp
model/book.cpp
model/book.h
model/opshandler.h

index 9c2ed9e..3dd9e24 100644 (file)
@@ -88,12 +88,12 @@ void BookView::loadContent(int index)
     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 {
@@ -294,7 +294,7 @@ void BookView::addNavigationBar()
     if (contentIndex == 0) {
         naviPrev = "";
     }
-    if (contentIndex >= mBook->toc.size() - 1) {
+    if (contentIndex >= mBook->parts.size() - 1) {
         naviNext = "";
     }
 
index b43f326..47319f1 100755 (executable)
@@ -300,7 +300,7 @@ void MainWindow::onPartLoadEnd(int index)
         if (index > 0) {
             enablePrevious = true;
         }
-        if (index < (book->toc.size() - 1)) {
+        if (index < (book->parts.size() - 1)) {
             enableNext = true;
         }
     }
@@ -346,7 +346,7 @@ void MainWindow::onGoToChapter(int index)
 
     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));
         }
index a11d3d3..fdf8ccb 100644 (file)
@@ -22,7 +22,7 @@ const int COVER_HEIGHT = 59;
 Book::Book(const QString &p, QObject *parent): QObject(parent)
 {
     mPath = "";
-    if (p != "") {
+    if (p.size()) {
         QFileInfo info(p);
         mPath = info.absoluteFilePath();
         title = info.baseName();
@@ -43,7 +43,7 @@ bool Book::open()
     t.trace(path());
     close();
     clear();
-    if (path() == "") {
+    if (path().isEmpty()) {
         title = "No book";
         return false;
     }
@@ -62,7 +62,7 @@ void Book::close()
 {
     Trace t("Book::close");
     content.clear();
-    toc.clear();
+    parts.clear();
     QDir::setCurrent(QDir::rootPath());
     clearDir(tmpDir());
 }
@@ -138,7 +138,7 @@ bool Book::parse()
 
     // 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;
@@ -170,6 +170,13 @@ bool Book::parse()
         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;
 }
 
@@ -352,7 +359,7 @@ QString Book::rootPath() const
 
 QString Book::name() const
 {
-    if (title != "") {
+    if (title.size()) {
         QString ret = title;
         if (creators.length()) {
             ret += "\nBy " + creators[0];
@@ -368,22 +375,20 @@ QString Book::name() const
 
 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);
@@ -411,10 +416,11 @@ int Book::tocFromChapter(int index)
         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;
 }
index 060fbb4..e6a13c1 100644 (file)
@@ -20,6 +20,7 @@ public:
     {
         QString href;
         QString name;
+        qint64 size;
     };
 
     /** Bookmark: a volume index and a relative position in volume. */
@@ -91,14 +92,14 @@ public:
     /** 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.
@@ -120,7 +121,7 @@ protected:
     /** Extract EPUB as ZIP. */
     bool extract();
 
-    /** Parse exteacted EPUB. */
+    /** Parse extracted EPUB. */
     bool parse();
 
     /** Clear all book fields except path. */
index e27f766..92d9943 100644 (file)
@@ -13,7 +13,7 @@ public:
     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;
@@ -32,7 +32,7 @@ public:
                     const QString &qName) {
         (void)namespaceUri;
         (void)qName;
-        if (currentText != "") {
+        if (currentText.size()) {
             if (name == "title") {
                 book.title = currentText;
             } else if (name == "creator") {
@@ -52,7 +52,7 @@ public:
 
     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 = "";
@@ -61,16 +61,16 @@ public:
             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;
     }