scaled(COVER_WIDTH, COVER_HEIGHT, Qt::KeepAspectRatio);
}
-Book::Book(const QString &p, QObject *parent): QObject(parent)
+Book::Book(const QString &p, QObject *parent): QObject(parent), loaded(false)
{
mPath = "";
if (p.size()) {
}
}
-QString Book::path() const
+QString Book::path()
{
return mPath;
}
qDebug() << path();
close();
clear();
+ load();
if (path().isEmpty()) {
title = "No book";
return false;
qDebug() << path();
close();
clear();
+ load();
if (path().isEmpty()) {
title = "No book";
return;
QString tmp = tmpDir();
qDebug() << "Extracting" << mPath << "to" << tmp;
+ load();
QDir::setCurrent(QDir::rootPath());
if (!clearDir(tmp)) {
qCritical() << "Book::extract: Failed to remove" << tmp;
{
TRACE;
+ load();
+
// Parse OPS file
bool ret = false;
QString opsFileName = opsPath();
void Book::load()
{
+ if (loaded) {
+ return;
+ }
+
TRACE;
+ loaded = true;
qDebug() << "path" << path();
QVariantHash data = BookDb::instance()->load(path());
{
TRACE;
+ load();
QVariantHash data;
data["title"] = title;
data["creators"] = creators;
void Book::setLastBookmark(int part, qreal position)
{
TRACE;
- qDebug() << "part" << part << "position" << position;
+ load();
mLastBookmark.part = part;
mLastBookmark.pos = position;
save();
}
-Book::Bookmark Book::lastBookmark() const
+Book::Bookmark Book::lastBookmark()
{
+ load();
return Book::Bookmark(mLastBookmark);
}
void Book::addBookmark(int part, qreal position, const QString ¬e)
{
+ load();
mBookmarks.append(Bookmark(part, position, note));
qSort(mBookmarks.begin(), mBookmarks.end());
save();
void Book::deleteBookmark(int index)
{
+ load();
mBookmarks.removeAt(index);
save();
}
-QList<Book::Bookmark> Book::bookmarks() const
+QList<Book::Bookmark> Book::bookmarks()
{
+ load();
return mBookmarks;
}
QString Book::opsPath()
{
TRACE;
+ load();
QString ret;
QFile container(tmpDir() + "/META-INF/container.xml");
return ret;
}
-QString Book::rootPath() const
+QString Book::rootPath()
{
+ load();
return mRootPath;
}
-QString Book::name() const
+QString Book::name()
{
+ load();
if (title.size()) {
QString ret = title;
if (creators.length()) {
}
}
-QString Book::shortName() const
+QString Book::shortName()
{
+ load();
return (title.isEmpty())? QFileInfo(path()).baseName(): title;
}
int Book::chapterFromPart(int index)
{
+ TRACE;
+ load();
int ret = -1;
QString partId = parts[index];
int Book::partFromChapter(int index, QString &fragment)
{
- Trace t("Book::partFromChapter");
+ TRACE;
+ load();
fragment.clear();
QString id = chapters[index];
QString href = content[id].href;
qreal Book::getProgress(int part, qreal position)
{
+ load();
Q_ASSERT(part < parts.size());
QString key;
qreal partSize = 0;
{
TRACE;
- qDebug() << path();
-
// Load book from old database (QSettings)
QSettings settings;
void Book::remove()
{
TRACE;
+ load();
BookDb::instance()->remove(path());
}
void close();
/** Return path to EPUB. */
- QString path() const;
+ QString path();
/**
* Return path to root directory of extracted EPUB.
* Only valid after parsing Book::opsPath().
*/
- QString rootPath() const;
+ QString rootPath();
/** Return temporary directory path for extracting EPUB file. */
QString tmpDir() const;
void setLastBookmark(int part, qreal position);
/** Get last bookmark. */
- Bookmark lastBookmark() const;
+ Bookmark lastBookmark();
/** Add bookmark. */
void addBookmark(int part, qreal position, const QString ¬e);
void deleteBookmark(int index);
/** List bookmarks. */
- QList<Bookmark> bookmarks() const;
+ QList<Bookmark> bookmarks();
/**
* Get friendly name.
* @return @see title or path name combined with author(s) name.
*/
- QString name() const;
+ QString name();
/** Get short friendly name: title or file name. */
- QString shortName() const;
+ QString shortName();
/** Get chapter index from part index. */
int chapterFromPart(int index);
QList<Bookmark> mBookmarks; //< List of bookmarks.
QString mRootPath; //< Path to root item in EPUB dir.
QTemporaryFile mTempFile; //< Guards extracting books.
+ bool loaded; //< True, if loaded from database.
};
#endif // BOOK_H