looqs/shared/indexer.h

104 wiersze
2.4 KiB
C
Czysty Zwykły widok Historia

2022-04-14 14:58:27 +02:00
#ifndef INDEXER_H
#define INDEXER_H
#include <QVector>
#include <QObject>
#include "sqlitedbservice.h"
#include "paralleldirscanner.h"
#include "filescanworker.h"
class IndexResult
{
public:
QDateTime begin;
QDateTime end;
QVector<FileScanResult> results;
unsigned int addedPaths = 0;
unsigned int skippedPaths = 0;
unsigned int erroredPaths = 0;
unsigned int total()
{
return addedPaths + skippedPaths + erroredPaths;
}
QVector<FileScanResult> failedResults() const
2022-04-14 14:58:27 +02:00
{
QVector<FileScanResult> result;
2022-04-14 14:58:27 +02:00
std::for_each(results.begin(), results.end(),
[&result](FileScanResult res)
{
if(res.second == DBFAIL || res.second == PROCESSFAIL || res.second == NOTFOUND ||
res.second == NOACCESS)
2022-04-14 14:58:27 +02:00
{
result.append(res);
2022-04-14 14:58:27 +02:00
}
});
return result;
}
QVector<QString> failedPaths() const
{
QVector<QString> result;
QVector<FileScanResult> results = failedResults();
std::for_each(results.begin(), results.end(), [&result](FileScanResult res) { result.append(res.first); });
return result;
}
2022-04-14 14:58:27 +02:00
};
class Indexer : public QObject
{
Q_OBJECT
protected:
bool verbose = false;
bool keepGoing = true;
SqliteDbService *db;
int progressReportThreshold = 50;
int currentScanProcessedCount = 0;
int runningWorkers = 0;
QVector<QString> pathsToScan;
QSharedPointer<ParallelDirScanner> dirScanner;
QStringList ignorePattern;
/* Those path pointing to files not directories */
ConcurrentQueue<QString> filePathTargetsQueue;
2022-04-15 21:06:19 +02:00
std::atomic<bool> workerCancellationToken;
2022-04-14 14:58:27 +02:00
IndexResult currentIndexResult;
void launchWorker(ConcurrentQueue<QString> &queue, int batchsize);
public:
2022-04-15 21:06:19 +02:00
bool isRunning();
2022-04-14 14:58:27 +02:00
void beginIndexing();
void setIgnorePattern(QStringList ignorePattern);
void setTargetPaths(QVector<QString> pathsToScan);
void setVerbose(bool verbose);
void setKeepGoing(bool keepGoing);
2022-04-14 14:58:27 +02:00
2022-04-15 21:06:19 +02:00
void requestCancellation();
2022-04-14 14:58:27 +02:00
Indexer(SqliteDbService &db);
IndexResult getResult();
public slots:
void dirScanFinished();
void dirScanProgress(int current, int total);
void processFileScanResult(FileScanResult result);
void processFinishedWorker();
signals:
void pathsCountChanged(int total);
void fileScanResult(FileScanResult *result);
void indexProgress(unsigned int processedFiles, unsigned int added, unsigned int skipped, unsigned int failed,
unsigned int totalPaths);
void finished();
};
#endif // INDEXER_H