10 #include <QTemporaryFile>
13 class Book: public QObject
19 /** Content item in the table of contents. */
27 /** Bookmark: a volume index and a relative position in volume. */
30 Bookmark(int part_, qreal pos_): part(part_), pos(pos_) {}
31 Bookmark() {part = pos = 0;}
34 bool operator<(const Bookmark&other) const {
35 return (part == other.part)? (pos < other.pos): (part < other.part);
39 /** Construct a book from an EPUB file in path. */
40 Book(const QString &path, QObject *parent = 0);
42 /** Default constructor. */
45 /** Load book from persistent storage. */
48 /** Save book to persistent storage. */
51 /** Extract and parse EPUB contents, fill in all members except mPath. */
54 /** Extract and parse EPUB metadata only, fill in all members except mPath. */
57 /** Clear toc and content members, remove extracted content files. */
60 /** Return path to EPUB. */
64 * Return path to root directory of extracted EPUB.
65 * Only valid after parsing Book::opsPath().
67 QString rootPath() const;
69 /** Return temporary directory path for extracting EPUB file. */
70 QString tmpDir() const;
72 /** Clear directory. */
73 bool clearDir(const QString &directory);
75 /** Set last bookmark. */
76 void setLastBookmark(int part, qreal position);
78 /** Get last bookmark. */
79 Bookmark lastBookmark() const;
82 void addBookmark(int part, qreal position);
84 /** Delete bookmark. */
85 void deleteBookmark(int index);
87 /** List bookmarks. */
88 QList<Bookmark> bookmarks() const;
92 * @return @see title or path name combined with author(s) name.
96 /** Get short friendly name: title or file name. */
97 QString shortName() const;
99 /** Get chapter index from part index. */
100 int chapterFromPart(int index);
102 /** Get part index from chapter index. */
103 int partFromChapter(int index);
105 /** Get progress (0..1) corresponding to part index and part position. */
106 qreal getProgress(int part, qreal position);
108 QString title; //< Book title from EPUB.
109 QStringList parts; //< EPUB part list.
110 QHash<QString, ContentItem> content; //< Content items from EPUB.
111 QImage cover; //< Cover image.
112 QStringList creators; //< Creators.
113 QString date; //< Date of creation.
114 QString publisher; //< Publisher.
115 QString datePublished; //< Date of publishing.
116 QString subject; //< Subject.
117 QString source; //< Source.
118 QString rights; //< Rights.
119 QString tocPath; //< Path to toc ncx.
120 QString coverPath; //< Path to cover html.
121 QStringList chapters; //< Main navigation items from EPUB.
122 qint64 size; //< Size of all parts.
125 /** Emitted if @see open() succeeds. */
126 void opened(const QString &bookPath);
129 /** Extract EPUB as ZIP. */
132 /** Extract metadata from EPUB. */
133 bool extractMetaData();
135 /** Parse extracted EPUB. */
138 /** Clear all book fields except path. */
141 /** Get location of OPS file in EPUB archive. */
144 QString mPath; //< Path to EPUB file.
145 Bookmark mLastBookmark; //< Last position read.
146 QList<Bookmark> mBookmarks; //< List of bookmarks.
147 QString mRootPath; //< Path to root item in EPUB dir.
148 QTemporaryFile mTempFile; //< Guards extracting books.