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
|
|
|
#include "index-status-recorder.h"
|
2022-03-17 15:40:55 +08:00
|
|
|
#include <mutex>
|
2021-05-13 11:17:07 +08:00
|
|
|
|
2021-12-14 14:43:35 +08:00
|
|
|
using namespace UkuiSearch;
|
2022-03-17 15:40:55 +08:00
|
|
|
IndexStatusRecorder *IndexStatusRecorder::m_instance = nullptr;
|
|
|
|
std::once_flag g_IndexStatusRecorderInstanceFlag;
|
2021-05-13 11:17:07 +08:00
|
|
|
IndexStatusRecorder *IndexStatusRecorder::getInstance()
|
|
|
|
{
|
2022-03-17 15:40:55 +08:00
|
|
|
std::call_once(g_IndexStatusRecorderInstanceFlag, [] () {
|
|
|
|
m_instance = new IndexStatusRecorder;
|
|
|
|
});
|
|
|
|
return m_instance;
|
2021-05-13 11:17:07 +08:00
|
|
|
}
|
|
|
|
|
2022-10-26 18:01:40 +08:00
|
|
|
IndexStatusRecorder::IndexStatusRecorder(QObject *parent) : QObject(parent)
|
|
|
|
{
|
|
|
|
m_status = new QSettings(INDEX_STATUS, QSettings::IniFormat, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexStatusRecorder::setStatus(const QString &key, State state)
|
2021-05-13 11:17:07 +08:00
|
|
|
{
|
2021-06-10 20:43:57 +08:00
|
|
|
m_mutex.lock();
|
2022-10-26 18:01:40 +08:00
|
|
|
m_status->setValue(key, state);
|
2021-05-13 11:17:07 +08:00
|
|
|
m_status->sync();
|
2021-06-10 20:43:57 +08:00
|
|
|
m_mutex.unlock();
|
2021-05-13 11:17:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const QVariant IndexStatusRecorder::getStatus(const QString &key)
|
|
|
|
{
|
2022-05-11 18:05:42 +08:00
|
|
|
m_status->sync();
|
2021-05-13 11:17:07 +08:00
|
|
|
return m_status->value(key);
|
|
|
|
}
|
|
|
|
|
2022-03-17 15:40:55 +08:00
|
|
|
bool IndexStatusRecorder::indexDatabaseEnable()
|
|
|
|
{
|
|
|
|
m_mutex.lock();
|
|
|
|
m_status->sync();
|
|
|
|
m_mutex.unlock();
|
2022-10-26 18:01:40 +08:00
|
|
|
if(m_status->value(INDEX_DATABASE_STATE, 0).toInt() == State::Ready) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2022-03-17 15:40:55 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IndexStatusRecorder::contentIndexDatabaseEnable()
|
|
|
|
{
|
|
|
|
m_mutex.lock();
|
|
|
|
m_status->sync();
|
|
|
|
m_mutex.unlock();
|
2022-10-26 18:01:40 +08:00
|
|
|
if(m_status->value(CONTENT_INDEX_DATABASE_STATE, 0).toInt() == State::Ready) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2021-05-13 11:17:07 +08:00
|
|
|
}
|