From c6449e55ff30ed746189560e3e86fc8e7ada006f Mon Sep 17 00:00:00 2001 From: El Mehdi Fekari Date: Tue, 9 Apr 2013 14:32:39 +0200 Subject: [PATCH] Qnx: Auto detect device PIN when requesting debugToken Task-number: QTCREATORBUG-9062 Change-Id: Ib6bc2f2da6f6cfe9e78eb1d9d7e9d8f6abbd9948 Reviewed-by: Rafael Roquetto Reviewed-by: Kevin Krammer --- .../qnx/blackberrydebugtokenrequestdialog.cpp | 30 +++++- .../qnx/blackberrydebugtokenrequestdialog.h | 5 + .../blackberrydeviceconfigurationwidget.cpp | 3 + ...ackberrydeviceconfigurationwizardpages.cpp | 3 + .../qnx/blackberrydeviceinformation.cpp | 91 +++++++++++++++++++ src/plugins/qnx/blackberrydeviceinformation.h | 76 ++++++++++++++++ src/plugins/qnx/blackberryndkprocess.cpp | 18 ++-- src/plugins/qnx/blackberryndkprocess.h | 1 + src/plugins/qnx/qnx.pro | 6 +- src/plugins/qnx/qnx.qbs | 2 + 10 files changed, 224 insertions(+), 11 deletions(-) create mode 100644 src/plugins/qnx/blackberrydeviceinformation.cpp create mode 100644 src/plugins/qnx/blackberrydeviceinformation.h diff --git a/src/plugins/qnx/blackberrydebugtokenrequestdialog.cpp b/src/plugins/qnx/blackberrydebugtokenrequestdialog.cpp index 22b60051b28..e79423021f1 100644 --- a/src/plugins/qnx/blackberrydebugtokenrequestdialog.cpp +++ b/src/plugins/qnx/blackberrydebugtokenrequestdialog.cpp @@ -31,6 +31,7 @@ #include "blackberrydebugtokenrequestdialog.h" #include "blackberrydebugtokenrequester.h" +#include "blackberrydeviceinformation.h" #include "blackberryconfiguration.h" #include "blackberrycertificate.h" #include "ui_blackberrydebugtokenrequestdialog.h" @@ -46,7 +47,8 @@ BlackBerryDebugTokenRequestDialog::BlackBerryDebugTokenRequestDialog( QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f), m_ui(new Ui_BlackBerryDebugTokenRequestDialog), - m_requester(new BlackBerryDebugTokenRequester) + m_requester(new BlackBerryDebugTokenRequester(this)), + m_deviceInfo(new BlackBerryDeviceInformation(this)) { m_ui->setupUi(this); m_ui->progressBar->hide(); @@ -83,6 +85,13 @@ BlackBerryDebugTokenRequestDialog::BlackBerryDebugTokenRequestDialog( this, SLOT(checkBoxChanged(int))); connect(m_requester, SIGNAL(finished(int)), this, SLOT(debugTokenArrived(int))); + connect(m_deviceInfo, SIGNAL(finished(int)), + this, SLOT(setDevicePin(int))); +} + +BlackBerryDebugTokenRequestDialog::~BlackBerryDebugTokenRequestDialog() +{ + delete m_ui; } QString BlackBerryDebugTokenRequestDialog::debugToken() const @@ -90,6 +99,12 @@ QString BlackBerryDebugTokenRequestDialog::debugToken() const return m_ui->debugTokenPath->path(); } +void BlackBerryDebugTokenRequestDialog::setTargetDetails(const QString &deviceIp, const QString &password) +{ + m_ui->devicePin->setPlaceholderText(tr("Requesting Device PIN...")); + m_deviceInfo->setDeviceTarget(deviceIp, password); +} + void BlackBerryDebugTokenRequestDialog::validate() { if (!m_ui->debugTokenPath->isValid() @@ -232,6 +247,19 @@ void BlackBerryDebugTokenRequestDialog::debugTokenArrived(int status) setBusy(false); } +void BlackBerryDebugTokenRequestDialog::setDevicePin(int status) +{ + m_ui->devicePin->setPlaceholderText(QString()); + if (status != BlackBerryDeviceInformation::Success) + return; + + const QString devicePin = m_deviceInfo->devicePin(); + if (devicePin.isEmpty()) + return; + + m_ui->devicePin->setText(devicePin); +} + void BlackBerryDebugTokenRequestDialog::setBusy(bool busy) { m_okButton->setEnabled(!busy); diff --git a/src/plugins/qnx/blackberrydebugtokenrequestdialog.h b/src/plugins/qnx/blackberrydebugtokenrequestdialog.h index e70f56d528b..7fe3e8065f4 100644 --- a/src/plugins/qnx/blackberrydebugtokenrequestdialog.h +++ b/src/plugins/qnx/blackberrydebugtokenrequestdialog.h @@ -43,6 +43,7 @@ namespace Internal { class Ui_BlackBerryDebugTokenRequestDialog; class BlackBerryDebugTokenRequester; +class BlackBerryDeviceInformation; class BlackBerryDebugTokenRequestDialog : public QDialog { @@ -51,8 +52,10 @@ Q_OBJECT public: explicit BlackBerryDebugTokenRequestDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); + ~BlackBerryDebugTokenRequestDialog(); QString debugToken() const; + void setTargetDetails(const QString &deviceIp, const QString &password); private slots: void validate(); @@ -62,6 +65,7 @@ private slots: void expandPath(); void checkBoxChanged(int state); void debugTokenArrived(int status); + void setDevicePin(int status); private: void setBusy(bool busy); @@ -70,6 +74,7 @@ private: Ui_BlackBerryDebugTokenRequestDialog *m_ui; BlackBerryDebugTokenRequester *m_requester; + BlackBerryDeviceInformation *m_deviceInfo; QPushButton *m_cancelButton; QPushButton *m_okButton; diff --git a/src/plugins/qnx/blackberrydeviceconfigurationwidget.cpp b/src/plugins/qnx/blackberrydeviceconfigurationwidget.cpp index 0641e092633..2283920f886 100644 --- a/src/plugins/qnx/blackberrydeviceconfigurationwidget.cpp +++ b/src/plugins/qnx/blackberrydeviceconfigurationwidget.cpp @@ -122,6 +122,9 @@ void BlackBerryDeviceConfigurationWidget::requestDebugToken() { BlackBerryDebugTokenRequestDialog dialog; + if (!ui->hostLineEdit->text().isEmpty() && !ui->pwdLineEdit->text().isEmpty()) + dialog.setTargetDetails(ui->hostLineEdit->text(), ui->pwdLineEdit->text()); + const int result = dialog.exec(); if (result != QDialog::Accepted) diff --git a/src/plugins/qnx/blackberrydeviceconfigurationwizardpages.cpp b/src/plugins/qnx/blackberrydeviceconfigurationwizardpages.cpp index d7d3d5a4c2e..dec90ec398d 100644 --- a/src/plugins/qnx/blackberrydeviceconfigurationwizardpages.cpp +++ b/src/plugins/qnx/blackberrydeviceconfigurationwizardpages.cpp @@ -133,6 +133,9 @@ void BlackBerryDeviceConfigurationWizardSetupPage::requestDebugToken() { BlackBerryDebugTokenRequestDialog dialog; + if (!m_ui->deviceHostIp->text().isEmpty() && !m_ui->password->text().isEmpty()) + dialog.setTargetDetails(m_ui->deviceHostIp->text(), m_ui->password->text()); + const int result = dialog.exec(); if (result != QDialog::Accepted) diff --git a/src/plugins/qnx/blackberrydeviceinformation.cpp b/src/plugins/qnx/blackberrydeviceinformation.cpp new file mode 100644 index 00000000000..f776823b15e --- /dev/null +++ b/src/plugins/qnx/blackberrydeviceinformation.cpp @@ -0,0 +1,91 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.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 "blackberrydeviceinformation.h" + +namespace { +static const char PROCESS_NAME[] = "blackberry-deploy"; +static const char ERR_NO_ROUTE_HOST[] = "Cannot connect"; +static const char ERR_AUTH_FAILED[] = "Authentication failed"; +static const char ERR_DEVELOPMENT_MODE_DISABLED[] = "Device is not in the Development Mode"; +} + +namespace Qnx { +namespace Internal { + +BlackBerryDeviceInformation::BlackBerryDeviceInformation(QObject *parent) : + BlackBerryNdkProcess(QLatin1String(PROCESS_NAME), parent) +{ + addErrorStringMapping(QLatin1String(ERR_NO_ROUTE_HOST), NoRouteToHost); + addErrorStringMapping(QLatin1String(ERR_AUTH_FAILED), AuthenticationFailed); + addErrorStringMapping(QLatin1String(ERR_DEVELOPMENT_MODE_DISABLED), DevelopmentModeDisabled); +} + +void BlackBerryDeviceInformation::setDeviceTarget(const QString &deviceIp, const QString &devicePassword) +{ + QStringList arguments; + + arguments << QLatin1String("-listDeviceInfo") + << QLatin1String("-device") + << deviceIp + << QLatin1String("-password") + << devicePassword; + + start(arguments); +} + +QString BlackBerryDeviceInformation::devicePin() const +{ + return m_devicePin; +} + +QString BlackBerryDeviceInformation::deviceOS() const +{ + return m_deviceOS; +} + +QString BlackBerryDeviceInformation::hardwareId() const +{ + return m_hardwareId; +} + +void BlackBerryDeviceInformation::processData(const QString &line) +{ + if (line.startsWith(QLatin1String("devicepin::"))) + m_devicePin = line.split(QLatin1String("::")).at(1).trimmed(); + else if (line.startsWith(QLatin1String("device_os::"))) + m_deviceOS = line.split(QLatin1String("::")).at(1).trimmed(); + else if (line.startsWith(QLatin1String("hardwareid::"))) + m_hardwareId = line.split(QLatin1String("::")).at(1).trimmed(); +} + +} // namespace Internal +} // namespace Qnx diff --git a/src/plugins/qnx/blackberrydeviceinformation.h b/src/plugins/qnx/blackberrydeviceinformation.h new file mode 100644 index 00000000000..d58e386fcb4 --- /dev/null +++ b/src/plugins/qnx/blackberrydeviceinformation.h @@ -0,0 +1,76 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.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. +** +****************************************************************************/ + +#ifndef QNX_INTERNAL_BLACKBERRYDEVICEINFO_H +#define QNX_INTERNAL_BLACKBERRYDEVICEINFO_H + +#include "blackberryndkprocess.h" + +namespace Qnx { +namespace Internal { + +class BlackBerryDeviceInformation : public BlackBerryNdkProcess +{ + Q_OBJECT + +public: + enum ReturnStatus + { + NoRouteToHost = UserStatus, + AuthenticationFailed, + DevelopmentModeDisabled, + FailedToStartInferiorProcess, + InferiorProcessTimedOut, + InferiorProcessCrashed, + InferiorProcessWriteError, + InferiorProcessReadError + }; + + explicit BlackBerryDeviceInformation(QObject *parent = 0); + + void setDeviceTarget(const QString &deviceIp, const QString &devicePassword); + + QString devicePin() const; + QString deviceOS() const; + QString hardwareId() const; + +private: + QString m_devicePin; + QString m_deviceOS; + QString m_hardwareId; + + void processData(const QString &line); +}; + +} +} + +#endif // QNX_INTERNAL_BLACKBERRYDEBUGTOKENUPLOADER_H diff --git a/src/plugins/qnx/blackberryndkprocess.cpp b/src/plugins/qnx/blackberryndkprocess.cpp index 2d00a9af10b..a148c9741b3 100644 --- a/src/plugins/qnx/blackberryndkprocess.cpp +++ b/src/plugins/qnx/blackberryndkprocess.cpp @@ -80,21 +80,18 @@ void BlackBerryNdkProcess::addErrorStringMapping( void BlackBerryNdkProcess::processFinished() { + QTextStream processOutput(m_process); if (m_process->exitCode() == 0) { + while (!processOutput.atEnd()) + processData(processOutput.readLine()); + emit finished(Success); return; } - QTextStream processOutput(m_process); - - QString errorString; int returnStatus = UnknownError; - while (!processOutput.atEnd()) { - const QString line = processOutput.readLine(); - - returnStatus = errorLineToReturnStatus(line); - + returnStatus = errorLineToReturnStatus(processOutput.readLine()); if (returnStatus >= 0) break; } @@ -144,5 +141,10 @@ int BlackBerryNdkProcess::errorLineToReturnStatus(const QString &line) const return -1; } +void BlackBerryNdkProcess::processData(const QString &line) +{ + Q_UNUSED(line); +} + } // namespace Internal } // namespace Qnx diff --git a/src/plugins/qnx/blackberryndkprocess.h b/src/plugins/qnx/blackberryndkprocess.h index 5e38914b3b9..f6236289652 100644 --- a/src/plugins/qnx/blackberryndkprocess.h +++ b/src/plugins/qnx/blackberryndkprocess.h @@ -73,6 +73,7 @@ private slots: private: int errorLineToReturnStatus(const QString &line) const; + virtual void processData(const QString &line); QProcess *m_process; diff --git a/src/plugins/qnx/qnx.pro b/src/plugins/qnx/qnx.pro index 7467c4f5224..ca088da04ec 100644 --- a/src/plugins/qnx/qnx.pro +++ b/src/plugins/qnx/qnx.pro @@ -75,7 +75,8 @@ SOURCES += qnxplugin.cpp \ blackberrycheckdevmodestep.cpp \ blackberrycheckdevmodestepconfigwidget.cpp \ blackberrydeviceconnection.cpp \ - blackberrydeviceconnectionmanager.cpp + blackberrydeviceconnectionmanager.cpp \ + blackberrydeviceinformation.cpp HEADERS += qnxplugin.h\ qnxconstants.h \ @@ -150,7 +151,8 @@ HEADERS += qnxplugin.h\ blackberrycheckdevmodestep.h \ blackberrycheckdevmodestepconfigwidget.h \ blackberrydeviceconnection.h \ - blackberrydeviceconnectionmanager.h + blackberrydeviceconnectionmanager.h \ + blackberrydeviceinformation.h FORMS += \ blackberrydeviceconfigurationwizardsetuppage.ui \ diff --git a/src/plugins/qnx/qnx.qbs b/src/plugins/qnx/qnx.qbs index fb66565191b..70a8f986b78 100644 --- a/src/plugins/qnx/qnx.qbs +++ b/src/plugins/qnx/qnx.qbs @@ -70,6 +70,8 @@ QtcPlugin { "blackberrydebugtokenreader.h", "blackberrydeviceconfiguration.cpp", "blackberrydeviceconfiguration.h", + "blackberrydeviceinformation.cpp", + "blackberrydeviceinformation.h", "blackberrydeviceconfigurationfactory.cpp", "blackberrydeviceconfigurationfactory.h", "blackberrydeviceconfigurationwidget.cpp",