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

77 lines
2.1 KiB
C++
Raw 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>
*
*/
#include "index-status-recorder.h"
#include <mutex>
2021-12-14 14:43:35 +08:00
using namespace UkuiSearch;
IndexStatusRecorder *IndexStatusRecorder::m_instance = nullptr;
std::once_flag g_IndexStatusRecorderInstanceFlag;
IndexStatusRecorder *IndexStatusRecorder::getInstance()
{
std::call_once(g_IndexStatusRecorderInstanceFlag, [] () {
m_instance = new IndexStatusRecorder;
});
return m_instance;
}
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)
{
m_mutex.lock();
2022-10-26 18:01:40 +08:00
m_status->setValue(key, state);
m_status->sync();
m_mutex.unlock();
}
const QVariant IndexStatusRecorder::getStatus(const QString &key)
{
m_status->sync();
return m_status->value(key);
}
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;
}
}
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;
}
}