summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKatja Marttila <katja.marttila@qt.io>2022-05-18 12:56:48 +0300
committerKatja Marttila <katja.marttila@qt.io>2022-05-27 10:21:40 +0300
commit8892e397c1b7f0c88713b787c7fa4f17dd89c064 (patch)
tree219ce35ec97dc08ff76ee30b4e54031d555c90d2
parentfc37cb9824b1c73a88f9a1e495e814bafa19fc8d (diff)
Windows: Allow asking installer value with different formats
This change expands installer.value() -function allowing QSettings::Format setting when asking registry key. Windows 32bit registry keys on 64bit Windows and 64bit application can be accessed using QSettings::Registry32Format. Window 64bit registry keys on 64bit windows and 32bit application can be accessed using QSettings::Registy64Format. If no format is set, QSettings::NativeFormat is used. Task-number: QTIFW-2657 Change-Id: Ie30e31886526db5b9d72793d5883c11bd1910737 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Arttu Tarkiainen <arttu.tarkiainen@qt.io>
-rw-r--r--doc/scripting-api/packagemanagercore.qdoc14
-rw-r--r--doc/scripting-api/qsettings.qdoc57
-rw-r--r--src/libs/installer/packagemanagercore.cpp10
-rw-r--r--src/libs/installer/packagemanagercore.h3
-rw-r--r--src/libs/installer/packagemanagercoredata.cpp4
-rw-r--r--src/libs/installer/packagemanagercoredata.h5
-rw-r--r--src/libs/installer/scriptengine.cpp16
-rw-r--r--src/libs/installer/scriptengine.h5
8 files changed, 101 insertions, 13 deletions
diff --git a/doc/scripting-api/packagemanagercore.qdoc b/doc/scripting-api/packagemanagercore.qdoc
index 3466c70f6..b14fd957f 100644
--- a/doc/scripting-api/packagemanagercore.qdoc
+++ b/doc/scripting-api/packagemanagercore.qdoc
@@ -754,10 +754,16 @@
*/
/*!
- \qmlmethod string installer::value(string key, string defaultValue = "")
-
- Returns the installer value for \a key. If \a key is not known to the system, \a defaultValue is
- returned. Additionally, on Windows, \a key can be a registry key.
+ \qmlmethod string installer::value(string key, string defaultValue = "", int format = 0)
+
+ Returns the installer value for \a key. If \a key is not known to the system,
+ \a defaultValue is returned. Additionally, on Windows, \a key can be a
+ registry key. Optionally, you can specify the \a format of the registry key.
+ By default the \a format is QSettings::NativeFormat. For accessing
+ the 32-bit system registry from a 64-bit application running on 64-bit
+ Windows, use QSettings::Registry32Format. For accessing the 64-bit system
+ registry from a 32-bit application running on 64-bit Windows, use
+ QSettings::Registry64Format.
\sa setValue, containsValue, valueChanged
*/
diff --git a/doc/scripting-api/qsettings.qdoc b/doc/scripting-api/qsettings.qdoc
new file mode 100644
index 000000000..04a0fe674
--- /dev/null
+++ b/doc/scripting-api/qsettings.qdoc
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Installer Framework.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \qmltype QSettings
+ \inqmlmodule scripting
+
+ \brief Provides enums for accessing QSettings format in Windows.
+
+ On Windows, a registry key can be asked using \l{installer::value}.
+ For accessing the 32-bit system registry from a 64-bit application running
+ on 64-bit Windows, use \l{QSettings::Registry32Format}{QSettings.Registry32Format}.
+ For accessing the 64-bit system registry from a 32-bit application running
+ on 64-bit Windows, use \l{QSettings::Registry64Format}{QSettings.Registry64Format}.
+ By default the \l{QSettings::NativeFormat}{QSettings.NativeFormat}is used.
+*/
+
+/*!
+ \qmlproperty enumeration QSettings::Format
+
+ The \l{installer::value} method can take one of the following enums as an argument:
+
+ \list
+ \li \l{QSettings::NativeFormat}{QSettings.NativeFormat}
+ \li \l{QSettings::Registry32Format}{QSettings.Registry32Format}
+ \li \l{QSettings::Registry64Format}{QSettings.Registry64Format}
+ \li \l{QSettings::IniFormat}{QSettings.IniFormat}
+ \li \l{QSettings::InvalidFormat}{QSettings.InvalidFormat}
+ \endlist
+
+ The enum values correspond to the values of the
+ \l{QSettings::Format} enum with the same names.
+*/
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp
index a62aa8940..8aaac366e 100644
--- a/src/libs/installer/packagemanagercore.cpp
+++ b/src/libs/installer/packagemanagercore.cpp
@@ -3420,14 +3420,18 @@ void PackageManagerCore::addResourcesForOfflineGeneration(const QString &rcPath)
/*!
Returns the installer value for \a key. If \a key is not known to the system, \a defaultValue is
- returned. Additionally, on Windows, \a key can be a registry key.
+ returned. Additionally, on Windows, \a key can be a registry key. Optionally, you can specify the
+ \a format of the registry key. By default the \a format is QSettings::NativeFormat.
+ For accessing the 32-bit system registry from a 64-bit application running on 64-bit Windows,
+ use QSettings::Registry32Format. For accessing the 64-bit system registry from a 32-bit
+ application running on 64-bit Windows, use QSettings::Registry64Format.
\sa {installer::value}{installer.value}
\sa setValue(), containsValue(), valueChanged()
*/
-QString PackageManagerCore::value(const QString &key, const QString &defaultValue) const
+QString PackageManagerCore::value(const QString &key, const QString &defaultValue, const QSettings::Format &format) const
{
- return d->m_data.value(key, defaultValue).toString();
+ return d->m_data.value(key, defaultValue, format).toString();
}
/*!
diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h
index 1cc62cac5..819c3ed01 100644
--- a/src/libs/installer/packagemanagercore.h
+++ b/src/libs/installer/packagemanagercore.h
@@ -39,6 +39,7 @@
#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <QtCore/QVector>
+#include <QSettings>
namespace QInstaller {
@@ -171,7 +172,7 @@ public:
// parameter handling
Q_INVOKABLE bool containsValue(const QString &key) const;
Q_INVOKABLE void setValue(const QString &key, const QString &value);
- Q_INVOKABLE QString value(const QString &key, const QString &defaultValue = QString()) const;
+ Q_INVOKABLE QString value(const QString &key, const QString &defaultValue = QString(), const QSettings::Format &format = QSettings::NativeFormat) const;
Q_INVOKABLE QStringList values(const QString &key, const QStringList &defaultValue = QStringList()) const;
Q_INVOKABLE QString key(const QString &value) const;
diff --git a/src/libs/installer/packagemanagercoredata.cpp b/src/libs/installer/packagemanagercoredata.cpp
index c72ff65fc..c19f0d1c0 100644
--- a/src/libs/installer/packagemanagercoredata.cpp
+++ b/src/libs/installer/packagemanagercoredata.cpp
@@ -233,7 +233,7 @@ bool PackageManagerCoreData::setValue(const QString &key, const QString &normali
return true;
}
-QVariant PackageManagerCoreData::value(const QString &key, const QVariant &_default) const
+QVariant PackageManagerCoreData::value(const QString &key, const QVariant &_default, const QSettings::Format &format) const
{
if (key == scTargetDir) {
QString dir = m_variables.value(key);
@@ -253,7 +253,7 @@ QVariant PackageManagerCoreData::value(const QString &key, const QVariant &_defa
static const QRegExp regex(QLatin1String("\\\\|/"));
const QString filename = key.section(regex, 0, -2);
const QString regKey = key.section(regex, -1);
- const QSettingsWrapper registry(filename, QSettings::NativeFormat);
+ const QSettingsWrapper registry(filename, format);
if (!filename.isEmpty() && !regKey.isEmpty() && registry.contains(regKey))
return registry.value(regKey).toString();
}
diff --git a/src/libs/installer/packagemanagercoredata.h b/src/libs/installer/packagemanagercoredata.h
index 3cfb77c95..2dcddf102 100644
--- a/src/libs/installer/packagemanagercoredata.h
+++ b/src/libs/installer/packagemanagercoredata.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2021 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -30,6 +30,7 @@
#define PACKAGEMANAGERCOREDATA_H
#include "settings.h"
+#include <QSettings>
namespace QInstaller {
@@ -53,7 +54,7 @@ public:
bool contains(const QString &key) const;
bool setValue(const QString &key, const QString &normalizedValue);
- QVariant value(const QString &key, const QVariant &_default = QVariant()) const;
+ QVariant value(const QString &key, const QVariant &_default = QVariant(), const QSettings::Format &format = QSettings::NativeFormat) const;
QString key(const QString &value) const;
QString replaceVariables(const QString &str) const;
diff --git a/src/libs/installer/scriptengine.cpp b/src/libs/installer/scriptengine.cpp
index 26fe79646..009215909 100644
--- a/src/libs/installer/scriptengine.cpp
+++ b/src/libs/installer/scriptengine.cpp
@@ -395,6 +395,9 @@ ScriptEngine::ScriptEngine(PackageManagerCore *core) :
global.setProperty(QLatin1String("buttons"), generateWizardButtonsObject());
global.setProperty(QLatin1String("QMessageBox"), generateMessageBoxObject());
global.setProperty(QLatin1String("QDesktopServices"), generateDesktopServicesObject());
+#ifdef Q_OS_WIN
+ global.setProperty(QLatin1String("QSettings"), generateSettingsObject());
+#endif
if (core) {
setGuiQObject(core->guiObject());
@@ -665,6 +668,19 @@ QJSValue ScriptEngine::generateDesktopServicesObject()
return object;
}
+#ifdef Q_OS_WIN
+QJSValue ScriptEngine::generateSettingsObject()
+{
+ QJSValue settingsObject = m_engine.newArray();
+ SETPROPERTY(settingsObject, NativeFormat, QSettings)
+ SETPROPERTY(settingsObject, IniFormat, QSettings)
+ SETPROPERTY(settingsObject, Registry32Format, QSettings)
+ SETPROPERTY(settingsObject, Registry64Format, QSettings)
+ SETPROPERTY(settingsObject, InvalidFormat, QSettings)
+ return settingsObject;
+}
+#endif
+
QJSValue ScriptEngine::generateQInstallerObject()
{
// register ::WizardPage enum in the script connection
diff --git a/src/libs/installer/scriptengine.h b/src/libs/installer/scriptengine.h
index a0c64c0e4..ae3cdd04f 100644
--- a/src/libs/installer/scriptengine.h
+++ b/src/libs/installer/scriptengine.h
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -69,6 +69,9 @@ private:
QJSValue generateQInstallerObject();
QJSValue generateWizardButtonsObject();
QJSValue generateDesktopServicesObject();
+#ifdef Q_OS_WIN
+ QJSValue generateSettingsObject();
+#endif
private:
QJSEngine m_engine;