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>
|
|
|
|
*
|
|
|
|
*/
|
2021-05-13 11:17:07 +08:00
|
|
|
#ifndef INDEXSTATUSRECORDER_H
|
|
|
|
#define INDEXSTATUSRECORDER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QDir>
|
2021-06-10 20:43:57 +08:00
|
|
|
#include <QMutex>
|
2022-12-02 13:48:59 +08:00
|
|
|
#define CONTENT_INDEX_DATABASE_STATE_KEY "content_index_database_state"
|
|
|
|
#define INDEX_DATABASE_STATE_KEY "index_database_state"
|
2021-05-13 11:17:07 +08:00
|
|
|
#define INDEX_STATUS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-index-status.conf"
|
2022-12-02 13:48:59 +08:00
|
|
|
#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 {
|
2021-05-13 11:17:07 +08:00
|
|
|
//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,
|
2023-03-15 16:39:38 +08:00
|
|
|
Updating = 3,
|
|
|
|
Off = 4
|
2022-10-26 18:01:40 +08:00
|
|
|
};
|
|
|
|
Q_ENUM(State)
|
|
|
|
|
2021-05-13 11:17:07 +08:00
|
|
|
static IndexStatusRecorder *getInstance();
|
2022-10-26 18:01:40 +08:00
|
|
|
void setStatus(const QString& key, UkuiSearch::IndexStatusRecorder::State state);
|
2021-05-13 11:17:07 +08:00
|
|
|
const QVariant getStatus(const QString& key);
|
2022-12-02 13:48:59 +08:00
|
|
|
void setVersion(const QString& key, const QString& version);
|
|
|
|
|
|
|
|
bool versionCheck(const QString& key, const QString& version);
|
2022-03-17 15:40:55 +08:00
|
|
|
bool indexDatabaseEnable();
|
|
|
|
bool contentIndexDatabaseEnable();
|
2021-05-13 11:17:07 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
explicit IndexStatusRecorder(QObject *parent = nullptr);
|
2022-03-17 15:40:55 +08:00
|
|
|
static IndexStatusRecorder *m_instance;
|
2022-10-26 18:01:40 +08:00
|
|
|
QSettings *m_status = nullptr;
|
2021-06-10 20:43:57 +08:00
|
|
|
QMutex m_mutex;
|
2021-05-13 11:17:07 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // INDEXSTATUSRECORDER_H
|