summaryrefslogtreecommitdiffstats
path: root/examples/doc/systeminfo.qdoc
blob: 11a2573c55406a56417d55c0f14fffdc39904d60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: http://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 http://www.qt.io/terms-conditions. For further
** information use the contact form at http://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: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \example systeminfo
    \ingroup qtifwexamples
    \title System Information Example

    \brief Using the systemInfo API in a component script to check operating
    system version and bitness.

    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{quitinstaller} examples.

    \skipto majorVersion

    \printuntil /^\}/

    \c majorVersion() takes a string of the format \c {<number>.<number>.<number>.[...]}.
    It uses the built-in JavaScript functions \c string.split() and \c parseInt() to return the
    first \c <number> 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, macOS, and individual Linux distributions.

    For macOS 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 macOS 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
*/