genericlinuxdeviceconfigurationwidget.cpp 8.75 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** 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.
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** 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
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29
30
31
32

#include "genericlinuxdeviceconfigurationwidget.h"
#include "ui_genericlinuxdeviceconfigurationwidget.h"

Kai Koehne's avatar
Kai Koehne committed
33
#include <utils/portlist.h>
Friedemann Kleint's avatar
Friedemann Kleint committed
34
#include <utils/fancylineedit.h>
35
36
#include <ssh/sshconnection.h>
#include <ssh/sshkeycreationdialog.h>
37

38
using namespace ProjectExplorer;
39
using namespace RemoteLinux;
40
using namespace QSsh;
Kai Koehne's avatar
Kai Koehne committed
41
using namespace Utils;
42
43

GenericLinuxDeviceConfigurationWidget::GenericLinuxDeviceConfigurationWidget(
44
45
        const IDevice::Ptr &deviceConfig, QWidget *parent) :
    IDeviceWidget(deviceConfig, parent),
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
    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()));
62
    connect(m_ui->createKeyButton, SIGNAL(clicked()), SLOT(createNewKey()));
63
    connect(m_ui->gdbServerLineEdit, SIGNAL(editingFinished()), SLOT(gdbServerEditingFinished()));
64
65
66
67
68
69
70
71
72
73
74

    initGui();
}

GenericLinuxDeviceConfigurationWidget::~GenericLinuxDeviceConfigurationWidget()
{
    delete m_ui;
}

void GenericLinuxDeviceConfigurationWidget::authenticationTypeChanged()
{
75
    SshConnectionParameters sshParams = device()->sshParameters();
76
77
    const bool usePassword = m_ui->passwordButton->isChecked();
    sshParams.authenticationType = usePassword
78
79
        ? SshConnectionParameters::AuthenticationTypeTryAllPasswordBasedMethods
        : SshConnectionParameters::AuthenticationTypePublicKey;
80
    device()->setSshParameters(sshParams);
81
82
83
84
85
86
87
88
    m_ui->pwdLineEdit->setEnabled(usePassword);
    m_ui->passwordLabel->setEnabled(usePassword);
    m_ui->keyFileLineEdit->setEnabled(!usePassword);
    m_ui->keyLabel->setEnabled(!usePassword);
}

void GenericLinuxDeviceConfigurationWidget::hostNameEditingFinished()
{
89
    SshConnectionParameters sshParams = device()->sshParameters();
90
    sshParams.host = m_ui->hostLineEdit->text().trimmed();
91
    device()->setSshParameters(sshParams);
92
93
94
95
}

void GenericLinuxDeviceConfigurationWidget::sshPortEditingFinished()
{
96
    SshConnectionParameters sshParams = device()->sshParameters();
97
    sshParams.port = m_ui->sshPortSpinBox->value();
98
    device()->setSshParameters(sshParams);
99
100
101
102
}

void GenericLinuxDeviceConfigurationWidget::timeoutEditingFinished()
{
103
    SshConnectionParameters sshParams = device()->sshParameters();
104
    sshParams.timeout = m_ui->timeoutSpinBox->value();
105
    device()->setSshParameters(sshParams);
106
107
108
109
}

void GenericLinuxDeviceConfigurationWidget::userNameEditingFinished()
{
110
    SshConnectionParameters sshParams = device()->sshParameters();
111
    sshParams.userName = m_ui->userLineEdit->text();
112
    device()->setSshParameters(sshParams);
113
114
115
116
}

void GenericLinuxDeviceConfigurationWidget::passwordEditingFinished()
{
117
    SshConnectionParameters sshParams = device()->sshParameters();
118
    sshParams.password = m_ui->pwdLineEdit->text();
119
    device()->setSshParameters(sshParams);
120
121
122
123
}

void GenericLinuxDeviceConfigurationWidget::keyFileEditingFinished()
{
124
    SshConnectionParameters sshParams = device()->sshParameters();
125
    sshParams.privateKeyFile = m_ui->keyFileLineEdit->path();
126
    device()->setSshParameters(sshParams);
127
128
}

