Fix forward navigation control on Linux.
[dorian] / model / bookfinder.cpp
1 #include <QFileInfoList>
2 #include <QStringList>
3 #include <QDir>
4
5 #include "bookfinder.h"
6 #include "trace.h"
7
8 BookFinder::BookFinder(QObject *parent): QObject(parent)
9 {
10 }
11
12 void BookFinder::find(const QString &path, const QStringList &books)
13 {
14     TRACE;
15     QStringList booksFound;
16     int toAdd = 0;
17     int added = 0;
18
19     QStringList filters(QString("*.epub"));
20     QFileInfoList entries =
21             QDir(path).entryInfoList(filters, QDir::Files | QDir::Readable);
22     foreach (QFileInfo entry, entries) {
23         booksFound.append(entry.absoluteFilePath());
24     }
25
26     foreach (QString found, booksFound) {
27         if (!books.contains(found)) {
28             toAdd++;
29         }
30     }
31     emit begin(toAdd);
32     foreach (QString found, booksFound) {
33         if (!books.contains(found)) {
34             qDebug() << "New book" << found;
35             emit add(found);
36             added++;
37         }
38     }
39     emit done(added);
40 }