+
+bool Book::extractMetaData()
+{
+ QStringList excludedExtensions;
+ excludedExtensions << ".html" << ".xhtml" << ".xht" << ".htm" << ".gif"
+ << ".css" << "*.ttf" << "mimetype";
+ return extract(excludedExtensions);
+}
+
+void Book::upgrade()
+{
+ TRACE;
+
+ // Load book from old database (QSettings)
+ QSettings settings;
+ QString key = "book/" + path() + "/";
+ title = settings.value(key + "title").toString();
+ qDebug() << title;
+ creators = settings.value(key + "creators").toStringList();
+ date = settings.value(key + "date").toString();
+ publisher = settings.value(key + "publisher").toString();
+ datePublished = settings.value(key + "datepublished").toString();
+ subject = settings.value(key + "subject").toString();
+ source = settings.value(key + "source").toString();
+ rights = settings.value(key + "rights").toString();
+ mLastBookmark.part = settings.value(key + "lastpart").toInt();
+ mLastBookmark.pos = settings.value(key + "lastpos").toReal();
+ cover = settings.value(key + "cover").value<QImage>();
+ if (cover.isNull()) {
+ cover = makeCover(":/icons/book.png");
+ } else {
+ cover = makeCover(QPixmap::fromImage(cover));
+ }
+ int size = settings.value(key + "bookmarks").toInt();
+ for (int i = 0; i < size; i++) {
+ int part = settings.value(key + "bookmark" + QString::number(i) +
+ "/part").toInt();
+ qreal pos = settings.value(key + "bookmark" + QString::number(i) +
+ "/pos").toReal();
+ qDebug() << QString("Bookmark %1 at part %2, %3").
+ arg(i).arg(part).arg(pos);
+ mBookmarks.append(Bookmark(part, pos));
+ }
+
+ // Remove QSettings
+ settings.remove("book/" + path());
+
+ // Save book to new database
+ save();
+}
+
+void Book::remove()
+{
+ TRACE;
+ close();
+ BookDb::instance()->remove(path());
+}
+
+QImage Book::makeCover(const QString &fileName)
+{
+ TRACE;
+ qDebug() << fileName;
+ QFileInfo info(fileName);
+ if (info.isReadable() && (info.size() < COVER_MAX)) {
+ return makeCover(QPixmap(fileName));
+ }
+ return makeCover(QPixmap(":/icons/book.png"));
+}
+
+QImage Book::makeCover(const QPixmap &pixmap)
+{
+ TRACE;
+ QPixmap src = pixmap.scaled(COVER_WIDTH, COVER_HEIGHT,
+ Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ QPixmap transparent(COVER_WIDTH, COVER_HEIGHT);
+ transparent.fill(Qt::transparent);
+
+ QPainter p;
+ p.begin(&transparent);
+ p.setCompositionMode(QPainter::CompositionMode_Source);
+ p.drawPixmap((COVER_WIDTH - src.width()) / 2,
+ (COVER_HEIGHT - src.height()) / 2, src);
+ p.end();
+
+ return transparent.toImage();
+}
+
+