analyzer: use ProfileChooser in remote valgrind dialog

Change-Id: I93acd2bb778e9a0b98b227591fc86250ad990147
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
hjk
2012-07-18 17:08:10 +02:00
parent d92df40125
commit c946b9e4bf
2 changed files with 33 additions and 168 deletions

View File

@@ -31,39 +31,31 @@
#include "startremotedialog.h" #include "startremotedialog.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/id.h>
#include <projectexplorer/profilechooser.h>
#include <projectexplorer/profileinformation.h>
#include <ssh/sshconnection.h> #include <ssh/sshconnection.h>
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QFormLayout> #include <QFormLayout>
#include <QGroupBox>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QPushButton> #include <QPushButton>
#include <QSpinBox> #include <QSpinBox>
using namespace ProjectExplorer;
using namespace Utils;
namespace Analyzer { namespace Analyzer {
namespace Internal { namespace Internal {
class StartRemoteDialogPrivate class StartRemoteDialogPrivate
{ {
public: public:
QLabel *hostLabel; ProfileChooser *profileChooser;
QLineEdit *host;
QLabel *userLabel;
QLineEdit *user;
QLabel *portLabel;
QSpinBox *port;
QLabel *passwordLabel;
QLineEdit *password;
QLabel *keyFileLabel;
Utils::PathChooser *keyFile;
QFormLayout *formLayout;
QLabel *executableLabel;
QLineEdit *executable; QLineEdit *executable;
QLabel *argumentsLabel;
QLineEdit *arguments; QLineEdit *arguments;
QLabel *workingDirectoryLabel;
QLineEdit *workingDirectory; QLineEdit *workingDirectory;
QDialogButtonBox *buttonBox; QDialogButtonBox *buttonBox;
}; };
@@ -77,97 +69,41 @@ StartRemoteDialog::StartRemoteDialog(QWidget *parent)
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setWindowTitle(tr("Start Remote Analysis")); setWindowTitle(tr("Start Remote Analysis"));
QGroupBox *groupBox = new QGroupBox(tr("Remote"), this); d->profileChooser = new ProfileChooser(this, true);
d->executable = new QLineEdit(this);
d->host = new QLineEdit(groupBox); d->arguments = new QLineEdit(this);
d->hostLabel = new QLabel(tr("Host:"), groupBox); d->workingDirectory = new QLineEdit(this);
d->user = new QLineEdit(groupBox);
d->userLabel = new QLabel(tr("User:"), groupBox);
d->port = new QSpinBox(groupBox);
d->port->setMaximum(65535);
d->port->setSingleStep(1);
d->port->setValue(22);
d->portLabel = new QLabel(tr("Port:"), groupBox);
d->passwordLabel = new QLabel(tr("Password:"), groupBox);
d->passwordLabel->setToolTip(tr("You need to pass either a password or an SSH key."));
d->password = new QLineEdit(groupBox);
d->password->setEchoMode(QLineEdit::Password);
d->keyFileLabel = new QLabel(tr("Private key:"), groupBox);
d->keyFileLabel->setToolTip(tr("You need to pass either a password or an SSH key."));
d->keyFile = new Utils::PathChooser(groupBox);
QGroupBox *groupBox2 = new QGroupBox(tr("Target"), this);
d->executable = new QLineEdit(groupBox2);
d->executableLabel = new QLabel(tr("Executable:"), groupBox2);
d->arguments = new QLineEdit(groupBox2);
d->argumentsLabel = new QLabel(tr("Arguments:"), groupBox2);
d->workingDirectory = new QLineEdit(groupBox2);
d->workingDirectoryLabel = new QLabel(tr("Working directory:"), groupBox2);
d->buttonBox = new QDialogButtonBox(this); d->buttonBox = new QDialogButtonBox(this);
d->buttonBox->setOrientation(Qt::Horizontal); d->buttonBox->setOrientation(Qt::Horizontal);
d->buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); d->buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
QFormLayout *formLayout = new QFormLayout(groupBox); QFormLayout *formLayout = new QFormLayout;
formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
formLayout->addRow(d->hostLabel, d->host); formLayout->addRow(tr("Profile:"), d->profileChooser);
formLayout->addRow(d->userLabel, d->user); formLayout->addRow(tr("Executable:"), d->executable);
formLayout->addRow(d->portLabel, d->port); formLayout->addRow(tr("Arguments:"), d->arguments);
formLayout->addRow(d->passwordLabel, d->password); formLayout->addRow(tr("Working directory:"), d->workingDirectory);
formLayout->addRow(d->keyFileLabel, d->keyFile);
QFormLayout *formLayout2 = new QFormLayout(groupBox2);
formLayout2->addRow(d->executableLabel, d->executable);
formLayout2->addRow(d->argumentsLabel, d->arguments);
formLayout2->addRow(d->workingDirectoryLabel, d->workingDirectory);
QVBoxLayout *verticalLayout = new QVBoxLayout(this); QVBoxLayout *verticalLayout = new QVBoxLayout(this);
verticalLayout->addWidget(groupBox); verticalLayout->addLayout(formLayout);
verticalLayout->addWidget(groupBox2);
verticalLayout->addWidget(d->buttonBox); verticalLayout->addWidget(d->buttonBox);
d->keyFile->setExpectedKind(Utils::PathChooser::File);
QSettings *settings = Core::ICore::settings(); QSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String("AnalyzerStartRemoteDialog")); settings->beginGroup(QLatin1String("AnalyzerStartRemoteDialog"));
d->host->setText(settings->value(QLatin1String("host")).toString()); QString profile = settings->value(QLatin1String("profile")).toString();
d->port->setValue(settings->value(QLatin1String("port"), 22).toInt()); d->profileChooser->setCurrentProfileId(Core::Id(profile));
d->user->setText(settings->value(QLatin1String("user"), qgetenv("USER")).toString());
d->keyFile->setPath(settings->value(QLatin1String("keyFile")).toString());
d->executable->setText(settings->value(QLatin1String("executable")).toString()); d->executable->setText(settings->value(QLatin1String("executable")).toString());
d->workingDirectory->setText(settings->value(QLatin1String("workingDirectory")).toString()); d->workingDirectory->setText(settings->value(QLatin1String("workingDirectory")).toString());
d->arguments->setText(settings->value(QLatin1String("arguments")).toString()); d->arguments->setText(settings->value(QLatin1String("arguments")).toString());
settings->endGroup(); settings->endGroup();
connect(d->host, SIGNAL(textChanged(QString)), connect(d->profileChooser, SIGNAL(activated(int)), SLOT(validate()));
this, SLOT(validate())); connect(d->executable, SIGNAL(textChanged(QString)), SLOT(validate()));
connect(d->port, SIGNAL(valueChanged(int)), connect(d->workingDirectory, SIGNAL(textChanged(QString)), SLOT(validate()));
this, SLOT(validate())); connect(d->arguments, SIGNAL(textChanged(QString)), SLOT(validate()));
connect(d->password, SIGNAL(textChanged(QString)), connect(d->buttonBox, SIGNAL(accepted()), SLOT(accept()));
this, SLOT(validate())); connect(d->buttonBox, SIGNAL(rejected()), SLOT(reject()));
connect(d->keyFile, SIGNAL(changed(QString)),
this, SLOT(validate()));
connect(d->executable, SIGNAL(textChanged(QString)),
this, SLOT(validate()));
connect(d->workingDirectory, SIGNAL(textChanged(QString)),
this, SLOT(validate()));
connect(d->arguments, SIGNAL(textChanged(QString)),
this, SLOT(validate()));
connect(d->buttonBox, SIGNAL(accepted()),
this, SLOT(accept()));
connect(d->buttonBox, SIGNAL(rejected()),
this, SLOT(reject()));
validate(); validate();
} }
@@ -181,10 +117,7 @@ void StartRemoteDialog::accept()
{ {
QSettings *settings = Core::ICore::settings(); QSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String("AnalyzerStartRemoteDialog")); settings->beginGroup(QLatin1String("AnalyzerStartRemoteDialog"));
settings->setValue(QLatin1String("host"), d->host->text()); settings->setValue(QLatin1String("profile"), d->profileChooser->currentProfileId().toString());
settings->setValue(QLatin1String("port"), d->port->value());
settings->setValue(QLatin1String("user"), d->user->text());
settings->setValue(QLatin1String("keyFile"), d->keyFile->path());
settings->setValue(QLatin1String("executable"), d->executable->text()); settings->setValue(QLatin1String("executable"), d->executable->text());
settings->setValue(QLatin1String("workingDirectory"), d->workingDirectory->text()); settings->setValue(QLatin1String("workingDirectory"), d->workingDirectory->text());
settings->setValue(QLatin1String("arguments"), d->arguments->text()); settings->setValue(QLatin1String("arguments"), d->arguments->text());
@@ -195,27 +128,15 @@ void StartRemoteDialog::accept()
void StartRemoteDialog::validate() void StartRemoteDialog::validate()
{ {
bool valid = !d->host->text().isEmpty() && !d->user->text().isEmpty() bool valid = !d->executable->text().isEmpty();
&& !d->executable->text().isEmpty();
valid = valid && (!d->password->text().isEmpty() || d->keyFile->isValid());
d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid); d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);
} }
QSsh::SshConnectionParameters StartRemoteDialog::sshParams() const QSsh::SshConnectionParameters StartRemoteDialog::sshParams() const
{ {
QSsh::SshConnectionParameters params; Profile *profile = d->profileChooser->currentProfile();
params.host = d->host->text(); IDevice::ConstPtr device = DeviceProfileInformation::device(profile);
params.userName = d->user->text(); return device->sshParameters();
if (d->keyFile->isValid()) {
params.authenticationType = QSsh::SshConnectionParameters::AuthenticationByKey;
params.privateKeyFile = d->keyFile->path();
} else {
params.authenticationType = QSsh::SshConnectionParameters::AuthenticationByPassword;
params.password = d->password->text();
}
params.port = d->port->value();
params.timeout = 10;
return params;
} }
QString StartRemoteDialog::executable() const QString StartRemoteDialog::executable() const

