2022-12-09 16:30:58 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2022, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: iaom <zhangpengfei@kylinos.cn>
|
|
|
|
*
|
|
|
|
*/
|
2022-10-26 18:01:40 +08:00
|
|
|
#include "monitor.h"
|
2022-12-09 16:30:58 +08:00
|
|
|
#include <QMetaEnum>
|
2022-10-26 18:01:40 +08:00
|
|
|
#include "file-indexer-config.h"
|
|
|
|
using namespace UkuiSearch;
|
2023-10-07 15:44:59 +08:00
|
|
|
Monitor::Monitor(IndexScheduler *scheduler, QObject *parent) : MonitorSource(parent),
|
|
|
|
m_scheduler(scheduler),
|
|
|
|
m_basicDatabase(DataBaseType::Basic),
|
|
|
|
m_contentDatabase(DataBaseType::Content),
|
|
|
|
m_ocrContentDatabase(DataBaseType::OcrContent)
|
2022-10-26 18:01:40 +08:00
|
|
|
{
|
|
|
|
connect(scheduler, &IndexScheduler::stateChange, this, &Monitor::onIndexStateChanged);
|
|
|
|
connect(scheduler, &IndexScheduler::process, this, &Monitor::processUpdate);
|
2022-12-09 16:30:58 +08:00
|
|
|
connect(scheduler, &IndexScheduler::basicIndexDone, this, &Monitor::basicIndexDone);
|
|
|
|
connect(scheduler, &IndexScheduler::contentIndexDone, this, &Monitor::contentIndexDone);
|
2023-10-07 15:44:59 +08:00
|
|
|
connect(FileIndexerConfig::getInstance(), &FileIndexerConfig::appendIndexDir, this, [&](){
|
2023-10-09 10:27:29 +08:00
|
|
|
m_currentIndexPaths = FileIndexerConfig::getInstance()->currentIndexableDir();
|
|
|
|
Q_EMIT currentIndexPathsChanged(m_currentIndexPaths);
|
2023-10-07 15:44:59 +08:00
|
|
|
});
|
|
|
|
connect(FileIndexerConfig::getInstance(), &FileIndexerConfig::removeIndexDir, this, [&](){
|
2023-10-09 10:27:29 +08:00
|
|
|
m_currentIndexPaths = FileIndexerConfig::getInstance()->currentIndexableDir();
|
|
|
|
Q_EMIT currentIndexPathsChanged(m_currentIndexPaths);
|
2023-10-07 15:44:59 +08:00
|
|
|
});
|
2022-10-26 18:01:40 +08:00
|
|
|
}
|
|
|
|
|
2023-10-07 15:44:59 +08:00
|
|
|
QStringList Monitor::currentIndexPaths() const
|
2022-10-26 18:01:40 +08:00
|
|
|
{
|
|
|
|
return FileIndexerConfig::getInstance()->currentIndexableDir();
|
|
|
|
}
|
|
|
|
|
2023-10-07 15:44:59 +08:00
|
|
|
QString Monitor::indexState() const
|
2022-10-26 18:01:40 +08:00
|
|
|
{
|
2022-12-09 16:30:58 +08:00
|
|
|
QMetaEnum metaEnum = QMetaEnum::fromType<IndexScheduler::IndexerState>();
|
|
|
|
return QString::fromLocal8Bit(metaEnum.valueToKey(m_scheduler->getIndexState()));
|
2022-10-26 18:01:40 +08:00
|
|
|
}
|
|
|
|
|
2023-10-07 15:44:59 +08:00
|
|
|
uint Monitor::basicIndexSize() const
|
2022-10-26 18:01:40 +08:00
|
|
|
{
|
|
|
|
return m_basicIndexSize;
|
|
|
|
}
|
|
|
|
|
2023-10-07 15:44:59 +08:00
|
|
|
uint Monitor::contentIndexSize() const
|
2022-10-26 18:01:40 +08:00
|
|
|
{
|
|
|
|
return m_contentIndexSize;
|
|
|
|
}
|
|
|
|
|
2023-10-07 15:44:59 +08:00
|
|
|
uint Monitor::ocrIndexSize() const
|
2022-10-26 18:01:40 +08:00
|
|
|
{
|
|
|
|
return m_ocrIndexSize;
|
|
|
|
}
|
|
|
|
|
2023-10-07 15:44:59 +08:00
|
|
|
uint Monitor::basicIndexProgress() const
|
2022-10-26 18:01:40 +08:00
|
|
|
{
|
|
|
|
return m_basicIndexProgress;
|
|
|
|
}
|
|
|
|
|
2023-10-07 15:44:59 +08:00
|
|
|
uint Monitor::contentIndexProgress() const
|
2022-10-26 18:01:40 +08:00
|
|
|
{
|
|
|
|
return m_contentIndexProgress;
|
|
|
|
}
|
|
|
|
|
2023-10-07 15:44:59 +08:00
|
|
|
uint Monitor::ocrIndexProgress() const
|
2022-10-26 18:01:40 +08:00
|
|
|
{
|
|
|
|
return m_ocrIndexProgress;
|
|
|
|
}
|
|
|
|
|
2023-10-07 15:44:59 +08:00
|
|
|
uint Monitor::basicIndexDocNum() const
|
2022-10-26 18:01:40 +08:00
|
|
|
{
|
2023-10-09 10:27:29 +08:00
|
|
|
return m_basicIndexDocNum;
|
2022-10-26 18:01:40 +08:00
|
|
|
}
|
|
|
|
|
2023-10-07 15:44:59 +08:00
|
|
|
uint Monitor::contentIndexDocNum() const
|
2022-10-26 18:01:40 +08:00
|
|
|
{
|
2023-10-09 10:27:29 +08:00
|
|
|
return m_contentIndexDocNum;
|
2022-10-26 18:01:40 +08:00
|
|
|
}
|
|
|
|
|
2023-10-07 15:44:59 +08:00
|
|
|
uint Monitor::ocrContentIndexDocNum() const
|
|
|
|
{
|
2023-10-09 10:27:29 +08:00
|
|
|
return m_ocrContentIndexDocNum;
|
2023-10-07 15:44:59 +08:00
|
|
|
}
|
|
|
|
|
2022-10-26 18:01:40 +08:00
|
|
|
void Monitor::onIndexStateChanged(IndexScheduler::IndexerState state)
|
|
|
|
{
|
2023-10-09 10:27:29 +08:00
|
|
|
if(state == IndexScheduler::IndexerState::Idle || state == IndexScheduler::IndexerState::Stop) {
|
|
|
|
m_basicIndexDocNum = m_basicDatabase.getIndexDocCount();
|
|
|
|
Q_EMIT basicIndexDocNumChanged(m_basicIndexDocNum);
|
|
|
|
m_contentIndexDocNum = m_contentDatabase.getIndexDocCount();
|
|
|
|
Q_EMIT contentIndexDocNumChanged(m_contentIndexDocNum);
|
|
|
|
m_ocrContentIndexDocNum = m_ocrContentDatabase.getIndexDocCount();
|
|
|
|
Q_EMIT ocrContentIndexDocNumChanged(m_ocrContentDatabase.getIndexDocCount());
|
2022-10-26 18:01:40 +08:00
|
|
|
}
|
2022-12-09 16:30:58 +08:00
|
|
|
QMetaEnum metaEnum = QMetaEnum::fromType<IndexScheduler::IndexerState>();
|
|
|
|
Q_EMIT indexStateChanged(QString::fromLocal8Bit(metaEnum.valueToKey(state)));
|
2022-10-26 18:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Monitor::processUpdate(IndexType type, uint all, uint finished)
|
|
|
|
{
|
|
|
|
switch (type) {
|
2023-10-09 10:27:29 +08:00
|
|
|
case IndexType::Basic:
|
|
|
|
m_basicIndexSize = all;
|
|
|
|
Q_EMIT basicIndexSizeChanged(m_basicIndexSize);
|
|
|
|
m_basicIndexProgress = finished;
|
|
|
|
Q_EMIT basicIndexProgressChanged(m_basicIndexProgress);
|
|
|
|
m_basicIndexDocNum = m_basicDatabase.getIndexDocCount();
|
|
|
|
Q_EMIT basicIndexDocNumChanged(m_basicIndexDocNum);
|
|
|
|
break;
|
|
|
|
case IndexType::Contents:
|
|
|
|
m_contentIndexSize = all;
|
|
|
|
Q_EMIT contentIndexSizeChanged(m_contentIndexSize);
|
|
|
|
m_contentIndexProgress = finished;
|
|
|
|
Q_EMIT contentIndexProgressChanged(m_contentIndexProgress);
|
|
|
|
m_contentIndexDocNum = m_contentDatabase.getIndexDocCount();
|
|
|
|
Q_EMIT contentIndexDocNumChanged(m_contentIndexDocNum);
|
|
|
|
break;
|
|
|
|
case IndexType::OCR:
|
|
|
|
m_ocrIndexSize = all;
|
|
|
|
Q_EMIT ocrIndexSizeChanged(m_ocrIndexSize);
|
2023-11-08 10:08:04 +08:00
|
|
|
m_ocrIndexProgress = finished;
|
|
|
|
Q_EMIT ocrIndexProgressChanged(m_ocrIndexProgress);
|
2023-10-09 10:27:29 +08:00
|
|
|
m_ocrContentIndexDocNum = m_ocrContentDatabase.getIndexDocCount();
|
|
|
|
Q_EMIT ocrContentIndexDocNumChanged(m_ocrContentDatabase.getIndexDocCount());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2022-10-26 18:01:40 +08:00
|
|
|
}
|
|
|
|
}
|