Jump to exact position on page, as identified by TOC entry. Handle
[dorian] / model / book.h
index e6a13c1..034b539 100644 (file)
@@ -7,6 +7,7 @@
 #include <QIcon>
 #include <QMetaType>
 #include <QObject>
+#include <QTemporaryFile>
 
 /** A book. */
 class Book: public QObject
@@ -15,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;
@@ -26,11 +27,13 @@ public:
     /** Bookmark: a volume index and a relative position in volume. */
     struct Bookmark
     {
-        Bookmark(int part_, qreal pos_): part(part_), pos(pos_) {}
-        Bookmark() {part = pos = 0;}
+        Bookmark(int part_, qreal pos_, const QString &note_ = QString()):
+                part(part_), pos(pos_), note(note_) {}
+        Bookmark(): part(0), pos(0.0) {}
         int part;
         qreal pos;
-        bool operator<(const Bookmark&other) const {
+        QString note;
+        bool operator<(const Bookmark &other) const {
             return (part == other.part)? (pos < other.pos): (part < other.part);
         }
     };
@@ -41,15 +44,24 @@ public:
     /** Default constructor. */
     Book();
 
-    /** Load book from persistent storage. */
+    /** Load book meta-data from persistent storage. */
     void load();
 
-    /** Save book to persistent storage. */
+    /** Save book meta-data to persistent storage. */
     void save();
 
+    /** Upgrade persistent storage of book meta-data. */
+    void upgrade();
+
+    /** Delete book meta-data from persistent storage. */
+    void remove();
+
     /** Extract and parse EPUB contents, fill in all members except mPath. */
     bool open();
 
+    /** Extract and parse metadata only, fill in all members except mPath. */
+    void peek();
+
     /** Clear toc and content members, remove extracted content files. */
     void close();
 
@@ -75,7 +87,7 @@ public:
     Bookmark lastBookmark() const;
 
     /** Add bookmark. */
-    void addBookmark(int part, qreal position);
+    void addBookmark(int part, qreal position, const QString &note);
 
     /** Delete bookmark. */
     void deleteBookmark(int index);
@@ -95,8 +107,11 @@ public:
     /** Get chapter index from part index. */
     int chapterFromPart(int index);
 
-    /** Get part index from chapter index. */
-    int partFromChapter(int index);
+    /** Get part index and URL fragment from chapter index. */
+    int partFromChapter(int index, QString &fragment);
+
+    /** Get progress (0..1) corresponding to part index and part position. */
+    qreal getProgress(int part, qreal position);
 
     QString title;                          //< Book title from EPUB.
     QStringList parts;                      //< EPUB part list.
@@ -109,9 +124,10 @@ 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.
 
 signals:
     /** Emitted if @see open() succeeds. */
@@ -119,7 +135,10 @@ signals:
 
 protected:
     /** Extract EPUB as ZIP. */
-    bool extract();
+    bool extract(const QStringList &excludedExtensions);
+
+    /** Extract metadata from EPUB. */
+    bool extractMetaData();
 
     /** Parse extracted EPUB. */
     bool parse();
@@ -134,6 +153,7 @@ protected:
     Bookmark mLastBookmark;                 //< Last position read.
     QList<Bookmark> mBookmarks;             //< List of bookmarks.
     QString mRootPath;                      //< Path to root item in EPUB dir.
+    QTemporaryFile mTempFile;               //< Guards extracting books.
 };
 
 #endif // BOOK_H