~bzoltan/kubuntu-packaging/decouple_cmake_plugin

« back to all changes in this revision

Viewing changes to src/plugins/qnx/blackberryinstallwizardpages.cpp

  • Committer: Timo Jyrinki
  • Date: 2013-11-15 12:25:23 UTC
  • mfrom: (1.1.28)
  • Revision ID: timo.jyrinki@canonical.com-20131115122523-i2kyamsu4gs2mu1m
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************
 
2
**
 
3
** Copyright (C) 2013 BlackBerry Limited. All rights reserved
 
4
**
 
5
** Contact: BlackBerry (qt@blackberry.com)
 
6
** Contact: KDAB (info@kdab.com)
 
7
**
 
8
** This file is part of Qt Creator.
 
9
**
 
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.
 
17
**
 
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.
 
25
**
 
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.
 
29
**
 
30
****************************************************************************/
 
31
 
 
32
#include "blackberryinstallwizardpages.h"
 
33
#include "blackberryconfigurationmanager.h"
 
34
#include "blackberryconfiguration.h"
 
35
 
 
36
#include "ui_blackberryinstallwizardtargetpage.h"
 
37
#include "ui_blackberryinstallwizardprocesspage.h"
 
38
#include "ui_blackberryinstallwizardndkpage.h"
 
39
 
 
40
#include "qnxutils.h"
 
41
 
 
42
#include <utils/synchronousprocess.h>
 
43
#include <utils/pathchooser.h>
 
44
 
 
45
#include <QProcess>
 
46
 
 
47
#include <QTreeWidgetItem>
 
48
 
 
49
#include <QFileInfo>
 
50
#include <QDir>
 
51
 
 
52
#include <QMessageBox>
 
53
#include <QLayout>
 
54
#include <QRadioButton>
 
55
 
 
56
namespace Qnx {
 
57
namespace Internal {
 
58
 
 
59
namespace {
 
60
const QLatin1String targetKeyWord("Native SDK");
 
61
}
 
62
 
 
63
NdkPathChooser::NdkPathChooser(Mode mode, QWidget *parent)
 
64
    : Utils::PathChooser(parent)
 
65
    , m_mode(mode)
 
66
{
 
67
    if (m_mode == NdkPathChooser::InstallMode)
 
68
        setExpectedKind(Utils::PathChooser::Directory);
 
69
    else
 
70
        setExpectedKind(Utils::PathChooser::File);
 
71
}
 
72
 
 
73
bool NdkPathChooser::validatePath(const QString &path, QString *errorMessage)
 
74
{
 
75
    bool result = PathChooser::validatePath(path, errorMessage);
 
76
    if (!result)
 
77
        return false;
 
78
 
 
79
    if (m_mode == NdkPathChooser::InstallMode)
 
80
        return !(QnxUtils::sdkInstallerPath(path).isEmpty());
 
81
 
 
82
    QFileInfo fi(path);
 
83
    return (fi.suffix() == QLatin1String("sh") || fi.suffix() == QLatin1String("bat"));
 
84
}
 
85
 
 
86
//------------------------------------------------------------------
 
87
 
 
88
BlackBerryInstallWizardOptionPage::BlackBerryInstallWizardOptionPage(BlackBerryInstallerDataHandler &data,
 
89
                                                                     QWidget *parent)
 
90
    : QWizardPage(parent)
 
91
    , m_layout(new QVBoxLayout(this))
 
92
    , m_installButton(new QRadioButton)
 
93
    , m_addButton(new QRadioButton)
 
94
    , m_envFileChooser(new NdkPathChooser(NdkPathChooser::ManualMode))
 
95
    , m_data(data)
 
96
{
 
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)));
 
100
}
 
101
 
 
102
void BlackBerryInstallWizardOptionPage::initializePage()
 
103
{
 
104
    m_installButton->setText(tr("Install New Target"));
 
105
    m_addButton->setText(tr("Add Existing Target"));
 
106
 
 
107
    if (m_data.mode == BlackBerryInstallerDataHandler::ManuallMode)
 
108
        m_addButton->setChecked(true);
 
109
    else
 
110
        m_installButton->setChecked(true);
 
111
 
 
112
    m_envFileChooser->setEnabled(m_addButton->isChecked());
 
113
 
 
114
    m_layout->addWidget(m_installButton);
 
115
    m_layout->addWidget(m_addButton);
 
116
    m_layout->addWidget(m_envFileChooser);
 
117
}
 
