Commit 74da2172 authored by Nicolas Arnaud-Cormos's avatar Nicolas Arnaud-Cormos Committed by Christian Kandeler

Extract the device specific settings for linux device.

The LinuxConfigFactory has now a new pure virtual method to create the widget for
the device specific settings. It allows new device to create their own settings page.

Change-Id: Ie14df043fdef088b0e6e3b1e08b5d0d1863f76e5
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@nokia.com>
parent 147396d7
......@@ -40,6 +40,7 @@
#include <remotelinux/remotelinuxprocessesdialog.h>
#include <remotelinux/remotelinuxprocesslist.h>
#include <remotelinux/remotelinux_constants.h>
#include <remotelinux/genericlinuxdeviceconfigurationwidget.h>
#include <utils/qtcassert.h>
using namespace RemoteLinux;
......@@ -66,6 +67,13 @@ ILinuxDeviceConfigurationWizard *MaddeDeviceConfigurationFactory::createWizard(Q
return new MaemoDeviceConfigWizard(parent);
}
ILinuxDeviceConfigurationWidget *MaddeDeviceConfigurationFactory::createWidget(
const LinuxDeviceConfiguration::Ptr &deviceConfig,
QWidget *parent) const
{
return new GenericLinuxDeviceConfigurationWidget(deviceConfig, parent);
}
bool MaddeDeviceConfigurationFactory::supportsOsType(const QString &osType) const
{
return osType == QLatin1String(Maemo5OsType) || osType == QLatin1String(HarmattanOsType)
......
......@@ -45,6 +45,9 @@ public:
QString displayName() const;
RemoteLinux::ILinuxDeviceConfigurationWizard *createWizard(QWidget *parent) const;
RemoteLinux::ILinuxDeviceConfigurationWidget *createWidget(
const RemoteLinux::LinuxDeviceConfiguration::Ptr &deviceConfig,
QWidget *parent = 0) const;
bool supportsOsType(const QString &osType) const;
QString displayNameForOsType(const QString &osType) const;
QStringList supportedDeviceActionIds() const;
......
......@@ -32,6 +32,7 @@
#include "genericlinuxdeviceconfigurationfactory.h"
#include "genericlinuxdeviceconfigurationwizard.h"
#include "genericlinuxdeviceconfigurationwidget.h"
#include "linuxdevicetestdialog.h"
#include "publickeydeploymentdialog.h"
#include "remotelinuxprocessesdialog.h"
......@@ -57,6 +58,13 @@ ILinuxDeviceConfigurationWizard *GenericLinuxDeviceConfigurationFactory::createW
return new GenericLinuxDeviceConfigurationWizard(parent);
}
ILinuxDeviceConfigurationWidget *GenericLinuxDeviceConfigurationFactory::createWidget(
const LinuxDeviceConfiguration::Ptr &deviceConfig,
QWidget *parent) const
{
return new GenericLinuxDeviceConfigurationWidget(deviceConfig, parent);
}
bool GenericLinuxDeviceConfigurationFactory::supportsOsType(const QString &osType) const
{
return osType == QLatin1String(Constants::GenericLinuxOsType);
......
......@@ -47,6 +47,9 @@ public:
QString displayName() const;
ILinuxDeviceConfigurationWizard *createWizard(QWidget *parent) const;
ILinuxDeviceConfigurationWidget *createWidget(
const LinuxDeviceConfiguration::Ptr &deviceConfig,
QWidget *parent = 0) const;
bool supportsOsType(const QString &osType) const;
QString displayNameForOsType(const QString &osType) const;
QStringList supportedDeviceActionIds() const;
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** GNU Lesser General Public License Usage
**
** 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.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "genericlinuxdeviceconfigurationwidget.h"
#include "ui_genericlinuxdeviceconfigurationwidget.h"
#include <remotelinux/portlist.h>
#include <remotelinux/linuxdeviceconfigurations.h>
#include <utils/ssh/sshconnection.h>
#include <QTextStream>
using namespace RemoteLinux;
GenericLinuxDeviceConfigurationWidget::GenericLinuxDeviceConfigurationWidget(
const LinuxDeviceConfiguration::Ptr &deviceConfig,
QWidget *parent) :
ILinuxDeviceConfigurationWidget(deviceConfig, parent),
m_ui(new Ui::GenericLinuxDeviceConfigurationWidget)
{
m_ui->setupUi(this);
connect(m_ui->hostLineEdit, SIGNAL(editingFinished()), this, SLOT(hostNameEditingFinished()));
connect(m_ui->userLineEdit, SIGNAL(editingFinished()), this, SLOT(userNameEditingFinished()));
connect(m_ui->pwdLineEdit, SIGNAL(editingFinished()), this, SLOT(passwordEditingFinished()));
connect(m_ui->passwordButton, SIGNAL(toggled(bool)), this, SLOT(authenticationTypeChanged()));
connect(m_ui->keyFileLineEdit, SIGNAL(editingFinished()), this, SLOT(keyFileEditingFinished()));
connect(m_ui->keyFileLineEdit, SIGNAL(browsingFinished()), this, SLOT(keyFileEditingFinished()));
connect(m_ui->keyButton, SIGNAL(toggled(bool)), this, SLOT(authenticationTypeChanged()));
connect(m_ui->timeoutSpinBox, SIGNAL(editingFinished()), this, SLOT(timeoutEditingFinished()));
connect(m_ui->timeoutSpinBox, SIGNAL(valueChanged(int)), this, SLOT(timeoutEditingFinished()));
connect(m_ui->sshPortSpinBox, SIGNAL(editingFinished()), this, SLOT(sshPortEditingFinished()));
connect(m_ui->sshPortSpinBox, SIGNAL(valueChanged(int)), this, SLOT(sshPortEditingFinished()));
connect(m_ui->showPasswordCheckBox, SIGNAL(toggled(bool)), this, SLOT(showPassword(bool)));
connect(m_ui->portsLineEdit, SIGNAL(editingFinished()), this, SLOT(handleFreePortsChanged()));
connect(m_ui->makeKeyFileDefaultButton, SIGNAL(clicked()), SLOT(setDefaultKeyFilePath()));
initGui();
}
GenericLinuxDeviceConfigurationWidget::~GenericLinuxDeviceConfigurationWidget()
{
delete m_ui;
}
void GenericLinuxDeviceConfigurationWidget::authenticationTypeChanged()
{
Utils::SshConnectionParameters sshParams = deviceConfiguration()->sshParameters();
const bool usePassword = m_ui->passwordButton->isChecked();
sshParams.authenticationType = usePassword
? Utils::SshConnectionParameters::AuthenticationByPassword
: Utils::SshConnectionParameters::AuthenticationByKey;
deviceConfiguration()->setSshParameters(sshParams);
m_ui->pwdLineEdit->setEnabled(usePassword);
m_ui->passwordLabel->setEnabled(usePassword);
m_ui->keyFileLineEdit->setEnabled(!usePassword);
m_ui->keyLabel->setEnabled(!usePassword);
m_ui->makeKeyFileDefaultButton->setEnabled(!usePassword);
}
void GenericLinuxDeviceConfigurationWidget::hostNameEditingFinished()
{
Utils::SshConnectionParameters sshParams = deviceConfiguration()->sshParameters();
sshParams.host = m_ui->hostLineEdit->text();
deviceConfiguration()->setSshParameters(sshParams);
}
void GenericLinuxDeviceConfigurationWidget::sshPortEditingFinished()
{
Utils::SshConnectionParameters sshParams = deviceConfiguration()->sshParameters();
sshParams.port = m_ui->sshPortSpinBox->value();
deviceConfiguration()->setSshParameters(sshParams);
}
void GenericLinuxDeviceConfigurationWidget::timeoutEditingFinished()
{
Utils::SshConnectionParameters sshParams = deviceConfiguration()->sshParameters();
sshParams.timeout = m_ui->timeoutSpinBox->value();
deviceConfiguration()->setSshParameters(sshParams);
}
void GenericLinuxDeviceConfigurationWidget::userNameEditingFinished()
{
Utils::SshConnectionParameters sshParams = deviceConfiguration()->sshParameters();
sshParams.userName = m_ui->userLineEdit->text();
deviceConfiguration()->setSshParameters(sshParams);
}
void GenericLinuxDeviceConfigurationWidget::passwordEditingFinished()
{
Utils::SshConnectionParameters sshParams = deviceConfiguration()->sshParameters();
sshParams.password = m_ui->pwdLineEdit->text();
deviceConfiguration()->setSshParameters(sshParams);
}
void GenericLinuxDeviceConfigurationWidget::keyFileEditingFinished()
{
Utils::SshConnectionParameters sshParams = deviceConfiguration()->sshParameters();
sshParams.privateKeyFile = m_ui->keyFileLineEdit->path();
deviceConfiguration()->setSshParameters(sshParams);
}
void GenericLinuxDeviceConfigurationWidget::handleFreePortsChanged()
{
deviceConfiguration()->setFreePorts(PortList::fromString(m_ui->portsLineEdit->text()));
updatePortsWarningLabel();
}
void GenericLinuxDeviceConfigurationWidget::showPassword(bool showClearText)
{
m_ui->pwdLineEdit->setEchoMode(showClearText
? QLineEdit::Normal : QLineEdit::Password);
}
void GenericLinuxDeviceConfigurationWidget::setDefaultKeyFilePath()
{
emit defaultSshKeyFilePathChanged(m_ui->keyFileLineEdit->path());
}
void GenericLinuxDeviceConfigurationWidget::setPrivateKey(const QString &path)
{
m_ui->keyFileLineEdit->setPath(path);
keyFileEditingFinished();
}
void GenericLinuxDeviceConfigurationWidget::updatePortsWarningLabel()
{
m_ui->portsWarningLabel->setVisible(!deviceConfiguration()->freePorts().hasMore());
}
void GenericLinuxDeviceConfigurationWidget::initGui()
{
m_ui->portsWarningLabel->setPixmap(QPixmap(":/projectexplorer/images/compile_error.png"));
m_ui->portsWarningLabel->setToolTip(QLatin1String("<font color=\"red\">")
+ tr("You will need at least one port.") + QLatin1String("</font>"));
m_ui->keyFileLineEdit->setExpectedKind(Utils::PathChooser::File);
m_ui->keyFileLineEdit->lineEdit()->setMinimumWidth(0);
QRegExpValidator * const portsValidator
= new QRegExpValidator(QRegExp(PortList::regularExpression()), this);
m_ui->portsLineEdit->setValidator(portsValidator);
const Utils::SshConnectionParameters &sshParams = deviceConfiguration()->sshParameters();
if (sshParams.authenticationType == Utils::SshConnectionParameters::AuthenticationByPassword)
m_ui->passwordButton->setChecked(true);
else
m_ui->keyButton->setChecked(true);
m_ui->timeoutSpinBox->setValue(sshParams.timeout);
m_ui->hostLineEdit->setEnabled(!deviceConfiguration()->isAutoDetected());
m_ui->sshPortSpinBox->setEnabled(!deviceConfiguration()->isAutoDetected());
m_ui->hostLineEdit->setText(sshParams.host);
m_ui->sshPortSpinBox->setValue(sshParams.port);
m_ui->portsLineEdit->setText(deviceConfiguration()->freePorts().toString());
m_ui->timeoutSpinBox->setValue(sshParams.timeout);
m_ui->userLineEdit->setText(sshParams.userName);
m_ui->pwdLineEdit->setText(sshParams.password);
m_ui->keyFileLineEdit->setPath(sshParams.privateKeyFile);
m_ui->showPasswordCheckBox->setChecked(false);
updatePortsWarningLabel();
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** GNU Lesser General Public License Usage
**
** 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.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef REMOTELINUX_GENERICLINUXDEVICECONFIGURATIONWIDGET_H
#define REMOTELINUX_GENERICLINUXDEVICECONFIGURATIONWIDGET_H
#include "remotelinux_export.h"
#include "linuxdeviceconfiguration.h"
namespace RemoteLinux {
namespace Ui {
class GenericLinuxDeviceConfigurationWidget;
}
class REMOTELINUX_EXPORT GenericLinuxDeviceConfigurationWidget : public ILinuxDeviceConfigurationWidget
{
Q_OBJECT
public:
explicit GenericLinuxDeviceConfigurationWidget(
const LinuxDeviceConfiguration::Ptr &deviceConfig,
QWidget *parent = 0);
~GenericLinuxDeviceConfigurationWidget();
private slots:
void authenticationTypeChanged();
void hostNameEditingFinished();
void sshPortEditingFinished();
void timeoutEditingFinished();
void userNameEditingFinished();
void passwordEditingFinished();
void keyFileEditingFinished();
void showPassword(bool showClearText);
void handleFreePortsChanged();
void setDefaultKeyFilePath();
void setPrivateKey(const QString &path);
private:
void updatePortsWarningLabel();
void initGui();
Ui::GenericLinuxDeviceConfigurationWidget *m_ui;
};
} // namespace RemoteLinux
#endif // REMOTELINUX_GENERICLINUXDEVICECONFIGURATIONWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RemoteLinux::GenericLinuxDeviceConfigurationWidget</class>
<widget class="QWidget" name="RemoteLinux::GenericLinuxDeviceConfigurationWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>393</width>
<height>170</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::FieldsStayAtSizeHint</enum>
</property>
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="authTypeLabel">
<property name="text">
<string>Authentication type:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QWidget" name="authTypeButtonsWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QRadioButton" name="passwordButton">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="keyButton">
<property name="text">
<string>&amp;Key</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="hostNameLabel">
<property name="text">
<string>&amp;Host name:</string>
</property>
<property name="buddy">
<cstring>hostLineEdit</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLineEdit" name="hostLineEdit">
<property name="placeholderText">
<string>IP or host name of the device</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="sshPortLabel">
<property name="text">
<string>&amp;SSH port:</string>
</property>
<property name="buddy">
<cstring>sshPortSpinBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="sshPortSpinBox">
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>22</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="freePortsLabel">
<property name="text">
<string>Free ports:</string>
</property>
<property name="buddy">
<cstring>portsLineEdit</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLineEdit" name="portsLineEdit">
<property name="toolTip">
<string>You can enter lists and ranges like this: 1024,1026-1028,1030</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="portsWarningLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="connectionTimeoutLabel">
<property name="text">
<string>Timeout:</string>
</property>
<property name="buddy">
<cstring>timeoutSpinBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="timeoutSpinBox">
<property name="suffix">
<string>s</string>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="value">
<number>1000</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="userNameLabel">
<property name="text">
<string>&amp;Username:</string>
</property>
<property name="buddy">
<cstring>userLineEdit</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="userLineEdit"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="passwordLabel">
<property name="text">
<string>&amp;Password:</string>
</property>
<property name="buddy">
<cstring>pwdLineEdit</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLineEdit" name="pwdLineEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showPasswordCheckBox">
<property name="text">
<string>Show password</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="QLabel" name="keyLabel">
<property name="text">
<string>Private key file:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="Utils::PathChooser" name="keyFileLineEdit" native="true"/>
</item>
<item>
<widget class="QPushButton" name="makeKeyFileDefaultButton">
<property name="text">
<string>Set as Default</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
<zorder>passwordLabel</zorder>
<zorder>authTypeButtonsWidget</zorder>
<zorder>hostNameLabel</zorder>
<zorder>userNameLabel</zorder>
<zorder>freePortsLabel</zorder>
<zorder>userLineEdit</zorder>
<zorder>authTypeLabel</zorder>
<zorder>keyLabel</zorder>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header location="global">utils/pathchooser.h</header>
<container>1</container>
<slots>
<signal>editingFinished()</signal>
<signal>browsingFinished()</signal>
</slots>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
......@@ -31,10 +31,12 @@
**************************************************************************/
#include "linuxdeviceconfiguration.h"
#include "linuxdeviceconfigurations.h"
#include "portlist.h"
#include "remotelinux_constants.h"
#include <utils/ssh/sshconnection.h>
#include <utils/qtcassert.h>
#include <QSettings>
#include <QDesktopServices>
......@@ -264,4 +266,19 @@ void LinuxDeviceConfiguration::setDefault(bool isDefault) { d->isDefault = isDef
const LinuxDeviceConfiguration::Id LinuxDeviceConfiguration::InvalidId = 0;
ILinuxDeviceConfigurationWidget::ILinuxDeviceConfigurationWidget(
const LinuxDeviceConfiguration::Ptr &deviceConfig,
QWidget *parent)
: QWidget(parent),
m_deviceConfiguration(deviceConfig)
{
QTC_CHECK(m_deviceConfiguration);
}
LinuxDeviceConfiguration::Ptr ILinuxDeviceConfigurationWidget::deviceConfiguration() const
{
return m_deviceConfiguration;
}
} // namespace RemoteLinux
......@@ -82,6 +82,10 @@ public:
QVariantHash attributes() const;
QVariant attribute(const QString &name) const;
void setSshParameters(const Utils::SshConnectionParameters &sshParameters);
void setFreePorts(const PortList &freePorts);
void setAttribute(const QString &name, const QVariant &value);
static QString defaultPrivateKeyFilePath();
static QString defaultPublicKeyFilePath();
......@@ -106,9 +110,6 @@ private:
void setDisplayName(const QString &name);
void setInternalId(Id id);
void setDefault(bool isDefault);
void setSshParameters(const Utils::SshConnectionParameters &sshParameters);
void setFreePorts(const PortList &freePorts);
void setAttribute(const QString &name, const QVariant &value);
void save(QSettings &settings) const;
Internal::LinuxDeviceConfigurationPrivate *d;
......@@ -137,7 +138,35 @@ protected:
/*!
\class ProjectExplorer::ILinuxDeviceConfiguration factory.
\class RemoteLinux::LinuxDeviceConfigurationWidget : public QWidget
\brief Provides an interface for the widget configuring a LinuxDeviceConfiguration
A class implementing this interface will display a widget in the configuration
options page "Linux Device", in the "Device configuration" tab.
It's used to configure a particular device, the default widget is empty.
*/