#include "library.h"
#include "book.h"
+#include "trace.h"
Library *Library::mInstance = 0;
switch (role) {
case Qt::DisplayRole:
return mBooks[index.row()]->name();
+ case Qt::DecorationRole:
+ return QPixmap::fromImage(mBooks[index.row()]->cover);
default:
return QVariant();
}
{
if (index.isValid()) {
if ((index.row() >= 0) && (index.row() < mBooks.size())) {
- qDebug() << "Library::book:" << index.row() << "is"
- << mBooks[index.row()]->name();
return mBooks[index.row()];
} else {
- qWarning() << "*** Library::book: Bad index" << index.row();
+ qCritical() << "*** Library::book: Bad index" << index.row();
}
}
return 0;
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();
- qDebug() << "Library::load: Add" << book->title << "from" << path;
mBooks.append(book);
}
QString currentPath = settings.value("lib/nowreading").toString();
void Library::save()
{
- qDebug() << "Library::save";
-
QSettings settings;
settings.setValue("lib/size", mBooks.size());
for (int i = 0; i < mBooks.size(); i++) {
bool Library::add(QString path)
{
- qDebug() << "Library::add" << path;
+ Trace t("Library::add " + path);
if (path == "") {
- qWarning() << "Library::add: Empty path";
+ qCritical() << "*** Library::add: Empty path";
return false;
}
if (find(path).isValid()) {
- qDebug() << " Book already exists in library";
+ t.trace("Book already exists in library");
return false;
}
int size = mBooks.size();
QModelIndex Library::nowReading() const
{
- qDebug() << "Library::nowReading" << mNowReading.row();
return mNowReading;
}
}
return QModelIndex();
}
+
+void Library::onBookOpened(const QString &path)
+{
+ Trace t("Library::onBookOpened " + path);
+ QModelIndex index = find(path);
+ if (index.isValid()) {
+ emit dataChanged(index, index);
+ }
+}