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

59 lines
1.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 INDEXSTATUSRECORDER_H
#define INDEXSTATUSRECORDER_H
#include <QObject>
#include <QSettings>
#include <QDir>
#include <QMutex>
#define CONTENT_INDEX_DATABASE_STATE "content_index_database_state"
#define INDEX_DATABASE_STATE "index_database_state"
#define INDEX_STATUS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-index-status.conf"
namespace UkuiSearch {
//fixme: we need a better way to record index status.
class IndexStatusRecorder : public QObject
{
Q_OBJECT
public:
enum State{
Initializing = 0,
Error = 1,
Ready = 2,
Updating = 3
};
Q_ENUM(State)
static IndexStatusRecorder *getInstance();
void setStatus(const QString& key, UkuiSearch::IndexStatusRecorder::State state);
const QVariant getStatus(const QString& key);
bool indexDatabaseEnable();
bool contentIndexDatabaseEnable();
private:
explicit IndexStatusRecorder(QObject *parent = nullptr);
static IndexStatusRecorder *m_instance;
QSettings *m_status = nullptr;
QMutex m_mutex;
};
}
#endif // INDEXSTATUSRECORDER_H