View File

@@ -120,70 +120,14 @@ bool MemcheckRunner::start()
setValgrindArguments(memcheckArguments); setValgrindArguments(memcheckArguments);
} }
if (startMode() == Analyzer::StartRemote) { if (startMode() == Analyzer::StartRemote) {
QTC_ASSERT(d->parser, return false); QTC_ASSERT(d->parser, return false);
QList<QHostAddress> possibleHostAddresses; QString ip = connectionParameters().host;
//NOTE: ::allAddresses does not seem to work for usb interfaces...
foreach (const QNetworkInterface &iface, QNetworkInterface::allInterfaces()) {
foreach (const QNetworkAddressEntry &entry, iface.addressEntries()) {
const QHostAddress addr = entry.ip();
if (addr.toString() != "127.0.0.1"
&& addr.toString() != "0:0:0:0:0:0:0:1")
{
possibleHostAddresses << addr;
break;
}
}
}
QHostAddress hostAddr;
if (possibleHostAddresses.isEmpty()) {
emit processErrorReceived(tr("No network interface found for remote analysis."),
QProcess::FailedToStart);
return false;
} else if (possibleHostAddresses.size() > 1) {
QDialog dlg;
dlg.setWindowTitle(tr("Select Network Interface"));
QVBoxLayout *layout = new QVBoxLayout;
QLabel *description = new QLabel;
description->setWordWrap(true);
description->setText(tr("More than one network interface was found on your machine. Please select which one you want to use for remote analysis."));
layout->addWidget(description);
QListWidget *list = new QListWidget;
foreach (const QHostAddress &address, possibleHostAddresses)
list->addItem(address.toString());
list->setSelectionMode(QAbstractItemView::SingleSelection);
list->setCurrentRow(0);
layout->addWidget(list);
QDialogButtonBox *buttons = new QDialogButtonBox;
buttons->addButton(QDialogButtonBox::Ok);
buttons->addButton(QDialogButtonBox::Cancel);
connect(buttons, SIGNAL(accepted()),
&dlg, SLOT(accept()));
connect(buttons, SIGNAL(rejected()),
&dlg, SLOT(reject()));
layout->addWidget(buttons);
dlg.setLayout(layout);
if (dlg.exec() != QDialog::Accepted) {
emit processErrorReceived(tr("No Network Interface was chosen for remote analysis"), QProcess::FailedToStart);
return false;
}
QTC_ASSERT(list->currentRow() >= 0, return false);
QTC_ASSERT(list->currentRow() < possibleHostAddresses.size(), return false);
hostAddr = possibleHostAddresses.at(list->currentRow());
} else {
hostAddr = possibleHostAddresses.first();
}
QString ip = hostAddr.toString();
QTC_ASSERT(!ip.isEmpty(), return false); QTC_ASSERT(!ip.isEmpty(), return false);
QHostAddress hostAddr(ip);
bool check = d->xmlServer.listen(hostAddr); bool check = d->xmlServer.listen(hostAddr);
QTC_ASSERT(check, return false); QTC_ASSERT(check, return false);
d->xmlServer.setMaxPendingConnections(1); d->xmlServer.setMaxPendingConnections(1);