13#include <QtCore/private/qstdweb_p.h>
20#include <emscripten.h>
21# include <emscripten/proxying.h>
22# include <emscripten/threading.h>
23# include <emscripten/val.h>
34 if (!prefixedStorageName.startsWith(prefix))
36 return prefixedStorageName.sliced(prefix.
length());
71 if (organization.isEmpty()) {
95 const QString prefix =
"qt-v0-" + escapedOrganization + separator;
97 if (!escapedApplication.isEmpty())
98 m_keyPrefixes.push_back(prefix + escapedApplication + separator);
99 m_keyPrefixes.push_back(prefix + allAppsSetting + separator);
101 if (!escapedApplication.isEmpty()) {
102 m_keyPrefixes.push_back(prefix + escapedApplication + separator + systemSetting
105 m_keyPrefixes.push_back(prefix + allAppsSetting + separator + systemSetting + separator);
112 qstdweb::runTaskOnMainThread<void>([
this, &removed, &
key]() {
113 std::vector<std::string>
children = { removed };
114 const int length = val::global(
"window")[
"localStorage"][
"length"].as<
int>();
117 val::global(
"window")[
"localStorage"].call<val>(
"key",
i).as<std::string>());
119 const QStringView storedKey = keyNameFromPrefixedStorageName(
120 m_keyPrefixes.first(),
QStringView(storedKeyWithPrefix));
121 if (storedKey.isEmpty() || !storedKey.startsWith(
key))
128 val::global(
"window")[
"localStorage"].call<val>(
"removeItem",
child);
134 qstdweb::runTaskOnMainThread<void>([
this, &
key, &
value]() {
137 val::global(
"window")[
"localStorage"].call<
void>(
"setItem",
keyString, valueString);
143 return qstdweb::runTaskOnMainThread<std::optional<QVariant>>(
144 [
this, &
key]() -> std::optional<QVariant> {
145 for (
const auto &prefix : m_keyPrefixes) {
147 const emscripten::val
value =
148 val::global(
"window")[
"localStorage"].call<val>(
"getItem",
keyString);
149 if (!
value.isNull()) {
163 return qstdweb::runTaskOnMainThread<QStringList>([
this, &prefix, &spec]() ->
QStringList {
168 const int length = val::global(
"window")[
"localStorage"][
"length"].as<
int>();
170 for (
const auto &storagePrefix : m_keyPrefixes) {
178 if (!
key.isEmpty() &&
key.startsWith(prefix)) {
195 qstdweb::runTaskOnMainThread<void>([
this]() {
197 const int length = val::global(
"window")[
"localStorage"][
"length"].as<
int>();
202 (val::global(
"window")[
"localStorage"].call<val>(
"key",
i).as<std::string>())));
208 if (!keyNameFromPrefixedStorageName(m_keyPrefixes.first(),
key).isEmpty())
209 val::global(
"window")[
"localStorage"].call<val>(
"removeItem",
key.toStdString());
239 void clear()
override;
240 void sync()
override;
244 void loadIndexedDBFiles();
251constexpr char DbName[] =
"/home/web_user";
265 databaseName = organization;
268 loadIndexedDBFiles();
275bool QWasmIDBSettingsPrivate::writeSettingsToTemporaryFile(
const QString &
fileName,
void *dataPtr,
282 dir.mkpath(fileInfo.path());
303 loadIndexedDBFiles();
313 reinterpret_cast<void *
>(dataPointer.data()), dataPointer.length(),
319void QWasmIDBSettingsPrivate::loadIndexedDBFiles()
324 emscripten_idb_exists(
DbName, confFile->name.toLocal8Bit(), &exists, &
error);
346 format = QSettings::WebLocalStorageFormat;
350 const bool cookiesEnabled = qstdweb::runTaskOnMainThread<bool>(
351 []() {
return val::global(
"navigator")[
"cookieEnabled"].as<
bool>(); });
354 "QSettings::%1 requires cookies, falling back to IniFormat with temporary file");
355 if (!cookiesEnabled) {
356 if (
format == QSettings::WebLocalStorageFormat) {
357 qWarning() << cookiesWarningMessage.arg(
"WebLocalStorageFormat");
359 }
else if (
format == QSettings::WebIndexedDBFormat) {
360 qWarning() << cookiesWarningMessage.arg(
"WebIndexedDBFormat");
365 qWarning() <<
"QSettings::WebIndexedDBFormat requires JSPI, falling back to IniFormat with "
372 case QSettings::Format::WebLocalStorageFormat:
374 case QSettings::Format::WebIndexedDBFormat:
virtual void initAccess()
QString fileName() const override
const QList< QConfFile * > & getConfFiles() const
QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
bool isEmpty() const noexcept
void push_back(parameter_type t)
static QSettingsPrivate * create(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application)
void setStatus(QSettings::Status status) const
static QVariant stringToVariant(const QString &s)
static QString variantToString(const QVariant &v)
static void processChild(QStringView key, ChildSpec spec, QStringList &result)
Format
This enum type specifies the storage format used by QSettings.
Scope
This enum specifies whether settings are user-specific or shared by all users of the same system.
constexpr qsizetype length() const noexcept
Same as size().
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString & replace(qsizetype i, qsizetype len, QChar after)
static QString fromStdString(const std::string &s)
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
std::string toStdString() const
Returns a std::string object with the data contained in this QString.
qsizetype length() const noexcept
Returns the number of characters in this string.
~QWasmIDBSettingsPrivate()
QWasmIDBSettingsPrivate(QSettings::Scope scope, const QString &organization, const QString &application)
std::optional< QVariant > get(const QString &key) const final
bool isWritable() const final
~QWasmLocalStorageSettingsPrivate() final=default
QWasmLocalStorageSettingsPrivate(QSettings::Scope scope, const QString &organization, const QString &application)
void remove(const QString &key) final
void set(const QString &key, const QVariant &value) final
QString fileName() const final
Combined button and popup list for selecting options.
QList< QString > QStringList
Constructs a string list that contains the given string, str.
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
GLint GLsizei GLsizei GLenum format
static QString keyString(int sym, QChar::Category category)
#define Q_ASSERT_X(cond, x, msg)
static char * toLocal8Bit(char *out, QStringView in, QStringConverter::State *state)
#define QStringLiteral(str)
QFuture< QSet< QChar > > set
[10]