118
 
 
119
bool BlackBerryInstallWizardOptionPage::isComplete() const
 
120
{
 
121
    return (m_installButton->isChecked()
 
122
            || (m_addButton->isChecked() && m_envFileChooser->isValid()));
 
123
}
 
124
 
 
125
int BlackBerryInstallWizardOptionPage::nextId() const
 
126
{
 
127
    if (m_addButton->isChecked())
 
128
        return BlackBerryInstallWizard::FinalPageId;
 
129
 
 
130
    return BlackBerryInstallWizard::NdkPageId;
 
131
}
 
132
 
 
133
void BlackBerryInstallWizardOptionPage::handleOptionChanged()
 
134
{
 
135
    if (m_addButton->isChecked())
 
136
        m_data.mode = BlackBerryInstallerDataHandler::ManuallMode;
 
137
    else
 
138
        m_data.mode = BlackBerryInstallerDataHandler::InstallMode;
 
139
 
 
140
    m_envFileChooser->setEnabled(m_addButton->isChecked());
 
141
    emit completeChanged();
 
142
}
 
143
 
 
144
void BlackBerryInstallWizardOptionPage::handlePathChanged(const QString &envFilePath)
 
145
{
 
146
    if (m_envFileChooser->isValid())
 
147
        m_data.ndkPath = envFilePath;
 
148
 
 
149
    emit completeChanged();
 
150
}
 
151
 
 
152
//------------------------------------------------------------------
 
153
 
 
154
BlackBerryInstallWizardNdkPage::BlackBerryInstallWizardNdkPage(BlackBerryInstallerDataHandler &data, QWidget *parent)
 
155
    : QWizardPage(parent)
 
156
    , m_ui(new Ui_BlackBerryInstallWizardNdkPage)
 
157
    , m_data(data)
 
158
    , m_ndkPathChooser(new NdkPathChooser(NdkPathChooser::InstallMode))
 
159
    , m_manual(new QListWidgetItem)
 
160
    , m_validNdkPath(false)
 
161
{
 
162
    m_ui->setupUi(this);
 
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()));
 
167
}
 
168
 
 
169
BlackBerryInstallWizardNdkPage::~BlackBerryInstallWizardNdkPage()
 
170
{
 
171
    delete m_ui;
 
172
}
 
173
 
 
174
void BlackBerryInstallWizardNdkPage::initializePage()
 
175
{
 
176
    m_manual->setText(tr("Specify 10.2 NDK path manually"));
 
177
    m_ui->ndkPathListWidget->addItem(m_manual);
 
178
    m_manual->setSelected(true);
 
179
    QFont font;
 
180
    font.setItalic(true);
 
181
    m_manual->setFont(font);
 
182
    foreach (const NdkInstallInformation &ndk, QnxUtils::installedNdks()) {
 
183
        bool found = false;
 
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) {
 
187
                found = true;
 
188
                break;
 
189
            }
 
190
        }
 
191
 
 
192
        if (found)
 
193
            continue;
 
194
 
 
195
        if (!QnxUtils::sdkInstallerPath(ndk.path).isEmpty()) {
 
196
            QListWidgetItem *ndkItem = new QListWidgetItem(m_ui->ndkPathListWidget);
 
197
            ndkItem->setText(ndk.path);
 
198
        }
 
199
    }
 
200
}
 
201
 
 
202
void BlackBerryInstallWizardNdkPage::setNdkPath()
 
203
{
 
204
    if (m_ui->ndkPathListWidget->selectedItems().isEmpty())
 
205
        return;
 
206
 
 
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;
 
212
    } else {
 
213
        m_validNdkPath = false;
 
214
    }
 
215
 
 
216
    emit completeChanged();
 
217
}
 
218
 
 
219
void BlackBerryInstallWizardNdkPage::setManualNdkPath()
 
220
{
 
221
    if (m_ndkPathChooser->isValid()) {
 
222
        m_validNdkPath = true;
 
223
        m_data.ndkPath = m_ndkPathChooser->path();
 
224
    } else {
 
225
        m_validNdkPath = false;
 
226
    }
 
227
 
 
228
    emit completeChanged();
 
229
}
 
