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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
/****************************************************************************
**
** This file is part of Qt Installer Framework
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Free Documentation License
**
** 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
****************************************************************************/
/*!
\contentspage{index.html}{Qt Installer Framework}
\previouspage noninteractive.html
\page scripting.html
\nextpage operations.html
\title Component Scripting
For each component, you can specify one script that is loaded and run by the
installer. The script format has to be compatible with QScriptEngine.
\section1 Construction
The script has to contain a \c Component object that the installer creates
when it loads the script. Therefore, the script must contain at
least the \a Component() function, which performs initialization, such as
putting pages in the correct places or connecting signals and slots.
The following code snippet places the \a ErrorPage (which is the class
name of the user interface file loaded from errorpage.ui) in front of the
ready for installation page and sets its completeness to \c false.
\code
function Component()
{
// Add a user interface file called ErrorPage, which should not be complete
installer.addWizardPage( component, "ErrorPage", QInstaller.ReadyForInstallation );
component.userInterface( "ErrorPage" ).complete = false;
}
\endcode
For more information, see the documentation for \a addWizardPage and
\a userInterface.
\section1 Installer Hooks
You can add the following hook methods into your script:
\table
\header
\o Method
\o Description
\row
\o \a{Component.prototype.retranslateUi}
\o Called when the language of the installer changes.
\row
\o \a{Component.prototype.createOperations}
\o See \a QInstaller::Component::createOperations.
\row
\o \a{Component.prototype.createOperationsForArchive}
\o See \a QInstaller::Component::createOperationsForArchive.
\row
\o \a{Component.prototype.createOperationsForPath}
\o See \a QInstaller::Component::createOperationsForPath.
\endtable
\section1 Global Variables
The installer puts the following symbols into the script space:
\table
\header
\o Symbol
\o Description
\row
\o installer
\o Reference to the \a installer of the component
\row
\o component
\o Reference to the \a Component of the component
\endtable
All methods marked with \a Q_INVOKABLE as well as all signals, slots, and
properties can be used by the script.
\section1 Message Boxes
You can show a \a QMessageBox from within the script by using:
\code
QMessageBox.critical
QMessageBox.information
QMessageBox.question
QMessageBox.warning
\endcode
For your convenience, the values for \a QMessageBox::StandardButton are made
available by using \a QMessageBox.Ok, \a QMessageBox.Open, and so on.
\section1 Adding Operations to Components
You might want to add custom operations after extracting the content, when
copying files or patching file content, for example. You can create and add
update operations to the installation from within
a script using \a QInstaller::Component::addOperation.
Each operation has a unique key used for identification and can take up to
five parameters. In the parameter values, you can use variables as set in
\a QInstaller::Installer::setValue. For more information, see
\l{Predefined Variables}.
For a summary of all available operations, see \l{Operations}.
\section1 Registering Custom Operations
You can register custom installation operations in the installer by deriving
\a KDUpdater::UpdateOperation. The following code displays the methods that
you must implement:
\code
#include <KDUpdater/UpdateOperation>
class CustomOperation : public KDUpdater::UpdateOperation
{
public:
CustomOperation()
{
setName( "CustomOperation" );
}
void backup()
{
// do whatever is needed to restore the state in undoOperation()
}
bool performOperation()
{
const QStringList args = arguments();
// do whatever is needed to do for the given arguments
bool success = ...;
return success;
}
void undoOperation()
{
// restore the previous state, as saved in backup()
}
bool testOperation()
{
// currently unused
return true;
}
CustomOperation* clone() const
{
return new CustomOperation;
}
QDomDocument toXml()
{
// automatically adds the operation's arguments and everything set via setValue
QDomDocument doc = KDUpdater::UpdateOperation::toXml();
// if you need any information to undo the operation you did,
// add them to the doc here
return doc;
}
bool fromXml( const QDomDocument& doc )
{
// automatically loads the operation's arguments and everything set via setValue
if( !KDUpdater::UpdateOperation::fromXml( doc ) )
return false;
// if you need any information to undo the operation you did,
// read them from the doc here
return true;
}
};
\endcode
Finally, you need to register your custom operation class, as follows:
\code
#include <KDupdater/UpdateOperationFactory>
KDUpdater::UpdateOperationFactory::instance().registerUpdateOperation< CustomOperation >( "CustomOperation" );
\endcode
Now you can use your operation in the installer in the same way as the
predefined operations.
\section1 Predefined Variables
You can use the following predefined variables in scripts to facilitate
directory access:
\table
\header
\o Symbol
\o Description
\row
\o ProductName
\o Name of the product to be installed, as defined in config.xml.
\row
\o ProductVersion
\o Version number of the product to be installed, as defined in
config.xml.
\row
\o Title
\o Title of the installation program, as defined in config.xml.
\row
\o Publisher
\o Publisher of the installation program, as defined in config.xml.
\row
\o Url
\o Product URL, as defined in config.xml.
\row
\o StartMenuDir
\o Start menu group, as defined in config.xml. Available on
Windows, only.
\row
\o TargetDir
\o Target directory for installation, as selected by the user.
\row
\o DesktopDir
\o Name of the directory that contains the user's desktop.
\row
\o os
\o Current platform: \c "x11", \c "win", or \c "mac".
\endtable
\note You can use the variables in the parameter list for installation
operations. For example, \c{"{TargetDir}/settings.xml"} might be expanded
to: \c{"C:/Program Files/My Program/settings.xml"}.
*/
|