Simplify QWasmIDBSettingsPrivate
Since QWasmIDBSettingsPrivate is only supported on JSPI now, there is no need to maintain the isReadReady flag anymore. This lets us simplify the class a lot. Change-Id: I67322389463af13b5110091a4f8433f08da19925 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>bb10
parent
381d6210c2
commit
322e2a2821
|
|
@ -236,26 +236,17 @@ public:
|
|||
const QString &application);
|
||||
~QWasmIDBSettingsPrivate();
|
||||
|
||||
std::optional<QVariant> get(const QString &key) const override;
|
||||
QStringList children(const QString &prefix, ChildSpec spec) const override;
|
||||
void clear() override;
|
||||
void sync() override;
|
||||
void flush() override;
|
||||
bool isWritable() const override;
|
||||
void initAccess() override;
|
||||
|
||||
void loadLocal();
|
||||
void setReady();
|
||||
|
||||
private:
|
||||
bool writeSettingsToTemporaryFile(void *dataPtr, int size);
|
||||
bool writeSettingsToTemporaryFile(const QString &fileName, void *dataPtr, int size);
|
||||
|
||||
QString databaseName;
|
||||
QString id;
|
||||
};
|
||||
|
||||
static bool isReadReady = false;
|
||||
|
||||
constexpr char DbName[] = "/home/web_user";
|
||||
|
||||
QWasmIDBSettingsPrivate::QWasmIDBSettingsPrivate(QSettings::Scope scope,
|
||||
|
|
@ -270,7 +261,6 @@ QWasmIDBSettingsPrivate::QWasmIDBSettingsPrivate(QSettings::Scope scope,
|
|||
return;
|
||||
}
|
||||
|
||||
setStatus(QSettings::AccessError); // access error until sandbox gets loaded
|
||||
databaseName = organization;
|
||||
id = application;
|
||||
|
||||
|
|
@ -285,35 +275,23 @@ QWasmIDBSettingsPrivate::QWasmIDBSettingsPrivate(QSettings::Scope scope,
|
|||
void *contents;
|
||||
int size;
|
||||
emscripten_idb_load(DbName, fileName().toLocal8Bit(), &contents, &size, &error);
|
||||
if (error || !writeSettingsToTemporaryFile(contents, size)) {
|
||||
if (error || !writeSettingsToTemporaryFile(fileName(), contents, size)) {
|
||||
setStatus(QSettings::AccessError);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setReady();
|
||||
QConfFileSettingsPrivate::initAccess();
|
||||
}
|
||||
|
||||
QWasmIDBSettingsPrivate::~QWasmIDBSettingsPrivate() = default;
|
||||
|
||||
void QWasmIDBSettingsPrivate::initAccess()
|
||||
{
|
||||
if (isReadReady)
|
||||
QConfFileSettingsPrivate::initAccess();
|
||||
}
|
||||
bool QWasmIDBSettingsPrivate::writeSettingsToTemporaryFile(const QString &fileName, void *dataPtr,
|
||||
int size)
|
||||
|
||||
std::optional<QVariant> QWasmIDBSettingsPrivate::get(const QString &key) const
|
||||
{
|
||||
if (isReadReady)
|
||||
return QConfFileSettingsPrivate::get(key);
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool QWasmIDBSettingsPrivate::writeSettingsToTemporaryFile(void *dataPtr, int size)
|
||||
{
|
||||
QFile file(fileName());
|
||||
QFileInfo fileInfo(fileName());
|
||||
QFile file(fileName);
|
||||
QFileInfo fileInfo(fileName);
|
||||
QDir dir(fileInfo.path());
|
||||
if (!dir.exists())
|
||||
dir.mkpath(fileInfo.path());
|
||||
|
|
@ -324,11 +302,6 @@ bool QWasmIDBSettingsPrivate::writeSettingsToTemporaryFile(void *dataPtr, int si
|
|||
return size == file.write(reinterpret_cast<char *>(dataPtr), size);
|
||||
}
|
||||
|
||||
QStringList QWasmIDBSettingsPrivate::children(const QString &prefix, ChildSpec spec) const
|
||||
{
|
||||
return QConfFileSettingsPrivate::children(prefix, spec);
|
||||
}
|
||||
|
||||
void QWasmIDBSettingsPrivate::clear()
|
||||
{
|
||||
QConfFileSettingsPrivate::clear();
|
||||
|
|
@ -359,18 +332,6 @@ void QWasmIDBSettingsPrivate::flush()
|
|||
sync();
|
||||
}
|
||||
|
||||
bool QWasmIDBSettingsPrivate::isWritable() const
|
||||
{
|
||||
return isReadReady && QConfFileSettingsPrivate::isWritable();
|
||||
}
|
||||
|
||||
void QWasmIDBSettingsPrivate::setReady()
|
||||
{
|
||||
isReadReady = true;
|
||||
setStatus(QSettings::NoError);
|
||||
QConfFileSettingsPrivate::initAccess();
|
||||
}
|
||||
|
||||
QSettingsPrivate *QSettingsPrivate::create(QSettings::Format format, QSettings::Scope scope,
|
||||
const QString &organization, const QString &application)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue