forked from openkylin/ukui-search
98 lines
2.4 KiB
C++
98 lines
2.4 KiB
C++
|
#include "monitor.h"
|
||
|
#include "file-indexer-config.h"
|
||
|
using namespace UkuiSearch;
|
||
|
Monitor::Monitor(IndexScheduler *scheduler, QObject *parent)
|
||
|
: QObject(parent),
|
||
|
m_scheduler(scheduler),
|
||
|
m_basicDatabase(DataBaseType::Basic),
|
||
|
m_contentDatabase(DataBaseType::Content)
|
||
|
{
|
||
|
connect(scheduler, &IndexScheduler::stateChange, this, &Monitor::indexStateChanged);
|
||
|
connect(scheduler, &IndexScheduler::stateChange, this, &Monitor::onIndexStateChanged);
|
||
|
connect(scheduler, &IndexScheduler::process, this, &Monitor::processUpdate);
|
||
|
}
|
||
|
|
||
|
QStringList Monitor::getCurrentIndexPaths()
|
||
|
{
|
||
|
return FileIndexerConfig::getInstance()->currentIndexableDir();
|
||
|
}
|
||
|
|
||
|
IndexScheduler::IndexerState Monitor::getIndexState()
|
||
|
{
|
||
|
return m_scheduler->getIndexState();
|
||
|
}
|
||
|
|
||
|
uint Monitor::getBasicIndexSize()
|
||
|
{
|
||
|
return m_basicIndexSize;
|
||
|
}
|
||
|
|
||
|
uint Monitor::getContentIndexSize()
|
||
|
{
|
||
|
return m_contentIndexSize;
|
||
|
}
|
||
|
|
||
|
uint Monitor::getOCRIndexSize()
|
||
|
{
|
||
|
return m_ocrIndexSize;
|
||
|
}
|
||
|
|
||
|
uint Monitor::getBasicIndexProgress()
|
||
|
{
|
||
|
return m_basicIndexProgress;
|
||
|
}
|
||
|
|
||
|
uint Monitor::getContentIndexProgress()
|
||
|
{
|
||
|
return m_contentIndexProgress;
|
||
|
}
|
||
|
|
||
|
uint Monitor::getOCRIndexProgress()
|
||
|
{
|
||
|
return m_ocrIndexProgress;
|
||
|
}
|
||
|
|
||
|
uint Monitor::getBasicIndexDocNum()
|
||
|
{
|
||
|
return m_basicDatabase.getIndexDocCount();
|
||
|
}
|
||
|
|
||
|
uint Monitor::getContentIndexDocNum()
|
||
|
{
|
||
|
return m_contentDatabase.getIndexDocCount();
|
||
|
}
|
||
|
|
||
|
void Monitor::onIndexStateChanged(IndexScheduler::IndexerState state)
|
||
|
{
|
||
|
if(state == IndexScheduler::IndexerState::Idle) {
|
||
|
Q_EMIT basicIndexDocNumUpdate(m_basicDatabase.getIndexDocCount());
|
||
|
Q_EMIT contentIndexDocNumUpdate(m_contentDatabase.getIndexDocCount());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Monitor::processUpdate(IndexType type, uint all, uint finished)
|
||
|
{
|
||
|
switch (type) {
|
||
|
case IndexType::Basic:
|
||
|
m_basicIndexSize = all;
|
||
|
Q_EMIT basicIndexSizeChange(m_basicIndexSize);
|
||
|
m_basicIndexProgress = finished;
|
||
|
Q_EMIT basicIndexProgressUpdate(m_basicIndexProgress);
|
||
|
break;
|
||
|
case IndexType::Contents:
|
||
|
m_contentIndexSize = all;
|
||
|
Q_EMIT contentIndexSizeChange(m_contentIndexSize);
|
||
|
m_contentIndexProgress = finished;
|
||
|
Q_EMIT contentIndexProgressUpdate(m_contentIndexProgress);
|
||
|
break;
|
||
|
case IndexType::OCR:
|
||
|
m_ocrIndexSize = all;
|
||
|
Q_EMIT ocrIndexSizeChange(m_ocrIndexSize);
|
||
|
m_contentIndexProgress = finished;
|
||
|
Q_EMIT ocrIndexProgressUpdate(m_contentIndexProgress);
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|