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_, const QString ¬e_ = QString()):
31 part(part_), pos(pos_), note(note_) {}
32 Bookmark(): part(0), pos(0.0) {}
36 bool operator<(const Bookmark &other) const {
37 return (part == other.part)? (pos < other.pos): (part < other.part);
41 /** Construct a book from an EPUB file in path. */
42 Book(const QString &path, QObject *parent = 0);
44 /** Default constructor. */
47 /** Load book meta-data from persistent storage. */
50 /** Save book meta-data to persistent storage. */
53 /** Upgrade persistent storage of book meta-data. */
56 /** Delete book meta-data from persistent storage. */
59 /** Extract and parse EPUB contents, fill in all members except mPath. */
62 /** Extract and parse metadata only, fill in all members except mPath. */
65 /** Clear toc and content members, remove extracted content files. */
68 /** Return path to EPUB. */
72 * Return path to root directory of extracted EPUB.
73 * Only valid after parsing Book::opsPath().
75 QString rootPath() const;
77 /** Return temporary directory path for extracting EPUB file. */
78 QString tmpDir() const;
80 /** Clear directory. */
81 bool clearDir(const QString &directory);
83 /** Set last bookmark. */
84 void setLastBookmark(int part, qreal position);
86 /** Get last bookmark. */
87 Bookmark lastBookmark() const;
90 void addBookmark(int part, qreal position, const QString ¬e);
92 /** Delete bookmark. */
93 void deleteBookmark(int index);
95 /** List bookmarks. */
96 QList<Bookmark> bookmarks() const;
100 * @return @see title or path name combined with author(s) name.
102 QString name() const;
104 /** Get short friendly name: title or file name. */
105 QString shortName() const;
107 /** Get chapter index from part index. */
108 int chapterFromPart(int index);
110 /** Get part index from chapter index. */
111 int partFromChapter(int index);
113 /** Get progress (0..1) corresponding to part index and part position. */
114 qreal getProgress(int part, qreal position);
116 QString title; //< Book title from EPUB.
117 QStringList parts; //< EPUB part list.
118 QHash<QString, ContentItem> content; //< Content items from EPUB.
119 QImage cover; //< Cover image.
120 QStringList creators; //< Creators.
121 QString date; //< Date of creation.
122 QString publisher; //< Publisher.
123 QString datePublished; //< Date of publishing.
124 QString subject; //< Subject.
125 QString source; //< Source.
126 QString rights; //< Rights.
127 QString tocPath; //< Path to toc NCX file.
128 QString coverPath; //< Path to cover HTML file.
129 QStringList chapters; //< Main navigation items from EPUB.
130 qint64 size; //< Size of all parts.
133 /** Emitted if @see open() succeeds. */
134 void opened(const QString &bookPath);
137 /** Extract EPUB as ZIP. */
138 bool extract(const QStringList &excludedExtensions);
140 /** Extract metadata from EPUB. */
141 bool extractMetaData();
143 /** Parse extracted EPUB. */
146 /** Clear all book fields except path. */
149 /** Get location of OPS file in EPUB archive. */
152 QString mPath; //< Path to EPUB file.
153 Bookmark mLastBookmark; //< Last position read.
154 QList<Bookmark> mBookmarks; //< List of bookmarks.
155 QString mRootPath; //< Path to root item in EPUB dir.
156 QTemporaryFile mTempFile; //< Guards extracting books.