shared: Begin FileScanWorker
This commit is contained in:
rodzic
d7705241ee
commit
564b5ddae8
29
shared/filescanworker.cpp
Normal file
29
shared/filescanworker.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include "filescanworker.h"
|
||||||
|
#include "logger.h"
|
||||||
|
FileScanWorker::FileScanWorker(SqliteDbService &db, ConcurrentQueue<QString> &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();
|
||||||
|
}
|
28
shared/filescanworker.h
Normal file
28
shared/filescanworker.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#ifndef FILESCANWORKER_H
|
||||||
|
#define FILESCANWORKER_H
|
||||||
|
#include <QString>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QtConcurrent>
|
||||||
|
#include <utility>
|
||||||
|
#include "paralleldirscanner.h"
|
||||||
|
#include "filesaver.h"
|
||||||
|
|
||||||
|
typedef std::pair<QString, SaveFileResult> FileScanResult;
|
||||||
|
|
||||||
|
class FileScanWorker : public QObject, public QRunnable
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
protected:
|
||||||
|
SqliteDbService *dbService;
|
||||||
|
ConcurrentQueue<QString> *queue;
|
||||||
|
int batchsize;
|
||||||
|
|
||||||
|
public:
|
||||||
|
FileScanWorker(SqliteDbService &db, ConcurrentQueue<QString> &queue, int batchsize);
|
||||||
|
void run() override;
|
||||||
|
signals:
|
||||||
|
void result(FileScanResult);
|
||||||
|
void finished();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FILESCANWORKER_H
|
Ładowanie…
Reference in New Issue
Block a user