#include "ncxhandler.h"
#include "trace.h"
-Book::Book()
-{
-}
+const int COVER_WIDTH = 50;
+const int COVER_HEIGHT = 55;
-Book::Book(const QString &path_)
+Book::Book(const QString &p, QObject *parent): QObject(parent)
{
mPath = "";
- if (path_ != "") {
- QFileInfo info(path_);
+ if (p != "") {
+ QFileInfo info(p);
mPath = info.absoluteFilePath();
title = info.baseName();
- cover = QIcon(":/icons/book.png");
+ cover = QImage(":/icons/book.png").scaled(COVER_WIDTH, COVER_HEIGHT,
+ Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
}
}
else {
save();
+ emit opened(path());
}
}
{
Trace t("Book::parse");
+ // Parse OPS file
bool ret = false;
QString opsFileName = opsPath();
t.trace("Parsing OPS file" + opsFileName);
delete opsHandler;
delete source;
+ // Load cover image
+ if (content.contains("cover-image")) {
+ t.trace("Loading cover image from " + content["cover-image"].href);
+ cover = QImage(content["cover-image"].href).scaled(COVER_WIDTH,
+ COVER_HEIGHT, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+ } else if (content.contains("img-cover-jpeg")) {
+ t.trace("Loading cover image from " + content["img-cover-jpeg"].href);
+ cover = QImage(content["img-cover-jpeg"].href).scaled(COVER_WIDTH,
+ COVER_HEIGHT, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+ }
+
// If there is an "ncx" item in content, parse it: That's the real table of
// contents
if (content.contains("ncx")) {
rights = settings.value(key + "rights").toString();
mLastBookmark.chapter = settings.value(key + "lastchapter").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 = QImage(":/icons/book.png").scaled(COVER_WIDTH, COVER_HEIGHT,
+ Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+ }
// Load bookmarks
int size = settings.value(key + "bookmarks").toInt();
settings.setValue(key + "rights", rights);
settings.setValue(key + "lastchapter", mLastBookmark.chapter);
settings.setValue(key + "lastpos", mLastBookmark.pos);
+ settings.setValue(key + "cover", cover);
// Save bookmarks
settings.setValue(key + "bookmarks", mBookmarks.size());
QString Book::name() const
{
if (title != "") {
- return title;
+ QString ret = title;
+ if (creators.length()) {
+ ret += "\nBy " + creators[0];
+ for (int i = 1; i < creators.length(); i++) {
+ ret += ", " + creators[i];
+ }
+ }
+ return ret;
} else {
return path();
}
#include <QHash>
#include <QIcon>
#include <QMetaType>
+#include <QObject>
/** A book. */
-class Book
+class Book: public QObject
{
+ Q_OBJECT
+
public:
/** Content item in the table of contents. */
};
/** Construct a book from an EPUB file in path. */
- Book(const QString &path);
+ Book(const QString &path, QObject *parent = 0);
/** Default constructor. */
Book();
QString title; //< Book title from EPUB.
QStringList toc; //< Table of contents from EPUB.
QHash<QString, ContentItem> content; //< Content items from EPUB.
- QIcon cover; //< Cover image.
+ QImage cover; //< Cover image.
QStringList creators; //< Creators.
QString date; //< Date of creation.
QString publisher; //< Publisher.
QString rights; //< Rights.
QString tocPath; //< Path to toc ncx.
QString coverPath; //< Path to cover html.
- QString coverImagePath; //< Path to cover image.
+
+signals:
+ /** Emitted if @see open() succeeds. */
+ void opened(const QString &bookPath);
protected:
/** Indicate failure by creating a single "error" content item. */
QString mRootPath; //< Path to root item in EPUB dir.
};
-Q_DECLARE_METATYPE(Book)
-
#endif // BOOK_H
signals:
void restore();
-public slots:
-
protected:
#ifdef Q_WS_MAEMO_5
# define MOUSE_ACTIVATE_EVENT mouseReleaseEvent
switch (role) {
case Qt::DisplayRole:
return mBooks[index.row()]->name();
+ case Qt::DecorationRole:
+ return QPixmap::fromImage(mBooks[index.row()]->cover);
default:
return QVariant();
}
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);
}
}
return QModelIndex();
}
+
+void Library::onBookOpened(const QString &path)
+{
+ Trace t("Library::onBookOpened " + path);
+ QModelIndex index = find(path);
+ if (index.isValid()) {
+ emit dataChanged(index, index);
+ }
+}
signals:
void nowReadingChanged();
+public slots:
+ void onBookOpened(const QString &path);
+
private:
explicit Library(QObject *parent = 0);
~Library();
QFrame *frame = new QFrame(this);
setCentralWidget(frame);
- QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
+ QHBoxLayout *horizontalLayout = new QHBoxLayout(frame);
frame->setLayout(horizontalLayout);
list = new QListView(this);
sortedLibrary = new SortedLibrary(this);
list->setModel(sortedLibrary);
list->setSelectionMode(QAbstractItemView::SingleSelection);
+ list->setSpacing(1);
list->setUniformItemSizes(true);
Library *library = Library::instance();
connect(list, SIGNAL(activated(const QModelIndex &)),
this, SLOT(onItemActivated(const QModelIndex &)));
#ifndef Q_WS_MAEMO_5
- connect(list, SIGNAL(itemSelectionChanged()),
- this, SLOT(onItemSelectionChanged()));
connect(addButton, SIGNAL(clicked()), this, SLOT(onAdd()));
connect(detailsButton, SIGNAL(clicked()), this, SLOT(onDetails()));
connect(readButton, SIGNAL(clicked()), this, SLOT(onRead()));
* Fix multiple navigation arrows [#6041]
* Make full screen switching more robust
+ * Show cover images in library
-- Akos Polster <akos@pipacs.com> Thu, 29 Jul 2010 20:00:00 +0200