ukui-search/libsearch/index/index-status-recorder.h

65 lines
2.1 KiB
C
Raw Permalink 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 INDEXSTATUSRECORDER_H
#define INDEXSTATUSRECORDER_H
#include <QObject>
#include <QSettings>
#include <QDir>
#include <QMutex>
#define CONTENT_INDEX_DATABASE_STATE_KEY "content_index_database_state"
#define INDEX_DATABASE_STATE_KEY "index_database_state"
#define INDEX_STATUS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-index-status.conf"
#define INDEX_DATABASE_VERSION_KEY "index_database_version"
#define CONTENT_DATABASE_VERSION_KEY "content_database_version"
2021-12-14 14:43:35 +08:00
namespace UkuiSearch {
//fixme: we need a better way to record index status.
class IndexStatusRecorder : public QObject
{
Q_OBJECT
public:
2022-10-26 18:01:40 +08:00
enum State{
Initializing = 0,
Error = 1,
Ready = 2,
2024-01-26 14:31:56 +08:00
Updating = 3,
Off = 4
2022-10-26 18:01:40 +08:00
};
Q_ENUM(State)
static IndexStatusRecorder *getInstance();
2022-10-26 18:01:40 +08:00
void setStatus(const QString& key, UkuiSearch::IndexStatusRecorder::State state);
const QVariant getStatus(const QString& key);
void setVersion(const QString& key, const QString& version);
bool versionCheck(const QString& key, const QString& version);
bool indexDatabaseEnable();
bool contentIndexDatabaseEnable();
private:
explicit IndexStatusRecorder(QObject *parent = nullptr);
static IndexStatusRecorder *m_instance;
2022-10-26 18:01:40 +08:00
QSettings *m_status = nullptr;
QMutex m_mutex;
};
}
#endif // INDEXSTATUSRECORDER_H