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 FIRSTRUNINDEXER_H
|
|
|
|
#define FIRSTRUNINDEXER_H
|
|
|
|
|
|
|
|
#include <QRunnable>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QAtomicInt>
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
namespace UkuiSearch {
|
2022-12-15 16:13:16 +08:00
|
|
|
class BatchIndexer : public QObject, public QRunnable
|
2022-10-26 18:01:40 +08:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief The WorkMode enum
|
|
|
|
* Update 增量更新
|
|
|
|
* Add 增加索引目录
|
|
|
|
* Rebuild 删除并重建数据库
|
|
|
|
*/
|
|
|
|
enum WorkMode{
|
|
|
|
Update = 0,
|
|
|
|
Add = 1,
|
|
|
|
Rebuild
|
|
|
|
};
|
2022-12-09 16:30:58 +08:00
|
|
|
Q_ENUM(WorkMode)
|
2022-10-26 18:01:40 +08:00
|
|
|
/**
|
|
|
|
* @brief The Target enum
|
|
|
|
* 要进行索引的数据库
|
|
|
|
* All 所有数据库
|
|
|
|
* Basic 基础索引数据库
|
|
|
|
* Content 内容索引数据库
|
|
|
|
*/
|
|
|
|
enum Target{
|
|
|
|
None = 0,
|
|
|
|
Basic = 1u << 0,
|
|
|
|
Content = 1u << 1,
|
|
|
|
All = Basic | Content
|
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(Targets, Target)
|
|
|
|
|
2023-08-03 09:09:18 +08:00
|
|
|
BatchIndexer(const QStringList& folders,
|
|
|
|
const QStringList& blackList,
|
|
|
|
QAtomicInt& indexStop,
|
|
|
|
QAtomicInt& contentIndexStop,
|
|
|
|
WorkMode mode = WorkMode::Update,
|
|
|
|
Targets target = Target::All);
|
2022-10-26 18:01:40 +08:00
|
|
|
void run() override;
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void progress(IndexType type, uint all, uint finished);
|
2023-08-03 09:09:18 +08:00
|
|
|
void basicIndexDone(WorkMode);
|
|
|
|
void contentIndexDone(WorkMode);
|
|
|
|
void done(WorkMode, Targets);
|
2022-10-26 18:01:40 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
void fetch();
|
|
|
|
void basicIndex();
|
|
|
|
void contentIndex();
|
|
|
|
|
|
|
|
QStringList m_folders;
|
|
|
|
QStringList m_blackList;
|
2023-08-03 09:09:18 +08:00
|
|
|
QAtomicInt *m_indexStop = nullptr;
|
|
|
|
QAtomicInt *m_contentIndexStop = nullptr;
|
2022-12-15 16:13:16 +08:00
|
|
|
WorkMode m_mode;
|
|
|
|
Targets m_target;
|
|
|
|
QStringList m_cache;
|
2022-10-26 18:01:40 +08:00
|
|
|
};
|
2022-12-15 16:13:16 +08:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(BatchIndexer::Targets)
|
2022-10-26 18:01:40 +08:00
|
|
|
}
|
|
|
|
#endif // FIRSTRUNINDEXER_H
|