10 #include <QTemporaryFile>
16 class Book: public QObject
22 /** Content item: An individual, named part of the book. */
30 /** Bookmark: a volume index and a relative position in volume. */
33 Bookmark(int part_, qreal pos_, const QString ¬e_ = QString()):
34 part(part_), pos(pos_), note(note_) {}
35 Bookmark(): part(0), pos(0.0) {}
39 bool operator<(const Bookmark &other) const {
40 return (part == other.part)? (pos<other.pos): (part<other.part);
44 /** Construct a book from an EPUB file. */
45 Book(const QString &fileName, QObject *parent = 0);
50 /** Load book meta-data from persistent storage. */
53 /** Save book meta-data to persistent storage. */
56 /** Upgrade persistent storage of book meta-data. */
59 /** Delete book meta-data from persistent storage. */
62 /** Extract and parse EPUB contents, fill in all members except mPath. */
65 /** Extract and parse metadata only, fill in all members except mPath. */
68 /** Clear toc and content members, remove extracted content files. */
71 /** Return path to EPUB. */
75 * Return path to root directory of extracted EPUB.
76 * Only valid after parsing Book::opsPath().
80 /** Return temporary directory path for extracting EPUB file. */
81 QString tmpDir() const;
83 /** Clear directory. */
84 bool clearDir(const QString &directory);
86 /** Set last bookmark. */
87 void setLastBookmark(int part, qreal position);
89 /** Get last bookmark. */
90 Bookmark lastBookmark();
93 void addBookmark(int part, qreal position, const QString ¬e);
95 /** Delete bookmark. */
96 void deleteBookmark(int index);
98 /** List bookmarks. */
99 QList<Bookmark> bookmarks();
103 * @return @see title or path name combined with author(s) name.
107 /** Get cover image. */
110 /** Get short friendly name: title or file name. */
113 /** Get chapter index from part index. */
114 int chapterFromPart(int index);
116 /** Get part index and URL fragment from chapter index. */
117 int partFromChapter(int index, QString &fragment);
119 /** Get progress (0..1) corresponding to part index and part position. */
120 qreal getProgress(int part, qreal position);
122 QString title; //< Book title from EPUB.
123 QStringList parts; //< EPUB part list.
124 QHash<QString, ContentItem> content; //< Content items from EPUB.
125 QImage cover; //< Cover image.
126 QStringList creators; //< Creators.
127 QString date; //< Date of creation.
128 QString publisher; //< Publisher.
129 QString datePublished; //< Date of publishing.
130 QString subject; //< Subject.
131 QString source; //< Source.
132 QString rights; //< Rights.
133 QString tocPath; //< Path to toc NCX file.
134 QString coverPath; //< Path to cover HTML file.
135 QStringList chapters; //< Main navigation items.
136 qint64 size; //< Size of all parts.
137 QDateTime dateAdded; //< Date book added to library.
138 QDateTime dateOpened; //< Date book was last read.
141 /** Emitted if @see open() succeeds. */
142 void opened(const QString &bookPath);
145 /** Extract EPUB as ZIP. */
146 bool extract(const QStringList &excludedExtensions);
148 /** Extract metadata from EPUB. */
149 bool extractMetaData();
151 /** Parse extracted EPUB. */
154 /** Clear all book fields except path. */
157 /** Get location of OPS file in EPUB archive. */
160 /** Make a cover image from a file. */
161 QImage makeCover(const QString &fileName);
163 /** Make a cover image from an pixmap. */
164 QImage makeCover(const QPixmap &pixmap);
166 QString mPath; //< Path to EPUB file.
167 Bookmark mLastBookmark; //< Last position read.
168 QList<Bookmark> mBookmarks; //< List of bookmarks.
169 QString mRootPath; //< Path to root item in EPUB dir.
170 QTemporaryFile mTempFile; //< Guards extracting books.
171 bool loaded; //< True, if loaded from database.