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>
|
2024-01-23 11:18:55 +08:00
|
|
|
|
#include <QEvent>
|
2022-10-26 18:01:40 +08:00
|
|
|
|
#include "file-watcher.h"
|
|
|
|
|
#include "index-status-recorder.h"
|
|
|
|
|
#include "common.h"
|
2022-12-15 16:13:16 +08:00
|
|
|
|
#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);
|
2023-08-03 09:09:18 +08:00
|
|
|
|
|
2024-01-23 11:18:55 +08:00
|
|
|
|
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);
|
2023-08-03 09:09:18 +08:00
|
|
|
|
void basicIndexDone(bool success);
|
|
|
|
|
void contentIndexDone(bool success);
|
2022-10-26 18:01:40 +08:00
|
|
|
|
void done();
|
|
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
2023-09-28 10:54:58 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief addNewPath
|
|
|
|
|
* @param folders 要添加索引的目录
|
|
|
|
|
* @param blackList 要添加索引的目录下的黑名单
|
|
|
|
|
*/
|
2024-01-23 11:18:55 +08:00
|
|
|
|
void addNewPath(const QString &folders, const QStringList& blackList = QStringList());
|
2023-09-28 10:54:58 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief removeIndex
|
|
|
|
|
* @param folders 要移除索引的目录
|
|
|
|
|
*/
|
2024-01-23 11:18:55 +08:00
|
|
|
|
void removeIndex(const QString& folders);
|
2023-08-03 09:09:18 +08:00
|
|
|
|
void start(BatchIndexer::Targets target);
|
|
|
|
|
void stop(BatchIndexer::Targets target);
|
2022-10-26 18:01:40 +08:00
|
|
|
|
void fileIndexEnable(bool enable);
|
2023-08-03 09:09:18 +08:00
|
|
|
|
void contentIndexEnable(bool enable);
|
2023-09-28 10:54:58 +08:00
|
|
|
|
void ocrContentIndexEnable(bool enable);
|
2022-10-26 18:01:40 +08:00
|
|
|
|
void updateIndex(const QVector<PendingFile>& files);
|
2023-09-28 10:54:58 +08:00
|
|
|
|
void batchIndexerFinished(BatchIndexer::WorkMode mode, BatchIndexer::Targets targets);
|
2022-10-26 18:01:40 +08:00
|
|
|
|
void updateFinished();
|
2022-12-09 16:30:58 +08:00
|
|
|
|
bool isIdle();
|
2023-08-03 09:09:18 +08:00
|
|
|
|
void onBasicIndexDone(BatchIndexer::WorkMode mode);
|
|
|
|
|
void onContentIndexDone(BatchIndexer::WorkMode mode);
|
2023-09-28 10:54:58 +08:00
|
|
|
|
void onOcrContentIndexDone(BatchIndexer::WorkMode mode);
|
2024-01-23 11:18:55 +08:00
|
|
|
|
void checkIfStartsWaiting();
|
|
|
|
|
void installWatches();
|
2022-10-26 18:01:40 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/**
|
|
|
|
|
* @brief checkAndRebuild
|
|
|
|
|
* 检查数据库状态,数据库状态处于 IndexStatusRecorder::State::Error 时,开始重建任务。
|
|
|
|
|
* @return 返回需要重建的数据库
|
|
|
|
|
*/
|
2023-08-03 09:09:18 +08:00
|
|
|
|
BatchIndexer::Targets checkAndRebuild(BatchIndexer::Targets target = BatchIndexer::All);
|
2022-12-15 16:13:16 +08:00
|
|
|
|
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;
|
2023-08-03 09:09:18 +08:00
|
|
|
|
QAtomicInt m_indexStop;
|
|
|
|
|
QAtomicInt m_contentIndexStop;
|
2023-09-28 10:54:58 +08:00
|
|
|
|
QAtomicInt m_ocrContentIndexStop;
|
2022-10-26 18:01:40 +08:00
|
|
|
|
QThreadPool m_threadPool;
|
|
|
|
|
|
2024-01-23 11:18:55 +08:00
|
|
|
|
//等待完成的工作数量
|
|
|
|
|
quint64 m_basicIndexPendingWorkCount = 0;
|
2023-09-28 10:54:58 +08:00
|
|
|
|
quint64 m_contentIndexPendingWorkCount = 0;
|
|
|
|
|
quint64 m_ocrContentIndexPendingWorkCount= 0;
|
|
|
|
|
quint64 m_updatePendingWorkCount = 0;
|
|
|
|
|
quint64 m_addNewPathPendingWorkCount = 0;
|
2024-01-23 11:18:55 +08:00
|
|
|
|
|
|
|
|
|
//是否有启动操作正在等待已有工作结束
|
|
|
|
|
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
|