230
 
 
231
bool BlackBerryInstallWizardNdkPage::isComplete() const
 
232
{
 
233
    return m_validNdkPath;
 
234
}
 
235
 
 
236
//------------------------------------------------------------------
 
237
 
 
238
BlackBerryInstallWizardTargetPage::BlackBerryInstallWizardTargetPage(BlackBerryInstallerDataHandler &data,
 
239
                                                                     QWidget *parent)
 
240
    : QWizardPage(parent)
 
241
    , m_data(data)
 
242
    , m_ui(new Ui_BlackBerryInstallWizardTargetPage)
 
243
    , m_isTargetValid(false)
 
244
    , m_targetListProcess(new QProcess(this))
 
245
{
 
246
    m_ui->setupUi(this);
 
247
    setTitle(tr("Target"));
 
248
 
 
249
    connect(m_targetListProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
 
250
            this, SLOT(targetsListProcessFinished()));
 
251
    connect(m_ui->targetsTreeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(setTarget()));
 
252
}
 
253
 
 
254
BlackBerryInstallWizardTargetPage::~BlackBerryInstallWizardTargetPage()
 
255
{
 
256
    Utils::SynchronousProcess::stopProcess(*m_targetListProcess);
 
257
    delete m_ui;
 
258
}
 
259
 
 
260
void BlackBerryInstallWizardTargetPage::initializePage()
 
261
{
 
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()));
 
269
    }
 
270
 
 
271
    updateAvailableTargetsList();
 
272
}
 
273
 
 
274
bool BlackBerryInstallWizardTargetPage::isComplete() const
 
275
{
 
276
    return m_isTargetValid;
 
277
}
 
278
 
 
279
bool BlackBerryInstallWizardTargetPage::isProcessRunning() const
 
280
{
 
281
    return (m_targetListProcess->state() == QProcess::Running);
 
282
}
 
283
 
 
284
void BlackBerryInstallWizardTargetPage::targetsListProcessFinished()
 
285
{
 
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));
 
297
            }
 
298
        }
 
299
    }
 
300
 
 
301
    m_ui->targetsTreeWidget->sortByColumn(0, Qt::DescendingOrder);
 
302
 
 
303
}
 
304
 
 
305
void BlackBerryInstallWizardTargetPage::setTarget()
 
306
{
 
307
    if (m_ui->targetsTreeWidget->selectedItems().isEmpty())
 
308
        return;
 
309
 
 
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;
 
316
    } else {
 
317
        m_isTargetValid = false;
 
318
    }
 
319
 
 
320
    emit completeChanged();
 
321
}
 
322
 
 
323
void BlackBerryInstallWizardTargetPage::initTargetsTreeWidget()
 
324
{
 
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);
 
331
}
 
332
 
 
333
void BlackBerryInstallWizardTargetPage::updateAvailableTargetsList()
 
334
{
 
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..."));
 
339
    QFont font;
 
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);
 
345
}
 
346
 
 
347
//------------------------------------------------------------------
 
348
 
 
349
BlackBerryInstallWizardProcessPage::BlackBerryInstallWizardProcessPage(BlackBerryInstallerDataHandler &data,
 
350
                                                                       QWidget *parent)
 
351
    : QWizardPage(parent)
 
352
    , m_ui(new Ui_BlackBerryInstallWizardProcessPage)
 
353
    , m_data(data)
 
354
    , m_targetProcess(new QProcess(this))
 
355
{
 
356
    m_ui->setupUi(this);
 
357
    if (m_data.mode == BlackBerryInstallerDataHandler::UninstallMode)
 
358
        setTitle(tr("Uninstalling"));
 
359
    else
 
360
        setTitle(tr("Installing"));
 
361
 
 
362
    connect(m_targetProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
 
363
            this, SLOT(handleProcessFinished(int,QProcess::ExitStatus)));
 
364
}
 
365
 
 
366
BlackBerryInstallWizardProcessPage::~BlackBerryInstallWizardProcessPage()
 
367
{
 
368
    Utils::SynchronousProcess::stopProcess(*m_targetProcess);
 
369
    delete m_ui;
 
370
}
 
371
 
 
372
void BlackBerryInstallWizardProcessPage::initializePage()
 
