10 #include <QTemporaryFile>
15 class Book: public QObject
21 /** Content item: An individual, named part of the book. */
29 /** Bookmark: a volume index and a relative position in volume. */
32 Bookmark(int part_, qreal pos_, const QString ¬e_ = QString()):
33 part(part_), pos(pos_), note(note_) {}
34 Bookmark(): part(0), pos(0.0) {}
38 bool operator<(const Bookmark &other) const {
39 return (part == other.part)? (pos < other.pos): (part < other.part);
43 /** Construct a book from an EPUB file. */
44 Book(const QString &fileName, QObject *parent = 0);
49 /** Load book meta-data from persistent storage. */
52 /** Save book meta-data to persistent storage. */
55 /** Upgrade persistent storage of book meta-data. */
58 /** Delete book meta-data from persistent storage. */
61 /** Extract and parse EPUB contents, fill in all members except mPath. */
64 /** Extract and parse metadata only, fill in all members except mPath. */
67 /** Clear toc and content members, remove extracted content files. */
70 /** Return path to EPUB. */
74 * Return path to root directory of extracted EPUB.
75 * Only valid after parsing Book::opsPath().
79 /** Return temporary directory path for extracting EPUB file. */
80 QString tmpDir() const;
82 /** Clear directory. */
83 bool clearDir(const QString &directory);
85 /** Set last bookmark. */
86 void setLastBookmark(int part, qreal position);
88 /** Get last bookmark. */
89 Bookmark lastBookmark();
92 void addBookmark(int part, qreal position, const QString ¬e);
94 /** Delete bookmark. */
95 void deleteBookmark(int index);
97 /** List bookmarks. */
98 QList<Bookmark> bookmarks();
102 * @return @see title or path name combined with author(s) name.
106 /** Get cover image. */
109 /** Get short friendly name: title or file name. */
112 /** Get chapter index from part index. */
113 int chapterFromPart(int index);
115 /** Get part index and URL fragment from chapter index. */
116 int partFromChapter(int index, QString &fragment);
118 /** Get progress (0..1) corresponding to part index and part position. */
119 qreal getProgress(int part, qreal position);
121 QString title; //< Book title from EPUB.
122 QStringList parts; //< EPUB part list.
123 QHash<QString, ContentItem> content; //< Content items from EPUB.
124 QImage cover; //< Cover image.
125 QStringList creators; //< Creators.
126 QString date; //< Date of creation.
127 QString publisher; //< Publisher.
128 QString datePublished; //< Date of publishing.
129 QString subject; //< Subject.
130 QString source; //< Source.
131 QString rights; //< Rights.
132 QString tocPath; //< Path to toc NCX file.
133 QString coverPath; //< Path to cover HTML file.
134 QStringList chapters; //< Main navigation items from EPUB.
135 qint64 size; //< Size of all parts.
138 /** Emitted if @see open() succeeds. */
139 void opened(const QString &bookPath);
142 /** Extract EPUB as ZIP. */
143 bool extract(const QStringList &excludedExtensions);
145 /** Extract metadata from EPUB. */
146 bool extractMetaData();
148 /** Parse extracted EPUB. */
151 /** Clear all book fields except path. */
154 /** Get location of OPS file in EPUB archive. */
157 /** Make a cover image from a file. */
158 QImage makeCover(const QString &fileName);
160 /** Make a cover image from an pixmap. */
161 QImage makeCover(const QPixmap &pixmap);
163 QString mPath; //< Path to EPUB file.
164 Bookmark mLastBookmark; //< Last position read.
165 QList<Bookmark> mBookmarks; //< List of bookmarks.
166 QString mRootPath; //< Path to root item in EPUB dir.
167 QTemporaryFile mTempFile; //< Guards extracting books.
168 bool loaded; //< True, if loaded from database.