10 #include <QTemporaryFile>
13 class Book: public QObject
19 /** Content item: An individual, named part of the book. */
27 /** Bookmark: a volume index and a relative position in volume. */
30 Bookmark(int part_, qreal pos_): part(part_), pos(pos_) {}
31 Bookmark(): part(0), pos(0.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 meta-data from persistent storage. */
48 /** Save book meta-data to persistent storage. */
51 /** Upgrade persistent storage of book meta-data. */
54 /** Extract and parse EPUB contents, fill in all members except mPath. */
57 /** Extract and parse metadata only, fill in all members except mPath. */
60 /** Clear toc and content members, remove extracted content files. */
63 /** Return path to EPUB. */
67 * Return path to root directory of extracted EPUB.
68 * Only valid after parsing Book::opsPath().
70 QString rootPath() const;
72 /** Return temporary directory path for extracting EPUB file. */
73 QString tmpDir() const;
75 /** Clear directory. */
76 bool clearDir(const QString &directory);
78 /** Set last bookmark. */
79 void setLastBookmark(int part, qreal position);
81 /** Get last bookmark. */
82 Bookmark lastBookmark() const;
85 void addBookmark(int part, qreal position);
87 /** Delete bookmark. */
88 void deleteBookmark(int index);
90 /** List bookmarks. */
91 QList<Bookmark> bookmarks() const;
95 * @return @see title or path name combined with author(s) name.
99 /** Get short friendly name: title or file name. */
100 QString shortName() const;
102 /** Get chapter index from part index. */
103 int chapterFromPart(int index);
105 /** Get part index from chapter index. */
106 int partFromChapter(int index);
108 /** Get progress (0..1) corresponding to part index and part position. */
109 qreal getProgress(int part, qreal position);
111 QString title; //< Book title from EPUB.
112 QStringList parts; //< EPUB part list.
113 QHash<QString, ContentItem> content; //< Content items from EPUB.
114 QImage cover; //< Cover image.
115 QStringList creators; //< Creators.
116 QString date; //< Date of creation.
117 QString publisher; //< Publisher.
118 QString datePublished; //< Date of publishing.
119 QString subject; //< Subject.
120 QString source; //< Source.
121 QString rights; //< Rights.
122 QString tocPath; //< Path to toc NCX file.
123 QString coverPath; //< Path to cover HTML file.
124 QStringList chapters; //< Main navigation items from EPUB.
125 qint64 size; //< Size of all parts.
128 /** Emitted if @see open() succeeds. */
129 void opened(const QString &bookPath);
132 /** Extract EPUB as ZIP. */
133 bool extract(const QStringList &excludedExtensions);
135 /** Extract metadata from EPUB. */
136 bool extractMetaData();
138 /** Parse extracted EPUB. */
141 /** Clear all book fields except path. */
144 /** Get location of OPS file in EPUB archive. */
147 QString mPath; //< Path to EPUB file.
148 Bookmark mLastBookmark; //< Last position read.
149 QList<Bookmark> mBookmarks; //< List of bookmarks.
150 QString mRootPath; //< Path to root item in EPUB dir.
151 QTemporaryFile mTempFile; //< Guards extracting books.