projects
/
dorian
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix loading book and restoring reading position on Maemo.
[dorian]
/
model
/
library.cpp
diff --git
a/model/library.cpp
b/model/library.cpp
index
1a322fc
..
14082e5
100644
(file)
--- a/
model/library.cpp
+++ b/
model/library.cpp
@@
-7,7
+7,7
@@
static const char *DORIAN_VERSION =
#include "pkg/version.txt"
;
#include "pkg/version.txt"
;
-Library *Library::mInstance = 0;
+static Library *theInstance = 0;
Library::Library(QObject *parent): QAbstractListModel(parent)
{
Library::Library(QObject *parent): QAbstractListModel(parent)
{
@@
-20,10
+20,10
@@
Library::~Library()
Library *Library::instance()
{
Library *Library::instance()
{
- if (!mInstance) {
- mInstance = new Library();
+ if (!theInstance) {
+ theInstance = new Library();
}
}
- return mInstance;
+ return theInstance;
}
int Library::rowCount(const QModelIndex &parent) const
}
int Library::rowCount(const QModelIndex &parent) const
@@
-37,18
+37,23
@@
int Library::rowCount(const QModelIndex &parent) const
QVariant Library::data(const QModelIndex &index, int role) const
{
QVariant Library::data(const QModelIndex &index, int role) const
{
+ QVariant ret;
if (!index.isValid()) {
if (!index.isValid()) {
- return QVariant();
+ return ret;
}
switch (role) {
case Qt::DisplayRole:
}
switch (role) {
case Qt::DisplayRole:
- return mBooks[index.row()]->name();
+ ret = mBooks[index.row()]->name();
+ break;
case Qt::DecorationRole:
case Qt::DecorationRole:
- return QPixmap::fromImage(mBooks[index.row()]->cover);
+ ret.setValue(mBooks[index.row()]->coverImage());
+ break;
default:
default:
- return QVariant();
+ ;
}
}
+
+ return ret;
}
Book *Library::book(const QModelIndex &index)
}
Book *Library::book(const QModelIndex &index)
@@
-65,8
+70,8
@@
Book *Library::book(const QModelIndex &index)
void Library::close()
{
void Library::close()
{
- delete mInstance;
- mInstance = 0;
+ delete theInstance;
+ theInstance = 0;
}
void Library::load()
}
void Library::load()
@@
-116,6
+121,7
@@
bool Library::add(const QString &path)
beginInsertRows(QModelIndex(), size, size);
Book *book = new Book(path);
book->peek();
beginInsertRows(QModelIndex(), size, size);
Book *book = new Book(path);
book->peek();
+ book->dateAdded = QDateTime::currentDateTime().toUTC();
mBooks.append(book);
save();
endInsertRows();
mBooks.append(book);
save();
endInsertRows();
@@
-129,21
+135,22
@@
void Library::remove(const QModelIndex &index)
if (!toRemove) {
return;
}
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();
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)
{
delete toRemove;
}
void Library::remove(const QString &path)
{
+ TRACE;
remove(find(path));
}
remove(find(path));
}
@@
-161,6
+168,7
@@
void Library::setNowReading(const QModelIndex &index)
void Library::clear()
{
void Library::clear()
{
+ TRACE;
for (int i = 0; i < mBooks.size(); i++) {
delete mBooks[i];
}
for (int i = 0; i < mBooks.size(); i++) {
delete mBooks[i];
}
@@
-170,6
+178,7
@@
void Library::clear()
QModelIndex Library::find(QString path) const
{
QModelIndex Library::find(QString path) const
{
+ TRACE;
if (path != "") {
QString absolutePath = QFileInfo(path).absoluteFilePath();
for (int i = 0; i < mBooks.size(); i++) {
if (path != "") {
QString absolutePath = QFileInfo(path).absoluteFilePath();
for (int i = 0; i < mBooks.size(); i++) {
@@
-183,6
+192,7
@@
QModelIndex Library::find(QString path) const
QModelIndex Library::find(const Book *book) const
{
QModelIndex Library::find(const Book *book) const
{
+ TRACE;
if (book) {
for (int i = 0; i < mBooks.size(); i++) {
if (book == mBooks[i]) {
if (book) {
for (int i = 0; i < mBooks.size(); i++) {
if (book == mBooks[i]) {