diff --git a/shared/filescanworker.cpp b/shared/filescanworker.cpp new file mode 100644 index 0000000..a4fb25d --- /dev/null +++ b/shared/filescanworker.cpp @@ -0,0 +1,29 @@ +#include "filescanworker.h" +#include "logger.h" +FileScanWorker::FileScanWorker(SqliteDbService &db, ConcurrentQueue &queue, int batchsize) +{ + this->dbService = &db; + this->queue = &queue; + this->batchsize = batchsize; +} + +void FileScanWorker::run() +{ + FileSaver saver{*this->dbService}; + auto paths = queue->dequeue(batchsize); + for(QString &path : paths) + { + SaveFileResult sfr; + try + { + sfr = saver.addFile(path); + } + catch(std::runtime_error &e) + { + Logger::error() << e.what(); + sfr = PROCESSFAIL; // well... + } + emit result({path, sfr}); + } + emit finished(); +} diff --git a/shared/filescanworker.h b/shared/filescanworker.h new file mode 100644 index 0000000..58ec691 --- /dev/null +++ b/shared/filescanworker.h @@ -0,0 +1,28 @@ +#ifndef FILESCANWORKER_H +#define FILESCANWORKER_H +#include +#include +#include +#include +#include "paralleldirscanner.h" +#include "filesaver.h" + +typedef std::pair FileScanResult; + +class FileScanWorker : public QObject, public QRunnable +{ + Q_OBJECT + protected: + SqliteDbService *dbService; + ConcurrentQueue *queue; + int batchsize; + + public: + FileScanWorker(SqliteDbService &db, ConcurrentQueue &queue, int batchsize); + void run() override; + signals: + void result(FileScanResult); + void finished(); +}; + +#endif // FILESCANWORKER_H