Commit f1c9b1ca authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Moved the testing of a Maemo device configuration into a dialog

Reduces the minimum size of the Options dialog.

Reviewed-by: kh1
parent d5bdad22
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of Qt Creator.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "maemoconfigtestdialog.h"
#include "ui_maemoconfigtestdialog.h"
#include "maemosshthread.h"
#include <QtGui/QPushButton>
namespace {
/**
* Class that waits until a thread is finished and then deletes it, and then
* schedules itself to be deleted.
*/
class SafeThreadDeleter : public QThread
{
public:
SafeThreadDeleter(QThread *thread) : m_thread(thread) {}
~SafeThreadDeleter() { wait(); }
protected:
void run()
{
// Wait for m_thread to finish and then delete it
m_thread->wait();
delete m_thread;
// Schedule this thread for deletion
deleteLater();
}
private:
QThread *m_thread;
};
} // anonymous namespace
namespace Qt4ProjectManager {
namespace Internal {
MaemoConfigTestDialog::MaemoConfigTestDialog(const MaemoDeviceConfig &config, QWidget *parent)
: QDialog(parent)
, m_ui(new Ui_MaemoConfigTestDialog)
, m_config(config)
, m_deviceTester(0)
{
setAttribute(Qt::WA_DeleteOnClose);
m_ui->setupUi(this);
m_closeButton = m_ui->buttonBox->button(QDialogButtonBox::Close);
connect(m_closeButton, SIGNAL(clicked()), SLOT(stopConfigTest()));
startConfigTest();
}
MaemoConfigTestDialog::~MaemoConfigTestDialog()
{
stopConfigTest();
}
void MaemoConfigTestDialog::startConfigTest()
{
if (m_deviceTester)
return;
m_ui->testResultEdit->setPlainText(tr("Testing configuration..."));
m_closeButton->setText(tr("Stop Test"));
QLatin1String sysInfoCmd("uname -rsm");
QLatin1String qtInfoCmd("dpkg -l |grep libqt "
"|sed 's/[[:space:]][[:space:]]*/ /g' "
"|cut -d ' ' -f 2,3 |sed 's/~.*//g'");
QString command(sysInfoCmd + " && " + qtInfoCmd);
m_deviceTester = new MaemoSshRunner(m_config, command);
connect(m_deviceTester, SIGNAL(remoteOutput(QString)),
this, SLOT(processSshOutput(QString)));
connect(m_deviceTester, SIGNAL(finished()),
this, SLOT(handleTestThreadFinished()));
m_deviceTester->start();
}
void MaemoConfigTestDialog::handleTestThreadFinished()
{
if (!m_deviceTester)
return;
QString output;
if (m_deviceTester->hasError()) {
output = tr("Device configuration test failed:\n%1").arg(m_deviceTester->error());
if (m_config.type == MaemoDeviceConfig::Simulator)
output.append(tr("\nDid you start Qemu?"));
} else {
output = parseTestOutput();
}
m_ui->testResultEdit->setPlainText(output);
stopConfigTest();
}
void MaemoConfigTestDialog::stopConfigTest()
{
if (m_deviceTester) {
m_deviceTester->disconnect(); // Disconnect signals
m_deviceTester->stop();
SafeThreadDeleter *deleter = new SafeThreadDeleter(m_deviceTester);
deleter->start();
m_deviceTester = 0;
m_deviceTestOutput.clear();
m_closeButton->setText(tr("Close"));
}
}
void MaemoConfigTestDialog::processSshOutput(const QString &data)
{
m_deviceTestOutput.append(data);
}
QString MaemoConfigTestDialog::parseTestOutput()
{
QString output;
const QRegExp unamePattern(QLatin1String("Linux (\\S+)\\s(\\S+)"));
int index = unamePattern.indexIn(m_deviceTestOutput);
if (index == -1) {
output = tr("Device configuration test failed: Unexpected output:\n%1").arg(m_deviceTestOutput);
return output;
}
output = tr("Hardware architecture: %1\n").arg(unamePattern.cap(2));
output.append(tr("Kernel version: %1\n").arg(unamePattern.cap(1)));
output.prepend(tr("Device configuration successful.\n"));
const QRegExp dkpgPattern(QLatin1String("libqt\\S+ \\d\\.\\d\\.\\d"));
index = dkpgPattern.indexIn(m_deviceTestOutput);
if (index == -1) {
output.append("No Qt packages installed.");
return output;
}
output.append("List of installed Qt packages:\n");
do {
output.append(QLatin1String("\t") + dkpgPattern.cap(0)
+ QLatin1String("\n"));
index = dkpgPattern.indexIn(m_deviceTestOutput, index + 1);
} while (index != -1);
return output;
}
} // namespace Internal
} // namespace Qt4ProjectManager
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of Qt Creator.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef MAEMOCONFIGTESTDIALOG_H
#define MAEMOCONFIGTESTDIALOG_H
#include <QDialog>
QT_BEGIN_NAMESPACE
class QPushButton;
class Ui_MaemoConfigTestDialog;
QT_END_NAMESPACE
namespace Qt4ProjectManager {
namespace Internal {
class MaemoDeviceConfig;
class MaemoSshRunner;
/**
* A dialog that runs a test of a device configuration.
*/
class MaemoConfigTestDialog : public QDialog
{
Q_OBJECT
public:
explicit MaemoConfigTestDialog(const MaemoDeviceConfig &config, QWidget *parent = 0);
~MaemoConfigTestDialog();
private slots:
void stopConfigTest();
void processSshOutput(const QString &data);
void handleTestThreadFinished();
private:
void startConfigTest();
QString parseTestOutput();
Ui_MaemoConfigTestDialog *m_ui;
QPushButton *m_closeButton;
const MaemoDeviceConfig &m_config;
MaemoSshRunner *m_deviceTester;
QString m_deviceTestOutput;
};
} // namespace Internal
} // namespace Qt4ProjectManager
#endif // MAEMOCONFIGTESTDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MaemoConfigTestDialog</class>
<widget class="QDialog" name="MaemoConfigTestDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>395</width>
<height>190</height>
</rect>
</property>
<property name="windowTitle">
<string>Device Configuration Test</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPlainTextEdit" name="testResultEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>MaemoConfigTestDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>MaemoConfigTestDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
...@@ -36,12 +36,14 @@ ...@@ -36,12 +36,14 @@
#include "ui_maemosettingswidget.h" #include "ui_maemosettingswidget.h"
#include "maemoconfigtestdialog.h"
#include "maemodeviceconfigurations.h" #include "maemodeviceconfigurations.h"
#include "maemosshthread.h" #include "maemosshthread.h"
#include <QtCore/QRegExp> #include <QtCore/QRegExp>
#include <QtGui/QFileDialog>
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtGui/QFileDialog>
#include <QtGui/QMessageBox>
#include <QtGui/QIntValidator> #include <QtGui/QIntValidator>
#include <algorithm> #include <algorithm>
...@@ -109,13 +111,12 @@ private: ...@@ -109,13 +111,12 @@ private:
MaemoSettingsWidget::MaemoSettingsWidget(QWidget *parent) MaemoSettingsWidget::MaemoSettingsWidget(QWidget *parent)
: QWidget(parent), : QWidget(parent),
m_ui(new Ui_maemoSettingsWidget), m_ui(new Ui_MaemoSettingsWidget),
m_devConfs(MaemoDeviceConfigurations::instance().devConfigs()), m_devConfs(MaemoDeviceConfigurations::instance().devConfigs()),
m_nameValidator(new NameValidator(m_devConfs)), m_nameValidator(new NameValidator(m_devConfs)),
m_sshPortValidator(new PortAndTimeoutValidator), m_sshPortValidator(new PortAndTimeoutValidator),
m_gdbServerPortValidator(new PortAndTimeoutValidator), m_gdbServerPortValidator(new PortAndTimeoutValidator),
m_timeoutValidator(new PortAndTimeoutValidator), m_timeoutValidator(new PortAndTimeoutValidator),
m_deviceTester(0),
m_keyDeployer(0) m_keyDeployer(0)
{ {
...@@ -134,9 +135,8 @@ void MaemoSettingsWidget::initGui() ...@@ -134,9 +135,8 @@ void MaemoSettingsWidget::initGui()
m_ui->gdbServerPortLineEdit->setValidator(m_gdbServerPortValidator); m_ui->gdbServerPortLineEdit->setValidator(m_gdbServerPortValidator);
m_ui->timeoutLineEdit->setValidator(m_timeoutValidator); m_ui->timeoutLineEdit->setValidator(m_timeoutValidator);
m_ui->keyFileLineEdit->setExpectedKind(Utils::PathChooser::File); m_ui->keyFileLineEdit->setExpectedKind(Utils::PathChooser::File);
foreach(const MaemoDeviceConfig &devConf, m_devConfs) foreach (const MaemoDeviceConfig &devConf, m_devConfs)
m_ui->configListWidget->addItem(devConf.name); m_ui->configListWidget->addItem(devConf.name);
m_defaultTestOutput = m_ui->testResultEdit->toPlainText();
if (m_devConfs.count() == 1) if (m_devConfs.count() == 1)
m_ui->configListWidget->setCurrentRow(0, QItemSelectionModel::Select); m_ui->configListWidget->setCurrentRow(0, QItemSelectionModel::Select);
} }
...@@ -314,93 +314,8 @@ void MaemoSettingsWidget::keyFileEditingFinished() ...@@ -314,93 +314,8 @@ void MaemoSettingsWidget::keyFileEditingFinished()
void MaemoSettingsWidget::testConfig() void MaemoSettingsWidget::testConfig()
{ {
if (m_deviceTester) QDialog *dialog = new MaemoConfigTestDialog(currentConfig(), this);
return; dialog->open();
m_ui->testConfigButton->disconnect();
m_ui->testResultEdit->setPlainText(m_defaultTestOutput);
QLatin1String sysInfoCmd("uname -rsm");
QLatin1String qtInfoCmd("dpkg -l |grep libqt "
"|sed 's/[[:space:]][[:space:]]*/ /g' "
"|cut -d ' ' -f 2,3 |sed 's/~.*//g'");
QString command(sysInfoCmd + " && " + qtInfoCmd);
m_deviceTester = new MaemoSshRunner(currentConfig(), command);
connect(m_deviceTester, SIGNAL(remoteOutput(QString)),
this, SLOT(processSshOutput(QString)));
connect(m_deviceTester, SIGNAL(finished()),
this, SLOT(handleTestThreadFinished()));
m_ui->testConfigButton->setText(tr("Stop test"));
connect(m_ui->testConfigButton, SIGNAL(clicked()),
this, SLOT(stopConfigTest()));
m_deviceTester->start();
}
void MaemoSettingsWidget::processSshOutput(const QString &data)
{
qDebug("%s", qPrintable(data));
m_deviceTestOutput.append(data);
}
void MaemoSettingsWidget::handleTestThreadFinished()
{
if (!m_deviceTester)
return;
QString output;
if (m_deviceTester->hasError()) {
output = tr("Device configuration test failed:\n%1").arg(m_deviceTester->error());
if (currentConfig().type == MaemoDeviceConfig::Simulator)
output.append(tr("\nDid you start Qemu?"));
} else {
output = parseTestOutput();
}
m_ui->testResultEdit->setPlainText(output);
stopConfigTest();
}
void MaemoSettingsWidget::stopConfigTest()
{
if (m_deviceTester) {
m_ui->testConfigButton->disconnect();
const bool buttonWasEnabled = m_ui->testConfigButton->isEnabled();
m_deviceTester->disconnect();
m_deviceTester->stop();
delete m_deviceTester;
m_deviceTester = 0;
m_deviceTestOutput.clear();
m_ui->testConfigButton->setText(tr("Test"));
connect(m_ui->testConfigButton, SIGNAL(clicked()),
this, SLOT(testConfig()));
m_ui->testConfigButton->setEnabled(buttonWasEnabled);
}
}
QString MaemoSettingsWidget::parseTestOutput()
{
QString output;
const QRegExp unamePattern(QLatin1String("Linux (\\S+)\\s(\\S+)"));
int index = unamePattern.indexIn(m_deviceTestOutput);
if (index == -1) {
output = tr("Device configuration test failed: Unexpected output:\n%1").arg(m_deviceTestOutput);
return output;
}
output = tr("Hardware architecture: %1\n").arg(unamePattern.cap(2));
output.append(tr("Kernel version: %1\n").arg(unamePattern.cap(1)));
output.prepend(tr("Device configuration successful.\n"));
const QRegExp dkpgPattern(QLatin1String("libqt\\S+ \\d\\.\\d\\.\\d"));
index = dkpgPattern.indexIn(m_deviceTestOutput);
if (index == -1) {
output.append("No Qt packages installed.");
return output;
}
output.append("List of installed Qt packages:\n");
do {
output.append(QLatin1String("\t") + dkpgPattern.cap(0)
+ QLatin1String("\n"));
index = dkpgPattern.indexIn(m_deviceTestOutput, index + 1);
} while (index != -1);
return output;
} }
void MaemoSettingsWidget::deployKey() void MaemoSettingsWidget::deployKey()
...@@ -434,13 +349,11 @@ void MaemoSettingsWidget::handleDeployThreadFinished() ...@@ -434,13 +349,11 @@ void MaemoSettingsWidget::handleDeployThreadFinished()
if (!m_keyDeployer) if (!m_keyDeployer)
return; return;
QString output; if (m_keyDeployer->hasError())
if (m_keyDeployer->hasError()) { QMessageBox::critical(this, tr("Deployment Failed"), tr("Key deployment failed: %1").arg(m_keyDeployer->error()));
output = tr("Key deployment failed: %1").arg(m_keyDeployer->error()); else
} else { QMessageBox::information(this, tr("Deployment Succeeded"), tr("Key was successfully deployed."));
output = tr("Key was successfully deployed.");
}
m_ui->testResultEdit->setPlainText(output);
stopDeploying(); stopDeploying();
} }
...@@ -465,9 +378,7 @@ void MaemoSettingsWidget::selectionChanged() ...@@ -465,9 +378,7 @@ void MaemoSettingsWidget::selectionChanged()
const QList<QListWidgetItem *> &selectedItems = const QList<QListWidgetItem *> &selectedItems =
m_ui->configListWidget->selectedItems(); m_ui->configListWidget->selectedItems();
Q_ASSERT(selectedItems.count() <= 1); Q_ASSERT(selectedItems.count() <= 1);
stopConfigTest();
stopDeploying(); stopDeploying();
m_ui->testResultEdit->setPlainText(m_defaultTestOutput);
if (selectedItems.isEmpty()) { if (selectedItems.isEmpty()) {
m_ui->removeConfigButton->setEnabled(false); m_ui->removeConfigButton->setEnabled(false);
m_ui->testConfigButton->setEnabled(false); m_ui->testConfigButton->setEnabled(false);
......
...@@ -44,13 +44,12 @@ ...@@ -44,13 +44,12 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QLineEdit; class QLineEdit;
class Ui_maemoSettingsWidget; class Ui_MaemoSettingsWidget;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Qt4ProjectManager { namespace Qt4ProjectManager {
namespace Internal { namespace Internal {
class MaemoSshRunner;
class MaemoSshDeployer; class MaemoSshDeployer;
class NameValidator; class NameValidator;
class PortAndTimeoutValidator; class PortAndTimeoutValidator;
...@@ -79,9 +78,6 @@ private slots: ...@@ -79,9 +78,6 @@ private slots:
// For configuration testing. // For configuration testing.
void testConfig(); void testConfig();
void processSshOutput(const QString &data);
void handleTestThreadFinished();
void stopConfigTest();
// For key deploying. // For key deploying.
void deployKey(); void deployKey();
...@@ -97,16 +93,13 @@ private: ...@@ -97,16 +93,13 @@ private:
void clearDetails(); void clearDetails();
QString parseTestOutput(); QString parseTestOutput();
Ui_maemoSettingsWidget *m_ui; Ui_MaemoSettingsWidget *m_ui;
QList<MaemoDeviceConfig> m_devConfs; QList<MaemoDeviceConfig> m_devConfs;
NameValidator * const m_nameValidator; NameValidator * const m_nameValidator;
PortAndTimeoutValidator * const m_sshPortValidator; PortAndTimeoutValidator * const m_sshPortValidator;
PortAndTimeoutValidator * const m_gdbServerPortValidator; PortAndTimeoutValidator * const m_gdbServerPortValidator;
PortAndTimeoutValidator * const m_timeoutValidator; PortAndTimeoutValidator * const m_timeoutValidator;
MaemoSshRunner *m_deviceTester;
MaemoSshDeployer *m_keyDeployer;