summaryrefslogtreecommitdiff
path: root/src/plugins/qnx/blackberrysetupwizardpages.cpp
blob: 4284591a3c076dcba05e73b14fcb059f029af237 (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
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
/**************************************************************************
**
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
**
** Contact: BlackBerry (qt@blackberry.com)
** Contact: KDAB (info@kdab.com)
**
** This file is part of Qt Creator.
**
** 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 Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

#include "blackberrysetupwizardpages.h"
#include "blackberryndksettingswidget.h"
#include "blackberryconfiguration.h"
#include "blackberrysigningutils.h"
#include "ui_blackberrysetupwizardkeyspage.h"
#include "ui_blackberrysetupwizardcertificatepage.h"
#include "ui_blackberrysetupwizarddevicepage.h"
#include "ui_blackberrysetupwizardfinishpage.h"

#include <QVBoxLayout>
#include <QFileInfo>
#include <QLabel>
#include <QVBoxLayout>
#include <QMessageBox>
#include <QAbstractButton>
#include <QDesktopServices>
#include <QUrl>

#include <QDebug>

using namespace Qnx;
using namespace Qnx::Internal;

BlackBerrySetupWizardWelcomePage::BlackBerrySetupWizardWelcomePage(QWidget *parent) :
    QWizardPage(parent)
{
    const QString welcomeMessage =
        tr("Welcome to the BlackBerry Development "
           "Environment Setup Wizard.\nThis wizard will guide you through "
           "the essential steps to deploy a ready-to-go development environment "
           "for BlackBerry 10 devices.");

    setTitle(tr("BlackBerry Development Environment Setup"));

    QLabel *label = new QLabel(this);
    label->setWordWrap(true);
    label->setText(welcomeMessage);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addStretch();
    layout->addWidget(label);
    layout->addStretch();

    setLayout(layout);
}

//-----------------------------------------------------------------------------

BlackBerrySetupWizardNdkPage::BlackBerrySetupWizardNdkPage(QWidget *parent) :
    QWizardPage(parent),
    m_widget(0)
{
    setTitle(tr("Configure the NDK Path"));

    m_widget = new BlackBerryNDKSettingsWidget(this);
    m_widget->setWizardMessageVisible(false);

    connect(m_widget, SIGNAL(kitsUpdated()), this, SIGNAL(completeChanged()));

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(m_widget);

    setLayout(layout);
}

BlackBerrySetupWizardNdkPage::~BlackBerrySetupWizardNdkPage()
{
}

bool BlackBerrySetupWizardNdkPage::isComplete() const
{
    return m_widget->hasActiveNdk();
}

//-----------------------------------------------------------------------------

BlackBerrySetupWizardKeysPage::BlackBerrySetupWizardKeysPage(QWidget *parent) :
    QWizardPage(parent),
    m_ui(0),
    m_complete(false)
{
    setTitle(tr("Setup Signing Keys"));

    initUi();
}

BlackBerrySetupWizardKeysPage::~BlackBerrySetupWizardKeysPage()
{
    delete m_ui;
    m_ui = 0;
}

void BlackBerrySetupWizardKeysPage::showKeysMessage(const QString &url)
{
    const QMessageBox::StandardButton button = QMessageBox::question(this,
            tr("Qt Creator"),
            tr("This wizard will be closed and you will be taken to the BlackBerry "
                "key request web page. Do you want to continue?"),
            QMessageBox::Yes | QMessageBox::No);

    if (button == QMessageBox::Yes) {
        QDesktopServices::openUrl(QUrl(url));
        wizard()->reject();
    }
}

bool BlackBerrySetupWizardKeysPage::isComplete() const
{
    return m_complete;
}

void BlackBerrySetupWizardKeysPage::initUi()
{
    BlackBerrySigningUtils &utils = BlackBerrySigningUtils::instance();

    m_ui = new Ui::BlackBerrySetupWizardKeysPage;
    m_ui->setupUi(this);

    if (utils.hasLegacyKeys()) {
        m_ui->linkLabel->setVisible(false);
        m_ui->legacyLabel->setVisible(true);
        m_ui->statusLabel->setVisible(false);

        setComplete(false);
    } else if (utils.hasRegisteredKeys()) {
        m_ui->linkLabel->setVisible(false);
        m_ui->legacyLabel->setVisible(false);
        m_ui->statusLabel->setVisible(true);

        setComplete(true);
    } else {
        m_ui->linkLabel->setVisible(true);
        m_ui->legacyLabel->setVisible(false);
        m_ui->statusLabel->setVisible(false);

        setComplete(false);
    }

    connect(m_ui->linkLabel, SIGNAL(linkActivated(QString)),
            this, SLOT(showKeysMessage(QString)));
    connect(m_ui->legacyLabel, SIGNAL(linkActivated(QString)),
            this, SLOT(showKeysMessage(QString)));
}

void BlackBerrySetupWizardKeysPage::setComplete(bool complete)
{
    if (m_complete != complete) {
        m_complete = complete;
        m_ui->linkLabel->setVisible(!complete);
        m_ui->statusLabel->setVisible(complete);
        emit completeChanged();
    }
}

//-----------------------------------------------------------------------------

const char BlackBerrySetupWizardCertificatePage::AuthorField[] = "CertificatePage::Author";
const char BlackBerrySetupWizardCertificatePage::PasswordField[] = "CertificatePage::Password";
const char BlackBerrySetupWizardCertificatePage::PasswordField2[] = "CertificatePage::Password2";

BlackBerrySetupWizardCertificatePage::BlackBerrySetupWizardCertificatePage(QWidget *parent)
    : QWizardPage(parent),
    m_ui(0),
    m_complete(false)
{
    setTitle(tr("Create Developer Certificate"));

    initUi();
}

bool BlackBerrySetupWizardCertificatePage::isComplete() const
{
    return m_complete;
}

void BlackBerrySetupWizardCertificatePage::validate()
{
    if (m_ui->author->text().isEmpty()
            || m_ui->password->text().isEmpty()
            || m_ui->password2->text().isEmpty()) {
        m_ui->status->clear();
        setComplete(false);
        return;
    }

    if (m_ui->password->text() != m_ui->password2->text()) {
        m_ui->status->setText(tr("The entered passwords do not match."));
        setComplete(false);
        return;
    }

    m_ui->status->clear();
    setComplete(true);
}

void BlackBerrySetupWizardCertificatePage::checkBoxChanged(int state)
{
    if (state == Qt::Checked) {
        m_ui->password->setEchoMode(QLineEdit::Normal);
        m_ui->password2->setEchoMode(QLineEdit::Normal);
    } else {
        m_ui->password->setEchoMode(QLineEdit::Password);
        m_ui->password2->setEchoMode(QLineEdit::Password);
    }
}

void BlackBerrySetupWizardCertificatePage::setComplete(bool complete)
{
    if (m_complete != complete) {
        m_complete = complete;
        emit completeChanged();
    }
}

void BlackBerrySetupWizardCertificatePage::initUi()
{
    m_ui = new Ui::BlackBerrySetupWizardCertificatePage;
    m_ui->setupUi(this);
    m_ui->status->clear();

    connect(m_ui->author, SIGNAL(textChanged(QString)),
            this, SLOT(validate()));
    connect(m_ui->password, SIGNAL(textChanged(QString)),
            this, SLOT(validate()));
    connect(m_ui->password2, SIGNAL(textChanged(QString)),
            this, SLOT(validate()));
    connect(m_ui->showPassword, SIGNAL(stateChanged(int)),
            this, SLOT(checkBoxChanged(int)));

    registerField(QLatin1String(AuthorField) + QLatin1Char('*'), m_ui->author);
    registerField(QLatin1String(PasswordField) + QLatin1Char('*'), m_ui->password);
    registerField(QLatin1String(PasswordField2) + QLatin1Char('*'), m_ui->password2);
}

//-----------------------------------------------------------------------------

const char BlackBerrySetupWizardDevicePage::NameField[] = "DevicePage::Name";
const char BlackBerrySetupWizardDevicePage::IpAddressField[] = "DevicePage::IpAddress";
const char BlackBerrySetupWizardDevicePage::PasswordField[] = "DevicePage::PasswordField";
const char BlackBerrySetupWizardDevicePage::PhysicalDeviceField[] = "DevicePage::PhysicalDeviceField";


BlackBerrySetupWizardDevicePage::BlackBerrySetupWizardDevicePage(QWidget *parent)
    : QWizardPage(parent),
    m_ui(0)
{
    setTitle(tr("Configure BlackBerry Device Connection"));

    m_ui = new Ui::BlackBerrySetupWizardDevicePage;
    m_ui->setupUi(this);

    m_ui->deviceName->setText(tr("BlackBerry Device"));
    m_ui->ipAddress->setText(QLatin1String("169.254.0.1"));

    connect(m_ui->deviceName, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged()));
    connect(m_ui->ipAddress, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged()));
    connect(m_ui->password, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged()));
    connect(m_ui->physicalDevice, SIGNAL(toggled(bool)), this, SIGNAL(completeChanged()));

    registerField(QLatin1String(NameField) + QLatin1Char('*'), m_ui->deviceName);
    registerField(QLatin1String(IpAddressField) + QLatin1Char('*'), m_ui->ipAddress);
    registerField(QLatin1String(PasswordField), m_ui->password);
    registerField(QLatin1String(PhysicalDeviceField), m_ui->physicalDevice);
}

bool BlackBerrySetupWizardDevicePage::isComplete() const
{
    if (m_ui->deviceName->text().isEmpty() || m_ui->ipAddress->text().isEmpty())
        return false;

    const bool passwordMandatory = m_ui->physicalDevice->isChecked();

    if (passwordMandatory && m_ui->password->text().isEmpty())
        return false;

    return true;
}

//-----------------------------------------------------------------------------

BlackBerrySetupWizardFinishPage::BlackBerrySetupWizardFinishPage(QWidget *parent)
    : QWizardPage(parent),
    m_ui(0)
{
    setSubTitle(tr("Your environment is ready to be configured."));

    m_ui = new Ui::BlackBerrySetupWizardFinishPage;
    m_ui->setupUi(this);
    setProgress(QString(), -1);
}

void BlackBerrySetupWizardFinishPage::setProgress(const QString &status, int progress)
{
    if (progress < 0) {
        m_ui->progressBar->hide();
        m_ui->statusLabel->clear();
        return;
    } else if (!m_ui->progressBar->isVisible()) {
        m_ui->progressBar->show();
    }

    m_ui->statusLabel->setText(status);
    m_ui->progressBar->setValue(progress);
}