2012-06-29 07:23:13 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2011 - 2013 Research In Motion
|
2012-06-29 07:23:13 +02:00
|
|
|
**
|
|
|
|
|
** Contact: Research In Motion (blackberry-qt@qnx.com)
|
|
|
|
|
** Contact: KDAB (info@kdab.com)
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-06-29 07:23:13 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
2012-06-29 07:23:13 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2012-06-29 07:23:13 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-06-29 07:23:13 +02:00
|
|
|
|
|
|
|
|
#include "blackberrydeviceconfigurationwizardpages.h"
|
2013-04-16 14:53:24 +02:00
|
|
|
#include "blackberryconfiguration.h"
|
2013-03-12 12:04:07 +01:00
|
|
|
#include "blackberrydebugtokenrequestdialog.h"
|
2013-04-23 10:39:05 +02:00
|
|
|
#include "blackberrysshkeysgenerator.h"
|
2012-06-29 07:23:13 +02:00
|
|
|
#include "ui_blackberrydeviceconfigurationwizardsetuppage.h"
|
|
|
|
|
#include "ui_blackberrydeviceconfigurationwizardsshkeypage.h"
|
2013-04-30 07:49:37 +02:00
|
|
|
#include "blackberryconfiguration.h"
|
2013-06-12 14:09:01 +02:00
|
|
|
#include "qnxutils.h"
|
2012-06-29 07:23:13 +02:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <ssh/sshkeygenerator.h>
|
|
|
|
|
|
2013-04-30 07:49:37 +02:00
|
|
|
#include <QDir>
|
2012-06-29 07:23:13 +02:00
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QMessageBox>
|
2013-04-16 14:53:24 +02:00
|
|
|
#include <QFileDialog>
|
2013-03-18 14:47:33 +01:00
|
|
|
#include <QFileInfo>
|
2013-04-16 14:53:24 +02:00
|
|
|
#include <QHostInfo>
|
2012-06-29 07:23:13 +02:00
|
|
|
|
2012-07-25 17:41:01 +02:00
|
|
|
using namespace ProjectExplorer;
|
2012-06-29 07:23:13 +02:00
|
|
|
using namespace Qnx;
|
|
|
|
|
using namespace Qnx::Internal;
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
const char DEVICENAME_FIELD_ID[] = "DeviceName";
|
2012-12-21 08:36:06 -05:00
|
|
|
|
|
|
|
|
QString defaultDeviceHostIp(IDevice::MachineType type)
|
|
|
|
|
{
|
|
|
|
|
return type == IDevice::Hardware ? QLatin1String("169.254.0.1") : QString();
|
|
|
|
|
}
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BlackBerryDeviceConfigurationWizardSetupPage::BlackBerryDeviceConfigurationWizardSetupPage(QWidget *parent)
|
|
|
|
|
: QWizardPage(parent)
|
|
|
|
|
, m_ui(new Ui::BlackBerryDeviceConfigurationWizardSetupPage)
|
|
|
|
|
{
|
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
|
setTitle(tr("Connection Details"));
|
|
|
|
|
|
|
|
|
|
m_ui->debugToken->setExpectedKind(Utils::PathChooser::File);
|
|
|
|
|
m_ui->debugToken->setPromptDialogFilter(QLatin1String("*.bar"));
|
|
|
|
|
|
2013-06-12 14:09:01 +02:00
|
|
|
QString debugTokenBrowsePath = QnxUtils::dataDirPath();
|
2013-04-30 07:49:37 +02:00
|
|
|
if (!QFileInfo(debugTokenBrowsePath).exists())
|
|
|
|
|
debugTokenBrowsePath = QDir::homePath();
|
|
|
|
|
m_ui->debugToken->setInitialBrowsePathBackup(debugTokenBrowsePath);
|
|
|
|
|
|
2012-06-29 07:23:13 +02:00
|
|
|
connect(m_ui->deviceName, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged()));
|
|
|
|
|
connect(m_ui->deviceHostIp, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged()));
|
2012-12-21 08:36:06 -05:00
|
|
|
connect(m_ui->physicalDevice, SIGNAL(toggled(bool)), this, SLOT(handleMachineTypeChanged()));
|
2013-02-13 14:15:33 +01:00
|
|
|
connect(m_ui->physicalDevice, SIGNAL(toggled(bool)), this, SIGNAL(completeChanged()));
|
2012-06-29 07:23:13 +02:00
|
|
|
connect(m_ui->debugToken, SIGNAL(changed(QString)), this, SIGNAL(completeChanged()));
|
2013-02-18 19:22:21 -03:00
|
|
|
connect(m_ui->requestButton, SIGNAL(clicked()), this, SLOT(requestDebugToken()));
|
2012-06-29 07:23:13 +02:00
|
|
|
|
|
|
|
|
registerField(QLatin1String(DEVICENAME_FIELD_ID), m_ui->deviceName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BlackBerryDeviceConfigurationWizardSetupPage::~BlackBerryDeviceConfigurationWizardSetupPage()
|
|
|
|
|
{
|
|
|
|
|
delete m_ui;
|
|
|
|
|
m_ui = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlackBerryDeviceConfigurationWizardSetupPage::initializePage()
|
|
|
|
|
{
|
|
|
|
|
m_ui->deviceName->setText(tr("BlackBerry Device"));
|
|
|
|
|
m_ui->password->setText(QString());
|
|
|
|
|
m_ui->physicalDevice->setChecked(true);
|
2012-12-21 08:36:06 -05:00
|
|
|
m_ui->deviceHostIp->setText(defaultDeviceHostIp(machineType()));
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BlackBerryDeviceConfigurationWizardSetupPage::isComplete() const
|
|
|
|
|
{
|
|
|
|
|
bool debugTokenComplete = m_ui->simulator->isChecked()
|
|
|
|
|
|| (m_ui->physicalDevice->isChecked() && !m_ui->debugToken->fileName().isEmpty()
|
|
|
|
|
&& QFileInfo(m_ui->debugToken->fileName().toString()).exists());
|
|
|
|
|
|
|
|
|
|
return !m_ui->deviceHostIp->text().isEmpty() && !m_ui->deviceHostIp->text().isEmpty()
|
|
|
|
|
&& debugTokenComplete;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString BlackBerryDeviceConfigurationWizardSetupPage::deviceName() const
|
|
|
|
|
{
|
|
|
|
|
return m_ui->deviceName->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString BlackBerryDeviceConfigurationWizardSetupPage::hostName() const
|
|
|
|
|
{
|
|
|
|
|
return m_ui->deviceHostIp->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString BlackBerryDeviceConfigurationWizardSetupPage::password() const
|
|
|
|
|
{
|
|
|
|
|
return m_ui->password->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString BlackBerryDeviceConfigurationWizardSetupPage::debugToken() const
|
|
|
|
|
{
|
|
|
|
|
return m_ui->debugToken->fileName().toString();
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-25 17:41:01 +02:00
|
|
|
IDevice::MachineType BlackBerryDeviceConfigurationWizardSetupPage::machineType() const
|
2012-06-29 07:23:13 +02:00
|
|
|
{
|
2012-07-25 17:41:01 +02:00
|
|
|
return m_ui->physicalDevice->isChecked() ? IDevice::Hardware : IDevice::Emulator;
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
2012-12-21 08:36:06 -05:00
|
|
|
void BlackBerryDeviceConfigurationWizardSetupPage::handleMachineTypeChanged()
|
|
|
|
|
{
|
2013-01-22 08:31:32 -05:00
|
|
|
if (m_ui->deviceHostIp->text().isEmpty())
|
|
|
|
|
m_ui->deviceHostIp->setText(defaultDeviceHostIp(machineType()));
|
2012-12-21 08:36:06 -05:00
|
|
|
}
|
|
|
|
|
|
2013-02-18 19:22:21 -03:00
|
|
|
void BlackBerryDeviceConfigurationWizardSetupPage::requestDebugToken()
|
|
|
|
|
{
|
|
|
|
|
BlackBerryDebugTokenRequestDialog dialog;
|
|
|
|
|
|
2013-04-09 14:32:39 +02:00
|
|
|
if (!m_ui->deviceHostIp->text().isEmpty() && !m_ui->password->text().isEmpty())
|
|
|
|
|
dialog.setTargetDetails(m_ui->deviceHostIp->text(), m_ui->password->text());
|
|
|
|
|
|
2013-02-18 19:22:21 -03:00
|
|
|
const int result = dialog.exec();
|
|
|
|
|
|
|
|
|
|
if (result != QDialog::Accepted)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_ui->debugToken->setPath(dialog.debugToken());
|
|
|
|
|
}
|
2012-06-29 07:23:13 +02:00
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BlackBerryDeviceConfigurationWizardSshKeyPage::BlackBerryDeviceConfigurationWizardSshKeyPage(QWidget *parent)
|
|
|
|
|
: QWizardPage(parent)
|
|
|
|
|
, m_ui(new Ui::BlackBerryDeviceConfigurationWizardSshKeyPage)
|
|
|
|
|
{
|
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
|
|
|
|
|
|
m_ui->privateKey->setExpectedKind(Utils::PathChooser::File);
|
2013-04-23 10:39:05 +02:00
|
|
|
m_ui->progressBar->hide();
|
2012-06-29 07:23:13 +02:00
|
|
|
|
2013-06-12 14:09:01 +02:00
|
|
|
QString initialBrowsePath = QnxUtils::dataDirPath();
|
2013-04-16 14:53:24 +02:00
|
|
|
if (!QFileInfo(initialBrowsePath).exists())
|
|
|
|
|
initialBrowsePath = QDir::homePath();
|
|
|
|
|
m_ui->privateKey->setInitialBrowsePathBackup(initialBrowsePath);
|
|
|
|
|
|
2012-06-29 07:23:13 +02:00
|
|
|
setTitle(tr("SSH Key Setup"));
|
|
|
|
|
setSubTitle(tr("Please select an existing <b>4096</b>-bit key or click <b>Generate</b> to create a new one."));
|
|
|
|
|
|
|
|
|
|
connect(m_ui->privateKey, SIGNAL(changed(QString)), this, SLOT(findMatchingPublicKey(QString)));
|
|
|
|
|
connect(m_ui->privateKey, SIGNAL(changed(QString)), this, SIGNAL(completeChanged()));
|
2013-04-23 10:39:05 +02:00
|
|
|
connect(m_ui->generate, SIGNAL(clicked()), this, SLOT(generateSshKeys()));
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BlackBerryDeviceConfigurationWizardSshKeyPage::~BlackBerryDeviceConfigurationWizardSshKeyPage()
|
|
|
|
|
{
|
|
|
|
|
delete m_ui;
|
|
|
|
|
m_ui = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlackBerryDeviceConfigurationWizardSshKeyPage::initializePage()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BlackBerryDeviceConfigurationWizardSshKeyPage::isComplete() const
|
|
|
|
|
{
|
|
|
|
|
QFileInfo privateKeyFi(m_ui->privateKey->fileName().toString());
|
|
|
|
|
QFileInfo publicKeyFi(m_ui->publicKey->text());
|
|
|
|
|
|
2013-04-16 14:53:24 +02:00
|
|
|
return privateKeyFi.exists() && publicKeyFi.exists();
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString BlackBerryDeviceConfigurationWizardSshKeyPage::privateKey() const
|
|
|
|
|
{
|
|
|
|
|
return m_ui->privateKey->fileName().toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString BlackBerryDeviceConfigurationWizardSshKeyPage::publicKey() const
|
|
|
|
|
{
|
|
|
|
|
return m_ui->publicKey->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlackBerryDeviceConfigurationWizardSshKeyPage::findMatchingPublicKey(const QString &privateKeyPath)
|
|
|
|
|
{
|
|
|
|
|
const QString candidate = privateKeyPath + QLatin1String(".pub");
|
|
|
|
|
if (QFileInfo(candidate).exists())
|
2013-07-18 18:31:44 +02:00
|
|
|
m_ui->publicKey->setText(QDir::toNativeSeparators(candidate));
|
2013-04-16 14:53:24 +02:00
|
|
|
else
|
|
|
|
|
m_ui->publicKey->clear();
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
2013-07-26 16:55:12 +02:00
|
|
|
void BlackBerryDeviceConfigurationWizardSshKeyPage::sshKeysGenerationFailed(const QString &error)
|
2012-06-29 07:23:13 +02:00
|
|
|
{
|
2013-04-16 14:53:24 +02:00
|
|
|
setBusy(false);
|
2013-07-26 16:55:12 +02:00
|
|
|
QMessageBox::critical(this, tr("Key Generation Failed"), error);
|
|
|
|
|
}
|
2013-04-16 14:53:24 +02:00
|
|
|
|
2013-07-26 16:55:12 +02:00
|
|
|
void BlackBerryDeviceConfigurationWizardSshKeyPage::processSshKeys(const QString &privateKeyPath, const QByteArray &privateKey, const QByteArray &publicKey)
|
|
|
|
|
{
|
|
|
|
|
setBusy(false);
|
2012-06-29 07:23:13 +02:00
|
|
|
|
2013-07-26 16:55:12 +02:00
|
|
|
const QString publicKeyPath = privateKeyPath + QLatin1String(".pub");
|
2012-06-29 07:23:13 +02:00
|
|
|
|
2013-07-26 16:55:12 +02:00
|
|
|
if (!saveKeys(privateKey, publicKey, privateKeyPath, publicKeyPath)) // saveKeys(..) will show an error message if necessary
|
2013-04-16 14:53:24 +02:00
|
|
|
return;
|
2013-04-23 10:39:05 +02:00
|
|
|
|
2013-07-26 16:55:12 +02:00
|
|
|
m_ui->privateKey->setFileName(Utils::FileName::fromString(privateKeyPath));
|
2013-07-18 18:31:44 +02:00
|
|
|
m_ui->publicKey->setText(QDir::toNativeSeparators(publicKeyPath));
|
2013-04-16 14:53:24 +02:00
|
|
|
|
|
|
|
|
emit completeChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-26 16:55:12 +02:00
|
|
|
bool BlackBerryDeviceConfigurationWizardSshKeyPage::saveKeys(const QByteArray &privateKey, const QByteArray &publicKey, const QString &privateKeyPath, const QString &publicKeyPath)
|
2013-04-16 14:53:24 +02:00
|
|
|
{
|
2013-07-26 16:55:12 +02:00
|
|
|
Utils::FileSaver privSaver(privateKeyPath);
|
|
|
|
|
privSaver.write(privateKey);
|
2013-04-16 14:53:24 +02:00
|
|
|
if (!privSaver.finalize(this))
|
|
|
|
|
return false; // finalize shows an error message if necessary
|
2013-07-26 16:55:12 +02:00
|
|
|
QFile::setPermissions(privateKeyPath, QFile::ReadOwner | QFile::WriteOwner);
|
2013-04-16 14:53:24 +02:00
|
|
|
|
2013-07-26 16:55:12 +02:00
|
|
|
Utils::FileSaver pubSaver(publicKeyPath);
|
2013-04-16 14:53:24 +02:00
|
|
|
|
2013-07-26 16:55:12 +02:00
|
|
|
pubSaver.write(publicKey);
|
2013-04-16 14:53:24 +02:00
|
|
|
if (!pubSaver.finalize(this))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
2013-04-23 10:39:05 +02:00
|
|
|
void BlackBerryDeviceConfigurationWizardSshKeyPage::generateSshKeys()
|
|
|
|
|
{
|
2013-06-12 14:09:01 +02:00
|
|
|
QString lookInDir = QnxUtils::dataDirPath();
|
2013-04-16 14:53:24 +02:00
|
|
|
if (!QFileInfo(lookInDir).exists())
|
|
|
|
|
lookInDir = QDir::homePath();
|
|
|
|
|
|
|
|
|
|
QString privateKeyPath = QFileDialog::getSaveFileName(this, tr("Choose Private Key File Name"), lookInDir);
|
|
|
|
|
if (privateKeyPath.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
2013-04-23 10:39:05 +02:00
|
|
|
setBusy(true);
|
2013-07-26 16:55:12 +02:00
|
|
|
BlackBerrySshKeysGenerator *sshKeysGenerator = new BlackBerrySshKeysGenerator(privateKeyPath);
|
|
|
|
|
connect(sshKeysGenerator, SIGNAL(sshKeysGenerationFailed(QString)), this, SLOT(sshKeysGenerationFailed(QString)), Qt::QueuedConnection);
|
|
|
|
|
connect(sshKeysGenerator, SIGNAL(sshKeysGenerationFinished(QString,QByteArray,QByteArray)), this, SLOT(processSshKeys(QString,QByteArray,QByteArray)), Qt::QueuedConnection);
|
|
|
|
|
sshKeysGenerator->start();
|
2013-04-23 10:39:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlackBerryDeviceConfigurationWizardSshKeyPage::setBusy(bool busy)
|
|
|
|
|
{
|
|
|
|
|
m_ui->privateKey->setEnabled(!busy);
|
2013-04-16 14:53:24 +02:00
|
|
|
m_ui->publicKey->setEnabled(!busy);
|
2013-04-23 10:39:05 +02:00
|
|
|
m_ui->generate->setEnabled(!busy);
|
|
|
|
|
m_ui->progressBar->setVisible(busy);
|
|
|
|
|
|
|
|
|
|
wizard()->button(QWizard::BackButton)->setEnabled(!busy);
|
|
|
|
|
wizard()->button(QWizard::NextButton)->setEnabled(!busy);
|
|
|
|
|
wizard()->button(QWizard::FinishButton)->setEnabled(!busy);
|
|
|
|
|
wizard()->button(QWizard::CancelButton)->setEnabled(!busy);
|
|
|
|
|
}
|
2012-06-29 07:23:13 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BlackBerryDeviceConfigurationWizardFinalPage::BlackBerryDeviceConfigurationWizardFinalPage(QWidget *parent)
|
|
|
|
|
: QWizardPage(parent)
|
|
|
|
|
{
|
|
|
|
|
setTitle(tr("Setup Finished"));
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
|
|
|
|
QLabel *label = new QLabel(tr("The new device configuration will now be created."), this);
|
|
|
|
|
layout->addWidget(label);
|
|
|
|
|
}
|
2013-04-23 10:39:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|