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