From de748023e53ce84afd01cde0ca380cddad057a4d Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 3 Dec 2014 10:41:48 +0100 Subject: Expose systemInfo API Add systemInfo as a wrapper for QSystemInfo. Task-number: QTIFW-592 Change-Id: Ib54fcea8b0ef3a397a74f5315202f3000abd63cd Reviewed-by: Niels Weber Reviewed-by: Jarek Kobus --- Changelog | 3 +- INSTALL | 2 +- README | 7 +- examples/doc/systeminfo.qdoc | 116 +++++++++++++ examples/examples.pro | 3 +- examples/systeminfo/README | 13 ++ examples/systeminfo/config/config.xml | 10 ++ .../systeminfo/packages/root.i386/meta/package.xml | 8 + .../packages/root.x86_64/meta/package.xml | 8 + .../systeminfo/packages/root/meta/installscript.qs | 121 ++++++++++++++ examples/systeminfo/packages/root/meta/package.xml | 8 + examples/systeminfo/systeminfo.pro | 13 ++ installerfw.pro | 4 +- src/libs/installer/installer.pro | 6 +- src/libs/installer/scriptengine.cpp | 3 + src/libs/installer/systeminfo.cpp | 185 +++++++++++++++++++++ src/libs/installer/systeminfo.h | 68 ++++++++ .../installer/scriptengine/tst_scriptengine.cpp | 13 ++ 18 files changed, 579 insertions(+), 12 deletions(-) create mode 100644 examples/doc/systeminfo.qdoc create mode 100644 examples/systeminfo/README create mode 100644 examples/systeminfo/config/config.xml create mode 100644 examples/systeminfo/packages/root.i386/meta/package.xml create mode 100644 examples/systeminfo/packages/root.x86_64/meta/package.xml create mode 100644 examples/systeminfo/packages/root/meta/installscript.qs create mode 100644 examples/systeminfo/packages/root/meta/package.xml create mode 100644 examples/systeminfo/systeminfo.pro create mode 100644 src/libs/installer/systeminfo.cpp create mode 100644 src/libs/installer/systeminfo.h diff --git a/Changelog b/Changelog index b9eab0def..a09ae47b2 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,5 @@ 2.0.0 -- Require Qt 5.3 as a minimal version, Qt 4 code removed. +- Require Qt 5.4 as a minimal version, Qt 4 code removed. - Only support Qt 5 on documentation side as well. - Source code is now available also under LGPLv3. - Changed the default value of AllowSpaceInPath in config.xml to true. @@ -39,6 +39,7 @@ - Updated and improved translations. - Removed SetQtCreatorArrayValue, AddQtCreatorArrayValue operations. - Removed ApplyProductKey, ReplaceInstallNames, QtPatch operations. +- Added systemInfo to the scripting API (QTIFW-592). Thanks go to Christoph VogtlÃĪnder, Sze Howe Koh, Ray Donnelly, Tasuku Suzuki and Sascha Cunz for contributions. diff --git a/INSTALL b/INSTALL index 76ca05ca5..f2e3ff06f 100644 --- a/INSTALL +++ b/INSTALL @@ -15,7 +15,7 @@ http://qt.gitorious.org/installer-framework Build a static Qt --------------------- -Building the Qt Installer Framework from sources requires Qt (version 5.3.0 +Building the Qt Installer Framework from sources requires Qt (version 5.4.0 or newer). If you want to ship your installer as a single file you have to build Qt and the Qt Installer Framework statically. diff --git a/README b/README index 7cc4340ac..719ff6226 100644 --- a/README +++ b/README @@ -12,12 +12,9 @@ to online versions. Notes -------------------------- -- To build an installer, it is advised to use a statically linked Qt. See the - documentation at +- To build an installer, it is advised to use a statically linked Qt (5.4 or newer). + See the documentation at http://doc-snapshot.qt-project.org/qtifw-master/ifw-getting-started.html -- At the moment, building with Qt 4.8.x and Qt 5.2.x is supported. -- Qt IFW 2.0 and on will only support building with Qt 5. - Getting Help -------------------------- diff --git a/examples/doc/systeminfo.qdoc b/examples/doc/systeminfo.qdoc new file mode 100644 index 000000000..bd5ed2779 --- /dev/null +++ b/examples/doc/systeminfo.qdoc @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example systeminfo + \ingroup qtifwexamples + \title System Information Example + + \brief Checking operating system version and bitness in a script. + + The \e{System Information Example} demonstrates how to use the \l{systemInfo} API to detect + details about the target operating system. + + The example installer consists of three packages: \c root, \c root.i386 and \c root.x86_64. + The \c root.i386 and \c root.x86_64 packages are assumed to contain binaries specific to the + architecture. The \c root package contains logic to check for minimum operating system version. + It also hides either the \c root.i386 or \c root.x86_64 package, based on the operating system + architecture. + + The logic to detect the operating system features is scripted in the + \c{root}'s \l{systeminfo/packages/root/meta/installscript.qs}{installscript.qs} file. + + \quotefromfile systeminfo/packages/root/meta/installscript.qs + + \section1 Helper Functions + + The \l{systeminfo/packages/root/meta/installscript.qs}{installscript.qs} file first + declares two helper functions: \c cancelInstaller() and \c majorVersion(). + + \skipto cancelInstaller + \printuntil /^\}/ + + \c cancelInstaller() sets all except the last installer page to invisible, and shows an error + message on the last one. This is a technique also demonstrated in the \l{componenterror} and + \l{quit_installer} examples. + + \skipto majorVersion + + \printuntil /^\}/ + + \c majorVersion() takes a string of the format \c {...[...]}. + It uses the built-in JavaScript functions \c string.split() and \c parseInt() to return the + first \c as an integer. + + \section1 Checking the Operating System Type + + The actual checks are executed as soon as the package is loaded, in the \c Component constructor + function. + + \skipto /function Component/ + \printuntil /\{/ + + The function uses the built-in \l{systemInfo::kernelType}{systemInfo.kernelType}, + \l{systemInfo::kernelVersion}{systemInfo.kernelVersion}, \l{systemInfo::productType}, + and \l{systemInfo::productVersion}{systemInfo.productVersion} properties to check the minimum + system requirements. + + \skipto validOs + \printto /\!validOs/ + + The script uses \l{systemInfo::productType}{systemInfo.productType} to differentiate + between Windows, OS X, and individual Linux distributions. + + For OS X and Windows, the script checks the operating system kernel version. + For a mapping of kernel to operating system versions, see + \l{http://en.wikipedia.org/wiki/Darwin_%28operating_system%29}{Darwin} and + \l{http://en.wikipedia.org/wiki/Windows_NT}{Windows NT}. + + In the case of Linux, it checks the distribution name and version. If it does not match + the specific distribution and version the binaries are presumably built for, + the installer shows a warning in a modal dialog, but allows installation. + + If the Windows or OS X version is too old, though, the script calls the \c cancelInstaller() + helper function to prevent an actual installation: + + \printuntil /\}/ + + \section1 Checking the Operating System Architecture + + The next section demonstrates the use of + \l{systemInfo::currentCpuArchitecture}{systemInfo.currentCpuArchitecture} to choose + the appropriate sub-package for a particular architecture: + + \skipto root.i386 + \printuntil /^\}/ + + Depending on the operating system architecture, either the package \c root.i386 or + \c root.x86_64 is marked \c Virtual, hiding it from the user. For the package that matches + the local architecture, the \c Default property is set to check the package by default. + + \include installerfw-examples-generating.qdocinc +*/ diff --git a/examples/examples.pro b/examples/examples.pro index ac886cd8a..1e5a816cd 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -9,4 +9,5 @@ SUBDIRS += \ openreadme \ quit_installer \ registerfileextension \ - startmenu + startmenu \ + systeminfo diff --git a/examples/systeminfo/README b/examples/systeminfo/README new file mode 100644 index 000000000..69440c088 --- /dev/null +++ b/examples/systeminfo/README @@ -0,0 +1,13 @@ +Shows how to use the systemInfo JS API. + +The installer rejects installations on Windows XP, +and OS X 10.6 or older. It shows a warning if +it is run on any Linux distribution other than openSUSE 13.2. + +It also shows only one of the two sub-packages, based on +the CPU architecture: "i386" on an 32-bit system, and +"x86_64" on an 64-bit system. + +Generate installer with + +binarycreator --offline-only -c config/config.xml -p packages installer diff --git a/examples/systeminfo/config/config.xml b/examples/systeminfo/config/config.xml new file mode 100644 index 000000000..ffbfd9d7f --- /dev/null +++ b/examples/systeminfo/config/config.xml @@ -0,0 +1,10 @@ + + + SystemInfo Example + 1.0.0 + SystemInfo Example + The Qt Company + + Qt Installer Framework Example + @HomeDir@/IFWSystemInfoExample + diff --git a/examples/systeminfo/packages/root.i386/meta/package.xml b/examples/systeminfo/packages/root.i386/meta/package.xml new file mode 100644 index 000000000..4d56928ce --- /dev/null +++ b/examples/systeminfo/packages/root.i386/meta/package.xml @@ -0,0 +1,8 @@ + + + i386 binaries + Binaries that require a x86 CPU. + 1.0.0-1 + 2014-12-01 + false + diff --git a/examples/systeminfo/packages/root.x86_64/meta/package.xml b/examples/systeminfo/packages/root.x86_64/meta/package.xml new file mode 100644 index 000000000..66cffdfd4 --- /dev/null +++ b/examples/systeminfo/packages/root.x86_64/meta/package.xml @@ -0,0 +1,8 @@ + + + x86-64 bit binaries + Binaries that require a x86-64 CPU. + 1.0.0-1 + 2014-12-01 + false + diff --git a/examples/systeminfo/packages/root/meta/installscript.qs b/examples/systeminfo/packages/root/meta/installscript.qs new file mode 100644 index 000000000..213a3c42c --- /dev/null +++ b/examples/systeminfo/packages/root/meta/installscript.qs @@ -0,0 +1,121 @@ +/************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +// Skip all pages and go directly to finished page. +// (see also componenterror example) +function cancelInstaller(message) +{ + installer.setDefaultPageVisible(QInstaller.Introduction, false); + installer.setDefaultPageVisible(QInstaller.TargetDirectory, false); + installer.setDefaultPageVisible(QInstaller.ComponentSelection, false); + installer.setDefaultPageVisible(QInstaller.ReadyForInstallation, false); + installer.setDefaultPageVisible(QInstaller.StartMenuSelection, false); + installer.setDefaultPageVisible(QInstaller.PerformInstallation, false); + installer.setDefaultPageVisible(QInstaller.LicenseCheck, false); + + var abortText = "" + message +""; + installer.setValue("FinishedText", abortText); +} + +// Returns the major version number as int +// string.split(".", 1) returns the string before the first '.', +// parseInt() converts it to an int. +function majorVersion(str) +{ + return parseInt(str.split(".", 1)); +} + +function Component() +{ + // + // Check whether OS is supported. + // + // For Windows and OS X we check the kernel version: + // - Require at least Windows Vista (winnt kernel version 6.0.x) + // - Require at least OS X 10.7 (Lion) (darwin kernel version 11.x) + // + // If the kernel version is older we move directly + // to the final page & show an error. + // + // For Linux, we check the distribution and version, but only + // show a warning if it does not match our preferred distribution. + // + + // start installer with -v to see debug output + console.log("OS: " + systemInfo.productType); + console.log("Kernel: " + systemInfo.kernelType + "/" + systemInfo.kernelVersion); + + var validOs = false; + + if (systemInfo.kernelType === "winnt") { + if (majorVersion(systemInfo.kernelVersion) >= 6) + validOs = true; + } else if (systemInfo.kernelType === "darwin") { + if (majorVersion(systemInfo.kernelVersion) >= 11) + validOs = true; + } else { + if (systemInfo.productType !== "opensuse" + || systemInfo.productVersion !== "13.2") { + QMessageBox["warning"]("os.warning", "Installer", + "Note that the binaries are only tested on OpenSUSE 13.2.", + QMessageBox.Ok); + } + validOs = true; + } + + if (!validOs) { + cancelInstaller("Installation on " + systemInfo.prettyProductName + " is not supported"); + return; + } + + // + // Hide/select packages based on architecture + // + // Marking a component as "Virtual" will hide it in the UI. + // Marking a component with "Default" will check it. + // + console.log("CPU Architecture: " + systemInfo.currentCpuArchitecture); + + installer.componentByName("root.i386").setValue("Virtual", "true"); + installer.componentByName("root.x86_64").setValue("Virtual", "true"); + + if ( systemInfo.currentCpuArchitecture === "i386") { + installer.componentByName("root.i386").setValue("Virtual", "false"); + installer.componentByName("root.i386").setValue("Default", "true"); + } + if ( systemInfo.currentCpuArchitecture === "x86_64") { + installer.componentByName("root.x86_64").setValue("Virtual", "false"); + installer.componentByName("root.x86_64").setValue("Default", "true"); + } +} diff --git a/examples/systeminfo/packages/root/meta/package.xml b/examples/systeminfo/packages/root/meta/package.xml new file mode 100644 index 000000000..0e67c1bc9 --- /dev/null +++ b/examples/systeminfo/packages/root/meta/package.xml @@ -0,0 +1,8 @@ + + + systemInfo example + Shows the use of the systemInfo JS API. + 1.0.0-1 + 2013-01-01 + + diff --git a/examples/systeminfo/systeminfo.pro b/examples/systeminfo/systeminfo.pro new file mode 100644 index 000000000..415df49d5 --- /dev/null +++ b/examples/systeminfo/systeminfo.pro @@ -0,0 +1,13 @@ +TEMPLATE = aux + +INSTALLER = installer + +INPUT = $$PWD/config/config.xml $$PWD/packages +example.input = INPUT +example.output = $$INSTALLER +example.commands = ../../bin/binarycreator -c $$PWD/config/config.xml -p $$PWD/packages ${QMAKE_FILE_OUT} +example.CONFIG += target_predeps no_link combine + +QMAKE_EXTRA_COMPILERS += example + +OTHER_FILES = README diff --git a/installerfw.pro b/installerfw.pro index 6b30cd04e..6dfca3997 100644 --- a/installerfw.pro +++ b/installerfw.pro @@ -13,7 +13,7 @@ BUILD_EXAMPLES = $$(BUILDEXAMPLES) isEmpty(BUILD_EXAMPLES):BUILD_EXAMPLES=$${BUILDEXAMPLES} !isEmpty(BUILD_EXAMPLES):SUBDIRS += examples -!minQtVersion(5, 3, 0) { +!minQtVersion(5, 4, 0) { message("Cannot build Qt Installer Framework with Qt version $${QT_VERSION}.") - error("Use at least Qt 5.3.0.") + error("Use at least Qt 5.4.0.") } diff --git a/src/libs/installer/installer.pro b/src/libs/installer/installer.pro index 700943739..34c7adba9 100644 --- a/src/libs/installer/installer.pro +++ b/src/libs/installer/installer.pro @@ -121,7 +121,8 @@ HEADERS += packagemanagercore.h \ componentchecker.h \ proxycredentialsdialog.h \ serverauthenticationdialog.h \ - keepaliveobject.h + keepaliveobject.h \ + systeminfo.h SOURCES += packagemanagercore.cpp \ packagemanagercore_p.cpp \ @@ -192,7 +193,8 @@ SOURCES += packagemanagercore.cpp \ componentchecker.cpp \ proxycredentialsdialog.cpp \ serverauthenticationdialog.cpp \ - keepaliveobject.cpp + keepaliveobject.cpp \ + systeminfo.cpp FORMS += proxycredentialsdialog.ui \ serverauthenticationdialog.ui diff --git a/src/libs/installer/scriptengine.cpp b/src/libs/installer/scriptengine.cpp index 428e95a8f..c67295f57 100644 --- a/src/libs/installer/scriptengine.cpp +++ b/src/libs/installer/scriptengine.cpp @@ -36,6 +36,7 @@ #include "messageboxhandler.h" #include "errors.h" #include "scriptengine_p.h" +#include "systeminfo.h" #include #include @@ -262,6 +263,8 @@ ScriptEngine::ScriptEngine(PackageManagerCore *core) #else m_engine.installTranslatorFunctions(); #endif + global.setProperty(QLatin1String("systemInfo"), m_engine.newQObject(new SystemInfo)); + global.setProperty(QLatin1String("QInstaller"), generateQInstallerObject()); global.setProperty(QLatin1String("buttons"), generateWizardButtonsObject()); global.setProperty(QLatin1String("QMessageBox"), generateMessageBoxObject()); diff --git a/src/libs/installer/systeminfo.cpp b/src/libs/installer/systeminfo.cpp new file mode 100644 index 000000000..0cf9cd935 --- /dev/null +++ b/src/libs/installer/systeminfo.cpp @@ -0,0 +1,185 @@ +/************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +#include "systeminfo.h" +#include + +namespace QInstaller { + +/*! + \qmltype systemInfo + \inqmlmodule scripting + + \brief Provides information about the operating system. +*/ + + +SystemInfo::SystemInfo(QObject *parent) : QObject(parent) +{ +} + + +/*! + \qmlproperty string systemInfo::currentCpuArchitecture + + The architecture of the CPU that the application is running on, in text format. + + Possible values include + \list + \li "i386" + \li "x86_64" + \endlist + + Note that this function depends on what the OS will report and may not detect the actual CPU + architecture if the OS hides that information or is unable to provide it. For example, a 32-bit + OS running on a 64-bit CPU is usually unable to determine whether the CPU is actually capable + of running 64-bit programs. + + \sa QSysInfo::currentCpuArchitecture() +*/ +QString SystemInfo::currentCpuArchitecture() const +{ + return QSysInfo::currentCpuArchitecture(); +} + +/*! + \qmlproperty string systemInfo::kernelType + + The type of the operating system kernel the installer was compiled for. It is also the + kernel the installer is running on, unless the host operating system is running a form of + compatibility or virtualization layer. + + For Windows, Linux, and OS X this will return + \list + \li "winnt" + \li "linux" + \li "darwin" + \endlist + + On Unix systems, it returns the same as the output of \c {uname -s} (lowercased). + + \sa QSysInfo::kernelType() +*/ +QString SystemInfo::kernelType() const +{ + return QSysInfo::kernelType(); +} + +/*! + \qmlproperty string systemInfo::kernelVersion + + Example values are + + \list + \li "6.1.7601" for Windows 7 with Service Pack 1 + \li "3.16.6-2-desktop" for openSUSE 13.2 kernel 3.16.6-2 + \li "12.5.0" last release of OS X "Mountain Lion" + \endlist + + The release version of the operating system kernel. On Windows, it returns the version of the + NT or CE kernel. On Unix systems, including OS X, it returns the same as the \c {uname -r} + command would return. + + \sa QSysInfo::kernelVersion() +*/ +QString SystemInfo::kernelVersion() const +{ + return QSysInfo::kernelVersion(); +} + +/*! + \qmlproperty string systemInfo::productType + + The product name of the operating system this application is running in. + + Example values are + + \list + \li "windows" + \li "opensuse" (for the Linux openSUSE distribution) + \li "osx" + \endlist + + \sa QSysInfo::productType() +*/ +QString SystemInfo::productType() const +{ + return QSysInfo::productType(); +} + +/*! + \qmlproperty string systemInfo::productVersion + + The product version of the operating system in string form. If the version could not be + determined, this function returns "unknown". + + Example values are + + \list + \li "7" for Windows 7 + \li "13.2" for openSUSE 13.2 + \li "10.8" for OS X Mountain Lion + \endlist + + \sa QSysInfo::productVersion() +*/ +QString SystemInfo::productVersion() const +{ + return QSysInfo::productVersion(); +} + +/*! + \qmlproperty string systemInfo::prettyProductName + + A prettier form of systemInfo::productType and systemInfo::productVersion, containing other + tokens like the operating system type, codenames and other information. The result of this + function is suitable for displaying to the user. + + Example values are + + \list + \li "Windows 7" + \li "openSUSE 13.2 (Harlequin) (x86_64)" + \li "OS X Mountain Lion (10.8)" + \endlist + + + \sa QSysInfo::prettyProductName() +*/ +QString SystemInfo::prettyProductName() const +{ + return QSysInfo::prettyProductName(); +} + +} // namespace QInstaller diff --git a/src/libs/installer/systeminfo.h b/src/libs/installer/systeminfo.h new file mode 100644 index 000000000..b352d3f72 --- /dev/null +++ b/src/libs/installer/systeminfo.h @@ -0,0 +1,68 @@ +/************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +#ifndef SYSTEMINFO_H +#define SYSTEMINFO_H + +#include + +namespace QInstaller { + +class SystemInfo : public QObject +{ + Q_OBJECT + Q_DISABLE_COPY(SystemInfo) + + Q_PROPERTY(QString currentCpuArchitecture READ currentCpuArchitecture CONSTANT) + Q_PROPERTY(QString kernelType READ kernelType CONSTANT) + Q_PROPERTY(QString kernelVersion READ kernelVersion CONSTANT) + Q_PROPERTY(QString productType READ productType CONSTANT) + Q_PROPERTY(QString productVersion READ productVersion CONSTANT) + Q_PROPERTY(QString prettyProductName READ prettyProductName CONSTANT) + +public: + explicit SystemInfo(QObject *parent = 0); + + QString currentCpuArchitecture() const; + + QString kernelType() const; + QString kernelVersion() const; + QString productType() const; + QString productVersion() const; + QString prettyProductName() const; +}; + +} // namespace QInstaller + +#endif // SYSTEMINFO_H diff --git a/tests/auto/installer/scriptengine/tst_scriptengine.cpp b/tests/auto/installer/scriptengine/tst_scriptengine.cpp index de5b32076..23cb56dd0 100644 --- a/tests/auto/installer/scriptengine/tst_scriptengine.cpp +++ b/tests/auto/installer/scriptengine/tst_scriptengine.cpp @@ -159,6 +159,19 @@ private slots: QCOMPARE(global.hasProperty(QLatin1String("gui")), true); QCOMPARE(global.hasProperty(QLatin1String("qsTr")), true); + + QCOMPARE(global.hasProperty(QLatin1String("systemInfo")), true); + QJSValue sinfo = global.property(QLatin1String("systemInfo")); + QCOMPARE(sinfo.property(QLatin1String("currentCpuArchitecture")).toString(), + QSysInfo::currentCpuArchitecture()); + QCOMPARE(sinfo.property(QLatin1String("kernelType")).toString(), QSysInfo::kernelType()); + QCOMPARE(sinfo.property(QLatin1String("kernelVersion")).toString(), + QSysInfo::kernelVersion()); + QCOMPARE(sinfo.property(QLatin1String("productType")).toString(), QSysInfo::productType()); + QCOMPARE(sinfo.property(QLatin1String("productVersion")).toString(), + QSysInfo::productVersion()); + QCOMPARE(sinfo.property(QLatin1String("prettyProductName")).toString(), + QSysInfo::prettyProductName()); } void testBrokenJSMethodConnect() -- cgit v1.2.3