diff --git a/src/plugins/qnx/bardescriptoreditorwidget.cpp b/src/plugins/qnx/bardescriptoreditorwidget.cpp index a44939b8d64..3d64cb3f17d 100644 --- a/src/plugins/qnx/bardescriptoreditorwidget.cpp +++ b/src/plugins/qnx/bardescriptoreditorwidget.cpp @@ -35,13 +35,18 @@ #include "qnxconstants.h" #include "bardescriptoreditor.h" #include "bardescriptorpermissionsmodel.h" +#include "blackberrydeviceconfiguration.h" +#include "blackberrydebugtokenreader.h" +#include #include #include #include #include +#include #include +#include #include #include @@ -103,6 +108,8 @@ BarDescriptorEditorWidget::~BarDescriptorEditorWidget() void BarDescriptorEditorWidget::initGeneralPage() { + m_ui->setFromDebugToken->setVisible(BlackBerryDebugTokenReader::isSupported()); + QRegExp versionNumberRegExp(QLatin1String("(\\d{1,3}\\.)?(\\d{1,3}\\.)?(\\d{1,3})")); QRegExpValidator *versionNumberValidator = new QRegExpValidator(versionNumberRegExp, this); m_ui->packageVersion->setValidator(versionNumberValidator); @@ -113,6 +120,7 @@ void BarDescriptorEditorWidget::initGeneralPage() connect(m_ui->author, SIGNAL(textChanged(QString)), this, SLOT(setDirty())); connect(m_ui->authorId, SIGNAL(textChanged(QString)), this, SLOT(setDirty())); + connect(m_ui->setFromDebugToken, SIGNAL(clicked()), this, SLOT(setAuthorFromDebugToken())); } void BarDescriptorEditorWidget::clearGeneralPage() @@ -691,3 +699,35 @@ void BarDescriptorEditorWidget::addImageAsAsset(const QString &path) asset.entry = false; addAssetInternal(asset); } + +void BarDescriptorEditorWidget::setAuthorFromDebugToken() +{ + // To select debug token, make it fancier once the debug token management is done in + // Qt Creator + QStringList debugTokens; + ProjectExplorer::DeviceManager *deviceManager = ProjectExplorer::DeviceManager::instance(); + for (int i = 0; i < deviceManager->deviceCount(); ++i) { + ProjectExplorer::IDevice::ConstPtr device = deviceManager->deviceAt(i); + if (device->type() == Core::Id(Constants::QNX_BB_OS_TYPE)) { + BlackBerryDeviceConfiguration::ConstPtr bbDevice = device.dynamicCast(); + QTC_ASSERT(bbDevice, continue); + + debugTokens << bbDevice->debugToken(); + } + } + debugTokens.removeDuplicates(); + + bool ok; + QString debugToken = QInputDialog::getItem(this, tr("Select Debug Token"), tr("Debug token:"), debugTokens, 0, false, &ok); + if (!ok || debugToken.isEmpty()) + return; + + BlackBerryDebugTokenReader debugTokenReader(debugToken); + if (!debugTokenReader.isValid()) { + QMessageBox::warning(this, tr("Error Reading Debug Token"), tr("There was a problem reading debug token")); + return; + } + + m_ui->author->setText(debugTokenReader.author()); + m_ui->authorId->setText(debugTokenReader.authorId()); +} diff --git a/src/plugins/qnx/bardescriptoreditorwidget.h b/src/plugins/qnx/bardescriptoreditorwidget.h index 1e22d7ce341..aaaae431b43 100644 --- a/src/plugins/qnx/bardescriptoreditorwidget.h +++ b/src/plugins/qnx/bardescriptoreditorwidget.h @@ -137,6 +137,8 @@ signals: void changed(); private slots: + void setAuthorFromDebugToken(); + void addNewAsset(); void removeSelectedAsset(); void updateEntryCheckState(QStandardItem *item); diff --git a/src/plugins/qnx/bardescriptoreditorwidget.ui b/src/plugins/qnx/bardescriptoreditorwidget.ui index 362b687f5ba..919603d211f 100644 --- a/src/plugins/qnx/bardescriptoreditorwidget.ui +++ b/src/plugins/qnx/bardescriptoreditorwidget.ui @@ -107,16 +107,23 @@ - + Author ID: - + + + + + Set from debug token... + + + diff --git a/src/plugins/qnx/blackberrydebugtokenreader.cpp b/src/plugins/qnx/blackberrydebugtokenreader.cpp new file mode 100644 index 00000000000..5f1e4237c3f --- /dev/null +++ b/src/plugins/qnx/blackberrydebugtokenreader.cpp @@ -0,0 +1,110 @@ +/************************************************************************** +** +** 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 "blackberrydebugtokenreader.h" + +#ifdef QNX_ZIP_FILE_SUPPORT +#include +#endif + +using namespace Qnx; +using namespace Qnx::Internal; + +namespace { +const char MANIFEST_FILENAME[] = "META-INF/MANIFEST.MF"; + +const char MANIFEST_AUTHOR_KEY[] = "Package-Author: "; +const char MANIFEST_AUTHOR_ID_KEY[] = "Package-Author-Id: "; +} + +BlackBerryDebugTokenReader::BlackBerryDebugTokenReader(const QString &filePath) +{ +#ifdef QNX_ZIP_FILE_SUPPORT + m_zipReader = new QZipReader(filePath); +#endif +} + +BlackBerryDebugTokenReader::~BlackBerryDebugTokenReader() +{ +#ifdef QNX_ZIP_FILE_SUPPORT + m_zipReader->close(); + delete m_zipReader; + m_zipReader = 0; +#endif +} + +bool BlackBerryDebugTokenReader::isValid() const +{ +#ifdef QNX_ZIP_FILE_SUPPORT + return m_zipReader->status() == QZipReader::NoError; +#else + return false; +#endif +} + +QString BlackBerryDebugTokenReader::author() const +{ + return manifestValue(MANIFEST_AUTHOR_KEY); +} + +QString BlackBerryDebugTokenReader::authorId() const +{ + return manifestValue(MANIFEST_AUTHOR_ID_KEY); +} + +bool BlackBerryDebugTokenReader::isSupported() +{ +#ifdef QNX_ZIP_FILE_SUPPORT + return true; +#else + return false; +#endif +} + +QString BlackBerryDebugTokenReader::manifestValue(const QByteArray &key) const +{ + if (!isValid()) + return QString(); + +#ifdef QNX_ZIP_FILE_SUPPORT + QByteArray manifestContent = m_zipReader->fileData(QLatin1String(MANIFEST_FILENAME)); + return value(key, manifestContent); +#else + return QString(); +#endif +} + +QString BlackBerryDebugTokenReader::value(const QByteArray &key, const QByteArray &data) const +{ + int valueStart = data.indexOf(key) + key.size(); + int valueEnd = data.indexOf(QByteArray("\r\n"), valueStart); + return QString::fromAscii(data.mid(valueStart, valueEnd - valueStart)); +} diff --git a/src/plugins/qnx/blackberrydebugtokenreader.h b/src/plugins/qnx/blackberrydebugtokenreader.h new file mode 100644 index 00000000000..4bd45723a9e --- /dev/null +++ b/src/plugins/qnx/blackberrydebugtokenreader.h @@ -0,0 +1,67 @@ +/************************************************************************** +** +** 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_BLACKBERRYDEBUGTOKENREADER_H +#define QNX_INTERNAL_BLACKBERRYDEBUGTOKENREADER_H + +#include + +QT_BEGIN_NAMESPACE +class QZipReader; +QT_END_NAMESPACE + +namespace Qnx { +namespace Internal { + +class BlackBerryDebugTokenReader +{ +public: + BlackBerryDebugTokenReader(const QString &filePath); + ~BlackBerryDebugTokenReader(); + + bool isValid() const; + + QString author() const; + QString authorId() const; + + static bool isSupported(); + +private: + QString manifestValue(const QByteArray &key) const; + QString value(const QByteArray &key, const QByteArray &data) const; + + QZipReader *m_zipReader; +}; + +} // namespace Internal +} // namespace Qnx + +#endif // QNX_INTERNAL_BLACKBERRYDEBUGTOKENREADER_H diff --git a/src/plugins/qnx/qnx.pro b/src/plugins/qnx/qnx.pro index f065197d0c7..6a08e9f7935 100644 --- a/src/plugins/qnx/qnx.pro +++ b/src/plugins/qnx/qnx.pro @@ -72,6 +72,7 @@ SOURCES += qnxplugin.cpp \ blackberrydebugtokenrequester.cpp \ blackberrydebugtokenrequestdialog.cpp \ blackberrydebugtokenuploader.cpp \ + blackberrydebugtokenreader.cpp \ blackberryndkprocess.cpp HEADERS += qnxplugin.h\ @@ -141,6 +142,7 @@ HEADERS += qnxplugin.h\ blackberrydebugtokenrequester.h \ blackberrydebugtokenrequestdialog.h \ blackberrydebugtokenuploader.h \ + blackberrydebugtokenreader.h \ blackberryndkprocess.h FORMS += \ @@ -158,6 +160,14 @@ FORMS += \ blackberrycreatecertificatedialog.ui \ blackberrydebugtokenrequestdialog.ui +include(../../private_headers.pri) +exists($${QT_PRIVATE_HEADERS}/QtGui/private/qzipreader_p.h) { + DEFINES += QNX_ZIP_FILE_SUPPORT +} else { + warning("The QNX plugin depends on private headers from QtGui module, to be fully functional.") + warning("To fix it, pass 'QT_PRIVATE_HEADERS=$QTDIR/include' to qmake, where $QTDIR is the source directory of qt.") +} + DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII RESOURCES += \ diff --git a/src/plugins/qnx/qnx.qbs b/src/plugins/qnx/qnx.qbs index 53b8a1c4fb4..28339146efa 100644 --- a/src/plugins/qnx/qnx.qbs +++ b/src/plugins/qnx/qnx.qbs @@ -62,6 +62,8 @@ QtcPlugin { "blackberrydeploystepconfigwidget.h", "blackberrydeploystepfactory.cpp", "blackberrydeploystepfactory.h", + "blackberrydebugtokenreader.cpp", + "blackberrydebugtokenreader.h", "blackberrydeviceconfiguration.cpp", "blackberrydeviceconfiguration.h", "blackberrydeviceconfigurationfactory.cpp",