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
|
|
|
}
|
|
|
|
|
|
|
|
void IndexStatusRecorder::setStatus(const QString &key, const QVariant &value)
|
|
|
|
{
|
2021-06-10 20:43:57 +08:00
|
|
|
m_mutex.lock();
|
2021-05-13 11:17:07 +08:00
|
|
|
m_status->setValue(key, value);
|
|
|
|
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();
|
|
|
|
return m_status->value(INDEX_DATABASE_STATE, QVariant(false)).toBool();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IndexStatusRecorder::contentIndexDatabaseEnable()
|
|
|
|
{
|
|
|
|
m_mutex.lock();
|
|
|
|
m_status->sync();
|
|
|
|
m_mutex.unlock();
|
|
|
|
return m_status->value(CONTENT_INDEX_DATABASE_STATE, QVariant(false)).toBool();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IndexStatusRecorder::ocrDatabaseEnable()
|
|
|
|
{
|
|
|
|
m_mutex.lock();
|
|
|
|
m_status->sync();
|
|
|
|
m_mutex.unlock();
|
|
|
|
return m_status->value(OCR_DATABASE_STATE, QVariant(false)).toBool();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-05-13 11:17:07 +08:00
|
|
|
IndexStatusRecorder::IndexStatusRecorder(QObject *parent) : QObject(parent)
|
|
|
|
{
|
|
|
|
m_status = new QSettings(INDEX_STATUS, QSettings::IniFormat, this);
|
|
|
|
}
|