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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// This file contains the QtCreator-specific part of the installer.
// It lists the files and features the installer should handle.
#include "qinstaller.h"
#include "qinstallergui.h"
#include <QtCore/QDebug>
#include <QtCore/QFileInfo>
#include <QtCore/QObject>
#include <QtGui/QApplication>
#include <QtGui/QBoxLayout>
#include <QtGui/QGridLayout>
#include <QtGui/QLabel>
#include <QtGui/QMessageBox>
// QInstallerGui is base of the Gui part of an installer, i.e.
// the "main installer wizard". In the simplest case it's just
// a sequence of "standard" wizard pages. A few commonly used
// ones are provided already in qinstallergui.h.
// A custom target directory selection based due to the no-space
// restriction...
class TargetDirectoryPage : public QInstallerTargetDirectoryPage
{
public:
TargetDirectoryPage(QInstaller *installer)
: QInstallerTargetDirectoryPage(installer)
{
m_noSpaceLabel = new QLabel(this);
m_noSpaceLabel->setText("The directory name should not contain any space.");
m_noSpaceLabel->hide();
insertWidget(m_noSpaceLabel, "MessageLabel");
}
bool isComplete() const
{
bool invalid = targetDir().contains(' ');
QPalette palette;
// We show the warning only if the user types a space.
// No need to scare him if the path is ok for us...
if (invalid) {
m_noSpaceLabel->show();
palette.setColor(QPalette::WindowText, Qt::red);
}
m_noSpaceLabel->setPalette(palette);
return !invalid;
}
int nextId() const
{
QFileInfo fi(targetDir());
if (isVisible() && fi.isDir()) {
QFileInfo fi2(targetDir() + '/' + installer()->uninstallerName());
if (fi2.exists()) {
QMessageBox::StandardButton bt = QMessageBox::warning(wizard(),
tr("Warning"),
tr("The directory you selected exists already and contains an installaion.\n"
"Do you want to overwrite it?"),
QMessageBox::Yes | QMessageBox::No);
if (bt == QMessageBox::No)
return wizard()->currentId();
} else {
QMessageBox::StandardButton bt = QMessageBox::warning(wizard(),
tr("Warning"),
tr("The directory you selected exists already.\n"
"Do you want to remove it and continue?"),
QMessageBox::Yes | QMessageBox::No);
if (bt == QMessageBox::No)
return wizard()->currentId();
}
}
return QInstallerPage::nextId();
}
private:
QLabel *m_noSpaceLabel;
};
////////////////////////////////////////////////////////////////////
//
// QtCreatorInstallerGui
//
////////////////////////////////////////////////////////////////////
// QtCreatorInstallerGui is the QtCreator specific incarnation
// of a QInstallerGui.
class QtCreatorInstallerGui : public QInstallerGui
{
public:
QtCreatorInstallerGui(QInstaller *installer)
{
// The Gui has access to the installer backend at construction
// time. For later access it needs to store the QInstaller *
// pointer provided. Not needed in this case here.
setWindowTitle(tr("%1 Setup").arg(installer->value("ProductName")));
installer->connectGui(this);
// We are happy with the default set of pages.
addPage(new QInstallerIntroductionPage(installer));
addPage(new QInstallerLicenseAgreementPage(installer));
//addPage(new QInstallerTargetDirectoryPage(installer));
addPage(new TargetDirectoryPage(installer));
if (installer->componentCount() > 1)
addPage(new QInstallerComponentSelectionPage(installer));
addPage(new QInstallerReadyForInstallationPage(installer));
addPage(new QInstallerPerformInstallationPage(installer));
addPage(new QInstallerFinishedPage(installer));
setStartId(installer->value("GuiStartPage").toInt());
}
};
// QInstaller is base of the "backend" part of an installer, i.e.
// the part handling the installer tasks and keeping track of
// related data like the directory to install to, the name of
// the Product, version of the Product etc.
// QtCreatorInstaller is the QtCreator specific incarnation
// of a QInstaller. It needs to list all tasks that a performed
// during installation. The tasks themselves specify what to
// do at uninstall time.
class QtCreatorInstaller : public QInstaller
{
public:
QtCreatorInstaller()
{
// basic product information
setValue("ProductName", "Qt Creator");
setValue("ProductVersion", "alpha");
// registration information
setValue("Comments", "");
setValue("Contact", "");
setValue("DisplayVersion", "");
setValue("HelpLink", "");
setValue("Publisher", "");
setValue("UrlAboutInfo", "");
// information needed at installer generation time
setValue("OutputFile", "qtcreator-installer");
setValue("RunProgram", "@TargetDir@/bin/qtcreator");
// default component selection, overridable from command line
setValue("UseQtCreator", "true");
#ifdef Q_OS_WIN
//setValue("UseQt", "true");
//setValue("UseMinGW", "true");
#endif
}
private:
// tasks related to QtCreator itself. Binary, libraries etc.
void appendQtCreatorComponent()
{
QString sourceDir = value("SourceDir");
if (sourceDir.isEmpty() && QFileInfo("../bin/qtcreator").isReadable())
sourceDir = QLatin1String("..");
if (sourceDir.isEmpty())
throw QInstallerError("Missing 'SourceDir=<dir>' on command line.");
QInstallerComponent *component = new QInstallerComponent(this);
component->setValue("Name", "QtCreator");
component->setValue("DisplayName", "Qt Creator");
component->setValue("Description", "The Qt Creator IDE");
component->setValue("SuggestedState", "AlwaysInstalled");
#ifdef Q_OS_MAC
component->appendDirectoryTasks(sourceDir + "/bin/QtCreator.app", "@TargetDir@");
#else
component->appendDirectoryTasks(sourceDir + "/bin", "@TargetDir@/bin");
component->appendDirectoryTasks(sourceDir + "/lib", "@TargetDir@/lib");
#endif
QInstallerPatchFileTask *task = new QInstallerPatchFileTask(this);
task->setTargetPath("@TargetDir@/lib/Trolltech/" + libraryName("ProjectExplorer", "1.0.0"));
task->setNeedle("Clear Session");
task->setReplacement("CLEAR SESSION");
component->appendTask(task);
appendComponent(component);
}
void appendMinGWComponent()
{
QString mingwSourceDir = value("MinGWSourceDir");
if (mingwSourceDir.isEmpty())
throw QInstallerError("Missing 'MinGWSourceDir=<dir>' on command line.");
QInstallerComponent *component = new QInstallerComponent(this);
component->setValue("Name", "MinGW");
component->setValue("DisplayName", "MinGW");
component->setValue("Description",
"The MinGW environment including the g++ compiler "
"and the gdb debugger.");
component->setValue("SuggestedState", "Installed");
component->appendDirectoryTasks(mingwSourceDir, "@TargetDir@");
appendComponent(component);
}
void appendQtComponent()
{
QString qtSourceDir = value("QtSourceDir");
if (qtSourceDir.isEmpty())
throw QInstallerError("Missing 'QtSourceDir=<dir>' on command line.");
QInstallerComponent *component = new QInstallerComponent(this);
component->setValue("Name", "Qt Development Libraries");
component->setValue("DisplayName", "Qt");
component->setValue("Description",
"The Qt library files for development including "
"documentation");
component->setValue("SuggestedState", "Installed");
component->appendDirectoryTasks(qtSourceDir, "@TargetDir@");
#ifdef Q_OS_WIN
static const struct
{
const char *fileName;
const char *sourceLocation;
} libs[] = {
{"/bin/Qt3Support", "/src/qt3support/"},
{"/bin/QtCore", "/src/corelib/"},
{"/bin/QtGui", "/src/gui/"},
{"/bin/QtHelp", "/tools/assistant/lib/"},
{"/bin/QtNetwork", "/src/network/"},
{"/bin/QtOpenGL", "/src/opengl/"},
{"/bin/QtScript", "/src/script/"},
{"/bin/QtSql", "/src/sql/"},
{"/bin/QtSvg", "/src/svg/"},
{"/bin/QtTest", "/src/testlib/"},
{"/bin/QtWebKit", "/src/3rdparty/webkit/WebCore/"},
{"/bin/QtXml", "/src/xml/"},
{"/bin/QtXmlPatterns", "/src/xmlpatterns/"},
{"/plugins/accessible/qtaccessiblecompatwidgets",
"/src/plugins/accessible/compat/"},
{"/plugins/accessible/qtaccessiblewidgets",
"/src/plugins/accessible/widgets/"},
{"/plugins/codecs/qcncodecs", "/src/plugins/codecs/cn/"},
{"/plugins/codecs/qjpcodecs", "/src/plugins/codecs/jp/"},
{"/plugins/codecs/qkrcodecs", "/src/plugins/codecs/kr/"},
{"/plugins/codecs/qtwcodecs", "/src/plugins/codecs/tw/"},
{"/plugins/iconengines/qsvgicon", "/src/plugins/iconengines/svgiconengine/"},
{"/plugins/imageformats/qgif", "/src/plugins/imageformats/gif/"},
{"/plugins/imageformats/qjpeg", "/src/plugins/imageformats/jpeg/"},
{"/plugins/imageformats/qmng", "/src/plugins/imageformats/mng/"},
{"/plugins/imageformats/qsvg", "/src/plugins/imageformats/svg/"},
{"/plugins/imageformats/qtiff", "/src/plugins/imageformats/tiff/"},
{"/plugins/sqldrivers/qsqlite", "/src/plugins/sqldrivers/sqlite/"},
// {"/plugins/sqldrivers/qsqlodbc", "/src/plugins/sqldrivers/odbc/"}
};
QString debug = QLatin1String("d4.dll");
for (int i = 0; i != sizeof(libs) / sizeof(libs[0]); ++i) {
QInstallerPatchFileTask *task = new QInstallerPatchFileTask(this);
task->setTargetPath(QString("@TargetDir@/") + libs[i].fileName + debug);
task->setNeedle("f:/depot/qt");
task->setReplacement(QByteArray("@TargetDir@/") + libs[i].sourceLocation);
component->appendTask(task);
}
#endif
appendComponent(component);
}
void createTasks()
{
// set UseXXX=false on command line to prevent inclusion of the
// respective component
if (value("UseQtCreator") == "true")
appendQtCreatorComponent();
if (value("UseMinGW") == "true")
appendMinGWComponent();
if (value("UseQt") == "true")
appendQtComponent();
}
};
////////////////////////////////////////////////////////////////////
//
// QtCreatorUninstallerGui
//
////////////////////////////////////////////////////////////////////
class QtCreatorUninstallerGui : public QObject
{
public:
QtCreatorUninstallerGui(QInstaller *installer)
: m_installer(installer)
{}
int exec()
{
QMessageBox::StandardButton bt = QMessageBox::question(0,
tr("Question"),
tr("Do you want to deinstall %1 and all of its modules?")
.arg(m_installer->value("ProductName")),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (bt == QMessageBox::No)
return 0;
QWizard wizard;
wizard.addPage(new QInstallerPerformUninstallationPage(m_installer));
wizard.show();
return qApp->exec();
}
private:
QInstaller *m_installer;
};
////////////////////////////////////////////////////////////////////
//
// The Main Driver Program
//
////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QStringList args = app.arguments();
qDebug() << "ARGS: " << args;
QtCreatorInstaller installer;
bool helpRequested = false;
bool guiRequested = true;
for (int i = 1; i < args.size(); ++i) {
if (args.at(i).contains('=')) {
const QString arg = args.at(i);
const QString name = arg.section('=', 0, 0);
const QString value = arg.section('=', 1, 1);
installer.setValue(name, value);
} else if (args.at(i) == "--help" || args.at(i) == "-h") {
helpRequested = true;
} else if (args.at(i) == "--no-gui" || args.at(i) == "NoGui") {
qDebug() << "NOGUI";
guiRequested = false;
} else if (args.at(i) == "--verbose" || args.at(i) == "Verbose") {
installer.setVerbose(true);
} else {
helpRequested = true;
}
}
if (installer.isVerbose())
installer.dump();
if (helpRequested) {
QString productName = installer.value("ProductName");
QString str;
if (installer.isCreator())
str = QString(" [SourceDir=<dir>]\n"
"\n Creates the %1 installer.\n").arg(productName);
else if (installer.isInstaller())
str = QString(" [--no-gui] [<name>=<value>...]\n"
"\n Runs the %1 installer\n"
"\n If the '--no-gui' parameter is given, it runs "
" installer without GUI\n").arg(productName);
else if (installer.isUninstaller())
str = QString(" [<name>=<value>...]\n"
"\n Runs the %1 uninstaller.\n").arg(productName);
str = "\nUsage: " + installer.installerBinaryPath() + str;
qDebug() << qPrintable(str);
return 0;
}
if (installer.isInstaller() && guiRequested) {
QtCreatorInstallerGui gui(&installer);
gui.show();
return app.exec();
}
#ifdef Q_OS_WIN
if (installer.isUninstaller()) {
QStringList newArgs = args;
newArgs.removeFirst();
installer.restartTempUninstaller(newArgs);
return 0;
}
#endif
if ((installer.isUninstaller() || installer.isTempUninstaller())
&& guiRequested) {
QtCreatorUninstallerGui gui(&installer);
//gui.show();
return gui.exec();
}
return installer.run() ? 0 : 1;
}
|