#include "pkg/version.txt"
;
-Library *Library::mInstance = 0;
+static Library *theInstance = 0;
Library::Library(QObject *parent): QAbstractListModel(parent)
{
Library *Library::instance()
{
- if (!mInstance) {
- mInstance = new Library();
+ if (!theInstance) {
+ theInstance = new Library();
}
- return mInstance;
+ return theInstance;
}
int Library::rowCount(const QModelIndex &parent) const
QVariant Library::data(const QModelIndex &index, int role) const
{
+ QVariant ret;
if (!index.isValid()) {
- return QVariant();
+ return ret;
}
switch (role) {
case Qt::DisplayRole:
- return mBooks[index.row()]->name();
+ ret = mBooks[index.row()]->name();
+ break;
case Qt::DecorationRole:
- return QPixmap::fromImage(mBooks[index.row()]->cover);
+ ret.setValue(mBooks[index.row()]->coverImage());
+ break;
default:
- return QVariant();
+ ;
}
+
+ return ret;
}
Book *Library::book(const QModelIndex &index)
void Library::close()
{
- delete mInstance;
- mInstance = 0;
+ delete theInstance;
+ theInstance = 0;
}
void Library::load()
if (!toRemove) {
return;
}
+ if (index == mNowReading) {
+ mNowReading = QModelIndex();
+ emit nowReadingChanged();
+ }
toRemove->remove();
int row = index.row();
beginRemoveRows(QModelIndex(), row, row);
mBooks.removeAt(row);
save();
endRemoveRows();
- if (index == mNowReading) {
- mNowReading = QModelIndex();
- emit nowReadingChanged();
- }
delete toRemove;
}
void Library::remove(const QString &path)
{
+ TRACE;
remove(find(path));
}
void Library::clear()
{
+ TRACE;
for (int i = 0; i < mBooks.size(); i++) {
delete mBooks[i];
}
QModelIndex Library::find(QString path) const
{
+ TRACE;
if (path != "") {
QString absolutePath = QFileInfo(path).absoluteFilePath();
for (int i = 0; i < mBooks.size(); i++) {
QModelIndex Library::find(const Book *book) const
{
+ TRACE;
if (book) {
for (int i = 0; i < mBooks.size(); i++) {
if (book == mBooks[i]) {