129
130
131
132
133
void GenericLinuxDeviceConfigurationWidget::gdbServerEditingFinished()
{
    device()->setDebugServerPath(m_ui->gdbServerLineEdit->text());
}

134
135
void GenericLinuxDeviceConfigurationWidget::handleFreePortsChanged()
{
136
    device()->setFreePorts(PortList::fromString(m_ui->portsLineEdit->text()));
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
    updatePortsWarningLabel();
}

void GenericLinuxDeviceConfigurationWidget::showPassword(bool showClearText)
{
    m_ui->pwdLineEdit->setEchoMode(showClearText
        ? QLineEdit::Normal : QLineEdit::Password);
}

void GenericLinuxDeviceConfigurationWidget::setPrivateKey(const QString &path)
{
    m_ui->keyFileLineEdit->setPath(path);
    keyFileEditingFinished();
}

152
153
154
155
156
157
158
void GenericLinuxDeviceConfigurationWidget::createNewKey()
{
    SshKeyCreationDialog dialog(this);
    if (dialog.exec() == QDialog::Accepted)
        setPrivateKey(dialog.privateKeyFilePath());
}

159
160
161
162
163
164
165
166
167
void GenericLinuxDeviceConfigurationWidget::updateDeviceFromUi()
{
    hostNameEditingFinished();
    sshPortEditingFinished();
    timeoutEditingFinished();
    userNameEditingFinished();
    passwordEditingFinished();
    keyFileEditingFinished();
    handleFreePortsChanged();
168
    gdbServerEditingFinished();
169
170
}

171
172
void GenericLinuxDeviceConfigurationWidget::updatePortsWarningLabel()
{
173
    m_ui->portsWarningLabel->setVisible(!device()->freePorts().hasMore());
174
175
176
177
}

void GenericLinuxDeviceConfigurationWidget::initGui()
{
178
    if (device()->machineType() == IDevice::Hardware)
179
180
181
        m_ui->machineTypeValueLabel->setText(tr("Physical Device"));
    else
        m_ui->machineTypeValueLabel->setText(tr("Emulator"));
182
    m_ui->portsWarningLabel->setPixmap(QPixmap(QLatin1String(":/projectexplorer/images/compile_error.png")));
183
184
    m_ui->portsWarningLabel->setToolTip(QLatin1String("<font color=\"red\">")
        + tr("You will need at least one port.") + QLatin1String("</font>"));
Kai Koehne's avatar
Kai Koehne committed
185
    m_ui->keyFileLineEdit->setExpectedKind(PathChooser::File);
186
    m_ui->keyFileLineEdit->setHistoryCompleter(QLatin1String("Ssh.KeyFile.History"));
187
188
189
190
191
    m_ui->keyFileLineEdit->lineEdit()->setMinimumWidth(0);
    QRegExpValidator * const portsValidator
        = new QRegExpValidator(QRegExp(PortList::regularExpression()), this);
    m_ui->portsLineEdit->setValidator(portsValidator);

192
    const SshConnectionParameters &sshParams = device()->sshParameters();
193

194
    if (sshParams.authenticationType != SshConnectionParameters::AuthenticationTypePublicKey)
195
196
197
198
        m_ui->passwordButton->setChecked(true);
    else
        m_ui->keyButton->setChecked(true);
    m_ui->timeoutSpinBox->setValue(sshParams.timeout);
199
200
    m_ui->hostLineEdit->setEnabled(!device()->isAutoDetected());
    m_ui->sshPortSpinBox->setEnabled(!device()->isAutoDetected());
201
202
203

    m_ui->hostLineEdit->setText(sshParams.host);
    m_ui->sshPortSpinBox->setValue(sshParams.port);
204
    m_ui->portsLineEdit->setText(device()->freePorts().toString());
205
206
207
208
209
    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);
210
    m_ui->gdbServerLineEdit->setText(device()->debugServerPath());
211
212
    updatePortsWarningLabel();
}