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 @@
#include "ui_maemosettingswidget.h"
#include "maemoconfigtestdialog.h"
#include "maemodeviceconfigurations.h"
#include "maemosshthread.h"
#include <QtCore/QRegExp>
#include <QtGui/QFileDialog>
#include <QtCore/QFileInfo>
#include <QtGui/QFileDialog>
#include <QtGui/QMessageBox>
#include <QtGui/QIntValidator>
#include <algorithm>
......@@ -109,13 +111,12 @@ private:
MaemoSettingsWidget::MaemoSettingsWidget(QWidget *parent)
: QWidget(parent),
m_ui(new Ui_maemoSettingsWidget),
m_ui(new Ui_MaemoSettingsWidget),
m_devConfs(MaemoDeviceConfigurations::instance().devConfigs()),
m_nameValidator(new NameValidator(m_devConfs)),
m_sshPortValidator(new PortAndTimeoutValidator),
m_gdbServerPortValidator(new PortAndTimeoutValidator),
m_timeoutValidator(new PortAndTimeoutValidator),
m_deviceTester(0),
m_keyDeployer(0)
{
......@@ -134,9 +135,8 @@ void MaemoSettingsWidget::initGui()
m_ui->gdbServerPortLineEdit->setValidator(m_gdbServerPortValidator);
m_ui->timeoutLineEdit->setValidator(m_timeoutValidator);
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_defaultTestOutput = m_ui->testResultEdit->toPlainText();
if (m_devConfs.count() == 1)
m_ui->configListWidget->setCurrentRow(0, QItemSelectionModel::Select);
}
......@@ -314,93 +314,8 @@ void MaemoSettingsWidget::keyFileEditingFinished()
void MaemoSettingsWidget::testConfig()
{
if (m_deviceTester)
return;
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;
QDialog *dialog = new MaemoConfigTestDialog(currentConfig(), this);
dialog->open();
}
void MaemoSettingsWidget::deployKey()
......@@ -434,13 +349,11 @@ void MaemoSettingsWidget::handleDeployThreadFinished()
if (!m_keyDeployer)
return;
QString output;
if (m_keyDeployer->hasError()) {
output = tr("Key deployment failed: %1").arg(m_keyDeployer->error());
} else {
output = tr("Key was successfully deployed.");
}
m_ui->testResultEdit->setPlainText(output);
if (m_keyDeployer->hasError())
QMessageBox::critical(this, tr("Deployment Failed"), tr("Key deployment failed: %1").arg(m_keyDeployer->error()));
else
QMessageBox::information(this, tr("Deployment Succeeded"), tr("Key was successfully deployed."));
stopDeploying();
}
......@@ -465,9 +378,7 @@ void MaemoSettingsWidget::selectionChanged()
const QList<QListWidgetItem *> &selectedItems =
m_ui->configListWidget->selectedItems();
Q_ASSERT(selectedItems.count() <= 1);
stopConfigTest();
stopDeploying();
m_ui->testResultEdit->setPlainText(m_defaultTestOutput);
if (selectedItems.isEmpty()) {
m_ui->removeConfigButton->setEnabled(false);
m_ui->testConfigButton->setEnabled(false);
......
......@@ -44,13 +44,12 @@
QT_BEGIN_NAMESPACE
class QLineEdit;
class Ui_maemoSettingsWidget;
class Ui_MaemoSettingsWidget;
QT_END_NAMESPACE
namespace Qt4ProjectManager {
namespace Internal {
class MaemoSshRunner;
class MaemoSshDeployer;
class NameValidator;
class PortAndTimeoutValidator;
......@@ -79,9 +78,6 @@ private slots:
// For configuration testing.
void testConfig();
void processSshOutput(const QString &data);
void handleTestThreadFinished();
void stopConfigTest();
// For key deploying.
void deployKey();
......@@ -97,16 +93,13 @@ private:
void clearDetails();
QString parseTestOutput();
Ui_maemoSettingsWidget *m_ui;
Ui_MaemoSettingsWidget *m_ui;
QList<MaemoDeviceConfig> m_devConfs;
NameValidator * const m_nameValidator;
PortAndTimeoutValidator * const m_sshPortValidator;
PortAndTimeoutValidator * const m_gdbServerPortValidator;
PortAndTimeoutValidator * const m_timeoutValidator;
MaemoSshRunner *m_deviceTester;
MaemoSshDeployer *m_keyDeployer;
QString m_deviceTestOutput;
QString m_defaultTestOutput;
};
} // namespace Internal
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>maemoSettingsWidget</class>
<widget class="QWidget" name="maemoSettingsWidget">
<class>MaemoSettingsWidget</class>
<widget class="QWidget" name="MaemoSettingsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>526</width>
<height>514</height>
<width>566</width>
<height>439</height>
</rect>
</property>
<property name="windowTitle">
......@@ -188,20 +188,6 @@
</layout>
</widget>
</item>
<item>
<widget class="QTextEdit" name="testResultEdit">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans Serif';&quot;&gt;No current test results available.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
......@@ -278,7 +264,7 @@ p, li { white-space: pre-wrap; }
<connection>
<sender>nameLineEdit</sender>
<signal>editingFinished()</signal>
<receiver>maemoSettingsWidget</receiver>
<receiver>MaemoSettingsWidget</receiver>
<slot>configNameEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
......@@ -294,7 +280,7 @@ p, li { white-space: pre-wrap; }
<connection>