diff options
author | Mikolaj Boc <mikolaj.boc@qt.io> | 2023-07-31 15:06:17 +0200 |
---|---|---|
committer | Mikolaj Boc <mikolaj.boc@qt.io> | 2023-08-21 12:12:44 +0200 |
commit | 7a0de7fda2e8dc3910313b1ddc5befefd4995d31 (patch) | |
tree | 82bb0b2e35974d035206b6ce62a79ea084c01530 | |
parent | e05b779c88c63b3efc15b5cb29f3c13ec22f1c48 (diff) |
Add WebLocalStorageFormat, WebIndexedIDBFormat to public API
Fixes: QTBUG-115587
Change-Id: Icb5dc795ad60608effbf08200592899d1a3d7fd1
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
-rw-r--r-- | src/corelib/io/qsettings.cpp | 10 | ||||
-rw-r--r-- | src/corelib/io/qsettings.h | 5 | ||||
-rw-r--r-- | src/corelib/io/qsettings_wasm.cpp | 28 |
3 files changed, 25 insertions, 18 deletions
diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 3bfac21261..20dc590483 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -2376,6 +2376,16 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, lose the distinction between numeric data and the strings used to encode them, so values written as numbers shall be read back as QString. + \value WebLocalStorageFormat + WASM only: Store the settings in window.localStorage for the current + origin. If cookies are not allowed, this falls back to the INI format. + This provides up to 5MiB storage per origin, but access to it is + synchronous and JSPI is not required. + \value WebIndexedDBFormat + WASM only: Store the settings in an Indexed DB for the current + origin. If cookies are not allowed, this falls back to the INI format. + This requires JSPI, but provides more storage than + WebLocalStorageFormat. \value InvalidFormat Special value returned by registerFormat(). \omitvalue CustomFormat1 diff --git a/src/corelib/io/qsettings.h b/src/corelib/io/qsettings.h index 86b55ea241..adaafd2519 100644 --- a/src/corelib/io/qsettings.h +++ b/src/corelib/io/qsettings.h @@ -55,9 +55,8 @@ public: #endif #if defined(Q_OS_WASM) - // FIXME: add public API in next minor release. - // WebLocalStorageFormat (IniFormat + 1) - // WebIDBSFormat (IniFormat + 2) + WebLocalStorageFormat, + WebIndexedDBFormat, #endif InvalidFormat = 16, diff --git a/src/corelib/io/qsettings_wasm.cpp b/src/corelib/io/qsettings_wasm.cpp index 5043f2f858..8329124804 100644 --- a/src/corelib/io/qsettings_wasm.cpp +++ b/src/corelib/io/qsettings_wasm.cpp @@ -405,32 +405,30 @@ void QWasmIDBSettingsPrivate::setReady() QSettingsPrivate *QSettingsPrivate::create(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application) { - const auto WebLocalStorageFormat = QSettings::IniFormat + 1; - const auto WebIdbFormat = QSettings::IniFormat + 2; - // Make WebLocalStorageFormat the default native format if (format == QSettings::NativeFormat) - format = QSettings::Format(WebLocalStorageFormat); + format = QSettings::WebLocalStorageFormat; // Check if cookies are enabled (required for using persistent storage) const bool cookiesEnabled = val::global("navigator")["cookieEnabled"].as<bool>(); constexpr QLatin1StringView cookiesWarningMessage ("QSettings::%1 requires cookies, falling back to IniFormat with temporary file"); - if (format == WebLocalStorageFormat && !cookiesEnabled) { - qWarning() << cookiesWarningMessage.arg("WebLocalStorageFormat"); - format = QSettings::IniFormat; - } else if (format == WebIdbFormat && !cookiesEnabled) { - qWarning() << cookiesWarningMessage.arg("WebIdbFormat"); - format = QSettings::IniFormat; + if (!cookiesEnabled) { + if (format == QSettings::WebLocalStorageFormat) { + qWarning() << cookiesWarningMessage.arg("WebLocalStorageFormat"); + format = QSettings::IniFormat; + } else if (format == QSettings::WebIndexedDBFormat) { + qWarning() << cookiesWarningMessage.arg("WebIndexedDBFormat"); + format = QSettings::IniFormat; + } } - if (format == WebLocalStorageFormat) - return new QWasmLocalStorageSettingsPrivate(scope, organization, application); - if (format == WebIdbFormat) - return new QWasmIDBSettingsPrivate(scope, organization, application); - // Create settings backend according to selected format switch (format) { + case QSettings::Format::WebLocalStorageFormat: + return new QWasmLocalStorageSettingsPrivate(scope, organization, application); + case QSettings::Format::WebIndexedDBFormat: + return new QWasmIDBSettingsPrivate(scope, organization, application); case QSettings::Format::IniFormat: case QSettings::Format::CustomFormat1: case QSettings::Format::CustomFormat2: |