ukui-search/libsearch/index/index-scheduler.h

124 lines
4.0 KiB
C
Raw Normal View History

2022-10-26 18:01:40 +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>
*
*/
#ifndef INDEXSCHEDULER_H
#define INDEXSCHEDULER_H
#include <QObject>
#include <QThreadPool>
#include <QAtomicInt>
#include <QEvent>
2022-10-26 18:01:40 +08:00
#include "file-watcher.h"
#include "index-status-recorder.h"
#include "common.h"
#include "batch-indexer.h"
2022-10-26 18:01:40 +08:00
namespace UkuiSearch {
class IndexScheduler : public QObject
{
Q_OBJECT
public:
enum IndexerState {
Startup,
Running,
Idle,
Stop
};
Q_ENUM(IndexerState)
explicit IndexScheduler(QObject *parent = nullptr);
Q_INVOKABLE IndexerState getIndexState();
/**
*
* @param target
*/
Q_INVOKABLE void forceUpdate(BatchIndexer::Targets target);
2022-10-26 18:01:40 +08:00
Q_SIGNALS:
void stateChange(IndexerState);
void process(IndexType type, uint all, uint finished);
void basicIndexDone(bool success);
void contentIndexDone(bool success);
2022-10-26 18:01:40 +08:00
void done();
private Q_SLOTS:
/**
* @brief addNewPath
* @param folders
* @param blackList
*/
void addNewPath(const QString &folders, const QStringList& blackList = QStringList());
/**
* @brief removeIndex
* @param folders
*/
void removeIndex(const QString& folders);
void start(BatchIndexer::Targets target);
void stop(BatchIndexer::Targets target);
2022-10-26 18:01:40 +08:00
void fileIndexEnable(bool enable);
void contentIndexEnable(bool enable);
void ocrContentIndexEnable(bool enable);
2022-10-26 18:01:40 +08:00
void updateIndex(const QVector<PendingFile>& files);
void batchIndexerFinished(BatchIndexer::WorkMode mode, BatchIndexer::Targets targets);
2022-10-26 18:01:40 +08:00
void updateFinished();
bool isIdle();
void onBasicIndexDone(BatchIndexer::WorkMode mode);
void onContentIndexDone(BatchIndexer::WorkMode mode);
void onOcrContentIndexDone(BatchIndexer::WorkMode mode);
void checkIfStartsWaiting();
void installWatches();
2022-10-26 18:01:40 +08:00
private:
/**
* @brief checkAndRebuild
* IndexStatusRecorder::State::Error
* @return
*/
BatchIndexer::Targets checkAndRebuild(BatchIndexer::Targets target = BatchIndexer::All);
void startIndexJob(const QStringList &folders, const QStringList &blackList, BatchIndexer::WorkMode mode, BatchIndexer::Targets target);
2022-10-26 18:01:40 +08:00
FileWatcher m_fileWatcher;
IndexStatusRecorder *m_statusRecorder = nullptr;
FileIndexerConfig *m_config = nullptr;
IndexerState m_state;
QAtomicInt m_indexStop;
QAtomicInt m_contentIndexStop;
QAtomicInt m_ocrContentIndexStop;
2022-10-26 18:01:40 +08:00
QThreadPool m_threadPool;
//等待完成的工作数量
quint64 m_basicIndexPendingWorkCount = 0;
quint64 m_contentIndexPendingWorkCount = 0;
quint64 m_ocrContentIndexPendingWorkCount= 0;
quint64 m_updatePendingWorkCount = 0;
quint64 m_addNewPathPendingWorkCount = 0;
//是否有启动操作正在等待已有工作结束
bool m_basicIndexStartWaiting = false;
bool m_contentIndexStartWaiting = false;
bool m_ocrContentIndexStartWaiting = false;
//监听是否已安装
bool m_watchInstalled = false;
2022-10-26 18:01:40 +08:00
};
}
#endif // INDEXSCHEDULER_H