1
/**************************************************************************
3
** Copyright (C) 2013 BlackBerry Limited. All rights reserved
5
** Contact: BlackBerry (qt@blackberry.com)
6
** Contact: KDAB (info@kdab.com)
8
** This file is part of Qt Creator.
10
** Commercial License Usage
11
** Licensees holding valid commercial Qt licenses may use this file in
12
** accordance with the commercial license agreement provided with the
13
** Software or, alternatively, in accordance with the terms contained in
14
** a written agreement between you and Digia. For licensing terms and
15
** conditions see http://qt.digia.com/licensing. For further information
16
** use the contact form at http://qt.digia.com/contact-us.
18
** GNU Lesser General Public License Usage
19
** Alternatively, this file may be used under the terms of the GNU Lesser
20
** General Public License version 2.1 as published by the Free Software
21
** Foundation and appearing in the file LICENSE.LGPL included in the
22
** packaging of this file. Please review the following information to
23
** ensure the GNU Lesser General Public License version 2.1 requirements
24
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
26
** In addition, as a special exception, Digia gives you certain additional
27
** rights. These rights are described in the Digia Qt LGPL Exception
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
30
****************************************************************************/
32
#include "blackberryinstallwizardpages.h"
33
#include "blackberryconfigurationmanager.h"
34
#include "blackberryconfiguration.h"
36
#include "ui_blackberryinstallwizardtargetpage.h"
37
#include "ui_blackberryinstallwizardprocesspage.h"
38
#include "ui_blackberryinstallwizardndkpage.h"
42
#include <utils/synchronousprocess.h>
43
#include <utils/pathchooser.h>
47
#include <QTreeWidgetItem>
52
#include <QMessageBox>
54
#include <QRadioButton>
60
const QLatin1String targetKeyWord("Native SDK");
63
NdkPathChooser::NdkPathChooser(Mode mode, QWidget *parent)
64
: Utils::PathChooser(parent)
67
if (m_mode == NdkPathChooser::InstallMode)
68
setExpectedKind(Utils::PathChooser::Directory);
70
setExpectedKind(Utils::PathChooser::File);
73
bool NdkPathChooser::validatePath(const QString &path, QString *errorMessage)
75
bool result = PathChooser::validatePath(path, errorMessage);
79
if (m_mode == NdkPathChooser::InstallMode)
80
return !(QnxUtils::sdkInstallerPath(path).isEmpty());
83
return (fi.suffix() == QLatin1String("sh") || fi.suffix() == QLatin1String("bat"));
86
//------------------------------------------------------------------
88
BlackBerryInstallWizardOptionPage::BlackBerryInstallWizardOptionPage(BlackBerryInstallerDataHandler &data,
91
, m_layout(new QVBoxLayout(this))
92
, m_installButton(new QRadioButton)
93
, m_addButton(new QRadioButton)
94
, m_envFileChooser(new NdkPathChooser(NdkPathChooser::ManualMode))
97
setTitle(tr("Options"));
98
connect(m_addButton, SIGNAL(toggled(bool)), this, SLOT(handleOptionChanged()));
99
connect(m_envFileChooser, SIGNAL(pathChanged(QString)), this, SLOT(handlePathChanged(QString)));
102
void BlackBerryInstallWizardOptionPage::initializePage()
104
m_installButton->setText(tr("Install New Target"));
105
m_addButton->setText(tr("Add Existing Target"));
107
if (m_data.mode == BlackBerryInstallerDataHandler::ManuallMode)
108
m_addButton->setChecked(true);
110
m_installButton->setChecked(true);
112
m_envFileChooser->setEnabled(m_addButton->isChecked());
114
m_layout->addWidget(m_installButton);
115
m_layout->addWidget(m_addButton);
116
m_layout->addWidget(m_envFileChooser);
119
bool BlackBerryInstallWizardOptionPage::isComplete() const
121
return (m_installButton->isChecked()
122
|| (m_addButton->isChecked() && m_envFileChooser->isValid()));
125
int BlackBerryInstallWizardOptionPage::nextId() const
127
if (m_addButton->isChecked())
128
return BlackBerryInstallWizard::FinalPageId;
130
return BlackBerryInstallWizard::NdkPageId;
133
void BlackBerryInstallWizardOptionPage::handleOptionChanged()
135
if (m_addButton->isChecked())
136
m_data.mode = BlackBerryInstallerDataHandler::ManuallMode;
138
m_data.mode = BlackBerryInstallerDataHandler::InstallMode;
140
m_envFileChooser->setEnabled(m_addButton->isChecked());
141
emit completeChanged();
144
void BlackBerryInstallWizardOptionPage::handlePathChanged(const QString &envFilePath)
146
if (m_envFileChooser->isValid())
147
m_data.ndkPath = envFilePath;
149
emit completeChanged();
152
//------------------------------------------------------------------
154
BlackBerryInstallWizardNdkPage::BlackBerryInstallWizardNdkPage(BlackBerryInstallerDataHandler &data, QWidget *parent)
155
: QWizardPage(parent)
156
, m_ui(new Ui_BlackBerryInstallWizardNdkPage)
158
, m_ndkPathChooser(new NdkPathChooser(NdkPathChooser::InstallMode))
159
, m_manual(new QListWidgetItem)
160
, m_validNdkPath(false)
163
setTitle(tr("Native SDK"));
164
m_ui->verticalLayout->addWidget(m_ndkPathChooser);
165
connect(m_ui->ndkPathListWidget, SIGNAL(itemSelectionChanged()), this, SLOT(setNdkPath()));
166
connect(m_ndkPathChooser, SIGNAL(pathChanged(QString)), this, SLOT(setManualNdkPath()));
169
BlackBerryInstallWizardNdkPage::~BlackBerryInstallWizardNdkPage()
174
void BlackBerryInstallWizardNdkPage::initializePage()
176
m_manual->setText(tr("Specify 10.2 NDK path manually"));
177
m_ui->ndkPathListWidget->addItem(m_manual);
178
m_manual->setSelected(true);
180
font.setItalic(true);
181
m_manual->setFont(font);
182
foreach (const NdkInstallInformation &ndk, QnxUtils::installedNdks()) {
184
for (int i = 0; i < m_ui->ndkPathListWidget->count(); i++) {
185
QListWidgetItem* item = m_ui->ndkPathListWidget->item(i);
186
if (item->text() == ndk.path) {
195
if (!QnxUtils::sdkInstallerPath(ndk.path).isEmpty()) {
196
QListWidgetItem *ndkItem = new QListWidgetItem(m_ui->ndkPathListWidget);
197
ndkItem->setText(ndk.path);
202
void BlackBerryInstallWizardNdkPage::setNdkPath()
204
if (m_ui->ndkPathListWidget->selectedItems().isEmpty())
207
m_ndkPathChooser->setEnabled(m_manual->isSelected());
208
QString selected = m_ui->ndkPathListWidget->selectedItems().first()->text();
209
if (!QnxUtils::sdkInstallerPath(selected).isEmpty()) {
210
m_validNdkPath = true;
211
m_data.ndkPath = selected;
213
m_validNdkPath = false;
216
emit completeChanged();
219
void BlackBerryInstallWizardNdkPage::setManualNdkPath()
221
if (m_ndkPathChooser->isValid()) {
222
m_validNdkPath = true;
223
m_data.ndkPath = m_ndkPathChooser->path();
225
m_validNdkPath = false;
228
emit completeChanged();
231
bool BlackBerryInstallWizardNdkPage::isComplete() const
233
return m_validNdkPath;
236
//------------------------------------------------------------------
238
BlackBerryInstallWizardTargetPage::BlackBerryInstallWizardTargetPage(BlackBerryInstallerDataHandler &data,
240
: QWizardPage(parent)
242
, m_ui(new Ui_BlackBerryInstallWizardTargetPage)
243
, m_isTargetValid(false)
244
, m_targetListProcess(new QProcess(this))
247
setTitle(tr("Target"));
249
connect(m_targetListProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
250
this, SLOT(targetsListProcessFinished()));
251
connect(m_ui->targetsTreeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(setTarget()));
254
BlackBerryInstallWizardTargetPage::~BlackBerryInstallWizardTargetPage()
256
Utils::SynchronousProcess::stopProcess(*m_targetListProcess);
260
void BlackBerryInstallWizardTargetPage::initializePage()
262
// process may be running if going back and forth
263
if (m_targetListProcess->state() == QProcess::Running) {
264
disconnect(m_targetListProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
265
this, SLOT(targetsListProcessFinished()));
266
Utils::SynchronousProcess::stopProcess(*m_targetListProcess);
267
connect(m_targetListProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
268
this, SLOT(targetsListProcessFinished()));
271
updateAvailableTargetsList();
274
bool BlackBerryInstallWizardTargetPage::isComplete() const
276
return m_isTargetValid;
279
bool BlackBerryInstallWizardTargetPage::isProcessRunning() const
281
return (m_targetListProcess->state() == QProcess::Running);
284
void BlackBerryInstallWizardTargetPage::targetsListProcessFinished()
286
initTargetsTreeWidget();
287
QString output = Utils::SynchronousProcess::normalizeNewlines(QString::fromLatin1(m_targetListProcess->readAll()));
288
QList<QString> targetList = output.split(QLatin1Char('\n'));
289
m_ui->targetsTreeWidget->clear();
290
foreach (const QString &target, targetList) {
291
if (!target.isEmpty() && target.contains(targetKeyWord)) {
292
QTreeWidgetItem *item = new QTreeWidgetItem(m_ui->targetsTreeWidget);
293
QStringList res = target.split(QLatin1Char('-'));
294
if (res.count() > 1) {
295
item->setText(0, res.at(0));
296
item->setText(1, res.at(1));
301
m_ui->targetsTreeWidget->sortByColumn(0, Qt::DescendingOrder);
305
void BlackBerryInstallWizardTargetPage::setTarget()
307
if (m_ui->targetsTreeWidget->selectedItems().isEmpty())
310
QString version = m_ui->targetsTreeWidget->selectedItems().first()->text(0);
311
QString target = m_ui->targetsTreeWidget->selectedItems().first()->text(1);
312
if (target.contains(targetKeyWord)) {
313
m_data.target = target;
314
m_data.version = version;
315
m_isTargetValid = true;
317
m_isTargetValid = false;
320
emit completeChanged();
323
void BlackBerryInstallWizardTargetPage::initTargetsTreeWidget()
325
m_ui->targetsTreeWidget->clear();
326
m_ui->targetsTreeWidget->setHeaderHidden(false);
327
m_ui->targetsTreeWidget->header()->setResizeMode(QHeaderView::ResizeToContents);
328
m_ui->targetsTreeWidget->setHeaderItem(new QTreeWidgetItem(QStringList() << tr("Version") << tr("Target")));
329
m_ui->targetsTreeWidget->setTextElideMode(Qt::ElideNone);
330
m_ui->targetsTreeWidget->setColumnCount(2);
333
void BlackBerryInstallWizardTargetPage::updateAvailableTargetsList()
335
m_ui->targetsTreeWidget->clear();
336
m_ui->targetsTreeWidget->setHeaderHidden(true);
337
QTreeWidgetItem *item = new QTreeWidgetItem(m_ui->targetsTreeWidget);
338
item->setText(0, tr("Querying available targets. Please wait..."));
340
font.setItalic(true);
341
item->setFont(0, font);
342
QString qdeProcess = QnxUtils::qdeInstallProcess(m_data.ndkPath, QLatin1String(" --list"));
343
QTC_ASSERT(!qdeProcess.isEmpty(), return);
344
m_targetListProcess->start(qdeProcess);
347
//------------------------------------------------------------------
349
BlackBerryInstallWizardProcessPage::BlackBerryInstallWizardProcessPage(BlackBerryInstallerDataHandler &data,
351
: QWizardPage(parent)
352
, m_ui(new Ui_BlackBerryInstallWizardProcessPage)
354
, m_targetProcess(new QProcess(this))
357
if (m_data.mode == BlackBerryInstallerDataHandler::UninstallMode)
358
setTitle(tr("Uninstalling"));
360
setTitle(tr("Installing"));
362
connect(m_targetProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
363
this, SLOT(handleProcessFinished(int,QProcess::ExitStatus)));
366
BlackBerryInstallWizardProcessPage::~BlackBerryInstallWizardProcessPage()
368
Utils::SynchronousProcess::stopProcess(*m_targetProcess);
372
void BlackBerryInstallWizardProcessPage::initializePage()
374
if (m_data.mode == BlackBerryInstallerDataHandler::UninstallMode) {
375
if (m_data.version.isEmpty()) {
380
foreach (const NdkInstallInformation &ndk, QnxUtils::installedNdks()) {
381
if (ndk.version == m_data.version) {
382
m_data.ndkPath = ndk.path;
383
m_data.target = ndk.name;
388
m_ui->label->setText(tr("Uninstalling target:") + QLatin1Char('\n') + m_data.target);
390
m_ui->label->setText(tr("Installing target:") + QLatin1Char('\n') + m_data.target);
392
// m_targetProcess could be running
393
if (m_targetProcess->state() == QProcess::Running) {
394
disconnect(m_targetProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
395
this, SLOT(handleProcessFinished(int,QProcess::ExitStatus)));
396
Utils::SynchronousProcess::stopProcess(*m_targetProcess);
397
connect(m_targetProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
398
this, SLOT(handleProcessFinished(int,QProcess::ExitStatus)));
404
bool BlackBerryInstallWizardProcessPage::isComplete() const
409
bool BlackBerryInstallWizardProcessPage::isProcessRunning() const
411
return (m_targetProcess->state() == QProcess::Running);
414
void BlackBerryInstallWizardProcessPage::handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
416
m_data.exitCode = exitCode;
417
m_data.exitStatus = exitStatus;
419
if (wizard()->currentPage() == this)
423
void BlackBerryInstallWizardProcessPage::processTarget()
426
if (m_data.mode == BlackBerryInstallerDataHandler::UninstallMode)
427
option = QLatin1String(" --uninstall");
429
option = QLatin1String(" --install");
431
QString version = m_data.version;
432
QTC_ASSERT(!version.isEmpty(), return);
434
// deactivate target if activated before uninstalling
435
if (m_data.mode == BlackBerryInstallerDataHandler::UninstallMode) {
436
foreach (BlackBerryConfiguration *config, BlackBerryConfigurationManager::instance().configurations()) {
437
if (m_data.target.contains((config->targetName())) && config->isActive()) {
438
config->deactivate();
444
// Killing the sdkinstall process won't kill the qde process it launched
445
// thus, let's directly launch the resulting qde process
446
QString qdeProcess = QnxUtils::qdeInstallProcess(m_data.ndkPath, option, version);
447
QTC_ASSERT(!qdeProcess.isEmpty(), return);
448
m_targetProcess->start(qdeProcess);
450
m_ui->progressBar->setMaximum(0);
451
m_ui->progressBar->setMinimum(0);
452
m_ui->progressBar->setValue(0);
455
// --------------------------------------------------------------------------------
457
BlackBerryInstallWizardFinalPage::BlackBerryInstallWizardFinalPage(BlackBerryInstallerDataHandler &data,
459
: QWizardPage(parent)
462
setTitle(tr("Summary"));
465
void BlackBerryInstallWizardFinalPage::initializePage()
467
QVBoxLayout *layout = new QVBoxLayout(this);
468
QLabel *label = new QLabel(this);
469
layout->addWidget(label);
471
if (m_data.mode == BlackBerryInstallerDataHandler::ManuallMode) {
472
BlackBerryConfigurationManager &configManager = BlackBerryConfigurationManager::instance();
473
BlackBerryConfiguration *config = configManager.configurationFromEnvFile(Utils::FileName::fromString(m_data.ndkPath));
476
config = new BlackBerryConfiguration(Utils::FileName::fromString(m_data.ndkPath), false);
477
if (!configManager.addConfiguration(config)) {
479
// TODO: more explicit error message!
480
label->setText(tr("An error has occurred while adding target from:\n %1").arg(m_data.ndkPath));
484
label->setText(tr("Target is being added.").arg(m_data.ndkPath));
488
label->setText(tr("Target is already added.").arg(m_data.ndkPath));
494
if (m_data.mode == BlackBerryInstallerDataHandler::UninstallMode)
495
actionMsg = tr("uninstalling");
497
actionMsg = tr("installing");
499
if (m_data.exitCode == 0 && m_data.exitStatus == QProcess::NormalExit) {
500
label->setText(tr("Finished %1 target:\n %2").arg(actionMsg, m_data.target));
503
label->setText(tr("An error has occurred while %1 target:\n %2").arg(actionMsg, m_data.target));
507
} // namespace Internal