96 lines
2.8 KiB
C
96 lines
2.8 KiB
C
|
/*
|
|||
|
* 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 "file-watcher.h"
|
|||
|
#include "index-status-recorder.h"
|
|||
|
#include "common.h"
|
|||
|
#include "first-run-indexer.h"
|
|||
|
namespace UkuiSearch {
|
|||
|
|
|||
|
class IndexScheduler : public QObject
|
|||
|
{
|
|||
|
Q_OBJECT
|
|||
|
|
|||
|
public:
|
|||
|
enum IndexerState {
|
|||
|
Startup,
|
|||
|
Running,
|
|||
|
Idle,
|
|||
|
Stop
|
|||
|
};
|
|||
|
Q_ENUM(IndexerState)
|
|||
|
|
|||
|
explicit IndexScheduler(QObject *parent = nullptr);
|
|||
|
/**
|
|||
|
* @brief addNewPath
|
|||
|
* @param folders 要添加索引的目录
|
|||
|
* @param blackList 要添加索引的目录下的黑名单
|
|||
|
*/
|
|||
|
Q_SCRIPTABLE void addNewPath(const QString &folders, const QStringList& blackList = QStringList());
|
|||
|
/**
|
|||
|
* @brief removeIndex
|
|||
|
* @param folders 要移除索引的目录
|
|||
|
*/
|
|||
|
Q_SCRIPTABLE void removeIndex(const QString& folders);
|
|||
|
Q_SCRIPTABLE void stop();
|
|||
|
Q_SCRIPTABLE void scheduleIndexing();
|
|||
|
Q_SCRIPTABLE IndexerState getIndexState();
|
|||
|
|
|||
|
Q_SIGNALS:
|
|||
|
void stateChange(IndexerState);
|
|||
|
void process(IndexType type, uint all, uint finished);
|
|||
|
void basicIndexDone(uint size, bool success);
|
|||
|
void contentIndexDone(uint size, bool success);
|
|||
|
void done();
|
|||
|
|
|||
|
private Q_SLOTS:
|
|||
|
void fileIndexEnable(bool enable);
|
|||
|
void updateIndex(const QVector<PendingFile>& files);
|
|||
|
void firstRunFinished();
|
|||
|
void updateFinished();
|
|||
|
void addNewPathFinished();
|
|||
|
|
|||
|
private:
|
|||
|
/**
|
|||
|
* @brief checkAndRebuild
|
|||
|
* 检查数据库状态,数据库状态处于 IndexStatusRecorder::State::Error 时,开始重建任务。
|
|||
|
* @return 返回需要重建的数据库
|
|||
|
*/
|
|||
|
FirstRunIndexer::Targets checkAndRebuild();
|
|||
|
void startIndexJob(FirstRunIndexer::WorkModes &mode, FirstRunIndexer::Targets &target);
|
|||
|
FileWatcher m_fileWatcher;
|
|||
|
IndexStatusRecorder *m_statusRecorder = nullptr;
|
|||
|
FileIndexerConfig *m_config = nullptr;
|
|||
|
IndexerState m_state;
|
|||
|
QAtomicInt m_stop;
|
|||
|
QThreadPool m_threadPool;
|
|||
|
|
|||
|
bool m_isFirstRunFinished = true;
|
|||
|
bool m_isUpdateFinished = true;
|
|||
|
bool m_isAddNewPathFinished = true;
|
|||
|
};
|
|||
|
}
|
|||
|
#endif // INDEXSCHEDULER_H
|