1
/**************************************************************************
3
** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
5
** Contact: BlackBerry (qt@blackberry.com)
7
** This file is part of Qt Creator.
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
****************************************************************************/
31
#include "blackberrysetupwidget.h"
33
#include "blackberryconfigurationmanager.h"
34
#include "blackberryapilevelconfiguration.h"
35
#include "blackberrysigningutils.h"
36
#include "blackberrydeviceconfigurationwizard.h"
37
#include "blackberryinstallwizard.h"
38
#include "blackberrycertificate.h"
39
#include "qnxconstants.h"
41
#include <projectexplorer/devicesupport/devicemanager.h>
45
#include <QHBoxLayout>
47
#include <QPushButton>
48
#include <QDesktopServices>
51
#include <QMessageBox>
56
SetupItem::SetupItem(const QString &desc, QWidget *parent)
59
m_timer.setSingleShot(true);
60
connect(&m_timer, SIGNAL(timeout()), this, SLOT(validate()));
62
setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
63
QVBoxLayout *frameLayout = new QVBoxLayout(this);
65
QHBoxLayout *childLayout = new QHBoxLayout;
66
frameLayout->addLayout(childLayout);
69
childLayout->addWidget(m_icon);
72
m_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
73
childLayout->addWidget(m_label);
75
m_button = new QPushButton;
76
childLayout->addWidget(m_button);
77
QObject::connect(m_button, SIGNAL(clicked()), this, SLOT(onFixPressed()));
79
if (!desc.isEmpty()) {
80
m_desc = new QLabel(desc);
81
m_desc->setWordWrap(true);
82
QFont font = m_desc->font();
84
m_desc->setFont(font);
85
frameLayout->addWidget(m_desc);
89
void SetupItem::set(Status status, const QString &message, const QString &fixText)
94
icon = Qnx::Constants::QNX_OK_ICON;
97
icon = Qnx::Constants::QNX_INFO_ICON;
100
icon = Qnx::Constants::QNX_WARNING_ICON;
103
icon = Qnx::Constants::QNX_ERROR_ICON;
106
m_icon->setPixmap(QPixmap(QLatin1String(icon)));
107
m_label->setText(message);
108
m_button->setVisible(!fixText.isEmpty());
109
m_button->setText(fixText);
112
void SetupItem::onFixPressed()
118
void SetupItem::validateLater()
120
// BlackBerryConfigurationManager.settingsChanged and DeviceManager.updated signals
121
// may be emitted multiple times during the same event handling. This would result in multiple
122
// validation() calls even through just one is needed.
123
// QTimer allows to merge those multiple signal emits into a single validate() call.
127
APILevelSetupItem::APILevelSetupItem(QWidget *parent)
128
: SetupItem(tr("API Level defines kits, Qt versions, compilers, debuggers needed"
129
" for building BlackBerry applications."), parent)
132
connect(BlackBerryConfigurationManager::instance(), SIGNAL(settingsChanged()),
133
this, SLOT(validateLater()));
136
void APILevelSetupItem::validate()
138
FoundTypes found = resolvedFoundType();
139
if (!found.testFlag(Any))
140
set(Error, tr("No API Level is installed."), tr("Install"));
141
else if (!found.testFlag(Valid))
142
set(Error, tr("No valid API Level is installed."), tr("Install"));
143
else if (!found.testFlag(Active))
144
set(Error, tr("Valid API Level is not activated."), tr("Activate"));
145
else if (!found.testFlag(V_10_2))
146
set(Warning, tr("Valid API Level 10.2 or newer is not installed."), tr("Install"));
147
else if (!found.testFlag(V_10_2_AS_DEFAULT))
148
set(Warning, tr("Valid API Level 10.2 or newer is not set as default."), tr("Set"));
150
set(Ok, tr("API Level is configured."));
151
// TODO: should we check something more e.g. BB10 kits are valid?
154
void APILevelSetupItem::fix()
156
FoundTypes found = resolvedFoundType();
157
if (!found.testFlag(Any) || !found.testFlag(Valid)) {
159
} else if (!found.testFlag(Active)) {
160
foreach (BlackBerryApiLevelConfiguration *config,
161
BlackBerryConfigurationManager::instance()->apiLevels()) {
162
if (config->isValid() && !config->isActive()) {
167
} else if (!found.testFlag(V_10_2)) {
168
// TODO: install filter for 10.2 only
170
} else if (!found.testFlag(V_10_2_AS_DEFAULT)) {
171
BlackBerryConfigurationManager::instance()->setDefaultConfiguration(0);
175
APILevelSetupItem::FoundTypes APILevelSetupItem::resolvedFoundType()
179
// TODO: for now, all Trunk versions are understood as 10.2 compliant
180
BlackBerryVersionNumber version_10_2(QLatin1String("10.2.0.0"));
181
foreach (BlackBerryApiLevelConfiguration *config,
182
BlackBerryConfigurationManager::instance()->apiLevels()) {
184
if (config->isValid()) {
186
if (config->isActive())
188
if (config->version() > version_10_2)
193
BlackBerryApiLevelConfiguration *config =
194
BlackBerryConfigurationManager::instance()->defaultApiLevel();
195
if (config && config->version() > version_10_2)
196
found |= V_10_2_AS_DEFAULT;
201
void APILevelSetupItem::installAPILevel()
203
BlackBerryInstallWizard wizard(
204
BlackBerryInstallerDataHandler::InstallMode,
205
BlackBerryInstallerDataHandler::ApiLevel, QString(), this);
206
connect(&wizard, SIGNAL(processFinished()), this, SLOT(handleInstallationFinished()));
210
void APILevelSetupItem::handleInstallationFinished()
212
// manually-added API Levels are automatically registered by BlackBerryInstallWizard
213
// auto-detected API Levels needs to reloaded explicitly
214
BlackBerryConfigurationManager::instance()->loadAutoDetectedApiLevels();
218
SigningKeysSetupItem::SigningKeysSetupItem(QWidget *parent)
219
: SetupItem(tr("Signing keys are needed for signing BlackBerry applications"
220
" and managing debug tokens."), parent)
223
connect(&BlackBerrySigningUtils::instance(), SIGNAL(defaultCertificateLoaded(int)),
224
this, SLOT(validate()));
227
void SigningKeysSetupItem::validate()
229
BlackBerrySigningUtils &utils = BlackBerrySigningUtils::instance();
230
if (utils.hasLegacyKeys())
231
set(Error, tr("Found legacy BlackBerry signing keys."), tr("Update"));
232
else if (!utils.hasRegisteredKeys())
233
set(Error, tr("Cannot find BlackBerry signing keys."), tr("Request"));
234
else if (!QFileInfo(BlackBerryConfigurationManager::instance()->defaultKeystorePath()).exists())
235
set(Error, tr("Cannot find developer certificate."), tr("Create"));
236
else if (utils.defaultCertificateOpeningStatus() != BlackBerrySigningUtils::Opened)
237
set(Info, tr("Developer certificate is not opened."), tr("Open"));
239
set(Ok, tr("Signing keys are ready to use."));
242
void SigningKeysSetupItem::fix()
244
BlackBerrySigningUtils &utils = BlackBerrySigningUtils::instance();
245
if (utils.hasLegacyKeys()) {
246
QDesktopServices::openUrl(QUrl(QLatin1String(Qnx::Constants::QNX_LEGACY_KEYS_URL)));
247
} else if (!utils.hasRegisteredKeys()) {
248
QDesktopServices::openUrl(QUrl(QLatin1String(Qnx::Constants::QNX_REGISTER_KEYS_URL)));
249
} else if (!QFileInfo(BlackBerryConfigurationManager::instance()->defaultKeystorePath()).exists()) {
250
set(Info, tr("Opening certificate..."));
251
utils.createCertificate();
252
} else if (utils.defaultCertificateOpeningStatus() != BlackBerrySigningUtils::Opened) {
253
connect(&utils, SIGNAL(defaultCertificateLoaded(int)), this, SLOT(defaultCertificateLoaded(int)));
254
utils.openDefaultCertificate(this);
258
void SigningKeysSetupItem::defaultCertificateLoaded(int status)
260
BlackBerrySigningUtils &utils = BlackBerrySigningUtils::instance();
261
disconnect(&utils, SIGNAL(defaultCertificateLoaded(int)), this, SLOT(defaultCertificateLoaded(int)));
263
case BlackBerryCertificate::Success:
264
// handled by the connect in ctor already
266
case BlackBerryCertificate::WrongPassword:
267
QMessageBox::critical(this, tr("Qt Creator"), tr("Invalid certificate password."));
269
case BlackBerryCertificate::Busy:
270
case BlackBerryCertificate::InvalidOutputFormat:
271
case BlackBerryCertificate::Error:
272
QMessageBox::critical(this, tr("Qt Creator"), tr("Error loading certificate."));
277
DeviceSetupItem::DeviceSetupItem(QWidget *parent)
278
: SetupItem(tr("BlackBerry 10 device or simulator is needed for running BlackBerry applications."),
282
connect(ProjectExplorer::DeviceManager::instance(), SIGNAL(updated()),
283
this, SLOT(validateLater()));
286
void DeviceSetupItem::validate()
289
ProjectExplorer::DeviceManager *manager = ProjectExplorer::DeviceManager::instance();
290
for (int i = 0; i < manager->deviceCount(); i ++) {
291
ProjectExplorer::IDevice::ConstPtr device = manager->deviceAt(i);
292
if (device->type() == Constants::QNX_BB_OS_TYPE) {
298
set(Error, tr("No BlackBerry 10 device or simulator is registered."), tr("Add"));
300
set(Ok, tr("BlackBerry 10 device or simulator is registered."));
301
// TODO: check for existence of an API Level matching a device?
304
void DeviceSetupItem::fix()
306
BlackBerryDeviceConfigurationWizard wizard(this);
307
if (wizard.exec() == QDialog::Accepted)
308
ProjectExplorer::DeviceManager::instance()->addDevice(wizard.device());
311
BlackBerrySetupWidget::BlackBerrySetupWidget(QWidget *parent)
314
QVBoxLayout *layout = new QVBoxLayout(this);
317
layout->addWidget(new APILevelSetupItem);
318
layout->addWidget(new SigningKeysSetupItem);
319
layout->addWidget(new DeviceSetupItem);
321
layout->addStretch();
323
QLabel *howTo = new QLabel;
324
howTo->setTextFormat(Qt::RichText);
325
howTo->setTextInteractionFlags(Qt::TextBrowserInteraction);
326
howTo->setOpenExternalLinks(true);
327
howTo->setText(tr("<a href=\"%1\">How to Setup Qt Creator for BlackBerry 10 development</a>")
328
.arg(QLatin1String(Qnx::Constants::QNX_BLACKBERRY_SETUP_URL)));
329
layout->addWidget(howTo);
332
} // namespace Internal