Add WebLocalStorageFormat, WebIndexedIDBFormat to public API
Fixes: QTBUG-115587 Change-Id: Icb5dc795ad60608effbf08200592899d1a3d7fd1 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>bb10
parent
e05b779c88
commit
7a0de7fda2
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue