+#include <QFileInfoList>
#include <QStringList>
#include <QDir>
-#include <QFileInfoList>
#include "bookfinder.h"
#include "trace.h"
{
}
-void BookFinder::find(const QStringList &directories, const QStringList &books)
+void BookFinder::find(const QString &path, const QStringList &books)
{
- Trace t("BookFinder::find");
+ TRACE;
QStringList booksFound;
+ int toAdd = 0;
+ int added = 0;
- foreach (QString path, directories) {
- QStringList filters(QString("*.epub"));
- QFileInfoList entries =
- QDir(path).entryInfoList(filters, QDir::Files | QDir::Readable);
- foreach (QFileInfo entry, entries) {
- booksFound.append(entry.absoluteFilePath());
- }
+ QStringList filters(QString("*.epub"));
+ QFileInfoList entries =
+ QDir(path).entryInfoList(filters, QDir::Files | QDir::Readable);
+ foreach (QFileInfo entry, entries) {
+ booksFound.append(entry.absoluteFilePath());
}
foreach (QString found, booksFound) {
if (!books.contains(found)) {
- t.trace(QString("New book ") + found);
- emit add(found);
+ toAdd++;
}
}
-
- foreach (QString book, books) {
- QFileInfo bookInfo = QFileInfo(book);
- QString bookDir = bookInfo.absolutePath();
- QString bookPath = bookInfo.absoluteFilePath();
- foreach (QString dirName, directories) {
- t.trace(bookDir + " vs. " + QDir(dirName).absolutePath());
- if (bookDir == QDir(dirName).absolutePath()) {
- if (!booksFound.contains(bookPath)) {
- t.trace(QString("Deleted book ") + bookPath);
- emit remove(bookPath);
- }
- break;
- }
+ emit begin(toAdd);
+ foreach (QString found, booksFound) {
+ if (!books.contains(found)) {
+ qDebug() << "New book" << found;
+ emit add(found);
+ added++;
}
}
+ emit done(added);
}