Merge branch 'master' of https://vcs.maemo.org/git/dorian
authorAkos Polster <akos@pipacs.com>
Wed, 3 Nov 2010 17:18:44 +0000 (18:18 +0100)
committerAkos Polster <akos@pipacs.com>
Wed, 3 Nov 2010 17:18:44 +0000 (18:18 +0100)
model/ncxhandler.h
pkg/changelog

index 8d5947f..1585942 100644 (file)
@@ -9,24 +9,68 @@
 class NcxHandler: public XmlHandler
 {
 public:
-    NcxHandler(Book &b): book(b) {
+    struct TreeItem
+    {
+        TreeItem(const QString &i, TreeItem *p = 0): id(i), parent(p) {
+            if (parent) {
+                parent->children.append(this);
+                depth = parent->depth + 1;
+            } else {
+                depth = 0;
+            }
+        }
+        ~TreeItem() {
+            qDeleteAll(children);
+        }
+        void addToBook(Book &book) {
+            Book::ContentItem contentItem;
+            contentItem.href = href;
+            contentItem.name = QString(" ").repeated(depth) + name;
+            contentItem.size = 0;
+            book.content[id] = contentItem;
+            book.chapters.append(id);
+            qDebug() << "" << id << "name" << name << "href" << href;
+            foreach (TreeItem *child, children) {
+                child->addToBook(book);
+            }
+        }
+        QList<TreeItem *> children;
+        QString id;
+        QString href;
+        QString name;
+        TreeItem *parent;
+        int depth;
+    };
+
+    NcxHandler(Book &b): book(b), rootItem(0), currentItem(0) {
         book.chapters.clear();
     }
 
+    ~NcxHandler() {
+        delete rootItem;
+    }
+
     bool endElement(const QString &namespaceUri, const QString &name,
                     const QString &qName) {
         (void)namespaceUri;
         (void)qName;
         if (name == "text") {
-            contentTitle = currentText;
+            if (currentItem) {
+                if (currentItem) {
+                    currentItem->name = currentText;
+                }
+            }
         } else if (name == "navPoint") {
-            qDebug() << "NcxHander::endElement: url" << contentUrl << "title"
-                    << contentTitle << "id" << contentId;
-            Book::ContentItem item;
-            item.href = contentUrl;
-            item.name = contentTitle;
-            book.content[contentId] = item;
-            book.chapters.append(contentId);
+            if (currentItem) {
+                qDebug() << "NcxHandler::endElement  " << currentItem->id;
+                currentItem = currentItem->parent;
+                if (currentItem == 0) {
+                    qDebug() << " Root item reached, dumping tree";
+                    rootItem->addToBook(book);
+                    delete rootItem;
+                    rootItem = 0;
+                }
+            }
         }
         return true;
     }
@@ -37,9 +81,16 @@ public:
         (void)qName;
         currentText = "";
         if (name == "navPoint") {
-            contentId = attrs.value("id");
+            TreeItem *item = new TreeItem(attrs.value("id"), currentItem);
+            qDebug() << "NcxHandler::startElement" << attrs.value("id");
+            if (!rootItem) {
+                rootItem = item;
+            }
+            currentItem = item;
         } else if (name == "content") {
-            contentUrl = attrs.value("src");
+            if (currentItem) {
+                currentItem->href = attrs.value("src");
+            }
         }
         return true;
     }
@@ -49,6 +100,8 @@ private:
     QString contentId;
     QString contentUrl;
     QString contentTitle;
+    TreeItem *rootItem;
+    TreeItem *currentItem;
 };
 
 #endif // NCXHANDLER_H
index 253bfdd..1c0b74a 100644 (file)
@@ -8,6 +8,9 @@ dorian (0.3.2-1) unstable; urgency=low
 
   * Fix dialog softkeys on Symbian
   * Fix full screen mode on Symbian
+  * Fix TOC in O'Reilly books (and handle TOC properly in general)
+  * Fix icon on Symbian^3
+  * Improve settings on Symbian
 
  -- Akos Polster <akos@pipacs.com>  Sun, 31 Oct 2010 02:00:00 +0200