373
{
 
374
    if (m_data.mode == BlackBerryInstallerDataHandler::UninstallMode) {
 
375
        if (m_data.version.isEmpty()) {
 
376
            wizard()->next();
 
377
            return;
 
378
        }
 
379
 
 
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;
 
384
                break;
 
385
            }
 
386
        }
 
387
 
 
388
        m_ui->label->setText(tr("Uninstalling target:") + QLatin1Char('\n') + m_data.target);
 
389
    } else {
 
390
        m_ui->label->setText(tr("Installing target:") + QLatin1Char('\n') + m_data.target);
 
391
    }
 
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)));
 
399
    }
 
400
 
 
401
    processTarget();
 
402
}
 
403
 
 
404
bool BlackBerryInstallWizardProcessPage::isComplete() const
 
405
{
 
406
    return false;
 
407
}
 
408
 
 
409
bool BlackBerryInstallWizardProcessPage::isProcessRunning() const
 
410
{
 
411
    return (m_targetProcess->state() == QProcess::Running);
 
412
}
 
413
 
 
414
void BlackBerryInstallWizardProcessPage::handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
 
415
{
 
416
    m_data.exitCode = exitCode;
 
417
    m_data.exitStatus = exitStatus;
 
418
 
 
419
    if (wizard()->currentPage() == this)
 
420
        wizard()->next();
 
421
}
 
422
 
 
423
void BlackBerryInstallWizardProcessPage::processTarget()
 
424
{
 
425
    QString option;
 
426
    if (m_data.mode == BlackBerryInstallerDataHandler::UninstallMode)
 
427
        option = QLatin1String(" --uninstall");
 
428
    else
 
429
        option = QLatin1String(" --install");
 
430
 
 
431
    QString version = m_data.version;
 
432
    QTC_ASSERT(!version.isEmpty(), return);
 
433
 
 
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();
 
439
                break;
 
440
            }
 
441
        }
 
442
    }
 
443
 
 
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);
 
449
 
 
450
    m_ui->progressBar->setMaximum(0);
 
451
    m_ui->progressBar->setMinimum(0);
 
452
    m_ui->progressBar->setValue(0);
 
453
}
 
454
 
 
455
// --------------------------------------------------------------------------------
 
456
 
 
457
BlackBerryInstallWizardFinalPage::BlackBerryInstallWizardFinalPage(BlackBerryInstallerDataHandler &data,
 
458
                                                                   QWidget *parent)
 
459
    : QWizardPage(parent)
 
460
    , m_data(data)
 
461
{
 
462
    setTitle(tr("Summary"));
 
463
}
 
464
 
 
465
void BlackBerryInstallWizardFinalPage::initializePage()
 
466
{
 
467
    QVBoxLayout *layout = new QVBoxLayout(this);
 
468
    QLabel *label = new QLabel(this);
 
469
    layout->addWidget(label);
 
470
 
 
471
    if (m_data.mode == BlackBerryInstallerDataHandler::ManuallMode) {
 
472
        BlackBerryConfigurationManager  &configManager = BlackBerryConfigurationManager::instance();
 
473
        BlackBerryConfiguration *config = configManager.configurationFromEnvFile(Utils::FileName::fromString(m_data.ndkPath));
 
474
 
 
475
        if (!config) {
 
476
            config = new BlackBerryConfiguration(Utils::FileName::fromString(m_data.ndkPath), false);
 
477
            if (!configManager.addConfiguration(config)) {
 
478
                delete 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));
 
481
                return;
 
482
            }
 
483
 
 
484
            label->setText(tr("Target is being added.").arg(m_data.ndkPath));
 
485
            emit done();
 
486
            return;
 
487
        } else {
 
488
            label->setText(tr("Target is already added.").arg(m_data.ndkPath));
 
489
            return;
 
490
        }
 
491
    }
 
492
 
 
493
    QString actionMsg;
 
494
    if (m_data.mode == BlackBerryInstallerDataHandler::UninstallMode)
 
495
        actionMsg = tr("uninstalling");
 
496
    else
 
497
        actionMsg = tr("installing");
 
498
 
 
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));
 
501
        emit done();
 
502
    } else {
 
503
        label->setText(tr("An error has occurred while %1 target:\n %2").arg(actionMsg, m_data.target));
 
504
    }
 
505
}
 
506
 
 
507
} // namespace Internal
 
508
} // namespace Qnx