diff --git a/src/qtquick/BookDatabase.h b/src/qtquick/BookDatabase.h --- a/src/qtquick/BookDatabase.h +++ b/src/qtquick/BookDatabase.h @@ -49,6 +49,11 @@ * @param entry The entry to add. */ void addEntry(BookEntry* entry); + /** + * @brief remove an entry by filename from the cache. + * @param entry the entry to remove. + */ + void removeEntry(BookEntry* entry); private: class Private; Private* d; diff --git a/src/qtquick/BookDatabase.cpp b/src/qtquick/BookDatabase.cpp --- a/src/qtquick/BookDatabase.cpp +++ b/src/qtquick/BookDatabase.cpp @@ -149,3 +149,17 @@ d->closeDb(); } + +void BookDatabase::removeEntry(BookEntry* entry) +{ + if(!d->prepareDb()) { + return; + } + qDebug() << "Removing book from the database" << entry->filename; + + QSqlQuery removeEntry; + removeEntry.prepare("DELETE FROM books WHERE filename='"+entry->filename+"';"); + removeEntry.exec(); + + d->closeDb(); +} diff --git a/src/qtquick/BookListModel.cpp b/src/qtquick/BookListModel.cpp --- a/src/qtquick/BookListModel.cpp +++ b/src/qtquick/BookListModel.cpp @@ -146,10 +146,19 @@ int i = 0; foreach(BookEntry* entry, entries) { - addEntry(q, entry); - if(++i % 100 == 0) { - emit q->countChanged(); - qApp->processEvents(); + /* + * This might turn out a little slow, but we should avoid having entries + * that do not exist. If we end up with slowdown issues when loading the + * cache this would be a good place to start investigating. + */ + if (QFileInfo::exists(entry->filename)) { + addEntry(q, entry); + if(++i % 100 == 0) { + emit q->countChanged(); + qApp->processEvents(); + } + } else { + db->removeEntry(entry); } } cacheLoaded = true; @@ -394,6 +403,7 @@ if(entry->filename == fileName) { emit entryRemoved(entry); + d->db->removeEntry(entry); delete entry; break; }