this, SLOT(onCurrentBookChanged()));
// Load library, upgrade it if needed
- upgradeProgress = new QProgressDialog(tr("Upgrading library"), "", 0, 0, this);
- upgradeProgress->reset();
- upgradeProgress->setMinimumDuration(0);
- upgradeProgress->setWindowModality(Qt::WindowModal);
- upgradeProgress->setCancelButton(0);
+ libraryProgress = new QProgressDialog(tr("Upgrading library"), "", 0, 0, this);
+ libraryProgress->reset();
+ libraryProgress->setMinimumDuration(0);
+ libraryProgress->setWindowModality(Qt::WindowModal);
+ libraryProgress->setCancelButton(0);
Library *library = Library::instance();
connect(library, SIGNAL(beginUpgrade(int)), this, SLOT(onBeginUpgrade(int)));
connect(library, SIGNAL(upgrading(const QString &)),
this, SLOT(onUpgrading(const QString &)));
connect(library, SIGNAL(endUpgrade()), this, SLOT(onEndUpgrade()));
+ connect(library, SIGNAL(beginLoad(int)), this, SLOT(onBeginLoad(int)));
+ connect(library, SIGNAL(loading(const QString &)),
+ this, SLOT(onLoading(const QString &)));
+ connect(library, SIGNAL(endLoad()), this, SLOT(onEndLoad()));
library->upgrade();
library->load();
void MainWindow::onBeginUpgrade(int total)
{
- upgradeProgress->setVisible(total > 0);
- upgradeProgress->setMaximum(total);
+ libraryProgress->setVisible(total > 0);
+ libraryProgress->setWindowTitle(tr("Upgrading library"));
+ libraryProgress->setMaximum(total);
}
void MainWindow::onUpgrading(const QString &path)
{
- upgradeProgress->setLabelText(tr("Upgrading %1").
+ libraryProgress->setLabelText(tr("Upgrading %1").
arg(QFileInfo(path).fileName()));
- upgradeProgress->setValue(upgradeProgress->value() + 1);
+ libraryProgress->setValue(libraryProgress->value() + 1);
}
void MainWindow::onEndUpgrade()
{
- upgradeProgress->hide();
- upgradeProgress->reset();
+ libraryProgress->hide();
+ libraryProgress->reset();
+}
+
+
+void MainWindow::onBeginLoad(int total)
+{
+ libraryProgress->setVisible(total > 0);
+ libraryProgress->setWindowTitle(tr("Loading library"));
+ libraryProgress->setMaximum(total);
+}
+
+void MainWindow::onLoading(const QString &path)
+{
+ libraryProgress->setLabelText(tr("Loading %1").
+ arg(QFileInfo(path).fileName()));
+ libraryProgress->setValue(libraryProgress->value() + 1);
+}
+
+void MainWindow::onEndLoad()
+{
+ libraryProgress->hide();
+ libraryProgress->reset();
}
void onBeginUpgrade(int total);
void onUpgrading(const QString &book);
void onEndUpgrade();
+ void onBeginLoad(int total);
+ void onLoading(const QString &book);
+ void onEndLoad();
protected:
void closeEvent(QCloseEvent *event);
Progress *progress;
TranslucentButton *previousButton;
TranslucentButton *nextButton;
- QProgressDialog *upgradeProgress;
+ QProgressDialog *libraryProgress;
};
#endif // MAINWINDOW_H
Trace t("Book::load");
qDebug() << "path" << path();
-#if 1
QVariantHash data = BookDb::instance()->load(path());
title = data["title"].toString();
qDebug() << title;
qreal pos = data[QString("bookmark%1pos").arg(i)].toReal();
mBookmarks.append(Bookmark(part, pos));
}
-#else
- QSettings settings;
- QString key = "book/" + path() + "/";
- qDebug() << "key" << key;
-
- // Load book info
- 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>().scaled(COVER_WIDTH,
- COVER_HEIGHT, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
- if (cover.isNull()) {
- cover = makeCover(":/icons/book.png");
- }
-
- // Load bookmarks
- 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));
- }
-#endif
}
void Book::save()
{
Trace t("Book::save");
-#if 1
QVariantHash data;
data["title"] = title;
data["creators"] = creators;
data[QString("bookmark%1pos").arg(i)] = mBookmarks[i].pos;
}
BookDb::instance()->save(path(), data);
-#else
- QSettings settings;
- QString key = "book/" + path() + "/";
- qDebug() << "key" << key;
-
- // Save book info
- settings.setValue(key + "title", title);
- qDebug() << "title" << title;
- settings.setValue(key + "creators", creators);
- settings.setValue(key + "date", date);
- settings.setValue(key + "publisher", publisher);
- settings.setValue(key + "datepublished", datePublished);
- settings.setValue(key + "subject", subject);
- settings.setValue(key + "source", source);
- settings.setValue(key + "rights", rights);
- settings.setValue(key + "lastpart", mLastBookmark.part);
- settings.setValue(key + "lastpos", mLastBookmark.pos);
- settings.setValue(key + "cover", cover);
-
- // Save bookmarks
- settings.setValue(key + "bookmarks", mBookmarks.size());
- for (int i = 0; i < mBookmarks.size(); i++) {
- qDebug() << QString("Bookmark %1 at %2, %3").
- arg(i).arg(mBookmarks[i].part).arg(mBookmarks[i].pos);
- settings.setValue(key + "bookmark" + QString::number(i) + "/part",
- mBookmarks[i].part);
- settings.setValue(key + "bookmark" + QString::number(i) + "/pos",
- mBookmarks[i].pos);
- }
-#endif
}
void Book::setLastBookmark(int part, qreal position)
{
+ Trace t("Book:setLastBookmark");
+ qDebug() << "part" << part << "position" << position;
mLastBookmark.part = part;
mLastBookmark.pos = position;
save();
void Book::upgrade()
{
Trace t("Book::upgrade");
+
qDebug() << path();
+
+ // 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>().scaled(COVER_WIDTH,
+ COVER_HEIGHT, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+ if (cover.isNull()) {
+ cover = makeCover(":/icons/book.png");
+ }
+ 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));
+ }
+
+ // Save book to new database
+
+ save();
+}
+
+void Book::remove()
+{
+ Trace t("Book::remove");
+ BookDb::instance()->remove(path());
}
/** Upgrade persistent storage of book meta-data. */
void upgrade();
+ /** Delete book meta-data from persistent storage. */
+ void remove();
+
/** Extract and parse EPUB contents, fill in all members except mPath. */
bool open();
Trace t("BookDb::load");
qDebug() << book;
QVariantHash ret;
+ QByteArray bytes;
QSqlQuery query("select content from book where name = ?");
query.bindValue(0, book);
+ query.setForwardOnly(true);
+ if (!query.exec()) {
+ qCritical() << "Query failed";
+ return ret;
+ }
while (query.next()) {
- ret = query.value(0).toHash();
+ bytes = query.value(0).toByteArray();
+ QDataStream in(bytes);
+ in >> ret;
break;
}
qDebug() << ret;
{
Trace t("BookDb::save");
qDebug() << book;
+ qDebug() << data;
+ QByteArray bytes;
+ QDataStream out(&bytes, QIODevice::WriteOnly);
+ out << data;
QSqlQuery query("insert or replace into book values (?, ?)");
query.bindValue(0, book);
- query.bindValue(1, data);
+ query.bindValue(1, bytes);
if (!query.exec()) {
- qCritical() << "Failed to insert or replace";
+ qCritical() << "Query failed";
}
}
void BookDb::remove(const QString &book)
{
+ // FIXME
Q_UNUSED(book);
}
QStringList ret;
QSqlQuery query("select name from book");
query.setForwardOnly(true);
+ if (!query.exec()) {
+ qCritical() << "Query failed";
+ return ret;
+ }
while (query.next()) {
ret.append(query.value(0).toString());
}
void Library::load()
{
- QSettings settings;
+ Trace t("Library::load");
+
clear();
-#if 0
- int size = settings.value("lib/size").toInt();
- for (int i = 0; i < size; i++) {
- QString key = "lib/book" + QString::number(i);
- QString path = settings.value(key).toString();
- Book *book = new Book(path);
- connect(book, SIGNAL(opened(const QString &)),
- this, SLOT(onBookOpened(const QString &)));
- book->load();
- mBooks.append(book);
- }
-#else
- foreach(QString path, BookDb::instance()->books()) {
+ QStringList books = BookDb::instance()->books();
+ emit beginLoad(books.size());
+
+ foreach(QString path, books) {
+ emit loading(path);
Book *book = new Book(path);
connect(book, SIGNAL(opened(const QString &)),
this, SLOT(onBookOpened(const QString &)));
book->load();
mBooks.append(book);
}
-#endif
+ QSettings settings;
QString currentPath = settings.value("lib/nowreading").toString();
mNowReading = find(currentPath);
+ emit endLoad();
}
void Library::save()
{
+ Trace t("Library::save");
QSettings settings;
-#if 0
- settings.setValue("lib/size", mBooks.size());
- for (int i = 0; i < mBooks.size(); i++) {
- QString key = "lib/book" + QString::number(i);
- settings.setValue(key, mBooks[i]->path());
- }
-#endif
Book *currentBook = book(mNowReading);
settings.setValue("lib/nowreading",
currentBook? currentBook->path(): QString());
void Library::remove(const QModelIndex &index)
{
+ Trace t("Library::remove");
Book *toRemove = book(index);
if (!toRemove) {
return;
}
+ toRemove->remove();
int row = index.row();
beginRemoveRows(QModelIndex(), row, row);
mBooks.removeAt(row);
Trace t("Library::upgrade");
QSettings settings;
QString oldVersion = settings.value("lib/version").toString();
- if (true /* oldVersion.isEmpty() */) {
+ if (/* true */ oldVersion.isEmpty()) {
int size = settings.value("lib/size").toInt();
emit beginUpgrade(size);
for (int i = 0; i < size; i++) {
void beginUpgrade(int total);
void upgrading(const QString &book);
void endUpgrade();
+ void beginLoad(int total);
+ void loading(const QString &book);
+ void endLoad();
public slots:
bool add(const QString &path);
-dorian (0.2.3-1) unstable; urgency=low
+dorian (0.3.0-1) unstable; urgency=low
* Keep library data in database
+ * Upgrade from old data format if needed
+ * Show progress during library load and upgrade
-- Akos Polster <akos@pipacs.com> Thu, 8 Oct 2010 02:00:00 +0200
Package: dorian
Architecture: armel
-Depends: zlib1g, libqt4-core (>= 4.6.1), libqt4-gui (>= 4.6.1), libqt4-webkit (>= 4.6.1), libqt4-xml (>= 4.6.1), libqt4-dbus (>= 4.6.1), mce
+Depends: zlib1g, libqt4-core (>= 4.6.1), libqt4-gui (>= 4.6.1), libqt4-webkit (>= 4.6.1), libqt4-xml (>= 4.6.1), libqt4-dbus (>= 4.6.1), libqt4-sql (>= 4.6.1), libqt4-sql-sqlite (>= 4.6.1), mce
Description: E-book reader
Read books published in DRM-free EPUB format
XB-Maemo-Display-Name: Dorian